diff --git a/generators/.run/events.run.xml b/generators/.run/events.run.xml
index 18f71033..f495007e 100644
--- a/generators/.run/events.run.xml
+++ b/generators/.run/events.run.xml
@@ -6,9 +6,9 @@
-
+
-
+
diff --git a/generators/bsp_q7s_events.csv b/generators/bsp_q7s_events.csv
index ad90e3d5..3696424d 100644
--- a/generators/bsp_q7s_events.csv
+++ b/generators/bsp_q7s_events.csv
@@ -100,6 +100,7 @@
11207;SELF_TEST_COIL_CURRENT_FAILURE;LOW;;C:\Users\jakob\eive-software\eive_obsw/mission/devices/IMTQHandler.h
11208;INVALID_ERROR_BYTE;LOW;Received invalid error byte. This indicates an error of the communication link between IMTQ and OBC.;C:\Users\jakob\eive-software\eive_obsw/mission/devices/IMTQHandler.h
11301;ERROR_STATE;HIGH;Reaction wheel signals an error state;C:\Users\jakob\eive-software\eive_obsw/mission/devices/RwHandler.h
+11401;BOOTING_FIRMWARE_FAILED;LOW;Failed to boot firmware;C:\Users\jakob\eive-software\eive_obsw/linux/devices/startracker/StarTrackerHandler.h
11501;SUPV_MEMORY_READ_RPT_CRC_FAILURE;LOW;PLOC supervisor crc failure in telemetry packet;C:\Users\jakob\eive-software\eive_obsw/bsp_q7s/devices/PlocSupervisorHandler.h
11502;SUPV_ACK_FAILURE;LOW;PLOC supervisor received acknowledgment failure report;C:\Users\jakob\eive-software\eive_obsw/bsp_q7s/devices/PlocSupervisorHandler.h
11503;SUPV_EXE_FAILURE;LOW;PLOC received execution failure report;C:\Users\jakob\eive-software\eive_obsw/bsp_q7s/devices/PlocSupervisorHandler.h
diff --git a/generators/events/translateEvents.cpp b/generators/events/translateEvents.cpp
index 117e264f..dc72a0f6 100644
--- a/generators/events/translateEvents.cpp
+++ b/generators/events/translateEvents.cpp
@@ -1,7 +1,7 @@
/**
- * @brief Auto-generated event translation file. Contains 137 translations.
+ * @brief Auto-generated event translation file. Contains 138 translations.
* @details
- * Generated on: 2022-02-13 15:31:27
+ * Generated on: 2022-02-22 09:46:40
*/
#include "translateEvents.h"
@@ -107,6 +107,7 @@ const char *SELF_TEST_MTM_RANGE_FAILURE_STRING = "SELF_TEST_MTM_RANGE_FAILURE";
const char *SELF_TEST_COIL_CURRENT_FAILURE_STRING = "SELF_TEST_COIL_CURRENT_FAILURE";
const char *INVALID_ERROR_BYTE_STRING = "INVALID_ERROR_BYTE";
const char *ERROR_STATE_STRING = "ERROR_STATE";
+const char *BOOTING_FIRMWARE_FAILED_STRING = "BOOTING_FIRMWARE_FAILED";
const char *SUPV_MEMORY_READ_RPT_CRC_FAILURE_STRING = "SUPV_MEMORY_READ_RPT_CRC_FAILURE";
const char *SUPV_ACK_FAILURE_STRING = "SUPV_ACK_FAILURE";
const char *SUPV_EXE_FAILURE_STRING = "SUPV_EXE_FAILURE";
@@ -349,6 +350,8 @@ const char * translateEvents(Event event) {
return INVALID_ERROR_BYTE_STRING;
case(11301):
return ERROR_STATE_STRING;
+ case(11401):
+ return BOOTING_FIRMWARE_FAILED_STRING;
case(11501):
return SUPV_MEMORY_READ_RPT_CRC_FAILURE_STRING;
case(11502):
diff --git a/generators/objects/translateObjects.cpp b/generators/objects/translateObjects.cpp
index 2400e1d8..465be750 100644
--- a/generators/objects/translateObjects.cpp
+++ b/generators/objects/translateObjects.cpp
@@ -2,7 +2,7 @@
* @brief Auto-generated object translation file.
* @details
* Contains 111 translations.
- * Generated on: 2022-02-13 15:31:32
+ * Generated on: 2022-02-23 11:11:47
*/
#include "translateObjects.h"
diff --git a/linux/devices/startracker/StarTrackerHandler.cpp b/linux/devices/startracker/StarTrackerHandler.cpp
index caf9ebdc..9a09dc0a 100644
--- a/linux/devices/startracker/StarTrackerHandler.cpp
+++ b/linux/devices/startracker/StarTrackerHandler.cpp
@@ -233,20 +233,14 @@ void StarTrackerHandler::performOperationHook() {
void StarTrackerHandler::doStartUp() {
switch (startupState) {
case StartupState::IDLE:
- startupState = StartupState::CHECK_BOOT_STATE;
+ startupState = StartupState::CHECK_PROGRAM;
return;
- case StartupState::BOOT_DELAY:
- if (bootCountdown.hasTimedOut()) {
- startupState = StartupState::VERIFY_BOOT;
- }
- return;
- case StartupState::FAILED_FIRMWARE_BOOT:
- startupState = StartupState::IDLE;
- // Though the star tracker failed to boot the firmware the device handler will go to
- // mode on. In bootloader mode the star tracker is still on and can e.g. perform firmware
- // updates.
- break;
+ 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:
+ submode = SUBMODE_BOOTLOADER;
startupState = StartupState::IDLE;
break;
default:
@@ -258,26 +252,18 @@ void StarTrackerHandler::doStartUp() {
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;
setMode(_MODE_POWER_DOWN);
}
-void StarTrackerHandler::doOffActivity() { startupState = StartupState::IDLE; }
+void StarTrackerHandler::doOffActivity() { internalState = InternalState::IDLE; }
ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
- if (!bootCountdown.hasTimedOut()) {
- return NOTHING_TO_SEND;
- }
- switch (internalState) {
- case InternalState::CHECK_PROGRAM:
- *id = startracker::REQ_VERSION;
- break;
- case InternalState::TEMPERATURE_REQUEST:
+ switch (normalState) {
+ case NormalState::TEMPERATURE_REQUEST:
*id = startracker::REQ_TEMPERATURE;
break;
default:
- sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid internal step"
+ sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid normal step"
<< std::endl;
break;
}
@@ -285,94 +271,103 @@ ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id
}
ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
- if (mode == _MODE_TO_NORMAL && currentProgram != startracker::Program::FIRMWARE) {
- internalState = InternalState::CHECK_PROGRAM;
- *id = startracker::BOOT;
- bootCountdown.setTimeout(BOOT_TIMEOUT);
- return buildCommandFromCommand(*id, nullptr, 0);
- } else if (mode != _MODE_START_UP) {
- return NOTHING_TO_SEND;
- }
- switch (startupState) {
- case StartupState::CHECK_BOOT_STATE:
- *id = startracker::REQ_VERSION;
- startupState = StartupState::STARTUP_CHECK;
- return buildCommandFromCommand(*id, nullptr, 0);
- case StartupState::BOOT:
+ switch (internalState) {
+ case InternalState::BOOT:
*id = startracker::BOOT;
bootCountdown.setTimeout(BOOT_TIMEOUT);
- startupState = StartupState::BOOT_DELAY;
+ internalState = InternalState::BOOT_DELAY;
return buildCommandFromCommand(*id, nullptr, 0);
- case StartupState::VERIFY_BOOT:
+ case InternalState::REQ_VERSION:
+ internalState = InternalState::VERIFY_BOOT;
// Again read program to check if firmware boot was successful
*id = startracker::REQ_VERSION;
- startupState = StartupState::FIRMWARE_CHECK;
return buildCommandFromCommand(*id, nullptr, 0);
- case StartupState::LOGLEVEL:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::LOGLEVEL:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LOGLEVEL;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::LIMITS:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::LIMITS:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LIMITS;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::TRACKING:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::TRACKING:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::TRACKING;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::MOUNTING:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::MOUNTING:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::MOUNTING;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::IMAGE_PROCESSOR:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::IMAGE_PROCESSOR:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::IMAGE_PROCESSOR;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::CAMERA:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::CAMERA:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::CAMERA;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::CENTROIDING:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::CENTROIDING:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::CENTROIDING;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::LISA:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::LISA:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LISA;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::MATCHING:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::MATCHING:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::MATCHING;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::VALIDATION:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::VALIDATION:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::VALIDATION;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::ALGO:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::ALGO:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::ALGO;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::LOG_SUBSCRIPTION:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::LOG_SUBSCRIPTION:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LOGSUBSCRIPTION;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
- case StartupState::DEBUG_CAMERA:
- startupState = StartupState::WAIT_FOR_EXECUTION;
+ case InternalState::DEBUG_CAMERA:
+ internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::DEBUG_CAMERA;
return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()),
paramJsonFile.size());
+ case InternalState::BOOT_BOOTLOADER:
+ internalState = InternalState::BOOTLOADER_CHECK;
+ *id = startracker::SWITCH_TO_BOOTLOADER_PROGRAM;
+ return buildCommandFromCommand(*id, nullptr, 0);
+ case InternalState::BOOTLOADER_CHECK:
+ *id = startracker::REQ_VERSION;
+ return buildCommandFromCommand(*id, nullptr, 0);
+ default:
+ break;
+ }
+ switch (startupState) {
+ case StartupState::CHECK_PROGRAM:
+ startupState = StartupState::WAIT_CHECK_PROGRAM;
+ *id = startracker::REQ_VERSION;
+ return buildCommandFromCommand(*id, nullptr, 0);
+ break;
+ case StartupState::BOOT_BOOTLOADER:
+ startupState = StartupState::CHECK_PROGRAM;
+ *id = startracker::SWITCH_TO_BOOTLOADER_PROGRAM;
+ return buildCommandFromCommand(*id, nullptr, 0);
+ break;
default:
break;
}
@@ -409,7 +404,6 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi
return RETURN_OK;
}
case (startracker::SWITCH_TO_BOOTLOADER_PROGRAM): {
- currentProgram = startracker::Program::BOOTLOADER;
prepareRebootCommand();
return RETURN_OK;
}
@@ -727,7 +721,7 @@ ReturnValue_t StarTrackerHandler::isModeCombinationValid(Mode_t mode, Submode_t
return INVALID_SUBMODE;
}
case MODE_ON:
- if (submode == SUBMODE_BOOTLOADER || submode == SUBMODE_FIRMWARE || submode == SUBMODE_NONE) {
+ if (submode == SUBMODE_BOOTLOADER || submode == SUBMODE_FIRMWARE) {
return RETURN_OK;
} else {
return INVALID_SUBMODE;
@@ -737,6 +731,86 @@ ReturnValue_t StarTrackerHandler::isModeCombinationValid(Mode_t mode, Submode_t
}
}
+void StarTrackerHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
+ switch (mode) {
+ case _MODE_TO_ON:
+ doOnTransition(subModeFrom);
+ break;
+ case _MODE_TO_RAW:
+ setMode(MODE_RAW);
+ break;
+ case _MODE_TO_NORMAL:
+ doNormalTransition(modeFrom, subModeFrom);
+ break;
+ case _MODE_POWER_DOWN:
+ internalState = InternalState::IDLE;
+ startupState = StartupState::IDLE;
+ break;
+ default:
+ break;
+ }
+}
+
+void StarTrackerHandler::doOnTransition(Submode_t subModeFrom) {
+ if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_FIRMWARE) {
+ bootBootloader();
+ } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_FIRMWARE) {
+ setMode(MODE_ON);
+ } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_BOOTLOADER) {
+ bootFirmware(MODE_ON);
+ } else if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_BOOTLOADER) {
+ setMode(MODE_ON);
+ } else if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_NONE) {
+ setMode(MODE_ON);
+ } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_NONE) {
+ setMode(MODE_ON);
+ }
+}
+
+void StarTrackerHandler::doNormalTransition(Mode_t modeFrom, Submode_t subModeFrom) {
+ if (subModeFrom == SUBMODE_FIRMWARE) {
+ setMode(MODE_NORMAL);
+ } else if (subModeFrom == SUBMODE_BOOTLOADER) {
+ bootFirmware(MODE_NORMAL);
+ } else if (modeFrom == MODE_NORMAL && subModeFrom == SUBMODE_NONE){
+ // Device handler already in mode normal
+ setMode(MODE_NORMAL);
+ }
+}
+
+void StarTrackerHandler::bootFirmware(Mode_t toMode) {
+ switch (internalState) {
+ case InternalState::IDLE:
+ internalState = InternalState::BOOT;
+ break;
+ case InternalState::BOOT_DELAY:
+ if (bootCountdown.hasTimedOut()) {
+ internalState = InternalState::REQ_VERSION;
+ }
+ break;
+ case InternalState::FAILED_FIRMWARE_BOOT:
+ internalState = InternalState::IDLE;
+ break;
+ case InternalState::DONE:
+ setMode(toMode);
+ internalState = InternalState::IDLE;
+ break;
+ default:
+ return;
+ }
+}
+
+void StarTrackerHandler::bootBootloader() {
+ if (internalState == InternalState::IDLE) {
+ internalState = InternalState::BOOT_BOOTLOADER;
+ } else if (internalState == InternalState::BOOTING_BOOTLOADER_FAILED) {
+ internalState = InternalState::IDLE;
+ } else if (internalState == InternalState::DONE) {
+ internalState = InternalState::IDLE;
+ setMode(MODE_ON);
+ }
+}
+
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = RETURN_OK;
@@ -955,7 +1029,14 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
void StarTrackerHandler::setNormalDatapoolEntriesInvalid() {}
-uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 20000; }
+uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
+// if (modeTo == MODE_ON && (submode == SUBMODE_NONE || submode == SUBMODE_BOOTLOADER)) {
+// return BOOTLOADER_TRANSITION_DELAY;
+// } else if (modeTo == MODE_ON && submode == SUBMODE_FIRMWARE && modeFrom == MODE_) {
+// return FIRMWARE_TRANSITION_DELAY;
+// }
+ return DEFAULT_TRANSITION_DELAY;
+}
ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
@@ -2161,12 +2242,12 @@ ReturnValue_t StarTrackerHandler::handleSetParamReply() {
sif::warning << "StarTrackerHandler::handleSetParamReply: Failed to execute parameter set "
" command with parameter ID"
<< static_cast(*(reply + PARAMETER_ID_OFFSET)) << std::endl;
- if (startupState != StartupState::IDLE) {
- startupState = StartupState::IDLE;
+ if (internalState != InternalState::IDLE) {
+ internalState = InternalState::IDLE;
}
return SET_PARAM_FAILED;
}
- if (startupState != StartupState::IDLE) {
+ if (internalState != InternalState::IDLE) {
handleStartup(reply + PARAMETER_ID_OFFSET);
}
return RETURN_OK;
@@ -2293,30 +2374,27 @@ ReturnValue_t StarTrackerHandler::checkProgram() {
PoolReadGuard pg(&versionSet);
switch (versionSet.program.value) {
case startracker::Program::BOOTLOADER:
- // Star tracker currently in bootloader program. Need to send boot command to switch to
- // firmware program
- currentProgram = startracker::Program::BOOTLOADER;
- if (startupState == StartupState::STARTUP_CHECK) {
- startupState = StartupState::BOOT;
- } else if (startupState == StartupState::FIRMWARE_CHECK) {
- startupState = StartupState::FAILED_FIRMWARE_BOOT;
+ if (startupState == StartupState::WAIT_CHECK_PROGRAM) {
+ startupState = StartupState::DONE;
}
- if (internalState == InternalState::CHECK_PROGRAM) {
- // Firmware boot failed when trying to switch to normal mode
- internalState = InternalState::IDLE;
- sif::warning << "StarTrackerHandler::checkProgram: Failed to boot firmware when "
- << "trying to switch to normal mode" << std::endl;
- setMode(_MODE_TO_ON);
+ if (internalState == InternalState::VERIFY_BOOT) {
+ sif::warning << "StarTrackerHandler::checkProgram: Failed to boot firmware" << std::endl;
+ // Device handler will run into timeout and fall back to transition source mode
+ triggerEvent(BOOTING_FIRMWARE_FAILED);
+ internalState = InternalState::FAILED_FIRMWARE_BOOT;
+ } else if (internalState == InternalState::BOOTLOADER_CHECK) {
+ internalState = InternalState::DONE;
}
break;
case startracker::Program::FIRMWARE:
- // Firmware already booted
- currentProgram = startracker::Program::FIRMWARE;
- if (startupState == StartupState::FIRMWARE_CHECK) {
- startupState = StartupState::LOGLEVEL;
+ if (startupState == StartupState::WAIT_CHECK_PROGRAM) {
+ startupState = StartupState::BOOT_BOOTLOADER;
}
- if (internalState == InternalState::CHECK_PROGRAM) {
- internalState = InternalState::TEMPERATURE_REQUEST;
+ if (internalState == InternalState::VERIFY_BOOT) {
+ internalState = InternalState::LOGLEVEL;
+ } else if (internalState == InternalState::BOOTLOADER_CHECK) {
+ triggerEvent(BOOTING_BOOTLOADER_FAILED);
+ internalState = InternalState::BOOTING_BOOTLOADER_FAILED;
}
break;
default:
@@ -2390,55 +2468,55 @@ ReturnValue_t StarTrackerHandler::handleActionReplySet(LocalPoolDataSetBase& dat
void StarTrackerHandler::handleStartup(const uint8_t* parameterId) {
switch (*parameterId) {
case (startracker::ID::LOG_LEVEL): {
- startupState = StartupState::LIMITS;
+ internalState = InternalState::LIMITS;
break;
}
case (startracker::ID::LIMITS): {
- startupState = StartupState::TRACKING;
+ internalState = InternalState::TRACKING;
break;
}
case (startracker::ID::TRACKING): {
- startupState = StartupState::MOUNTING;
+ internalState = InternalState::MOUNTING;
break;
}
case (startracker::ID::MOUNTING): {
- startupState = StartupState::IMAGE_PROCESSOR;
+ internalState = InternalState::IMAGE_PROCESSOR;
break;
}
case (startracker::ID::IMAGE_PROCESSOR): {
- startupState = StartupState::CAMERA;
+ internalState = InternalState::CAMERA;
break;
}
case (startracker::ID::CAMERA): {
- startupState = StartupState::CENTROIDING;
+ internalState = InternalState::CENTROIDING;
break;
}
case (startracker::ID::CENTROIDING): {
- startupState = StartupState::LISA;
+ internalState = InternalState::LISA;
break;
}
case (startracker::ID::LISA): {
- startupState = StartupState::MATCHING;
+ internalState = InternalState::MATCHING;
break;
}
case (startracker::ID::MATCHING): {
- startupState = StartupState::VALIDATION;
+ internalState = InternalState::VALIDATION;
break;
}
case (startracker::ID::VALIDATION): {
- startupState = StartupState::ALGO;
+ internalState = InternalState::ALGO;
break;
}
case (startracker::ID::ALGO): {
- startupState = StartupState::LOG_SUBSCRIPTION;
+ internalState = InternalState::LOG_SUBSCRIPTION;
break;
}
case (startracker::ID::LOG_SUBSCRIPTION): {
- startupState = StartupState::DEBUG_CAMERA;
+ internalState = InternalState::DEBUG_CAMERA;
break;
}
case (startracker::ID::DEBUG_CAMERA): {
- startupState = StartupState::DONE;
+ internalState = InternalState::DONE;
break;
}
default: {
@@ -2451,11 +2529,6 @@ void StarTrackerHandler::handleStartup(const uint8_t* parameterId) {
ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) {
switch (actionId) {
- case startracker::BOOT:
- if (currentProgram != startracker::Program::BOOTLOADER) {
- return STARTRACKER_ALREADY_BOOTED;
- }
- break;
case startracker::REQ_INTERFACE:
case startracker::REQ_TIME:
case startracker::SWITCH_TO_BOOTLOADER_PROGRAM:
@@ -2472,12 +2545,12 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) {
case startracker::DOWNLOAD_MATCHED_STAR:
case startracker::DOWNLOAD_DBIMAGE:
case startracker::DOWNLOAD_BLOBPIXEL:
- if (currentProgram != startracker::Program::FIRMWARE) {
+ if (!(mode == MODE_ON && submode == startracker::Program::FIRMWARE)) {
return STARTRACKER_RUNNING_BOOTLOADER;
}
break;
case startracker::FIRMWARE_UPDATE:
- if (currentProgram != startracker::Program::BOOTLOADER) {
+ if (!(mode == MODE_ON && submode == startracker::Program::BOOTLOADER)) {
return STARTRACKER_RUNNING_FIRMWARE;
}
break;
diff --git a/linux/devices/startracker/StarTrackerHandler.h b/linux/devices/startracker/StarTrackerHandler.h
index 691237a4..91d4d9dd 100644
--- a/linux/devices/startracker/StarTrackerHandler.h
+++ b/linux/devices/startracker/StarTrackerHandler.h
@@ -73,6 +73,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
*/
virtual size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
virtual ReturnValue_t doSendReadHook() override;
+ virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HANDLER;
@@ -142,6 +143,13 @@ class StarTrackerHandler : public DeviceHandlerBase {
//! [EXPORT] : [COMMENT] Star tracker is in bootloader mode but must be in firmware mode to execute this command
static const ReturnValue_t STARTRACKER_RUNNING_BOOTLOADER = MAKE_RETURN_CODE(0xBD);
+ static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HANDLER;
+
+ //! [EXPORT] : [COMMENT] Failed to boot firmware
+ static const Event BOOTING_FIRMWARE_FAILED = MAKE_EVENT(1, severity::LOW);
+ //! [EXPORT] : [COMMENT] Failed to boot star tracker into bootloader mode
+ static const Event BOOTING_BOOTLOADER_FAILED = MAKE_EVENT(2, severity::LOW);
+
static const size_t MAX_PATH_SIZE = 50;
static const size_t MAX_FILE_NAME = 30;
@@ -163,6 +171,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
static const MutexIF::TimeoutType TIMEOUT_TYPE = MutexIF::TimeoutType::WAITING;
static const uint32_t MUTEX_TIMEOUT = 20;
static const uint32_t BOOT_TIMEOUT = 1000;
+ static const uint32_t DEFAULT_TRANSITION_DELAY = 15000;
class WriteCmd {
public:
@@ -303,18 +312,16 @@ class StarTrackerHandler : public DeviceHandlerBase {
#endif
#endif
- enum class InternalState {
- IDLE,
- CHECK_PROGRAM,
- TEMPERATURE_REQUEST,
+ enum class NormalState {
+ TEMPERATURE_REQUEST
};
- InternalState internalState = InternalState::IDLE;
+ NormalState normalState = NormalState::TEMPERATURE_REQUEST;
- enum class StartupState {
+ enum class InternalState {
IDLE,
- CHECK_BOOT_STATE,
BOOT,
+ REQ_VERSION,
VERIFY_BOOT,
STARTUP_CHECK,
BOOT_DELAY,
@@ -335,15 +342,26 @@ class StarTrackerHandler : public DeviceHandlerBase {
DEBUG_CAMERA,
WAIT_FOR_EXECUTION,
DONE,
- FAILED_FIRMWARE_BOOT
+ FAILED_FIRMWARE_BOOT,
+ BOOT_BOOTLOADER,
+ BOOTLOADER_CHECK,
+ BOOTING_BOOTLOADER_FAILED
+ };
+
+ InternalState internalState = InternalState::IDLE;
+
+ enum class StartupState {
+ IDLE,
+ CHECK_PROGRAM,
+ WAIT_CHECK_PROGRAM,
+ BOOT_BOOTLOADER,
+ DONE
};
StartupState startupState = StartupState::IDLE;
bool strHelperExecuting = false;
- uint8_t currentProgram = startracker::Program::BOOTLOADER;
-
/**
* @brief Handles internal state
*/
@@ -598,6 +616,11 @@ class StarTrackerHandler : public DeviceHandlerBase {
* @return RETURN_OK if star tracker is in valid mode, otherwise error return value
*/
ReturnValue_t checkCommand(ActionId_t actionId);
+
+ void doOnTransition(Submode_t subModeFrom);
+ void doNormalTransition(Mode_t modeFrom, Submode_t subModeFrom);
+ void bootFirmware(Mode_t toMode);
+ void bootBootloader();
};
#endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */
diff --git a/linux/devices/startracker/StrHelper.cpp b/linux/devices/startracker/StrHelper.cpp
index f2f89a31..d3741fb9 100644
--- a/linux/devices/startracker/StrHelper.cpp
+++ b/linux/devices/startracker/StrHelper.cpp
@@ -1,10 +1,11 @@
#include "StrHelper.h"
-#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
#include
#include
#include "OBSWConfig.h"
+#include "fsfw/timemanager/Countdown.h"
+#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
#include "mission/utility/Timestamp.h"
StrHelper::StrHelper(object_id_t objectId) : SystemObject(objectId) {}
@@ -184,7 +185,7 @@ ReturnValue_t StrHelper::performImageDownload() {
downloadReq.position = 0;
while (downloadReq.position < ImageDownload::LAST_POSITION) {
if (terminate) {
- file.close();
+ file.close();
return RETURN_OK;
}
arc_pack_download_action_req(&downloadReq, commandBuffer, &size);
@@ -249,7 +250,7 @@ ReturnValue_t StrHelper::performImageUpload() {
imageSize = file.tellg();
while ((uploadReq.position + 1) * SIZE_IMAGE_PART < imageSize) {
if (terminate) {
- file.close();
+ file.close();
return RETURN_OK;
}
file.seekg(uploadReq.position * SIZE_IMAGE_PART, file.beg);
@@ -257,12 +258,12 @@ ReturnValue_t StrHelper::performImageUpload() {
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
result = sendAndRead(size, uploadReq.position);
if (result != RETURN_OK) {
- file.close();
+ file.close();
return RETURN_FAILED;
}
result = checkActionReply();
if (result != RETURN_OK) {
- file.close();
+ file.close();
return result;
}
#if OBSW_DEBUG_STARTRACKER == 1
@@ -292,15 +293,15 @@ ReturnValue_t StrHelper::performImageUpload() {
}
ReturnValue_t StrHelper::performFirmwareUpdate() {
- using namespace startracker;
- ReturnValue_t result = RETURN_OK;
- result = unlockAndEraseRegions(static_cast(startracker::FirmwareRegions::FIRST),
- static_cast(startracker::FirmwareRegions::LAST));
- if (result != RETURN_OK) {
- return result;
- }
- result = performFlashWrite();
+ using namespace startracker;
+ ReturnValue_t result = RETURN_OK;
+ result = unlockAndEraseRegions(static_cast(startracker::FirmwareRegions::FIRST),
+ static_cast(startracker::FirmwareRegions::LAST));
+ if (result != RETURN_OK) {
return result;
+ }
+ result = performFlashWrite();
+ return result;
}
ReturnValue_t StrHelper::performFlashWrite() {
@@ -318,8 +319,8 @@ ReturnValue_t StrHelper::performFlashWrite() {
file.seekg(0, file.end);
fileSize = file.tellg();
if (fileSize > FLASH_REGION_SIZE * (flashWrite.lastRegion - flashWrite.firstRegion)) {
- sif::warning << "StrHelper::performFlashWrite: Invalid file" << std::endl;
- return RETURN_FAILED;
+ sif::warning << "StrHelper::performFlashWrite: Invalid file" << std::endl;
+ return RETURN_FAILED;
}
uint32_t fileChunks = fileSize / CHUNK_SIZE;
bytesWritten = 0;
@@ -327,36 +328,36 @@ ReturnValue_t StrHelper::performFlashWrite() {
req.length = CHUNK_SIZE;
for (uint32_t idx = 0; idx < fileChunks; idx++) {
if (terminate) {
- file.close();
+ file.close();
return RETURN_OK;
}
file.seekg(idx * CHUNK_SIZE, file.beg);
file.read(reinterpret_cast(req.data), CHUNK_SIZE);
if (bytesWritten + CHUNK_SIZE > FLASH_REGION_SIZE) {
- req.region++;
- bytesWritten = 0;
+ req.region++;
+ bytesWritten = 0;
}
req.address = bytesWritten;
arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address);
if (result != RETURN_OK) {
- file.close();
+ file.close();
return result;
}
- result = checkFlashActionReply(req.region, req.address, req.length);
+ result = checkActionReply();
if (result != RETURN_OK) {
- file.close();
+ file.close();
return result;
}
bytesWritten += CHUNK_SIZE;
}
uint32_t remainingBytes = fileSize - fileChunks * CHUNK_SIZE;
- file.seekg((fileChunks - 1) * CHUNK_SIZE , file.beg);
+ file.seekg((fileChunks - 1) * CHUNK_SIZE, file.beg);
file.read(reinterpret_cast(req.data), remainingBytes);
file.close();
if (bytesWritten + CHUNK_SIZE > FLASH_REGION_SIZE) {
- req.region++;
- bytesWritten = 0;
+ req.region++;
+ bytesWritten = 0;
}
req.address = bytesWritten;
req.length = remainingBytes;
@@ -365,7 +366,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
if (result != RETURN_OK) {
return result;
}
- result = checkFlashActionReply(req.region, req.address, req.length);
+ result = checkActionReply();
if (result != RETURN_OK) {
return result;
}
@@ -416,7 +417,7 @@ ReturnValue_t StrHelper::performFlashRead() {
file.close();
return result;
}
- result = checkFlashActionReply(req.region, req.address, req.length);
+ result = checkActionReply();
if (result != RETURN_OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie);
@@ -435,7 +436,7 @@ ReturnValue_t StrHelper::performFlashRead() {
return RETURN_OK;
}
-ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) {
+ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter, uint32_t delayMs) {
ReturnValue_t result = RETURN_OK;
ReturnValue_t decResult = RETURN_OK;
size_t receivedDataLen = 0;
@@ -452,6 +453,10 @@ ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) {
}
decResult = ArcsecDatalinkLayer::DEC_IN_PROGRESS;
while (decResult == ArcsecDatalinkLayer::DEC_IN_PROGRESS) {
+ Countdown delay(delayMs);
+ delay.resetTimer();
+ while (delay.isBusy()) {
+ }
result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2);
if (result != RETURN_OK) {
sif::warning << "StrHelper::sendAndRead: Failed to request reply" << std::endl;
@@ -513,46 +518,6 @@ ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) {
return RETURN_OK;
}
-ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address_,
- uint16_t length_) {
- ReturnValue_t result = RETURN_OK;
- result = checkActionReply();
- if (result != RETURN_OK) {
- return result;
- }
- const uint8_t* data = datalinkLayer.getReply();
- uint8_t region = *(data + REGION_OFFSET);
- uint32_t address;
- const uint8_t* addressData = data + ADDRESS_OFFSET;
- size_t size = sizeof(address);
- result =
- SerializeAdapter::deSerialize(&address, &addressData, &size, SerializeIF::Endianness::LITTLE);
- if (result != RETURN_OK) {
- sif::warning << "StrHelper::checkFlashActionReply: Deserialization of address failed"
- << std::endl;
- return result;
- }
- uint16_t length = 0;
- size = sizeof(length);
- const uint8_t* lengthData = data + LENGTH_OFFSET;
- result =
- SerializeAdapter::deSerialize(&length, lengthData, &size, SerializeIF::Endianness::LITTLE);
- if (result != RETURN_OK) {
- sif::warning << "StrHelper::checkFlashActionReply: Deserialization of length failed"
- << std::endl;
- }
- if (region != region_) {
- return REGION_MISMATCH;
- }
- if (address != address_) {
- return ADDRESS_MISMATCH;
- }
- if (length != length_) {
- return LENGTH_MISMATCH;
- }
- return RETURN_OK;
-}
-
#ifdef XIPHOS_Q7S
ReturnValue_t StrHelper::checkPath(std::string name) {
if (name.substr(0, sizeof(SdCardManager::SD_0_MOUNT_POINT)) ==
@@ -585,29 +550,29 @@ void StrHelper::printProgress(uint32_t itemsTransferred, uint32_t fullNumItems)
}
ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
- ReturnValue_t result = RETURN_OK;
- struct UnlockActionRequest unlockReq;
- struct EraseActionRequest eraseReq;
- uint32_t size = 0;
- for (uint8_t idx = from; idx <= to; idx++) {
- unlockReq.region = idx;
- unlockReq.code = startracker::region_secrets::secret[idx];
- arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
- sendAndRead(size, unlockReq.region);
- result = checkActionReply();
- if (result != RETURN_OK) {
- sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
- << static_cast(unlockReq.region) << std::endl;
- return result;
- }
- eraseReq.region = idx;
- arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
- result = sendAndRead(size, eraseReq.region);
- if (result != RETURN_OK) {
- sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
- << static_cast(eraseReq.region) << std::endl;
- return result;
- }
+ ReturnValue_t result = RETURN_OK;
+ struct UnlockActionRequest unlockReq;
+ struct EraseActionRequest eraseReq;
+ uint32_t size = 0;
+ for (uint8_t idx = from; idx <= to; idx++) {
+ unlockReq.region = idx;
+ unlockReq.code = startracker::region_secrets::secret[idx];
+ arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
+ sendAndRead(size, unlockReq.region);
+ result = checkActionReply();
+ if (result != RETURN_OK) {
+ sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
+ << static_cast(unlockReq.region) << std::endl;
+ return result;
}
- return result;
+ eraseReq.region = idx;
+ arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
+ result = sendAndRead(size, eraseReq.region, FLASH_ERASE_DELAY);
+ if (result != RETURN_OK) {
+ sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
+ << static_cast(eraseReq.region) << std::endl;
+ return result;
+ }
+ }
+ return result;
}
diff --git a/linux/devices/startracker/StrHelper.h b/linux/devices/startracker/StrHelper.h
index e65ce782..6533eab9 100644
--- a/linux/devices/startracker/StrHelper.h
+++ b/linux/devices/startracker/StrHelper.h
@@ -181,7 +181,8 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
static const uint8_t ADDRESS_OFFSET = 3;
static const uint8_t LENGTH_OFFSET = 7;
static const size_t CHUNK_SIZE = 1024;
- static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 3;
+ static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 2000;
+ static const uint32_t FLASH_ERASE_DELAY = 500;
enum class InternalState {
IDLE,
@@ -307,10 +308,11 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
*
* @param size Size of data beforehand written to the commandBuffer
* @param parameter Parameter 2 of trigger event function
+ * @param delayMs Delay in milliseconds between send and receive call
*
* @return RETURN_OK if successful, otherwise RETURN_FAILED
*/
- ReturnValue_t sendAndRead(size_t size, uint32_t parameter);
+ ReturnValue_t sendAndRead(size_t size, uint32_t parameter, uint32_t delayMs = 0);
/**
* @brief Checks the header (type id and status fields) of the action reply
@@ -328,14 +330,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
*/
ReturnValue_t checkReplyPosition(uint32_t expectedPosition);
- /**
- * @brief Checks the region, address and length value of a flash write or read reply.
- *
- * @return RETURN_OK if values match expected values, otherwise appropriate error return
- * value.
- */
- ReturnValue_t checkFlashActionReply(uint8_t region_, uint32_t address_, uint16_t length_);
-
#ifdef XIPHOS_Q7S
/**
* @brief Checks if a path points to an sd card and whether the SD card is monuted.
diff --git a/linux/fsfwconfig/events/translateEvents.cpp b/linux/fsfwconfig/events/translateEvents.cpp
index 117e264f..dc72a0f6 100644
--- a/linux/fsfwconfig/events/translateEvents.cpp
+++ b/linux/fsfwconfig/events/translateEvents.cpp
@@ -1,7 +1,7 @@
/**
- * @brief Auto-generated event translation file. Contains 137 translations.
+ * @brief Auto-generated event translation file. Contains 138 translations.
* @details
- * Generated on: 2022-02-13 15:31:27
+ * Generated on: 2022-02-22 09:46:40
*/
#include "translateEvents.h"
@@ -107,6 +107,7 @@ const char *SELF_TEST_MTM_RANGE_FAILURE_STRING = "SELF_TEST_MTM_RANGE_FAILURE";
const char *SELF_TEST_COIL_CURRENT_FAILURE_STRING = "SELF_TEST_COIL_CURRENT_FAILURE";
const char *INVALID_ERROR_BYTE_STRING = "INVALID_ERROR_BYTE";
const char *ERROR_STATE_STRING = "ERROR_STATE";
+const char *BOOTING_FIRMWARE_FAILED_STRING = "BOOTING_FIRMWARE_FAILED";
const char *SUPV_MEMORY_READ_RPT_CRC_FAILURE_STRING = "SUPV_MEMORY_READ_RPT_CRC_FAILURE";
const char *SUPV_ACK_FAILURE_STRING = "SUPV_ACK_FAILURE";
const char *SUPV_EXE_FAILURE_STRING = "SUPV_EXE_FAILURE";
@@ -349,6 +350,8 @@ const char * translateEvents(Event event) {
return INVALID_ERROR_BYTE_STRING;
case(11301):
return ERROR_STATE_STRING;
+ case(11401):
+ return BOOTING_FIRMWARE_FAILED_STRING;
case(11501):
return SUPV_MEMORY_READ_RPT_CRC_FAILURE_STRING;
case(11502):
diff --git a/linux/fsfwconfig/events/translateEvents.h b/linux/fsfwconfig/events/translateEvents.h
index 1b8a8831..bdabb21b 100644
--- a/linux/fsfwconfig/events/translateEvents.h
+++ b/linux/fsfwconfig/events/translateEvents.h
@@ -3,6 +3,6 @@
#include "fsfw/events/Event.h"
-const char* translateEvents(Event event);
+const char * translateEvents(Event event);
#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */
diff --git a/linux/fsfwconfig/objects/translateObjects.cpp b/linux/fsfwconfig/objects/translateObjects.cpp
index 2400e1d8..465be750 100644
--- a/linux/fsfwconfig/objects/translateObjects.cpp
+++ b/linux/fsfwconfig/objects/translateObjects.cpp
@@ -2,7 +2,7 @@
* @brief Auto-generated object translation file.
* @details
* Contains 111 translations.
- * Generated on: 2022-02-13 15:31:32
+ * Generated on: 2022-02-23 11:11:47
*/
#include "translateObjects.h"