pub struct HeartbeatMonitor { /* private fields */ }Expand description
Tracks per-node heartbeats and flags nodes that stop producing them.
A CANopen node emits a heartbeat on 0x700 + node; a master watches those
frames to know each node is alive and in which state. Construct with the
consumer timeout, feed every received frame to HeartbeatMonitor::on_frame,
and query HeartbeatMonitor::timed_out / HeartbeatMonitor::is_alive.
Implementations§
Source§impl HeartbeatMonitor
impl HeartbeatMonitor
Sourcepub fn new(timeout: Duration) -> Self
pub fn new(timeout: Duration) -> Self
Create a monitor that considers a node dead after timeout without a
heartbeat.
Sourcepub fn on_frame(
&mut self,
cob_id: u16,
data: &[u8],
now: Instant,
) -> Option<(NodeId, NmtState)>
pub fn on_frame( &mut self, cob_id: u16, data: &[u8], now: Instant, ) -> Option<(NodeId, NmtState)>
Feed a received frame, timestamped now.
If it is a heartbeat or boot-up frame, records it and returns the
(node, state) it reported; otherwise returns None.
Sourcepub fn state(&self, node: NodeId) -> Option<NmtState>
pub fn state(&self, node: NodeId) -> Option<NmtState>
The last state reported by node, if it has ever been heard from.
Sourcepub fn health(&self, node: NodeId) -> Option<NodeHealth>
pub fn health(&self, node: NodeId) -> Option<NodeHealth>
The full health record for node.
Sourcepub fn is_alive(&self, node: NodeId, now: Instant) -> bool
pub fn is_alive(&self, node: NodeId, now: Instant) -> bool
Whether node produced a heartbeat within the timeout as of now.
Sourcepub fn timed_out(&self, now: Instant) -> impl Iterator<Item = NodeId> + '_
pub fn timed_out(&self, now: Instant) -> impl Iterator<Item = NodeId> + '_
The nodes that have gone silent — no heartbeat within the timeout.
Sourcepub fn nodes(&self) -> impl Iterator<Item = (NodeId, NodeHealth)> + '_
pub fn nodes(&self) -> impl Iterator<Item = (NodeId, NodeHealth)> + '_
Every monitored node paired with its health record.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HeartbeatMonitor
impl RefUnwindSafe for HeartbeatMonitor
impl Send for HeartbeatMonitor
impl Sync for HeartbeatMonitor
impl Unpin for HeartbeatMonitor
impl UnsafeUnpin for HeartbeatMonitor
impl UnwindSafe for HeartbeatMonitor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more