fix STR bugs and improve code

- Reset reply size after returning a reply
- Reset data link layer and flush RX for regular commands and before
  performing special commands to ensure consistent start state
- Clean up DHB a bit
- Set STR dev to OFF in assembly when it is faulty.
This commit is contained in:
Robin Müller 2023-04-04 01:35:05 +02:00
parent afbab6d3f2
commit 9270165bf8
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 72 additions and 59 deletions

View File

@ -42,7 +42,6 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
while (true) { while (true) {
lock->lockMutex(); lock->lockMutex();
state = InternalState::SLEEPING; state = InternalState::SLEEPING;
datalinkLayer.reset();
lock->unlockMutex(); lock->unlockMutex();
semaphore.acquire(); semaphore.acquire();
switch (state) { switch (state) {
@ -58,6 +57,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
} }
case InternalState::UPLOAD_IMAGE: { case InternalState::UPLOAD_IMAGE: {
replyTimeout.setTimeout(200); replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performImageUpload(); result = performImageUpload();
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
triggerEvent(IMAGE_UPLOAD_SUCCESSFUL); triggerEvent(IMAGE_UPLOAD_SUCCESSFUL);
@ -68,6 +68,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
} }
case InternalState::DOWNLOAD_IMAGE: { case InternalState::DOWNLOAD_IMAGE: {
replyTimeout.setTimeout(200); replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performImageDownload(); result = performImageDownload();
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
triggerEvent(IMAGE_DOWNLOAD_SUCCESSFUL); triggerEvent(IMAGE_DOWNLOAD_SUCCESSFUL);
@ -78,6 +79,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
} }
case InternalState::FLASH_READ: { case InternalState::FLASH_READ: {
replyTimeout.setTimeout(200); replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performFlashRead(); result = performFlashRead();
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
triggerEvent(FLASH_READ_SUCCESSFUL); triggerEvent(FLASH_READ_SUCCESSFUL);
@ -88,6 +90,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
} }
case InternalState::FIRMWARE_UPDATE: { case InternalState::FIRMWARE_UPDATE: {
replyTimeout.setTimeout(200); replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performFirmwareUpdate(); result = performFirmwareUpdate();
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
triggerEvent(FIRMWARE_UPDATE_SUCCESSFUL); triggerEvent(FIRMWARE_UPDATE_SUCCESSFUL);
@ -645,7 +648,8 @@ ReturnValue_t StrComHandler::sendMessage(CookieIF* cookie, const uint8_t* sendDa
return BUSY; return BUSY;
} }
} }
serial::flushRxBuf(serialPort); // Ensure consistent state.
resetReplyHandlingState();
const uint8_t* txFrame; const uint8_t* txFrame;
size_t frameLen; size_t frameLen;
@ -697,6 +701,7 @@ ReturnValue_t StrComHandler::readReceivedMessage(CookieIF* cookie, uint8_t** buf
*buffer = const_cast<uint8_t*>(replyPtr); *buffer = const_cast<uint8_t*>(replyPtr);
*size = replyLen; *size = replyLen;
} }
replyLen = 0;
return replyResult; return replyResult;
} }
@ -781,3 +786,8 @@ ReturnValue_t StrComHandler::readOneReply(uint32_t failParameter) {
} }
} }
} }
void StrComHandler::resetReplyHandlingState() {
serial::flushRxBuf(serialPort);
datalinkLayer.reset();
}

View File

@ -374,6 +374,8 @@ class StrComHandler : public SystemObject, public DeviceCommunicationIF, public
* @return * @return
*/ */
ReturnValue_t readOneReply(uint32_t failParameter); ReturnValue_t readOneReply(uint32_t failParameter);
void resetReplyHandlingState();
}; };
#endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */ #endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */

View File

