Indented.
This commit is contained in:
+27
-13
@@ -37,10 +37,13 @@
|
||||
#include "bacdef.h"
|
||||
|
||||
/* encode service */
|
||||
int abort_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, uint8_t abort_reason, bool server)
|
||||
int abort_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
uint8_t abort_reason,
|
||||
bool server)
|
||||
{
|
||||
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 (server)
|
||||
@@ -56,8 +59,11 @@ int abort_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int abort_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason)
|
||||
int abort_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint8_t * abort_reason)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -77,8 +83,11 @@ int abort_decode_service_request(uint8_t * apdu,
|
||||
#include "ctest.h"
|
||||
|
||||
/* decode the whole APDU - mainly used for unit testing */
|
||||
int abort_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason,
|
||||
int abort_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint8_t * abort_reason,
|
||||
bool * server)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -102,8 +111,11 @@ int abort_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testAbortAPDU(Test * pTest,
|
||||
uint8_t invoke_id, uint8_t abort_reason, bool server)
|
||||
void testAbortAPDU(
|
||||
Test * pTest,
|
||||
uint8_t invoke_id,
|
||||
uint8_t abort_reason,
|
||||
bool server)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -126,7 +138,8 @@ void testAbortAPDU(Test * pTest,
|
||||
}
|
||||
|
||||
|
||||
void testAbort(Test * pTest)
|
||||
void testAbort(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -174,7 +187,8 @@ void testAbort(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_ABORT
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -191,5 +205,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_ABORT */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_ABORT */
|
||||
#endif /* TEST */
|
||||
|
||||
+46
-27
@@ -53,7 +53,8 @@ static struct Address_Cache_Entry {
|
||||
BACNET_ADDRESS address;
|
||||
} Address_Cache[MAX_ADDRESS_CACHE];
|
||||
|
||||
void address_remove_device(uint32_t device_id)
|
||||
void address_remove_device(
|
||||
uint32_t device_id)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
@@ -69,7 +70,8 @@ void address_remove_device(uint32_t device_id)
|
||||
return;
|
||||
}
|
||||
|
||||
void address_init(void)
|
||||
void address_init(
|
||||
void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
@@ -81,11 +83,13 @@ void address_init(void)
|
||||
return;
|
||||
}
|
||||
|
||||
bool address_get_by_device(uint32_t device_id,
|
||||
unsigned *max_apdu, BACNET_ADDRESS * src)
|
||||
bool address_get_by_device(
|
||||
uint32_t device_id,
|
||||
unsigned *max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
unsigned i;
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
if (Address_Cache[i].valid &&
|
||||
@@ -101,11 +105,12 @@ bool address_get_by_device(uint32_t device_id,
|
||||
}
|
||||
|
||||
/* find a device id from a given MAC address */
|
||||
bool address_get_device_id(BACNET_ADDRESS * src,
|
||||
uint32_t *device_id)
|
||||
bool address_get_device_id(
|
||||
BACNET_ADDRESS * src,
|
||||
uint32_t * device_id)
|
||||
{
|
||||
unsigned i;
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
if (Address_Cache[i].valid) {
|
||||
@@ -122,11 +127,13 @@ bool address_get_device_id(BACNET_ADDRESS * src,
|
||||
return found;
|
||||
}
|
||||
|
||||
void address_add(uint32_t device_id,
|
||||
unsigned max_apdu, BACNET_ADDRESS * src)
|
||||
void address_add(
|
||||
uint32_t device_id,
|
||||
unsigned max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
unsigned i;
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
/* existing device - update address */
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
@@ -156,11 +163,13 @@ void address_add(uint32_t device_id,
|
||||
|
||||
/* returns true if device is already bound */
|
||||
/* also returns the address and max apdu if already bound */
|
||||
bool address_bind_request(uint32_t device_id,
|
||||
unsigned *max_apdu, BACNET_ADDRESS * src)
|
||||
bool address_bind_request(
|
||||
uint32_t device_id,
|
||||
unsigned *max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
unsigned i;
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
/* existing device - update address */
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
@@ -192,11 +201,13 @@ bool address_bind_request(uint32_t device_id,
|
||||
return found;
|
||||
}
|
||||
|
||||
void address_add_binding(uint32_t device_id,
|
||||
unsigned max_apdu, BACNET_ADDRESS * src)
|
||||
void address_add_binding(
|
||||
uint32_t device_id,
|
||||
unsigned max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
unsigned i;
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
/* existing device - update address */
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
@@ -225,10 +236,13 @@ void address_add_binding(uint32_t device_id,
|
||||
return;
|
||||
}
|
||||
|
||||
bool address_get_by_index(unsigned index,
|
||||
uint32_t * device_id, unsigned *max_apdu, BACNET_ADDRESS * src)
|
||||
bool address_get_by_index(
|
||||
unsigned index,
|
||||
uint32_t * device_id,
|
||||
unsigned *max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
bool found = false; /* return value */
|
||||
bool found = false; /* return value */
|
||||
|
||||
if (index < MAX_ADDRESS_CACHE) {
|
||||
if (Address_Cache[index].valid) {
|
||||
@@ -242,10 +256,11 @@ bool address_get_by_index(unsigned index,
|
||||
return found;
|
||||
}
|
||||
|
||||
unsigned address_count(void)
|
||||
unsigned address_count(
|
||||
void)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned count = 0; /* return value */
|
||||
unsigned count = 0; /* return value */
|
||||
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
if (Address_Cache[i].valid)
|
||||
@@ -260,7 +275,9 @@ unsigned address_count(void)
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
static void set_address(unsigned index, BACNET_ADDRESS * dest)
|
||||
static void set_address(
|
||||
unsigned index,
|
||||
BACNET_ADDRESS * dest)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
@@ -275,7 +292,8 @@ static void set_address(unsigned index, BACNET_ADDRESS * dest)
|
||||
}
|
||||
}
|
||||
|
||||
void testAddress(Test * pTest)
|
||||
void testAddress(
|
||||
Test * pTest)
|
||||
{
|
||||
unsigned i, count;
|
||||
BACNET_ADDRESS src;
|
||||
@@ -324,7 +342,8 @@ void testAddress(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_ADDRESS
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -341,5 +360,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_ADDRESS */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_ADDRESS */
|
||||
#endif /* TEST */
|
||||
|
||||
+230
-218
@@ -97,7 +97,8 @@ static BACNET_SERVICES_SUPPORTED
|
||||
/* If they are not set, they are handled by a reject message */
|
||||
static confirmed_function Confirmed_Function[MAX_BACNET_CONFIRMED_SERVICE];
|
||||
|
||||
void apdu_set_confirmed_handler(BACNET_CONFIRMED_SERVICE service_choice,
|
||||
void apdu_set_confirmed_handler(
|
||||
BACNET_CONFIRMED_SERVICE service_choice,
|
||||
confirmed_function pFunction)
|
||||
{
|
||||
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE)
|
||||
@@ -107,8 +108,8 @@ void apdu_set_confirmed_handler(BACNET_CONFIRMED_SERVICE service_choice,
|
||||
/* Allow the APDU handler to automatically reject */
|
||||
static confirmed_function Unrecognized_Service_Handler;
|
||||
|
||||
void apdu_set_unrecognized_service_handler_handler(confirmed_function
|
||||
pFunction)
|
||||
void apdu_set_unrecognized_service_handler_handler(
|
||||
confirmed_function pFunction)
|
||||
{
|
||||
Unrecognized_Service_Handler = pFunction;
|
||||
}
|
||||
@@ -118,14 +119,16 @@ void apdu_set_unrecognized_service_handler_handler(confirmed_function
|
||||
static unconfirmed_function
|
||||
Unconfirmed_Function[MAX_BACNET_UNCONFIRMED_SERVICE];
|
||||
|
||||
void apdu_set_unconfirmed_handler(BACNET_UNCONFIRMED_SERVICE
|
||||
service_choice, unconfirmed_function pFunction)
|
||||
void apdu_set_unconfirmed_handler(
|
||||
BACNET_UNCONFIRMED_SERVICE service_choice,
|
||||
unconfirmed_function pFunction)
|
||||
{
|
||||
if (service_choice < MAX_BACNET_UNCONFIRMED_SERVICE)
|
||||
Unconfirmed_Function[service_choice] = pFunction;
|
||||
}
|
||||
|
||||
bool apdu_service_supported(BACNET_SERVICES_SUPPORTED service_supported)
|
||||
bool apdu_service_supported(
|
||||
BACNET_SERVICES_SUPPORTED service_supported)
|
||||
{
|
||||
int i = 0;
|
||||
bool status = false;
|
||||
@@ -159,70 +162,73 @@ bool apdu_service_supported(BACNET_SERVICES_SUPPORTED service_supported)
|
||||
/* Confirmed ACK Function Handlers */
|
||||
static void *Confirmed_ACK_Function[MAX_BACNET_CONFIRMED_SERVICE];
|
||||
|
||||
void apdu_set_confirmed_simple_ack_handler(BACNET_CONFIRMED_SERVICE
|
||||
service_choice, confirmed_simple_ack_function pFunction)
|
||||
void apdu_set_confirmed_simple_ack_handler(
|
||||
BACNET_CONFIRMED_SERVICE service_choice,
|
||||
confirmed_simple_ack_function pFunction)
|
||||
{
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM:
|
||||
case SERVICE_CONFIRMED_COV_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_EVENT_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
|
||||
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_DELETE_OBJECT:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
|
||||
case SERVICE_CONFIRMED_TEXT_MESSAGE:
|
||||
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_CLOSE:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_REQUEST_KEY:
|
||||
Confirmed_ACK_Function[service_choice] = (void *) pFunction;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM:
|
||||
case SERVICE_CONFIRMED_COV_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_EVENT_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
|
||||
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_DELETE_OBJECT:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
|
||||
case SERVICE_CONFIRMED_TEXT_MESSAGE:
|
||||
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_CLOSE:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_REQUEST_KEY:
|
||||
Confirmed_ACK_Function[service_choice] = (void *) pFunction;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void apdu_set_confirmed_ack_handler(BACNET_CONFIRMED_SERVICE
|
||||
service_choice, confirmed_ack_function pFunction)
|
||||
void apdu_set_confirmed_ack_handler(
|
||||
BACNET_CONFIRMED_SERVICE service_choice,
|
||||
confirmed_ack_function pFunction)
|
||||
{
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_GET_ALARM_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
|
||||
/* File Access Services */
|
||||
case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
|
||||
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_CREATE_OBJECT:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
|
||||
case SERVICE_CONFIRMED_READ_RANGE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_OPEN:
|
||||
case SERVICE_CONFIRMED_VT_DATA:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_AUTHENTICATE:
|
||||
Confirmed_ACK_Function[service_choice] = (void *) pFunction;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SERVICE_CONFIRMED_GET_ALARM_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
|
||||
/* File Access Services */
|
||||
case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
|
||||
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_CREATE_OBJECT:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
|
||||
case SERVICE_CONFIRMED_READ_RANGE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_OPEN:
|
||||
case SERVICE_CONFIRMED_VT_DATA:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_AUTHENTICATE:
|
||||
Confirmed_ACK_Function[service_choice] = (void *) pFunction;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static error_function Error_Function[MAX_BACNET_CONFIRMED_SERVICE];
|
||||
|
||||
void apdu_set_error_handler(BACNET_CONFIRMED_SERVICE service_choice,
|
||||
void apdu_set_error_handler(
|
||||
BACNET_CONFIRMED_SERVICE service_choice,
|
||||
error_function pFunction)
|
||||
{
|
||||
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE)
|
||||
@@ -231,25 +237,29 @@ void apdu_set_error_handler(BACNET_CONFIRMED_SERVICE service_choice,
|
||||
|
||||
static abort_function Abort_Function;
|
||||
|
||||
void apdu_set_abort_handler(abort_function pFunction)
|
||||
void apdu_set_abort_handler(
|
||||
abort_function pFunction)
|
||||
{
|
||||
Abort_Function = pFunction;
|
||||
}
|
||||
|
||||
static reject_function Reject_Function;
|
||||
|
||||
void apdu_set_reject_handler(reject_function pFunction)
|
||||
void apdu_set_reject_handler(
|
||||
reject_function pFunction)
|
||||
{
|
||||
Reject_Function = pFunction;
|
||||
}
|
||||
|
||||
uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */
|
||||
uint16_t apdu_decode_confirmed_service_request(
|
||||
uint8_t * apdu, /* APDU data */
|
||||
uint16_t apdu_len,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data,
|
||||
uint8_t * service_choice,
|
||||
uint8_t ** service_request, uint16_t * service_request_len)
|
||||
uint8_t ** service_request,
|
||||
uint16_t * service_request_len)
|
||||
{
|
||||
uint16_t len = 0; /* counts where we are in PDU */
|
||||
uint16_t len = 0; /* counts where we are in PDU */
|
||||
|
||||
service_data->segmented_message = (apdu[0] & BIT3) ? true : false;
|
||||
service_data->more_follows = (apdu[0] & BIT2) ? true : false;
|
||||
@@ -270,7 +280,9 @@ uint16_t apdu_decode_confirmed_service_request(uint8_t * apdu, /* APDU data */
|
||||
return len;
|
||||
}
|
||||
|
||||
void apdu_handler(BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */
|
||||
void apdu_handler(
|
||||
BACNET_ADDRESS * src,
|
||||
uint8_t * apdu, /* APDU data */
|
||||
uint16_t apdu_len)
|
||||
{
|
||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||
@@ -279,7 +291,7 @@ void apdu_handler(BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */
|
||||
uint8_t service_choice = 0;
|
||||
uint8_t *service_request = NULL;
|
||||
uint16_t service_request_len = 0;
|
||||
uint16_t len = 0; /* counts where we are in PDU */
|
||||
uint16_t len = 0; /* counts where we are in PDU */
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
int error_code = 0;
|
||||
@@ -290,165 +302,165 @@ void apdu_handler(BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */
|
||||
if (apdu) {
|
||||
/* PDU Type */
|
||||
switch (apdu[0] & 0xF0) {
|
||||
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
|
||||
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
|
||||
apdu_len,
|
||||
&service_data,
|
||||
&service_choice, &service_request, &service_request_len);
|
||||
/* When network communications are completely disabled,
|
||||
only DeviceCommunicationControl and ReinitializeDevice APDUs
|
||||
shall be processed and no messages shall be initiated. */
|
||||
if (dcc_communication_disabled() &&
|
||||
((service_choice !=
|
||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL)
|
||||
&& (service_choice !=
|
||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE)))
|
||||
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
|
||||
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
|
||||
apdu_len,
|
||||
&service_data,
|
||||
&service_choice, &service_request, &service_request_len);
|
||||
/* When network communications are completely disabled,
|
||||
only DeviceCommunicationControl and ReinitializeDevice APDUs
|
||||
shall be processed and no messages shall be initiated. */
|
||||
if (dcc_communication_disabled() &&
|
||||
((service_choice !=
|
||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL)
|
||||
&& (service_choice !=
|
||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE)))
|
||||
break;
|
||||
if ((service_choice < MAX_BACNET_CONFIRMED_SERVICE) &&
|
||||
(Confirmed_Function[service_choice]))
|
||||
Confirmed_Function[service_choice] (service_request,
|
||||
service_request_len, src, &service_data);
|
||||
else if (Unrecognized_Service_Handler)
|
||||
Unrecognized_Service_Handler(service_request,
|
||||
service_request_len, src, &service_data);
|
||||
break;
|
||||
if ((service_choice < MAX_BACNET_CONFIRMED_SERVICE) &&
|
||||
(Confirmed_Function[service_choice]))
|
||||
Confirmed_Function[service_choice] (service_request,
|
||||
service_request_len, src, &service_data);
|
||||
else if (Unrecognized_Service_Handler)
|
||||
Unrecognized_Service_Handler(service_request,
|
||||
service_request_len, src, &service_data);
|
||||
break;
|
||||
case PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST:
|
||||
if (dcc_communication_disabled())
|
||||
break;
|
||||
service_choice = apdu[1];
|
||||
service_request = &apdu[2];
|
||||
service_request_len = apdu_len - 2;
|
||||
if (service_choice < MAX_BACNET_UNCONFIRMED_SERVICE) {
|
||||
if (Unconfirmed_Function[service_choice])
|
||||
Unconfirmed_Function[service_choice] (service_request,
|
||||
service_request_len, src);
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_SIMPLE_ACK:
|
||||
invoke_id = apdu[1];
|
||||
service_choice = apdu[2];
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM:
|
||||
case SERVICE_CONFIRMED_COV_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_EVENT_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
|
||||
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_DELETE_OBJECT:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
|
||||
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
|
||||
case SERVICE_CONFIRMED_TEXT_MESSAGE:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_CLOSE:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_REQUEST_KEY:
|
||||
if (Confirmed_ACK_Function[service_choice]) {
|
||||
((confirmed_simple_ack_function)
|
||||
Confirmed_ACK_Function[service_choice]) (src,
|
||||
invoke_id);
|
||||
case PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST:
|
||||
if (dcc_communication_disabled())
|
||||
break;
|
||||
service_choice = apdu[1];
|
||||
service_request = &apdu[2];
|
||||
service_request_len = apdu_len - 2;
|
||||
if (service_choice < MAX_BACNET_UNCONFIRMED_SERVICE) {
|
||||
if (Unconfirmed_Function[service_choice])
|
||||
Unconfirmed_Function[service_choice] (service_request,
|
||||
service_request_len, src);
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_SIMPLE_ACK:
|
||||
invoke_id = apdu[1];
|
||||
service_choice = apdu[2];
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM:
|
||||
case SERVICE_CONFIRMED_COV_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_EVENT_NOTIFICATION:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV:
|
||||
case SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY:
|
||||
case SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_ADD_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
|
||||
case SERVICE_CONFIRMED_DELETE_OBJECT:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY:
|
||||
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
|
||||
/* Remote Device Management Services */
|
||||
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
|
||||
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
|
||||
case SERVICE_CONFIRMED_TEXT_MESSAGE:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_CLOSE:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_REQUEST_KEY:
|
||||
if (Confirmed_ACK_Function[service_choice]) {
|
||||
((confirmed_simple_ack_function)
|
||||
Confirmed_ACK_Function[service_choice]) (src,
|
||||
invoke_id);
|
||||
}
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_COMPLEX_ACK:
|
||||
service_ack_data.segmented_message =
|
||||
(apdu[0] & BIT3) ? true : false;
|
||||
service_ack_data.more_follows =
|
||||
(apdu[0] & BIT2) ? true : false;
|
||||
invoke_id = service_ack_data.invoke_id = apdu[1];
|
||||
len = 2;
|
||||
if (service_ack_data.segmented_message) {
|
||||
service_ack_data.sequence_number = apdu[len++];
|
||||
service_ack_data.proposed_window_number = apdu[len++];
|
||||
}
|
||||
service_choice = apdu[len++];
|
||||
service_request = &apdu[len];
|
||||
service_request_len = apdu_len - len;
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_GET_ALARM_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
|
||||
/* File Access Services */
|
||||
case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
|
||||
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_CREATE_OBJECT:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
|
||||
case SERVICE_CONFIRMED_READ_RANGE:
|
||||
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_OPEN:
|
||||
case SERVICE_CONFIRMED_VT_DATA:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_AUTHENTICATE:
|
||||
if (Confirmed_ACK_Function[service_choice]) {
|
||||
((confirmed_ack_function)
|
||||
Confirmed_ACK_Function[service_choice])
|
||||
(service_request, service_request_len, src,
|
||||
&service_ack_data);
|
||||
}
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_SEGMENT_ACK:
|
||||
/* FIXME: what about a denial of service attack here?
|
||||
we could check src to see if that matched the tsm */
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_ERROR:
|
||||
invoke_id = apdu[1];
|
||||
service_choice = apdu[2];
|
||||
len = 3;
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_class);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_code);
|
||||
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
|
||||
if (Error_Function[service_choice])
|
||||
Error_Function[service_choice] (src,
|
||||
invoke_id,
|
||||
(BACNET_ERROR_CLASS) error_class,
|
||||
(BACNET_ERROR_CODE) error_code);
|
||||
}
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_REJECT:
|
||||
invoke_id = apdu[1];
|
||||
reason = apdu[2];
|
||||
if (Reject_Function)
|
||||
Reject_Function(src, invoke_id, reason);
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_ABORT:
|
||||
server = apdu[0] & 0x01;
|
||||
invoke_id = apdu[1];
|
||||
reason = apdu[2];
|
||||
if (Abort_Function)
|
||||
Abort_Function(src, invoke_id, reason, server);
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_COMPLEX_ACK:
|
||||
service_ack_data.segmented_message =
|
||||
(apdu[0] & BIT3) ? true : false;
|
||||
service_ack_data.more_follows =
|
||||
(apdu[0] & BIT2) ? true : false;
|
||||
invoke_id = service_ack_data.invoke_id = apdu[1];
|
||||
len = 2;
|
||||
if (service_ack_data.segmented_message) {
|
||||
service_ack_data.sequence_number = apdu[len++];
|
||||
service_ack_data.proposed_window_number = apdu[len++];
|
||||
}
|
||||
service_choice = apdu[len++];
|
||||
service_request = &apdu[len];
|
||||
service_request_len = apdu_len - len;
|
||||
switch (service_choice) {
|
||||
case SERVICE_CONFIRMED_GET_ALARM_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY:
|
||||
case SERVICE_CONFIRMED_GET_EVENT_INFORMATION:
|
||||
/* File Access Services */
|
||||
case SERVICE_CONFIRMED_ATOMIC_READ_FILE:
|
||||
case SERVICE_CONFIRMED_ATOMIC_WRITE_FILE:
|
||||
/* Object Access Services */
|
||||
case SERVICE_CONFIRMED_CREATE_OBJECT:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
|
||||
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
|
||||
case SERVICE_CONFIRMED_READ_RANGE:
|
||||
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
|
||||
/* Virtual Terminal Services */
|
||||
case SERVICE_CONFIRMED_VT_OPEN:
|
||||
case SERVICE_CONFIRMED_VT_DATA:
|
||||
/* Security Services */
|
||||
case SERVICE_CONFIRMED_AUTHENTICATE:
|
||||
if (Confirmed_ACK_Function[service_choice]) {
|
||||
((confirmed_ack_function)
|
||||
Confirmed_ACK_Function[service_choice])
|
||||
(service_request, service_request_len, src,
|
||||
&service_ack_data);
|
||||
}
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PDU_TYPE_SEGMENT_ACK:
|
||||
/* FIXME: what about a denial of service attack here?
|
||||
we could check src to see if that matched the tsm */
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_ERROR:
|
||||
invoke_id = apdu[1];
|
||||
service_choice = apdu[2];
|
||||
len = 3;
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_class);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_code);
|
||||
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
|
||||
if (Error_Function[service_choice])
|
||||
Error_Function[service_choice] (src,
|
||||
invoke_id,
|
||||
(BACNET_ERROR_CLASS)error_class,
|
||||
(BACNET_ERROR_CODE)error_code);
|
||||
}
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_REJECT:
|
||||
invoke_id = apdu[1];
|
||||
reason = apdu[2];
|
||||
if (Reject_Function)
|
||||
Reject_Function(src, invoke_id, reason);
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
case PDU_TYPE_ABORT:
|
||||
server = apdu[0] & 0x01;
|
||||
invoke_id = apdu[1];
|
||||
reason = apdu[2];
|
||||
if (Abort_Function)
|
||||
Abort_Function(src, invoke_id, reason, server);
|
||||
tsm_free_invoke_id(invoke_id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
+80
-63
@@ -41,10 +41,12 @@
|
||||
/* Atomic Read File */
|
||||
|
||||
/* encode service */
|
||||
int arf_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
int arf_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -56,24 +58,24 @@ int arf_encode_apdu(uint8_t * apdu,
|
||||
apdu_len += encode_application_object_id(&apdu[apdu_len],
|
||||
data->object_type, data->object_instance);
|
||||
switch (data->access) {
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.stream.requestedOctetCount);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.RecordCount);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.stream.requestedOctetCount);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.RecordCount);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,14 +83,16 @@ int arf_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int arf_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
int arf_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
int tag_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu_len && data) {
|
||||
@@ -154,9 +158,11 @@ int arf_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int arf_decode_apdu(uint8_t * apdu,
|
||||
int arf_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -181,10 +187,12 @@ int arf_decode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* encode service */
|
||||
int arf_ack_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
int arf_ack_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK;
|
||||
@@ -195,26 +203,26 @@ int arf_ack_encode_apdu(uint8_t * apdu,
|
||||
apdu_len +=
|
||||
encode_application_boolean(&apdu[apdu_len], data->endOfFile);
|
||||
switch (data->access) {
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.RecordCount);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.RecordCount);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +230,10 @@ int arf_ack_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int arf_ack_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
int arf_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
int tag_len = 0;
|
||||
@@ -301,9 +311,11 @@ int arf_ack_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int arf_ack_decode_apdu(uint8_t * apdu,
|
||||
int arf_ack_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -332,7 +344,8 @@ int arf_ack_decode_apdu(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testAtomicReadFileAckAccess(Test * pTest,
|
||||
void testAtomicReadFileAckAccess(
|
||||
Test * pTest,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 };
|
||||
@@ -346,8 +359,7 @@ void testAtomicReadFileAckAccess(Test * pTest,
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
|
||||
len = arf_ack_decode_apdu(&apdu[0],
|
||||
apdu_len, &test_invoke_id, &test_data);
|
||||
len = arf_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_data.endOfFile == data->endOfFile);
|
||||
ct_test(pTest, test_data.access == data->access);
|
||||
@@ -367,7 +379,8 @@ void testAtomicReadFileAckAccess(Test * pTest,
|
||||
octetstring_length(&test_data.fileData)) == 0);
|
||||
}
|
||||
|
||||
void testAtomicReadFileAck(Test * pTest)
|
||||
void testAtomicReadFileAck(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
|
||||
uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher";
|
||||
@@ -391,7 +404,8 @@ void testAtomicReadFileAck(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testAtomicReadFileAccess(Test * pTest,
|
||||
void testAtomicReadFileAccess(
|
||||
Test * pTest,
|
||||
BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
{
|
||||
BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 };
|
||||
@@ -423,7 +437,8 @@ void testAtomicReadFileAccess(Test * pTest,
|
||||
}
|
||||
}
|
||||
|
||||
void testAtomicReadFile(Test * pTest)
|
||||
void testAtomicReadFile(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_ATOMIC_READ_FILE_DATA data = { 0 };
|
||||
|
||||
@@ -445,12 +460,14 @@ void testAtomicReadFile(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_ATOMIC_READ_FILE
|
||||
uint16_t Device_Max_APDU_Length_Accepted(void)
|
||||
uint16_t Device_Max_APDU_Length_Accepted(
|
||||
void)
|
||||
{
|
||||
return MAX_APDU;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -469,5 +486,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_xxx */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_xxx */
|
||||
#endif /* TEST */
|
||||
|
||||
+73
-55
@@ -41,10 +41,12 @@
|
||||
/* Atomic Write File */
|
||||
|
||||
/* encode service */
|
||||
int awf_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
int awf_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -56,26 +58,26 @@ int awf_encode_apdu(uint8_t * apdu,
|
||||
apdu_len += encode_application_object_id(&apdu[apdu_len],
|
||||
data->object_type, data->object_instance);
|
||||
switch (data->access) {
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.returnedRecordCount);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.stream.fileStartPosition);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len],
|
||||
data->type.record.fileStartRecord);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
data->type.record.returnedRecordCount);
|
||||
apdu_len += encode_application_octet_string(&apdu[apdu_len],
|
||||
&data->fileData);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +85,10 @@ int awf_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int awf_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
int awf_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
int tag_len = 0;
|
||||
@@ -92,7 +96,7 @@ int awf_decode_service_request(uint8_t * apdu,
|
||||
uint32_t len_value_type = 0;
|
||||
int32_t signed_value = 0;
|
||||
uint32_t unsigned_value = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu_len && data) {
|
||||
@@ -113,7 +117,7 @@ int awf_decode_service_request(uint8_t * apdu,
|
||||
len += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
|
||||
return -1;
|
||||
len += decode_signed(&apdu[len], len_value_type, &signed_value);
|
||||
len += decode_signed(&apdu[len], len_value_type, &signed_value);
|
||||
data->type.stream.fileStartPosition = signed_value;
|
||||
/* fileData */
|
||||
tag_len = decode_tag_number_and_value(&apdu[len],
|
||||
@@ -145,7 +149,7 @@ int awf_decode_service_request(uint8_t * apdu,
|
||||
len += tag_len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return -1;
|
||||
len += decode_unsigned(&apdu[len], len_value_type,
|
||||
len += decode_unsigned(&apdu[len], len_value_type,
|
||||
&unsigned_value);
|
||||
data->type.record.returnedRecordCount = unsigned_value;
|
||||
/* fileData */
|
||||
@@ -167,9 +171,11 @@ int awf_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int awf_decode_apdu(uint8_t * apdu,
|
||||
int awf_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -193,10 +199,12 @@ int awf_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int awf_ack_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
int awf_ack_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK;
|
||||
@@ -204,16 +212,16 @@ int awf_ack_encode_apdu(uint8_t * apdu,
|
||||
apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */
|
||||
apdu_len = 3;
|
||||
switch (data->access) {
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_context_signed(&apdu[apdu_len], 0,
|
||||
data->type.stream.fileStartPosition);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_context_signed(&apdu[apdu_len], 1,
|
||||
data->type.record.fileStartRecord);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case FILE_STREAM_ACCESS:
|
||||
apdu_len += encode_context_signed(&apdu[apdu_len], 0,
|
||||
data->type.stream.fileStartPosition);
|
||||
break;
|
||||
case FILE_RECORD_ACCESS:
|
||||
apdu_len += encode_context_signed(&apdu[apdu_len], 1,
|
||||
data->type.record.fileStartRecord);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,8 +229,10 @@ int awf_ack_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int awf_ack_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
int awf_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -248,9 +258,11 @@ int awf_ack_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int awf_ack_decode_apdu(uint8_t * apdu,
|
||||
int awf_ack_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -278,7 +290,8 @@ int awf_ack_decode_apdu(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testAtomicWriteFileAccess(Test * pTest,
|
||||
void testAtomicWriteFileAccess(
|
||||
Test * pTest,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
|
||||
@@ -313,7 +326,8 @@ void testAtomicWriteFileAccess(Test * pTest,
|
||||
octetstring_length(&test_data.fileData)) == 0);
|
||||
}
|
||||
|
||||
void testAtomicWriteFile(Test * pTest)
|
||||
void testAtomicWriteFile(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 };
|
||||
uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher";
|
||||
@@ -338,7 +352,8 @@ void testAtomicWriteFile(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testAtomicWriteFileAckAccess(Test * pTest,
|
||||
void testAtomicWriteFileAckAccess(
|
||||
Test * pTest,
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
|
||||
@@ -364,7 +379,8 @@ void testAtomicWriteFileAckAccess(Test * pTest,
|
||||
}
|
||||
}
|
||||
|
||||
void testAtomicWriteFileAck(Test * pTest)
|
||||
void testAtomicWriteFileAck(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 };
|
||||
|
||||
@@ -380,12 +396,14 @@ void testAtomicWriteFileAck(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_ATOMIC_WRITE_FILE
|
||||
uint16_t Device_Max_APDU_Length_Accepted(void)
|
||||
uint16_t Device_Max_APDU_Length_Accepted(
|
||||
void)
|
||||
{
|
||||
return MAX_APDU;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -404,5 +422,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WRITE_PROPERTY */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WRITE_PROPERTY */
|
||||
#endif /* TEST */
|
||||
|
||||
+32
-28
@@ -37,7 +37,9 @@
|
||||
#include "config.h"
|
||||
#include "bacdef.h"
|
||||
|
||||
void bacnet_address_copy(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
|
||||
void bacnet_address_copy(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -54,32 +56,34 @@ void bacnet_address_copy(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
|
||||
}
|
||||
}
|
||||
|
||||
bool bacnet_address_same(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
|
||||
bool bacnet_address_same(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned max_len;
|
||||
bool match = true; /* return value */
|
||||
|
||||
if (dest->mac_len != src->mac_len)
|
||||
match = false;
|
||||
max_len = dest->mac_len;
|
||||
if (max_len > MAX_MAC_LEN)
|
||||
max_len = MAX_MAC_LEN;
|
||||
for (i = 0; i < max_len; i++) {
|
||||
if (dest->mac[i] != src->mac[i])
|
||||
match = false;
|
||||
}
|
||||
if (dest->net != src->net)
|
||||
match = false;
|
||||
if (dest->len != src->len)
|
||||
match = false;
|
||||
max_len = dest->len;
|
||||
if (max_len > MAX_MAC_LEN)
|
||||
max_len = MAX_MAC_LEN;
|
||||
for (i = 0; i < max_len; i++) {
|
||||
if (dest->adr[i] != src->adr[i])
|
||||
match = false;
|
||||
}
|
||||
|
||||
return match;
|
||||
unsigned i;
|
||||
unsigned max_len;
|
||||
bool match = true; /* return value */
|
||||
|
||||
if (dest->mac_len != src->mac_len)
|
||||
match = false;
|
||||
max_len = dest->mac_len;
|
||||
if (max_len > MAX_MAC_LEN)
|
||||
max_len = MAX_MAC_LEN;
|
||||
for (i = 0; i < max_len; i++) {
|
||||
if (dest->mac[i] != src->mac[i])
|
||||
match = false;
|
||||
}
|
||||
if (dest->net != src->net)
|
||||
match = false;
|
||||
if (dest->len != src->len)
|
||||
match = false;
|
||||
max_len = dest->len;
|
||||
if (max_len > MAX_MAC_LEN)
|
||||
max_len = MAX_MAC_LEN;
|
||||
for (i = 0; i < max_len; i++) {
|
||||
if (dest->adr[i] != src->adr[i])
|
||||
match = false;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
+517
-490
File diff suppressed because it is too large
Load Diff
+358
-243
File diff suppressed because it is too large
Load Diff
+35
-31
@@ -37,12 +37,14 @@
|
||||
#include "bacdef.h"
|
||||
|
||||
/* encode service */
|
||||
int bacerror_encode_apdu(uint8_t * apdu,
|
||||
int bacerror_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_CONFIRMED_SERVICE service,
|
||||
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||
BACNET_ERROR_CLASS error_class,
|
||||
BACNET_ERROR_CODE error_code)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_ERROR;
|
||||
@@ -50,7 +52,8 @@ int bacerror_encode_apdu(uint8_t * apdu,
|
||||
apdu[2] = service;
|
||||
apdu_len = 3;
|
||||
/* service parameters */
|
||||
apdu_len += encode_application_enumerated(&apdu[apdu_len], error_class);
|
||||
apdu_len +=
|
||||
encode_application_enumerated(&apdu[apdu_len], error_class);
|
||||
apdu_len += encode_application_enumerated(&apdu[apdu_len], error_code);
|
||||
}
|
||||
|
||||
@@ -58,9 +61,11 @@ int bacerror_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* 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,
|
||||
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
BACNET_ERROR_CODE * error_code)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -73,30 +78,30 @@ int bacerror_decode_error_class_and_code(uint8_t * apdu,
|
||||
&tag_number, &len_value_type);
|
||||
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
|
||||
return 0;
|
||||
len +=
|
||||
decode_enumerated(&apdu[len], len_value_type, &decoded_value);
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &decoded_value);
|
||||
if (error_class)
|
||||
*error_class = (BACNET_ERROR_CLASS)decoded_value;
|
||||
*error_class = (BACNET_ERROR_CLASS) decoded_value;
|
||||
/* error code */
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
|
||||
return 0;
|
||||
len +=
|
||||
decode_enumerated(&apdu[len], len_value_type, &decoded_value);
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &decoded_value);
|
||||
if (error_code)
|
||||
*error_code = (BACNET_ERROR_CODE)decoded_value;
|
||||
*error_code = (BACNET_ERROR_CODE) decoded_value;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int bacerror_decode_service_request(uint8_t * apdu,
|
||||
int bacerror_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
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 len = 0;
|
||||
|
||||
@@ -104,7 +109,7 @@ int bacerror_decode_service_request(uint8_t * apdu,
|
||||
if (invoke_id)
|
||||
*invoke_id = apdu[0];
|
||||
if (service)
|
||||
*service = (BACNET_CONFIRMED_SERVICE)apdu[1];
|
||||
*service = (BACNET_CONFIRMED_SERVICE) apdu[1];
|
||||
/* decode the application class and code */
|
||||
len = bacerror_decode_error_class_and_code(&apdu[2],
|
||||
apdu_len - 2, error_class, error_code);
|
||||
@@ -119,11 +124,13 @@ int bacerror_decode_service_request(uint8_t * apdu,
|
||||
#include "ctest.h"
|
||||
|
||||
/* 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,
|
||||
uint8_t * invoke_id,
|
||||
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 len = 0;
|
||||
|
||||
@@ -142,7 +149,8 @@ int bacerror_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testBACError(Test * pTest)
|
||||
void testBACError(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -163,8 +171,7 @@ void testBACError(Test * pTest)
|
||||
|
||||
len = bacerror_decode_apdu(&apdu[0],
|
||||
apdu_len,
|
||||
&test_invoke_id,
|
||||
&test_service, &test_error_class, &test_error_code);
|
||||
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest, test_service == service);
|
||||
@@ -175,22 +182,19 @@ void testBACError(Test * pTest)
|
||||
apdu[0] = PDU_TYPE_ABORT;
|
||||
len = bacerror_decode_apdu(&apdu[0],
|
||||
apdu_len,
|
||||
&test_invoke_id,
|
||||
&test_service, &test_error_class, &test_error_code);
|
||||
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
|
||||
ct_test(pTest, len == -1);
|
||||
|
||||
/* test NULL APDU */
|
||||
len = bacerror_decode_apdu(NULL,
|
||||
apdu_len,
|
||||
&test_invoke_id,
|
||||
&test_service, &test_error_class, &test_error_code);
|
||||
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
|
||||
ct_test(pTest, len == -1);
|
||||
|
||||
/* force a zero length */
|
||||
len = bacerror_decode_apdu(&apdu[0],
|
||||
0,
|
||||
&test_invoke_id,
|
||||
&test_service, &test_error_class, &test_error_code);
|
||||
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
|
||||
ct_test(pTest, len == 0);
|
||||
|
||||
|
||||
@@ -227,8 +231,7 @@ void testBACError(Test * pTest)
|
||||
ct_test(pTest, len != 0);
|
||||
len = bacerror_decode_apdu(&apdu[0],
|
||||
apdu_len,
|
||||
&test_invoke_id,
|
||||
&test_service, &test_error_class, &test_error_code);
|
||||
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest, test_service == service);
|
||||
@@ -238,7 +241,8 @@ void testBACError(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_BACERROR
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -255,5 +259,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_ERROR */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_ERROR */
|
||||
#endif /* TEST */
|
||||
|
||||
+106
-70
@@ -38,74 +38,90 @@
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
|
||||
int encode_unsigned16(uint8_t * apdu, uint16_t value)
|
||||
int encode_unsigned16(
|
||||
uint8_t * apdu,
|
||||
uint16_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff00) >> 8);
|
||||
apdu[1] = (uint8_t)(value & 0x00ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
|
||||
apdu[1] = (uint8_t) (value & 0x00ff);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int decode_unsigned16(uint8_t * apdu, uint16_t * value)
|
||||
int decode_unsigned16(
|
||||
uint8_t * apdu,
|
||||
uint16_t * value)
|
||||
{
|
||||
if (value) {
|
||||
*value = (uint16_t)((((uint16_t)apdu[0]) << 8) & 0xff00);
|
||||
*value |= ((uint16_t)(((uint16_t)apdu[1]) & 0x00ff));
|
||||
*value = (uint16_t) ((((uint16_t) apdu[0]) << 8) & 0xff00);
|
||||
*value |= ((uint16_t) (((uint16_t) apdu[1]) & 0x00ff));
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int encode_unsigned24(uint8_t * apdu, uint32_t value)
|
||||
int encode_unsigned24(
|
||||
uint8_t * apdu,
|
||||
uint32_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
|
||||
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
|
||||
apdu[2] = (uint8_t)(value & 0x0000ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
|
||||
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
|
||||
apdu[2] = (uint8_t) (value & 0x0000ff);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int decode_unsigned24(uint8_t * apdu, uint32_t * value)
|
||||
int decode_unsigned24(
|
||||
uint8_t * apdu,
|
||||
uint32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
*value = ((uint32_t)((((uint32_t)apdu[0]) << 16) & 0x00ff0000));
|
||||
*value |= (uint32_t)((((uint32_t)apdu[1]) << 8) & 0x0000ff00);
|
||||
*value |= ((uint32_t)(((uint32_t)apdu[2]) & 0x000000ff));
|
||||
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 16) & 0x00ff0000));
|
||||
*value |= (uint32_t) ((((uint32_t) apdu[1]) << 8) & 0x0000ff00);
|
||||
*value |= ((uint32_t) (((uint32_t) apdu[2]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int encode_unsigned32(uint8_t * apdu, uint32_t value)
|
||||
int encode_unsigned32(
|
||||
uint8_t * apdu,
|
||||
uint32_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
|
||||
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
|
||||
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
|
||||
apdu[3] = (uint8_t)(value & 0x000000ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
|
||||
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
|
||||
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
|
||||
apdu[3] = (uint8_t) (value & 0x000000ff);
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
int decode_unsigned32(uint8_t * apdu, uint32_t * value)
|
||||
int decode_unsigned32(
|
||||
uint8_t * apdu,
|
||||
uint32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
*value = ((uint32_t)((((uint32_t)apdu[0]) << 24) & 0xff000000));
|
||||
*value |= ((uint32_t)((((uint32_t)apdu[1]) << 16) & 0x00ff0000));
|
||||
*value |= ((uint32_t)((((uint32_t)apdu[2]) << 8) & 0x0000ff00));
|
||||
*value |= ((uint32_t)(((uint32_t)apdu[3]) & 0x000000ff));
|
||||
*value = ((uint32_t) ((((uint32_t) apdu[0]) << 24) & 0xff000000));
|
||||
*value |= ((uint32_t) ((((uint32_t) apdu[1]) << 16) & 0x00ff0000));
|
||||
*value |= ((uint32_t) ((((uint32_t) apdu[2]) << 8) & 0x0000ff00));
|
||||
*value |= ((uint32_t) (((uint32_t) apdu[3]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
int encode_signed8(uint8_t * apdu, int8_t value)
|
||||
int encode_signed8(
|
||||
uint8_t * apdu,
|
||||
int8_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)value;
|
||||
apdu[0] = (uint8_t) value;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int decode_signed8(uint8_t * apdu, int32_t * value)
|
||||
int decode_signed8(
|
||||
uint8_t * apdu,
|
||||
int32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
/* negative - bit 7 is set */
|
||||
@@ -113,21 +129,25 @@ int decode_signed8(uint8_t * apdu, int32_t * value)
|
||||
*value = 0xFFFFFF00;
|
||||
else
|
||||
*value = 0;
|
||||
*value |= ((int32_t)(((int32_t)apdu[0]) & 0x000000ff));
|
||||
*value |= ((int32_t) (((int32_t) apdu[0]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int encode_signed16(uint8_t * apdu, int16_t value)
|
||||
int encode_signed16(
|
||||
uint8_t * apdu,
|
||||
int16_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff00) >> 8);
|
||||
apdu[1] = (uint8_t)(value & 0x00ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff00) >> 8);
|
||||
apdu[1] = (uint8_t) (value & 0x00ff);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int decode_signed16(uint8_t * apdu, int32_t * value)
|
||||
int decode_signed16(
|
||||
uint8_t * apdu,
|
||||
int32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
/* negative - bit 7 is set */
|
||||
@@ -135,23 +155,27 @@ int decode_signed16(uint8_t * apdu, int32_t * value)
|
||||
*value = 0xFFFF0000;
|
||||
else
|
||||
*value = 0;
|
||||
*value |= ((int32_t)((((int32_t)apdu[0]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t)(((int32_t)apdu[1]) & 0x000000ff));
|
||||
*value |= ((int32_t) ((((int32_t) apdu[0]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t) (((int32_t) apdu[1]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int encode_signed24(uint8_t * apdu, int32_t value)
|
||||
int encode_signed24(
|
||||
uint8_t * apdu,
|
||||
int32_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
|
||||
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
|
||||
apdu[2] = (uint8_t)(value & 0x0000ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff0000) >> 16);
|
||||
apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8);
|
||||
apdu[2] = (uint8_t) (value & 0x0000ff);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int decode_signed24(uint8_t * apdu, int32_t * value)
|
||||
int decode_signed24(
|
||||
uint8_t * apdu,
|
||||
int32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
/* negative - bit 7 is set */
|
||||
@@ -159,31 +183,35 @@ int decode_signed24(uint8_t * apdu, int32_t * value)
|
||||
*value = 0xFF000000;
|
||||
else
|
||||
*value = 0;
|
||||
*value |= ((int32_t)((((int32_t)apdu[0]) << 16) & 0x00ff0000));
|
||||
*value |= ((int32_t)((((int32_t)apdu[1]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t)(((int32_t)apdu[2]) & 0x000000ff));
|
||||
*value |= ((int32_t) ((((int32_t) apdu[0]) << 16) & 0x00ff0000));
|
||||
*value |= ((int32_t) ((((int32_t) apdu[1]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t) (((int32_t) apdu[2]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int encode_signed32(uint8_t * apdu, int32_t value)
|
||||
int encode_signed32(
|
||||
uint8_t * apdu,
|
||||
int32_t value)
|
||||
{
|
||||
apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
|
||||
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
|
||||
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
|
||||
apdu[3] = (uint8_t)(value & 0x000000ff);
|
||||
apdu[0] = (uint8_t) ((value & 0xff000000) >> 24);
|
||||
apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16);
|
||||
apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8);
|
||||
apdu[3] = (uint8_t) (value & 0x000000ff);
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
int decode_signed32(uint8_t * apdu, int32_t * value)
|
||||
int decode_signed32(
|
||||
uint8_t * apdu,
|
||||
int32_t * value)
|
||||
{
|
||||
if (value) {
|
||||
*value = ((int32_t)((((int32_t)apdu[0]) << 24) & 0xff000000));
|
||||
*value |= ((int32_t)((((int32_t)apdu[1]) << 16) & 0x00ff0000));
|
||||
*value |= ((int32_t)((((int32_t)apdu[2]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t)(((int32_t)apdu[3]) & 0x000000ff));
|
||||
*value = ((int32_t) ((((int32_t) apdu[0]) << 24) & 0xff000000));
|
||||
*value |= ((int32_t) ((((int32_t) apdu[1]) << 16) & 0x00ff0000));
|
||||
*value |= ((int32_t) ((((int32_t) apdu[2]) << 8) & 0x0000ff00));
|
||||
*value |= ((int32_t) (((int32_t) apdu[3]) & 0x000000ff));
|
||||
}
|
||||
|
||||
return 4;
|
||||
@@ -196,13 +224,14 @@ int decode_signed32(uint8_t * apdu, int32_t * value)
|
||||
#include <ctype.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBACnetUnsigned16(Test * pTest)
|
||||
void testBACnetUnsigned16(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
uint16_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = 0; ; value++) {
|
||||
for (value = 0;; value++) {
|
||||
len = encode_unsigned16(&apdu[0], value);
|
||||
ct_test(pTest, len == 2);
|
||||
len = decode_unsigned16(&apdu[0], &test_value);
|
||||
@@ -212,13 +241,14 @@ void testBACnetUnsigned16(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetUnsigned24(Test * pTest)
|
||||
void testBACnetUnsigned24(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
uint32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = 0; ; value+=0xf) {
|
||||
for (value = 0;; value += 0xf) {
|
||||
len = encode_unsigned24(&apdu[0], value);
|
||||
ct_test(pTest, len == 3);
|
||||
len = decode_unsigned24(&apdu[0], &test_value);
|
||||
@@ -228,13 +258,14 @@ void testBACnetUnsigned24(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetUnsigned32(Test * pTest)
|
||||
void testBACnetUnsigned32(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
uint32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = 0; ; value+=0xff) {
|
||||
for (value = 0;; value += 0xff) {
|
||||
len = encode_unsigned32(&apdu[0], value);
|
||||
ct_test(pTest, len == 4);
|
||||
len = decode_unsigned32(&apdu[0], &test_value);
|
||||
@@ -244,13 +275,14 @@ void testBACnetUnsigned32(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetSigned8(Test * pTest)
|
||||
void testBACnetSigned8(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
int32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = -127; ; value++) {
|
||||
for (value = -127;; value++) {
|
||||
len = encode_signed8(&apdu[0], value);
|
||||
ct_test(pTest, len == 1);
|
||||
len = decode_signed8(&apdu[0], &test_value);
|
||||
@@ -260,13 +292,14 @@ void testBACnetSigned8(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetSigned16(Test * pTest)
|
||||
void testBACnetSigned16(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
int32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = -32767; ; value++) {
|
||||
for (value = -32767;; value++) {
|
||||
len = encode_signed16(&apdu[0], value);
|
||||
ct_test(pTest, len == 2);
|
||||
len = decode_signed16(&apdu[0], &test_value);
|
||||
@@ -276,13 +309,14 @@ void testBACnetSigned16(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetSigned24(Test * pTest)
|
||||
void testBACnetSigned24(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
int32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = -8388607; value <= 8388607; value+=15) {
|
||||
for (value = -8388607; value <= 8388607; value += 15) {
|
||||
len = encode_signed24(&apdu[0], value);
|
||||
ct_test(pTest, len == 3);
|
||||
len = decode_signed24(&apdu[0], &test_value);
|
||||
@@ -290,19 +324,20 @@ void testBACnetSigned24(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetSigned32(Test * pTest)
|
||||
void testBACnetSigned32(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[32] = { 0 };
|
||||
int32_t value = 0, test_value = 0;
|
||||
int len = 0;
|
||||
|
||||
for (value = -2147483647; value < 0; value+=127) {
|
||||
for (value = -2147483647; value < 0; value += 127) {
|
||||
len = encode_signed32(&apdu[0], value);
|
||||
ct_test(pTest, len == 4);
|
||||
len = decode_signed32(&apdu[0], &test_value);
|
||||
ct_test(pTest, value == test_value);
|
||||
}
|
||||
for (value = 2147483647; value > 0; value-=127) {
|
||||
for (value = 2147483647; value > 0; value -= 127) {
|
||||
len = encode_signed32(&apdu[0], value);
|
||||
ct_test(pTest, len == 4);
|
||||
len = decode_signed32(&apdu[0], &test_value);
|
||||
@@ -311,7 +346,8 @@ void testBACnetSigned32(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_BACINT
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -340,5 +376,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BACINT */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_BACINT */
|
||||
#endif /* TEST */
|
||||
|
||||
+14
-10
@@ -76,8 +76,10 @@ PROP_TAG_DATA bacnet_object_device_property_tag_map[] = {
|
||||
{-1, -1}
|
||||
};
|
||||
|
||||
signed bacprop_tag_by_index_default(PROP_TAG_DATA * data_list,
|
||||
signed index, signed default_ret)
|
||||
signed bacprop_tag_by_index_default(
|
||||
PROP_TAG_DATA * data_list,
|
||||
signed index,
|
||||
signed default_ret)
|
||||
{
|
||||
signed pUnsigned = 0;
|
||||
|
||||
@@ -95,16 +97,18 @@ signed bacprop_tag_by_index_default(PROP_TAG_DATA * data_list,
|
||||
}
|
||||
|
||||
|
||||
signed bacprop_property_tag(BACNET_OBJECT_TYPE type, signed prop)
|
||||
signed bacprop_property_tag(
|
||||
BACNET_OBJECT_TYPE type,
|
||||
signed prop)
|
||||
{
|
||||
switch (type) {
|
||||
case OBJECT_DEVICE:
|
||||
return
|
||||
bacprop_tag_by_index_default
|
||||
(bacnet_object_device_property_tag_map, prop, -1);
|
||||
default:
|
||||
fprintf(stderr, "Unsupported object type");
|
||||
break;
|
||||
case OBJECT_DEVICE:
|
||||
return
|
||||
bacprop_tag_by_index_default
|
||||
(bacnet_object_device_property_tag_map, prop, -1);
|
||||
default:
|
||||
fprintf(stderr, "Unsupported object type");
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -44,12 +44,14 @@
|
||||
/* NOTE: byte order plays a role in decoding multibyte values */
|
||||
/* http://www.unixpapa.com/incnote/byteorder.html */
|
||||
#ifndef BIG_ENDIAN
|
||||
#error Define BIG_ENDIAN=0 or BIG_ENDIAN=1 for BACnet Stack in compiler settings
|
||||
#error Define BIG_ENDIAN=0 or BIG_ENDIAN=1 for BACnet Stack in compiler settings
|
||||
#endif
|
||||
|
||||
/* from clause 20.2.6 Encoding of a Real Number Value */
|
||||
/* returns the number of apdu bytes consumed */
|
||||
int decode_real(uint8_t * apdu, float *real_value)
|
||||
int decode_real(
|
||||
uint8_t * apdu,
|
||||
float *real_value)
|
||||
{
|
||||
union {
|
||||
uint8_t byte[4];
|
||||
@@ -76,7 +78,9 @@ int decode_real(uint8_t * apdu, float *real_value)
|
||||
|
||||
/* from clause 20.2.6 Encoding of a Real Number Value */
|
||||
/* returns the number of apdu bytes consumed */
|
||||
int encode_bacnet_real(float value, uint8_t * apdu)
|
||||
int encode_bacnet_real(
|
||||
float value,
|
||||
uint8_t * apdu)
|
||||
{
|
||||
union {
|
||||
uint8_t byte[4];
|
||||
@@ -107,12 +111,13 @@ int encode_bacnet_real(float value, uint8_t * apdu)
|
||||
#include <ctype.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBACreal(Test * pTest)
|
||||
void testBACreal(
|
||||
Test * pTest)
|
||||
{
|
||||
float real_value = 3.14159F, test_real_value = 0.0;
|
||||
uint8_t apdu[MAX_APDU] = { 0 };
|
||||
int len = 0, test_len = 0;
|
||||
|
||||
|
||||
len = encode_bacnet_real(real_value, &apdu[0]);
|
||||
ct_test(pTest, len == 4);
|
||||
test_len = decode_real(&apdu[0], &test_real_value);
|
||||
@@ -120,7 +125,8 @@ void testBACreal(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_BACNET_REAL
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -138,6 +144,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BACNET_REAL */
|
||||
#endif /* TEST */
|
||||
|
||||
#endif /* TEST_BACNET_REAL */
|
||||
#endif /* TEST */
|
||||
|
||||
+92
-53
@@ -34,11 +34,12 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h> /* for strlen */
|
||||
#include <string.h> /* for strlen */
|
||||
#include "bacstr.h"
|
||||
#include "bits.h"
|
||||
|
||||
void bitstring_init(BACNET_BIT_STRING * bit_string)
|
||||
void bitstring_init(
|
||||
BACNET_BIT_STRING * bit_string)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -48,7 +49,9 @@ void bitstring_init(BACNET_BIT_STRING * bit_string)
|
||||
}
|
||||
}
|
||||
|
||||
void bitstring_set_bit(BACNET_BIT_STRING * bit_string, uint8_t bit_number,
|
||||
void bitstring_set_bit(
|
||||
BACNET_BIT_STRING * bit_string,
|
||||
uint8_t bit_number,
|
||||
bool value)
|
||||
{
|
||||
uint8_t byte_number = bit_number / 8;
|
||||
@@ -66,7 +69,9 @@ void bitstring_set_bit(BACNET_BIT_STRING * bit_string, uint8_t bit_number,
|
||||
}
|
||||
}
|
||||
|
||||
bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit_number)
|
||||
bool bitstring_bit(
|
||||
BACNET_BIT_STRING * bit_string,
|
||||
uint8_t bit_number)
|
||||
{
|
||||
bool value = false;
|
||||
uint8_t byte_number = bit_number / 8;
|
||||
@@ -81,15 +86,17 @@ bool bitstring_bit(BACNET_BIT_STRING * bit_string, uint8_t bit_number)
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t bitstring_bits_used(BACNET_BIT_STRING * bit_string)
|
||||
uint8_t bitstring_bits_used(
|
||||
BACNET_BIT_STRING * bit_string)
|
||||
{
|
||||
return bit_string->bits_used;
|
||||
}
|
||||
|
||||
/* returns the number of bytes that a bit string is using */
|
||||
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 last_bit = 0;
|
||||
|
||||
@@ -104,7 +111,9 @@ int bitstring_bytes_used(BACNET_BIT_STRING * bit_string)
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t bitstring_octet(BACNET_BIT_STRING * bit_string, uint8_t index)
|
||||
uint8_t bitstring_octet(
|
||||
BACNET_BIT_STRING * bit_string,
|
||||
uint8_t index)
|
||||
{
|
||||
uint8_t octet = 0;
|
||||
|
||||
@@ -117,8 +126,10 @@ uint8_t bitstring_octet(BACNET_BIT_STRING * bit_string, uint8_t index)
|
||||
return octet;
|
||||
}
|
||||
|
||||
bool bitstring_set_octet(BACNET_BIT_STRING * bit_string,
|
||||
uint8_t index, uint8_t octet)
|
||||
bool bitstring_set_octet(
|
||||
BACNET_BIT_STRING * bit_string,
|
||||
uint8_t index,
|
||||
uint8_t octet)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -132,8 +143,10 @@ bool bitstring_set_octet(BACNET_BIT_STRING * bit_string,
|
||||
return status;
|
||||
}
|
||||
|
||||
bool bitstring_set_bits_used(BACNET_BIT_STRING * bit_string,
|
||||
uint8_t bytes_used, uint8_t unused_bits)
|
||||
bool bitstring_set_bits_used(
|
||||
BACNET_BIT_STRING * bit_string,
|
||||
uint8_t bytes_used,
|
||||
uint8_t unused_bits)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -147,7 +160,8 @@ bool bitstring_set_bits_used(BACNET_BIT_STRING * bit_string,
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t bitstring_bits_capacity(BACNET_BIT_STRING * bit_string)
|
||||
uint8_t bitstring_bits_capacity(
|
||||
BACNET_BIT_STRING * bit_string)
|
||||
{
|
||||
if (bit_string)
|
||||
return (sizeof(bit_string->value) * 8);
|
||||
@@ -161,7 +175,7 @@ bool bitstring_copy(
|
||||
{
|
||||
unsigned i;
|
||||
bool status = false;
|
||||
|
||||
|
||||
if (dest && src) {
|
||||
dest->bits_used = src->bits_used;
|
||||
for (i = 0; i < MAX_BITSTRING_BYTES; i++) {
|
||||
@@ -169,18 +183,21 @@ bool bitstring_copy(
|
||||
}
|
||||
status = true;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#define CHARACTER_STRING_CAPACITY (MAX_CHARACTER_STRING_BYTES - 1)
|
||||
/* returns false if the string exceeds capacity
|
||||
initialize by using length=0 */
|
||||
bool characterstring_init(BACNET_CHARACTER_STRING * char_string,
|
||||
uint8_t encoding, char *value, size_t length)
|
||||
bool characterstring_init(
|
||||
BACNET_CHARACTER_STRING * char_string,
|
||||
uint8_t encoding,
|
||||
char *value,
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
|
||||
if (char_string) {
|
||||
char_string->length = 0;
|
||||
@@ -208,14 +225,16 @@ bool characterstring_init(BACNET_CHARACTER_STRING * char_string,
|
||||
return status;
|
||||
}
|
||||
|
||||
bool characterstring_init_ansi(BACNET_CHARACTER_STRING * char_string,
|
||||
bool characterstring_init_ansi(
|
||||
BACNET_CHARACTER_STRING * char_string,
|
||||
char *value)
|
||||
{
|
||||
return characterstring_init(char_string,
|
||||
CHARACTER_ANSI_X34, value, value ? strlen(value) : 0);
|
||||
}
|
||||
|
||||
bool characterstring_copy(BACNET_CHARACTER_STRING * dest,
|
||||
bool characterstring_copy(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
BACNET_CHARACTER_STRING * src)
|
||||
{
|
||||
return characterstring_init(dest,
|
||||
@@ -224,15 +243,15 @@ bool characterstring_copy(BACNET_CHARACTER_STRING * dest,
|
||||
}
|
||||
|
||||
/* returns true if the character encoding and string contents are the same */
|
||||
bool characterstring_same(BACNET_CHARACTER_STRING * dest,
|
||||
bool characterstring_same(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
BACNET_CHARACTER_STRING * src)
|
||||
{
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
bool same_status = false;
|
||||
|
||||
if (src && dest) {
|
||||
if ((src->length == dest->length) &&
|
||||
(src->encoding == dest->encoding)) {
|
||||
if ((src->length == dest->length) && (src->encoding == dest->encoding)) {
|
||||
same_status = true;
|
||||
for (i = 0; i < src->length; i++) {
|
||||
if (src->value[i] != dest->value[i]) {
|
||||
@@ -252,10 +271,11 @@ bool characterstring_same(BACNET_CHARACTER_STRING * dest,
|
||||
return same_status;
|
||||
}
|
||||
|
||||
bool characterstring_ansi_same(BACNET_CHARACTER_STRING * dest,
|
||||
bool characterstring_ansi_same(
|
||||
BACNET_CHARACTER_STRING * dest,
|
||||
const char *src)
|
||||
{
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
bool same_status = false;
|
||||
|
||||
if (src && dest) {
|
||||
@@ -283,10 +303,12 @@ bool characterstring_ansi_same(BACNET_CHARACTER_STRING * dest,
|
||||
}
|
||||
|
||||
/* returns false if the string exceeds capacity */
|
||||
bool characterstring_append(BACNET_CHARACTER_STRING * char_string,
|
||||
char *value, size_t length)
|
||||
bool characterstring_append(
|
||||
BACNET_CHARACTER_STRING * char_string,
|
||||
char *value,
|
||||
size_t length)
|
||||
{
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (char_string) {
|
||||
@@ -305,7 +327,8 @@ bool characterstring_append(BACNET_CHARACTER_STRING * char_string,
|
||||
/* This function sets a new length without changing the value.
|
||||
If length exceeds capacity, no modification happens and
|
||||
function returns false. */
|
||||
bool characterstring_truncate(BACNET_CHARACTER_STRING * char_string,
|
||||
bool characterstring_truncate(
|
||||
BACNET_CHARACTER_STRING * char_string,
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
@@ -321,7 +344,8 @@ bool characterstring_truncate(BACNET_CHARACTER_STRING * char_string,
|
||||
}
|
||||
|
||||
/* Returns the value. */
|
||||
char *characterstring_value(BACNET_CHARACTER_STRING * char_string)
|
||||
char *characterstring_value(
|
||||
BACNET_CHARACTER_STRING * char_string)
|
||||
{
|
||||
char *value = NULL;
|
||||
|
||||
@@ -333,7 +357,8 @@ char *characterstring_value(BACNET_CHARACTER_STRING * char_string)
|
||||
}
|
||||
|
||||
/* returns the length. */
|
||||
size_t characterstring_length(BACNET_CHARACTER_STRING * char_string)
|
||||
size_t characterstring_length(
|
||||
BACNET_CHARACTER_STRING * char_string)
|
||||
{
|
||||
size_t length = 0;
|
||||
|
||||
@@ -345,7 +370,8 @@ size_t characterstring_length(BACNET_CHARACTER_STRING * char_string)
|
||||
return length;
|
||||
}
|
||||
|
||||
size_t characterstring_capacity(BACNET_CHARACTER_STRING * char_string)
|
||||
size_t characterstring_capacity(
|
||||
BACNET_CHARACTER_STRING * char_string)
|
||||
{
|
||||
size_t length = 0;
|
||||
|
||||
@@ -357,7 +383,8 @@ size_t characterstring_capacity(BACNET_CHARACTER_STRING * char_string)
|
||||
}
|
||||
|
||||
/* returns the encoding. */
|
||||
uint8_t characterstring_encoding(BACNET_CHARACTER_STRING * char_string)
|
||||
uint8_t characterstring_encoding(
|
||||
BACNET_CHARACTER_STRING * char_string)
|
||||
{
|
||||
uint8_t encoding = 0;
|
||||
|
||||
@@ -370,11 +397,13 @@ uint8_t characterstring_encoding(BACNET_CHARACTER_STRING * char_string)
|
||||
|
||||
/* returns false if the string exceeds capacity
|
||||
initialize by using length=0 */
|
||||
bool octetstring_init(BACNET_OCTET_STRING * octet_string,
|
||||
uint8_t * value, size_t length)
|
||||
bool octetstring_init(
|
||||
BACNET_OCTET_STRING * octet_string,
|
||||
uint8_t * value,
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
|
||||
if (octet_string) {
|
||||
octet_string->length = 0;
|
||||
@@ -396,7 +425,8 @@ bool octetstring_init(BACNET_OCTET_STRING * octet_string,
|
||||
return status;
|
||||
}
|
||||
|
||||
bool octetstring_copy(BACNET_OCTET_STRING * dest,
|
||||
bool octetstring_copy(
|
||||
BACNET_OCTET_STRING * dest,
|
||||
BACNET_OCTET_STRING * src)
|
||||
{
|
||||
return octetstring_init(dest,
|
||||
@@ -404,10 +434,12 @@ bool octetstring_copy(BACNET_OCTET_STRING * dest,
|
||||
}
|
||||
|
||||
/* returns false if the string exceeds capacity */
|
||||
bool octetstring_append(BACNET_OCTET_STRING * octet_string,
|
||||
uint8_t * value, size_t length)
|
||||
bool octetstring_append(
|
||||
BACNET_OCTET_STRING * octet_string,
|
||||
uint8_t * value,
|
||||
size_t length)
|
||||
{
|
||||
size_t i; /* counter */
|
||||
size_t i; /* counter */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (octet_string) {
|
||||
@@ -426,7 +458,8 @@ bool octetstring_append(BACNET_OCTET_STRING * octet_string,
|
||||
/* This function sets a new length without changing the value.
|
||||
If length exceeds capacity, no modification happens and
|
||||
function returns false. */
|
||||
bool octetstring_truncate(BACNET_OCTET_STRING * octet_string,
|
||||
bool octetstring_truncate(
|
||||
BACNET_OCTET_STRING * octet_string,
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
@@ -442,7 +475,8 @@ bool octetstring_truncate(BACNET_OCTET_STRING * octet_string,
|
||||
}
|
||||
|
||||
/* returns the length. Returns the value in parameter. */
|
||||
uint8_t *octetstring_value(BACNET_OCTET_STRING * octet_string)
|
||||
uint8_t *octetstring_value(
|
||||
BACNET_OCTET_STRING * octet_string)
|
||||
{
|
||||
uint8_t *value = NULL;
|
||||
|
||||
@@ -454,7 +488,8 @@ uint8_t *octetstring_value(BACNET_OCTET_STRING * octet_string)
|
||||
}
|
||||
|
||||
/* returns the length. */
|
||||
size_t octetstring_length(BACNET_OCTET_STRING * octet_string)
|
||||
size_t octetstring_length(
|
||||
BACNET_OCTET_STRING * octet_string)
|
||||
{
|
||||
size_t length = 0;
|
||||
|
||||
@@ -467,7 +502,8 @@ size_t octetstring_length(BACNET_OCTET_STRING * octet_string)
|
||||
}
|
||||
|
||||
/* returns the length. */
|
||||
size_t octetstring_capacity(BACNET_OCTET_STRING * octet_string)
|
||||
size_t octetstring_capacity(
|
||||
BACNET_OCTET_STRING * octet_string)
|
||||
{
|
||||
size_t length = 0;
|
||||
|
||||
@@ -484,7 +520,8 @@ size_t octetstring_capacity(BACNET_OCTET_STRING * octet_string)
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBitString(Test * pTest)
|
||||
void testBitString(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t bit = 0;
|
||||
BACNET_BIT_STRING bit_string;
|
||||
@@ -511,7 +548,8 @@ void testBitString(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testCharacterString(Test * pTest)
|
||||
void testCharacterString(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_CHARACTER_STRING bacnet_string;
|
||||
char *value = "Joshua,Mary,Anna,Christopher";
|
||||
@@ -524,8 +562,7 @@ void testCharacterString(Test * pTest)
|
||||
size_t i = 0;
|
||||
|
||||
/* verify initialization */
|
||||
status =
|
||||
characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0);
|
||||
status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, 0);
|
||||
ct_test(pTest, status == true);
|
||||
ct_test(pTest, characterstring_length(&bacnet_string) == 0);
|
||||
ct_test(pTest,
|
||||
@@ -569,7 +606,8 @@ void testCharacterString(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testOctetString(Test * pTest)
|
||||
void testOctetString(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_OCTET_STRING bacnet_string;
|
||||
uint8_t *value = NULL;
|
||||
@@ -631,7 +669,8 @@ void testOctetString(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_BACSTR
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -652,5 +691,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BACSTR */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_BACSTR */
|
||||
#endif /* TEST */
|
||||
|
||||
+38
-19
@@ -75,7 +75,8 @@ INDTEXT_DATA bacnet_confirmed_service_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_confirmed_service_name(int index)
|
||||
const char *bactext_confirmed_service_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_confirmed_service_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -106,7 +107,8 @@ INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_unconfirmed_service_name(int index)
|
||||
const char *bactext_unconfirmed_service_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_unconfirmed_service_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -148,7 +150,8 @@ INDTEXT_DATA bacnet_application_tag_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_application_tag_name(int index)
|
||||
const char *bactext_application_tag_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_application_tag_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -223,7 +226,8 @@ INDTEXT_DATA bacnet_object_type_names[] = {
|
||||
the procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const char *bactext_object_type_name(int index)
|
||||
const char *bactext_object_type_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_object_type_names,
|
||||
index, 128, ASHRAE_Reserved_String, Vendor_Proprietary_String);
|
||||
@@ -685,13 +689,15 @@ INDTEXT_DATA bacnet_property_names[] = {
|
||||
procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const char *bactext_property_name(int index)
|
||||
const char *bactext_property_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_property_names,
|
||||
index, 512, ASHRAE_Reserved_String, Vendor_Proprietary_String);
|
||||
}
|
||||
|
||||
unsigned bactext_property_id(const char *name)
|
||||
unsigned bactext_property_id(
|
||||
const char *name)
|
||||
{
|
||||
return indtext_by_istring_default(bacnet_property_names, name, 0);
|
||||
}
|
||||
@@ -1090,7 +1096,8 @@ INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
the procedures and constraints described in Clause 23. */
|
||||
};
|
||||
|
||||
const char *bactext_engineering_unit_name(int index)
|
||||
const char *bactext_engineering_unit_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_engineering_unit_names,
|
||||
index, 256, ASHRAE_Reserved_String, Vendor_Proprietary_String);
|
||||
@@ -1121,7 +1128,8 @@ INDTEXT_DATA bacnet_reject_reason_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_reject_reason_name(int index)
|
||||
const char *bactext_reject_reason_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_reject_reason_names,
|
||||
index,
|
||||
@@ -1144,7 +1152,8 @@ INDTEXT_DATA bacnet_abort_reason_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_abort_reason_name(int index)
|
||||
const char *bactext_abort_reason_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_abort_reason_names,
|
||||
index,
|
||||
@@ -1170,7 +1179,8 @@ INDTEXT_DATA bacnet_error_class_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_error_class_name(int index)
|
||||
const char *bactext_error_class_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_error_class_names,
|
||||
index,
|
||||
@@ -1294,7 +1304,8 @@ INDTEXT_DATA bacnet_error_code_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_error_code_name(int index)
|
||||
const char *bactext_error_code_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(bacnet_error_code_names,
|
||||
index,
|
||||
@@ -1332,7 +1343,8 @@ INDTEXT_DATA bacnet_month_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_month_name(int index)
|
||||
const char *bactext_month_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_month_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1356,7 +1368,8 @@ INDTEXT_DATA bacnet_week_of_month_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_week_of_month_name(int index)
|
||||
const char *bactext_week_of_month_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_week_of_month_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1383,7 +1396,8 @@ INDTEXT_DATA bacnet_day_of_week_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_day_of_week_name(int index)
|
||||
const char *bactext_day_of_week_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_day_of_week_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1403,7 +1417,8 @@ INDTEXT_DATA bacnet_event_state_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_event_state_name(int index)
|
||||
const char *bactext_event_state_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_event_state_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1417,7 +1432,8 @@ INDTEXT_DATA bacnet_binary_present_value_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_binary_present_value_name(int index)
|
||||
const char *bactext_binary_present_value_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_binary_present_value_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1449,7 +1465,8 @@ INDTEXT_DATA bacnet_reliability_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_reliability_name(int index)
|
||||
const char *bactext_reliability_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_reliability_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1469,7 +1486,8 @@ INDTEXT_DATA bacnet_device_status_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_device_status_name(int index)
|
||||
const char *bactext_device_status_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_device_status_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
@@ -1487,7 +1505,8 @@ INDTEXT_DATA bacnet_segmentation_names[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *bactext_segmentation_name(int index)
|
||||
const char *bactext_segmentation_name(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(bacnet_segmentation_names,
|
||||
index, ASHRAE_Reserved_String);
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
/* x[2] = 0x03 */
|
||||
/* x[3] = 0x04 */
|
||||
|
||||
int big_endian(void)
|
||||
int big_endian(
|
||||
void)
|
||||
{
|
||||
union {
|
||||
long l;
|
||||
|
||||
+43
-31
@@ -32,12 +32,12 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "bacint.h"
|
||||
#include "bip.h"
|
||||
#include "net.h" /* custom per port */
|
||||
#include "net.h" /* custom per port */
|
||||
|
||||
static int BIP_Socket = -1;
|
||||
/* port to use - stored in host byte order */
|
||||
@@ -47,22 +47,26 @@ static struct in_addr BIP_Address;
|
||||
/* Broadcast Address - stored in host byte order */
|
||||
static struct in_addr BIP_Broadcast_Address;
|
||||
|
||||
void bip_set_socket(int sock_fd)
|
||||
void bip_set_socket(
|
||||
int sock_fd)
|
||||
{
|
||||
BIP_Socket = sock_fd;
|
||||
}
|
||||
|
||||
int bip_socket(void)
|
||||
int bip_socket(
|
||||
void)
|
||||
{
|
||||
return BIP_Socket;
|
||||
}
|
||||
|
||||
bool bip_valid(void)
|
||||
bool bip_valid(
|
||||
void)
|
||||
{
|
||||
return (BIP_Socket != -1);
|
||||
}
|
||||
|
||||
void bip_cleanup(void)
|
||||
void bip_cleanup(
|
||||
void)
|
||||
{
|
||||
if (bip_valid())
|
||||
close(BIP_Socket);
|
||||
@@ -72,48 +76,55 @@ void bip_cleanup(void)
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* returns host byte order */
|
||||
uint32_t bip_get_addr(void)
|
||||
uint32_t bip_get_addr(
|
||||
void)
|
||||
{
|
||||
return BIP_Address.s_addr;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* returns host byte order */
|
||||
uint32_t bip_get_broadcast_addr(void)
|
||||
uint32_t bip_get_broadcast_addr(
|
||||
void)
|
||||
{
|
||||
return BIP_Broadcast_Address.s_addr;
|
||||
}
|
||||
|
||||
/* set using host byte order */
|
||||
void bip_set_port(uint16_t port)
|
||||
void bip_set_port(
|
||||
uint16_t port)
|
||||
{
|
||||
BIP_Port = port;
|
||||
}
|
||||
|
||||
/* returns host byte order */
|
||||
uint16_t bip_get_port(void)
|
||||
uint16_t bip_get_port(
|
||||
void)
|
||||
{
|
||||
return BIP_Port;
|
||||
}
|
||||
|
||||
/* function to send a packet out the BACnet/IP socket (Annex J) */
|
||||
/* returns number of bytes sent on success, negative number on failure */
|
||||
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
int bip_send_pdu(
|
||||
BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
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 */
|
||||
{ /* number of bytes of data */
|
||||
struct sockaddr_in bip_dest;
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
@@ -135,7 +146,7 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
} else if (dest->mac_len == 6) {
|
||||
/* valid unicast */
|
||||
(void) decode_unsigned32(&dest->mac[0],
|
||||
(uint32_t *)&(bip_dest.sin_addr.s_addr));
|
||||
(uint32_t *) & (bip_dest.sin_addr.s_addr));
|
||||
(void) decode_unsigned16(&dest->mac[4], &(bip_dest.sin_port));
|
||||
memset(&(bip_dest.sin_zero), '\0', 8);
|
||||
mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||
@@ -160,11 +171,12 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
|
||||
/* receives a BACnet/IP packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
uint16_t bip_receive(
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout)
|
||||
{ /* number of milliseconds to wait for a packet */
|
||||
{ /* number of milliseconds to wait for a packet */
|
||||
int received_bytes = 0;
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
@@ -195,8 +207,7 @@ uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
|
||||
/* see if there is a packet for us */
|
||||
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
|
||||
received_bytes = recvfrom(BIP_Socket,
|
||||
(char *) &pdu[0], max_pdu, 0,
|
||||
(struct sockaddr *) &sin, &sin_len);
|
||||
(char *) &pdu[0], max_pdu, 0, (struct sockaddr *) &sin, &sin_len);
|
||||
else
|
||||
return 0;
|
||||
|
||||
@@ -233,7 +244,7 @@ uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
|
||||
if (pdu_len < max_pdu) {
|
||||
/* shift the buffer to return a valid PDU */
|
||||
for (i = 0; i < pdu_len; i++) {
|
||||
pdu[i] = pdu[i+4];
|
||||
pdu[i] = pdu[i + 4];
|
||||
}
|
||||
}
|
||||
/* ignore packets that are too large */
|
||||
@@ -246,13 +257,13 @@ uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void bip_get_my_address(BACNET_ADDRESS * my_address)
|
||||
void bip_get_my_address(
|
||||
BACNET_ADDRESS * my_address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
my_address->mac_len = 6;
|
||||
(void) encode_unsigned32(&my_address->mac[0],
|
||||
htonl(BIP_Address.s_addr));
|
||||
(void) encode_unsigned32(&my_address->mac[0], htonl(BIP_Address.s_addr));
|
||||
(void) encode_unsigned16(&my_address->mac[4], htons(BIP_Port));
|
||||
my_address->net = 0; /* local only, no routing */
|
||||
my_address->len = 0; /* no SLEN */
|
||||
@@ -264,9 +275,10 @@ void bip_get_my_address(BACNET_ADDRESS * my_address)
|
||||
return;
|
||||
}
|
||||
|
||||
void bip_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
void bip_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (dest) {
|
||||
dest->mac_len = 6;
|
||||
@@ -274,7 +286,7 @@ void bip_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
htonl(BIP_Broadcast_Address.s_addr));
|
||||
(void) encode_unsigned16(&dest->mac[4], htons(BIP_Port));
|
||||
dest->net = BACNET_BROADCAST_NETWORK;
|
||||
dest->len = 0; /* no SLEN */
|
||||
dest->len = 0; /* no SLEN */
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
/* no SADR */
|
||||
dest->adr[i] = 0;
|
||||
|
||||
+196
-203
@@ -32,9 +32,9 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include <time.h> /* for the standard bool type. */
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include <time.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "bacint.h"
|
||||
#include "bvlc.h"
|
||||
@@ -45,8 +45,7 @@
|
||||
Broadcast Distribution Table, and
|
||||
Foreign Device Registration */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
/* true if valid entry - false if not */
|
||||
bool valid;
|
||||
/* BACnet/IP address */
|
||||
@@ -69,8 +68,7 @@ seconds remaining before the BBMD will purge the registrant's FDT
|
||||
entry if no re-registration occurs. This value will be initialized
|
||||
to the 2-octet Time-to-Live value supplied at the time of
|
||||
registration.*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
bool valid;
|
||||
/* BACnet/IP address */
|
||||
struct in_addr dest_address;
|
||||
@@ -79,7 +77,7 @@ typedef struct
|
||||
/* seconds for valid entry lifetime */
|
||||
uint16_t time_to_live;
|
||||
/* our counter */
|
||||
time_t seconds_remaining; /* includes 30 second grace period */
|
||||
time_t seconds_remaining; /* includes 30 second grace period */
|
||||
} FD_TABLE_ENTRY;
|
||||
|
||||
#define MAX_FD_ENTRIES 128
|
||||
@@ -88,7 +86,8 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
||||
/* result from a client request */
|
||||
BACNET_BVLC_RESULT BVLC_Result_Code = BVLC_RESULT_SUCCESSFUL_COMPLETION;
|
||||
|
||||
void bvlc_maintenance_timer(unsigned seconds)
|
||||
void bvlc_maintenance_timer(
|
||||
unsigned seconds)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
@@ -109,8 +108,8 @@ void bvlc_maintenance_timer(unsigned seconds)
|
||||
}
|
||||
|
||||
int bvlc_encode_bip_address(
|
||||
uint8_t * pdu, /* buffer to store encoding */
|
||||
struct in_addr *address, /* in host format */
|
||||
uint8_t * pdu, /* buffer to store encoding */
|
||||
struct in_addr *address, /* in host format */
|
||||
uint16_t port)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -124,8 +123,8 @@ int bvlc_encode_bip_address(
|
||||
}
|
||||
|
||||
int bvlc_decode_bip_address(
|
||||
uint8_t * pdu, /* buffer to extract encoded address */
|
||||
struct in_addr * address, /* in host format */
|
||||
uint8_t * pdu, /* buffer to extract encoded address */
|
||||
struct in_addr *address, /* in host format */
|
||||
uint16_t * port)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -142,7 +141,8 @@ int bvlc_decode_bip_address(
|
||||
}
|
||||
|
||||
/* used for both read and write entries */
|
||||
int bvlc_encode_address_entry(uint8_t * pdu,
|
||||
int bvlc_encode_address_entry(
|
||||
uint8_t * pdu,
|
||||
struct in_addr *address,
|
||||
uint16_t port,
|
||||
struct in_addr *mask)
|
||||
@@ -234,7 +234,7 @@ int bvlc_encode_read_bdt_ack(
|
||||
uint8_t * pdu,
|
||||
uint16_t max_pdu)
|
||||
{
|
||||
int pdu_len = 0; /* return value */
|
||||
int pdu_len = 0; /* return value */
|
||||
int len = 0;
|
||||
unsigned count = 0;
|
||||
unsigned i;
|
||||
@@ -244,20 +244,18 @@ int bvlc_encode_read_bdt_ack(
|
||||
count++;
|
||||
}
|
||||
}
|
||||
len = bvlc_encode_read_bdt_ack_init(&pdu[0],count);
|
||||
len = bvlc_encode_read_bdt_ack_init(&pdu[0], count);
|
||||
pdu_len += len;
|
||||
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
|
||||
if (BBMD_Table[i].valid) {
|
||||
/* too much to send */
|
||||
if ((pdu_len+10) > max_pdu) {
|
||||
if ((pdu_len + 10) > max_pdu) {
|
||||
pdu_len = 0;
|
||||
break;
|
||||
}
|
||||
len = bvlc_encode_address_entry(
|
||||
&pdu[pdu_len],
|
||||
len = bvlc_encode_address_entry(&pdu[pdu_len],
|
||||
&BBMD_Table[i].dest_address,
|
||||
BBMD_Table[i].dest_port,
|
||||
&BBMD_Table[i].broadcast_mask);
|
||||
BBMD_Table[i].dest_port, &BBMD_Table[i].broadcast_mask);
|
||||
pdu_len += len;
|
||||
}
|
||||
}
|
||||
@@ -266,14 +264,15 @@ int bvlc_encode_read_bdt_ack(
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_forwarded_npdu(uint8_t * pdu,
|
||||
int bvlc_encode_forwarded_npdu(
|
||||
uint8_t * pdu,
|
||||
BACNET_ADDRESS * src,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
unsigned i; /* for loop counter */
|
||||
unsigned i; /* for loop counter */
|
||||
|
||||
if (pdu) {
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
@@ -296,7 +295,8 @@ int bvlc_encode_forwarded_npdu(uint8_t * pdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int bvlc_encode_register_foreign_device(uint8_t * pdu,
|
||||
int bvlc_encode_register_foreign_device(
|
||||
uint8_t * pdu,
|
||||
uint16_t time_to_live_seconds)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -356,7 +356,7 @@ int bvlc_encode_read_fdt_ack(
|
||||
uint8_t * pdu,
|
||||
uint16_t max_pdu)
|
||||
{
|
||||
int pdu_len = 0; /* return value */
|
||||
int pdu_len = 0; /* return value */
|
||||
int len = 0;
|
||||
unsigned count = 0;
|
||||
unsigned i;
|
||||
@@ -366,19 +366,17 @@ int bvlc_encode_read_fdt_ack(
|
||||
count++;
|
||||
}
|
||||
}
|
||||
len = bvlc_encode_read_fdt_ack_init(&pdu[0],count);
|
||||
len = bvlc_encode_read_fdt_ack_init(&pdu[0], count);
|
||||
pdu_len += len;
|
||||
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
||||
if (FD_Table[i].valid) {
|
||||
/* too much to send */
|
||||
if ((pdu_len+10) > max_pdu) {
|
||||
if ((pdu_len + 10) > max_pdu) {
|
||||
pdu_len = 0;
|
||||
break;
|
||||
}
|
||||
len = bvlc_encode_bip_address(
|
||||
&pdu[pdu_len],
|
||||
&FD_Table[i].dest_address,
|
||||
FD_Table[i].dest_port);
|
||||
len = bvlc_encode_bip_address(&pdu[pdu_len],
|
||||
&FD_Table[i].dest_address, FD_Table[i].dest_port);
|
||||
pdu_len += len;
|
||||
encode_unsigned16(&pdu[pdu_len], FD_Table[i].time_to_live);
|
||||
pdu_len += len;
|
||||
@@ -391,7 +389,8 @@ int bvlc_encode_read_fdt_ack(
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_delete_fdt_entry(uint8_t * pdu,
|
||||
int bvlc_encode_delete_fdt_entry(
|
||||
uint8_t * pdu,
|
||||
struct in_addr *address,
|
||||
uint16_t port)
|
||||
{
|
||||
@@ -413,12 +412,13 @@ int bvlc_encode_delete_fdt_entry(uint8_t * pdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int bvlc_encode_distribute_broadcast_to_network(uint8_t * pdu,
|
||||
int bvlc_encode_distribute_broadcast_to_network(
|
||||
uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
unsigned i; /* for loop counter */
|
||||
int len = 0; /* return value */
|
||||
unsigned i; /* for loop counter */
|
||||
|
||||
if (pdu) {
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
@@ -436,12 +436,13 @@ int bvlc_encode_distribute_broadcast_to_network(uint8_t * pdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int bvlc_encode_original_unicast_npdu(uint8_t * pdu,
|
||||
int bvlc_encode_original_unicast_npdu(
|
||||
uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
unsigned i = 0; /* loop counter */
|
||||
int len = 0; /* return value */
|
||||
unsigned i = 0; /* loop counter */
|
||||
|
||||
if (pdu) {
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
@@ -460,12 +461,13 @@ int bvlc_encode_original_unicast_npdu(uint8_t * pdu,
|
||||
}
|
||||
|
||||
|
||||
int bvlc_encode_original_broadcast_npdu(uint8_t * pdu,
|
||||
int bvlc_encode_original_broadcast_npdu(
|
||||
uint8_t * pdu,
|
||||
uint8_t * npdu,
|
||||
unsigned npdu_length)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
unsigned i = 0; /* loop counter */
|
||||
int len = 0; /* return value */
|
||||
unsigned i = 0; /* loop counter */
|
||||
|
||||
if (pdu) {
|
||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||
@@ -486,9 +488,9 @@ int bvlc_encode_original_broadcast_npdu(uint8_t * pdu,
|
||||
/* copy the source internet address to the BACnet address */
|
||||
/* FIXME: IPv6? */
|
||||
void bvlc_internet_to_bacnet_address(
|
||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
||||
struct sockaddr_in *sin)
|
||||
{ /* source internet address */
|
||||
{ /* source internet address */
|
||||
int len = 0;
|
||||
uint32_t address;
|
||||
uint16_t port;
|
||||
@@ -510,9 +512,9 @@ void bvlc_internet_to_bacnet_address(
|
||||
/* FIXME: IPv6? */
|
||||
/* FIXME: is sockaddr_in host or network order? */
|
||||
void bvlc_bacnet_to_internet_address(
|
||||
struct sockaddr_in *sin, /* source internet address */
|
||||
BACNET_ADDRESS * src) /* returns the BACnet source address */
|
||||
{
|
||||
struct sockaddr_in *sin, /* source internet address */
|
||||
BACNET_ADDRESS * src)
|
||||
{ /* returns the BACnet source address */
|
||||
int len = 0;
|
||||
uint32_t address;
|
||||
uint16_t port;
|
||||
@@ -520,7 +522,7 @@ void bvlc_bacnet_to_internet_address(
|
||||
if (src && sin) {
|
||||
if (src->mac_len == 6) {
|
||||
len = decode_unsigned32(&src->mac[0], &address);
|
||||
len += decode_unsigned16(&src->mac[4], &port );
|
||||
len += decode_unsigned16(&src->mac[4], &port);
|
||||
sin->sin_addr.s_addr = htonl(address);
|
||||
sin->sin_port = htons(port);
|
||||
}
|
||||
@@ -567,16 +569,17 @@ bool bvlc_create_bdt(
|
||||
}
|
||||
|
||||
bool bvlc_register_foreign_device(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint16_t time_to_live) /* time in seconds */
|
||||
{
|
||||
struct sockaddr_in * sin, /* the source address */
|
||||
uint16_t time_to_live)
|
||||
{ /* time in seconds */
|
||||
unsigned i = 0;
|
||||
bool status = false;
|
||||
|
||||
/* am I here already? If so, update my time to live... */
|
||||
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
||||
if (FD_Table[i].valid) {
|
||||
if ((FD_Table[i].dest_address.s_addr == ntohl(sin->sin_addr.s_addr)) &&
|
||||
if ((FD_Table[i].dest_address.s_addr ==
|
||||
ntohl(sin->sin_addr.s_addr)) &&
|
||||
(FD_Table[i].dest_port == ntohs(sin->sin_port))) {
|
||||
status = true;
|
||||
FD_Table[i].time_to_live = time_to_live;
|
||||
@@ -602,11 +605,12 @@ bool bvlc_register_foreign_device(
|
||||
return status;
|
||||
}
|
||||
|
||||
bool bvlc_delete_foreign_device(uint8_t * pdu)
|
||||
bool bvlc_delete_foreign_device(
|
||||
uint8_t * pdu)
|
||||
{
|
||||
struct sockaddr_in sin = {0}; /* the ip address */
|
||||
uint16_t port = 0; /* the decoded port */
|
||||
bool status = false; /* return value */
|
||||
struct sockaddr_in sin = { 0 }; /* the ip address */
|
||||
uint16_t port = 0; /* the decoded port */
|
||||
bool status = false; /* return value */
|
||||
unsigned i = 0;
|
||||
|
||||
bvlc_decode_bip_address(pdu, &sin.sin_addr, &port);
|
||||
@@ -625,14 +629,14 @@ bool bvlc_delete_foreign_device(uint8_t * pdu)
|
||||
}
|
||||
|
||||
void bvlc_bdt_forward_npdu(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* the NPDU */
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* the NPDU */
|
||||
uint16_t npdu_length)
|
||||
{ /* length of the NPDU */
|
||||
uint8_t mtu[MAX_MPDU] = {0};
|
||||
{ /* length of the NPDU */
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
int bytes_sent = 0;
|
||||
unsigned i = 0; /* loop counter */
|
||||
unsigned i = 0; /* loop counter */
|
||||
struct sockaddr_in bip_dest;
|
||||
BACNET_ADDRESS src;
|
||||
|
||||
@@ -641,11 +645,7 @@ void bvlc_bdt_forward_npdu(
|
||||
return;
|
||||
}
|
||||
bvlc_internet_to_bacnet_address(&src, sin);
|
||||
mtu_len = bvlc_encode_forwarded_npdu(
|
||||
&mtu[0],
|
||||
&src,
|
||||
npdu,
|
||||
npdu_length);
|
||||
mtu_len = bvlc_encode_forwarded_npdu(&mtu[0], &src, npdu, npdu_length);
|
||||
/* load destination IP address */
|
||||
bip_dest.sin_family = AF_INET;
|
||||
/* loop through the BDT and send one to each entry, except us */
|
||||
@@ -660,8 +660,8 @@ void bvlc_bdt_forward_npdu(
|
||||
BBMD_Table[i].dest_address.s_addr));
|
||||
bip_dest.sin_port = htons(BBMD_Table[i].dest_port);
|
||||
/* don't send to my broadcast address and same port */
|
||||
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr())) &&
|
||||
(bip_dest.sin_port == htons(bip_get_port()))) {
|
||||
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr()))
|
||||
&& (bip_dest.sin_port == htons(bip_get_port()))) {
|
||||
continue;
|
||||
}
|
||||
/* don't send to my ip address and same port */
|
||||
@@ -672,8 +672,7 @@ void bvlc_bdt_forward_npdu(
|
||||
/* Send the packet */
|
||||
bytes_sent =
|
||||
sendto(bip_socket(), (char *) mtu, mtu_len, 0,
|
||||
(struct sockaddr *) &bip_dest,
|
||||
sizeof(struct sockaddr));
|
||||
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,22 +680,22 @@ void bvlc_bdt_forward_npdu(
|
||||
}
|
||||
|
||||
void bvlc_broadcast_forward_npdu(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t npdu_len) /* amount of space available in the NPDU */
|
||||
{
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t npdu_len)
|
||||
{ /* amount of space available in the NPDU */
|
||||
/* FIXME: write the code... */
|
||||
}
|
||||
|
||||
void bvlc_fdt_forward_npdu(
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t max_npdu) /* amount of space available in the NPDU */
|
||||
{
|
||||
uint8_t mtu[MAX_MPDU] = {0};
|
||||
struct sockaddr_in *sin, /* the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t max_npdu)
|
||||
{ /* amount of space available in the NPDU */
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
int bytes_sent = 0;
|
||||
unsigned i = 0; /* loop counter */
|
||||
unsigned i = 0; /* loop counter */
|
||||
struct sockaddr_in bvlc_dest;
|
||||
BACNET_ADDRESS src;
|
||||
|
||||
@@ -705,24 +704,18 @@ void bvlc_fdt_forward_npdu(
|
||||
return;
|
||||
}
|
||||
bvlc_internet_to_bacnet_address(&src, sin);
|
||||
mtu_len = bvlc_encode_forwarded_npdu(
|
||||
&mtu[0],
|
||||
&src,
|
||||
npdu,
|
||||
max_npdu);
|
||||
mtu_len = bvlc_encode_forwarded_npdu(&mtu[0], &src, npdu, max_npdu);
|
||||
/* load destination IP address */
|
||||
bvlc_dest.sin_family = AF_INET;
|
||||
/* loop through the FDT and send one to each entry */
|
||||
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
||||
if (FD_Table[i].valid && FD_Table[i].seconds_remaining) {
|
||||
bvlc_dest.sin_addr.s_addr =
|
||||
htonl(FD_Table[i].dest_address.s_addr);
|
||||
bvlc_dest.sin_addr.s_addr = htonl(FD_Table[i].dest_address.s_addr);
|
||||
bvlc_dest.sin_port = htons(FD_Table[i].dest_port);
|
||||
/* Send the packet */
|
||||
bytes_sent =
|
||||
sendto(bip_socket(), (char *) mtu, mtu_len, 0,
|
||||
(struct sockaddr *) &bvlc_dest,
|
||||
sizeof(struct sockaddr));
|
||||
(struct sockaddr *) &bvlc_dest, sizeof(struct sockaddr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -730,10 +723,10 @@ void bvlc_fdt_forward_npdu(
|
||||
}
|
||||
|
||||
void bvlc_send_mpdu(
|
||||
struct sockaddr_in *dest, /* the destination address */
|
||||
uint8_t * mtu, /* the data */
|
||||
uint16_t mtu_len) /* amount of data to send */
|
||||
{
|
||||
struct sockaddr_in *dest, /* the destination address */
|
||||
uint8_t * mtu, /* the data */
|
||||
uint16_t mtu_len)
|
||||
{ /* amount of data to send */
|
||||
int bytes_sent = 0;
|
||||
struct sockaddr_in bvlc_dest;
|
||||
|
||||
@@ -748,17 +741,16 @@ void bvlc_send_mpdu(
|
||||
/* Send the packet */
|
||||
bytes_sent =
|
||||
sendto(bip_socket(), (char *) mtu, mtu_len, 0,
|
||||
(struct sockaddr *) &bvlc_dest,
|
||||
sizeof(struct sockaddr));
|
||||
(struct sockaddr *) &bvlc_dest, sizeof(struct sockaddr));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void bvlc_send_result(
|
||||
struct sockaddr_in *dest, /* the destination address */
|
||||
struct sockaddr_in *dest, /* the destination address */
|
||||
BACNET_BVLC_RESULT result_code)
|
||||
{
|
||||
uint8_t mtu[MAX_MPDU] = {0};
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
|
||||
mtu_len = bvlc_encode_bvlc_result(&mtu[0], result_code);
|
||||
@@ -767,9 +759,10 @@ void bvlc_send_result(
|
||||
return;
|
||||
}
|
||||
|
||||
int bvlc_send_bdt(struct sockaddr_in *dest)
|
||||
int bvlc_send_bdt(
|
||||
struct sockaddr_in *dest)
|
||||
{
|
||||
uint8_t mtu[MAX_MPDU] = {0};
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
|
||||
mtu_len = bvlc_encode_read_bdt_ack(&mtu[0], sizeof(mtu));
|
||||
@@ -780,9 +773,10 @@ int bvlc_send_bdt(struct sockaddr_in *dest)
|
||||
return mtu_len;
|
||||
}
|
||||
|
||||
int bvlc_send_fdt(struct sockaddr_in *dest)
|
||||
int bvlc_send_fdt(
|
||||
struct sockaddr_in *dest)
|
||||
{
|
||||
uint8_t mtu[MAX_MPDU] = {0};
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
|
||||
mtu_len = bvlc_encode_read_fdt_ack(&mtu[0], sizeof(mtu));
|
||||
@@ -794,8 +788,8 @@ int bvlc_send_fdt(struct sockaddr_in *dest)
|
||||
}
|
||||
|
||||
bool bvlc_broadcast_address_same(
|
||||
struct sockaddr_in *sin) /* network order address */
|
||||
{
|
||||
struct sockaddr_in * sin)
|
||||
{ /* network order address */
|
||||
bool same = false;
|
||||
|
||||
if ((sin->sin_addr.s_addr == htonl(bip_get_broadcast_addr())) &&
|
||||
@@ -809,12 +803,12 @@ bool bvlc_broadcast_address_same(
|
||||
/* returns:
|
||||
Number of bytes received, or 0 if none or timeout. */
|
||||
uint16_t bvlc_receive(
|
||||
BACNET_ADDRESS * src, /* returns the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t max_npdu, /* amount of space available in the NPDU */
|
||||
unsigned timeout) /* number of milliseconds to wait for a packet */
|
||||
{
|
||||
uint16_t npdu_len = 0; /* return value */
|
||||
BACNET_ADDRESS * src, /* returns the source address */
|
||||
uint8_t * npdu, /* returns the NPDU */
|
||||
uint16_t max_npdu, /* amount of space available in the NPDU */
|
||||
unsigned timeout)
|
||||
{ /* number of milliseconds to wait for a packet */
|
||||
uint16_t npdu_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
int max = 0;
|
||||
struct timeval select_timeout;
|
||||
@@ -824,7 +818,7 @@ uint16_t bvlc_receive(
|
||||
int function_type = 0;
|
||||
int received_bytes = 0;
|
||||
uint16_t result_code = 0;
|
||||
unsigned i =0;
|
||||
unsigned i = 0;
|
||||
bool status = false;
|
||||
uint16_t time_to_live = 0;
|
||||
|
||||
@@ -839,7 +833,7 @@ uint16_t bvlc_receive(
|
||||
if (timeout >= 1000) {
|
||||
select_timeout.tv_sec = timeout / 1000;
|
||||
select_timeout.tv_usec =
|
||||
1000 * (timeout - select_timeout.tv_sec * 1000);
|
||||
1000 * (timeout - select_timeout.tv_sec * 1000);
|
||||
} else {
|
||||
select_timeout.tv_sec = 0;
|
||||
select_timeout.tv_usec = 1000 * timeout;
|
||||
@@ -849,11 +843,9 @@ uint16_t bvlc_receive(
|
||||
max = bip_socket();
|
||||
/* see if there is a packet for us */
|
||||
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) {
|
||||
received_bytes = recvfrom(
|
||||
bip_socket(),
|
||||
received_bytes = recvfrom(bip_socket(),
|
||||
(char *) &npdu[0],
|
||||
max_npdu, 0,
|
||||
(struct sockaddr *) &sin, &sin_len);
|
||||
max_npdu, 0, (struct sockaddr *) &sin, &sin_len);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -877,40 +869,41 @@ uint16_t bvlc_receive(
|
||||
switch (function_type) {
|
||||
case BVLC_RESULT:
|
||||
/* Upon receipt of a BVLC-Result message containing a result code
|
||||
of X'0000' indicating the successful completion of the
|
||||
registration, a foreign device shall start a timer with a value
|
||||
equal to the Time-to-Live parameter of the preceding Register-
|
||||
Foreign-Device message. At the expiration of the timer, the
|
||||
foreign device shall re-register with the BBMD by sending a BVLL
|
||||
Register-Foreign-Device message */
|
||||
of X'0000' indicating the successful completion of the
|
||||
registration, a foreign device shall start a timer with a value
|
||||
equal to the Time-to-Live parameter of the preceding Register-
|
||||
Foreign-Device message. At the expiration of the timer, the
|
||||
foreign device shall re-register with the BBMD by sending a BVLL
|
||||
Register-Foreign-Device message */
|
||||
/* FIXME: clients may need this result */
|
||||
(void) decode_unsigned16(&npdu[4], &result_code);
|
||||
BVLC_Result_Code = result_code;
|
||||
break;
|
||||
case BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE:
|
||||
/* Upon receipt of a BVLL Write-Broadcast-Distribution-Table
|
||||
message, a BBMD shall attempt to create or replace its BDT,
|
||||
depending on whether or not a BDT has previously existed.
|
||||
If the creation or replacement of the BDT is successful, the BBMD
|
||||
shall return a BVLC-Result message to the originating device with
|
||||
a result code of X'0000'. Otherwise, the BBMD shall return a
|
||||
BVLC-Result message to the originating device with a result code
|
||||
of X'0010' indicating that the write attempt has failed. */
|
||||
status = bvlc_create_bdt(&npdu[4],npdu_len);
|
||||
message, a BBMD shall attempt to create or replace its BDT,
|
||||
depending on whether or not a BDT has previously existed.
|
||||
If the creation or replacement of the BDT is successful, the BBMD
|
||||
shall return a BVLC-Result message to the originating device with
|
||||
a result code of X'0000'. Otherwise, the BBMD shall return a
|
||||
BVLC-Result message to the originating device with a result code
|
||||
of X'0010' indicating that the write attempt has failed. */
|
||||
status = bvlc_create_bdt(&npdu[4], npdu_len);
|
||||
if (status) {
|
||||
bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION);
|
||||
} else {
|
||||
bvlc_send_result(&sin, BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK);
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK);
|
||||
}
|
||||
break;
|
||||
case BVLC_READ_BROADCAST_DISTRIBUTION_TABLE:
|
||||
/* Upon receipt of a BVLL Read-Broadcast-Distribution-Table
|
||||
message, a BBMD shall load the contents of its BDT into a BVLL
|
||||
Read-Broadcast-Distribution-Table-Ack message and send it to the
|
||||
originating device. If the BBMD is unable to perform the
|
||||
read of its BDT, it shall return a BVLC-Result message to the
|
||||
originating device with a result code of X'0020' indicating that
|
||||
the read attempt has failed.*/
|
||||
message, a BBMD shall load the contents of its BDT into a BVLL
|
||||
Read-Broadcast-Distribution-Table-Ack message and send it to the
|
||||
originating device. If the BBMD is unable to perform the
|
||||
read of its BDT, it shall return a BVLC-Result message to the
|
||||
originating device with a result code of X'0020' indicating that
|
||||
the read attempt has failed. */
|
||||
if (bvlc_send_bdt(&sin) <= 0) {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK);
|
||||
@@ -921,23 +914,23 @@ uint16_t bvlc_receive(
|
||||
break;
|
||||
case BVLC_FORWARDED_NPDU:
|
||||
/* Upon receipt of a BVLL Forwarded-NPDU message, a BBMD shall
|
||||
process it according to whether it was received from a peer
|
||||
BBMD as the result of a directed broadcast or a unicast
|
||||
transmission. A BBMD may ascertain the method by which Forwarded-
|
||||
NPDU messages will arrive by inspecting the broadcast distribution
|
||||
mask field in its own BDT entry since all BDTs are required
|
||||
to be identical. If the message arrived via directed broadcast,
|
||||
it was also received by the other devices on the BBMD's subnet. In
|
||||
this case the BBMD merely retransmits the message directly to each
|
||||
foreign device currently in the BBMD's FDT. If the
|
||||
message arrived via a unicast transmission it has not yet been
|
||||
received by the other devices on the BBMD's subnet. In this case,
|
||||
the message is sent to the devices on the BBMD's subnet using the
|
||||
B/IP broadcast address as well as to each foreign device
|
||||
currently in the BBMD's FDT. A BBMD on a subnet with no other
|
||||
BACnet devices may omit the broadcast using the B/IP
|
||||
broadcast address. The method by which a BBMD determines whether
|
||||
or not other BACnet devices are present is a local matter. */
|
||||
process it according to whether it was received from a peer
|
||||
BBMD as the result of a directed broadcast or a unicast
|
||||
transmission. A BBMD may ascertain the method by which Forwarded-
|
||||
NPDU messages will arrive by inspecting the broadcast distribution
|
||||
mask field in its own BDT entry since all BDTs are required
|
||||
to be identical. If the message arrived via directed broadcast,
|
||||
it was also received by the other devices on the BBMD's subnet. In
|
||||
this case the BBMD merely retransmits the message directly to each
|
||||
foreign device currently in the BBMD's FDT. If the
|
||||
message arrived via a unicast transmission it has not yet been
|
||||
received by the other devices on the BBMD's subnet. In this case,
|
||||
the message is sent to the devices on the BBMD's subnet using the
|
||||
B/IP broadcast address as well as to each foreign device
|
||||
currently in the BBMD's FDT. A BBMD on a subnet with no other
|
||||
BACnet devices may omit the broadcast using the B/IP
|
||||
broadcast address. The method by which a BBMD determines whether
|
||||
or not other BACnet devices are present is a local matter. */
|
||||
/* if this was received via Broadcast, don't broadcast it */
|
||||
|
||||
/* FIXME: how do I know if I received a unicast or broadcast? */
|
||||
@@ -950,18 +943,17 @@ uint16_t bvlc_receive(
|
||||
break;
|
||||
case BVLC_REGISTER_FOREIGN_DEVICE:
|
||||
/* Upon receipt of a BVLL Register-Foreign-Device message, a BBMD
|
||||
shall start a timer with a value equal to the Time-to-Live
|
||||
parameter supplied plus a fixed grace period of 30 seconds. If,
|
||||
within the period during which the timer is active, another BVLL
|
||||
Register-Foreign-Device message from the same device is received,
|
||||
the timer shall be reset and restarted. If the time expires
|
||||
without the receipt of another BVLL Register-Foreign-Device
|
||||
message from the same foreign device, the FDT entry for this
|
||||
device shall be cleared.*/
|
||||
shall start a timer with a value equal to the Time-to-Live
|
||||
parameter supplied plus a fixed grace period of 30 seconds. If,
|
||||
within the period during which the timer is active, another BVLL
|
||||
Register-Foreign-Device message from the same device is received,
|
||||
the timer shall be reset and restarted. If the time expires
|
||||
without the receipt of another BVLL Register-Foreign-Device
|
||||
message from the same foreign device, the FDT entry for this
|
||||
device shall be cleared. */
|
||||
(void) decode_unsigned16(&npdu[4], &time_to_live);
|
||||
if (bvlc_register_foreign_device(&sin, time_to_live)) {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_SUCCESSFUL_COMPLETION);
|
||||
bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION);
|
||||
} else {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK);
|
||||
@@ -969,12 +961,12 @@ uint16_t bvlc_receive(
|
||||
break;
|
||||
case BVLC_READ_FOREIGN_DEVICE_TABLE:
|
||||
/* Upon receipt of a BVLL Read-Foreign-Device-Table message, a
|
||||
BBMD shall load the contents of its FDT into a BVLL Read-
|
||||
Foreign-Device-Table-Ack message and send it to the originating
|
||||
device. If the BBMD is unable to perform the read of its FDT,
|
||||
it shall return a BVLC-Result message to the originating device
|
||||
with a result code of X'0040' indicating that the read attempt has
|
||||
failed.*/
|
||||
BBMD shall load the contents of its FDT into a BVLL Read-
|
||||
Foreign-Device-Table-Ack message and send it to the originating
|
||||
device. If the BBMD is unable to perform the read of its FDT,
|
||||
it shall return a BVLC-Result message to the originating device
|
||||
with a result code of X'0040' indicating that the read attempt has
|
||||
failed. */
|
||||
if (bvlc_send_fdt(&sin) <= 0) {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK);
|
||||
@@ -985,16 +977,15 @@ uint16_t bvlc_receive(
|
||||
break;
|
||||
case BVLC_DELETE_FOREIGN_DEVICE_TABLE_ENTRY:
|
||||
/* Upon receipt of a BVLL Delete-Foreign-Device-Table-Entry
|
||||
message, a BBMD shall search its foreign device table for an entry
|
||||
corresponding to the B/IP address supplied in the message. If an
|
||||
entry is found, it shall be deleted and the BBMD shall return a
|
||||
BVLC-Result message to the originating device with a result code
|
||||
of X'0000'. Otherwise, the BBMD shall return a BVLCResult
|
||||
message to the originating device with a result code of X'0050'
|
||||
indicating that the deletion attempt has failed.*/
|
||||
message, a BBMD shall search its foreign device table for an entry
|
||||
corresponding to the B/IP address supplied in the message. If an
|
||||
entry is found, it shall be deleted and the BBMD shall return a
|
||||
BVLC-Result message to the originating device with a result code
|
||||
of X'0000'. Otherwise, the BBMD shall return a BVLCResult
|
||||
message to the originating device with a result code of X'0050'
|
||||
indicating that the deletion attempt has failed. */
|
||||
if (bvlc_delete_foreign_device(&npdu[4])) {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_SUCCESSFUL_COMPLETION);
|
||||
bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION);
|
||||
} else {
|
||||
bvlc_send_result(&sin,
|
||||
BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK);
|
||||
@@ -1002,17 +993,17 @@ uint16_t bvlc_receive(
|
||||
break;
|
||||
case BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK:
|
||||
/* Upon receipt of a BVLL Distribute-Broadcast-To-Network message
|
||||
from a foreign device, the receiving BBMD shall transmit a
|
||||
BVLL Forwarded-NPDU message on its local IP subnet using the
|
||||
local B/IP broadcast address as the destination address. In
|
||||
addition, a Forwarded-NPDU message shall be sent to each entry
|
||||
in its BDT as described above in the case of the receipt of a
|
||||
BVLL Original-Broadcast-NPDU as well as directly to each foreign
|
||||
device currently in the BBMD's FDT except the originating
|
||||
node. If the BBMD is unable to perform the forwarding function,
|
||||
it shall return a BVLC-Result message to the foreign device
|
||||
with a result code of X'0060' indicating that the forwarding
|
||||
attempt was unsuccessful*/
|
||||
from a foreign device, the receiving BBMD shall transmit a
|
||||
BVLL Forwarded-NPDU message on its local IP subnet using the
|
||||
local B/IP broadcast address as the destination address. In
|
||||
addition, a Forwarded-NPDU message shall be sent to each entry
|
||||
in its BDT as described above in the case of the receipt of a
|
||||
BVLL Original-Broadcast-NPDU as well as directly to each foreign
|
||||
device currently in the BBMD's FDT except the originating
|
||||
node. If the BBMD is unable to perform the forwarding function,
|
||||
it shall return a BVLC-Result message to the foreign device
|
||||
with a result code of X'0060' indicating that the forwarding
|
||||
attempt was unsuccessful */
|
||||
/* FIXME: complete the function code */
|
||||
bvlc_broadcast_forward_npdu(&sin, &npdu[4], npdu_len);
|
||||
bvlc_fdt_forward_npdu(&sin, &npdu[4], npdu_len);
|
||||
@@ -1027,7 +1018,7 @@ uint16_t bvlc_receive(
|
||||
if (npdu_len < max_npdu) {
|
||||
/* shift the buffer to return a valid PDU */
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
npdu[i] = npdu[i+4];
|
||||
npdu[i] = npdu[i + 4];
|
||||
}
|
||||
} else {
|
||||
/* ignore packets that are too large */
|
||||
@@ -1054,7 +1045,7 @@ uint16_t bvlc_receive(
|
||||
if (npdu_len < max_npdu) {
|
||||
/* shift the buffer to return a valid PDU */
|
||||
for (i = 0; i < npdu_len; i++) {
|
||||
npdu[i] = npdu[i+4];
|
||||
npdu[i] = npdu[i + 4];
|
||||
}
|
||||
/* if BDT or FDT entries exist, Forward the NPDU */
|
||||
bvlc_bdt_forward_npdu(&sin, &npdu[0], npdu_len);
|
||||
@@ -1073,11 +1064,12 @@ uint16_t bvlc_receive(
|
||||
|
||||
/* function to send a packet out the BACnet/IP socket (Annex J) */
|
||||
/* returns number of bytes sent on success, negative number on failure */
|
||||
int bvlc_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
int bvlc_send_pdu(
|
||||
BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
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 */
|
||||
{ /* number of bytes of data */
|
||||
struct sockaddr_in bvlc_dest;
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
@@ -1129,7 +1121,8 @@ int bvlc_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBIPAddress(Test * pTest)
|
||||
void testBIPAddress(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[50] = { 0 };
|
||||
uint32_t value = 0, test_value = 0;
|
||||
@@ -1139,16 +1132,15 @@ void testBIPAddress(Test * pTest)
|
||||
uint16_t port = 0, test_port = 0;
|
||||
|
||||
address.s_addr = 42;
|
||||
len = bvlc_encode_bip_address(&apdu[0],
|
||||
&address, port);
|
||||
test_len = bvlc_decode_bip_address(&apdu[0],
|
||||
&test_address, &test_port);
|
||||
len = bvlc_encode_bip_address(&apdu[0], &address, port);
|
||||
test_len = bvlc_decode_bip_address(&apdu[0], &test_address, &test_port);
|
||||
ct_test(pTest, len == test_len);
|
||||
ct_test(pTest, address.s_addr == test_address.s_addr);
|
||||
ct_test(pTest, port == test_port);
|
||||
}
|
||||
|
||||
void testInternetAddress(Test * pTest)
|
||||
void testInternetAddress(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_ADDRESS src;
|
||||
BACNET_ADDRESS test_src;
|
||||
@@ -1164,9 +1156,10 @@ void testInternetAddress(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_BVLC
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test * pTest;
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("BACnet Virtual Link Control", NULL);
|
||||
@@ -1184,5 +1177,5 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST_BBMD */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_BBMD */
|
||||
#endif /* TEST */
|
||||
|
||||
+120
-73
@@ -49,10 +49,12 @@ COV Subscribe Property
|
||||
COV Notification
|
||||
Unconfirmed COV Notification
|
||||
*/
|
||||
static int notify_encode_adpu(uint8_t * apdu, BACNET_COV_DATA * data)
|
||||
static int notify_encode_adpu(
|
||||
uint8_t * apdu,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
|
||||
|
||||
if (apdu) {
|
||||
@@ -71,8 +73,7 @@ static int notify_encode_adpu(uint8_t * apdu, BACNET_COV_DATA * data)
|
||||
data->monitoredObjectIdentifier.instance);
|
||||
apdu_len += len;
|
||||
/* tag 3 - timeRemaining */
|
||||
len = encode_context_unsigned(&apdu[apdu_len],
|
||||
3, data->timeRemaining);
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 3, data->timeRemaining);
|
||||
apdu_len += len;
|
||||
/* tag 4 - listOfValues */
|
||||
len = encode_opening_tag(&apdu[apdu_len], 4);
|
||||
@@ -119,11 +120,13 @@ static int notify_encode_adpu(uint8_t * apdu, BACNET_COV_DATA * data)
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int ccov_notify_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_COV_DATA * data)
|
||||
int ccov_notify_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
uint16_t max_apdu = Device_Max_APDU_Length_Accepted();
|
||||
|
||||
if (apdu) {
|
||||
@@ -139,10 +142,12 @@ int ccov_notify_encode_apdu(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int ucov_notify_encode_apdu(uint8_t * apdu, BACNET_COV_DATA * data)
|
||||
int ucov_notify_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && data) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -157,15 +162,17 @@ int ucov_notify_encode_apdu(uint8_t * apdu, BACNET_COV_DATA * data)
|
||||
|
||||
/* decode the service request only */
|
||||
/* COV and Unconfirmed COV are the same */
|
||||
int cov_notify_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_COV_DATA * data)
|
||||
int cov_notify_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
int len = 0; /* return value */
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint32_t decoded_value = 0; /* for decoding */
|
||||
int decoded_type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
BACNET_PROPERTY_VALUE *value = NULL; /* value in list */
|
||||
|
||||
if (apdu_len && data) {
|
||||
@@ -232,8 +239,7 @@ int cov_notify_decode_service_request(uint8_t * apdu,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
value->propertyArrayIndex = decoded_value;
|
||||
} else
|
||||
value->propertyArrayIndex = BACNET_ARRAY_ALL;
|
||||
@@ -255,8 +261,7 @@ int cov_notify_decode_service_request(uint8_t * apdu,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
value->priority = decoded_value;
|
||||
} else
|
||||
value->priority = BACNET_NO_PRIORITY;
|
||||
@@ -292,11 +297,13 @@ SubscribeCOV-Request ::= SEQUENCE {
|
||||
}
|
||||
*/
|
||||
|
||||
int cov_subscribe_encode_adpu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
int cov_subscribe_encode_adpu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
uint16_t max_apdu = Device_Max_APDU_Length_Accepted();
|
||||
|
||||
if (apdu && data) {
|
||||
@@ -326,8 +333,7 @@ int cov_subscribe_encode_adpu(uint8_t * apdu,
|
||||
2, data->issueConfirmedNotifications);
|
||||
apdu_len += len;
|
||||
/* tag 3 - lifetime */
|
||||
len = encode_context_unsigned(&apdu[apdu_len],
|
||||
3, data->lifetime);
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime);
|
||||
apdu_len += len;
|
||||
}
|
||||
}
|
||||
@@ -336,10 +342,12 @@ int cov_subscribe_encode_adpu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int cov_subscribe_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
int cov_subscribe_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
int len = 0; /* return value */
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint32_t decoded_value = 0; /* for decoding */
|
||||
@@ -367,7 +375,7 @@ int cov_subscribe_decode_service_request(uint8_t * apdu,
|
||||
} else
|
||||
return -1;
|
||||
/* optional parameters - if missing, means cancellation */
|
||||
if ((unsigned)len < apdu_len) {
|
||||
if ((unsigned) len < apdu_len) {
|
||||
/* tag 2 - issueConfirmedNotifications - optional */
|
||||
if (decode_is_context_tag(&apdu[len], 2)) {
|
||||
data->cancellationRequest = false;
|
||||
@@ -417,11 +425,13 @@ BACnetPropertyReference ::= SEQUENCE {
|
||||
|
||||
*/
|
||||
|
||||
int cov_subscribe_property_encode_adpu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
int cov_subscribe_property_encode_adpu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
uint16_t max_apdu = Device_Max_APDU_Length_Accepted();
|
||||
|
||||
if (apdu && data) {
|
||||
@@ -446,8 +456,7 @@ int cov_subscribe_property_encode_adpu(uint8_t * apdu,
|
||||
2, data->issueConfirmedNotifications);
|
||||
apdu_len += len;
|
||||
/* tag 3 - lifetime */
|
||||
len = encode_context_unsigned(&apdu[apdu_len],
|
||||
3, data->lifetime);
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* tag 4 - monitoredPropertyIdentifier */
|
||||
@@ -467,8 +476,7 @@ int cov_subscribe_property_encode_adpu(uint8_t * apdu,
|
||||
|
||||
/* tag 5 - covIncrement */
|
||||
if (data->covIncrementPresent) {
|
||||
len = encode_context_real(&apdu[apdu_len],
|
||||
5, data->covIncrement);
|
||||
len = encode_context_real(&apdu[apdu_len], 5, data->covIncrement);
|
||||
apdu_len += len;
|
||||
}
|
||||
}
|
||||
@@ -477,15 +485,17 @@ int cov_subscribe_property_encode_adpu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int cov_subscribe_property_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
int cov_subscribe_property_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
int len = 0; /* return value */
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint32_t decoded_value = 0; /* for decoding */
|
||||
int decoded_type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
|
||||
if (apdu_len && data) {
|
||||
/* tag 0 - subscriberProcessIdentifier */
|
||||
@@ -571,7 +581,9 @@ int cov_subscribe_property_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int ucov_notify_send(uint8_t * buffer, BACNET_COV_DATA * data)
|
||||
int ucov_notify_send(
|
||||
uint8_t * buffer,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
@@ -599,8 +611,11 @@ int ucov_notify_send(uint8_t * buffer, BACNET_COV_DATA * data)
|
||||
#include "ctest.h"
|
||||
#include "bacapp.h"
|
||||
|
||||
int ccov_notify_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id, BACNET_COV_DATA * data)
|
||||
int ccov_notify_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -626,8 +641,10 @@ int ccov_notify_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int ucov_notify_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_COV_DATA * data)
|
||||
int ucov_notify_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -650,8 +667,10 @@ int ucov_notify_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int cov_subscribe_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id,
|
||||
int cov_subscribe_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -678,8 +697,10 @@ int cov_subscribe_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int cov_subscribe_property_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id,
|
||||
int cov_subscribe_property_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
@@ -707,22 +728,29 @@ int cov_subscribe_property_decode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
int npdu_encode_pdu(uint8_t * npdu,
|
||||
int npdu_encode_pdu(
|
||||
uint8_t * npdu,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_NPDU_DATA * npdu_data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu,
|
||||
bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority)
|
||||
void npdu_encode_npdu_data(
|
||||
BACNET_NPDU_DATA * npdu,
|
||||
bool data_expecting_reply,
|
||||
BACNET_MESSAGE_PRIORITY priority)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data, uint8_t * pdu, unsigned pdu_len)
|
||||
int datalink_send_pdu(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
uint8_t * pdu,
|
||||
unsigned pdu_len)
|
||||
{
|
||||
(void) dest;
|
||||
(void) npdu_data;
|
||||
@@ -733,19 +761,23 @@ int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
void datalink_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest)
|
||||
{
|
||||
(void) dest;
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
uint16_t Device_Max_APDU_Length_Accepted(void)
|
||||
uint16_t Device_Max_APDU_Length_Accepted(
|
||||
void)
|
||||
{
|
||||
return MAX_APDU;
|
||||
}
|
||||
|
||||
void testCOVNotifyData(Test * pTest,
|
||||
BACNET_COV_DATA * data, BACNET_COV_DATA * test_data)
|
||||
void testCOVNotifyData(
|
||||
Test * pTest,
|
||||
BACNET_COV_DATA * data,
|
||||
BACNET_COV_DATA * test_data)
|
||||
{
|
||||
ct_test(pTest,
|
||||
test_data->subscriberProcessIdentifier ==
|
||||
@@ -763,7 +795,9 @@ void testCOVNotifyData(Test * pTest,
|
||||
/* FIXME: test the listOfValues in some clever manner */
|
||||
}
|
||||
|
||||
void testUCOVNotifyData(Test * pTest, BACNET_COV_DATA * data)
|
||||
void testUCOVNotifyData(
|
||||
Test * pTest,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -780,7 +814,9 @@ void testUCOVNotifyData(Test * pTest, BACNET_COV_DATA * data)
|
||||
testCOVNotifyData(pTest, data, &test_data);
|
||||
}
|
||||
|
||||
void testCCOVNotifyData(Test * pTest, uint8_t invoke_id,
|
||||
void testCCOVNotifyData(
|
||||
Test * pTest,
|
||||
uint8_t invoke_id,
|
||||
BACNET_COV_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
@@ -801,7 +837,8 @@ void testCCOVNotifyData(Test * pTest, uint8_t invoke_id,
|
||||
testCOVNotifyData(pTest, data, &test_data);
|
||||
}
|
||||
|
||||
void testCOVNotify(Test * pTest)
|
||||
void testCOVNotify(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t invoke_id = 12;
|
||||
BACNET_COV_DATA data;
|
||||
@@ -826,7 +863,8 @@ void testCOVNotify(Test * pTest)
|
||||
/* FIXME: add more values to the list of values */
|
||||
}
|
||||
|
||||
void testCOVSubscribeData(Test * pTest,
|
||||
void testCOVSubscribeData(
|
||||
Test * pTest,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data,
|
||||
BACNET_SUBSCRIBE_COV_DATA * test_data)
|
||||
{
|
||||
@@ -852,7 +890,8 @@ void testCOVSubscribeData(Test * pTest,
|
||||
}
|
||||
}
|
||||
|
||||
void testCOVSubscribePropertyData(Test * pTest,
|
||||
void testCOVSubscribePropertyData(
|
||||
Test * pTest,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data,
|
||||
BACNET_SUBSCRIBE_COV_DATA * test_data)
|
||||
{
|
||||
@@ -870,7 +909,9 @@ void testCOVSubscribePropertyData(Test * pTest,
|
||||
}
|
||||
}
|
||||
|
||||
void testCOVSubscribeEncoding(Test * pTest, uint8_t invoke_id,
|
||||
void testCOVSubscribeEncoding(
|
||||
Test * pTest,
|
||||
uint8_t invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
@@ -890,7 +931,9 @@ void testCOVSubscribeEncoding(Test * pTest, uint8_t invoke_id,
|
||||
testCOVSubscribeData(pTest, data, &test_data);
|
||||
}
|
||||
|
||||
void testCOVSubscribePropertyEncoding(Test * pTest, uint8_t invoke_id,
|
||||
void testCOVSubscribePropertyEncoding(
|
||||
Test * pTest,
|
||||
uint8_t invoke_id,
|
||||
BACNET_SUBSCRIBE_COV_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
@@ -910,7 +953,8 @@ void testCOVSubscribePropertyEncoding(Test * pTest, uint8_t invoke_id,
|
||||
testCOVSubscribePropertyData(pTest, data, &test_data);
|
||||
}
|
||||
|
||||
void testCOVSubscribe(Test * pTest)
|
||||
void testCOVSubscribe(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t invoke_id = 12;
|
||||
BACNET_SUBSCRIBE_COV_DATA data;
|
||||
@@ -927,7 +971,8 @@ void testCOVSubscribe(Test * pTest)
|
||||
testCOVSubscribeEncoding(pTest, invoke_id, &data);
|
||||
}
|
||||
|
||||
void testCOVSubscribeProperty(Test * pTest)
|
||||
void testCOVSubscribeProperty(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t invoke_id = 12;
|
||||
BACNET_SUBSCRIBE_COV_DATA data;
|
||||
@@ -954,7 +999,9 @@ void testCOVSubscribeProperty(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_COV
|
||||
int main(int argc, char *argv[])
|
||||
int main(
|
||||
int argc,
|
||||
char *argv[])
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -975,5 +1022,5 @@ int main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_COV */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_COV */
|
||||
#endif /* TEST */
|
||||
|
||||
+31
-20
@@ -38,8 +38,7 @@
|
||||
|
||||
#if defined(CRC_USE_TABLE)
|
||||
/* note: table is created using unit test below */
|
||||
static const uint8_t HeaderCRC[256] =
|
||||
{
|
||||
static const uint8_t HeaderCRC[256] = {
|
||||
0x00, 0xfe, 0xff, 0x01, 0xfd, 0x03, 0x02, 0xfc,
|
||||
0xf9, 0x07, 0x06, 0xf8, 0x04, 0xfa, 0xfb, 0x05,
|
||||
0xf1, 0x0f, 0x0e, 0xf0, 0x0c, 0xf2, 0xf3, 0x0d,
|
||||
@@ -74,14 +73,15 @@ static const uint8_t HeaderCRC[256] =
|
||||
0xa9, 0x57, 0x56, 0xa8, 0x54, 0xaa, 0xab, 0x55
|
||||
};
|
||||
|
||||
uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue)
|
||||
uint8_t CRC_Calc_Header(
|
||||
uint8_t dataValue,
|
||||
uint8_t crcValue)
|
||||
{
|
||||
return HeaderCRC[crcValue ^ dataValue];
|
||||
}
|
||||
|
||||
/* note: table is created using unit test below */
|
||||
static const uint16_t DataCRC[256] =
|
||||
{
|
||||
static const uint16_t DataCRC[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
@@ -116,7 +116,9 @@ static const uint16_t DataCRC[256] =
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
|
||||
uint16_t CRC_Calc_Data(
|
||||
uint8_t dataValue,
|
||||
uint16_t crcValue)
|
||||
{
|
||||
return ((crcValue >> 8) ^ DataCRC[(crcValue & 0x00FF) ^ dataValue]);
|
||||
|
||||
@@ -127,7 +129,9 @@ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
|
||||
/* */
|
||||
/* The ^ operator means exclusive OR. */
|
||||
/* Note: This function is copied directly from the BACnet standard. */
|
||||
uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue)
|
||||
uint8_t CRC_Calc_Header(
|
||||
uint8_t dataValue,
|
||||
uint8_t crcValue)
|
||||
{
|
||||
uint16_t crc;
|
||||
|
||||
@@ -147,7 +151,9 @@ uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue)
|
||||
/* */
|
||||
/* The ^ operator means exclusive OR. */
|
||||
/* Note: This function is copied directly from the BACnet standard. */
|
||||
uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
|
||||
uint16_t CRC_Calc_Data(
|
||||
uint8_t dataValue,
|
||||
uint16_t crcValue)
|
||||
{
|
||||
uint16_t crcLow;
|
||||
|
||||
@@ -167,10 +173,11 @@ uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue)
|
||||
#include "bytes.h"
|
||||
|
||||
/* 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 frame_crc; /* appended to the end of the frame */
|
||||
uint8_t crc = 0xff; /* accumulates the crc value */
|
||||
uint8_t frame_crc; /* appended to the end of the frame */
|
||||
|
||||
crc = CRC_Calc_Header(0x00, crc);
|
||||
ct_test(pTest, crc == 0x55);
|
||||
@@ -192,7 +199,8 @@ void testCRC8(Test * pTest)
|
||||
}
|
||||
|
||||
/* test from Annex G 2.0 of BACnet Standard */
|
||||
void testCRC16(Test * pTest)
|
||||
void testCRC16(
|
||||
Test * pTest)
|
||||
{
|
||||
uint16_t crc = 0xffff;
|
||||
uint16_t data_crc;
|
||||
@@ -213,19 +221,20 @@ void testCRC16(Test * pTest)
|
||||
ct_test(pTest, crc == 0xF0B8);
|
||||
}
|
||||
|
||||
void testCRC8CreateTable(Test *pTest)
|
||||
void testCRC8CreateTable(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t crc = 0xff; /* accumulates the crc value */
|
||||
uint8_t crc = 0xff; /* accumulates the crc value */
|
||||
int i;
|
||||
|
||||
(void)pTest;
|
||||
(void) pTest;
|
||||
printf("static const uint8_t HeaderCRC[256] =\n");
|
||||
printf("{\n");
|
||||
printf(" ");
|
||||
for (i = 0; i < 256; i++) {
|
||||
crc = CRC_Calc_Header(i, 0);
|
||||
printf("0x%02x, ", crc);
|
||||
if (!((i+1)%8)) {
|
||||
if (!((i + 1) % 8)) {
|
||||
printf("\n");
|
||||
if (i != 255) {
|
||||
printf(" ");
|
||||
@@ -235,19 +244,20 @@ void testCRC8CreateTable(Test *pTest)
|
||||
printf("};\n");
|
||||
}
|
||||
|
||||
void testCRC16CreateTable(Test *pTest)
|
||||
void testCRC16CreateTable(
|
||||
Test * pTest)
|
||||
{
|
||||
uint16_t crc;
|
||||
int i;
|
||||
|
||||
(void)pTest;
|
||||
(void) pTest;
|
||||
printf("static const uint16_t DataCRC[256] =\n");
|
||||
printf("{\n");
|
||||
printf(" ");
|
||||
for (i = 0; i < 256; i++) {
|
||||
crc = CRC_Calc_Data(i, 0);
|
||||
printf("0x%04x, ", crc);
|
||||
if (!((i+1)%8)) {
|
||||
if (!((i + 1) % 8)) {
|
||||
printf("\n");
|
||||
if (i != 255) {
|
||||
printf(" ");
|
||||
@@ -260,7 +270,8 @@ void testCRC16CreateTable(Test *pTest)
|
||||
#endif
|
||||
|
||||
#ifdef TEST_CRC
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
+44
-33
@@ -34,50 +34,61 @@
|
||||
#include "datalink.h"
|
||||
|
||||
/* Function pointers - point to your datalink */
|
||||
bool (*datalink_init)(char *ifname);
|
||||
bool(*datalink_init) (char *ifname);
|
||||
|
||||
int (*datalink_send_pdu)(BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data, uint8_t * pdu, unsigned pdu_len);
|
||||
int (
|
||||
*datalink_send_pdu) (
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
uint8_t * pdu,
|
||||
unsigned pdu_len);
|
||||
|
||||
uint16_t (*datalink_receive)(BACNET_ADDRESS * src,
|
||||
uint16_t(*datalink_receive) (BACNET_ADDRESS * src,
|
||||
uint8_t * pdu, uint16_t max_pdu, unsigned timeout);
|
||||
|
||||
void (*datalink_cleanup)(void);
|
||||
void (
|
||||
*datalink_cleanup) (
|
||||
void);
|
||||
|
||||
void (*datalink_get_broadcast_address)(BACNET_ADDRESS * dest);
|
||||
void (
|
||||
*datalink_get_broadcast_address) (
|
||||
BACNET_ADDRESS * dest);
|
||||
|
||||
void (*datalink_get_my_address)(BACNET_ADDRESS * my_address);
|
||||
void (
|
||||
*datalink_get_my_address) (
|
||||
BACNET_ADDRESS * my_address);
|
||||
|
||||
void datalink_configure(void)
|
||||
void datalink_configure(
|
||||
void)
|
||||
{
|
||||
#if defined(BACDL_ETHERNET)
|
||||
datalink_init = ethernet_init;
|
||||
datalink_send_pdu = ethernet_send_pdu;
|
||||
datalink_receive = ethernet_receive;
|
||||
datalink_cleanup = ethernet_cleanup;
|
||||
datalink_get_broadcast_address = ethernet_get_broadcast_address;
|
||||
datalink_get_my_address = ethernet_get_my_address;
|
||||
datalink_init = ethernet_init;
|
||||
datalink_send_pdu = ethernet_send_pdu;
|
||||
datalink_receive = ethernet_receive;
|
||||
datalink_cleanup = ethernet_cleanup;
|
||||
datalink_get_broadcast_address = ethernet_get_broadcast_address;
|
||||
datalink_get_my_address = ethernet_get_my_address;
|
||||
#elif defined(BACDL_ARCNET)
|
||||
datalink_init = arcnet_init;
|
||||
datalink_send_pdu = arcnet_send_pdu;
|
||||
datalink_receive = arcnet_receive;
|
||||
datalink_cleanup = arcnet_cleanup;
|
||||
datalink_get_broadcast_address = arcnet_get_broadcast_address;
|
||||
datalink_get_my_address = arcnet_get_my_address;
|
||||
datalink_init = arcnet_init;
|
||||
datalink_send_pdu = arcnet_send_pdu;
|
||||
datalink_receive = arcnet_receive;
|
||||
datalink_cleanup = arcnet_cleanup;
|
||||
datalink_get_broadcast_address = arcnet_get_broadcast_address;
|
||||
datalink_get_my_address = arcnet_get_my_address;
|
||||
#elif defined(BACDL_MSTP)
|
||||
datalink_init = dlmstp_init;
|
||||
datalink_send_pdu = dlmstp_send_pdu;
|
||||
datalink_receive = dlmstp_receive;
|
||||
datalink_cleanup = dlmstp_cleanup;
|
||||
datalink_get_broadcast_address = dlmstp_get_broadcast_address;
|
||||
datalink_get_my_address = dlmstp_get_my_address;
|
||||
datalink_init = dlmstp_init;
|
||||
datalink_send_pdu = dlmstp_send_pdu;
|
||||
datalink_receive = dlmstp_receive;
|
||||
datalink_cleanup = dlmstp_cleanup;
|
||||
datalink_get_broadcast_address = dlmstp_get_broadcast_address;
|
||||
datalink_get_my_address = dlmstp_get_my_address;
|
||||
#elif defined(BACDL_BIP)
|
||||
datalink_init = bip_init;
|
||||
datalink_send_pdu = bip_send_pdu;
|
||||
datalink_receive = bip_receive;
|
||||
datalink_cleanup = bip_cleanup;
|
||||
datalink_get_broadcast_address = bip_get_broadcast_address;
|
||||
datalink_get_my_address = bip_get_my_address;
|
||||
datalink_init = bip_init;
|
||||
datalink_send_pdu = bip_send_pdu;
|
||||
datalink_receive = bip_receive;
|
||||
datalink_cleanup = bip_cleanup;
|
||||
datalink_get_broadcast_address = bip_get_broadcast_address;
|
||||
datalink_get_my_address = bip_get_my_address;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+104
-50
@@ -52,7 +52,8 @@
|
||||
time or date may be interpreted as "any" or "don't care"
|
||||
*/
|
||||
|
||||
static bool is_leap_year(uint16_t year)
|
||||
static bool is_leap_year(
|
||||
uint16_t year)
|
||||
{
|
||||
if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0))
|
||||
return (true);
|
||||
@@ -60,12 +61,13 @@ static bool is_leap_year(uint16_t year)
|
||||
return (false);
|
||||
}
|
||||
|
||||
static uint8_t month_days(uint16_t year, uint8_t month)
|
||||
static uint8_t month_days(
|
||||
uint16_t year,
|
||||
uint8_t month)
|
||||
{
|
||||
/* note: start with a zero in the first element to save us from a
|
||||
month - 1 calculation in the lookup */
|
||||
int month_days[13] =
|
||||
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
int month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
/* February */
|
||||
if ((month == 2) && is_leap_year(year))
|
||||
@@ -76,12 +78,15 @@ static uint8_t month_days(uint16_t year, uint8_t month)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day)
|
||||
static uint32_t days_since_epoch(
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
uint32_t days = 0; /* return value */
|
||||
uint8_t monthdays; /* days in a month */
|
||||
uint16_t years = 0; /* loop counter for years */
|
||||
uint8_t months = 0; /* loop counter for months */
|
||||
uint32_t days = 0; /* return value */
|
||||
uint8_t monthdays; /* days in a month */
|
||||
uint16_t years = 0; /* loop counter for years */
|
||||
uint8_t months = 0; /* loop counter for months */
|
||||
|
||||
monthdays = month_days(year, month);
|
||||
if ((year >= 1900) && (monthdays) && (day >= 1) && (day <= monthdays)) {
|
||||
@@ -99,8 +104,11 @@ static uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day)
|
||||
return (days);
|
||||
}
|
||||
|
||||
static void days_since_epoch_into_ymd(uint32_t days,
|
||||
uint16_t * pYear, uint8_t * pMonth, uint8_t * pDay)
|
||||
static void days_since_epoch_into_ymd(
|
||||
uint32_t days,
|
||||
uint16_t * pYear,
|
||||
uint8_t * pMonth,
|
||||
uint8_t * pDay)
|
||||
{
|
||||
uint16_t year = 1900;
|
||||
uint8_t month = 1;
|
||||
@@ -135,7 +143,10 @@ static void days_since_epoch_into_ymd(uint32_t days,
|
||||
|
||||
/* Jan 1, 1900 is a Monday */
|
||||
/* wday 1=Monday...7=Sunday */
|
||||
static uint8_t day_of_week(uint16_t year, uint8_t month, uint8_t day)
|
||||
static uint8_t day_of_week(
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
return ((uint8_t) (days_since_epoch(year, month, day) % 7) + 1);
|
||||
}
|
||||
@@ -143,7 +154,9 @@ static uint8_t day_of_week(uint16_t year, uint8_t month, uint8_t day)
|
||||
/* if the date1 is the same as date2, return is 0
|
||||
if date1 is after date2, returns positive
|
||||
if date1 is before date2, returns negative */
|
||||
int datetime_compare_date(BACNET_DATE * date1, BACNET_DATE * date2)
|
||||
int datetime_compare_date(
|
||||
BACNET_DATE * date1,
|
||||
BACNET_DATE * date2)
|
||||
{
|
||||
int diff = 0;
|
||||
|
||||
@@ -163,7 +176,9 @@ int datetime_compare_date(BACNET_DATE * date1, BACNET_DATE * date2)
|
||||
/* if the time1 is the same as time2, return is 0
|
||||
if time1 is after time2, returns positive
|
||||
if time1 is before time2, returns negative */
|
||||
int datetime_compare_time(BACNET_TIME * time1, BACNET_TIME * time2)
|
||||
int datetime_compare_time(
|
||||
BACNET_TIME * time1,
|
||||
BACNET_TIME * time2)
|
||||
{
|
||||
int diff = 0;
|
||||
|
||||
@@ -174,8 +189,7 @@ int datetime_compare_time(BACNET_TIME * time1, BACNET_TIME * time2)
|
||||
if (diff == 0) {
|
||||
diff = (int) time1->sec - (int) time2->sec;
|
||||
if (diff == 0) {
|
||||
diff =
|
||||
(int) time1->hundredths - (int) time2->hundredths;
|
||||
diff = (int) time1->hundredths - (int) time2->hundredths;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +201,8 @@ int datetime_compare_time(BACNET_TIME * time1, BACNET_TIME * time2)
|
||||
/* if the datetime1 is the same as datetime2, return is 0
|
||||
if datetime1 is before datetime2, returns negative
|
||||
if datetime1 is after datetime2, returns positive */
|
||||
int datetime_compare(BACNET_DATE_TIME * datetime1,
|
||||
int datetime_compare(
|
||||
BACNET_DATE_TIME * datetime1,
|
||||
BACNET_DATE_TIME * datetime2)
|
||||
{
|
||||
int diff = 0;
|
||||
@@ -200,7 +215,9 @@ int datetime_compare(BACNET_DATE_TIME * datetime1,
|
||||
return diff;
|
||||
}
|
||||
|
||||
void datetime_copy_date(BACNET_DATE * dest_date, BACNET_DATE * src_date)
|
||||
void datetime_copy_date(
|
||||
BACNET_DATE * dest_date,
|
||||
BACNET_DATE * src_date)
|
||||
{
|
||||
if (dest_date && src_date) {
|
||||
dest_date->year = src_date->year;
|
||||
@@ -210,7 +227,9 @@ void datetime_copy_date(BACNET_DATE * dest_date, BACNET_DATE * src_date)
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_copy_time(BACNET_TIME * dest_time, BACNET_TIME * src_time)
|
||||
void datetime_copy_time(
|
||||
BACNET_TIME * dest_time,
|
||||
BACNET_TIME * src_time)
|
||||
{
|
||||
if (dest_time && src_time) {
|
||||
dest_time->hour = src_time->hour;
|
||||
@@ -220,15 +239,19 @@ void datetime_copy_time(BACNET_TIME * dest_time, BACNET_TIME * src_time)
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_copy(BACNET_DATE_TIME * dest_datetime,
|
||||
void datetime_copy(
|
||||
BACNET_DATE_TIME * dest_datetime,
|
||||
BACNET_DATE_TIME * src_datetime)
|
||||
{
|
||||
datetime_copy_time(&dest_datetime->time, &src_datetime->time);
|
||||
datetime_copy_date(&dest_datetime->date, &src_datetime->date);
|
||||
}
|
||||
|
||||
void datetime_set_date(BACNET_DATE * bdate,
|
||||
uint16_t year, uint8_t month, uint8_t day)
|
||||
void datetime_set_date(
|
||||
BACNET_DATE * bdate,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
if (bdate) {
|
||||
bdate->year = year;
|
||||
@@ -238,8 +261,12 @@ void datetime_set_date(BACNET_DATE * bdate,
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_set_time(BACNET_TIME * btime,
|
||||
uint8_t hour, uint8_t minute, uint8_t seconds, uint8_t hundredths)
|
||||
void datetime_set_time(
|
||||
BACNET_TIME * btime,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths)
|
||||
{
|
||||
if (btime) {
|
||||
btime->hour = hour;
|
||||
@@ -249,8 +276,10 @@ void datetime_set_time(BACNET_TIME * btime,
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_set(BACNET_DATE_TIME * bdatetime,
|
||||
BACNET_DATE * bdate, BACNET_TIME * btime)
|
||||
void datetime_set(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
BACNET_DATE * bdate,
|
||||
BACNET_TIME * btime)
|
||||
{
|
||||
if (bdate && btime && bdatetime) {
|
||||
bdatetime->time.hour = btime->hour;
|
||||
@@ -264,9 +293,15 @@ void datetime_set(BACNET_DATE_TIME * bdatetime,
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_set_values(BACNET_DATE_TIME * bdatetime,
|
||||
uint16_t year, uint8_t month, uint8_t day,
|
||||
uint8_t hour, uint8_t minute, uint8_t seconds, uint8_t hundredths)
|
||||
void datetime_set_values(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths)
|
||||
{
|
||||
if (bdatetime) {
|
||||
bdatetime->date.year = year;
|
||||
@@ -280,14 +315,19 @@ void datetime_set_values(BACNET_DATE_TIME * bdatetime,
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t seconds_since_midnight(uint8_t hours, uint8_t minutes,
|
||||
static uint32_t seconds_since_midnight(
|
||||
uint8_t hours,
|
||||
uint8_t minutes,
|
||||
uint8_t seconds)
|
||||
{
|
||||
return ((hours * 60 * 60) + (minutes * 60) + seconds);
|
||||
}
|
||||
|
||||
static void seconds_since_midnight_into_hms(uint32_t seconds,
|
||||
uint8_t * pHours, uint8_t * pMinutes, uint8_t * pSeconds)
|
||||
static void seconds_since_midnight_into_hms(
|
||||
uint32_t seconds,
|
||||
uint8_t * pHours,
|
||||
uint8_t * pMinutes,
|
||||
uint8_t * pSeconds)
|
||||
{
|
||||
uint8_t hour = 0;
|
||||
uint8_t minute = 0;
|
||||
@@ -305,7 +345,9 @@ static void seconds_since_midnight_into_hms(uint32_t seconds,
|
||||
*pSeconds = (uint8_t) seconds;
|
||||
}
|
||||
|
||||
void datetime_add_minutes(BACNET_DATE_TIME * bdatetime, uint32_t minutes)
|
||||
void datetime_add_minutes(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
uint32_t minutes)
|
||||
{
|
||||
uint32_t bdatetime_minutes = 0;
|
||||
uint32_t bdatetime_days = 0;
|
||||
@@ -329,13 +371,13 @@ void datetime_add_minutes(BACNET_DATE_TIME * bdatetime, uint32_t minutes)
|
||||
seconds_since_midnight_into_hms(bdatetime_minutes * 60,
|
||||
&bdatetime->time.hour, &bdatetime->time.min, &bdatetime->time.sec);
|
||||
days_since_epoch_into_ymd(bdatetime_days,
|
||||
&bdatetime->date.year,
|
||||
&bdatetime->date.month, &bdatetime->date.day);
|
||||
&bdatetime->date.year, &bdatetime->date.month, &bdatetime->date.day);
|
||||
bdatetime->date.wday = day_of_week(bdatetime->date.year,
|
||||
bdatetime->date.month, bdatetime->date.day);
|
||||
}
|
||||
|
||||
bool datetime_wildcard(BACNET_DATE_TIME * bdatetime)
|
||||
bool datetime_wildcard(
|
||||
BACNET_DATE_TIME * bdatetime)
|
||||
{
|
||||
bool wildcard_present = false;
|
||||
|
||||
@@ -355,7 +397,8 @@ bool datetime_wildcard(BACNET_DATE_TIME * bdatetime)
|
||||
return wildcard_present;
|
||||
}
|
||||
|
||||
void datetime_date_wildcard_set(BACNET_DATE * bdate)
|
||||
void datetime_date_wildcard_set(
|
||||
BACNET_DATE * bdate)
|
||||
{
|
||||
if (bdate) {
|
||||
bdate->year = 1900 + 0xFF;
|
||||
@@ -365,7 +408,8 @@ void datetime_date_wildcard_set(BACNET_DATE * bdate)
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_time_wildcard_set(BACNET_TIME * btime)
|
||||
void datetime_time_wildcard_set(
|
||||
BACNET_TIME * btime)
|
||||
{
|
||||
if (btime) {
|
||||
btime->hour = 0xFF;
|
||||
@@ -375,7 +419,8 @@ void datetime_time_wildcard_set(BACNET_TIME * btime)
|
||||
}
|
||||
}
|
||||
|
||||
void datetime_wildcard_set(BACNET_DATE_TIME * bdatetime)
|
||||
void datetime_wildcard_set(
|
||||
BACNET_DATE_TIME * bdatetime)
|
||||
{
|
||||
if (bdatetime) {
|
||||
datetime_date_wildcard_set(&bdatetime->date);
|
||||
@@ -389,7 +434,8 @@ void datetime_wildcard_set(BACNET_DATE_TIME * bdatetime)
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBACnetDateTimeWildcard(Test * pTest)
|
||||
void testBACnetDateTimeWildcard(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_DATE_TIME bdatetime;
|
||||
bool status = false;
|
||||
@@ -403,7 +449,8 @@ void testBACnetDateTimeWildcard(Test * pTest)
|
||||
ct_test(pTest, status == true);
|
||||
}
|
||||
|
||||
void testBACnetDateTimeAdd(Test * pTest)
|
||||
void testBACnetDateTimeAdd(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_DATE_TIME bdatetime, test_bdatetime;
|
||||
uint32_t minutes = 0;
|
||||
@@ -436,7 +483,8 @@ void testBACnetDateTimeAdd(Test * pTest)
|
||||
|
||||
|
||||
|
||||
void testBACnetDateTimeSeconds(Test * pTest)
|
||||
void testBACnetDateTimeSeconds(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t hour = 0, minute = 0, second = 0;
|
||||
uint8_t test_hour = 0, test_minute = 0, test_second = 0;
|
||||
@@ -457,7 +505,8 @@ void testBACnetDateTimeSeconds(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetDate(Test * pTest)
|
||||
void testBACnetDate(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_DATE bdate1, bdate2;
|
||||
int diff = 0;
|
||||
@@ -518,7 +567,8 @@ void testBACnetDate(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testBACnetTime(Test * pTest)
|
||||
void testBACnetTime(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_TIME btime1, btime2;
|
||||
int diff = 0;
|
||||
@@ -567,7 +617,8 @@ void testBACnetTime(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testBACnetDateTime(Test * pTest)
|
||||
void testBACnetDateTime(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_DATE_TIME bdatetime1, bdatetime2;
|
||||
BACNET_DATE bdate;
|
||||
@@ -634,7 +685,8 @@ void testBACnetDateTime(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testDateEpoch(Test * pTest)
|
||||
void testDateEpoch(
|
||||
Test * pTest)
|
||||
{
|
||||
uint32_t days = 0;
|
||||
uint16_t year = 0, test_year = 0;
|
||||
@@ -663,7 +715,8 @@ void testDateEpoch(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testBACnetDayOfWeek(Test * pTest)
|
||||
void testBACnetDayOfWeek(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t dow = 0;
|
||||
|
||||
@@ -692,7 +745,8 @@ void testBACnetDayOfWeek(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_DATE_TIME
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -723,5 +777,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_DATE_TIME */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_DATE_TIME */
|
||||
#endif /* TEST */
|
||||
|
||||
+38
-27
@@ -46,12 +46,14 @@ static BACNET_COMMUNICATION_ENABLE_DISABLE DCC_Enable_Disable =
|
||||
COMMUNICATION_ENABLE;
|
||||
/* password is optionally supported */
|
||||
|
||||
BACNET_COMMUNICATION_ENABLE_DISABLE dcc_enable_status(void)
|
||||
BACNET_COMMUNICATION_ENABLE_DISABLE dcc_enable_status(
|
||||
void)
|
||||
{
|
||||
return DCC_Enable_Disable;
|
||||
}
|
||||
|
||||
bool dcc_communication_enabled(void)
|
||||
bool dcc_communication_enabled(
|
||||
void)
|
||||
{
|
||||
return (DCC_Enable_Disable == COMMUNICATION_ENABLE);
|
||||
}
|
||||
@@ -59,7 +61,8 @@ bool dcc_communication_enabled(void)
|
||||
/* When network communications are completely disabled,
|
||||
only DeviceCommunicationControl and ReinitializeDevice APDUs
|
||||
shall be processed and no messages shall be initiated.*/
|
||||
bool dcc_communication_disabled(void)
|
||||
bool dcc_communication_disabled(
|
||||
void)
|
||||
{
|
||||
return (DCC_Enable_Disable == COMMUNICATION_DISABLE);
|
||||
}
|
||||
@@ -73,19 +76,22 @@ bool dcc_communication_disabled(void)
|
||||
for any Who-Is request that is received if and only if
|
||||
the Who-Is request does not contain an address range or
|
||||
the device is included in the address range. */
|
||||
bool dcc_communication_initiation_disabled(void)
|
||||
bool dcc_communication_initiation_disabled(
|
||||
void)
|
||||
{
|
||||
return (DCC_Enable_Disable == COMMUNICATION_DISABLE_INITIATION);
|
||||
}
|
||||
|
||||
uint32_t dcc_duration_seconds(void)
|
||||
uint32_t dcc_duration_seconds(
|
||||
void)
|
||||
{
|
||||
return DCC_Time_Duration_Seconds;
|
||||
}
|
||||
|
||||
/* called every second or so. If more than one second,
|
||||
then seconds should be the number of seconds to tick away */
|
||||
void dcc_timer_seconds(uint32_t seconds)
|
||||
void dcc_timer_seconds(
|
||||
uint32_t seconds)
|
||||
{
|
||||
if (DCC_Time_Duration_Seconds) {
|
||||
if (DCC_Time_Duration_Seconds > seconds)
|
||||
@@ -98,7 +104,8 @@ void dcc_timer_seconds(uint32_t seconds)
|
||||
}
|
||||
}
|
||||
|
||||
bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE status,
|
||||
bool dcc_set_status_duration(
|
||||
BACNET_COMMUNICATION_ENABLE_DISABLE status,
|
||||
uint16_t minutes)
|
||||
{
|
||||
bool valid = false;
|
||||
@@ -117,12 +124,15 @@ bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE status,
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
{ /* NULL=optional */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -132,20 +142,17 @@ int dcc_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint16_t timeDuration,
|
||||
apdu_len = 4;
|
||||
/* optional timeDuration */
|
||||
if (timeDuration) {
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 0, timeDuration);
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 0, timeDuration);
|
||||
apdu_len += len;
|
||||
}
|
||||
/* enable disable */
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 1, enable_disable);
|
||||
len = encode_context_enumerated(&apdu[apdu_len], 1, enable_disable);
|
||||
apdu_len += len;
|
||||
/* optional password */
|
||||
if (password) {
|
||||
/* FIXME: must be at least 1 character, limited to 20 characters */
|
||||
len =
|
||||
encode_context_character_string(&apdu[apdu_len], 2,
|
||||
password);
|
||||
encode_context_character_string(&apdu[apdu_len], 2, password);
|
||||
apdu_len += len;
|
||||
}
|
||||
}
|
||||
@@ -154,7 +161,8 @@ int dcc_encode_apdu(uint8_t * apdu, uint8_t invoke_id, uint16_t timeDuration,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int dcc_decode_service_request(uint8_t * apdu,
|
||||
int dcc_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint16_t * timeDuration,
|
||||
BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable,
|
||||
@@ -184,7 +192,7 @@ int dcc_decode_service_request(uint8_t * apdu,
|
||||
&tag_number, &len_value_type);
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &value);
|
||||
if (enable_disable)
|
||||
*enable_disable = (BACNET_COMMUNICATION_ENABLE_DISABLE)value;
|
||||
*enable_disable = (BACNET_COMMUNICATION_ENABLE_DISABLE) value;
|
||||
/* Tag 2: password --optional-- */
|
||||
if (len < apdu_len) {
|
||||
if (!decode_is_context_tag(&apdu[len], 2))
|
||||
@@ -192,8 +200,7 @@ int dcc_decode_service_request(uint8_t * apdu,
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_character_string(&apdu[len], len_value_type,
|
||||
password);
|
||||
decode_character_string(&apdu[len], len_value_type, password);
|
||||
} else if (password)
|
||||
characterstring_init_ansi(password, NULL);
|
||||
}
|
||||
@@ -206,7 +213,8 @@ int dcc_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int dcc_decode_apdu(uint8_t * apdu,
|
||||
int dcc_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint16_t * timeDuration,
|
||||
@@ -235,7 +243,8 @@ int dcc_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void test_DeviceCommunicationControlData(Test * pTest,
|
||||
void test_DeviceCommunicationControlData(
|
||||
Test * pTest,
|
||||
uint8_t invoke_id,
|
||||
uint16_t timeDuration,
|
||||
BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable,
|
||||
@@ -265,7 +274,8 @@ void test_DeviceCommunicationControlData(Test * pTest,
|
||||
ct_test(pTest, characterstring_same(&test_password, password));
|
||||
}
|
||||
|
||||
void test_DeviceCommunicationControl(Test * pTest)
|
||||
void test_DeviceCommunicationControl(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t invoke_id = 128;
|
||||
uint16_t timeDuration = 0;
|
||||
@@ -287,7 +297,8 @@ void test_DeviceCommunicationControl(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_DEVICE_COMMUNICATION_CONTROL
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -304,5 +315,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_DEVICE_COMMUNICATION_CONTROL */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_DEVICE_COMMUNICATION_CONTROL */
|
||||
#endif /* TEST */
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char *filename_remove_path(const char *filename_in)
|
||||
char *filename_remove_path(
|
||||
const char *filename_in)
|
||||
{
|
||||
char *filename_out = NULL;
|
||||
|
||||
@@ -57,7 +58,8 @@ char *filename_remove_path(const char *filename_in)
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
void testFilename(Test * pTest)
|
||||
void testFilename(
|
||||
Test * pTest)
|
||||
{
|
||||
char *data1 = "c:\\Joshua\\run";
|
||||
char *data2 = "/home/Anna/run";
|
||||
@@ -78,7 +80,8 @@ void testFilename(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_FILENAME
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -97,5 +100,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_FILENAME */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_FILENAME */
|
||||
#endif /* TEST */
|
||||
|
||||
+55
-39
@@ -42,12 +42,15 @@
|
||||
#include "address.h"
|
||||
|
||||
/* encode I-Am service */
|
||||
int iam_encode_apdu(uint8_t * apdu,
|
||||
int iam_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
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 apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -67,12 +70,15 @@ int iam_encode_apdu(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int iam_decode_service_request(uint8_t * apdu,
|
||||
int iam_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id)
|
||||
unsigned *pMax_apdu,
|
||||
int *pSegmentation,
|
||||
uint16_t * pVendor_id)
|
||||
{
|
||||
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 */
|
||||
uint32_t object_instance = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -82,13 +88,11 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
|
||||
/* OBJECT ID - object id */
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
|
||||
apdu_len += len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID)
|
||||
return -1;
|
||||
len =
|
||||
decode_object_id(&apdu[apdu_len], &object_type, &object_instance);
|
||||
len = decode_object_id(&apdu[apdu_len], &object_type, &object_instance);
|
||||
apdu_len += len;
|
||||
if (object_type != OBJECT_DEVICE)
|
||||
return -1;
|
||||
@@ -96,8 +100,7 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
*pDevice_id = object_instance;
|
||||
/* MAX APDU - unsigned */
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
|
||||
apdu_len += len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return -1;
|
||||
@@ -107,8 +110,7 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
*pMax_apdu = decoded_value;
|
||||
/* Segmentation - enumerated */
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
|
||||
apdu_len += len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
|
||||
return -1;
|
||||
@@ -120,8 +122,7 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
*pSegmentation = decoded_integer;
|
||||
/* Vendor ID - unsigned16 */
|
||||
len =
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
|
||||
apdu_len += len;
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return -1;
|
||||
@@ -135,9 +136,10 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int iam_encode_pdu(uint8_t * buffer,
|
||||
BACNET_ADDRESS *dest,
|
||||
BACNET_NPDU_DATA *npdu_data)
|
||||
int iam_encode_pdu(
|
||||
uint8_t * buffer,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data)
|
||||
{
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
@@ -156,7 +158,8 @@ int iam_encode_pdu(uint8_t * buffer,
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
int iam_send(uint8_t * buffer)
|
||||
int iam_send(
|
||||
uint8_t * buffer)
|
||||
{
|
||||
int pdu_len = 0;
|
||||
BACNET_ADDRESS dest;
|
||||
@@ -179,11 +182,14 @@ int iam_send(uint8_t * buffer)
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int iam_decode_apdu(uint8_t * apdu,
|
||||
int iam_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
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? */
|
||||
if (!apdu)
|
||||
@@ -199,7 +205,8 @@ int iam_decode_apdu(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
void testIAm(Test * pTest)
|
||||
void testIAm(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -217,8 +224,7 @@ void testIAm(Test * pTest)
|
||||
ct_test(pTest, len != 0);
|
||||
|
||||
len = iam_decode_apdu(&apdu[0],
|
||||
&test_device_id,
|
||||
&test_max_apdu, &test_segmentation, &test_vendor_id);
|
||||
&test_device_id, &test_max_apdu, &test_segmentation, &test_vendor_id);
|
||||
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_device_id == device_id);
|
||||
@@ -229,8 +235,11 @@ void testIAm(Test * pTest)
|
||||
|
||||
#ifdef TEST_IAM
|
||||
/* dummy function stubs */
|
||||
int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data, uint8_t * pdu, unsigned pdu_len)
|
||||
int datalink_send_pdu(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
uint8_t * pdu,
|
||||
unsigned pdu_len)
|
||||
{
|
||||
(void) dest;
|
||||
(void) npdu_data;
|
||||
@@ -240,23 +249,28 @@ int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
void datalink_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
(void) dest;
|
||||
}
|
||||
|
||||
uint16_t Device_Vendor_Identifier(void)
|
||||
uint16_t Device_Vendor_Identifier(
|
||||
void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Device_Object_Instance_Number(void)
|
||||
uint32_t Device_Object_Instance_Number(
|
||||
void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void address_add_binding(uint32_t device_id,
|
||||
unsigned max_apdu, BACNET_ADDRESS * src)
|
||||
void address_add_binding(
|
||||
uint32_t device_id,
|
||||
unsigned max_apdu,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
(void) device_id;
|
||||
(void) max_apdu;
|
||||
@@ -264,14 +278,16 @@ void address_add_binding(uint32_t device_id,
|
||||
}
|
||||
|
||||
/* dummy for apdu dependency */
|
||||
void tsm_free_invoke_id(uint8_t invokeID)
|
||||
void tsm_free_invoke_id(
|
||||
uint8_t invokeID)
|
||||
{
|
||||
/* dummy stub for testing */
|
||||
(void) invokeID;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -288,5 +304,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_IAM */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_IAM */
|
||||
#endif /* TEST */
|
||||
|
||||
+27
-22
@@ -37,10 +37,12 @@
|
||||
#include "bacdef.h"
|
||||
#include "ihave.h"
|
||||
|
||||
int ihave_encode_apdu(uint8_t * apdu, BACNET_I_HAVE_DATA * data)
|
||||
int ihave_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
BACNET_I_HAVE_DATA * data)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && data) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -64,8 +66,10 @@ int ihave_encode_apdu(uint8_t * apdu, BACNET_I_HAVE_DATA * data)
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int ihave_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_I_HAVE_DATA * data)
|
||||
int ihave_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_I_HAVE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -75,8 +79,7 @@ int ihave_decode_service_request(uint8_t * apdu,
|
||||
if (apdu_len && data) {
|
||||
/* deviceIdentifier */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
len += decode_object_id(&apdu[len], &decoded_type,
|
||||
&data->device_id.instance);
|
||||
@@ -85,8 +88,7 @@ int ihave_decode_service_request(uint8_t * apdu,
|
||||
return -1;
|
||||
/* objectIdentifier */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||
len += decode_object_id(&apdu[len], &decoded_type,
|
||||
&data->object_id.instance);
|
||||
@@ -95,8 +97,7 @@ int ihave_decode_service_request(uint8_t * apdu,
|
||||
return -1;
|
||||
/* objectName */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||
len += decode_character_string(&apdu[len], len_value,
|
||||
&data->object_name);
|
||||
@@ -108,8 +109,10 @@ int ihave_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int ihave_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_I_HAVE_DATA * data)
|
||||
int ihave_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_I_HAVE_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -130,7 +133,9 @@ int ihave_decode_apdu(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testIHaveData(Test * pTest, BACNET_I_HAVE_DATA * data)
|
||||
void testIHaveData(
|
||||
Test * pTest,
|
||||
BACNET_I_HAVE_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -144,16 +149,15 @@ void testIHaveData(Test * pTest, BACNET_I_HAVE_DATA * data)
|
||||
len = ihave_decode_apdu(&apdu[0], apdu_len, &test_data);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_data.device_id.type == data->device_id.type);
|
||||
ct_test(pTest, test_data.device_id.instance ==
|
||||
data->device_id.instance);
|
||||
ct_test(pTest, test_data.device_id.instance == data->device_id.instance);
|
||||
ct_test(pTest, test_data.object_id.type == data->object_id.type);
|
||||
ct_test(pTest, test_data.object_id.instance ==
|
||||
data->object_id.instance);
|
||||
ct_test(pTest, test_data.object_id.instance == data->object_id.instance);
|
||||
ct_test(pTest, characterstring_same(&test_data.object_name,
|
||||
&data->object_name));
|
||||
}
|
||||
|
||||
void testIHave(Test * pTest)
|
||||
void testIHave(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_I_HAVE_DATA data;
|
||||
|
||||
@@ -175,7 +179,8 @@ void testIHave(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_I_HAVE
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -192,5 +197,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
|
||||
+36
-19
@@ -39,8 +39,10 @@
|
||||
#define strcasecmp stricmp
|
||||
#endif
|
||||
|
||||
bool indtext_by_string(INDTEXT_DATA * data_list,
|
||||
const char *search_name, unsigned *found_index)
|
||||
bool indtext_by_string(
|
||||
INDTEXT_DATA * data_list,
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
bool found = false;
|
||||
unsigned index = 0;
|
||||
@@ -63,8 +65,10 @@ bool indtext_by_string(INDTEXT_DATA * data_list,
|
||||
}
|
||||
|
||||
/* case insensitive version */
|
||||
bool indtext_by_istring(INDTEXT_DATA * data_list,
|
||||
const char *search_name, unsigned *found_index)
|
||||
bool indtext_by_istring(
|
||||
INDTEXT_DATA * data_list,
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
bool found = false;
|
||||
unsigned index = 0;
|
||||
@@ -86,8 +90,10 @@ bool indtext_by_istring(INDTEXT_DATA * data_list,
|
||||
return found;
|
||||
}
|
||||
|
||||
unsigned indtext_by_string_default(INDTEXT_DATA * data_list,
|
||||
const char *search_name, unsigned default_index)
|
||||
unsigned indtext_by_string_default(
|
||||
INDTEXT_DATA * data_list,
|
||||
const char *search_name,
|
||||
unsigned default_index)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
@@ -97,8 +103,10 @@ unsigned indtext_by_string_default(INDTEXT_DATA * data_list,
|
||||
return index;
|
||||
}
|
||||
|
||||
unsigned indtext_by_istring_default(INDTEXT_DATA * data_list,
|
||||
const char *search_name, unsigned default_index)
|
||||
unsigned indtext_by_istring_default(
|
||||
INDTEXT_DATA * data_list,
|
||||
const char *search_name,
|
||||
unsigned default_index)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
@@ -108,8 +116,10 @@ unsigned indtext_by_istring_default(INDTEXT_DATA * data_list,
|
||||
return index;
|
||||
}
|
||||
|
||||
const char *indtext_by_index_default(INDTEXT_DATA * data_list,
|
||||
unsigned index, const char *default_string)
|
||||
const char *indtext_by_index_default(
|
||||
INDTEXT_DATA * data_list,
|
||||
unsigned index,
|
||||
const char *default_string)
|
||||
{
|
||||
const char *pString = NULL;
|
||||
|
||||
@@ -126,10 +136,12 @@ const char *indtext_by_index_default(INDTEXT_DATA * data_list,
|
||||
return pString ? pString : default_string;
|
||||
}
|
||||
|
||||
const char *indtext_by_index_split_default(INDTEXT_DATA * data_list,
|
||||
const char *indtext_by_index_split_default(
|
||||
INDTEXT_DATA * data_list,
|
||||
int index,
|
||||
int split_index,
|
||||
const char *before_split_default_name, const char *default_name)
|
||||
const char *before_split_default_name,
|
||||
const char *default_name)
|
||||
{
|
||||
if (index < split_index)
|
||||
return indtext_by_index_default(data_list, index,
|
||||
@@ -139,14 +151,17 @@ const char *indtext_by_index_split_default(INDTEXT_DATA * data_list,
|
||||
};
|
||||
|
||||
|
||||
const char *indtext_by_index(INDTEXT_DATA * data_list, unsigned index)
|
||||
const char *indtext_by_index(
|
||||
INDTEXT_DATA * data_list,
|
||||
unsigned index)
|
||||
{
|
||||
return indtext_by_index_default(data_list, index, NULL);
|
||||
}
|
||||
|
||||
unsigned indtext_count(INDTEXT_DATA * data_list)
|
||||
unsigned indtext_count(
|
||||
INDTEXT_DATA * data_list)
|
||||
{
|
||||
unsigned count = 0; /* return value */
|
||||
unsigned count = 0; /* return value */
|
||||
|
||||
if (data_list) {
|
||||
while (data_list->pString) {
|
||||
@@ -170,9 +185,10 @@ static INDTEXT_DATA data_list[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
void testIndexText(Test * pTest)
|
||||
void testIndexText(
|
||||
Test * pTest)
|
||||
{
|
||||
unsigned i; /*counter */
|
||||
unsigned i; /*counter */
|
||||
const char *pString;
|
||||
unsigned index;
|
||||
bool valid;
|
||||
@@ -206,7 +222,8 @@ void testIndexText(Test * pTest)
|
||||
#endif
|
||||
|
||||
#ifdef TEST_INDEX_TEXT
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -225,4 +242,4 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_INDEX_TEXT */
|
||||
#endif /* TEST_INDEX_TEXT */
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
#include "ctest.h"
|
||||
|
||||
/* test the encode and decode macros */
|
||||
void testKeys(Test * pTest)
|
||||
void testKeys(
|
||||
Test * pTest)
|
||||
{
|
||||
int type, id;
|
||||
int decoded_type, decoded_id;
|
||||
@@ -62,7 +63,8 @@ void testKeys(Test * pTest)
|
||||
}
|
||||
|
||||
/* test the encode and decode macros */
|
||||
void testKeySample(Test * pTest)
|
||||
void testKeySample(
|
||||
Test * pTest)
|
||||
{
|
||||
int type, id;
|
||||
int type_list[] = { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1 };
|
||||
@@ -92,7 +94,8 @@ void testKeySample(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_KEY
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -112,5 +115,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* LOCAL_TEST */
|
||||
#endif /* LOCAL_TEST */
|
||||
#endif
|
||||
|
||||
+73
-41
@@ -41,7 +41,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "keylist.h" /* check for valid prototypes */
|
||||
#include "keylist.h" /* check for valid prototypes */
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
@@ -56,13 +56,15 @@
|
||||
/*/////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/* grab memory for a node */
|
||||
static struct Keylist_Node *NodeCreate(void)
|
||||
static struct Keylist_Node *NodeCreate(
|
||||
void)
|
||||
{
|
||||
return calloc(1, sizeof(struct Keylist_Node));
|
||||
}
|
||||
|
||||
/* grab memory for a list */
|
||||
static struct Keylist *KeylistCreate(void)
|
||||
static struct Keylist *KeylistCreate(
|
||||
void)
|
||||
{
|
||||
return calloc(1, sizeof(struct Keylist));
|
||||
}
|
||||
@@ -70,12 +72,13 @@ static struct Keylist *KeylistCreate(void)
|
||||
/* check to see if the array is big enough for an addition */
|
||||
/* or is too big when we are deleting and we can shrink */
|
||||
/* returns TRUE if success, FALSE if failed */
|
||||
static int CheckArraySize(OS_Keylist list)
|
||||
static int CheckArraySize(
|
||||
OS_Keylist list)
|
||||
{
|
||||
int new_size = 0; /* set it up so that no size change is the default */
|
||||
int new_size = 0; /* set it up so that no size change is the default */
|
||||
const int chunk = 8; /* minimum number of nodes to allocate memory for */
|
||||
struct Keylist_Node **new_array; /* new array of nodes, if needed */
|
||||
int i; /* counter */
|
||||
int i; /* counter */
|
||||
if (!list)
|
||||
return FALSE;
|
||||
|
||||
@@ -115,14 +118,17 @@ static int CheckArraySize(OS_Keylist list)
|
||||
/* returns the found key and the index where it was found in parameters */
|
||||
/* If the key is not found, the nearest index from the bottom will be returned, */
|
||||
/* allowing the ability to find where an key should go into the list. */
|
||||
static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
||||
static int FindIndex(
|
||||
OS_Keylist list,
|
||||
KEY key,
|
||||
int *pIndex)
|
||||
{
|
||||
struct Keylist_Node *node; /* holds the new node */
|
||||
int left = 0; /* the left branch of tree, beginning of list */
|
||||
int right = 0; /* the right branch on the tree, end of list */
|
||||
int index = 0; /* our current search place in the array */
|
||||
int left = 0; /* the left branch of tree, beginning of list */
|
||||
int right = 0; /* the right branch on the tree, end of list */
|
||||
int index = 0; /* our current search place in the array */
|
||||
KEY current_key = 0; /* place holder for current node key */
|
||||
int status = FALSE; /* return value */
|
||||
int status = FALSE; /* return value */
|
||||
if (!list || !list->array || !list->count) {
|
||||
*pIndex = 0;
|
||||
return (FALSE);
|
||||
@@ -166,11 +172,14 @@ static int FindIndex(OS_Keylist list, KEY key, int *pIndex)
|
||||
/* list data functions */
|
||||
/*/////////////////////////////////////////////////////////////////// */
|
||||
/* inserts a node into its sorted position */
|
||||
int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
||||
int Keylist_Data_Add(
|
||||
OS_Keylist list,
|
||||
KEY key,
|
||||
void *data)
|
||||
{
|
||||
struct Keylist_Node *node; /* holds the new node */
|
||||
int index = -1; /* return value */
|
||||
int i; /* counts through the array */
|
||||
int index = -1; /* return value */
|
||||
int i; /* counts through the array */
|
||||
|
||||
if (list && CheckArraySize(list)) {
|
||||
/* figure out where to put the new node */
|
||||
@@ -208,7 +217,9 @@ int Keylist_Data_Add(OS_Keylist list, KEY key, void *data)
|
||||
|
||||
/* deletes a node specified by its index */
|
||||
/* returns the data from the node */
|
||||
void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
||||
void *Keylist_Data_Delete_By_Index(
|
||||
OS_Keylist list,
|
||||
int index)
|
||||
{
|
||||
struct Keylist_Node *node;
|
||||
void *data = NULL;
|
||||
@@ -231,7 +242,7 @@ void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
||||
}
|
||||
/* Move all the nodes down one */
|
||||
else {
|
||||
int i; /* counter */
|
||||
int i; /* counter */
|
||||
int count = list->count - 1;
|
||||
for (i = index; i < count; i++) {
|
||||
list->array[i] = list->array[i + 1];
|
||||
@@ -250,10 +261,12 @@ void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index)
|
||||
|
||||
/* deletes a node specified by its key */
|
||||
/* returns the data from the node */
|
||||
void *Keylist_Data_Delete(OS_Keylist list, KEY key)
|
||||
void *Keylist_Data_Delete(
|
||||
OS_Keylist list,
|
||||
KEY key)
|
||||
{
|
||||
void *data = NULL; /* return value */
|
||||
int index; /* where the node is in the array */
|
||||
void *data = NULL; /* return value */
|
||||
int index; /* where the node is in the array */
|
||||
|
||||
if (list) {
|
||||
if (FindIndex(list, key, &index))
|
||||
@@ -264,10 +277,11 @@ void *Keylist_Data_Delete(OS_Keylist list, KEY key)
|
||||
}
|
||||
|
||||
/* returns the data from last node, and removes it from the list */
|
||||
void *Keylist_Data_Pop(OS_Keylist list)
|
||||
void *Keylist_Data_Pop(
|
||||
OS_Keylist list)
|
||||
{
|
||||
void *data = NULL; /* return value */
|
||||
int index; /* position in the array */
|
||||
void *data = NULL; /* return value */
|
||||
int index; /* position in the array */
|
||||
|
||||
if (list && list->count) {
|
||||
index = list->count - 1;
|
||||
@@ -278,10 +292,12 @@ void *Keylist_Data_Pop(OS_Keylist list)
|
||||
}
|
||||
|
||||
/* returns the data from the node specified by key */
|
||||
void *Keylist_Data(OS_Keylist list, KEY key)
|
||||
void *Keylist_Data(
|
||||
OS_Keylist list,
|
||||
KEY key)
|
||||
{
|
||||
struct Keylist_Node *node = NULL;
|
||||
int index = 0; /* used to look up the index of node */
|
||||
int index = 0; /* used to look up the index of node */
|
||||
|
||||
if (list && list->array && list->count) {
|
||||
if (FindIndex(list, key, &index))
|
||||
@@ -292,7 +308,9 @@ void *Keylist_Data(OS_Keylist list, KEY key)
|
||||
}
|
||||
|
||||
/* returns the data specified by key */
|
||||
void *Keylist_Data_Index(OS_Keylist list, int index)
|
||||
void *Keylist_Data_Index(
|
||||
OS_Keylist list,
|
||||
int index)
|
||||
{
|
||||
struct Keylist_Node *node = NULL;
|
||||
|
||||
@@ -304,9 +322,11 @@ void *Keylist_Data_Index(OS_Keylist list, int index)
|
||||
}
|
||||
|
||||
/* return the key at the given index */
|
||||
KEY Keylist_Key(OS_Keylist list, int index)
|
||||
KEY Keylist_Key(
|
||||
OS_Keylist list,
|
||||
int index)
|
||||
{
|
||||
KEY key = 0; /* return value */
|
||||
KEY key = 0; /* return value */
|
||||
struct Keylist_Node *node;
|
||||
|
||||
if (list && list->array && list->count &&
|
||||
@@ -320,7 +340,9 @@ KEY Keylist_Key(OS_Keylist list, int index)
|
||||
}
|
||||
|
||||
/* returns the next empty key from the list */
|
||||
KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key)
|
||||
KEY Keylist_Next_Empty_Key(
|
||||
OS_Keylist list,
|
||||
KEY key)
|
||||
{
|
||||
int index;
|
||||
|
||||
@@ -336,7 +358,8 @@ KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key)
|
||||
}
|
||||
|
||||
/* return the number of nodes in this list */
|
||||
int Keylist_Count(OS_Keylist list)
|
||||
int Keylist_Count(
|
||||
OS_Keylist list)
|
||||
{
|
||||
return list->count;
|
||||
}
|
||||
@@ -346,7 +369,8 @@ int Keylist_Count(OS_Keylist list)
|
||||
/*/////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/* returns head of the list or NULL on failure. */
|
||||
OS_Keylist Keylist_Create(void)
|
||||
OS_Keylist Keylist_Create(
|
||||
void)
|
||||
{
|
||||
struct Keylist *list;
|
||||
|
||||
@@ -358,8 +382,9 @@ OS_Keylist Keylist_Create(void)
|
||||
}
|
||||
|
||||
/* delete specified list */
|
||||
void Keylist_Delete(OS_Keylist list) /* list number to be deleted */
|
||||
{
|
||||
void Keylist_Delete(
|
||||
OS_Keylist list)
|
||||
{ /* list number to be deleted */
|
||||
if (list) {
|
||||
/* clean out the list */
|
||||
while (list->count) {
|
||||
@@ -380,7 +405,8 @@ void Keylist_Delete(OS_Keylist list) /* list number to be deleted */
|
||||
#include "ctest.h"
|
||||
|
||||
/* test the encode and decode macros */
|
||||
void testKeySample(Test * pTest)
|
||||
void testKeySample(
|
||||
Test * pTest)
|
||||
{
|
||||
int type, id;
|
||||
int type_list[] =
|
||||
@@ -412,7 +438,8 @@ void testKeySample(Test * pTest)
|
||||
}
|
||||
|
||||
/* test the FIFO */
|
||||
void testKeyListFIFO(Test * pTest)
|
||||
void testKeyListFIFO(
|
||||
Test * pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
@@ -455,7 +482,8 @@ void testKeyListFIFO(Test * pTest)
|
||||
}
|
||||
|
||||
/* test the FILO */
|
||||
void testKeyListFILO(Test * pTest)
|
||||
void testKeyListFILO(
|
||||
Test * pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
@@ -501,7 +529,8 @@ void testKeyListFILO(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testKeyListDataKey(Test * pTest)
|
||||
void testKeyListDataKey(
|
||||
Test * pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
@@ -581,7 +610,8 @@ void testKeyListDataKey(Test * pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
void testKeyListDataIndex(Test * pTest)
|
||||
void testKeyListDataIndex(
|
||||
Test * pTest)
|
||||
{
|
||||
OS_Keylist list;
|
||||
KEY key;
|
||||
@@ -652,7 +682,8 @@ void testKeyListDataIndex(Test * pTest)
|
||||
}
|
||||
|
||||
/* test access of a lot of entries */
|
||||
void testKeyListLarge(Test * pTest)
|
||||
void testKeyListLarge(
|
||||
Test * pTest)
|
||||
{
|
||||
int data1 = 42;
|
||||
int *data;
|
||||
@@ -683,7 +714,8 @@ void testKeyListLarge(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_KEYLIST
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -712,5 +744,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_KEYLIST */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_KEYLIST */
|
||||
#endif /* TEST */
|
||||
|
||||
+1027
-1229
File diff suppressed because it is too large
Load Diff
+11
-11
@@ -12,10 +12,10 @@ static INDTEXT_DATA mstp_receive_state_text[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *mstptext_receive_state(int index)
|
||||
const char *mstptext_receive_state(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(mstp_receive_state_text,
|
||||
index, "unknown");
|
||||
return indtext_by_index_default(mstp_receive_state_text, index, "unknown");
|
||||
}
|
||||
|
||||
static INDTEXT_DATA mstp_master_state_text[] = {
|
||||
@@ -31,10 +31,10 @@ static INDTEXT_DATA mstp_master_state_text[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *mstptext_master_state(int index)
|
||||
const char *mstptext_master_state(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_default(mstp_master_state_text,
|
||||
index, "unknown");
|
||||
return indtext_by_index_default(mstp_master_state_text, index, "unknown");
|
||||
}
|
||||
|
||||
static INDTEXT_DATA mstp_frame_type_text[] = {
|
||||
@@ -44,15 +44,15 @@ static INDTEXT_DATA mstp_frame_type_text[] = {
|
||||
{FRAME_TYPE_TEST_REQUEST, "TEST_REQUEST"},
|
||||
{FRAME_TYPE_TEST_RESPONSE, "TEST_RESPONSE"},
|
||||
{FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY, "BACNET_DATA_EXPECTING_REPLY"},
|
||||
{FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY, "BACNET_DATA_NOT_EXPECTING_REPLY"},
|
||||
{FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
|
||||
"BACNET_DATA_NOT_EXPECTING_REPLY"},
|
||||
{FRAME_TYPE_REPLY_POSTPONED, "REPLY_POSTPONED"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
const char *mstptext_frame_type(int index)
|
||||
const char *mstptext_frame_type(
|
||||
int index)
|
||||
{
|
||||
return indtext_by_index_split_default(mstp_frame_type_text,
|
||||
index,
|
||||
FRAME_TYPE_PROPRIETARY_MIN,
|
||||
"UNKNOWN", "PROPRIETARY");
|
||||
index, FRAME_TYPE_PROPRIETARY_MIN, "UNKNOWN", "PROPRIETARY");
|
||||
}
|
||||
|
||||
+49
-38
@@ -41,7 +41,9 @@
|
||||
#include "npdu.h"
|
||||
#include "apdu.h"
|
||||
|
||||
void npdu_copy_data(BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src)
|
||||
void npdu_copy_data(
|
||||
BACNET_NPDU_DATA * dest,
|
||||
BACNET_NPDU_DATA * src)
|
||||
{
|
||||
if (dest && src) {
|
||||
dest->protocol_version = src->protocol_version;
|
||||
@@ -94,12 +96,14 @@ ABORT.request Yes No Yes No
|
||||
ABORT.indication Yes Yes Yes No
|
||||
*/
|
||||
|
||||
int npdu_encode_pdu(uint8_t * npdu,
|
||||
int npdu_encode_pdu(
|
||||
uint8_t * npdu,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_NPDU_DATA * npdu_data)
|
||||
{
|
||||
int len = 0; /* return value - number of octets loaded in this function */
|
||||
int i = 0; /* counter */
|
||||
int len = 0; /* return value - number of octets loaded in this function */
|
||||
int i = 0; /* counter */
|
||||
|
||||
|
||||
if (npdu && npdu_data) {
|
||||
@@ -221,26 +225,30 @@ described in 6.2.2.
|
||||
whether (TRUE) or not (FALSE) a reply service primitive
|
||||
is expected for the service being issued.
|
||||
*/
|
||||
void npdu_encode_npdu_data(BACNET_NPDU_DATA * npdu_data,
|
||||
bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority)
|
||||
void npdu_encode_npdu_data(
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
bool data_expecting_reply,
|
||||
BACNET_MESSAGE_PRIORITY priority)
|
||||
{
|
||||
if (npdu_data) {
|
||||
npdu_data->data_expecting_reply = data_expecting_reply;
|
||||
npdu_data->protocol_version = BACNET_PROTOCOL_VERSION;
|
||||
npdu_data->network_layer_message = false; /* false if APDU */
|
||||
npdu_data->network_message_type = NETWORK_MESSAGE_INVALID; /* optional */
|
||||
npdu_data->network_message_type = NETWORK_MESSAGE_INVALID; /* optional */
|
||||
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
|
||||
npdu_data->priority = priority;
|
||||
npdu_data->hop_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int npdu_decode(uint8_t * npdu,
|
||||
int npdu_decode(
|
||||
uint8_t * npdu,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_NPDU_DATA * npdu_data)
|
||||
{
|
||||
int len = 0; /* return value - number of octets loaded in this function */
|
||||
int i = 0; /* counter */
|
||||
int len = 0; /* return value - number of octets loaded in this function */
|
||||
int i = 0; /* counter */
|
||||
uint16_t src_net = 0;
|
||||
uint16_t dest_net = 0;
|
||||
uint8_t address_len = 0;
|
||||
@@ -271,7 +279,7 @@ int npdu_decode(uint8_t * npdu,
|
||||
/* B'10' = Critical Equipment message */
|
||||
/* B'01' = Urgent message */
|
||||
/* B'00' = Normal message */
|
||||
npdu_data->priority = (BACNET_MESSAGE_PRIORITY)(npdu[1] & 0x03);
|
||||
npdu_data->priority = (BACNET_MESSAGE_PRIORITY) (npdu[1] & 0x03);
|
||||
/* set the offset to where the optional stuff starts */
|
||||
len = 2;
|
||||
/*Bit 5: Destination specifier where: */
|
||||
@@ -342,14 +350,14 @@ int npdu_decode(uint8_t * npdu,
|
||||
/* Indicates that the NSDU conveys a network layer message. */
|
||||
/* Message Type field is present. */
|
||||
if (npdu_data->network_layer_message) {
|
||||
npdu_data->network_message_type = (BACNET_NETWORK_MESSAGE_TYPE)npdu[len++];
|
||||
npdu_data->network_message_type =
|
||||
(BACNET_NETWORK_MESSAGE_TYPE) npdu[len++];
|
||||
/* Message Type field contains a value in the range 0x80 - 0xFF, */
|
||||
/* then a Vendor ID field shall be present */
|
||||
if (npdu_data->network_message_type >= 0x80)
|
||||
len +=
|
||||
decode_unsigned16(&npdu[len], &npdu_data->vendor_id);
|
||||
len += decode_unsigned16(&npdu[len], &npdu_data->vendor_id);
|
||||
} else {
|
||||
/* FIXME: another value for this? */
|
||||
/* FIXME: another value for this? */
|
||||
npdu_data->network_message_type = NETWORK_MESSAGE_INVALID;
|
||||
}
|
||||
}
|
||||
@@ -357,10 +365,11 @@ int npdu_decode(uint8_t * npdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void npdu_handler(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
void npdu_handler(
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t pdu_len)
|
||||
{ /* length PDU */
|
||||
{ /* length PDU */
|
||||
int apdu_offset = 0;
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
@@ -384,7 +393,8 @@ void npdu_handler(BACNET_ADDRESS * src, /* source address */
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testNPDU2(Test * pTest)
|
||||
void testNPDU2(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t pdu[480] = { 0 };
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
@@ -395,7 +405,7 @@ void testNPDU2(Test * pTest)
|
||||
bool data_expecting_reply = true;
|
||||
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
int i = 0; /* counter */
|
||||
int i = 0; /* counter */
|
||||
int npdu_len = 0;
|
||||
bool network_layer_message = false; /* false if APDU */
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
|
||||
@@ -428,11 +438,9 @@ void testNPDU2(Test * pTest)
|
||||
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
|
||||
ct_test(pTest, npdu_len != 0);
|
||||
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
|
||||
ct_test(pTest,
|
||||
npdu_data.network_layer_message == network_layer_message);
|
||||
ct_test(pTest, npdu_data.network_layer_message == network_layer_message);
|
||||
if (npdu_data.network_layer_message) {
|
||||
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.priority == priority);
|
||||
@@ -450,7 +458,8 @@ void testNPDU2(Test * pTest)
|
||||
}
|
||||
}
|
||||
|
||||
void testNPDU1(Test * pTest)
|
||||
void testNPDU1(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t pdu[480] = { 0 };
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
@@ -461,7 +470,7 @@ void testNPDU1(Test * pTest)
|
||||
bool data_expecting_reply = false;
|
||||
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
int i = 0; /* counter */
|
||||
int i = 0; /* counter */
|
||||
int npdu_len = 0;
|
||||
bool network_layer_message = false; /* false if APDU */
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
|
||||
@@ -495,11 +504,9 @@ void testNPDU1(Test * pTest)
|
||||
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
|
||||
ct_test(pTest, npdu_len != 0);
|
||||
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
|
||||
ct_test(pTest,
|
||||
npdu_data.network_layer_message == network_layer_message);
|
||||
ct_test(pTest, npdu_data.network_layer_message == network_layer_message);
|
||||
if (npdu_data.network_layer_message) {
|
||||
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.priority == priority);
|
||||
@@ -509,20 +516,24 @@ void testNPDU1(Test * pTest)
|
||||
|
||||
#ifdef TEST_NPDU
|
||||
/* dummy stub for testing */
|
||||
void tsm_free_invoke_id(uint8_t invokeID)
|
||||
void tsm_free_invoke_id(
|
||||
uint8_t invokeID)
|
||||
{
|
||||
(void) invokeID;
|
||||
}
|
||||
|
||||
void iam_handler(uint8_t * service_request,
|
||||
uint16_t service_len, BACNET_ADDRESS * src)
|
||||
void iam_handler(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
(void) service_request;
|
||||
(void) service_len;
|
||||
(void) src;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -541,5 +552,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_NPDU */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_NPDU */
|
||||
#endif /* TEST */
|
||||
|
||||
+22
-15
@@ -38,12 +38,14 @@
|
||||
#include "rd.h"
|
||||
|
||||
/* encode service */
|
||||
int rd_encode_apdu(uint8_t * apdu,
|
||||
int rd_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_REINITIALIZED_STATE state, BACNET_CHARACTER_STRING * password)
|
||||
BACNET_REINITIALIZED_STATE state,
|
||||
BACNET_CHARACTER_STRING * password)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -66,9 +68,11 @@ int rd_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int rd_decode_service_request(uint8_t * apdu,
|
||||
int rd_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_REINITIALIZED_STATE * state, BACNET_CHARACTER_STRING * password)
|
||||
BACNET_REINITIALIZED_STATE * state,
|
||||
BACNET_CHARACTER_STRING * password)
|
||||
{
|
||||
unsigned len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -84,7 +88,7 @@ int rd_decode_service_request(uint8_t * apdu,
|
||||
&tag_number, &len_value_type);
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &value);
|
||||
if (state)
|
||||
*state = (BACNET_REINITIALIZED_STATE)value;
|
||||
*state = (BACNET_REINITIALIZED_STATE) value;
|
||||
/* Tag 1: password - optional */
|
||||
if (len < apdu_len) {
|
||||
if (!decode_is_context_tag(&apdu[len], 1))
|
||||
@@ -92,8 +96,7 @@ int rd_decode_service_request(uint8_t * apdu,
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
len +=
|
||||
decode_character_string(&apdu[len], len_value_type,
|
||||
password);
|
||||
decode_character_string(&apdu[len], len_value_type, password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +108,12 @@ int rd_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int rd_decode_apdu(uint8_t * apdu,
|
||||
int rd_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_REINITIALIZED_STATE * state, BACNET_CHARACTER_STRING * password)
|
||||
BACNET_REINITIALIZED_STATE * state,
|
||||
BACNET_CHARACTER_STRING * password)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -132,7 +137,8 @@ int rd_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void test_ReinitializeDevice(Test * pTest)
|
||||
void test_ReinitializeDevice(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -161,7 +167,8 @@ void test_ReinitializeDevice(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_REINITIALIZE_DEVICE
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -178,5 +185,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_REINITIALIZE_DEVICE */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_REINITIALIZE_DEVICE */
|
||||
#endif /* TEST */
|
||||
|
||||
+21
-11
@@ -37,10 +37,12 @@
|
||||
#include "bacdef.h"
|
||||
|
||||
/* encode service */
|
||||
int reject_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, uint8_t reject_reason)
|
||||
int reject_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
uint8_t reject_reason)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_REJECT;
|
||||
@@ -53,8 +55,11 @@ int reject_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int reject_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason)
|
||||
int reject_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint8_t * reject_reason)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -74,8 +79,11 @@ int reject_decode_service_request(uint8_t * apdu,
|
||||
#include "ctest.h"
|
||||
|
||||
/* decode the whole APDU - mainly used for unit testing */
|
||||
int reject_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * reject_reason)
|
||||
int reject_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint8_t * reject_reason)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -94,7 +102,8 @@ int reject_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testReject(Test * pTest)
|
||||
void testReject(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -147,7 +156,8 @@ void testReject(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_REJECT
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -164,5 +174,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_REJECT */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_REJECT */
|
||||
#endif /* TEST */
|
||||
|
||||
+23
-20
@@ -46,7 +46,8 @@
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool Ringbuf_Empty(RING_BUFFER const *b)
|
||||
bool Ringbuf_Empty(
|
||||
RING_BUFFER const *b)
|
||||
{
|
||||
return (b->count == 0);
|
||||
}
|
||||
@@ -57,7 +58,8 @@ bool Ringbuf_Empty(RING_BUFFER const *b)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
char *Ringbuf_Get_Front(RING_BUFFER const *b)
|
||||
char *Ringbuf_Get_Front(
|
||||
RING_BUFFER const *b)
|
||||
{
|
||||
return (b->count ? &(b->data[b->head * b->element_size]) : NULL);
|
||||
}
|
||||
@@ -68,9 +70,10 @@ char *Ringbuf_Get_Front(RING_BUFFER const *b)
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
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) {
|
||||
data = &(b->data[b->head * b->element_size]);
|
||||
@@ -89,13 +92,14 @@ char *Ringbuf_Pop_Front(RING_BUFFER * b)
|
||||
* ALGORITHM: 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 */
|
||||
{ /* one element to add to the ring */
|
||||
bool status = false; /* return value */
|
||||
unsigned offset = 0; /* offset into array of data */
|
||||
char *ring_data = NULL; /* used to help point ring data */
|
||||
unsigned i; /* loop counter */
|
||||
unsigned i; /* loop counter */
|
||||
|
||||
if (b && data_element) {
|
||||
/* limit the amount of data that we accept */
|
||||
@@ -121,11 +125,12 @@ bool Ringbuf_Put(RING_BUFFER * b, /* ring buffer structure */
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */
|
||||
char *data, /* data block or array of data */
|
||||
void Ringbuf_Init(
|
||||
RING_BUFFER * b, /* ring buffer structure */
|
||||
char *data, /* data block or array of data */
|
||||
unsigned element_size, /* size of one element in the data block */
|
||||
unsigned element_count)
|
||||
{ /* number of elements in the data block */
|
||||
{ /* number of elements in the data block */
|
||||
b->head = 0;
|
||||
b->count = 0;
|
||||
b->data = data;
|
||||
@@ -144,7 +149,8 @@ void Ringbuf_Init(RING_BUFFER * b, /* ring buffer structure */
|
||||
/* test the FIFO */
|
||||
#define RING_BUFFER_DATA_SIZE 5
|
||||
#define RING_BUFFER_COUNT 16
|
||||
void testRingBuf(Test * pTest)
|
||||
void testRingBuf(
|
||||
Test * pTest)
|
||||
{
|
||||
RING_BUFFER test_buffer;
|
||||
char data_store[RING_BUFFER_DATA_SIZE * RING_BUFFER_COUNT];
|
||||
@@ -181,8 +187,7 @@ void testRingBuf(Test * pTest)
|
||||
|
||||
/* fill to max */
|
||||
for (index = 0; index < RING_BUFFER_COUNT; index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
|
||||
data_index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) {
|
||||
data[data_index] = index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data);
|
||||
@@ -191,8 +196,7 @@ void testRingBuf(Test * pTest)
|
||||
}
|
||||
/* verify actions on full buffer */
|
||||
for (index = 0; index < RING_BUFFER_COUNT; index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
|
||||
data_index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) {
|
||||
data[data_index] = index;
|
||||
}
|
||||
status = Ringbuf_Put(&test_buffer, data);
|
||||
@@ -203,14 +207,12 @@ void testRingBuf(Test * pTest)
|
||||
/* check buffer full */
|
||||
for (index = 0; index < RING_BUFFER_COUNT; index++) {
|
||||
test_data = Ringbuf_Get_Front(&test_buffer);
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
|
||||
data_index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == index);
|
||||
}
|
||||
|
||||
test_data = Ringbuf_Pop_Front(&test_buffer);
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE;
|
||||
data_index++) {
|
||||
for (data_index = 0; data_index < RING_BUFFER_DATA_SIZE; data_index++) {
|
||||
ct_test(pTest, test_data[data_index] == index);
|
||||
}
|
||||
}
|
||||
@@ -250,7 +252,8 @@ void testRingBuf(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_RINGBUF
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
+44
-28
@@ -38,11 +38,13 @@
|
||||
#include "rp.h"
|
||||
|
||||
/* encode service */
|
||||
int rp_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
int rp_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -68,14 +70,16 @@ int rp_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int rp_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
int rp_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
unsigned len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
uint32_t array_value = 0; /* for decoding */
|
||||
|
||||
/* check for value pointers */
|
||||
@@ -84,14 +88,14 @@ int rp_decode_service_request(uint8_t * apdu,
|
||||
if (!decode_is_context_tag(&apdu[len++], 0))
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len], &type, &rpdata->object_instance);
|
||||
rpdata->object_type = (BACNET_OBJECT_TYPE)type;
|
||||
rpdata->object_type = (BACNET_OBJECT_TYPE) type;
|
||||
/* Tag 1: Property ID */
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
rpdata->object_property = (BACNET_PROPERTY_ID)property;
|
||||
rpdata->object_property = (BACNET_PROPERTY_ID) property;
|
||||
/* Tag 2: Optional Array Index */
|
||||
if (len < apdu_len) {
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
@@ -109,11 +113,13 @@ int rp_decode_service_request(uint8_t * apdu,
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int rp_ack_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
int rp_ack_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
|
||||
@@ -141,13 +147,15 @@ int rp_ack_encode_apdu(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
int rp_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int tag_len = 0; /* length of tag decode */
|
||||
int len = 0; /* total length of decodes */
|
||||
int tag_len = 0; /* length of tag decode */
|
||||
int len = 0; /* total length of decodes */
|
||||
int object = 0, property = 0; /* for decoding */
|
||||
uint32_t array_value = 0; /* for decoding */
|
||||
|
||||
@@ -157,14 +165,14 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length
|
||||
return -1;
|
||||
len = 1;
|
||||
len += decode_object_id(&apdu[len], &object, &rpdata->object_instance);
|
||||
rpdata->object_type = (BACNET_OBJECT_TYPE)object;
|
||||
rpdata->object_type = (BACNET_OBJECT_TYPE) object;
|
||||
/* Tag 1: Property ID */
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
rpdata->object_property = (BACNET_PROPERTY_ID)property;
|
||||
rpdata->object_property = (BACNET_PROPERTY_ID) property;
|
||||
/* Tag 2: Optional Array Index */
|
||||
tag_len = decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
@@ -192,9 +200,11 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int rp_decode_apdu(uint8_t * apdu,
|
||||
int rp_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -218,8 +228,11 @@ int rp_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
int rp_ack_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id,
|
||||
BACNET_READ_PROPERTY_DATA * rpdata)
|
||||
{
|
||||
int len = 0;
|
||||
int offset = 0;
|
||||
@@ -241,7 +254,8 @@ int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the a
|
||||
return len;
|
||||
}
|
||||
|
||||
void testReadPropertyAck(Test * pTest)
|
||||
void testReadPropertyAck(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
uint8_t apdu2[480] = { 0 };
|
||||
@@ -289,7 +303,8 @@ void testReadPropertyAck(Test * pTest)
|
||||
ct_test(pTest, object_instance == rpdata.object_instance);
|
||||
}
|
||||
|
||||
void testReadProperty(Test * pTest)
|
||||
void testReadProperty(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -318,7 +333,8 @@ void testReadProperty(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_READ_PROPERTY
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -337,5 +353,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_READ_PROPERTY */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_READ_PROPERTY */
|
||||
#endif /* TEST */
|
||||
|
||||
+97
-58
@@ -40,9 +40,11 @@
|
||||
#include "rpm.h"
|
||||
|
||||
/* encode the initial portion of the service */
|
||||
int rpm_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
|
||||
int rpm_encode_apdu_init(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -55,10 +57,12 @@ int rpm_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_encode_apdu_object_begin(uint8_t * apdu,
|
||||
BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||
int rpm_encode_apdu_object_begin(
|
||||
uint8_t * apdu,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu_len = encode_context_object_id(&apdu[0], 0,
|
||||
@@ -70,10 +74,12 @@ int rpm_encode_apdu_object_begin(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_encode_apdu_object_property(uint8_t * apdu,
|
||||
BACNET_PROPERTY_ID object_property, int32_t array_index)
|
||||
int rpm_encode_apdu_object_property(
|
||||
uint8_t * apdu,
|
||||
BACNET_PROPERTY_ID object_property,
|
||||
int32_t array_index)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu_len = encode_context_enumerated(&apdu[0], 0, object_property);
|
||||
@@ -86,9 +92,10 @@ int rpm_encode_apdu_object_property(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_encode_apdu_object_end(uint8_t * apdu)
|
||||
int rpm_encode_apdu_object_end(
|
||||
uint8_t * apdu)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu_len = encode_closing_tag(&apdu[0], 1);
|
||||
@@ -98,12 +105,14 @@ int rpm_encode_apdu_object_end(uint8_t * apdu)
|
||||
}
|
||||
|
||||
/* decode the object portion of the service request only */
|
||||
int rpm_decode_object_id(uint8_t * apdu,
|
||||
int rpm_decode_object_id(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_OBJECT_TYPE * object_type, uint32_t * object_instance)
|
||||
BACNET_OBJECT_TYPE * object_type,
|
||||
uint32_t * object_instance)
|
||||
{
|
||||
unsigned len = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu && apdu_len && object_type && object_instance) {
|
||||
@@ -112,19 +121,21 @@ int rpm_decode_object_id(uint8_t * apdu,
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len], &type, object_instance);
|
||||
if (object_type)
|
||||
*object_type = (BACNET_OBJECT_TYPE)type;
|
||||
*object_type = (BACNET_OBJECT_TYPE) type;
|
||||
/* Tag 1: sequence of ReadAccessSpecification */
|
||||
if (!decode_is_opening_tag_number(&apdu[len], 1))
|
||||
return -1;
|
||||
len++; /* opening tag is only one octet */
|
||||
len++; /* opening tag is only one octet */
|
||||
}
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int rpm_decode_object_end(uint8_t * apdu, unsigned apdu_len)
|
||||
int rpm_decode_object_end(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len)
|
||||
{
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && apdu_len) {
|
||||
if (decode_is_closing_tag_number(apdu, 1))
|
||||
@@ -142,15 +153,17 @@ int rpm_decode_object_end(uint8_t * apdu, unsigned apdu_len)
|
||||
-- if omitted with an array the entire array is referenced
|
||||
}
|
||||
*/
|
||||
int rpm_decode_object_property(uint8_t * apdu,
|
||||
int rpm_decode_object_property(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_PROPERTY_ID * object_property, int32_t * array_index)
|
||||
BACNET_PROPERTY_ID * object_property,
|
||||
int32_t * array_index)
|
||||
{
|
||||
unsigned len = 0;
|
||||
unsigned option_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int property = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
uint32_t array_value = 0; /* for decoding */
|
||||
|
||||
/* check for valid pointers */
|
||||
@@ -164,7 +177,7 @@ int rpm_decode_object_property(uint8_t * apdu,
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
if (object_property)
|
||||
*object_property = (BACNET_PROPERTY_ID)property;
|
||||
*object_property = (BACNET_PROPERTY_ID) property;
|
||||
/* Tag 1: Optional propertyArrayIndex */
|
||||
if ((len < apdu_len) &&
|
||||
decode_is_context_specific(&apdu[len]) &&
|
||||
@@ -186,9 +199,11 @@ int rpm_decode_object_property(uint8_t * apdu,
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
|
||||
int rpm_ack_encode_apdu_init(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
|
||||
@@ -200,10 +215,12 @@ int rpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_object_begin(uint8_t * apdu,
|
||||
BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||
int rpm_ack_encode_apdu_object_begin(
|
||||
uint8_t * apdu,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
/* Tag 0: objectIdentifier */
|
||||
@@ -216,10 +233,12 @@ int rpm_ack_encode_apdu_object_begin(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_object_property(uint8_t * apdu,
|
||||
BACNET_PROPERTY_ID object_property, int32_t array_index)
|
||||
int rpm_ack_encode_apdu_object_property(
|
||||
uint8_t * apdu,
|
||||
BACNET_PROPERTY_ID object_property,
|
||||
int32_t array_index)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
/* Tag 2: propertyIdentifier */
|
||||
@@ -233,10 +252,12 @@ int rpm_ack_encode_apdu_object_property(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_object_property_value(uint8_t * apdu,
|
||||
uint8_t * application_data, unsigned application_data_len)
|
||||
int rpm_ack_encode_apdu_object_property_value(
|
||||
uint8_t * apdu,
|
||||
uint8_t * application_data,
|
||||
unsigned application_data_len)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
unsigned len = 0;
|
||||
|
||||
if (apdu) {
|
||||
@@ -251,15 +272,18 @@ int rpm_ack_encode_apdu_object_property_value(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_object_property_error(uint8_t * apdu,
|
||||
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||
int rpm_ack_encode_apdu_object_property_error(
|
||||
uint8_t * apdu,
|
||||
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) {
|
||||
/* Tag 5: propertyAccessError */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 5);
|
||||
apdu_len += encode_application_enumerated(&apdu[apdu_len], error_class);
|
||||
apdu_len +=
|
||||
encode_application_enumerated(&apdu[apdu_len], error_class);
|
||||
apdu_len += encode_application_enumerated(&apdu[apdu_len], error_code);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 5);
|
||||
}
|
||||
@@ -267,9 +291,10 @@ int rpm_ack_encode_apdu_object_property_error(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_ack_encode_apdu_object_end(uint8_t * apdu)
|
||||
int rpm_ack_encode_apdu_object_end(
|
||||
uint8_t * apdu)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu_len = encode_closing_tag(&apdu[0], 1);
|
||||
@@ -279,12 +304,14 @@ int rpm_ack_encode_apdu_object_end(uint8_t * apdu)
|
||||
}
|
||||
|
||||
/* decode the object portion of the service request only */
|
||||
int rpm_ack_decode_object_id(uint8_t * apdu,
|
||||
int rpm_ack_decode_object_id(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_OBJECT_TYPE * object_type, uint32_t * object_instance)
|
||||
BACNET_OBJECT_TYPE * object_type,
|
||||
uint32_t * object_instance)
|
||||
{
|
||||
unsigned len = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu && apdu_len && object_type && object_instance) {
|
||||
@@ -293,20 +320,22 @@ int rpm_ack_decode_object_id(uint8_t * apdu,
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len], &type, object_instance);
|
||||
if (object_type)
|
||||
*object_type = (BACNET_OBJECT_TYPE)type;
|
||||
*object_type = (BACNET_OBJECT_TYPE) type;
|
||||
/* Tag 1: listOfResults */
|
||||
if (!decode_is_opening_tag_number(&apdu[len], 1))
|
||||
return -1;
|
||||
len++; /* opening tag is only one octet */
|
||||
len++; /* opening tag is only one octet */
|
||||
}
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
/* is this the end of the list of this objects properties values? */
|
||||
int rpm_ack_decode_object_end(uint8_t * apdu, unsigned apdu_len)
|
||||
int rpm_ack_decode_object_end(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len)
|
||||
{
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && apdu_len) {
|
||||
if (decode_is_closing_tag_number(apdu, 1))
|
||||
@@ -316,15 +345,17 @@ int rpm_ack_decode_object_end(uint8_t * apdu, unsigned apdu_len)
|
||||
return len;
|
||||
}
|
||||
|
||||
int rpm_ack_decode_object_property(uint8_t * apdu,
|
||||
int rpm_ack_decode_object_property(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_PROPERTY_ID * object_property, int32_t * array_index)
|
||||
BACNET_PROPERTY_ID * object_property,
|
||||
int32_t * array_index)
|
||||
{
|
||||
unsigned len = 0;
|
||||
unsigned tag_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int property = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
uint32_t array_value = 0; /* for decoding */
|
||||
|
||||
/* check for valid pointers */
|
||||
@@ -338,7 +369,7 @@ int rpm_ack_decode_object_property(uint8_t * apdu,
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
if (object_property)
|
||||
*object_property = (BACNET_PROPERTY_ID)property;
|
||||
*object_property = (BACNET_PROPERTY_ID) property;
|
||||
/* Tag 3: Optional propertyArrayIndex */
|
||||
if ((len < apdu_len) &&
|
||||
decode_is_context_specific(&apdu[len]) &&
|
||||
@@ -366,9 +397,12 @@ int rpm_ack_decode_object_property(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int rpm_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
int rpm_ack_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id,
|
||||
uint8_t ** service_request, unsigned *service_request_len)
|
||||
uint8_t ** service_request,
|
||||
unsigned *service_request_len)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
@@ -391,10 +425,12 @@ int rpm_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the a
|
||||
return offset;
|
||||
}
|
||||
|
||||
int rpm_decode_apdu(uint8_t * apdu,
|
||||
int rpm_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
uint8_t ** service_request, unsigned *service_request_len)
|
||||
uint8_t ** service_request,
|
||||
unsigned *service_request_len)
|
||||
{
|
||||
unsigned offset = 0;
|
||||
|
||||
@@ -419,7 +455,8 @@ int rpm_decode_apdu(uint8_t * apdu,
|
||||
return offset;
|
||||
}
|
||||
|
||||
void testReadPropertyMultiple(Test * pTest)
|
||||
void testReadPropertyMultiple(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -527,7 +564,8 @@ void testReadPropertyMultiple(Test * pTest)
|
||||
ct_test(pTest, len == service_request_len);
|
||||
}
|
||||
|
||||
void testReadPropertyMultipleAck(Test * pTest)
|
||||
void testReadPropertyMultipleAck(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -740,7 +778,8 @@ void testReadPropertyMultipleAck(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_READ_PROPERTY_MULTIPLE
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -759,6 +798,6 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_READ_PROPERTY_MULTIPLE */
|
||||
#endif /* TEST_READ_PROPERTY_MULTIPLE */
|
||||
|
||||
#endif /* TEST */
|
||||
#endif /* TEST */
|
||||
|
||||
+30
-20
@@ -40,10 +40,11 @@
|
||||
#include <stddef.h>
|
||||
#include "sbuf.h"
|
||||
|
||||
void sbuf_init(STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* actual size, in bytes, of the data block or array of data */
|
||||
void sbuf_init(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* actual size, in bytes, of the data block or array of data */
|
||||
unsigned size)
|
||||
{ /* number of bytes used */
|
||||
{ /* number of bytes used */
|
||||
if (b) {
|
||||
b->data = data;
|
||||
b->size = size;
|
||||
@@ -54,32 +55,37 @@ void sbuf_init(STATIC_BUFFER * b, /* static buffer structure */
|
||||
}
|
||||
|
||||
/* returns true if count==0, false if count > 0 */
|
||||
bool sbuf_empty(STATIC_BUFFER const *b)
|
||||
bool sbuf_empty(
|
||||
STATIC_BUFFER const *b)
|
||||
{
|
||||
return (b ? (b->count == 0) : false);
|
||||
}
|
||||
|
||||
char *sbuf_data(STATIC_BUFFER const *b)
|
||||
char *sbuf_data(
|
||||
STATIC_BUFFER const *b)
|
||||
{
|
||||
return (b ? b->data : NULL);
|
||||
}
|
||||
|
||||
unsigned sbuf_size(STATIC_BUFFER * b)
|
||||
unsigned sbuf_size(
|
||||
STATIC_BUFFER * b)
|
||||
{
|
||||
return (b ? b->size : 0);
|
||||
}
|
||||
|
||||
unsigned sbuf_count(STATIC_BUFFER * b)
|
||||
unsigned sbuf_count(
|
||||
STATIC_BUFFER * b)
|
||||
{
|
||||
return (b ? b->count : 0);
|
||||
}
|
||||
|
||||
/* returns true if successful, false if not enough room to append data */
|
||||
bool sbuf_put(STATIC_BUFFER * b, /* static buffer structure */
|
||||
unsigned offset, /* where to start */
|
||||
char *data, /* number of bytes used */
|
||||
bool sbuf_put(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
unsigned offset, /* where to start */
|
||||
char *data, /* number of bytes used */
|
||||
unsigned data_size)
|
||||
{ /* how many to add */
|
||||
{ /* how many to add */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (b && b->data) {
|
||||
@@ -99,10 +105,11 @@ bool sbuf_put(STATIC_BUFFER * b, /* static buffer structure */
|
||||
}
|
||||
|
||||
/* returns true if successful, false if not enough room to append data */
|
||||
bool sbuf_append(STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* number of bytes used */
|
||||
bool sbuf_append(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* number of bytes used */
|
||||
unsigned data_size)
|
||||
{ /* how many to add */
|
||||
{ /* how many to add */
|
||||
unsigned count = 0;
|
||||
|
||||
if (b)
|
||||
@@ -112,9 +119,10 @@ bool sbuf_append(STATIC_BUFFER * b, /* static buffer structure */
|
||||
}
|
||||
|
||||
/* returns true if successful, false if not enough room to append data */
|
||||
bool sbuf_truncate(STATIC_BUFFER * b, /* static buffer structure */
|
||||
bool sbuf_truncate(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
unsigned count)
|
||||
{ /* total number of bytes in use */
|
||||
{ /* total number of bytes in use */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (b) {
|
||||
@@ -133,7 +141,8 @@ bool sbuf_truncate(STATIC_BUFFER * b, /* static buffer structure */
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
void testStaticBuffer(Test * pTest)
|
||||
void testStaticBuffer(
|
||||
Test * pTest)
|
||||
{
|
||||
STATIC_BUFFER sbuffer;
|
||||
char *data1 = "Joshua";
|
||||
@@ -186,7 +195,8 @@ void testStaticBuffer(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_STATIC_BUFFER
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -205,5 +215,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_STATIC_BUFFER */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_STATIC_BUFFER */
|
||||
#endif /* TEST */
|
||||
|
||||
+52
-35
@@ -39,12 +39,14 @@
|
||||
#include "timesync.h"
|
||||
|
||||
/* encode service */
|
||||
int timesync_encode_apdu_service(uint8_t * apdu,
|
||||
int timesync_encode_apdu_service(
|
||||
uint8_t * apdu,
|
||||
BACNET_UNCONFIRMED_SERVICE service,
|
||||
BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && my_date && my_time) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -59,23 +61,30 @@ int timesync_encode_apdu_service(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int timesync_utc_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
int timesync_utc_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
return timesync_encode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, my_date, my_time);
|
||||
}
|
||||
|
||||
int timesync_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
int timesync_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
return timesync_encode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, my_date, my_time);
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int timesync_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
int timesync_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -84,16 +93,14 @@ int timesync_decode_service_request(uint8_t * apdu,
|
||||
if (apdu_len && my_date && my_time) {
|
||||
/* date */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number == BACNET_APPLICATION_TAG_DATE) {
|
||||
len += decode_date(&apdu[len], my_date);
|
||||
} else
|
||||
return -1;
|
||||
/* time */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number == BACNET_APPLICATION_TAG_TIME) {
|
||||
len += decode_bacnet_time(&apdu[len], my_time);
|
||||
} else
|
||||
@@ -108,9 +115,12 @@ int timesync_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int timesync_decode_apdu_service(uint8_t * apdu,
|
||||
int timesync_decode_apdu_service(
|
||||
uint8_t * apdu,
|
||||
BACNET_UNCONFIRMED_SERVICE service,
|
||||
unsigned apdu_len, BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -130,24 +140,31 @@ int timesync_decode_apdu_service(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int timesync_utc_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
int timesync_utc_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
return timesync_decode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
|
||||
apdu_len, my_date, my_time);
|
||||
}
|
||||
|
||||
int timesync_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
int timesync_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
return timesync_decode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
|
||||
apdu_len, my_date, my_time);
|
||||
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_len, my_date, my_time);
|
||||
}
|
||||
|
||||
void testTimeSyncData(Test * pTest,
|
||||
BACNET_DATE * my_date, BACNET_TIME * my_time)
|
||||
void testTimeSyncData(
|
||||
Test * pTest,
|
||||
BACNET_DATE * my_date,
|
||||
BACNET_TIME * my_time)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -166,23 +183,22 @@ void testTimeSyncData(Test * pTest,
|
||||
len = timesync_utc_encode_apdu(&apdu[0], my_date, my_time);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
len =
|
||||
timesync_utc_decode_apdu(&apdu[0], apdu_len, &test_date,
|
||||
&test_time);
|
||||
len = timesync_utc_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, datetime_compare_time(my_time, &test_time) == 0);
|
||||
ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0);
|
||||
}
|
||||
|
||||
void testTimeSync(Test * pTest)
|
||||
void testTimeSync(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_DATE bdate;
|
||||
BACNET_TIME btime;
|
||||
|
||||
bdate.year = 2006; /* AD */
|
||||
bdate.month = 4; /* 1=Jan */
|
||||
bdate.day = 11; /* 1..31 */
|
||||
bdate.wday = 1; /* 1=Monday */
|
||||
bdate.year = 2006; /* AD */
|
||||
bdate.month = 4; /* 1=Jan */
|
||||
bdate.day = 11; /* 1..31 */
|
||||
bdate.wday = 1; /* 1=Monday */
|
||||
|
||||
btime.hour = 7;
|
||||
btime.min = 0;
|
||||
@@ -193,7 +209,8 @@ void testTimeSync(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_TIMESYNC
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -210,5 +227,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
|
||||
+50
-29
@@ -62,9 +62,10 @@
|
||||
static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS];
|
||||
|
||||
/* 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 */
|
||||
|
||||
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
|
||||
@@ -77,9 +78,10 @@ static uint8_t tsm_find_invokeID_index(uint8_t invokeID)
|
||||
return index;
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
|
||||
@@ -92,10 +94,11 @@ static uint8_t tsm_find_first_free_index(void)
|
||||
return index;
|
||||
}
|
||||
|
||||
bool tsm_transaction_available(void)
|
||||
bool tsm_transaction_available(
|
||||
void)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
unsigned i = 0; /* counter */
|
||||
unsigned i = 0; /* counter */
|
||||
|
||||
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
|
||||
if (TSM_List[i].InvokeID == 0) {
|
||||
@@ -108,10 +111,11 @@ bool tsm_transaction_available(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t tsm_transaction_idle_count(void)
|
||||
uint8_t tsm_transaction_idle_count(
|
||||
void)
|
||||
{
|
||||
uint8_t count = 0; /* return value */
|
||||
unsigned i = 0; /* counter */
|
||||
uint8_t count = 0; /* return value */
|
||||
unsigned i = 0; /* counter */
|
||||
|
||||
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
|
||||
if ((TSM_List[i].InvokeID == 0) &&
|
||||
@@ -127,7 +131,8 @@ uint8_t tsm_transaction_idle_count(void)
|
||||
/* gets the next free invokeID,
|
||||
and reserves a spot in the table
|
||||
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... */
|
||||
uint8_t index = 0;
|
||||
@@ -154,7 +159,7 @@ uint8_t tsm_next_free_invokeID(void)
|
||||
current_invokeID = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
/* found! This invokeID is already used */
|
||||
/* try next one */
|
||||
current_invokeID++;
|
||||
@@ -169,9 +174,12 @@ uint8_t tsm_next_free_invokeID(void)
|
||||
return invokeID;
|
||||
}
|
||||
|
||||
void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
|
||||
BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
|
||||
uint8_t * apdu, uint16_t apdu_len)
|
||||
void tsm_set_confirmed_unsegmented_transaction(
|
||||
uint8_t invokeID,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * ndpu_data,
|
||||
uint8_t * apdu,
|
||||
uint16_t apdu_len)
|
||||
{
|
||||
uint16_t j = 0;
|
||||
uint8_t index;
|
||||
@@ -199,9 +207,12 @@ void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID,
|
||||
|
||||
/* used to retrieve the transaction payload */
|
||||
/* if we wanted to find out what we sent (i.e. when we get an ack) */
|
||||
bool tsm_get_transaction_pdu(uint8_t invokeID,
|
||||
BACNET_ADDRESS * dest, BACNET_NPDU_DATA * ndpu_data,
|
||||
uint8_t * apdu, uint16_t * apdu_len)
|
||||
bool tsm_get_transaction_pdu(
|
||||
uint8_t invokeID,
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * ndpu_data,
|
||||
uint8_t * apdu,
|
||||
uint16_t * apdu_len)
|
||||
{
|
||||
uint16_t j = 0;
|
||||
uint8_t index;
|
||||
@@ -228,9 +239,10 @@ bool tsm_get_transaction_pdu(uint8_t invokeID,
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) {
|
||||
@@ -259,7 +271,8 @@ void tsm_timer_milliseconds(uint16_t milliseconds)
|
||||
}
|
||||
|
||||
/* frees the invokeID and sets its state to IDLE */
|
||||
void tsm_free_invoke_id(uint8_t invokeID)
|
||||
void tsm_free_invoke_id(
|
||||
uint8_t invokeID)
|
||||
{
|
||||
uint8_t index;
|
||||
|
||||
@@ -271,7 +284,8 @@ void tsm_free_invoke_id(uint8_t invokeID)
|
||||
}
|
||||
|
||||
/* check if the invoke ID has been made free */
|
||||
bool tsm_invoke_id_free(uint8_t invokeID)
|
||||
bool tsm_invoke_id_free(
|
||||
uint8_t invokeID)
|
||||
{
|
||||
bool status = true;
|
||||
uint8_t index;
|
||||
@@ -284,7 +298,8 @@ bool tsm_invoke_id_free(uint8_t invokeID)
|
||||
}
|
||||
|
||||
/* see if the invoke ID has failed get a confirmation */
|
||||
bool tsm_invoke_id_failed(uint8_t invokeID)
|
||||
bool tsm_invoke_id_failed(
|
||||
uint8_t invokeID)
|
||||
{
|
||||
bool status = false;
|
||||
uint8_t index;
|
||||
@@ -310,8 +325,11 @@ bool tsm_invoke_id_failed(uint8_t invokeID)
|
||||
bool I_Am_Request = true;
|
||||
|
||||
/* dummy function stubs */
|
||||
int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data, uint8_t * pdu, unsigned pdu_len)
|
||||
int datalink_send_pdu(
|
||||
BACNET_ADDRESS * dest,
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
uint8_t * pdu,
|
||||
unsigned pdu_len)
|
||||
{
|
||||
(void) dest;
|
||||
(void) npdu_data;
|
||||
@@ -322,19 +340,22 @@ int datalink_send_pdu(BACNET_ADDRESS * dest,
|
||||
}
|
||||
|
||||
/* dummy function stubs */
|
||||
void datalink_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
void datalink_get_broadcast_address(
|
||||
BACNET_ADDRESS * dest)
|
||||
{
|
||||
(void) dest;
|
||||
}
|
||||
|
||||
void testTSM(Test * pTest)
|
||||
void testTSM(
|
||||
Test * pTest)
|
||||
{
|
||||
/* FIXME: add some unit testing... */
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_TSM
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -351,6 +372,6 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_TSM */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_TSM */
|
||||
#endif /* TEST */
|
||||
#endif /* MAX_TSM_TRANSACTIONS */
|
||||
|
||||
+23
-15
@@ -39,10 +39,12 @@
|
||||
|
||||
/* encode service - use -1 for limit for 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 len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu && data) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -53,9 +55,7 @@ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data)
|
||||
&& (data->low_limit <= BACNET_MAX_INSTANCE)
|
||||
&& (data->high_limit >= 0)
|
||||
&& (data->high_limit <= BACNET_MAX_INSTANCE)) {
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 0,
|
||||
data->low_limit);
|
||||
len = encode_context_unsigned(&apdu[apdu_len], 0, data->low_limit);
|
||||
apdu_len += len;
|
||||
len = encode_context_unsigned(&apdu[apdu_len],
|
||||
1, data->high_limit);
|
||||
@@ -78,8 +78,10 @@ int whohas_encode_apdu(uint8_t * apdu, BACNET_WHO_HAS_DATA * data)
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int whohas_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_WHO_HAS_DATA * data)
|
||||
int whohas_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_WHO_HAS_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -142,8 +144,10 @@ int whohas_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int whohas_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_WHO_HAS_DATA * data)
|
||||
int whohas_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_WHO_HAS_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -162,7 +166,9 @@ int whohas_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testWhoHasData(Test * pTest, BACNET_WHO_HAS_DATA * data)
|
||||
void testWhoHasData(
|
||||
Test * pTest,
|
||||
BACNET_WHO_HAS_DATA * data)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -192,7 +198,8 @@ void testWhoHasData(Test * pTest, BACNET_WHO_HAS_DATA * data)
|
||||
}
|
||||
}
|
||||
|
||||
void testWhoHas(Test * pTest)
|
||||
void testWhoHas(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_WHO_HAS_DATA data;
|
||||
|
||||
@@ -227,7 +234,8 @@ void testWhoHas(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_WHOHAS
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -244,5 +252,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
|
||||
+24
-16
@@ -37,11 +37,13 @@
|
||||
#include "bacdef.h"
|
||||
|
||||
/* encode I-Am service - use -1 for limit if you want unlimited */
|
||||
int whois_encode_apdu(uint8_t * apdu,
|
||||
int32_t low_limit, int32_t high_limit)
|
||||
int whois_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
int32_t low_limit,
|
||||
int32_t high_limit)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
@@ -61,8 +63,11 @@ int whois_encode_apdu(uint8_t * apdu,
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int whois_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, int32_t * pLow_limit, int32_t * pHigh_limit)
|
||||
int whois_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
int32_t * pLow_limit,
|
||||
int32_t * pHigh_limit)
|
||||
{
|
||||
int len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
@@ -72,8 +77,7 @@ int whois_decode_service_request(uint8_t * apdu,
|
||||
/* optional limits - must be used as a pair */
|
||||
if (apdu_len) {
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number != 0)
|
||||
return -1;
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
@@ -82,8 +86,7 @@ int whois_decode_service_request(uint8_t * apdu,
|
||||
*pLow_limit = decoded_value;
|
||||
}
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
@@ -101,8 +104,11 @@ int whois_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int whois_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len, int32_t * pLow_limit, int32_t * pHigh_limit)
|
||||
int whois_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
int32_t * pLow_limit,
|
||||
int32_t * pHigh_limit)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
@@ -122,7 +128,8 @@ int whois_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testWhoIs(Test * pTest)
|
||||
void testWhoIs(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int len = 0;
|
||||
@@ -161,7 +168,8 @@ void testWhoIs(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_WHOIS
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -178,5 +186,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WHOIS */
|
||||
#endif /* TEST */
|
||||
|
||||
+72
-62
@@ -39,11 +39,13 @@
|
||||
#include "wp.h"
|
||||
|
||||
/* encode service */
|
||||
int wp_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
int wp_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
@@ -87,17 +89,19 @@ int wp_encode_apdu(uint8_t * apdu,
|
||||
/* decode the service request only */
|
||||
/* FIXME: there could be various error messages returned
|
||||
using unique values less than zero */
|
||||
int wp_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
int wp_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
{
|
||||
int len = 0;
|
||||
int tag_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
int type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
int type = 0; /* for decoding */
|
||||
int property = 0; /* for decoding */
|
||||
uint32_t unsigned_value = 0;
|
||||
int i = 0; /* loop counter */
|
||||
int i = 0; /* loop counter */
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu_len && wpdata) {
|
||||
@@ -105,14 +109,14 @@ int wp_decode_service_request(uint8_t * apdu,
|
||||
if (!decode_is_context_tag(&apdu[len++], 0))
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len], &type, &wpdata->object_instance);
|
||||
wpdata->object_type = (BACNET_OBJECT_TYPE)type;
|
||||
wpdata->object_type = (BACNET_OBJECT_TYPE) type;
|
||||
/* Tag 1: Property ID */
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value_type);
|
||||
if (tag_number != 1)
|
||||
return -1;
|
||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||
wpdata->object_property = (BACNET_PROPERTY_ID)property;
|
||||
wpdata->object_property = (BACNET_PROPERTY_ID) property;
|
||||
/* Tag 2: Optional Array Index */
|
||||
/* note: decode without incrementing len so we can check for opening tag */
|
||||
tag_len = decode_tag_number_and_value(&apdu[len],
|
||||
@@ -129,7 +133,7 @@ int wp_decode_service_request(uint8_t * apdu,
|
||||
return -1;
|
||||
/* determine the length of the data blob */
|
||||
wpdata->application_data_len = bacapp_data_len(&apdu[len],
|
||||
apdu_len - len, (BACNET_PROPERTY_ID)property);
|
||||
apdu_len - len, (BACNET_PROPERTY_ID) property);
|
||||
/* a tag number of 3 is not extended so only one octet */
|
||||
len++;
|
||||
/* copy the data from the APDU */
|
||||
@@ -169,9 +173,11 @@ int wp_decode_service_request(uint8_t * apdu,
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int wp_decode_apdu(uint8_t * apdu,
|
||||
int wp_decode_apdu(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
uint8_t * invoke_id,
|
||||
BACNET_WRITE_PROPERTY_DATA * wpdata)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
@@ -195,7 +201,8 @@ int wp_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
void testWritePropertyTag(Test * pTest,
|
||||
void testWritePropertyTag(
|
||||
Test * pTest,
|
||||
BACNET_APPLICATION_DATA_VALUE * value)
|
||||
{
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
@@ -224,52 +231,53 @@ void testWritePropertyTag(Test * pTest,
|
||||
test_data.application_data_len, &test_value);
|
||||
ct_test(pTest, test_value.tag == value->tag);
|
||||
switch (test_value.tag) {
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
ct_test(pTest, test_value.type.Boolean == value->type.Boolean);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
ct_test(pTest, test_value.type.Unsigned_Int ==
|
||||
value->type.Unsigned_Int);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
ct_test(pTest, test_value.type.Signed_Int ==
|
||||
value->type.Signed_Int);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
ct_test(pTest, test_value.type.Real == value->type.Real);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||
ct_test(pTest, test_value.type.Enumerated ==
|
||||
value->type.Enumerated);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
ct_test(pTest, test_value.type.Date.year == value->type.Date.year);
|
||||
ct_test(pTest, test_value.type.Date.month ==
|
||||
value->type.Date.month);
|
||||
ct_test(pTest, test_value.type.Date.day == value->type.Date.day);
|
||||
ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
ct_test(pTest, test_value.type.Time.hour == value->type.Time.hour);
|
||||
ct_test(pTest, test_value.type.Time.min == value->type.Time.min);
|
||||
ct_test(pTest, test_value.type.Time.sec == value->type.Time.sec);
|
||||
ct_test(pTest, test_value.type.Time.hundredths ==
|
||||
value->type.Time.hundredths);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
ct_test(pTest, test_value.type.Object_Id.type ==
|
||||
value->type.Object_Id.type);
|
||||
ct_test(pTest, test_value.type.Object_Id.instance ==
|
||||
value->type.Object_Id.instance);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
ct_test(pTest, test_value.type.Boolean == value->type.Boolean);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
ct_test(pTest, test_value.type.Unsigned_Int ==
|
||||
value->type.Unsigned_Int);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
ct_test(pTest, test_value.type.Signed_Int ==
|
||||
value->type.Signed_Int);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
ct_test(pTest, test_value.type.Real == value->type.Real);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||
ct_test(pTest, test_value.type.Enumerated ==
|
||||
value->type.Enumerated);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
ct_test(pTest, test_value.type.Date.year == value->type.Date.year);
|
||||
ct_test(pTest, test_value.type.Date.month ==
|
||||
value->type.Date.month);
|
||||
ct_test(pTest, test_value.type.Date.day == value->type.Date.day);
|
||||
ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
ct_test(pTest, test_value.type.Time.hour == value->type.Time.hour);
|
||||
ct_test(pTest, test_value.type.Time.min == value->type.Time.min);
|
||||
ct_test(pTest, test_value.type.Time.sec == value->type.Time.sec);
|
||||
ct_test(pTest, test_value.type.Time.hundredths ==
|
||||
value->type.Time.hundredths);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
ct_test(pTest, test_value.type.Object_Id.type ==
|
||||
value->type.Object_Id.type);
|
||||
ct_test(pTest, test_value.type.Object_Id.instance ==
|
||||
value->type.Object_Id.instance);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void testWriteProperty(Test * pTest)
|
||||
void testWriteProperty(
|
||||
Test * pTest)
|
||||
{
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
|
||||
@@ -346,12 +354,14 @@ void testWriteProperty(Test * pTest)
|
||||
}
|
||||
|
||||
#ifdef TEST_WRITE_PROPERTY
|
||||
uint16_t Device_Max_APDU_Length_Accepted(void)
|
||||
uint16_t Device_Max_APDU_Length_Accepted(
|
||||
void)
|
||||
{
|
||||
return MAX_APDU;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -368,5 +378,5 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_WRITE_PROPERTY */
|
||||
#endif /* TEST */
|
||||
#endif /* TEST_WRITE_PROPERTY */
|
||||
#endif /* TEST */
|
||||
|
||||
Reference in New Issue
Block a user