changed c++ comments to c comments using comment.sh script.
This commit is contained in:
@@ -37,13 +37,13 @@
|
||||
#include "arcnet.h"
|
||||
#include "net.h"
|
||||
|
||||
// my local device data - MAC address
|
||||
/* my local device data - MAC address */
|
||||
uint8_t ARCNET_MAC_Address = 0;
|
||||
// ARCNET file handle
|
||||
/* ARCNET file handle */
|
||||
static int ARCNET_Sock_FD = -1;
|
||||
// ARCNET socket address (has the interface name)
|
||||
/* ARCNET socket address (has the interface name) */
|
||||
static struct sockaddr ARCNET_Socket_Address;
|
||||
// Broadcast address
|
||||
/* Broadcast address */
|
||||
#define ARCNET_BROADCAST 0
|
||||
|
||||
/*
|
||||
@@ -95,9 +95,9 @@ void arcnet_cleanup(void)
|
||||
|
||||
static int arcnet_bind(char *interface_name)
|
||||
{
|
||||
int sock_fd = -1; // return value
|
||||
int sock_fd = -1; /* return value */
|
||||
struct ifreq ifr;
|
||||
int rv; // return value - error value from df or ioctl call
|
||||
int rv; /* return value - error value from df or ioctl call */
|
||||
int uid = 0;
|
||||
|
||||
/* check to see if we are being run as root */
|
||||
@@ -109,10 +109,10 @@ static int arcnet_bind(char *interface_name)
|
||||
return sock_fd;
|
||||
}
|
||||
fprintf(stderr, "arcnet: opening \"%s\"\n", interface_name);
|
||||
// note: on some systems you may have to add or enable in
|
||||
// modules.conf (or in modutils/alias on Debian with update-modules)
|
||||
// alias net-pf-17 af_packet
|
||||
// Then follow it by: # modprobe af_packet
|
||||
/* note: on some systems you may have to add or enable in */
|
||||
/* modules.conf (or in modutils/alias on Debian with update-modules) */
|
||||
/* alias net-pf-17 af_packet */
|
||||
/* Then follow it by: # modprobe af_packet */
|
||||
if ((sock_fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
|
||||
/* Error occured */
|
||||
fprintf(stderr,
|
||||
@@ -129,7 +129,7 @@ static int arcnet_bind(char *interface_name)
|
||||
if (ARCNET_Sock_FD >= 0) {
|
||||
/* Bind the socket to an interface name so we only get packets from it */
|
||||
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
|
||||
//ARCNET_Socket_Address.sa_family = PF_INET;
|
||||
/*ARCNET_Socket_Address.sa_family = PF_INET; */
|
||||
/* Clear the memory before copying */
|
||||
memset(ARCNET_Socket_Address.sa_data, '\0',
|
||||
sizeof(ARCNET_Socket_Address.sa_data));
|
||||
@@ -158,9 +158,9 @@ static int arcnet_bind(char *interface_name)
|
||||
rv = ioctl(sock_fd, SIOCGIFHWADDR, &ifr);
|
||||
if (rv != -1) /* worked okay */
|
||||
ARCNET_MAC_Address = ifr.ifr_hwaddr.sa_data[0];
|
||||
// copy this info into the local copy since bind wiped it out
|
||||
/* copy this info into the local copy since bind wiped it out */
|
||||
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
|
||||
//ARCNET_Socket_Address.sa_family = PF_INET;
|
||||
/*ARCNET_Socket_Address.sa_family = PF_INET; */
|
||||
/* Clear the memory before copying */
|
||||
memset(ARCNET_Socket_Address.sa_data, '\0',
|
||||
sizeof(ARCNET_Socket_Address.sa_data));
|
||||
@@ -184,17 +184,17 @@ bool arcnet_init(char *interface_name)
|
||||
|
||||
/* function to send a packet out the socket */
|
||||
/* returns number of bytes sent on success, negative on failure */
|
||||
int arcnet_send(BACNET_ADDRESS * dest, // destination address
|
||||
BACNET_ADDRESS * src, // source address
|
||||
uint8_t * pdu, // any data to be sent - may be null
|
||||
unsigned pdu_len) // number of bytes of data
|
||||
{
|
||||
int arcnet_send(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int bytes = 0;
|
||||
uint8_t mtu[512] = { 0 };
|
||||
int mtu_len = 0;
|
||||
struct archdr *pkt = (struct archdr *) mtu;
|
||||
|
||||
// don't waste time if the socket is not valid
|
||||
/* don't waste time if the socket is not valid */
|
||||
if (ARCNET_Sock_FD < 0) {
|
||||
fprintf(stderr, "arcnet: socket is invalid!\n");
|
||||
return -1;
|
||||
@@ -239,30 +239,30 @@ int arcnet_send(BACNET_ADDRESS * dest, // destination address
|
||||
|
||||
/* function to send a PDU out the socket */
|
||||
/* returns number of bytes sent on success, negative on failure */
|
||||
int arcnet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||
uint8_t * pdu, // any data to be sent - may be null
|
||||
unsigned pdu_len) // number of bytes of data
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; // source address
|
||||
int arcnet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
BACNET_ADDRESS src = { 0 }; /* source address */
|
||||
|
||||
src.mac[0] = ARCNET_MAC_Address;
|
||||
src.mac_len = 1;
|
||||
return arcnet_send(dest, // destination address
|
||||
&src, // source address
|
||||
pdu, // any data to be sent - may be null
|
||||
pdu_len); // number of bytes of data
|
||||
return arcnet_send(dest, /* destination address */
|
||||
&src, /* source address */
|
||||
pdu, /* any data to be sent - may be null */
|
||||
pdu_len); /* number of bytes of data */
|
||||
}
|
||||
|
||||
// receives an framed packet
|
||||
// returns the number of octets in the PDU, or zero on failure
|
||||
uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
|
||||
uint8_t * pdu, // PDU data
|
||||
uint16_t max_pdu, // amount of space available in the PDU
|
||||
unsigned timeout) // milliseconds to wait for a packet
|
||||
{
|
||||
/* receives an framed packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t arcnet_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout)
|
||||
{ /* milliseconds to wait for a packet */
|
||||
int received_bytes;
|
||||
uint8_t buf[512] = { 0 }; // data
|
||||
uint16_t pdu_len = 0; // return value
|
||||
uint8_t buf[512] = { 0 }; /* data */
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
int max;
|
||||
struct timeval select_timeout;
|
||||
@@ -294,9 +294,9 @@ uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
|
||||
|
||||
/* See if there is a problem */
|
||||
if (received_bytes < 0) {
|
||||
// EAGAIN Non-blocking I/O has been selected
|
||||
// using O_NONBLOCK and no data
|
||||
// was immediately available for reading.
|
||||
/* EAGAIN Non-blocking I/O has been selected */
|
||||
/* using O_NONBLOCK and no data */
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN)
|
||||
fprintf(stderr,
|
||||
"ethernet: Read error in receiving packet: %s\n",
|
||||
@@ -344,10 +344,10 @@ uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
|
||||
/* compute the PDU length */
|
||||
pdu_len = received_bytes - ARC_HDR_SIZE;
|
||||
pdu_len -= 4 /* SC, DSAP, SSAP, LLC Control */ ;
|
||||
// copy the buffer into the PDU
|
||||
/* copy the buffer into the PDU */
|
||||
if (pdu_len < max_pdu)
|
||||
memmove(&pdu[0], &pkt->soft.raw[4], pdu_len);
|
||||
// silently ignore packets that are too large
|
||||
/* silently ignore packets that are too large */
|
||||
else
|
||||
pdu_len = 0;
|
||||
|
||||
@@ -360,7 +360,7 @@ void arcnet_get_my_address(BACNET_ADDRESS * my_address)
|
||||
|
||||
my_address->mac_len = 1;
|
||||
my_address->mac[0] = ARCNET_MAC_Address;
|
||||
my_address->net = 0; // local only, no routing
|
||||
my_address->net = 0; /* local only, no routing */
|
||||
my_address->len = 0;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
my_address->adr[i] = 0;
|
||||
@@ -369,15 +369,15 @@ void arcnet_get_my_address(BACNET_ADDRESS * my_address)
|
||||
return;
|
||||
}
|
||||
|
||||
void arcnet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
|
||||
{
|
||||
int i = 0; // counter
|
||||
void arcnet_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (dest) {
|
||||
dest->mac[0] = ARCNET_BROADCAST;
|
||||
dest->mac_len = 1;
|
||||
dest->net = BACNET_BROADCAST_NETWORK;
|
||||
dest->len = 0; // len=0 denotes broadcast address
|
||||
dest->len = 0; /* len=0 denotes broadcast address */
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
dest->adr[i] = 0;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h> // for standard integer types uint8_t etc.
|
||||
#include <stdbool.h> // for the standard bool type.
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "bip.h"
|
||||
#include "net.h"
|
||||
@@ -43,7 +43,7 @@ static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr,
|
||||
int request)
|
||||
{
|
||||
int fd;
|
||||
int rv; // return value
|
||||
int rv; /* return value */
|
||||
|
||||
strncpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name));
|
||||
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
@@ -60,7 +60,7 @@ static int get_local_address_ioctl(char *ifname,
|
||||
{
|
||||
struct ifreq ifr = { {{0}} };
|
||||
struct sockaddr_in *tcpip_address;
|
||||
int rv; // return value
|
||||
int rv; /* return value */
|
||||
|
||||
rv = get_local_ifr_ioctl(ifname, &ifr, request);
|
||||
if (rv >= 0) {
|
||||
@@ -93,18 +93,18 @@ void bip_set_interface(char *ifname)
|
||||
|
||||
bool bip_init(void)
|
||||
{
|
||||
int status = 0; // return from socket lib calls
|
||||
int status = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin;
|
||||
int sockopt = 0;
|
||||
int sock_fd = -1;
|
||||
|
||||
// assumes that the driver has already been initialized
|
||||
/* assumes that the driver has already been initialized */
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
bip_set_socket(sock_fd);
|
||||
if (sock_fd < 0)
|
||||
return false;
|
||||
// Allow us to use the same socket for sending and receiving
|
||||
// This makes sure that the src port is correct when sending
|
||||
/* Allow us to use the same socket for sending and receiving */
|
||||
/* This makes sure that the src port is correct when sending */
|
||||
sockopt = 1;
|
||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
&sockopt, sizeof(sockopt));
|
||||
@@ -113,7 +113,7 @@ bool bip_init(void)
|
||||
bip_set_socket(-1);
|
||||
return status;
|
||||
}
|
||||
// allow us to send a broadcast
|
||||
/* allow us to send a broadcast */
|
||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||
&sockopt, sizeof(sockopt));
|
||||
if (status < 0) {
|
||||
@@ -121,7 +121,7 @@ bool bip_init(void)
|
||||
bip_set_socket(-1);
|
||||
return status;
|
||||
}
|
||||
// bind the socket to the local port number and IP address
|
||||
/* bind the socket to the local port number and IP address */
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_port = htons(bip_get_port());
|
||||
|
||||
@@ -32,25 +32,25 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h> // for standard integer types uint8_t etc.
|
||||
#include <stdbool.h> // for the standard bool type.
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
|
||||
#include "net.h"
|
||||
#include "bacdef.h"
|
||||
#include "ethernet.h"
|
||||
#include "bacdcode.h"
|
||||
|
||||
// commonly used comparison address for ethernet
|
||||
/* commonly used comparison address for ethernet */
|
||||
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
// commonly used empty address for ethernet quick compare
|
||||
/* commonly used empty address for ethernet quick compare */
|
||||
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// my local device data - MAC address
|
||||
/* my local device data - MAC address */
|
||||
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0 };
|
||||
|
||||
static int eth802_sockfd = -1; /* 802.2 file handle */
|
||||
static struct sockaddr eth_addr = { 0 }; // used for binding 802.2
|
||||
static struct sockaddr eth_addr = { 0 }; /* used for binding 802.2 */
|
||||
|
||||
bool ethernet_valid(void)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ int setNonblocking(int fd)
|
||||
/* opens an 802.2 socket to receive and send packets */
|
||||
static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
||||
{
|
||||
int sock_fd = -1; // return value
|
||||
int sock_fd = -1; /* return value */
|
||||
int uid = 0;
|
||||
|
||||
fprintf(stderr, "ethernet: opening \"%s\"\n", interface_name);
|
||||
@@ -99,10 +99,10 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
||||
"Try running with root priveleges.\n");
|
||||
return sock_fd;
|
||||
}
|
||||
// note: on some systems you may have to add or enable in
|
||||
// modules.conf (or in modutils/alias on Debian with update-modules)
|
||||
// alias net-pf-17 af_packet
|
||||
// Then follow it by: # modprobe af_packet
|
||||
/* note: on some systems you may have to add or enable in */
|
||||
/* modules.conf (or in modutils/alias on Debian with update-modules) */
|
||||
/* alias net-pf-17 af_packet */
|
||||
/* Then follow it by: # modprobe af_packet */
|
||||
|
||||
/* Attempt to open the socket for 802.2 ethernet frames */
|
||||
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
|
||||
@@ -152,7 +152,7 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int fd;
|
||||
int rv; // return value - error value from df or ioctl call
|
||||
int rv; /* return value - error value from df or ioctl call */
|
||||
|
||||
/* determine the local MAC address */
|
||||
strcpy(ifr.ifr_name, ifname);
|
||||
@@ -178,17 +178,17 @@ bool ethernet_init(char *interface_name)
|
||||
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns bytes sent success, negative on failure */
|
||||
int ethernet_send(BACNET_ADDRESS * dest, // destination address
|
||||
BACNET_ADDRESS * src, // source address
|
||||
uint8_t * pdu, // any data to be sent - may be null
|
||||
unsigned pdu_len) // number of bytes of data
|
||||
{
|
||||
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int bytes = 0;
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
int i = 0;
|
||||
|
||||
// don't waste time if the socket is not valid
|
||||
/* don't waste time if the socket is not valid */
|
||||
if (eth802_sockfd < 0) {
|
||||
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
||||
return -1;
|
||||
@@ -221,7 +221,7 @@ int ethernet_send(BACNET_ADDRESS * dest, // destination address
|
||||
/* packet length */
|
||||
mtu_len += encode_unsigned16(&mtu[12],
|
||||
3 /*DSAP,SSAP,LLC */ + pdu_len);
|
||||
// Logical PDU portion
|
||||
/* Logical PDU portion */
|
||||
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
|
||||
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
|
||||
mtu[mtu_len++] = 0x03; /* Control byte in header */
|
||||
@@ -242,12 +242,12 @@ int ethernet_send(BACNET_ADDRESS * dest, // destination address
|
||||
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns number of bytes sent on success, negative on failure */
|
||||
int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||
uint8_t * pdu, // any data to be sent - may be null
|
||||
unsigned pdu_len) // number of bytes of data
|
||||
{
|
||||
int i = 0; // counter
|
||||
BACNET_ADDRESS src = { 0 }; // source address
|
||||
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len)
|
||||
{ /* number of bytes of data */
|
||||
int i = 0; /* counter */
|
||||
BACNET_ADDRESS src = { 0 }; /* source address */
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
src.mac[i] = Ethernet_MAC_Address[i];
|
||||
@@ -255,22 +255,22 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||
}
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns 1 on success, 0 on failure */
|
||||
return ethernet_send(dest, // destination address
|
||||
&src, // source address
|
||||
pdu, // any data to be sent - may be null
|
||||
pdu_len); // number of bytes of data
|
||||
return ethernet_send(dest, /* destination address */
|
||||
&src, /* source address */
|
||||
pdu, /* any data to be sent - may be null */
|
||||
pdu_len); /* number of bytes of data */
|
||||
}
|
||||
|
||||
// receives an 802.2 framed packet
|
||||
// returns the number of octets in the PDU, or zero on failure
|
||||
uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
|
||||
uint8_t * pdu, // PDU data
|
||||
uint16_t max_pdu, // amount of space available in the PDU
|
||||
unsigned timeout) // number of milliseconds to wait for a packet
|
||||
{
|
||||
/* receives an 802.2 framed packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout)
|
||||
{ /* number of milliseconds to wait for a packet */
|
||||
int received_bytes;
|
||||
uint8_t buf[MAX_MPDU] = { 0 }; // data
|
||||
uint16_t pdu_len = 0; // return value
|
||||
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
fd_set read_fds;
|
||||
int max;
|
||||
struct timeval select_timeout;
|
||||
@@ -301,9 +301,9 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
|
||||
|
||||
/* See if there is a problem */
|
||||
if (received_bytes < 0) {
|
||||
// EAGAIN Non-blocking I/O has been selected
|
||||
// using O_NONBLOCK and no data
|
||||
// was immediately available for reading.
|
||||
/* EAGAIN Non-blocking I/O has been selected */
|
||||
/* using O_NONBLOCK and no data */
|
||||
/* was immediately available for reading. */
|
||||
if (errno != EAGAIN)
|
||||
fprintf(stderr,
|
||||
"ethernet: Read error in receiving packet: %s\n",
|
||||
@@ -316,27 +316,27 @@ uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
|
||||
|
||||
/* the signature of an 802.2 BACnet packet */
|
||||
if ((buf[14] != 0x82) && (buf[15] != 0x82)) {
|
||||
//fprintf(stderr,"ethernet: Non-BACnet packet\n");
|
||||
/*fprintf(stderr,"ethernet: Non-BACnet packet\n"); */
|
||||
return 0;
|
||||
}
|
||||
// copy the source address
|
||||
/* copy the source address */
|
||||
src->mac_len = 6;
|
||||
memmove(src->mac, &buf[6], 6);
|
||||
|
||||
// check destination address for when
|
||||
// the Ethernet card is in promiscious mode
|
||||
/* check destination address for when */
|
||||
/* the Ethernet card is in promiscious mode */
|
||||
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
|
||||
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0)) {
|
||||
//fprintf(stderr, "ethernet: This packet isn't for us\n");
|
||||
/*fprintf(stderr, "ethernet: This packet isn't for us\n"); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) decode_unsigned16(&buf[12], &pdu_len);
|
||||
pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ;
|
||||
// copy the buffer into the PDU
|
||||
/* copy the buffer into the PDU */
|
||||
if (pdu_len < max_pdu)
|
||||
memmove(&pdu[0], &buf[17], pdu_len);
|
||||
// ignore packets that are too large
|
||||
/* ignore packets that are too large */
|
||||
else
|
||||
pdu_len = 0;
|
||||
|
||||
@@ -364,7 +364,7 @@ void ethernet_get_my_address(BACNET_ADDRESS * my_address)
|
||||
my_address->mac[i] = Ethernet_MAC_Address[i];
|
||||
my_address->mac_len++;
|
||||
}
|
||||
my_address->net = 0; // local only, no routing
|
||||
my_address->net = 0; /* local only, no routing */
|
||||
my_address->len = 0;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
my_address->adr[i] = 0;
|
||||
@@ -373,9 +373,9 @@ void ethernet_get_my_address(BACNET_ADDRESS * my_address)
|
||||
return;
|
||||
}
|
||||
|
||||
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
|
||||
{
|
||||
int i = 0; // counter
|
||||
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (dest) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
@@ -383,7 +383,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination a
|
||||
}
|
||||
dest->mac_len = 6;
|
||||
dest->net = BACNET_BROADCAST_NETWORK;
|
||||
dest->len = 0; // denotes broadcast address
|
||||
dest->len = 0; /* denotes broadcast address */
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
dest->adr[i] = 0;
|
||||
}
|
||||
@@ -394,7 +394,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination a
|
||||
|
||||
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
|
||||
{
|
||||
int i = 0; // counter
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (info)
|
||||
fprintf(stderr, "%s", info);
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
#include "net.h"
|
||||
#include "txbuf.h"
|
||||
|
||||
// This is an example application using the BACnet Stack on Linux
|
||||
/* This is an example application using the BACnet Stack on Linux */
|
||||
bool Who_Is_Request = true;
|
||||
|
||||
// buffers used for receiving
|
||||
/* buffers used for receiving */
|
||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
|
||||
static void LocalIAmHandler(uint8_t * service_request,
|
||||
@@ -134,7 +134,7 @@ static void Read_Properties(void)
|
||||
invoke ID from the sending of the request, and wait until we
|
||||
got the reply with matching invoke ID or the TSM of the
|
||||
invoke ID expired. This demo is doing things asynchronously. */
|
||||
status = Send_Read_Property_Request(device_id, // destination device
|
||||
status = Send_Read_Property_Request(device_id, /* destination device */
|
||||
OBJECT_DEVICE,
|
||||
device_id, object_props[property], BACNET_ARRAY_ALL);
|
||||
if (status)
|
||||
@@ -156,25 +156,25 @@ static void Read_Properties(void)
|
||||
|
||||
static void Init_Service_Handlers(void)
|
||||
{
|
||||
// we need to handle who-is to support dynamic device binding
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||
handler_who_is);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||
LocalIAmHandler);
|
||||
|
||||
// set the handler for all the services we don't implement
|
||||
// It is required to send the proper reject message...
|
||||
/* set the handler for all the services we don't implement */
|
||||
/* It is required to send the proper reject message... */
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
// Set the handlers for any confirmed services that we support.
|
||||
// We must implement read property - it's required!
|
||||
/* Set the handlers for any confirmed services that we support. */
|
||||
/* We must implement read property - it's required! */
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||
handler_write_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||
handler_atomic_read_file);
|
||||
// handle the data coming back from confirmed requests
|
||||
/* handle the data coming back from confirmed requests */
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property_ack);
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||
@@ -223,23 +223,23 @@ static void sig_handler(int signo)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; // address where message came from
|
||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; // milliseconds
|
||||
unsigned count = 0; // milliseconds
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
unsigned count = 0; /* milliseconds */
|
||||
time_t start_time;
|
||||
time_t new_time = 0;
|
||||
|
||||
start_time = time(NULL); /* get current time */
|
||||
// Linux specials
|
||||
/* Linux specials */
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGTERM, sig_handler);
|
||||
// setup this BACnet Server device
|
||||
/* setup this BACnet Server device */
|
||||
Device_Set_Object_Instance_Number(111);
|
||||
Init_Service_Handlers();
|
||||
#ifdef BACDL_ETHERNET
|
||||
// init the physical layer
|
||||
/* init the physical layer */
|
||||
if (!ethernet_init("eth0"))
|
||||
return 1;
|
||||
#endif
|
||||
@@ -254,14 +254,14 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
// loop forever
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
// input
|
||||
/* input */
|
||||
new_time = time(NULL);
|
||||
// returns 0 bytes on timeout
|
||||
/* returns 0 bytes on timeout */
|
||||
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
|
||||
// process
|
||||
/* process */
|
||||
if (pdu_len) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
@@ -276,13 +276,13 @@ int main(int argc, char *argv[])
|
||||
Who_Is_Request = false;
|
||||
Send_WhoIs(-1, -1);
|
||||
}
|
||||
// output
|
||||
// some round robin task switching
|
||||
/* output */
|
||||
/* some round robin task switching */
|
||||
count++;
|
||||
switch (count) {
|
||||
case 1:
|
||||
// used for testing, but kind of noisy on the network
|
||||
//Read_Properties();
|
||||
/* used for testing, but kind of noisy on the network */
|
||||
/*Read_Properties(); */
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
@@ -291,7 +291,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
// blink LEDs, Turn on or off outputs, etc
|
||||
/* blink LEDs, Turn on or off outputs, etc */
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
// The module handles sending data out the RS-485 port
|
||||
// and handles receiving data from the RS-485 port.
|
||||
// Customize this file for your specific hardware
|
||||
/* The module handles sending data out the RS-485 port */
|
||||
/* and handles receiving data from the RS-485 port. */
|
||||
/* Customize this file for your specific hardware */
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -43,18 +43,18 @@
|
||||
|
||||
#include "mstp.h"
|
||||
|
||||
// Transmits a Frame on the wire
|
||||
void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, // port specific data
|
||||
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
||||
uint16_t nbytes) // number of bytes of data (up to 501)
|
||||
{
|
||||
/* Transmits a Frame on the wire */
|
||||
void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, /* port specific data */
|
||||
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||
uint16_t nbytes)
|
||||
{ /* number of bytes of data (up to 501) */
|
||||
|
||||
// in order to avoid line contention
|
||||
/* in order to avoid line contention */
|
||||
while (mstp_port->Turn_Around_Waiting) {
|
||||
// wait, yield, or whatever
|
||||
/* wait, yield, or whatever */
|
||||
}
|
||||
|
||||
// Disable the receiver, and enable the transmit line driver.
|
||||
/* Disable the receiver, and enable the transmit line driver. */
|
||||
|
||||
while (nbytes) {
|
||||
putc(*buffer, stderr);
|
||||
@@ -62,32 +62,32 @@ void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, // port specific
|
||||
nbytes--;
|
||||
}
|
||||
|
||||
// Wait until the final stop bit of the most significant CRC octet
|
||||
// has been transmitted but not more than Tpostdrive.
|
||||
/* Wait until the final stop bit of the most significant CRC octet */
|
||||
/* has been transmitted but not more than Tpostdrive. */
|
||||
|
||||
// Disable the transmit line driver.
|
||||
/* Disable the transmit line driver. */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// called by timer, interrupt(?) or other thread
|
||||
/* called by timer, interrupt(?) or other thread */
|
||||
void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
// wait for state machine to clear this
|
||||
/* wait for state machine to clear this */
|
||||
}
|
||||
// wait for state machine to read from the DataRegister
|
||||
/* wait for state machine to read from the DataRegister */
|
||||
else if (mstp_port->DataAvailable == false) {
|
||||
// check for data
|
||||
/* check for data */
|
||||
|
||||
// if error,
|
||||
// ReceiveError = TRUE;
|
||||
// return;
|
||||
/* if error, */
|
||||
/* ReceiveError = TRUE; */
|
||||
/* return; */
|
||||
|
||||
mstp_port->DataRegister = 0; // FIXME: Get this data from UART or buffer
|
||||
mstp_port->DataRegister = 0; /* FIXME: Get this data from UART or buffer */
|
||||
|
||||
// if data is ready,
|
||||
// DataAvailable = TRUE;
|
||||
// return;
|
||||
/* if data is ready, */
|
||||
/* DataAvailable = TRUE; */
|
||||
/* return; */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user