@ -56,6 +56,49 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF,
StarTrackerHandler::~StarTrackerHandler() {} StarTrackerHandler::~StarTrackerHandler() {}
void StarTrackerHandler::doStartUp() {
switch (startupState) {
case StartupState::IDLE:
startupState = StartupState::CHECK_PROGRAM;
return;
case StartupState::BOOT_BOOTLOADER:
// This step is required in case the star tracker is already in firmware mode to harmonize
// the device handler's submode to the star tracker's mode
return;
case StartupState::DONE:
if (jcfgCountdown.isBusy()) {
startupState = StartupState::WAIT_JCFG;
return;
}
startupState = StartupState::IDLE;
break;
case StartupState::WAIT_JCFG: {
if (jcfgCountdown.hasTimedOut()) {
startupState = StartupState::IDLE;
break;
}
return;
}
default:
return;
}
solutionSet.setReportingEnabled(true);
startupState = StartupState::DONE;
internalState = InternalState::IDLE;
setMode(_MODE_TO_ON);
}
void StarTrackerHandler::doShutDown() {
// If the star tracker is shutdown also stop all running processes in the image loader task
strHelper->stopProcess();
internalState = InternalState::IDLE;
startupState = StartupState::IDLE;
bootState = FwBootState::NONE;
solutionSet.setReportingEnabled(false);
reinitNextSetParam = false;
setMode(_MODE_POWER_DOWN);
}
ReturnValue_t StarTrackerHandler::initialize() { ReturnValue_t StarTrackerHandler::initialize() {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
result = DeviceHandlerBase::initialize(); result = DeviceHandlerBase::initialize();
@ -236,49 +279,6 @@ void StarTrackerHandler::performOperationHook() {
Submode_t StarTrackerHandler::getInitialSubmode() { return SUBMODE_BOOTLOADER; } Submode_t StarTrackerHandler::getInitialSubmode() { return SUBMODE_BOOTLOADER; }
void StarTrackerHandler::doStartUp() {
switch (startupState) {
case StartupState::IDLE:
startupState = StartupState::CHECK_PROGRAM;
return;
case StartupState::BOOT_BOOTLOADER:
// This step is required in case the star tracker is already in firmware mode to harmonize
// the device handler's submode to the star tracker's mode
return;
case StartupState::DONE:
if (jcfgCountdown.isBusy()) {
startupState = StartupState::WAIT_JCFG;
return;
}
startupState = StartupState::IDLE;
break;
case StartupState::WAIT_JCFG: {
if (jcfgCountdown.hasTimedOut()) {
startupState = StartupState::IDLE;
break;
}
return;
}
default:
return;
}
solutionSet.setReportingEnabled(true);
startupState = StartupState::DONE;
internalState = InternalState::IDLE;
setMode(_MODE_TO_ON);
}
void StarTrackerHandler::doShutDown() {
// If the star tracker is shutdown also stop all running processes in the image loader task
strHelper->stopProcess();
internalState = InternalState::IDLE;
startupState = StartupState::IDLE;
bootState = FwBootState::NONE;
solutionSet.setReportingEnabled(false);
reinitNextSetParam = false;
setMode(_MODE_POWER_DOWN);
}
ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
if (strHelperHandlingSpecialRequest) { if (strHelperHandlingSpecialRequest) {
return NOTHING_TO_SEND; return NOTHING_TO_SEND;
@ -831,7 +831,6 @@ void StarTrackerHandler::bootBootloader() {
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t remainingSize, ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) { DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
size_t bytesLeft = 0;
if (remainingSize == 0) { if (remainingSize == 0) {
*foundLen = remainingSize; *foundLen = remainingSize;
@ -845,24 +844,24 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t rema
switch (startracker::getReplyFrameType(start)) { switch (startracker::getReplyFrameType(start)) {
case TMTC_ACTIONREPLY: { case TMTC_ACTIONREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize;
result = scanForActionReply(startracker::getId(start), foundId); return scanForActionReply(startracker::getId(start), foundId);
break; break;
} }
case TMTC_SETPARAMREPLY: { case TMTC_SETPARAMREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize;
result = scanForSetParameterReply(startracker::getId(start), foundId); return scanForSetParameterReply(startracker::getId(start), foundId);
break; break;
} }
case TMTC_PARAMREPLY: { case TMTC_PARAMREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize;
result = scanForGetParameterReply(startracker::getId(start), foundId); return scanForGetParameterReply(startracker::getId(start), foundId);
break; break;
} }
case TMTC_TELEMETRYREPLYA: case TMTC_TELEMETRYREPLYA:
case TMTC_TELEMETRYREPLY: { case TMTC_TELEMETRYREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize;
result = scanForTmReply(startracker::getId(start), foundId); return scanForTmReply(startracker::getId(start), foundId);
break; break;
} }
default: { default: {
@ -870,9 +869,6 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t rema
result = returnvalue::FAILED; result = returnvalue::FAILED;
} }
} }
remainingSize = bytesLeft;
return result; return result;
} }

View File

@ -11,8 +11,13 @@ StrAssembly::StrAssembly(object_id_t objectId) : AssemblyBase(objectId) {
} }
ReturnValue_t StrAssembly::commandChildren(Mode_t mode, Submode_t submode) { ReturnValue_t StrAssembly::commandChildren(Mode_t mode, Submode_t submode) {
// To ensure consistent state.
commandTable[0].setMode(MODE_OFF);
commandTable[0].setSubmode(submode);
if (healthHelper.healthTable->getHealth(objects::STAR_TRACKER) != FAULTY) {
commandTable[0].setMode(mode); commandTable[0].setMode(mode);
commandTable[0].setSubmode(submode); commandTable[0].setSubmode(submode);
}
HybridIterator<ModeListEntry> iter(commandTable.begin(), commandTable.end()); HybridIterator<ModeListEntry> iter(commandTable.begin(), commandTable.end());
executeTable(iter); executeTable(iter);
return returnvalue::OK; return returnvalue::OK;

2
tmtc

@ -1 +1 @@
Subproject commit 5f87092465b3d298b9f66410d333e8069e78df95 Subproject commit 0202c93252d71e9acc420dbb357a26ea0c46b760