Skip to main content

Module header

Module header 

Source
Expand description

The fixed header of the APDUs that carry service parameters, read and written without an allocator (#1614): an Unconfirmed-Request, an unsegmented Confirmed-Request or ComplexACK, and an Error (Clauses 20.1.2, 20.1.3, 20.1.5 and 20.1.7); and the two answers that are all header, a Reject and an Abort (Clauses 20.1.8 and 20.1.9), so a device without a heap can refuse what it doesn’t serve (#1771).

ApduHeader::decode splits an APDU into its header and the service parameters after it, borrowed in place; ApduHeader::encode_to_sink and ApduHeader::encode_with_parameters_to_sink write the same octets the owned encode_apdu does. A segmented Confirmed-Request or ComplexACK is refused with DecodingKind::Unsupported: reassembling one needs storage this profile doesn’t assume. A device that can’t take segmented requests answers one with an Abort (Clause 5.4.5.1). A SimpleACK or a SegmentACK is refused the same way.

use bacnet_encoding::apdu::header::{ApduHeader, MaxApdu, MaxSegments};
use bacnet_types::enums::ConfirmedServiceChoice;

// A ReadProperty request: invoke ID 42, segmented replies accepted, any
// number of segments, APDUs up to 1476 octets.
let apdu = [0x02, 0x05, 0x2A, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x19, 0x55];
let (header, parameters) = ApduHeader::decode(&apdu)?;
let ApduHeader::ConfirmedRequest(request) = header else { unreachable!() };
assert_eq!(request.invoke_id, 42);
assert_eq!(request.service_choice, ConfirmedServiceChoice::READ_PROPERTY);
assert_eq!(request.max_apdu.octets(), 1476);
assert_eq!(request.max_segments, MaxSegments::UNSPECIFIED);
assert_eq!(parameters, &apdu[4..]);

// The ComplexACK that answers it, written in front of its parameters.
let mut storage = [0; 16];
let mut tail = &mut storage[..];
let ack = ApduHeader::ComplexAck { invoke_id: 42, service_choice: request.service_choice };
let written = ack.encode_with_parameters_to_sink(&mut tail, &[0x0C])?;
assert_eq!(storage[..written], [0x30, 0x2A, 0x0C, 0x0C]);

Structs§

ConfirmedRequestHeader
The header of an unsegmented Confirmed-Request (Clause 20.1.2).
MaxApdu
The max-APDU-length-accepted field of a Confirmed-Request (Clause 20.1.2.5): one of six sizes, 50 (MinimumMessageSize), 128, 206, 480, 1024 and 1476 octets. The other ten codes are reserved.
MaxSegments
The max-segments-accepted field of a Confirmed-Request (Clause 20.1.2.4): three bits naming 2, 4, 8, 16, 32 or 64 segments, more than 64, or an unspecified number.

Enums§

ApduHeader
The header of an APDU that carries service parameters, or the whole of a Reject or an Abort, as the allocation-free profile reads and writes it.