1const fn code(e: u8, f: u8) -> [u8; 6] {
14 [0x81, 0x81, 0xC7, 0xC7, e, f]
15}
16
17pub const OK: [u8; 6] = code(0xFD, 0x00);
19pub const LATER: [u8; 6] = code(0xFD, 0x01);
21pub const ERROR: [u8; 6] = code(0xFE, 0x00);
23pub const UNKNOWN_IDENTIFIER: [u8; 6] = code(0xFE, 0x01);
25pub const AUTHENTICATION: [u8; 6] = code(0xFE, 0x02);
27pub const SERVER_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x03);
29pub const REQ_FILE_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x04);
31pub const NOT_WRITABLE: [u8; 6] = code(0xFE, 0x05);
33pub const NOT_READABLE: [u8; 6] = code(0xFE, 0x06);
35pub const MEASURING_POINT_DISTURBED: [u8; 6] = code(0xFE, 0x07);
37pub const RAW_DATA_UNINTERPRETABLE: [u8; 6] = code(0xFE, 0x08);
39pub const OUT_OF_RANGE: [u8; 6] = code(0xFE, 0x09);
41pub const NOT_EXECUTED: [u8; 6] = code(0xFE, 0x0A);
43pub const CHECKSUM: [u8; 6] = code(0xFE, 0x0B);
45pub const BROADCAST_UNSUPPORTED: [u8; 6] = code(0xFE, 0x0C);
47pub const UNEXPECTED_MESSAGE: [u8; 6] = code(0xFE, 0x0D);
49pub const UNKNOWN_PROFILE_OBJECT: [u8; 6] = code(0xFE, 0x0E);
51pub const UNSUPPORTED_TYPE: [u8; 6] = code(0xFE, 0x0F);
53pub const OPTIONAL_UNSUPPORTED: [u8; 6] = code(0xFE, 0x10);
55pub const PROFILE_EMPTY: [u8; 6] = code(0xFE, 0x11);
57pub const END_BEFORE_BEGIN: [u8; 6] = code(0xFE, 0x12);
59pub const NO_CLOSE: [u8; 6] = code(0xFE, 0x14);
61pub 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
90pub 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}