improvements in supervisor helper
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Jakob Meier
2022-04-19 13:33:37 +02:00
parent 1ce45acba3
commit ffd64d0463
16 changed files with 310 additions and 254 deletions

View File

@ -10,6 +10,7 @@
#endif
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/timemanager/Countdown.h"
#include "mission/utility/Filenaming.h"
#include "mission/utility/ProgressPrinter.h"
#include "mission/utility/Timestamp.h"
@ -44,7 +45,6 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_UPDATE_SUCCESSFUL, result);
} else if (result == PROCESS_TERMINATED) {
// Event already triggered
break;
} else {
triggerEvent(SUPV_UPDATE_FAILED, result);
}
@ -109,10 +109,6 @@ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
update.length = getFileSize(update.file);
update.memoryId = memoryId;
update.startAddress = startAddress;
result = calcImageCrc();
if (result != RETURN_OK) {
return result;
}
internalState = InternalState::UPDATE;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release();
@ -140,6 +136,10 @@ void PlocSupvHelper::stopProcess() { terminate = true; }
ReturnValue_t PlocSupvHelper::performUpdate() {
ReturnValue_t result = RETURN_OK;
result = calcImageCrc();
if (result != RETURN_OK) {
return result;
}
result = prepareUpdate();
if (result != RETURN_OK) {
return result;
@ -149,8 +149,7 @@ ReturnValue_t PlocSupvHelper::performUpdate() {
return result;
}
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
ProgressPrinter progressPrinter("Supervisor update: ", update.length,
ProgressPrinter::ONE_PERCENT);
ProgressPrinter progressPrinter("Supervisor update", update.length, ProgressPrinter::ONE_PERCENT);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
uint8_t tempData[supv::WriteMemory::CHUNK_MAX];
std::ifstream file(update.file, std::ifstream::binary);
@ -166,11 +165,17 @@ ReturnValue_t PlocSupvHelper::performUpdate() {
if (remainingSize > supv::WriteMemory::CHUNK_MAX) {
dataLength = supv::WriteMemory::CHUNK_MAX;
} else {
dataLength = remainingSize;
dataLength = static_cast<uint16_t>(remainingSize);
}
if (file.is_open()) {
file.seekg(bytesWritten, file.beg);
file.read(reinterpret_cast<char*>(tempData), dataLength);
if (!file) {
sif::warning << "PlocSupvHelper::performUpdate: Read only " << file.gcount() << " of "
<< dataLength << " bytes" << std::endl;
sif::info << "PlocSupvHelper::performUpdate: Failed when trying to read byte "
<< bytesWritten << std::endl;
}
remainingSize -= dataLength;
} else {
return FILE_CLOSED_ACCIDENTALLY;
@ -236,14 +241,15 @@ ReturnValue_t PlocSupvHelper::prepareUpdate() {
ReturnValue_t PlocSupvHelper::eraseMemory() {
ReturnValue_t result = RETURN_OK;
supv::EraseMemory eraseMemory(update.memoryId, update.startAddress, update.length);
result = handlePacketTransmission(eraseMemory);
result = handlePacketTransmission(eraseMemory, supv::recv_timeout::ERASE_MEMORY);
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
ReturnValue_t PlocSupvHelper::handlePacketTransmission(SpacePacket& packet) {
ReturnValue_t PlocSupvHelper::handlePacketTransmission(SpacePacket& packet,
uint32_t timeoutExecutionReport) {
ReturnValue_t result = RETURN_OK;
result = sendCommand(packet);
if (result != RETURN_OK) {
@ -253,7 +259,7 @@ ReturnValue_t PlocSupvHelper::handlePacketTransmission(SpacePacket& packet) {
if (result != RETURN_OK) {
return result;
}
result = handleExe();
result = handleExe(timeoutExecutionReport);
if (result != RETURN_OK) {
return result;
}
@ -302,10 +308,10 @@ void PlocSupvHelper::handleAckApidFailure(uint16_t apid) {
}
}
ReturnValue_t PlocSupvHelper::handleExe() {
ReturnValue_t PlocSupvHelper::handleExe(uint32_t timeout) {
ReturnValue_t result = RETURN_OK;
supv::TmPacket tmPacket;
result = handleTmReception(&tmPacket, supv::SIZE_EXE_REPORT);
result = handleTmReception(&tmPacket, supv::SIZE_EXE_REPORT, timeout);
if (result != RETURN_OK) {
triggerEvent(EXE_RECEPTION_FAILURE, result, static_cast<uint32_t>(rememberApid));
sif::warning << "PlocSupvHelper::handleExe: Error in reception of execution report"
@ -332,11 +338,13 @@ void PlocSupvHelper::handleExeApidFailure(uint16_t apid) {
}
}
ReturnValue_t PlocSupvHelper::handleTmReception(supv::TmPacket* tmPacket, size_t remainingBytes) {
ReturnValue_t PlocSupvHelper::handleTmReception(supv::TmPacket* tmPacket, size_t remainingBytes,
uint32_t timeout) {
ReturnValue_t result = RETURN_OK;
size_t readBytes = 0;
size_t currentBytes = 0;
for (int retries = 0; retries < RETRIES; retries++) {
Countdown countdown(timeout);
while (!countdown.hasTimedOut()) {
result = receive(tmPacket->getWholeData() + readBytes, &currentBytes, remainingBytes);
if (result != RETURN_OK) {
return result;
@ -395,11 +403,21 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() {
std::ifstream file(update.file, std::ifstream::binary);
uint16_t remainder = CRC16_INIT;
uint8_t input;
for (uint32_t byteCount = 0; byteCount < update.length; byteCount++) {
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
ProgressPrinter progress("Supervisor update crc calculation", update.length);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
uint32_t byteCount = 0;
for (byteCount = 0; byteCount < update.length; byteCount++) {
file.seekg(byteCount, file.beg);
file.read(reinterpret_cast<char*>(&input), 1);
remainder = CRC::crc16ccitt(&input, sizeof(input), remainder);
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progress.print(byteCount);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
}
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progress.print(byteCount);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
file.close();
update.crc = remainder;
return result;
@ -419,7 +437,8 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
}
supv::UpdateStatusReport updateStatusReport;
result = handleTmReception(&updateStatusReport,
static_cast<size_t>(updateStatusReport.getNominalSize()));
static_cast<size_t>(updateStatusReport.getNominalSize()),
supv::recv_timeout::UPDATE_STATUS_REPORT);
if (result != RETURN_OK) {
return result;
}
@ -487,7 +506,3 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception() {
}
return result;
}
//ReturnValue_t PlocSupervisorHandler::parseStatusCode(std::string* meaning) {
//
//}