diff --git a/bacnet-stack/include/bacstr.h b/bacnet-stack/include/bacstr.h index 95c772b3..100298ff 100644 --- a/bacnet-stack/include/bacstr.h +++ b/bacnet-stack/include/bacstr.h @@ -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 } diff --git a/bacnet-stack/src/arf.c b/bacnet-stack/src/arf.c index dfdf2e72..f3d87899 100644 --- a/bacnet-stack/src/arf.c +++ b/bacnet-stack/src/arf.c @@ -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) { diff --git a/bacnet-stack/src/awf.c b/bacnet-stack/src/awf.c index 7060c268..cdb4257a 100644 --- a/bacnet-stack/src/awf.c +++ b/bacnet-stack/src/awf.c @@ -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) { diff --git a/bacnet-stack/src/bacapp.c b/bacnet-stack/src/bacapp.c index a687490d..ff286c83 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -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; diff --git a/bacnet-stack/src/bacdcode.c b/bacnet-stack/src/bacdcode.c index 4f4a48a3..fe0d74f3 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -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); diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index a556b085..2cf62248 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -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 #include diff --git a/bacnet-stack/src/cov.c b/bacnet-stack/src/cov.c index 5abbe355..57d4c075 100644 --- a/bacnet-stack/src/cov.c +++ b/bacnet-stack/src/cov.c @@ -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) { diff --git a/bacnet-stack/src/iam.c b/bacnet-stack/src/iam.c index 30b92050..c21bfbf6 100755 --- a/bacnet-stack/src/iam.c +++ b/bacnet-stack/src/iam.c @@ -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; diff --git a/bacnet-stack/src/ihave.c b/bacnet-stack/src/ihave.c index cad91d67..15847927 100644 --- a/bacnet-stack/src/ihave.c +++ b/bacnet-stack/src/ihave.c @@ -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 */ diff --git a/bacnet-stack/src/rp.c b/bacnet-stack/src/rp.c index 09102234..b7dd178c 100644 --- a/bacnet-stack/src/rp.c +++ b/bacnet-stack/src/rp.c @@ -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 */ diff --git a/bacnet-stack/src/rpm.c b/bacnet-stack/src/rpm.c index fadcb5c5..285644da 100644 --- a/bacnet-stack/src/rpm.c +++ b/bacnet-stack/src/rpm.c @@ -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) { diff --git a/bacnet-stack/src/whohas.c b/bacnet-stack/src/whohas.c index 0e34be17..572989b5 100644 --- a/bacnet-stack/src/whohas.c +++ b/bacnet-stack/src/whohas.c @@ -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 */ diff --git a/bacnet-stack/src/wp.c b/bacnet-stack/src/wp.c index c146f24c..1604e6c8 100644 --- a/bacnet-stack/src/wp.c +++ b/bacnet-stack/src/wp.c @@ -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 */ diff --git a/bacnet-stack/test/bacapp.mak b/bacnet-stack/test/bacapp.mak index 851312ba..f8d67f93 100644 --- a/bacnet-stack/test/bacapp.mak +++ b/bacnet-stack/test/bacapp.mak @@ -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 diff --git a/bacnet-stack/test/datetime.mak b/bacnet-stack/test/datetime.mak index 6564c654..a1a58a46 100644 --- a/bacnet-stack/test/datetime.mak +++ b/bacnet-stack/test/datetime.mak @@ -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