Skip to main content

Module hdlc

Module hdlc 

Source
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) | 7E

The 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§

HdlcAddress
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).
HdlcFrame
A decoded HDLC frame.
HdlcLayer
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§

Control
The HDLC control field.
HdlcError
Errors that can occur while decoding an HDLC frame.

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 e is a read timeout (from PhysicalTransport::set_read_timeout).
read_exact 🔒
Reads exactly buf.len() bytes from transport, looping over short reads.