From f98411f421236abdd309e98e75a8eca671e47936 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 22 Aug 2022 10:35:23 +0200 Subject: [PATCH] speed up crc proc significantly --- linux/devices/ploc/PlocSupvHelper.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/linux/devices/ploc/PlocSupvHelper.cpp b/linux/devices/ploc/PlocSupvHelper.cpp index 13185d2d..a8858e25 100644 --- a/linux/devices/ploc/PlocSupvHelper.cpp +++ b/linux/devices/ploc/PlocSupvHelper.cpp @@ -1,5 +1,7 @@ #include "PlocSupvHelper.h" +#include + #include #include #include @@ -10,7 +12,6 @@ #include "bsp_q7s/memory/SdCardManager.h" #endif -#include "fsfw/globalfunctions/CRC.h" #include "fsfw/tasks/TaskFactory.h" #include "fsfw/timemanager/Countdown.h" #include "mission/utility/Filenaming.h" @@ -509,32 +510,39 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() { #ifdef XIPHOS_Q7S result = FilesystemHelper::checkPath(update.file); #endif + auto crc16Calcer = etl::crc16_ccitt(); if (result != RETURN_OK) { sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist" << std::endl; return result; } std::ifstream file(update.file, std::ifstream::binary); - uint16_t remainder = CRC16_INIT; - uint8_t input; + std::array crcBuf; #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 ProgressPrinter progress("Supervisor update crc calculation", update.length, ProgressPrinter::ONE_PERCENT); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ uint32_t byteCount = 0; - for (byteCount = 0; byteCount < update.length; byteCount++) { + while (byteCount < update.length) { + size_t bytesToRead = 1024; + size_t remLen = update.length - byteCount; + if (remLen < 1024) { + bytesToRead = remLen; + } file.seekg(byteCount, file.beg); - file.read(reinterpret_cast(&input), 1); - remainder = CRC::crc16ccitt(&input, sizeof(input), remainder); + file.read(reinterpret_cast(crcBuf.data()), bytesToRead); + crc16Calcer.add(crcBuf.begin(), crcBuf.begin() + bytesToRead); + #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 progress.print(byteCount); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ + byteCount += bytesToRead; } #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 progress.print(byteCount); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ file.close(); - update.crc = remainder; + update.crc = crc16Calcer.value(); return result; }