Skip to main content

sml_kit/
attention.rs

1//! Attention numbers (`SML_Attention.Res`, TR-03109-1 Anlage IV Tab. 2 and 3).
2//!
3//! A device answers a request it will not or cannot execute with an attention number,
4//! an OBIS-like six-byte code. `81 81 c7 c7 fd xx` are hints, `81 81 c7 c7 fe xx` are
5//! errors, and `e0 00` to `fc ff` in the last two bytes are application specific.
6//!
7//! ```
8//! use sml_kit::attention;
9//!
10//! assert_eq!(attention::describe(&attention::AUTHENTICATION), Some("insufficient authentication"));
11//! ```
12
13const fn code(e: u8, f: u8) -> [u8; 6] {
14    [0x81, 0x81, 0xC7, 0xC7, e, f]
15}
16
17/// Positive acknowledgement.
18pub const OK: [u8; 6] = code(0xFD, 0x00);
19/// The order will be executed later; its result follows as a response without request.
20pub const LATER: [u8; 6] = code(0xFD, 0x01);
21/// Error not covered by another number.
22pub const ERROR: [u8; 6] = code(0xFE, 0x00);
23/// Unknown SML identifier.
24pub const UNKNOWN_IDENTIFIER: [u8; 6] = code(0xFE, 0x01);
25/// Insufficient authentication (user name or password).
26pub const AUTHENTICATION: [u8; 6] = code(0xFE, 0x02);
27/// Destination address (`serverId`) not available.
28pub const SERVER_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x03);
29/// Request (`reqFileId`) not available.
30pub const REQ_FILE_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x04);
31/// One or more destination attributes cannot be written.
32pub const NOT_WRITABLE: [u8; 6] = code(0xFE, 0x05);
33/// One or more destination attributes cannot be read.
34pub const NOT_READABLE: [u8; 6] = code(0xFE, 0x06);
35/// Communication with the measuring point is disturbed.
36pub const MEASURING_POINT_DISTURBED: [u8; 6] = code(0xFE, 0x07);
37/// Raw data cannot be interpreted.
38pub const RAW_DATA_UNINTERPRETABLE: [u8; 6] = code(0xFE, 0x08);
39/// Value out of permitted range.
40pub const OUT_OF_RANGE: [u8; 6] = code(0xFE, 0x09);
41/// Request not executed (e.g. tree path invalid).
42pub const NOT_EXECUTED: [u8; 6] = code(0xFE, 0x0A);
43/// Checksum faulty.
44pub const CHECKSUM: [u8; 6] = code(0xFE, 0x0B);
45/// Broadcast not supported.
46pub const BROADCAST_UNSUPPORTED: [u8; 6] = code(0xFE, 0x0C);
47/// Unexpected SML message.
48pub const UNEXPECTED_MESSAGE: [u8; 6] = code(0xFE, 0x0D);
49/// Unknown object in the load profile.
50pub const UNKNOWN_PROFILE_OBJECT: [u8; 6] = code(0xFE, 0x0E);
51/// Data type not supported in a set request.
52pub const UNSUPPORTED_TYPE: [u8; 6] = code(0xFE, 0x0F);
53/// Optional element not supported.
54pub const OPTIONAL_UNSUPPORTED: [u8; 6] = code(0xFE, 0x10);
55/// The requested load profile has no entry.
56pub const PROFILE_EMPTY: [u8; 6] = code(0xFE, 0x11);
57/// End limit before start limit in a load profile request.
58pub const END_BEFORE_BEGIN: [u8; 6] = code(0xFE, 0x12);
59/// The file ended without a close request.
60pub const NO_CLOSE: [u8; 6] = code(0xFE, 0x14);
61/// The load profile is temporarily unavailable.
62pub const PROFILE_UNAVAILABLE: [u8; 6] = code(0xFE, 0x15);
63
64const DESCRIPTIONS: &[([u8; 6], &str)] = &[
65    (OK, "ok, positive acknowledgement"),
66    (LATER, "will be executed later; result follows as response without request"),
67    (ERROR, "error"),
68    (UNKNOWN_IDENTIFIER, "unknown SML identifier"),
69    (AUTHENTICATION, "insufficient authentication"),
70    (SERVER_ID_UNAVAILABLE, "destination address (serverId) not available"),
71    (REQ_FILE_ID_UNAVAILABLE, "request (reqFileId) not available"),
72    (NOT_WRITABLE, "destination attribute(s) cannot be written"),
73    (NOT_READABLE, "destination attribute(s) cannot be read"),
74    (MEASURING_POINT_DISTURBED, "communication with measuring point disturbed"),
75    (RAW_DATA_UNINTERPRETABLE, "raw data cannot be interpreted"),
76    (OUT_OF_RANGE, "value out of permitted range"),
77    (NOT_EXECUTED, "request not executed"),
78    (CHECKSUM, "checksum faulty"),
79    (BROADCAST_UNSUPPORTED, "broadcast not supported"),
80    (UNEXPECTED_MESSAGE, "unexpected SML message"),
81    (UNKNOWN_PROFILE_OBJECT, "unknown object in the load profile"),
82    (UNSUPPORTED_TYPE, "data type not supported"),
83    (OPTIONAL_UNSUPPORTED, "optional element not supported"),
84    (PROFILE_EMPTY, "requested load profile has no entry"),
85    (END_BEFORE_BEGIN, "end limit before start limit"),
86    (NO_CLOSE, "file ended without close request"),
87    (PROFILE_UNAVAILABLE, "load profile temporarily unavailable"),
88];
89
90/// What a standard attention number means. Application-specific and unknown numbers
91/// have no description.
92pub fn describe(number: &[u8]) -> Option<&'static str> {
93    DESCRIPTIONS.iter().find(|(n, _)| n.as_slice() == number).map(|&(_, d)| d)
94}
95
96#[cfg(test)]
97mod tests {
98    use super::*;
99
100    #[test]
101    fn standard_numbers_are_described() {
102        assert_eq!(describe(&[0x81, 0x81, 0xC7, 0xC7, 0xFE, 0x0B]), Some("checksum faulty"));
103        assert_eq!(describe(&OK), Some("ok, positive acknowledgement"));
104        assert_eq!(describe(&[0x81, 0x81, 0xC7, 0xC7, 0xE0, 0x00]), None);
105        assert_eq!(describe(&[1, 2]), None);
106    }
107}