darra_ethercat/sugar/
display.rs1
2use crate::data::error::{LinkState, RedundancyState, CiA402State, CiA402Mode};
3use crate::data::types::EcALState;
4use crate::utils::ffi::SlaveIdentity;
5use std::fmt;
6
7impl fmt::Display for LinkState {
8 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9 let s: &'static str = (*self).into();
10 f.write_str(s)
11 }
12}
13
14impl fmt::Display for RedundancyState {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 let s: &'static str = (*self).into();
17 f.write_str(s)
18 }
19}
20
21impl fmt::Display for CiA402State {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 let name = match self {
24 CiA402State::NotReady => "NotReady",
25 CiA402State::SwitchOnDisabled => "SwitchOnDisabled",
26 CiA402State::ReadyToSwitchOn => "ReadyToSwitchOn",
27 CiA402State::SwitchedOn => "SwitchedOn",
28 CiA402State::OperationEnabled => "OperationEnabled",
29 CiA402State::QuickStopActive => "QuickStopActive",
30 CiA402State::FaultReaction => "FaultReaction",
31 CiA402State::Fault => "Fault",
32 CiA402State::Unknown => "Unknown",
33 };
34 f.write_str(name)
35 }
36}
37
38impl fmt::Display for CiA402Mode {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 let name = match self {
41 CiA402Mode::PP => "PP",
42 CiA402Mode::VL => "VL",
43 CiA402Mode::PV => "PV",
44 CiA402Mode::PT => "PT",
45 CiA402Mode::HM => "HM",
46 CiA402Mode::IP => "IP",
47 CiA402Mode::CSP => "CSP",
48 CiA402Mode::CSV => "CSV",
49 CiA402Mode::CST => "CST",
50 };
51 f.write_str(name)
52 }
53}
54
55impl fmt::Display for EcALState {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 let name = match self {
58 EcALState::NoError => "NoError",
59 EcALState::UnspecifiedError => "UnspecifiedError",
60 EcALState::NoMemory => "NoMemory",
61 EcALState::InvalidDeviceSetup => "InvalidDeviceSetup",
62 EcALState::InvalidRevision => "InvalidRevision",
63 EcALState::SiiEepromMismatch => "SiiEepromMismatch",
64 EcALState::FirmwareUpdateFailed => "FirmwareUpdateFailed",
65 EcALState::LicenseError => "LicenseError",
66 EcALState::InvalidStateChange => "InvalidStateChange",
67 EcALState::UnknownRequestedState => "UnknownRequestedState",
68 EcALState::BootstrapNotSupported => "BootstrapNotSupported",
69 EcALState::NoValidFirmware => "NoValidFirmware",
70 EcALState::InvalidMailboxConfig => "InvalidMailboxConfig",
71 EcALState::InvalidMailBoxConfig => "InvalidMailBoxConfig",
72 EcALState::InvalidSyncManagerConfig => "InvalidSyncManagerConfig",
73 EcALState::NoValidInputs => "NoValidInputs",
74 EcALState::NoValidOutputs => "NoValidOutputs",
75 EcALState::SyncError => "SyncError",
76 EcALState::SyncManagerWatchdog => "SyncManagerWatchdog",
77 EcALState::InvalidSyncManagerTypes => "InvalidSyncManagerTypes",
78 EcALState::InvalidOutputConfig => "InvalidOutputConfig",
79 EcALState::InvalidInputConfig => "InvalidInputConfig",
80 EcALState::InvalidWatchdogConfig => "InvalidWatchdogConfig",
81 EcALState::NeedsColdStart => "NeedsColdStart",
82 EcALState::NeedsInit => "NeedsInit",
83 EcALState::NeedsPreOp => "NeedsPreOp",
84 EcALState::NeedsSafeOp => "NeedsSafeOp",
85 EcALState::Unknown => return write!(f, "Unknown(0xFFFF)"),
86 other => return write!(f, "AL(0x{:04X})", *other as u16),
87 };
88 f.write_str(name)
89 }
90}
91
92impl fmt::Display for SlaveIdentity {
93 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94 write!(
95 f,
96 "Vendor=0x{:08X} Product=0x{:08X} Rev=0x{:08X} Serial=0x{:08X}",
97 self.vendor_id, self.product_code, self.revision_no, self.serial_no
98 )
99 }
100}