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