diff --git a/bacnet-stack/ports/atmega168/h_rp.c b/bacnet-stack/ports/atmega168/h_rp.c index d9910b1b..f8ec7c29 100644 --- a/bacnet-stack/ports/atmega168/h_rp.c +++ b/bacnet-stack/ports/atmega168/h_rp.c @@ -96,6 +96,7 @@ void handler_read_property( BACNET_READ_PROPERTY_DATA data; int len = 0; int ack_len = 0; + int property_len = 0; int pdu_len = 0; BACNET_NPDU_DATA npdu_data; bool error = false; @@ -129,15 +130,14 @@ void handler_read_property( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); /* 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, data.object_instance, data.object_property, data.array_index, &error_class, &error_code); if (len >= 0) { - pdu_len = pdu_len + len + ack_len; len = rp_ack_encode_apdu_object_property_end( - &Handler_Transmit_Buffer[pdu_len]); - pdu_len += len; + &Handler_Transmit_Buffer[pdu_len + property_len + ack_len]); + len += ack_len + property_len; error = false; } } diff --git a/bacnet-stack/src/rp.c b/bacnet-stack/src/rp.c index 6aa36ecf..e8764efa 100644 --- a/bacnet-stack/src/rp.c +++ b/bacnet-stack/src/rp.c @@ -133,19 +133,23 @@ int rp_ack_encode_apdu_init( apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 3; /* service ack follows */ - apdu_len += - encode_context_object_id(&apdu[apdu_len], 0, + len = + encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, rpdata->object_instance); - apdu_len += + apdu_len += len; + len = encode_context_enumerated(&apdu[apdu_len], 1, rpdata->object_property); + apdu_len += len; /* context 2 array index is optional */ if (rpdata->array_index != BACNET_ARRAY_ALL) { - apdu_len += + len = encode_context_unsigned(&apdu[apdu_len], 2, 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;