Skip to main content

powerlink_rs/node/
mod.rs

1pub mod cn;
2pub mod handler;
3
4use crate::nmt::states::NmtState;
5use alloc::vec::Vec;
6
7/// Represents the possible actions a POWERLINK node might need to perform
8/// in response to an event or a tick.
9#[derive(Debug)]
10pub enum NodeAction {
11    /// The node needs to send a frame over the network.
12    SendFrame(Vec<u8>),
13    /// The node needs a timer to be set for the specified duration in microseconds.
14    /// When the timer expires, the application should call `tick()`.
15    SetTimer(u64),
16    /// No immediate action is required.
17    NoAction,
18}
19
20/// A trait that defines the common interface for all POWERLINK nodes (MN and CN).
21pub trait Node {
22    /// Processes a raw byte buffer received from the network.
23    fn process_raw_frame(&mut self, buffer: &[u8]) -> NodeAction;
24    /// Called periodically by the application to handle time-based events, like timeouts.
25    fn tick(&mut self) -> NodeAction;
26    /// Returns the current NMT state of the node.
27    fn nmt_state(&self) -> NmtState;
28}
29