Skip to content

Commit 962b3c9

Browse files
authored
Command Loss Time Does not propogate across boots (#297)
* make the writing only happen on first boot * bug fix: * no file needed * added 45 min wait * urn safe mode seuaence on safe mode boot * removed 5 hour wait * changed watchdog stop so it always otos into safe mode * watchdog boot * changed safe mode seq to be safe
1 parent 5f2ffde commit 962b3c9

File tree

7 files changed

+37
-55
lines changed

7 files changed

+37
-55
lines changed

FprimeZephyrReference/Components/AuthenticationRouter/AuthenticationRouter.cpp

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -224,62 +224,22 @@ void AuthenticationRouter ::GET_COMMAND_LOSS_DATA_cmdHandler(FwOpcodeType opCode
224224
}
225225

226226
Fw::Time AuthenticationRouter ::update_command_loss_start(bool write_to_file) {
227+
// Lock the mutex to prevent multiple threads from updating the command loss start time simultaneously
227228
Os::ScopeLock lock(this->m_commandLossMutex);
228229

229-
// Update file with current time and cache it
230230
Fw::Time current_time = this->getTime();
231231

232-
// if current time base if monotonic, we don't want to write it to file, but we still want to update the cached
233-
// time and return it this way we never write monotonic time to file, which would be invalid on reboot and if
234-
// the system is using monotonic time, we don't consistently return a previously saved workstation time to a
235-
// cube stuck on monotonic (ie broken RTC). So we don't write monotonic time to file, but cache it for use in
236-
// current session
237-
238-
if (current_time.getTimeBase() == TimeBase::TB_PROC_TIME) {
239-
if (write_to_file) {
240-
// Don't write monotonic time to file, but cache it for use in current session
241-
this->m_commandLossStartTime = current_time;
242-
return current_time;
243-
} else {
244-
// Return cached time (the time when last command arrived)
245-
return this->m_commandLossStartTime;
246-
}
247-
}
248-
249-
Fw::ParamValid is_valid;
250-
auto time_file = this->paramGet_COMM_LOSS_TIME_START_FILE(is_valid);
251-
252-
if (write_to_file) {
253-
Os::File::Status status = Utilities::FileHelper::writeToFile(time_file.toChar(), current_time);
254-
if (status != Os::File::OP_OK) {
255-
this->log_WARNING_HI_CommandLossFileInitFailure();
256-
}
232+
// If writing (command received), reset the timer to current time
233+
// On boot, m_commandLossStartTime starts at ZERO_TIME, so first command will set it
234+
// Also reset if timebase changed (can't compare times with different timebases)
235+
bool changed_time_base = this->m_commandLossStartTime.getTimeBase() != current_time.getTimeBase();
236+
if (write_to_file || this->m_commandLossStartTime == Fw::ZERO_TIME || changed_time_base) {
257237
this->m_commandLossStartTime = current_time;
258-
259238
return current_time;
260-
} else {
261-
// Check if we need to load from file (cache is zero/uninitialized or timebase mismatch with the file)
262-
// Otherwise we want to read from the cache in case the filesystem is broken
263-
// Also invalidate cache if timebase changed (e.g., system switched from monotonic to workstation time)
264-
if (this->m_commandLossStartTime == Fw::ZERO_TIME ||
265-
this->m_commandLossStartTime.getTimeBase() != current_time.getTimeBase()) {
266-
// Read stored time from file, or use current time if file doesn't exist
267-
Fw::Time time = this->getTime();
268-
Os::File::Status status = Utilities::FileHelper::readFromFile(time_file.toChar(), time);
269-
270-
// On read failure, write the current time to the file for future reads
271-
if (status != Os::File::OP_OK) {
272-
status = Utilities::FileHelper::writeToFile(time_file.toChar(), time);
273-
if (status != Os::File::OP_OK) {
274-
this->log_WARNING_HI_CommandLossFileInitFailure();
275-
}
276-
}
277-
// Cache the loaded time
278-
this->m_commandLossStartTime = time;
279-
}
280-
// Return cached time
281-
return this->m_commandLossStartTime;
282239
}
240+
241+
// If reading (checking timer), return the stored start time
242+
return this->m_commandLossStartTime;
283243
}
284244

285245
void AuthenticationRouter ::fileBufferReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {

FprimeZephyrReference/Components/ModeManager/ModeManager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ void ModeManager ::loadState() {
265265
if (this->m_mode == SystemMode::SAFE_MODE) {
266266
// Turn off non-critical components to match safe mode state
267267
this->turnOffNonCriticalComponents();
268+
// run radio safe to match default safe params
269+
this->runSafeModeSequence();
268270

269271
// Log that we're restoring safe mode (not entering it fresh)
270272
Fw::LogStringArg reasonStr("State restored from persistent storage");
@@ -311,9 +313,11 @@ void ModeManager ::loadState() {
311313
// Handle unintended reboot detection AFTER basic state restoration
312314
// This ensures we enter safe mode due to system fault
313315
if (unintendedReboot) {
314-
// On unintended reboot, re-enter safe mode and run the safe mode sequence
316+
// On unintended reboot, enter safe mode and run the safe mode sequence
317+
// (e.g., to reset radio parameters and enforce any transmit delay policy)
315318
this->log_WARNING_HI_UnintendedRebootDetected();
316319
this->enterSafeMode(Components::SafeModeReason::SYSTEM_FAULT);
320+
this->runSafeModeSequence();
317321
}
318322

319323
// Clear clean shutdown flag for next boot detection

FprimeZephyrReference/Components/ModeManager/ModeManager.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module Components {
183183
@ Debounce time for voltage transitions (seconds)
184184
param SafeModeDebounceSeconds: U32 default 10
185185

186-
param SAFEMODE_SEQUENCE_FILE: string default "/seq/radio_enter_safe.bin"
186+
param SAFEMODE_SEQUENCE_FILE: string default "/seq/enter_safe.bin"
187187

188188
###############################################################################
189189
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #

FprimeZephyrReference/Components/Watchdog/Watchdog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Watchdog ::start_handler(FwIndexType portNum) {
4747

4848
void Watchdog ::stop_handler(FwIndexType portNum) {
4949
// Stop the watchdog
50-
this->prepareForReboot_out(0);
50+
5151
this->m_run = false;
5252

5353
// Report watchdog stopped
@@ -68,8 +68,8 @@ void Watchdog ::START_WATCHDOG_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
6868

6969
void Watchdog ::STOP_WATCHDOG_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
7070
// call stop handler
71+
this->prepareForReboot_out(0);
7172
this->stop_handler(0);
72-
7373
// Provide command response
7474
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
7575
}

sequences/enter_safe.seq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Enter safe: turn off load switches
2+
R00:00:00 ReferenceDeployment.face4LoadSwitch.TURN_OFF
3+
R00:00:00 ReferenceDeployment.face0LoadSwitch.TURN_OFF
4+
R00:00:01 ReferenceDeployment.face1LoadSwitch.TURN_OFF
5+
R00:00:01 ReferenceDeployment.face2LoadSwitch.TURN_OFF
6+
R00:00:01 ReferenceDeployment.face3LoadSwitch.TURN_OFF
7+
R00:00:01 ReferenceDeployment.face5LoadSwitch.TURN_OFF
8+
R00:00:01 ReferenceDeployment.payloadPowerLoadSwitch.TURN_OFF
9+
R00:00:01 ReferenceDeployment.payloadBatteryLoadSwitch.TURN_OFF

sequences/radio_enter_safe.seq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
R05:00:00 ReferenceDeployment.lora.TRANSMIT, DISABLED
1+
R00:00:00 ReferenceDeployment.lora.TRANSMIT, DISABLED
22
R00:00:00 ReferenceDeployment.lora.DATA_RATE_PRM_SET, SF_8
33
R00:00:00 ReferenceDeployment.downlinkDelay.DIVIDER_PRM_SET, 299
44
R00:00:00 ReferenceDeployment.telemetryDelay.DIVIDER_PRM_SET, 29
55
R00:00:00 ReferenceDeployment.lora.CODING_RATE_PRM_SET, CR_4_5
66
R00:00:00 ReferenceDeployment.lora.BANDWIDTH_RX_PRM_SET, BW_125_KHZ
77
R00:00:00 ReferenceDeployment.lora.BANDWIDTH_TX_PRM_SET, BW_125_KHZ
8-
R00:00:01 ReferenceDeployment.lora.TRANSMIT, ENABLED
8+
R00:45:00 ReferenceDeployment.lora.TRANSMIT, ENABLED

sequences/startup.seq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ R00:00:00 CdhCore.events.SET_ID_FILTER, 268439553, ENABLED ; RateGroupSlip (50)
55
R00:00:00 CdhCore.events.SET_ID_FILTER, 268443649, ENABLED ; RateGroupSlip (10)
66

77
R00:45:00 ReferenceDeployment.antennaDeployer.DEPLOY
8+
R00:00:00 ReferenceDeployment.lora.TRANSMIT, DISABLED
9+
R00:00:00 ReferenceDeployment.lora.DATA_RATE_PRM_SET, SF_8
10+
R00:00:00 ReferenceDeployment.downlinkDelay.DIVIDER_PRM_SET, 299
11+
R00:00:00 ReferenceDeployment.telemetryDelay.DIVIDER_PRM_SET, 29
12+
R00:00:00 ReferenceDeployment.lora.CODING_RATE_PRM_SET, CR_4_5
13+
R00:00:00 ReferenceDeployment.lora.BANDWIDTH_RX_PRM_SET, BW_125_KHZ
14+
R00:00:00 ReferenceDeployment.lora.BANDWIDTH_TX_PRM_SET, BW_125_KHZ
15+
16+
817
R00:00:00 ReferenceDeployment.lora.TRANSMIT ENABLED
918

1019
; Exit Safe Mode should turn on faces

0 commit comments

Comments
 (0)