ethercat_soem/
error.rs

1use crate::AlStatus;
2use ethercat_types as ec;
3use thiserror::Error;
4
5/// Error
6#[derive(Debug, Error)]
7pub enum Error {
8    #[error("Could not init EtherCAT master")]
9    Init,
10    #[error("Invalid network interface")]
11    Iface,
12    #[error("No slaves found")]
13    NoSlaves,
14    #[error("Could not configure map group")]
15    CfgMapGroup,
16    #[error("Could not configure DC")]
17    CfgDc,
18    #[error("Could not set requested state")]
19    SetState,
20    #[error("Could not check state")]
21    CheckState,
22    #[error("Could not read states")]
23    ReadStates,
24    #[error("Could not send process data")]
25    SendProcessData,
26    #[error("Could not receive process data")]
27    RecvProcessData,
28    #[error("Invalid AL state: {0:?}")]
29    AlState(AlStatus),
30    #[error("Invalid group ID")]
31    GroupId,
32    #[error("Could not read OD list of {0:?}")]
33    ReadOdList(ec::SlavePos),
34    #[error("Could not read OD description of {0:?}")]
35    ReadOdDesc(ec::SdoPos),
36    #[error("Could not read OE list of {0:?}")]
37    ReadOeList(ec::SdoPos),
38    #[error("Could not read {1:?} of {0:?}")]
39    ReadSdo(ec::SlavePos, ec::SdoIdx),
40    #[error("Index {1:?} not found at {0:?}")]
41    IdxNotFound(ec::SlavePos, ec::Idx),
42    #[error("Subindex {1:?} not found at {0:?}")]
43    SubIdxNotFound(ec::SlavePos, ec::SdoIdx),
44    #[error("Could not write {1:?} of {0:?}")]
45    WriteSdo(ec::SlavePos, ec::SdoIdx),
46    #[error("Data type ({0:?}) is not supported yet")]
47    UnsuportedDataType(ec::DataType),
48    #[error("Value ({0:?}) is not supported yet")]
49    UnsuportedValue(ec::Value),
50    #[error("Cannot read value from empty buffer")]
51    ValueFromEmptyBuf,
52    #[error("Cannot convert raw data to EtherCAT value")]
53    ValueConversion(#[from] std::array::TryFromSliceError),
54    #[error("Unexpected data type")]
55    UnexpectedDataType, // TODO: add expected and actual
56    #[error("No frame received")]
57    NoFrame,
58    #[error("Unkown frame received")]
59    OtherFrame,
60    #[error("Invalid SM type")]
61    InvalidSmType,
62    #[error("{0:?} not found")]
63    SlaveNotFound(ec::SlavePos),
64    #[error("PDO entry {0:?} not found")]
65    PdoEntryNotFound(ec::PdoEntryIdx),
66}
67
68impl From<ec::InvalidSmTypeError> for Error {
69    fn from(_: ec::InvalidSmTypeError) -> Self {
70        Self::InvalidSmType
71    }
72}