Adjusted Device Object type decoding to use uint16_t rather than int. Corrected unit tests.

This commit is contained in:
skarg
2008-10-22 02:19:03 +00:00
parent 63ca977553
commit 35236bea22
15 changed files with 74 additions and 40 deletions
+5
View File
@@ -178,6 +178,11 @@ extern "C" {
BACNET_OCTET_STRING * octet_string);
size_t octetstring_capacity(
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
}
+1 -1
View File
@@ -95,7 +95,7 @@ int arf_decode_service_request(
int tag_len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu_len && data) {
+1 -1
View File
@@ -100,7 +100,7 @@ int awf_decode_service_request(
uint32_t len_value_type = 0;
int32_t signed_value = 0;
uint32_t unsigned_value = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu_len && data) {
+2 -2
View File
@@ -148,7 +148,7 @@ int bacapp_encode_application_data(
return apdu_len;
}
/* decode the data and store it into value.
/* decode the data and store it into value.
Return the number of octets consumed. */
int bacapp_decode_data(
uint8_t * apdu,
@@ -236,7 +236,7 @@ int bacapp_decode_data(
#if defined (BACAPP_OBJECT_ID)
case BACNET_APPLICATION_TAG_OBJECT_ID:
{
int object_type = 0;
uint16_t object_type = 0;
uint32_t instance = 0;
len = decode_object_id(&apdu[0], &object_type, &instance);
value->type.Object_Id.type = object_type;
+15 -16
View File
@@ -76,18 +76,18 @@
From clause 20.2.1.3.1
B'000' interpreted as Value = FALSE if application class == BOOLEAN
B'001' interpreted as Value = TRUE if application class == BOOLEAN
B'001' interpreted as Value = TRUE if application class == BOOLEAN
B'000' interpreted as Length = 0 if application class != BOOLEAN
B'001' interpreted as Length = 1
B'010' interpreted as Length = 2
B'011' interpreted as Length = 3
B'100' interpreted as Length = 4
B'000' interpreted as Length = 0 if application class != BOOLEAN
B'001' interpreted as Length = 1
B'010' interpreted as Length = 2
B'011' interpreted as Length = 3
B'100' interpreted as Length = 4
B'101' interpreted as Length > 4
B'110' interpreted as Type = Opening Tag
B'111' interpreted as Type = Closing Tag
*/
/* from clause 20.1.2.4 max-segments-accepted */
/* and clause 20.1.2.5 max-APDU-length-accepted */
@@ -721,7 +721,7 @@ int encode_context_bitstring(
/* returns the number of apdu bytes consumed */
int decode_object_id(
uint8_t * apdu,
int *object_type,
uint16_t *object_type,
uint32_t * instance)
{
uint32_t value = 0;
@@ -912,13 +912,13 @@ int decode_context_octet_string(
bool status = false;
uint32_t len_value = 0;
if (decode_is_context_tag(&apdu[len], tag_number))
if (decode_is_context_tag(&apdu[len], tag_number))
{
len += decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value);
status = octetstring_init(octet_string, &apdu[len], len_value);
if (status) {
len += len_value;
}
@@ -1022,7 +1022,7 @@ int decode_context_character_string(
bool status = false;
uint32_t len_value = 0;
if (decode_is_context_tag(&apdu[len], tag_number))
if (decode_is_context_tag(&apdu[len], tag_number))
{
len += decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value);
@@ -2203,7 +2203,7 @@ void testBACDCodeObject(
uint32_t decoded_instance = 0;
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);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
@@ -2213,7 +2213,7 @@ void testBACDCodeObject(
for (type = 0; type < 1024; type++) {
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
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);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
@@ -2586,8 +2586,7 @@ void testOctetStringContextDecodes(Test * pTest)
ct_test(pTest, outLen2 == -1);
ct_test(pTest, inLen == outLen);
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)
@@ -2690,7 +2689,7 @@ int main(
rc = ct_addTestFunction(pTest, testCharacterStringContextDecodes);
assert(rc);
rc = ct_addTestFunction(pTest, testFloatContextDecodes);
assert(rc);
+22
View File
@@ -539,6 +539,28 @@ size_t octetstring_capacity(
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
#include <assert.h>
#include <string.h>
+3 -3
View File
@@ -174,7 +174,7 @@ int cov_notify_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
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 */
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
@@ -360,7 +360,7 @@ int cov_subscribe_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
int decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* tag 0 - subscriberProcessIdentifier */
@@ -506,7 +506,7 @@ int cov_subscribe_property_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
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 */
if (apdu_len && data) {
+1 -1
View File
@@ -80,7 +80,7 @@ int iam_decode_service_request(
{
int len = 0;
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;
uint8_t tag_number = 0;
uint32_t len_value = 0;
+1 -1
View File
@@ -77,7 +77,7 @@ int ihave_decode_service_request(
int len = 0;
uint8_t tag_number = 0;
uint32_t len_value = 0;
int decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* deviceIdentifier */
+3 -2
View File
@@ -81,7 +81,7 @@ int rp_decode_service_request(
unsigned len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
int property = 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;
int tag_len = 0; /* length of tag decode */
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 */
/* FIXME: check apdu_len against the len during decode */
+2 -2
View File
@@ -113,7 +113,7 @@ int rpm_decode_object_id(
uint32_t * object_instance)
{
unsigned len = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu && apdu_len && object_type && object_instance) {
@@ -313,7 +313,7 @@ int rpm_ack_decode_object_id(
uint32_t * object_instance)
{
unsigned len = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu && apdu_len && object_type && object_instance) {
+1 -1
View File
@@ -88,7 +88,7 @@ int whohas_decode_service_request(
uint8_t tag_number = 0;
uint32_t len_value = 0;
uint32_t decoded_value = 0; /* for decoding */
int decoded_type = 0; /* for decoding */
uint16_t decoded_type = 0; /* for decoding */
if (apdu_len && data) {
/* optional limits - must be used as a pair */
+1 -1
View File
@@ -99,7 +99,7 @@ int wp_decode_service_request(
int tag_len = 0;
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
int type = 0; /* for decoding */
uint16_t type = 0; /* for decoding */
int property = 0; /* for decoding */
uint32_t unsigned_value = 0;
int i = 0; /* loop counter */
+5 -5
View File
@@ -22,18 +22,18 @@ OBJS = ${SRCS:.c=.o}
TARGET = bacapp
all: ${TARGET}
${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS}
${CC} -o $@ ${OBJS}
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf ${TARGET} $(OBJS)
rm -rf ${TARGET} $(OBJS)
include: .depend
+11 -4
View File
@@ -7,6 +7,13 @@ DEFINES = -DBIG_ENDIAN=0 -DTEST -DTEST_DATE_TIME
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
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
OBJS = ${SRCS:.c=.o}
@@ -14,17 +21,17 @@ OBJS = ${SRCS:.c=.o}
TARGET = datetime
all: ${TARGET}
${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS}
${CC} -o $@ ${OBJS}
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini