Add segmentation support functions (#1218)

* Added segmentation support functions and example changes, but no support for segmentation in the TSM or APDU handlers.
This commit is contained in:
Steve Karg
2026-02-04 17:03:13 -06:00
committed by GitHub
parent 577ecf8d7f
commit 8cd1d82d81
14 changed files with 224 additions and 4 deletions
+39 -2
View File
@@ -45,6 +45,10 @@ static struct Address_Cache_Entry {
uint8_t Flags;
uint32_t device_id;
unsigned max_apdu;
#if BACNET_SEGMENTATION_ENABLED
uint8_t segmentation;
uint16_t maxsegments;
#endif
BACNET_ADDRESS address;
uint32_t TimeToLive;
} Address_Cache[MAX_ADDRESS_CACHE];
@@ -346,9 +350,16 @@ void address_set_device_TTL(
* @param device_id Device-Id
* @param max_apdu Pointer to a variable, taking the maximum APDU size.
* @param src Pointer to address structure for return.
* @param segmentation Pointer to a variable, taking the BACNET_SEGMENTATION
* flag.
* @param maxsegments Pointer to a variable, taking the maximum segments.
*/
bool address_get_by_device(
uint32_t device_id, unsigned *max_apdu, BACNET_ADDRESS *src)
bool address_segment_get_by_device(
uint32_t device_id,
unsigned *max_apdu,
BACNET_ADDRESS *src,
uint8_t *segmentation,
uint16_t *maxsegments)
{
struct Address_Cache_Entry *pMatch;
bool found = false; /* return value */
@@ -364,6 +375,20 @@ bool address_get_by_device(
if (max_apdu) {
*max_apdu = pMatch->max_apdu;
}
if (segmentation) {
#if BACNET_SEGMENTATION_ENABLED
*segmentation = pMatch->segmentation;
#else
*segmentation = SEGMENTATION_NONE;
#endif
}
if (maxsegments) {
#if BACNET_SEGMENTATION_ENABLED
*maxsegments = pMatch->maxsegments;
#else
*maxsegments = 1;
#endif
}
/* Prove we found it */
found = true;
}
@@ -375,6 +400,18 @@ bool address_get_by_device(
return found;
}
/**
* @brief Return the cached address for the given device-id
* @param device_id Device-Id
* @param max_apdu Pointer to a variable, taking the maximum APDU size.
* @param src Pointer to address structure for return.
*/
bool address_get_by_device(
uint32_t device_id, unsigned *max_apdu, BACNET_ADDRESS *src)
{
return address_segment_get_by_device(device_id, max_apdu, src, NULL, NULL);
}
/**
* Find a device id from a given MAC address.
*
+8
View File
@@ -43,6 +43,14 @@ BACNET_STACK_EXPORT
bool address_get_by_device(
uint32_t device_id, unsigned *max_apdu, BACNET_ADDRESS *src);
BACNET_STACK_EXPORT
bool address_segment_get_by_device(
uint32_t device_id,
unsigned *max_apdu,
BACNET_ADDRESS *src,
uint8_t *segmentation,
uint16_t *maxsegments);
BACNET_STACK_EXPORT
bool address_get_by_index(
unsigned index,
+8
View File
@@ -1333,7 +1333,11 @@ uint8_t Device_Protocol_Revision(void)
BACNET_SEGMENTATION Device_Segmentation_Supported(void)
{
#if BACNET_SEGMENTATION_ENABLED
return SEGMENTATION_BOTH;
#else
return SEGMENTATION_NONE;
#endif
}
/**
@@ -1804,8 +1808,12 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
rpdata->object_instance, rpdata->array_index,
Device_Object_List_Element_Encode, count, apdu, apdu_max);
if (apdu_len == BACNET_STATUS_ABORT) {
#if BACNET_SEGMENTATION_ENABLED
rpdata->error_code = ERROR_CODE_ABORT_BUFFER_OVERFLOW;
#else
rpdata->error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
#endif
} else if (apdu_len == BACNET_STATUS_ERROR) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
+2 -2
View File
@@ -85,7 +85,7 @@ int iam_encode_pdu(
/* encode the APDU portion of the packet */
len = iam_encode_apdu(
&buffer[pdu_len], Device_Object_Instance_Number(), MAX_APDU,
SEGMENTATION_NONE, Device_Vendor_Identifier());
Device_Segmentation_Supported(), Device_Vendor_Identifier());
pdu_len += len;
return pdu_len;
@@ -158,7 +158,7 @@ int iam_unicast_encode_pdu(
/* encode the APDU portion of the packet */
apdu_len = iam_encode_apdu(
&buffer[npdu_len], Device_Object_Instance_Number(), MAX_APDU,
SEGMENTATION_NONE, Device_Vendor_Identifier());
Device_Segmentation_Supported(), Device_Vendor_Identifier());
pdu_len = npdu_len + apdu_len;
return pdu_len;