rewriting ReadPropertyMultiple to use new BACnet Application Data type. Unit test is not passing yet.

This commit is contained in:
skarg
2005-12-11 13:11:48 +00:00
parent a28d0acb14
commit ea9a4635a5
3 changed files with 62 additions and 77 deletions
+58 -71
View File
@@ -36,6 +36,7 @@
#include "bacerror.h" #include "bacerror.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacapp.h"
#include "rpm.h" #include "rpm.h"
/* encode the initial portion of the service */ /* encode the initial portion of the service */
@@ -286,23 +287,24 @@ int rpm_ack_encode_apdu_object_property(
return apdu_len; return apdu_len;
} }
/* This could be using a generic data buffer or the
specific application data type. Using the specific
application data type container would encourage
using standard types, and would make it easier on
the developer. */
int rpm_ack_encode_apdu_object_property_value( int rpm_ack_encode_apdu_object_property_value(
uint8_t *apdu, uint8_t *apdu,
uint8_t *application_data, BACNET_APPLICATION_DATA_VALUE *application_data)
unsigned application_data_len)
{ {
int apdu_len = 0; /* total length of the apdu, return value */ int apdu_len = 0; /* total length of the apdu, return value */
unsigned len = 0;
if (apdu) if (apdu)
{ {
/* Tag 4: propertyValue */ /* Tag 4: propertyValue */
apdu_len += encode_opening_tag(&apdu[apdu_len], 4); apdu_len += encode_opening_tag(&apdu[apdu_len], 4);
for (len = 0; len < application_data_len; len++) apdu_len += bacapp_encode_application_data(
{ &apdu[apdu_len],
apdu[apdu_len++] = application_data[len]; &application_data[0]);
}
apdu_len += encode_closing_tag(&apdu[apdu_len], 4); apdu_len += encode_closing_tag(&apdu[apdu_len], 4);
} }
@@ -458,26 +460,6 @@ int rpm_ack_decode_is_object_property_error(
return len; return len;
} }
/* decode the object property value portion of the service request only */
int rpm_ack_decode_object_property_value(
uint8_t *apdu,
unsigned apdu_len,
uint8_t **application_data,
unsigned *application_data_len)
{
unsigned len = 0;
/* check for valid pointers */
if (apdu && apdu_len && application_data && application_data_len)
{
// don't decode the application tag number or its data here
*application_data = &apdu[len];
*application_data_len = apdu_len - len - 1 /*closing tag*/;
}
return (int)len;
}
int rpm_ack_decode_apdu( int rpm_ack_decode_apdu(
uint8_t *apdu, uint8_t *apdu,
int apdu_len, /* total length of the apdu */ int apdu_len, /* total length of the apdu */
@@ -664,20 +646,20 @@ void testReadPropertyMultipleAck(Test * pTest)
uint32_t object_instance = 0; uint32_t object_instance = 0;
BACNET_PROPERTY_ID object_property = PROP_OBJECT_IDENTIFIER; BACNET_PROPERTY_ID object_property = PROP_OBJECT_IDENTIFIER;
int32_t array_index = 0; int32_t array_index = 0;
uint8_t application_data[4][480] = {{0}}; BACNET_APPLICATION_DATA_VALUE application_data[4] = {{0}};
int application_data_len[4] = {0}; BACNET_APPLICATION_DATA_VALUE test_application_data = {0};
uint8_t test_application_data[480] = {0};
unsigned test_application_data_len = 0;
uint8_t *test_application_data_ptr;
BACNET_ERROR_CLASS error_class; BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code; BACNET_ERROR_CODE error_code;
/* build the RPM - try to make it easy for the Application Layer development */ /* build the RPM - try to make it easy for the
/* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu to Application Layer development */
let the called function handle the out of space problem that these get into /* IDEA: similar construction, but pass apdu, apdu_len pointer,
by returning a boolean of success/failure. size of apdu to let the called function handle the out of
space problem that these get into by returning a boolean
of success/failure.
It almost needs to use the keylist library or something similar. It almost needs to use the keylist library or something similar.
Also check case of storing a backoff point (i.e. save enough room for object_end) */ Also check case of storing a backoff point
(i.e. save enough room for object_end) */
apdu_len = rpm_ack_encode_apdu_init(&apdu[0], invoke_id); apdu_len = rpm_ack_encode_apdu_init(&apdu[0], invoke_id);
/* object beginning */ /* object beginning */
@@ -687,19 +669,19 @@ void testReadPropertyMultipleAck(Test * pTest)
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL);
/* reply value */ /* reply value */
application_data_len[0] = application_data[0].tag = BACNET_APPLICATION_TAG_OBJECT_ID;
encode_bacnet_object_id( application_data[0].type.Object_Id.type = OBJECT_DEVICE;
&application_data[0][0],OBJECT_DEVICE, 123); application_data[0].type.Object_Id.instance = 123;
apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len],
application_data[0],application_data_len[0]); &application_data[0]);
/* reply property */ /* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_NAME, BACNET_ARRAY_ALL); PROP_OBJECT_TYPE, BACNET_ARRAY_ALL);
/* reply value */ /* reply value */
application_data_len[1] = encode_bacnet_character_string(&application_data[1][0], application_data[1].tag = BACNET_APPLICATION_TAG_ENUMERATED;
"my object name"); application_data[1].type.Enumerated = OBJECT_DEVICE;
apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len],
application_data[1],application_data_len[1]); &application_data[1]);
/* object end */ /* object end */
apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]);
@@ -708,12 +690,12 @@ void testReadPropertyMultipleAck(Test * pTest)
OBJECT_ANALOG_INPUT, 33); OBJECT_ANALOG_INPUT, 33);
/* reply property */ /* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); PROP_PRESENT_VALUE, BACNET_ARRAY_ALL);
/* reply value */ /* reply value */
application_data_len[2] = encode_bacnet_object_id(&application_data[2][0], application_data[2].tag = BACNET_APPLICATION_TAG_REAL;
OBJECT_ANALOG_INPUT, 33); application_data[2].type.Real = 0.0;
apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len],
application_data[2],application_data_len[2]); &application_data[2]);
/* reply property */ /* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len], apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_DEADBAND, BACNET_ARRAY_ALL); PROP_DEADBAND, BACNET_ARRAY_ALL);
@@ -722,8 +704,8 @@ void testReadPropertyMultipleAck(Test * pTest)
ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY); ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY);
/* object end */ /* object end */
apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]);
ct_test(pTest, apdu_len != 0); ct_test(pTest, apdu_len != 0);
/* decode the packet */ /* decode the packet */
test_len = rpm_ack_decode_apdu( test_len = rpm_ack_decode_apdu(
&apdu[0], &apdu[0],
@@ -754,7 +736,7 @@ void testReadPropertyMultipleAck(Test * pTest)
ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER); ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, array_index == BACNET_ARRAY_ALL); ct_test(pTest, array_index == BACNET_ARRAY_ALL);
len += test_len; len += test_len;
/* what is the result value? */ /* what is the result? An error or a value? */
test_len = rpm_ack_decode_is_object_property_error( test_len = rpm_ack_decode_is_object_property_error(
&service_request[len], &service_request[len],
service_request_len - len); service_request_len - len);
@@ -765,13 +747,14 @@ void testReadPropertyMultipleAck(Test * pTest)
ct_test(pTest, test_len == 1); ct_test(pTest, test_len == 1);
len += test_len; len += test_len;
/* decode the object property portion of the service request */ /* decode the object property portion of the service request */
test_application_data_ptr = &test_application_data[0]; test_len += bacapp_decode_application_data(
test_len = rpm_ack_decode_object_property_value( &apdu[len],
&service_request[len], apdu_len - len,
service_request_len - len, &test_application_data);
&test_application_data_ptr, ct_test(pTest, test_len > 0);
&test_application_data_len); testCompareApplicationData(pTest,
ct_test(pTest, test_len != -1); &application_data[0],
&test_application_data);
len += test_len; len += test_len;
/* see if there is another property */ /* see if there is another property */
test_len = rpm_ack_decode_object_property( test_len = rpm_ack_decode_object_property(
@@ -794,12 +777,14 @@ void testReadPropertyMultipleAck(Test * pTest)
ct_test(pTest, test_len == 1); ct_test(pTest, test_len == 1);
len += test_len; len += test_len;
/* decode the object property portion of the service request */ /* decode the object property portion of the service request */
test_len = rpm_ack_decode_object_property_value( test_len += bacapp_decode_application_data(
&service_request[len], &apdu[len],
service_request_len - len, apdu_len - len,
&test_application_data_ptr, &test_application_data);
&test_application_data_len); ct_test(pTest, test_len > 0);
ct_test(pTest, test_len != -1); testCompareApplicationData(pTest,
&application_data[1],
&test_application_data);
len += test_len; len += test_len;
/* see if there is another property */ /* see if there is another property */
/* this time we should fail */ /* this time we should fail */
@@ -846,12 +831,14 @@ void testReadPropertyMultipleAck(Test * pTest)
ct_test(pTest, test_len == 1); ct_test(pTest, test_len == 1);
len += test_len; len += test_len;
/* decode the object property portion of the service request */ /* decode the object property portion of the service request */
test_len = rpm_ack_decode_object_property_value( test_len += bacapp_decode_application_data(
&service_request[len], &apdu[len],
service_request_len - len, apdu_len - len,
&test_application_data_ptr, &test_application_data);
&test_application_data_len); ct_test(pTest, test_len > 0);
ct_test(pTest, test_len != -1); testCompareApplicationData(pTest,
&application_data[2],
&test_application_data);
len += test_len; len += test_len;
/* see if there is another property */ /* see if there is another property */
test_len = rpm_ack_decode_object_property( test_len = rpm_ack_decode_object_property(
+2 -5
View File
@@ -38,6 +38,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "bacenum.h" #include "bacenum.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacapp.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -101,8 +102,7 @@ int rpm_ack_encode_apdu_object_begin(
int rpm_ack_encode_apdu_object_property_value( int rpm_ack_encode_apdu_object_property_value(
uint8_t *apdu, uint8_t *apdu,
uint8_t *application_data, BACNET_APPLICATION_DATA_VALUE *application_data);
unsigned application_data_len);
int rpm_ack_encode_apdu_object_property_error( int rpm_ack_encode_apdu_object_property_error(
uint8_t *apdu, uint8_t *apdu,
@@ -126,9 +126,6 @@ int rpm_ack_decode_object_property(
unsigned apdu_len, unsigned apdu_len,
BACNET_PROPERTY_ID *object_property, BACNET_PROPERTY_ID *object_property,
int32_t *array_index); int32_t *array_index);
int rpm_ack_decode_is_object_property_value(
uint8_t *apdu,
unsigned apdu_len);
int rpm_ack_decode_is_object_property_error( int rpm_ack_decode_is_object_property_error(
uint8_t *apdu, uint8_t *apdu,
unsigned apdu_len); unsigned apdu_len);
+1
View File
@@ -8,6 +8,7 @@ CFLAGS = -Wall -I. -Itest -DTEST -DTEST_READ_PROPERTY_MULTIPLE -g
SRCS = bacdcode.c \ SRCS = bacdcode.c \
bacerror.c \ bacerror.c \
bacapp.c \
bigend.c \ bigend.c \
rpm.c \ rpm.c \
test/ctest.c test/ctest.c