Indented using indent script. Corrected any C++ comments using the comment script.
This commit is contained in:
+18
-31
@@ -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));
|
||||
|
||||
|
||||
@@ -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
@@ -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 */
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user