converted C++ comments using script
This commit is contained in:
@@ -152,7 +152,7 @@ void handler_get_alarm_summary(
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0) {
|
||||
//fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */
|
||||
}
|
||||
#else
|
||||
bytes_sent = bytes_sent;
|
||||
|
||||
@@ -21,9 +21,9 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
#include "bacint.h"
|
||||
|
||||
#ifdef TEST_PACKET
|
||||
uint8_t test_packet[]={0x81, 0x0a, 0x00, 0x16, // BVLC header
|
||||
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, // NPDU
|
||||
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; // APDU
|
||||
uint8_t test_packet[]={0x81, 0x0a, 0x00, 0x16, /* BVLC header */
|
||||
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */
|
||||
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; /* APDU */
|
||||
#endif
|
||||
|
||||
extern int get_local_address_ioctl(
|
||||
@@ -36,18 +36,18 @@ void* dl_ip_thread(void *pArgs) {
|
||||
BACMSG msg_storage, *bacmsg = NULL;
|
||||
MSG_DATA *msg_data;
|
||||
ROUTER_PORT *port = (ROUTER_PORT*)pArgs;
|
||||
IP_DATA ip_data; // port specific parameters
|
||||
IP_DATA ip_data; /* port specific parameters */
|
||||
BACNET_ADDRESS address = { 0 };
|
||||
int status;
|
||||
uint8_t shutdown = 0;
|
||||
|
||||
// initialize router port
|
||||
/* initialize router port */
|
||||
if (!dl_ip_init(port, &ip_data)) {
|
||||
port->state = INIT_FAILED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// allocate buffer
|
||||
/* allocate buffer */
|
||||
ip_data.max_buff = MAX_BIP_MPDU;
|
||||
ip_data.buff = (uint8_t*)malloc(ip_data.max_buff);
|
||||
|
||||
@@ -68,7 +68,7 @@ void* dl_ip_thread(void *pArgs) {
|
||||
|
||||
while (!shutdown) {
|
||||
|
||||
// check for incoming messages
|
||||
/* check for incoming messages */
|
||||
bacmsg = recv_from_msgbox(port->port_id, &msg_storage);
|
||||
|
||||
if (bacmsg) {
|
||||
@@ -117,7 +117,7 @@ void* dl_ip_thread(void *pArgs) {
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup procedure
|
||||
/* cleanup procedure */
|
||||
dl_ip_cleanup(&ip_data);
|
||||
port->state = FINISHED;
|
||||
return NULL;
|
||||
@@ -127,17 +127,17 @@ bool dl_ip_init(ROUTER_PORT *port,
|
||||
IP_DATA *ip_data) {
|
||||
struct sockaddr_in sin;
|
||||
int socket_opt = 0;
|
||||
int status = 0; // for error checking
|
||||
int status = 0; /* for error checking */
|
||||
|
||||
// setup port for later use
|
||||
/* setup port for later use */
|
||||
ip_data->port = htons(port->params.bip_params.port);
|
||||
|
||||
// get local address
|
||||
/* get local address */
|
||||
status = get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR);
|
||||
if (status < 0) {
|
||||
return false;
|
||||
}
|
||||
// get broadcast address
|
||||
/* get broadcast address */
|
||||
status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, SIOCGIFBRDADDR);
|
||||
if (status < 0) {
|
||||
return false;
|
||||
@@ -147,7 +147,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
||||
if (ip_data->socket < 0)
|
||||
return false;
|
||||
|
||||
// setup socket options
|
||||
/* setup socket options */
|
||||
|
||||
socket_opt = 1;
|
||||
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, sizeof(socket_opt));
|
||||
@@ -162,7 +162,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
||||
return false;
|
||||
}
|
||||
|
||||
// bind the socket to the local port number
|
||||
/* bind the socket to the local port number */
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_port = ip_data->port;
|
||||
@@ -175,7 +175,7 @@ bool dl_ip_init(ROUTER_PORT *port,
|
||||
return false;
|
||||
}
|
||||
|
||||
// add BIP address to router port structure
|
||||
/* add BIP address to router port structure */
|
||||
memcpy(&port->route_info.mac[0], &ip_data->local_addr.s_addr, 4);
|
||||
memcpy(&port->route_info.mac[4], &port->params.bip_params.port, 2);
|
||||
port->route_info.mac_len = 6;
|
||||
@@ -204,7 +204,7 @@ int dl_ip_send(IP_DATA *data,
|
||||
data->buff[0] = BVLL_TYPE_BACNET_IP;
|
||||
bip_dest.sin_family = AF_INET;
|
||||
if (dest->net == BACNET_BROADCAST_NETWORK) {
|
||||
// broadcast
|
||||
/* broadcast */
|
||||
bip_dest.sin_addr.s_addr = data->broadcast_addr.s_addr;
|
||||
bip_dest.sin_port = data->port;
|
||||
data->buff[1] = BVLC_ORIGINAL_BROADCAST_NPDU;
|
||||
@@ -213,7 +213,7 @@ int dl_ip_send(IP_DATA *data,
|
||||
memcpy(&bip_dest.sin_port, &dest->mac[4], 2);
|
||||
data->buff[1] = BVLC_ORIGINAL_UNICAST_NPDU;
|
||||
} else {
|
||||
// invalid address
|
||||
/* invalid address */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ int dl_ip_send(IP_DATA *data,
|
||||
memcpy(&data->buff[buff_len], pdu, pdu_len);
|
||||
buff_len += pdu_len;
|
||||
|
||||
// send the packet
|
||||
/* send the packet */
|
||||
bytes_sent =
|
||||
sendto(data->socket, (char *) data->buff, buff_len, 0,
|
||||
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
|
||||
@@ -241,13 +241,13 @@ int dl_ip_recv(
|
||||
unsigned timeout)
|
||||
{
|
||||
int received_bytes = 0;
|
||||
uint16_t buff_len = 0; // return value
|
||||
uint16_t buff_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
struct timeval select_timeout;
|
||||
struct sockaddr_in sin = { 0 };
|
||||
socklen_t sin_len = sizeof(sin);
|
||||
|
||||
// make sure the socket is open
|
||||
/* make sure the socket is open */
|
||||
if (data->socket < 0)
|
||||
return 0;
|
||||
|
||||
@@ -268,7 +268,7 @@ int dl_ip_recv(
|
||||
sin.sin_addr.s_addr = 0x7E1D40A; sin.sin_port = 0xC0BA;
|
||||
#else
|
||||
int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
|
||||
// see if there is a packet for us
|
||||
/* see if there is a packet for us */
|
||||
if (ret > 0)
|
||||
received_bytes =
|
||||
recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0,
|
||||
@@ -278,12 +278,12 @@ int dl_ip_recv(
|
||||
#endif
|
||||
PRINT(DEBUG, "received from %s\n", inet_ntoa(sin.sin_addr));
|
||||
|
||||
// check for errors
|
||||
/* check for errors */
|
||||
if (received_bytes <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the signature of a BACnet/IP packet
|
||||
/* the signature of a BACnet/IP packet */
|
||||
if (data->buff[0] != BVLL_TYPE_BACNET_IP)
|
||||
return 0;
|
||||
|
||||
@@ -302,18 +302,18 @@ int dl_ip_recv(
|
||||
memcpy(&src->mac[4], &sin.sin_port, 2);
|
||||
|
||||
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
||||
// subtract off the BVLC header
|
||||
/* subtract off the BVLC header */
|
||||
buff_len -= 4;
|
||||
if (buff_len < data->max_buff) {
|
||||
// allocate data message stucture
|
||||
/* allocate data message stucture */
|
||||
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
||||
(*msg_data)->pdu_len = buff_len;
|
||||
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
||||
// fill up data message structure
|
||||
/* fill up data message structure */
|
||||
memmove(&(*msg_data)->pdu[0], &data->buff[4], (*msg_data)->pdu_len);
|
||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||
}
|
||||
// ignore packets that are too large
|
||||
/* ignore packets that are too large */
|
||||
else {
|
||||
buff_len = 0;
|
||||
|
||||
@@ -336,18 +336,18 @@ int dl_ip_recv(
|
||||
memcpy(&src->mac[4], &sin.sin_port, 2);
|
||||
|
||||
(void) decode_unsigned16(&data->buff[2], &buff_len);
|
||||
// subtract off the BVLC header
|
||||
/* subtract off the BVLC header */
|
||||
buff_len -= 10;
|
||||
if (buff_len < data->max_buff) {
|
||||
// allocate data message stucture
|
||||
/* allocate data message stucture */
|
||||
(*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA));
|
||||
(*msg_data)->pdu_len = buff_len;
|
||||
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len);
|
||||
// fill up data message structure
|
||||
/* fill up data message structure */
|
||||
memmove(&(*msg_data)->pdu, &data->buff[4+6], (*msg_data)->pdu_len);
|
||||
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS));
|
||||
} else {
|
||||
// ignore packets that are too large
|
||||
/* ignore packets that are too large */
|
||||
buff_len = 0;
|
||||
}
|
||||
}
|
||||
@@ -364,10 +364,10 @@ int dl_ip_recv(
|
||||
|
||||
void dl_ip_cleanup(
|
||||
IP_DATA *ip_data) {
|
||||
// free buffer
|
||||
/* free buffer */
|
||||
if (ip_data->buff)
|
||||
free(ip_data->buff);
|
||||
// close socket
|
||||
/* close socket */
|
||||
if (ip_data->socket > 0)
|
||||
close(ip_data->socket);
|
||||
return;
|
||||
|
||||
@@ -51,7 +51,7 @@ int dl_ip_send(
|
||||
|
||||
int dl_ip_recv(
|
||||
IP_DATA *data,
|
||||
MSG_DATA **msg, // on recieve fill up message
|
||||
MSG_DATA **msg, /* on recieve fill up message */
|
||||
BACNET_ADDRESS *src,
|
||||
unsigned timeout);
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h> // for time
|
||||
#include <time.h> /* for time */
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <libconfig.h> // read config files
|
||||
#include <unistd.h> // for getopt
|
||||
#include <termios.h> // used in kbhit()
|
||||
#include <libconfig.h> /* read config files */
|
||||
#include <unistd.h> /* for getopt */
|
||||
#include <termios.h> /* used in kbhit() */
|
||||
#include <getopt.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
@@ -42,7 +42,7 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
|
||||
|
||||
#define KEY_ESC 27
|
||||
|
||||
ROUTER_PORT *head = NULL; // pointer to list of router ports
|
||||
ROUTER_PORT *head = NULL; /* pointer to list of router ports */
|
||||
|
||||
int port_count;
|
||||
|
||||
@@ -122,7 +122,7 @@ int main(
|
||||
{
|
||||
MSGBOX_ID msg_src = bacmsg->origin;
|
||||
|
||||
// allocate message structure
|
||||
/* allocate message structure */
|
||||
msg_data = malloc(sizeof(MSG_DATA));
|
||||
if (!msg_data) {
|
||||
PRINT(ERROR, "Error: Could not allocate memory\n");
|
||||
@@ -141,13 +141,13 @@ int main(
|
||||
buff_len = process_msg(bacmsg, msg_data, &buff);
|
||||
}
|
||||
|
||||
// if buff_len
|
||||
// >0 - form new message and send
|
||||
// =-1 - try to find next router
|
||||
// other value - discard message
|
||||
/* if buff_len */
|
||||
/* >0 - form new message and send */
|
||||
/* =-1 - try to find next router */
|
||||
/* other value - discard message */
|
||||
|
||||
if (buff_len > 0) {
|
||||
// form new message
|
||||
/* form new message */
|
||||
msg_data->pdu = buff;
|
||||
msg_data->pdu_len = buff_len;
|
||||
msg_storage.origin = head->main_id;
|
||||
@@ -176,11 +176,11 @@ int main(
|
||||
}
|
||||
}
|
||||
} else if (buff_len == -1) {
|
||||
uint16_t net = msg_data->dest.net; // NET to find
|
||||
uint16_t net = msg_data->dest.net; /* NET to find */
|
||||
PRINT(INFO, "Searching NET...\n");
|
||||
send_network_message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, &buff, &net);
|
||||
} else {
|
||||
// if invalid message send Reject-Message-To-Network
|
||||
/* if invalid message send Reject-Message-To-Network */
|
||||
PRINT(ERROR, "Error: Invalid message\n");
|
||||
free_data(msg_data);
|
||||
}
|
||||
@@ -223,20 +223,20 @@ bool read_config(
|
||||
|
||||
config_init(&cfg);
|
||||
|
||||
// open configuration file
|
||||
/* open configuration file */
|
||||
if (!config_read_file(&cfg, filepath)) {
|
||||
PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get router "port" count
|
||||
/* get router "port" count */
|
||||
setting = config_lookup(&cfg, "ports");
|
||||
if (setting != NULL) {
|
||||
int count = config_setting_length(setting);
|
||||
int i;
|
||||
|
||||
// lookup and initialize router "port" parameters
|
||||
/* lookup and initialize router "port" parameters */
|
||||
for (i = 0; i < count; i++) {
|
||||
const char *dev_type;
|
||||
const char *iface;
|
||||
@@ -244,7 +244,7 @@ bool read_config(
|
||||
const char *str_param;
|
||||
config_setting_t *port = config_setting_get_elem(setting, i);
|
||||
|
||||
// create new list node to store port information
|
||||
/* create new list node to store port information */
|
||||
if (head == NULL) {
|
||||
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
||||
head->next = NULL;
|
||||
@@ -268,7 +268,7 @@ bool read_config(
|
||||
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
||||
strcpy(current->iface, iface);
|
||||
|
||||
// check if interface is valid
|
||||
/* check if interface is valid */
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd) {
|
||||
struct ifreq ifr;
|
||||
@@ -306,7 +306,7 @@ bool read_config(
|
||||
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char));
|
||||
strcpy(current->iface, iface);
|
||||
|
||||
// check if interface is valid
|
||||
/* check if interface is valid */
|
||||
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
@@ -421,7 +421,7 @@ bool parse_cmd(
|
||||
if (argc < 2)
|
||||
print_help();
|
||||
|
||||
// begin checking cmd parameters
|
||||
/* begin checking cmd parameters */
|
||||
opt = getopt_long(argc, argv, optString, Options, &index);
|
||||
printf("opt = %c\r\n", opt);
|
||||
while (opt != -1) {
|
||||
@@ -435,7 +435,7 @@ bool parse_cmd(
|
||||
break;
|
||||
case 'D':
|
||||
|
||||
// create new list node to store port information
|
||||
/* create new list node to store port information */
|
||||
if (head == NULL) {
|
||||
head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT));
|
||||
head->next = NULL;
|
||||
@@ -458,11 +458,11 @@ bool parse_cmd(
|
||||
current->iface = "eth0";
|
||||
}
|
||||
|
||||
// setup default parameters
|
||||
current->params.bip_params.port = 0xBAC0; // 47808
|
||||
/* setup default parameters */
|
||||
current->params.bip_params.port = 0xBAC0; /* 47808 */
|
||||
current->route_info.net = get_next_free_dnet();
|
||||
|
||||
// check if interface is valid
|
||||
/* check if interface is valid */
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd) {
|
||||
struct ifreq ifr;
|
||||
@@ -484,7 +484,7 @@ bool parse_cmd(
|
||||
if (result) {
|
||||
current->params.bip_params.port = (uint16_t)result;
|
||||
} else {
|
||||
current->params.bip_params.port = 0xBAC0; // 47808
|
||||
current->params.bip_params.port = 0xBAC0; /* 47808 */
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
@@ -508,7 +508,7 @@ bool parse_cmd(
|
||||
current->iface = "/dev/ttyS0";
|
||||
}
|
||||
|
||||
// check if interface is valid
|
||||
/* check if interface is valid */
|
||||
fd = open(current->iface, O_NOCTTY | O_NONBLOCK);
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
@@ -517,7 +517,7 @@ bool parse_cmd(
|
||||
return false;
|
||||
}
|
||||
|
||||
// setup default parameters
|
||||
/* setup default parameters */
|
||||
current->route_info.mac[0] = 127;
|
||||
current->route_info.mac_len = 1;
|
||||
current->params.mstp_params.max_master = 127;
|
||||
@@ -619,7 +619,7 @@ void init_port_threads(
|
||||
port->func,
|
||||
port);
|
||||
|
||||
pthread_detach(*thread); // for proper thread termination
|
||||
pthread_detach(*thread); /* for proper thread termination */
|
||||
|
||||
port = port->next;
|
||||
}
|
||||
@@ -634,7 +634,7 @@ bool init_router() {
|
||||
return false;
|
||||
|
||||
port = head;
|
||||
// add main message box id to all ports
|
||||
/* add main message box id to all ports */
|
||||
while (port != NULL) {
|
||||
port->main_id = msgboxid;
|
||||
port = port->next;
|
||||
@@ -642,7 +642,7 @@ bool init_router() {
|
||||
|
||||
init_port_threads(head);
|
||||
|
||||
// wait for port initialization
|
||||
/* wait for port initialization */
|
||||
port = head;
|
||||
while (port != NULL) {
|
||||
if (port->state == RUNNING) {
|
||||
@@ -672,9 +672,9 @@ void cleanup() {
|
||||
msg.type = SERVICE;
|
||||
msg.subtype = SHUTDOWN;
|
||||
|
||||
del_msgbox(head->main_id); // close routers message box
|
||||
del_msgbox(head->main_id); /* close routers message box */
|
||||
|
||||
// send shutdown message to all router ports
|
||||
/* send shutdown message to all router ports */
|
||||
port = head;
|
||||
while (port != NULL) {
|
||||
if (port->state == RUNNING)
|
||||
@@ -736,11 +736,11 @@ uint16_t process_msg(BACMSG *msg,
|
||||
if (srcport && destport) {
|
||||
data->src.net = srcport->route_info.net;
|
||||
|
||||
// if received from another router save real source address (not other router source address)
|
||||
/* if received from another router save real source address (not other router source address) */
|
||||
if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net)
|
||||
memmove(&data->src, &addr, sizeof(BACNET_ADDRESS));
|
||||
|
||||
// encode both source and destination for broadcast and router-to-router communication
|
||||
/* encode both source and destination for broadcast and router-to-router communication */
|
||||
if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) {
|
||||
npdu_len = npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data);
|
||||
}
|
||||
@@ -751,15 +751,15 @@ uint16_t process_msg(BACMSG *msg,
|
||||
buff_len = npdu_len + data->pdu_len - apdu_offset;
|
||||
|
||||
*buff = (uint8_t*)malloc(buff_len);
|
||||
memmove(*buff, npdu, npdu_len); // copy newly formed NPDU
|
||||
memmove(*buff+npdu_len, &data->pdu[apdu_offset], apdu_len); // copy APDU
|
||||
memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */
|
||||
memmove(*buff+npdu_len, &data->pdu[apdu_offset], apdu_len); /* copy APDU */
|
||||
|
||||
} else {
|
||||
// request net search
|
||||
/* request net search */
|
||||
return -1;
|
||||
}
|
||||
|
||||
// delete received message
|
||||
/* delete received message */
|
||||
free_data((MSG_DATA*)msg->data);
|
||||
|
||||
return buff_len;
|
||||
@@ -771,7 +771,7 @@ int kbhit()
|
||||
static bool initialized = false;
|
||||
|
||||
if (! initialized) {
|
||||
// use termios to turn off line buffering
|
||||
/* use termios to turn off line buffering */
|
||||
struct termios term;
|
||||
tcgetattr(STDIN, &term);
|
||||
term.c_lflag &= ~ICANON;
|
||||
@@ -787,12 +787,12 @@ int kbhit()
|
||||
|
||||
bool is_network_msg(BACMSG *msg) {
|
||||
|
||||
uint8_t control_byte; // NPDU control byte
|
||||
uint8_t control_byte; /* NPDU control byte */
|
||||
MSG_DATA *data = (MSG_DATA*)msg->data;
|
||||
|
||||
control_byte = data->pdu[1];
|
||||
|
||||
return control_byte & 0x80; // check 7th bit
|
||||
return control_byte & 0x80; /* check 7th bit */
|
||||
}
|
||||
|
||||
uint16_t get_next_free_dnet() {
|
||||
|
||||
@@ -86,7 +86,7 @@ void free_data(
|
||||
void check_data(
|
||||
MSG_DATA *data) {
|
||||
|
||||
// lock and decrement messages reference count
|
||||
/* lock and decrement messages reference count */
|
||||
pthread_mutex_lock(&msg_lock);
|
||||
if (--data->ref_count == 0) {
|
||||
free_data(data);
|
||||
|
||||
@@ -47,10 +47,10 @@ typedef struct _message {
|
||||
MSGTYPE type;
|
||||
MSGSUBTYPE subtype;
|
||||
void *data;
|
||||
// add timestamp
|
||||
/* add timestamp */
|
||||
} BACMSG;
|
||||
|
||||
// specific message type data structures
|
||||
/* specific message type data structures */
|
||||
typedef struct _msg_data {
|
||||
BACNET_ADDRESS dest;
|
||||
BACNET_ADDRESS src;
|
||||
@@ -61,12 +61,12 @@ typedef struct _msg_data {
|
||||
|
||||
MSGBOX_ID create_msgbox();
|
||||
|
||||
// returns sent byte count
|
||||
/* returns sent byte count */
|
||||
bool send_to_msgbox(
|
||||
MSGBOX_ID dest,
|
||||
BACMSG *msg);
|
||||
|
||||
// returns received message
|
||||
/* returns received message */
|
||||
BACMSG* recv_from_msgbox(
|
||||
MSGBOX_ID src,
|
||||
BACMSG *msg);
|
||||
@@ -74,11 +74,11 @@ BACMSG* recv_from_msgbox(
|
||||
void del_msgbox(
|
||||
MSGBOX_ID msgboxid);
|
||||
|
||||
// free message data structure
|
||||
/* free message data structure */
|
||||
void free_data(
|
||||
MSG_DATA *data);
|
||||
|
||||
// check message reference counter and delete data if needed
|
||||
/* check message reference counter and delete data if needed */
|
||||
void check_data(
|
||||
MSG_DATA *data);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ void* dl_mstp_thread(void* pArgs) {
|
||||
port->state = RUNNING;
|
||||
|
||||
while (!shutdown) {
|
||||
// message loop
|
||||
/* message loop */
|
||||
BACMSG msg_storage, * bacmsg;
|
||||
MSG_DATA * msg_data;
|
||||
|
||||
|
||||
@@ -47,25 +47,25 @@ uint16_t process_network_message(
|
||||
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
||||
PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n");
|
||||
if (apdu_len) {
|
||||
// if NET specified
|
||||
/* if NET specified */
|
||||
decode_unsigned16(&data->pdu[apdu_offset], &net);
|
||||
if (srcport->route_info.net == net) {
|
||||
PRINT(INFO, "Message discarded: NET directly connected\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
destport = find_dnet(net, NULL); // see if NET can be reached
|
||||
destport = find_dnet(net, NULL); /* see if NET can be reached */
|
||||
if (destport) {
|
||||
// if TRUE send reply
|
||||
/* if TRUE send reply */
|
||||
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
||||
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||
data, buff, &net);
|
||||
} else {
|
||||
data->dest.net = net; // NET to look for
|
||||
return -1; // else initiate NET search procedure
|
||||
data->dest.net = net; /* NET to look for */
|
||||
return -1; /* else initiate NET search procedure */
|
||||
}
|
||||
} else {
|
||||
// if NET is omitted (message sent with -1)
|
||||
/* if NET is omitted (message sent with -1) */
|
||||
PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
|
||||
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||
data, buff, NULL);
|
||||
@@ -79,15 +79,15 @@ uint16_t process_network_message(
|
||||
int net_count = apdu_len / 2;
|
||||
int i;
|
||||
for (i = 0; i < net_count; i++) {
|
||||
decode_unsigned16(&data->pdu[apdu_offset+2*i], &net); // decode received NET values
|
||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
||||
decode_unsigned16(&data->pdu[apdu_offset+2*i], &net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
||||
{
|
||||
// first octet of the message contains rejection reason
|
||||
// next two octets contain NET (can be decoded for additional info on error)
|
||||
/* first octet of the message contains rejection reason */
|
||||
/* next two octets contain NET (can be decoded for additional info on error) */
|
||||
error_code = data->pdu[apdu_offset];
|
||||
switch (error_code) {
|
||||
case 0:
|
||||
@@ -114,9 +114,9 @@ uint16_t process_network_message(
|
||||
int net_count = data->pdu[apdu_offset];
|
||||
while (net_count--) {
|
||||
int i = 1;
|
||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); // decode received NET values
|
||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
||||
if (data->pdu[apdu_offset+i+3] > 0) // find next NET value
|
||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||
if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */
|
||||
i = data->pdu[apdu_offset+i+3] + 4;
|
||||
else
|
||||
i = i + 4;
|
||||
@@ -132,9 +132,9 @@ uint16_t process_network_message(
|
||||
int net_count = data->pdu[apdu_offset];
|
||||
while (net_count--) {
|
||||
int i = 1;
|
||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); // decode received NET values
|
||||
add_dnet(&srcport->route_info, net, data->src); // and update routing table
|
||||
if (data->pdu[apdu_offset+i+3] > 0) // find next NET value
|
||||
decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */
|
||||
add_dnet(&srcport->route_info, net, data->src); /* and update routing table */
|
||||
if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */
|
||||
i = data->pdu[apdu_offset+i+3] + 4;
|
||||
else
|
||||
i = i + 4;
|
||||
@@ -148,7 +148,7 @@ uint16_t process_network_message(
|
||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
||||
// hell if I know what to do with these messages
|
||||
/* hell if I know what to do with these messages */
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -173,9 +173,9 @@ uint16_t create_network_message(
|
||||
data_expecting_reply = true;
|
||||
init_npdu(&npdu_data, network_message_type, data_expecting_reply);
|
||||
|
||||
*buff = (uint8_t*)malloc(128); // resolve different length
|
||||
*buff = (uint8_t*)malloc(128); /* resolve different length */
|
||||
|
||||
// manual destination setup for Init-RT-Table-Ack message
|
||||
/* manual destination setup for Init-RT-Table-Ack message */
|
||||
data->dest.net = BACNET_BROADCAST_NETWORK;
|
||||
buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data);
|
||||
|
||||
@@ -252,7 +252,7 @@ uint16_t create_network_message(
|
||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK:
|
||||
// hell if I know what to do with these messages
|
||||
/* hell if I know what to do with these messages */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ void send_network_message(
|
||||
|
||||
buff_len = create_network_message(network_message_type, data, buff, val);
|
||||
|
||||
// form network message
|
||||
/* form network message */
|
||||
data->pdu = *buff;
|
||||
data->pdu_len = buff_len;
|
||||
msg.origin = head->main_id;
|
||||
|
||||
@@ -40,17 +40,17 @@ ROUTER_PORT* find_dnet(
|
||||
ROUTER_PORT *port = head;
|
||||
DNET *dnet;
|
||||
|
||||
// for broadcast messages no search is needed
|
||||
/* for broadcast messages no search is needed */
|
||||
if (net == BACNET_BROADCAST_NETWORK)
|
||||
return port;
|
||||
|
||||
while(port != NULL) {
|
||||
|
||||
// check if DNET is directly connected to the router
|
||||
/* check if DNET is directly connected to the router */
|
||||
if (net == port->route_info.net)
|
||||
return port;
|
||||
|
||||
// else search router ports DNET list
|
||||
/* else search router ports DNET list */
|
||||
else if (port->route_info.dnets) {
|
||||
dnet = port->route_info.dnets;
|
||||
while (dnet != NULL) {
|
||||
@@ -88,7 +88,7 @@ void add_dnet(
|
||||
} else {
|
||||
|
||||
while (dnet != NULL) {
|
||||
if (dnet->net == net) // make sure NETs are not repeated
|
||||
if (dnet->net == net) /* make sure NETs are not repeated */
|
||||
return;
|
||||
tmp = dnet;
|
||||
dnet = dnet->next;
|
||||
|
||||
@@ -47,7 +47,7 @@ typedef enum {
|
||||
FINISHED
|
||||
} PORT_STATE;
|
||||
|
||||
// router port thread function
|
||||
/* router port thread function */
|
||||
typedef void* (*PORT_FUNC)(
|
||||
void*);
|
||||
|
||||
@@ -57,7 +57,7 @@ typedef enum {
|
||||
PARITY_ODD
|
||||
}PARITY;
|
||||
|
||||
// port specific parameters
|
||||
/* port specific parameters */
|
||||
typedef union _port_params {
|
||||
struct {
|
||||
uint16_t port;
|
||||
@@ -72,16 +72,16 @@ typedef union _port_params {
|
||||
} mstp_params;
|
||||
} PORT_PARAMS;
|
||||
|
||||
// list node for reacheble networks
|
||||
/* list node for reacheble networks */
|
||||
typedef struct _dnet {
|
||||
uint8_t mac[MAX_MAC_LEN];
|
||||
uint8_t mac_len;
|
||||
uint16_t net;
|
||||
bool state; // enabled or disabled
|
||||
bool state; /* enabled or disabled */
|
||||
struct _dnet *next;
|
||||
} DNET;
|
||||
|
||||
// information for routing table
|
||||
/* information for routing table */
|
||||
typedef struct _routing_table_entry {
|
||||
uint8_t mac[MAX_MAC_LEN];
|
||||
uint8_t mac_len;
|
||||
@@ -92,28 +92,28 @@ typedef struct _routing_table_entry {
|
||||
typedef struct _port {
|
||||
DL_TYPE type;
|
||||
PORT_STATE state;
|
||||
MSGBOX_ID main_id; // same for every router port
|
||||
MSGBOX_ID port_id; // different for every router port
|
||||
MSGBOX_ID main_id; /* same for every router port */
|
||||
MSGBOX_ID port_id; /* different for every router port */
|
||||
char *iface;
|
||||
PORT_FUNC func;
|
||||
RT_ENTRY route_info;
|
||||
PORT_PARAMS params;
|
||||
struct _port *next; // pointer to next list node
|
||||
struct _port *next; /* pointer to next list node */
|
||||
} ROUTER_PORT;
|
||||
|
||||
extern ROUTER_PORT *head;
|
||||
extern int port_count;
|
||||
|
||||
// get recieving router port
|
||||
/* get recieving router port */
|
||||
ROUTER_PORT* find_snet(
|
||||
MSGBOX_ID id);
|
||||
|
||||
// get sending router port
|
||||
/* get sending router port */
|
||||
ROUTER_PORT* find_dnet(
|
||||
uint16_t net,
|
||||
BACNET_ADDRESS *addr);
|
||||
|
||||
// add reacheble network for specified router port
|
||||
/* add reacheble network for specified router port */
|
||||
void add_dnet(
|
||||
RT_ENTRY *route_info,
|
||||
uint16_t net,
|
||||
|
||||
@@ -45,7 +45,7 @@ uint32_t timeGetTime(
|
||||
struct timespec now;
|
||||
uint32_t ticks;
|
||||
|
||||
// clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
/* clock_gettime(CLOCK_MONOTONIC, &now); */
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||
@@ -145,7 +145,7 @@ uint32_t timer_reset(
|
||||
void timer_init(
|
||||
void)
|
||||
{
|
||||
//clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
/*clock_gettime(CLOCK_MONOTONIC, &start); */
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "bacdef.h"
|
||||
#include "bacaddr.h"
|
||||
#include "mstp.h"
|
||||
//#include "dlmstp.h"
|
||||
/*#include "dlmstp.h" */
|
||||
#include "dlmstp_linux.h"
|
||||
#include "rs485.h"
|
||||
#include "npdu.h"
|
||||
@@ -602,7 +602,7 @@ void dlmstp_set_mac_address(
|
||||
void * poPort,
|
||||
uint8_t mac_address)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
@@ -633,7 +633,7 @@ void dlmstp_set_mac_address(
|
||||
uint8_t dlmstp_mac_address(
|
||||
void * poPort)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
@@ -660,7 +660,7 @@ void dlmstp_set_max_info_frames(
|
||||
void * poPort,
|
||||
uint8_t max_info_frames)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
@@ -688,7 +688,7 @@ void dlmstp_set_max_info_frames(
|
||||
uint8_t dlmstp_max_info_frames(
|
||||
void * poPort)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
@@ -713,7 +713,7 @@ void dlmstp_set_max_master(
|
||||
void * poPort,
|
||||
uint8_t max_master)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
@@ -743,7 +743,7 @@ void dlmstp_set_max_master(
|
||||
uint8_t dlmstp_max_master(
|
||||
void * poPort)
|
||||
{
|
||||
// SHARED_MSTP_DATA * poSharedData;
|
||||
/* SHARED_MSTP_DATA * poSharedData; */
|
||||
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort;
|
||||
if(!mstp_port)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define DLMSTP_LINUX_H
|
||||
|
||||
#include "mstp.h"
|
||||
//#include "dlmstp.h"
|
||||
/*#include "dlmstp.h" */
|
||||
#include "bits/pthreadtypes.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
Reference in New Issue
Block a user