#[non_exhaustive]pub enum Reply {
QuerySpeed {
set_speed: Speed,
estop: bool,
commanded: Speed,
actual: Speed,
},
QueryFunction {
addr: u32,
value: u16,
},
AssignController {
result: u8,
},
QueryController {
flags: u8,
controller: NodeId,
},
ControllerChanged {
result: u8,
},
Reserve {
result: u8,
},
Heartbeat {
timeout_s: u8,
},
Unknown(Vec<u8>),
}Expand description
A Traction Control Reply (train → throttle).
Decode the payload of a received
Message::TractionReply with
Reply::decode; a train implementation builds replies with
Reply::encode.
use rolcb::traction::{Reply, Speed};
let r = Reply::QuerySpeed {
set_speed: Speed::from_mph(10.0, true),
estop: false,
commanded: Speed::NAN,
actual: Speed::NAN,
};
assert_eq!(Reply::decode(&r.encode()), r);
assert_eq!(Reply::decode(&[0x20, 0x01, 0x00]), Reply::AssignController { result: 0 });The enum is #[non_exhaustive]: match it with a _ arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
QuerySpeed
Answer to Command::QuerySpeed (0x10).
Fields
commanded: SpeedThe speed currently being commanded (may lag set_speed with
momentum); Speed::NAN if not available or not sent.
actual: SpeedMeasured actual speed; Speed::NAN if not available or not sent.
QueryFunction
Answer to Command::QueryFunction (0x11).
AssignController
Result 0 = accepted.
Answer to Command::AssignController (0x20 0x01). A nonzero
result means the assignment was refused (for example, the current
controller did not agree to hand over).
QueryController
Answer to Command::QueryController (0x20 0x03).
ControllerChanged
Answer to Command::ControllerChangingNotify (0x20 0x04 result),
sent by the current controller back to the train.
Despite the name, a throttle does not receive this; it sends it after the train asked whether another node may take over. Result 0 accepts the handover (the throttle should then consider the train lost); nonzero refuses it, and the train refuses the new controller’s Assign Controller.
Reserve
Answer to Command::Reserve (0x40 0x01).
Heartbeat
The train wants a Command::Noop within timeout_s seconds.
Encoded as 0x40 0x03 timeout. If the controller stays silent past
the timeout, the train stops itself as a safety measure.
Unknown(Vec<u8>)
Anything not recognised, raw bytes kept.
Implementations§
Source§impl Reply
impl Reply
Sourcepub fn decode(p: &[u8]) -> Reply
pub fn decode(p: &[u8]) -> Reply
Parse reply payload bytes. Never fails; unknown or truncated replies
become Reply::Unknown. Missing optional fields of a Query Speed
reply decode as Speed::NAN; a missing result byte decodes as 0.