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
+6 -9
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
@@ -218,20 +219,16 @@ static void Init_DataLink(void)
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,
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 -14
View File
@@ -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
@@ -387,20 +388,16 @@ static void Init_DataLink(void)
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,
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");
+39 -58
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,7 +138,8 @@ 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 */
@@ -152,28 +149,26 @@ static int cov_encode_subscription(
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;
@@ -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,32 +335,26 @@ 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;
}
@@ -401,8 +384,7 @@ void handler_cov_task(
COV_Subscriptions[index].lifetime -= elapsed_seconds;
#if 0
fprintf(stderr, "COVtask: subscription[%d].lifetime=%d\n",
index,
COV_Subscriptions[index].lifetime);
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;
+16 -11
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;
@@ -166,10 +173,8 @@ void testBACnetObjects(
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++) {
pDevice = objects_device_delete(0);
+6 -8
View File
@@ -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;
+6 -9
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
@@ -273,20 +274,16 @@ static void Init_DataLink(void)
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,
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;
+7 -11
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
@@ -210,20 +211,16 @@ static void Init_DataLink(void)
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,
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 */
+6 -9
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
@@ -213,20 +214,16 @@ static void Init_DataLink(void)
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,
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;
+6 -9
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
@@ -176,20 +177,16 @@ static void Init_DataLink(void)
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,
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;
+6 -9
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
@@ -182,20 +183,16 @@ static void Init_DataLink(void)
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,
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;
+6 -10
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
@@ -143,19 +144,14 @@ static void Init_DataLink(void)
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,
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;
@@ -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);
+6 -9
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
@@ -182,20 +183,16 @@ static void Init_DataLink(void)
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,
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;
+6 -9
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
@@ -218,20 +219,16 @@ static void Init_DataLink(void)
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,
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;
+6 -9
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
@@ -227,20 +228,16 @@ static void Init_DataLink(void)
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,
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;
+7 -11
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
@@ -224,20 +225,16 @@ static void Init_DataLink(void)
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,
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 */
+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
+2 -1
View File
@@ -151,7 +151,8 @@ 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;
+11 -7
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,7 +86,8 @@ 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];
@@ -98,8 +100,7 @@ static uint32_t getIpMaskForIpAddress( uint32_t ipAddress )
/* GetAdapterInfo:
[out] buffer to receive data
[in] size of receive data buffer */
DWORD dwStatus = GetAdaptersInfo(
AdapterInfo,
DWORD dwStatus = GetAdaptersInfo(AdapterInfo,
&dwBufLen);
if (dwStatus == ERROR_SUCCESS) {
/* Verify return value is valid, no buffer overflow
@@ -109,8 +110,10 @@ static uint32_t getIpMaskForIpAddress( uint32_t ipAddress )
do {
IP_ADDR_STRING *pIpAddressInfo = &pAdapterInfo->IpAddressList;
do {
unsigned long adapterAddress = inet_addr(pIpAddressInfo->IpAddress.String);
unsigned long adapterMask = inet_addr(pIpAddressInfo->IpMask.String);
unsigned long adapterAddress =
inet_addr(pIpAddressInfo->IpAddress.String);
unsigned long adapterMask =
inet_addr(pIpAddressInfo->IpMask.String);
if (adapterAddress == ipAddress) {
ipMask = adapterMask;
break;
@@ -131,7 +134,8 @@ static uint32_t getIpMaskForIpAddress( uint32_t ipAddress )
}
#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
+8 -21
View File
@@ -97,33 +97,20 @@ void address_file_init(
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];
+12 -16
View File
@@ -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;
@@ -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;
@@ -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,8 +955,7 @@ 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 */
+3 -1
View File
@@ -37,7 +37,9 @@
#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;
+6 -14
View File
@@ -1363,23 +1363,15 @@ mstp_port->ReceivedValidFrame = false; break; default:
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.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);
}
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);