Changed all the C++ comments to C comments using comment.sh script.

This commit is contained in:
skarg
2006-02-19 01:32:09 +00:00
parent c80d26a894
commit dee63d45bc
76 changed files with 1856 additions and 1856 deletions
+9 -9
View File
@@ -36,11 +36,11 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "bacdef.h" #include "bacdef.h"
// encode service /* encode service */
int abort_encode_apdu(uint8_t * apdu, int abort_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, uint8_t abort_reason) 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) { if (apdu) {
apdu[0] = PDU_TYPE_ABORT; apdu[0] = PDU_TYPE_ABORT;
@@ -52,7 +52,7 @@ int abort_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int abort_decode_service_request(uint8_t * apdu, int abort_decode_service_request(uint8_t * apdu,
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason) 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; 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, int abort_decode_apdu(uint8_t * apdu,
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason) unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason)
{ {
@@ -76,7 +76,7 @@ int abort_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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_len) {
if (apdu[0] != PDU_TYPE_ABORT) if (apdu[0] != PDU_TYPE_ABORT)
return -1; return -1;
@@ -114,24 +114,24 @@ void testAbort(Test * pTest)
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason); 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; apdu[0] = PDU_TYPE_REJECT;
len = abort_decode_apdu(&apdu[0], len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason); apdu_len, &test_invoke_id, &test_abort_reason);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// test NULL APDU /* test NULL APDU */
len = abort_decode_apdu(NULL, len = abort_decode_apdu(NULL,
apdu_len, &test_invoke_id, &test_abort_reason); apdu_len, &test_invoke_id, &test_abort_reason);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// force a zero length /* force a zero length */
len = abort_decode_apdu(&apdu[0], len = abort_decode_apdu(&apdu[0],
0, &test_invoke_id, &test_abort_reason); 0, &test_invoke_id, &test_abort_reason);
ct_test(pTest, len == 0); ct_test(pTest, len == 0);
// check them all... /* check them all... */
for (invoke_id = 0; invoke_id < 255; invoke_id++) { for (invoke_id = 0; invoke_id < 255; invoke_id++) {
for (abort_reason = 0; abort_reason < 255; abort_reason++) { for (abort_reason = 0; abort_reason < 255; abort_reason++) {
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason); len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason);
+20 -20
View File
@@ -40,9 +40,9 @@
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
// This module is used to handle the address binding that /* This module is used to handle the address binding that */
// occurs in BACnet. A device id is bound to a MAC address. /* 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 /* The normal method is using Who-Is, and using the data from I-Am */
static struct Address_Cache_Entry { static struct Address_Cache_Entry {
bool valid; bool valid;
@@ -54,7 +54,7 @@ static struct Address_Cache_Entry {
void address_copy(BACNET_ADDRESS * dest, BACNET_ADDRESS * src) void address_copy(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
{ {
unsigned i = 0; // counter unsigned i = 0; /* counter */
if (dest && src) { if (dest && src) {
for (i = 0; i < MAX_MAC_LEN; i++) { 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 *max_apdu, BACNET_ADDRESS * src)
{ {
unsigned i; unsigned i;
bool found = false; // return value bool found = false; /* return value */
for (i = 0; i < MAX_ADDRESS_CACHE; i++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (Address_Cache[i].valid && if (Address_Cache[i].valid &&
@@ -122,9 +122,9 @@ void address_add(uint32_t device_id,
unsigned max_apdu, BACNET_ADDRESS * src) unsigned max_apdu, BACNET_ADDRESS * src)
{ {
unsigned i; 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++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (Address_Cache[i].valid && if (Address_Cache[i].valid &&
(Address_Cache[i].device_id == device_id)) { (Address_Cache[i].device_id == device_id)) {
@@ -134,7 +134,7 @@ void address_add(uint32_t device_id,
break; break;
} }
} }
// new device /* new device */
if (!found) { if (!found) {
for (i = 0; i < MAX_ADDRESS_CACHE; i++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (!Address_Cache[i].valid) { if (!Address_Cache[i].valid) {
@@ -150,15 +150,15 @@ void address_add(uint32_t device_id,
return; return;
} }
// returns true if device is already bound /* returns true if device is already bound */
// also returns the address and max apdu if already bound /* also returns the address and max apdu if already bound */
bool address_bind_request(uint32_t device_id, bool address_bind_request(uint32_t device_id,
unsigned *max_apdu, BACNET_ADDRESS * src) unsigned *max_apdu, BACNET_ADDRESS * src)
{ {
unsigned i; 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++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (Address_Cache[i].valid && if (Address_Cache[i].valid &&
(Address_Cache[i].device_id == device_id)) { (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; *max_apdu = Address_Cache[i].max_apdu;
break; 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 && else if (Address_Cache[i].bind_request &&
(Address_Cache[i].device_id == device_id)) { (Address_Cache[i].device_id == device_id)) {
return found; return found;
@@ -179,7 +179,7 @@ bool address_bind_request(uint32_t device_id,
if (!(Address_Cache[i].bind_request || Address_Cache[i].valid)) { if (!(Address_Cache[i].bind_request || Address_Cache[i].valid)) {
Address_Cache[i].bind_request = true; Address_Cache[i].bind_request = true;
Address_Cache[i].device_id = device_id; 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; break;
} }
} }
@@ -192,9 +192,9 @@ void address_add_binding(uint32_t device_id,
unsigned max_apdu, BACNET_ADDRESS * src) unsigned max_apdu, BACNET_ADDRESS * src)
{ {
unsigned i; 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++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (Address_Cache[i].valid && if (Address_Cache[i].valid &&
(Address_Cache[i].device_id == device_id)) { (Address_Cache[i].device_id == device_id)) {
@@ -204,7 +204,7 @@ void address_add_binding(uint32_t device_id,
break; break;
} }
} }
// add new device - but only if bind requested /* add new device - but only if bind requested */
if (!found) { if (!found) {
for (i = 0; i < MAX_ADDRESS_CACHE; i++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (!Address_Cache[i].valid && Address_Cache[i].bind_request) { 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, bool address_get_by_index(unsigned index,
uint32_t * device_id, unsigned *max_apdu, BACNET_ADDRESS * src) 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 (index < MAX_ADDRESS_CACHE) {
if (Address_Cache[index].valid) { if (Address_Cache[index].valid) {
@@ -241,7 +241,7 @@ bool address_get_by_index(unsigned index,
unsigned address_count(void) unsigned address_count(void)
{ {
unsigned i; unsigned i;
unsigned count = 0; // return value unsigned count = 0; /* return value */
for (i = 0; i < MAX_ADDRESS_CACHE; i++) { for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if (Address_Cache[i].valid) if (Address_Cache[i].valid)
@@ -255,7 +255,7 @@ bool address_match(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
{ {
unsigned i; unsigned i;
unsigned max_len; unsigned max_len;
bool match = true; // return value bool match = true; /* return value */
if (dest->mac_len != src->mac_len) if (dest->mac_len != src->mac_len)
match = false; match = false;
+30 -30
View File
@@ -93,8 +93,8 @@ static BACNET_SERVICES_SUPPORTED
SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION
}; };
// Confirmed Function Handlers /* Confirmed Function Handlers */
// If they are not set, they are handled by a reject message /* If they are not set, they are handled by a reject message */
static confirmed_function Confirmed_Function[MAX_BACNET_CONFIRMED_SERVICE]; static confirmed_function Confirmed_Function[MAX_BACNET_CONFIRMED_SERVICE];
void apdu_set_confirmed_handler(BACNET_CONFIRMED_SERVICE service_choice, 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; return status;
} }
// Allow the APDU handler to automatically reject /* Allow the APDU handler to automatically reject */
static confirmed_function Unrecognized_Service_Handler; static confirmed_function Unrecognized_Service_Handler;
void apdu_set_unrecognized_service_handler_handler(confirmed_function 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; Unrecognized_Service_Handler = pFunction;
} }
// Unconfirmed Function Handlers /* Unconfirmed Function Handlers */
// If they are not set, they are not handled /* If they are not set, they are not handled */
static unconfirmed_function static unconfirmed_function
Unconfirmed_Function[MAX_BACNET_UNCONFIRMED_SERVICE] = { Unconfirmed_Function[MAX_BACNET_UNCONFIRMED_SERVICE] = {
NULL NULL
@@ -180,7 +180,7 @@ bool apdu_unconfirmed_handler(BACNET_UNCONFIRMED_SERVICE service_choice)
return status; return status;
} }
// Confirmed ACK Function Handlers /* Confirmed ACK Function Handlers */
static void *Confirmed_ACK_Function[MAX_BACNET_CONFIRMED_SERVICE]; static void *Confirmed_ACK_Function[MAX_BACNET_CONFIRMED_SERVICE];
void apdu_set_confirmed_simple_ack_handler(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:
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY: case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION: case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
// Object Access Services /* Object Access Services */
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT: case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT: case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
case SERVICE_CONFIRMED_DELETE_OBJECT: case SERVICE_CONFIRMED_DELETE_OBJECT:
case SERVICE_CONFIRMED_WRITE_PROPERTY: case SERVICE_CONFIRMED_WRITE_PROPERTY:
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
// Remote Device Management Services /* Remote Device Management Services */
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
case SERVICE_CONFIRMED_TEXT_MESSAGE: case SERVICE_CONFIRMED_TEXT_MESSAGE:
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
// Virtual Terminal Services /* Virtual Terminal Services */
case SERVICE_CONFIRMED_VT_CLOSE: case SERVICE_CONFIRMED_VT_CLOSE:
// Security Services /* Security Services */
case SERVICE_CONFIRMED_REQUEST_KEY: case SERVICE_CONFIRMED_REQUEST_KEY:
Confirmed_ACK_Function[service_choice] = (void *) pFunction; Confirmed_ACK_Function[service_choice] = (void *) pFunction;
break; break;
@@ -221,21 +221,21 @@ void apdu_set_confirmed_ack_handler(BACNET_CONFIRMED_SERVICE
case SERVICE_CONFIRMED_GET_ALARM_SUMMARY: case SERVICE_CONFIRMED_GET_ALARM_SUMMARY:
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY: case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION: case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
// File Access Services /* File Access Services */
case SERVICE_CONFIRMED_ATOMIC_READ_FILE: case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE: case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
// Object Access Services /* Object Access Services */
case SERVICE_CONFIRMED_CREATE_OBJECT: case SERVICE_CONFIRMED_CREATE_OBJECT:
case SERVICE_CONFIRMED_READ_PROPERTY: case SERVICE_CONFIRMED_READ_PROPERTY:
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL: case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_READ_RANGE: case SERVICE_CONFIRMED_READ_RANGE:
// Remote Device Management Services /* Remote Device Management Services */
case SERVICE_CONFIRMED_PRIVATE_TRANSFER: case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
// Virtual Terminal Services /* Virtual Terminal Services */
case SERVICE_CONFIRMED_VT_OPEN: case SERVICE_CONFIRMED_VT_OPEN:
case SERVICE_CONFIRMED_VT_DATA: case SERVICE_CONFIRMED_VT_DATA:
// Security Services /* Security Services */
case SERVICE_CONFIRMED_AUTHENTICATE: case SERVICE_CONFIRMED_AUTHENTICATE:
Confirmed_ACK_Function[service_choice] = (void *) pFunction; Confirmed_ACK_Function[service_choice] = (void *) pFunction;
break; break;
@@ -267,13 +267,13 @@ void apdu_set_reject_handler(reject_function pFunction)
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, uint16_t apdu_len,
BACNET_CONFIRMED_SERVICE_DATA * service_data, BACNET_CONFIRMED_SERVICE_DATA * service_data,
uint8_t * service_choice, uint8_t * service_choice,
uint8_t ** service_request, uint16_t * service_request_len) 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->segmented_message = (apdu[0] & BIT3) ? true : false;
service_data->more_follows = (apdu[0] & BIT2) ? 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; return len;
} }
void apdu_handler(BACNET_ADDRESS * src, // source address void apdu_handler(BACNET_ADDRESS * src, /* source address */
bool data_expecting_reply, uint8_t * apdu, // APDU data bool data_expecting_reply, uint8_t * apdu, /* APDU data */
uint16_t apdu_len) uint16_t apdu_len)
{ {
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; 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_choice = 0;
uint8_t *service_request = NULL; uint8_t *service_request = NULL;
uint16_t service_request_len = 0; 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; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
int error_code = 0; int error_code = 0;
@@ -313,10 +313,10 @@ void apdu_handler(BACNET_ADDRESS * src, // source address
(void) data_expecting_reply; (void) data_expecting_reply;
if (apdu) { if (apdu) {
// PDU Type /* PDU Type */
switch (apdu[0] & 0xF0) { switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: 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, apdu_len,
&service_data, &service_data,
&service_choice, &service_request, &service_request_len); &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:
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY: case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION: case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
// Object Access Services /* Object Access Services */
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT: case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT: case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
case SERVICE_CONFIRMED_DELETE_OBJECT: case SERVICE_CONFIRMED_DELETE_OBJECT:
case SERVICE_CONFIRMED_WRITE_PROPERTY: case SERVICE_CONFIRMED_WRITE_PROPERTY:
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
// Remote Device Management Services /* Remote Device Management Services */
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
case SERVICE_CONFIRMED_TEXT_MESSAGE: case SERVICE_CONFIRMED_TEXT_MESSAGE:
// Virtual Terminal Services /* Virtual Terminal Services */
case SERVICE_CONFIRMED_VT_CLOSE: case SERVICE_CONFIRMED_VT_CLOSE:
// Security Services /* Security Services */
case SERVICE_CONFIRMED_REQUEST_KEY: case SERVICE_CONFIRMED_REQUEST_KEY:
if (Confirmed_ACK_Function[service_choice]) { if (Confirmed_ACK_Function[service_choice]) {
((confirmed_simple_ack_function) ((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_ALARM_SUMMARY:
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY: case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION: case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
// File Access Services /* File Access Services */
case SERVICE_CONFIRMED_ATOMIC_READ_FILE: case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE: case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
// Object Access Services /* Object Access Services */
case SERVICE_CONFIRMED_CREATE_OBJECT: case SERVICE_CONFIRMED_CREATE_OBJECT:
case SERVICE_CONFIRMED_READ_PROPERTY: case SERVICE_CONFIRMED_READ_PROPERTY:
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL: case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE: case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_READ_RANGE: case SERVICE_CONFIRMED_READ_RANGE:
case SERVICE_CONFIRMED_PRIVATE_TRANSFER: case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
// Virtual Terminal Services /* Virtual Terminal Services */
case SERVICE_CONFIRMED_VT_OPEN: case SERVICE_CONFIRMED_VT_OPEN:
case SERVICE_CONFIRMED_VT_DATA: case SERVICE_CONFIRMED_VT_DATA:
// Security Services /* Security Services */
case SERVICE_CONFIRMED_AUTHENTICATE: case SERVICE_CONFIRMED_AUTHENTICATE:
if (Confirmed_ACK_Function[service_choice]) { if (Confirmed_ACK_Function[service_choice]) {
((confirmed_ack_function) ((confirmed_ack_function)
+32 -32
View File
@@ -62,56 +62,56 @@ extern "C" {
uint8_t proposed_window_number; uint8_t proposed_window_number;
} BACNET_CONFIRMED_SERVICE_ACK_DATA; } BACNET_CONFIRMED_SERVICE_ACK_DATA;
// generic unconfirmed function handler /* generic unconfirmed function handler */
// Suitable to handle the following services: /* Suitable to handle the following services: */
// I_Am, Who_Is, Unconfirmed_COV_Notification, I_Have, /* I_Am, Who_Is, Unconfirmed_COV_Notification, I_Have, */
// Unconfirmed_Event_Notification, Unconfirmed_Private_Transfer, /* Unconfirmed_Event_Notification, Unconfirmed_Private_Transfer, */
// Unconfirmed_Text_Message, Time_Synchronization, Who_Has, /* Unconfirmed_Text_Message, Time_Synchronization, Who_Has, */
// UTC_Time_Synchronization /* UTC_Time_Synchronization */
typedef void (*unconfirmed_function) (uint8_t * service_request, typedef void (*unconfirmed_function) (uint8_t * service_request,
uint16_t len, BACNET_ADDRESS * src); uint16_t len, BACNET_ADDRESS * src);
// generic confirmed function handler /* generic confirmed function handler */
// Suitable to handle the following services: /* Suitable to handle the following services: */
// Acknowledge_Alarm, Confirmed_COV_Notification, /* Acknowledge_Alarm, Confirmed_COV_Notification, */
// Confirmed_Event_Notification, Get_Alarm_Summary, /* Confirmed_Event_Notification, Get_Alarm_Summary, */
// Get_Enrollment_Summary_Handler, Get_Event_Information, /* Get_Enrollment_Summary_Handler, Get_Event_Information, */
// Subscribe_COV_Handler, Subscribe_COV_Property, /* Subscribe_COV_Handler, Subscribe_COV_Property, */
// Life_Safety_Operation, Atomic_Read_File, /* Life_Safety_Operation, Atomic_Read_File, */
// Confirmed_Atomic_Write_File, Add_List_Element, /* Confirmed_Atomic_Write_File, Add_List_Element, */
// Remove_List_Element, Create_Object_Handler, /* Remove_List_Element, Create_Object_Handler, */
// Delete_Object_Handler, Read_Property, /* Delete_Object_Handler, Read_Property, */
// Read_Property_Conditional, Read_Property_Multiple, Read_Range, /* Read_Property_Conditional, Read_Property_Multiple, Read_Range, */
// Write_Property, Write_Property_Multiple, /* Write_Property, Write_Property_Multiple, */
// Device_Communication_Control, Confirmed_Private_Transfer, /* Device_Communication_Control, Confirmed_Private_Transfer, */
// Confirmed_Text_Message, Reinitialize_Device, /* Confirmed_Text_Message, Reinitialize_Device, */
// VT_Open, VT_Close, VT_Data_Handler, /* VT_Open, VT_Close, VT_Data_Handler, */
// Authenticate, Request_Key /* Authenticate, Request_Key */
typedef void (*confirmed_function) (uint8_t * service_request, typedef void (*confirmed_function) (uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data); 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, typedef void (*confirmed_simple_ack_function) (BACNET_ADDRESS * src,
uint8_t invoke_id); uint8_t invoke_id);
// generic confirmed ack function handler /* generic confirmed ack function handler */
typedef void (*confirmed_ack_function) (uint8_t * service_request, typedef void (*confirmed_ack_function) (uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
BACNET_ADDRESS * src, BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data); BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
// generic error reply function /* generic error reply function */
typedef void (*error_function) (BACNET_ADDRESS * src, typedef void (*error_function) (BACNET_ADDRESS * src,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code); 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, typedef void (*abort_function) (BACNET_ADDRESS * src,
uint8_t invoke_id, uint8_t abort_reason); uint8_t invoke_id, uint8_t abort_reason);
// generic reject reply function /* generic reject reply function */
typedef void (*reject_function) (BACNET_ADDRESS * src, typedef void (*reject_function) (BACNET_ADDRESS * src,
uint8_t invoke_id, uint8_t reject_reason); uint8_t invoke_id, uint8_t reject_reason);
@@ -121,7 +121,7 @@ extern "C" {
void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE
service_choice, confirmed_simple_ack_function pFunction); 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 void apdu_set_unrecognized_service_handler_handler(confirmed_function
pFunction); pFunction);
@@ -149,15 +149,15 @@ extern "C" {
void apdu_set_reject_handler(reject_function pFunction); 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, uint16_t apdu_len,
BACNET_CONFIRMED_SERVICE_DATA * service_data, BACNET_CONFIRMED_SERVICE_DATA * service_data,
uint8_t * service_choice, uint8_t * service_choice,
uint8_t ** service_request, uint16_t * service_request_len); uint8_t ** service_request, uint16_t * service_request_len);
void apdu_handler(BACNET_ADDRESS * src, // source address void apdu_handler(BACNET_ADDRESS * src, /* source address */
bool data_expecting_reply, uint8_t * apdu, // APDU data bool data_expecting_reply, uint8_t * apdu, /* APDU data */
uint16_t pdu_len); // for confirmed messages uint16_t pdu_len); /* for confirmed messages */
#ifdef __cplusplus #ifdef __cplusplus
} }
+15 -15
View File
@@ -39,7 +39,7 @@
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
// specific defines for ARCNET /* specific defines for ARCNET */
#define MAX_HEADER (1+1+2+2+1+1+1+1) #define MAX_HEADER (1+1+2+2+1+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
@@ -53,26 +53,26 @@ extern "C" {
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns 0 on success, non-zero on failure */ /* returns 0 on success, non-zero on failure */
int arcnet_send(BACNET_ADDRESS * dest, // destination address int arcnet_send(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, // source address BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int arcnet_send_pdu(BACNET_ADDRESS * dest, // destination address int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
// receives an framed packet /* receives an framed packet */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); // milliseconds to wait for a packet unsigned timeout); /* milliseconds to wait for a packet */
void arcnet_get_my_address(BACNET_ADDRESS * my_address); 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 #ifdef __cplusplus
} }
+33 -33
View File
@@ -38,20 +38,20 @@
#include "device.h" #include "device.h"
#include "arf.h" #include "arf.h"
// Atomic Read File /* Atomic Read File */
// encode service /* encode service */
int arf_encode_apdu(uint8_t * apdu, int arf_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data) 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) { if (apdu) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = apdu[1] =
encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted());
apdu[2] = invoke_id; 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 = 4;
apdu_len += encode_tagged_object_id(&apdu[apdu_len], apdu_len += encode_tagged_object_id(&apdu[apdu_len],
data->object_type, data->object_instance); data->object_type, data->object_instance);
@@ -80,7 +80,7 @@ int arf_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int arf_decode_service_request(uint8_t * apdu, int arf_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data) 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; int tag_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 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) { if (apdu_len && data) {
len = len =
decode_tag_number_and_value(&apdu[0], &tag_number, 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; data->object_type = type;
if (decode_is_opening_tag_number(&apdu[len], 0)) { if (decode_is_opening_tag_number(&apdu[len], 0)) {
data->access = FILE_STREAM_ACCESS; 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++; len++;
// fileStartPosition /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -111,7 +111,7 @@ int arf_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition); len_value_type, &data->type.stream.fileStartPosition);
// requestedOctetCount /* requestedOctetCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -121,13 +121,13 @@ int arf_decode_service_request(uint8_t * apdu,
len_value_type, &data->type.stream.requestedOctetCount); len_value_type, &data->type.stream.requestedOctetCount);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else if (decode_is_opening_tag_number(&apdu[len], 1)) { } else if (decode_is_opening_tag_number(&apdu[len], 1)) {
data->access = FILE_RECORD_ACCESS; 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++; len++;
// fileStartRecord /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -135,7 +135,7 @@ int arf_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord); len_value_type, &data->type.record.fileStartRecord);
// RecordCount /* RecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -145,7 +145,7 @@ int arf_decode_service_request(uint8_t * apdu,
len_value_type, &data->type.record.RecordCount); len_value_type, &data->type.record.RecordCount);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else } else
return -1; return -1;
@@ -163,10 +163,10 @@ int arf_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_READ_FILE) if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_READ_FILE)
return -1; return -1;
@@ -180,18 +180,18 @@ int arf_decode_apdu(uint8_t * apdu,
return len; return len;
} }
// encode service /* encode service */
int arf_ack_encode_apdu(uint8_t * apdu, int arf_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data) 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) { if (apdu) {
apdu[0] = PDU_TYPE_COMPLEX_ACK; apdu[0] = PDU_TYPE_COMPLEX_ACK;
apdu[1] = invoke_id; 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; apdu_len = 3;
// endOfFile /* endOfFile */
apdu_len += apdu_len +=
encode_tagged_boolean(&apdu[apdu_len], data->endOfFile); encode_tagged_boolean(&apdu[apdu_len], data->endOfFile);
switch (data->access) { switch (data->access) {
@@ -221,7 +221,7 @@ int arf_ack_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int arf_ack_decode_service_request(uint8_t * apdu, int arf_ack_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data) 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; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
// check for value pointers /* check for value pointers */
if (apdu_len && data) { if (apdu_len && data) {
len = len =
decode_tag_number_and_value(&apdu[0], &tag_number, 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); data->endOfFile = decode_boolean(len_value_type);
if (decode_is_opening_tag_number(&apdu[len], 0)) { if (decode_is_opening_tag_number(&apdu[len], 0)) {
data->access = FILE_STREAM_ACCESS; 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++; len++;
// fileStartPosition /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -250,7 +250,7 @@ int arf_ack_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition); len_value_type, &data->type.stream.fileStartPosition);
// fileData /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -260,13 +260,13 @@ int arf_ack_decode_service_request(uint8_t * apdu,
len_value_type, &data->fileData); len_value_type, &data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else if (decode_is_opening_tag_number(&apdu[len], 1)) { } else if (decode_is_opening_tag_number(&apdu[len], 1)) {
data->access = FILE_RECORD_ACCESS; 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++; len++;
// fileStartRecord /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -274,7 +274,7 @@ int arf_ack_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord); len_value_type, &data->type.record.fileStartRecord);
// returnedRecordCount /* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -282,7 +282,7 @@ int arf_ack_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_unsigned(&apdu[len], len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.RecordCount); len_value_type, &data->type.record.RecordCount);
// fileData /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -292,7 +292,7 @@ int arf_ack_decode_service_request(uint8_t * apdu,
len_value_type, &data->fileData); len_value_type, &data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else } else
return -1; return -1;
@@ -310,7 +310,7 @@ int arf_ack_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
return -1; return -1;
*invoke_id = apdu[1]; /* invoke id - filled in by net layer */ *invoke_id = apdu[1]; /* invoke id - filled in by net layer */
+7 -7
View File
@@ -50,7 +50,7 @@ typedef struct BACnet_Atomic_Read_File_Data {
} stream; } stream;
struct { struct {
int32_t fileStartRecord; int32_t fileStartRecord;
// requested or returned record count /* requested or returned record count */
uint32_t RecordCount; uint32_t RecordCount;
} record; } record;
} type; } type;
@@ -62,12 +62,12 @@ typedef struct BACnet_Atomic_Read_File_Data {
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// Atomic Read File /* Atomic Read File */
// encode service /* encode service */
int arf_encode_apdu(uint8_t * apdu, int arf_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); 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, int arf_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data); unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data);
@@ -75,13 +75,13 @@ extern "C" {
unsigned apdu_len, unsigned apdu_len,
uint8_t * invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); 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, int arf_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data); 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, int arf_ack_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data); unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data);
+23 -23
View File
@@ -38,20 +38,20 @@
#include "device.h" #include "device.h"
#include "awf.h" #include "awf.h"
// Atomic Write File /* Atomic Write File */
// encode service /* encode service */
int awf_encode_apdu(uint8_t * apdu, int awf_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data) 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) { if (apdu) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = apdu[1] =
encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted());
apdu[2] = invoke_id; 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 = 4;
apdu_len += encode_tagged_object_id(&apdu[apdu_len], apdu_len += encode_tagged_object_id(&apdu[apdu_len],
data->object_type, data->object_instance); data->object_type, data->object_instance);
@@ -82,7 +82,7 @@ int awf_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int awf_decode_service_request(uint8_t * apdu, int awf_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data) 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; int tag_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 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) { if (apdu_len && data) {
len = len =
decode_tag_number_and_value(&apdu[0], &tag_number, 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; data->object_type = type;
if (decode_is_opening_tag_number(&apdu[len], 0)) { if (decode_is_opening_tag_number(&apdu[len], 0)) {
data->access = FILE_STREAM_ACCESS; 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++; len++;
// fileStartPosition /* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -113,7 +113,7 @@ int awf_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition); len_value_type, &data->type.stream.fileStartPosition);
// fileData /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -123,13 +123,13 @@ int awf_decode_service_request(uint8_t * apdu,
len_value_type, &data->fileData); len_value_type, &data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0)) if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else if (decode_is_opening_tag_number(&apdu[len], 1)) { } else if (decode_is_opening_tag_number(&apdu[len], 1)) {
data->access = FILE_RECORD_ACCESS; 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++; len++;
// fileStartRecord /* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -137,7 +137,7 @@ int awf_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_signed(&apdu[len], len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord); len_value_type, &data->type.record.fileStartRecord);
// returnedRecordCount /* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -145,7 +145,7 @@ int awf_decode_service_request(uint8_t * apdu,
return -1; return -1;
len += decode_unsigned(&apdu[len], len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.returnedRecordCount); len_value_type, &data->type.record.returnedRecordCount);
// fileData /* fileData */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
len += tag_len; len += tag_len;
@@ -155,7 +155,7 @@ int awf_decode_service_request(uint8_t * apdu,
len_value_type, &data->fileData); len_value_type, &data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1)) if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1; return -1;
// a tag number is not extended so only one octet /* a tag number is not extended so only one octet */
len++; len++;
} else } else
return -1; return -1;
@@ -173,10 +173,10 @@ int awf_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_WRITE_FILE) if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_WRITE_FILE)
return -1; return -1;
@@ -193,12 +193,12 @@ int awf_decode_apdu(uint8_t * apdu,
int awf_ack_encode_apdu(uint8_t * apdu, int awf_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data) 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) { if (apdu) {
apdu[0] = PDU_TYPE_COMPLEX_ACK; apdu[0] = PDU_TYPE_COMPLEX_ACK;
apdu[1] = invoke_id; 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; apdu_len = 3;
switch (data->access) { switch (data->access) {
case FILE_STREAM_ACCESS: case FILE_STREAM_ACCESS:
@@ -217,7 +217,7 @@ int awf_ack_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int awf_ack_decode_service_request(uint8_t * apdu, int awf_ack_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data) 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; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
// check for value pointers /* check for value pointers */
if (apdu_len && data) { if (apdu_len && data) {
len = len =
decode_tag_number_and_value(&apdu[0], &tag_number, decode_tag_number_and_value(&apdu[0], &tag_number,
@@ -254,7 +254,7 @@ int awf_ack_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
return -1; return -1;
*invoke_id = apdu[1]; /* invoke id - filled in by net layer */ *invoke_id = apdu[1]; /* invoke id - filled in by net layer */
+6 -6
View File
@@ -58,12 +58,12 @@ typedef struct BACnet_Atomic_Write_File_Data {
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// Atomic Write File /* Atomic Write File */
// encode service /* encode service */
int awf_encode_apdu(uint8_t * apdu, int awf_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); 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, int awf_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data); unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data);
@@ -71,12 +71,12 @@ extern "C" {
unsigned apdu_len, unsigned apdu_len,
uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data);
// Atomic Write File Ack /* Atomic Write File Ack */
// encode service /* encode service */
int awf_ack_encode_apdu(uint8_t * apdu, int awf_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data); 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, int awf_ack_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data); unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data);
+1 -1
View File
@@ -46,7 +46,7 @@
int bacapp_encode_application_data(uint8_t * apdu, int bacapp_encode_application_data(uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value) 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 (apdu) {
if (value->tag == BACNET_APPLICATION_TAG_NULL) if (value->tag == BACNET_APPLICATION_TAG_NULL)
+215 -215
View File
File diff suppressed because it is too large Load Diff
+51 -51
View File
@@ -44,54 +44,54 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// from clause 20.2.1 General Rules for Encoding BACnet Tags /* from clause 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_tag(uint8_t * apdu, uint8_t tag_number, int encode_tag(uint8_t * apdu, uint8_t tag_number,
bool context_specific, uint32_t len_value_type); bool context_specific, uint32_t len_value_type);
// from clause 20.2.1.3.2 Constructed Data /* from clause 20.2.1.3.2 Constructed Data */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_opening_tag(uint8_t * apdu, uint8_t tag_number); int encode_opening_tag(uint8_t * apdu, uint8_t tag_number);
int encode_closing_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, int decode_tag_number_and_value(uint8_t * apdu, uint8_t * tag_number,
uint32_t * value); 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); 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); 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); 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); 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); 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); int encode_tagged_boolean(uint8_t * apdu, bool boolean_value);
bool decode_boolean(uint32_t len_value); bool decode_boolean(uint32_t len_value);
int encode_context_boolean(uint8_t * apdu, bool boolean_value); int encode_context_boolean(uint8_t * apdu, bool boolean_value);
bool decode_context_boolean(uint8_t * apdu); bool decode_context_boolean(uint8_t * apdu);
// from clause 20.2.10 Encoding of a Bit String Value /* from clause 20.2.10 Encoding of a Bit String Value */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int decode_bitstring(uint8_t * apdu, uint32_t len_value, int decode_bitstring(uint8_t * apdu, uint32_t len_value,
BACNET_BIT_STRING * bit_string); 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_bitstring(uint8_t * apdu, BACNET_BIT_STRING * bit_string);
int encode_tagged_bitstring(uint8_t * apdu, int encode_tagged_bitstring(uint8_t * apdu,
BACNET_BIT_STRING * bit_string); BACNET_BIT_STRING * bit_string);
// from clause 20.2.6 Encoding of a Real Number Value /* from clause 20.2.6 Encoding of a Real Number Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int decode_real(uint8_t * apdu, float *real_value); int decode_real(uint8_t * apdu, float *real_value);
int encode_bacnet_real(float value, uint8_t * apdu); int encode_bacnet_real(float value, uint8_t * apdu);
int encode_tagged_real(uint8_t * apdu, float value); int encode_tagged_real(uint8_t * apdu, float value);
// from clause 20.2.14 Encoding of an Object Identifier Value /* from clause 20.2.14 Encoding of an Object Identifier Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int decode_object_id(uint8_t * apdu, int *object_type, int decode_object_id(uint8_t * apdu, int *object_type,
uint32_t * instance); uint32_t * instance);
int encode_bacnet_object_id(uint8_t * apdu, int object_type, 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, int encode_tagged_object_id(uint8_t * apdu, int object_type,
uint32_t instance); uint32_t instance);
// from clause 20.2.8 Encoding of an Octet String Value /* from clause 20.2.8 Encoding of an Octet String Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_octet_string(uint8_t * apdu, int encode_octet_string(uint8_t * apdu,
BACNET_OCTET_STRING * octet_string); BACNET_OCTET_STRING * octet_string);
int encode_tagged_octet_string(uint8_t * apdu, int encode_tagged_octet_string(uint8_t * apdu,
@@ -112,9 +112,9 @@ extern "C" {
BACNET_OCTET_STRING * octet_string); BACNET_OCTET_STRING * octet_string);
// from clause 20.2.9 Encoding of a Character String Value /* from clause 20.2.9 Encoding of a Character String Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_bacnet_character_string(uint8_t * apdu, int encode_bacnet_character_string(uint8_t * apdu,
BACNET_CHARACTER_STRING * char_string); BACNET_CHARACTER_STRING * char_string);
int encode_tagged_character_string(uint8_t * apdu, 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, int decode_character_string(uint8_t * apdu, uint32_t len_value,
BACNET_CHARACTER_STRING * char_string); BACNET_CHARACTER_STRING * char_string);
// from clause 20.2.4 Encoding of an Unsigned Integer Value /* from clause 20.2.4 Encoding of an Unsigned Integer Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_bacnet_unsigned(uint8_t * apdu, uint32_t value); int encode_bacnet_unsigned(uint8_t * apdu, uint32_t value);
int encode_context_unsigned(uint8_t * apdu, int tag_number, int encode_context_unsigned(uint8_t * apdu, int tag_number,
uint32_t value); uint32_t value);
@@ -134,27 +134,27 @@ extern "C" {
int decode_unsigned(uint8_t * apdu, uint32_t len_value, int decode_unsigned(uint8_t * apdu, uint32_t len_value,
uint32_t * value); uint32_t * value);
// from clause 20.2.5 Encoding of a Signed Integer Value /* from clause 20.2.5 Encoding of a Signed Integer Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_bacnet_signed(uint8_t * apdu, int32_t value); int encode_bacnet_signed(uint8_t * apdu, int32_t value);
int encode_tagged_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, int encode_context_signed(uint8_t * apdu, int tag_number,
int32_t value); int32_t value);
int decode_signed(uint8_t * apdu, uint32_t len_value, 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 /* from clause 20.2.11 Encoding of an Enumerated Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int decode_enumerated(uint8_t * apdu, uint32_t len_value, int *value); int decode_enumerated(uint8_t * apdu, uint32_t len_value, int *value);
int encode_bacnet_enumerated(uint8_t * apdu, int value); int encode_bacnet_enumerated(uint8_t * apdu, int value);
int encode_tagged_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 encode_context_enumerated(uint8_t * apdu, int tag_number,
int value); int value);
// from clause 20.2.13 Encoding of a Time Value /* from clause 20.2.13 Encoding of a Time Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_bacnet_time(uint8_t * apdu, int hour, int min, int sec, int encode_bacnet_time(uint8_t * apdu, int hour, int min, int sec,
int hundredths); int hundredths);
int encode_tagged_time(uint8_t * apdu, int hour, int min, int sec, 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 decode_bacnet_time(uint8_t * apdu, int *hour, int *min, int *sec,
int *hundredths); int *hundredths);
// BACnet Date /* BACnet Date */
// year = years since 1900 /* year = years since 1900 */
// month 1=Jan /* month 1=Jan */
// day = day of month /* day = day of month */
// wday 1=Monday...7=Sunday /* wday 1=Monday...7=Sunday */
// from clause 20.2.12 Encoding of a Date Value /* from clause 20.2.12 Encoding of a Date Value */
// and 20.2.1 General Rules for Encoding BACnet Tags /* and 20.2.1 General Rules for Encoding BACnet Tags */
// returns the number of apdu bytes consumed /* returns the number of apdu bytes consumed */
int encode_bacnet_date(uint8_t * apdu, int year, int month, int day, int encode_bacnet_date(uint8_t * apdu, int year, int month, int day,
int wday); int wday);
int encode_tagged_date(uint8_t * apdu, int year, int month, int day, 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 decode_date(uint8_t * apdu, int *year, int *month, int *day,
int *wday); int *wday);
// two octet unsigned16 /* two octet unsigned16 */
int encode_unsigned16(uint8_t * apdu, uint16_t value); int encode_unsigned16(uint8_t * apdu, uint16_t value);
int decode_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 encode_unsigned32(uint8_t * apdu, uint32_t value);
int decode_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 /* from clause 20.1.2.4 max-segments-accepted */
// and clause 20.1.2.5 max-APDU-length-accepted /* and clause 20.1.2.5 max-APDU-length-accepted */
// returns the encoded octet /* returns the encoded octet */
uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu); uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu);
int decode_max_segs(uint8_t octet); int decode_max_segs(uint8_t octet);
int decode_max_apdu(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, int encode_simple_ack(uint8_t * apdu, uint8_t invoke_id,
uint8_t service_choice); uint8_t service_choice);
+16 -16
View File
@@ -39,23 +39,23 @@
#include "bacenum.h" #include "bacenum.h"
#include "config.h" #include "config.h"
// largest BACnet Instance Number /* largest BACnet Instance Number */
// Also used as a device instance number wildcard address /* Also used as a device instance number wildcard address */
#define BACNET_MAX_INSTANCE (0x3FFFFF) #define BACNET_MAX_INSTANCE (0x3FFFFF)
#define BACNET_INSTANCE_BITS 22 #define BACNET_INSTANCE_BITS 22
// large BACnet Object Type /* large BACnet Object Type */
#define BACNET_MAX_OBJECT (0x3FF) #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_LENGTH_INDEX 0
#define BACNET_ARRAY_ALL (~0) #define BACNET_ARRAY_ALL (~0)
// Priority Array for commandable objects /* Priority Array for commandable objects */
#define BACNET_NO_PRIORITY 0 #define BACNET_NO_PRIORITY 0
#define BACNET_MIN_PRIORITY 1 #define BACNET_MIN_PRIORITY 1
#define BACNET_MAX_PRIORITY 16 #define BACNET_MAX_PRIORITY 16
// embedded systems need fixed name sizes /* embedded systems need fixed name sizes */
#define MAX_OBJECT_NAME 10 #define MAX_OBJECT_NAME 10
// common object properties /* common object properties */
typedef struct BACnet_Object_Data { typedef struct BACnet_Object_Data {
uint32_t Object_Identifier; uint32_t Object_Identifier;
char Object_Name[MAX_OBJECT_NAME]; char Object_Name[MAX_OBJECT_NAME];
@@ -63,20 +63,20 @@ typedef struct BACnet_Object_Data {
} BACNET_OBJECT_DATA; } BACNET_OBJECT_DATA;
#define BACNET_BROADCAST_NETWORK 0xFFFF #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 #define MAX_MAC_LEN 18
struct BACnet_Device_Address { struct BACnet_Device_Address {
// mac_len = 0 if global address /* mac_len = 0 if global address */
int mac_len; int mac_len;
// note: MAC for IP addresses uses 4 bytes for addr, 2 bytes for port /* 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 /* use de/encode_unsigned32/16 for re/storing the IP address */
uint8_t mac[MAX_MAC_LEN]; uint8_t mac[MAX_MAC_LEN];
// DNET,DLEN,DADR or SNET,SLEN,SADR /* DNET,DLEN,DADR or SNET,SLEN,SADR */
// the following are used if the device is behind a router /* the following are used if the device is behind a router */
// net = 0 indicates local /* net = 0 indicates local */
uint16_t net; /* BACnet network number */ uint16_t net; /* BACnet network number */
// LEN = 0 denotes broadcast MAC ADR and ADR field is absent /* LEN = 0 denotes broadcast MAC ADR and ADR field is absent */
// LEN > 0 specifies length of ADR field /* LEN > 0 specifies length of ADR field */
int len; /* length of MAC address */ int len; /* length of MAC address */
uint8_t adr[MAX_MAC_LEN]; /* hwaddr (MAC) address */ uint8_t adr[MAX_MAC_LEN]; /* hwaddr (MAC) address */
}; };
+89 -89
View File
@@ -130,7 +130,7 @@ typedef enum {
PROP_PROGRAM_STATE = 92, PROP_PROGRAM_STATE = 92,
PROP_PROPORTIONAL_CONSTANT = 93, PROP_PROPORTIONAL_CONSTANT = 93,
PROP_PROPORTIONAL_CONSTANT_UNITS = 94, 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_OBJECT_TYPES_SUPPORTED = 96,
PROP_PROTOCOL_SERVICES_SUPPORTED = 97, PROP_PROTOCOL_SERVICES_SUPPORTED = 97,
PROP_PROTOCOL_VERSION = 98, PROP_PROTOCOL_VERSION = 98,
@@ -229,13 +229,13 @@ typedef enum {
PROP_VALUE_SET = 191, PROP_VALUE_SET = 191,
PROP_VALUE_CHANGE_TIME = 192, PROP_VALUE_CHANGE_TIME = 192,
// The special property identifiers all, optional, and required /* The special property identifiers all, optional, and required */
// are reserved for use in the ReadPropertyConditional and /* are reserved for use in the ReadPropertyConditional and */
// ReadPropertyMultiple services or services not defined in this standard. /* ReadPropertyMultiple services or services not defined in this standard. */
// Enumerated values 0-511 are reserved for definition by ASHRAE. /* Enumerated values 0-511 are reserved for definition by ASHRAE. */
// Enumerated values 512-4194303 may be used by others subject to the /* Enumerated values 512-4194303 may be used by others subject to the */
// procedures and constraints described in Clause 23. /* procedures and constraints described in Clause 23. */
// The highest enumeration used in this version is 168. /* The highest enumeration used in this version is 168. */
MAX_BACNET_PROPERTY_ID = 4194303 MAX_BACNET_PROPERTY_ID = 4194303
} BACNET_PROPERTY_ID; } BACNET_PROPERTY_ID;
@@ -520,9 +520,9 @@ typedef enum {
PROGRAM_ERROR_INTERNAL = 2, PROGRAM_ERROR_INTERNAL = 2,
PROGRAM_ERROR_PROGRAM = 3, PROGRAM_ERROR_PROGRAM = 3,
PROGRAM_ERROR_OTHER = 4 PROGRAM_ERROR_OTHER = 4
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
} BACNET_PROGRAM_ERROR; } BACNET_PROGRAM_ERROR;
typedef enum { typedef enum {
@@ -537,9 +537,9 @@ typedef enum {
RELIABILITY_PROCESS_ERROR = 8, RELIABILITY_PROCESS_ERROR = 8,
RELIABILITY_MULTI_STATE_FAULT = 9, RELIABILITY_MULTI_STATE_FAULT = 9,
RELIABILITY_CONFIGURATION_ERROR = 10 RELIABILITY_CONFIGURATION_ERROR = 10
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
} BACNET_RELIABILITY; } BACNET_RELIABILITY;
typedef enum { typedef enum {
@@ -555,13 +555,13 @@ typedef enum {
EVENT_EXTENDED = 9, EVENT_EXTENDED = 9,
EVENT_BUFFER_READY = 10, EVENT_BUFFER_READY = 10,
EVENT_UNSIGNED_RANGE = 11, EVENT_UNSIGNED_RANGE = 11,
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
// It is expected that these enumerated values will correspond to /* It is expected that these enumerated values will correspond to */
// the use of the complex-event-type CHOICE [6] of the /* the use of the complex-event-type CHOICE [6] of the */
// BACnetNotificationParameters production. /* BACnetNotificationParameters production. */
// The last enumeration used in this version is 11. /* The last enumeration used in this version is 11. */
} BACNET_EVENT_TYPE; } BACNET_EVENT_TYPE;
typedef enum { typedef enum {
@@ -586,9 +586,9 @@ typedef enum {
LIFE_SAFETY_MODE_DISABLED = 12, LIFE_SAFETY_MODE_DISABLED = 12,
LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13, LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13,
LIFE_SAFETY_MODE_DEFAULT = 14 LIFE_SAFETY_MODE_DEFAULT = 14
// Enumerated values 0-255 are reserved for definition by ASHRAE. /* Enumerated values 0-255 are reserved for definition by ASHRAE. */
// Enumerated values 256-65535 may be used by others subject to /* Enumerated values 256-65535 may be used by others subject to */
// procedures and constraints described in Clause 23. /* procedures and constraints described in Clause 23. */
} BACNET_LIFE_SAFETY_MODE; } BACNET_LIFE_SAFETY_MODE;
typedef enum { typedef enum {
@@ -602,9 +602,9 @@ typedef enum {
LIFE_SAFETY_OPERATION_UNSILENCE = 7, LIFE_SAFETY_OPERATION_UNSILENCE = 7,
LIFE_SAFETY_OPERATION_UNSILENCE_AUDIBLE = 8, LIFE_SAFETY_OPERATION_UNSILENCE_AUDIBLE = 8,
LIFE_SAFETY_OPERATION_UNSILENCE_VISUAL = 9 LIFE_SAFETY_OPERATION_UNSILENCE_VISUAL = 9
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// procedures and constraints described in Clause 23. /* procedures and constraints described in Clause 23. */
} BACNET_LIFE_SAFETY_OPERATION; } BACNET_LIFE_SAFETY_OPERATION;
typedef enum { typedef enum {
@@ -632,9 +632,9 @@ typedef enum {
LIFE_SAFETY_STATE_GENERAL_ALARM = 21, LIFE_SAFETY_STATE_GENERAL_ALARM = 21,
LIFE_SAFETY_STATE_SUPERVISORY = 22, LIFE_SAFETY_STATE_SUPERVISORY = 22,
LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23 LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23
// Enumerated values 0-255 are reserved for definition by ASHRAE. /* Enumerated values 0-255 are reserved for definition by ASHRAE. */
// Enumerated values 256-65535 may be used by others subject to /* Enumerated values 256-65535 may be used by others subject to */
// procedures and constraints described in Clause 23. /* procedures and constraints described in Clause 23. */
} BACNET_LIFE_SAFETY_STATE; } BACNET_LIFE_SAFETY_STATE;
typedef enum { typedef enum {
@@ -642,9 +642,9 @@ typedef enum {
MAINTENANCE_PERIODIC_TEST = 1, MAINTENANCE_PERIODIC_TEST = 1,
AINTENANCE_NEED_SERVICE_OPERATIONAL = 2, AINTENANCE_NEED_SERVICE_OPERATIONAL = 2,
MAINTENANCE_NEED_SERVICE_INOPERATIVE = 3 MAINTENANCE_NEED_SERVICE_INOPERATIVE = 3
// Enumerated values 0-255 are reserved for definition by ASHRAE. /* Enumerated values 0-255 are reserved for definition by ASHRAE. */
// Enumerated values 256-65535 may be used by others subject to /* Enumerated values 256-65535 may be used by others subject to */
// procedures and constraints described in Clause 23. /* procedures and constraints described in Clause 23. */
} BACNET_MAINTENANCE; } BACNET_MAINTENANCE;
typedef enum { typedef enum {
@@ -679,10 +679,10 @@ typedef enum {
OBJECT_LIFE_SAFETY_ZONE = 22, OBJECT_LIFE_SAFETY_ZONE = 22,
OBJECT_ACCUMULATOR = 23, OBJECT_ACCUMULATOR = 23,
OBJECT_PULSE_CONVERTER = 24, OBJECT_PULSE_CONVERTER = 24,
// Enumerated values 0-127 are reserved for definition by ASHRAE. /* Enumerated values 0-127 are reserved for definition by ASHRAE. */
// Enumerated values 128-1023 may be used by others subject to /* Enumerated values 128-1023 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
MAX_ASHRAE_OBJECT_TYPE = 25, // used for bit string loop MAX_ASHRAE_OBJECT_TYPE = 25, /* used for bit string loop */
MAX_BACNET_OBJECT_TYPE = 1023 MAX_BACNET_OBJECT_TYPE = 1023
} BACNET_OBJECT_TYPE; } BACNET_OBJECT_TYPE;
@@ -702,9 +702,9 @@ typedef enum {
VT_CLASS_DEC_VT220 = 4, VT_CLASS_DEC_VT220 = 4,
VT_CLASS_HP_700_94 = 5, /* real name is HP 700/94 */ VT_CLASS_HP_700_94 = 5, /* real name is HP 700/94 */
VT_CLASS_IBM_3130 = 6 VT_CLASS_IBM_3130 = 6
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
} BACNET_VT_CLASS; } BACNET_VT_CLASS;
typedef enum { typedef enum {
@@ -736,8 +736,8 @@ typedef enum {
MAX_BACNET_APPLICATION_TAG = 16 MAX_BACNET_APPLICATION_TAG = 16
} BACNET_APPLICATION_TAG; } BACNET_APPLICATION_TAG;
// note: these are not the real values, /* note: these are not the real values, */
// but are shifted left for easy encoding /* but are shifted left for easy encoding */
typedef enum { typedef enum {
PDU_TYPE_CONFIRMED_SERVICE_REQUEST = 0, PDU_TYPE_CONFIRMED_SERVICE_REQUEST = 0,
PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST = 0x10, PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST = 0x10,
@@ -750,7 +750,7 @@ typedef enum {
} BACNET_PDU_TYPE; } BACNET_PDU_TYPE;
typedef enum { typedef enum {
// Alarm and Event Services /* Alarm and Event Services */
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM = 0, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM = 0,
SERVICE_CONFIRMED_COV_NOTIFICATION = 1, SERVICE_CONFIRMED_COV_NOTIFICATION = 1,
SERVICE_CONFIRMED_EVENT_NOTIFICATION = 2, SERVICE_CONFIRMED_EVENT_NOTIFICATION = 2,
@@ -760,10 +760,10 @@ typedef enum {
SERVICE_CONFIRMED_SUBSCRIBE_COV = 5, SERVICE_CONFIRMED_SUBSCRIBE_COV = 5,
SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY = 28, SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY = 28,
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION = 27, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION = 27,
// File Access Services /* File Access Services */
SERVICE_CONFIRMED_ATOMIC_READ_FILE = 6, SERVICE_CONFIRMED_ATOMIC_READ_FILE = 6,
SERVICE_CONFIRMED_ATOMIC_WRITE_FILE = 7, SERVICE_CONFIRMED_ATOMIC_WRITE_FILE = 7,
// Object Access Services /* Object Access Services */
SERVICE_CONFIRMED_ADD_LIST_ELEMENT = 8, SERVICE_CONFIRMED_ADD_LIST_ELEMENT = 8,
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT = 9, SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT = 9,
SERVICE_CONFIRMED_CREATE_OBJECT = 10, SERVICE_CONFIRMED_CREATE_OBJECT = 10,
@@ -774,23 +774,23 @@ typedef enum {
SERVICE_CONFIRMED_READ_RANGE = 26, SERVICE_CONFIRMED_READ_RANGE = 26,
SERVICE_CONFIRMED_WRITE_PROPERTY = 15, SERVICE_CONFIRMED_WRITE_PROPERTY = 15,
SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE = 16, SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE = 16,
// Remote Device Management Services /* Remote Device Management Services */
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL = 17, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL = 17,
SERVICE_CONFIRMED_PRIVATE_TRANSFER = 18, SERVICE_CONFIRMED_PRIVATE_TRANSFER = 18,
SERVICE_CONFIRMED_TEXT_MESSAGE = 19, SERVICE_CONFIRMED_TEXT_MESSAGE = 19,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE = 20, SERVICE_CONFIRMED_REINITIALIZE_DEVICE = 20,
// Virtual Terminal Services /* Virtual Terminal Services */
SERVICE_CONFIRMED_VT_OPEN = 21, SERVICE_CONFIRMED_VT_OPEN = 21,
SERVICE_CONFIRMED_VT_CLOSE = 22, SERVICE_CONFIRMED_VT_CLOSE = 22,
SERVICE_CONFIRMED_VT_DATA = 23, SERVICE_CONFIRMED_VT_DATA = 23,
// Security Services /* Security Services */
SERVICE_CONFIRMED_AUTHENTICATE = 24, SERVICE_CONFIRMED_AUTHENTICATE = 24,
SERVICE_CONFIRMED_REQUEST_KEY = 25, SERVICE_CONFIRMED_REQUEST_KEY = 25,
// Services added after 1995 /* Services added after 1995 */
// readRange (26) see Object Access Services /* readRange (26) see Object Access Services */
// lifeSafetyOperation (27) see Alarm and Event Services /* lifeSafetyOperation (27) see Alarm and Event Services */
// subscribeCOVProperty (28) see Alarm and Event Services /* subscribeCOVProperty (28) see Alarm and Event Services */
// getEventInformation (29) see Alarm and Event Services /* getEventInformation (29) see Alarm and Event Services */
MAX_BACNET_CONFIRMED_SERVICE = 30 MAX_BACNET_CONFIRMED_SERVICE = 30
} BACNET_CONFIRMED_SERVICE; } BACNET_CONFIRMED_SERVICE;
@@ -805,17 +805,17 @@ typedef enum {
SERVICE_UNCONFIRMED_WHO_HAS = 7, SERVICE_UNCONFIRMED_WHO_HAS = 7,
SERVICE_UNCONFIRMED_WHO_IS = 8, SERVICE_UNCONFIRMED_WHO_IS = 8,
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION = 9, SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION = 9,
// Other services to be added as they are defined. /* Other services to be added as they are defined. */
// All choice values in this production are reserved /* All choice values in this production are reserved */
// for definition by ASHRAE. /* for definition by ASHRAE. */
// Proprietary extensions are made by using the /* Proprietary extensions are made by using the */
// UnconfirmedPrivateTransfer service. See Clause 23. /* UnconfirmedPrivateTransfer service. See Clause 23. */
MAX_BACNET_UNCONFIRMED_SERVICE = 10 MAX_BACNET_UNCONFIRMED_SERVICE = 10
} BACNET_UNCONFIRMED_SERVICE; } BACNET_UNCONFIRMED_SERVICE;
// Bit String Enumerations /* Bit String Enumerations */
typedef enum { typedef enum {
// Alarm and Event Services /* Alarm and Event Services */
SERVICE_SUPPORTED_ACKNOWLEDGE_ALARM = 0, SERVICE_SUPPORTED_ACKNOWLEDGE_ALARM = 0,
SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION = 1, SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION = 1,
SERVICE_SUPPORTED_CONFIRMED_EVENT_NOTIFICATION = 2, SERVICE_SUPPORTED_CONFIRMED_EVENT_NOTIFICATION = 2,
@@ -825,10 +825,10 @@ typedef enum {
SERVICE_SUPPORTED_SUBSCRIBE_COV = 5, SERVICE_SUPPORTED_SUBSCRIBE_COV = 5,
SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY = 38, SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY = 38,
SERVICE_SUPPORTED_LIFE_SAFETY_OPERATION = 37, SERVICE_SUPPORTED_LIFE_SAFETY_OPERATION = 37,
// File Access Services /* File Access Services */
SERVICE_SUPPORTED_ATOMIC_READ_FILE = 6, SERVICE_SUPPORTED_ATOMIC_READ_FILE = 6,
SERVICE_SUPPORTED_ATOMIC_WRITE_FILE = 7, SERVICE_SUPPORTED_ATOMIC_WRITE_FILE = 7,
// Object Access Services /* Object Access Services */
SERVICE_SUPPORTED_ADD_LIST_ELEMENT = 8, SERVICE_SUPPORTED_ADD_LIST_ELEMENT = 8,
SERVICE_SUPPORTED_REMOVE_LIST_ELEMENT = 9, SERVICE_SUPPORTED_REMOVE_LIST_ELEMENT = 9,
SERVICE_SUPPORTED_CREATE_OBJECT = 10, SERVICE_SUPPORTED_CREATE_OBJECT = 10,
@@ -839,16 +839,16 @@ typedef enum {
SERVICE_SUPPORTED_READ_RANGE = 35, SERVICE_SUPPORTED_READ_RANGE = 35,
SERVICE_SUPPORTED_WRITE_PROPERTY = 15, SERVICE_SUPPORTED_WRITE_PROPERTY = 15,
SERVICE_SUPPORTED_WRITE_PROPERTY_MULTIPLE = 16, SERVICE_SUPPORTED_WRITE_PROPERTY_MULTIPLE = 16,
// Remote Device Management Services /* Remote Device Management Services */
SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL = 17, SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL = 17,
SERVICE_SUPPORTED_PRIVATE_TRANSFER = 18, SERVICE_SUPPORTED_PRIVATE_TRANSFER = 18,
SERVICE_SUPPORTED_TEXT_MESSAGE = 19, SERVICE_SUPPORTED_TEXT_MESSAGE = 19,
SERVICE_SUPPORTED_REINITIALIZE_DEVICE = 20, SERVICE_SUPPORTED_REINITIALIZE_DEVICE = 20,
// Virtual Terminal Services /* Virtual Terminal Services */
SERVICE_SUPPORTED_VT_OPEN = 21, SERVICE_SUPPORTED_VT_OPEN = 21,
SERVICE_SUPPORTED_VT_CLOSE = 22, SERVICE_SUPPORTED_VT_CLOSE = 22,
SERVICE_SUPPORTED_VT_DATA = 23, SERVICE_SUPPORTED_VT_DATA = 23,
// Security Services /* Security Services */
SERVICE_SUPPORTED_AUTHENTICATE = 24, SERVICE_SUPPORTED_AUTHENTICATE = 24,
SERVICE_SUPPORTED_REQUEST_KEY = 25, SERVICE_SUPPORTED_REQUEST_KEY = 25,
SERVICE_SUPPORTED_I_AM = 26, SERVICE_SUPPORTED_I_AM = 26,
@@ -861,13 +861,13 @@ typedef enum {
SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION = 36, SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION = 36,
SERVICE_SUPPORTED_WHO_HAS = 33, SERVICE_SUPPORTED_WHO_HAS = 33,
SERVICE_SUPPORTED_WHO_IS = 34, SERVICE_SUPPORTED_WHO_IS = 34,
// Other services to be added as they are defined. /* Other services to be added as they are defined. */
// All values in this production are reserved /* All values in this production are reserved */
// for definition by ASHRAE. /* for definition by ASHRAE. */
MAX_BACNET_SERVICES_SUPPORTED = 40 MAX_BACNET_SERVICES_SUPPORTED = 40
} BACNET_SERVICES_SUPPORTED; } BACNET_SERVICES_SUPPORTED;
// Bit String Enumerations /* Bit String Enumerations */
typedef enum { typedef enum {
STATUS_FLAG_IN_ALARM = 0, STATUS_FLAG_IN_ALARM = 0,
STATUS_FLAG_FAULT = 1, STATUS_FLAG_FAULT = 1,
@@ -918,10 +918,10 @@ typedef enum {
MESSAGE_PRIORITY_LIFE_SAFETY = 3 MESSAGE_PRIORITY_LIFE_SAFETY = 3
} BACNET_MESSAGE_PRIORITY; } BACNET_MESSAGE_PRIORITY;
//Network Layer Message Type /*Network Layer Message Type */
//If Bit 7 of the control octet described in 6.2.2 is 1, /*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. /* a message type octet shall be present as shown in Figure 6-1. */
// The following message types are indicated: /* The following message types are indicated: */
typedef enum { typedef enum {
NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK = 0, NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK = 0,
NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK = 1, NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK = 1,
@@ -933,8 +933,8 @@ typedef enum {
NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE_ACK = 7, NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE_ACK = 7,
NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK = 8, NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK = 8,
NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9 NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9
// X'0A' to X'7F': Reserved for use by ASHRAE, /* X'0A' to X'7F': Reserved for use by ASHRAE, */
// X'80' to X'FF': Available for vendor proprietary messages /* X'80' to X'FF': Available for vendor proprietary messages */
} BACNET_NETWORK_MESSAGE_TYPE; } BACNET_NETWORK_MESSAGE_TYPE;
@@ -954,9 +954,9 @@ typedef enum {
ABORT_REASON_INVALID_APDU_IN_THIS_STATE = 2, ABORT_REASON_INVALID_APDU_IN_THIS_STATE = 2,
ABORT_REASON_PREEMPTED_BY_HIGHER_PRIORITY_TASK = 3, ABORT_REASON_PREEMPTED_BY_HIGHER_PRIORITY_TASK = 3,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED = 4, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED = 4,
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
MAX_BACNET_ABORT_REASON = 5, MAX_BACNET_ABORT_REASON = 5,
FIRST_PROPRIETARY_ABORT_REASON = 64, FIRST_PROPRIETARY_ABORT_REASON = 64,
LAST_PROPRIETARY_ABORT_REASON = 65535 LAST_PROPRIETARY_ABORT_REASON = 65535
@@ -973,9 +973,9 @@ typedef enum {
REJECT_REASON_TOO_MANY_ARGUMENTS = 7, REJECT_REASON_TOO_MANY_ARGUMENTS = 7,
REJECT_REASON_UNDEFINED_ENUMERATION = 8, REJECT_REASON_UNDEFINED_ENUMERATION = 8,
REJECT_REASON_UNRECOGNIZED_SERVICE = 9, REJECT_REASON_UNRECOGNIZED_SERVICE = 9,
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
MAX_BACNET_REJECT_REASON = 10, MAX_BACNET_REJECT_REASON = 10,
FIRST_PROPRIETARY_REJECT_REASON = 64, FIRST_PROPRIETARY_REJECT_REASON = 64,
LAST_PROPRIETARY_REJECT_REASON = 65535 LAST_PROPRIETARY_REJECT_REASON = 65535
@@ -989,9 +989,9 @@ typedef enum {
ERROR_CLASS_SECURITY = 4, ERROR_CLASS_SECURITY = 4,
ERROR_CLASS_SERVICES = 5, ERROR_CLASS_SERVICES = 5,
ERROR_CLASS_VT = 6, ERROR_CLASS_VT = 6,
// Enumerated values 0-63 are reserved for definition by ASHRAE. /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
// Enumerated values 64-65535 may be used by others subject to /* Enumerated values 64-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
MAX_BACNET_ERROR_CLASS = 7, MAX_BACNET_ERROR_CLASS = 7,
FIRST_PROPRIETARY_ERROR_CLASS = 64, FIRST_PROPRIETARY_ERROR_CLASS = 64,
LAST_PROPRIETARY_ERROR_CLASS = 65535 LAST_PROPRIETARY_ERROR_CLASS = 65535
@@ -1057,10 +1057,10 @@ typedef enum {
/* see duplicate-name (48), */ /* see duplicate-name (48), */
/* see duplicate-object-id (49), */ /* see duplicate-object-id (49), */
/* see property-is-not-an-array (50), */ /* see property-is-not-an-array (50), */
// Enumerated values 0-255 are reserved for definition by ASHRAE. /* Enumerated values 0-255 are reserved for definition by ASHRAE. */
// Enumerated values 256-65535 may be used by others subject to /* Enumerated values 256-65535 may be used by others subject to */
// the procedures and constraints described in Clause 23. /* the procedures and constraints described in Clause 23. */
// The last enumeration used in this version is 50. /* The last enumeration used in this version is 50. */
MAX_BACNET_ERROR_CODE = 51, MAX_BACNET_ERROR_CODE = 51,
FIRST_PROPRIETARY_ERROR_CODE = 256, FIRST_PROPRIETARY_ERROR_CODE = 256,
LAST_PROPRIETARY_ERROR_CODE = 65535 LAST_PROPRIETARY_ERROR_CODE = 65535
@@ -1077,4 +1077,4 @@ typedef enum {
MAX_BACNET_REINITIALIZED_STATE = 7 MAX_BACNET_REINITIALIZED_STATE = 7
} BACNET_REINITIALIZED_STATE; } BACNET_REINITIALIZED_STATE;
#endif // end of BACENUM_H #endif /* end of BACENUM_H */
+15 -15
View File
@@ -36,20 +36,20 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "bacdef.h" #include "bacdef.h"
// encode service /* encode service */
int bacerror_encode_apdu(uint8_t * apdu, int bacerror_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_CONFIRMED_SERVICE service, BACNET_CONFIRMED_SERVICE service,
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code) 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) { if (apdu) {
apdu[0] = PDU_TYPE_ERROR; apdu[0] = PDU_TYPE_ERROR;
apdu[1] = invoke_id; apdu[1] = invoke_id;
apdu[2] = service; apdu[2] = service;
apdu_len = 3; 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_class);
apdu_len += encode_tagged_enumerated(&apdu[apdu_len], error_code); apdu_len += encode_tagged_enumerated(&apdu[apdu_len], error_code);
} }
@@ -57,7 +57,7 @@ int bacerror_encode_apdu(uint8_t * apdu,
return apdu_len; 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, int bacerror_decode_error_class_and_code(uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) 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; int decoded_value = 0;
if (apdu_len) { if (apdu_len) {
// error class /* error class */
len += decode_tag_number_and_value(&apdu[len], len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) 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); decode_enumerated(&apdu[len], len_value_type, &decoded_value);
if (error_class) if (error_class)
*error_class = decoded_value; *error_class = decoded_value;
// error code /* error code */
len += decode_tag_number_and_value(&apdu[len], len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
@@ -91,7 +91,7 @@ int bacerror_decode_error_class_and_code(uint8_t * apdu,
return len; return len;
} }
// decode the service request only /* decode the service request only */
int bacerror_decode_service_request(uint8_t * apdu, int bacerror_decode_service_request(uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t * invoke_id, uint8_t * invoke_id,
@@ -105,7 +105,7 @@ int bacerror_decode_service_request(uint8_t * apdu,
*invoke_id = apdu[0]; *invoke_id = apdu[0];
if (service) if (service)
*service = apdu[1]; *service = apdu[1];
// decode the application class and code /* decode the application class and code */
len = bacerror_decode_error_class_and_code(&apdu[2], len = bacerror_decode_error_class_and_code(&apdu[2],
apdu_len - 2, error_class, error_code); apdu_len - 2, error_class, error_code);
} }
@@ -113,7 +113,7 @@ int bacerror_decode_service_request(uint8_t * apdu,
return len; 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, int bacerror_decode_apdu(uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
uint8_t * invoke_id, uint8_t * invoke_id,
@@ -124,7 +124,7 @@ int bacerror_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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_len) {
if (apdu[0] != PDU_TYPE_ERROR) if (apdu[0] != PDU_TYPE_ERROR)
return -1; return -1;
@@ -171,7 +171,7 @@ void testBACError(Test * pTest)
ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_class == error_class);
ct_test(pTest, test_error_code == error_code); 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; apdu[0] = PDU_TYPE_ABORT;
len = bacerror_decode_apdu(&apdu[0], len = bacerror_decode_apdu(&apdu[0],
apdu_len, apdu_len,
@@ -179,14 +179,14 @@ void testBACError(Test * pTest)
&test_service, &test_error_class, &test_error_code); &test_service, &test_error_class, &test_error_code);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// test NULL APDU /* test NULL APDU */
len = bacerror_decode_apdu(NULL, len = bacerror_decode_apdu(NULL,
apdu_len, apdu_len,
&test_invoke_id, &test_invoke_id,
&test_service, &test_error_class, &test_error_code); &test_service, &test_error_class, &test_error_code);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// force a zero length /* force a zero length */
len = bacerror_decode_apdu(&apdu[0], len = bacerror_decode_apdu(&apdu[0],
0, 0,
&test_invoke_id, &test_invoke_id,
@@ -194,7 +194,7 @@ void testBACError(Test * pTest)
ct_test(pTest, len == 0); ct_test(pTest, len == 0);
// check them all... /* check them all... */
for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) { for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) {
for (error_class = 0; for (error_class = 0;
error_class < MAX_BACNET_ERROR_CLASS; error_class++) { error_class < MAX_BACNET_ERROR_CLASS; error_class++) {
@@ -217,7 +217,7 @@ void testBACError(Test * pTest)
} }
} }
// max boundaries /* max boundaries */
service = 255; service = 255;
error_class = LAST_PROPRIETARY_ERROR_CLASS; error_class = LAST_PROPRIETARY_ERROR_CLASS;
error_code = LAST_PROPRIETARY_ERROR_CODE; error_code = LAST_PROPRIETARY_ERROR_CODE;
+10 -10
View File
@@ -55,7 +55,7 @@ void bitstring_set_bit(BACNET_BIT_STRING * bit_string, uint8_t bit,
uint8_t bit_mask = 1; uint8_t bit_mask = 1;
if (byte_number < MAX_BITSTRING_BYTES) { if (byte_number < MAX_BITSTRING_BYTES) {
// set max bits used /* set max bits used */
if (bit_string->bits_used < (bit + 1)) if (bit_string->bits_used < (bit + 1))
bit_string->bits_used = bit + 1; bit_string->bits_used = bit + 1;
bit_mask = bit_mask << (bit - (byte_number * 8)); 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; 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 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 used_bytes = 0;
uint8_t last_bit = 0; uint8_t last_bit = 0;
if (bit_string->bits_used) { if (bit_string->bits_used) {
last_bit = bit_string->bits_used - 1; last_bit = bit_string->bits_used - 1;
used_bytes = last_bit / 8; used_bytes = last_bit / 8;
// add one for the first byte /* add one for the first byte */
used_bytes++; used_bytes++;
len = used_bytes; len = used_bytes;
} }
@@ -471,19 +471,19 @@ void testBitString(Test * pTest)
BACNET_BIT_STRING bit_string; BACNET_BIT_STRING bit_string;
bitstring_init(&bit_string); bitstring_init(&bit_string);
// verify initialization /* verify initialization */
ct_test(pTest, bitstring_bits_used(&bit_string) == 0); ct_test(pTest, bitstring_bits_used(&bit_string) == 0);
for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) {
ct_test(pTest, bitstring_bit(&bit_string, bit) == false); ct_test(pTest, bitstring_bit(&bit_string, bit) == false);
} }
// test for true /* test for true */
for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) {
bitstring_set_bit(&bit_string, bit, true); bitstring_set_bit(&bit_string, bit, true);
ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1)); ct_test(pTest, bitstring_bits_used(&bit_string) == (bit + 1));
ct_test(pTest, bitstring_bit(&bit_string, bit) == true); ct_test(pTest, bitstring_bit(&bit_string, bit) == true);
} }
// test for false /* test for false */
bitstring_init(&bit_string); bitstring_init(&bit_string);
for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) { for (bit = 0; bit < (MAX_BITSTRING_BYTES * 8); bit++) {
bitstring_set_bit(&bit_string, bit, false); bitstring_set_bit(&bit_string, bit, false);
@@ -504,7 +504,7 @@ void testCharacterString(Test * pTest)
size_t test_length = 0; size_t test_length = 0;
size_t i = 0; size_t i = 0;
// verify initialization /* verify initialization */
status = status =
characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0); characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0);
ct_test(pTest, status == true); ct_test(pTest, status == true);
@@ -562,7 +562,7 @@ void testOctetString(Test * pTest)
size_t test_length = 0; size_t test_length = 0;
size_t i = 0; size_t i = 0;
// verify initialization /* verify initialization */
status = octetstring_init(&bacnet_string, NULL, 0); status = octetstring_init(&bacnet_string, NULL, 0);
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, octetstring_length(&bacnet_string) == 0); ct_test(pTest, octetstring_length(&bacnet_string) == 0);
@@ -625,7 +625,7 @@ int main(void)
assert(rc); assert(rc);
rc = ct_addTestFunction(pTest, testOctetString); rc = ct_addTestFunction(pTest, testOctetString);
assert(rc); assert(rc);
// configure output /* configure output */
ct_setStream(pTest, stdout); ct_setStream(pTest, stdout);
ct_run(pTest); ct_run(pTest);
(void) ct_report(pTest); (void) ct_report(pTest);
+1 -1
View File
@@ -72,7 +72,7 @@ extern "C" {
bool value); bool value);
bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit); bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit);
uint8_t bitstring_bits_used(BACNET_BIT_STRING * bit_string); 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); int bitstring_bytes_used(BACNET_BIT_STRING * bit_string);
uint8_t bitstring_bits_capacity(BACNET_BIT_STRING * bit_string); uint8_t bitstring_bits_capacity(BACNET_BIT_STRING * bit_string);
/* used for encoding and decoding from the APDU */ /* used for encoding and decoding from the APDU */
+15 -15
View File
@@ -1,19 +1,19 @@
// Big-Endian systems save the most significant byte first. /* Big-Endian systems save the most significant byte first. */
// Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. /* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */
// "Network Byte Order" is also know as "Big-Endian Byte Order" /* "Network Byte Order" is also know as "Big-Endian Byte Order" */
// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. /* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
// x[0] = 0x04 /* x[0] = 0x04 */
// x[1] = 0x03 /* x[1] = 0x03 */
// x[2] = 0x02 /* x[2] = 0x02 */
// x[3] = 0x01 /* x[3] = 0x01 */
// Little-Endian systems save the least significant byte first. /* Little-Endian systems save the least significant byte first. */
// The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. /* The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. */
// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. /* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
// x[0] = 0x01 /* x[0] = 0x01 */
// x[1] = 0x02 /* x[1] = 0x02 */
// x[2] = 0x03 /* x[2] = 0x03 */
// x[3] = 0x04 /* x[3] = 0x04 */
int big_endian(void) int big_endian(void)
{ {
+14 -14
View File
@@ -5,21 +5,21 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// Big-Endian systems save the most significant byte first. /* Big-Endian systems save the most significant byte first. */
// Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. /* Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. */
// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. /* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
// x[0] = 0x04 /* x[0] = 0x04 */
// x[1] = 0x03 /* x[1] = 0x03 */
// x[2] = 0x02 /* x[2] = 0x02 */
// x[3] = 0x01 /* x[3] = 0x01 */
// Little-Endian systems save the least significant byte first. /* Little-Endian systems save the least significant byte first. */
// The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. /* The entire Intel x86 family, Vaxes, Alphas and PDP-11s are little-endian. */
// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. /* for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. */
// x[0] = 0x01 /* x[0] = 0x01 */
// x[1] = 0x02 /* x[1] = 0x02 */
// x[2] = 0x03 /* x[2] = 0x03 */
// x[3] = 0x04 /* x[3] = 0x04 */
int big_endian(void); int big_endian(void);
+36 -36
View File
@@ -32,11 +32,11 @@
------------------------------------------- -------------------------------------------
####COPYRIGHTEND####*/ ####COPYRIGHTEND####*/
#include <stdint.h> // for standard integer types uint8_t etc. #include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> // for the standard bool type. #include <stdbool.h> /* for the standard bool type. */
#include "bacdcode.h" #include "bacdcode.h"
#include "bip.h" #include "bip.h"
#include "net.h" // custom per port #include "net.h" /* custom per port */
static int BIP_Socket = -1; static int BIP_Socket = -1;
/* port to use - stored in host byte order */ /* port to use - stored in host byte order */
@@ -95,37 +95,37 @@ void bip_set_broadcast_address(uint8_t octet1,
octet4); octet4);
} }
// set using network byte order /* set using network byte order */
void bip_set_addr(uint32_t net_address) void bip_set_addr(uint32_t net_address)
{ {
BIP_Address.s_addr = ntohl(net_address); BIP_Address.s_addr = ntohl(net_address);
} }
// returns host byte order /* returns host byte order */
uint32_t bip_get_addr(void) uint32_t bip_get_addr(void)
{ {
return BIP_Address.s_addr; return BIP_Address.s_addr;
} }
// set using network byte order /* set using network byte order */
void bip_set_broadcast_addr(uint32_t net_address) void bip_set_broadcast_addr(uint32_t net_address)
{ {
BIP_Broadcast_Address.s_addr = ntohl(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) uint32_t bip_get_broadcast_addr(void)
{ {
return BIP_Broadcast_Address.s_addr; return BIP_Broadcast_Address.s_addr;
} }
// set using host byte order /* set using host byte order */
void bip_set_port(uint16_t port) void bip_set_port(uint16_t port)
{ {
BIP_Port = port; BIP_Port = port;
} }
// returns host byte order /* returns host byte order */
uint16_t bip_get_port(void) uint16_t bip_get_port(void)
{ {
return BIP_Port; 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) */ /* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */ /* 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 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 unsigned pdu_len)
{ { /* number of bytes of data */
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0; int mtu_len = 0;
int bytes_sent = 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) if (BIP_Socket < 0)
return BIP_Socket; 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) */ /* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */ /* returns number of bytes sent on success, negative number on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, // destination address int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) // number of bytes of data unsigned pdu_len)
{ { /* number of bytes of data */
struct sockaddr_in bip_dest; struct sockaddr_in bip_dest;
/* load destination IP address */ /* 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 */ /* function to send a packet out the BACnet/IP socket */
/* returns 1 on success, 0 on failure */ /* returns 1 on success, 0 on failure */
return bip_send(&bip_dest, // destination address return bip_send(&bip_dest, /* destination address */
pdu, // any data to be sent - may be null pdu, /* any data to be sent - may be null */
pdu_len); // number of bytes of data pdu_len); /* number of bytes of data */
} }
// receives a BACnet/IP packet /* receives a BACnet/IP packet */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t bip_receive(BACNET_ADDRESS * src, // source address uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) // number of milliseconds to wait for a packet unsigned timeout)
{ { /* number of milliseconds to wait for a packet */
int received_bytes; int received_bytes;
uint8_t buf[MAX_MPDU] = { 0 }; // data uint8_t buf[MAX_MPDU] = { 0 }; /* data */
uint16_t pdu_len = 0; // return value uint16_t pdu_len = 0; /* return value */
fd_set read_fds; fd_set read_fds;
int max; int max;
struct timeval select_timeout; struct timeval select_timeout;
@@ -259,16 +259,16 @@ uint16_t bip_receive(BACNET_ADDRESS * src, // source address
src->mac_len = 6; src->mac_len = 6;
(void) encode_unsigned32(&src->mac[0], sin.sin_addr.s_addr); (void) encode_unsigned32(&src->mac[0], sin.sin_addr.s_addr);
(void) encode_unsigned16(&src->mac[4], sin.sin_port); (void) encode_unsigned16(&src->mac[4], sin.sin_port);
// FIXME: check destination address /* FIXME: check destination address */
// see if it is broadcast or for us /* see if it is broadcast or for us */
/* decode the length of the PDU - length is inclusive of BVLC */ /* decode the length of the PDU - length is inclusive of BVLC */
(void) decode_unsigned16(&buf[2], &pdu_len); (void) decode_unsigned16(&buf[2], &pdu_len);
/* copy the buffer into the PDU */ /* copy the buffer into the PDU */
pdu_len -= 4; /* BVLC header */ pdu_len -= 4; /* BVLC header */
if (pdu_len < max_pdu) if (pdu_len < max_pdu)
memmove(&pdu[0], &buf[4], pdu_len); memmove(&pdu[0], &buf[4], pdu_len);
// ignore packets that are too large /* ignore packets that are too large */
// clients should check my max-apdu first /* clients should check my max-apdu first */
else else
pdu_len = 0; pdu_len = 0;
} }
@@ -295,9 +295,9 @@ void bip_get_my_address(BACNET_ADDRESS * my_address)
return; return;
} }
void bip_get_broadcast_address(BACNET_ADDRESS * dest) // destination address void bip_get_broadcast_address(BACNET_ADDRESS * dest)
{ { /* destination address */
int i = 0; // counter int i = 0; /* counter */
if (dest) { if (dest) {
dest->mac_len = 6; dest->mac_len = 6;
+19 -19
View File
@@ -40,7 +40,7 @@
#include "bacdef.h" #include "bacdef.h"
#include "net.h" #include "net.h"
// specific defines for Ethernet /* specific defines for Ethernet */
#define MAX_HEADER (1 + 1 + 2) #define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
@@ -48,47 +48,47 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// note: define init and cleanup in your ports section /* note: define init and cleanup in your ports section */
bool bip_init(void); bool bip_init(void);
// normal functions... /* normal functions... */
void bip_cleanup(void); void bip_cleanup(void);
void bip_set_socket(int sock_fd); void bip_set_socket(int sock_fd);
bool bip_valid(void); 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); void bip_get_my_address(BACNET_ADDRESS * my_address);
/* function to send a packet out the BACnet/IP socket */ /* function to send a packet out the BACnet/IP socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, // destination address int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
// receives a BACnet/IP packet /* receives a BACnet/IP packet */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t bip_receive(BACNET_ADDRESS * src, // source address uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); // milliseconds to wait for a packet unsigned timeout); /* milliseconds to wait for a packet */
void bip_set_address(uint8_t octet1, uint8_t octet2, void bip_set_address(uint8_t octet1, uint8_t octet2,
uint8_t octet3, uint8_t octet4); uint8_t octet3, uint8_t octet4);
void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2, void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2,
uint8_t octet3, uint8_t octet4); 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); void bip_set_port(uint16_t port);
// returns host byte order /* returns host byte order */
uint16_t bip_get_port(void); 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); void bip_set_addr(uint32_t net_address);
// returns host byte order /* returns host byte order */
uint32_t bip_get_addr(void); 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); void bip_set_broadcast_addr(uint32_t net_address);
// returns host byte order /* returns host byte order */
uint32_t bip_get_broadcast_addr(void); uint32_t bip_get_broadcast_addr(void);
void bip_set_interface(char *ifname); void bip_set_interface(char *ifname);
+2 -2
View File
@@ -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 #ifndef BYTES_H
@@ -67,4 +67,4 @@
#endif // end of header file #endif /* end of header file */
+21 -21
View File
@@ -1,32 +1,32 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
// declare a single physical layer /* declare a single physical layer */
//#include "ethernet.h" /*#include "ethernet.h" */
//#include "arcnet.h" /*#include "arcnet.h" */
//#include "mstp.h" /*#include "mstp.h" */
// Max number of bytes in an APDU. /* Max number of bytes in an APDU. */
// Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets /* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */
// This is used in constructing messages and to tell others our limits /* This is used in constructing messages and to tell others our limits */
// 50 is the minimum; adjust to your memory and physical layer constraints /* 50 is the minimum; adjust to your memory and physical layer constraints */
// Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 /* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */
//#define MAX_APDU 50 /*#define MAX_APDU 50 */
#define MAX_APDU 480 #define MAX_APDU 480
//#define MAX_APDU 1476 /*#define MAX_APDU 1476 */
// for confirmed messages, this is the number of transactions /* for confirmed messages, this is the number of transactions */
// that we hold in a queue waiting for timeout. /* that we hold in a queue waiting for timeout. */
// Configure to zero if you don't want any confirmed messages /* Configure to zero if you don't want any confirmed messages */
// Configure from 1..255 for number of outstanding confirmed /* Configure from 1..255 for number of outstanding confirmed */
// requests available. /* requests available. */
#define MAX_TSM_TRANSACTIONS 16 #define MAX_TSM_TRANSACTIONS 16
// The address cache is used for binding to BACnet devices /* The address cache is used for binding to BACnet devices */
// The number of entries corresponds to the number of /* The number of entries corresponds to the number of */
// devices that might respond to an I-Am on the network. /* devices that might respond to an I-Am on the network. */
// If your device is a simple server and does not need to bind, /* If your device is a simple server and does not need to bind, */
// then you don't need to use this. /* then you don't need to use this. */
#define MAX_ADDRESS_CACHE 255 #define MAX_ADDRESS_CACHE 255
#endif #endif
+19 -19
View File
@@ -36,11 +36,11 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
// Accumulate "dataValue" into the CRC in crcValue. /* Accumulate "dataValue" into the CRC in crcValue. */
// Return value is updated CRC /* Return value is updated CRC */
// /* */
// The ^ operator means exclusive OR. /* The ^ operator means exclusive OR. */
// Note: This function is copied directly from the BACnet standard. /* Note: This function is copied directly from the BACnet standard. */
uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue) uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue)
{ {
uint16_t crc; uint16_t crc;
@@ -56,11 +56,11 @@ uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue)
return (crc & 0xfe) ^ ((crc >> 8) & 1); return (crc & 0xfe) ^ ((crc >> 8) & 1);
} }
// Accumulate "dataValue" into the CRC in crcValue. /* Accumulate "dataValue" into the CRC in crcValue. */
// Return value is updated CRC /* Return value is updated CRC */
// /* */
// The ^ operator means exclusive OR. /* The ^ operator means exclusive OR. */
// Note: This function is copied directly from the BACnet standard. /* Note: This function is copied directly from the BACnet standard. */
uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
{ {
uint16_t crcLow; uint16_t crcLow;
@@ -79,11 +79,11 @@ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
#include "ctest.h" #include "ctest.h"
#include "bytes.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) void testCRC8(Test * pTest)
{ {
uint8_t crc = 0xff; // accumulates the crc value uint8_t crc = 0xff; /* accumulates the crc value */
uint8_t frame_crc; // appended to the end of the frame uint8_t frame_crc; /* appended to the end of the frame */
crc = CRC_Calc_Header(0x00, crc); crc = CRC_Calc_Header(0x00, crc);
ct_test(pTest, crc == 0x55); ct_test(pTest, crc == 0x55);
@@ -95,16 +95,16 @@ void testCRC8(Test * pTest)
ct_test(pTest, crc == 0x95); ct_test(pTest, crc == 0x95);
crc = CRC_Calc_Header(0x00, crc); crc = CRC_Calc_Header(0x00, crc);
ct_test(pTest, crc == 0x73); ct_test(pTest, crc == 0x73);
// send the ones complement of the CRC in place of /* send the ones complement of the CRC in place of */
// the CRC, and the resulting CRC will always equal 0x55. /* the CRC, and the resulting CRC will always equal 0x55. */
frame_crc = ~crc; frame_crc = ~crc;
ct_test(pTest, frame_crc == 0x8C); 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); crc = CRC_Calc_Header(frame_crc, crc);
ct_test(pTest, crc == 0x55); 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) void testCRC16(Test * pTest)
{ {
uint16_t crc = 0xffff; uint16_t crc = 0xffff;
@@ -116,8 +116,8 @@ void testCRC16(Test * pTest)
ct_test(pTest, crc == 0xEB70); ct_test(pTest, crc == 0xEB70);
crc = CRC_Calc_Data(0x30, crc); crc = CRC_Calc_Data(0x30, crc);
ct_test(pTest, crc == 0x42EF); ct_test(pTest, crc == 0x42EF);
// send the ones complement of the CRC in place of /* send the ones complement of the CRC in place of */
// the CRC, and the resulting CRC will always equal 0xF0B8. /* the CRC, and the resulting CRC will always equal 0xF0B8. */
data_crc = ~crc; data_crc = ~crc;
ct_test(pTest, data_crc == 0xBD10); ct_test(pTest, data_crc == 0xBD10);
crc = CRC_Calc_Data(LO_BYTE(data_crc), crc); crc = CRC_Calc_Data(LO_BYTE(data_crc), crc);
+16 -16
View File
@@ -35,16 +35,16 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "datalink.h" #include "datalink.h"
// currently this is oriented to a single data link /* currently this is oriented to a single data link */
// However, it could handle multiple data links with the /* However, it could handle multiple data links with the */
// addition of passing a network number or datalink number /* addition of passing a network number or datalink number */
// as part of the calls. /* as part of the calls. */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, // destination address int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) // number of bytes of data unsigned pdu_len)
{ { /* number of bytes of data */
#ifdef BACDL_ARCNET #ifdef BACDL_ARCNET
return arcnet_send_pdu(dest, pdu, pdu_len); return arcnet_send_pdu(dest, pdu, pdu_len);
#endif #endif
@@ -59,12 +59,12 @@ int datalink_send_pdu(BACNET_ADDRESS * dest, // destination address
#endif #endif
} }
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t datalink_receive(BACNET_ADDRESS * src, // source address uint16_t datalink_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) // number of milliseconds to wait for a packet unsigned timeout)
{ { /* number of milliseconds to wait for a packet */
#ifdef BACDL_ARCNET #ifdef BACDL_ARCNET
return arcnet_receive(src, pdu, max_pdu, timeout); return arcnet_receive(src, pdu, max_pdu, timeout);
#endif #endif
@@ -95,8 +95,8 @@ void datalink_cleanup(void)
#endif #endif
} }
void datalink_get_broadcast_address(BACNET_ADDRESS * dest) // destination address void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
{ { /* destination address */
#ifdef BACDL_ARCNET #ifdef BACDL_ARCNET
arcnet_get_broadcast_address(dest); arcnet_get_broadcast_address(dest);
#endif #endif
+9 -9
View File
@@ -60,19 +60,19 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu(BACNET_ADDRESS * dest, // destination address int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t datalink_receive(BACNET_ADDRESS * src, // source address uint16_t datalink_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); // number of milliseconds to wait for a packet unsigned timeout); /* number of milliseconds to wait for a packet */
void datalink_cleanup(void); 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); void datalink_get_my_address(BACNET_ADDRESS * my_address);
+2 -2
View File
@@ -213,10 +213,10 @@ int dcc_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE)
return -1; return -1;
+2 -2
View File
@@ -57,11 +57,11 @@ extern "C" {
bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE
status, uint16_t minutes); status, uint16_t minutes);
// encode service /* encode service */
int dcc_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint16_t timeDuration, /* 0=optional */ 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 */ 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, int dcc_decode_service_request(uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
uint16_t * timeDuration, uint16_t * timeDuration,
+1 -1
View File
@@ -58,7 +58,7 @@ extern "C" {
BACNET_PROPERTY_ID object_property, int32_t array_index); BACNET_PROPERTY_ID object_property, int32_t array_index);
/* returns the invoke ID for confirmed request, or 0 if failed */ /* 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, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_ID object_property, BACNET_PROPERTY_ID object_property,
+6 -6
View File
@@ -59,12 +59,12 @@ void handler_atomic_read_file(uint8_t * service_request,
len = arf_decode_service_request(service_request, service_len, &data); len = arf_decode_service_request(service_request, service_len, &data);
if (len < 0) if (len < 0)
fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n"); fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n");
// prepare a reply /* prepare a reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); MESSAGE_PRIORITY_NORMAL);
// bad decoding - send an abort /* bad decoding - send an abort */
if (len < 0) { if (len < 0) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
@@ -112,8 +112,8 @@ void handler_atomic_read_file(uint8_t * service_request,
send = true; send = true;
} }
if (send) { if (send) {
bytes_sent = datalink_send_pdu(src, // destination address bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
} }
+8 -8
View File
@@ -41,11 +41,11 @@
#include "handlers.h" #include "handlers.h"
#include "txbuf.h" #include "txbuf.h"
// We performed an AtomicReadFile Request, /* We performed an AtomicReadFile Request, */
// and here is the data from the server /* and here is the data from the server */
// Note: it does not have to be the same file=instance /* Note: it does not have to be the same file=instance */
// that someone can read from us. It is common to /* that someone can read from us. It is common to */
// use the description as the file name. /* use the description as the file name. */
#if BACFILE #if BACFILE
void handler_atomic_read_file_ack(uint8_t * service_request, void handler_atomic_read_file_ack(uint8_t * service_request,
uint16_t service_len, uint16_t service_len,
@@ -58,13 +58,13 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
uint32_t instance = 0; uint32_t instance = 0;
(void) src; (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); instance = bacfile_instance_from_tsm(service_data->invoke_id);
len = arf_ack_decode_service_request(service_request, len = arf_ack_decode_service_request(service_request,
service_len, &data); service_len, &data);
fprintf(stderr, "Received Read-File Ack!\n"); fprintf(stderr, "Received Read-File Ack!\n");
if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) { 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) { if (data.access == FILE_STREAM_ACCESS) {
pFilename = bacfile_name(instance); pFilename = bacfile_name(instance);
if (pFilename) { if (pFilename) {
@@ -81,7 +81,7 @@ void handler_atomic_read_file_ack(uint8_t * service_request,
} }
} }
} else if (data.access == FILE_RECORD_ACCESS) { } else if (data.access == FILE_RECORD_ACCESS) {
// FIXME: add handling for Record Access /* FIXME: add handling for Record Access */
} }
} }
} }
+7 -7
View File
@@ -52,7 +52,7 @@ void handler_device_communication_control(uint8_t * service_request,
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
int bytes_sent = 0; int bytes_sent = 0;
// decode the service request only /* decode the service request only */
len = dcc_decode_service_request(service_request, len = dcc_decode_service_request(service_request,
service_len, &timeDuration, &state, &password); service_len, &timeDuration, &state, &password);
fprintf(stderr, "DeviceCommunicationControl!\n"); fprintf(stderr, "DeviceCommunicationControl!\n");
@@ -64,12 +64,12 @@ void handler_device_communication_control(uint8_t * service_request,
else else
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Unable to decode request!\n"); "Unable to decode request!\n");
// prepare a reply /* prepare a reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); 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) { if (len == -1) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER); 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"); "Sending Error - password failure.\n");
} }
} }
bytes_sent = datalink_send_pdu(src, // destination address bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "DeviceCommunicationControl: " fprintf(stderr, "DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n", strerror(errno)); "Failed to send PDU (%s)!\n", strerror(errno));
+1 -1
View File
@@ -66,7 +66,7 @@ void handler_i_am_bind(uint8_t * service_request,
(void) service_len; (void) service_len;
len = iam_decode_service_request(service_request, len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id); &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); address_add_binding(device_id, max_apdu, src);
return; return;
+7 -7
View File
@@ -51,7 +51,7 @@ void handler_reinitialize_device(uint8_t * service_request,
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
int bytes_sent = 0; int bytes_sent = 0;
// decode the service request only /* decode the service request only */
len = rd_decode_service_request(service_request, len = rd_decode_service_request(service_request,
service_len, &state, &password); service_len, &state, &password);
fprintf(stderr, "ReinitializeDevice!\n"); fprintf(stderr, "ReinitializeDevice!\n");
@@ -60,12 +60,12 @@ void handler_reinitialize_device(uint8_t * service_request,
(unsigned) state, characterstring_value(&password)); (unsigned) state, characterstring_value(&password));
else else
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
// prepare a reply /* prepare a reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); 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) { if (len == -1) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER); 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"); "ReinitializeDevice: Sending Error - password failure.\n");
} }
} }
bytes_sent = datalink_send_pdu(src, // destination address bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno)); strerror(errno));
+15 -15
View File
@@ -62,12 +62,12 @@ void handler_read_property(uint8_t * service_request,
len = rp_decode_service_request(service_request, service_len, &data); len = rp_decode_service_request(service_request, service_len, &data);
if (len <= 0) if (len <= 0)
fprintf(stderr, "Unable to decode Read-Property Request!\n"); fprintf(stderr, "Unable to decode Read-Property Request!\n");
// prepare a reply /* prepare a reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); MESSAGE_PRIORITY_NORMAL);
// bad decoding - send an abort /* bad decoding - send an abort */
if (len == -1) { if (len == -1) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
@@ -82,16 +82,16 @@ void handler_read_property(uint8_t * service_request,
} else { } else {
switch (data.object_type) { switch (data.object_type) {
case OBJECT_DEVICE: 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()) { if (data.object_instance == Device_Object_Instance_Number()) {
len = Device_Encode_Property_APDU(&Temp_Buf[0], len = Device_Encode_Property_APDU(&Temp_Buf[0],
data.object_property, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { 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 = &Temp_Buf[0];
data.application_data_len = len; 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 += pdu_len +=
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
@@ -109,10 +109,10 @@ void handler_read_property(uint8_t * service_request,
data.object_property, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { 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 = &Temp_Buf[0];
data.application_data_len = len; 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 += pdu_len +=
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
@@ -130,10 +130,10 @@ void handler_read_property(uint8_t * service_request,
data.object_property, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { 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 = &Temp_Buf[0];
data.application_data_len = len; 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 += pdu_len +=
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
@@ -152,10 +152,10 @@ void handler_read_property(uint8_t * service_request,
data.object_property, data.object_property,
data.array_index, &error_class, &error_code); data.array_index, &error_class, &error_code);
if (len >= 0) { 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 = &Temp_Buf[0];
data.application_data_len = len; 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 += pdu_len +=
rp_ack_encode_apdu(&Handler_Transmit_Buffer rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data); [pdu_len], service_data->invoke_id, &data);
@@ -180,8 +180,8 @@ void handler_read_property(uint8_t * service_request,
send = true; send = true;
} }
if (send) { if (send) {
bytes_sent = datalink_send_pdu(src, // destination address bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
} }
+7 -7
View File
@@ -55,7 +55,7 @@ void handler_write_property(uint8_t * service_request,
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
int bytes_sent = 0; int bytes_sent = 0;
// decode the service request only /* decode the service request only */
len = wp_decode_service_request(service_request, len = wp_decode_service_request(service_request,
service_len, &wp_data); service_len, &wp_data);
fprintf(stderr, "Received Write-Property Request!\n"); 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); wp_data.object_property, wp_data.array_index);
else else
fprintf(stderr, "Unable to decode Write-Property Request!\n"); fprintf(stderr, "Unable to decode Write-Property Request!\n");
// prepare a reply /* prepare a reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); 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) { if (len == -1) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER); service_data->invoke_id, ABORT_REASON_OTHER);
@@ -134,8 +134,8 @@ void handler_write_property(uint8_t * service_request,
break; break;
} }
} }
bytes_sent = datalink_send_pdu(src, // destination address bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+5 -5
View File
@@ -46,16 +46,16 @@ void handler_unrecognized_service(uint8_t * service_request,
(void) service_len; (void) service_len;
datalink_get_my_address(&src); datalink_get_my_address(&src);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); 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], pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
bytes_sent = datalink_send_pdu(dest, // destination address bytes_sent = datalink_send_pdu(dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent > 0) if (bytes_sent > 0)
fprintf(stderr, "Sent Reject!\n"); fprintf(stderr, "Sent Reject!\n");
else else
+4 -4
View File
@@ -63,11 +63,11 @@ uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t t
status = tsm_transaction_available(); status = tsm_transaction_available();
if (status) { if (status) {
datalink_get_my_address(&my_address); 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); MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
// load the data for the encoding /* load the data for the encoding */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
pdu_len += dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, 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) { if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send DeviceCommunicationControl Request (%s)!\n", "Failed to Send DeviceCommunicationControl Request (%s)!\n",
+2 -2
View File
@@ -68,8 +68,8 @@ void Send_I_Have(uint32_t device_id,
characterstring_init_ansi(&data.object_name, object_name); characterstring_init_ansi(&data.object_name, object_name);
pdu_len += ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
strerror(errno)); strerror(errno));
+4 -4
View File
@@ -64,11 +64,11 @@ uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
status = tsm_transaction_available(); status = tsm_transaction_available();
if (status) { if (status) {
datalink_get_my_address(&my_address); 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); MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
// load the data for the encoding /* load the data for the encoding */
characterstring_init_ansi(&password_string, password); characterstring_init_ansi(&password_string, password);
pdu_len += rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, state, password ? &password_string : NULL); 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) { if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReinitializeDevice Request (%s)!\n", "Failed to Send ReinitializeDevice Request (%s)!\n",
+4 -4
View File
@@ -67,11 +67,11 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
status = tsm_transaction_available(); status = tsm_transaction_available();
if (status) { if (status) {
datalink_get_my_address(&my_address); 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); MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); 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_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
data.object_property = object_property; 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) { if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send ReadProperty Request (%s)!\n", "Failed to Send ReadProperty Request (%s)!\n",
+4 -4
View File
@@ -67,8 +67,8 @@ void Send_WhoHas_Name(int32_t low_limit,
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
&data); &data);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
@@ -101,8 +101,8 @@ void Send_WhoHas_Object(int32_t low_limit,
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
&data); &data);
/* send the data */ /* send the data */
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
strerror(errno)); strerror(errno));
+6 -6
View File
@@ -52,19 +52,19 @@ void Send_WhoIs(int32_t low_limit, int32_t high_limit)
if (!dcc_communication_enabled()) if (!dcc_communication_enabled())
return; return;
// Who-Is is a global broadcast /* Who-Is is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
// encode the NPDU portion of the packet /* 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); 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], pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
low_limit, high_limit); low_limit, high_limit);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
strerror(errno)); strerror(errno));
+5 -5
View File
@@ -43,7 +43,7 @@
#include "txbuf.h" #include "txbuf.h"
/* returns the invoke ID for confirmed request, or zero on failure */ /* 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, BACNET_OBJECT_TYPE object_type,
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_ID object_property, 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(); status = tsm_transaction_available();
if (status) { if (status) {
datalink_get_my_address(&my_address); 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); MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); 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_type = object_type;
data.object_instance = object_instance; data.object_instance = object_instance;
data.object_property = object_property; 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) { if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send WriteProperty Request (%s)!\n", "Failed to Send WriteProperty Request (%s)!\n",
+12 -12
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
// Analog Input Objects customize for your use /* Analog Input Objects customize for your use */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@@ -31,13 +31,13 @@
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacenum.h" #include "bacenum.h"
#include "config.h" // the custom stuff #include "config.h" /* the custom stuff */
#define MAX_ANALOG_INPUTS 7 #define MAX_ANALOG_INPUTS 7
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then you need validate that the /* more complex, and then you need validate that the */
// given instance exists /* given instance exists */
bool Analog_Input_Valid_Instance(uint32_t object_instance) bool Analog_Input_Valid_Instance(uint32_t object_instance)
{ {
if (object_instance < MAX_ANALOG_INPUTS) if (object_instance < MAX_ANALOG_INPUTS)
@@ -46,16 +46,16 @@ bool Analog_Input_Valid_Instance(uint32_t object_instance)
return false; return false;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then count how many you have /* more complex, and then count how many you have */
unsigned Analog_Input_Count(void) unsigned Analog_Input_Count(void)
{ {
return MAX_ANALOG_INPUTS; return MAX_ANALOG_INPUTS;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then you need to return the instance /* more complex, and then you need to return the instance */
// that correlates to the correct index /* that correlates to the correct index */
uint32_t Analog_Input_Index_To_Instance(unsigned index) uint32_t Analog_Input_Index_To_Instance(unsigned index)
{ {
return index; return index;
@@ -81,7 +81,7 @@ int Analog_Input_Encode_Property_APDU(uint8_t * apdu,
int32_t array_index, int32_t array_index,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) 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_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
float value = 3.14; float value = 3.14;
@@ -149,7 +149,7 @@ void testAnalogInput(Test * pTest)
BACNET_ERROR_CODE error_code; 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], len = Analog_Input_Encode_Property_APDU(&apdu[0],
instance, instance,
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_IDENTIFIER,
+37 -37
View File
@@ -23,7 +23,7 @@
* *
*********************************************************************/ *********************************************************************/
// Analog Output Objects - customize for your use /* Analog Output Objects - customize for your use */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@@ -31,28 +31,28 @@
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacenum.h" #include "bacenum.h"
#include "config.h" // the custom stuff #include "config.h" /* the custom stuff */
#include "wp.h" #include "wp.h"
#define MAX_ANALOG_OUTPUTS 4 #define MAX_ANALOG_OUTPUTS 4
// we choose to have a NULL level in our system represented by /* we choose to have a NULL level in our system represented by */
// a particular value. When the priorities are not in use, they /* a particular value. When the priorities are not in use, they */
// will be relinquished (i.e. set to the NULL level). /* will be relinquished (i.e. set to the NULL level). */
#define AO_LEVEL_NULL 255 #define AO_LEVEL_NULL 255
// When all the priorities are level null, the present value returns /* When all the priorities are level null, the present value returns */
// the Relinquish Default value /* the Relinquish Default value */
#define AO_RELINQUISH_DEFAULT 0 #define AO_RELINQUISH_DEFAULT 0
// Here is our Priority Array. They are supposed to be Real, but /* 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 /* 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. /* and load a Real for returning the value when asked. */
static uint8_t static uint8_t
Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY]; Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY];
// Writable out-of-service allows others to play with our Present Value /* Writable out-of-service allows others to play with our Present Value */
// without changing the physical output /* without changing the physical output */
static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS]; 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; static bool Analog_Ouput_Initialized = false;
void Analog_Output_Init(void) void Analog_Output_Init(void)
@@ -62,7 +62,7 @@ void Analog_Output_Init(void)
if (!Analog_Ouput_Initialized) { if (!Analog_Ouput_Initialized) {
Analog_Ouput_Initialized = true; 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 (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
for (j = 0; j < BACNET_MAX_PRIORITY; j++) { for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
Analog_Output_Level[i][j] = AO_LEVEL_NULL; Analog_Output_Level[i][j] = AO_LEVEL_NULL;
@@ -73,9 +73,9 @@ void Analog_Output_Init(void)
return; return;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then you need validate that the /* more complex, and then you need validate that the */
// given instance exists /* given instance exists */
bool Analog_Output_Valid_Instance(uint32_t object_instance) bool Analog_Output_Valid_Instance(uint32_t object_instance)
{ {
Analog_Output_Init(); Analog_Output_Init();
@@ -85,26 +85,26 @@ bool Analog_Output_Valid_Instance(uint32_t object_instance)
return false; return false;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then count how many you have /* more complex, and then count how many you have */
unsigned Analog_Output_Count(void) unsigned Analog_Output_Count(void)
{ {
Analog_Output_Init(); Analog_Output_Init();
return MAX_ANALOG_OUTPUTS; return MAX_ANALOG_OUTPUTS;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then you need to return the instance /* more complex, and then you need to return the instance */
// that correlates to the correct index /* that correlates to the correct index */
uint32_t Analog_Output_Index_To_Instance(unsigned index) uint32_t Analog_Output_Index_To_Instance(unsigned index)
{ {
Analog_Output_Init(); Analog_Output_Init();
return index; return index;
} }
// we simply have 0-n object instances. Yours might be /* we simply have 0-n object instances. Yours might be */
// more complex, and then you need to return the index /* more complex, and then you need to return the index */
// that correlates to the correct instance number /* that correlates to the correct instance number */
unsigned Analog_Output_Instance_To_Index(uint32_t object_instance) unsigned Analog_Output_Instance_To_Index(uint32_t object_instance)
{ {
unsigned index = MAX_ANALOG_OUTPUTS; 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) BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
{ {
int len = 0; int len = 0;
int apdu_len = 0; // return value int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string; BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
float real_value = 1.414; 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); apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT);
break; break;
case PROP_PRIORITY_ARRAY: 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) if (array_index == BACNET_ARRAY_LENGTH_INDEX)
apdu_len = apdu_len =
encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY);
// if no index was specified, then try to encode the entire list /* if no index was specified, then try to encode the entire list */
// into one packet. /* into one packet. */
else if (array_index == BACNET_ARRAY_ALL) { else if (array_index == BACNET_ARRAY_ALL) {
object_index = object_index =
Analog_Output_Instance_To_Index(object_instance); Analog_Output_Instance_To_Index(object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) { 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) if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL)
len = encode_tagged_null(&apdu[apdu_len]); len = encode_tagged_null(&apdu[apdu_len]);
else { else {
real_value = Analog_Output_Level[object_index][i]; real_value = Analog_Output_Level[object_index][i];
len = encode_tagged_real(&apdu[apdu_len], real_value); 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) if ((apdu_len + len) < MAX_APDU)
apdu_len += len; apdu_len += len;
else { else {
@@ -263,11 +263,11 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// returns true if successful /* returns true if successful */
bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) 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 object_index = 0;
unsigned int priority = 0; unsigned int priority = 0;
uint8_t level = AO_LEVEL_NULL; 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; *error_code = ERROR_CODE_UNKNOWN_OBJECT;
return false; return false;
} }
// decode the some of the request /* decode the some of the request */
switch (wp_data->object_property) { switch (wp_data->object_property) {
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL) { 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); object_instance);
priority--; priority--;
Analog_Output_Level[object_index][priority] = level; Analog_Output_Level[object_index][priority] = level;
// if Out of Service is TRUE, then don't set the /* if Out of Service is TRUE, then don't set the */
// physical output. This comment may apply to the /* physical output. This comment may apply to the */
// main loop (i.e. check out of service before changing output) /* main loop (i.e. check out of service before changing output) */
status = true; status = true;
} else if (priority == 6) { } else if (priority == 6) {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
+26 -26
View File
@@ -48,7 +48,7 @@ static BACNET_FILE_LISTING BACnet_File_Listing[] = {
{0, "test.log"}, {0, "test.log"},
{1, "script.txt"}, {1, "script.txt"},
{2, "bacenum.h"}, {2, "bacenum.h"},
{0, NULL} // last file indication {0, NULL} /* last file indication */
}; };
char *bacfile_name(uint32_t instance) char *bacfile_name(uint32_t instance)
@@ -56,7 +56,7 @@ char *bacfile_name(uint32_t instance)
uint32_t index = 0; uint32_t index = 0;
char *filename = NULL; char *filename = NULL;
// linear search for file instance match /* linear search for file instance match */
while (BACnet_File_Listing[index].filename) { while (BACnet_File_Listing[index].filename) {
if (BACnet_File_Listing[index].instance == instance) { if (BACnet_File_Listing[index].instance == instance) {
filename = BACnet_File_Listing[index].filename; filename = BACnet_File_Listing[index].filename;
@@ -77,7 +77,7 @@ uint32_t bacfile_count(void)
{ {
uint32_t index = 0; uint32_t index = 0;
// linear search for file instance match /* linear search for file instance match */
while (BACnet_File_Listing[index].filename) { while (BACnet_File_Listing[index].filename) {
index++; index++;
} }
@@ -90,7 +90,7 @@ uint32_t bacfile_index_to_instance(unsigned find_index)
uint32_t instance = BACNET_MAX_INSTANCE + 1; uint32_t instance = BACNET_MAX_INSTANCE + 1;
uint32_t index = 0; uint32_t index = 0;
// bounds checking... /* bounds checking... */
while (BACnet_File_Listing[index].filename) { while (BACnet_File_Listing[index].filename) {
if (index == find_index) { if (index == find_index) {
instance = BACnet_File_Listing[index].instance; instance = BACnet_File_Listing[index].instance;
@@ -141,7 +141,7 @@ int bacfile_encode_property_apdu(uint8_t * apdu,
int32_t array_index, int32_t array_index,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) 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] = { "" }; char text_string[32] = { "" };
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
@@ -173,18 +173,18 @@ int bacfile_encode_property_apdu(uint8_t * apdu,
bacfile_file_size(object_instance)); bacfile_file_size(object_instance));
break; break;
case PROP_MODIFICATION_DATE: case PROP_MODIFICATION_DATE:
// FIXME: get the actual value /* FIXME: get the actual value */
apdu_len = encode_tagged_date(&apdu[0], apdu_len = encode_tagged_date(&apdu[0],
2005, 12, 25, 7 /* sunday */ ); 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); apdu_len += encode_tagged_time(&apdu[apdu_len], 12, 0, 0, 0);
break; break;
case PROP_ARCHIVE: 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); apdu_len = encode_tagged_boolean(&apdu[0], true);
break; break;
case PROP_READ_ONLY: case PROP_READ_ONLY:
// FIXME: get the actual value /* FIXME: get the actual value */
apdu_len = encode_tagged_boolean(&apdu[0], true); apdu_len = encode_tagged_boolean(&apdu[0], true);
break; break;
case PROP_FILE_ACCESS_METHOD: case PROP_FILE_ACCESS_METHOD:
@@ -205,7 +205,7 @@ uint32_t bacfile_instance(char *filename)
uint32_t index = 0; uint32_t index = 0;
uint32_t instance = BACNET_MAX_INSTANCE + 1; uint32_t instance = BACNET_MAX_INSTANCE + 1;
// linear search for filename match /* linear search for filename match */
while (BACnet_File_Listing[index].filename) { while (BACnet_File_Listing[index].filename) {
if (strcmp(BACnet_File_Listing[index].filename, filename) == 0) { if (strcmp(BACnet_File_Listing[index].filename, filename) == 0) {
instance = BACnet_File_Listing[index].instance; instance = BACnet_File_Listing[index].instance;
@@ -218,37 +218,37 @@ uint32_t bacfile_instance(char *filename)
} }
#if TSM_ENABLED #if TSM_ENABLED
// this is one way to match up the invoke ID with /* this is one way to match up the invoke ID with */
// the file ID from the AtomicReadFile request. /* the file ID from the AtomicReadFile request. */
// Another way would be to store the /* Another way would be to store the */
// invokeID and file instance in a list or table /* invokeID and file instance in a list or table */
// when the request was sent /* when the request was sent */
uint32_t bacfile_instance_from_tsm(uint8_t invokeID) 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 }; BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
uint8_t service_choice = 0; uint8_t service_choice = 0;
uint8_t *service_request = NULL; uint8_t *service_request = NULL;
uint16_t service_request_len = 0; uint16_t service_request_len = 0;
BACNET_ADDRESS dest; // where the original packet was destined BACNET_ADDRESS dest; /* where the original packet was destined */
uint8_t pdu[MAX_PDU] = { 0 }; // original sent packet uint8_t pdu[MAX_PDU] = { 0 }; /* original sent packet */
uint16_t pdu_len = 0; // original packet length uint16_t pdu_len = 0; /* original packet length */
uint16_t len = 0; // apdu header length uint16_t len = 0; /* apdu header length */
BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; 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; bool found = false;
int apdu_offset = 0; int apdu_offset = 0;
found = tsm_get_transaction_pdu(invokeID, &dest, &pdu[0], &pdu_len); found = tsm_get_transaction_pdu(invokeID, &dest, &pdu[0], &pdu_len);
if (found) { if (found) {
apdu_offset = npdu_decode(&pdu[0], // data to decode apdu_offset = npdu_decode(&pdu[0], /* data to decode */
NULL, // destination address - get the DNET/DLEN/DADR if in there NULL, /* destination address - get the DNET/DLEN/DADR if in there */
NULL, // source address - get the SNET/SLEN/SADR if in there NULL, /* source address - get the SNET/SLEN/SADR if in there */
&npdu_data); // amount of data to decode &npdu_data); /* amount of data to decode */
if (!npdu_data.network_layer_message && if (!npdu_data.network_layer_message &&
((pdu[apdu_offset] & 0xF0) == ((pdu[apdu_offset] & 0xF0) ==
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { 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, pdu_len - apdu_offset,
&service_data, &service_data,
&service_choice, &service_request, &service_request_len); &service_choice, &service_request, &service_request_len);
+7 -7
View File
@@ -51,18 +51,18 @@ extern "C" {
uint32_t bacfile_index_to_instance(unsigned find_index); uint32_t bacfile_index_to_instance(unsigned find_index);
uint32_t bacfile_instance(char *filename); uint32_t bacfile_instance(char *filename);
#if TSM_ENABLED #if TSM_ENABLED
// this is one way to match up the invoke ID with /* this is one way to match up the invoke ID with */
// the file ID from the AtomicReadFile request. /* the file ID from the AtomicReadFile request. */
// Another way would be to store the /* Another way would be to store the */
// invokeID and file instance in a list or table /* invokeID and file instance in a list or table */
// when the request was sent /* when the request was sent */
uint32_t bacfile_instance_from_tsm(uint8_t invokeID); uint32_t bacfile_instance_from_tsm(uint8_t invokeID);
#endif #endif
// AtomicReadFile ACK helper /* AtomicReadFile ACK helper */
bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data); 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, int bacfile_encode_property_apdu(uint8_t * apdu,
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_ID property, BACNET_PROPERTY_ID property,
+44 -44
View File
@@ -107,7 +107,7 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id)
bool Device_Valid_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) || return ((Object_Instance_Number == object_id) ||
(object_id == BACNET_MAX_INSTANCE)); (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) void Device_Set_System_Status(BACNET_DEVICE_STATUS status)
{ {
// FIXME: bounds check? /* FIXME: bounds check? */
System_Status = status; System_Status = status;
} }
@@ -285,7 +285,7 @@ uint16_t Device_APDU_Timeout(void)
return APDU_Timeout; return APDU_Timeout;
} }
// in milliseconds /* in milliseconds */
void Device_Set_APDU_Timeout(uint16_t timeout) void Device_Set_APDU_Timeout(uint16_t timeout)
{ {
APDU_Timeout = timeout; APDU_Timeout = timeout;
@@ -311,8 +311,8 @@ void Device_Set_Database_Revision(uint8_t revision)
Database_Revision = revision; Database_Revision = revision;
} }
// Since many network clients depend on the object list /* Since many network clients depend on the object list */
// for discovery, it must be consistent! /* for discovery, it must be consistent! */
unsigned Device_Object_List_Count(void) unsigned Device_Object_List_Count(void)
{ {
unsigned count = 1; unsigned count = 1;
@@ -339,7 +339,7 @@ bool Device_Object_List_Identifier(unsigned array_index,
} }
if (!status) { 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; object_index = array_index - 2;
if (object_index < Analog_Input_Count()) { if (object_index < Analog_Input_Count()) {
*object_type = OBJECT_ANALOG_INPUT; *object_type = OBJECT_ANALOG_INPUT;
@@ -426,14 +426,14 @@ char *Device_Valid_Object_Id(int object_type, uint32_t object_instance)
return name; 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, int Device_Encode_Property_APDU(uint8_t * apdu,
BACNET_PROPERTY_ID property, BACNET_PROPERTY_ID property,
int32_t array_index, int32_t array_index,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
{ {
int apdu_len = 0; // return value int apdu_len = 0; /* return value */
int len = 0; // apdu len intermediate value int len = 0; /* apdu len intermediate value */
BACNET_BIT_STRING bit_string; BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING char_string;
unsigned i = 0; unsigned i = 0;
@@ -480,31 +480,31 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
Application_Software_Version); Application_Software_Version);
apdu_len = encode_tagged_character_string(&apdu[0], &char_string); apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break; break;
// if you support time /* if you support time */
//case PROP_LOCAL_TIME: /*case PROP_LOCAL_TIME: */
//t = time(NULL); /*t = time(NULL); */
//my_tm = localtime(&t); /*my_tm = localtime(&t); */
//apdu_len = /*apdu_len = */
// encode_tagged_time(&apdu[0], my_tm->tm_hour, my_tm->tm_min, /* encode_tagged_time(&apdu[0], my_tm->tm_hour, my_tm->tm_min, */
// my_tm->tm_sec, 0); /* my_tm->tm_sec, 0); */
//break; /*break; */
// if you support date /* if you support date */
//case PROP_LOCAL_DATE: /*case PROP_LOCAL_DATE: */
//t = time(NULL); /*t = time(NULL); */
//my_tm = localtime(&t); /*my_tm = localtime(&t); */
// month 1=Jan /* month 1=Jan */
// day = day of month /* day = day of month */
// wday 1=Monday...7=Sunday /* wday 1=Monday...7=Sunday */
//apdu_len = encode_tagged_date(&apdu[0], /*apdu_len = encode_tagged_date(&apdu[0], */
// my_tm->tm_year+1900, /* my_tm->tm_year+1900, */
// my_tm->tm_mon + 1, /* my_tm->tm_mon + 1, */
// my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday)); /* my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday)); */
//break; /*break; */
case PROP_PROTOCOL_VERSION: case PROP_PROTOCOL_VERSION:
apdu_len = apdu_len =
encode_tagged_unsigned(&apdu[0], Device_Protocol_Version()); encode_tagged_unsigned(&apdu[0], Device_Protocol_Version());
break; break;
// BACnet Legacy Support /* BACnet Legacy Support */
case PROP_PROTOCOL_CONFORMANCE_CLASS: case PROP_PROTOCOL_CONFORMANCE_CLASS:
apdu_len = encode_tagged_unsigned(&apdu[0], 1); apdu_len = encode_tagged_unsigned(&apdu[0], 1);
break; break;
@@ -523,7 +523,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
not a list of objects that this device can access */ not a list of objects that this device can access */
bitstring_init(&bit_string); bitstring_init(&bit_string);
for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { 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); bitstring_set_bit(&bit_string, (uint8_t) i, false);
} }
/* FIXME: indicate the objects that YOU support */ /* FIXME: indicate the objects that YOU support */
@@ -537,13 +537,13 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
break; break;
case PROP_OBJECT_LIST: case PROP_OBJECT_LIST:
count = Device_Object_List_Count(); 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) if (array_index == BACNET_ARRAY_LENGTH_INDEX)
apdu_len = encode_tagged_unsigned(&apdu[0], count); apdu_len = encode_tagged_unsigned(&apdu[0], count);
// if no index was specified, then try to encode the entire list /* if no index was specified, then try to encode the entire list */
// into one packet. Note that more than likely you will have /* into one packet. Note that more than likely you will have */
// to return an error if the number of encoded objects exceeds /* to return an error if the number of encoded objects exceeds */
// your maximum APDU size. /* your maximum APDU size. */
else if (array_index == BACNET_ARRAY_ALL) { else if (array_index == BACNET_ARRAY_ALL) {
for (i = 1; i <= count; i++) { for (i = 1; i <= count; i++) {
if (Device_Object_List_Identifier(i, &object_type, 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], encode_tagged_object_id(&apdu[apdu_len],
object_type, instance); object_type, instance);
apdu_len += len; apdu_len += len;
// assume next one is the same size as this one /* assume next one is the same size as this one */
// can we all fit into the APDU? /* can we all fit into the APDU? */
if ((apdu_len + len) >= MAX_APDU) { if ((apdu_len + len) >= MAX_APDU) {
*error_class = ERROR_CLASS_SERVICES; *error_class = ERROR_CLASS_SERVICES;
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; *error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
@@ -561,7 +561,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
break; break;
} }
} else { } else {
// error: internal error? /* error: internal error? */
*error_class = ERROR_CLASS_SERVICES; *error_class = ERROR_CLASS_SERVICES;
*error_code = ERROR_CODE_OTHER; *error_code = ERROR_CODE_OTHER;
apdu_len = -1; apdu_len = -1;
@@ -609,21 +609,21 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
return apdu_len; 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; extern bool I_Am_Request;
// returns true if successful /* returns true if successful */
bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) 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)) { if (!Device_Valid_Object_Instance_Number(wp_data->object_instance)) {
*error_class = ERROR_CLASS_OBJECT; *error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT; *error_code = ERROR_CODE_UNKNOWN_OBJECT;
return false; return false;
} }
// decode the some of the request /* decode the some of the request */
switch (wp_data->object_property) { switch (wp_data->object_property) {
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (wp_data->value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (wp_data->value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
@@ -765,7 +765,7 @@ void testDevice(Test * pTest)
} }
#ifdef TEST_DEVICE #ifdef TEST_DEVICE
// stubs to dependencies to keep unit test simple /* stubs to dependencies to keep unit test simple */
unsigned Analog_Input_Count(void) unsigned Analog_Input_Count(void)
{ {
return 0; return 0;
+1 -1
View File
@@ -76,7 +76,7 @@ extern "C" {
const char *Device_Location(void); const char *Device_Location(void);
bool Device_Set_Location(const char *name, size_t length); 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_Version(void);
uint8_t Device_Protocol_Revision(void); uint8_t Device_Protocol_Revision(void);
uint16_t Device_Max_APDU_Length_Accepted(void); uint16_t Device_Max_APDU_Length_Accepted(void);
+8 -8
View File
@@ -48,7 +48,7 @@
#include "handlers.h" #include "handlers.h"
#include "txbuf.h" #include "txbuf.h"
// buffer used for receive /* buffer used for receive */
static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
/* global variables used in this file */ /* 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(); status = tsm_transaction_available();
if (status) { if (status) {
datalink_get_my_address(&my_address); 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); MESSAGE_PRIORITY_NORMAL);
invoke_id = tsm_next_free_invokeID(); 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_type = OBJECT_FILE;
data.object_instance = file_instance; data.object_instance = file_instance;
data.access = FILE_STREAM_ACCESS; 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) { if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, tsm_set_confirmed_unsegmented_transaction(invoke_id,
&dest, &Handler_Transmit_Buffer[0], pdu_len); &dest, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
if (bytes_sent <= 0) if (bytes_sent <= 0)
fprintf(stderr, fprintf(stderr,
"Failed to Send AtomicReadFile Request (%s)!\n", "Failed to Send AtomicReadFile Request (%s)!\n",
@@ -161,7 +161,7 @@ static void Send_WhoIs(uint32_t device_id)
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */ /* 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); MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -268,9 +268,9 @@ static void Init_Service_Handlers(void)
int main(int argc, char *argv[]) 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; uint16_t pdu_len = 0;
unsigned timeout = 100; // milliseconds unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
time_t elapsed_seconds = 0; time_t elapsed_seconds = 0;
time_t last_seconds = 0; time_t last_seconds = 0;
+12 -12
View File
@@ -50,10 +50,10 @@ void dlmstp_cleanup(void)
} }
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, // destination address int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) // number of bytes of data unsigned pdu_len)
{ { /* number of bytes of data */
(void) dest; (void) dest;
(void) pdu; (void) pdu;
@@ -62,12 +62,12 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, // destination address
return 0; return 0;
} }
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t dlmstp_receive(BACNET_ADDRESS * src, // source address uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) // milliseconds to wait for a packet unsigned timeout)
{ { /* milliseconds to wait for a packet */
(void) src; (void) src;
(void) pdu; (void) pdu;
(void) max_pdu; (void) max_pdu;
@@ -86,7 +86,7 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
return; return;
} }
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) // destination address void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
{ { /* destination address */
return; return;
} }
+10 -10
View File
@@ -40,7 +40,7 @@
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #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_HEADER (2+1+1+1+2+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
@@ -52,19 +52,19 @@ extern "C" {
void dlmstp_cleanup(void); void dlmstp_cleanup(void);
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, // destination address int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t dlmstp_receive(BACNET_ADDRESS * src, // source address uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); // milliseconds to wait for a packet unsigned timeout); /* milliseconds to wait for a packet */
void dlmstp_set_my_address(BACNET_ADDRESS * my_address); void dlmstp_set_my_address(BACNET_ADDRESS * my_address);
void dlmstp_get_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 #ifdef __cplusplus
} }
+15 -15
View File
@@ -39,7 +39,7 @@
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
// specific defines for Ethernet /* specific defines for Ethernet */
#define MAX_HEADER (6+6+2+1+1+1) #define MAX_HEADER (6+6+2+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
@@ -53,27 +53,27 @@ extern "C" {
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int ethernet_send(BACNET_ADDRESS * dest, // destination address int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS * src, // source address BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
/* function to send a packet out the 802.2 socket */ /* function to send a packet out the 802.2 socket */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); // number of bytes of data unsigned pdu_len); /* number of bytes of data */
// receives an 802.2 framed packet /* receives an 802.2 framed packet */
// returns the number of octets in the PDU, or zero on failure /* returns the number of octets in the PDU, or zero on failure */
uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t max_pdu, // amount of space available in the PDU uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); // milliseconds to wait for a packet unsigned timeout); /* milliseconds to wait for a packet */
void ethernet_set_my_address(BACNET_ADDRESS * my_address); void ethernet_set_my_address(BACNET_ADDRESS * my_address);
void ethernet_get_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 #ifdef __cplusplus
} }
+28 -28
View File
@@ -40,17 +40,17 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "address.h" #include "address.h"
// encode I-Am service /* encode I-Am service */
int iam_encode_apdu(uint8_t * apdu, int iam_encode_apdu(uint8_t * apdu,
uint32_t device_id, uint32_t device_id,
unsigned max_apdu, int segmentation, uint16_t vendor_id) unsigned max_apdu, int segmentation, uint16_t vendor_id)
{ {
int len = 0; // length of each encoding int len = 0; /* length of each encoding */
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 (apdu) {
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; 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; apdu_len = 2;
len = encode_tagged_object_id(&apdu[apdu_len], len = encode_tagged_object_id(&apdu[apdu_len],
OBJECT_DEVICE, device_id); 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) unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id)
{ {
int len = 0; int len = 0;
int apdu_len = 0; // total length of the apdu, return value int apdu_len = 0; /* total length of the apdu, return value */
int object_type = 0; // should be a Device Object int object_type = 0; /* should be a Device Object */
uint32_t object_instance = 0; uint32_t object_instance = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
uint32_t decoded_value = 0; uint32_t decoded_value = 0;
int decoded_integer = 0; int decoded_integer = 0;
// OBJECT ID - object id /* OBJECT ID - object id */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value); &len_value);
@@ -93,7 +93,7 @@ int iam_decode_service_request(uint8_t * apdu,
return -1; return -1;
if (pDevice_id) if (pDevice_id)
*pDevice_id = object_instance; *pDevice_id = object_instance;
// MAX APDU - unsigned /* MAX APDU - unsigned */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value); &len_value);
@@ -104,7 +104,7 @@ int iam_decode_service_request(uint8_t * apdu,
apdu_len += len; apdu_len += len;
if (pMax_apdu) if (pMax_apdu)
*pMax_apdu = decoded_value; *pMax_apdu = decoded_value;
// Segmentation - enumerated /* Segmentation - enumerated */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value); &len_value);
@@ -117,7 +117,7 @@ int iam_decode_service_request(uint8_t * apdu,
return -1; return -1;
if (pSegmentation) if (pSegmentation)
*pSegmentation = decoded_integer; *pSegmentation = decoded_integer;
// Vendor ID - unsigned16 /* Vendor ID - unsigned16 */
len = len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value); &len_value);
@@ -138,12 +138,12 @@ int iam_decode_apdu(uint8_t * apdu,
uint32_t * pDevice_id, uint32_t * pDevice_id,
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_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) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
return -1; return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM) if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
@@ -160,20 +160,20 @@ int iam_send(uint8_t * buffer)
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
int bytes_sent = 0; int bytes_sent = 0;
// I-Am is a global broadcast /* I-Am is a global broadcast */
datalink_get_broadcast_address(&dest); datalink_get_broadcast_address(&dest);
// encode the NPDU portion of the packet /* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL, false, // true for confirmed messages pdu_len = npdu_encode_apdu(&buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL); 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], pdu_len += iam_encode_apdu(&buffer[pdu_len],
Device_Object_Instance_Number(), Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
bytes_sent = datalink_send_pdu(&dest, // destination address bytes_sent = datalink_send_pdu(&dest, /* destination address */
&buffer[0], pdu_len); // number of bytes of data &buffer[0], pdu_len); /* number of bytes of data */
return bytes_sent; return bytes_sent;
} }
@@ -212,16 +212,16 @@ void testIAm(Test * pTest)
} }
#ifdef TEST_IAM #ifdef TEST_IAM
// Dummy stubs to eliminate depencies /* Dummy stubs to eliminate depencies */
void datalink_get_broadcast_address(BACNET_ADDRESS * dest) // destination address void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
{ { /* destination address */
(void) dest; (void) dest;
} }
int datalink_send_pdu(BACNET_ADDRESS * dest, // destination address int datalink_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, // any data to be sent - may be null uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) // number of bytes of data unsigned pdu_len)
{ { /* number of bytes of data */
(void) dest; (void) dest;
(void) pdu; (void) pdu;
@@ -246,10 +246,10 @@ void address_add_binding(uint32_t device_id,
(void) src; (void) src;
} }
// dummy for apdu dependency /* dummy for apdu dependency */
void tsm_free_invoke_id(uint8_t invokeID) void tsm_free_invoke_id(uint8_t invokeID)
{ {
// dummy stub for testing /* dummy stub for testing */
(void) invokeID; (void) invokeID;
} }
+6 -6
View File
@@ -43,19 +43,19 @@
int main(void) int main(void)
{ {
struct mstp_port_struct_t mstp_port; // port data struct mstp_port_struct_t mstp_port; /* port data */
uint8_t my_mac = 0x05; // local MAC address uint8_t my_mac = 0x05; /* local MAC address */
MSTP_Init(&mstp_port, my_mac); MSTP_Init(&mstp_port, my_mac);
// loop forever /* loop forever */
for (;;) { for (;;) {
// input /* input */
RS485_Check_UART_Data(&mstp_port); RS485_Check_UART_Data(&mstp_port);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
// process /* process */
// output /* output */
MSTP_Master_Node_FSM(&mstp_port); MSTP_Master_Node_FSM(&mstp_port);
} }
+427 -427
View File
File diff suppressed because it is too large Load Diff
+83 -83
View File
@@ -42,12 +42,12 @@
#include "bacdef.h" #include "bacdef.h"
#include "dlmstp.h" #include "dlmstp.h"
// The value 255 is used to denote broadcast when used as a /* The value 255 is used to denote broadcast when used as a */
// destination address but is not allowed as a value for a station. /* destination address but is not allowed as a value for a station. */
#define MSTP_BROADCAST_ADDRESS 255 #define MSTP_BROADCAST_ADDRESS 255
// MS/TP Frame Type /* MS/TP Frame Type */
// Frame Types 8 through 127 are reserved by ASHRAE. /* Frame Types 8 through 127 are reserved by ASHRAE. */
#define FRAME_TYPE_TOKEN 0 #define FRAME_TYPE_TOKEN 0
#define FRAME_TYPE_POLL_FOR_MASTER 1 #define FRAME_TYPE_POLL_FOR_MASTER 1
#define FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER 2 #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_EXPECTING_REPLY 5
#define FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY 6 #define FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY 6
#define FRAME_TYPE_REPLY_POSTPONED 7 #define FRAME_TYPE_REPLY_POSTPONED 7
// Frame Types 128 through 255: Proprietary Frames /* Frame Types 128 through 255: Proprietary Frames */
// These frames are available to vendors as proprietary (non-BACnet) 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 /* The first two octets of the Data field shall specify the unique vendor */
// identification code, most significant octet first, for the type of /* identification code, most significant octet first, for the type of */
// vendor-proprietary frame to be conveyed. The length of the data portion /* 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. /* of a Proprietary frame shall be in the range of 2 to 501 octets. */
#define FRAME_TYPE_PROPRIETARY_MIN 128 #define FRAME_TYPE_PROPRIETARY_MIN 128
#define FRAME_TYPE_PROPRIETARY_MAX 255 #define FRAME_TYPE_PROPRIETARY_MAX 255
// receive FSM states /* receive FSM states */
typedef enum { typedef enum {
MSTP_RECEIVE_STATE_IDLE, MSTP_RECEIVE_STATE_IDLE,
MSTP_RECEIVE_STATE_PREAMBLE, MSTP_RECEIVE_STATE_PREAMBLE,
@@ -75,7 +75,7 @@ typedef enum {
MSTP_RECEIVE_STATE_DATA_CRC MSTP_RECEIVE_STATE_DATA_CRC
} MSTP_RECEIVE_STATE; } MSTP_RECEIVE_STATE;
// master node FSM states /* master node FSM states */
typedef enum { typedef enum {
MSTP_MASTER_STATE_INITIALIZE, MSTP_MASTER_STATE_INITIALIZE,
MSTP_MASTER_STATE_IDLE, MSTP_MASTER_STATE_IDLE,
@@ -90,115 +90,115 @@ typedef enum {
struct mstp_port_struct_t { struct mstp_port_struct_t {
MSTP_RECEIVE_STATE receive_state; MSTP_RECEIVE_STATE receive_state;
// When a master node is powered up or reset, /* When a master node is powered up or reset, */
// it shall unconditionally enter the INITIALIZE state. /* it shall unconditionally enter the INITIALIZE state. */
MSTP_MASTER_STATE master_state; MSTP_MASTER_STATE master_state;
// A Boolean flag set to TRUE by the Receive State Machine /* A Boolean flag set to TRUE by the Receive State Machine */
// if an error is detected during the reception of a frame. /* if an error is detected during the reception of a frame. */
// Set to FALSE by the main state machine. /* Set to FALSE by the main state machine. */
unsigned ReceiveError:1; unsigned ReceiveError:1;
// There is data in the buffer /* There is data in the buffer */
unsigned DataAvailable:1; 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; unsigned ReceivedInvalidFrame:1;
// A Boolean flag set to TRUE by the Receive State Machine /* A Boolean flag set to TRUE by the Receive State Machine */
// if a valid frame is received. /* if a valid frame is received. */
// Set to FALSE by the main state machine. /* Set to FALSE by the main state machine. */
unsigned ReceivedValidFrame:1; unsigned ReceivedValidFrame:1;
// A Boolean flag set to TRUE by the master machine if this node is the /* A Boolean flag set to TRUE by the master machine if this node is the */
// only known master node. /* only known master node. */
unsigned SoleMaster:1; unsigned SoleMaster:1;
// After receiving a frame this value will be TRUE until Tturnaround /* After receiving a frame this value will be TRUE until Tturnaround */
// has expired /* has expired */
unsigned Turn_Around_Waiting:1; unsigned Turn_Around_Waiting:1;
// stores the latest received data /* stores the latest received data */
uint8_t DataRegister; 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; 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; 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; uint8_t DestinationAddress;
// Used to count the number of received octets or errors. /* Used to count the number of received octets or errors. */
// This is used in the detection of link activity. /* This is used in the detection of link activity. */
unsigned EventCount; 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; uint8_t FrameType;
// The number of frames sent by this node during a single token hold. /* 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 /* When this counter reaches the value Nmax_info_frames, the node must */
// pass the token. /* pass the token. */
unsigned FrameCount; 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; uint8_t HeaderCRC;
// Used as an index by the Receive State Machine, up to a maximum value of /* Used as an index by the Receive State Machine, up to a maximum value of */
// InputBufferSize. /* InputBufferSize. */
unsigned Index; unsigned Index;
// An array of octets, used to store octets as they are received. /* An array of octets, used to store octets as they are received. */
// InputBuffer is indexed from 0 to InputBufferSize-1. /* InputBuffer is indexed from 0 to InputBufferSize-1. */
// The maximum size of a frame is 501 octets. /* The maximum size of a frame is 501 octets. */
uint8_t InputBuffer[MAX_MPDU]; uint8_t InputBuffer[MAX_MPDU];
// "Next Station," the MAC address of the node to which This Station passes /* "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 /* the token. If the Next_Station is unknown, Next_Station shall be equal to */
// This_Station. /* This_Station. */
uint8_t Next_Station; uint8_t Next_Station;
// "Poll Station," the MAC address of the node to which This Station last /* "Poll Station," the MAC address of the node to which This Station last */
// sent a Poll For Master. This is used during token maintenance. /* sent a Poll For Master. This is used during token maintenance. */
uint8_t Poll_Station; uint8_t Poll_Station;
// A counter of transmission retries used for Token and Poll For Master /* A counter of transmission retries used for Token and Poll For Master */
// transmission. /* transmission. */
unsigned RetryCount; unsigned RetryCount;
// A timer with nominal 5 millisecond resolution used to measure and /* A timer with nominal 5 millisecond resolution used to measure and */
// generate silence on the medium between octets. It is incremented by a /* generate silence on the medium between octets. It is incremented by a */
// timer process and is cleared by the Receive State Machine when activity /* timer process and is cleared by the Receive State Machine when activity */
// is detected and by the SendFrame procedure as each octet is transmitted. /* is detected and by the SendFrame procedure as each octet is transmitted. */
// Since the timer resolution is limited and the timer is not necessarily /* Since the timer resolution is limited and the timer is not necessarily */
// synchronized to other machine events, a timer value of N will actually /* synchronized to other machine events, a timer value of N will actually */
// denote intervals between N-1 and N /* denote intervals between N-1 and N */
unsigned SilenceTimer; unsigned SilenceTimer;
// A timer used to measure and generate Reply Postponed frames. It is /* 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 /* incremented by a timer process and is cleared by the Master Node State */
// Machine when a Data Expecting Reply Answer activity is completed. /* Machine when a Data Expecting Reply Answer activity is completed. */
unsigned ReplyPostponedTimer; 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; uint8_t SourceAddress;
// The number of tokens received by this node. When this counter reaches the /* 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 /* 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 /* additional master nodes. TokenCount is set to zero at the end of the */
// polling process. /* polling process. */
unsigned TokenCount; unsigned TokenCount;
// "This Station," the MAC address of this node. TS is generally read from a /* "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 /* 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 /* 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. /* destination address but is not allowed as a value for TS. */
uint8_t This_Station; uint8_t This_Station;
// This parameter represents the value of the Max_Info_Frames property of /* 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 /* 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 /* maximum number of information frames the node may send before it must */
// pass the token. Max_Info_Frames may have different values on different /* 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 /* 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 /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
// node, its value shall be 1. /* node, its value shall be 1. */
unsigned Nmax_info_frames; unsigned Nmax_info_frames;
// This parameter represents the value of the Max_Master property of the /* This parameter represents the value of the Max_Master property of the */
// node's Device object. The value of Max_Master specifies the highest /* node's Device object. The value of Max_Master specifies the highest */
// allowable address for master nodes. The value of Max_Master shall be /* 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, /* less than or equal to 127. If Max_Master is not writable in a node, */
// its value shall be 127. /* its value shall be 127. */
unsigned Nmax_master; unsigned Nmax_master;
}; };
#define DEFAULT_MAX_INFO_FRAMES 1 #define DEFAULT_MAX_INFO_FRAMES 1
#define DEFAULT_MAX_MASTER 127 #define DEFAULT_MAX_MASTER 127
// The minimum time after the end of the stop bit of the final octet of a /* 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. /* 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 /* At 9600 baud, 40 bit times would be about 4.166 milliseconds */
#define Tturnaround 40; #define Tturnaround 40;
#ifdef __cplusplus #ifdef __cplusplus
+125 -125
View File
@@ -44,58 +44,58 @@ int npdu_encode_raw(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; // return value - number of octets loaded in this function int len = 0; /* return value - number of octets loaded in this function */
int i = 0; // counter int i = 0; /* counter */
if (npdu && npdu_data) { if (npdu && npdu_data) {
// Protocol Version /* Protocol Version */
npdu[0] = 1; npdu[0] = 1;
// control octet /* control octet */
npdu[1] = 0; npdu[1] = 0;
// Bit 7: 1 indicates that the NSDU conveys a network layer message. /* Bit 7: 1 indicates that the NSDU conveys a network layer message. */
// Message Type field is present. /* Message Type field is present. */
// 0 indicates that the NSDU contains a BACnet APDU. /* 0 indicates that the NSDU contains a BACnet APDU. */
// Message Type field is absent. /* Message Type field is absent. */
if (npdu_data->network_layer_message) if (npdu_data->network_layer_message)
npdu[1] |= BIT7; npdu[1] |= BIT7;
//Bit 6: Reserved. Shall be zero. /*Bit 6: Reserved. Shall be zero. */
//Bit 5: Destination specifier where: /*Bit 5: Destination specifier where: */
// 0 = DNET, DLEN, DADR, and Hop Count absent /* 0 = DNET, DLEN, DADR, and Hop Count absent */
// 1 = DNET, DLEN, and Hop Count present /* 1 = DNET, DLEN, and Hop Count present */
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
// DLEN > 0 specifies length of DADR field /* DLEN > 0 specifies length of DADR field */
if (dest && dest->net) if (dest && dest->net)
npdu[1] |= BIT5; npdu[1] |= BIT5;
// Bit 4: Reserved. Shall be zero. /* Bit 4: Reserved. Shall be zero. */
// Bit 3: Source specifier where: /* Bit 3: Source specifier where: */
// 0 = SNET, SLEN, and SADR absent /* 0 = SNET, SLEN, and SADR absent */
// 1 = SNET, SLEN, and SADR present /* 1 = SNET, SLEN, and SADR present */
// SLEN = 0 Invalid /* SLEN = 0 Invalid */
// SLEN > 0 specifies length of SADR field /* SLEN > 0 specifies length of SADR field */
if (src && src->net) if (src && src->net)
npdu[1] |= BIT3; npdu[1] |= BIT3;
// Bit 2: The value of this bit corresponds to the data_expecting_reply /* Bit 2: The value of this bit corresponds to the data_expecting_reply */
// parameter in the N-UNITDATA primitives. /* parameter in the N-UNITDATA primitives. */
// 1 indicates that a BACnet-Confirmed-Request-PDU, /* 1 indicates that a BACnet-Confirmed-Request-PDU, */
// a segment of a BACnet-ComplexACK-PDU, /* a segment of a BACnet-ComplexACK-PDU, */
// or a network layer message expecting a reply is present. /* or a network layer message expecting a reply is present. */
// 0 indicates that other than a BACnet-Confirmed-Request-PDU, /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
// a segment of a BACnet-ComplexACK-PDU, /* a segment of a BACnet-ComplexACK-PDU, */
// or a network layer message expecting a reply is present. /* or a network layer message expecting a reply is present. */
if (npdu_data->data_expecting_reply) if (npdu_data->data_expecting_reply)
npdu[1] |= BIT2; npdu[1] |= BIT2;
// Bits 1,0: Network priority where: /* Bits 1,0: Network priority where: */
// B'11' = Life Safety message /* B'11' = Life Safety message */
// B'10' = Critical Equipment message /* B'10' = Critical Equipment message */
// B'01' = Urgent message /* B'01' = Urgent message */
// B'00' = Normal message /* B'00' = Normal message */
npdu[1] |= (npdu_data->priority & 0x03); npdu[1] |= (npdu_data->priority & 0x03);
len = 2; len = 2;
if (dest && dest->net) { if (dest && dest->net) {
len += encode_unsigned16(&npdu[len], dest->net); len += encode_unsigned16(&npdu[len], dest->net);
npdu[len++] = dest->len; npdu[len++] = dest->len;
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
// DLEN > 0 specifies length of DADR field /* DLEN > 0 specifies length of DADR field */
if (dest->len) { if (dest->len) {
for (i = 0; i < dest->len; i++) { for (i = 0; i < dest->len; i++) {
npdu[len++] = dest->adr[i]; npdu[len++] = dest->adr[i];
@@ -105,17 +105,17 @@ int npdu_encode_raw(uint8_t * npdu,
if (src && src->net) { if (src && src->net) {
len += encode_unsigned16(&npdu[len], src->net); len += encode_unsigned16(&npdu[len], src->net);
npdu[len++] = src->len; npdu[len++] = src->len;
// SLEN = 0 denotes broadcast MAC SADR and SADR field is absent /* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */
// SLEN > 0 specifies length of SADR field /* SLEN > 0 specifies length of SADR field */
if (src->len) { if (src->len) {
for (i = 0; i < src->len; i++) { for (i = 0; i < src->len; i++) {
npdu[len++] = src->adr[i]; npdu[len++] = src->adr[i];
} }
} }
} }
// The Hop Count field shall be present only if the message is /* The Hop Count field shall be present only if the message is */
// destined for a remote network, i.e., if DNET is present. /* 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. /* This is a one-octet field that is initialized to a value of 0xff. */
if (dest && dest->net) { if (dest && dest->net) {
npdu[len] = 0xFF; npdu[len] = 0xFF;
len++; len++;
@@ -123,8 +123,8 @@ int npdu_encode_raw(uint8_t * npdu,
if (npdu_data->network_layer_message) { if (npdu_data->network_layer_message) {
npdu[len] = npdu_data->network_message_type; npdu[len] = npdu_data->network_message_type;
len++; len++;
// Message Type field contains a value in the range 0x80 - 0xFF, /* Message Type field contains a value in the range 0x80 - 0xFF, */
// then a Vendor ID field shall be present /* then a Vendor ID field shall be present */
if (npdu_data->network_message_type >= 0x80) if (npdu_data->network_message_type >= 0x80)
len += encode_unsigned16(&npdu[len], npdu_data->vendor_id); len += encode_unsigned16(&npdu[len], npdu_data->vendor_id);
} }
@@ -133,19 +133,19 @@ int npdu_encode_raw(uint8_t * npdu,
return len; return len;
} }
// encode the NPDU portion of the packet for an APDU /* encode the NPDU portion of the packet for an APDU */
// This function does not handle the network messages, just APDUs. /* 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 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_MESSAGE_PRIORITY priority)
{ {
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
npdu_data.data_expecting_reply = data_expecting_reply; npdu_data.data_expecting_reply = data_expecting_reply;
npdu_data.network_layer_message = false; // false if APDU npdu_data.network_layer_message = false; /* false if APDU */
npdu_data.network_message_type = 0; // optional npdu_data.network_message_type = 0; /* optional */
npdu_data.vendor_id = 0; // optional, if net message type is > 0x80 npdu_data.vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data.priority = priority; npdu_data.priority = priority;
// call the real function... /* call the real function... */
return npdu_encode_raw(npdu, dest, src, &npdu_data); return npdu_encode_raw(npdu, dest, src, &npdu_data);
} }
@@ -153,50 +153,50 @@ int npdu_decode(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data) BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
{ {
int len = 0; // return value - number of octets loaded in this function int len = 0; /* return value - number of octets loaded in this function */
int i = 0; // counter int i = 0; /* counter */
uint16_t src_net = 0; uint16_t src_net = 0;
uint16_t dest_net = 0; uint16_t dest_net = 0;
uint8_t address_len = 0; uint8_t address_len = 0;
uint8_t mac_octet = 0; uint8_t mac_octet = 0;
if (npdu && npdu_data) { if (npdu && npdu_data) {
// Protocol Version /* Protocol Version */
npdu_data->protocol_version = npdu[0]; npdu_data->protocol_version = npdu[0];
// control octet /* control octet */
// Bit 7: 1 indicates that the NSDU conveys a network layer message. /* Bit 7: 1 indicates that the NSDU conveys a network layer message. */
// Message Type field is present. /* Message Type field is present. */
// 0 indicates that the NSDU contains a BACnet APDU. /* 0 indicates that the NSDU contains a BACnet APDU. */
// Message Type field is absent. /* Message Type field is absent. */
npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false; npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false;
//Bit 6: Reserved. Shall be zero. /*Bit 6: Reserved. Shall be zero. */
// Bit 4: Reserved. Shall be zero. /* Bit 4: Reserved. Shall be zero. */
// Bit 2: The value of this bit corresponds to the data_expecting_reply /* Bit 2: The value of this bit corresponds to the data_expecting_reply */
// parameter in the N-UNITDATA primitives. /* parameter in the N-UNITDATA primitives. */
// 1 indicates that a BACnet-Confirmed-Request-PDU, /* 1 indicates that a BACnet-Confirmed-Request-PDU, */
// a segment of a BACnet-ComplexACK-PDU, /* a segment of a BACnet-ComplexACK-PDU, */
// or a network layer message expecting a reply is present. /* or a network layer message expecting a reply is present. */
// 0 indicates that other than a BACnet-Confirmed-Request-PDU, /* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
// a segment of a BACnet-ComplexACK-PDU, /* a segment of a BACnet-ComplexACK-PDU, */
// or a network layer message expecting a reply is present. /* or a network layer message expecting a reply is present. */
npdu_data->data_expecting_reply = (npdu[1] & BIT2) ? true : false; npdu_data->data_expecting_reply = (npdu[1] & BIT2) ? true : false;
// Bits 1,0: Network priority where: /* Bits 1,0: Network priority where: */
// B'11' = Life Safety message /* B'11' = Life Safety message */
// B'10' = Critical Equipment message /* B'10' = Critical Equipment message */
// B'01' = Urgent message /* B'01' = Urgent message */
// B'00' = Normal message /* B'00' = Normal message */
npdu_data->priority = npdu[1] & 0x03; 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; len = 2;
//Bit 5: Destination specifier where: /*Bit 5: Destination specifier where: */
// 0 = DNET, DLEN, DADR, and Hop Count absent /* 0 = DNET, DLEN, DADR, and Hop Count absent */
// 1 = DNET, DLEN, and Hop Count present /* 1 = DNET, DLEN, and Hop Count present */
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
// DLEN > 0 specifies length of DADR field /* DLEN > 0 specifies length of DADR field */
if (npdu[1] & BIT5) { if (npdu[1] & BIT5) {
len += decode_unsigned16(&npdu[len], &dest_net); len += decode_unsigned16(&npdu[len], &dest_net);
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
// DLEN > 0 specifies length of DADR field /* DLEN > 0 specifies length of DADR field */
address_len = npdu[len++]; address_len = npdu[len++];
if (dest) { if (dest) {
dest->net = dest_net; 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) { else if (dest) {
dest->net = 0; dest->net = 0;
dest->len = 0; dest->len = 0;
@@ -218,15 +218,15 @@ int npdu_decode(uint8_t * npdu,
dest->adr[i] = 0; dest->adr[i] = 0;
} }
} }
// Bit 3: Source specifier where: /* Bit 3: Source specifier where: */
// 0 = SNET, SLEN, and SADR absent /* 0 = SNET, SLEN, and SADR absent */
// 1 = SNET, SLEN, and SADR present /* 1 = SNET, SLEN, and SADR present */
// SLEN = 0 Invalid /* SLEN = 0 Invalid */
// SLEN > 0 specifies length of SADR field /* SLEN > 0 specifies length of SADR field */
if (npdu[1] & BIT3) { if (npdu[1] & BIT3) {
len += decode_unsigned16(&npdu[len], &src_net); len += decode_unsigned16(&npdu[len], &src_net);
// SLEN = 0 denotes broadcast MAC SADR and SADR field is absent /* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */
// SLEN > 0 specifies length of SADR field /* SLEN > 0 specifies length of SADR field */
address_len = npdu[len++]; address_len = npdu[len++];
if (src) { if (src) {
src->net = src_net; src->net = src_net;
@@ -246,19 +246,19 @@ int npdu_decode(uint8_t * npdu,
src->adr[i] = 0; src->adr[i] = 0;
} }
} }
// The Hop Count field shall be present only if the message is /* The Hop Count field shall be present only if the message is */
// destined for a remote network, i.e., if DNET is present. /* 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. /* This is a one-octet field that is initialized to a value of 0xff. */
if (dest_net) if (dest_net)
npdu_data->hop_count = npdu[len++]; npdu_data->hop_count = npdu[len++];
else else
npdu_data->hop_count = 0; npdu_data->hop_count = 0;
// Indicates that the NSDU conveys a network layer message. /* Indicates that the NSDU conveys a network layer message. */
// Message Type field is present. /* Message Type field is present. */
if (npdu_data->network_layer_message) { if (npdu_data->network_layer_message) {
npdu_data->network_message_type = npdu[len++]; npdu_data->network_message_type = npdu[len++];
// Message Type field contains a value in the range 0x80 - 0xFF, /* Message Type field contains a value in the range 0x80 - 0xFF, */
// then a Vendor ID field shall be present /* then a Vendor ID field shall be present */
if (npdu_data->network_message_type >= 0x80) if (npdu_data->network_message_type >= 0x80)
len += len +=
decode_unsigned16(&npdu[len], &npdu_data->vendor_id); decode_unsigned16(&npdu[len], &npdu_data->vendor_id);
@@ -269,20 +269,20 @@ int npdu_decode(uint8_t * npdu,
return len; return len;
} }
void npdu_handler(BACNET_ADDRESS * src, // source address void npdu_handler(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t pdu_len) // length PDU uint16_t pdu_len)
{ { /* length PDU */
int apdu_offset = 0; int apdu_offset = 0;
BACNET_ADDRESS dest = { 0 }; BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
apdu_offset = npdu_decode(&pdu[0], // data to decode apdu_offset = npdu_decode(&pdu[0], /* data to decode */
&dest, // destination address - get the DNET/DLEN/DADR if in there &dest, /* destination address - get the DNET/DLEN/DADR if in there */
src, // source address - get the SNET/SLEN/SADR if in there src, /* source address - get the SNET/SLEN/SADR if in there */
&npdu_data); // amount of data to decode &npdu_data); /* amount of data to decode */
if (npdu_data.network_layer_message) { if (npdu_data.network_layer_message) {
//FIXME: network layer message received! Handle it! /*FIXME: network layer message received! Handle it! */
} else { } else {
apdu_handler(src, apdu_handler(src,
npdu_data.data_expecting_reply, npdu_data.data_expecting_reply,
@@ -306,21 +306,21 @@ void testNPDU2(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 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_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; // counter int i = 0; /* counter */
int npdu_len = 0; int npdu_len = 0;
bool network_layer_message = false; // false if APDU bool network_layer_message = false; /* false if APDU */
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
uint16_t vendor_id = 0; // optional, if net message type is > 0x80 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; dest.mac_len = 6;
for (i = 0; i < dest.mac_len; i++) { for (i = 0; i < dest.mac_len; i++) {
dest.mac[i] = i; dest.mac[i] = i;
} }
// DNET,DLEN,DADR /* DNET,DLEN,DADR */
dest.net = 1; dest.net = 1;
dest.len = 6; dest.len = 6;
for (i = 0; i < dest.len; i++) { for (i = 0; i < dest.len; i++) {
@@ -330,7 +330,7 @@ void testNPDU2(Test * pTest)
for (i = 0; i < src.mac_len; i++) { for (i = 0; i < src.mac_len; i++) {
src.mac[i] = 0x80; src.mac[i] = 0x80;
} }
// SNET,SLEN,SADR /* SNET,SLEN,SADR */
src.net = 2; src.net = 2;
src.len = 1; src.len = 1;
for (i = 0; i < src.len; i++) { for (i = 0; i < src.len; i++) {
@@ -339,7 +339,7 @@ void testNPDU2(Test * pTest)
len = npdu_encode_apdu(&pdu[0], len = npdu_encode_apdu(&pdu[0],
&dest, &src, data_expecting_reply, priority); &dest, &src, data_expecting_reply, priority);
ct_test(pTest, len != 0); 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); npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); 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.network_message_type == network_message_type);
ct_test(pTest, npdu_data.vendor_id == vendor_id); ct_test(pTest, npdu_data.vendor_id == vendor_id);
ct_test(pTest, npdu_data.priority == priority); 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.net == dest.net);
ct_test(pTest, npdu_dest.len == dest.len); ct_test(pTest, npdu_dest.len == dest.len);
for (i = 0; i < dest.len; i++) { for (i = 0; i < dest.len; i++) {
ct_test(pTest, npdu_dest.adr[i] == dest.adr[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.net == src.net);
ct_test(pTest, npdu_src.len == src.len); ct_test(pTest, npdu_src.len == src.len);
for (i = 0; i < src.len; i++) { for (i = 0; i < src.len; i++) {
@@ -370,21 +370,21 @@ void testNPDU1(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 }; BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 }; BACNET_ADDRESS npdu_src = { 0 };
int len = 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_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 }; BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; // counter int i = 0; /* counter */
int npdu_len = 0; int npdu_len = 0;
bool network_layer_message = false; // false if APDU bool network_layer_message = false; /* false if APDU */
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
uint16_t vendor_id = 0; // optional, if net message type is > 0x80 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; dest.mac_len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
dest.mac[i] = 0; dest.mac[i] = 0;
} }
// DNET,DLEN,DADR /* DNET,DLEN,DADR */
dest.net = 0; dest.net = 0;
dest.len = 0; dest.len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
@@ -394,7 +394,7 @@ void testNPDU1(Test * pTest)
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
src.mac[i] = 0; src.mac[i] = 0;
} }
// SNET,SLEN,SADR /* SNET,SLEN,SADR */
src.net = 0; src.net = 0;
src.len = 0; src.len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) { for (i = 0; i < MAX_MAC_LEN; i++) {
@@ -403,7 +403,7 @@ void testNPDU1(Test * pTest)
len = npdu_encode_apdu(&pdu[0], len = npdu_encode_apdu(&pdu[0],
&dest, &src, data_expecting_reply, priority); &dest, &src, data_expecting_reply, priority);
ct_test(pTest, len != 0); 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); npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0); ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply); ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
@@ -417,7 +417,7 @@ void testNPDU1(Test * pTest)
} }
#ifdef TEST_NPDU #ifdef TEST_NPDU
// dummy stub for testing /* dummy stub for testing */
void tsm_free_invoke_id(uint8_t invokeID) void tsm_free_invoke_id(uint8_t invokeID)
{ {
(void) invokeID; (void) invokeID;
+12 -12
View File
@@ -39,16 +39,16 @@
#include "bacdef.h" #include "bacdef.h"
#include "bacenum.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 { typedef struct bacnet_npdu_data_t {
uint8_t protocol_version; uint8_t protocol_version;
// parts of the control octet: /* parts of the control octet: */
bool data_expecting_reply; // true for confirmed messages bool data_expecting_reply; /* true for confirmed messages */
bool network_layer_message; // false if APDU bool network_layer_message; /* false if APDU */
BACNET_MESSAGE_PRIORITY priority; BACNET_MESSAGE_PRIORITY priority;
// optional network message info /* optional network message info */
BACNET_NETWORK_MESSAGE_TYPE network_message_type; // optional BACNET_NETWORK_MESSAGE_TYPE network_message_type; /* optional */
uint16_t vendor_id; // optional, if net message type is > 0x80 uint16_t vendor_id; /* optional, if net message type is > 0x80 */
uint8_t hop_count; uint8_t hop_count;
} BACNET_NPDU_DATA; } BACNET_NPDU_DATA;
@@ -60,17 +60,17 @@ extern "C" {
int npdu_encode_raw(uint8_t * npdu, int npdu_encode_raw(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data);
// encode the NPDU portion of the packet for an APDU /* 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 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_MESSAGE_PRIORITY priority);
int npdu_decode(uint8_t * npdu, int npdu_decode(uint8_t * npdu,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data); BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data);
void npdu_handler(BACNET_ADDRESS * src, // source address void npdu_handler(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, // PDU data uint8_t * pdu, /* PDU data */
uint16_t pdu_len); // length PDU uint16_t pdu_len); /* length PDU */
#ifdef __cplusplus #ifdef __cplusplus
} }
+2 -2
View File
@@ -110,10 +110,10 @@ int rd_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE)
return -1; return -1;
+2 -2
View File
@@ -41,13 +41,13 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// encode service /* encode service */
int rd_encode_apdu(uint8_t * apdu, int rd_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, uint8_t invoke_id,
BACNET_REINITIALIZED_STATE state, BACNET_REINITIALIZED_STATE state,
BACNET_CHARACTER_STRING * password); BACNET_CHARACTER_STRING * password);
// decode the service request only /* decode the service request only */
int rd_decode_service_request(uint8_t * apdu, int rd_decode_service_request(uint8_t * apdu,
unsigned apdu_len, unsigned apdu_len,
BACNET_REINITIALIZED_STATE * state, BACNET_REINITIALIZED_STATE * state,
+9 -9
View File
@@ -36,11 +36,11 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "bacdef.h" #include "bacdef.h"
// encode service /* encode service */
int reject_encode_apdu(uint8_t * apdu, int reject_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, uint8_t reject_reason) 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) { if (apdu) {
apdu[0] = PDU_TYPE_REJECT; apdu[0] = PDU_TYPE_REJECT;
@@ -52,7 +52,7 @@ int reject_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int reject_decode_service_request(uint8_t * apdu, int reject_decode_service_request(uint8_t * apdu,
unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason) 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; 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, int reject_decode_apdu(uint8_t * apdu,
unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason) unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason)
{ {
@@ -76,7 +76,7 @@ int reject_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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_len) {
if (apdu[0] != PDU_TYPE_REJECT) if (apdu[0] != PDU_TYPE_REJECT)
return -1; return -1;
@@ -114,24 +114,24 @@ void testReject(Test * pTest)
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_reject_reason == reject_reason); 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; apdu[0] = PDU_TYPE_ABORT;
len = reject_decode_apdu(&apdu[0], len = reject_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_reject_reason); apdu_len, &test_invoke_id, &test_reject_reason);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// test NULL APDU /* test NULL APDU */
len = reject_decode_apdu(NULL, len = reject_decode_apdu(NULL,
apdu_len, &test_invoke_id, &test_reject_reason); apdu_len, &test_invoke_id, &test_reject_reason);
ct_test(pTest, len == -1); ct_test(pTest, len == -1);
// force a zero length /* force a zero length */
len = reject_decode_apdu(&apdu[0], len = reject_decode_apdu(&apdu[0],
0, &test_invoke_id, &test_reject_reason); 0, &test_invoke_id, &test_reject_reason);
ct_test(pTest, len == 0); ct_test(pTest, len == 0);
// check them all... /* check them all... */
for (invoke_id = 0; invoke_id < 255; invoke_id++) { for (invoke_id = 0; invoke_id < 255; invoke_id++) {
for (reject_reason = 0; reject_reason < 255; reject_reason++) { for (reject_reason = 0; reject_reason < 255; reject_reason++) {
len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason); len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason);
+19 -19
View File
@@ -70,7 +70,7 @@ char *Ringbuf_Get_Front(RING_BUFFER const *b)
*****************************************************************************/ *****************************************************************************/
char *Ringbuf_Pop_Front(RING_BUFFER * b) char *Ringbuf_Pop_Front(RING_BUFFER * b)
{ {
char *data = NULL; // return value char *data = NULL; /* return value */
if (b->count) { if (b->count) {
data = &(b->data[b->head * b->element_size]); data = &(b->data[b->head * b->element_size]);
@@ -89,16 +89,16 @@ char *Ringbuf_Pop_Front(RING_BUFFER * b)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure bool Ringbuf_Put(RING_BUFFER * b, /* ring buffer structure */
char *data_element) // one element to add to the ring char *data_element)
{ { /* one element to add to the ring */
bool status = false; // return value bool status = false; /* return value */
unsigned offset = 0; // offset into array of data unsigned offset = 0; /* offset into array of data */
char *ring_data = NULL; // used to help point ring data char *ring_data = NULL; /* used to help point ring data */
unsigned i; // loop counter unsigned i; /* loop counter */
if (b && data_element) { 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) { if (b->count < b->element_count) {
offset = b->head + b->count; offset = b->head + b->count;
if (offset >= b->element_count) if (offset >= b->element_count)
@@ -121,11 +121,11 @@ bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */
char *data, // data block or array of data char *data, /* data block or array of data */
unsigned element_size, // size of one element in the data block unsigned element_size, /* size of one element in the data block */
unsigned element_count) // number of elements in the data block unsigned element_count)
{ { /* number of elements in the data block */
b->head = 0; b->head = 0;
b->count = 0; b->count = 0;
b->data = data; b->data = data;
@@ -141,7 +141,7 @@ void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure
#include "ctest.h" #include "ctest.h"
// test the FIFO /* test the FIFO */
#define RING_BUFFER_DATA_SIZE 5 #define RING_BUFFER_DATA_SIZE 5
#define RING_BUFFER_SIZE 16 #define RING_BUFFER_SIZE 16
void testRingBuf(Test * pTest) void testRingBuf(Test * pTest)
@@ -179,7 +179,7 @@ void testRingBuf(Test * pTest)
} }
ct_test(pTest, Ringbuf_Empty(&test_buffer)); ct_test(pTest, Ringbuf_Empty(&test_buffer));
// fill to max /* fill to max */
for (index = 0; index < RING_BUFFER_SIZE; index++) { for (index = 0; index < RING_BUFFER_SIZE; index++) {
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
data_index++) { data_index++) {
@@ -189,7 +189,7 @@ void testRingBuf(Test * pTest)
ct_test(pTest, status == true); ct_test(pTest, status == true);
ct_test(pTest, !Ringbuf_Empty(&test_buffer)); 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 (index = 0; index < RING_BUFFER_SIZE; index++) {
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
data_index++) { data_index++) {
@@ -200,7 +200,7 @@ void testRingBuf(Test * pTest)
ct_test(pTest, !Ringbuf_Empty(&test_buffer)); ct_test(pTest, !Ringbuf_Empty(&test_buffer));
} }
// check buffer full /* check buffer full */
for (index = 0; index < RING_BUFFER_SIZE; index++) { for (index = 0; index < RING_BUFFER_SIZE; index++) {
test_data = Ringbuf_Get_Front(&test_buffer); test_data = Ringbuf_Get_Front(&test_buffer);
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; 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)); 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 (index = 0; index < RING_BUFFER_SIZE; index++) {
for (count = 1; count < 4; count++) { for (count = 1; count < 4; count++) {
dummy = index * count; dummy = index * count;
+11 -11
View File
@@ -43,11 +43,11 @@
#include <stdbool.h> #include <stdbool.h>
struct ring_buffer_t { struct ring_buffer_t {
char *data; // block of memory or array of data char *data; /* block of memory or array of data */
unsigned element_size; // how many bytes for each chunk unsigned element_size; /* how many bytes for each chunk */
unsigned element_count; // number of chunks of data unsigned element_count; /* number of chunks of data */
unsigned head; // first chunk of data unsigned head; /* first chunk of data */
unsigned count; // number of chunks in use unsigned count; /* number of chunks in use */
}; };
typedef struct ring_buffer_t RING_BUFFER; typedef struct ring_buffer_t RING_BUFFER;
@@ -58,12 +58,12 @@ extern "C" {
bool Ringbuf_Empty(RING_BUFFER const *b); bool Ringbuf_Empty(RING_BUFFER const *b);
char *Ringbuf_Get_Front(RING_BUFFER const *b); char *Ringbuf_Get_Front(RING_BUFFER const *b);
char *Ringbuf_Pop_Front(RING_BUFFER * b); char *Ringbuf_Pop_Front(RING_BUFFER * b);
bool Ringbuf_Put(RING_BUFFER * b, // ring buffer structure bool Ringbuf_Put(RING_BUFFER * b, /* ring buffer structure */
char *data_element); // one element to add to the ring char *data_element); /* one element to add to the ring */
void Ringbuf_Init(RING_BUFFER * b, // ring buffer structure void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */
char *data, // data block or array of data char *data, /* data block or array of data */
unsigned element_size, // size of one element in the data block unsigned element_size, /* size of one element in the data block */
unsigned element_count); // number of elements in the data block unsigned element_count); /* number of elements in the data block */
#ifdef __cplusplus #ifdef __cplusplus
} }
+36 -36
View File
@@ -37,18 +37,18 @@
#include "bacdef.h" #include "bacdef.h"
#include "rp.h" #include "rp.h"
// encode service /* encode service */
int rp_encode_apdu(uint8_t * apdu, int rp_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data) uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data)
{ {
int len = 0; // length of each encoding int len = 0; /* length of each encoding */
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 (apdu) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
apdu[2] = invoke_id; apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; // service choice apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
apdu_len = 4; apdu_len = 4;
len = encode_context_object_id(&apdu[apdu_len], 0, len = encode_context_object_id(&apdu[apdu_len], 0,
data->object_type, data->object_instance); data->object_type, data->object_instance);
@@ -67,32 +67,32 @@ int rp_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int rp_decode_service_request(uint8_t * apdu, int rp_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data) unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data)
{ {
unsigned len = 0; unsigned len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
int type = 0; // for decoding int type = 0; /* for decoding */
int property = 0; // for decoding int property = 0; /* for decoding */
uint32_t array_value = 0; // for decoding uint32_t array_value = 0; /* for decoding */
// check for value pointers /* check for value pointers */
if (apdu_len && data) { if (apdu_len && data) {
// Tag 0: Object ID /* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[len++], 0)) if (!decode_is_context_tag(&apdu[len++], 0))
return -1; return -1;
len += decode_object_id(&apdu[len], &type, &data->object_instance); len += decode_object_id(&apdu[len], &type, &data->object_instance);
data->object_type = type; data->object_type = type;
// Tag 1: Property ID /* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len], len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number != 1) if (tag_number != 1)
return -1; return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property); len += decode_enumerated(&apdu[len], len_value_type, &property);
data->object_property = property; data->object_property = property;
// Tag 2: Optional Array Index /* Tag 2: Optional Array Index */
if (len < apdu_len) { if (len < apdu_len) {
len += decode_tag_number_and_value(&apdu[len], &tag_number, len += decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type); &len_value_type);
@@ -118,10 +118,10 @@ int rp_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY)
return -1; return -1;
@@ -138,25 +138,25 @@ int rp_decode_apdu(uint8_t * apdu,
int rp_ack_encode_apdu(uint8_t * apdu, int rp_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data) uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data)
{ {
int len = 0; // length of each encoding int len = 0; /* length of each encoding */
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 (apdu) {
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
apdu[1] = invoke_id; /* original invoke id from request */ 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; apdu_len = 3;
// service ack follows /* service ack follows */
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
data->object_type, data->object_instance); data->object_type, data->object_instance);
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, apdu_len += encode_context_enumerated(&apdu[apdu_len], 1,
data->object_property); data->object_property);
// context 2 array index is optional /* context 2 array index is optional */
if (data->array_index != BACNET_ARRAY_ALL) { if (data->array_index != BACNET_ARRAY_ALL) {
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, apdu_len += encode_context_unsigned(&apdu[apdu_len], 2,
data->array_index); data->array_index);
} }
// propertyValue /* propertyValue */
apdu_len += encode_opening_tag(&apdu[apdu_len], 3); apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
for (len = 0; len < data->application_data_len; len++) { for (len = 0; len < data->application_data_len; len++) {
apdu[apdu_len++] = data->application_data[len]; apdu[apdu_len++] = data->application_data[len];
@@ -167,31 +167,31 @@ int rp_ack_encode_apdu(uint8_t * apdu,
return apdu_len; 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) BACNET_READ_PROPERTY_DATA * data)
{ {
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
int tag_len = 0; // length of tag decode int tag_len = 0; /* length of tag decode */
int len = 0; // total length of decodes int len = 0; /* total length of decodes */
int object = 0, property = 0; // for decoding int object = 0, property = 0; /* for decoding */
uint32_t array_value = 0; // for decoding uint32_t array_value = 0; /* for decoding */
// FIXME: check apdu_len against the len during decode /* FIXME: check apdu_len against the len during decode */
// Tag 0: Object ID /* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[0], 0)) if (!decode_is_context_tag(&apdu[0], 0))
return -1; return -1;
len = 1; len = 1;
len += decode_object_id(&apdu[len], &object, &data->object_instance); len += decode_object_id(&apdu[len], &object, &data->object_instance);
data->object_type = object; data->object_type = object;
// Tag 1: Property ID /* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len], len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number != 1) if (tag_number != 1)
return -1; return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property); len += decode_enumerated(&apdu[len], len_value_type, &property);
data->object_property = 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_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number == 2) { if (tag_number == 2) {
@@ -201,11 +201,11 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length
} else } else
data->array_index = BACNET_ARRAY_ALL; data->array_index = BACNET_ARRAY_ALL;
// Tag 3: opening context tag */ /* Tag 3: opening context tag */ */
if (decode_is_opening_tag_number(&apdu[len], 3)) { if (decode_is_opening_tag_number(&apdu[len], 3)) {
// 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++;
// 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 = &apdu[len];
data->application_data_len = apdu_len - len - 1 /*closing tag */ ; data->application_data_len = apdu_len - len - 1 /*closing tag */ ;
} else } else
@@ -214,7 +214,7 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, // total length
return len; 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) uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data)
{ {
int len = 0; 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) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
return -1; return -1;
*invoke_id = apdu[1]; *invoke_id = apdu[1];
@@ -269,7 +269,7 @@ void testReadPropertyAck(Test * pTest)
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
apdu_len = len; 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); &test_invoke_id, &test_data);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_invoke_id == invoke_id);
+4 -4
View File
@@ -50,11 +50,11 @@ typedef struct BACnet_Read_Property_Data {
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// encode service /* encode service */
int rp_encode_apdu(uint8_t * apdu, int rp_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data); 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, int rp_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data); unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data);
@@ -65,10 +65,10 @@ extern "C" {
int rp_ack_encode_apdu(uint8_t * apdu, int rp_ack_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data); 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); 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); uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data);
+4 -4
View File
@@ -45,11 +45,11 @@ extern "C" {
void RS485_Initialize(void); void RS485_Initialize(void);
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port specific data 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) uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes); // number of bytes of data (up to 501) 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); void RS485_Process_Tx_Message(void);
+32 -32
View File
@@ -34,7 +34,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> // memmove() #include <string.h> /* memmove() */
#include "bits.h" #include "bits.h"
#include "apdu.h" #include "apdu.h"
#include "bacdef.h" #include "bacdef.h"
@@ -47,23 +47,23 @@
#include "handlers.h" #include "handlers.h"
#include "address.h" #include "address.h"
// Transaction State Machine /* Transaction State Machine */
// Really only needed for segmented messages /* Really only needed for segmented messages */
// and a little for sending confirmed messages /* and a little for sending confirmed messages */
// If we are only a server and only initiate broadcasts, /* If we are only a server and only initiate broadcasts, */
// then we don't need a TSM layer. /* 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 */ /* table rules: an Invoke ID = 0 is an unused spot in the table */
static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = { {0} }; 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) static uint8_t tsm_find_invokeID_index(uint8_t invokeID)
{ {
unsigned i = 0; // counter unsigned i = 0; /* counter */
uint8_t index = MAX_TSM_TRANSACTIONS; // return value uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
if (TSM_List[i].InvokeID == invokeID) { 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) static uint8_t tsm_find_first_free_index(void)
{ {
unsigned i = 0; // counter unsigned i = 0; /* counter */
uint8_t index = MAX_TSM_TRANSACTIONS; // return value uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
if (TSM_List[i].InvokeID == 0) { 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 tsm_transaction_available(void)
{ {
bool status = false; // return value bool status = false; /* return value */
unsigned i = 0; // counter unsigned i = 0; /* counter */
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
if (TSM_List[i].InvokeID == 0) { if (TSM_List[i].InvokeID == 0) {
// one is available! /* one is available! */
status = true; status = true;
break; break;
} }
@@ -108,13 +108,13 @@ bool tsm_transaction_available(void)
uint8_t tsm_transaction_idle_count(void) uint8_t tsm_transaction_idle_count(void)
{ {
uint8_t count = 0; // return value uint8_t count = 0; /* return value */
unsigned i = 0; // counter unsigned i = 0; /* counter */
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
if ((TSM_List[i].InvokeID == 0) && if ((TSM_List[i].InvokeID == 0) &&
(TSM_List[i].state == TSM_STATE_IDLE)) { (TSM_List[i].state == TSM_STATE_IDLE)) {
// one is available! /* one is available! */
count++; count++;
} }
} }
@@ -127,7 +127,7 @@ uint8_t tsm_transaction_idle_count(void)
returns 0 if none are available */ returns 0 if none are available */
uint8_t tsm_next_free_invokeID(void) 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 index = 0;
uint8_t invokeID = 0; uint8_t invokeID = 0;
bool found = false; bool found = false;
@@ -145,7 +145,7 @@ uint8_t tsm_next_free_invokeID(void)
TSM_List[index].RequestTimer = Device_APDU_Timeout(); TSM_List[index].RequestTimer = Device_APDU_Timeout();
/* update for the next call or check */ /* update for the next call or check */
current_invokeID++; 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) if (current_invokeID == 0)
current_invokeID = 1; current_invokeID = 1;
} }
@@ -164,12 +164,12 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
if (invokeID) { if (invokeID) {
index = tsm_find_invokeID_index(invokeID); index = tsm_find_invokeID_index(invokeID);
if (index < MAX_TSM_TRANSACTIONS) { if (index < MAX_TSM_TRANSACTIONS) {
// assign the transaction /* assign the transaction */
TSM_List[index].state = TSM_STATE_AWAIT_CONFIRMATION; TSM_List[index].state = TSM_STATE_AWAIT_CONFIRMATION;
TSM_List[index].RetryCount = Device_Number_Of_APDU_Retries(); TSM_List[index].RetryCount = Device_Number_Of_APDU_Retries();
// start the timer /* start the timer */
TSM_List[index].RequestTimer = Device_APDU_Timeout(); TSM_List[index].RequestTimer = Device_APDU_Timeout();
// copy the data /* copy the data */
for (j = 0; j < pdu_len; j++) { for (j = 0; j < pdu_len; j++) {
TSM_List[index].pdu[j] = pdu[j]; TSM_List[index].pdu[j] = pdu[j];
} }
@@ -181,8 +181,8 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
return; return;
} }
// used to retrieve the transaction payload /* used to retrieve the transaction payload */
// if we wanted to find out what we sent (i.e. when we get an ack) /* if we wanted to find out what we sent (i.e. when we get an ack) */
bool tsm_get_transaction_pdu(uint8_t invokeID, bool tsm_get_transaction_pdu(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len) BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len)
{ {
@@ -192,11 +192,11 @@ bool tsm_get_transaction_pdu(uint8_t invokeID,
if (invokeID) { if (invokeID) {
index = tsm_find_invokeID_index(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) { if (index < MAX_TSM_TRANSACTIONS) {
// FIXME: we may want to free the transaction so it doesn't timeout /* FIXME: we may want to free the transaction so it doesn't timeout */
// retrieve the transaction /* retrieve the transaction */
// FIXME: bounds check the pdu_len? /* FIXME: bounds check the pdu_len? */
*pdu_len = TSM_List[index].pdu_len; *pdu_len = TSM_List[index].pdu_len;
for (j = 0; j < *pdu_len; j++) { for (j = 0; j < *pdu_len; j++) {
pdu[j] = TSM_List[index].pdu[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 */ /* called once a millisecond or slower */
void tsm_timer_milliseconds(uint16_t milliseconds) void tsm_timer_milliseconds(uint16_t milliseconds)
{ {
unsigned i = 0; // counter unsigned i = 0; /* counter */
int bytes_sent = 0; int bytes_sent = 0;
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
@@ -266,7 +266,7 @@ bool tsm_invoke_id_free(uint8_t invokeID)
#include <string.h> #include <string.h>
#include "ctest.h" #include "ctest.h"
// flag to send an I-Am /* flag to send an I-Am */
bool I_Am_Request = true; bool I_Am_Request = true;
void testTSM(Test * pTest) void testTSM(Test * pTest)
+29 -29
View File
@@ -50,37 +50,37 @@ typedef enum {
TSM_STATE_SEGMENTED_CONFIRMATION TSM_STATE_SEGMENTED_CONFIRMATION
} BACNET_TSM_STATE; } BACNET_TSM_STATE;
// 5.4.1 Variables And Parameters /* 5.4.1 Variables And Parameters */
// The following variables are defined for each instance of /* The following variables are defined for each instance of */
// Transaction State Machine: /* Transaction State Machine: */
typedef struct BACnet_TSM_Data { typedef struct BACnet_TSM_Data {
// used to count APDU retries /* used to count APDU retries */
uint8_t RetryCount; uint8_t RetryCount;
// used to count segment retries /* used to count segment retries */
//uint8_t SegmentRetryCount; /*uint8_t SegmentRetryCount; */
// used to control APDU retries and the acceptance of server replies /* used to control APDU retries and the acceptance of server replies */
//bool SentAllSegments; /*bool SentAllSegments; */
// stores the sequence number of the last segment received in order /* stores the sequence number of the last segment received in order */
//uint8_t LastSequenceNumber; /*uint8_t LastSequenceNumber; */
// stores the sequence number of the first segment of /* stores the sequence number of the first segment of */
// a sequence of segments that fill a window /* a sequence of segments that fill a window */
//uint8_t InitialSequenceNumber; /*uint8_t InitialSequenceNumber; */
// stores the current window size /* stores the current window size */
//uint8_t ActualWindowSize; /*uint8_t ActualWindowSize; */
// stores the window size proposed by the segment sender /* stores the window size proposed by the segment sender */
//uint8_t ProposedWindowSize; /*uint8_t ProposedWindowSize; */
// used to perform timeout on PDU segments /* used to perform timeout on PDU segments */
//uint8_t SegmentTimer; /*uint8_t SegmentTimer; */
// used to perform timeout on Confirmed Requests /* used to perform timeout on Confirmed Requests */
// in milliseconds /* in milliseconds */
uint16_t RequestTimer; uint16_t RequestTimer;
// unique id /* unique id */
uint8_t InvokeID; uint8_t InvokeID;
// state that the TSM is in /* state that the TSM is in */
BACNET_TSM_STATE state; BACNET_TSM_STATE state;
// the address we sent it to /* the address we sent it to */
BACNET_ADDRESS dest; 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]; uint8_t pdu[MAX_PDU];
unsigned pdu_len; unsigned pdu_len;
} BACNET_TSM_DATA; } BACNET_TSM_DATA;
@@ -92,14 +92,14 @@ extern "C" {
bool tsm_transaction_available(void); bool tsm_transaction_available(void);
uint8_t tsm_transaction_idle_count(void); uint8_t tsm_transaction_idle_count(void);
void tsm_timer_milliseconds(uint16_t milliseconds); 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); void tsm_free_invoke_id(uint8_t invokeID);
// use these in tandem /* use these in tandem */
uint8_t tsm_next_free_invokeID(void); 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, void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t pdu_len); 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, bool tsm_get_transaction_pdu(uint8_t invokeID,
BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len); BACNET_ADDRESS * dest, uint8_t * pdu, uint16_t * pdu_len);
+7 -7
View File
@@ -41,14 +41,14 @@
int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data) int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data)
{ {
int len = 0; // length of each encoding int len = 0; /* length of each encoding */
int apdu_len = 0; // total length of the apdu, return value int apdu_len = 0; /* total length of the apdu, return value */
if (apdu && data) { if (apdu && data) {
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; 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; apdu_len = 2;
// optional limits - must be used as a pair /* optional limits - must be used as a pair */
if ((data->low_limit >= 0) if ((data->low_limit >= 0)
&& (data->low_limit <= BACNET_MAX_INSTANCE) && (data->low_limit <= BACNET_MAX_INSTANCE)
&& (data->high_limit >= 0) && (data->high_limit >= 0)
@@ -77,7 +77,7 @@ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data)
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int whohas_decode_service_request(uint8_t * apdu, int whohas_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_WHO_HAS_DATA * data) unsigned apdu_len, BACNET_WHO_HAS_DATA * data)
{ {
@@ -144,12 +144,12 @@ int whohas_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
return -1; return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS)
return -1; return -1;
// optional limits - must be used as a pair /* optional limits - must be used as a pair */
if (apdu_len > 2) { if (apdu_len > 2) {
len = whohas_decode_service_request(&apdu[2], apdu_len - 2, data); len = whohas_decode_service_request(&apdu[2], apdu_len - 2, data);
} }
+1 -1
View File
@@ -52,7 +52,7 @@ typedef struct BACnet_Who_Has_Data {
extern "C" { extern "C" {
#endif /* __cplusplus */ #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_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data);
int whohas_decode_service_request(uint8_t * apdu, int whohas_decode_service_request(uint8_t * apdu,
+9 -9
View File
@@ -36,18 +36,18 @@
#include "bacdcode.h" #include "bacdcode.h"
#include "bacdef.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, int whois_encode_apdu(uint8_t * apdu,
int32_t low_limit, int32_t high_limit) int32_t low_limit, int32_t high_limit)
{ {
int len = 0; // length of each encoding int len = 0; /* length of each encoding */
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 (apdu) {
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; 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; 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) && if ((low_limit >= 0) && (low_limit <= BACNET_MAX_INSTANCE) &&
(high_limit >= 0) && (high_limit <= BACNET_MAX_INSTANCE)) { (high_limit >= 0) && (high_limit <= BACNET_MAX_INSTANCE)) {
len = encode_context_unsigned(&apdu[apdu_len], 0, low_limit); len = encode_context_unsigned(&apdu[apdu_len], 0, low_limit);
@@ -60,7 +60,7 @@ int whois_encode_apdu(uint8_t * apdu,
return apdu_len; return apdu_len;
} }
// decode the service request only /* decode the service request only */
int whois_decode_service_request(uint8_t * apdu, int whois_decode_service_request(uint8_t * apdu,
unsigned apdu_len, int32_t * pLow_limit, int32_t * pHigh_limit) 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 len_value = 0;
uint32_t decoded_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) { if (apdu_len) {
len += len +=
decode_tag_number_and_value(&apdu[len], &tag_number, decode_tag_number_and_value(&apdu[len], &tag_number,
@@ -103,12 +103,12 @@ int whois_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
return -1; return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS)
return -1; return -1;
// optional limits - must be used as a pair /* optional limits - must be used as a pair */
if (apdu_len > 2) { if (apdu_len > 2) {
len = whois_decode_service_request(&apdu[2], len = whois_decode_service_request(&apdu[2],
apdu_len - 2, pLow_limit, pHigh_limit); apdu_len - 2, pLow_limit, pHigh_limit);
+1 -1
View File
@@ -41,7 +41,7 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #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, int whois_encode_apdu(uint8_t * apdu,
int32_t low_limit, int32_t high_limit); int32_t low_limit, int32_t high_limit);
+19 -19
View File
@@ -38,18 +38,18 @@
#include "device.h" #include "device.h"
#include "wp.h" #include "wp.h"
// encode service /* encode service */
int wp_encode_apdu(uint8_t * apdu, int wp_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_WRITE_PROPERTY_DATA * data) 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) { if (apdu) {
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = apdu[1] =
encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted());
apdu[2] = invoke_id; 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 = 4;
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
data->object_type, data->object_instance); data->object_type, data->object_instance);
@@ -59,12 +59,12 @@ int wp_encode_apdu(uint8_t * apdu,
if (data->array_index != BACNET_ARRAY_ALL) if (data->array_index != BACNET_ARRAY_ALL)
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, apdu_len += encode_context_unsigned(&apdu[apdu_len], 2,
data->array_index); data->array_index);
// propertyValue /* propertyValue */
apdu_len += encode_opening_tag(&apdu[apdu_len], 3); apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
apdu_len += apdu_len +=
bacapp_encode_application_data(&apdu[apdu_len], &data->value); bacapp_encode_application_data(&apdu[apdu_len], &data->value);
apdu_len += encode_closing_tag(&apdu[apdu_len], 3); 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) if (data->priority != BACNET_NO_PRIORITY)
apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, apdu_len += encode_context_unsigned(&apdu[apdu_len], 4,
data->priority); data->priority);
@@ -83,26 +83,26 @@ int wp_decode_service_request(uint8_t * apdu,
int tag_len = 0; int tag_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
int type = 0; // for decoding int type = 0; /* for decoding */
int property = 0; // for decoding int property = 0; /* for decoding */
uint32_t unsigned_value = 0; uint32_t unsigned_value = 0;
// check for value pointers /* check for value pointers */
if (apdu_len && data) { if (apdu_len && data) {
// Tag 0: Object ID /* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[len++], 0)) if (!decode_is_context_tag(&apdu[len++], 0))
return -1; return -1;
len += decode_object_id(&apdu[len], &type, &data->object_instance); len += decode_object_id(&apdu[len], &type, &data->object_instance);
data->object_type = type; data->object_type = type;
// Tag 1: Property ID /* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len], len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number != 1) if (tag_number != 1)
return -1; return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property); len += decode_enumerated(&apdu[len], len_value_type, &property);
data->object_property = property; data->object_property = property;
// Tag 2: Optional Array Index /* Tag 2: Optional Array Index */
// note: decode without incrementing len so we can check for opening tag /* note: decode without incrementing len so we can check for opening tag */
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type); &tag_number, &len_value_type);
if (tag_number == 2) { if (tag_number == 2) {
@@ -112,10 +112,10 @@ int wp_decode_service_request(uint8_t * apdu,
data->array_index = unsigned_value; data->array_index = unsigned_value;
} else } else
data->array_index = BACNET_ARRAY_ALL; data->array_index = BACNET_ARRAY_ALL;
// Tag 3: opening context tag */ /* Tag 3: opening context tag */ */
if (!decode_is_opening_tag_number(&apdu[len], 3)) if (!decode_is_opening_tag_number(&apdu[len], 3))
return -1; 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++;
len += bacapp_decode_application_data(&apdu[len], len += bacapp_decode_application_data(&apdu[len],
apdu_len - len, &data->value); 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! */ /* FIXME: there might be more than one data element in here! */
if (!decode_is_closing_tag_number(&apdu[len], 3)) if (!decode_is_closing_tag_number(&apdu[len], 3))
return -1; 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++;
// 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; data->priority = BACNET_MAX_PRIORITY;
if ((unsigned) len < apdu_len) { if ((unsigned) len < apdu_len) {
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
@@ -156,10 +156,10 @@ int wp_decode_apdu(uint8_t * apdu,
if (!apdu) if (!apdu)
return -1; 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) if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
return -1; 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 */ *invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_WRITE_PROPERTY) if (apdu[3] != SERVICE_CONFIRMED_WRITE_PROPERTY)
return -1; return -1;
+4 -4
View File
@@ -43,20 +43,20 @@ typedef struct BACnet_Write_Property_Data {
BACNET_OBJECT_TYPE object_type; BACNET_OBJECT_TYPE object_type;
uint32_t object_instance; uint32_t object_instance;
BACNET_PROPERTY_ID object_property; 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; 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; } BACNET_WRITE_PROPERTY_DATA;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
// encode service /* encode service */
int wp_encode_apdu(uint8_t * apdu, int wp_encode_apdu(uint8_t * apdu,
uint8_t invoke_id, BACNET_WRITE_PROPERTY_DATA * data); 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, int wp_decode_service_request(uint8_t * apdu,
unsigned apdu_len, BACNET_WRITE_PROPERTY_DATA * data); unsigned apdu_len, BACNET_WRITE_PROPERTY_DATA * data);