Corrected read-property handler example for encoding ack without an extra buffer.

This commit is contained in:
skarg
2008-01-07 21:40:33 +00:00
parent f8adfe1f41
commit 9f1dc8223f
2 changed files with 13 additions and 9 deletions
+4 -4
View File
@@ -96,6 +96,7 @@ void handler_read_property(
BACNET_READ_PROPERTY_DATA data; BACNET_READ_PROPERTY_DATA data;
int len = 0; int len = 0;
int ack_len = 0; int ack_len = 0;
int property_len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
bool error = false; bool error = false;
@@ -129,15 +130,14 @@ void handler_read_property(
&Handler_Transmit_Buffer[pdu_len], &Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data); service_data->invoke_id, &data);
/* FIXME: add buffer len as passed into function or use smart buffer */ /* FIXME: add buffer len as passed into function or use smart buffer */
len = Encode_Property_APDU( property_len = Encode_Property_APDU(
&Handler_Transmit_Buffer[pdu_len + ack_len], data.object_type, &Handler_Transmit_Buffer[pdu_len + ack_len], data.object_type,
data.object_instance, data.object_property, data.array_index, data.object_instance, data.object_property, data.array_index,
&error_class, &error_code); &error_class, &error_code);
if (len >= 0) { if (len >= 0) {
pdu_len = pdu_len + len + ack_len;
len = rp_ack_encode_apdu_object_property_end( len = rp_ack_encode_apdu_object_property_end(
&Handler_Transmit_Buffer[pdu_len]); &Handler_Transmit_Buffer[pdu_len + property_len + ack_len]);
pdu_len += len; len += ack_len + property_len;
error = false; error = false;
} }
} }
+9 -5
View File
@@ -133,19 +133,23 @@ int rp_ack_encode_apdu_init(
apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
apdu_len = 3; apdu_len = 3;
/* service ack follows */ /* service ack follows */
apdu_len += len =
encode_context_object_id(&apdu[apdu_len], 0, encode_context_object_id(&apdu[apdu_len], 0,
rpdata->object_type, rpdata->object_instance); rpdata->object_type, rpdata->object_instance);
apdu_len += apdu_len += len;
len =
encode_context_enumerated(&apdu[apdu_len], 1, encode_context_enumerated(&apdu[apdu_len], 1,
rpdata->object_property); rpdata->object_property);
apdu_len += len;
/* context 2 array index is optional */ /* context 2 array index is optional */
if (rpdata->array_index != BACNET_ARRAY_ALL) { if (rpdata->array_index != BACNET_ARRAY_ALL) {
apdu_len += len =
encode_context_unsigned(&apdu[apdu_len], 2, encode_context_unsigned(&apdu[apdu_len], 2,
rpdata->array_index); rpdata->array_index);
apdu_len += len;
} }
apdu_len += encode_opening_tag(&apdu[apdu_len], 3); len = encode_opening_tag(&apdu[apdu_len], 3);
apdu_len += len;
} }
return apdu_len; return apdu_len;