speed up crc proc significantly
This commit is contained in:
parent
1f3365960d
commit
f98411f421
@ -1,5 +1,7 @@
|
|||||||
#include "PlocSupvHelper.h"
|
#include "PlocSupvHelper.h"
|
||||||
|
|
||||||
|
#include <etl/crc16_ccitt.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -10,7 +12,6 @@
|
|||||||
#include "bsp_q7s/memory/SdCardManager.h"
|
#include "bsp_q7s/memory/SdCardManager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fsfw/globalfunctions/CRC.h"
|
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
#include "fsfw/timemanager/Countdown.h"
|
#include "fsfw/timemanager/Countdown.h"
|
||||||
#include "mission/utility/Filenaming.h"
|
#include "mission/utility/Filenaming.h"
|
||||||
@ -509,32 +510,39 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() {
|
|||||||
#ifdef XIPHOS_Q7S
|
#ifdef XIPHOS_Q7S
|
||||||
result = FilesystemHelper::checkPath(update.file);
|
result = FilesystemHelper::checkPath(update.file);
|
||||||
#endif
|
#endif
|
||||||
|
auto crc16Calcer = etl::crc16_ccitt();
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist"
|
sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
std::ifstream file(update.file, std::ifstream::binary);
|
std::ifstream file(update.file, std::ifstream::binary);
|
||||||
uint16_t remainder = CRC16_INIT;
|
std::array<uint8_t, 1025> crcBuf;
|
||||||
uint8_t input;
|
|
||||||
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
||||||
ProgressPrinter progress("Supervisor update crc calculation", update.length,
|
ProgressPrinter progress("Supervisor update crc calculation", update.length,
|
||||||
ProgressPrinter::ONE_PERCENT);
|
ProgressPrinter::ONE_PERCENT);
|
||||||
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
||||||
uint32_t byteCount = 0;
|
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.seekg(byteCount, file.beg);
|
||||||
file.read(reinterpret_cast<char*>(&input), 1);
|
file.read(reinterpret_cast<char*>(crcBuf.data()), bytesToRead);
|
||||||
remainder = CRC::crc16ccitt(&input, sizeof(input), remainder);
|
crc16Calcer.add(crcBuf.begin(), crcBuf.begin() + bytesToRead);
|
||||||
|
|
||||||
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
||||||
progress.print(byteCount);
|
progress.print(byteCount);
|
||||||
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
||||||
|
byteCount += bytesToRead;
|
||||||
}
|
}
|
||||||
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
||||||
progress.print(byteCount);
|
progress.print(byteCount);
|
||||||
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
||||||
file.close();
|
file.close();
|
||||||
update.crc = remainder;
|
update.crc = crc16Calcer.value();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user