Feature/makefile add apps library (#218)

* add BACnet stack library at apps/lib

* convert apps to use apps/lib for smaller binary

* fix -DBACDL_ALL=1 build

* fix piface build

* datalink MAX_MPDU and MAX_HEADER cleanup

* add bip6 to git workflow

* fix system library dependency of BACnet library

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2022-01-29 15:55:40 -06:00
committed by GitHub
parent 9c72572692
commit 295f127c2b
79 changed files with 917 additions and 1104 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ int bip_send_pdu(BACNET_ADDRESS *dest, /* destination address */
unsigned pdu_len)
{ /* number of bytes of data */
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[BIP_MPDU_MAX] = { 0 };
int mtu_len = 0;
int bytes_sent = 0;
/* addr and port in host format */
+2 -2
View File
@@ -31,8 +31,8 @@
#include "bacnet/npdu.h"
/* specific defines for BACnet/IP over Ethernet */
#define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define BIP_HEADER_MAX (1 + 1 + 2)
#define BIP_MPDU_MAX (BIP_HEADER_MAX+MAX_PDU)
#define BVLL_TYPE_BACNET_IP (0x81)
+1 -1
View File
@@ -80,7 +80,7 @@ static void bvlc_send_result(uint8_t *dest_addr,
BACNET_BVLC_RESULT result_code)
{
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[BIP_MPDU_MAX] = { 0 };
uint16_t mtu_len = 0;
mtu_len = (uint16_t)bvlc_encode_bvlc_result(&mtu[0], result_code);
+1 -1
View File
@@ -189,7 +189,7 @@ struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
/* count must be a power of 2 for ringbuf library */
#ifndef MSTP_PDU_PACKET_COUNT
+1 -1
View File
@@ -193,7 +193,7 @@ struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
static struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT];
static RING_BUFFER PDU_Queue;
+3 -3
View File
@@ -77,14 +77,14 @@ static bool run_thread;
/* local MS/TP port data - shared with RS-485 */
static volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
/* data structure for MS/TP PDU Queue */
struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
/* count must be a power of 2 for ringbuf library */
#ifndef MSTP_PDU_PACKET_COUNT
+6 -6
View File
@@ -40,8 +40,8 @@
#include "bacnet/basic/sys/ringbuf.h"
/* defines specific to MS/TP */
/* preamble+type+dest+src+len+crc8+crc16 */
#define MAX_HEADER (2+1+1+1+2+1+2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define DLMSTP_HEADER_MAX (2+1+1+1+2+1+2)
#define DLMSTP_MPDU_MAX (DLMSTP_HEADER_MAX+MAX_PDU)
/* count must be a power of 2 for ringbuf library */
#ifndef MSTP_PDU_PACKET_COUNT
@@ -53,7 +53,7 @@ typedef struct dlmstp_packet {
BACNET_ADDRESS address; /* source address */
uint8_t frame_type; /* type of message */
uint16_t pdu_len; /* packet length */
uint8_t pdu[MAX_MPDU]; /* packet */
uint8_t pdu[DLMSTP_MPDU_MAX]; /* packet */
} DLMSTP_PACKET;
/* data structure for MS/TP PDU Queue */
@@ -61,7 +61,7 @@ struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
typedef struct shared_mstp_data {
@@ -85,8 +85,8 @@ typedef struct shared_mstp_data {
pthread_cond_t Master_Done_Flag;
pthread_mutex_t Master_Done_Mutex;
/* buffers needed by mstp port struct */
uint8_t TxBuffer[MAX_MPDU];
uint8_t RxBuffer[MAX_MPDU];
uint8_t TxBuffer[DLMSTP_MPDU_MAX];
uint8_t RxBuffer[DLMSTP_MPDU_MAX];
/* The minimum time without a DataAvailable or ReceiveError event */
/* that a node must wait for a station to begin replying to a */
/* confirmed request: 255 milliseconds. (Implementations may use */
+3 -3
View File
@@ -226,7 +226,7 @@ int ethernet_send_pdu(BACNET_ADDRESS *dest, /* destination address */
int i = 0; /* counter */
int bytes = 0;
BACNET_ADDRESS src = { 0 }; /* source address for npdu */
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
uint8_t mtu[ETHERNET_MPDU_MAX] = { 0 }; /* our buffer */
int mtu_len = 0;
(void)npdu_data;
@@ -265,7 +265,7 @@ int ethernet_send_pdu(BACNET_ADDRESS *dest, /* destination address */
mtu[15] = 0x82; /* SSAP for BACnet */
mtu[16] = 0x03; /* Control byte in header */
mtu_len = 17;
if ((mtu_len + pdu_len) > MAX_MPDU) {
if ((mtu_len + pdu_len) > ETHERNET_MPDU_MAX) {
fprintf(stderr, "ethernet: PDU is too big to send!\n");
return -4;
}
@@ -293,7 +293,7 @@ uint16_t ethernet_receive(BACNET_ADDRESS *src, /* source address */
unsigned timeout)
{ /* number of milliseconds to wait for a packet */
int received_bytes;
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
uint8_t buf[ETHERNET_MPDU_MAX] = { 0 }; /* data */
uint16_t pdu_len = 0; /* return value */
fd_set read_fds;
int max;
+2 -2
View File
@@ -61,8 +61,8 @@
/* local port data - shared with RS-485 */
static volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static struct mstimer Silence_Timer;
static uint32_t Timer_Silence(void *pArg)
+2 -2
View File
@@ -69,8 +69,8 @@
/* local port data - shared with RS-485 */
static volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static uint16_t SilenceTime;
#define INCREMENT_AND_LIMIT_UINT16(x) \
{ \
+1 -1
View File
@@ -111,7 +111,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS *dest, /* destination address */
MSTP_Port.TxDestination = MSTP_BROADCAST_ADDRESS;
}
dlmstp_get_my_address(&src);
if ((MAX_HEADER + pdu_len) > MAX_MPDU) {
if ((DLMSTP_HEADER_MAX + pdu_len) > DLMSTP_MPDU_MAX) {
return -4;
}
bytes_sent = MSTP_Create_Frame((uint8_t *)&MSTP_Port.TxBuffer[0],
+3 -3
View File
@@ -42,15 +42,15 @@
#include "bacnet/npdu.h"
/* defines specific to MS/TP */
#define MAX_HEADER (2+1+1+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define DLMSTP_HEADER_MAX (2+1+1+1+2+1)
#define DLMSTP_MPDU_MAX (DLMSTP_HEADER_MAX+MAX_PDU)
typedef struct dlmstp_packet {
bool ready; /* true if ready to be sent or received */
BACNET_ADDRESS address; /* source address */
uint8_t frame_type; /* type of message */
unsigned pdu_len; /* packet length */
uint8_t pdu[MAX_MPDU]; /* packet */
uint8_t pdu[DLMSTP_MPDU_MAX]; /* packet */
} DLMSTP_PACKET;
/* number of MS/TP tx/rx packets */
+2 -2
View File
@@ -222,7 +222,7 @@ void MSTP_Create_And_Send_Frame(
uint8_t *data, /* any data to be sent - may be null */
unsigned data_len)
{ /* number of bytes of data (up to 501) */
uint8_t buffer[MAX_MPDU] = { 0 }; /* buffer for sending */
uint8_t buffer[DLMSTP_MPDU_MAX] = { 0 }; /* buffer for sending */
uint16_t len = 0; /* number of bytes to send */
len = (uint16_t)MSTP_Create_Frame(&buffer[0], /* where frame is loaded */
@@ -435,7 +435,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
(mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
/* FrameTooLong */
if (mstp_port->DataLength > MAX_MPDU) {
if (mstp_port->DataLength > DLMSTP_MPDU_MAX) {
/* indicate that a frame with an illegal or */
/* unacceptable data length has been received */
mstp_port->ReceivedInvalidFrame = true;
+1 -1
View File
@@ -111,7 +111,7 @@ int dlmstp_send_pdu(BACNET_ADDRESS *dest, /* destination address */
MSTP_Port.TxDestination = MSTP_BROADCAST_ADDRESS;
}
dlmstp_get_my_address(&src);
if ((MAX_HEADER + pdu_len) > MAX_MPDU) {
if ((DLMSTP_HEADER_MAX + pdu_len) > DLMSTP_MPDU_MAX) {
return -4;
}
bytes_sent = MSTP_Create_Frame((uint8_t *)&MSTP_Port.TxBuffer[0],
+3 -3
View File
@@ -42,15 +42,15 @@
#include "bacnet/npdu.h"
/* defines specific to MS/TP */
#define MAX_HEADER (2+1+1+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define DLMSTP_HEADER_MAX (2+1+1+1+2+1)
#define DLMSTP_MPDU_MAX (DLMSTP_HEADER_MAX+MAX_PDU)
typedef struct dlmstp_packet {
bool ready; /* true if ready to be sent or received */
BACNET_ADDRESS address; /* source address */
uint8_t frame_type; /* type of message */
unsigned pdu_len; /* packet length */
uint8_t pdu[MAX_MPDU]; /* packet */
uint8_t pdu[DLMSTP_MPDU_MAX]; /* packet */
} DLMSTP_PACKET;
/* number of MS/TP tx/rx packets */
+2 -2
View File
@@ -222,7 +222,7 @@ void MSTP_Create_And_Send_Frame(
uint8_t *data, /* any data to be sent - may be null */
unsigned data_len)
{ /* number of bytes of data (up to 501) */
uint8_t buffer[MAX_MPDU] = { 0 }; /* buffer for sending */
uint8_t buffer[DLMSTP_MPDU_MAX] = { 0 }; /* buffer for sending */
uint16_t len = 0; /* number of bytes to send */
len = (uint16_t)MSTP_Create_Frame(&buffer[0], /* where frame is loaded */
@@ -435,7 +435,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
(mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
/* FrameTooLong */
if (mstp_port->DataLength > MAX_MPDU) {
if (mstp_port->DataLength > DLMSTP_MPDU_MAX) {
/* indicate that a frame with an illegal or */
/* unacceptable data length has been received */
mstp_port->ReceivedInvalidFrame = true;
+1 -1
View File
@@ -148,7 +148,7 @@ struct mstp_port_struct_t {
/* An array of octets, used to store PDU octets prior to being transmitted. */
/* This array is only used for APDU messages */
uint8_t TxBuffer[MAX_MPDU];
uint8_t TxBuffer[DLMSTP_MPDU_MAX];
unsigned TxLength;
uint8_t TxDestination;
bool TxReady; /* true if ready to be sent or received */
+3 -3
View File
@@ -94,7 +94,7 @@ int ethernet_send_pdu(BACNET_ADDRESS *dest, /* destination address */
int i = 0; /* counter */
int bytes = 0;
BACNET_ADDRESS src = { 0 }; /* source address for npdu */
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
uint8_t mtu[ETHERNET_MPDU_MAX] = { 0 }; /* our buffer */
int mtu_len = 0;
(void)npdu_data;
@@ -130,7 +130,7 @@ int ethernet_send_pdu(BACNET_ADDRESS *dest, /* destination address */
mtu[15] = 0x82; /* SSAP for BACnet */
mtu[16] = 0x03; /* Control byte in header */
mtu_len = 17;
if ((mtu_len + pdu_len) > MAX_MPDU) {
if ((mtu_len + pdu_len) > ETHERNET_MPDU_MAX) {
return -4;
}
memcpy(&mtu[mtu_len], pdu, pdu_len);
@@ -152,7 +152,7 @@ uint16_t ethernet_receive(BACNET_ADDRESS *src, /* source address */
unsigned timeout)
{ /* number of milliseconds to wait for a packet */
int received_bytes;
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
uint8_t buf[ETHERNET_MPDU_MAX] = { 0 }; /* data */
uint16_t pdu_len = 0; /* return value */
/* Make sure the socket is open */
+2 -2
View File
@@ -165,7 +165,7 @@ static uint8_t Nmax_master = 127;
struct mstp_tx_packet {
uint16_t length;
uint16_t index;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
/* count must be a power of 2 for ringbuf library */
#ifndef MSTP_TRANSMIT_PACKET_COUNT
@@ -179,7 +179,7 @@ struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
/* count must be a power of 2 for ringbuf library */
#ifndef MSTP_PDU_PACKET_COUNT
+1 -1
View File
@@ -155,7 +155,7 @@ static volatile uint8_t Nmax_master = 127;
/* An array of octets, used to store octets for transmitting */
/* OutputBuffer is indexed from 0 to OutputBufferSize-1. */
/* The maximum size of a frame is 501 octets. */
static uint8_t OutputBuffer[MAX_MPDU];
static uint8_t OutputBuffer[DLMSTP_MPDU_MAX];
/* Number of bytes pending transmit. 0=nothing pending transmit */
uint16_t OutputBufferLength;
+2 -2
View File
@@ -37,12 +37,12 @@
#include "rs485.h"
/* buffer for storing received bytes - size must be power of two */
/* BACnet MAX_MPDU for MS/TP is 501 bytes */
/* BACnet DLMSTP_MPDU_MAX for MS/TP is 501 bytes */
static uint8_t Receive_Queue_Data[512];
static FIFO_BUFFER Receive_Queue;
/* buffer for storing bytes to transmit */
/* BACnet MAX_MPDU for MS/TP is 501 bytes */
/* BACnet DLMSTP_MPDU_MAX for MS/TP is 501 bytes */
static uint8_t Transmit_Queue_Data[512];
static FIFO_BUFFER Transmit_Queue;
+4 -4
View File
@@ -54,8 +54,8 @@ static DLMSTP_PACKET Transmit_Packet;
/* local MS/TP port data - shared with RS-485 */
volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
/* Timer that indicates line silence - and functions */
static uint32_t SilenceStartTime;
static uint32_t TimeBeginPeriod;
@@ -282,7 +282,7 @@ uint16_t MSTP_Get_Send(
} else {
destination = MSTP_BROADCAST_ADDRESS;
}
if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) {
if ((MAX_HEADER + Transmit_Packet.pdu_len) > DLMSTP_MPDU_MAX) {
return 0;
}
/* convert the PDU into the MSTP Frame */
@@ -421,7 +421,7 @@ uint16_t MSTP_Get_Reply(
} else {
return 0;
}
if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) {
if ((MAX_HEADER + Transmit_Packet.pdu_len) > DLMSTP_MPDU_MAX) {
return 0;
}
/* is this the reply to the DER? */
+4 -4
View File
@@ -53,8 +53,8 @@ static DLMSTP_PACKET Transmit_Packet;
/* local MS/TP port data - shared with RS-485 */
volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
/* The minimum time without a DataAvailable or ReceiveError event */
/* that a node must wait for a station to begin replying to a */
/* confirmed request: 255 milliseconds. (Implementations may use */
@@ -267,7 +267,7 @@ uint16_t MSTP_Get_Send(
} else {
destination = MSTP_BROADCAST_ADDRESS;
}
if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) {
if ((MAX_HEADER + Transmit_Packet.pdu_len) > DLMSTP_MPDU_MAX) {
return 0;
}
/* convert the PDU into the MSTP Frame */
@@ -407,7 +407,7 @@ uint16_t MSTP_Get_Reply(
} else {
return 0;
}
if ((MAX_HEADER + Transmit_Packet.pdu_len) > MAX_MPDU) {
if ((MAX_HEADER + Transmit_Packet.pdu_len) > DLMSTP_MPDU_MAX) {
return 0;
}
/* is this the reply to the DER? */
+3 -3
View File
@@ -193,7 +193,7 @@ bool ethernet_init(char *if_name)
*/
/* Open the output device */
pcap_eth802_fp = pcap_open(if_name, /* name of the device */
MAX_MPDU, /* portion of the packet to capture */
ETHERNET_MPDU_MAX, /* portion of the packet to capture */
PCAP_OPENFLAG_PROMISCUOUS, /* promiscuous mode */
eth_timeout, /* read timeout */
NULL, /* authentication on the remote machine */
@@ -226,7 +226,7 @@ int ethernet_send(BACNET_ADDRESS *dest, /* destination address */
)
{
int bytes = 0;
uint8_t mtu[MAX_MPDU] = { 0 };
uint8_t mtu[ETHERNET_MPDU_MAX] = { 0 };
int mtu_len = 0;
int i = 0;
@@ -256,7 +256,7 @@ int ethernet_send(BACNET_ADDRESS *dest, /* destination address */
LogError("ethernet.c: invalid source MAC address!\n");
return -3;
}
if ((14 + 3 + pdu_len) > MAX_MPDU) {
if ((14 + 3 + pdu_len) > ETHERNET_MPDU_MAX) {
LogError("ethernet.c: PDU is too big to send!\n");
return -4;
}
+1 -1
View File
@@ -226,7 +226,7 @@ static void RS485_Configure_Status(void)
RS485_Print_Error();
}
/* Set the Comm buffer size */
SetupComm(RS485_Handle, MAX_MPDU, MAX_MPDU);
SetupComm(RS485_Handle, DLMSTP_MPDU_MAX, DLMSTP_MPDU_MAX);
/* raise DTR */
if (!EscapeCommFunction(RS485_Handle, SETDTR)) {
fprintf(stderr, "Unable to set DTR on %s\n", RS485_Port_Name);
+2 -2
View File
@@ -78,8 +78,8 @@ typedef struct pcaprec_hdr_s {
/* local port data - shared with RS-485 */
volatile struct mstp_port_struct_t MSTP_Port;
static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[DLMSTP_MPDU_MAX];
static uint8_t TxBuffer[DLMSTP_MPDU_MAX];
static uint16_t SilenceTime;
#define INCREMENT_AND_LIMIT_UINT16(x) \
{ \
+1 -1
View File
@@ -177,7 +177,7 @@ struct mstp_pdu_packet {
bool data_expecting_reply;
uint8_t destination_mac;
uint16_t length;
uint8_t buffer[MAX_MPDU];
uint8_t buffer[DLMSTP_MPDU_MAX];
};
static volatile struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT];
static RING_BUFFER PDU_Queue;
+2 -2
View File
@@ -32,8 +32,8 @@
#include "bacnet/npdu.h"
/* specific defines for Ethernet */
#define MAX_HEADER (6+6+2+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
#define ETHERNET_HEADER_MAX (6+6+2+1+1+1)
#define ETHERNET_MPDU_MAX (ETHERNET_HEADER_MAX+MAX_PDU)
/* Unless we explicitly need these remaps to be NOT exposed
* (e.g. implementation where we need both bacnet and Zephyr symbols),