From dee63d45bc967e4f26402163ac05587f4e7fa04c Mon Sep 17 00:00:00 2001 From: skarg Date: Sun, 19 Feb 2006 01:32:09 +0000 Subject: [PATCH] Changed all the C++ comments to C comments using comment.sh script. --- bacnet-stack/abort.c | 18 +- bacnet-stack/address.c | 40 +- bacnet-stack/apdu.c | 60 +- bacnet-stack/apdu.h | 64 +- bacnet-stack/arcnet.h | 30 +- bacnet-stack/arf.c | 66 +- bacnet-stack/arf.h | 14 +- bacnet-stack/awf.c | 46 +- bacnet-stack/awf.h | 12 +- bacnet-stack/bacapp.c | 2 +- bacnet-stack/bacdcode.c | 430 ++++++------- bacnet-stack/bacdcode.h | 102 +-- bacnet-stack/bacdef.h | 32 +- bacnet-stack/bacenum.h | 178 +++--- bacnet-stack/bacerror.c | 30 +- bacnet-stack/bacstr.c | 20 +- bacnet-stack/bacstr.h | 2 +- bacnet-stack/bigend.c | 30 +- bacnet-stack/bigend.h | 28 +- bacnet-stack/bip.c | 72 +-- bacnet-stack/bip.h | 38 +- bacnet-stack/bytes.h | 4 +- bacnet-stack/config.h | 42 +- bacnet-stack/crc.c | 38 +- bacnet-stack/datalink.c | 32 +- bacnet-stack/datalink.h | 18 +- bacnet-stack/dcc.c | 4 +- bacnet-stack/dcc.h | 4 +- bacnet-stack/demo/handler/client.h | 2 +- bacnet-stack/demo/handler/h_arf.c | 12 +- bacnet-stack/demo/handler/h_arf_a.c | 16 +- bacnet-stack/demo/handler/h_dcc.c | 14 +- bacnet-stack/demo/handler/h_iam.c | 2 +- bacnet-stack/demo/handler/h_rd.c | 14 +- bacnet-stack/demo/handler/h_rp.c | 30 +- bacnet-stack/demo/handler/h_wp.c | 14 +- bacnet-stack/demo/handler/noserv.c | 10 +- bacnet-stack/demo/handler/s_dcc.c | 8 +- bacnet-stack/demo/handler/s_ihave.c | 4 +- bacnet-stack/demo/handler/s_rd.c | 8 +- bacnet-stack/demo/handler/s_rp.c | 8 +- bacnet-stack/demo/handler/s_whohas.c | 8 +- bacnet-stack/demo/handler/s_whois.c | 12 +- bacnet-stack/demo/handler/s_wp.c | 10 +- bacnet-stack/demo/object/ai.c | 24 +- bacnet-stack/demo/object/ao.c | 74 +-- bacnet-stack/demo/object/bacfile.c | 52 +- bacnet-stack/demo/object/bacfile.h | 14 +- bacnet-stack/demo/object/device.c | 88 +-- bacnet-stack/demo/object/device.h | 2 +- bacnet-stack/demo/readfile/readfile.c | 16 +- bacnet-stack/dlmstp.c | 24 +- bacnet-stack/dlmstp.h | 20 +- bacnet-stack/ethernet.h | 30 +- bacnet-stack/iam.c | 56 +- bacnet-stack/main.c | 12 +- bacnet-stack/mstp.c | 854 +++++++++++++------------- bacnet-stack/mstp.h | 166 ++--- bacnet-stack/npdu.c | 250 ++++---- bacnet-stack/npdu.h | 24 +- bacnet-stack/rd.c | 4 +- bacnet-stack/rd.h | 4 +- bacnet-stack/reject.c | 18 +- bacnet-stack/ringbuf.c | 38 +- bacnet-stack/ringbuf.h | 22 +- bacnet-stack/rp.c | 72 +-- bacnet-stack/rp.h | 8 +- bacnet-stack/rs485.h | 8 +- bacnet-stack/tsm.c | 64 +- bacnet-stack/tsm.h | 58 +- bacnet-stack/whohas.c | 14 +- bacnet-stack/whohas.h | 2 +- bacnet-stack/whois.c | 18 +- bacnet-stack/whois.h | 2 +- bacnet-stack/wp.c | 38 +- bacnet-stack/wp.h | 8 +- 76 files changed, 1856 insertions(+), 1856 deletions(-) diff --git a/bacnet-stack/abort.c b/bacnet-stack/abort.c index cdf4d767..db9d1340 100644 --- a/bacnet-stack/abort.c +++ b/bacnet-stack/abort.c @@ -36,11 +36,11 @@ #include "bacdcode.h" #include "bacdef.h" -// encode service +/* encode service */ int abort_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint8_t abort_reason) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_ABORT; @@ -52,7 +52,7 @@ int abort_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int abort_decode_service_request(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason) { @@ -68,7 +68,7 @@ int abort_decode_service_request(uint8_t * apdu, return len; } -// decode the whole APDU - mainly used for unit testing +/* decode the whole APDU - mainly used for unit testing */ int abort_decode_apdu(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason) { @@ -76,7 +76,7 @@ int abort_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu_len) { if (apdu[0] != PDU_TYPE_ABORT) return -1; @@ -114,24 +114,24 @@ void testAbort(Test * pTest) ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_abort_reason == abort_reason); - // change type to get negative response + /* change type to get negative response */ apdu[0] = PDU_TYPE_REJECT; len = abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_abort_reason); ct_test(pTest, len == -1); - // test NULL APDU + /* test NULL APDU */ len = abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason); ct_test(pTest, len == -1); - // force a zero length + /* force a zero length */ len = abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason); ct_test(pTest, len == 0); - // check them all... + /* check them all... */ for (invoke_id = 0; invoke_id < 255; invoke_id++) { for (abort_reason = 0; abort_reason < 255; abort_reason++) { len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason); diff --git a/bacnet-stack/address.c b/bacnet-stack/address.c index 0f13dd23..e6755105 100644 --- a/bacnet-stack/address.c +++ b/bacnet-stack/address.c @@ -40,9 +40,9 @@ #include "bacdef.h" #include "bacdcode.h" -// This module is used to handle the address binding that -// occurs in BACnet. A device id is bound to a MAC address. -// The normal method is using Who-Is, and using the data from I-Am +/* This module is used to handle the address binding that */ +/* occurs in BACnet. A device id is bound to a MAC address. */ +/* The normal method is using Who-Is, and using the data from I-Am */ static struct Address_Cache_Entry { bool valid; @@ -54,7 +54,7 @@ static struct Address_Cache_Entry { void address_copy(BACNET_ADDRESS * dest, BACNET_ADDRESS * src) { - unsigned i = 0; // counter + unsigned i = 0; /* counter */ if (dest && src) { for (i = 0; i < MAX_MAC_LEN; i++) { @@ -103,7 +103,7 @@ bool address_get_by_device(uint32_t device_id, unsigned *max_apdu, BACNET_ADDRESS * src) { unsigned i; - bool found = false; // return value + bool found = false; /* return value */ for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (Address_Cache[i].valid && @@ -122,9 +122,9 @@ void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS * src) { unsigned i; - bool found = false; // return value + bool found = false; /* return value */ - // existing device - update address + /* existing device - update address */ for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (Address_Cache[i].valid && (Address_Cache[i].device_id == device_id)) { @@ -134,7 +134,7 @@ void address_add(uint32_t device_id, break; } } - // new device + /* new device */ if (!found) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (!Address_Cache[i].valid) { @@ -150,15 +150,15 @@ void address_add(uint32_t device_id, return; } -// returns true if device is already bound -// also returns the address and max apdu if already bound +/* returns true if device is already bound */ +/* also returns the address and max apdu if already bound */ bool address_bind_request(uint32_t device_id, unsigned *max_apdu, BACNET_ADDRESS * src) { unsigned i; - bool found = false; // return value + bool found = false; /* return value */ - // existing device - update address + /* existing device - update address */ for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (Address_Cache[i].valid && (Address_Cache[i].device_id == device_id)) { @@ -167,7 +167,7 @@ bool address_bind_request(uint32_t device_id, *max_apdu = Address_Cache[i].max_apdu; break; } - // already have a bind request active for this puppy + /* already have a bind request active for this puppy */ else if (Address_Cache[i].bind_request && (Address_Cache[i].device_id == device_id)) { return found; @@ -179,7 +179,7 @@ bool address_bind_request(uint32_t device_id, if (!(Address_Cache[i].bind_request || Address_Cache[i].valid)) { Address_Cache[i].bind_request = true; Address_Cache[i].device_id = device_id; - // now would be a good time to do a Who-Is request + /* now would be a good time to do a Who-Is request */ break; } } @@ -192,9 +192,9 @@ void address_add_binding(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS * src) { unsigned i; - bool found = false; // return value + bool found = false; /* return value */ - // existing device - update address + /* existing device - update address */ for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (Address_Cache[i].valid && (Address_Cache[i].device_id == device_id)) { @@ -204,7 +204,7 @@ void address_add_binding(uint32_t device_id, break; } } - // add new device - but only if bind requested + /* add new device - but only if bind requested */ if (!found) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (!Address_Cache[i].valid && Address_Cache[i].bind_request) { @@ -224,7 +224,7 @@ void address_add_binding(uint32_t device_id, bool address_get_by_index(unsigned index, uint32_t * device_id, unsigned *max_apdu, BACNET_ADDRESS * src) { - bool found = false; // return value + bool found = false; /* return value */ if (index < MAX_ADDRESS_CACHE) { if (Address_Cache[index].valid) { @@ -241,7 +241,7 @@ bool address_get_by_index(unsigned index, unsigned address_count(void) { unsigned i; - unsigned count = 0; // return value + unsigned count = 0; /* return value */ for (i = 0; i < MAX_ADDRESS_CACHE; i++) { if (Address_Cache[i].valid) @@ -255,7 +255,7 @@ bool address_match(BACNET_ADDRESS * dest, BACNET_ADDRESS * src) { unsigned i; unsigned max_len; - bool match = true; // return value + bool match = true; /* return value */ if (dest->mac_len != src->mac_len) match = false; diff --git a/bacnet-stack/apdu.c b/bacnet-stack/apdu.c index d973517f..a20954fd 100644 --- a/bacnet-stack/apdu.c +++ b/bacnet-stack/apdu.c @@ -93,8 +93,8 @@ static BACNET_SERVICES_SUPPORTED SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION }; -// Confirmed Function Handlers -// If they are not set, they are handled by a reject message +/* Confirmed Function Handlers */ +/* If they are not set, they are handled by a reject message */ static confirmed_function Confirmed_Function[MAX_BACNET_CONFIRMED_SERVICE]; void apdu_set_confirmed_handler(BACNET_CONFIRMED_SERVICE service_choice, @@ -146,7 +146,7 @@ bool apdu_service_supported(BACNET_SERVICES_SUPPORTED service_supported) return status; } -// Allow the APDU handler to automatically reject +/* Allow the APDU handler to automatically reject */ static confirmed_function Unrecognized_Service_Handler; void apdu_set_unrecognized_service_handler_handler(confirmed_function @@ -155,8 +155,8 @@ void apdu_set_unrecognized_service_handler_handler(confirmed_function Unrecognized_Service_Handler = pFunction; } -// Unconfirmed Function Handlers -// If they are not set, they are not handled +/* Unconfirmed Function Handlers */ +/* If they are not set, they are not handled */ static unconfirmed_function Unconfirmed_Function[MAX_BACNET_UNCONFIRMED_SERVICE] = { NULL @@ -180,7 +180,7 @@ bool apdu_unconfirmed_handler(BACNET_UNCONFIRMED_SERVICE service_choice) return status; } -// Confirmed ACK Function Handlers +/* Confirmed ACK Function Handlers */ static void *Confirmed_ACK_Function[MAX_BACNET_CONFIRMED_SERVICE]; void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE @@ -193,19 +193,19 @@ void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE case SERVICE_CONFIRMED_SUBSCRIBE_COV: case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY: case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION: - // Object Access Services + /* Object Access Services */ case SERVICE_CONFIRMED_ADD_LIST_ELEMENT: case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT: case SERVICE_CONFIRMED_DELETE_OBJECT: case SERVICE_CONFIRMED_WRITE_PROPERTY: case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE: - // Remote Device Management Services + /* Remote Device Management Services */ case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: case SERVICE_CONFIRMED_TEXT_MESSAGE: case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: - // Virtual Terminal Services + /* Virtual Terminal Services */ case SERVICE_CONFIRMED_VT_CLOSE: - // Security Services + /* Security Services */ case SERVICE_CONFIRMED_REQUEST_KEY: Confirmed_ACK_Function[service_choice] = (void *) pFunction; break; @@ -221,21 +221,21 @@ void apdu_set_confirmed_ack_handler(BACNET_CONFIRMED_SERVICE case SERVICE_CONFIRMED_GET_ALARM_SUMMARY: case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY: case SERVICE_CONFIRMED_GET_EVENT_INFORMATION: - // File Access Services + /* File Access Services */ case SERVICE_CONFIRMED_ATOMIC_READ_FILE: case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE: - // Object Access Services + /* Object Access Services */ case SERVICE_CONFIRMED_CREATE_OBJECT: case SERVICE_CONFIRMED_READ_PROPERTY: case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL: case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_READ_RANGE: - // Remote Device Management Services + /* Remote Device Management Services */ case SERVICE_CONFIRMED_PRIVATE_TRANSFER: - // Virtual Terminal Services + /* Virtual Terminal Services */ case SERVICE_CONFIRMED_VT_OPEN: case SERVICE_CONFIRMED_VT_DATA: - // Security Services + /* Security Services */ case SERVICE_CONFIRMED_AUTHENTICATE: Confirmed_ACK_Function[service_choice] = (void *) pFunction; break; @@ -267,13 +267,13 @@ void apdu_set_reject_handler(reject_function pFunction) Reject_Function = pFunction; } -uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, // APDU data +uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */ uint16_t apdu_len, BACNET_CONFIRMED_SERVICE_DATA * service_data, uint8_t * service_choice, uint8_t ** service_request, uint16_t * service_request_len) { - uint16_t len = 0; // counts where we are in PDU + uint16_t len = 0; /* counts where we are in PDU */ service_data->segmented_message = (apdu[0] & BIT3) ? true : false; service_data->more_follows = (apdu[0] & BIT2) ? true : false; @@ -294,8 +294,8 @@ uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, // APDU data return len; } -void apdu_handler(BACNET_ADDRESS * src, // source address - bool data_expecting_reply, uint8_t * apdu, // APDU data +void apdu_handler(BACNET_ADDRESS * src, /* source address */ + bool data_expecting_reply, uint8_t * apdu, /* APDU data */ uint16_t apdu_len) { BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; @@ -304,7 +304,7 @@ void apdu_handler(BACNET_ADDRESS * src, // source address uint8_t service_choice = 0; uint8_t *service_request = NULL; uint16_t service_request_len = 0; - uint16_t len = 0; // counts where we are in PDU + uint16_t len = 0; /* counts where we are in PDU */ uint8_t tag_number = 0; uint32_t len_value = 0; int error_code = 0; @@ -313,10 +313,10 @@ void apdu_handler(BACNET_ADDRESS * src, // source address (void) data_expecting_reply; if (apdu) { - // PDU Type + /* PDU Type */ switch (apdu[0] & 0xF0) { case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: - len = apdu_decode_confirmed_service_request(&apdu[0], // APDU data + len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */ apdu_len, &service_data, &service_choice, &service_request, &service_request_len); @@ -359,19 +359,19 @@ void apdu_handler(BACNET_ADDRESS * src, // source address case SERVICE_CONFIRMED_SUBSCRIBE_COV: case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY: case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION: - // Object Access Services + /* Object Access Services */ case SERVICE_CONFIRMED_ADD_LIST_ELEMENT: case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT: case SERVICE_CONFIRMED_DELETE_OBJECT: case SERVICE_CONFIRMED_WRITE_PROPERTY: case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE: - // Remote Device Management Services + /* Remote Device Management Services */ case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: case SERVICE_CONFIRMED_TEXT_MESSAGE: - // Virtual Terminal Services + /* Virtual Terminal Services */ case SERVICE_CONFIRMED_VT_CLOSE: - // Security Services + /* Security Services */ case SERVICE_CONFIRMED_REQUEST_KEY: if (Confirmed_ACK_Function[service_choice]) { ((confirmed_simple_ack_function) @@ -402,20 +402,20 @@ void apdu_handler(BACNET_ADDRESS * src, // source address case SERVICE_CONFIRMED_GET_ALARM_SUMMARY: case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY: case SERVICE_CONFIRMED_GET_EVENT_INFORMATION: - // File Access Services + /* File Access Services */ case SERVICE_CONFIRMED_ATOMIC_READ_FILE: case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE: - // Object Access Services + /* Object Access Services */ case SERVICE_CONFIRMED_CREATE_OBJECT: case SERVICE_CONFIRMED_READ_PROPERTY: case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL: case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_READ_RANGE: case SERVICE_CONFIRMED_PRIVATE_TRANSFER: - // Virtual Terminal Services + /* Virtual Terminal Services */ case SERVICE_CONFIRMED_VT_OPEN: case SERVICE_CONFIRMED_VT_DATA: - // Security Services + /* Security Services */ case SERVICE_CONFIRMED_AUTHENTICATE: if (Confirmed_ACK_Function[service_choice]) { ((confirmed_ack_function) diff --git a/bacnet-stack/apdu.h b/bacnet-stack/apdu.h index fb6f1932..1349b65c 100644 --- a/bacnet-stack/apdu.h +++ b/bacnet-stack/apdu.h @@ -62,56 +62,56 @@ extern "C" { uint8_t proposed_window_number; } BACNET_CONFIRMED_SERVICE_ACK_DATA; -// generic unconfirmed function handler -// Suitable to handle the following services: -// I_Am, Who_Is, Unconfirmed_COV_Notification, I_Have, -// Unconfirmed_Event_Notification, Unconfirmed_Private_Transfer, -// Unconfirmed_Text_Message, Time_Synchronization, Who_Has, -// UTC_Time_Synchronization +/* generic unconfirmed function handler */ +/* Suitable to handle the following services: */ +/* I_Am, Who_Is, Unconfirmed_COV_Notification, I_Have, */ +/* Unconfirmed_Event_Notification, Unconfirmed_Private_Transfer, */ +/* Unconfirmed_Text_Message, Time_Synchronization, Who_Has, */ +/* UTC_Time_Synchronization */ typedef void (*unconfirmed_function) (uint8_t * service_request, uint16_t len, BACNET_ADDRESS * src); -// generic confirmed function handler -// Suitable to handle the following services: -// Acknowledge_Alarm, Confirmed_COV_Notification, -// Confirmed_Event_Notification, Get_Alarm_Summary, -// Get_Enrollment_Summary_Handler, Get_Event_Information, -// Subscribe_COV_Handler, Subscribe_COV_Property, -// Life_Safety_Operation, Atomic_Read_File, -// Confirmed_Atomic_Write_File, Add_List_Element, -// Remove_List_Element, Create_Object_Handler, -// Delete_Object_Handler, Read_Property, -// Read_Property_Conditional, Read_Property_Multiple, Read_Range, -// Write_Property, Write_Property_Multiple, -// Device_Communication_Control, Confirmed_Private_Transfer, -// Confirmed_Text_Message, Reinitialize_Device, -// VT_Open, VT_Close, VT_Data_Handler, -// Authenticate, Request_Key +/* generic confirmed function handler */ +/* Suitable to handle the following services: */ +/* Acknowledge_Alarm, Confirmed_COV_Notification, */ +/* Confirmed_Event_Notification, Get_Alarm_Summary, */ +/* Get_Enrollment_Summary_Handler, Get_Event_Information, */ +/* Subscribe_COV_Handler, Subscribe_COV_Property, */ +/* Life_Safety_Operation, Atomic_Read_File, */ +/* Confirmed_Atomic_Write_File, Add_List_Element, */ +/* Remove_List_Element, Create_Object_Handler, */ +/* Delete_Object_Handler, Read_Property, */ +/* Read_Property_Conditional, Read_Property_Multiple, Read_Range, */ +/* Write_Property, Write_Property_Multiple, */ +/* Device_Communication_Control, Confirmed_Private_Transfer, */ +/* Confirmed_Text_Message, Reinitialize_Device, */ +/* VT_Open, VT_Close, VT_Data_Handler, */ +/* Authenticate, Request_Key */ typedef void (*confirmed_function) (uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); -// generic confirmed simple ack function handler +/* generic confirmed simple ack function handler */ typedef void (*confirmed_simple_ack_function) (BACNET_ADDRESS * src, uint8_t invoke_id); -// generic confirmed ack function handler +/* generic confirmed ack function handler */ typedef void (*confirmed_ack_function) (uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data); -// generic error reply function +/* generic error reply function */ typedef void (*error_function) (BACNET_ADDRESS * src, uint8_t invoke_id, BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code); -// generic abort reply function +/* generic abort reply function */ typedef void (*abort_function) (BACNET_ADDRESS * src, uint8_t invoke_id, uint8_t abort_reason); -// generic reject reply function +/* generic reject reply function */ typedef void (*reject_function) (BACNET_ADDRESS * src, uint8_t invoke_id, uint8_t reject_reason); @@ -121,7 +121,7 @@ extern "C" { void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE service_choice, confirmed_simple_ack_function pFunction); -// configure reject for confirmed services that are not supported +/* configure reject for confirmed services that are not supported */ void apdu_set_unrecognized_service_handler_handler(confirmed_function pFunction); @@ -149,15 +149,15 @@ extern "C" { void apdu_set_reject_handler(reject_function pFunction); - uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, // APDU data + uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */ uint16_t apdu_len, BACNET_CONFIRMED_SERVICE_DATA * service_data, uint8_t * service_choice, uint8_t ** service_request, uint16_t * service_request_len); - void apdu_handler(BACNET_ADDRESS * src, // source address - bool data_expecting_reply, uint8_t * apdu, // APDU data - uint16_t pdu_len); // for confirmed messages + void apdu_handler(BACNET_ADDRESS * src, /* source address */ + bool data_expecting_reply, uint8_t * apdu, /* APDU data */ + uint16_t pdu_len); /* for confirmed messages */ #ifdef __cplusplus } diff --git a/bacnet-stack/arcnet.h b/bacnet-stack/arcnet.h index c9e8dc0c..1d15ee1b 100644 --- a/bacnet-stack/arcnet.h +++ b/bacnet-stack/arcnet.h @@ -39,7 +39,7 @@ #include #include "bacdef.h" -// specific defines for ARCNET +/* specific defines for ARCNET */ #define MAX_HEADER (1+1+2+2+1+1+1+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) @@ -53,26 +53,26 @@ extern "C" { /* function to send a packet out the 802.2 socket */ /* returns 0 on success, non-zero on failure */ - int arcnet_send(BACNET_ADDRESS * dest, // destination address - BACNET_ADDRESS * src, // source address - uint8_t * pdu, // any data to be sent - may be null - unsigned pdu_len); // number of bytes of data + int arcnet_send(BACNET_ADDRESS * dest, /* destination address */ + BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* any data to be sent - may be null */ + unsigned pdu_len); /* number of bytes of data */ /* function to send a packet out the 802.2 socket */ /* returns zero on success, non-zero on failure */ - int arcnet_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 + int arcnet_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 */ -// receives an framed packet -// returns the number of octets in the PDU, or zero on failure - uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout); // milliseconds to wait for a packet +/* receives an framed packet */ +/* returns the number of octets in the PDU, or zero on failure */ + uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout); /* milliseconds to wait for a packet */ void arcnet_get_my_address(BACNET_ADDRESS * my_address); - void arcnet_get_broadcast_address(BACNET_ADDRESS * dest); // destination address + void arcnet_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ #ifdef __cplusplus } diff --git a/bacnet-stack/arf.c b/bacnet-stack/arf.c index a001c53a..7e3bcf33 100644 --- a/bacnet-stack/arf.c +++ b/bacnet-stack/arf.c @@ -38,20 +38,20 @@ #include "device.h" #include "arf.h" -// Atomic Read File +/* Atomic Read File */ -// encode service +/* encode service */ int arf_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; // service choice + apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ apdu_len = 4; apdu_len += encode_tagged_object_id(&apdu[apdu_len], data->object_type, data->object_instance); @@ -80,7 +80,7 @@ int arf_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int arf_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data) { @@ -88,9 +88,9 @@ int arf_decode_service_request(uint8_t * apdu, int tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - int type = 0; // for decoding + int type = 0; /* for decoding */ - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { len = decode_tag_number_and_value(&apdu[0], &tag_number, @@ -101,9 +101,9 @@ int arf_decode_service_request(uint8_t * apdu, data->object_type = type; if (decode_is_opening_tag_number(&apdu[len], 0)) { data->access = FILE_STREAM_ACCESS; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; - // fileStartPosition + /* fileStartPosition */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -111,7 +111,7 @@ int arf_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.stream.fileStartPosition); - // requestedOctetCount + /* requestedOctetCount */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -121,13 +121,13 @@ int arf_decode_service_request(uint8_t * apdu, len_value_type, &data->type.stream.requestedOctetCount); if (!decode_is_closing_tag_number(&apdu[len], 0)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else if (decode_is_opening_tag_number(&apdu[len], 1)) { data->access = FILE_RECORD_ACCESS; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; - // fileStartRecord + /* fileStartRecord */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -135,7 +135,7 @@ int arf_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.record.fileStartRecord); - // RecordCount + /* RecordCount */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -145,7 +145,7 @@ int arf_decode_service_request(uint8_t * apdu, len_value_type, &data->type.record.RecordCount); if (!decode_is_closing_tag_number(&apdu[len], 1)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else return -1; @@ -163,10 +163,10 @@ int arf_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_READ_FILE) return -1; @@ -180,18 +180,18 @@ int arf_decode_apdu(uint8_t * apdu, return len; } -// encode service +/* encode service */ int arf_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; apdu[1] = invoke_id; - apdu[2] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; // service choice + apdu[2] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ apdu_len = 3; - // endOfFile + /* endOfFile */ apdu_len += encode_tagged_boolean(&apdu[apdu_len], data->endOfFile); switch (data->access) { @@ -221,7 +221,7 @@ int arf_ack_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int arf_ack_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data) { @@ -230,7 +230,7 @@ int arf_ack_decode_service_request(uint8_t * apdu, uint8_t tag_number = 0; uint32_t len_value_type = 0; - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { len = decode_tag_number_and_value(&apdu[0], &tag_number, @@ -240,9 +240,9 @@ int arf_ack_decode_service_request(uint8_t * apdu, data->endOfFile = decode_boolean(len_value_type); if (decode_is_opening_tag_number(&apdu[len], 0)) { data->access = FILE_STREAM_ACCESS; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; - // fileStartPosition + /* fileStartPosition */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -250,7 +250,7 @@ int arf_ack_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.stream.fileStartPosition); - // fileData + /* fileData */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -260,13 +260,13 @@ int arf_ack_decode_service_request(uint8_t * apdu, len_value_type, &data->fileData); if (!decode_is_closing_tag_number(&apdu[len], 0)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else if (decode_is_opening_tag_number(&apdu[len], 1)) { data->access = FILE_RECORD_ACCESS; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; - // fileStartRecord + /* fileStartRecord */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -274,7 +274,7 @@ int arf_ack_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.record.fileStartRecord); - // returnedRecordCount + /* returnedRecordCount */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -282,7 +282,7 @@ int arf_ack_decode_service_request(uint8_t * apdu, return -1; len += decode_unsigned(&apdu[len], len_value_type, &data->type.record.RecordCount); - // fileData + /* fileData */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -292,7 +292,7 @@ int arf_ack_decode_service_request(uint8_t * apdu, len_value_type, &data->fileData); if (!decode_is_closing_tag_number(&apdu[len], 1)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else return -1; @@ -310,7 +310,7 @@ int arf_ack_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ diff --git a/bacnet-stack/arf.h b/bacnet-stack/arf.h index 0b260e7f..b693e737 100644 --- a/bacnet-stack/arf.h +++ b/bacnet-stack/arf.h @@ -50,7 +50,7 @@ typedef struct BACnet_Atomic_Read_File_Data { } stream; struct { int32_t fileStartRecord; - // requested or returned record count + /* requested or returned record count */ uint32_t RecordCount; } record; } type; @@ -62,12 +62,12 @@ typedef struct BACnet_Atomic_Read_File_Data { extern "C" { #endif /* __cplusplus */ -// Atomic Read File -// encode service +/* Atomic Read File */ +/* encode service */ int arf_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); -// decode the service request only +/* decode the service request only */ int arf_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data); @@ -75,13 +75,13 @@ extern "C" { unsigned apdu_len, uint8_t * invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); -// Atomic Read File Ack +/* Atomic Read File Ack */ -// encode service +/* encode service */ int arf_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); -// decode the service request only +/* decode the service request only */ int arf_ack_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data); diff --git a/bacnet-stack/awf.c b/bacnet-stack/awf.c index 159c5440..2422210b 100644 --- a/bacnet-stack/awf.c +++ b/bacnet-stack/awf.c @@ -38,20 +38,20 @@ #include "device.h" #include "awf.h" -// Atomic Write File +/* Atomic Write File */ -// encode service +/* encode service */ int awf_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; // service choice + apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ apdu_len = 4; apdu_len += encode_tagged_object_id(&apdu[apdu_len], data->object_type, data->object_instance); @@ -82,7 +82,7 @@ int awf_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int awf_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data) { @@ -90,9 +90,9 @@ int awf_decode_service_request(uint8_t * apdu, int tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - int type = 0; // for decoding + int type = 0; /* for decoding */ - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { len = decode_tag_number_and_value(&apdu[0], &tag_number, @@ -103,9 +103,9 @@ int awf_decode_service_request(uint8_t * apdu, data->object_type = type; if (decode_is_opening_tag_number(&apdu[len], 0)) { data->access = FILE_STREAM_ACCESS; - // a tag number of 2 is not extended so only one octet + /* a tag number of 2 is not extended so only one octet */ len++; - // fileStartPosition + /* fileStartPosition */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -113,7 +113,7 @@ int awf_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.stream.fileStartPosition); - // fileData + /* fileData */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -123,13 +123,13 @@ int awf_decode_service_request(uint8_t * apdu, len_value_type, &data->fileData); if (!decode_is_closing_tag_number(&apdu[len], 0)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else if (decode_is_opening_tag_number(&apdu[len], 1)) { data->access = FILE_RECORD_ACCESS; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; - // fileStartRecord + /* fileStartRecord */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -137,7 +137,7 @@ int awf_decode_service_request(uint8_t * apdu, return -1; len += decode_signed(&apdu[len], len_value_type, &data->type.record.fileStartRecord); - // returnedRecordCount + /* returnedRecordCount */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -145,7 +145,7 @@ int awf_decode_service_request(uint8_t * apdu, return -1; len += decode_unsigned(&apdu[len], len_value_type, &data->type.record.returnedRecordCount); - // fileData + /* fileData */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); len += tag_len; @@ -155,7 +155,7 @@ int awf_decode_service_request(uint8_t * apdu, len_value_type, &data->fileData); if (!decode_is_closing_tag_number(&apdu[len], 1)) return -1; - // a tag number is not extended so only one octet + /* a tag number is not extended so only one octet */ len++; } else return -1; @@ -173,10 +173,10 @@ int awf_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_WRITE_FILE) return -1; @@ -193,12 +193,12 @@ int awf_decode_apdu(uint8_t * apdu, int awf_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; apdu[1] = invoke_id; - apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; // service choice + apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ apdu_len = 3; switch (data->access) { case FILE_STREAM_ACCESS: @@ -217,7 +217,7 @@ int awf_ack_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int awf_ack_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data) { @@ -225,7 +225,7 @@ int awf_ack_decode_service_request(uint8_t * apdu, uint8_t tag_number = 0; uint32_t len_value_type = 0; - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { len = decode_tag_number_and_value(&apdu[0], &tag_number, @@ -254,7 +254,7 @@ int awf_ack_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ diff --git a/bacnet-stack/awf.h b/bacnet-stack/awf.h index cc0af1b2..639a8c98 100644 --- a/bacnet-stack/awf.h +++ b/bacnet-stack/awf.h @@ -58,12 +58,12 @@ typedef struct BACnet_Atomic_Write_File_Data { extern "C" { #endif /* __cplusplus */ -// Atomic Write File -// encode service +/* Atomic Write File */ +/* encode service */ int awf_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); -// decode the service request only +/* decode the service request only */ int awf_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data); @@ -71,12 +71,12 @@ extern "C" { unsigned apdu_len, uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); -// Atomic Write File Ack -// encode service +/* Atomic Write File Ack */ +/* encode service */ int awf_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); -// decode the service request only +/* decode the service request only */ int awf_ack_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data); diff --git a/bacnet-stack/bacapp.c b/bacnet-stack/bacapp.c index 89c65275..757ef837 100644 --- a/bacnet-stack/bacapp.c +++ b/bacnet-stack/bacapp.c @@ -46,7 +46,7 @@ int bacapp_encode_application_data(uint8_t * apdu, BACNET_APPLICATION_DATA_VALUE * value) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { if (value->tag == BACNET_APPLICATION_TAG_NULL) diff --git a/bacnet-stack/bacdcode.c b/bacnet-stack/bacdcode.c index 4f25a533..9ca0b00c 100644 --- a/bacnet-stack/bacdcode.c +++ b/bacnet-stack/bacdcode.c @@ -41,8 +41,8 @@ #include "bigend.h" #include "bacstr.h" -// NOTE: byte order plays a role in decoding multibyte values -// http://www.unixpapa.com/incnote/byteorder.html +/* NOTE: byte order plays a role in decoding multibyte values */ +/* http://www.unixpapa.com/incnote/byteorder.html */ /* max-segments-accepted B'000' Unspecified number of segments accepted. @@ -73,9 +73,9 @@ B'1110' reserved by ASHRAE B'1111' reserved by ASHRAE */ -// from clause 20.1.2.4 max-segments-accepted -// and clause 20.1.2.5 max-APDU-length-accepted -// returns the encoded octet +/* from clause 20.1.2.4 max-segments-accepted */ +/* and clause 20.1.2.5 max-APDU-length-accepted */ +/* returns the encoded octet */ uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu) { uint8_t octet = 0; @@ -97,29 +97,29 @@ uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu) else octet = 0x70; - // max_apdu must be 50 octets minimum + /* max_apdu must be 50 octets minimum */ if (max_apdu <= 50) octet |= 0x00; else if (max_apdu <= 128) octet |= 0x01; - //fits in a LonTalk frame + /*fits in a LonTalk frame */ else if (max_apdu <= 206) octet |= 0x02; - //fits in an ARCNET or MS/TP frame + /*fits in an ARCNET or MS/TP frame */ else if (max_apdu <= 480) octet |= 0x03; else if (max_apdu <= 1024) octet |= 0x04; - // fits in an ISO 8802-3 frame + /* fits in an ISO 8802-3 frame */ else if (max_apdu <= 1476) octet |= 0x05; return octet; } -// from clause 20.1.2.4 max-segments-accepted -// and clause 20.1.2.5 max-APDU-length-accepted -// returns the encoded octet +/* from clause 20.1.2.4 max-segments-accepted */ +/* and clause 20.1.2.5 max-APDU-length-accepted */ +/* returns the encoded octet */ int decode_max_segs(uint8_t octet) { int max_segs = 0; @@ -493,19 +493,19 @@ int decode_signed32(uint8_t * apdu, int32_t * value) return 4; } -// from clause 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, uint32_t len_value_type) { - int len = 1; // return value + int len = 1; /* return value */ apdu[0] = 0; if (context_specific) apdu[0] = BIT3; - // additional tag byte after this byte - // for extended tag byte + /* additional tag byte after this byte */ + /* for extended tag byte */ if (tag_number <= 14) apdu[0] |= (tag_number << 4); else { @@ -514,8 +514,8 @@ int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, len++; } - // NOTE: additional len byte(s) after extended tag byte - // if larger than 4 + /* NOTE: additional len byte(s) after extended tag byte */ + /* if larger than 4 */ if (len_value_type <= 4) apdu[0] |= len_value_type; else { @@ -535,14 +535,14 @@ int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, return len; } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ int encode_opening_tag(uint8_t * apdu, uint8_t tag_number) { int len = 1; apdu[0] = BIT3; - // additional tag byte after this byte for extended tag byte + /* additional tag byte after this byte for extended tag byte */ if (tag_number <= 14) apdu[0] |= (tag_number << 4); else { @@ -551,20 +551,20 @@ int encode_opening_tag(uint8_t * apdu, uint8_t tag_number) len++; } - // type indicates opening tag + /* type indicates opening tag */ apdu[0] |= 6; return len; } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ int encode_closing_tag(uint8_t * apdu, uint8_t tag_number) { int len = 1; apdu[0] = BIT3; - // additional tag byte after this byte for extended tag byte + /* additional tag byte after this byte for extended tag byte */ if (tag_number <= 14) apdu[0] |= (tag_number << 4); else { @@ -573,28 +573,28 @@ int encode_closing_tag(uint8_t * apdu, uint8_t tag_number) len++; } - // type indicates closing tag + /* type indicates closing tag */ apdu[0] |= 7; return len; } -// from clause 20.2.1.3.2 Constructed Data -// returns true if extended tag numbering is used +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns true if extended tag numbering is used */ static bool decode_is_extended_tag_number(uint8_t * apdu) { return ((apdu[0] & 0xF0) == 0xF0); } -// from clause 20.2.1.3.2 Constructed Data -// returns true if the extended value is used +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns true if the extended value is used */ static bool decode_is_extended_value(uint8_t * apdu) { return ((apdu[0] & 0x07) == 5); } -// from clause 20.2.1.3.2 Constructed Data -// returns true if the tag is context specific +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns true if the tag is context specific */ bool decode_is_context_specific(uint8_t * apdu) { return ((apdu[0] & BIT3) == BIT3); @@ -602,11 +602,11 @@ bool decode_is_context_specific(uint8_t * apdu) int decode_tag_number(uint8_t * apdu, uint8_t * tag_number) { - int len = 1; // return value + int len = 1; /* return value */ - // decode the tag number first + /* decode the tag number first */ if (decode_is_extended_tag_number(&apdu[0])) { - // extended tag + /* extended tag */ if (tag_number) *tag_number = apdu[1]; len++; @@ -623,17 +623,17 @@ static bool decode_is_opening_tag(uint8_t * apdu) return ((apdu[0] & 0x07) == 6); } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ static bool decode_is_closing_tag(uint8_t * apdu) { return ((apdu[0] & 0x07) == 7); } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ int decode_tag_number_and_value(uint8_t * apdu, uint8_t * tag_number, uint32_t * value) { @@ -642,23 +642,23 @@ int decode_tag_number_and_value(uint8_t * apdu, uint32_t value32; len = decode_tag_number(&apdu[0], tag_number); - // decode the value + /* decode the value */ if (decode_is_extended_value(&apdu[0])) { - // tagged as uint32_t + /* tagged as uint32_t */ if (apdu[len] == 255) { len++; len += decode_unsigned32(&apdu[len], &value32); if (value) *value = value32; } - // tagged as uint16_t + /* tagged as uint16_t */ else if (apdu[len] == 254) { len++; len += decode_unsigned16(&apdu[len], &value16); if (value) *value = value16; } - // no tag - must be uint8_t + /* no tag - must be uint8_t */ else { if (value) *value = apdu[len]; @@ -666,18 +666,18 @@ int decode_tag_number_and_value(uint8_t * apdu, } } else if (decode_is_opening_tag(&apdu[0]) && value) *value = 0; - // closing tag + /* closing tag */ else if (decode_is_closing_tag(&apdu[0]) && value) *value = 0; - // small value + /* small value */ else if (value) *value = apdu[0] & 0x07; return len; } -// from clause 20.2.1.3.2 Constructed Data -// returns true if the tag is context specific and matches +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns true if the tag is context specific and matches */ bool decode_is_context_tag(uint8_t * apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; @@ -689,8 +689,8 @@ bool decode_is_context_tag(uint8_t * apdu, uint8_t tag_number) return (context_specific && (my_tag_number == tag_number)); } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ bool decode_is_opening_tag_number(uint8_t * apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; @@ -702,8 +702,8 @@ bool decode_is_opening_tag_number(uint8_t * apdu, uint8_t tag_number) return (opening_tag && (my_tag_number == tag_number)); } -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ bool decode_is_closing_tag_number(uint8_t * apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; @@ -715,9 +715,9 @@ bool decode_is_closing_tag_number(uint8_t * apdu, uint8_t tag_number) return (closing_tag && (my_tag_number == tag_number)); } -// from clause 20.2.3 Encoding of a Boolean Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.3 Encoding of a Boolean Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_boolean(uint8_t * apdu, bool boolean_value) { int len = 0; @@ -732,7 +732,7 @@ int encode_tagged_boolean(uint8_t * apdu, bool boolean_value) return len; } -// context tagged is encoded differently +/* context tagged is encoded differently */ int encode_context_boolean(uint8_t * apdu, bool boolean_value) { apdu[0] = boolean_value ? 1 : 0; @@ -750,9 +750,9 @@ bool decode_context_boolean(uint8_t * apdu) return boolean_value; } -// from clause 20.2.3 Encoding of a Boolean Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.3 Encoding of a Boolean Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ bool decode_boolean(uint32_t len_value) { bool boolean_value = false; @@ -763,9 +763,9 @@ bool decode_boolean(uint32_t len_value) return boolean_value; } -// from clause 20.2.2 Encoding of a Null Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.2 Encoding of a Null Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_null(uint8_t * apdu) { return encode_tag(&apdu[0], BACNET_APPLICATION_TAG_NULL, false, 0); @@ -795,8 +795,8 @@ static uint8_t byte_reverse_bits(uint8_t in_byte) return out_byte; } -// from clause 20.2.10 Encoding of a Bit String Value -// returns the number of apdu bytes consumed +/* from clause 20.2.10 Encoding of a Bit String Value */ +/* returns the number of apdu bytes consumed */ int decode_bitstring(uint8_t * apdu, uint32_t len_value, BACNET_BIT_STRING * bit_string) { @@ -808,7 +808,7 @@ int decode_bitstring(uint8_t * apdu, uint32_t len_value, bitstring_init(bit_string); if (len_value) { - // the first octet contains the unused bits + /* the first octet contains the unused bits */ bytes_used = len_value - 1; if (bytes_used <= MAX_BITSTRING_BYTES) { len = 1; @@ -825,8 +825,8 @@ int decode_bitstring(uint8_t * apdu, uint32_t len_value, return len; } -// from clause 20.2.10 Encoding of a Bit String Value -// returns the number of apdu bytes consumed +/* from clause 20.2.10 Encoding of a Bit String Value */ +/* returns the number of apdu bytes consumed */ int encode_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string) { int len = 0; @@ -834,14 +834,14 @@ int encode_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string) uint8_t used_bytes = 0; uint8_t i = 0; - // if the bit string is empty, then the first octet shall be zero + /* if the bit string is empty, then the first octet shall be zero */ if (bitstring_bits_used(bit_string) == 0) apdu[len++] = 0; else { used_bytes = bitstring_bytes_used(bit_string); remaining_used_bits = bitstring_bits_used(bit_string) - ((used_bytes - 1) * 8); - // number of unused bits in the subsequent final octet + /* number of unused bits in the subsequent final octet */ apdu[len++] = 8 - remaining_used_bits; for (i = 0; i < used_bytes; i++) { apdu[len++] = @@ -855,9 +855,9 @@ int encode_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string) int encode_tagged_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string) { int len = 0; - int bit_string_encoded_length = 1; // 1 for the bits remaining octet + int bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ - // bit string may use more than 1 octet for the tag, so find out how many + /* bit string may use more than 1 octet for the tag, so find out how many */ bit_string_encoded_length += bitstring_bytes_used(bit_string); len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false, bit_string_encoded_length); @@ -866,8 +866,8 @@ int encode_tagged_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string) return len; } -// from clause 20.2.6 Encoding of a Real Number Value -// returns the number of apdu bytes consumed +/* from clause 20.2.6 Encoding of a Real Number Value */ +/* returns the number of apdu bytes consumed */ int decode_real(uint8_t * apdu, float *real_value) { union { @@ -892,8 +892,8 @@ int decode_real(uint8_t * apdu, float *real_value) return 4; } -// from clause 20.2.6 Encoding of a Real Number Value -// returns the number of apdu bytes consumed +/* from clause 20.2.6 Encoding of a Real Number Value */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_real(float value, uint8_t * apdu) { union { @@ -918,22 +918,22 @@ int encode_bacnet_real(float value, uint8_t * apdu) return 4; } -// from clause 20.2.6 Encoding of a Real Number Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.6 Encoding of a Real Number Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_real(uint8_t * apdu, float value) { int len = 0; - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_real(value, &apdu[1]); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_REAL, false, len); return len; } -// from clause 20.2.14 Encoding of an Object Identifier Value -// returns the number of apdu bytes consumed +/* from clause 20.2.14 Encoding of an Object Identifier Value */ +/* returns the number of apdu bytes consumed */ int decode_object_id(uint8_t * apdu, int *object_type, uint32_t * instance) { uint32_t value = 0; @@ -946,8 +946,8 @@ int decode_object_id(uint8_t * apdu, int *object_type, uint32_t * instance) return len; } -// from clause 20.2.14 Encoding of an Object Identifier Value -// returns the number of apdu bytes consumed +/* from clause 20.2.14 Encoding of an Object Identifier Value */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_object_id(uint8_t * apdu, int object_type, uint32_t instance) { @@ -963,30 +963,30 @@ int encode_bacnet_object_id(uint8_t * apdu, return len; } -// from clause 20.2.14 Encoding of an Object Identifier Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.14 Encoding of an Object Identifier Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_context_object_id(uint8_t * apdu, int tag_number, int object_type, uint32_t instance) { int len = 0; - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_object_id(&apdu[1], object_type, instance); len += encode_tag(&apdu[0], (uint8_t) tag_number, true, len); return len; } -// from clause 20.2.14 Encoding of an Object Identifier Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.14 Encoding of an Object Identifier Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_object_id(uint8_t * apdu, int object_type, uint32_t instance) { int len = 0; - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_object_id(&apdu[1], object_type, instance); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OBJECT_ID, false, len); @@ -994,8 +994,8 @@ int encode_tagged_object_id(uint8_t * apdu, return len; } -// from clause 20.2.8 Encoding of an Octet String Value -// returns the number of apdu bytes consumed +/* from clause 20.2.8 Encoding of an Octet String Value */ +/* returns the number of apdu bytes consumed */ int encode_octet_string(uint8_t * apdu, BACNET_OCTET_STRING * octet_string) { int len = 0; /* return value */ @@ -1010,9 +1010,9 @@ int encode_octet_string(uint8_t * apdu, BACNET_OCTET_STRING * octet_string) return len; } -// from clause 20.2.8 Encoding of an Octet String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.8 Encoding of an Octet String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_octet_string(uint8_t * apdu, BACNET_OCTET_STRING * octet_string) { @@ -1033,13 +1033,13 @@ int encode_tagged_octet_string(uint8_t * apdu, return apdu_len; } -// from clause 20.2.8 Encoding of an Octet String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.8 Encoding of an Octet String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_octet_string(uint8_t * apdu, uint32_t len_value, BACNET_OCTET_STRING * octet_string) { - int len = 0; // return value + int len = 0; /* return value */ bool status = false; status = octetstring_init(octet_string, &apdu[0], len_value); @@ -1049,8 +1049,8 @@ int decode_octet_string(uint8_t * apdu, uint32_t len_value, return len; } -// from clause 20.2.9 Encoding of a Character String Value -// returns the number of apdu bytes consumed +/* from clause 20.2.9 Encoding of a Character String Value */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_character_string(uint8_t * apdu, BACNET_CHARACTER_STRING * char_string) { @@ -1063,9 +1063,9 @@ int encode_bacnet_character_string(uint8_t * apdu, return len + 1 /* for encoding */ ; } -// from clause 20.2.9 Encoding of a Character String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.9 Encoding of a Character String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_character_string(uint8_t * apdu, BACNET_CHARACTER_STRING * char_string) { @@ -1102,13 +1102,13 @@ int encode_context_character_string(uint8_t * apdu, int tag_number, return len; } -// from clause 20.2.9 Encoding of a Character String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.9 Encoding of a Character String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_character_string(uint8_t * apdu, uint32_t len_value, BACNET_CHARACTER_STRING * char_string) { - int len = 0; // return value + int len = 0; /* return value */ bool status = false; status = characterstring_init(char_string, apdu[0], (char *) &apdu[1], @@ -1119,13 +1119,13 @@ int decode_character_string(uint8_t * apdu, uint32_t len_value, return len; } -// from clause 20.2.4 Encoding of an Unsigned Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed -// FIXME: What about endian? +/* from clause 20.2.4 Encoding of an Unsigned Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ +/* FIXME: What about endian? */ int encode_bacnet_unsigned(uint8_t * apdu, uint32_t value) { - int len = 0; // return value + int len = 0; /* return value */ if (value < 0x100) { apdu[0] = (uint8_t) value; @@ -1141,9 +1141,9 @@ int encode_bacnet_unsigned(uint8_t * apdu, uint32_t value) return len; } -// from clause 20.2.4 Encoding of an Unsigned Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.4 Encoding of an Unsigned Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_context_unsigned(uint8_t * apdu, int tag_number, uint32_t value) { int len = 0; @@ -1154,9 +1154,9 @@ int encode_context_unsigned(uint8_t * apdu, int tag_number, uint32_t value) return len; } -// from clause 20.2.4 Encoding of an Unsigned Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.4 Encoding of an Unsigned Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_unsigned(uint8_t * apdu, uint32_t value) { int len = 0; @@ -1168,10 +1168,10 @@ int encode_tagged_unsigned(uint8_t * apdu, uint32_t value) return len; } -// from clause 20.2.4 Encoding of an Unsigned Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed -// FIXME: What about endian? +/* from clause 20.2.4 Encoding of an Unsigned Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ +/* FIXME: What about endian? */ int decode_unsigned(uint8_t * apdu, uint32_t len_value, uint32_t * value) { uint16_t unsigned16_value = 0; @@ -1200,9 +1200,9 @@ int decode_unsigned(uint8_t * apdu, uint32_t len_value, uint32_t * value) return len_value; } -// from clause 20.2.11 Encoding of an Enumerated Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.11 Encoding of an Enumerated Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_enumerated(uint8_t * apdu, uint32_t len_value, int *value) { uint32_t unsigned_value = 0; @@ -1215,22 +1215,22 @@ int decode_enumerated(uint8_t * apdu, uint32_t len_value, int *value) return len; } -// from clause 20.2.11 Encoding of an Enumerated Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.11 Encoding of an Enumerated Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_enumerated(uint8_t * apdu, int value) { return encode_bacnet_unsigned(apdu, value); } -// from clause 20.2.11 Encoding of an Enumerated Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.11 Encoding of an Enumerated Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_enumerated(uint8_t * apdu, int value) { - int len = 0; // return value + int len = 0; /* return value */ - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_enumerated(&apdu[1], value); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED, false, len); @@ -1238,23 +1238,23 @@ int encode_tagged_enumerated(uint8_t * apdu, int value) return len; } -// from clause 20.2.11 Encoding of an Enumerated Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.11 Encoding of an Enumerated Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_context_enumerated(uint8_t * apdu, int tag_number, int value) { - int len = 0; // return value + int len = 0; /* return value */ - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_enumerated(&apdu[1], value); len += encode_tag(&apdu[0], (uint8_t) tag_number, true, len); return len; } -// from clause 20.2.5 Encoding of a Signed Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.5 Encoding of a Signed Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_signed(uint8_t * apdu, uint32_t len_value, int32_t * value) { int8_t signed8_value = 0; @@ -1285,12 +1285,12 @@ int decode_signed(uint8_t * apdu, uint32_t len_value, int32_t * value) return len_value; } -// from clause 20.2.5 Encoding of a Signed Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.5 Encoding of a Signed Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_signed(uint8_t * apdu, int32_t value) { - int len = 0; // return value + int len = 0; /* return value */ /* don't encode the leading X'FF' or X'00' of the two's compliment. That is, the first octet of any multi-octet encoded value shall @@ -1310,14 +1310,14 @@ int encode_bacnet_signed(uint8_t * apdu, int32_t value) return len; } -// from clause 20.2.5 Encoding of a Signed Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.5 Encoding of a Signed Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_signed(uint8_t * apdu, int32_t value) { - int len = 0; // return value + int len = 0; /* return value */ - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_signed(&apdu[1], value); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_SIGNED_INT, false, len); @@ -1325,23 +1325,23 @@ int encode_tagged_signed(uint8_t * apdu, int32_t value) return len; } -// from clause 20.2.5 Encoding of a Signed Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.5 Encoding of a Signed Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_context_signed(uint8_t * apdu, int tag_number, int32_t value) { - int len = 0; // return value + int len = 0; /* return value */ - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_signed(&apdu[1], value); len += encode_tag(&apdu[0], (uint8_t) tag_number, true, len); return len; } -// from clause 20.2.13 Encoding of a Time Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.13 Encoding of a Time Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_time(uint8_t * apdu, int hour, int min, int sec, int hundredths) { @@ -1353,15 +1353,15 @@ int encode_bacnet_time(uint8_t * apdu, int hour, int min, int sec, return 4; } -// from clause 20.2.13 Encoding of a Time Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.13 Encoding of a Time Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_time(uint8_t * apdu, int hour, int min, int sec, int hundredths) { int len = 0; - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_time(&apdu[1], hour, min, sec, hundredths); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_TIME, false, len); @@ -1369,9 +1369,9 @@ int encode_tagged_time(uint8_t * apdu, int hour, int min, int sec, } -// from clause 20.2.13 Encoding of a Time Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.13 Encoding of a Time Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_bacnet_time(uint8_t * apdu, int *hour, int *min, int *sec, int *hundredths) { @@ -1383,15 +1383,15 @@ int decode_bacnet_time(uint8_t * apdu, int *hour, int *min, int *sec, return 4; } -// BACnet Date -// year = years since 1900 -// month 1=Jan -// day = day of month -// wday 1=Monday...7=Sunday +/* BACnet Date */ +/* year = years since 1900 */ +/* month 1=Jan */ +/* day = day of month */ +/* wday 1=Monday...7=Sunday */ -// from clause 20.2.12 Encoding of a Date Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.12 Encoding of a Date Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_date(uint8_t * apdu, int year, int month, int day, int wday) { @@ -1410,15 +1410,15 @@ int encode_bacnet_date(uint8_t * apdu, int year, int month, int day, return 4; } -// from clause 20.2.12 Encoding of a Date Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.12 Encoding of a Date Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tagged_date(uint8_t * apdu, int year, int month, int day, int wday) { int len = 0; - // assumes that the tag only consumes 1 octet + /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_date(&apdu[1], year, month, day, wday); len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DATE, false, len); @@ -1426,9 +1426,9 @@ int encode_tagged_date(uint8_t * apdu, int year, int month, int day, } -// from clause 20.2.12 Encoding of a Date Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.12 Encoding of a Date Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_date(uint8_t * apdu, int *year, int *month, int *day, int *wday) { *year = apdu[0] + 1900; @@ -1439,7 +1439,7 @@ int decode_date(uint8_t * apdu, int *year, int *month, int *day, int *wday) return 4; } -// returns the number of apdu bytes consumed +/* returns the number of apdu bytes consumed */ int encode_simple_ack(uint8_t * apdu, uint8_t invoke_id, uint8_t service_choice) { @@ -1464,7 +1464,7 @@ static int get_apdu_len(bool extended_tag, uint32_t value) if (extended_tag) test_len++; if (value <= 4) - test_len += 0; // do nothing... + test_len += 0; /* do nothing... */ else if (value <= 253) test_len += 1; else if (value <= 65535) @@ -1480,8 +1480,8 @@ static void print_apdu(uint8_t * pBlock, uint32_t num) size_t lines = 0; /* number of lines to print */ size_t line = 0; /* line of text counter */ size_t last_line = 0; /* line on which the last text resided */ - unsigned long count = 0; // address to print - unsigned int i = 0; // counter + unsigned long count = 0; /* address to print */ + unsigned int i = 0; /* counter */ if (pBlock && num) { /* how many lines to print? */ @@ -1552,7 +1552,7 @@ void testBACDCodeTags(Test * pTest) ct_test(pTest, tag_number == test_tag_number); ct_test(pTest, decode_is_opening_tag(&apdu[0]) == false); ct_test(pTest, decode_is_closing_tag(&apdu[0]) == true); - // test the len-value-type portion + /* test the len-value-type portion */ for (value = 1;; value = value << 1) { len = encode_tag(&apdu[0], tag_number, false, value); len = decode_tag_number_and_value(&apdu[0], &test_tag_number, @@ -1563,11 +1563,11 @@ void testBACDCodeTags(Test * pTest) get_apdu_len(decode_is_extended_tag_number(&apdu[0]), value); ct_test(pTest, len == test_len); - // stop at the the last value + /* stop at the the last value */ if (value & BIT31) break; } - // stop after the last tag number + /* stop after the last tag number */ if (tag_number == 255) break; } @@ -1593,10 +1593,10 @@ void testBACDCodeReal(Test * pTest) ct_test(pTest, memcmp(&real_array, &encoded_array, sizeof(real_array)) == 0); - // a real will take up 4 octects plus a one octet tag + /* a real will take up 4 octects plus a one octet tag */ apdu_len = encode_tagged_real(&apdu[0], value); ct_test(pTest, apdu_len == 5); - // len tells us how many octets were used for encoding the value + /* len tells us how many octets were used for encoding the value */ len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_REAL); ct_test(pTest, decode_is_context_specific(&apdu[0]) == false); @@ -1629,24 +1629,24 @@ void testBACDCodeEnumerated(Test * pTest) ct_test(pTest, decoded_value == value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_ENUMERATED); ct_test(pTest, len == apdu_len); - // encode back the value + /* encode back the value */ encode_tagged_enumerated(&encoded_array[0], decoded_value); ct_test(pTest, memcmp(&array[0], &encoded_array[0], sizeof(array)) == 0); - // an enumerated will take up to 4 octects - // plus a one octet for the tag + /* an enumerated will take up to 4 octects */ + /* plus a one octet for the tag */ apdu_len = encode_tagged_enumerated(&apdu[0], value); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); ct_test(pTest, len == 1); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_ENUMERATED); ct_test(pTest, decode_is_context_specific(&apdu[0]) == false); - // context specific encoding + /* context specific encoding */ apdu_len = encode_context_enumerated(&apdu[0], 3, value); ct_test(pTest, decode_is_context_specific(&apdu[0]) == true); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); ct_test(pTest, len == 1); ct_test(pTest, tag_number == 3); - // test the interesting values + /* test the interesting values */ value = value << 1; } @@ -1674,11 +1674,11 @@ void testBACDCodeUnsignedValue(Test * pTest, uint32_t value) encode_tagged_unsigned(&encoded_array[0], decoded_value); ct_test(pTest, memcmp(&array[0], &encoded_array[0], sizeof(array)) == 0); - // an unsigned will take up to 4 octects - // plus a one octet for the tag + /* an unsigned will take up to 4 octects */ + /* plus a one octet for the tag */ apdu_len = encode_tagged_unsigned(&apdu[0], value); - // apdu_len varies... - //ct_test(pTest, apdu_len == 5); + /* apdu_len varies... */ + /*ct_test(pTest, apdu_len == 5); */ len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); ct_test(pTest, len == 1); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_UNSIGNED_INT); @@ -1728,8 +1728,8 @@ void testBACDCodeSignedValue(Test * pTest, int32_t value) print_apdu(&array[0], sizeof(array)); print_apdu(&encoded_array[0], sizeof(array)); } - // a signed int will take up to 4 octects - // plus a one octet for the tag + /* a signed int will take up to 4 octects */ + /* plus a one octet for the tag */ apdu_len = encode_tagged_signed(&apdu[0], value); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_SIGNED_INT); @@ -1769,7 +1769,7 @@ void testBACDCodeOctetString(Test * pTest) BACNET_OCTET_STRING octet_string; BACNET_OCTET_STRING test_octet_string; uint8_t test_value[MAX_APDU] = { "" }; - int i; // for loop counter + int i; /* for loop counter */ int apdu_len; int len; uint8_t tag_number = 0; @@ -1822,7 +1822,7 @@ void testBACDCodeCharacterString(Test * pTest) BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING test_char_string; char test_value[MAX_APDU] = { "" }; - int i; // for loop counter + int i; /* for loop counter */ int apdu_len; int len; uint8_t tag_number = 0; @@ -1920,7 +1920,7 @@ void testBACDCodeMaxSegsApdu(Test * pTest) int j = 0; uint8_t octet = 0; - // test + /* test */ for (i = 0; i < 8; i++) { for (j = 0; j < 6; j++) { octet = encode_max_segs_max_apdu(max_segs[i], max_apdu[j]); @@ -1941,19 +1941,19 @@ void testBACDCodeBitString(Test * pTest) int len = 0; bitstring_init(&bit_string); - // verify initialization + /* verify initialization */ ct_test(pTest, bitstring_bits_used(&bit_string) == 0); for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { ct_test(pTest, bitstring_bit(&bit_string, bit) == false); } - // test encode/decode -- true + /* test encode/decode -- true */ for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { bitstring_set_bit(&bit_string, bit, true); ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); ct_test(pTest, bitstring_bit(&bit_string, bit) == true); - // encode + /* encode */ len = encode_tagged_bitstring(&apdu[0], &bit_string); - // decode + /* decode */ len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_BIT_STRING); @@ -1963,15 +1963,15 @@ void testBACDCodeBitString(Test * pTest) bitstring_bits_used(&decoded_bit_string) == (bit + 1)); ct_test(pTest, bitstring_bit(&decoded_bit_string, bit) == true); } - // test encode/decode -- false + /* test encode/decode -- false */ bitstring_init(&bit_string); for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { bitstring_set_bit(&bit_string, bit, false); ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); ct_test(pTest, bitstring_bit(&bit_string, bit) == false); - // encode + /* encode */ len = encode_tagged_bitstring(&apdu[0], &bit_string); - // decode + /* decode */ len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_BIT_STRING); @@ -2011,7 +2011,7 @@ int main(void) assert(rc); rc = ct_addTestFunction(pTest, testBACDCodeBitString); assert(rc); - // configure output + /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); (void) ct_report(pTest); diff --git a/bacnet-stack/bacdcode.h b/bacnet-stack/bacdcode.h index 224f7e98..159bc76d 100644 --- a/bacnet-stack/bacdcode.h +++ b/bacnet-stack/bacdcode.h @@ -44,54 +44,54 @@ extern "C" { #endif /* __cplusplus */ -// from clause 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, uint32_t len_value_type); -// from clause 20.2.1.3.2 Constructed Data -// returns the number of apdu bytes consumed +/* from clause 20.2.1.3.2 Constructed Data */ +/* returns the number of apdu bytes consumed */ int encode_opening_tag(uint8_t * apdu, uint8_t tag_number); int encode_closing_tag(uint8_t * apdu, uint8_t tag_number); int decode_tag_number_and_value(uint8_t * apdu, uint8_t * tag_number, uint32_t * value); -// returns true if the tag is context specific +/* returns true if the tag is context specific */ bool decode_is_context_specific(uint8_t * apdu); -// returns true if the tag is an opening tag and matches +/* returns true if the tag is an opening tag and matches */ bool decode_is_opening_tag_number(uint8_t * apdu, uint8_t tag_number); -// returns true if the tag is a closing tag and matches +/* returns true if the tag is a closing tag and matches */ bool decode_is_closing_tag_number(uint8_t * apdu, uint8_t tag_number); -// returns true if the tag is context specific and matches +/* returns true if the tag is context specific and matches */ bool decode_is_context_tag(uint8_t * apdu, uint8_t tag_number); -// from clause 20.2.2 Encoding of a Null Value +/* from clause 20.2.2 Encoding of a Null Value */ int encode_tagged_null(uint8_t * apdu); -// from clause 20.2.3 Encoding of a Boolean Value +/* from clause 20.2.3 Encoding of a Boolean Value */ int encode_tagged_boolean(uint8_t * apdu, bool boolean_value); bool decode_boolean(uint32_t len_value); int encode_context_boolean(uint8_t * apdu, bool boolean_value); bool decode_context_boolean(uint8_t * apdu); -// from clause 20.2.10 Encoding of a Bit String Value -// returns the number of apdu bytes consumed +/* from clause 20.2.10 Encoding of a Bit String Value */ +/* returns the number of apdu bytes consumed */ int decode_bitstring(uint8_t * apdu, uint32_t len_value, BACNET_BIT_STRING * bit_string); -// returns the number of apdu bytes consumed +/* returns the number of apdu bytes consumed */ int encode_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string); int encode_tagged_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string); -// from clause 20.2.6 Encoding of a Real Number Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.6 Encoding of a Real Number Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_real(uint8_t * apdu, float *real_value); int encode_bacnet_real(float value, uint8_t * apdu); int encode_tagged_real(uint8_t * apdu, float value); -// from clause 20.2.14 Encoding of an Object Identifier Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.14 Encoding of an Object Identifier Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_object_id(uint8_t * apdu, int *object_type, uint32_t * instance); int encode_bacnet_object_id(uint8_t * apdu, int object_type, @@ -101,9 +101,9 @@ extern "C" { int encode_tagged_object_id(uint8_t * apdu, int object_type, uint32_t instance); -// from clause 20.2.8 Encoding of an Octet String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.8 Encoding of an Octet String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_octet_string(uint8_t * apdu, BACNET_OCTET_STRING * octet_string); int encode_tagged_octet_string(uint8_t * apdu, @@ -112,9 +112,9 @@ extern "C" { BACNET_OCTET_STRING * octet_string); -// from clause 20.2.9 Encoding of a Character String Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.9 Encoding of a Character String Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_character_string(uint8_t * apdu, BACNET_CHARACTER_STRING * char_string); int encode_tagged_character_string(uint8_t * apdu, @@ -124,9 +124,9 @@ extern "C" { int decode_character_string(uint8_t * apdu, uint32_t len_value, BACNET_CHARACTER_STRING * char_string); -// from clause 20.2.4 Encoding of an Unsigned Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.4 Encoding of an Unsigned Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_unsigned(uint8_t * apdu, uint32_t value); int encode_context_unsigned(uint8_t * apdu, int tag_number, uint32_t value); @@ -134,27 +134,27 @@ extern "C" { int decode_unsigned(uint8_t * apdu, uint32_t len_value, uint32_t * value); -// from clause 20.2.5 Encoding of a Signed Integer Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.5 Encoding of a Signed Integer Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_signed(uint8_t * apdu, int32_t value); int encode_tagged_signed(uint8_t * apdu, int32_t value); int encode_context_signed(uint8_t * apdu, int tag_number, int32_t value); int decode_signed(uint8_t * apdu, uint32_t len_value, int32_t * value); -// from clause 20.2.11 Encoding of an Enumerated Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.11 Encoding of an Enumerated Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int decode_enumerated(uint8_t * apdu, uint32_t len_value, int *value); int encode_bacnet_enumerated(uint8_t * apdu, int value); int encode_tagged_enumerated(uint8_t * apdu, int value); int encode_context_enumerated(uint8_t * apdu, int tag_number, int value); -// from clause 20.2.13 Encoding of a Time Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.13 Encoding of a Time Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_time(uint8_t * apdu, int hour, int min, int sec, int hundredths); int encode_tagged_time(uint8_t * apdu, int hour, int min, int sec, @@ -162,15 +162,15 @@ extern "C" { int decode_bacnet_time(uint8_t * apdu, int *hour, int *min, int *sec, int *hundredths); -// BACnet Date -// year = years since 1900 -// month 1=Jan -// day = day of month -// wday 1=Monday...7=Sunday +/* BACnet Date */ +/* year = years since 1900 */ +/* month 1=Jan */ +/* day = day of month */ +/* wday 1=Monday...7=Sunday */ -// from clause 20.2.12 Encoding of a Date Value -// and 20.2.1 General Rules for Encoding BACnet Tags -// returns the number of apdu bytes consumed +/* from clause 20.2.12 Encoding of a Date Value */ +/* and 20.2.1 General Rules for Encoding BACnet Tags */ +/* returns the number of apdu bytes consumed */ int encode_bacnet_date(uint8_t * apdu, int year, int month, int day, int wday); int encode_tagged_date(uint8_t * apdu, int year, int month, int day, @@ -178,21 +178,21 @@ extern "C" { int decode_date(uint8_t * apdu, int *year, int *month, int *day, int *wday); -// two octet unsigned16 +/* two octet unsigned16 */ int encode_unsigned16(uint8_t * apdu, uint16_t value); int decode_unsigned16(uint8_t * apdu, uint16_t * value); -// four octet unsigned32 +/* four octet unsigned32 */ int encode_unsigned32(uint8_t * apdu, uint32_t value); int decode_unsigned32(uint8_t * apdu, uint32_t * value); -// from clause 20.1.2.4 max-segments-accepted -// and clause 20.1.2.5 max-APDU-length-accepted -// returns the encoded octet +/* from clause 20.1.2.4 max-segments-accepted */ +/* and clause 20.1.2.5 max-APDU-length-accepted */ +/* returns the encoded octet */ uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu); int decode_max_segs(uint8_t octet); int decode_max_apdu(uint8_t octet); -// returns the number of apdu bytes consumed +/* returns the number of apdu bytes consumed */ int encode_simple_ack(uint8_t * apdu, uint8_t invoke_id, uint8_t service_choice); diff --git a/bacnet-stack/bacdef.h b/bacnet-stack/bacdef.h index ce45e912..dce15b32 100644 --- a/bacnet-stack/bacdef.h +++ b/bacnet-stack/bacdef.h @@ -39,23 +39,23 @@ #include "bacenum.h" #include "config.h" -// largest BACnet Instance Number -// Also used as a device instance number wildcard address +/* largest BACnet Instance Number */ +/* Also used as a device instance number wildcard address */ #define BACNET_MAX_INSTANCE (0x3FFFFF) #define BACNET_INSTANCE_BITS 22 -// large BACnet Object Type +/* large BACnet Object Type */ #define BACNET_MAX_OBJECT (0x3FF) -// Array index 0=size of array, n=array element n, MAX=all array elements +/* Array index 0=size of array, n=array element n, MAX=all array elements */ #define BACNET_ARRAY_LENGTH_INDEX 0 #define BACNET_ARRAY_ALL (~0) -// Priority Array for commandable objects +/* Priority Array for commandable objects */ #define BACNET_NO_PRIORITY 0 #define BACNET_MIN_PRIORITY 1 #define BACNET_MAX_PRIORITY 16 -// embedded systems need fixed name sizes +/* embedded systems need fixed name sizes */ #define MAX_OBJECT_NAME 10 -// common object properties +/* common object properties */ typedef struct BACnet_Object_Data { uint32_t Object_Identifier; char Object_Name[MAX_OBJECT_NAME]; @@ -63,20 +63,20 @@ typedef struct BACnet_Object_Data { } BACNET_OBJECT_DATA; #define BACNET_BROADCAST_NETWORK 0xFFFF -// IPv6 (16 octets) coupled with port number (2 octets) +/* IPv6 (16 octets) coupled with port number (2 octets) */ #define MAX_MAC_LEN 18 struct BACnet_Device_Address { - // mac_len = 0 if global address + /* mac_len = 0 if global address */ int mac_len; - // note: MAC for IP addresses uses 4 bytes for addr, 2 bytes for port - // use de/encode_unsigned32/16 for re/storing the IP address + /* note: MAC for IP addresses uses 4 bytes for addr, 2 bytes for port */ + /* use de/encode_unsigned32/16 for re/storing the IP address */ uint8_t mac[MAX_MAC_LEN]; - // DNET,DLEN,DADR or SNET,SLEN,SADR - // the following are used if the device is behind a router - // net = 0 indicates local + /* DNET,DLEN,DADR or SNET,SLEN,SADR */ + /* the following are used if the device is behind a router */ + /* net = 0 indicates local */ uint16_t net; /* BACnet network number */ - // LEN = 0 denotes broadcast MAC ADR and ADR field is absent - // LEN > 0 specifies length of ADR field + /* LEN = 0 denotes broadcast MAC ADR and ADR field is absent */ + /* LEN > 0 specifies length of ADR field */ int len; /* length of MAC address */ uint8_t adr[MAX_MAC_LEN]; /* hwaddr (MAC) address */ }; diff --git a/bacnet-stack/bacenum.h b/bacnet-stack/bacenum.h index ef1a2214..924c95ed 100644 --- a/bacnet-stack/bacenum.h +++ b/bacnet-stack/bacenum.h @@ -130,7 +130,7 @@ typedef enum { PROP_PROGRAM_STATE = 92, PROP_PROPORTIONAL_CONSTANT = 93, PROP_PROPORTIONAL_CONSTANT_UNITS = 94, - PROP_PROTOCOL_CONFORMANCE_CLASS = 95, // deleted in version 1 revision 2 + PROP_PROTOCOL_CONFORMANCE_CLASS = 95, /* deleted in version 1 revision 2 */ PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED = 96, PROP_PROTOCOL_SERVICES_SUPPORTED = 97, PROP_PROTOCOL_VERSION = 98, @@ -229,13 +229,13 @@ typedef enum { PROP_VALUE_SET = 191, PROP_VALUE_CHANGE_TIME = 192, - // The special property identifiers all, optional, and required - // are reserved for use in the ReadPropertyConditional and - // ReadPropertyMultiple services or services not defined in this standard. - // Enumerated values 0-511 are reserved for definition by ASHRAE. - // Enumerated values 512-4194303 may be used by others subject to the - // procedures and constraints described in Clause 23. - // The highest enumeration used in this version is 168. + /* The special property identifiers all, optional, and required */ + /* are reserved for use in the ReadPropertyConditional and */ + /* ReadPropertyMultiple services or services not defined in this standard. */ + /* Enumerated values 0-511 are reserved for definition by ASHRAE. */ + /* Enumerated values 512-4194303 may be used by others subject to the */ + /* procedures and constraints described in Clause 23. */ + /* The highest enumeration used in this version is 168. */ MAX_BACNET_PROPERTY_ID = 4194303 } BACNET_PROPERTY_ID; @@ -520,9 +520,9 @@ typedef enum { PROGRAM_ERROR_INTERNAL = 2, PROGRAM_ERROR_PROGRAM = 3, PROGRAM_ERROR_OTHER = 4 - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ } BACNET_PROGRAM_ERROR; typedef enum { @@ -537,9 +537,9 @@ typedef enum { RELIABILITY_PROCESS_ERROR = 8, RELIABILITY_MULTI_STATE_FAULT = 9, RELIABILITY_CONFIGURATION_ERROR = 10 - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ } BACNET_RELIABILITY; typedef enum { @@ -555,13 +555,13 @@ typedef enum { EVENT_EXTENDED = 9, EVENT_BUFFER_READY = 10, EVENT_UNSIGNED_RANGE = 11, - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. - // It is expected that these enumerated values will correspond to - // the use of the complex-event-type CHOICE [6] of the - // BACnetNotificationParameters production. - // The last enumeration used in this version is 11. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ + /* It is expected that these enumerated values will correspond to */ + /* the use of the complex-event-type CHOICE [6] of the */ + /* BACnetNotificationParameters production. */ + /* The last enumeration used in this version is 11. */ } BACNET_EVENT_TYPE; typedef enum { @@ -586,9 +586,9 @@ typedef enum { LIFE_SAFETY_MODE_DISABLED = 12, LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13, LIFE_SAFETY_MODE_DEFAULT = 14 - // Enumerated values 0-255 are reserved for definition by ASHRAE. - // Enumerated values 256-65535 may be used by others subject to - // procedures and constraints described in Clause 23. + /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ + /* Enumerated values 256-65535 may be used by others subject to */ + /* procedures and constraints described in Clause 23. */ } BACNET_LIFE_SAFETY_MODE; typedef enum { @@ -602,9 +602,9 @@ typedef enum { LIFE_SAFETY_OPERATION_UNSILENCE = 7, LIFE_SAFETY_OPERATION_UNSILENCE_AUDIBLE = 8, LIFE_SAFETY_OPERATION_UNSILENCE_VISUAL = 9 - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* procedures and constraints described in Clause 23. */ } BACNET_LIFE_SAFETY_OPERATION; typedef enum { @@ -632,9 +632,9 @@ typedef enum { LIFE_SAFETY_STATE_GENERAL_ALARM = 21, LIFE_SAFETY_STATE_SUPERVISORY = 22, LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23 - // Enumerated values 0-255 are reserved for definition by ASHRAE. - // Enumerated values 256-65535 may be used by others subject to - // procedures and constraints described in Clause 23. + /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ + /* Enumerated values 256-65535 may be used by others subject to */ + /* procedures and constraints described in Clause 23. */ } BACNET_LIFE_SAFETY_STATE; typedef enum { @@ -642,9 +642,9 @@ typedef enum { MAINTENANCE_PERIODIC_TEST = 1, AINTENANCE_NEED_SERVICE_OPERATIONAL = 2, MAINTENANCE_NEED_SERVICE_INOPERATIVE = 3 - // Enumerated values 0-255 are reserved for definition by ASHRAE. - // Enumerated values 256-65535 may be used by others subject to - // procedures and constraints described in Clause 23. + /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ + /* Enumerated values 256-65535 may be used by others subject to */ + /* procedures and constraints described in Clause 23. */ } BACNET_MAINTENANCE; typedef enum { @@ -679,10 +679,10 @@ typedef enum { OBJECT_LIFE_SAFETY_ZONE = 22, OBJECT_ACCUMULATOR = 23, OBJECT_PULSE_CONVERTER = 24, - // Enumerated values 0-127 are reserved for definition by ASHRAE. - // Enumerated values 128-1023 may be used by others subject to - // the procedures and constraints described in Clause 23. - MAX_ASHRAE_OBJECT_TYPE = 25, // used for bit string loop + /* Enumerated values 0-127 are reserved for definition by ASHRAE. */ + /* Enumerated values 128-1023 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ + MAX_ASHRAE_OBJECT_TYPE = 25, /* used for bit string loop */ MAX_BACNET_OBJECT_TYPE = 1023 } BACNET_OBJECT_TYPE; @@ -702,9 +702,9 @@ typedef enum { VT_CLASS_DEC_VT220 = 4, VT_CLASS_HP_700_94 = 5, /* real name is HP 700/94 */ VT_CLASS_IBM_3130 = 6 - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ } BACNET_VT_CLASS; typedef enum { @@ -736,8 +736,8 @@ typedef enum { MAX_BACNET_APPLICATION_TAG = 16 } BACNET_APPLICATION_TAG; -// note: these are not the real values, -// but are shifted left for easy encoding +/* note: these are not the real values, */ +/* but are shifted left for easy encoding */ typedef enum { PDU_TYPE_CONFIRMED_SERVICE_REQUEST = 0, PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST = 0x10, @@ -750,7 +750,7 @@ typedef enum { } BACNET_PDU_TYPE; typedef enum { - // Alarm and Event Services + /* Alarm and Event Services */ SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM = 0, SERVICE_CONFIRMED_COV_NOTIFICATION = 1, SERVICE_CONFIRMED_EVENT_NOTIFICATION = 2, @@ -760,10 +760,10 @@ typedef enum { SERVICE_CONFIRMED_SUBSCRIBE_COV = 5, SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY = 28, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION = 27, - // File Access Services + /* File Access Services */ SERVICE_CONFIRMED_ATOMIC_READ_FILE = 6, SERVICE_CONFIRMED_ATOMIC_WRITE_FILE = 7, - // Object Access Services + /* Object Access Services */ SERVICE_CONFIRMED_ADD_LIST_ELEMENT = 8, SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT = 9, SERVICE_CONFIRMED_CREATE_OBJECT = 10, @@ -774,23 +774,23 @@ typedef enum { SERVICE_CONFIRMED_READ_RANGE = 26, SERVICE_CONFIRMED_WRITE_PROPERTY = 15, SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE = 16, - // Remote Device Management Services + /* Remote Device Management Services */ SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL = 17, SERVICE_CONFIRMED_PRIVATE_TRANSFER = 18, SERVICE_CONFIRMED_TEXT_MESSAGE = 19, SERVICE_CONFIRMED_REINITIALIZE_DEVICE = 20, - // Virtual Terminal Services + /* Virtual Terminal Services */ SERVICE_CONFIRMED_VT_OPEN = 21, SERVICE_CONFIRMED_VT_CLOSE = 22, SERVICE_CONFIRMED_VT_DATA = 23, - // Security Services + /* Security Services */ SERVICE_CONFIRMED_AUTHENTICATE = 24, SERVICE_CONFIRMED_REQUEST_KEY = 25, - // Services added after 1995 - // readRange (26) see Object Access Services - // lifeSafetyOperation (27) see Alarm and Event Services - // subscribeCOVProperty (28) see Alarm and Event Services - // getEventInformation (29) see Alarm and Event Services + /* Services added after 1995 */ + /* readRange (26) see Object Access Services */ + /* lifeSafetyOperation (27) see Alarm and Event Services */ + /* subscribeCOVProperty (28) see Alarm and Event Services */ + /* getEventInformation (29) see Alarm and Event Services */ MAX_BACNET_CONFIRMED_SERVICE = 30 } BACNET_CONFIRMED_SERVICE; @@ -805,17 +805,17 @@ typedef enum { SERVICE_UNCONFIRMED_WHO_HAS = 7, SERVICE_UNCONFIRMED_WHO_IS = 8, SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION = 9, - // Other services to be added as they are defined. - // All choice values in this production are reserved - // for definition by ASHRAE. - // Proprietary extensions are made by using the - // UnconfirmedPrivateTransfer service. See Clause 23. + /* Other services to be added as they are defined. */ + /* All choice values in this production are reserved */ + /* for definition by ASHRAE. */ + /* Proprietary extensions are made by using the */ + /* UnconfirmedPrivateTransfer service. See Clause 23. */ MAX_BACNET_UNCONFIRMED_SERVICE = 10 } BACNET_UNCONFIRMED_SERVICE; -// Bit String Enumerations +/* Bit String Enumerations */ typedef enum { - // Alarm and Event Services + /* Alarm and Event Services */ SERVICE_SUPPORTED_ACKNOWLEDGE_ALARM = 0, SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION = 1, SERVICE_SUPPORTED_CONFIRMED_EVENT_NOTIFICATION = 2, @@ -825,10 +825,10 @@ typedef enum { SERVICE_SUPPORTED_SUBSCRIBE_COV = 5, SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY = 38, SERVICE_SUPPORTED_LIFE_SAFETY_OPERATION = 37, - // File Access Services + /* File Access Services */ SERVICE_SUPPORTED_ATOMIC_READ_FILE = 6, SERVICE_SUPPORTED_ATOMIC_WRITE_FILE = 7, - // Object Access Services + /* Object Access Services */ SERVICE_SUPPORTED_ADD_LIST_ELEMENT = 8, SERVICE_SUPPORTED_REMOVE_LIST_ELEMENT = 9, SERVICE_SUPPORTED_CREATE_OBJECT = 10, @@ -839,16 +839,16 @@ typedef enum { SERVICE_SUPPORTED_READ_RANGE = 35, SERVICE_SUPPORTED_WRITE_PROPERTY = 15, SERVICE_SUPPORTED_WRITE_PROPERTY_MULTIPLE = 16, - // Remote Device Management Services + /* Remote Device Management Services */ SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL = 17, SERVICE_SUPPORTED_PRIVATE_TRANSFER = 18, SERVICE_SUPPORTED_TEXT_MESSAGE = 19, SERVICE_SUPPORTED_REINITIALIZE_DEVICE = 20, - // Virtual Terminal Services + /* Virtual Terminal Services */ SERVICE_SUPPORTED_VT_OPEN = 21, SERVICE_SUPPORTED_VT_CLOSE = 22, SERVICE_SUPPORTED_VT_DATA = 23, - // Security Services + /* Security Services */ SERVICE_SUPPORTED_AUTHENTICATE = 24, SERVICE_SUPPORTED_REQUEST_KEY = 25, SERVICE_SUPPORTED_I_AM = 26, @@ -861,13 +861,13 @@ typedef enum { SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION = 36, SERVICE_SUPPORTED_WHO_HAS = 33, SERVICE_SUPPORTED_WHO_IS = 34, - // Other services to be added as they are defined. - // All values in this production are reserved - // for definition by ASHRAE. + /* Other services to be added as they are defined. */ + /* All values in this production are reserved */ + /* for definition by ASHRAE. */ MAX_BACNET_SERVICES_SUPPORTED = 40 } BACNET_SERVICES_SUPPORTED; -// Bit String Enumerations +/* Bit String Enumerations */ typedef enum { STATUS_FLAG_IN_ALARM = 0, STATUS_FLAG_FAULT = 1, @@ -918,10 +918,10 @@ typedef enum { MESSAGE_PRIORITY_LIFE_SAFETY = 3 } BACNET_MESSAGE_PRIORITY; -//Network Layer Message Type -//If Bit 7 of the control octet described in 6.2.2 is 1, -// a message type octet shall be present as shown in Figure 6-1. -// The following message types are indicated: +/*Network Layer Message Type */ +/*If Bit 7 of the control octet described in 6.2.2 is 1, */ +/* a message type octet shall be present as shown in Figure 6-1. */ +/* The following message types are indicated: */ typedef enum { NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK = 0, NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK = 1, @@ -933,8 +933,8 @@ typedef enum { NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE_ACK = 7, NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK = 8, NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9 - // X'0A' to X'7F': Reserved for use by ASHRAE, - // X'80' to X'FF': Available for vendor proprietary messages + /* X'0A' to X'7F': Reserved for use by ASHRAE, */ + /* X'80' to X'FF': Available for vendor proprietary messages */ } BACNET_NETWORK_MESSAGE_TYPE; @@ -954,9 +954,9 @@ typedef enum { ABORT_REASON_INVALID_APDU_IN_THIS_STATE = 2, ABORT_REASON_PREEMPTED_BY_HIGHER_PRIORITY_TASK = 3, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED = 4, - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ MAX_BACNET_ABORT_REASON = 5, FIRST_PROPRIETARY_ABORT_REASON = 64, LAST_PROPRIETARY_ABORT_REASON = 65535 @@ -973,9 +973,9 @@ typedef enum { REJECT_REASON_TOO_MANY_ARGUMENTS = 7, REJECT_REASON_UNDEFINED_ENUMERATION = 8, REJECT_REASON_UNRECOGNIZED_SERVICE = 9, - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ MAX_BACNET_REJECT_REASON = 10, FIRST_PROPRIETARY_REJECT_REASON = 64, LAST_PROPRIETARY_REJECT_REASON = 65535 @@ -989,9 +989,9 @@ typedef enum { ERROR_CLASS_SECURITY = 4, ERROR_CLASS_SERVICES = 5, ERROR_CLASS_VT = 6, - // Enumerated values 0-63 are reserved for definition by ASHRAE. - // Enumerated values 64-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. + /* Enumerated values 0-63 are reserved for definition by ASHRAE. */ + /* Enumerated values 64-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ MAX_BACNET_ERROR_CLASS = 7, FIRST_PROPRIETARY_ERROR_CLASS = 64, LAST_PROPRIETARY_ERROR_CLASS = 65535 @@ -1057,10 +1057,10 @@ typedef enum { /* see duplicate-name (48), */ /* see duplicate-object-id (49), */ /* see property-is-not-an-array (50), */ - // Enumerated values 0-255 are reserved for definition by ASHRAE. - // Enumerated values 256-65535 may be used by others subject to - // the procedures and constraints described in Clause 23. - // The last enumeration used in this version is 50. + /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ + /* Enumerated values 256-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ + /* The last enumeration used in this version is 50. */ MAX_BACNET_ERROR_CODE = 51, FIRST_PROPRIETARY_ERROR_CODE = 256, LAST_PROPRIETARY_ERROR_CODE = 65535 @@ -1077,4 +1077,4 @@ typedef enum { MAX_BACNET_REINITIALIZED_STATE = 7 } BACNET_REINITIALIZED_STATE; -#endif // end of BACENUM_H +#endif /* end of BACENUM_H */ diff --git a/bacnet-stack/bacerror.c b/bacnet-stack/bacerror.c index 52b7684b..fc38be4a 100644 --- a/bacnet-stack/bacerror.c +++ b/bacnet-stack/bacerror.c @@ -36,20 +36,20 @@ #include "bacdcode.h" #include "bacdef.h" -// encode service +/* encode service */ int bacerror_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_CONFIRMED_SERVICE service, BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_ERROR; apdu[1] = invoke_id; apdu[2] = service; apdu_len = 3; - // service parameters + /* service parameters */ apdu_len += encode_tagged_enumerated(&apdu[apdu_len], error_class); apdu_len += encode_tagged_enumerated(&apdu[apdu_len], error_code); } @@ -57,7 +57,7 @@ int bacerror_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the application class and code +/* decode the application class and code */ int bacerror_decode_error_class_and_code(uint8_t * apdu, unsigned apdu_len, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) @@ -68,7 +68,7 @@ int bacerror_decode_error_class_and_code(uint8_t * apdu, int decoded_value = 0; if (apdu_len) { - // error class + /* error class */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) @@ -77,7 +77,7 @@ int bacerror_decode_error_class_and_code(uint8_t * apdu, decode_enumerated(&apdu[len], len_value_type, &decoded_value); if (error_class) *error_class = decoded_value; - // error code + /* error code */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) @@ -91,7 +91,7 @@ int bacerror_decode_error_class_and_code(uint8_t * apdu, return len; } -// decode the service request only +/* decode the service request only */ int bacerror_decode_service_request(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, @@ -105,7 +105,7 @@ int bacerror_decode_service_request(uint8_t * apdu, *invoke_id = apdu[0]; if (service) *service = apdu[1]; - // decode the application class and code + /* decode the application class and code */ len = bacerror_decode_error_class_and_code(&apdu[2], apdu_len - 2, error_class, error_code); } @@ -113,7 +113,7 @@ int bacerror_decode_service_request(uint8_t * apdu, return len; } -// decode the whole APDU - mainly used for unit testing +/* decode the whole APDU - mainly used for unit testing */ int bacerror_decode_apdu(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, @@ -124,7 +124,7 @@ int bacerror_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu_len) { if (apdu[0] != PDU_TYPE_ERROR) return -1; @@ -171,7 +171,7 @@ void testBACError(Test * pTest) ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_code == error_code); - // change type to get negative response + /* change type to get negative response */ apdu[0] = PDU_TYPE_ABORT; len = bacerror_decode_apdu(&apdu[0], apdu_len, @@ -179,14 +179,14 @@ void testBACError(Test * pTest) &test_service, &test_error_class, &test_error_code); ct_test(pTest, len == -1); - // test NULL APDU + /* test NULL APDU */ len = bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_service, &test_error_class, &test_error_code); ct_test(pTest, len == -1); - // force a zero length + /* force a zero length */ len = bacerror_decode_apdu(&apdu[0], 0, &test_invoke_id, @@ -194,7 +194,7 @@ void testBACError(Test * pTest) ct_test(pTest, len == 0); - // check them all... + /* check them all... */ for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) { for (error_class = 0; error_class < MAX_BACNET_ERROR_CLASS; error_class++) { @@ -217,7 +217,7 @@ void testBACError(Test * pTest) } } - // max boundaries + /* max boundaries */ service = 255; error_class = LAST_PROPRIETARY_ERROR_CLASS; error_code = LAST_PROPRIETARY_ERROR_CODE; diff --git a/bacnet-stack/bacstr.c b/bacnet-stack/bacstr.c index 8f847f87..cd142503 100644 --- a/bacnet-stack/bacstr.c +++ b/bacnet-stack/bacstr.c @@ -55,7 +55,7 @@ void bitstring_set_bit(BACNET_BIT_STRING * bit_string, uint8_t bit, uint8_t bit_mask = 1; if (byte_number < MAX_BITSTRING_BYTES) { - // set max bits used + /* set max bits used */ if (bit_string->bits_used < (bit + 1)) bit_string->bits_used = bit + 1; bit_mask = bit_mask << (bit - (byte_number * 8)); @@ -86,17 +86,17 @@ uint8_t bitstring_bits_used(BACNET_BIT_STRING * bit_string) return bit_string->bits_used; } -// returns the number of bytes that a bit string is using +/* returns the number of bytes that a bit string is using */ int bitstring_bytes_used(BACNET_BIT_STRING * bit_string) { - int len = 0; // return value + int len = 0; /* return value */ uint8_t used_bytes = 0; uint8_t last_bit = 0; if (bit_string->bits_used) { last_bit = bit_string->bits_used - 1; used_bytes = last_bit / 8; - // add one for the first byte + /* add one for the first byte */ used_bytes++; len = used_bytes; } @@ -471,19 +471,19 @@ void testBitString(Test * pTest) BACNET_BIT_STRING bit_string; bitstring_init(&bit_string); - // verify initialization + /* verify initialization */ ct_test(pTest, bitstring_bits_used(&bit_string) == 0); for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { ct_test(pTest, bitstring_bit(&bit_string, bit) == false); } - // test for true + /* test for true */ for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { bitstring_set_bit(&bit_string, bit, true); ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); ct_test(pTest, bitstring_bit(&bit_string, bit) == true); } - // test for false + /* test for false */ bitstring_init(&bit_string); for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { bitstring_set_bit(&bit_string, bit, false); @@ -504,7 +504,7 @@ void testCharacterString(Test * pTest) size_t test_length = 0; size_t i = 0; - // verify initialization + /* verify initialization */ status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0); ct_test(pTest, status == true); @@ -562,7 +562,7 @@ void testOctetString(Test * pTest) size_t test_length = 0; size_t i = 0; - // verify initialization + /* verify initialization */ status = octetstring_init(&bacnet_string, NULL, 0); ct_test(pTest, status == true); ct_test(pTest, octetstring_length(&bacnet_string) == 0); @@ -625,7 +625,7 @@ int main(void) assert(rc); rc = ct_addTestFunction(pTest, testOctetString); assert(rc); - // configure output + /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); (void) ct_report(pTest); diff --git a/bacnet-stack/bacstr.h b/bacnet-stack/bacstr.h index 4f6939e1..048d9f4a 100644 --- a/bacnet-stack/bacstr.h +++ b/bacnet-stack/bacstr.h @@ -72,7 +72,7 @@ extern "C" { bool value); bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit); uint8_t bitstring_bits_used(BACNET_BIT_STRING * bit_string); -// returns the number of bytes that a bit string is using +/* returns the number of bytes that a bit string is using */ int bitstring_bytes_used(BACNET_BIT_STRING * bit_string); uint8_t bitstring_bits_capacity(BACNET_BIT_STRING * bit_string); /* used for encoding and decoding from the APDU */ diff --git a/bacnet-stack/bigend.c b/bacnet-stack/bigend.c index c9aac8cd..222327b9 100644 --- a/bacnet-stack/bigend.c +++ b/bacnet-stack/bigend.c @@ -1,19 +1,19 @@ -// Big-Endian systems save the most significant byte first. -// Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. -// "Network Byte Order" is also know as "Big-Endian Byte Order" -// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. -// x[0] = 0x04 -// x[1] = 0x03 -// x[2] = 0x02 -// x[3] = 0x01 +/* Big-Endian systems save the most significant byte first. */ +/* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */ +/* "Network Byte Order" is also know as "Big-Endian Byte Order" */ +/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */ +/* x[0] = 0x04 */ +/* x[1] = 0x03 */ +/* x[2] = 0x02 */ +/* x[3] = 0x01 */ -// Little-Endian systems save the least significant byte first. -// The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. -// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. -// x[0] = 0x01 -// x[1] = 0x02 -// x[2] = 0x03 -// x[3] = 0x04 +/* Little-Endian systems save the least significant byte first. */ +/* The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. */ +/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */ +/* x[0] = 0x01 */ +/* x[1] = 0x02 */ +/* x[2] = 0x03 */ +/* x[3] = 0x04 */ int big_endian(void) { diff --git a/bacnet-stack/bigend.h b/bacnet-stack/bigend.h index 9841e07b..c82b3a65 100644 --- a/bacnet-stack/bigend.h +++ b/bacnet-stack/bigend.h @@ -5,21 +5,21 @@ extern "C" { #endif /* __cplusplus */ -// Big-Endian systems save the most significant byte first. -// Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. -// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. -// x[0] = 0x04 -// x[1] = 0x03 -// x[2] = 0x02 -// x[3] = 0x01 +/* Big-Endian systems save the most significant byte first. */ +/* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */ +/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */ +/* x[0] = 0x04 */ +/* x[1] = 0x03 */ +/* x[2] = 0x02 */ +/* x[3] = 0x01 */ -// Little-Endian systems save the least significant byte first. -// The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. -// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. -// x[0] = 0x01 -// x[1] = 0x02 -// x[2] = 0x03 -// x[3] = 0x04 +/* Little-Endian systems save the least significant byte first. */ +/* The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. */ +/* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */ +/* x[0] = 0x01 */ +/* x[1] = 0x02 */ +/* x[2] = 0x03 */ +/* x[3] = 0x04 */ int big_endian(void); diff --git a/bacnet-stack/bip.c b/bacnet-stack/bip.c index ed72b10b..6dd78055 100644 --- a/bacnet-stack/bip.c +++ b/bacnet-stack/bip.c @@ -32,11 +32,11 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include // for standard integer types uint8_t etc. -#include // for the standard bool type. +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ #include "bacdcode.h" #include "bip.h" -#include "net.h" // custom per port +#include "net.h" /* custom per port */ static int BIP_Socket = -1; /* port to use - stored in host byte order */ @@ -95,37 +95,37 @@ void bip_set_broadcast_address(uint8_t octet1, octet4); } -// set using network byte order +/* set using network byte order */ void bip_set_addr(uint32_t net_address) { BIP_Address.s_addr = ntohl(net_address); } -// returns host byte order +/* returns host byte order */ uint32_t bip_get_addr(void) { return BIP_Address.s_addr; } -// set using network byte order +/* set using network byte order */ void bip_set_broadcast_addr(uint32_t net_address) { BIP_Broadcast_Address.s_addr = ntohl(net_address); } -// returns host byte order +/* returns host byte order */ uint32_t bip_get_broadcast_addr(void) { return BIP_Broadcast_Address.s_addr; } -// set using host byte order +/* set using host byte order */ void bip_set_port(uint16_t port) { BIP_Port = port; } -// returns host byte order +/* returns host byte order */ uint16_t bip_get_port(void) { return BIP_Port; @@ -133,14 +133,14 @@ 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 */ -static int bip_send(struct sockaddr_in *bip_dest, uint8_t * pdu, // any data to be sent - may be null - unsigned pdu_len) // number of bytes of data -{ +static int bip_send(struct sockaddr_in *bip_dest, uint8_t * pdu, /* any data to be sent - may be null */ + unsigned pdu_len) +{ /* number of bytes of data */ uint8_t mtu[MAX_MPDU] = { 0 }; int mtu_len = 0; int bytes_sent = 0; - // assumes that the driver has already been initialized + /* assumes that the driver has already been initialized */ if (BIP_Socket < 0) return BIP_Socket; @@ -165,10 +165,10 @@ static int bip_send(struct sockaddr_in *bip_dest, uint8_t * pdu, // any d /* 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 - uint8_t * pdu, // any data to be sent - may be null - unsigned pdu_len) // number of bytes of data -{ +int bip_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 */ struct sockaddr_in bip_dest; /* load destination IP address */ @@ -189,21 +189,21 @@ int bip_send_pdu(BACNET_ADDRESS * dest, // destination address /* function to send a packet out the BACnet/IP socket */ /* returns 1 on success, 0 on failure */ - return bip_send(&bip_dest, // destination address - pdu, // any data to be sent - may be null - pdu_len); // number of bytes of data + return bip_send(&bip_dest, /* destination address */ + pdu, /* any data to be sent - may be null */ + pdu_len); /* number of bytes of data */ } -// receives a BACnet/IP packet -// returns the number of octets in the PDU, or zero on failure -uint16_t bip_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout) // number of milliseconds to wait for a packet -{ +/* receives a BACnet/IP packet */ +/* returns the number of octets in the PDU, or zero on failure */ +uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout) +{ /* number of milliseconds to wait for a packet */ int received_bytes; - uint8_t buf[MAX_MPDU] = { 0 }; // data - uint16_t pdu_len = 0; // return value + uint8_t buf[MAX_MPDU] = { 0 }; /* data */ + uint16_t pdu_len = 0; /* return value */ fd_set read_fds; int max; struct timeval select_timeout; @@ -259,16 +259,16 @@ uint16_t bip_receive(BACNET_ADDRESS * src, // source address src->mac_len = 6; (void) encode_unsigned32(&src->mac[0], sin.sin_addr.s_addr); (void) encode_unsigned16(&src->mac[4], sin.sin_port); - // FIXME: check destination address - // see if it is broadcast or for us + /* FIXME: check destination address */ + /* see if it is broadcast or for us */ /* decode the length of the PDU - length is inclusive of BVLC */ (void) decode_unsigned16(&buf[2], &pdu_len); /* copy the buffer into the PDU */ pdu_len -= 4; /* BVLC header */ if (pdu_len < max_pdu) memmove(&pdu[0], &buf[4], pdu_len); - // ignore packets that are too large - // clients should check my max-apdu first + /* ignore packets that are too large */ + /* clients should check my max-apdu first */ else pdu_len = 0; } @@ -295,9 +295,9 @@ void bip_get_my_address(BACNET_ADDRESS * my_address) return; } -void bip_get_broadcast_address(BACNET_ADDRESS * dest) // destination address -{ - int i = 0; // counter +void bip_get_broadcast_address(BACNET_ADDRESS * dest) +{ /* destination address */ + int i = 0; /* counter */ if (dest) { dest->mac_len = 6; diff --git a/bacnet-stack/bip.h b/bacnet-stack/bip.h index f8d9e96d..28e29bef 100644 --- a/bacnet-stack/bip.h +++ b/bacnet-stack/bip.h @@ -40,7 +40,7 @@ #include "bacdef.h" #include "net.h" -// specific defines for Ethernet +/* specific defines for Ethernet */ #define MAX_HEADER (1 + 1 + 2) #define MAX_MPDU (MAX_HEADER+MAX_PDU) @@ -48,47 +48,47 @@ extern "C" { #endif /* __cplusplus */ -// note: define init and cleanup in your ports section +/* note: define init and cleanup in your ports section */ bool bip_init(void); -// normal functions... +/* normal functions... */ void bip_cleanup(void); void bip_set_socket(int sock_fd); bool bip_valid(void); - void bip_get_broadcast_address(BACNET_ADDRESS * dest); // destination address + void bip_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ void bip_get_my_address(BACNET_ADDRESS * my_address); /* 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 - uint8_t * pdu, // any data to be sent - may be null - unsigned pdu_len); // number of bytes of data + int bip_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 */ -// receives a BACnet/IP packet -// returns the number of octets in the PDU, or zero on failure - uint16_t bip_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout); // milliseconds to wait for a packet +/* receives a BACnet/IP packet */ +/* returns the number of octets in the PDU, or zero on failure */ + uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout); /* milliseconds to wait for a packet */ void bip_set_address(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4); void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4); -// use host byte order for setting +/* use host byte order for setting */ void bip_set_port(uint16_t port); -// returns host byte order +/* returns host byte order */ uint16_t bip_get_port(void); -// use network byte order for setting +/* use network byte order for setting */ void bip_set_addr(uint32_t net_address); -// returns host byte order +/* returns host byte order */ uint32_t bip_get_addr(void); -// use network byte order for setting +/* use network byte order for setting */ void bip_set_broadcast_addr(uint32_t net_address); -// returns host byte order +/* returns host byte order */ uint32_t bip_get_broadcast_addr(void); void bip_set_interface(char *ifname); diff --git a/bacnet-stack/bytes.h b/bacnet-stack/bytes.h index b77dd87b..f1c360ab 100644 --- a/bacnet-stack/bytes.h +++ b/bacnet-stack/bytes.h @@ -1,4 +1,4 @@ -// Defines the bit/byte/word/long conversions that are used in code +/* Defines the bit/byte/word/long conversions that are used in code */ #ifndef BYTES_H @@ -67,4 +67,4 @@ -#endif // end of header file +#endif /* end of header file */ diff --git a/bacnet-stack/config.h b/bacnet-stack/config.h index 68ab95fd..99836cd8 100644 --- a/bacnet-stack/config.h +++ b/bacnet-stack/config.h @@ -1,32 +1,32 @@ #ifndef CONFIG_H #define CONFIG_H -// declare a single physical layer -//#include "ethernet.h" -//#include "arcnet.h" -//#include "mstp.h" +/* declare a single physical layer */ +/*#include "ethernet.h" */ +/*#include "arcnet.h" */ +/*#include "mstp.h" */ -// Max number of bytes in an APDU. -// Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets -// This is used in constructing messages and to tell others our limits -// 50 is the minimum; adjust to your memory and physical layer constraints -// Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 -//#define MAX_APDU 50 +/* Max number of bytes in an APDU. */ +/* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */ +/* This is used in constructing messages and to tell others our limits */ +/* 50 is the minimum; adjust to your memory and physical layer constraints */ +/* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */ +/*#define MAX_APDU 50 */ #define MAX_APDU 480 -//#define MAX_APDU 1476 +/*#define MAX_APDU 1476 */ -// for confirmed messages, this is the number of transactions -// that we hold in a queue waiting for timeout. -// Configure to zero if you don't want any confirmed messages -// Configure from 1..255 for number of outstanding confirmed -// requests available. +/* for confirmed messages, this is the number of transactions */ +/* that we hold in a queue waiting for timeout. */ +/* Configure to zero if you don't want any confirmed messages */ +/* Configure from 1..255 for number of outstanding confirmed */ +/* requests available. */ #define MAX_TSM_TRANSACTIONS 16 -// The address cache is used for binding to BACnet devices -// The number of entries corresponds to the number of -// devices that might respond to an I-Am on the network. -// If your device is a simple server and does not need to bind, -// then you don't need to use this. +/* The address cache is used for binding to BACnet devices */ +/* The number of entries corresponds to the number of */ +/* devices that might respond to an I-Am on the network. */ +/* If your device is a simple server and does not need to bind, */ +/* then you don't need to use this. */ #define MAX_ADDRESS_CACHE 255 #endif diff --git a/bacnet-stack/crc.c b/bacnet-stack/crc.c index 3d088d03..7ebeadb0 100644 --- a/bacnet-stack/crc.c +++ b/bacnet-stack/crc.c @@ -36,11 +36,11 @@ #include #include -// Accumulate "dataValue" into the CRC in crcValue. -// Return value is updated CRC -// -// The ^ operator means exclusive OR. -// Note: This function is copied directly from the BACnet standard. +/* Accumulate "dataValue" into the CRC in crcValue. */ +/* Return value is updated CRC */ +/* */ +/* The ^ operator means exclusive OR. */ +/* Note: This function is copied directly from the BACnet standard. */ uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue) { uint16_t crc; @@ -56,11 +56,11 @@ uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue) return (crc & 0xfe) ^ ((crc >> 8) & 1); } -// Accumulate "dataValue" into the CRC in crcValue. -// Return value is updated CRC -// -// The ^ operator means exclusive OR. -// Note: This function is copied directly from the BACnet standard. +/* Accumulate "dataValue" into the CRC in crcValue. */ +/* Return value is updated CRC */ +/* */ +/* The ^ operator means exclusive OR. */ +/* Note: This function is copied directly from the BACnet standard. */ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) { uint16_t crcLow; @@ -79,11 +79,11 @@ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) #include "ctest.h" #include "bytes.h" -// test from Annex G 1.0 of BACnet Standard +/* test from Annex G 1.0 of BACnet Standard */ void testCRC8(Test * pTest) { - uint8_t crc = 0xff; // accumulates the crc value - uint8_t frame_crc; // appended to the end of the frame + uint8_t crc = 0xff; /* accumulates the crc value */ + uint8_t frame_crc; /* appended to the end of the frame */ crc = CRC_Calc_Header(0x00, crc); ct_test(pTest, crc == 0x55); @@ -95,16 +95,16 @@ void testCRC8(Test * pTest) ct_test(pTest, crc == 0x95); crc = CRC_Calc_Header(0x00, crc); ct_test(pTest, crc == 0x73); - // send the ones complement of the CRC in place of - // the CRC, and the resulting CRC will always equal 0x55. + /* send the ones complement of the CRC in place of */ + /* the CRC, and the resulting CRC will always equal 0x55. */ frame_crc = ~crc; ct_test(pTest, frame_crc == 0x8C); - // use the ones complement value and the next to last CRC value + /* use the ones complement value and the next to last CRC value */ crc = CRC_Calc_Header(frame_crc, crc); ct_test(pTest, crc == 0x55); } -// test from Annex G 2.0 of BACnet Standard +/* test from Annex G 2.0 of BACnet Standard */ void testCRC16(Test * pTest) { uint16_t crc = 0xffff; @@ -116,8 +116,8 @@ void testCRC16(Test * pTest) ct_test(pTest, crc == 0xEB70); crc = CRC_Calc_Data(0x30, crc); ct_test(pTest, crc == 0x42EF); - // send the ones complement of the CRC in place of - // the CRC, and the resulting CRC will always equal 0xF0B8. + /* send the ones complement of the CRC in place of */ + /* the CRC, and the resulting CRC will always equal 0xF0B8. */ data_crc = ~crc; ct_test(pTest, data_crc == 0xBD10); crc = CRC_Calc_Data(LO_BYTE(data_crc), crc); diff --git a/bacnet-stack/datalink.c b/bacnet-stack/datalink.c index c638ab8f..2f9f590c 100644 --- a/bacnet-stack/datalink.c +++ b/bacnet-stack/datalink.c @@ -35,16 +35,16 @@ #include #include #include "datalink.h" -// currently this is oriented to a single data link -// However, it could handle multiple data links with the -// addition of passing a network number or datalink number -// as part of the calls. +/* currently this is oriented to a single data link */ +/* However, it could handle multiple data links with the */ +/* addition of passing a network number or datalink number */ +/* as part of the calls. */ /* returns number of bytes sent on success, negative on failure */ -int datalink_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 -{ +int datalink_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 */ #ifdef BACDL_ARCNET return arcnet_send_pdu(dest, pdu, pdu_len); #endif @@ -59,12 +59,12 @@ int datalink_send_pdu(BACNET_ADDRESS * dest, // destination address #endif } -// returns the number of octets in the PDU, or zero on failure -uint16_t datalink_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout) // number of milliseconds to wait for a packet -{ +/* returns the number of octets in the PDU, or zero on failure */ +uint16_t datalink_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout) +{ /* number of milliseconds to wait for a packet */ #ifdef BACDL_ARCNET return arcnet_receive(src, pdu, max_pdu, timeout); #endif @@ -95,8 +95,8 @@ void datalink_cleanup(void) #endif } -void datalink_get_broadcast_address(BACNET_ADDRESS * dest) // destination address -{ +void datalink_get_broadcast_address(BACNET_ADDRESS * dest) +{ /* destination address */ #ifdef BACDL_ARCNET arcnet_get_broadcast_address(dest); #endif diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index bf7613d7..769ffeb1 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -60,19 +60,19 @@ extern "C" { #endif /* __cplusplus */ /* returns number of bytes sent on success, negative on failure */ - int datalink_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 + int datalink_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 */ -// returns the number of octets in the PDU, or zero on failure - uint16_t datalink_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout); // number of milliseconds to wait for a packet +/* returns the number of octets in the PDU, or zero on failure */ + uint16_t datalink_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout); /* number of milliseconds to wait for a packet */ void datalink_cleanup(void); - void datalink_get_broadcast_address(BACNET_ADDRESS * dest); // destination address + void datalink_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ void datalink_get_my_address(BACNET_ADDRESS * my_address); diff --git a/bacnet-stack/dcc.c b/bacnet-stack/dcc.c index 2a6bb84d..c5b18bdc 100644 --- a/bacnet-stack/dcc.c +++ b/bacnet-stack/dcc.c @@ -213,10 +213,10 @@ int dcc_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) return -1; diff --git a/bacnet-stack/dcc.h b/bacnet-stack/dcc.h index 0899fe4d..b248ead5 100644 --- a/bacnet-stack/dcc.h +++ b/bacnet-stack/dcc.h @@ -57,11 +57,11 @@ extern "C" { bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE status, uint16_t minutes); -// encode service +/* encode service */ int dcc_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint16_t timeDuration, /* 0=optional */ BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, BACNET_CHARACTER_STRING * password); /* NULL=optional */ -// decode the service request only +/* decode the service request only */ int dcc_decode_service_request(uint8_t * apdu, unsigned apdu_len, uint16_t * timeDuration, diff --git a/bacnet-stack/demo/handler/client.h b/bacnet-stack/demo/handler/client.h index c9e77f37..51c838a2 100644 --- a/bacnet-stack/demo/handler/client.h +++ b/bacnet-stack/demo/handler/client.h @@ -58,7 +58,7 @@ extern "C" { BACNET_PROPERTY_ID object_property, int32_t array_index); /* returns the invoke ID for confirmed request, or 0 if failed */ - uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device + uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */ BACNET_OBJECT_TYPE object_type, uint32_t object_instance, BACNET_PROPERTY_ID object_property, diff --git a/bacnet-stack/demo/handler/h_arf.c b/bacnet-stack/demo/handler/h_arf.c index c9fe3a1f..96f9c5ca 100644 --- a/bacnet-stack/demo/handler/h_arf.c +++ b/bacnet-stack/demo/handler/h_arf.c @@ -59,12 +59,12 @@ void handler_atomic_read_file(uint8_t * service_request, len = arf_decode_service_request(service_request, service_len, &data); if (len < 0) fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n"); - // prepare a reply + /* prepare a reply */ datalink_get_my_address(&my_address); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // bad decoding - send an abort + /* bad decoding - send an abort */ if (len < 0) { pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER); @@ -112,8 +112,8 @@ void handler_atomic_read_file(uint8_t * service_request, send = true; } if (send) { - bytes_sent = datalink_send_pdu(src, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(src, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); } diff --git a/bacnet-stack/demo/handler/h_arf_a.c b/bacnet-stack/demo/handler/h_arf_a.c index 933cc091..47a1d3d0 100644 --- a/bacnet-stack/demo/handler/h_arf_a.c +++ b/bacnet-stack/demo/handler/h_arf_a.c @@ -41,11 +41,11 @@ #include "handlers.h" #include "txbuf.h" -// We performed an AtomicReadFile Request, -// and here is the data from the server -// Note: it does not have to be the same file=instance -// that someone can read from us. It is common to -// use the description as the file name. +/* We performed an AtomicReadFile Request, */ +/* and here is the data from the server */ +/* Note: it does not have to be the same file=instance */ +/* that someone can read from us. It is common to */ +/* use the description as the file name. */ #if BACFILE void handler_atomic_read_file_ack(uint8_t * service_request, uint16_t service_len, @@ -58,13 +58,13 @@ void handler_atomic_read_file_ack(uint8_t * service_request, uint32_t instance = 0; (void) src; - // get the file instance from the tsm data before freeing it + /* get the file instance from the tsm data before freeing it */ instance = bacfile_instance_from_tsm(service_data->invoke_id); len = arf_ack_decode_service_request(service_request, service_len, &data); fprintf(stderr, "Received Read-File Ack!\n"); if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) { - // write the data received to the file specified + /* write the data received to the file specified */ if (data.access == FILE_STREAM_ACCESS) { pFilename = bacfile_name(instance); if (pFilename) { @@ -81,7 +81,7 @@ void handler_atomic_read_file_ack(uint8_t * service_request, } } } else if (data.access == FILE_RECORD_ACCESS) { - // FIXME: add handling for Record Access + /* FIXME: add handling for Record Access */ } } } diff --git a/bacnet-stack/demo/handler/h_dcc.c b/bacnet-stack/demo/handler/h_dcc.c index d93488a4..3257e9ab 100644 --- a/bacnet-stack/demo/handler/h_dcc.c +++ b/bacnet-stack/demo/handler/h_dcc.c @@ -52,7 +52,7 @@ void handler_device_communication_control(uint8_t * service_request, BACNET_ADDRESS my_address; int bytes_sent = 0; - // decode the service request only + /* decode the service request only */ len = dcc_decode_service_request(service_request, service_len, &timeDuration, &state, &password); fprintf(stderr, "DeviceCommunicationControl!\n"); @@ -64,12 +64,12 @@ void handler_device_communication_control(uint8_t * service_request, else fprintf(stderr, "DeviceCommunicationControl: " "Unable to decode request!\n"); - // prepare a reply + /* prepare a reply */ datalink_get_my_address(&my_address); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // bad decoding or something we didn't understand - send an abort + /* bad decoding or something we didn't understand - send an abort */ if (len == -1) { pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER); @@ -105,8 +105,8 @@ void handler_device_communication_control(uint8_t * service_request, "Sending Error - password failure.\n"); } } - bytes_sent = datalink_send_pdu(src, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(src, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/h_iam.c b/bacnet-stack/demo/handler/h_iam.c index 91ed48a5..6c141075 100644 --- a/bacnet-stack/demo/handler/h_iam.c +++ b/bacnet-stack/demo/handler/h_iam.c @@ -66,7 +66,7 @@ void handler_i_am_bind(uint8_t * service_request, (void) service_len; len = iam_decode_service_request(service_request, &device_id, &max_apdu, &segmentation, &vendor_id); - // only add address if requested to bind + /* only add address if requested to bind */ address_add_binding(device_id, max_apdu, src); return; diff --git a/bacnet-stack/demo/handler/h_rd.c b/bacnet-stack/demo/handler/h_rd.c index dba93741..de7501ac 100644 --- a/bacnet-stack/demo/handler/h_rd.c +++ b/bacnet-stack/demo/handler/h_rd.c @@ -51,7 +51,7 @@ void handler_reinitialize_device(uint8_t * service_request, BACNET_ADDRESS my_address; int bytes_sent = 0; - // decode the service request only + /* decode the service request only */ len = rd_decode_service_request(service_request, service_len, &state, &password); fprintf(stderr, "ReinitializeDevice!\n"); @@ -60,12 +60,12 @@ void handler_reinitialize_device(uint8_t * service_request, (unsigned) state, characterstring_value(&password)); else fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); - // prepare a reply + /* prepare a reply */ datalink_get_my_address(&my_address); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // bad decoding or something we didn't understand - send an abort + /* bad decoding or something we didn't understand - send an abort */ if (len == -1) { pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER); @@ -103,8 +103,8 @@ void handler_reinitialize_device(uint8_t * service_request, "ReinitializeDevice: Sending Error - password failure.\n"); } } - bytes_sent = datalink_send_pdu(src, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(src, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index 99bb92a1..b4d7dae9 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -62,12 +62,12 @@ void handler_read_property(uint8_t * service_request, len = rp_decode_service_request(service_request, service_len, &data); if (len <= 0) fprintf(stderr, "Unable to decode Read-Property Request!\n"); - // prepare a reply + /* prepare a reply */ datalink_get_my_address(&my_address); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // bad decoding - send an abort + /* bad decoding - send an abort */ if (len == -1) { pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER); @@ -82,16 +82,16 @@ void handler_read_property(uint8_t * service_request, } else { switch (data.object_type) { case OBJECT_DEVICE: - // FIXME: probably need a length limitation sent with encode + /* FIXME: probably need a length limitation sent with encode */ if (data.object_instance == Device_Object_Instance_Number()) { len = Device_Encode_Property_APDU(&Temp_Buf[0], data.object_property, data.array_index, &error_class, &error_code); if (len >= 0) { - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ data.application_data = &Temp_Buf[0]; data.application_data_len = len; - // FIXME: probably need a length limitation sent with encode + /* FIXME: probably need a length limitation sent with encode */ pdu_len += rp_ack_encode_apdu(&Handler_Transmit_Buffer [pdu_len], service_data->invoke_id, &data); @@ -109,10 +109,10 @@ void handler_read_property(uint8_t * service_request, data.object_property, data.array_index, &error_class, &error_code); if (len >= 0) { - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ data.application_data = &Temp_Buf[0]; data.application_data_len = len; - // FIXME: probably need a length limitation sent with encode + /* FIXME: probably need a length limitation sent with encode */ pdu_len += rp_ack_encode_apdu(&Handler_Transmit_Buffer [pdu_len], service_data->invoke_id, &data); @@ -130,10 +130,10 @@ void handler_read_property(uint8_t * service_request, data.object_property, data.array_index, &error_class, &error_code); if (len >= 0) { - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ data.application_data = &Temp_Buf[0]; data.application_data_len = len; - // FIXME: probably need a length limitation sent with encode + /* FIXME: probably need a length limitation sent with encode */ pdu_len += rp_ack_encode_apdu(&Handler_Transmit_Buffer [pdu_len], service_data->invoke_id, &data); @@ -152,10 +152,10 @@ void handler_read_property(uint8_t * service_request, data.object_property, data.array_index, &error_class, &error_code); if (len >= 0) { - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ data.application_data = &Temp_Buf[0]; data.application_data_len = len; - // FIXME: probably need a length limitation sent with encode + /* FIXME: probably need a length limitation sent with encode */ pdu_len += rp_ack_encode_apdu(&Handler_Transmit_Buffer [pdu_len], service_data->invoke_id, &data); @@ -180,8 +180,8 @@ void handler_read_property(uint8_t * service_request, send = true; } if (send) { - bytes_sent = datalink_send_pdu(src, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(src, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); } diff --git a/bacnet-stack/demo/handler/h_wp.c b/bacnet-stack/demo/handler/h_wp.c index 8cdaa91a..1cf60a10 100644 --- a/bacnet-stack/demo/handler/h_wp.c +++ b/bacnet-stack/demo/handler/h_wp.c @@ -55,7 +55,7 @@ void handler_write_property(uint8_t * service_request, BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; int bytes_sent = 0; - // decode the service request only + /* decode the service request only */ len = wp_decode_service_request(service_request, service_len, &wp_data); fprintf(stderr, "Received Write-Property Request!\n"); @@ -66,12 +66,12 @@ 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"); - // prepare a reply + /* prepare a reply */ datalink_get_my_address(&my_address); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // bad decoding or something we didn't understand - send an abort + /* bad decoding or something we didn't understand - send an abort */ if (len == -1) { pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER); @@ -134,8 +134,8 @@ void handler_write_property(uint8_t * service_request, break; } } - bytes_sent = datalink_send_pdu(src, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(src, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/noserv.c b/bacnet-stack/demo/handler/noserv.c index 84fb7d49..ada64e6a 100644 --- a/bacnet-stack/demo/handler/noserv.c +++ b/bacnet-stack/demo/handler/noserv.c @@ -46,16 +46,16 @@ void handler_unrecognized_service(uint8_t * service_request, (void) service_len; datalink_get_my_address(&src); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); - bytes_sent = datalink_send_pdu(dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent > 0) fprintf(stderr, "Sent Reject!\n"); else diff --git a/bacnet-stack/demo/handler/s_dcc.c b/bacnet-stack/demo/handler/s_dcc.c index ba4aac5e..6e4476be 100644 --- a/bacnet-stack/demo/handler/s_dcc.c +++ b/bacnet-stack/demo/handler/s_dcc.c @@ -63,11 +63,11 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t status = tsm_transaction_available(); if (status) { datalink_get_my_address(&my_address); - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); invoke_id = tsm_next_free_invokeID(); - // load the data for the encoding + /* load the data for the encoding */ characterstring_init_ansi(&password_string, password); pdu_len += dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, @@ -80,8 +80,8 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t if ((unsigned) pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send DeviceCommunicationControl Request (%s)!\n", diff --git a/bacnet-stack/demo/handler/s_ihave.c b/bacnet-stack/demo/handler/s_ihave.c index 880bff72..0e8bf622 100644 --- a/bacnet-stack/demo/handler/s_ihave.c +++ b/bacnet-stack/demo/handler/s_ihave.c @@ -68,8 +68,8 @@ void Send_I_Have(uint32_t device_id, characterstring_init_ansi(&data.object_name, object_name); pdu_len += ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); /* send the data */ - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/s_rd.c b/bacnet-stack/demo/handler/s_rd.c index 114567f1..506642ba 100644 --- a/bacnet-stack/demo/handler/s_rd.c +++ b/bacnet-stack/demo/handler/s_rd.c @@ -64,11 +64,11 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id, status = tsm_transaction_available(); if (status) { datalink_get_my_address(&my_address); - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); invoke_id = tsm_next_free_invokeID(); - // load the data for the encoding + /* load the data for the encoding */ characterstring_init_ansi(&password_string, password); pdu_len += rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, state, password ? &password_string : NULL); @@ -80,8 +80,8 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id, if ((unsigned) pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send ReinitializeDevice Request (%s)!\n", diff --git a/bacnet-stack/demo/handler/s_rp.c b/bacnet-stack/demo/handler/s_rp.c index 829e15bc..6d74f50b 100644 --- a/bacnet-stack/demo/handler/s_rp.c +++ b/bacnet-stack/demo/handler/s_rp.c @@ -67,11 +67,11 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */ status = tsm_transaction_available(); if (status) { datalink_get_my_address(&my_address); - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); invoke_id = tsm_next_free_invokeID(); - // load the data for the encoding + /* load the data for the encoding */ data.object_type = object_type; data.object_instance = object_instance; data.object_property = object_property; @@ -86,8 +86,8 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */ if ((unsigned) pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n", diff --git a/bacnet-stack/demo/handler/s_whohas.c b/bacnet-stack/demo/handler/s_whohas.c index 97321a29..52e76746 100644 --- a/bacnet-stack/demo/handler/s_whohas.c +++ b/bacnet-stack/demo/handler/s_whohas.c @@ -67,8 +67,8 @@ void Send_WhoHas_Name(int32_t low_limit, pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); /* send the data */ - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); @@ -101,8 +101,8 @@ void Send_WhoHas_Object(int32_t low_limit, pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); /* send the data */ - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/s_whois.c b/bacnet-stack/demo/handler/s_whois.c index 1ad07246..e7bda834 100644 --- a/bacnet-stack/demo/handler/s_whois.c +++ b/bacnet-stack/demo/handler/s_whois.c @@ -52,19 +52,19 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit) if (!dcc_communication_enabled()) return; - // Who-Is is a global broadcast + /* Who-Is is a global broadcast */ datalink_get_broadcast_address(&dest); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit, high_limit); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", strerror(errno)); diff --git a/bacnet-stack/demo/handler/s_wp.c b/bacnet-stack/demo/handler/s_wp.c index fc7a7a24..660fc71b 100644 --- a/bacnet-stack/demo/handler/s_wp.c +++ b/bacnet-stack/demo/handler/s_wp.c @@ -43,7 +43,7 @@ #include "txbuf.h" /* returns the invoke ID for confirmed request, or zero on failure */ -uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device +uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */ BACNET_OBJECT_TYPE object_type, uint32_t object_instance, BACNET_PROPERTY_ID object_property, @@ -69,11 +69,11 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device status = tsm_transaction_available(); if (status) { datalink_get_my_address(&my_address); - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); invoke_id = tsm_next_free_invokeID(); - // load the data for the encoding + /* load the data for the encoding */ data.object_type = object_type; data.object_instance = object_instance; data.object_property = object_property; @@ -90,8 +90,8 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device if ((unsigned) pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send WriteProperty Request (%s)!\n", diff --git a/bacnet-stack/demo/object/ai.c b/bacnet-stack/demo/object/ai.c index fafda408..f5f63de8 100644 --- a/bacnet-stack/demo/object/ai.c +++ b/bacnet-stack/demo/object/ai.c @@ -23,7 +23,7 @@ * *********************************************************************/ -// Analog Input Objects customize for your use +/* Analog Input Objects customize for your use */ #include #include @@ -31,13 +31,13 @@ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" -#include "config.h" // the custom stuff +#include "config.h" /* the custom stuff */ #define MAX_ANALOG_INPUTS 7 -// we simply have 0-n object instances. Yours might be -// more complex, and then you need validate that the -// given instance exists +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need validate that the */ +/* given instance exists */ bool Analog_Input_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ANALOG_INPUTS) @@ -46,16 +46,16 @@ bool Analog_Input_Valid_Instance(uint32_t object_instance) return false; } -// we simply have 0-n object instances. Yours might be -// more complex, and then count how many you have +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then count how many you have */ unsigned Analog_Input_Count(void) { return MAX_ANALOG_INPUTS; } -// we simply have 0-n object instances. Yours might be -// more complex, and then you need to return the instance -// that correlates to the correct index +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need to return the instance */ +/* that correlates to the correct index */ uint32_t Analog_Input_Index_To_Instance(unsigned index) { return index; @@ -81,7 +81,7 @@ int Analog_Input_Encode_Property_APDU(uint8_t * apdu, int32_t array_index, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { - int apdu_len = 0; // return value + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; float value = 3.14; @@ -149,7 +149,7 @@ void testAnalogInput(Test * pTest) BACNET_ERROR_CODE error_code; - // FIXME: we should do a lot more testing here... + /* FIXME: we should do a lot more testing here... */ len = Analog_Input_Encode_Property_APDU(&apdu[0], instance, PROP_OBJECT_IDENTIFIER, diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 1490b376..c22cf3b2 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -23,7 +23,7 @@ * *********************************************************************/ -// Analog Output Objects - customize for your use +/* Analog Output Objects - customize for your use */ #include #include @@ -31,28 +31,28 @@ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" -#include "config.h" // the custom stuff +#include "config.h" /* the custom stuff */ #include "wp.h" #define MAX_ANALOG_OUTPUTS 4 -// we choose to have a NULL level in our system represented by -// a particular value. When the priorities are not in use, they -// will be relinquished (i.e. set to the NULL level). +/* we choose to have a NULL level in our system represented by */ +/* a particular value. When the priorities are not in use, they */ +/* will be relinquished (i.e. set to the NULL level). */ #define AO_LEVEL_NULL 255 -// When all the priorities are level null, the present value returns -// the Relinquish Default value +/* When all the priorities are level null, the present value returns */ +/* the Relinquish Default value */ #define AO_RELINQUISH_DEFAULT 0 -// Here is our Priority Array. They are supposed to be Real, but -// we don't have that kind of memory, so we will use a single byte -// and load a Real for returning the value when asked. +/* Here is our Priority Array. They are supposed to be Real, but */ +/* we don't have that kind of memory, so we will use a single byte */ +/* and load a Real for returning the value when asked. */ static uint8_t Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY]; -// Writable out-of-service allows others to play with our Present Value -// without changing the physical output +/* Writable out-of-service allows others to play with our Present Value */ +/* without changing the physical output */ static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS]; -// we need to have our arrays initialized before answering any calls +/* we need to have our arrays initialized before answering any calls */ static bool Analog_Ouput_Initialized = false; void Analog_Output_Init(void) @@ -62,7 +62,7 @@ void Analog_Output_Init(void) if (!Analog_Ouput_Initialized) { Analog_Ouput_Initialized = true; - // initialize all the analog output priority arrays to NULL + /* initialize all the analog output priority arrays to NULL */ for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { for (j = 0; j < BACNET_MAX_PRIORITY; j++) { Analog_Output_Level[i][j] = AO_LEVEL_NULL; @@ -73,9 +73,9 @@ void Analog_Output_Init(void) return; } -// we simply have 0-n object instances. Yours might be -// more complex, and then you need validate that the -// given instance exists +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need validate that the */ +/* given instance exists */ bool Analog_Output_Valid_Instance(uint32_t object_instance) { Analog_Output_Init(); @@ -85,26 +85,26 @@ bool Analog_Output_Valid_Instance(uint32_t object_instance) return false; } -// we simply have 0-n object instances. Yours might be -// more complex, and then count how many you have +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then count how many you have */ unsigned Analog_Output_Count(void) { Analog_Output_Init(); return MAX_ANALOG_OUTPUTS; } -// we simply have 0-n object instances. Yours might be -// more complex, and then you need to return the instance -// that correlates to the correct index +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need to return the instance */ +/* that correlates to the correct index */ uint32_t Analog_Output_Index_To_Instance(unsigned index) { Analog_Output_Init(); return index; } -// we simply have 0-n object instances. Yours might be -// more complex, and then you need to return the index -// that correlates to the correct instance number +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need to return the index */ +/* that correlates to the correct instance number */ unsigned Analog_Output_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ANALOG_OUTPUTS; @@ -157,7 +157,7 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { int len = 0; - int apdu_len = 0; // return value + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; float real_value = 1.414; @@ -202,24 +202,24 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu, apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT); break; case PROP_PRIORITY_ARRAY: - // Array element zero is the number of elements in the array + /* Array element zero is the number of elements in the array */ if (array_index == BACNET_ARRAY_LENGTH_INDEX) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); - // if no index was specified, then try to encode the entire list - // into one packet. + /* if no index was specified, then try to encode the entire list */ + /* into one packet. */ else if (array_index == BACNET_ARRAY_ALL) { object_index = Analog_Output_Instance_To_Index(object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { - // FIXME: check if we have room before adding it to APDU + /* FIXME: check if we have room before adding it to APDU */ if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL) len = encode_tagged_null(&apdu[apdu_len]); else { real_value = Analog_Output_Level[object_index][i]; len = encode_tagged_real(&apdu[apdu_len], real_value); } - // add it if we have room + /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; else { @@ -263,11 +263,11 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu, return apdu_len; } -// returns true if successful +/* returns true if successful */ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { - bool status = false; // return value + bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; uint8_t level = AO_LEVEL_NULL; @@ -278,7 +278,7 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, *error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } - // decode the some of the request + /* decode the some of the request */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL) { @@ -293,9 +293,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, object_instance); priority--; Analog_Output_Level[object_index][priority] = level; - // if Out of Service is TRUE, then don't set the - // physical output. This comment may apply to the - // main loop (i.e. check out of service before changing output) + /* if Out of Service is TRUE, then don't set the */ + /* physical output. This comment may apply to the */ + /* main loop (i.e. check out of service before changing output) */ status = true; } else if (priority == 6) { *error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/demo/object/bacfile.c b/bacnet-stack/demo/object/bacfile.c index fa778ece..4fc42c19 100644 --- a/bacnet-stack/demo/object/bacfile.c +++ b/bacnet-stack/demo/object/bacfile.c @@ -48,7 +48,7 @@ static BACNET_FILE_LISTING BACnet_File_Listing[] = { {0, "test.log"}, {1, "script.txt"}, {2, "bacenum.h"}, - {0, NULL} // last file indication + {0, NULL} /* last file indication */ }; char *bacfile_name(uint32_t instance) @@ -56,7 +56,7 @@ char *bacfile_name(uint32_t instance) uint32_t index = 0; char *filename = NULL; - // linear search for file instance match + /* linear search for file instance match */ while (BACnet_File_Listing[index].filename) { if (BACnet_File_Listing[index].instance == instance) { filename = BACnet_File_Listing[index].filename; @@ -77,7 +77,7 @@ uint32_t bacfile_count(void) { uint32_t index = 0; - // linear search for file instance match + /* linear search for file instance match */ while (BACnet_File_Listing[index].filename) { index++; } @@ -90,7 +90,7 @@ uint32_t bacfile_index_to_instance(unsigned find_index) uint32_t instance = BACNET_MAX_INSTANCE + 1; uint32_t index = 0; - // bounds checking... + /* bounds checking... */ while (BACnet_File_Listing[index].filename) { if (index == find_index) { instance = BACnet_File_Listing[index].instance; @@ -141,7 +141,7 @@ int bacfile_encode_property_apdu(uint8_t * apdu, int32_t array_index, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { - int apdu_len = 0; // return value + int apdu_len = 0; /* return value */ char text_string[32] = { "" }; BACNET_CHARACTER_STRING char_string; @@ -173,18 +173,18 @@ int bacfile_encode_property_apdu(uint8_t * apdu, bacfile_file_size(object_instance)); break; case PROP_MODIFICATION_DATE: - // FIXME: get the actual value + /* FIXME: get the actual value */ apdu_len = encode_tagged_date(&apdu[0], 2005, 12, 25, 7 /* sunday */ ); - // FIXME: get the actual value + /* FIXME: get the actual value */ apdu_len += encode_tagged_time(&apdu[apdu_len], 12, 0, 0, 0); break; case PROP_ARCHIVE: - // FIXME: get the actual value: note it may be inverse... + /* FIXME: get the actual value: note it may be inverse... */ apdu_len = encode_tagged_boolean(&apdu[0], true); break; case PROP_READ_ONLY: - // FIXME: get the actual value + /* FIXME: get the actual value */ apdu_len = encode_tagged_boolean(&apdu[0], true); break; case PROP_FILE_ACCESS_METHOD: @@ -205,7 +205,7 @@ uint32_t bacfile_instance(char *filename) uint32_t index = 0; uint32_t instance = BACNET_MAX_INSTANCE + 1; - // linear search for filename match + /* linear search for filename match */ while (BACnet_File_Listing[index].filename) { if (strcmp(BACnet_File_Listing[index].filename, filename) == 0) { instance = BACnet_File_Listing[index].instance; @@ -218,37 +218,37 @@ uint32_t bacfile_instance(char *filename) } #if TSM_ENABLED -// this is one way to match up the invoke ID with -// the file ID from the AtomicReadFile request. -// Another way would be to store the -// invokeID and file instance in a list or table -// when the request was sent +/* this is one way to match up the invoke ID with */ +/* the file ID from the AtomicReadFile request. */ +/* Another way would be to store the */ +/* invokeID and file instance in a list or table */ +/* when the request was sent */ uint32_t bacfile_instance_from_tsm(uint8_t invokeID) { - BACNET_NPDU_DATA npdu_data = { 0 }; // dummy for getting npdu length + BACNET_NPDU_DATA npdu_data = { 0 }; /* dummy for getting npdu length */ BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; uint8_t service_choice = 0; uint8_t *service_request = NULL; uint16_t service_request_len = 0; - BACNET_ADDRESS dest; // where the original packet was destined - uint8_t pdu[MAX_PDU] = { 0 }; // original sent packet - uint16_t pdu_len = 0; // original packet length - uint16_t len = 0; // apdu header length + BACNET_ADDRESS dest; /* where the original packet was destined */ + uint8_t pdu[MAX_PDU] = { 0 }; /* original sent packet */ + uint16_t pdu_len = 0; /* original 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 + uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ bool found = false; int apdu_offset = 0; found = tsm_get_transaction_pdu(invokeID, &dest, &pdu[0], &pdu_len); if (found) { - apdu_offset = npdu_decode(&pdu[0], // data to decode - NULL, // destination address - get the DNET/DLEN/DADR if in there - NULL, // source address - get the SNET/SLEN/SADR if in there - &npdu_data); // amount of data to decode + apdu_offset = npdu_decode(&pdu[0], /* data to decode */ + NULL, /* destination address - get the DNET/DLEN/DADR if in there */ + NULL, /* source address - get the SNET/SLEN/SADR if in there */ + &npdu_data); /* amount of data to decode */ if (!npdu_data.network_layer_message && ((pdu[apdu_offset] & 0xF0) == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { - len = apdu_decode_confirmed_service_request(&pdu[apdu_offset], // APDU data + len = apdu_decode_confirmed_service_request(&pdu[apdu_offset], /* APDU data */ pdu_len - apdu_offset, &service_data, &service_choice, &service_request, &service_request_len); diff --git a/bacnet-stack/demo/object/bacfile.h b/bacnet-stack/demo/object/bacfile.h index b08ecb53..59ce52b9 100644 --- a/bacnet-stack/demo/object/bacfile.h +++ b/bacnet-stack/demo/object/bacfile.h @@ -51,18 +51,18 @@ extern "C" { uint32_t bacfile_index_to_instance(unsigned find_index); uint32_t bacfile_instance(char *filename); #if TSM_ENABLED -// this is one way to match up the invoke ID with -// the file ID from the AtomicReadFile request. -// Another way would be to store the -// invokeID and file instance in a list or table -// when the request was sent +/* this is one way to match up the invoke ID with */ +/* the file ID from the AtomicReadFile request. */ +/* Another way would be to store the */ +/* invokeID and file instance in a list or table */ +/* when the request was sent */ uint32_t bacfile_instance_from_tsm(uint8_t invokeID); #endif -// AtomicReadFile ACK helper +/* AtomicReadFile ACK helper */ bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data); -// handling for read property service +/* handling for read property service */ int bacfile_encode_property_apdu(uint8_t * apdu, uint32_t object_instance, BACNET_PROPERTY_ID property, diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 2864f679..db94d8c8 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -107,7 +107,7 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id) bool Device_Valid_Object_Instance_Number(uint32_t object_id) { - // BACnet allows for a wildcard instance number + /* BACnet allows for a wildcard instance number */ return ((Object_Instance_Number == object_id) || (object_id == BACNET_MAX_INSTANCE)); } @@ -137,7 +137,7 @@ BACNET_DEVICE_STATUS Device_System_Status(void) void Device_Set_System_Status(BACNET_DEVICE_STATUS status) { - // FIXME: bounds check? + /* FIXME: bounds check? */ System_Status = status; } @@ -285,7 +285,7 @@ uint16_t Device_APDU_Timeout(void) return APDU_Timeout; } -// in milliseconds +/* in milliseconds */ void Device_Set_APDU_Timeout(uint16_t timeout) { APDU_Timeout = timeout; @@ -311,8 +311,8 @@ void Device_Set_Database_Revision(uint8_t revision) Database_Revision = revision; } -// Since many network clients depend on the object list -// for discovery, it must be consistent! +/* Since many network clients depend on the object list */ +/* for discovery, it must be consistent! */ unsigned Device_Object_List_Count(void) { unsigned count = 1; @@ -339,7 +339,7 @@ bool Device_Object_List_Identifier(unsigned array_index, } if (!status) { - // array index starts at 1, and 1 for the device object + /* array index starts at 1, and 1 for the device object */ object_index = array_index - 2; if (object_index < Analog_Input_Count()) { *object_type = OBJECT_ANALOG_INPUT; @@ -426,14 +426,14 @@ char *Device_Valid_Object_Id(int object_type, uint32_t object_instance) return name; } -// return the length of the apdu encoded or -1 for error +/* return the length of the apdu encoded or -1 for error */ int Device_Encode_Property_APDU(uint8_t * apdu, BACNET_PROPERTY_ID property, int32_t array_index, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { - int apdu_len = 0; // return value - int len = 0; // apdu len intermediate value + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned i = 0; @@ -480,31 +480,31 @@ int Device_Encode_Property_APDU(uint8_t * apdu, Application_Software_Version); apdu_len = encode_tagged_character_string(&apdu[0], &char_string); break; - // if you support time - //case PROP_LOCAL_TIME: - //t = time(NULL); - //my_tm = localtime(&t); - //apdu_len = - // encode_tagged_time(&apdu[0], my_tm->tm_hour, my_tm->tm_min, - // my_tm->tm_sec, 0); - //break; - // if you support date - //case PROP_LOCAL_DATE: - //t = time(NULL); - //my_tm = localtime(&t); - // month 1=Jan - // day = day of month - // wday 1=Monday...7=Sunday - //apdu_len = encode_tagged_date(&apdu[0], - // my_tm->tm_year+1900, - // my_tm->tm_mon + 1, - // my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday)); - //break; + /* if you support time */ + /*case PROP_LOCAL_TIME: */ + /*t = time(NULL); */ + /*my_tm = localtime(&t); */ + /*apdu_len = */ + /* encode_tagged_time(&apdu[0], my_tm->tm_hour, my_tm->tm_min, */ + /* my_tm->tm_sec, 0); */ + /*break; */ + /* if you support date */ + /*case PROP_LOCAL_DATE: */ + /*t = time(NULL); */ + /*my_tm = localtime(&t); */ + /* month 1=Jan */ + /* day = day of month */ + /* wday 1=Monday...7=Sunday */ + /*apdu_len = encode_tagged_date(&apdu[0], */ + /* my_tm->tm_year+1900, */ + /* my_tm->tm_mon + 1, */ + /* my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday)); */ + /*break; */ case PROP_PROTOCOL_VERSION: apdu_len = encode_tagged_unsigned(&apdu[0], Device_Protocol_Version()); break; - // BACnet Legacy Support + /* BACnet Legacy Support */ case PROP_PROTOCOL_CONFORMANCE_CLASS: apdu_len = encode_tagged_unsigned(&apdu[0], 1); break; @@ -523,7 +523,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, not a list of objects that this device can access */ bitstring_init(&bit_string); for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { - // initialize all the object types to not-supported + /* initialize all the object types to not-supported */ bitstring_set_bit(&bit_string, (uint8_t) i, false); } /* FIXME: indicate the objects that YOU support */ @@ -537,13 +537,13 @@ int Device_Encode_Property_APDU(uint8_t * apdu, break; case PROP_OBJECT_LIST: count = Device_Object_List_Count(); - // Array element zero is the number of objects in the list + /* Array element zero is the number of objects in the list */ if (array_index == BACNET_ARRAY_LENGTH_INDEX) apdu_len = encode_tagged_unsigned(&apdu[0], count); - // if no index was specified, then try to encode the entire list - // into one packet. Note that more than likely you will have - // to return an error if the number of encoded objects exceeds - // your maximum APDU size. + /* if no index was specified, then try to encode the entire list */ + /* into one packet. Note that more than likely you will have */ + /* to return an error if the number of encoded objects exceeds */ + /* your maximum APDU size. */ else if (array_index == BACNET_ARRAY_ALL) { for (i = 1; i <= count; i++) { if (Device_Object_List_Identifier(i, &object_type, @@ -552,8 +552,8 @@ int Device_Encode_Property_APDU(uint8_t * apdu, encode_tagged_object_id(&apdu[apdu_len], object_type, instance); apdu_len += len; - // assume next one is the same size as this one - // can we all fit into the APDU? + /* assume next one is the same size as this one */ + /* can we all fit into the APDU? */ if ((apdu_len + len) >= MAX_APDU) { *error_class = ERROR_CLASS_SERVICES; *error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; @@ -561,7 +561,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, break; } } else { - // error: internal error? + /* error: internal error? */ *error_class = ERROR_CLASS_SERVICES; *error_code = ERROR_CODE_OTHER; apdu_len = -1; @@ -609,21 +609,21 @@ int Device_Encode_Property_APDU(uint8_t * apdu, return apdu_len; } -// we can send an I-Am when our device ID changes +/* we can send an I-Am when our device ID changes */ extern bool I_Am_Request; -// returns true if successful +/* returns true if successful */ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { - bool status = false; // return value + bool status = false; /* return value */ if (!Device_Valid_Object_Instance_Number(wp_data->object_instance)) { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } - // decode the some of the request + /* decode the some of the request */ switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (wp_data->value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { @@ -765,7 +765,7 @@ void testDevice(Test * pTest) } #ifdef TEST_DEVICE -// stubs to dependencies to keep unit test simple +/* stubs to dependencies to keep unit test simple */ unsigned Analog_Input_Count(void) { return 0; diff --git a/bacnet-stack/demo/object/device.h b/bacnet-stack/demo/object/device.h index 563b0c92..c59bac37 100644 --- a/bacnet-stack/demo/object/device.h +++ b/bacnet-stack/demo/object/device.h @@ -76,7 +76,7 @@ extern "C" { const char *Device_Location(void); bool Device_Set_Location(const char *name, size_t length); -// some stack-centric constant values - no set methods +/* some stack-centric constant values - no set methods */ uint8_t Device_Protocol_Version(void); uint8_t Device_Protocol_Revision(void); uint16_t Device_Max_APDU_Length_Accepted(void); diff --git a/bacnet-stack/demo/readfile/readfile.c b/bacnet-stack/demo/readfile/readfile.c index 29998625..ceb83ec1 100644 --- a/bacnet-stack/demo/readfile/readfile.c +++ b/bacnet-stack/demo/readfile/readfile.c @@ -48,7 +48,7 @@ #include "handlers.h" #include "txbuf.h" -// buffer used for receive +/* buffer used for receive */ static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; /* global variables used in this file */ @@ -117,11 +117,11 @@ static uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id, status = tsm_transaction_available(); if (status) { datalink_get_my_address(&my_address); - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); invoke_id = tsm_next_free_invokeID(); - // load the data for the encoding + /* load the data for the encoding */ data.object_type = OBJECT_FILE; data.object_instance = file_instance; data.access = FILE_STREAM_ACCESS; @@ -137,8 +137,8 @@ static uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id, if ((unsigned) pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, &Handler_Transmit_Buffer[0], pdu_len); - bytes_sent = datalink_send_pdu(&dest, // destination address - &Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */ if (bytes_sent <= 0) fprintf(stderr, "Failed to Send AtomicReadFile Request (%s)!\n", @@ -161,7 +161,7 @@ static void Send_WhoIs(uint32_t device_id) datalink_get_broadcast_address(&dest); /* encode the NPDU portion of the packet */ - pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages + pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); /* encode the APDU portion of the packet */ @@ -268,9 +268,9 @@ static void Init_Service_Handlers(void) int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { 0 }; // address where message came from + BACNET_ADDRESS src = { 0 }; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; // milliseconds + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; diff --git a/bacnet-stack/dlmstp.c b/bacnet-stack/dlmstp.c index ea0eafcb..55429d57 100644 --- a/bacnet-stack/dlmstp.c +++ b/bacnet-stack/dlmstp.c @@ -50,10 +50,10 @@ void dlmstp_cleanup(void) } /* returns number of bytes sent on success, negative 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 -{ +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 */ (void) dest; (void) pdu; @@ -62,12 +62,12 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, // destination address return 0; } -// returns the number of octets in the PDU, or zero on failure -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) // milliseconds to wait for a packet -{ +/* returns the number of octets in the PDU, or zero on failure */ +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) +{ /* milliseconds to wait for a packet */ (void) src; (void) pdu; (void) max_pdu; @@ -86,7 +86,7 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address) return; } -void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) // destination address -{ +void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) +{ /* destination address */ return; } diff --git a/bacnet-stack/dlmstp.h b/bacnet-stack/dlmstp.h index d21dc7c2..850c5d28 100644 --- a/bacnet-stack/dlmstp.h +++ b/bacnet-stack/dlmstp.h @@ -40,7 +40,7 @@ #include #include "bacdef.h" -// defines specific to MS/TP +/* defines specific to MS/TP */ #define MAX_HEADER (2+1+1+1+2+1+2+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) @@ -52,19 +52,19 @@ extern "C" { void dlmstp_cleanup(void); /* returns number of bytes sent on success, negative 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 + 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 */ -// returns the number of octets in the PDU, or zero on failure - 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); // milliseconds to wait for a packet +/* returns the number of octets in the PDU, or zero on failure */ + 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); /* milliseconds to wait for a packet */ void dlmstp_set_my_address(BACNET_ADDRESS * my_address); void dlmstp_get_my_address(BACNET_ADDRESS * my_address); - void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest); // destination address + void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ #ifdef __cplusplus } diff --git a/bacnet-stack/ethernet.h b/bacnet-stack/ethernet.h index 2f4ee673..e4401015 100644 --- a/bacnet-stack/ethernet.h +++ b/bacnet-stack/ethernet.h @@ -39,7 +39,7 @@ #include #include "bacdef.h" -// specific defines for Ethernet +/* specific defines for Ethernet */ #define MAX_HEADER (6+6+2+1+1+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) @@ -53,27 +53,27 @@ extern "C" { /* function to send a packet out the 802.2 socket */ /* returns number of bytes sent on success, negative on failure */ - int ethernet_send(BACNET_ADDRESS * dest, // destination address - BACNET_ADDRESS * src, // source address - uint8_t * pdu, // any data to be sent - may be null - unsigned pdu_len); // number of bytes of data + int ethernet_send(BACNET_ADDRESS * dest, /* destination address */ + BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* any data to be sent - may be null */ + unsigned pdu_len); /* number of bytes of data */ /* function to send a packet out the 802.2 socket */ /* returns number of bytes sent on success, negative on failure */ - int ethernet_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 + int ethernet_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 */ -// receives an 802.2 framed packet -// returns the number of octets in the PDU, or zero on failure - uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t max_pdu, // amount of space available in the PDU - unsigned timeout); // milliseconds to wait for a packet +/* receives an 802.2 framed packet */ +/* returns the number of octets in the PDU, or zero on failure */ + uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout); /* milliseconds to wait for a packet */ void ethernet_set_my_address(BACNET_ADDRESS * my_address); void ethernet_get_my_address(BACNET_ADDRESS * my_address); - void ethernet_get_broadcast_address(BACNET_ADDRESS * dest); // destination address + void ethernet_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ #ifdef __cplusplus } diff --git a/bacnet-stack/iam.c b/bacnet-stack/iam.c index 81a305ab..bb0e27ae 100755 --- a/bacnet-stack/iam.c +++ b/bacnet-stack/iam.c @@ -40,17 +40,17 @@ #include "bacdcode.h" #include "address.h" -// encode I-Am service +/* encode I-Am service */ int iam_encode_apdu(uint8_t * apdu, uint32_t device_id, unsigned max_apdu, int segmentation, uint16_t vendor_id) { - int len = 0; // length of each encoding - int apdu_len = 0; // total length of the apdu, return value + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_I_AM; // service choice + apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */ apdu_len = 2; len = encode_tagged_object_id(&apdu[apdu_len], OBJECT_DEVICE, device_id); @@ -71,15 +71,15 @@ int iam_decode_service_request(uint8_t * apdu, unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id) { int len = 0; - int apdu_len = 0; // total length of the apdu, return value - int object_type = 0; // should be a Device Object + int apdu_len = 0; /* total length of the apdu, return value */ + int object_type = 0; /* should be a Device Object */ uint32_t object_instance = 0; uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t decoded_value = 0; int decoded_integer = 0; - // OBJECT ID - object id + /* OBJECT ID - object id */ len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); @@ -93,7 +93,7 @@ int iam_decode_service_request(uint8_t * apdu, return -1; if (pDevice_id) *pDevice_id = object_instance; - // MAX APDU - unsigned + /* MAX APDU - unsigned */ len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); @@ -104,7 +104,7 @@ int iam_decode_service_request(uint8_t * apdu, apdu_len += len; if (pMax_apdu) *pMax_apdu = decoded_value; - // Segmentation - enumerated + /* Segmentation - enumerated */ len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); @@ -117,7 +117,7 @@ int iam_decode_service_request(uint8_t * apdu, return -1; if (pSegmentation) *pSegmentation = decoded_integer; - // Vendor ID - unsigned16 + /* Vendor ID - unsigned16 */ len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); @@ -138,12 +138,12 @@ int iam_decode_apdu(uint8_t * apdu, uint32_t * pDevice_id, unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ - // valid data? + /* valid data? */ if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) return -1; if (apdu[1] != SERVICE_UNCONFIRMED_I_AM) @@ -160,20 +160,20 @@ int iam_send(uint8_t * buffer) BACNET_ADDRESS dest; int bytes_sent = 0; - // I-Am is a global broadcast + /* I-Am is a global broadcast */ datalink_get_broadcast_address(&dest); - // encode the NPDU portion of the packet - pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL, false, // true for confirmed messages + /* encode the NPDU portion of the packet */ + pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL, false, /* true for confirmed messages */ MESSAGE_PRIORITY_NORMAL); - // encode the APDU portion of the packet + /* encode the APDU portion of the packet */ pdu_len += iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); - bytes_sent = datalink_send_pdu(&dest, // destination address - &buffer[0], pdu_len); // number of bytes of data + bytes_sent = datalink_send_pdu(&dest, /* destination address */ + &buffer[0], pdu_len); /* number of bytes of data */ return bytes_sent; } @@ -212,16 +212,16 @@ void testIAm(Test * pTest) } #ifdef TEST_IAM -// Dummy stubs to eliminate depencies -void datalink_get_broadcast_address(BACNET_ADDRESS * dest) // destination address -{ +/* Dummy stubs to eliminate depencies */ +void datalink_get_broadcast_address(BACNET_ADDRESS * dest) +{ /* destination address */ (void) dest; } -int datalink_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 -{ +int datalink_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 */ (void) dest; (void) pdu; @@ -246,10 +246,10 @@ void address_add_binding(uint32_t device_id, (void) src; } -// dummy for apdu dependency +/* dummy for apdu dependency */ void tsm_free_invoke_id(uint8_t invokeID) { - // dummy stub for testing + /* dummy stub for testing */ (void) invokeID; } diff --git a/bacnet-stack/main.c b/bacnet-stack/main.c index 63ed7f23..8bf40eb6 100644 --- a/bacnet-stack/main.c +++ b/bacnet-stack/main.c @@ -43,19 +43,19 @@ int main(void) { - struct mstp_port_struct_t mstp_port; // port data - uint8_t my_mac = 0x05; // local MAC address + struct mstp_port_struct_t mstp_port; /* port data */ + uint8_t my_mac = 0x05; /* local MAC address */ MSTP_Init(&mstp_port, my_mac); - // loop forever + /* loop forever */ for (;;) { - // input + /* input */ RS485_Check_UART_Data(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port); - // process + /* process */ - // output + /* output */ MSTP_Master_Node_FSM(&mstp_port); } diff --git a/bacnet-stack/mstp.c b/bacnet-stack/mstp.c index 35ced47a..599319ff 100644 --- a/bacnet-stack/mstp.c +++ b/bacnet-stack/mstp.c @@ -33,16 +33,16 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -// This clause describes a Master-Slave/Token-Passing (MS/TP) data link -// protocol, which provides the same services to the network layer as -// ISO 8802-2 Logical Link Control. It uses services provided by the -// EIA-485 physical layer. Relevant clauses of EIA-485 are deemed to be -// included in this standard by reference. The following hardware is assumed: -// (a) A UART (Universal Asynchronous Receiver/Transmitter) capable of -// transmitting and receiving eight data bits with one stop bit -// and no parity. -// (b) An EIA-485 transceiver whose driver may be disabled. -// (c) A timer with a resolution of five milliseconds or less +/* This clause describes a Master-Slave/Token-Passing (MS/TP) data link */ +/* protocol, which provides the same services to the network layer as */ +/* ISO 8802-2 Logical Link Control. It uses services provided by the */ +/* EIA-485 physical layer. Relevant clauses of EIA-485 are deemed to be */ +/* included in this standard by reference. The following hardware is assumed: */ +/* (a) A UART (Universal Asynchronous Receiver/Transmitter) capable of */ +/* transmitting and receiving eight data bits with one stop bit */ +/* and no parity. */ +/* (b) An EIA-485 transceiver whose driver may be disabled. */ +/* (c) A timer with a resolution of five milliseconds or less */ #include #include @@ -52,95 +52,95 @@ #include "rs485.h" #include "ringbuf.h" -// MS/TP Frame Format -// All frames are of the following format: -// -// Preamble: two octet preamble: X`55', X`FF' -// Frame Type: one octet -// Destination Address: one octet address -// Source Address: one octet address -// Length: two octets, most significant octet first, of the Data field -// Header CRC: one octet -// Data: (present only if Length is non-zero) -// Data CRC: (present only if Length is non-zero) two octets, -// least significant octet first -// (pad): (optional) at most one octet of padding: X'FF' +/* MS/TP Frame Format */ +/* All frames are of the following format: */ +/* */ +/* Preamble: two octet preamble: X`55', X`FF' */ +/* Frame Type: one octet */ +/* Destination Address: one octet address */ +/* Source Address: one octet address */ +/* Length: two octets, most significant octet first, of the Data field */ +/* Header CRC: one octet */ +/* Data: (present only if Length is non-zero) */ +/* Data CRC: (present only if Length is non-zero) two octets, */ +/* least significant octet first */ +/* (pad): (optional) at most one octet of padding: X'FF' */ - // The number of tokens received or used before a Poll For Master cycle -// is executed: 50. + /* The number of tokens received or used before a Poll For Master cycle */ +/* is executed: 50. */ const unsigned Npoll = 50; -// The number of retries on sending Token: 1. +/* The number of retries on sending Token: 1. */ const unsigned Nretry_token = 1; -// The minimum number of DataAvailable or ReceiveError events that must be -// seen by a receiving node in order to declare the line "active": 4. +/* The minimum number of DataAvailable or ReceiveError events that must be */ +/* seen by a receiving node in order to declare the line "active": 4. */ const unsigned Nmin_octets = 4; -// The minimum time without a DataAvailable or ReceiveError event within -// a frame before a receiving node may discard the frame: 60 bit times. -// (Implementations may use larger values for this timeout, -// not to exceed 100 milliseconds.) -// At 9600 baud, 60 bit times would be about 6.25 milliseconds +/* The minimum time without a DataAvailable or ReceiveError event within */ +/* a frame before a receiving node may discard the frame: 60 bit times. */ +/* (Implementations may use larger values for this timeout, */ +/* not to exceed 100 milliseconds.) */ +/* At 9600 baud, 60 bit times would be about 6.25 milliseconds */ const unsigned Tframe_abort = 1 + ((1000 * 60) / 9600); -// The maximum idle time a sending node may allow to elapse between octets -// of a frame the node is transmitting: 20 bit times. +/* The maximum idle time a sending node may allow to elapse between octets */ +/* of a frame the node is transmitting: 20 bit times. */ const unsigned Tframe_gap = 20; -// The time without a DataAvailable or ReceiveError event before declaration -// of loss of token: 500 milliseconds. +/* The time without a DataAvailable or ReceiveError event before declaration */ +/* of loss of token: 500 milliseconds. */ const unsigned Tno_token = 500; -// The maximum time after the end of the stop bit of the final -// octet of a transmitted frame before a node must disable its -// EIA-485 driver: 15 bit times. +/* The maximum time after the end of the stop bit of the final */ +/* octet of a transmitted frame before a node must disable its */ +/* EIA-485 driver: 15 bit times. */ const unsigned Tpostdrive = 15; -// The maximum time a node may wait after reception of a frame that expects -// a reply before sending the first octet of a reply or Reply Postponed -// frame: 250 milliseconds. +/* The maximum time a node may wait after reception of a frame that expects */ +/* a reply before sending the first octet of a reply or Reply Postponed */ +/* frame: 250 milliseconds. */ const unsigned Treply_delay = 225; -// The minimum time without a DataAvailable or ReceiveError event -// that a node must wait for a station to begin replying to a -// confirmed request: 255 milliseconds. (Implementations may use -// larger values for this timeout, not to exceed 300 milliseconds.) +/* The minimum time without a DataAvailable or ReceiveError event */ +/* that a node must wait for a station to begin replying to a */ +/* confirmed request: 255 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 300 milliseconds.) */ const unsigned Treply_timeout = 255; -// Repeater turnoff delay. The duration of a continuous logical one state -// at the active input port of an MS/TP repeater after which the repeater -// will enter the IDLE state: 29 bit times < Troff < 40 bit times. +/* Repeater turnoff delay. The duration of a continuous logical one state */ +/* at the active input port of an MS/TP repeater after which the repeater */ +/* will enter the IDLE state: 29 bit times < Troff < 40 bit times. */ const unsigned Troff = 30; -// The width of the time slot within which a node may generate a token: -// 10 milliseconds. +/* The width of the time slot within which a node may generate a token: */ +/* 10 milliseconds. */ const unsigned Tslot = 10; -// The maximum time a node may wait after reception of the token or -// a Poll For Master frame before sending the first octet of a frame: -// 15 milliseconds. +/* The maximum time a node may wait after reception of the token or */ +/* a Poll For Master frame before sending the first octet of a frame: */ +/* 15 milliseconds. */ const unsigned Tusage_delay = 15; -// The minimum time without a DataAvailable or ReceiveError event that a -// node must wait for a remote node to begin using a token or replying to -// a Poll For Master frame: 20 milliseconds. (Implementations may use -// larger values for this timeout, not to exceed 100 milliseconds.) +/* The minimum time without a DataAvailable or ReceiveError event that a */ +/* node must wait for a remote node to begin using a token or replying to */ +/* a Poll For Master frame: 20 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 100 milliseconds.) */ const unsigned Tusage_timeout = 20; -unsigned MSTP_Create_Frame(uint8_t * buffer, // where frame is loaded - unsigned buffer_len, // amount of space available - uint8_t frame_type, // type of frame to send - see defines - uint8_t destination, // destination address - uint8_t source, // source address - uint8_t * data, // any data to be sent - may be null - unsigned data_len) // number of bytes of data (up to 501) -{ - uint8_t crc8 = 0xFF; // used to calculate the crc value - uint16_t crc16 = 0xFFFF; // used to calculate the crc value - unsigned index = 0; // used to load the data portion of the frame +unsigned MSTP_Create_Frame(uint8_t * buffer, /* where frame is loaded */ + unsigned buffer_len, /* amount of space available */ + uint8_t frame_type, /* type of frame to send - see defines */ + uint8_t destination, /* destination address */ + uint8_t source, /* source address */ + uint8_t * data, /* any data to be sent - may be null */ + unsigned data_len) +{ /* number of bytes of data (up to 501) */ + uint8_t crc8 = 0xFF; /* used to calculate the crc value */ + uint16_t crc16 = 0xFFFF; /* used to calculate the crc value */ + unsigned index = 0; /* used to load the data portion of the frame */ - // not enough to do a header + /* not enough to do a header */ if (buffer_len < 8) return 0; @@ -166,7 +166,7 @@ unsigned MSTP_Create_Frame(uint8_t * buffer, // where frame is loaded index++; data_len--; } - // append the data CRC if necessary + /* append the data CRC if necessary */ if (index > 8) { if ((index + 2) <= buffer_len) { crc16 = ~crc16; @@ -178,31 +178,31 @@ unsigned MSTP_Create_Frame(uint8_t * buffer, // where frame is loaded return 0; } - return index; // returns the frame length + return index; /* returns the frame length */ } -void MSTP_Create_And_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port to send from - uint8_t frame_type, // type of frame to send - see defines - uint8_t destination, // destination address - uint8_t source, // source address - uint8_t * data, // any data to be sent - may be null - unsigned data_len) // number of bytes of data (up to 501) -{ +void MSTP_Create_And_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port to send from */ + uint8_t frame_type, /* type of frame to send - see defines */ + uint8_t destination, /* destination address */ + uint8_t source, /* source address */ + uint8_t * data, /* any data to be sent - may be null */ + unsigned data_len) +{ /* number of bytes of data (up to 501) */ uint8_t buffer[MAX_MPDU] = { 0 }; - uint16_t len = 0; // number of bytes to send + uint16_t len = 0; /* number of bytes to send */ - len = (uint16_t) MSTP_Create_Frame(buffer, // where frame is loaded - sizeof(buffer), // amount of space available - frame_type, // type of frame to send - see defines - destination, // destination address - source, // source address - data, // any data to be sent - may be null - data_len); // number of bytes of data (up to 501) + len = (uint16_t) MSTP_Create_Frame(buffer, /* where frame is loaded */ + sizeof(buffer), /* amount of space available */ + frame_type, /* type of frame to send - see defines */ + destination, /* destination address */ + source, /* source address */ + data, /* any data to be sent - may be null */ + data_len); /* number of bytes of data (up to 501) */ RS485_Send_Frame(mstp_port, buffer, len); } -// Millisecond Timer - called every millisecond +/* Millisecond Timer - called every millisecond */ void MSTP_Millisecond_Timer(volatile struct mstp_port_struct_t *mstp_port) { if (mstp_port->SilenceTimer < 255) @@ -216,102 +216,102 @@ void MSTP_Millisecond_Timer(volatile struct mstp_port_struct_t *mstp_port) void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) { switch (mstp_port->receive_state) { - // In the IDLE state, the node waits for the beginning of a frame. + /* In the IDLE state, the node waits for the beginning of a frame. */ case MSTP_RECEIVE_STATE_IDLE: - // EatAnError + /* EatAnError */ if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else { if (mstp_port->DataAvailable == true) { - // Preamble1 + /* Preamble1 */ if (mstp_port->DataRegister == 0x55) { mstp_port->DataAvailable = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // receive the remainder of the frame. + /* receive the remainder of the frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE; } - // EatAnOctet + /* EatAnOctet */ else { mstp_port->DataAvailable = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } } } break; - // In the PREAMBLE state, the node waits for the second octet of the preamble. + /* In the PREAMBLE state, the node waits for the second octet of the preamble. */ case MSTP_RECEIVE_STATE_PREAMBLE: - // Timeout + /* Timeout */ if (mstp_port->SilenceTimer > Tframe_abort) { - // a correct preamble has not been received - // wait for the start of a frame. + /* a correct preamble has not been received */ + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // Error + /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else { if (mstp_port->DataAvailable == true) { - // Preamble2 + /* Preamble2 */ if (mstp_port->DataRegister == 0xFF) { mstp_port->DataAvailable = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; mstp_port->Index = 0; mstp_port->HeaderCRC = 0xFF; - // receive the remainder of the frame. + /* receive the remainder of the frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // ignore RepeatedPreamble1 + /* ignore RepeatedPreamble1 */ else if (mstp_port->DataRegister == 0x55) { mstp_port->DataAvailable = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // wait for the second preamble octet. + /* wait for the second preamble octet. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE; } - // NotPreamble + /* NotPreamble */ else { mstp_port->DataAvailable = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } } } break; - // In the HEADER state, the node waits for the fixed message header. + /* In the HEADER state, the node waits for the fixed message header. */ case MSTP_RECEIVE_STATE_HEADER: - // Timeout + /* Timeout */ if (mstp_port->SilenceTimer > Tframe_abort) { - // indicate that an error has occurred during the reception of a frame + /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // Error + /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // indicate that an error has occurred during the reception of a frame + /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else if (mstp_port->DataAvailable == true) { - // FrameType + /* FrameType */ if (mstp_port->Index == 0) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -323,7 +323,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index = 1; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // Destination + /* Destination */ else if (mstp_port->Index == 1) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -335,7 +335,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index = 2; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // Source + /* Source */ else if (mstp_port->Index == 2) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -347,7 +347,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index = 3; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // Length1 + /* Length1 */ else if (mstp_port->Index == 3) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -359,7 +359,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index = 4; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // Length2 + /* Length2 */ else if (mstp_port->Index == 4) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -371,7 +371,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index = 5; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER; } - // HeaderCRC + /* HeaderCRC */ else if (mstp_port->Index == 5) { mstp_port->SilenceTimer = 0; mstp_port->EventCount++; @@ -381,81 +381,81 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->DataAvailable = false; mstp_port->receive_state = MSTP_RECEIVE_STATE_HEADER_CRC; } - // not per MS/TP standard, but it is a case not covered + /* not per MS/TP standard, but it is a case not covered */ else { mstp_port->ReceiveError = false; mstp_port->SilenceTimer = 0; mstp_port->EventCount++; - // indicate that an error has occurred during - // the reception of a frame + /* indicate that an error has occurred during */ + /* the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of a frame. + /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } } break; - // In the HEADER_CRC state, the node validates the CRC on the fixed - // message header. + /* In the HEADER_CRC state, the node validates the CRC on the fixed */ + /* message header. */ case MSTP_RECEIVE_STATE_HEADER_CRC: - // BadCRC + /* BadCRC */ if (mstp_port->HeaderCRC != 0x55) { - // indicate that an error has occurred during the reception of a frame + /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else { if ((mstp_port->DestinationAddress == mstp_port->This_Station) || (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)) { - // FrameTooLong + /* FrameTooLong */ if (mstp_port->DataLength > MAX_MPDU) { - // indicate that a frame with an illegal or - // unacceptable data length has been received + /* indicate that a frame with an illegal or */ + /* unacceptable data length has been received */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // NoData + /* NoData */ else if (mstp_port->DataLength == 0) { - // indicate that a frame with no data has been received + /* indicate that a frame with no data has been received */ mstp_port->ReceivedValidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // Data + /* Data */ else { mstp_port->Index = 0; mstp_port->DataCRC = 0xFFFF; - // receive the data portion of the frame. + /* receive the data portion of the frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; } } - // NotForUs + /* NotForUs */ else { - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } } break; - // In the DATA state, the node waits for the data portion of a frame. + /* In the DATA state, the node waits for the data portion of a frame. */ case MSTP_RECEIVE_STATE_DATA: - // Timeout + /* Timeout */ if (mstp_port->SilenceTimer > Tframe_abort) { - // indicate that an error has occurred during the reception of a frame + /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // Error + /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; mstp_port->SilenceTimer = 0; - // indicate that an error has occurred during the reception of a frame + /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else if (mstp_port->DataAvailable == true) { - // DataOctet + /* DataOctet */ if (mstp_port->Index < mstp_port->DataLength) { mstp_port->SilenceTimer = 0; mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, @@ -466,16 +466,16 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Index++; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; } - // CRC1 + /* CRC1 */ else if (mstp_port->Index == mstp_port->DataLength) { mstp_port->SilenceTimer = 0; mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, mstp_port->DataCRC); mstp_port->DataAvailable = false; - mstp_port->Index++; // Index now becomes the number of data octets + mstp_port->Index++; /* Index now becomes the number of data octets */ mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; } - // CRC2 + /* CRC2 */ else if (mstp_port->Index == (mstp_port->DataLength + 1)) { mstp_port->SilenceTimer = 0; mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, @@ -485,29 +485,29 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) } } break; - // In the DATA_CRC state, the node validates the CRC of the message data. + /* In the DATA_CRC state, the node validates the CRC of the message data. */ case MSTP_RECEIVE_STATE_DATA_CRC: - // GoodCRC + /* GoodCRC */ if (mstp_port->DataCRC == 0xF0B8) { - // indicate the complete reception of a valid frame + /* indicate the complete reception of a valid frame */ mstp_port->ReceivedValidFrame = true; - // now might be a good time to process the message or - // copy the data to a buffer so that we can process the message + /* now might be a good time to process the message or */ + /* copy the data to a buffer so that we can process the message */ - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - // BadCRC + /* BadCRC */ else { - // to indicate that an error has occurred during the reception of a frame + /* to indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - // wait for the start of the next frame. + /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } break; default: - // shouldn't get here - but if we do... + /* shouldn't get here - but if we do... */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; break; } @@ -520,71 +520,71 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) switch (mstp_port->master_state) { case MSTP_MASTER_STATE_INITIALIZE: - // DoneInitializing - mstp_port->This_Station = 0; // FIXME: the node's station address - // indicate that the next station is unknown + /* DoneInitializing */ + mstp_port->This_Station = 0; /* FIXME: the node's station address */ + /* indicate that the next station is unknown */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->Poll_Station = mstp_port->This_Station; - // cause a Poll For Master to be sent when this node first - // receives the token + /* cause a Poll For Master to be sent when this node first */ + /* receives the token */ mstp_port->TokenCount = Npoll; mstp_port->SoleMaster = false; mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedInvalidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_IDLE; break; - // In the IDLE state, the node waits for a frame. + /* In the IDLE state, the node waits for a frame. */ case MSTP_MASTER_STATE_IDLE: - // LostToken + /* LostToken */ if (mstp_port->SilenceTimer >= Tno_token) { - // assume that the token has been lost + /* assume that the token has been lost */ mstp_port->master_state = MSTP_MASTER_STATE_NO_TOKEN; } - // mstp_port->ReceivedInvalidFrame + /* mstp_port->ReceivedInvalidFrame */ else if (mstp_port->ReceivedInvalidFrame == true) { - // invalid frame was received + /* invalid frame was received */ mstp_port->ReceivedInvalidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // ReceivedUnwantedFrame + /* ReceivedUnwantedFrame */ else if (mstp_port->ReceivedValidFrame == true) { if ((mstp_port->DestinationAddress != mstp_port->This_Station) || (mstp_port->DestinationAddress != MSTP_BROADCAST_ADDRESS)) { - // an unexpected or unwanted frame was received. + /* an unexpected or unwanted frame was received. */ mstp_port->ReceivedValidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // DestinationAddress is equal to 255 (broadcast) and - // FrameType has a value of Token, BACnet Data Expecting Reply, Test_Request, - // or a proprietary type known to this node that expects a reply - // (such frames may not be broadcast), or + /* DestinationAddress is equal to 255 (broadcast) and */ + /* FrameType has a value of Token, BACnet Data Expecting Reply, Test_Request, */ + /* or a proprietary type known to this node that expects a reply */ + /* (such frames may not be broadcast), or */ else if ((mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS) && ((mstp_port->FrameType == FRAME_TYPE_TOKEN) || (mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY) || (mstp_port->FrameType == FRAME_TYPE_TEST_REQUEST))) { - // an unexpected or unwanted frame was received. + /* an unexpected or unwanted frame was received. */ mstp_port->ReceivedValidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // FrameType has a value that indicates a standard or proprietary type - // that is not known to this node. - // FIXME: change this if you add a proprietary type + /* FrameType has a value that indicates a standard or proprietary type */ + /* that is not known to this node. */ + /* FIXME: change this if you add a proprietary type */ else if /*( */ (mstp_port->FrameType >= FRAME_TYPE_PROPRIETARY_MIN) { /*&& */ /*(FrameType <= FRAME_TYPE_PROPRIETARY_MAX)) */ /* unnecessary if FrameType is uint8_t with max of 255 */ - // an unexpected or unwanted frame was received. + /* an unexpected or unwanted frame was received. */ mstp_port->ReceivedValidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // ReceivedToken + /* ReceivedToken */ else if ((mstp_port->DestinationAddress == mstp_port->This_Station) && (mstp_port->FrameType == FRAME_TYPE_TOKEN)) { @@ -593,7 +593,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->SoleMaster = false; mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; } - // ReceivedPFM + /* ReceivedPFM */ else if ((mstp_port->DestinationAddress == mstp_port->This_Station) && (mstp_port->FrameType == FRAME_TYPE_POLL_FOR_MASTER)) { @@ -602,174 +602,174 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->SourceAddress, mstp_port->This_Station, NULL, 0); mstp_port->ReceivedValidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // ReceivedDataNoReply - // or a proprietary type known to this node that does not expect a reply + /* ReceivedDataNoReply */ + /* or a proprietary type known to this node that does not expect a reply */ else if (((mstp_port->DestinationAddress == mstp_port->This_Station) || (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)) && ((mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY) || - // (mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || + /* (mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || */ (mstp_port->FrameType == FRAME_TYPE_TEST_RESPONSE))) { - // FIXME: indicate successful reception to the higher layers - // i.e. Process this frame! + /* FIXME: indicate successful reception to the higher layers */ + /* i.e. Process this frame! */ mstp_port->ReceivedValidFrame = false; - // wait for the next frame + /* wait for the next frame */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // ReceivedDataNeedingReply - // or a proprietary type known to this node that expects a reply + /* ReceivedDataNeedingReply */ + /* or a proprietary type known to this node that expects a reply */ else if ((mstp_port->DestinationAddress == mstp_port->This_Station) && ((mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY) || - // (mstp_port->FrameType == FRAME_TYPE_PROPRIETARY) || + /* (mstp_port->FrameType == FRAME_TYPE_PROPRIETARY) || */ (mstp_port->FrameType == FRAME_TYPE_TEST_REQUEST))) { mstp_port->ReplyPostponedTimer = 0; - // indicate successful reception to the higher layers - // (management entity in the case of Test_Request); + /* indicate successful reception to the higher layers */ + /* (management entity in the case of Test_Request); */ mstp_port->ReceivedValidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_ANSWER_DATA_REQUEST; } } break; - // In the USE_TOKEN state, the node is allowed to send one or - // more data frames. These may be BACnet Data frames or - // proprietary frames. + /* In the USE_TOKEN state, the node is allowed to send one or */ + /* more data frames. These may be BACnet Data frames or */ + /* proprietary frames. */ case MSTP_MASTER_STATE_USE_TOKEN: - // NothingToSend - // FIXME: If there is no data frame awaiting transmission, + /* NothingToSend */ + /* FIXME: If there is no data frame awaiting transmission, */ { mstp_port->FrameCount = mstp_port->Nmax_info_frames; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; } - // SendNoWait - // FIXME: If there is a frame awaiting transmission that - // is of type Test_Response, BACnet Data Not Expecting Reply, - // or a proprietary type that does not expect a reply, -// { -// // transmit the data frame -// MSTP_Create_And_Send_Frame(?????????????); -// FrameCount++; -// mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; -// } - // SendAndWait - // FIXME: If there is a frame awaiting transmission that is of - // type Test_Request, BACnet Data Expecting Reply, or - // a proprietary type that expects a reply, -// { -// // transmit the data frame -// MSTP_Create_And_Send_Frame(); -// FrameCount++; -// mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; -// } - // In the WAIT_FOR_REPLY state, the node waits for - // a reply from another node. + /* SendNoWait */ + /* FIXME: If there is a frame awaiting transmission that */ + /* is of type Test_Response, BACnet Data Not Expecting Reply, */ + /* or a proprietary type that does not expect a reply, */ +/* { */ +/* // transmit the data frame */ +/* MSTP_Create_And_Send_Frame(?????????????); */ +/* FrameCount++; */ +/* mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; */ +/* } */ + /* SendAndWait */ + /* FIXME: If there is a frame awaiting transmission that is of */ + /* type Test_Request, BACnet Data Expecting Reply, or */ + /* a proprietary type that expects a reply, */ +/* { */ +/* // transmit the data frame */ +/* MSTP_Create_And_Send_Frame(); */ +/* FrameCount++; */ +/* mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; */ +/* } */ + /* In the WAIT_FOR_REPLY state, the node waits for */ + /* a reply from another node. */ case MSTP_MASTER_STATE_WAIT_FOR_REPLY: - // ReplyTimeout + /* ReplyTimeout */ if (mstp_port->SilenceTimer >= Treply_timeout) { - // assume that the request has failed + /* assume that the request has failed */ mstp_port->FrameCount = mstp_port->Nmax_info_frames; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; - // Any retry of the data frame shall await the next entry - // to the USE_TOKEN state. (Because of the length of the timeout, - // this transition will cause the token to be passed regardless - // of the initial value of FrameCount.) + /* Any retry of the data frame shall await the next entry */ + /* to the USE_TOKEN state. (Because of the length of the timeout, */ + /* this transition will cause the token to be passed regardless */ + /* of the initial value of FrameCount.) */ } - // InvalidFrame + /* InvalidFrame */ else if ((mstp_port->SilenceTimer < Treply_timeout) && (mstp_port->ReceivedInvalidFrame == true)) { - // error in frame reception + /* error in frame reception */ mstp_port->ReceivedInvalidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; } - // ReceivedReply - // or a proprietary type that indicates a reply + /* ReceivedReply */ + /* or a proprietary type that indicates a reply */ else if ((mstp_port->SilenceTimer < Treply_timeout) && (mstp_port->ReceivedValidFrame == true) && (mstp_port->DestinationAddress == mstp_port->This_Station) && ((mstp_port->FrameType == FRAME_TYPE_TEST_RESPONSE) || - //(mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || + /*(mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || */ (mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY))) { - // FIXME: indicate successful reception to the higher layers + /* FIXME: indicate successful reception to the higher layers */ mstp_port->ReceivedValidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; } - // ReceivedPostpone + /* ReceivedPostpone */ else if ((mstp_port->SilenceTimer < Treply_timeout) && (mstp_port->ReceivedValidFrame == true) && (mstp_port->DestinationAddress == mstp_port->This_Station) && (mstp_port->FrameType == FRAME_TYPE_REPLY_POSTPONED)) { - // FIXME: then the reply to the message has been postponed until a later time. - // So, what does this really mean? + /* FIXME: then the reply to the message has been postponed until a later time. */ + /* So, what does this really mean? */ mstp_port->ReceivedValidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; } - // ReceivedUnexpectedFrame + /* ReceivedUnexpectedFrame */ else if ((mstp_port->SilenceTimer < Treply_timeout) && (mstp_port->ReceivedValidFrame == true) && (mstp_port->DestinationAddress != mstp_port->This_Station)) - //the expected reply should not be broadcast) + /*the expected reply should not be broadcast) */ { - // an unexpected frame was received - // This may indicate the presence of multiple tokens. + /* an unexpected frame was received */ + /* This may indicate the presence of multiple tokens. */ mstp_port->ReceivedValidFrame = false; - // Synchronize with the network. - // This action drops the token. + /* Synchronize with the network. */ + /* This action drops the token. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // ReceivedUnexpectedFrame + /* ReceivedUnexpectedFrame */ else if ((mstp_port->SilenceTimer < Treply_timeout) && (mstp_port->ReceivedValidFrame == true) && ((mstp_port->FrameType == FRAME_TYPE_TEST_RESPONSE) || - //(mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || + /*(mstp_port->FrameType == FRAME_TYPE_PROPRIETARY_0) || */ (mstp_port->FrameType == FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY))) { - // An unexpected frame was received. - // This may indicate the presence of multiple tokens. + /* An unexpected frame was received. */ + /* This may indicate the presence of multiple tokens. */ mstp_port->ReceivedValidFrame = false; - // Synchronize with the network. - // This action drops the token. + /* Synchronize with the network. */ + /* This action drops the token. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } break; - // The DONE_WITH_TOKEN state either sends another data frame, - // passes the token, or initiates a Poll For Master cycle. + /* The DONE_WITH_TOKEN state either sends another data frame, */ + /* passes the token, or initiates a Poll For Master cycle. */ case MSTP_MASTER_STATE_DONE_WITH_TOKEN: - // SendAnotherFrame + /* SendAnotherFrame */ if (mstp_port->FrameCount < mstp_port->Nmax_info_frames) { - // then this node may send another information frame - // before passing the token. + /* then this node may send another information frame */ + /* before passing the token. */ mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; } - // mstp_port->SoleMaster + /* mstp_port->SoleMaster */ else if ((mstp_port->FrameCount >= mstp_port->Nmax_info_frames) && (mstp_port->TokenCount < Npoll) && (mstp_port->SoleMaster == true)) { - // there are no other known master nodes to - // which the token may be sent (true master-slave operation). + /* there are no other known master nodes to */ + /* which the token may be sent (true master-slave operation). */ mstp_port->FrameCount = 0; mstp_port->TokenCount++; mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; } - // SendToken + /* SendToken */ else if (((mstp_port->FrameCount >= mstp_port->Nmax_info_frames) && (mstp_port->TokenCount < Npoll) && (mstp_port->SoleMaster == false)) || - // The comparison of NS and TS+1 eliminates the Poll For Master - // if there are no addresses between TS and NS, since there is no - // address at which a new master node may be found in that case. + /* The comparison of NS and TS+1 eliminates the Poll For Master */ + /* if there are no addresses between TS and NS, since there is no */ + /* address at which a new master node may be found in that case. */ (mstp_port->Next_Station == (uint8_t) ((mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1)))) { mstp_port->TokenCount++; - // transmit a Token frame to NS + /* transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL, 0); @@ -777,7 +777,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->EventCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; } - // SendMaintenancePFM + /* SendMaintenancePFM */ else if ((mstp_port->FrameCount >= mstp_port->Nmax_info_frames) && (mstp_port->TokenCount >= Npoll) && ((uint8_t) ((mstp_port->Poll_Station + @@ -792,7 +792,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->RetryCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } - // ResetMaintenancePFM + /* ResetMaintenancePFM */ else if ((mstp_port->FrameCount >= mstp_port->Nmax_info_frames) && (mstp_port->TokenCount >= Npoll) && ((uint8_t) ((mstp_port->Poll_Station + @@ -800,7 +800,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Next_Station) && (mstp_port->SoleMaster == false)) { mstp_port->Poll_Station = mstp_port->This_Station; - // transmit a Token frame to NS + /* transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL, 0); @@ -809,7 +809,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->EventCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; } - // SoleMasterRestartMaintenancePFM + /* SoleMasterRestartMaintenancePFM */ else if ((mstp_port->FrameCount >= mstp_port->Nmax_info_frames) && (mstp_port->TokenCount >= Npoll) && ((uint8_t) ((mstp_port->Poll_Station + @@ -822,97 +822,97 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); - // no known successor node + /* no known successor node */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; mstp_port->TokenCount = 0; mstp_port->EventCount = 0; - // find a new successor to TS + /* find a new successor to TS */ mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } - // The PASS_TOKEN state listens for a successor to begin using - // the token that this node has just attempted to pass. + /* The PASS_TOKEN state listens for a successor to begin using */ + /* the token that this node has just attempted to pass. */ case MSTP_MASTER_STATE_PASS_TOKEN: - // SawTokenUser + /* SawTokenUser */ if ((mstp_port->SilenceTimer < Tusage_timeout) && (mstp_port->EventCount > Nmin_octets)) { - // Assume that a frame has been sent by the new token user. - // Enter the IDLE state to process the frame. + /* Assume that a frame has been sent by the new token user. */ + /* Enter the IDLE state to process the frame. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // RetrySendToken + /* RetrySendToken */ else if ((mstp_port->SilenceTimer >= Tusage_timeout) && (mstp_port->RetryCount < Nretry_token)) { mstp_port->RetryCount++; - // Transmit a Token frame to NS + /* Transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL, 0); mstp_port->EventCount = 0; - // re-enter the current state to listen for NS - // to begin using the token. + /* re-enter the current state to listen for NS */ + /* to begin using the token. */ } - // FindNewSuccessor + /* FindNewSuccessor */ else if ((mstp_port->SilenceTimer >= Tusage_timeout) && (mstp_port->RetryCount >= Nretry_token)) { - // Assume that NS has failed. + /* Assume that NS has failed. */ mstp_port->Poll_Station = (mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1); - // Transmit a Poll For Master frame to PS. + /* Transmit a Poll For Master frame to PS. */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); - // no known successor node + /* no known successor node */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; mstp_port->TokenCount = 0; mstp_port->EventCount = 0; - // find a new successor to TS + /* find a new successor to TS */ mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } break; - // The NO_TOKEN state is entered if mstp_port->SilenceTimer becomes greater - // than Tno_token, indicating that there has been no network activity - // for that period of time. The timeout is continued to determine - // whether or not this node may create a token. + /* The NO_TOKEN state is entered if mstp_port->SilenceTimer becomes greater */ + /* than Tno_token, indicating that there has been no network activity */ + /* for that period of time. The timeout is continued to determine */ + /* whether or not this node may create a token. */ case MSTP_MASTER_STATE_NO_TOKEN: - // SawFrame + /* SawFrame */ if ((mstp_port->SilenceTimer < (Tno_token + (Tslot * mstp_port->This_Station))) && (mstp_port->EventCount > Nmin_octets)) { - // Some other node exists at a lower address. - // Enter the IDLE state to receive and process the incoming frame. + /* Some other node exists at a lower address. */ + /* Enter the IDLE state to receive and process the incoming frame. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // GenerateToken + /* GenerateToken */ else if ((mstp_port->SilenceTimer >= (Tno_token + (Tslot * mstp_port->This_Station))) && (mstp_port->SilenceTimer < (Tno_token + (Tslot * (mstp_port->This_Station + 1))))) { - // Assume that this node is the lowest numerical address - // on the network and is empowered to create a token. + /* Assume that this node is the lowest numerical address */ + /* on the network and is empowered to create a token. */ mstp_port->Poll_Station = (mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1); - // Transmit a Poll For Master frame to PS. + /* Transmit a Poll For Master frame to PS. */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); - // indicate that the next station is unknown + /* indicate that the next station is unknown */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; mstp_port->TokenCount = 0; mstp_port->EventCount = 0; - // enter the POLL_FOR_MASTER state to find a new successor to TS. + /* enter the POLL_FOR_MASTER state to find a new successor to TS. */ mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } break; - // In the POLL_FOR_MASTER state, the node listens for a reply to - // a previously sent Poll For Master frame in order to find - // a successor node. + /* In the POLL_FOR_MASTER state, the node listens for a reply to */ + /* a previously sent Poll For Master frame in order to find */ + /* a successor node. */ case MSTP_MASTER_STATE_POLL_FOR_MASTER: - // ReceivedReplyToPFM + /* ReceivedReplyToPFM */ if ((mstp_port->ReceivedValidFrame == true) && (mstp_port->DestinationAddress == mstp_port->This_Station) && (mstp_port->FrameType == FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) @@ -920,7 +920,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->SoleMaster = false; mstp_port->Next_Station = mstp_port->SourceAddress; mstp_port->EventCount = 0; - // Transmit a Token frame to NS + /* Transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL, 0); @@ -930,37 +930,37 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->ReceivedValidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; } - // ReceivedUnexpectedFrame + /* ReceivedUnexpectedFrame */ else if ((mstp_port->ReceivedValidFrame == true) && ((mstp_port->DestinationAddress != mstp_port->This_Station) || (mstp_port->FrameType != FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER))) { - // An unexpected frame was received. - // This may indicate the presence of multiple tokens. + /* An unexpected frame was received. */ + /* This may indicate the presence of multiple tokens. */ mstp_port->ReceivedValidFrame = false; - // enter the IDLE state to synchronize with the network. - // This action drops the token. + /* enter the IDLE state to synchronize with the network. */ + /* This action drops the token. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // mstp_port->SoleMaster + /* mstp_port->SoleMaster */ else if ((mstp_port->SoleMaster == true) && ((mstp_port->SilenceTimer >= Tusage_timeout) || (mstp_port->ReceivedInvalidFrame == true))) { - // There was no valid reply to the periodic poll - // by the sole known master for other masters. + /* There was no valid reply to the periodic poll */ + /* by the sole known master for other masters. */ mstp_port->FrameCount = 0; mstp_port->ReceivedInvalidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; } - // DoneWithPFM + /* DoneWithPFM */ else if ((mstp_port->SoleMaster == false) && (mstp_port->Next_Station != mstp_port->This_Station) && ((mstp_port->SilenceTimer >= Tusage_timeout) || (mstp_port->ReceivedInvalidFrame == true))) { - // There was no valid reply to the maintenance - // poll for a master at address PS. + /* There was no valid reply to the maintenance */ + /* poll for a master at address PS. */ mstp_port->EventCount = 0; - // transmit a Token frame to NS + /* transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, mstp_port->This_Station, NULL, 0); @@ -968,8 +968,8 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->ReceivedInvalidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; } - // SendNextPFM - else if ((mstp_port->SoleMaster == false) && (mstp_port->Next_Station == mstp_port->This_Station) && // no known successor node + /* SendNextPFM */ + else if ((mstp_port->SoleMaster == false) && (mstp_port->Next_Station == mstp_port->This_Station) && /* no known successor node */ ((uint8_t) ((mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1)) != mstp_port->This_Station) @@ -978,52 +978,52 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) mstp_port->Poll_Station = (mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1); - // Transmit a Poll For Master frame to PS. + /* Transmit a Poll For Master frame to PS. */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; mstp_port->ReceivedInvalidFrame = false; - // Re-enter the current state. + /* Re-enter the current state. */ } - // DeclareSoleMaster - else if ((mstp_port->SoleMaster == false) && (mstp_port->Next_Station == mstp_port->This_Station) && // no known successor node + /* DeclareSoleMaster */ + else if ((mstp_port->SoleMaster == false) && (mstp_port->Next_Station == mstp_port->This_Station) && /* no known successor node */ ((uint8_t) ((mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1)) == mstp_port->This_Station) && ((mstp_port->SilenceTimer >= Tusage_timeout) || (mstp_port->ReceivedInvalidFrame == true))) { - // to indicate that this station is the only master + /* to indicate that this station is the only master */ mstp_port->SoleMaster = true; mstp_port->FrameCount = 0; mstp_port->ReceivedInvalidFrame = false; mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; } break; - // The ANSWER_DATA_REQUEST state is entered when a - // BACnet Data Expecting Reply, a Test_Request, or - // a proprietary frame that expects a reply is received. + /* The ANSWER_DATA_REQUEST state is entered when a */ + /* BACnet Data Expecting Reply, a Test_Request, or */ + /* a proprietary frame that expects a reply is received. */ case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST: if (mstp_port->ReplyPostponedTimer <= Treply_delay) { - // Reply - // If a reply is available from the higher layers - // within Treply_delay after the reception of the - // final octet of the requesting frame - // (the mechanism used to determine this is a local matter), - // then call MSTP_Create_And_Send_Frame to transmit the reply frame - // and enter the IDLE state to wait for the next frame. + /* Reply */ + /* If a reply is available from the higher layers */ + /* within Treply_delay after the reception of the */ + /* final octet of the requesting frame */ + /* (the mechanism used to determine this is a local matter), */ + /* then call MSTP_Create_And_Send_Frame to transmit the reply frame */ + /* and enter the IDLE state to wait for the next frame. */ - // Test Request - // If a receiving node can successfully receive and return - // the information field, it shall do so. If it cannot receive - // and return the entire information field but can detect - // the reception of a valid Test_Request frame - // (for example, by computing the CRC on octets as - // they are received), then the receiving node shall discard - // the information field and return a Test_Response containing - // no information field. If the receiving node cannot detect - // the valid reception of frames with overlength information fields, - // then no response shall be returned. + /* Test Request */ + /* If a receiving node can successfully receive and return */ + /* the information field, it shall do so. If it cannot receive */ + /* and return the entire information field but can detect */ + /* the reception of a valid Test_Request frame */ + /* (for example, by computing the CRC on octets as */ + /* they are received), then the receiving node shall discard */ + /* the information field and return a Test_Response containing */ + /* no information field. If the receiving node cannot detect */ + /* the valid reception of frames with overlength information fields, */ + /* then no response shall be returned. */ if (mstp_port->FrameType == FRAME_TYPE_TEST_REQUEST) { MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TEST_RESPONSE, @@ -1034,16 +1034,16 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) } mstp_port->master_state = MSTP_MASTER_STATE_IDLE; } - // - // DeferredReply - // If no reply will be available from the higher layers - // within Treply_delay after the reception of the - // final octet of the requesting frame (the mechanism - // used to determine this is a local matter), - // then an immediate reply is not possible. - // Any reply shall wait until this node receives the token. - // Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed frame, - // and enter the IDLE state. + /* */ + /* DeferredReply */ + /* If no reply will be available from the higher layers */ + /* within Treply_delay after the reception of the */ + /* final octet of the requesting frame (the mechanism */ + /* used to determine this is a local matter), */ + /* then an immediate reply is not possible. */ + /* Any reply shall wait until this node receives the token. */ + /* Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed frame, */ + /* and enter the IDLE state. */ else { MSTP_Create_And_Send_Frame(mstp_port, @@ -1064,7 +1064,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port, uint8_t this_station_mac) { - int i; //loop counter + int i; /*loop counter */ if (mstp_port) { mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -1106,11 +1106,11 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port, #include #include "ctest.h" -// test stub functions -void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port specific data - uint8_t * buffer, // frame to send (up to 501 bytes of data) - uint16_t nbytes) // number of bytes of data (up to 501) -{ +/* test stub functions */ +void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ + uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ + uint16_t nbytes) +{ /* number of bytes of data (up to 501) */ (void) mstp_port; (void) buffer; (void) nbytes; @@ -1122,7 +1122,7 @@ static RING_BUFFER Test_Buffer; static uint8_t Test_Buffer_Data[RING_BUFFER_DATA_SIZE * RING_BUFFER_SIZE]; static void Load_Input_Buffer(uint8_t * buffer, size_t len) { - static bool initialized = false; // tracks our init + static bool initialized = false; /* tracks our init */ if (!initialized) { @@ -1131,7 +1131,7 @@ static void Load_Input_Buffer(uint8_t * buffer, size_t len) (char *) Test_Buffer_Data, RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE); } - // empty any the existing data + /* empty any the existing data */ while (!Ringbuf_Empty(&Test_Buffer)) { (void) Ringbuf_Pop_Front(&Test_Buffer); } @@ -1145,8 +1145,8 @@ static void Load_Input_Buffer(uint8_t * buffer, size_t len) } } -void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) // port specific data -{ +void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) +{ /* port specific data */ char *data; if (!Ringbuf_Empty(&Test_Buffer) && mstp_port && (mstp_port->DataAvailable == false)) { @@ -1160,19 +1160,19 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) void testReceiveNodeFSM(Test * pTest) { - volatile struct mstp_port_struct_t mstp_port; // port data - unsigned EventCount = 0; // local counter - uint8_t my_mac = 0x05; // local MAC address - uint8_t HeaderCRC = 0; // for local CRC calculation - uint8_t FrameType = 0; // type of packet that was sent - unsigned len; // used for the size of the message packet - size_t i; // used to loop through the message bytes + volatile struct mstp_port_struct_t mstp_port; /* port data */ + unsigned EventCount = 0; /* local counter */ + uint8_t my_mac = 0x05; /* local MAC address */ + uint8_t HeaderCRC = 0; /* for local CRC calculation */ + uint8_t FrameType = 0; /* type of packet that was sent */ + unsigned len; /* used for the size of the message packet */ + size_t i; /* used to loop through the message bytes */ uint8_t buffer[MAX_MPDU] = { 0 }; uint8_t data[MAX_MPDU - 8 /*header */ - 2 /*CRC*/] = { 0 }; MSTP_Init(&mstp_port, my_mac); - // check the receive error during idle + /* check the receive error during idle */ mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port.ReceiveError = true; mstp_port.SilenceTimer = 255; @@ -1184,7 +1184,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.ReceiveError == false); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for bad packet header + /* check for bad packet header */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x11; EventCount++; @@ -1194,7 +1194,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for good packet header, but timeout + /* check for good packet header, but timeout */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1203,12 +1203,12 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.SilenceTimer == 0); ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - // force the timeout + /* force the timeout */ mstp_port.SilenceTimer = Tframe_abort + 1; MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for good packet header preamble, but receive error + /* check for good packet header preamble, but receive error */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1217,7 +1217,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.SilenceTimer == 0); ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - // force the error + /* force the error */ mstp_port.ReceiveError = true; EventCount++; MSTP_Receive_Frame_FSM(&mstp_port); @@ -1226,7 +1226,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for good packet header preamble1, but bad preamble2 + /* check for good packet header preamble1, but bad preamble2 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1236,12 +1236,12 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); MSTP_Receive_Frame_FSM(&mstp_port); - // no change of state if no data yet + /* no change of state if no data yet */ MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - // repeated preamble1 + /* repeated preamble1 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1250,7 +1250,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.SilenceTimer == 0); ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - // repeated preamble1 + /* repeated preamble1 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1259,7 +1259,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.SilenceTimer == 0); ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); - // bad data + /* bad data */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x11; EventCount++; @@ -1269,7 +1269,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for good packet header preamble, but timeout in packet + /* check for good packet header preamble, but timeout in packet */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1279,7 +1279,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); MSTP_Receive_Frame_FSM(&mstp_port); - // preamble2 + /* preamble2 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF; EventCount++; @@ -1290,13 +1290,13 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 0); ct_test(pTest, mstp_port.HeaderCRC == 0xFF); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - // force the timeout + /* force the timeout */ mstp_port.SilenceTimer = Tframe_abort + 1; MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); - // check for good packet header preamble, but error in packet + /* check for good packet header preamble, but error in packet */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1306,7 +1306,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); MSTP_Receive_Frame_FSM(&mstp_port); - // preamble2 + /* preamble2 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF; EventCount++; @@ -1317,7 +1317,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 0); ct_test(pTest, mstp_port.HeaderCRC == 0xFF); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - // force the error + /* force the error */ mstp_port.ReceiveError = true; EventCount++; MSTP_Receive_Frame_FSM(&mstp_port); @@ -1326,7 +1326,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // check for good packet header preamble + /* check for good packet header preamble */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55; EventCount++; @@ -1336,7 +1336,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.EventCount == EventCount); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE); MSTP_Receive_Frame_FSM(&mstp_port); - // preamble2 + /* preamble2 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF; EventCount++; @@ -1347,13 +1347,13 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 0); ct_test(pTest, mstp_port.HeaderCRC == 0xFF); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - // no change of state if no data yet + /* no change of state if no data yet */ MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); - // Data is received - index is incremented - // FrameType + /* Data is received - index is incremented */ + /* FrameType */ mstp_port.DataAvailable = true; mstp_port.DataRegister = FRAME_TYPE_TOKEN; HeaderCRC = 0xFF; @@ -1366,7 +1366,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 1); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, FrameType == FRAME_TYPE_TOKEN); - // Destination + /* Destination */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x10; HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); @@ -1378,7 +1378,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 2); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.DestinationAddress == 0x10); - // Source + /* Source */ mstp_port.DataAvailable = true; mstp_port.DataRegister = my_mac; HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); @@ -1390,7 +1390,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 3); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.SourceAddress == my_mac); - // Length1 = length*256 + /* Length1 = length*256 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0; HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); @@ -1402,7 +1402,7 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 4); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.DataLength == 0); - // Length2 + /* Length2 */ mstp_port.DataAvailable = true; mstp_port.DataRegister = 0; HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC); @@ -1414,10 +1414,10 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.Index == 5); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.DataLength == 0); - // HeaderCRC + /* HeaderCRC */ mstp_port.DataAvailable = true; - ct_test(pTest, HeaderCRC == 0x73); // per Annex G example - mstp_port.DataRegister = ~HeaderCRC; // one's compliment of CRC is sent + ct_test(pTest, HeaderCRC == 0x73); /* per Annex G example */ + mstp_port.DataRegister = ~HeaderCRC; /* one's compliment of CRC is sent */ EventCount++; MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.DataAvailable == false); @@ -1427,19 +1427,19 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER_CRC); ct_test(pTest, mstp_port.HeaderCRC == 0x55); - // NotForUs + /* NotForUs */ MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // BadCRC in header check + /* BadCRC in header check */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, // destination - my_mac, // source - NULL, // data - 0); // data size + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); - // make the header CRC bad + /* make the header CRC bad */ buffer[7] = 0x00; Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) { @@ -1457,13 +1457,13 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.ReceivedValidFrame == false); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // NoData for us + /* NoData for us */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, // destination - my_mac, // source - NULL, // data - 0); // data size + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) { @@ -1481,15 +1481,15 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.ReceivedValidFrame == true); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // FrameTooLong + /* FrameTooLong */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, // destination - my_mac, // source - NULL, // data - 0); // data size + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); - // make the header data length bad + /* make the header data length bad */ buffer[5] = 0x02; Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) { @@ -1507,14 +1507,14 @@ void testReceiveNodeFSM(Test * pTest) ct_test(pTest, mstp_port.ReceivedValidFrame == false); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); - // Data + /* Data */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; memset(data, 0, sizeof(data)); - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, my_mac, // destination - my_mac, // source - data, // data - sizeof(data)); // data size + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, my_mac, /* destination */ + my_mac, /* source */ + data, /* data */ + sizeof(data)); /* data size */ ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len); RS485_Check_UART_Data(&mstp_port); @@ -1533,8 +1533,8 @@ void testReceiveNodeFSM(Test * pTest) void testMasterNodeFSM(Test * pTest) { - volatile struct mstp_port_struct_t mstp_port; // port data - uint8_t my_mac = 0x05; // local MAC address + volatile struct mstp_port_struct_t mstp_port; /* port data */ + uint8_t my_mac = 0x05; /* local MAC address */ MSTP_Init(&mstp_port, my_mac); ct_test(pTest, mstp_port.master_state == MSTP_MASTER_STATE_INITIALIZE); diff --git a/bacnet-stack/mstp.h b/bacnet-stack/mstp.h index b241f91c..a2e62834 100644 --- a/bacnet-stack/mstp.h +++ b/bacnet-stack/mstp.h @@ -42,12 +42,12 @@ #include "bacdef.h" #include "dlmstp.h" -// The value 255 is used to denote broadcast when used as a -// destination address but is not allowed as a value for a station. +/* The value 255 is used to denote broadcast when used as a */ +/* destination address but is not allowed as a value for a station. */ #define MSTP_BROADCAST_ADDRESS 255 -// MS/TP Frame Type -// Frame Types 8 through 127 are reserved by ASHRAE. +/* MS/TP Frame Type */ +/* Frame Types 8 through 127 are reserved by ASHRAE. */ #define FRAME_TYPE_TOKEN 0 #define FRAME_TYPE_POLL_FOR_MASTER 1 #define FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER 2 @@ -56,16 +56,16 @@ #define FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY 5 #define FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY 6 #define FRAME_TYPE_REPLY_POSTPONED 7 -// Frame Types 128 through 255: Proprietary Frames -// These frames are available to vendors as proprietary (non-BACnet) frames. -// The first two octets of the Data field shall specify the unique vendor -// identification code, most significant octet first, for the type of -// vendor-proprietary frame to be conveyed. The length of the data portion -// of a Proprietary frame shall be in the range of 2 to 501 octets. +/* Frame Types 128 through 255: Proprietary Frames */ +/* These frames are available to vendors as proprietary (non-BACnet) frames. */ +/* The first two octets of the Data field shall specify the unique vendor */ +/* identification code, most significant octet first, for the type of */ +/* vendor-proprietary frame to be conveyed. The length of the data portion */ +/* of a Proprietary frame shall be in the range of 2 to 501 octets. */ #define FRAME_TYPE_PROPRIETARY_MIN 128 #define FRAME_TYPE_PROPRIETARY_MAX 255 -// receive FSM states +/* receive FSM states */ typedef enum { MSTP_RECEIVE_STATE_IDLE, MSTP_RECEIVE_STATE_PREAMBLE, @@ -75,7 +75,7 @@ typedef enum { MSTP_RECEIVE_STATE_DATA_CRC } MSTP_RECEIVE_STATE; -// master node FSM states +/* master node FSM states */ typedef enum { MSTP_MASTER_STATE_INITIALIZE, MSTP_MASTER_STATE_IDLE, @@ -90,115 +90,115 @@ typedef enum { struct mstp_port_struct_t { MSTP_RECEIVE_STATE receive_state; - // When a master node is powered up or reset, - // it shall unconditionally enter the INITIALIZE state. + /* When a master node is powered up or reset, */ + /* it shall unconditionally enter the INITIALIZE state. */ MSTP_MASTER_STATE master_state; - // A Boolean flag set to TRUE by the Receive State Machine - // if an error is detected during the reception of a frame. - // Set to FALSE by the main state machine. + /* A Boolean flag set to TRUE by the Receive State Machine */ + /* if an error is detected during the reception of a frame. */ + /* Set to FALSE by the main state machine. */ unsigned ReceiveError:1; - // There is data in the buffer + /* There is data in the buffer */ unsigned DataAvailable:1; - unsigned FramingError:1; // TRUE if we got a framing error + unsigned FramingError:1; /* TRUE if we got a framing error */ unsigned ReceivedInvalidFrame:1; - // A Boolean flag set to TRUE by the Receive State Machine - // if a valid frame is received. - // Set to FALSE by the main state machine. + /* A Boolean flag set to TRUE by the Receive State Machine */ + /* if a valid frame is received. */ + /* Set to FALSE by the main state machine. */ unsigned ReceivedValidFrame:1; - // A Boolean flag set to TRUE by the master machine if this node is the - // only known master node. + /* A Boolean flag set to TRUE by the master machine if this node is the */ + /* only known master node. */ unsigned SoleMaster:1; - // After receiving a frame this value will be TRUE until Tturnaround - // has expired + /* After receiving a frame this value will be TRUE until Tturnaround */ + /* has expired */ unsigned Turn_Around_Waiting:1; - // stores the latest received data + /* stores the latest received data */ uint8_t DataRegister; - // Used to accumulate the CRC on the data field of a frame. + /* Used to accumulate the CRC on the data field of a frame. */ uint16_t DataCRC; - // Used to store the data length of a received frame. + /* Used to store the data length of a received frame. */ unsigned DataLength; - // Used to store the destination address of a received frame. + /* Used to store the destination address of a received frame. */ uint8_t DestinationAddress; - // Used to count the number of received octets or errors. - // This is used in the detection of link activity. + /* Used to count the number of received octets or errors. */ + /* This is used in the detection of link activity. */ unsigned EventCount; - // Used to store the frame type of a received frame. + /* Used to store the frame type of a received frame. */ uint8_t FrameType; - // The number of frames sent by this node during a single token hold. - // When this counter reaches the value Nmax_info_frames, the node must - // pass the token. + /* The number of frames sent by this node during a single token hold. */ + /* When this counter reaches the value Nmax_info_frames, the node must */ + /* pass the token. */ unsigned FrameCount; - // Used to accumulate the CRC on the header of a frame. + /* Used to accumulate the CRC on the header of a frame. */ uint8_t HeaderCRC; - // Used as an index by the Receive State Machine, up to a maximum value of - // InputBufferSize. + /* Used as an index by the Receive State Machine, up to a maximum value of */ + /* InputBufferSize. */ unsigned Index; - // An array of octets, used to store octets as they are received. - // InputBuffer is indexed from 0 to InputBufferSize-1. - // The maximum size of a frame is 501 octets. + /* An array of octets, used to store octets as they are received. */ + /* InputBuffer is indexed from 0 to InputBufferSize-1. */ + /* The maximum size of a frame is 501 octets. */ uint8_t InputBuffer[MAX_MPDU]; - // "Next Station," the MAC address of the node to which This Station passes - // the token. If the Next_Station is unknown, Next_Station shall be equal to - // This_Station. + /* "Next Station," the MAC address of the node to which This Station passes */ + /* the token. If the Next_Station is unknown, Next_Station shall be equal to */ + /* This_Station. */ uint8_t Next_Station; - // "Poll Station," the MAC address of the node to which This Station last - // sent a Poll For Master. This is used during token maintenance. + /* "Poll Station," the MAC address of the node to which This Station last */ + /* sent a Poll For Master. This is used during token maintenance. */ uint8_t Poll_Station; - // A counter of transmission retries used for Token and Poll For Master - // transmission. + /* A counter of transmission retries used for Token and Poll For Master */ + /* transmission. */ unsigned RetryCount; - // A timer with nominal 5 millisecond resolution used to measure and - // generate silence on the medium between octets. It is incremented by a - // timer process and is cleared by the Receive State Machine when activity - // is detected and by the SendFrame procedure as each octet is transmitted. - // Since the timer resolution is limited and the timer is not necessarily - // synchronized to other machine events, a timer value of N will actually - // denote intervals between N-1 and N + /* A timer with nominal 5 millisecond resolution used to measure and */ + /* generate silence on the medium between octets. It is incremented by a */ + /* timer process and is cleared by the Receive State Machine when activity */ + /* is detected and by the SendFrame procedure as each octet is transmitted. */ + /* Since the timer resolution is limited and the timer is not necessarily */ + /* synchronized to other machine events, a timer value of N will actually */ + /* denote intervals between N-1 and N */ unsigned SilenceTimer; - // A timer used to measure and generate Reply Postponed frames. It is - // incremented by a timer process and is cleared by the Master Node State - // Machine when a Data Expecting Reply Answer activity is completed. + /* A timer used to measure and generate Reply Postponed frames. It is */ + /* incremented by a timer process and is cleared by the Master Node State */ + /* Machine when a Data Expecting Reply Answer activity is completed. */ unsigned ReplyPostponedTimer; - // Used to store the Source Address of a received frame. + /* Used to store the Source Address of a received frame. */ uint8_t SourceAddress; - // The number of tokens received by this node. When this counter reaches the - // value Npoll, the node polls the address range between TS and NS for - // additional master nodes. TokenCount is set to zero at the end of the - // polling process. + /* The number of tokens received by this node. When this counter reaches the */ + /* value Npoll, the node polls the address range between TS and NS for */ + /* additional master nodes. TokenCount is set to zero at the end of the */ + /* polling process. */ unsigned TokenCount; - // "This Station," the MAC address of this node. TS is generally read from a - // hardware DIP switch, or from nonvolatile memory. Valid values for TS are - // 0 to 254. The value 255 is used to denote broadcast when used as a - // destination address but is not allowed as a value for TS. + /* "This Station," the MAC address of this node. TS is generally read from a */ + /* hardware DIP switch, or from nonvolatile memory. Valid values for TS are */ + /* 0 to 254. The value 255 is used to denote broadcast when used as a */ + /* destination address but is not allowed as a value for TS. */ uint8_t This_Station; - // This parameter represents the value of the Max_Info_Frames property of - // the node's Device object. The value of Max_Info_Frames specifies the - // maximum number of information frames the node may send before it must - // pass the token. Max_Info_Frames may have different values on different - // nodes. This may be used to allocate more or less of the available link - // bandwidth to particular nodes. If Max_Info_Frames is not writable in a - // node, its value shall be 1. + /* This parameter represents the value of the Max_Info_Frames property of */ + /* the node's Device object. The value of Max_Info_Frames specifies the */ + /* maximum number of information frames the node may send before it must */ + /* pass the token. Max_Info_Frames may have different values on different */ + /* nodes. This may be used to allocate more or less of the available link */ + /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */ + /* node, its value shall be 1. */ unsigned Nmax_info_frames; - // This parameter represents the value of the Max_Master property of the - // node's Device object. The value of Max_Master specifies the highest - // allowable address for master nodes. The value of Max_Master shall be - // less than or equal to 127. If Max_Master is not writable in a node, - // its value shall be 127. + /* This parameter represents the value of the Max_Master property of the */ + /* node's Device object. The value of Max_Master specifies the highest */ + /* allowable address for master nodes. The value of Max_Master shall be */ + /* less than or equal to 127. If Max_Master is not writable in a node, */ + /* its value shall be 127. */ unsigned Nmax_master; }; #define DEFAULT_MAX_INFO_FRAMES 1 #define DEFAULT_MAX_MASTER 127 -// The minimum time after the end of the stop bit of the final octet of a -// received frame before a node may enable its EIA-485 driver: 40 bit times. -// At 9600 baud, 40 bit times would be about 4.166 milliseconds +/* The minimum time after the end of the stop bit of the final octet of a */ +/* received frame before a node may enable its EIA-485 driver: 40 bit times. */ +/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */ #define Tturnaround 40; #ifdef __cplusplus diff --git a/bacnet-stack/npdu.c b/bacnet-stack/npdu.c index 1a960a80..3df1b9a2 100644 --- a/bacnet-stack/npdu.c +++ b/bacnet-stack/npdu.c @@ -44,58 +44,58 @@ int npdu_encode_raw(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) { - int len = 0; // return value - number of octets loaded in this function - int i = 0; // counter + int len = 0; /* return value - number of octets loaded in this function */ + int i = 0; /* counter */ if (npdu && npdu_data) { - // Protocol Version + /* Protocol Version */ npdu[0] = 1; - // control octet + /* control octet */ npdu[1] = 0; - // Bit 7: 1 indicates that the NSDU conveys a network layer message. - // Message Type field is present. - // 0 indicates that the NSDU contains a BACnet APDU. - // Message Type field is absent. + /* Bit 7: 1 indicates that the NSDU conveys a network layer message. */ + /* Message Type field is present. */ + /* 0 indicates that the NSDU contains a BACnet APDU. */ + /* Message Type field is absent. */ if (npdu_data->network_layer_message) npdu[1] |= BIT7; - //Bit 6: Reserved. Shall be zero. - //Bit 5: Destination specifier where: - // 0 = DNET, DLEN, DADR, and Hop Count absent - // 1 = DNET, DLEN, and Hop Count present - // DLEN = 0 denotes broadcast MAC DADR and DADR field is absent - // DLEN > 0 specifies length of DADR field + /*Bit 6: Reserved. Shall be zero. */ + /*Bit 5: Destination specifier where: */ + /* 0 = DNET, DLEN, DADR, and Hop Count absent */ + /* 1 = DNET, DLEN, and Hop Count present */ + /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */ + /* DLEN > 0 specifies length of DADR field */ if (dest && dest->net) npdu[1] |= BIT5; - // Bit 4: Reserved. Shall be zero. - // Bit 3: Source specifier where: - // 0 = SNET, SLEN, and SADR absent - // 1 = SNET, SLEN, and SADR present - // SLEN = 0 Invalid - // SLEN > 0 specifies length of SADR field + /* Bit 4: Reserved. Shall be zero. */ + /* Bit 3: Source specifier where: */ + /* 0 = SNET, SLEN, and SADR absent */ + /* 1 = SNET, SLEN, and SADR present */ + /* SLEN = 0 Invalid */ + /* SLEN > 0 specifies length of SADR field */ if (src && src->net) npdu[1] |= BIT3; - // Bit 2: The value of this bit corresponds to the data_expecting_reply - // parameter in the N-UNITDATA primitives. - // 1 indicates that a BACnet-Confirmed-Request-PDU, - // a segment of a BACnet-ComplexACK-PDU, - // or a network layer message expecting a reply is present. - // 0 indicates that other than a BACnet-Confirmed-Request-PDU, - // a segment of a BACnet-ComplexACK-PDU, - // or a network layer message expecting a reply is present. + /* Bit 2: The value of this bit corresponds to the data_expecting_reply */ + /* parameter in the N-UNITDATA primitives. */ + /* 1 indicates that a BACnet-Confirmed-Request-PDU, */ + /* a segment of a BACnet-ComplexACK-PDU, */ + /* or a network layer message expecting a reply is present. */ + /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */ + /* a segment of a BACnet-ComplexACK-PDU, */ + /* or a network layer message expecting a reply is present. */ if (npdu_data->data_expecting_reply) npdu[1] |= BIT2; - // Bits 1,0: Network priority where: - // B'11' = Life Safety message - // B'10' = Critical Equipment message - // B'01' = Urgent message - // B'00' = Normal message + /* Bits 1,0: Network priority where: */ + /* B'11' = Life Safety message */ + /* B'10' = Critical Equipment message */ + /* B'01' = Urgent message */ + /* B'00' = Normal message */ npdu[1] |= (npdu_data->priority & 0x03); len = 2; if (dest && dest->net) { len += encode_unsigned16(&npdu[len], dest->net); npdu[len++] = dest->len; - // DLEN = 0 denotes broadcast MAC DADR and DADR field is absent - // DLEN > 0 specifies length of DADR field + /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */ + /* DLEN > 0 specifies length of DADR field */ if (dest->len) { for (i = 0; i < dest->len; i++) { npdu[len++] = dest->adr[i]; @@ -105,17 +105,17 @@ int npdu_encode_raw(uint8_t * npdu, if (src && src->net) { len += encode_unsigned16(&npdu[len], src->net); npdu[len++] = src->len; - // SLEN = 0 denotes broadcast MAC SADR and SADR field is absent - // SLEN > 0 specifies length of SADR field + /* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */ + /* SLEN > 0 specifies length of SADR field */ if (src->len) { for (i = 0; i < src->len; i++) { npdu[len++] = src->adr[i]; } } } - // The Hop Count field shall be present only if the message is - // destined for a remote network, i.e., if DNET is present. - // This is a one-octet field that is initialized to a value of 0xff. + /* The Hop Count field shall be present only if the message is */ + /* destined for a remote network, i.e., if DNET is present. */ + /* This is a one-octet field that is initialized to a value of 0xff. */ if (dest && dest->net) { npdu[len] = 0xFF; len++; @@ -123,8 +123,8 @@ int npdu_encode_raw(uint8_t * npdu, if (npdu_data->network_layer_message) { npdu[len] = npdu_data->network_message_type; len++; - // Message Type field contains a value in the range 0x80 - 0xFF, - // then a Vendor ID field shall be present + /* Message Type field contains a value in the range 0x80 - 0xFF, */ + /* then a Vendor ID field shall be present */ if (npdu_data->network_message_type >= 0x80) len += encode_unsigned16(&npdu[len], npdu_data->vendor_id); } @@ -133,19 +133,19 @@ int npdu_encode_raw(uint8_t * npdu, return len; } -// encode the NPDU portion of the packet for an APDU -// This function does not handle the network messages, just APDUs. -int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, // true for confirmed messages +/* encode the NPDU portion of the packet for an APDU */ +/* This function does not handle the network messages, just APDUs. */ +int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority) { BACNET_NPDU_DATA npdu_data = { 0 }; npdu_data.data_expecting_reply = data_expecting_reply; - 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; - // call the real function... + /* call the real function... */ return npdu_encode_raw(npdu, dest, src, &npdu_data); } @@ -153,50 +153,50 @@ int npdu_decode(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) { - int len = 0; // return value - number of octets loaded in this function - int i = 0; // counter + int len = 0; /* return value - number of octets loaded in this function */ + int i = 0; /* counter */ uint16_t src_net = 0; uint16_t dest_net = 0; uint8_t address_len = 0; uint8_t mac_octet = 0; if (npdu && npdu_data) { - // Protocol Version + /* Protocol Version */ npdu_data->protocol_version = npdu[0]; - // control octet - // Bit 7: 1 indicates that the NSDU conveys a network layer message. - // Message Type field is present. - // 0 indicates that the NSDU contains a BACnet APDU. - // Message Type field is absent. + /* control octet */ + /* Bit 7: 1 indicates that the NSDU conveys a network layer message. */ + /* Message Type field is present. */ + /* 0 indicates that the NSDU contains a BACnet APDU. */ + /* Message Type field is absent. */ npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false; - //Bit 6: Reserved. Shall be zero. - // Bit 4: Reserved. Shall be zero. - // Bit 2: The value of this bit corresponds to the data_expecting_reply - // parameter in the N-UNITDATA primitives. - // 1 indicates that a BACnet-Confirmed-Request-PDU, - // a segment of a BACnet-ComplexACK-PDU, - // or a network layer message expecting a reply is present. - // 0 indicates that other than a BACnet-Confirmed-Request-PDU, - // a segment of a BACnet-ComplexACK-PDU, - // or a network layer message expecting a reply is present. + /*Bit 6: Reserved. Shall be zero. */ + /* Bit 4: Reserved. Shall be zero. */ + /* Bit 2: The value of this bit corresponds to the data_expecting_reply */ + /* parameter in the N-UNITDATA primitives. */ + /* 1 indicates that a BACnet-Confirmed-Request-PDU, */ + /* a segment of a BACnet-ComplexACK-PDU, */ + /* or a network layer message expecting a reply is present. */ + /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */ + /* a segment of a BACnet-ComplexACK-PDU, */ + /* or a network layer message expecting a reply is present. */ npdu_data->data_expecting_reply = (npdu[1] & BIT2) ? true : false; - // Bits 1,0: Network priority where: - // B'11' = Life Safety message - // B'10' = Critical Equipment message - // B'01' = Urgent message - // B'00' = Normal message + /* Bits 1,0: Network priority where: */ + /* B'11' = Life Safety message */ + /* B'10' = Critical Equipment message */ + /* B'01' = Urgent message */ + /* B'00' = Normal message */ npdu_data->priority = npdu[1] & 0x03; - // set the offset to where the optional stuff starts + /* set the offset to where the optional stuff starts */ len = 2; - //Bit 5: Destination specifier where: - // 0 = DNET, DLEN, DADR, and Hop Count absent - // 1 = DNET, DLEN, and Hop Count present - // DLEN = 0 denotes broadcast MAC DADR and DADR field is absent - // DLEN > 0 specifies length of DADR field + /*Bit 5: Destination specifier where: */ + /* 0 = DNET, DLEN, DADR, and Hop Count absent */ + /* 1 = DNET, DLEN, and Hop Count present */ + /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */ + /* DLEN > 0 specifies length of DADR field */ if (npdu[1] & BIT5) { len += decode_unsigned16(&npdu[len], &dest_net); - // DLEN = 0 denotes broadcast MAC DADR and DADR field is absent - // DLEN > 0 specifies length of DADR field + /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */ + /* DLEN > 0 specifies length of DADR field */ address_len = npdu[len++]; if (dest) { dest->net = dest_net; @@ -210,7 +210,7 @@ int npdu_decode(uint8_t * npdu, } } } - // zero out the destination address + /* zero out the destination address */ else if (dest) { dest->net = 0; dest->len = 0; @@ -218,15 +218,15 @@ int npdu_decode(uint8_t * npdu, dest->adr[i] = 0; } } - // Bit 3: Source specifier where: - // 0 = SNET, SLEN, and SADR absent - // 1 = SNET, SLEN, and SADR present - // SLEN = 0 Invalid - // SLEN > 0 specifies length of SADR field + /* Bit 3: Source specifier where: */ + /* 0 = SNET, SLEN, and SADR absent */ + /* 1 = SNET, SLEN, and SADR present */ + /* SLEN = 0 Invalid */ + /* SLEN > 0 specifies length of SADR field */ if (npdu[1] & BIT3) { len += decode_unsigned16(&npdu[len], &src_net); - // SLEN = 0 denotes broadcast MAC SADR and SADR field is absent - // SLEN > 0 specifies length of SADR field + /* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */ + /* SLEN > 0 specifies length of SADR field */ address_len = npdu[len++]; if (src) { src->net = src_net; @@ -246,19 +246,19 @@ int npdu_decode(uint8_t * npdu, src->adr[i] = 0; } } - // The Hop Count field shall be present only if the message is - // destined for a remote network, i.e., if DNET is present. - // This is a one-octet field that is initialized to a value of 0xff. + /* The Hop Count field shall be present only if the message is */ + /* destined for a remote network, i.e., if DNET is present. */ + /* This is a one-octet field that is initialized to a value of 0xff. */ if (dest_net) npdu_data->hop_count = npdu[len++]; else npdu_data->hop_count = 0; - // Indicates that the NSDU conveys a network layer message. - // Message Type field is present. + /* Indicates that the NSDU conveys a network layer message. */ + /* Message Type field is present. */ if (npdu_data->network_layer_message) { npdu_data->network_message_type = npdu[len++]; - // Message Type field contains a value in the range 0x80 - 0xFF, - // then a Vendor ID field shall be present + /* Message Type field contains a value in the range 0x80 - 0xFF, */ + /* then a Vendor ID field shall be present */ if (npdu_data->network_message_type >= 0x80) len += decode_unsigned16(&npdu[len], &npdu_data->vendor_id); @@ -269,20 +269,20 @@ int npdu_decode(uint8_t * npdu, return len; } -void npdu_handler(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t pdu_len) // length PDU -{ +void npdu_handler(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t pdu_len) +{ /* length PDU */ int apdu_offset = 0; BACNET_ADDRESS dest = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 }; - apdu_offset = npdu_decode(&pdu[0], // data to decode - &dest, // destination address - get the DNET/DLEN/DADR if in there - src, // source address - get the SNET/SLEN/SADR if in there - &npdu_data); // amount of data to decode + apdu_offset = npdu_decode(&pdu[0], /* data to decode */ + &dest, /* destination address - get the DNET/DLEN/DADR if in there */ + src, /* source address - get the SNET/SLEN/SADR if in there */ + &npdu_data); /* amount of data to decode */ if (npdu_data.network_layer_message) { - //FIXME: network layer message received! Handle it! + /*FIXME: network layer message received! Handle it! */ } else { apdu_handler(src, npdu_data.data_expecting_reply, @@ -306,21 +306,21 @@ void testNPDU2(Test * pTest) BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_src = { 0 }; int len = 0; - bool data_expecting_reply = false; // true for confirmed messages + bool data_expecting_reply = false; /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; // counter + int i = 0; /* counter */ int npdu_len = 0; - bool network_layer_message = false; // false if APDU - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional - uint16_t vendor_id = 0; // optional, if net message type is > 0x80 + bool network_layer_message = false; /* false if APDU */ + BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ + uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ - // mac_len = 0 if global address + /* mac_len = 0 if global address */ dest.mac_len = 6; for (i = 0; i < dest.mac_len; i++) { dest.mac[i] = i; } - // DNET,DLEN,DADR + /* DNET,DLEN,DADR */ dest.net = 1; dest.len = 6; for (i = 0; i < dest.len; i++) { @@ -330,7 +330,7 @@ void testNPDU2(Test * pTest) for (i = 0; i < src.mac_len; i++) { src.mac[i] = 0x80; } - // SNET,SLEN,SADR + /* SNET,SLEN,SADR */ src.net = 2; src.len = 1; for (i = 0; i < src.len; i++) { @@ -339,7 +339,7 @@ void testNPDU2(Test * pTest) len = npdu_encode_apdu(&pdu[0], &dest, &src, data_expecting_reply, priority); ct_test(pTest, len != 0); - // can we get the info back? + /* can we get the info back? */ npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); @@ -348,13 +348,13 @@ void testNPDU2(Test * pTest) ct_test(pTest, npdu_data.network_message_type == network_message_type); ct_test(pTest, npdu_data.vendor_id == vendor_id); ct_test(pTest, npdu_data.priority == priority); - // DNET,DLEN,DADR + /* DNET,DLEN,DADR */ ct_test(pTest, npdu_dest.net == dest.net); ct_test(pTest, npdu_dest.len == dest.len); for (i = 0; i < dest.len; i++) { ct_test(pTest, npdu_dest.adr[i] == dest.adr[i]); } - // SNET,SLEN,SADR + /* SNET,SLEN,SADR */ ct_test(pTest, npdu_src.net == src.net); ct_test(pTest, npdu_src.len == src.len); for (i = 0; i < src.len; i++) { @@ -370,21 +370,21 @@ void testNPDU1(Test * pTest) BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_src = { 0 }; int len = 0; - bool data_expecting_reply = false; // true for confirmed messages + bool data_expecting_reply = false; /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; // counter + int i = 0; /* counter */ int npdu_len = 0; - bool network_layer_message = false; // false if APDU - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional - uint16_t vendor_id = 0; // optional, if net message type is > 0x80 + bool network_layer_message = false; /* false if APDU */ + BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ + uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ - // mac_len = 0 if global address + /* mac_len = 0 if global address */ dest.mac_len = 0; for (i = 0; i < MAX_MAC_LEN; i++) { dest.mac[i] = 0; } - // DNET,DLEN,DADR + /* DNET,DLEN,DADR */ dest.net = 0; dest.len = 0; for (i = 0; i < MAX_MAC_LEN; i++) { @@ -394,7 +394,7 @@ void testNPDU1(Test * pTest) for (i = 0; i < MAX_MAC_LEN; i++) { src.mac[i] = 0; } - // SNET,SLEN,SADR + /* SNET,SLEN,SADR */ src.net = 0; src.len = 0; for (i = 0; i < MAX_MAC_LEN; i++) { @@ -403,7 +403,7 @@ void testNPDU1(Test * pTest) len = npdu_encode_apdu(&pdu[0], &dest, &src, data_expecting_reply, priority); ct_test(pTest, len != 0); - // can we get the info back? + /* can we get the info back? */ npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data); ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); @@ -417,7 +417,7 @@ void testNPDU1(Test * pTest) } #ifdef TEST_NPDU -// dummy stub for testing +/* dummy stub for testing */ void tsm_free_invoke_id(uint8_t invokeID) { (void) invokeID; diff --git a/bacnet-stack/npdu.h b/bacnet-stack/npdu.h index 41549d07..66d304be 100644 --- a/bacnet-stack/npdu.h +++ b/bacnet-stack/npdu.h @@ -39,16 +39,16 @@ #include "bacdef.h" #include "bacenum.h" -// an NPDU structure keeps the parameter stack to a minimum +/* an NPDU structure keeps the parameter stack to a minimum */ typedef struct bacnet_npdu_data_t { uint8_t protocol_version; - // parts of the control octet: - bool data_expecting_reply; // true for confirmed messages - bool network_layer_message; // false if APDU + /* parts of the control octet: */ + bool data_expecting_reply; /* true for confirmed messages */ + bool network_layer_message; /* false if APDU */ BACNET_MESSAGE_PRIORITY priority; - // optional network message info - BACNET_NETWORK_MESSAGE_TYPE network_message_type; // optional - uint16_t vendor_id; // optional, if net message type is > 0x80 + /* optional network message info */ + BACNET_NETWORK_MESSAGE_TYPE network_message_type; /* optional */ + uint16_t vendor_id; /* optional, if net message type is > 0x80 */ uint8_t hop_count; } BACNET_NPDU_DATA; @@ -60,17 +60,17 @@ extern "C" { int npdu_encode_raw(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); -// encode the NPDU portion of the packet for an APDU - int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, // true for confirmed messages +/* encode the NPDU portion of the packet for an APDU */ + int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */ BACNET_MESSAGE_PRIORITY priority); int npdu_decode(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); - void npdu_handler(BACNET_ADDRESS * src, // source address - uint8_t * pdu, // PDU data - uint16_t pdu_len); // length PDU + void npdu_handler(BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t pdu_len); /* length PDU */ #ifdef __cplusplus } diff --git a/bacnet-stack/rd.c b/bacnet-stack/rd.c index 9746a592..6b1784a9 100644 --- a/bacnet-stack/rd.c +++ b/bacnet-stack/rd.c @@ -110,10 +110,10 @@ int rd_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) return -1; diff --git a/bacnet-stack/rd.h b/bacnet-stack/rd.h index 735937f6..415e65f4 100644 --- a/bacnet-stack/rd.h +++ b/bacnet-stack/rd.h @@ -41,13 +41,13 @@ extern "C" { #endif /* __cplusplus */ -// encode service +/* encode service */ int rd_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_REINITIALIZED_STATE state, BACNET_CHARACTER_STRING * password); -// decode the service request only +/* decode the service request only */ int rd_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_REINITIALIZED_STATE * state, diff --git a/bacnet-stack/reject.c b/bacnet-stack/reject.c index b466756a..91fd716c 100644 --- a/bacnet-stack/reject.c +++ b/bacnet-stack/reject.c @@ -36,11 +36,11 @@ #include "bacdcode.h" #include "bacdef.h" -// encode service +/* encode service */ int reject_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint8_t reject_reason) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_REJECT; @@ -52,7 +52,7 @@ int reject_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int reject_decode_service_request(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason) { @@ -68,7 +68,7 @@ int reject_decode_service_request(uint8_t * apdu, return len; } -// decode the whole APDU - mainly used for unit testing +/* decode the whole APDU - mainly used for unit testing */ int reject_decode_apdu(uint8_t * apdu, unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason) { @@ -76,7 +76,7 @@ int reject_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu_len) { if (apdu[0] != PDU_TYPE_REJECT) return -1; @@ -114,24 +114,24 @@ void testReject(Test * pTest) ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_reject_reason == reject_reason); - // change type to get negative response + /* change type to get negative response */ apdu[0] = PDU_TYPE_ABORT; len = reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_reject_reason); ct_test(pTest, len == -1); - // test NULL APDU + /* test NULL APDU */ len = reject_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_reject_reason); ct_test(pTest, len == -1); - // force a zero length + /* force a zero length */ len = reject_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_reject_reason); ct_test(pTest, len == 0); - // check them all... + /* check them all... */ for (invoke_id = 0; invoke_id < 255; invoke_id++) { for (reject_reason = 0; reject_reason < 255; reject_reason++) { len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason); diff --git a/bacnet-stack/ringbuf.c b/bacnet-stack/ringbuf.c index c1b64bed..56858d5d 100644 --- a/bacnet-stack/ringbuf.c +++ b/bacnet-stack/ringbuf.c @@ -70,7 +70,7 @@ char *Ringbuf_Get_Front(RING_BUFFER const *b) *****************************************************************************/ char *Ringbuf_Pop_Front(RING_BUFFER * b) { - char *data = NULL; // return value + char *data = NULL; /* return value */ if (b->count) { data = &(b->data[b->head * b->element_size]); @@ -89,16 +89,16 @@ char *Ringbuf_Pop_Front(RING_BUFFER * b) * ALGORITHM: none * NOTES: none *****************************************************************************/ -bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure - char *data_element) // one element to add to the ring -{ - bool status = false; // return value - unsigned offset = 0; // offset into array of data - char *ring_data = NULL; // used to help point ring data - unsigned i; // loop counter +bool Ringbuf_Put(RING_BUFFER * b, /* ring buffer structure */ + char *data_element) +{ /* one element to add to the ring */ + bool status = false; /* return value */ + unsigned offset = 0; /* offset into array of data */ + char *ring_data = NULL; /* used to help point ring data */ + unsigned i; /* loop counter */ if (b && data_element) { - // limit the amount of data that we accept + /* limit the amount of data that we accept */ if (b->count < b->element_count) { offset = b->head + b->count; if (offset >= b->element_count) @@ -121,11 +121,11 @@ bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure * ALGORITHM: none * NOTES: none *****************************************************************************/ -void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure - char *data, // data block or array of data - unsigned element_size, // size of one element in the data block - unsigned element_count) // number of elements in the data block -{ +void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */ + char *data, /* data block or array of data */ + unsigned element_size, /* size of one element in the data block */ + unsigned element_count) +{ /* number of elements in the data block */ b->head = 0; b->count = 0; b->data = data; @@ -141,7 +141,7 @@ void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure #include "ctest.h" -// test the FIFO +/* test the FIFO */ #define RING_BUFFER_DATA_SIZE 5 #define RING_BUFFER_SIZE 16 void testRingBuf(Test * pTest) @@ -179,7 +179,7 @@ void testRingBuf(Test * pTest) } ct_test(pTest, Ringbuf_Empty(&test_buffer)); - // fill to max + /* fill to max */ for (index = 0; index < RING_BUFFER_SIZE; index++) { for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) { @@ -189,7 +189,7 @@ void testRingBuf(Test * pTest) ct_test(pTest, status == true); ct_test(pTest, !Ringbuf_Empty(&test_buffer)); } - // verify actions on full buffer + /* verify actions on full buffer */ for (index = 0; index < RING_BUFFER_SIZE; index++) { for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) { @@ -200,7 +200,7 @@ void testRingBuf(Test * pTest) ct_test(pTest, !Ringbuf_Empty(&test_buffer)); } - // check buffer full + /* check buffer full */ for (index = 0; index < RING_BUFFER_SIZE; index++) { test_data = Ringbuf_Get_Front(&test_buffer); for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; @@ -216,7 +216,7 @@ void testRingBuf(Test * pTest) } ct_test(pTest, Ringbuf_Empty(&test_buffer)); - // test the ring around the buffer + /* test the ring around the buffer */ for (index = 0; index < RING_BUFFER_SIZE; index++) { for (count = 1; count < 4; count++) { dummy = index * count; diff --git a/bacnet-stack/ringbuf.h b/bacnet-stack/ringbuf.h index 7631350b..6a6e4f72 100644 --- a/bacnet-stack/ringbuf.h +++ b/bacnet-stack/ringbuf.h @@ -43,11 +43,11 @@ #include struct ring_buffer_t { - char *data; // block of memory or array of data - unsigned element_size; // how many bytes for each chunk - unsigned element_count; // number of chunks of data - unsigned head; // first chunk of data - unsigned count; // number of chunks in use + char *data; /* block of memory or array of data */ + unsigned element_size; /* how many bytes for each chunk */ + unsigned element_count; /* number of chunks of data */ + unsigned head; /* first chunk of data */ + unsigned count; /* number of chunks in use */ }; typedef struct ring_buffer_t RING_BUFFER; @@ -58,12 +58,12 @@ extern "C" { bool Ringbuf_Empty(RING_BUFFER const *b); char *Ringbuf_Get_Front(RING_BUFFER const *b); char *Ringbuf_Pop_Front(RING_BUFFER * b); - bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure - char *data_element); // one element to add to the ring - void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure - char *data, // data block or array of data - unsigned element_size, // size of one element in the data block - unsigned element_count); // number of elements in the data block + bool Ringbuf_Put(RING_BUFFER * b, /* ring buffer structure */ + char *data_element); /* one element to add to the ring */ + void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */ + char *data, /* data block or array of data */ + unsigned element_size, /* size of one element in the data block */ + unsigned element_count); /* number of elements in the data block */ #ifdef __cplusplus } diff --git a/bacnet-stack/rp.c b/bacnet-stack/rp.c index 1c98d8ea..98549d7f 100644 --- a/bacnet-stack/rp.c +++ b/bacnet-stack/rp.c @@ -37,18 +37,18 @@ #include "bacdef.h" #include "rp.h" -// encode service +/* encode service */ int rp_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data) { - int len = 0; // length of each encoding - int apdu_len = 0; // total length of the apdu, return value + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; // service choice + apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 4; len = encode_context_object_id(&apdu[apdu_len], 0, data->object_type, data->object_instance); @@ -67,32 +67,32 @@ int rp_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int rp_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data) { unsigned len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - int type = 0; // for decoding - int property = 0; // for decoding - uint32_t array_value = 0; // for decoding + int type = 0; /* for decoding */ + int property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { - // Tag 0: Object ID + /* Tag 0: Object ID */ if (!decode_is_context_tag(&apdu[len++], 0)) return -1; len += decode_object_id(&apdu[len], &type, &data->object_instance); data->object_type = type; - // Tag 1: Property ID + /* Tag 1: Property ID */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); data->object_property = property; - // Tag 2: Optional Array Index + /* Tag 2: Optional Array Index */ if (len < apdu_len) { len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); @@ -118,10 +118,10 @@ int rp_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) return -1; @@ -138,25 +138,25 @@ int rp_decode_apdu(uint8_t * apdu, int rp_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data) { - int len = 0; // length of each encoding - int apdu_len = 0; // total length of the apdu, return value + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ apdu[1] = invoke_id; /* original invoke id from request */ - apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; // service choice + apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 3; - // service ack follows + /* service ack follows */ apdu_len += encode_context_object_id(&apdu[apdu_len], 0, data->object_type, data->object_instance); apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, data->object_property); - // context 2 array index is optional + /* context 2 array index is optional */ if (data->array_index != BACNET_ARRAY_ALL) { apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, data->array_index); } - // propertyValue + /* propertyValue */ apdu_len += encode_opening_tag(&apdu[apdu_len], 3); for (len = 0; len < data->application_data_len; len++) { apdu[apdu_len++] = data->application_data[len]; @@ -167,31 +167,31 @@ int rp_ack_encode_apdu(uint8_t * apdu, return apdu_len; } -int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length of the apdu +int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */ BACNET_READ_PROPERTY_DATA * data) { uint8_t tag_number = 0; 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 - uint32_t array_value = 0; // for decoding + int tag_len = 0; /* length of tag decode */ + int len = 0; /* total length of decodes */ + int object = 0, property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ - // FIXME: check apdu_len against the len during decode - // Tag 0: Object ID + /* FIXME: check apdu_len against the len during decode */ + /* Tag 0: Object ID */ if (!decode_is_context_tag(&apdu[0], 0)) return -1; len = 1; len += decode_object_id(&apdu[len], &object, &data->object_instance); data->object_type = object; - // Tag 1: Property ID + /* Tag 1: Property ID */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); data->object_property = property; - // Tag 2: Optional Array Index + /* Tag 2: Optional Array Index */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number == 2) { @@ -201,11 +201,11 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length } else data->array_index = BACNET_ARRAY_ALL; - // Tag 3: opening context tag */ - if (decode_is_opening_tag_number(&apdu[len], 3)) { - // a tag number of 3 is not extended so only one octet + /* Tag 3: opening context tag */ */ + if (decode_is_opening_tag_number(&apdu[len], 3)) { + /* a tag number of 3 is not extended so only one octet */ len++; - // don't decode the application tag number or its data here + /* don't decode the application tag number or its data here */ data->application_data = &apdu[len]; data->application_data_len = apdu_len - len - 1 /*closing tag */ ; } else @@ -214,7 +214,7 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length return len; } -int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, // total length of the apdu +int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */ uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data) { int len = 0; @@ -222,7 +222,7 @@ int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, // total length of the a if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; *invoke_id = apdu[1]; @@ -269,7 +269,7 @@ void testReadPropertyAck(Test * pTest) ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; - len = rp_ack_decode_apdu(&apdu[0], apdu_len, // total length of the apdu + len = rp_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */ &test_invoke_id, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); diff --git a/bacnet-stack/rp.h b/bacnet-stack/rp.h index 77cfa4d2..64fd5ad8 100644 --- a/bacnet-stack/rp.h +++ b/bacnet-stack/rp.h @@ -50,11 +50,11 @@ typedef struct BACnet_Read_Property_Data { extern "C" { #endif /* __cplusplus */ -// encode service +/* encode service */ int rp_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data); -// decode the service request only +/* decode the service request only */ int rp_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data); @@ -65,10 +65,10 @@ extern "C" { int rp_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data); - int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length of the apdu + int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */ BACNET_READ_PROPERTY_DATA * data); - int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, // total length of the apdu + int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */ uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data); diff --git a/bacnet-stack/rs485.h b/bacnet-stack/rs485.h index a3c0ae0b..0409e8f3 100644 --- a/bacnet-stack/rs485.h +++ b/bacnet-stack/rs485.h @@ -45,11 +45,11 @@ extern "C" { void RS485_Initialize(void); - void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port specific data - uint8_t * buffer, // frame to send (up to 501 bytes of data) - uint16_t nbytes); // number of bytes of data (up to 501) + void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ + uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ + uint16_t nbytes); /* number of bytes of data (up to 501) */ - void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port); // port specific data + void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port); /* port specific data */ void RS485_Process_Tx_Message(void); diff --git a/bacnet-stack/tsm.c b/bacnet-stack/tsm.c index d3bbcdac..6f765688 100644 --- a/bacnet-stack/tsm.c +++ b/bacnet-stack/tsm.c @@ -34,7 +34,7 @@ #include #include #include -#include // memmove() +#include /* memmove() */ #include "bits.h" #include "apdu.h" #include "bacdef.h" @@ -47,23 +47,23 @@ #include "handlers.h" #include "address.h" -// Transaction State Machine -// Really only needed for segmented messages -// and a little for sending confirmed messages -// If we are only a server and only initiate broadcasts, -// then we don't need a TSM layer. +/* Transaction State Machine */ +/* Really only needed for segmented messages */ +/* and a little for sending confirmed messages */ +/* If we are only a server and only initiate broadcasts, */ +/* then we don't need a TSM layer. */ -// FIXME: not coded for segmentation +/* FIXME: not coded for segmentation */ -// declare space for the TSM transactions, and set it up in the init. +/* declare space for the TSM transactions, and set it up in the init. */ /* table rules: an Invoke ID = 0 is an unused spot in the table */ static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = { {0} }; -// returns MAX_TSM_TRANSACTIONS if not found +/* returns MAX_TSM_TRANSACTIONS if not found */ static uint8_t tsm_find_invokeID_index(uint8_t invokeID) { - unsigned i = 0; // counter - uint8_t index = MAX_TSM_TRANSACTIONS; // return value + unsigned i = 0; /* counter */ + uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == invokeID) { @@ -77,8 +77,8 @@ static uint8_t tsm_find_invokeID_index(uint8_t invokeID) static uint8_t tsm_find_first_free_index(void) { - unsigned i = 0; // counter - uint8_t index = MAX_TSM_TRANSACTIONS; // return value + unsigned i = 0; /* counter */ + uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == 0) { @@ -92,12 +92,12 @@ static uint8_t tsm_find_first_free_index(void) bool tsm_transaction_available(void) { - bool status = false; // return value - unsigned i = 0; // counter + bool status = false; /* return value */ + unsigned i = 0; /* counter */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == 0) { - // one is available! + /* one is available! */ status = true; break; } @@ -108,13 +108,13 @@ bool tsm_transaction_available(void) uint8_t tsm_transaction_idle_count(void) { - uint8_t count = 0; // return value - unsigned i = 0; // counter + uint8_t count = 0; /* return value */ + unsigned i = 0; /* counter */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if ((TSM_List[i].InvokeID == 0) && (TSM_List[i].state == TSM_STATE_IDLE)) { - // one is available! + /* one is available! */ count++; } } @@ -127,7 +127,7 @@ uint8_t tsm_transaction_idle_count(void) returns 0 if none are available */ uint8_t tsm_next_free_invokeID(void) { - static uint8_t current_invokeID = 1; // incremented... + static uint8_t current_invokeID = 1; /* incremented... */ uint8_t index = 0; uint8_t invokeID = 0; bool found = false; @@ -145,7 +145,7 @@ uint8_t tsm_next_free_invokeID(void) TSM_List[index].RequestTimer = Device_APDU_Timeout(); /* update for the next call or check */ current_invokeID++; - // skip zero - we treat that internally as invalid or no free + /* skip zero - we treat that internally as invalid or no free */ if (current_invokeID == 0) current_invokeID = 1; } @@ -164,12 +164,12 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, if (invokeID) { index = tsm_find_invokeID_index(invokeID); if (index < MAX_TSM_TRANSACTIONS) { - // assign the transaction + /* assign the transaction */ TSM_List[index].state = TSM_STATE_AWAIT_CONFIRMATION; TSM_List[index].RetryCount = Device_Number_Of_APDU_Retries(); - // start the timer + /* start the timer */ TSM_List[index].RequestTimer = Device_APDU_Timeout(); - // copy the data + /* copy the data */ for (j = 0; j < pdu_len; j++) { TSM_List[index].pdu[j] = pdu[j]; } @@ -181,8 +181,8 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, return; } -// used to retrieve the transaction payload -// if we wanted to find out what we sent (i.e. when we get an ack) +/* used to retrieve the transaction payload */ +/* if we wanted to find out what we sent (i.e. when we get an ack) */ bool tsm_get_transaction_pdu(uint8_t invokeID, BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len) { @@ -192,11 +192,11 @@ bool tsm_get_transaction_pdu(uint8_t invokeID, if (invokeID) { index = tsm_find_invokeID_index(invokeID); - // how much checking is needed? state? dest match? just invokeID? + /* how much checking is needed? state? dest match? just invokeID? */ if (index < MAX_TSM_TRANSACTIONS) { - // FIXME: we may want to free the transaction so it doesn't timeout - // retrieve the transaction - // FIXME: bounds check the pdu_len? + /* FIXME: we may want to free the transaction so it doesn't timeout */ + /* retrieve the transaction */ + /* FIXME: bounds check the pdu_len? */ *pdu_len = TSM_List[index].pdu_len; for (j = 0; j < *pdu_len; j++) { pdu[j] = TSM_List[index].pdu[j]; @@ -212,7 +212,7 @@ bool tsm_get_transaction_pdu(uint8_t invokeID, /* called once a millisecond or slower */ void tsm_timer_milliseconds(uint16_t milliseconds) { - unsigned i = 0; // counter + unsigned i = 0; /* counter */ int bytes_sent = 0; for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { @@ -266,7 +266,7 @@ bool tsm_invoke_id_free(uint8_t invokeID) #include #include "ctest.h" -// flag to send an I-Am +/* flag to send an I-Am */ bool I_Am_Request = true; void testTSM(Test * pTest) diff --git a/bacnet-stack/tsm.h b/bacnet-stack/tsm.h index 14fa6325..018da8f7 100644 --- a/bacnet-stack/tsm.h +++ b/bacnet-stack/tsm.h @@ -50,37 +50,37 @@ typedef enum { TSM_STATE_SEGMENTED_CONFIRMATION } BACNET_TSM_STATE; -// 5.4.1 Variables And Parameters -// The following variables are defined for each instance of -// Transaction State Machine: +/* 5.4.1 Variables And Parameters */ +/* The following variables are defined for each instance of */ +/* Transaction State Machine: */ typedef struct BACnet_TSM_Data { - // used to count APDU retries + /* used to count APDU retries */ uint8_t RetryCount; - // used to count segment retries - //uint8_t SegmentRetryCount; - // used to control APDU retries and the acceptance of server replies - //bool SentAllSegments; - // stores the sequence number of the last segment received in order - //uint8_t LastSequenceNumber; - // stores the sequence number of the first segment of - // a sequence of segments that fill a window - //uint8_t InitialSequenceNumber; - // stores the current window size - //uint8_t ActualWindowSize; - // stores the window size proposed by the segment sender - //uint8_t ProposedWindowSize; - // used to perform timeout on PDU segments - //uint8_t SegmentTimer; - // used to perform timeout on Confirmed Requests - // in milliseconds + /* used to count segment retries */ + /*uint8_t SegmentRetryCount; */ + /* used to control APDU retries and the acceptance of server replies */ + /*bool SentAllSegments; */ + /* stores the sequence number of the last segment received in order */ + /*uint8_t LastSequenceNumber; */ + /* stores the sequence number of the first segment of */ + /* a sequence of segments that fill a window */ + /*uint8_t InitialSequenceNumber; */ + /* stores the current window size */ + /*uint8_t ActualWindowSize; */ + /* stores the window size proposed by the segment sender */ + /*uint8_t ProposedWindowSize; */ + /* used to perform timeout on PDU segments */ + /*uint8_t SegmentTimer; */ + /* used to perform timeout on Confirmed Requests */ + /* in milliseconds */ uint16_t RequestTimer; - // unique id + /* unique id */ uint8_t InvokeID; - // state that the TSM is in + /* state that the TSM is in */ BACNET_TSM_STATE state; - // the address we sent it to + /* the address we sent it to */ BACNET_ADDRESS dest; - // copy of the PDU, should we need to send it again + /* copy of the PDU, should we need to send it again */ uint8_t pdu[MAX_PDU]; unsigned pdu_len; } BACNET_TSM_DATA; @@ -92,14 +92,14 @@ extern "C" { bool tsm_transaction_available(void); uint8_t tsm_transaction_idle_count(void); void tsm_timer_milliseconds(uint16_t milliseconds); -// free the invoke ID when the reply comes back +/* free the invoke ID when the reply comes back */ void tsm_free_invoke_id(uint8_t invokeID); -// use these in tandem +/* use these in tandem */ uint8_t tsm_next_free_invokeID(void); -// returns the same invoke ID that was given +/* returns the same invoke ID that was given */ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t pdu_len); -// returns true if transaction is found +/* returns true if transaction is found */ bool tsm_get_transaction_pdu(uint8_t invokeID, BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len); diff --git a/bacnet-stack/whohas.c b/bacnet-stack/whohas.c index af5b6294..2dfcd82c 100644 --- a/bacnet-stack/whohas.c +++ b/bacnet-stack/whohas.c @@ -41,14 +41,14 @@ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data) { - int len = 0; // length of each encoding - int apdu_len = 0; // total length of the apdu, return value + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_WHO_HAS; // service choice + apdu[1] = SERVICE_UNCONFIRMED_WHO_HAS; /* service choice */ apdu_len = 2; - // optional limits - must be used as a pair + /* optional limits - must be used as a pair */ if ((data->low_limit >= 0) && (data->low_limit <= BACNET_MAX_INSTANCE) && (data->high_limit >= 0) @@ -77,7 +77,7 @@ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data) return apdu_len; } -// decode the service request only +/* decode the service request only */ int whohas_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_WHO_HAS_DATA * data) { @@ -144,12 +144,12 @@ int whohas_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) return -1; if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) return -1; - // optional limits - must be used as a pair + /* optional limits - must be used as a pair */ if (apdu_len > 2) { len = whohas_decode_service_request(&apdu[2], apdu_len - 2, data); } diff --git a/bacnet-stack/whohas.h b/bacnet-stack/whohas.h index 22f81e35..c51e2312 100644 --- a/bacnet-stack/whohas.h +++ b/bacnet-stack/whohas.h @@ -52,7 +52,7 @@ typedef struct BACnet_Who_Has_Data { extern "C" { #endif /* __cplusplus */ -// encode service - use -1 for limit if you want unlimited +/* encode service - use -1 for limit if you want unlimited */ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data); int whohas_decode_service_request(uint8_t * apdu, diff --git a/bacnet-stack/whois.c b/bacnet-stack/whois.c index 9ae5ff19..6016ccf8 100644 --- a/bacnet-stack/whois.c +++ b/bacnet-stack/whois.c @@ -36,18 +36,18 @@ #include "bacdcode.h" #include "bacdef.h" -// encode I-Am service - use -1 for limit if you want unlimited +/* encode I-Am service - use -1 for limit if you want unlimited */ int whois_encode_apdu(uint8_t * apdu, int32_t low_limit, int32_t high_limit) { - int len = 0; // length of each encoding - int apdu_len = 0; // total length of the apdu, return value + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_WHO_IS; // service choice + apdu[1] = SERVICE_UNCONFIRMED_WHO_IS; /* service choice */ apdu_len = 2; - // optional limits - must be used as a pair + /* optional limits - must be used as a pair */ if ((low_limit >= 0) && (low_limit <= BACNET_MAX_INSTANCE) && (high_limit >= 0) && (high_limit <= BACNET_MAX_INSTANCE)) { len = encode_context_unsigned(&apdu[apdu_len], 0, low_limit); @@ -60,7 +60,7 @@ int whois_encode_apdu(uint8_t * apdu, return apdu_len; } -// decode the service request only +/* decode the service request only */ int whois_decode_service_request(uint8_t * apdu, unsigned apdu_len, int32_t * pLow_limit, int32_t * pHigh_limit) { @@ -69,7 +69,7 @@ int whois_decode_service_request(uint8_t * apdu, uint32_t len_value = 0; uint32_t decoded_value = 0; - // optional limits - must be used as a pair + /* optional limits - must be used as a pair */ if (apdu_len) { len += decode_tag_number_and_value(&apdu[len], &tag_number, @@ -103,12 +103,12 @@ int whois_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) return -1; if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) return -1; - // optional limits - must be used as a pair + /* optional limits - must be used as a pair */ if (apdu_len > 2) { len = whois_decode_service_request(&apdu[2], apdu_len - 2, pLow_limit, pHigh_limit); diff --git a/bacnet-stack/whois.h b/bacnet-stack/whois.h index d309d6ed..d5459f51 100644 --- a/bacnet-stack/whois.h +++ b/bacnet-stack/whois.h @@ -41,7 +41,7 @@ extern "C" { #endif /* __cplusplus */ -// encode service - use -1 for limit if you want unlimited +/* encode service - use -1 for limit if you want unlimited */ int whois_encode_apdu(uint8_t * apdu, int32_t low_limit, int32_t high_limit); diff --git a/bacnet-stack/wp.c b/bacnet-stack/wp.c index c70ed161..48dba51f 100644 --- a/bacnet-stack/wp.c +++ b/bacnet-stack/wp.c @@ -38,18 +38,18 @@ #include "device.h" #include "wp.h" -// encode service +/* encode service */ int wp_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_WRITE_PROPERTY_DATA * data) { - int apdu_len = 0; // total length of the apdu, return value + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_WRITE_PROPERTY; // service choice + apdu[3] = SERVICE_CONFIRMED_WRITE_PROPERTY; /* service choice */ apdu_len = 4; apdu_len += encode_context_object_id(&apdu[apdu_len], 0, data->object_type, data->object_instance); @@ -59,12 +59,12 @@ int wp_encode_apdu(uint8_t * apdu, if (data->array_index != BACNET_ARRAY_ALL) apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, data->array_index); - // propertyValue + /* propertyValue */ apdu_len += encode_opening_tag(&apdu[apdu_len], 3); apdu_len += bacapp_encode_application_data(&apdu[apdu_len], &data->value); apdu_len += encode_closing_tag(&apdu[apdu_len], 3); - // optional priority - 0 if not set, 1..16 if set + /* optional priority - 0 if not set, 1..16 if set */ if (data->priority != BACNET_NO_PRIORITY) apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, data->priority); @@ -83,26 +83,26 @@ int wp_decode_service_request(uint8_t * apdu, int tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - int type = 0; // for decoding - int property = 0; // for decoding + int type = 0; /* for decoding */ + int property = 0; /* for decoding */ uint32_t unsigned_value = 0; - // check for value pointers + /* check for value pointers */ if (apdu_len && data) { - // Tag 0: Object ID + /* Tag 0: Object ID */ if (!decode_is_context_tag(&apdu[len++], 0)) return -1; len += decode_object_id(&apdu[len], &type, &data->object_instance); data->object_type = type; - // Tag 1: Property ID + /* Tag 1: Property ID */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); data->object_property = property; - // Tag 2: Optional Array Index - // note: decode without incrementing len so we can check for opening tag + /* Tag 2: Optional Array Index */ + /* note: decode without incrementing len so we can check for opening tag */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number == 2) { @@ -112,10 +112,10 @@ int wp_decode_service_request(uint8_t * apdu, data->array_index = unsigned_value; } else data->array_index = BACNET_ARRAY_ALL; - // Tag 3: opening context tag */ - if (!decode_is_opening_tag_number(&apdu[len], 3)) + /* Tag 3: opening context tag */ */ + if (!decode_is_opening_tag_number(&apdu[len], 3)) return -1; - // a tag number of 3 is not extended so only one octet + /* a tag number of 3 is not extended so only one octet */ len++; len += bacapp_decode_application_data(&apdu[len], apdu_len - len, &data->value); @@ -123,9 +123,9 @@ int wp_decode_service_request(uint8_t * apdu, /* FIXME: there might be more than one data element in here! */ if (!decode_is_closing_tag_number(&apdu[len], 3)) return -1; - // a tag number of 3 is not extended so only one octet + /* a tag number of 3 is not extended so only one octet */ len++; - // Tag 4: optional Priority - assumed MAX if not explicitly set + /* Tag 4: optional Priority - assumed MAX if not explicitly set */ data->priority = BACNET_MAX_PRIORITY; if ((unsigned) len < apdu_len) { tag_len = decode_tag_number_and_value(&apdu[len], @@ -156,10 +156,10 @@ int wp_decode_apdu(uint8_t * apdu, if (!apdu) return -1; - // optional checking - most likely was already done prior to this call + /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; - // apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_WRITE_PROPERTY) return -1; diff --git a/bacnet-stack/wp.h b/bacnet-stack/wp.h index 2a30fd2f..141da5ad 100644 --- a/bacnet-stack/wp.h +++ b/bacnet-stack/wp.h @@ -43,20 +43,20 @@ typedef struct BACnet_Write_Property_Data { BACNET_OBJECT_TYPE object_type; uint32_t object_instance; BACNET_PROPERTY_ID object_property; - int32_t array_index; // use BACNET_ARRAY_ALL when not setting + int32_t array_index; /* use BACNET_ARRAY_ALL when not setting */ BACNET_APPLICATION_DATA_VALUE value; - uint8_t priority; // use 0 if not setting the priority + uint8_t priority; /* use 0 if not setting the priority */ } BACNET_WRITE_PROPERTY_DATA; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -// encode service +/* encode service */ int wp_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_WRITE_PROPERTY_DATA * data); -// decode the service request only +/* decode the service request only */ int wp_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_WRITE_PROPERTY_DATA * data);