Adjusted Device Object type decoding to use uint16_t rather than int. Corrected unit tests.
This commit is contained in:
@@ -178,6 +178,11 @@ extern "C" {
|
|||||||
BACNET_OCTET_STRING * octet_string);
|
BACNET_OCTET_STRING * octet_string);
|
||||||
size_t octetstring_capacity(
|
size_t octetstring_capacity(
|
||||||
BACNET_OCTET_STRING * octet_string);
|
BACNET_OCTET_STRING * octet_string);
|
||||||
|
/* returns true if the same length and contents */
|
||||||
|
bool octetstring_value_same(
|
||||||
|
BACNET_OCTET_STRING * octet_string1,
|
||||||
|
BACNET_OCTET_STRING * octet_string2);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ int arf_decode_service_request(
|
|||||||
int tag_len = 0;
|
int tag_len = 0;
|
||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value_type = 0;
|
uint32_t len_value_type = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
|
|
||||||
/* check for value pointers */
|
/* check for value pointers */
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ int awf_decode_service_request(
|
|||||||
uint32_t len_value_type = 0;
|
uint32_t len_value_type = 0;
|
||||||
int32_t signed_value = 0;
|
int32_t signed_value = 0;
|
||||||
uint32_t unsigned_value = 0;
|
uint32_t unsigned_value = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
|
|
||||||
/* check for value pointers */
|
/* check for value pointers */
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ int bacapp_decode_data(
|
|||||||
#if defined (BACAPP_OBJECT_ID)
|
#if defined (BACAPP_OBJECT_ID)
|
||||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||||
{
|
{
|
||||||
int object_type = 0;
|
uint16_t object_type = 0;
|
||||||
uint32_t instance = 0;
|
uint32_t instance = 0;
|
||||||
len = decode_object_id(&apdu[0], &object_type, &instance);
|
len = decode_object_id(&apdu[0], &object_type, &instance);
|
||||||
value->type.Object_Id.type = object_type;
|
value->type.Object_Id.type = object_type;
|
||||||
|
|||||||
@@ -721,7 +721,7 @@ int encode_context_bitstring(
|
|||||||
/* returns the number of apdu bytes consumed */
|
/* returns the number of apdu bytes consumed */
|
||||||
int decode_object_id(
|
int decode_object_id(
|
||||||
uint8_t * apdu,
|
uint8_t * apdu,
|
||||||
int *object_type,
|
uint16_t *object_type,
|
||||||
uint32_t * instance)
|
uint32_t * instance)
|
||||||
{
|
{
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
@@ -2203,7 +2203,7 @@ void testBACDCodeObject(
|
|||||||
uint32_t decoded_instance = 0;
|
uint32_t decoded_instance = 0;
|
||||||
|
|
||||||
encode_bacnet_object_id(&encoded_array[0], type, instance);
|
encode_bacnet_object_id(&encoded_array[0], type, instance);
|
||||||
decode_object_id(&encoded_array[0], (int *) &decoded_type,
|
decode_object_id(&encoded_array[0], (uint16_t *) &decoded_type,
|
||||||
&decoded_instance);
|
&decoded_instance);
|
||||||
ct_test(pTest, decoded_type == type);
|
ct_test(pTest, decoded_type == type);
|
||||||
ct_test(pTest, decoded_instance == instance);
|
ct_test(pTest, decoded_instance == instance);
|
||||||
@@ -2213,7 +2213,7 @@ void testBACDCodeObject(
|
|||||||
for (type = 0; type < 1024; type++) {
|
for (type = 0; type < 1024; type++) {
|
||||||
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
|
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
|
||||||
encode_bacnet_object_id(&encoded_array[0], type, instance);
|
encode_bacnet_object_id(&encoded_array[0], type, instance);
|
||||||
decode_object_id(&encoded_array[0], (int *) &decoded_type,
|
decode_object_id(&encoded_array[0], (uint16_t *) &decoded_type,
|
||||||
&decoded_instance);
|
&decoded_instance);
|
||||||
ct_test(pTest, decoded_type == type);
|
ct_test(pTest, decoded_type == type);
|
||||||
ct_test(pTest, decoded_instance == instance);
|
ct_test(pTest, decoded_instance == instance);
|
||||||
@@ -2586,8 +2586,7 @@ void testOctetStringContextDecodes(Test * pTest)
|
|||||||
ct_test(pTest, outLen2 == -1);
|
ct_test(pTest, outLen2 == -1);
|
||||||
ct_test(pTest, inLen == outLen);
|
ct_test(pTest, inLen == outLen);
|
||||||
ct_test(pTest, in.length == out.length);
|
ct_test(pTest, in.length == out.length);
|
||||||
ct_test(pTest, memcmp(in.value, out.value, MAX_APDU - 6) == 0);
|
ct_test(pTest, octetstring_value_same(&in, &out));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testTimeContextDecodes(Test * pTest)
|
void testTimeContextDecodes(Test * pTest)
|
||||||
|
|||||||
@@ -539,6 +539,28 @@ size_t octetstring_capacity(
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* returns true if the same length and contents */
|
||||||
|
bool octetstring_value_same(
|
||||||
|
BACNET_OCTET_STRING * octet_string1,
|
||||||
|
BACNET_OCTET_STRING * octet_string2)
|
||||||
|
{
|
||||||
|
size_t i = 0; /* loop counter */
|
||||||
|
|
||||||
|
if (octet_string1 && octet_string2) {
|
||||||
|
if ((octet_string1->length == octet_string2->length) &&
|
||||||
|
(octet_string1->length <= sizeof(octet_string1->value))) {
|
||||||
|
for (i = 0; i < octet_string1->length; i++) {
|
||||||
|
if (octet_string1->value[i] != octet_string2->value[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ int cov_notify_decode_service_request(
|
|||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
uint32_t decoded_value = 0; /* for decoding */
|
uint32_t decoded_value = 0; /* for decoding */
|
||||||
int decoded_type = 0; /* for decoding */
|
uint16_t decoded_type = 0; /* for decoding */
|
||||||
int property = 0; /* for decoding */
|
int property = 0; /* for decoding */
|
||||||
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
|
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ int cov_subscribe_decode_service_request(
|
|||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
uint32_t decoded_value = 0; /* for decoding */
|
uint32_t decoded_value = 0; /* for decoding */
|
||||||
int decoded_type = 0; /* for decoding */
|
uint16_t decoded_type = 0; /* for decoding */
|
||||||
|
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
/* tag 0 - subscriberProcessIdentifier */
|
/* tag 0 - subscriberProcessIdentifier */
|
||||||
@@ -506,7 +506,7 @@ int cov_subscribe_property_decode_service_request(
|
|||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
uint32_t decoded_value = 0; /* for decoding */
|
uint32_t decoded_value = 0; /* for decoding */
|
||||||
int decoded_type = 0; /* for decoding */
|
uint16_t decoded_type = 0; /* for decoding */
|
||||||
int property = 0; /* for decoding */
|
int property = 0; /* for decoding */
|
||||||
|
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ int iam_decode_service_request(
|
|||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int apdu_len = 0; /* total length of the apdu, return value */
|
int apdu_len = 0; /* total length of the apdu, return value */
|
||||||
int object_type = 0; /* should be a Device Object */
|
uint16_t object_type = 0; /* should be a Device Object */
|
||||||
uint32_t object_instance = 0;
|
uint32_t object_instance = 0;
|
||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ int ihave_decode_service_request(
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
int decoded_type = 0; /* for decoding */
|
uint16_t decoded_type = 0; /* for decoding */
|
||||||
|
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
/* deviceIdentifier */
|
/* deviceIdentifier */
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ int rp_decode_service_request(
|
|||||||
unsigned len = 0;
|
unsigned len = 0;
|
||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value_type = 0;
|
uint32_t len_value_type = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
int property = 0; /* for decoding */
|
int property = 0; /* for decoding */
|
||||||
uint32_t array_value = 0; /* for decoding */
|
uint32_t array_value = 0; /* for decoding */
|
||||||
|
|
||||||
@@ -214,7 +214,8 @@ int rp_ack_decode_service_request(
|
|||||||
uint32_t len_value_type = 0;
|
uint32_t len_value_type = 0;
|
||||||
int tag_len = 0; /* length of tag decode */
|
int tag_len = 0; /* length of tag decode */
|
||||||
int len = 0; /* total length of decodes */
|
int len = 0; /* total length of decodes */
|
||||||
int object = 0, property = 0; /* for decoding */
|
uint16_t object = 0; /* object type */
|
||||||
|
int property = 0; /* for decoding */
|
||||||
uint32_t array_value = 0; /* for decoding */
|
uint32_t array_value = 0; /* for decoding */
|
||||||
|
|
||||||
/* FIXME: check apdu_len against the len during decode */
|
/* FIXME: check apdu_len against the len during decode */
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ int rpm_decode_object_id(
|
|||||||
uint32_t * object_instance)
|
uint32_t * object_instance)
|
||||||
{
|
{
|
||||||
unsigned len = 0;
|
unsigned len = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
|
|
||||||
/* check for value pointers */
|
/* check for value pointers */
|
||||||
if (apdu && apdu_len && object_type && object_instance) {
|
if (apdu && apdu_len && object_type && object_instance) {
|
||||||
@@ -313,7 +313,7 @@ int rpm_ack_decode_object_id(
|
|||||||
uint32_t * object_instance)
|
uint32_t * object_instance)
|
||||||
{
|
{
|
||||||
unsigned len = 0;
|
unsigned len = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
|
|
||||||
/* check for value pointers */
|
/* check for value pointers */
|
||||||
if (apdu && apdu_len && object_type && object_instance) {
|
if (apdu && apdu_len && object_type && object_instance) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ int whohas_decode_service_request(
|
|||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value = 0;
|
uint32_t len_value = 0;
|
||||||
uint32_t decoded_value = 0; /* for decoding */
|
uint32_t decoded_value = 0; /* for decoding */
|
||||||
int decoded_type = 0; /* for decoding */
|
uint16_t decoded_type = 0; /* for decoding */
|
||||||
|
|
||||||
if (apdu_len && data) {
|
if (apdu_len && data) {
|
||||||
/* optional limits - must be used as a pair */
|
/* optional limits - must be used as a pair */
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ int wp_decode_service_request(
|
|||||||
int tag_len = 0;
|
int tag_len = 0;
|
||||||
uint8_t tag_number = 0;
|
uint8_t tag_number = 0;
|
||||||
uint32_t len_value_type = 0;
|
uint32_t len_value_type = 0;
|
||||||
int type = 0; /* for decoding */
|
uint16_t type = 0; /* for decoding */
|
||||||
int property = 0; /* for decoding */
|
int property = 0; /* for decoding */
|
||||||
uint32_t unsigned_value = 0;
|
uint32_t unsigned_value = 0;
|
||||||
int i = 0; /* loop counter */
|
int i = 0; /* loop counter */
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ DEFINES = -DBIG_ENDIAN=0 -DTEST -DTEST_DATE_TIME
|
|||||||
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
|
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
|
||||||
|
|
||||||
SRCS = $(SRC_DIR)/datetime.c \
|
SRCS = $(SRC_DIR)/datetime.c \
|
||||||
|
$(SRC_DIR)/bacdcode.c \
|
||||||
|
$(SRC_DIR)/bacint.c \
|
||||||
|
$(SRC_DIR)/bacstr.c \
|
||||||
|
$(SRC_DIR)/bacreal.c \
|
||||||
|
$(SRC_DIR)/bacapp.c \
|
||||||
|
$(SRC_DIR)/bactext.c \
|
||||||
|
$(SRC_DIR)/indtext.c \
|
||||||
ctest.c
|
ctest.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|||||||
Reference in New Issue
Block a user