Expand description
The HDLC-based data link layer (IEC 62056-46, ISO/IEC 13239 frame format type 3).
This module provides a frame codec — HdlcFrame, HdlcAddress,
Control and the fcs16 check sequence — and, on top of a
crate::transport::PhysicalTransport, the crate::transport::hdlc::HdlcLayer data-link sub-layer. Because it only
needs a byte channel, the same implementation works over a serial line and
over TCP.
A type-3 frame is laid out as:
7E | format(2) | dest addr(1-4) | src addr(1-4) | control(1) | [HCS(2)] | [information] | FCS(2) | 7EThe frame format field holds the type (0xA), a segmentation bit and an
11-bit frame length (the octet count between the flags). The HCS is present
only when the frame carries an information field; the FCS is always present.
Both check sequences are the CRC-16/X.25 defined by fcs16.
Structs§
- Hdlc
Address - An HDLC address (client or server), of 1, 2 or 4 octets. Each octet carries seven address bits and one extension bit (set on the final octet).
- Hdlc
Frame - A decoded HDLC frame.
- Hdlc
Layer - The HDLC data-link sub-layer over a physical transport.
- XidParams
- XID parameters negotiated during the SNRM/UA exchange (IEC 62056-46 §6.4.4.4.3.2): the maximum information field length and window size each station uses in each direction.
Enums§
Constants§
- FLAG
- HDLC opening/closing flag.
- INACTIVITY_
MAX_ 🔒S - IEC 62056-46 / Blue Book inactivity timeout limit, in seconds (0 disables it).
- INTER_
OCTET_ 🔒DEFAULT_ MS - INTER_
OCTET_ 🔒MAX_ MS - INTER_
OCTET_ 🔒MIN_ MS - IEC 62056-46 / Blue Book inter-octet timeout limits, in milliseconds.
- LLC_
COMMAND 🔒 - The DLMS LLC header prepended to the information field of I/UI frames sent by the client (command).
- LLC_
RESPONSE 🔒 - The DLMS LLC header for frames sent by the server (response).
- MAX_
BAD_ 🔒FRAMES - How many consecutive undecodable (bad FCS/HCS, malformed) frames are silently dropped before receive gives up (IEC 62056-46 §6.4.4.3: frames with an invalid check sequence are discarded without a response).
Functions§
- fcs16
- Computes the HDLC frame/header check sequence (CRC-16/X.25): polynomial 0x1021 reflected (0x8408), initial value 0xFFFF, final one’s complement. The result is transmitted low octet first.
- inter_
octet_ 🔒timeout - Relabels a timeout mid-frame as an inter-octet timeout; other errors pass through unchanged.
- is_
timeout 🔒 - Whether
eis a read timeout (fromPhysicalTransport::set_read_timeout). - read_
exact 🔒 - Reads exactly
buf.len()bytes fromtransport, looping over short reads.