From 9c1f65145846d73dc568a9a7840a2c63ddea4abe Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 3 Oct 2011 22:24:57 +0000 Subject: [PATCH] Moved Device object dependency to the demo handlers. --- bacnet-stack/demo/handler/h_rp.c | 5 +++++ bacnet-stack/demo/handler/h_rpm.c | 5 +++++ bacnet-stack/src/rp.c | 15 +++++---------- bacnet-stack/src/rpm.c | 10 ++-------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index bdd1389f..da3117ee 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -117,6 +117,11 @@ void handler_read_property( rpdata.application_data = &Handler_Transmit_Buffer[npdu_len + apdu_len]; rpdata.application_data_len = sizeof(Handler_Transmit_Buffer) - (npdu_len + apdu_len); + /* Test for case of indefinite Device object instance */ + if ((rpdata.object_type == OBJECT_DEVICE) && + (rpdata.object_instance == BACNET_MAX_INSTANCE)) { + rpdata.object_instance = Device_Object_Instance_Number(); + } len = Device_Read_Property(&rpdata); if (len >= 0) { apdu_len += len; diff --git a/bacnet-stack/demo/handler/h_rpm.c b/bacnet-stack/demo/handler/h_rpm.c index 030f1e0e..4168bd4f 100644 --- a/bacnet-stack/demo/handler/h_rpm.c +++ b/bacnet-stack/demo/handler/h_rpm.c @@ -126,6 +126,11 @@ static int RPM_Encode_Property( len = 0; rpdata.error_class = ERROR_CLASS_OBJECT; rpdata.error_code = ERROR_CODE_UNKNOWN_OBJECT; + /* Test for case of indefinite Device object instance */ + if ((rpmdata->object_type == OBJECT_DEVICE) && + (rpmdata->object_instance == BACNET_MAX_INSTANCE)) { + rpmdata->object_instance = Device_Object_Instance_Number(); + } rpdata.object_type = rpmdata->object_type; rpdata.object_instance = rpmdata->object_instance; rpdata.object_property = rpmdata->object_property; diff --git a/bacnet-stack/src/rp.c b/bacnet-stack/src/rp.c index b3558a19..e00b0e1a 100644 --- a/bacnet-stack/src/rp.c +++ b/bacnet-stack/src/rp.c @@ -147,23 +147,18 @@ int rp_ack_encode_apdu_init( { int len = 0; /* length of each encoding */ int apdu_len = 0; /* total length of the apdu, return value */ - uint32_t obj_instance = rpdata->object_instance; if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ apdu[1] = invoke_id; /* original invoke id from request */ apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 3; - - /* Test for case of indefinite Device object instance */ - if ( (rpdata->object_type == OBJECT_DEVICE) && - (obj_instance == BACNET_MAX_INSTANCE) ) - obj_instance = Device_Object_Instance_Number(); - + /* service ack follows */ len = - encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, - obj_instance); + encode_context_object_id(&apdu[apdu_len], 0, + rpdata->object_type, + rpdata->object_instance); apdu_len += len; len = encode_context_enumerated(&apdu[apdu_len], 1, @@ -205,7 +200,7 @@ int rp_ack_encode_apdu( int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { - /* Do the initial encoding */ + /* Do the initial encoding */ apdu_len = rp_ack_encode_apdu_init(apdu, invoke_id, rpdata); /* propertyValue */ for (len = 0; len < rpdata->application_data_len; len++) { diff --git a/bacnet-stack/src/rpm.c b/bacnet-stack/src/rpm.c index b60177dd..3c644ad3 100644 --- a/bacnet-stack/src/rpm.c +++ b/bacnet-stack/src/rpm.c @@ -109,7 +109,7 @@ int rpm_encode_apdu_object_end( } /** Encode an RPM request, to be sent. - * + * * @param apdu [in,out] Buffer to hold encoded bytes. * @param max_apdu [in] Length of apdu buffer. * @param invoke_id [in] The Invoke ID to use for this message. @@ -336,18 +336,12 @@ int rpm_ack_encode_apdu_object_begin( BACNET_RPM_DATA * rpmdata) { int apdu_len = 0; /* total length of the apdu, return value */ - uint32_t obj_instance = rpmdata->object_instance; if (apdu) { - /* Test for case of indefinite Device object instance */ - if ( (rpmdata->object_type == OBJECT_DEVICE) && - (obj_instance == BACNET_MAX_INSTANCE) ) - obj_instance = Device_Object_Instance_Number(); - /* Tag 0: objectIdentifier */ apdu_len = encode_context_object_id(&apdu[0], 0, rpmdata->object_type, - obj_instance); + rpmdata->object_instance); /* Tag 1: listOfResults */ apdu_len += encode_opening_tag(&apdu[apdu_len], 1); }