Skip to main content

Watchdog

Struct Watchdog 

Source
pub struct Watchdog { /* private fields */ }
Expand description

A deadman timer: it expires unless fed often enough, catching a stalled controller or link.

Autonomy assumes a stream of fresh commands. If that stream stops, because the controller hung or the radio dropped, the last command must not run forever. A watchdog counts the time since it was last fed and reports expiry once that exceeds its timeout; the caller feeds it each time a fresh command arrives. It accumulates a supplied dt rather than reading a clock, so it works the same on a microcontroller with no wall time.

§Examples

use pamoja_kit::Watchdog;

let mut dog = Watchdog::new(0.5); // expire after 0.5 s of silence
dog.feed();
assert!(!dog.update(0.3)); // 0.3 s since feeding: still alive
assert!(dog.update(0.3)); // 0.6 s total: expired
dog.feed(); // a fresh command revives it
assert!(!dog.is_expired());

Implementations§

Source§

impl Watchdog

Source

pub fn new(timeout: f32) -> Self

Creates a watchdog that expires after timeout without being fed.

§Arguments
  • timeout - the allowed silence before expiry; its magnitude is used, and one that is not a number is taken as zero, so the watchdog expires rather than never.
§Returns

A freshly fed watchdog.

Source

pub fn feed(&mut self)

Feeds the watchdog, resetting the silence timer.

Source

pub fn update(&mut self, dt: f32) -> bool

Advances the timer by dt and returns whether it has expired.

§Arguments
  • dt - the time since the previous update; its magnitude is used. One that is not a finite number means the time is unknown, and the watchdog expires until it is fed, since silence of unknown length is not safe to assume short.
§Returns

true if the watchdog is now expired.

Source

pub fn is_expired(&self) -> bool

Returns whether the watchdog is currently expired.

§Returns

true if the time since feeding exceeds the timeout.

Trait Implementations§

Source§

impl Clone for Watchdog

Source§

fn clone(&self) -> Watchdog

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Watchdog

Source§

impl Debug for Watchdog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.