1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "README.md" ) ) ]
#![deny(missing_docs)]
use core::fmt;

/// Error type
#[derive(thiserror::Error, Debug)]
pub enum Error {
    /// All I/O errors
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),
    /// Unsupported data type
    #[error("unsupported data type: {0}")]
    DataType(u8),
    /// Unsupported COT
    #[error("unsupported COT: {0}")]
    COT(u8),
    /// Operation overflow
    #[error("operation overflow")]
    Overflow,
    /// Data conversion errors
    #[error("conversion failed: {0}")]
    Conversion(String),
    /// TX/RX chat sequence errors
    #[error("chat sequence error ({0}/{1}")]
    ChatSequence(u16, u16),
    /// Invalid data
    #[error("invalid data: {0}")]
    InvalidData(String),
}

impl Error {
    fn conversion(msg: impl fmt::Display) -> Self {
        Error::Conversion(msg.to_string())
    }
    fn invalid_data(msg: impl fmt::Display) -> Self {
        Error::InvalidData(msg.to_string())
    }
}

/// Server events
pub mod events;
/// IEC 60870-5-101
pub mod telegram101;
/// IEC 60870-5-104
pub mod telegram104;
/// Common data types
pub mod types;