Skip to content

Commit 8b57df0

Browse files
CopilotMikefly123
andcommitted
Fix critical issues causing Zephyr crash
- Corrected event log function to log_ACTIVITY_LOW_TotalPowerReset() (was incorrectly reverted to log_ACTIVITY_LO_ which causes undefined behavior) - Added sanity check for power values (0-1000W range) to prevent invalid data - Emit telemetry on first call to initialize the channel - These fixes address the board freeze/crash issue Co-authored-by: Mikefly123 <[email protected]>
1 parent c8266c5 commit 8b57df0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

FprimeZephyrReference/Components/PowerMonitor/PowerMonitor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void PowerMonitor ::run_handler(FwIndexType portNum, U32 context) {
4444
void PowerMonitor ::RESET_TOTAL_POWER_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
4545
this->m_totalPower_mWh = 0.0f;
4646
this->m_lastUpdateTime_s = this->getCurrentTimeSeconds();
47-
this->log_ACTIVITY_LO_TotalPowerReset();
47+
this->log_ACTIVITY_LOW_TotalPowerReset();
4848
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
4949
}
5050

@@ -58,11 +58,18 @@ F64 PowerMonitor ::getCurrentTimeSeconds() {
5858
}
5959

6060
void PowerMonitor ::updatePower(F64 powerW) {
61+
// Guard against invalid power values
62+
if (powerW < 0.0 || powerW > 1000.0) { // Sanity check: power should be 0-1000W
63+
return;
64+
}
65+
6166
F64 now_s = this->getCurrentTimeSeconds();
6267

6368
// Initialize time on first call
6469
if (this->m_lastUpdateTime_s == 0.0) {
6570
this->m_lastUpdateTime_s = now_s;
71+
// Emit initial telemetry value
72+
this->tlmWrite_TotalPowerConsumption(this->m_totalPower_mWh);
6673
return;
6774
}
6875

0 commit comments

Comments
 (0)