From a30d4976692e0d90944a0d87ce755e68f49ce901 Mon Sep 17 00:00:00 2001 From: skarg Date: Sun, 13 Aug 2006 00:57:17 +0000 Subject: [PATCH] indented. --- bacnet-stack/apdu.c | 3 +- bacnet-stack/apdu.h | 2 +- bacnet-stack/bacapp.c | 113 ++++--- bacnet-stack/bacapp.h | 10 +- bacnet-stack/bacdcode.c | 84 ++--- bacnet-stack/bactext.h | 12 +- bacnet-stack/bip.c | 6 +- bacnet-stack/bip.h | 2 +- bacnet-stack/cov.c | 2 +- bacnet-stack/datalink.c | 2 +- bacnet-stack/datalink.h | 2 +- bacnet-stack/demo/handler/h_arf.c | 35 ++- bacnet-stack/demo/handler/h_arf_a.c | 11 +- bacnet-stack/demo/handler/h_dcc.c | 28 +- bacnet-stack/demo/handler/h_iam.c | 12 +- bacnet-stack/demo/handler/h_ihave.c | 8 +- bacnet-stack/demo/handler/h_rd.c | 28 +- bacnet-stack/demo/handler/h_rp.c | 73 ++--- bacnet-stack/demo/handler/h_wp.c | 88 +++--- bacnet-stack/demo/handler/noserv.c | 4 +- bacnet-stack/demo/handler/s_arfs.c | 18 +- bacnet-stack/demo/handler/s_awfs.c | 23 +- bacnet-stack/demo/handler/s_dcc.c | 18 +- bacnet-stack/demo/handler/s_ihave.c | 7 +- bacnet-stack/demo/handler/s_rd.c | 18 +- bacnet-stack/demo/handler/s_rp.c | 18 +- bacnet-stack/demo/handler/s_ts.c | 8 +- bacnet-stack/demo/handler/s_whohas.c | 11 +- bacnet-stack/demo/handler/s_whois.c | 4 +- bacnet-stack/demo/handler/s_wp.c | 18 +- bacnet-stack/demo/object/bacfile.c | 16 +- bacnet-stack/demo/readfile/readfile.c | 3 +- bacnet-stack/demo/writefile/writefile.c | 3 +- bacnet-stack/dlmstp.h | 19 +- bacnet-stack/iam.c | 5 +- bacnet-stack/npdu.c | 25 +- bacnet-stack/npdu.h | 2 +- bacnet-stack/ports/pic18/dlmstp.c | 394 ++++++++++++------------ bacnet-stack/ports/pic18/main.c | 5 +- bacnet-stack/ports/pic18/rs485.c | 2 +- bacnet-stack/tsm.c | 5 +- 41 files changed, 574 insertions(+), 573 deletions(-) diff --git a/bacnet-stack/apdu.c b/bacnet-stack/apdu.c index d339ea46..4bca44b8 100644 --- a/bacnet-stack/apdu.c +++ b/bacnet-stack/apdu.c @@ -272,8 +272,7 @@ uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */ return len; } -void apdu_handler(BACNET_ADDRESS * src, - uint8_t * apdu, /* APDU data */ +void apdu_handler(BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */ uint16_t apdu_len) { BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; diff --git a/bacnet-stack/apdu.h b/bacnet-stack/apdu.h index f1a6e07a..4554e315 100644 --- a/bacnet-stack/apdu.h +++ b/bacnet-stack/apdu.h @@ -149,7 +149,7 @@ extern "C" { uint8_t ** service_request, uint16_t * service_request_len); void apdu_handler(BACNET_ADDRESS * src, /* source address */ - uint8_t * apdu, /* APDU data */ + uint8_t * apdu, /* APDU data */ uint16_t pdu_len); /* for confirmed messages */ #ifdef __cplusplus diff --git a/bacnet-stack/bacapp.c b/bacnet-stack/bacapp.c index 766b7e6a..07eac39e 100644 --- a/bacnet-stack/bacapp.c +++ b/bacnet-stack/bacapp.c @@ -48,65 +48,61 @@ int bacapp_encode_application_data(uint8_t * apdu, { int apdu_len = 0; /* total length of the apdu, return value */ - if (value && apdu) - { + if (value && apdu) { switch (value->tag) { - case BACNET_APPLICATION_TAG_NULL: - apdu[0] = value->tag; - apdu_len++; - break; - case BACNET_APPLICATION_TAG_BOOLEAN: - apdu_len = encode_tagged_boolean(&apdu[0], - value->type.Boolean); - break; - case BACNET_APPLICATION_TAG_UNSIGNED_INT: - apdu_len = encode_tagged_unsigned(&apdu[0], - value->type.Unsigned_Int); - break; - case BACNET_APPLICATION_TAG_SIGNED_INT: - apdu_len = encode_tagged_signed(&apdu[0], - value->type.Signed_Int); - break; - case BACNET_APPLICATION_TAG_REAL: - apdu_len = encode_tagged_real(&apdu[0], - value->type.Real); - break; - case BACNET_APPLICATION_TAG_ENUMERATED: - apdu_len = encode_tagged_enumerated(&apdu[0], - value->type.Enumerated); - break; - case BACNET_APPLICATION_TAG_DATE: - apdu_len = encode_tagged_date(&apdu[0], - &value->type.Date); - break; - case BACNET_APPLICATION_TAG_TIME: - apdu_len = encode_tagged_time(&apdu[0], - &value->type.Time); - break; - case BACNET_APPLICATION_TAG_OBJECT_ID: - apdu_len = encode_tagged_object_id(&apdu[0], - value->type.Object_Id.type, - value->type.Object_Id.instance); - break; - case BACNET_APPLICATION_TAG_OCTET_STRING: - apdu_len = encode_tagged_octet_string(&apdu[0], - &value->type.Octet_String); - break; - case BACNET_APPLICATION_TAG_CHARACTER_STRING: - apdu_len = encode_tagged_character_string(&apdu[0], - &value->type.Character_String); - break; - case BACNET_APPLICATION_TAG_BIT_STRING: - apdu_len = encode_tagged_bitstring(&apdu[0], - &value->type.Bit_String); - break; - case BACNET_APPLICATION_TAG_DOUBLE: - /* FIXME: double is not implemented yet. - apdu_len = encode_tagged_double(&apdu[0], - value->type.Double); - */ - default: - break; + case BACNET_APPLICATION_TAG_NULL: + apdu[0] = value->tag; + apdu_len++; + break; + case BACNET_APPLICATION_TAG_BOOLEAN: + apdu_len = encode_tagged_boolean(&apdu[0], + value->type.Boolean); + break; + case BACNET_APPLICATION_TAG_UNSIGNED_INT: + apdu_len = encode_tagged_unsigned(&apdu[0], + value->type.Unsigned_Int); + break; + case BACNET_APPLICATION_TAG_SIGNED_INT: + apdu_len = encode_tagged_signed(&apdu[0], + value->type.Signed_Int); + break; + case BACNET_APPLICATION_TAG_REAL: + apdu_len = encode_tagged_real(&apdu[0], value->type.Real); + break; + case BACNET_APPLICATION_TAG_ENUMERATED: + apdu_len = encode_tagged_enumerated(&apdu[0], + value->type.Enumerated); + break; + case BACNET_APPLICATION_TAG_DATE: + apdu_len = encode_tagged_date(&apdu[0], &value->type.Date); + break; + case BACNET_APPLICATION_TAG_TIME: + apdu_len = encode_tagged_time(&apdu[0], &value->type.Time); + break; + case BACNET_APPLICATION_TAG_OBJECT_ID: + apdu_len = encode_tagged_object_id(&apdu[0], + value->type.Object_Id.type, + value->type.Object_Id.instance); + break; + case BACNET_APPLICATION_TAG_OCTET_STRING: + apdu_len = encode_tagged_octet_string(&apdu[0], + &value->type.Octet_String); + break; + case BACNET_APPLICATION_TAG_CHARACTER_STRING: + apdu_len = encode_tagged_character_string(&apdu[0], + &value->type.Character_String); + break; + case BACNET_APPLICATION_TAG_BIT_STRING: + apdu_len = encode_tagged_bitstring(&apdu[0], + &value->type.Bit_String); + break; + case BACNET_APPLICATION_TAG_DOUBLE: + /* FIXME: double is not implemented yet. + apdu_len = encode_tagged_double(&apdu[0], + value->type.Double); + */ + default: + break; } } @@ -491,6 +487,7 @@ bool bacapp_same_time(BACNET_TIME * time1, BACNET_TIME * time2) return status; } + /* generic - can be used by other unit tests returns true if matching or same, false if different */ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value, diff --git a/bacnet-stack/bacapp.h b/bacnet-stack/bacapp.h index f37f2283..c5841d8d 100644 --- a/bacnet-stack/bacapp.h +++ b/bacnet-stack/bacapp.h @@ -73,11 +73,11 @@ extern "C" { BACNET_APPLICATION_DATA_VALUE * src_value); #if PRINT_ENABLED - #define BACAPP_PRINT_ENABLED +#define BACAPP_PRINT_ENABLED #else - #ifdef TEST - #define BACAPP_PRINT_ENABLED - #endif +#ifdef TEST +#define BACAPP_PRINT_ENABLED +#endif #endif #ifdef BACAPP_PRINT_ENABLED @@ -96,7 +96,7 @@ extern "C" { bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE * value, BACNET_APPLICATION_DATA_VALUE * test_value); -void testBACnetApplicationData(Test * pTest); + void testBACnetApplicationData(Test * pTest); #endif #ifdef __cplusplus diff --git a/bacnet-stack/bacdcode.c b/bacnet-stack/bacdcode.c index 7271c09e..be16d334 100644 --- a/bacnet-stack/bacdcode.c +++ b/bacnet-stack/bacdcode.c @@ -195,13 +195,13 @@ int encode_unsigned16(uint8_t * apdu, uint16_t value) 0}}; short_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = short_data.byte[0]; apdu[1] = short_data.byte[1]; - #else +#else apdu[0] = short_data.byte[1]; apdu[1] = short_data.byte[0]; - #endif +#endif return 2; } @@ -214,13 +214,13 @@ int decode_unsigned16(uint8_t * apdu, uint16_t * value) } short_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN short_data.byte[0] = apdu[0]; short_data.byte[1] = apdu[1]; - #else +#else short_data.byte[1] = apdu[0]; short_data.byte[0] = apdu[1]; - #endif +#endif if (value) *value = short_data.value; @@ -236,15 +236,15 @@ int encode_unsigned24(uint8_t * apdu, uint32_t value) 0}}; long_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = long_data.byte[1]; apdu[1] = long_data.byte[2]; apdu[2] = long_data.byte[3]; - #else +#else apdu[0] = long_data.byte[2]; apdu[1] = long_data.byte[1]; apdu[2] = long_data.byte[0]; - #endif +#endif return 3; } @@ -257,15 +257,15 @@ int decode_unsigned24(uint8_t * apdu, uint32_t * value) } long_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN long_data.byte[1] = apdu[0]; long_data.byte[2] = apdu[1]; long_data.byte[3] = apdu[2]; - #else +#else long_data.byte[2] = apdu[0]; long_data.byte[1] = apdu[1]; long_data.byte[0] = apdu[2]; - #endif +#endif if (value) *value = long_data.value; @@ -281,17 +281,17 @@ int encode_unsigned32(uint8_t * apdu, uint32_t value) 0}}; long_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = long_data.byte[0]; apdu[1] = long_data.byte[1]; apdu[2] = long_data.byte[2]; apdu[3] = long_data.byte[3]; - #else +#else apdu[0] = long_data.byte[3]; apdu[1] = long_data.byte[2]; apdu[2] = long_data.byte[1]; apdu[3] = long_data.byte[0]; - #endif +#endif return 4; } @@ -304,17 +304,17 @@ int decode_unsigned32(uint8_t * apdu, uint32_t * value) } long_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN long_data.byte[0] = apdu[0]; long_data.byte[1] = apdu[1]; long_data.byte[2] = apdu[2]; long_data.byte[3] = apdu[3]; - #else +#else long_data.byte[3] = apdu[0]; long_data.byte[2] = apdu[1]; long_data.byte[1] = apdu[2]; long_data.byte[0] = apdu[3]; - #endif +#endif if (value) *value = long_data.value; @@ -359,13 +359,13 @@ int encode_signed16(uint8_t * apdu, int16_t value) 0}}; short_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = short_data.byte[0]; apdu[1] = short_data.byte[1]; - #else +#else apdu[0] = short_data.byte[1]; apdu[1] = short_data.byte[0]; - #endif +#endif return 2; } @@ -378,13 +378,13 @@ int decode_signed16(uint8_t * apdu, int16_t * value) } short_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN short_data.byte[0] = apdu[0]; short_data.byte[1] = apdu[1]; - #else +#else short_data.byte[1] = apdu[0]; short_data.byte[0] = apdu[1]; - #endif +#endif if (value) *value = short_data.value; @@ -400,15 +400,15 @@ int encode_signed24(uint8_t * apdu, int32_t value) 0}}; long_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = long_data.byte[1]; apdu[1] = long_data.byte[2]; apdu[2] = long_data.byte[3]; - #else +#else apdu[0] = long_data.byte[2]; apdu[1] = long_data.byte[1]; apdu[2] = long_data.byte[0]; - #endif +#endif return 3; } @@ -421,7 +421,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value) } long_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN /* negative - bit 7 is set */ if (apdu[0] & 0x80) long_data.byte[0] = 0xFF; @@ -429,7 +429,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value) long_data.byte[1] = apdu[0]; long_data.byte[2] = apdu[1]; long_data.byte[3] = apdu[2]; - #else +#else /* negative - bit 7 is set */ if (apdu[0] & 0x80) long_data.byte[3] = 0xFF; @@ -437,7 +437,7 @@ int decode_signed24(uint8_t * apdu, int32_t * value) long_data.byte[2] = apdu[0]; long_data.byte[1] = apdu[1]; long_data.byte[0] = apdu[2]; - #endif +#endif if (value) *value = long_data.value; @@ -453,17 +453,17 @@ int encode_signed32(uint8_t * apdu, int32_t value) 0}}; long_data.value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = long_data.byte[0]; apdu[1] = long_data.byte[1]; apdu[2] = long_data.byte[2]; apdu[3] = long_data.byte[3]; - #else +#else apdu[0] = long_data.byte[3]; apdu[1] = long_data.byte[2]; apdu[2] = long_data.byte[1]; apdu[3] = long_data.byte[0]; - #endif +#endif return 4; } @@ -476,17 +476,17 @@ int decode_signed32(uint8_t * apdu, int32_t * value) } long_data = { { 0}}; - #if BIG_ENDIAN +#if BIG_ENDIAN long_data.byte[0] = apdu[0]; long_data.byte[1] = apdu[1]; long_data.byte[2] = apdu[2]; long_data.byte[3] = apdu[3]; - #else +#else long_data.byte[3] = apdu[0]; long_data.byte[2] = apdu[1]; long_data.byte[1] = apdu[2]; long_data.byte[0] = apdu[3]; - #endif +#endif if (value) *value = long_data.value; @@ -876,17 +876,17 @@ int decode_real(uint8_t * apdu, float *real_value) } my_data; /* NOTE: assumes the compiler stores float as IEEE-754 float */ - #if BIG_ENDIAN +#if BIG_ENDIAN my_data.byte[0] = apdu[0]; my_data.byte[1] = apdu[1]; my_data.byte[2] = apdu[2]; my_data.byte[3] = apdu[3]; - #else +#else my_data.byte[0] = apdu[3]; my_data.byte[1] = apdu[2]; my_data.byte[2] = apdu[1]; my_data.byte[3] = apdu[0]; - #endif +#endif *real_value = my_data.real_value; @@ -904,17 +904,17 @@ int encode_bacnet_real(float value, uint8_t * apdu) /* NOTE: assumes the compiler stores float as IEEE-754 float */ my_data.real_value = value; - #if BIG_ENDIAN +#if BIG_ENDIAN apdu[0] = my_data.byte[0]; apdu[1] = my_data.byte[1]; apdu[2] = my_data.byte[2]; apdu[3] = my_data.byte[3]; - #else +#else apdu[0] = my_data.byte[3]; apdu[1] = my_data.byte[2]; apdu[2] = my_data.byte[1]; apdu[3] = my_data.byte[0]; - #endif +#endif return 4; } diff --git a/bacnet-stack/bactext.h b/bacnet-stack/bactext.h index a5a40338..2e961c7e 100644 --- a/bacnet-stack/bactext.h +++ b/bacnet-stack/bactext.h @@ -36,11 +36,11 @@ /* tiny implementations have no need to print */ #if PRINT_ENABLED - #define BACTEXT_PRINT_ENABLED +#define BACTEXT_PRINT_ENABLED #else - #ifdef TEST - #define BACTEXT_PRINT_ENABLED - #endif +#ifdef TEST +#define BACTEXT_PRINT_ENABLED +#endif #endif #ifdef BACTEXT_PRINT_ENABLED @@ -77,7 +77,5 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - -#endif /* BACTEXT_PRINT_ENABLED */ - +#endif /* BACTEXT_PRINT_ENABLED */ #endif diff --git a/bacnet-stack/bip.c b/bacnet-stack/bip.c index df09931c..d4c2ad25 100644 --- a/bacnet-stack/bip.c +++ b/bacnet-stack/bip.c @@ -139,7 +139,7 @@ uint16_t bip_get_port(void) /* function to send a packet out the BACnet/IP socket (Annex J) */ /* returns number of bytes sent on success, negative number on failure */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ @@ -152,7 +152,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ /* assumes that the driver has already been initialized */ if (BIP_Socket < 0) return BIP_Socket; - + mtu[0] = BVLL_TYPE_BACNET_IP; bip_dest.sin_family = AF_INET; if (dest->mac_len == 6) { @@ -177,7 +177,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ mtu_len += 4; memcpy(&mtu[mtu_len], pdu, pdu_len); mtu_len += pdu_len; - encode_unsigned16(&mtu[2],mtu_len); + encode_unsigned16(&mtu[2], mtu_len); /* Send the packet */ bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0, diff --git a/bacnet-stack/bip.h b/bacnet-stack/bip.h index a997e433..b6aea1e5 100644 --- a/bacnet-stack/bip.h +++ b/bacnet-stack/bip.h @@ -65,7 +65,7 @@ extern "C" { /* function to send a packet out the BACnet/IP socket */ /* returns zero on success, non-zero on failure */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len); /* number of bytes of data */ diff --git a/bacnet-stack/cov.c b/bacnet-stack/cov.c index 77ffbba9..75172cbb 100644 --- a/bacnet-stack/cov.c +++ b/bacnet-stack/cov.c @@ -360,7 +360,7 @@ void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu, /* dummy function stubs */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ diff --git a/bacnet-stack/datalink.c b/bacnet-stack/datalink.c index 0e834389..c25eeae9 100644 --- a/bacnet-stack/datalink.c +++ b/bacnet-stack/datalink.c @@ -42,7 +42,7 @@ /* returns number of bytes sent on success, negative on failure */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index 6451e69a..61022ccc 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -62,7 +62,7 @@ extern "C" { /* returns number of bytes sent on success, negative on failure */ int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len); /* number of bytes of data */ diff --git a/bacnet-stack/demo/handler/h_arf.c b/bacnet-stack/demo/handler/h_arf.c index 5d9d4955..8aba4506 100644 --- a/bacnet-stack/demo/handler/h_arf.c +++ b/bacnet-stack/demo/handler/h_arf.c @@ -52,31 +52,32 @@ void handler_atomic_read_file(uint8_t * service_request, int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Received Atomic-Read-File Request!\n"); - #endif +#endif len = arf_decode_service_request(service_request, service_len, &data); /* prepare a reply */ /* bad decoding - send an abort */ if (len < 0) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_OTHER); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Bad Encoding. Sending Abort!\n"); - #endif +#endif } else if (service_data->segmented_message) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Segmented Message. Sending Abort!\n"); - #endif +#endif } else { if (data.access == FILE_STREAM_ACCESS) { if (data.type.stream.requestedOctetCount < octetstring_capacity(&data.fileData)) { if (bacfile_read_data(&data)) { - pdu_len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[0], + pdu_len = + arf_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); } else { error = true; @@ -86,27 +87,29 @@ void handler_atomic_read_file(uint8_t * service_request, abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Too Big To Send. Sending Abort!\n"); - #endif +#endif } } else { - pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE, - ERROR_CLASS_SERVICES, ERROR_CODE_INVALID_FILE_ACCESS_METHOD); - #if PRINT_ENABLED + pdu_len = + bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_ATOMIC_READ_FILE, ERROR_CLASS_SERVICES, + ERROR_CODE_INVALID_FILE_ACCESS_METHOD); +#if PRINT_ENABLED fprintf(stderr, "Record Access Requested. Sending Error!\n"); - #endif +#endif } } npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); } - #endif +#endif return; } diff --git a/bacnet-stack/demo/handler/h_arf_a.c b/bacnet-stack/demo/handler/h_arf_a.c index 956bfc6d..1562c0e5 100644 --- a/bacnet-stack/demo/handler/h_arf_a.c +++ b/bacnet-stack/demo/handler/h_arf_a.c @@ -62,9 +62,9 @@ void handler_atomic_read_file_ack(uint8_t * service_request, instance = bacfile_instance_from_tsm(service_data->invoke_id); len = arf_ack_decode_service_request(service_request, service_len, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Received Read-File Ack!\n"); - #endif +#endif if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) { /* write the data received to the file specified */ if (data.access == FILE_STREAM_ACCESS) { @@ -76,12 +76,11 @@ void handler_atomic_read_file_ack(uint8_t * service_request, data.type.stream.fileStartPosition, SEEK_SET); if (fwrite(octetstring_value(&data.fileData), octetstring_length(&data.fileData), 1, - pFile) != 1) - { - #if PRINT_ENABLED + pFile) != 1) { +#if PRINT_ENABLED fprintf(stderr, "Failed to write to %s (%u)!\n", pFilename, instance); - #endif +#endif } fclose(pFile); } diff --git a/bacnet-stack/demo/handler/h_dcc.c b/bacnet-stack/demo/handler/h_dcc.c index 3e67b8cb..53bd62be 100644 --- a/bacnet-stack/demo/handler/h_dcc.c +++ b/bacnet-stack/demo/handler/h_dcc.c @@ -55,46 +55,46 @@ void handler_device_communication_control(uint8_t * service_request, /* decode the service request only */ len = dcc_decode_service_request(service_request, service_len, &timeDuration, &state, &password); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl!\n"); if (len > 0) fprintf(stderr, "DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n", (unsigned) timeDuration, (unsigned) state, characterstring_value(&password)); - #endif +#endif /* bad decoding or something we didn't understand - send an abort */ if (len < 0) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_OTHER); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Sending Abort - could not decode.\n"); - #endif +#endif } else if (service_data->segmented_message) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Sending Abort - segmented message.\n"); - #endif +#endif } else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) { pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Sending Reject - undefined enumeration\n"); - #endif +#endif } else { if (characterstring_ansi_same(&password, My_Password)) { pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Sending Simple Ack!\n"); - #endif +#endif dcc_set_status_duration(state, timeDuration); } else { pdu_len = @@ -102,21 +102,21 @@ void handler_device_communication_control(uint8_t * service_request, service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Sending Error - password failure.\n"); - #endif +#endif } } npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n", strerror(errno)); - #endif +#endif return; } diff --git a/bacnet-stack/demo/handler/h_iam.c b/bacnet-stack/demo/handler/h_iam.c index aee70359..58737886 100644 --- a/bacnet-stack/demo/handler/h_iam.c +++ b/bacnet-stack/demo/handler/h_iam.c @@ -44,18 +44,18 @@ void handler_i_am_add(uint8_t * service_request, (void) service_len; len = iam_decode_service_request(service_request, &device_id, &max_apdu, &segmentation, &vendor_id); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Received I-Am Request"); - #endif +#endif if (len != -1) { - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, " from %u!\n", device_id); - #endif +#endif address_add(device_id, max_apdu, src); } else { - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "!\n"); - #endif +#endif } return; diff --git a/bacnet-stack/demo/handler/h_ihave.c b/bacnet-stack/demo/handler/h_ihave.c index 92447c49..d1d39a71 100644 --- a/bacnet-stack/demo/handler/h_ihave.c +++ b/bacnet-stack/demo/handler/h_ihave.c @@ -43,17 +43,17 @@ void handler_i_have(uint8_t * service_request, len = ihave_decode_service_request(service_request, service_len, &data); if (len != -1) { - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "I-Have: %s %d from %s %u!\r\n", bactext_object_type_name(data.object_id.type), data.object_id.instance, bactext_object_type_name(data.device_id.type), data.device_id.instance); - #endif +#endif } else { - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "I-Have: received, but unable to decode!\n"); - #endif +#endif } return; diff --git a/bacnet-stack/demo/handler/h_rd.c b/bacnet-stack/demo/handler/h_rd.c index 0913162b..501b9b03 100644 --- a/bacnet-stack/demo/handler/h_rd.c +++ b/bacnet-stack/demo/handler/h_rd.c @@ -55,46 +55,46 @@ void handler_reinitialize_device(uint8_t * service_request, /* decode the service request only */ len = rd_decode_service_request(service_request, service_len, &state, &their_password); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice!\n"); if (len > 0) fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n", (unsigned) state, characterstring_value(&their_password)); else fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); - #endif +#endif /* bad decoding or something we didn't understand - send an abort */ if (len < 0) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_OTHER); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Abort - could not decode.\n"); - #endif +#endif } else if (service_data->segmented_message) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Abort - segmented message.\n"); - #endif +#endif } else if (state >= MAX_BACNET_REINITIALIZED_STATE) { pdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Reject - undefined enumeration\n"); - #endif +#endif } else { characterstring_init_ansi(&My_Password, Password); if (characterstring_same(&their_password, &My_Password)) { pdu_len = encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n"); - #endif +#endif /* FIXME: now you can reboot, restart, quit, or something clever */ /* Note: you can use a mix of state and password to do specific stuff */ /* Note: if you don't do something clever like actually restart, @@ -105,20 +105,20 @@ void handler_reinitialize_device(uint8_t * service_request, service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE, ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Error - password failure.\n"); - #endif +#endif } } npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", strerror(errno)); - #endif +#endif return; } diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index db39a3a2..98d2c2b9 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -66,25 +66,25 @@ void handler_read_property(uint8_t * service_request, BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; len = rp_decode_service_request(service_request, service_len, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED if (len <= 0) fprintf(stderr, "Unable to decode Read-Property Request!\n"); - #endif +#endif /* bad decoding - send an abort */ if (len < 0) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_OTHER); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Abort!\n"); - #endif +#endif send = true; } else if (service_data->segmented_message) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Abort!\n"); - #endif +#endif send = true; } else { switch (data.object_type) { @@ -99,12 +99,13 @@ void handler_read_property(uint8_t * service_request, data.application_data = &Temp_Buf[0]; data.application_data_len = len; /* FIXME: probably need a length limitation sent with encode */ - pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], + pdu_len = + rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for Device!\n"); - #endif +#endif send = true; } else error = true; @@ -125,9 +126,9 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for AI!\n"); - #endif +#endif send = true; } else error = true; @@ -148,9 +149,9 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for BI!\n"); - #endif +#endif send = true; } else error = true; @@ -168,11 +169,12 @@ void handler_read_property(uint8_t * service_request, data.application_data = &Temp_Buf[0]; data.application_data_len = len; /* FIXME: probably need a length limitation sent with encode */ - pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], - service_data->invoke_id, &data); - #if PRINT_ENABLED + pdu_len = + rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], + service_data->invoke_id, &data); +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for BO!\n"); - #endif +#endif send = true; } else error = true; @@ -193,9 +195,9 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for BV!\n"); - #endif +#endif send = true; } else error = true; @@ -216,9 +218,9 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for AO!\n"); - #endif +#endif send = true; } else error = true; @@ -239,9 +241,9 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for AV!\n"); - #endif +#endif send = true; } else error = true; @@ -262,10 +264,10 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for LSP!\n"); - #endif +#endif send = true; } else error = true; @@ -286,10 +288,10 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for MSO!\n"); - #endif +#endif send = true; } else error = true; @@ -311,17 +313,17 @@ void handler_read_property(uint8_t * service_request, pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Ack for File!\n"); - #endif +#endif send = true; } else error = true; } else error = true; break; -#endif /* BACFILE */ +#endif /* BACFILE */ default: error = true; break; @@ -331,19 +333,18 @@ void handler_read_property(uint8_t * service_request, pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Read Property Error!\n"); - #endif +#endif send = true; } if (send) { npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - bytes_sent = datalink_send_pdu(src, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ - #if PRINT_ENABLED + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); - #endif +#endif } return; diff --git a/bacnet-stack/demo/handler/h_wp.c b/bacnet-stack/demo/handler/h_wp.c index 5e2f69d9..8dc4264a 100644 --- a/bacnet-stack/demo/handler/h_wp.c +++ b/bacnet-stack/demo/handler/h_wp.c @@ -64,7 +64,7 @@ void handler_write_property(uint8_t * service_request, /* decode the service request only */ len = wp_decode_service_request(service_request, service_len, &wp_data); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Received Write-Property Request!\n"); if (len > 0) fprintf(stderr, "type=%u instance=%u property=%u index=%d\n", @@ -73,21 +73,21 @@ void handler_write_property(uint8_t * service_request, wp_data.object_property, wp_data.array_index); else fprintf(stderr, "Unable to decode Write-Property Request!\n"); - #endif +#endif /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_OTHER); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Abort!\n"); - #endif +#endif } else if (service_data->segmented_message) { pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Abort!\n"); - #endif +#endif } else { switch (wp_data.object_type) { case OBJECT_DEVICE: @@ -96,20 +96,20 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for Device!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Error for Device!\n"); - #endif +#endif } break; case OBJECT_ANALOG_INPUT: @@ -120,9 +120,9 @@ void handler_write_property(uint8_t * service_request, bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error!\n"); - #endif +#endif break; case OBJECT_BINARY_OUTPUT: if (Binary_Output_Write_Property(&wp_data, &error_class, @@ -131,19 +131,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for BO!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for BO!\n"); - #endif +#endif } break; case OBJECT_BINARY_VALUE: @@ -153,19 +153,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for BV!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for BV!\n"); - #endif +#endif } break; case OBJECT_ANALOG_OUTPUT: @@ -175,19 +175,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for AO!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for AO!\n"); - #endif +#endif } break; case OBJECT_ANALOG_VALUE: @@ -197,19 +197,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for AV!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for AV!\n"); - #endif +#endif } break; case OBJECT_LIFE_SAFETY_POINT: @@ -219,19 +219,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for LSP!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for LSP!\n"); - #endif +#endif } break; case OBJECT_MULTI_STATE_OUTPUT: @@ -241,19 +241,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for MSO!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for MSO!\n"); - #endif +#endif } break; #if BACFILE @@ -264,19 +264,19 @@ void handler_write_property(uint8_t * service_request, encode_simple_ack(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Property Simple Ack for File!\n"); - #endif +#endif } else { pdu_len = bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for File!\n"); - #endif +#endif } break; #endif @@ -285,19 +285,19 @@ void handler_write_property(uint8_t * service_request, bacerror_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code); - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Sending Unknown Object Error!\n"); - #endif +#endif break; } } npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); - #endif +#endif return; } diff --git a/bacnet-stack/demo/handler/noserv.c b/bacnet-stack/demo/handler/noserv.c index 86da2742..de5e93a8 100644 --- a/bacnet-stack/demo/handler/noserv.c +++ b/bacnet-stack/demo/handler/noserv.c @@ -53,10 +53,10 @@ void handler_unrecognized_service(uint8_t * service_request, /* send the data */ bytes_sent = datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent > 0) fprintf(stderr, "Sent Reject!\n"); else fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); - #endif +#endif } diff --git a/bacnet-stack/demo/handler/s_arfs.c b/bacnet-stack/demo/handler/s_arfs.c index 5a2f81bd..dbf227cc 100644 --- a/bacnet-stack/demo/handler/s_arfs.c +++ b/bacnet-stack/demo/handler/s_arfs.c @@ -74,24 +74,26 @@ uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id, we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len < max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send AtomicReadFile Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send AtomicReadFile Request " "(payload exceeds destination maximum APDU)!\n"); - #endif +#endif } } diff --git a/bacnet-stack/demo/handler/s_awfs.c b/bacnet-stack/demo/handler/s_awfs.c index 8d118922..1ddd6cd2 100644 --- a/bacnet-stack/demo/handler/s_awfs.c +++ b/bacnet-stack/demo/handler/s_awfs.c @@ -75,37 +75,38 @@ uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id, we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len <= max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send AtomicWriteFile Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send AtomicWriteFile Request " "(payload [%d] exceeds destination maximum APDU [%u])!\n", pdu_len, max_apdu); - #endif +#endif } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send AtomicWriteFile Request " "(payload [%d] exceeds octet string capacity)!\n", pdu_len); - #endif +#endif } } return invoke_id; } - diff --git a/bacnet-stack/demo/handler/s_dcc.c b/bacnet-stack/demo/handler/s_dcc.c index 62063744..60f53a97 100644 --- a/bacnet-stack/demo/handler/s_dcc.c +++ b/bacnet-stack/demo/handler/s_dcc.c @@ -73,25 +73,27 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len < max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send DeviceCommunicationControl Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send DeviceCommunicationControl Request " "(exceeds destination maximum APDU)!\n"); - #endif +#endif } } diff --git a/bacnet-stack/demo/handler/s_ihave.c b/bacnet-stack/demo/handler/s_ihave.c index ac036066..76ca627d 100644 --- a/bacnet-stack/demo/handler/s_ihave.c +++ b/bacnet-stack/demo/handler/s_ihave.c @@ -67,11 +67,10 @@ void Send_I_Have(uint32_t device_id, pdu_len = ihave_encode_apdu(&Handler_Transmit_Buffer[0], &data); /* send the data */ npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ - #if PRINT_ENABLED + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno)); - #endif +#endif } diff --git a/bacnet-stack/demo/handler/s_rd.c b/bacnet-stack/demo/handler/s_rd.c index 5a5dd0ce..123dc3dc 100644 --- a/bacnet-stack/demo/handler/s_rd.c +++ b/bacnet-stack/demo/handler/s_rd.c @@ -73,24 +73,26 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id, we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len < max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send ReinitializeDevice Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send ReinitializeDevice Request " "(exceeds destination maximum APDU)!\n"); - #endif +#endif } } diff --git a/bacnet-stack/demo/handler/s_rp.c b/bacnet-stack/demo/handler/s_rp.c index 7e4651bb..9c58d9e3 100644 --- a/bacnet-stack/demo/handler/s_rp.c +++ b/bacnet-stack/demo/handler/s_rp.c @@ -79,24 +79,26 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */ we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len < max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send ReadProperty Request " "(exceeds destination maximum APDU)!\n"); - #endif +#endif } } diff --git a/bacnet-stack/demo/handler/s_ts.c b/bacnet-stack/demo/handler/s_ts.c index 154f032b..1483e003 100644 --- a/bacnet-stack/demo/handler/s_ts.c +++ b/bacnet-stack/demo/handler/s_ts.c @@ -61,12 +61,12 @@ void Send_TimeSync(BACNET_DATE * bdate, BACNET_TIME * btime) /* send it out the datalink */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Time-Synchronization Request (%s)!\n", strerror(errno)); - #endif +#endif } void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime) @@ -87,10 +87,10 @@ void Send_TimeSyncUTC(BACNET_DATE * bdate, BACNET_TIME * btime) npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send UTC-Time-Synchronization Request (%s)!\n", strerror(errno)); - #endif +#endif } diff --git a/bacnet-stack/demo/handler/s_whohas.c b/bacnet-stack/demo/handler/s_whohas.c index 531f1b27..7127a596 100644 --- a/bacnet-stack/demo/handler/s_whohas.c +++ b/bacnet-stack/demo/handler/s_whohas.c @@ -62,17 +62,16 @@ void Send_WhoHas_Name(int32_t low_limit, data.high_limit = high_limit; data.object_name = true; characterstring_init_ansi(&data.object.name, object_name); - pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0], - &data); + pdu_len = whohas_encode_apdu(&Handler_Transmit_Buffer[0], &data); npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); /* send the data */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); - #endif +#endif } /* find a specific device, or use -1 for limit if you want unlimited */ @@ -101,9 +100,9 @@ void Send_WhoHas_Object(int32_t low_limit, npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); - #endif +#endif } diff --git a/bacnet-stack/demo/handler/s_whois.c b/bacnet-stack/demo/handler/s_whois.c index 395f201e..afc4caeb 100644 --- a/bacnet-stack/demo/handler/s_whois.c +++ b/bacnet-stack/demo/handler/s_whois.c @@ -61,9 +61,9 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit) npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", strerror(errno)); - #endif +#endif } diff --git a/bacnet-stack/demo/handler/s_wp.c b/bacnet-stack/demo/handler/s_wp.c index 52bea99b..d57fc544 100644 --- a/bacnet-stack/demo/handler/s_wp.c +++ b/bacnet-stack/demo/handler/s_wp.c @@ -83,24 +83,26 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */ we have a way to check for that and update the max_apdu in the address binding table. */ if ((unsigned) pdu_len < max_apdu) { - npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); - tsm_set_confirmed_unsegmented_transaction(invoke_id, - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, &npdu_data, + npdu_encode_confirmed_apdu(&npdu_data, + MESSAGE_PRIORITY_NORMAL); + tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, + &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = + datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED +#if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send WriteProperty Request (%s)!\n", strerror(errno)); - #endif +#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - #if PRINT_ENABLED +#if PRINT_ENABLED fprintf(stderr, "Failed to Send WriteProperty Request " "(exceeds destination maximum APDU)!\n"); - #endif +#endif } } diff --git a/bacnet-stack/demo/object/bacfile.c b/bacnet-stack/demo/object/bacfile.c index cef4d769..624fdd45 100644 --- a/bacnet-stack/demo/object/bacfile.c +++ b/bacnet-stack/demo/object/bacfile.c @@ -301,8 +301,8 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID) uint8_t *service_request = NULL; uint16_t service_request_len = 0; BACNET_ADDRESS dest; /* where the original packet was destined */ - uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */ - uint16_t apdu_len = 0; /* original APDU packet length */ + uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */ + uint16_t apdu_len = 0; /* original APDU packet length */ uint16_t len = 0; /* apdu header length */ BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ @@ -312,12 +312,12 @@ uint32_t bacfile_instance_from_tsm(uint8_t invokeID) found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], &apdu_len); if (found) { - if (!npdu_data.network_layer_message && npdu_data.confirmed_message && - (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { - len = apdu_decode_confirmed_service_request(&apdu[0], - apdu_len - apdu_offset, - &service_data, - &service_choice, &service_request, &service_request_len); + if (!npdu_data.network_layer_message && npdu_data.confirmed_message + && (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { + len = + apdu_decode_confirmed_service_request(&apdu[0], + apdu_len - apdu_offset, &service_data, &service_choice, + &service_request, &service_request_len); if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) { len = arf_decode_service_request(service_request, service_request_len, &data); diff --git a/bacnet-stack/demo/readfile/readfile.c b/bacnet-stack/demo/readfile/readfile.c index a7041dfa..f751b4f3 100644 --- a/bacnet-stack/demo/readfile/readfile.c +++ b/bacnet-stack/demo/readfile/readfile.c @@ -239,7 +239,8 @@ int main(int argc, char *argv[]) timeout_seconds = (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries(); /* try to bind with the device */ - Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance); + Send_WhoIs(Target_Device_Object_Instance, + Target_Device_Object_Instance); /* loop forever */ for (;;) { /* increment timer - exit if timed out */ diff --git a/bacnet-stack/demo/writefile/writefile.c b/bacnet-stack/demo/writefile/writefile.c index afb46ece..f0a820e5 100644 --- a/bacnet-stack/demo/writefile/writefile.c +++ b/bacnet-stack/demo/writefile/writefile.c @@ -195,7 +195,8 @@ int main(int argc, char *argv[]) timeout_seconds = (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries(); /* try to bind with the device */ - Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance); + Send_WhoIs(Target_Device_Object_Instance, + Target_Device_Object_Instance); /* loop forever */ for (;;) { /* increment timer - exit if timed out */ diff --git a/bacnet-stack/dlmstp.h b/bacnet-stack/dlmstp.h index 533892d4..a85f199d 100644 --- a/bacnet-stack/dlmstp.h +++ b/bacnet-stack/dlmstp.h @@ -44,13 +44,12 @@ #define MAX_HEADER (2+1+1+1+2+1+2+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) -typedef struct dlmstp_packet -{ - bool ready; /* true if ready to be sent or received */ +typedef struct dlmstp_packet { + bool ready; /* true if ready to be sent or received */ bool data_expecting_reply; - BACNET_ADDRESS address; /* src or dest address*/ - unsigned pdu_len; /* packet length */ - uint8_t pdu[MAX_MPDU]; /* packet */ + BACNET_ADDRESS address; /* src or dest address */ + unsigned pdu_len; /* packet length */ + uint8_t pdu[MAX_MPDU]; /* packet */ } DLMSTP_PACKET; #ifdef __cplusplus @@ -72,13 +71,13 @@ extern "C" { uint8_t * pdu, /* PDU data */ uint16_t max_pdu, /* amount of space available in the PDU */ unsigned timeout); /* milliseconds to wait for a packet */ - + /* function for MS/TP state machine to use to get a packet to transmit. It returns the number of bytes in the packet, or 0 if none. */ - int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ - uint8_t * pdu); /* any data to be sent - may be null */ - + int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ + uint8_t * pdu); /* any data to be sent - may be null */ + void dlmstp_set_my_address(uint8_t my_address); void dlmstp_get_my_address(BACNET_ADDRESS * my_address); diff --git a/bacnet-stack/iam.c b/bacnet-stack/iam.c index f8434cdd..c6e34c67 100755 --- a/bacnet-stack/iam.c +++ b/bacnet-stack/iam.c @@ -151,8 +151,7 @@ int iam_send(uint8_t * buffer) /* encode the NPDU portion of the packet */ npdu_encode_unconfirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL); /* send data */ - bytes_sent = datalink_send_pdu(&dest, &npdu_data, - &buffer[0], pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); return bytes_sent; } @@ -218,7 +217,7 @@ void datalink_get_broadcast_address(BACNET_ADDRESS * dest) } int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ + BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ diff --git a/bacnet-stack/npdu.c b/bacnet-stack/npdu.c index 005c3594..b379ccbf 100644 --- a/bacnet-stack/npdu.c +++ b/bacnet-stack/npdu.c @@ -57,8 +57,7 @@ void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src) int npdu_encode_pdu(uint8_t * npdu, BACNET_ADDRESS * dest, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data) + BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) { int len = 0; /* return value - number of octets loaded in this function */ int i = 0; /* counter */ @@ -158,13 +157,12 @@ int npdu_encode_pdu(uint8_t * npdu, void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data, BACNET_MESSAGE_PRIORITY priority) { - if (npdu_data) - { + if (npdu_data) { npdu_data->confirmed_message = true; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = false; /* false if APDU */ - npdu_data->network_message_type = 0; /* optional */ - npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ + npdu_data->network_layer_message = false; /* false if APDU */ + npdu_data->network_message_type = 0; /* optional */ + npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->priority = priority; npdu_data->hop_count = 0; } @@ -173,13 +171,12 @@ void npdu_encode_confirmed_apdu(BACNET_NPDU_DATA * npdu_data, void npdu_encode_unconfirmed_apdu(BACNET_NPDU_DATA * npdu_data, BACNET_MESSAGE_PRIORITY priority) { - if (npdu_data) - { + if (npdu_data) { npdu_data->confirmed_message = false; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = false; /* false if APDU */ - npdu_data->network_message_type = 0; /* optional */ - npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ + npdu_data->network_layer_message = false; /* false if APDU */ + npdu_data->network_message_type = 0; /* optional */ + npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->priority = priority; npdu_data->hop_count = 0; } @@ -339,7 +336,7 @@ void testNPDU2(Test * pTest) BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_src = { 0 }; int len = 0; - bool confirmed_message = true; /* true for confirmed messages */ + bool confirmed_message = true; /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_NPDU_DATA npdu_data = { 0 }; int i = 0; /* counter */ @@ -403,7 +400,7 @@ void testNPDU1(Test * pTest) BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_src = { 0 }; int len = 0; - bool confirmed_message = false; /* true for confirmed messages */ + bool confirmed_message = false; /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_NPDU_DATA npdu_data = { 0 }; int i = 0; /* counter */ diff --git a/bacnet-stack/npdu.h b/bacnet-stack/npdu.h index ee83b4b7..385e9dda 100644 --- a/bacnet-stack/npdu.h +++ b/bacnet-stack/npdu.h @@ -43,7 +43,7 @@ typedef struct bacnet_npdu_data_t { uint8_t protocol_version; /* parts of the control octet: */ - bool confirmed_message; /* true for confirmed messages */ + bool confirmed_message; /* true for confirmed messages */ bool network_layer_message; /* false if APDU */ BACNET_MESSAGE_PRIORITY priority; /* optional network message info */ diff --git a/bacnet-stack/ports/pic18/dlmstp.c b/bacnet-stack/ports/pic18/dlmstp.c index a3644bbb..ef3fc7fd 100644 --- a/bacnet-stack/ports/pic18/dlmstp.c +++ b/bacnet-stack/ports/pic18/dlmstp.c @@ -1,198 +1,196 @@ -/************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ -#include -#include -#include -#include -#include "bacdef.h" -#include "mstp.h" -#include "dlmstp.h" -#include "rs485.h" - -static DLMSTP_PACKET Receive_Buffer; -static DLMSTP_PACKET Transmit_Buffer; -volatile struct mstp_port_struct_t MSTP_Port; /* port data */ -static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */ - -void dlmstp_init(void) -{ - /* initialize buffer */ - Receive_Buffer.ready = false; - Receive_Buffer.data_expecting_reply = false; - Receive_Buffer.pdu_len = 0; - /* initialize buffer */ - Transmit_Buffer.ready = false; - Transmit_Buffer.data_expecting_reply = false; - Transmit_Buffer.pdu_len = 0; - /* initialize hardware */ - RS485_Initialize(); - MSTP_Init(&MSTP_Port, MSTP_MAC_Address); -} - -void dlmstp_cleanup(void) -{ - /* nothing to do for static buffers */ -} - -/* returns number of bytes sent on success, zero on failure */ -int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - uint8_t * pdu, /* any data to be sent - may be null */ - unsigned pdu_len) -{ /* number of bytes of data */ - bool status; - int bytes_sent = 0; - - if (Transmit_Buffer.ready == false) - { - /* FIXME: how do we get data_expecting_reply? */ - Transmit_Buffer.data_expecting_reply = false; - Receive_Buffer.pdu_len = 0; - memmove(&Transmit_Buffer.address,dest,sizeof(Transmit_Buffer.address)); - Transmit_Buffer.pdu_len = pdu_len; - /* FIXME: copy the whole PDU or just the pdu_len? */ - memmove(Transmit_Buffer.pdu,pdu,sizeof(Transmit_Buffer.pdu)); - bytes_sent = pdu_len; - Transmit_Buffer.ready = true; - } - - return bytes_sent; -} - -/* function for MS/TP to use to get a packet to transmit - returns the number of bytes in the packet, or zero if none. */ -int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ - uint8_t * pdu) /* any data to be sent - may be null */ -{ - bool status; - DLMSTP_PACKET *packet; - unsigned pdu_len = 0; - - if (Transmit_Buffer.ready) - { - memmove(dest,&packet->address,sizeof(packet->address)); - pdu_len = packet->pdu_len; - memmove(pdu,packet->pdu,sizeof(packet.pdu)); - } - - return pdu_len; -} - -int dlmstp_set_transmit_pdu_ready(bool ready) -{ - Transmit_Buffer.ready = ready; -} - -void dlmstp_task(void) -{ - RS485_Check_UART_Data(&MSTP_Port); - MSTP_Receive_Frame_FSM(&MSTP_Port); - - RS485_Process_Tx_Message(); - MSTP_Master_Node_FSM(&MSTP_Port); -} - -/* called about once a millisecond */ -void dlmstp_millisecond_timer(void) -{ - MSTP_Millisecond_Timer(&MSTP_Port); -} - -/* returns the number of octets in the PDU, or zero on failure */ -/* This function is expecting to be polled. */ -uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t max_pdu, /* amount of space available in the PDU */ - unsigned timeout) -{ - DLMSTP_PACKET *packet; - - (void) timeout; - /* see if there is a packet available */ - if (!Ringbuf_Empty(&Receive_Buffer)) - { - packet = (char *)Ringbuf_Pop_Front(&Receive_Buffer); - memmove(src,&packet->address,sizeof(packet->address)); - pdu_len = packet->pdu_len; - memmove(pdu,packet->pdu,max_pdu); - } - - return pdu_len; -} - -/* for the MS/TP state machine to use for putting received data */ -uint16_t dlmstp_put_receive(BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t pdu_len) -{ - bool status; - int bytes_put = 0; - - memmove(&Temp_Packet.address,src,sizeof(Temp_Packet.address)); - Temp_Packet.pdu_len = pdu_len; - memmove(Temp_Packet.pdu,pdu,sizeof(Temp_Packet.pdu)); - status = Ringbuf_Put(&Receive_Buffer, &Temp_Packet); - if (status) - bytes_put = pdu_len; - - return bytes_put; -} - -void dlmstp_set_my_address(uint8_t mac_address) -{ - /* FIXME: Master Nodes can only have address 1-127 */ - MSTP_MAC_Address = mac_address; - - return; -} - -void dlmstp_get_my_address(BACNET_ADDRESS * my_address) -{ - my_address->mac_len = 1; - my_address->mac[0] = MSTP_MAC_Address; - my_address->net = 0; /* local only, no routing */ - my_address->len = 0; - for (i = 0; i < MAX_MAC_LEN; i++) { - my_address->adr[i] = 0; - } - - return; -} - -void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) -{ /* destination address */ - int i = 0; /* counter */ - - if (dest) { - dest->mac_len = 1; - dest->mac[0] = MSTP_BROADCAST_ADDRESS; - dest->net = BACNET_BROADCAST_NETWORK; - dest->len = 0; /* len=0 denotes broadcast address */ - for (i = 0; i < MAX_MAC_LEN; i++) { - dest->adr[i] = 0; - } - } - - return; -} +/************************************************************************** +* +* Copyright (C) 2006 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ +#include +#include +#include +#include +#include "bacdef.h" +#include "mstp.h" +#include "dlmstp.h" +#include "rs485.h" + +static DLMSTP_PACKET Receive_Buffer; +static DLMSTP_PACKET Transmit_Buffer; +volatile struct mstp_port_struct_t MSTP_Port; /* port data */ +static uint8_t MSTP_MAC_Address = 0x05; /* local MAC address */ + +void dlmstp_init(void) +{ + /* initialize buffer */ + Receive_Buffer.ready = false; + Receive_Buffer.data_expecting_reply = false; + Receive_Buffer.pdu_len = 0; + /* initialize buffer */ + Transmit_Buffer.ready = false; + Transmit_Buffer.data_expecting_reply = false; + Transmit_Buffer.pdu_len = 0; + /* initialize hardware */ + RS485_Initialize(); + MSTP_Init(&MSTP_Port, MSTP_MAC_Address); +} + +void dlmstp_cleanup(void) +{ + /* nothing to do for static buffers */ +} + +/* returns number of bytes sent on success, zero on failure */ +int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ + uint8_t * pdu, /* any data to be sent - may be null */ + unsigned pdu_len) +{ /* number of bytes of data */ + bool status; + int bytes_sent = 0; + + if (Transmit_Buffer.ready == false) { + /* FIXME: how do we get data_expecting_reply? */ + Transmit_Buffer.data_expecting_reply = false; + Receive_Buffer.pdu_len = 0; + memmove(&Transmit_Buffer.address, dest, + sizeof(Transmit_Buffer.address)); + Transmit_Buffer.pdu_len = pdu_len; + /* FIXME: copy the whole PDU or just the pdu_len? */ + memmove(Transmit_Buffer.pdu, pdu, sizeof(Transmit_Buffer.pdu)); + bytes_sent = pdu_len; + Transmit_Buffer.ready = true; + } + + return bytes_sent; +} + +/* function for MS/TP to use to get a packet to transmit + returns the number of bytes in the packet, or zero if none. */ +int dlmstp_get_transmit_pdu(BACNET_ADDRESS * dest, /* destination address */ + uint8_t * pdu) +{ /* any data to be sent - may be null */ + bool status; + DLMSTP_PACKET *packet; + unsigned pdu_len = 0; + + if (Transmit_Buffer.ready) { + memmove(dest, &packet->address, sizeof(packet->address)); + pdu_len = packet->pdu_len; + memmove(pdu, packet->pdu, sizeof(packet.pdu)); + } + + return pdu_len; +} + +int dlmstp_set_transmit_pdu_ready(bool ready) +{ + Transmit_Buffer.ready = ready; +} + +void dlmstp_task(void) +{ + RS485_Check_UART_Data(&MSTP_Port); + MSTP_Receive_Frame_FSM(&MSTP_Port); + + RS485_Process_Tx_Message(); + MSTP_Master_Node_FSM(&MSTP_Port); +} + +/* called about once a millisecond */ +void dlmstp_millisecond_timer(void) +{ + MSTP_Millisecond_Timer(&MSTP_Port); +} + +/* returns the number of octets in the PDU, or zero on failure */ +/* This function is expecting to be polled. */ +uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout) +{ + DLMSTP_PACKET *packet; + + (void) timeout; + /* see if there is a packet available */ + if (!Ringbuf_Empty(&Receive_Buffer)) { + packet = (char *) Ringbuf_Pop_Front(&Receive_Buffer); + memmove(src, &packet->address, sizeof(packet->address)); + pdu_len = packet->pdu_len; + memmove(pdu, packet->pdu, max_pdu); + } + + return pdu_len; +} + +/* for the MS/TP state machine to use for putting received data */ +uint16_t dlmstp_put_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t pdu_len) +{ + bool status; + int bytes_put = 0; + + memmove(&Temp_Packet.address, src, sizeof(Temp_Packet.address)); + Temp_Packet.pdu_len = pdu_len; + memmove(Temp_Packet.pdu, pdu, sizeof(Temp_Packet.pdu)); + status = Ringbuf_Put(&Receive_Buffer, &Temp_Packet); + if (status) + bytes_put = pdu_len; + + return bytes_put; +} + +void dlmstp_set_my_address(uint8_t mac_address) +{ + /* FIXME: Master Nodes can only have address 1-127 */ + MSTP_MAC_Address = mac_address; + + return; +} + +void dlmstp_get_my_address(BACNET_ADDRESS * my_address) +{ + my_address->mac_len = 1; + my_address->mac[0] = MSTP_MAC_Address; + my_address->net = 0; /* local only, no routing */ + my_address->len = 0; + for (i = 0; i < MAX_MAC_LEN; i++) { + my_address->adr[i] = 0; + } + + return; +} + +void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) +{ /* destination address */ + int i = 0; /* counter */ + + if (dest) { + dest->mac_len = 1; + dest->mac[0] = MSTP_BROADCAST_ADDRESS; + dest->net = BACNET_BROADCAST_NETWORK; + dest->len = 0; /* len=0 denotes broadcast address */ + for (i = 0; i < MAX_MAC_LEN; i++) { + dest->adr[i] = 0; + } + } + + return; +} diff --git a/bacnet-stack/ports/pic18/main.c b/bacnet-stack/ports/pic18/main.c index 14ed3362..855df1e1 100644 --- a/bacnet-stack/ports/pic18/main.c +++ b/bacnet-stack/ports/pic18/main.c @@ -52,8 +52,9 @@ static uint8_t Temp_Buf[MAX_APDU]; /* buffer used for receiving */ static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; + /* address where message came from */ -static BACNET_ADDRESS src; +static BACNET_ADDRESS src; /* address used to send */ static BACNET_ADDRESS my_address; @@ -170,7 +171,7 @@ void main(void) Device_Set_Object_Instance_Number(5); dlmstp_set_my_address(0x05); dlmstp_init(); - + init_hardware(); /* broadcast an I-Am on startup */ diff --git a/bacnet-stack/ports/pic18/rs485.c b/bacnet-stack/ports/pic18/rs485.c index 132f77fe..71460ed3 100644 --- a/bacnet-stack/ports/pic18/rs485.c +++ b/bacnet-stack/ports/pic18/rs485.c @@ -50,7 +50,7 @@ static struct { /* Duplicate of the RCSTA reg used due to the double buffering of the */ /* fifo. Reading the RCREG reg will cause the second RCSTA reg to be */ /* loaded if there is one. */ - struct _rcstabits { +struct _rcstabits { unsigned char RX9D:1; unsigned char OERR:1; unsigned char FERR:1; diff --git a/bacnet-stack/tsm.c b/bacnet-stack/tsm.c index f625d9c1..7e04a227 100644 --- a/bacnet-stack/tsm.c +++ b/bacnet-stack/tsm.c @@ -133,8 +133,7 @@ uint8_t tsm_next_free_invokeID(void) bool found = false; /* is there even space available? */ - if (tsm_transaction_available()) - { + if (tsm_transaction_available()) { while (!found) { index = tsm_find_invokeID_index(current_invokeID); /* not found - that is good! */ @@ -208,7 +207,7 @@ bool tsm_get_transaction_pdu(uint8_t invokeID, for (j = 0; j < *apdu_len; j++) { apdu[j] = TSM_List[index].apdu[j]; } - npdu_copy_data(ndpu_data,&TSM_List[index].npdu_data); + npdu_copy_data(ndpu_data, &TSM_List[index].npdu_data); address_copy(dest, &TSM_List[index].dest); found = true; }