Feature/make pretty apps and ports (#80)

* Added pretty-apps and pretty-ports make targets

* pretty-fied apps folder C files

* Pretty-fied ports folder C and H files

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2020-04-30 10:13:11 -05:00
committed by GitHub
parent 0abcbea971
commit fdd49f1791
152 changed files with 9668 additions and 11674 deletions
+47 -62
View File
@@ -32,12 +32,12 @@
-------------------------------------------
####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 "bacnet/bacdcode.h"
#include "bacnet/datalink/bip.h"
#include "eth.h"
#include "bacport.h" /* custom per port */
#include "bacport.h" /* custom per port */
static int BIP_Socket = -1;
/* port to use - stored in host byte order */
@@ -47,86 +47,75 @@ static struct in_addr BIP_Address;
/* Broadcast Address - stored in host byte order */
static struct in_addr BIP_Broadcast_Address;
void bip_set_socket(
int sock_fd)
void bip_set_socket(int sock_fd)
{
BIP_Socket = sock_fd;
}
int bip_socket(
void)
int bip_socket(void)
{
return BIP_Socket;
}
bool bip_valid(
void)
bool bip_valid(void)
{
return (BIP_Socket != -1);
}
void bip_cleanup(
void)
void bip_cleanup(void)
{
/* if (bip_valid()) */
/* close(BIP_Socket); */
/* if (bip_valid()) */
/* close(BIP_Socket); */
BIP_Socket = -1;
return;
}
/* set using network byte order */
void bip_set_addr(
uint32_t net_address)
void bip_set_addr(uint32_t net_address)
{
/* BIP_Address.s_addr = ntohl(net_address); */
/* BIP_Address.s_addr = ntohl(net_address); */
BIP_Address.s_addr = net_address;
}
/* returns host byte order */
uint32_t bip_get_addr(
void)
uint32_t bip_get_addr(void)
{
return BIP_Address.s_addr;
}
/* set using network byte order */
void bip_set_broadcast_addr(
uint32_t net_address)
void bip_set_broadcast_addr(uint32_t net_address)
{
/* BIP_Broadcast_Address.s_addr = ntohl(net_address); */
/* BIP_Broadcast_Address.s_addr = ntohl(net_address); */
BIP_Broadcast_Address.s_addr = net_address;
}
/* returns host byte order */
uint32_t bip_get_broadcast_addr(
void)
uint32_t bip_get_broadcast_addr(void)
{
return BIP_Broadcast_Address.s_addr;
}
/* set using host byte order */
void bip_set_port(
uint16_t port)
void bip_set_port(uint16_t port)
{
BIP_Port = port;
}
/* returns host byte order */
uint16_t bip_get_port(
void)
uint16_t bip_get_port(void)
{
return BIP_Port;
}
/* function to send a packet out the BACnet/IP socket (Annex J) */
/* returns number of bytes sent on success, negative number on failure */
int bip_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
int bip_send_pdu(BACNET_ADDRESS *dest, /* destination address */
BACNET_NPDU_DATA *npdu_data, /* network information */
uint8_t *pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
{ /* number of bytes of data */
struct sockaddr_in bip_dest;
uint8_t mtu[4];
@@ -136,11 +125,11 @@ int bip_send_pdu(
IP_HDR iphdr;
uint8_t mac[6];
(void) npdu_data;
(void)npdu_data;
/* assumes that the driver has already been initialized */
/* if (BIP_Socket < 0) */
/* return BIP_Socket; */
/* if (BIP_Socket < 0) */
/* return BIP_Socket; */
mtu[0] = BVLL_TYPE_BACNET_IP;
bip_dest.sin_family = AF_INET;
@@ -161,9 +150,8 @@ int bip_send_pdu(
return -1;
mtu_len = 2;
mtu_len +=
encode_unsigned16(&mtu[mtu_len],
(uint16_t) (pdu_len + 4 /*inclusive */ ));
mtu_len += encode_unsigned16(
&mtu[mtu_len], (uint16_t)(pdu_len + 4 /*inclusive */));
mtu_len += pdu_len;
/* IP address should be in network byte order */
@@ -182,9 +170,10 @@ int bip_send_pdu(
iphdr.destipaddr = bip_dest.sin_addr.s_addr;
/* Calculate IP checksum. */
iphdr.ipchksum = ~(ip_getchksum((uint8_t *) & iphdr));
iphdr.ipchksum = ~(ip_getchksum((uint8_t *)&iphdr));
/* Ports are sent in Network byte order. BIP_Port is stored in Host byte order */
/* Ports are sent in Network byte order. BIP_Port is stored in Host byte
* order */
udphdr.srcport = htons(BIP_Port);
udphdr.destport = bip_dest.sin_port;
udphdr.udplen = htons(mtu_len + sizeof(UDP_HDR));
@@ -192,36 +181,33 @@ int bip_send_pdu(
udphdr.udpchksum = 0;
EthernetSendHeader(mac, UIP_ETHTYPE_IP);
EthernetSend((uint8_t *) & iphdr, sizeof(IP_HDR));
EthernetSend((uint8_t *) & udphdr, sizeof(UDP_HDR));
EthernetSend((uint8_t *)&iphdr, sizeof(IP_HDR));
EthernetSend((uint8_t *)&udphdr, sizeof(UDP_HDR));
EthernetSend(mtu, 4);
EthernetSend(pdu, pdu_len);
EthernetFlush();
uip_stat.ip.sent++;
}
/* receives a BACnet/IP packet */
/* returns the number of octets in the PDU, or zero on failure */
uint16_t bip_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */
uint16_t bip_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 */
{ /* number of milliseconds to wait for a packet */
return 0;
}
void bip_get_my_address(
BACNET_ADDRESS * my_address)
void bip_get_my_address(BACNET_ADDRESS *my_address)
{
int i = 0;
my_address->mac_len = 6;
(void) encode_unsigned32(&my_address->mac[0], htonl(BIP_Address.s_addr));
(void) encode_unsigned16(&my_address->mac[4], htons(BIP_Port));
my_address->net = 0; /* local only, no routing */
my_address->len = 0; /* no SLEN */
(void)encode_unsigned32(&my_address->mac[0], htonl(BIP_Address.s_addr));
(void)encode_unsigned16(&my_address->mac[4], htons(BIP_Port));
my_address->net = 0; /* local only, no routing */
my_address->len = 0; /* no SLEN */
for (i = 0; i < MAX_MAC_LEN; i++) {
/* no SADR */
my_address->adr[i] = 0;
@@ -230,18 +216,17 @@ void bip_get_my_address(
return;
}
void bip_get_broadcast_address(
BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
void bip_get_broadcast_address(BACNET_ADDRESS *dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
dest->mac_len = 6;
(void) encode_unsigned32(&dest->mac[0],
htonl(BIP_Broadcast_Address.s_addr));
(void) encode_unsigned16(&dest->mac[4], htons(BIP_Port));
(void)encode_unsigned32(
&dest->mac[0], htonl(BIP_Broadcast_Address.s_addr));
(void)encode_unsigned16(&dest->mac[4], htons(BIP_Port));
dest->net = BACNET_BROADCAST_NETWORK;
dest->len = 0; /* no SLEN */
dest->len = 0; /* no SLEN */
for (i = 0; i < MAX_MAC_LEN; i++) {
/* no SADR */
dest->adr[i] = 0;