better thread and startup handling

This commit is contained in:
Robin Müller 2023-11-21 14:17:19 +01:00
parent 8c51f53a26
commit a648b4be37
2 changed files with 27 additions and 10 deletions

View File

@ -82,17 +82,13 @@ void StarTrackerHandler::doStartUp() {
// the device handler's submode to the star tracker's mode
return;
case StartupState::DONE:
if (jcfgCountdown.isBusy()) {
if (!JCFG_DONE) {
startupState = StartupState::WAIT_JCFG;
return;
}
startupState = StartupState::IDLE;
break;
case StartupState::WAIT_JCFG: {
if (jcfgCountdown.hasTimedOut()) {
startupState = StartupState::IDLE;
break;
}
return;
}
default:
@ -172,6 +168,7 @@ bool StarTrackerHandler::reloadJsonCfgFile() {
jcfgCountdown.resetTimer();
auto strCfgPath = cfgPathGetter.getCfgPath();
if (strCfgPath.has_value()) {
jcfgPending = true;
jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()};
return true;
}
@ -199,13 +196,14 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
return EXECUTION_FINISHED;
}
case (startracker::RELOAD_JSON_CFG_FILE): {
if (jcfgPending) {
return HasActionsIF::IS_BUSY;
}
// It should be noted that this just reloads the JSON config structure in memory from the
// JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve
// this is to simply reboot the device after a reload.
if (reloadJsonCfgFile()) {
return HasActionsIF::EXECUTION_FINISHED;
}
return returnvalue::FAILED;
reloadJsonCfgFile();
return returnvalue::OK;
}
case (startracker::RESET_SECONDARY_TM_SET): {
resetSecondaryTmSet();
@ -355,6 +353,24 @@ void StarTrackerHandler::performOperationHook() {
break;
}
}
if (jcfgPending) {
if (JCFG_DONE) {
auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE);
if (iter != deviceCommandMap.end()) {
if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) {
actionHelper.finish(true, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE);
}
}
jsonCfgTask.join();
jcfgPending = false;
} else if (jcfgCountdown.hasTimedOut()) {
auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE);
if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) {
actionHelper.finish(false, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE,
returnvalue::FAILED);
}
}
}
}
Submode_t StarTrackerHandler::getInitialSubmode() { return startracker::SUBMODE_BOOTLOADER; }

View File

@ -240,8 +240,9 @@ class StarTrackerHandler : public DeviceHandlerBase {
Subscription subscription;
AutoThreshold autoThreshold;
};
bool jcfgPending = false;
JsonConfigs jcfgs;
Countdown jcfgCountdown = Countdown(250);
Countdown jcfgCountdown = Countdown(1000);
bool commandExecuted = false;
std::thread jsonCfgTask;
static void setUpJsonCfgs(JsonConfigs& cfgs, std::string paramJsonFile);