pub struct Watchdog {
config: WatchdogConfig,
}Expand description
Represents the Watchdog responsible for activating and petting the watchdog.
This struct encapsulates the configuration, interface details, and internal state required to communicate with the operating system.
Thread Communication:
This module is designed to run in its own dedicated thread.
It reads commands provided by the messaging system and acts accordingly.
It responds to Quit commands for graceful shutdown.
Platform-Specific Behavior: The watchdog logic will only work on Linux systems but compile for any other system as well.
Thread communication of this component is as follows:
graph LR
messaging[Messaging] --> ds18b20[Ds18b20]
signal_handler[SignalHandler] --> ds18b20Fields§
§config: WatchdogConfigImplementations§
Source§impl Watchdog
impl Watchdog
Sourcepub fn new(config: WatchdogConfig) -> Result<Watchdog, WatchdogError>
pub fn new(config: WatchdogConfig) -> Result<Watchdog, WatchdogError>
Creates a new Watchdog instance.
This constructor initializes the watchdog communication module with its specified configuration. It performs critical validation checks on the configuration parameters to ensure the watchdog can operate correctly and safely.
**Validation checks performed: **
heartbeat_duration_millismust be greater than zero.watchdog_filenamecannot be an empty string.watchdog_heartbeatmessage cannot be an empty string.watchdog_deactivationmessage cannot be an empty string.watchdog_heartbeatandwatchdog_deactivationmessages must be different.
§Arguments
config- Configuration data for the watchdog communication, loaded from a TOML file. This includes filename, heartbeat messages, and timing parameters.
§Returns
A new Watchdog struct, ready for sending heartbeats or respond to termination requests.
§Panics
This function will panic if any of the configuration validation checks fail, as an incorrectly configured watchdog can lead to system instability or unintended resets.
Sourcepub fn execute(
&mut self,
watchdog_channels: &mut WatchDogChannels,
petting: &mut impl PettingTrait,
)
pub fn execute( &mut self, watchdog_channels: &mut WatchDogChannels, petting: &mut impl PettingTrait, )
Executes the main control loop for the watchdog communication module.
This function runs continuously, managing the periodic sending of heartbeats to a system watchdog. It ensures the application’s liveness is maintained and handles various external commands for controlling its operation.
Key Operations:
- Heartbeat Sending: If
activeand notinhibited, it calls thepetting.pet()method to send a heartbeat message to the configuredwatchdog_filename. - Cycle Management: It sleeps for the configured
heartbeat_duration_millisbetween each heartbeat. - External Control: It processes
StartandStopcommands received from messaging or the signal handler toinhibitor re-enable watchdog activity. - Graceful Deactivation: Upon receiving a
Quitcommand, it sends a finalwatchdog_deactivationmessage before exiting the loop. - Shutdown Confirmation: After exiting the loop, it sends a confirmation back to the signal handler.
§Arguments
watchdog_channels- A mutable reference to the struct containing the channels.petting- A mutable reference to an object implementing thePettingTrait, responsible for the actual writing of heartbeat/deactivation messages to the watchdog file.
Trait Implementations§
Source§impl ProcessExternalRequestTrait for Watchdog
impl ProcessExternalRequestTrait for Watchdog
Source§fn process_external_request(
&mut self,
rx_from_signal_handler: &mut AquaReceiver<InternalCommand>,
rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>,
) -> (bool, bool, bool)
fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)
Checks for and processes new commands relevant to the Watchdog module from external channels.
This is the specialized implementation of ProcessExternalRequestTrait for the Watchdog.
It handles standard “Terminate” or “Quit” commands from the signal handler.
From the messaging channel, it specifically processes “Start” and “Stop” commands,
ignoring other inapplicable commands with warnings.
§Arguments
rx_from_signal_handler- A reference to the receiver end of the channel for commands originating from the signal handler.rx_from_messaging_opt- AnOptioncontaining a reference to the receiver end of the channel for commands from the messaging system. This channel is optional.
§Returns
A tuple (bool, bool, bool) indicating the status of specific commands received:
- The first
boolistrueif aQuitorTerminatecommand was received from the signal handler; otherwisefalse. - The second
boolistrueif aStartcommand was received from messaging; otherwisefalse. - The third
boolistrueif aStopcommand was received from messaging; otherwisefalse.