Skip to main content

Reply

Enum Reply 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

QuerySpeed

Answer to Command::QuerySpeed (0x10).

Fields

§set_speed: Speed

The last speed set by a controller.

§estop: bool

True if the train is in emergency stop (status byte bit 0).

§commanded: Speed

The speed currently being commanded (may lag set_speed with momentum); Speed::NAN if not available or not sent.

§actual: Speed

Measured actual speed; Speed::NAN if not available or not sent.

§

QueryFunction

Answer to Command::QueryFunction (0x11).

Fields

§addr: u32

24-bit function address.

§value: u16

Current value.

§

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).

Fields

§result: u8

0 on success; nonzero error flags otherwise.

§

QueryController

Answer to Command::QueryController (0x20 0x03).

Fields

§flags: u8

Flags byte.

§controller: NodeId

The current controller; all-zero if none.

§

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.

Fields

§result: u8

0 = handover accepted; nonzero = refused.

§

Reserve

Answer to Command::Reserve (0x40 0x01).

Fields

§result: u8

0 on success.

§

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.

Fields

§timeout_s: u8

Seconds the controller has to answer.

§

Unknown(Vec<u8>)

Anything not recognised, raw bytes kept.

Implementations§

Source§

impl Reply

Source

pub fn encode(&self) -> Vec<u8> ⓘ

Serialize to the reply payload bytes.

Source

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.

Trait Implementations§

Source§

impl Clone for Reply

Source§

fn clone(&self) -> Self

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 Debug for Reply

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Reply

Source§

impl Hash for Reply

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Reply

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Reply

Auto Trait Implementations§

§

impl Freeze for Reply

§

impl RefUnwindSafe for Reply

§

impl Send for Reply

§

impl Sync for Reply

§

impl Unpin for Reply

§

impl UnsafeUnpin for Reply

§

impl UnwindSafe for Reply

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.