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

@ -222,6 +222,12 @@ static const uint32_t BOOT_REPORT_SET_ID = BOOT_STATUS_REPORT;
static const uint32_t LATCHUP_RPT_ID = LATCHUP_REPORT;
static const uint32_t LOGGING_RPT_ID = LOGGING_REQUEST_COUNTERS;
namespace recv_timeout {
// Erase memory can require up to 60 seconds for execution
static const uint32_t ERASE_MEMORY = 60000;
static const uint32_t UPDATE_STATUS_REPORT = 60000;
}
/**
* @brief This class creates a space packet containing only the header data and the CRC.
*/

View File

@ -243,6 +243,80 @@ void PlocMPSoCHandler::fillCommandAndReplyMap() {
this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT);
}
ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies, bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = RETURN_OK;
uint8_t enabledReplies = 0;
switch (command->first) {
case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHDELETE:
case mpsoc::TC_REPLAY_START:
case mpsoc::TC_REPLAY_STOP:
case mpsoc::TC_DOWNLINK_PWR_ON:
case mpsoc::TC_DOWNLINK_PWR_OFF:
case mpsoc::TC_REPLAY_WRITE_SEQUENCE:
case mpsoc::TC_MODE_REPLAY:
enabledReplies = 2;
break;
case mpsoc::TC_MEM_READ: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
mpsoc::TM_MEMORY_READ_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
<< mpsoc::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
}
break;
}
case mpsoc::OBSW_RESET_SEQ_COUNT:
break;
default:
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::EXE_REPORT
<< " not in replyMap" << std::endl;
}
switch (command->first) {
case mpsoc::TC_REPLAY_WRITE_SEQUENCE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
// Overwrite delay cycles because replay write sequence command can required up to
// 30 seconds for execution
iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY;
break;
}
case mpsoc::TC_DOWNLINK_PWR_ON: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
//
iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON;
break;
}
default:
break;
}
return RETURN_OK;
}
ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = RETURN_OK;
@ -586,79 +660,7 @@ ReturnValue_t PlocMPSoCHandler::handleMemoryReadReport(const uint8_t* data) {
return result;
}
ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies, bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = RETURN_OK;
uint8_t enabledReplies = 0;
switch (command->first) {
case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHDELETE:
case mpsoc::TC_REPLAY_START:
case mpsoc::TC_REPLAY_STOP:
case mpsoc::TC_DOWNLINK_PWR_ON:
case mpsoc::TC_DOWNLINK_PWR_OFF:
case mpsoc::TC_REPLAY_WRITE_SEQUENCE:
case mpsoc::TC_MODE_REPLAY:
enabledReplies = 2;
break;
case mpsoc::TC_MEM_READ: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
mpsoc::TM_MEMORY_READ_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
<< mpsoc::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
}
break;
}
case mpsoc::OBSW_RESET_SEQ_COUNT:
break;
default:
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::EXE_REPORT
<< " not in replyMap" << std::endl;
}
switch (command->first) {
case mpsoc::TC_REPLAY_WRITE_SEQUENCE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
// Overwrite delay cycles because replay write sequence command can required up to
// 30 seconds for execution
iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY;
break;
}
case mpsoc::TC_DOWNLINK_PWR_ON: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
//
iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON;
break;
}
default:
break;
}
return RETURN_OK;
}
void PlocMPSoCHandler::setNextReplyId() {
switch (getPendingCommand()) {

View File

@ -88,7 +88,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
switch (actionId) {
case TERMINATE_SUPV_HELPER: {
supvHelper->stopProcess();
break;
return EXECUTION_FINISHED;
}
default:
break;
@ -1145,6 +1145,14 @@ size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) {
return replyLen;
}
ReturnValue_t PlocSupervisorHandler::doSendReadHook() {
// Prevent DHB from polling UART during commands executed by the supervisor helper task
if (plocSupvHelperExecuting) {
return RETURN_FAILED;
}
return RETURN_OK;
}
void PlocSupervisorHandler::handleDeviceTM(const uint8_t* data, size_t dataSize,
DeviceCommandId_t replyId) {
ReturnValue_t result = RETURN_OK;

View File

@ -55,6 +55,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
uint8_t expectedReplies = 1, bool useAlternateId = false,
DeviceCommandId_t alternateReplyID = 0) override;
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
virtual ReturnValue_t doSendReadHook() override;
private:

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) {
//
//}

View File

@ -123,9 +123,6 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
//! [EXPORT] : [COMMENT] Expected event buffer TM but received space packet with other APID
static const ReturnValue_t EVENT_BUFFER_REPLY_INVALID_APID = MAKE_RETURN_CODE(0xA3);
// Maximum number of times the communication interface retries polling data from the reply
// buffer
static const int RETRIES = 20000;
static const uint16_t CRC16_INIT = 0xFFFF;
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with
// 192 bytes
@ -180,7 +177,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
ReturnValue_t performUpdate();
ReturnValue_t performEventBufferRequest();
ReturnValue_t handlePacketTransmission(SpacePacket& packet);
ReturnValue_t handlePacketTransmission(SpacePacket& packet,
uint32_t timeoutExecutionReport = 1000);
ReturnValue_t sendCommand(SpacePacket& packet);
/**
* @brief Function which reads form the communication interface
@ -191,7 +189,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
*/
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
ReturnValue_t handleAck();
ReturnValue_t handleExe();
ReturnValue_t handleExe(uint32_t timeout = 1000);
void handleAckApidFailure(uint16_t apid);
void handleExeApidFailure(uint16_t apid);
/**
@ -199,8 +197,10 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
*
* @param tmPacket Pointer to space packet where received data will be written to
* @param reaminingBytes Number of bytes to read in the space packet
* @param timeout Receive timeout in milliseconds
*/
ReturnValue_t handleTmReception(supv::TmPacket* tmPacket, size_t remainingBytes);
ReturnValue_t handleTmReception(supv::TmPacket* tmPacket, size_t remainingBytes,
uint32_t timeout = 1000);
ReturnValue_t prepareUpdate();
ReturnValue_t eraseMemory();
// Calculates CRC over image. Will be used for verification after update writing has

View File

@ -1,7 +1,7 @@
/**
* @brief Auto-generated event translation file. Contains 192 translations.
* @brief Auto-generated event translation file. Contains 194 translations.
* @details
* Generated on: 2022-04-16 17:47:08
* Generated on: 2022-04-18 16:58:03
*/
#include "translateEvents.h"
@ -193,6 +193,8 @@ const char *SUPV_ACK_FAILURE_REPORT_STRING = "SUPV_ACK_FAILURE_REPORT";
const char *SUPV_EXE_FAILURE_REPORT_STRING = "SUPV_EXE_FAILURE_REPORT";
const char *SUPV_ACK_INVALID_APID_STRING = "SUPV_ACK_INVALID_APID";
const char *SUPV_EXE_INVALID_APID_STRING = "SUPV_EXE_INVALID_APID";
const char *ACK_RECEPTION_FAILURE_STRING = "ACK_RECEPTION_FAILURE";
const char *EXE_RECEPTION_FAILURE_STRING = "EXE_RECEPTION_FAILURE";
const char *translateEvents(Event event) {
switch ((event & 0xFFFF)) {
@ -572,6 +574,10 @@ const char *translateEvents(Event event) {
return SUPV_ACK_INVALID_APID_STRING;
case (13614):
return SUPV_EXE_INVALID_APID_STRING;
case (13615):
return ACK_RECEPTION_FAILURE_STRING;
case (13616):
return EXE_RECEPTION_FAILURE_STRING;
default:
return "UNKNOWN_EVENT";
}

View File

@ -2,7 +2,7 @@
* @brief Auto-generated object translation file.
* @details
* Contains 116 translations.
* Generated on: 2022-04-16 17:47:17
* Generated on: 2022-04-18 16:58:07
*/
#include "translateObjects.h"