Link Layer#
- icspacket.proto.dnp3.link.LPDU_HEADER_MIN_LENGTH = 5#
Minimum number of bytes required to represent an LPDU header.
- icspacket.proto.dnp3.link.LPDU_HEADER_MAX_LENGTH = 255#
Maximum possible size of an LPDU header in bytes.
- icspacket.proto.dnp3.link.LPDU_USER_DATA_MAX_LENGTH = 250#
Maximum user data size (250 bytes) that a single LPDU can contain.
- class icspacket.proto.dnp3.link.LinkDirection(*values)[source]#
Values for the DNP3 link layer’s direction bit (DIR field), used by this library to tag which kind of station produced a frame.
(See DNP3 Specification, Section 9.2.4.1.3.1)
- MASTER = 1#
Marks a frame as originating from a Master device.
- OUTSTATION = 0#
Marks a frame as originating from an Outstation device.
- class icspacket.proto.dnp3.link.LinkPrimaryFunctionCode(*values)[source]#
Function codes this library uses for frames traveling from a primary station to a secondary station.
These codes are valid when the PRM bit is set (PRM = 1). (See DNP3 Specification, Table 9-1)
- RESET_LINK_STATES = 0#
Resets the secondary station’s link-layer state.
- TEST_LINK_STATES = 2#
Tests whether the secondary station’s link layer is still responsive.
- CONFIRMED_USER_DATA = 3#
Carries user data that the secondary station must acknowledge.
- UNCONFIRMED_USER_DATA = 4#
Carries user data that does not require an acknowledgement.
- REQUEST_LINK_STATUS = 9#
Asks the secondary station to report its current link status.
- class icspacket.proto.dnp3.link.LinkSecondaryFunctionCode(*values)[source]#
Function codes this library uses for frames traveling from a secondary station back to a primary station.
These codes are valid when the PRM bit is clear (PRM = 0). (See DNP3 Specification, Table 9-2)
- ACK = 0#
Confirms that the previous frame from the primary station was accepted.
- NACK = 1#
Reports that the previous frame from the primary station was rejected.
- LINK_STATUS = 11#
Carries the secondary station’s answer to a REQUEST_LINK_STATUS query.
- NOT_SUPPORTED = 15#
Tells the primary station that the requested link function code is not implemented.
- class icspacket.proto.dnp3.link.LinkControl(direction: LinkDirection = LinkDirection.MASTER, primary_message: bool = False, frame_count_bit: bool = False, frame_count_valid: bool = False, function_code: int = 0)[source]#
This bitfield models the LPDU’s control octet, exposing a frame’s direction, transaction role, retry-detection flags, and function code as individual attributes instead of raw bits. (See DNP3 Specification, Section 9.2.4.1.3)
- direction: LinkDirection = 1#
DIR bit. Records which kind of station - Master or Outstation - originated the frame.
- primary_message: bool = False#
PRM bit.
TrueThis frame opens a new transaction.FalseThis frame completes an existing transaction.
- frame_count_bit: bool = False#
FCB bit. Toggled on primary-to-secondary frames so the secondary station can detect lost or duplicated frames.
- frame_count_valid: bool = False#
FCV bit. Tells the secondary station whether it should pay attention to the FCB carried in this frame.
- function_code: int = 0#
Raw 4-bit function code; decode it with
pri2sec_codeorsec2pri_codedepending on whether this is a primary or secondary frame.
- property data_flow_control: bool#
Expose the DFC bit as a boolean.
A
Truevalue signals that the sending station’s Data Link Layer receive buffer has too little free space to accept more data.- Returns:
Trueif buffer space is insufficient,Falseotherwise.- Return type:
bool
- property pri2sec_code: LinkPrimaryFunctionCode#
Interpret the function code for Primary-to-Secondary frames.
- Returns:
Link layer function code for PRM = 1.
- Return type:
- property sec2pri_code: LinkSecondaryFunctionCode#
Interpret the function code for Secondary-to-Primary frames.
- Returns:
Link layer function code for PRM = 0.
- Return type:
- class icspacket.proto.dnp3.link.LPDU(*, start: bytes = b'\x05d', length: int = 0, control: LinkControl = None, destination: int = 0, source: int = 0, crc16: int = 0, user_data: TPDU | None = None)[source]#
Link-layer Protocol Data Unit (LPDU).
This struct models a complete LPDU as a fixed-size header followed by zero or more variable-length data blocks, each one closed off with its own 16-bit CRC. (See DNP3 Specification, Section 9.2.4)
- start: bytes = b'\x05d'#
Fixed two-byte sync sequence (0x05, 0x64) at the start of every LPDU.
- length: int = 0#
Length field: count of the non-CRC bytes that follow it, spanning the CONTROL, DESTINATION, SOURCE, and USER DATA fields.
- control: LinkControl = None#
Control octet for the frame, modeled by
LinkControl, holding the direction, function code, and status flags.
- destination: int = 0#
Address of the data-link frame’s destination station.
- source: int = 0#
Address of the data-link frame’s source station.
- crc16: int = 0#
Checksum protecting the LPDU header block.
- user_data: TPDU | None = None#
The frame’s payload, held as one or more user-data chunks via
LinkUserData.
- build() bytes[source]#
Construct a serialized LPDU with correct length.
- Returns:
Encoded LPDU bytes.
- Return type:
bytes