From e79bd532af43fc3b0901a11690598f0a1eb017a9 Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 7 Jan 2008 23:01:44 +0000 Subject: [PATCH] Updated atmega project. --- bacnet-stack/include/bacenum.h | 6 +-- bacnet-stack/include/bacstr.h | 6 +-- bacnet-stack/ports/atmega168/readme.txt | 17 ++++++++- bacnet-stack/src/bacstr.c | 49 ++++++++++++++----------- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/bacnet-stack/include/bacenum.h b/bacnet-stack/include/bacenum.h index 23c4339a..62986aec 100644 --- a/bacnet-stack/include/bacenum.h +++ b/bacnet-stack/include/bacenum.h @@ -806,9 +806,9 @@ typedef enum { BACNET_APPLICATION_TAG_DATE = 10, BACNET_APPLICATION_TAG_TIME = 11, BACNET_APPLICATION_TAG_OBJECT_ID = 12, - BACNET_APPLICATION_TAG_RESERVED1 = 13, - BACNET_APPLICATION_TAG_RESERVED2 = 14, - BACNET_APPLICATION_TAG_RESERVED3 = 15, + BACNET_APPLICATION_TAG_RESERVE1 = 13, + BACNET_APPLICATION_TAG_RESERVE2 = 14, + BACNET_APPLICATION_TAG_RESERVE3 = 15, MAX_BACNET_APPLICATION_TAG = 16 } BACNET_APPLICATION_TAG; diff --git a/bacnet-stack/include/bacstr.h b/bacnet-stack/include/bacstr.h index 6abd4f4f..289776bc 100644 --- a/bacnet-stack/include/bacstr.h +++ b/bacnet-stack/include/bacstr.h @@ -105,12 +105,12 @@ extern "C" { bool characterstring_init( BACNET_CHARACTER_STRING * char_string, uint8_t encoding, - char *value, + const char *value, size_t length); /* used for ANSI C-Strings */ bool characterstring_init_ansi( BACNET_CHARACTER_STRING * char_string, - char *value); + const char *value); bool characterstring_copy( BACNET_CHARACTER_STRING * dest, BACNET_CHARACTER_STRING * src); @@ -124,7 +124,7 @@ extern "C" { /* returns false if the string exceeds capacity */ bool characterstring_append( BACNET_CHARACTER_STRING * char_string, - char *value, + const char *value, size_t length); /* This function sets a new length without changing the value. If length exceeds capacity, no modification happens and diff --git a/bacnet-stack/ports/atmega168/readme.txt b/bacnet-stack/ports/atmega168/readme.txt index 3a51708b..d3e18252 100644 --- a/bacnet-stack/ports/atmega168/readme.txt +++ b/bacnet-stack/ports/atmega168/readme.txt @@ -101,6 +101,19 @@ MISRA C Extra Options Use command line options (not enabled) -Hopefully you find it useful! +Note: The BACnet Stack at Sourceforge source code has to be built +with lots of different compilers. The IAR compiler has particularly +strong (pedantic) source checking and generates several warnings when +compiling the source code. Unfortunately not all warnings can be +fixed by modifying the source code. Some warnings have therefore been +disabled in the project file. + Compiler Diagnostics: + (Pe550) I initilize all local variables as a best practice. + Linker Diagnostics: + (w31) The supplied standard libraries expect char parameters to + be unsigned (in functions such as strncpy(), etc.). It may + be possible to recompile the libraries with signed plain char's. -Steve Karg +Hopefully you find this code useful! + +Steve Karg diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index 6bb96596..43d55c25 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -59,13 +59,15 @@ void bitstring_set_bit( if (byte_number < MAX_BITSTRING_BYTES) { /* set max bits used */ - if (bit_string->bits_used < (bit_number + 1)) + if (bit_string->bits_used < (bit_number + 1)) { bit_string->bits_used = bit_number + 1; + } bit_mask = bit_mask << (bit_number - (byte_number * 8)); - if (value) + if (value) { bit_string->value[byte_number] |= bit_mask; - else + } else { bit_string->value[byte_number] &= (~(bit_mask)); + } } } @@ -79,8 +81,9 @@ bool bitstring_bit( if (bit_number < (MAX_BITSTRING_BYTES * 8)) { bit_mask = bit_mask << (bit_number - (byte_number * 8)); - if (bit_string->value[byte_number] & bit_mask) + if (bit_string->value[byte_number] & bit_mask) { value = true; + } } return value; @@ -113,13 +116,13 @@ int bitstring_bytes_used( uint8_t bitstring_octet( BACNET_BIT_STRING * bit_string, - uint8_t index) + uint8_t octet_index) { uint8_t octet = 0; if (bit_string) { - if (index < MAX_BITSTRING_BYTES) { - octet = bit_string->value[index]; + if (octet_index < MAX_BITSTRING_BYTES) { + octet = bit_string->value[octet_index]; } } @@ -163,10 +166,11 @@ bool bitstring_set_bits_used( uint8_t bitstring_bits_capacity( BACNET_BIT_STRING * bit_string) { - if (bit_string) + if (bit_string) { return (sizeof(bit_string->value) * 8); - else + } else { return 0; + } } bool bitstring_copy( @@ -193,7 +197,7 @@ bool bitstring_copy( bool characterstring_init( BACNET_CHARACTER_STRING * char_string, uint8_t encoding, - char *value, + const char *value, size_t length) { bool status = false; /* return value */ @@ -210,8 +214,9 @@ bool characterstring_init( if (i < length) { char_string->value[char_string->length] = value[i]; char_string->length++; - } else + } else { char_string->value[i] = 0; + } } } else { for (i = 0; i < MAX_CHARACTER_STRING_BYTES; i++) { @@ -227,7 +232,7 @@ bool characterstring_init( bool characterstring_init_ansi( BACNET_CHARACTER_STRING * char_string, - char *value) + const char *value) { return characterstring_init(char_string, CHARACTER_ANSI_X34, value, value ? strlen(value) : 0); @@ -252,19 +257,20 @@ bool characterstring_same( if (src && dest) { if ((src->length == dest->length) && (src->encoding == dest->encoding)) { same_status = true; - for (i = 0; i < src->length; i++) { + for (i = 0; (i < src->length) && same_status; i++) { if (src->value[i] != dest->value[i]) { same_status = false; - break; } } } } else if (src) { - if (src->length == 0) + if (src->length == 0) { same_status = true; + } } else if (dest) { - if (dest->length == 0) + if (dest->length == 0) { same_status = true; + } } return same_status; @@ -281,21 +287,22 @@ bool characterstring_ansi_same( if ((dest->length == strlen(src)) && (dest->encoding == CHARACTER_ANSI_X34)) { same_status = true; - for (i = 0; i < dest->length; i++) { + for (i = 0; (i < dest->length) && same_status; i++) { if (src[i] != dest->value[i]) { same_status = false; - break; } } } } /* NULL matches an empty string in our world */ else if (src) { - if (strlen(src) == 0) + if (strlen(src) == 0) { same_status = true; + } } else if (dest) { - if (dest->length == 0) + if (dest->length == 0) { same_status = true; + } } return same_status; @@ -304,7 +311,7 @@ bool characterstring_ansi_same( /* returns false if the string exceeds capacity */ bool characterstring_append( BACNET_CHARACTER_STRING * char_string, - char *value, + const char *value, size_t length) { size_t i; /* counter */