tokio_mc/frame/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum ProtocolError {
5    #[error("The number of points to read or write is out of the allowed range.")]
6    OutOfRange,
7
8    #[error("The function code received is not recognized or is invalid: {0:?}")]
9    InvalidFunctionCode([u8; 4]),
10
11    #[error("Invalid address: {0}")]
12    InvalidAddress(String),
13
14    #[error("This functionality is not yet implemented.")]
15    NotImplemented,
16}
17
18pub fn map_error_code(error_code: u16) -> Option<ProtocolError> {
19    match error_code {
20        0xC051..=0xC054 => Some(ProtocolError::OutOfRange),
21        // 其他错误映射
22        _ => None,
23    }
24}