Skip to main content

ember_plus/s101/
constants.rs

1//! S101 protocol constants.
2
3/// Frame start marker (BOF).
4pub const BOF: u8 = 0xFE;
5
6/// Frame end marker (EOF).
7pub const EOF: u8 = 0xFF;
8
9/// Escape byte for byte stuffing.
10pub const ESCAPE_BYTE: u8 = 0xFD;
11
12/// XOR value for escaped bytes.
13pub const ESCAPE_XOR: u8 = 0x20;
14
15/// Invalid byte that must be escaped.
16pub const INVALID_BYTE: u8 = 0xFC;
17
18/// Slot byte position.
19pub const SLOT_OFFSET: usize = 0;
20
21/// Message type byte position.
22pub const MESSAGE_TYPE_OFFSET: usize = 1;
23
24/// Command byte position.
25pub const COMMAND_OFFSET: usize = 2;
26
27/// Version byte position (for Ember messages).
28pub const VERSION_OFFSET: usize = 3;
29
30/// Maximum frame size.
31pub const MAX_FRAME_SIZE: usize = 65535;
32
33/// Keep-alive request command.
34pub const CMD_KEEPALIVE_REQUEST: u8 = 0x01;
35
36/// Keep-alive response command.
37pub const CMD_KEEPALIVE_RESPONSE: u8 = 0x02;
38
39/// Ember data command.
40pub const CMD_EMBER: u8 = 0x00;
41
42/// Message type: Ember (for both data and keep-alive commands).
43pub const MSG_TYPE_EMBER: u8 = 0x0E;
44
45/// Invalid byte threshold - bytes >= this must be escaped.
46pub const S101_INV: u8 = 0xF8;
47
48/// CRC polynomial (CRC-16-CCITT).
49pub const CRC_POLYNOMIAL: u16 = 0x1021;
50
51/// CRC initial value.
52pub const CRC_INITIAL: u16 = 0xFFFF;
53
54/// Header length for Ember messages.
55pub const EMBER_HEADER_LEN: usize = 7;