MovedMoved ReadProperty to subdirectory for library splitting. Split client, server, test for ReadProperty.

This commit is contained in:
skarg
2007-10-14 02:19:24 +00:00
parent b91d73d0bc
commit 947756fa0d
10 changed files with 118 additions and 1030 deletions
-175
View File
@@ -36,158 +36,6 @@
#include "bacdcode.h"
#include "bacdef.h"
#include "rp.h"
/* encode service */
int rp_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data)
{
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
if (apdu) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
apdu_len = 4;
len = encode_context_object_id(&apdu[apdu_len], 0,
data->object_type, data->object_instance);
apdu_len += len;
len = encode_context_enumerated(&apdu[apdu_len], 1,
data->object_property);
apdu_len += len;
/* optional array index */
if (data->array_index != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu[apdu_len], 2,
data->array_index);
apdu_len += len;
}
}
return apdu_len;
}
/* decode the service request only */
int rp_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data)
{
unsigned len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
int type = 0; /* for decoding */
int property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */
/* check for value pointers */
if (apdu_len && data) {
/* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[len++], 0))
return -1;
len += decode_object_id(&apdu[len], &type, &data->object_instance);
data->object_type = (BACNET_OBJECT_TYPE)type;
/* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
if (tag_number != 1)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
data->object_property = (BACNET_PROPERTY_ID)property;
/* Tag 2: Optional Array Index */
if (len < apdu_len) {
len += decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 2) {
len += decode_unsigned(&apdu[len], len_value_type,
&array_value);
data->array_index = array_value;
} else
data->array_index = BACNET_ARRAY_ALL;
} else
data->array_index = BACNET_ARRAY_ALL;
}
return (int) len;
}
int rp_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data)
{
int len = 0; /* length of each encoding */
int apdu_len = 0; /* total length of the apdu, return value */
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;
/* service ack follows */
apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
data->object_type, data->object_instance);
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1,
data->object_property);
/* context 2 array index is optional */
if (data->array_index != BACNET_ARRAY_ALL) {
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2,
data->array_index);
}
/* propertyValue */
apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
for (len = 0; len < data->application_data_len; len++) {
apdu[apdu_len++] = data->application_data[len];
}
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
}
return apdu_len;
}
int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */
BACNET_READ_PROPERTY_DATA * data)
{
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
int tag_len = 0; /* length of tag decode */
int len = 0; /* total length of decodes */
int object = 0, property = 0; /* for decoding */
uint32_t array_value = 0; /* for decoding */
/* FIXME: check apdu_len against the len during decode */
/* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[0], 0))
return -1;
len = 1;
len += decode_object_id(&apdu[len], &object, &data->object_instance);
data->object_type = (BACNET_OBJECT_TYPE)object;
/* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
if (tag_number != 1)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
data->object_property = (BACNET_PROPERTY_ID)property;
/* Tag 2: Optional Array Index */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
if (tag_number == 2) {
len += tag_len;
len += decode_unsigned(&apdu[len], len_value_type, &array_value);
data->array_index = array_value;
} else
data->array_index = BACNET_ARRAY_ALL;
/* Tag 3: opening context tag */
if (decode_is_opening_tag_number(&apdu[len], 3)) {
/* a tag number of 3 is not extended so only one octet */
len++;
/* don't decode the application tag number or its data here */
data->application_data = &apdu[len];
data->application_data_len = apdu_len - len - 1 /*closing tag */ ;
} else
return -1;
return len;
}
#ifdef TEST
#include <assert.h>
#include <string.h>
#include "ctest.h"
@@ -316,26 +164,3 @@ void testReadProperty(Test * pTest)
return;
}
#ifdef TEST_READ_PROPERTY
int main(void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet ReadProperty", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testReadProperty);
assert(rc);
rc = ct_addTestFunction(pTest, testReadPropertyAck);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void) ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif /* TEST_READ_PROPERTY */
#endif /* TEST */