const fn code(e: u8, f: u8) -> [u8; 6] {
[0x81, 0x81, 0xC7, 0xC7, e, f]
}
pub const OK: [u8; 6] = code(0xFD, 0x00);
pub const LATER: [u8; 6] = code(0xFD, 0x01);
pub const ERROR: [u8; 6] = code(0xFE, 0x00);
pub const UNKNOWN_IDENTIFIER: [u8; 6] = code(0xFE, 0x01);
pub const AUTHENTICATION: [u8; 6] = code(0xFE, 0x02);
pub const SERVER_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x03);
pub const REQ_FILE_ID_UNAVAILABLE: [u8; 6] = code(0xFE, 0x04);
pub const NOT_WRITABLE: [u8; 6] = code(0xFE, 0x05);
pub const NOT_READABLE: [u8; 6] = code(0xFE, 0x06);
pub const MEASURING_POINT_DISTURBED: [u8; 6] = code(0xFE, 0x07);
pub const RAW_DATA_UNINTERPRETABLE: [u8; 6] = code(0xFE, 0x08);
pub const OUT_OF_RANGE: [u8; 6] = code(0xFE, 0x09);
pub const NOT_EXECUTED: [u8; 6] = code(0xFE, 0x0A);
pub const CHECKSUM: [u8; 6] = code(0xFE, 0x0B);
pub const BROADCAST_UNSUPPORTED: [u8; 6] = code(0xFE, 0x0C);
pub const UNEXPECTED_MESSAGE: [u8; 6] = code(0xFE, 0x0D);
pub const UNKNOWN_PROFILE_OBJECT: [u8; 6] = code(0xFE, 0x0E);
pub const UNSUPPORTED_TYPE: [u8; 6] = code(0xFE, 0x0F);
pub const OPTIONAL_UNSUPPORTED: [u8; 6] = code(0xFE, 0x10);
pub const PROFILE_EMPTY: [u8; 6] = code(0xFE, 0x11);
pub const END_BEFORE_BEGIN: [u8; 6] = code(0xFE, 0x12);
pub const NO_CLOSE: [u8; 6] = code(0xFE, 0x14);
pub const PROFILE_UNAVAILABLE: [u8; 6] = code(0xFE, 0x15);
const DESCRIPTIONS: &[([u8; 6], &str)] = &[
(OK, "ok, positive acknowledgement"),
(LATER, "will be executed later; result follows as response without request"),
(ERROR, "error"),
(UNKNOWN_IDENTIFIER, "unknown SML identifier"),
(AUTHENTICATION, "insufficient authentication"),
(SERVER_ID_UNAVAILABLE, "destination address (serverId) not available"),
(REQ_FILE_ID_UNAVAILABLE, "request (reqFileId) not available"),
(NOT_WRITABLE, "destination attribute(s) cannot be written"),
(NOT_READABLE, "destination attribute(s) cannot be read"),
(MEASURING_POINT_DISTURBED, "communication with measuring point disturbed"),
(RAW_DATA_UNINTERPRETABLE, "raw data cannot be interpreted"),
(OUT_OF_RANGE, "value out of permitted range"),
(NOT_EXECUTED, "request not executed"),
(CHECKSUM, "checksum faulty"),
(BROADCAST_UNSUPPORTED, "broadcast not supported"),
(UNEXPECTED_MESSAGE, "unexpected SML message"),
(UNKNOWN_PROFILE_OBJECT, "unknown object in the load profile"),
(UNSUPPORTED_TYPE, "data type not supported"),
(OPTIONAL_UNSUPPORTED, "optional element not supported"),
(PROFILE_EMPTY, "requested load profile has no entry"),
(END_BEFORE_BEGIN, "end limit before start limit"),
(NO_CLOSE, "file ended without close request"),
(PROFILE_UNAVAILABLE, "load profile temporarily unavailable"),
];
pub fn describe(number: &[u8]) -> Option<&'static str> {
DESCRIPTIONS.iter().find(|(n, _)| n.as_slice() == number).map(|&(_, d)| d)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn standard_numbers_are_described() {
assert_eq!(describe(&[0x81, 0x81, 0xC7, 0xC7, 0xFE, 0x0B]), Some("checksum faulty"));
assert_eq!(describe(&OK), Some("ok, positive acknowledgement"));
assert_eq!(describe(&[0x81, 0x81, 0xC7, 0xC7, 0xE0, 0x00]), None);
assert_eq!(describe(&[1, 2]), None);
}
}