Indented using indent script. Corrected any C++ comments using the comment script.

This commit is contained in:
skarg
2008-03-10 21:00:48 +00:00
parent 25b4979a28
commit cf9d15631a
33 changed files with 381 additions and 436 deletions
+8 -11
View File
@@ -141,7 +141,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -158,7 +159,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -217,21 +218,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
+12 -17
View File
@@ -189,7 +189,7 @@ void PrintReadPropertyData(
bacapp_print_value(stdout, &value, data->object_property); bacapp_print_value(stdout, &value, data->object_property);
if (Object_List_Index <= Object_List_Length) { if (Object_List_Index <= Object_List_Length) {
fprintf(stdout, ","); fprintf(stdout, ",");
if (!(Object_List_Index%4)) { if (!(Object_List_Index % 4)) {
fprintf(stdout, "\r\n "); fprintf(stdout, "\r\n ");
} }
} else { } else {
@@ -300,7 +300,7 @@ static uint8_t Read_Properties(
printf(" %s: ", bactext_property_name(pRequired[index])); printf(" %s: ", bactext_property_name(pRequired[index]));
invoke_id = invoke_id =
Send_Read_Property_Request(device_instance, OBJECT_DEVICE, Send_Read_Property_Request(device_instance, OBJECT_DEVICE,
device_instance, pRequired[index], BACNET_ARRAY_ALL); device_instance, pRequired[index], BACNET_ARRAY_ALL);
if (invoke_id) { if (invoke_id) {
index++; index++;
} }
@@ -310,7 +310,8 @@ static uint8_t Read_Properties(
return invoke_id; return invoke_id;
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -386,21 +387,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
@@ -437,13 +434,11 @@ int main(
timeout_seconds = timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries(); (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */ /* try to bind with the device */
found = address_bind_request( found =
Target_Device_Object_Instance, address_bind_request(Target_Device_Object_Instance, &max_apdu,
&max_apdu,
&Target_Address); &Target_Address);
if (!found) { if (!found) {
Send_WhoIs( Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
} }
printf("List of Objects in test device:\r\n"); printf("List of Objects in test device:\r\n");
+43 -62
View File
@@ -116,24 +116,20 @@ static int cov_encode_subscription(
apdu_len += len; apdu_len += len;
/* network-number Unsigned16, */ /* network-number Unsigned16, */
/* -- A value of 0 indicates the local network */ /* -- A value of 0 indicates the local network */
len = encode_application_unsigned( len =
&apdu[apdu_len], encode_application_unsigned(&apdu[apdu_len],
cov_subscription->dest.net); cov_subscription->dest.net);
apdu_len += len; apdu_len += len;
/* mac-address OCTET STRING */ /* mac-address OCTET STRING */
/* -- A string of length 0 indicates a broadcast */ /* -- A string of length 0 indicates a broadcast */
if (cov_subscription->dest.net) { if (cov_subscription->dest.net) {
octetstring_init(&octet_string, octetstring_init(&octet_string, &cov_subscription->dest.adr[0],
&cov_subscription->dest.adr[0],
cov_subscription->dest.len); cov_subscription->dest.len);
} else { } else {
octetstring_init(&octet_string, octetstring_init(&octet_string, &cov_subscription->dest.mac[0],
&cov_subscription->dest.mac[0],
cov_subscription->dest.mac_len); cov_subscription->dest.mac_len);
} }
len = encode_application_octet_string( len = encode_application_octet_string(&apdu[apdu_len], &octet_string);
&apdu[apdu_len],
&octet_string);
apdu_len += len; apdu_len += len;
/* CHOICE - address [1] BACnetAddress - closing */ /* CHOICE - address [1] BACnetAddress - closing */
len = encode_closing_tag(&apdu[apdu_len], 1); len = encode_closing_tag(&apdu[apdu_len], 1);
@@ -142,38 +138,37 @@ static int cov_encode_subscription(
len = encode_closing_tag(&apdu[apdu_len], 0); len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len; apdu_len += len;
/* processIdentifier [1] Unsigned32 */ /* processIdentifier [1] Unsigned32 */
len = encode_context_unsigned(&apdu[apdu_len],1, len =
encode_context_unsigned(&apdu[apdu_len], 1,
cov_subscription->subscriberProcessIdentifier); cov_subscription->subscriberProcessIdentifier);
apdu_len += len; apdu_len += len;
/* Recipient [0] BACnetRecipientProcess - closing */ /* Recipient [0] BACnetRecipientProcess - closing */
len = encode_closing_tag(&apdu[apdu_len], 0); len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len; apdu_len += len;
/* MonitoredPropertyReference [1] BACnetObjectPropertyReference,*/ /* MonitoredPropertyReference [1] BACnetObjectPropertyReference, */
len = encode_opening_tag(&apdu[apdu_len], 1); len = encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += len; apdu_len += len;
/* objectIdentifier [0] */ /* objectIdentifier [0] */
len = encode_context_object_id( len =
&apdu[apdu_len],0, encode_context_object_id(&apdu[apdu_len], 0,
cov_subscription->monitoredObjectIdentifier.type, cov_subscription->monitoredObjectIdentifier.type,
cov_subscription->monitoredObjectIdentifier.instance); cov_subscription->monitoredObjectIdentifier.instance);
apdu_len += len; apdu_len += len;
/* propertyIdentifier [1] */ /* propertyIdentifier [1] */
/* FIXME: we are monitoring 2 properties! How to encode? */ /* FIXME: we are monitoring 2 properties! How to encode? */
len = encode_context_enumerated( len = encode_context_enumerated(&apdu[apdu_len], 1, PROP_PRESENT_VALUE);
&apdu[apdu_len],1,
PROP_PRESENT_VALUE);
apdu_len += len; apdu_len += len;
/* MonitoredPropertyReference [1] - closing */ /* MonitoredPropertyReference [1] - closing */
len = encode_closing_tag(&apdu[apdu_len], 1); len = encode_closing_tag(&apdu[apdu_len], 1);
apdu_len += len; apdu_len += len;
/* IssueConfirmedNotifications [2] BOOLEAN, */ /* IssueConfirmedNotifications [2] BOOLEAN, */
len = encode_context_boolean( len =
&apdu[apdu_len],2, encode_context_boolean(&apdu[apdu_len], 2,
cov_subscription->issueConfirmedNotifications); cov_subscription->issueConfirmedNotifications);
apdu_len += len; apdu_len += len;
/* TimeRemaining [3] Unsigned, */ /* TimeRemaining [3] Unsigned, */
len = encode_context_unsigned( len =
&apdu[apdu_len],3, encode_context_unsigned(&apdu[apdu_len], 3,
cov_subscription->lifetime); cov_subscription->lifetime);
apdu_len += len; apdu_len += len;
@@ -181,7 +176,8 @@ static int cov_encode_subscription(
} }
int handler_cov_encode_subscriptions( int handler_cov_encode_subscriptions(
uint8_t * apdu, int max_apdu) uint8_t * apdu,
int max_apdu)
{ {
int len = 0; int len = 0;
int apdu_len = 0; int apdu_len = 0;
@@ -190,10 +186,9 @@ int handler_cov_encode_subscriptions(
if (apdu) { if (apdu) {
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) { for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
if (COV_Subscriptions[index].valid) { if (COV_Subscriptions[index].valid) {
len = cov_encode_subscription( len =
&apdu[apdu_len], cov_encode_subscription(&apdu[apdu_len],
max_apdu - apdu_len, max_apdu - apdu_len, &COV_Subscriptions[index]);
&COV_Subscriptions[index]);
apdu_len += len; apdu_len += len;
if (apdu_len > max_apdu) { if (apdu_len > max_apdu) {
return -2; return -2;
@@ -304,7 +299,7 @@ static bool cov_send_request(
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
int bytes_sent = 0; int bytes_sent = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool status = false; /* return value */ bool status = false; /* return value */
BACNET_COV_DATA cov_data; BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE value_list[2]; BACNET_PROPERTY_VALUE value_list[2];
@@ -314,31 +309,25 @@ static bool cov_send_request(
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = pdu_len =
npdu_encode_pdu( npdu_encode_pdu(&Handler_Transmit_Buffer[0], &cov_subscription->dest,
&Handler_Transmit_Buffer[0], &my_address, &npdu_data);
&cov_subscription->dest,
&my_address,
&npdu_data);
/* load the COV data structure for outgoing message */ /* load the COV data structure for outgoing message */
cov_data.subscriberProcessIdentifier = cov_data.subscriberProcessIdentifier =
cov_subscription->subscriberProcessIdentifier; cov_subscription->subscriberProcessIdentifier;
cov_data.initiatingDeviceIdentifier = cov_data.initiatingDeviceIdentifier = Device_Object_Instance_Number();
Device_Object_Instance_Number();
cov_data.monitoredObjectIdentifier.type = cov_data.monitoredObjectIdentifier.type =
cov_subscription->monitoredObjectIdentifier.type; cov_subscription->monitoredObjectIdentifier.type;
cov_data.monitoredObjectIdentifier.instance = cov_data.monitoredObjectIdentifier.instance =
cov_subscription->monitoredObjectIdentifier.instance; cov_subscription->monitoredObjectIdentifier.instance;
cov_data.timeRemaining = cov_data.timeRemaining = cov_subscription->lifetime;
cov_subscription->lifetime;
/* encode the value list */ /* encode the value list */
cov_data.listOfValues = &value_list[0]; cov_data.listOfValues = &value_list[0];
value_list[0].next = &value_list[1]; value_list[0].next = &value_list[1];
value_list[1].next = NULL; value_list[1].next = NULL;
switch (cov_subscription->monitoredObjectIdentifier.type) { switch (cov_subscription->monitoredObjectIdentifier.type) {
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
Binary_Input_Encode_Value_List( Binary_Input_Encode_Value_List(cov_subscription->
cov_subscription->monitoredObjectIdentifier.instance, monitoredObjectIdentifier.instance, &value_list[0]);
&value_list[0]);
break; break;
default: default:
goto COV_FAILED; goto COV_FAILED;
@@ -346,37 +335,31 @@ static bool cov_send_request(
if (cov_subscription->issueConfirmedNotifications) { if (cov_subscription->issueConfirmedNotifications) {
invoke_id = tsm_next_free_invokeID(); invoke_id = tsm_next_free_invokeID();
if (invoke_id) { if (invoke_id) {
len = ccov_notify_encode_apdu( len =
&Handler_Transmit_Buffer[pdu_len], ccov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, invoke_id, &cov_data);
&cov_data);
} else { } else {
goto COV_FAILED; goto COV_FAILED;
} }
} else { } else {
len = ucov_notify_encode_apdu( len =
&Handler_Transmit_Buffer[pdu_len], ucov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
&cov_data); &cov_data);
} }
pdu_len += len; pdu_len += len;
if (cov_subscription->issueConfirmedNotifications) { if (cov_subscription->issueConfirmedNotifications) {
tsm_set_confirmed_unsegmented_transaction( tsm_set_confirmed_unsegmented_transaction(invoke_id,
invoke_id, &cov_subscription->dest, &npdu_data, &Handler_Transmit_Buffer[0],
&cov_subscription->dest,
&npdu_data,
&Handler_Transmit_Buffer[0],
(uint16_t) pdu_len); (uint16_t) pdu_len);
} }
bytes_sent = datalink_send_pdu( bytes_sent =
&cov_subscription->dest, datalink_send_pdu(&cov_subscription->dest, &npdu_data,
&npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
&Handler_Transmit_Buffer[0],
pdu_len);
if (bytes_sent > 0) { if (bytes_sent > 0) {
status = true; status = true;
} }
COV_FAILED: COV_FAILED:
return status; return status;
} }
@@ -400,9 +383,8 @@ void handler_cov_task(
if (lifetime_seconds >= elapsed_seconds) { if (lifetime_seconds >= elapsed_seconds) {
COV_Subscriptions[index].lifetime -= elapsed_seconds; COV_Subscriptions[index].lifetime -= elapsed_seconds;
#if 0 #if 0
fprintf(stderr,"COVtask: subscription[%d].lifetime=%d\n", fprintf(stderr, "COVtask: subscription[%d].lifetime=%d\n",
index, index, COV_Subscriptions[index].lifetime);
COV_Subscriptions[index].lifetime);
#endif #endif
} else { } else {
COV_Subscriptions[index].lifetime = 0; COV_Subscriptions[index].lifetime = 0;
@@ -419,8 +401,7 @@ void handler_cov_task(
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
if (Binary_Input_Change_Of_Value(object_id.instance)) { if (Binary_Input_Change_Of_Value(object_id.instance)) {
COV_Subscriptions[index].send_requested = true; COV_Subscriptions[index].send_requested = true;
Binary_Input_Change_Of_Value_Clear( Binary_Input_Change_Of_Value_Clear(object_id.instance);
object_id.instance);
} }
break; break;
default: default:
@@ -445,8 +426,8 @@ static bool cov_subscribe(
switch (cov_data->monitoredObjectIdentifier.type) { switch (cov_data->monitoredObjectIdentifier.type) {
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
status = true; status = true;
status = cov_list_subscribe(src, cov_data, status =
error_class, error_code); cov_list_subscribe(src, cov_data, error_class, error_code);
break; break;
default: default:
*error_class = ERROR_CLASS_OBJECT; *error_class = ERROR_CLASS_OBJECT;
+29 -24
View File
@@ -42,31 +42,36 @@
/* list of devices */ /* list of devices */
static OS_Keylist Device_List = NULL; static OS_Keylist Device_List = NULL;
void objects_init(void) void objects_init(
void)
{ {
if (!Device_List) if (!Device_List)
Device_List = Keylist_Create(); Device_List = Keylist_Create();
} }
int objects_device_count(void) int objects_device_count(
void)
{ {
objects_init(); objects_init();
return Keylist_Count(Device_List); return Keylist_Count(Device_List);
} }
OBJECT_DEVICE_T *objects_device_data(int index) OBJECT_DEVICE_T *objects_device_data(
int index)
{ {
objects_init(); objects_init();
return Keylist_Data_Index(Device_List, index); return Keylist_Data_Index(Device_List, index);
} }
OBJECT_DEVICE_T *objects_device_by_instance(uint32_t device_instance) OBJECT_DEVICE_T *objects_device_by_instance(
uint32_t device_instance)
{ {
objects_init(); objects_init();
return Keylist_Data(Device_List, device_instance); return Keylist_Data(Device_List, device_instance);
} }
OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance) OBJECT_DEVICE_T *objects_device_new(
uint32_t device_instance)
{ {
OBJECT_DEVICE_T *pDevice = NULL; OBJECT_DEVICE_T *pDevice = NULL;
KEY key = device_instance; KEY key = device_instance;
@@ -85,7 +90,8 @@ OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance)
pDevice->Object_List = Keylist_Create(); pDevice->Object_List = Keylist_Create();
Keylist_Data_Add(Device_List, key, pDevice); Keylist_Data_Add(Device_List, key, pDevice);
} else { } else {
fprintf(stderr,"Objects: Unable to allocate device %d buffer\n", fprintf(stderr,
"Objects: Unable to allocate device %d buffer\n",
device_instance); device_instance);
} }
} }
@@ -94,7 +100,8 @@ OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance)
return pDevice; return pDevice;
} }
OBJECT_DEVICE_T *objects_device_delete(int index) OBJECT_DEVICE_T *objects_device_delete(
int index)
{ {
OBJECT_DEVICE_T *pDevice = NULL; OBJECT_DEVICE_T *pDevice = NULL;
BACNET_OBJECT_ID *pObject; BACNET_OBJECT_ID *pObject;
@@ -102,12 +109,12 @@ OBJECT_DEVICE_T *objects_device_delete(int index)
if (Device_List) { if (Device_List) {
pDevice = Keylist_Data_Delete_By_Index(Device_List, index); pDevice = Keylist_Data_Delete_By_Index(Device_List, index);
if (pDevice) { if (pDevice) {
fprintf(stderr,"Objects: removing device %d", fprintf(stderr, "Objects: removing device %d",
pDevice->Object_Identifier.instance); pDevice->Object_Identifier.instance);
if (pDevice->Object_List) { if (pDevice->Object_List) {
do { do {
pObject = pObject =
Keylist_Data_Delete_By_Index(pDevice->Object_List,0); Keylist_Data_Delete_By_Index(pDevice->Object_List, 0);
/* free any dynamic memory used */ /* free any dynamic memory used */
if (pObject) { if (pObject) {
free(pObject); free(pObject);
@@ -130,7 +137,7 @@ OBJECT_DEVICE_T *objects_device_delete(int index)
/* test the object creation and deletion */ /* test the object creation and deletion */
void testBACnetObjectsCompare( void testBACnetObjectsCompare(
Test * pTest, Test * pTest,
OBJECT_DEVICE_T *pDevice, OBJECT_DEVICE_T * pDevice,
uint32_t device_id) uint32_t device_id)
{ {
ct_test(pTest, pDevice != NULL); ct_test(pTest, pDevice != NULL);
@@ -150,28 +157,26 @@ void testBACnetObjects(
const unsigned max_test_points = 20; const unsigned max_test_points = 20;
OBJECT_DEVICE_T *pDevice; OBJECT_DEVICE_T *pDevice;
for (test_point = 0;test_point < max_test_points;test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE/max_test_points); device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_new(device_id); pDevice = objects_device_new(device_id);
testBACnetObjectsCompare(pTest, pDevice, device_id); testBACnetObjectsCompare(pTest, pDevice, device_id);
pDevice = objects_device_by_instance(device_id); pDevice = objects_device_by_instance(device_id);
testBACnetObjectsCompare(pTest, pDevice, device_id); testBACnetObjectsCompare(pTest, pDevice, device_id);
} }
ct_test(pTest, max_test_points == objects_device_count()); ct_test(pTest, max_test_points == objects_device_count());
for (test_point = 0;test_point < max_test_points;test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE/max_test_points); device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_by_instance(device_id); pDevice = objects_device_by_instance(device_id);
testBACnetObjectsCompare(pTest, pDevice, device_id); testBACnetObjectsCompare(pTest, pDevice, device_id);
} }
for (test_point = 0;test_point < max_test_points;test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
device_id = test_point * (BACNET_MAX_INSTANCE/max_test_points); device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points);
pDevice = objects_device_data(test_point); pDevice = objects_device_data(test_point);
testBACnetObjectsCompare( testBACnetObjectsCompare(pTest, pDevice, Keylist_Key(Device_List,
pTest, test_point));
pDevice,
Keylist_Key(Device_List, test_point));
} }
for (test_point = 0;test_point < max_test_points;test_point++) { for (test_point = 0; test_point < max_test_points; test_point++) {
pDevice = objects_device_delete(0); pDevice = objects_device_delete(0);
} }
} }
+7 -9
View File
@@ -207,7 +207,7 @@ void Binary_Input_Change_Of_Value_Clear(
bool Binary_Input_Encode_Value_List( bool Binary_Input_Encode_Value_List(
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_VALUE *value_list) BACNET_PROPERTY_VALUE * value_list)
{ {
value_list->propertyIdentifier = PROP_PRESENT_VALUE; value_list->propertyIdentifier = PROP_PRESENT_VALUE;
value_list->propertyArrayIndex = BACNET_ARRAY_ALL; value_list->propertyArrayIndex = BACNET_ARRAY_ALL;
@@ -224,20 +224,18 @@ bool Binary_Input_Encode_Value_List(
value_list->value.context_specific = false; value_list->value.context_specific = false;
value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
bitstring_init(&value_list->value.type.Bit_String); bitstring_init(&value_list->value.type.Bit_String);
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_IN_ALARM,
STATUS_FLAG_IN_ALARM, false); false);
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT,
STATUS_FLAG_FAULT, false); false);
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
if (Binary_Input_Out_Of_Service(object_instance)) { if (Binary_Input_Out_Of_Service(object_instance)) {
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String,
STATUS_FLAG_OUT_OF_SERVICE, STATUS_FLAG_OUT_OF_SERVICE, true);
true);
} else { } else {
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String,
STATUS_FLAG_OUT_OF_SERVICE, STATUS_FLAG_OUT_OF_SERVICE, false);
false);
} }
value_list->priority = BACNET_NO_PRIORITY; value_list->priority = BACNET_NO_PRIORITY;
+1 -2
View File
@@ -877,8 +877,7 @@ int Device_Encode_Property_APDU(
#endif #endif
case PROP_ACTIVE_COV_SUBSCRIPTIONS: case PROP_ACTIVE_COV_SUBSCRIPTIONS:
/* FIXME: the real max apdu should be passed into function */ /* FIXME: the real max apdu should be passed into function */
apdu_len = handler_cov_encode_subscriptions( apdu_len = handler_cov_encode_subscriptions(&apdu[0], MAX_APDU);
&apdu[0], MAX_APDU);
break; break;
default: default:
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
+8 -11
View File
@@ -196,7 +196,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -213,7 +214,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -272,21 +273,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
+9 -13
View File
@@ -133,7 +133,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -150,7 +151,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -209,21 +210,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
@@ -282,8 +279,7 @@ int main(
address_bind_request(Target_Device_Object_Instance, &max_apdu, address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address); &Target_Address);
if (!found) { if (!found) {
Send_WhoIs( Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
} }
/* loop forever */ /* loop forever */
+8 -11
View File
@@ -136,7 +136,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -153,7 +154,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -212,21 +213,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
+44 -47
View File
@@ -98,7 +98,8 @@ static void cleanup(
datalink_cleanup(); datalink_cleanup();
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -115,7 +116,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -175,21 +176,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
time_t last_seconds = 0; time_t last_seconds = 0;
@@ -200,43 +197,43 @@ int main(
/* allow the device ID to be set */ /* allow the device ID to be set */
if (argc > 1) if (argc > 1)
Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0)); Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0));
printf("BACnet Server Demo\n" "BACnet Stack Version %s\n" printf("BACnet Server Demo\n" "BACnet Stack Version %s\n"
"BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version, "BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version,
Device_Object_Instance_Number(), MAX_APDU); Device_Object_Instance_Number(), MAX_APDU);
Init_Service_Handlers(); Init_Service_Handlers();
Init_DataLink(); Init_DataLink();
atexit(cleanup); atexit(cleanup);
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
/* broadcast an I-Am on startup */ /* broadcast an I-Am on startup */
iam_send(&Handler_Transmit_Buffer[0]); iam_send(&Handler_Transmit_Buffer[0]);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* input */ /* input */
current_seconds = time(NULL); current_seconds = time(NULL);
/* returns 0 bytes on timeout */ /* returns 0 bytes on timeout */
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
/* process */ /* process */
if (pdu_len) { if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
/* at least one second has passed */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
last_seconds = current_seconds;
dcc_timer_seconds(elapsed_seconds);
#if defined(BACDL_BIP) && BBMD_ENABLED
bvlc_maintenance_timer(elapsed_seconds);
#endif
Load_Control_State_Machine_Handler();
elapsed_milliseconds = elapsed_seconds * 1000;
handler_cov_task(elapsed_seconds);
tsm_timer_milliseconds(elapsed_milliseconds);
}
/* output */
/* blink LEDs, Turn on or off outputs, etc */
} }
/* at least one second has passed */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
last_seconds = current_seconds;
dcc_timer_seconds(elapsed_seconds);
#if defined(BACDL_BIP) && BBMD_ENABLED
bvlc_maintenance_timer(elapsed_seconds);
#endif
Load_Control_State_Machine_Handler();
elapsed_milliseconds = elapsed_seconds * 1000;
handler_cov_task(elapsed_seconds);
tsm_timer_milliseconds(elapsed_milliseconds);
}
/* output */
/* blink LEDs, Turn on or off outputs, etc */
} }
}
+8 -11
View File
@@ -105,7 +105,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -122,7 +123,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -181,21 +182,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
time_t elapsed_seconds = 0; time_t elapsed_seconds = 0;
+9 -13
View File
@@ -66,7 +66,8 @@ static void Init_Service_Handlers(
handler_read_property); handler_read_property);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -83,7 +84,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -142,27 +143,22 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc,
char *argv[])
{
char *value_string = NULL; char *value_string = NULL;
bool status = false; bool status = false;
BACNET_COV_DATA cov_data; BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE value_list; BACNET_PROPERTY_VALUE value_list;
uint8_t tag; uint8_t tag;
if (argc < 7) { if (argc < 7) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s pid device-id object-type object-instance " printf("Usage: %s pid device-id object-type object-instance "
"time property tag value [priority] [index]\r\n" "\r\n" "pid:\r\n" "time property tag value [priority] [index]\r\n" "\r\n" "pid:\r\n"
@@ -215,8 +211,8 @@ int main(
filename_remove_path(argv[0]), filename_remove_path(argv[0])); filename_remove_path(argv[0]), filename_remove_path(argv[0]));
return 0; return 0;
} }
/* decode the command line parameters */ /* decode the command line parameters */ cov_data.
cov_data.subscriberProcessIdentifier = strtol(argv[1], NULL, 0); subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0); cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0);
cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0); cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0);
cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0); cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0);
+8 -11
View File
@@ -105,7 +105,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -122,7 +123,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -181,21 +182,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
time_t elapsed_seconds = 0; time_t elapsed_seconds = 0;
+8 -11
View File
@@ -141,7 +141,8 @@ static void print_address_cache(
} }
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -158,7 +159,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -217,21 +218,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
time_t total_seconds = 0; time_t total_seconds = 0;
+8 -11
View File
@@ -150,7 +150,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -167,7 +168,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -226,21 +227,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
+9 -13
View File
@@ -147,7 +147,8 @@ static void Init_Service_Handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
static void Init_DataLink(void) static void Init_DataLink(
void)
{ {
char *pEnv = NULL; char *pEnv = NULL;
#if defined(BACDL_BIP) && BBMD_ENABLED #if defined(BACDL_BIP) && BBMD_ENABLED
@@ -164,7 +165,7 @@ static void Init_DataLink(void)
datalink_set(NULL); datalink_set(NULL);
} }
#endif #endif
#if defined(BACDL_BIP) #if defined(BACDL_BIP)
pEnv = getenv("BACNET_IP_PORT"); pEnv = getenv("BACNET_IP_PORT");
if (pEnv) { if (pEnv) {
@@ -223,21 +224,17 @@ static void Init_DataLink(void)
struct in_addr addr; struct in_addr addr;
addr.s_addr = bbmd_address; addr.s_addr = bbmd_address;
printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n", printf("WhoIs: Registering with BBMD at %s:%ld for %ld seconds\n",
inet_ntoa(addr),bbmd_port, bbmd_timetolive_seconds); inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
bvlc_register_with_bbmd( bvlc_register_with_bbmd(bbmd_address, bbmd_port,
bbmd_address,
bbmd_port,
bbmd_timetolive_seconds); bbmd_timetolive_seconds);
} }
} }
#endif #endif
} }
int main( int main(int argc, char *argv[]) {
int argc, BACNET_ADDRESS src = {
char *argv[]) 0}; /* address where message came from */
{
BACNET_ADDRESS src = { 0 }; /* address where message came from */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
unsigned timeout = 100; /* milliseconds */ unsigned timeout = 100; /* milliseconds */
unsigned max_apdu = 0; unsigned max_apdu = 0;
@@ -399,8 +396,7 @@ int main(
address_bind_request(Target_Device_Object_Instance, &max_apdu, address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address); &Target_Address);
if (!found) { if (!found) {
Send_WhoIs( Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
} }
/* loop forever */ /* loop forever */
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
uint32_t object_instance); uint32_t object_instance);
bool Binary_Input_Encode_Value_List( bool Binary_Input_Encode_Value_List(
uint32_t object_instance, uint32_t object_instance,
BACNET_PROPERTY_VALUE *value_list); BACNET_PROPERTY_VALUE * value_list);
int Binary_Input_Encode_Property_APDU( int Binary_Input_Encode_Property_APDU(
uint8_t * apdu, uint8_t * apdu,
+2 -1
View File
@@ -115,7 +115,8 @@ extern "C" {
a name that is a domain name a name that is a domain name
returns 0 if not found, or returns 0 if not found, or
an IP address in network byte order */ an IP address in network byte order */
long bip_getaddrbyname(const char *host_name); long bip_getaddrbyname(
const char *host_name);
#ifdef __cplusplus #ifdef __cplusplus
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
#endif #endif
/* registers with a bbmd as a foreign device */ /* registers with a bbmd as a foreign device */
void bvlc_register_with_bbmd( void bvlc_register_with_bbmd(
long bbmd_address, /* in network byte order */ long bbmd_address, /* in network byte order */
uint16_t bbmd_port, uint16_t bbmd_port,
uint16_t time_to_live_seconds); uint16_t time_to_live_seconds);
+1 -1
View File
@@ -52,7 +52,7 @@ typedef struct BACnet_COV_Data {
uint32_t subscriberProcessIdentifier; uint32_t subscriberProcessIdentifier;
uint32_t initiatingDeviceIdentifier; uint32_t initiatingDeviceIdentifier;
BACNET_OBJECT_ID monitoredObjectIdentifier; BACNET_OBJECT_ID monitoredObjectIdentifier;
uint32_t timeRemaining; /* seconds */ uint32_t timeRemaining; /* seconds */
/* simple linked list of values */ /* simple linked list of values */
BACNET_PROPERTY_VALUE *listOfValues; BACNET_PROPERTY_VALUE *listOfValues;
} BACNET_COV_DATA; } BACNET_COV_DATA;
+3 -2
View File
@@ -151,8 +151,9 @@ extern "C" {
void handler_cov_task( void handler_cov_task(
uint32_t elapsed_seconds); uint32_t elapsed_seconds);
int handler_cov_encode_subscriptions( int handler_cov_encode_subscriptions(
uint8_t * apdu, int max_apdu); uint8_t * apdu,
int max_apdu);
#ifdef __cplusplus #ifdef __cplusplus
} }
+51 -32
View File
@@ -457,7 +457,8 @@ static void MSTP_Receive_Frame_FSM(
switch (Receive_State) { switch (Receive_State) {
case MSTP_RECEIVE_STATE_IDLE: case MSTP_RECEIVE_STATE_IDLE:
/* In the IDLE state, the node waits for the beginning of a frame. */ /* In the IDLE state, the node waits
for the beginning of a frame. */
if (RS485_ReceiveError()) { if (RS485_ReceiveError()) {
/* EatAnError */ /* EatAnError */
Timer_Silence_Reset(); Timer_Silence_Reset();
@@ -507,10 +508,12 @@ static void MSTP_Receive_Frame_FSM(
} }
break; break;
case MSTP_RECEIVE_STATE_HEADER: case MSTP_RECEIVE_STATE_HEADER:
/* In the HEADER state, the node waits for the fixed message header. */ /* In the HEADER state, the node waits
for the fixed message header. */
if (Timer_Silence() > Tframe_abort) { if (Timer_Silence() > Tframe_abort) {
/* Timeout */ /* Timeout */
/* indicate that an error has occurred during the reception of a frame */ /* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true; MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of a frame. */ /* wait for the start of a frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE; Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -518,7 +521,8 @@ static void MSTP_Receive_Frame_FSM(
/* Error */ /* Error */
Timer_Silence_Reset(); Timer_Silence_Reset();
INCREMENT_AND_LIMIT_UINT8(EventCount); INCREMENT_AND_LIMIT_UINT8(EventCount);
/* indicate that an error has occurred during the reception of a frame */ /* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true; MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of a frame. */ /* wait for the start of a frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE; Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -606,10 +610,12 @@ static void MSTP_Receive_Frame_FSM(
} }
break; break;
case MSTP_RECEIVE_STATE_DATA: case MSTP_RECEIVE_STATE_DATA:
/* In the DATA state, the node waits for the data portion of a frame. */ /* In the DATA state, the node waits
for the data portion of a frame. */
if (Timer_Silence() > Tframe_abort) { if (Timer_Silence() > Tframe_abort) {
/* Timeout */ /* Timeout */
/* indicate that an error has occurred during the reception of a frame */ /* indicate that an error has occurred
during the reception of a frame */
MSTP_Flag.ReceivedInvalidFrame = true; MSTP_Flag.ReceivedInvalidFrame = true;
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
Receive_State = MSTP_RECEIVE_STATE_IDLE; Receive_State = MSTP_RECEIVE_STATE_IDLE;
@@ -671,9 +677,9 @@ static bool MSTP_Master_Node_FSM(
/* When this counter reaches the value Nmax_info_frames, the node must */ /* When this counter reaches the value Nmax_info_frames, the node must */
/* pass the token. */ /* pass the token. */
static uint8_t FrameCount; static uint8_t FrameCount;
/* "Next Station," the MAC address of the node to which This Station passes */ /* "Next Station," the MAC address of the node to which This Station
/* the token. If the Next_Station is unknown, Next_Station shall be equal to */ passes the token. If the Next_Station is unknown, Next_Station shall
/* This_Station. */ be equal to This_Station. */
static uint8_t Next_Station; static uint8_t Next_Station;
/* "Poll Station," the MAC address of the node to which This Station last */ /* "Poll Station," the MAC address of the node to which This Station last */
/* sent a Poll For Master. This is used during token maintenance. */ /* sent a Poll For Master. This is used during token maintenance. */
@@ -681,10 +687,10 @@ static bool MSTP_Master_Node_FSM(
/* A counter of transmission retries used for Token and Poll For Master */ /* A counter of transmission retries used for Token and Poll For Master */
/* transmission. */ /* transmission. */
static unsigned RetryCount; static unsigned RetryCount;
/* The number of tokens received by this node. When this counter reaches the */ /* The number of tokens received by this node. When this counter reaches */
/* value Npoll, the node polls the address range between TS and NS for */ /* the value Npoll, the node polls the address range between TS and NS */
/* additional master nodes. TokenCount is set to zero at the end of the */ /* for additional master nodes. TokenCount is set to zero at the end of */
/* polling process. */ /* the polling process. */
static unsigned TokenCount; static unsigned TokenCount;
/* next-x-station calculations */ /* next-x-station calculations */
uint8_t next_poll_station = 0; uint8_t next_poll_station = 0;
@@ -749,7 +755,7 @@ static bool MSTP_Master_Node_FSM(
MSTP_Flag.ReceivePacketPending = true; MSTP_Flag.ReceivePacketPending = true;
break; break;
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY: case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
/* indicate successful reception to the higher layers */ /* indicate successful reception to higher layers */
MSTP_Flag.ReceivePacketPending = true; MSTP_Flag.ReceivePacketPending = true;
/* broadcast DER just remains IDLE */ /* broadcast DER just remains IDLE */
if (DestinationAddress != MSTP_BROADCAST_ADDRESS) { if (DestinationAddress != MSTP_BROADCAST_ADDRESS) {
@@ -759,8 +765,8 @@ static bool MSTP_Master_Node_FSM(
break; break;
case FRAME_TYPE_TEST_REQUEST: case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE, MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station, SourceAddress, This_Station, &InputBuffer[0],
&InputBuffer[0], DataLength); DataLength);
break; break;
case FRAME_TYPE_TEST_RESPONSE: case FRAME_TYPE_TEST_RESPONSE:
default: default:
@@ -823,8 +829,10 @@ static bool MSTP_Master_Node_FSM(
FrameCount = Nmax_info_frames; FrameCount = Nmax_info_frames;
Master_State = MSTP_MASTER_STATE_DONE_WITH_TOKEN; Master_State = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
/* Any retry of the data frame shall await the next entry */ /* Any retry of the data frame shall await the next entry */
/* to the USE_TOKEN state. (Because of the length of the timeout, */ /* to the USE_TOKEN state. */
/* this transition will cause the token to be passed regardless */ /* (Because of the length of the timeout, */
/* this transition will cause the token to be */
/* passed regardless */
/* of the initial value of FrameCount.) */ /* of the initial value of FrameCount.) */
transition_now = true; transition_now = true;
} else { } else {
@@ -848,8 +856,10 @@ static bool MSTP_Master_Node_FSM(
break; break;
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY: case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
/* ReceivedReply */ /* ReceivedReply */
/* or a proprietary type that indicates a reply */ /* or a proprietary type that indicates
/* indicate successful reception to the higher layers */ a reply */
/* indicate successful reception to
the higher layers */
MSTP_Flag.ReceivePacketPending = true; MSTP_Flag.ReceivePacketPending = true;
Master_State = Master_State =
MSTP_MASTER_STATE_DONE_WITH_TOKEN; MSTP_MASTER_STATE_DONE_WITH_TOKEN;
@@ -891,7 +901,8 @@ static bool MSTP_Master_Node_FSM(
(Next_Station != next_this_station)) { (Next_Station != next_this_station)) {
/* SoleMaster */ /* SoleMaster */
/* there are no other known master nodes to */ /* there are no other known master nodes to */
/* which the token may be sent (true master-slave operation). */ /* which the token may be sent
(true master-slave operation). */
FrameCount = 0; FrameCount = 0;
TokenCount++; TokenCount++;
Master_State = MSTP_MASTER_STATE_USE_TOKEN; Master_State = MSTP_MASTER_STATE_USE_TOKEN;
@@ -899,9 +910,12 @@ static bool MSTP_Master_Node_FSM(
} else { } else {
/* SendToken */ /* SendToken */
/* Npoll changed in Errata SSPC-135-2004 */ /* Npoll changed in Errata SSPC-135-2004 */
/* The comparison of NS and TS+1 eliminates the Poll For Master */ /* The comparison of NS and TS+1
/* if there are no addresses between TS and NS, since there is no */ eliminates the Poll For Master
/* address at which a new master node may be found in that case. */ if there are no addresses between
TS and NS, since there is no
address at which a new master node
may be found in that case. */
TokenCount++; TokenCount++;
/* transmit a Token frame to NS */ /* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station, MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
@@ -949,7 +963,8 @@ static bool MSTP_Master_Node_FSM(
if (Timer_Silence() <= Tusage_timeout) { if (Timer_Silence() <= Tusage_timeout) {
if (EventCount > Nmin_octets) { if (EventCount > Nmin_octets) {
/* SawTokenUser */ /* SawTokenUser */
/* Assume that a frame has been sent by the new token user. */ /* Assume that a frame has been sent by
the new token user. */
/* Enter the IDLE state to process the frame. */ /* Enter the IDLE state to process the frame. */
Master_State = MSTP_MASTER_STATE_IDLE; Master_State = MSTP_MASTER_STATE_IDLE;
transition_now = true; transition_now = true;
@@ -981,17 +996,19 @@ static bool MSTP_Master_Node_FSM(
} }
} }
break; break;
/* The NO_TOKEN state is entered if Timer_Silence() becomes greater */ /* The NO_TOKEN state is entered if Timer_Silence()
/* than Tno_token, indicating that there has been no network activity */ becomes greater than Tno_token, indicating that
/* for that period of time. The timeout is continued to determine */ there has been no network activity for that period
/* whether or not this node may create a token. */ of time. The timeout is continued to determine
whether or not this node may create a token. */
case MSTP_MASTER_STATE_NO_TOKEN: case MSTP_MASTER_STATE_NO_TOKEN:
my_timeout = Tno_token + (Tslot * This_Station); my_timeout = Tno_token + (Tslot * This_Station);
if (Timer_Silence() < my_timeout) { if (Timer_Silence() < my_timeout) {
if (EventCount > Nmin_octets) { if (EventCount > Nmin_octets) {
/* SawFrame */ /* SawFrame */
/* Some other node exists at a lower address. */ /* Some other node exists at a lower address. */
/* Enter the IDLE state to receive and process the incoming frame. */ /* Enter the IDLE state to receive and
process the incoming frame. */
Master_State = MSTP_MASTER_STATE_IDLE; Master_State = MSTP_MASTER_STATE_IDLE;
transition_now = true; transition_now = true;
} }
@@ -1010,7 +1027,8 @@ static bool MSTP_Master_Node_FSM(
RetryCount = 0; RetryCount = 0;
TokenCount = 0; TokenCount = 0;
/* EventCount = 0; removed Addendum 135-2004d-8 */ /* EventCount = 0; removed Addendum 135-2004d-8 */
/* enter the POLL_FOR_MASTER state to find a new successor to TS. */ /* enter the POLL_FOR_MASTER state
to find a new successor to TS. */
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER; Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
} }
} }
@@ -1075,7 +1093,8 @@ static bool MSTP_Master_Node_FSM(
/* Re-enter the current state. */ /* Re-enter the current state. */
} else { } else {
/* DeclareSoleMaster */ /* DeclareSoleMaster */
/* to indicate that this station is the only master */ /* to indicate that this station
is the only master */
MSTP_Flag.SoleMaster = true; MSTP_Flag.SoleMaster = true;
FrameCount = 0; FrameCount = 0;
Master_State = MSTP_MASTER_STATE_USE_TOKEN; Master_State = MSTP_MASTER_STATE_USE_TOKEN;
+2 -2
View File
@@ -673,8 +673,8 @@ static bool MSTP_Master_Node_FSM(
break; break;
case FRAME_TYPE_TEST_REQUEST: case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE, MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station, SourceAddress, This_Station, &InputBuffer[0],
&InputBuffer[0], DataLength); DataLength);
break; break;
case FRAME_TYPE_TEST_RESPONSE: case FRAME_TYPE_TEST_RESPONSE:
default: default:
+2 -2
View File
@@ -758,8 +758,8 @@ static bool MSTP_Master_Node_FSM(
break; break;
case FRAME_TYPE_TEST_REQUEST: case FRAME_TYPE_TEST_REQUEST:
MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE, MSTP_Send_Frame(FRAME_TYPE_TEST_RESPONSE,
SourceAddress, This_Station, SourceAddress, This_Station, &InputBuffer[0],
&InputBuffer[0], DataLength); DataLength);
break; break;
case FRAME_TYPE_TEST_RESPONSE: case FRAME_TYPE_TEST_RESPONSE:
default: default:
+2 -1
View File
@@ -45,7 +45,8 @@ bool BIP_Debug = false;
a name that is a domain name a name that is a domain name
returns 0 if not found, or returns 0 if not found, or
an IP address in network byte order */ an IP address in network byte order */
long bip_getaddrbyname(const char *host_name) long bip_getaddrbyname(
const char *host_name)
{ {
struct hostent *host_ent; struct hostent *host_ent;
+2 -2
View File
@@ -672,7 +672,7 @@ static int create_named_server_socket(
} }
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sock, sizeof(sock)); setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sock, sizeof(sock));
/* Bind a name to the socket. */ /* Bind a name to the socket. */
bzero((char *)&name, sizeof(name)); bzero((char *) &name, sizeof(name));
name.sun_family = AF_LOCAL; name.sun_family = AF_LOCAL;
strncpy(name.sun_path, filename, sizeof(name.sun_path)); strncpy(name.sun_path, filename, sizeof(name.sun_path));
/* The size of the address is /* The size of the address is
@@ -711,7 +711,7 @@ static int connect_named_server_socket(
#endif #endif
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
bzero((char *)&name, sizeof(name)); bzero((char *) &name, sizeof(name));
name.sun_family = AF_LOCAL; name.sun_family = AF_LOCAL;
strncpy(name.sun_path, filename, sizeof(name.sun_path)); strncpy(name.sun_path, filename, sizeof(name.sun_path));
/* The size of the address is /* The size of the address is
+33 -29
View File
@@ -49,7 +49,8 @@ bool BIP_Debug = false;
a name that is a domain name a name that is a domain name
returns 0 if not found, or returns 0 if not found, or
an IP address in network byte order */ an IP address in network byte order */
long bip_getaddrbyname(const char *host_name) long bip_getaddrbyname(
const char *host_name)
{ {
struct hostent *host_ent; struct hostent *host_ent;
@@ -85,53 +86,56 @@ static long gethostaddr(
#if (!defined(USE_INADDR) || (USE_INADDR == 0)) && \ #if (!defined(USE_INADDR) || (USE_INADDR == 0)) && \
(!defined(USE_CLASSADDR) || (USE_CLASSADDR == 0)) (!defined(USE_CLASSADDR) || (USE_CLASSADDR == 0))
/* returns the subnet mask in network byte order */ /* returns the subnet mask in network byte order */
static uint32_t getIpMaskForIpAddress( uint32_t ipAddress ) static uint32_t getIpMaskForIpAddress(
uint32_t ipAddress)
{ {
/* Allocate information for up to 16 NICs */ /* Allocate information for up to 16 NICs */
IP_ADAPTER_INFO AdapterInfo[16]; IP_ADAPTER_INFO AdapterInfo[16];
/* Save memory size of buffer */ /* Save memory size of buffer */
DWORD dwBufLen = sizeof(AdapterInfo); DWORD dwBufLen = sizeof(AdapterInfo);
uint32_t ipMask = INADDR_BROADCAST; uint32_t ipMask = INADDR_BROADCAST;
PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapterInfo;
/* GetAdapterInfo: /* GetAdapterInfo:
[out] buffer to receive data [out] buffer to receive data
[in] size of receive data buffer */ [in] size of receive data buffer */
DWORD dwStatus = GetAdaptersInfo( DWORD dwStatus = GetAdaptersInfo(AdapterInfo,
AdapterInfo, &dwBufLen);
&dwBufLen); if (dwStatus == ERROR_SUCCESS) {
if( dwStatus == ERROR_SUCCESS ) {
/* Verify return value is valid, no buffer overflow /* Verify return value is valid, no buffer overflow
Contains pointer to current adapter info */ Contains pointer to current adapter info */
pAdapterInfo = AdapterInfo; pAdapterInfo = AdapterInfo;
do { do {
IP_ADDR_STRING* pIpAddressInfo = &pAdapterInfo->IpAddressList; IP_ADDR_STRING *pIpAddressInfo = &pAdapterInfo->IpAddressList;
do { do {
unsigned long adapterAddress = inet_addr(pIpAddressInfo->IpAddress.String); unsigned long adapterAddress =
unsigned long adapterMask = inet_addr(pIpAddressInfo->IpMask.String); inet_addr(pIpAddressInfo->IpAddress.String);
if( adapterAddress == ipAddress ) { unsigned long adapterMask =
ipMask = adapterMask; inet_addr(pIpAddressInfo->IpMask.String);
if (adapterAddress == ipAddress) {
ipMask = adapterMask;
break; break;
} }
pIpAddressInfo = pIpAddressInfo->Next; pIpAddressInfo = pIpAddressInfo->Next;
} }
while(pIpAddressInfo); while (pIpAddressInfo);
if( ipMask != 0L ) { if (ipMask != 0L) {
break; break;
} }
/* Progress through linked list */ /* Progress through linked list */
pAdapterInfo = pAdapterInfo->Next; pAdapterInfo = pAdapterInfo->Next;
/* Terminate on last adapter */ /* Terminate on last adapter */
} while(pAdapterInfo); } while (pAdapterInfo);
} }
return ipMask; return ipMask;
} }
#endif #endif
static void set_broadcast_address(uint32_t net_address) static void set_broadcast_address(
uint32_t net_address)
{ {
#if defined(USE_INADDR) && USE_INADDR #if defined(USE_INADDR) && USE_INADDR
/* Note: sometimes INADDR_BROADCAST does not let me get /* Note: sometimes INADDR_BROADCAST does not let me get
@@ -154,20 +158,20 @@ static void set_broadcast_address(uint32_t net_address)
broadcast_address = broadcast_address =
(ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST; (ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST;
else else
broadcast_address = INADDR_BROADCAST; broadcast_address = INADDR_BROADCAST;
bip_set_broadcast_addr(htonl(broadcast_address)); bip_set_broadcast_addr(htonl(broadcast_address));
#else #else
/* these are network byte order variables */ /* these are network byte order variables */
long broadcast_address = 0; long broadcast_address = 0;
long net_mask = 0; long net_mask = 0;
net_mask = getIpMaskForIpAddress( net_address ); net_mask = getIpMaskForIpAddress(net_address);
if (BIP_Debug) { if (BIP_Debug) {
struct in_addr address; struct in_addr address;
address.s_addr = net_mask; address.s_addr = net_mask;
printf("IP Mask: %s\n", inet_ntoa(address)); printf("IP Mask: %s\n", inet_ntoa(address));
} }
broadcast_address = (net_address & net_mask) | (~net_mask); broadcast_address = (net_address & net_mask) | (~net_mask);
bip_set_broadcast_addr(broadcast_address); bip_set_broadcast_addr(broadcast_address);
#endif #endif
} }
+18 -31
View File
@@ -82,7 +82,7 @@ void address_file_init(
const char *pFilename) const char *pFilename)
{ {
FILE *pFile = NULL; /* stream pointer */ FILE *pFile = NULL; /* stream pointer */
char line[256] = {""}; /* holds line from file */ char line[256] = { "" }; /* holds line from file */
long device_id = 0; long device_id = 0;
int snet = 0; int snet = 0;
int max_apdu = 0; int max_apdu = 0;
@@ -92,38 +92,25 @@ void address_file_init(
BACNET_ADDRESS src; BACNET_ADDRESS src;
int index = 0; int index = 0;
pFile = fopen(pFilename,"r"); pFile = fopen(pFilename, "r");
if (pFile) { if (pFile) {
while (fgets(line, sizeof(line), pFile) != NULL) { while (fgets(line, sizeof(line), pFile) != NULL) {
/* ignore comments */ /* ignore comments */
if (line[0] != ';') { if (line[0] != ';') {
if (sscanf(line, if (sscanf(line, "%ld %s %d %s %d", &device_id, &mac_string[0],
"%ld %s %d %s %d", &snet, &sadr_string[0], &max_apdu) == 5) {
&device_id, count =
&mac_string[0], sscanf(mac_string, "%x:%x:%x:%x:%x:%x", &mac[0],
&snet, &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
&sadr_string[0],
&max_apdu) == 5) {
count = sscanf(mac_string,"%x:%x:%x:%x:%x:%x",
&mac[0],
&mac[1],
&mac[2],
&mac[3],
&mac[4],
&mac[5]);
src.mac_len = count; src.mac_len = count;
for (index = 0; index < MAX_MAC_LEN; index++) { for (index = 0; index < MAX_MAC_LEN; index++) {
src.mac[index] = mac[index]; src.mac[index] = mac[index];
} }
src.net = snet; src.net = snet;
if (snet) { if (snet) {
count = sscanf(sadr_string,"%x:%x:%x:%x:%x:%x", count =
&mac[0], sscanf(sadr_string, "%x:%x:%x:%x:%x:%x", &mac[0],
&mac[1], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
&mac[2],
&mac[3],
&mac[4],
&mac[5]);
src.len = count; src.len = count;
for (index = 0; index < MAX_MAC_LEN; index++) { for (index = 0; index < MAX_MAC_LEN; index++) {
src.adr[index] = mac[index]; src.adr[index] = mac[index];
@@ -374,15 +361,15 @@ static void set_file_address(
uint16_t max_apdu) uint16_t max_apdu)
{ {
unsigned i; unsigned i;
FILE * pFile = NULL; FILE *pFile = NULL;
pFile = fopen(pFilename,"w"); pFile = fopen(pFilename, "w");
if (pFile) { if (pFile) {
fprintf(pFile, "%lu ", (long unsigned int)device_id); fprintf(pFile, "%lu ", (long unsigned int) device_id);
for (i = 0; i < dest->mac_len; i++) { for (i = 0; i < dest->mac_len; i++) {
fprintf(pFile, "%02x", dest->mac[i]); fprintf(pFile, "%02x", dest->mac[i]);
if ((i+1) < dest->mac_len) { if ((i + 1) < dest->mac_len) {
fprintf(pFile, ":"); fprintf(pFile, ":");
} }
} }
@@ -390,7 +377,7 @@ static void set_file_address(
if (dest->net) { if (dest->net) {
for (i = 0; i < dest->len; i++) { for (i = 0; i < dest->len; i++) {
fprintf(pFile, "%02x", dest->adr[i]); fprintf(pFile, "%02x", dest->adr[i]);
if ((i+1) < dest->len) { if ((i + 1) < dest->len) {
fprintf(pFile, ":"); fprintf(pFile, ":");
} }
} }
@@ -405,7 +392,7 @@ static void set_file_address(
void testAddressFile( void testAddressFile(
Test * pTest) Test * pTest)
{ {
BACNET_ADDRESS src = {0}; BACNET_ADDRESS src = { 0 };
uint32_t device_id = 0; uint32_t device_id = 0;
unsigned max_apdu = 480; unsigned max_apdu = 480;
BACNET_ADDRESS test_address; BACNET_ADDRESS test_address;
@@ -422,7 +409,7 @@ void testAddressFile(
address_file_init(Address_Cache_Filename); address_file_init(Address_Cache_Filename);
ct_test(pTest, address_get_by_device(device_id, &test_max_apdu, ct_test(pTest, address_get_by_device(device_id, &test_max_apdu,
&test_address)); &test_address));
ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src)); ct_test(pTest, bacnet_address_same(&test_address, &src));
@@ -443,7 +430,7 @@ void testAddressFile(
address_file_init(Address_Cache_Filename); address_file_init(Address_Cache_Filename);
ct_test(pTest, address_get_by_device(device_id, &test_max_apdu, ct_test(pTest, address_get_by_device(device_id, &test_max_apdu,
&test_address)); &test_address));
ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src)); ct_test(pTest, bacnet_address_same(&test_address, &src));
+7 -7
View File
@@ -39,7 +39,7 @@
#include "bip.h" #include "bip.h"
#include "net.h" /* custom per port */ #include "net.h" /* custom per port */
#if PRINT_ENABLED #if PRINT_ENABLED
#include <stdio.h> /* for standard integer types uint8_t etc. */ #include <stdio.h> /* for standard integer types uint8_t etc. */
#endif #endif
static int BIP_Socket = -1; static int BIP_Socket = -1;
/* port to use - stored in host byte order */ /* port to use - stored in host byte order */
@@ -253,7 +253,7 @@ uint16_t bip_receive(
(sin.sin_port == htons(BIP_Port))) { (sin.sin_port == htons(BIP_Port))) {
pdu_len = 0; pdu_len = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr,"BIP: src is me. Discarded!\n"); fprintf(stderr, "BIP: src is me. Discarded!\n");
#endif #endif
} else { } else {
/* copy the source address - into host format */ /* copy the source address - into host format */
@@ -268,17 +268,17 @@ uint16_t bip_receive(
pdu_len -= 4; pdu_len -= 4;
if (pdu_len < max_pdu) { if (pdu_len < max_pdu) {
#if 0 #if 0
fprintf(stderr,"BIP: NPDU[%hu]:",pdu_len); fprintf(stderr, "BIP: NPDU[%hu]:", pdu_len);
#endif #endif
/* shift the buffer to return a valid PDU */ /* shift the buffer to return a valid PDU */
for (i = 0; i < pdu_len; i++) { for (i = 0; i < pdu_len; i++) {
pdu[i] = pdu[4 + i]; pdu[i] = pdu[4 + i];
#if 0 #if 0
fprintf(stderr,"%02X ",pdu[i]); fprintf(stderr, "%02X ", pdu[i]);
#endif #endif
} }
#if 0 #if 0
fprintf(stderr,"\n"); fprintf(stderr, "\n");
#endif #endif
} }
/* ignore packets that are too large */ /* ignore packets that are too large */
@@ -286,13 +286,13 @@ uint16_t bip_receive(
else { else {
pdu_len = 0; pdu_len = 0;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr,"BIP: PDU too large. Discarded!.\n"); fprintf(stderr, "BIP: PDU too large. Discarded!.\n");
#endif #endif
} }
} }
} else { } else {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr,"BIP: BVLC discarded!\n"); fprintf(stderr, "BIP: BVLC discarded!\n");
#endif #endif
} }
+19 -23
View File
@@ -278,7 +278,7 @@ int bvlc_encode_read_bdt_ack(
int bvlc_encode_forwarded_npdu( int bvlc_encode_forwarded_npdu(
uint8_t * pdu, uint8_t * pdu,
struct sockaddr_in *sin, /* source address in network order */ struct sockaddr_in *sin, /* source address in network order */
uint8_t * npdu, uint8_t * npdu,
unsigned npdu_length) unsigned npdu_length)
{ {
@@ -298,9 +298,7 @@ int bvlc_encode_forwarded_npdu(
len = 4; len = 4;
address.s_addr = ntohl(sin->sin_addr.s_addr); address.s_addr = ntohl(sin->sin_addr.s_addr);
port = ntohs(sin->sin_port); port = ntohs(sin->sin_port);
len += bvlc_encode_bip_address(&pdu[len], len += bvlc_encode_bip_address(&pdu[len], &address, port);
&address,
port);
for (i = 0; i < npdu_length; i++) { for (i = 0; i < npdu_length; i++) {
pdu[len] = npdu[i]; pdu[len] = npdu[i];
len++; len++;
@@ -503,8 +501,8 @@ int bvlc_encode_original_broadcast_npdu(
/* FIXME: IPv6? */ /* FIXME: IPv6? */
void bvlc_internet_to_bacnet_address( 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 address in network order */ struct sockaddr_in *sin)
{ { /* source address in network order */
int len = 0; int len = 0;
uint32_t address; uint32_t address;
uint16_t port; uint16_t port;
@@ -525,7 +523,7 @@ void bvlc_internet_to_bacnet_address(
/* copy the source internet address to the BACnet address */ /* copy the source internet address to the BACnet address */
/* FIXME: IPv6? */ /* FIXME: IPv6? */
void bvlc_bacnet_to_internet_address( void bvlc_bacnet_to_internet_address(
struct sockaddr_in *sin, /* source address in network order */ struct sockaddr_in *sin, /* source address in network order */
BACNET_ADDRESS * src) BACNET_ADDRESS * src)
{ /* returns the BACnet source address */ { /* returns the BACnet source address */
int len = 0; int len = 0;
@@ -582,7 +580,7 @@ bool bvlc_create_bdt(
} }
bool bvlc_register_foreign_device( bool bvlc_register_foreign_device(
struct sockaddr_in * sin, /* source address in network order */ struct sockaddr_in * sin, /* source address in network order */
uint16_t time_to_live) uint16_t time_to_live)
{ /* time in seconds */ { /* time in seconds */
unsigned i = 0; unsigned i = 0;
@@ -644,8 +642,8 @@ bool bvlc_delete_foreign_device(
int bvlc_send_mpdu( int bvlc_send_mpdu(
struct sockaddr_in *dest, /* the destination address */ struct sockaddr_in *dest, /* the destination address */
uint8_t * mtu, /* the data */ uint8_t * mtu, /* the data */
uint16_t mtu_len) /* amount of data to send */ uint16_t mtu_len)
{ { /* amount of data to send */
struct sockaddr_in bvlc_dest; struct sockaddr_in bvlc_dest;
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
@@ -705,8 +703,8 @@ void bvlc_bdt_forward_npdu(
void bvlc_broadcast_forward_npdu( void bvlc_broadcast_forward_npdu(
struct sockaddr_in *sin, /* the source address */ struct sockaddr_in *sin, /* the source address */
uint8_t * npdu, /* returns the NPDU */ uint8_t * npdu, /* returns the NPDU */
uint16_t npdu_len) /* size of the NPDU */ uint16_t npdu_len)
{ { /* size of the NPDU */
uint8_t mtu[MAX_MPDU] = { 0 }; uint8_t mtu[MAX_MPDU] = { 0 };
int mtu_len = 0; int mtu_len = 0;
struct sockaddr_in bvlc_dest; struct sockaddr_in bvlc_dest;
@@ -752,7 +750,7 @@ void bvlc_fdt_forward_npdu(
} }
void bvlc_register_with_bbmd( void bvlc_register_with_bbmd(
long bbmd_address, /* in network byte order */ long bbmd_address, /* in network byte order */
uint16_t bbmd_port, /* in host byte order */ uint16_t bbmd_port, /* in host byte order */
uint16_t time_to_live_seconds) uint16_t time_to_live_seconds)
{ {
@@ -765,9 +763,8 @@ void bvlc_register_with_bbmd(
we need to register our address with the remote BBMD using we need to register our address with the remote BBMD using
Write Broadcast Distribution Table, or Write Broadcast Distribution Table, or
register with the BBMD as a Foreign Device */ register with the BBMD as a Foreign Device */
mtu_len = bvlc_encode_register_foreign_device( mtu_len =
&mtu[0], bvlc_encode_register_foreign_device(&mtu[0], time_to_live_seconds);
time_to_live_seconds);
bvlc_send_mpdu(&Remote_BBMD, &mtu[0], mtu_len); bvlc_send_mpdu(&Remote_BBMD, &mtu[0], mtu_len);
} }
@@ -813,8 +810,8 @@ int bvlc_send_fdt(
} }
static bool bvlc_address_same( static bool bvlc_address_same(
struct sockaddr_in * sin) /* network order address */ struct sockaddr_in *sin)
{ { /* network order address */
bool same = false; bool same = false;
if ((sin->sin_addr.s_addr == htonl(bip_get_addr())) && if ((sin->sin_addr.s_addr == htonl(bip_get_addr())) &&
@@ -958,17 +955,16 @@ uint16_t bvlc_receive(
broadcast address. The method by which a BBMD determines whether broadcast address. The method by which a BBMD determines whether
or not other BACnet devices are present is a local matter. */ or not other BACnet devices are present is a local matter. */
/* decode the 4 byte original address and 2 byte port */ /* decode the 4 byte original address and 2 byte port */
bvlc_decode_bip_address(&npdu[4], bvlc_decode_bip_address(&npdu[4], &original_sin.sin_addr,
&original_sin.sin_addr,
&original_sin.sin_port); &original_sin.sin_port);
npdu_len -= 6; npdu_len -= 6;
/* Broadcast it if this was received via unicast */ /* Broadcast it if this was received via unicast */
if (bvlc_address_same(&sin)) { if (bvlc_address_same(&sin)) {
dest.sin_addr.s_addr = htonl(bip_get_broadcast_addr()); dest.sin_addr.s_addr = htonl(bip_get_broadcast_addr());
dest.sin_port = htons(bip_get_port()); dest.sin_port = htons(bip_get_port());
bvlc_send_mpdu(&dest, &npdu[4+6], npdu_len); bvlc_send_mpdu(&dest, &npdu[4 + 6], npdu_len);
} }
bvlc_fdt_forward_npdu(&sin, &npdu[4+6], npdu_len); bvlc_fdt_forward_npdu(&sin, &npdu[4 + 6], npdu_len);
/* use the original addr from the BVLC for src */ /* use the original addr from the BVLC for src */
dest.sin_addr.s_addr = htonl(original_sin.sin_addr.s_addr); dest.sin_addr.s_addr = htonl(original_sin.sin_addr.s_addr);
dest.sin_port = htons(original_sin.sin_port); dest.sin_port = htons(original_sin.sin_port);
@@ -976,7 +972,7 @@ uint16_t bvlc_receive(
if (npdu_len < max_npdu) { if (npdu_len < max_npdu) {
/* shift the buffer to return a valid PDU */ /* shift the buffer to return a valid PDU */
for (i = 0; i < npdu_len; i++) { for (i = 0; i < npdu_len; i++) {
npdu[i] = npdu[4+6+i]; npdu[i] = npdu[4 + 6 + i];
} }
} else { } else {
/* ignore packets that are too large */ /* ignore packets that are too large */
+8 -6
View File
@@ -37,20 +37,22 @@
#if !defined(__BORLANDC__) && !defined(_MSC_VER) #if !defined(__BORLANDC__) && !defined(_MSC_VER)
#include <ctype.h> #include <ctype.h>
int stricmp(const char *s1, const char *s2) int stricmp(
const char *s1,
const char *s2)
{ {
unsigned char c1,c2; unsigned char c1, c2;
do { do {
c1 = *s1; c1 = *s1;
c2 = *s2; c2 = *s2;
c1 = (unsigned char) tolower( (unsigned char) c1); c1 = (unsigned char) tolower((unsigned char) c1);
c2 = (unsigned char) tolower( (unsigned char) c2); c2 = (unsigned char) tolower((unsigned char) c2);
s1++; s1++;
s2++; s2++;
} while((c1 == c2) && (c1 != '\0')); } while ((c1 == c2) && (c1 != '\0'));
return (int) c1-c2; return (int) c1 - c2;
} }
#endif #endif
+9 -17
View File
@@ -1362,25 +1362,17 @@ mstp_port->ReceivedValidFrame = false; break; default:
ct_test(pTest, mstp_port.ReceivedValidFrame == false); ct_test(pTest, mstp_port.ReceivedValidFrame == false);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
/* Data */ /* Data */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false; memset(data, 0, sizeof(data));
memset(data, 0, sizeof(data)); len =
len = MSTP_Create_Frame(buffer, MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN,
sizeof(buffer), my_mac, my_mac, data, sizeof(data)); ct_test(pTest, len > 0);
FRAME_TYPE_PROPRIETARY_MIN, Load_Input_Buffer(buffer, len); RS485_Check_UART_Data(&mstp_port);
my_mac,
my_mac,
data,
sizeof(data));
ct_test(pTest, len > 0);
Load_Input_Buffer(buffer, len);
RS485_Check_UART_Data(&mstp_port);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) { while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) {
RS485_Check_UART_Data(&mstp_port); RS485_Check_UART_Data(&mstp_port);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);}
} ct_test(pTest, mstp_port.DataLength == sizeof(data));
ct_test(pTest, mstp_port.DataLength == sizeof(data));
ct_test(pTest, mstp_port.ReceivedInvalidFrame == false); ct_test(pTest, mstp_port.ReceivedInvalidFrame == false);
ct_test(pTest, mstp_port.ReceivedValidFrame == true); ct_test(pTest, mstp_port.ReceivedValidFrame == true);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
+1 -1
View File
@@ -382,7 +382,7 @@ void npdu_handler(
if (npdu_data.network_layer_message) { if (npdu_data.network_layer_message) {
/*FIXME: network layer message received! Handle it! */ /*FIXME: network layer message received! Handle it! */
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr,"NPDU: Network Layer Message discarded!\n"); fprintf(stderr, "NPDU: Network Layer Message discarded!\n");
#endif #endif
} else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) {
/* only handle the version that we know how to handle */ /* only handle the version that we know how to handle */