darra-ethercat-master 2.6.0

Commercial EtherCAT master protocol stack, real-time kernel driver integration, Windows and Linux support, multi-language SDKs, complex topology and hot-plug support.
Documentation

use crate::data::error::{LinkState, RedundancyState, CiA402State, CiA402Mode};
use crate::data::types::EcALState;
use crate::utils::ffi::SlaveIdentity;
use std::fmt;

impl fmt::Display for LinkState {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let s: &'static str = (*self).into();
        f.write_str(s)
    }
}

impl fmt::Display for RedundancyState {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let s: &'static str = (*self).into();
        f.write_str(s)
    }
}

impl fmt::Display for CiA402State {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let name = match self {
            CiA402State::NotReady => "NotReady",
            CiA402State::SwitchOnDisabled => "SwitchOnDisabled",
            CiA402State::ReadyToSwitchOn => "ReadyToSwitchOn",
            CiA402State::SwitchedOn => "SwitchedOn",
            CiA402State::OperationEnabled => "OperationEnabled",
            CiA402State::QuickStopActive => "QuickStopActive",
            CiA402State::FaultReaction => "FaultReaction",
            CiA402State::Fault => "Fault",
            CiA402State::Unknown => "Unknown",
        };
        f.write_str(name)
    }
}

impl fmt::Display for CiA402Mode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let name = match self {
            CiA402Mode::PP => "PP",
            CiA402Mode::VL => "VL",
            CiA402Mode::PV => "PV",
            CiA402Mode::PT => "PT",
            CiA402Mode::HM => "HM",
            CiA402Mode::IP => "IP",
            CiA402Mode::CSP => "CSP",
            CiA402Mode::CSV => "CSV",
            CiA402Mode::CST => "CST",
        };
        f.write_str(name)
    }
}

impl fmt::Display for EcALState {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let name = match self {
            EcALState::NoError => "NoError",
            EcALState::UnspecifiedError => "UnspecifiedError",
            EcALState::NoMemory => "NoMemory",
            EcALState::InvalidDeviceSetup => "InvalidDeviceSetup",
            EcALState::InvalidRevision => "InvalidRevision",
            EcALState::SiiEepromMismatch => "SiiEepromMismatch",
            EcALState::FirmwareUpdateFailed => "FirmwareUpdateFailed",
            EcALState::LicenseError => "LicenseError",
            EcALState::InvalidStateChange => "InvalidStateChange",
            EcALState::UnknownRequestedState => "UnknownRequestedState",
            EcALState::BootstrapNotSupported => "BootstrapNotSupported",
            EcALState::NoValidFirmware => "NoValidFirmware",
            EcALState::InvalidMailboxConfig => "InvalidMailboxConfig",
            EcALState::InvalidMailBoxConfig => "InvalidMailBoxConfig",
            EcALState::InvalidSyncManagerConfig => "InvalidSyncManagerConfig",
            EcALState::NoValidInputs => "NoValidInputs",
            EcALState::NoValidOutputs => "NoValidOutputs",
            EcALState::SyncError => "SyncError",
            EcALState::SyncManagerWatchdog => "SyncManagerWatchdog",
            EcALState::InvalidSyncManagerTypes => "InvalidSyncManagerTypes",
            EcALState::InvalidOutputConfig => "InvalidOutputConfig",
            EcALState::InvalidInputConfig => "InvalidInputConfig",
            EcALState::InvalidWatchdogConfig => "InvalidWatchdogConfig",
            EcALState::NeedsColdStart => "NeedsColdStart",
            EcALState::NeedsInit => "NeedsInit",
            EcALState::NeedsPreOp => "NeedsPreOp",
            EcALState::NeedsSafeOp => "NeedsSafeOp",
            EcALState::Unknown => return write!(f, "Unknown(0xFFFF)"),
            other => return write!(f, "AL(0x{:04X})", *other as u16),
        };
        f.write_str(name)
    }
}

impl fmt::Display for SlaveIdentity {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "Vendor=0x{:08X} Product=0x{:08X} Rev=0x{:08X} Serial=0x{:08X}",
            self.vendor_id, self.product_code, self.revision_no, self.serial_no
        )
    }
}