-
Notifications
You must be signed in to change notification settings - Fork 5
Safe <-> Normal Mode Auto Switch #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
93bac53
e027055
f8336e0
2809b15
1e8d449
b4ce7d4
62a100c
05ff516
fddb10f
a7d5508
5b0cc7e
286cd57
a44949d
0e6cfed
79b6202
f19e98e
54112b9
28a5522
ef87174
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,12 @@ class ModeManager : public ModeManagerComponentBase { | |
| Components::SystemMode getMode_handler(FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| //! Handler implementation for prepareForReboot | ||
| //! | ||
| //! Port called before intentional reboot to set clean shutdown flag | ||
| void prepareForReboot_handler(FwIndexType portNum //!< The port number | ||
| ) override; | ||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Handler implementations for commands | ||
| // ---------------------------------------------------------------------- | ||
|
|
@@ -70,6 +76,16 @@ class ModeManager : public ModeManagerComponentBase { | |
| U32 cmdSeq //!< The command sequence number | ||
| ) override; | ||
|
|
||
| //! Handler implementation for command ENTER_PAYLOAD_MODE | ||
| void ENTER_PAYLOAD_MODE_cmdHandler(FwOpcodeType opCode, //!< The opcode | ||
| U32 cmdSeq //!< The command sequence number | ||
| ) override; | ||
|
|
||
| //! Handler implementation for command EXIT_PAYLOAD_MODE | ||
| void EXIT_PAYLOAD_MODE_cmdHandler(FwOpcodeType opCode, //!< The opcode | ||
| U32 cmdSeq //!< The command sequence number | ||
| ) override; | ||
|
|
||
| private: | ||
| // ---------------------------------------------------------------------- | ||
| // Private helper methods | ||
|
|
@@ -81,15 +97,35 @@ class ModeManager : public ModeManagerComponentBase { | |
| //! Save persistent state to file | ||
| void saveState(); | ||
|
|
||
| //! Enter safe mode with optional reason override | ||
| void enterSafeMode(const char* reason = nullptr); | ||
| //! Enter safe mode with specified reason | ||
| void enterSafeMode(Components::SafeModeReason reason); | ||
|
|
||
| //! Exit safe mode | ||
| //! Exit safe mode (manual command) | ||
| void exitSafeMode(); | ||
|
|
||
| //! Exit safe mode automatically due to voltage recovery | ||
| //! Only allowed when safe mode reason is LOW_BATTERY | ||
| void exitSafeModeAutomatic(F32 voltage); | ||
|
|
||
| //! Enter payload mode with optional reason override | ||
| void enterPayloadMode(const char* reason = nullptr); | ||
|
|
||
| //! Exit payload mode (manual) | ||
| void exitPayloadMode(); | ||
|
|
||
| //! Exit payload mode automatically due to fault condition | ||
| //! More aggressive than manual exit - turns off all switches | ||
| void exitPayloadModeAutomatic(F32 voltage); | ||
|
|
||
| //! Turn off non-critical components | ||
| void turnOffNonCriticalComponents(); | ||
|
|
||
| //! Turn on payload (load switches 6 & 7) | ||
| void turnOnPayload(); | ||
|
|
||
| //! Turn off payload (load switches 6 & 7) | ||
| void turnOffPayload(); | ||
|
|
||
| //! Turn on components (restore normal operation) | ||
| void turnOnComponents(); | ||
|
|
||
|
|
@@ -103,24 +139,46 @@ class ModeManager : public ModeManagerComponentBase { | |
| // Private enums and types | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| //! System mode enumeration | ||
| enum class SystemMode : U8 { NORMAL = 0, SAFE_MODE = 1 }; | ||
| //! System mode enumeration (values ordered for +1/-1 sequential transitions) | ||
| enum class SystemMode : U8 { SAFE_MODE = 1, NORMAL = 2, PAYLOAD_MODE = 3 }; | ||
|
|
||
| //! Persistent state structure | ||
| //! Persistent state structure (v2: includes safe mode reason and clean shutdown flag) | ||
| struct PersistentState { | ||
| U8 mode; //!< Current mode (SystemMode) | ||
| U32 safeModeEntryCount; //!< Number of times safe mode entered | ||
| U8 mode; //!< Current mode (SystemMode) | ||
| U32 safeModeEntryCount; //!< Number of times safe mode entered | ||
| U32 payloadModeEntryCount; //!< Number of times payload mode entered | ||
| U8 safeModeReason; //!< Reason for current safe mode (SafeModeReason) | ||
| U8 cleanShutdown; //!< Flag indicating if last shutdown was intentional (1=clean, 0=unclean) | ||
| }; | ||
|
Comment on lines
+145
to
152
|
||
|
|
||
| // ---------------------------------------------------------------------- | ||
| // Private member variables | ||
| // ---------------------------------------------------------------------- | ||
|
|
||
| SystemMode m_mode; //!< Current system mode | ||
| U32 m_safeModeEntryCount; //!< Counter for safe mode entries | ||
| U32 m_runCounter; //!< Counter for run handler calls (1Hz) | ||
| SystemMode m_mode; //!< Current system mode | ||
| U32 m_safeModeEntryCount; //!< Counter for safe mode entries | ||
| U32 m_payloadModeEntryCount; //!< Counter for payload mode entries | ||
| U32 m_runCounter; //!< Counter for run handler calls (1Hz) | ||
| U32 m_lowVoltageCounter; //!< Counter for consecutive low voltage readings (payload mode exit) | ||
|
|
||
| // Safe mode specific state | ||
| Components::SafeModeReason m_safeModeReason; //!< Reason for current safe mode entry | ||
| U32 m_safeModeVoltageCounter; //!< Counter for consecutive low voltage readings (safe mode entry) | ||
| U32 m_recoveryVoltageCounter; //!< Counter for consecutive high voltage readings (safe mode exit) | ||
|
|
||
| static constexpr const char* STATE_FILE_PATH = "/mode_state.bin"; //!< State file path | ||
|
|
||
| // Voltage threshold constants for payload mode protection | ||
| static constexpr F32 LOW_VOLTAGE_THRESHOLD = 7.2f; //!< Voltage threshold for payload mode exit | ||
| static constexpr U32 LOW_VOLTAGE_DEBOUNCE_SECONDS = 10; //!< Consecutive seconds below threshold | ||
|
|
||
| // Voltage threshold constants for safe mode entry/exit (Normal <-> Safe) | ||
| static constexpr F32 SAFE_MODE_ENTRY_VOLTAGE = 6.7f; //!< Voltage threshold for safe mode entry | ||
| static constexpr F32 SAFE_MODE_RECOVERY_VOLTAGE = 8.0f; //!< Voltage threshold for safe mode auto-recovery | ||
| static constexpr U32 SAFE_MODE_DEBOUNCE_SECONDS = 10; //!< Consecutive seconds for safe mode transitions | ||
|
|
||
| // Buffer size for reason strings (must match FPP string size definitions) | ||
| static constexpr FwSizeType REASON_STRING_SIZE = 100; //!< Matches FPP reason: string size 100 | ||
| }; | ||
|
|
||
| } // namespace Components | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AutoSafeModeEntry event takes two parameters (reason and voltage) as shown in line 149-150, but the event emission in ModeManager.cpp line 98 only passes the reason and voltage correctly. However, the event format string on line 153 shows "reason={} voltage={}V" which will display the enum numeric value (e.g., "1") rather than the enum name ("LOW_BATTERY"). Consider using a formatted string representation or documenting that operators will see numeric enum values.