Feature/router bsd (#821)

* fix router compile warnings declaration-after-statement overlength-strings

* router disable PRINT(debug_level)

* ports rename dlmstp_[linux|bsd] to dlmstp_port

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* fix typedef in bip_get_local_address_ioctl

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* add bsd support for router app

* fix clang __attribute__ optimize dont work
clang O2/O3/Os are also not working

* fix pre-commit

* fix bsd SO_BINDTODEVICE is not available

* add brew install libconfig for app router and bsd

* fix BACDL_MSTP test on macOS

* remove old comments
This commit is contained in:
Patrick Grimm
2024-10-21 14:53:01 +02:00
committed by GitHub
parent 57c3b81bb1
commit b9de08cf60
18 changed files with 1127 additions and 103 deletions
+5 -1
View File
@@ -15,6 +15,10 @@ ifeq (${BACNET_PORT},linux)
TARGET_EXT =
LIBS = -lpthread -lconfig -lm
LFLAGS = $(LIBS)
else ifeq (${BACNET_PORT},bsd)
TARGET_EXT =
LIBS = -lpthread -lconfig -lm
LFLAGS = $(LIBS)
endif
SOURCE_DIR = ../../src
@@ -24,7 +28,7 @@ SRCS = main.c \
${BACNET_PORT_DIR}/rs485.c \
${BACNET_PORT_DIR}/mstimer-init.c \
${BACNET_PORT_DIR}/bip-init.c \
${BACNET_PORT_DIR}/dlmstp_linux.c \
${BACNET_PORT_DIR}/dlmstp_port.c \
${BACNET_SOURCE_DIR}/basic/bbmd/h_bbmd.c \
${BACNET_SOURCE_DIR}/datalink/bvlc.c \
${BACNET_SOURCE_DIR}/basic/sys/fifo.c \
+3 -3
View File
@@ -24,7 +24,7 @@ uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */
/* BUG with optimize Os */
/* *** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated */
void __attribute__((optimize("O2"))) * dl_ip_thread(void *pArgs)
void *dl_ip_thread(void *pArgs)
{
MSGBOX_ID msgboxid;
BACMSG msg_storage, *bacmsg = NULL;
@@ -260,7 +260,7 @@ int dl_ip_recv(
struct timeval select_timeout;
struct sockaddr_in sin = { 0 };
socklen_t sin_len = sizeof(sin);
int ret;
/* make sure the socket is open */
if (data->socket < 0) {
return 0;
@@ -284,7 +284,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);
ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
/* see if there is a packet for us */
if (ret > 0) {
received_bytes = recvfrom(
+12 -12
View File
@@ -61,7 +61,7 @@ uint16_t get_next_free_dnet(void);
int kbhit(void);
inline bool is_network_msg(const BACMSG *msg);
bool is_network_msg(const BACMSG *msg);
int main(int argc, char *argv[])
{
@@ -189,16 +189,16 @@ void print_help(void)
"-c, --config <filepath>\n\tinitialize router with a configuration "
"file (.cfg) located at <filepath>\n"
"-D, --device <dev_type> <iface> [params]\n\tinitialize a <dev_type> "
"device using an <iface> interface specified with\n\t[params]\n"
"\ninit_parameters:\n"
"-n, --network <net>\n\tspecify device network number\n"
"-P, --port <port>\n\tspecify udp port for BIP device\n"
"-m, --mac <mac_address> [max_master] [max_frames]\n\tspecify MSTP "
"port parameters\n"
"-b, --baud <baud>\n\tspecify MSTP port baud rate\n"
"-p, --parity <None|Even|Odd>\n\tspecify MSTP port parity\n"
"-d, --databits <5|6|7|8>\n\tspecify MSTP port databits\n"
"-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n");
"device using an <iface> interface specified with\n\t[params]\n");
printf("\ninit_parameters:\n"
"-n, --network <net>\n\tspecify device network number\n"
"-P, --port <port>\n\tspecify udp port for BIP device\n"
"-m, --mac <mac_address> [max_master] [max_frames]\n\tspecify MSTP "
"port parameters\n"
"-b, --baud <baud>\n\tspecify MSTP port baud rate\n"
"-p, --parity <None|Even|Odd>\n\tspecify MSTP port parity\n"
"-d, --databits <5|6|7|8>\n\tspecify MSTP port databits\n"
"-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n");
}
bool read_config(const char *filepath)
@@ -813,6 +813,7 @@ int kbhit(void)
{
static const int STDIN = 0;
static bool initialized = false;
int bytesWaiting;
if (!initialized) {
/* use termios to turn off line buffering */
@@ -824,7 +825,6 @@ int kbhit(void)
initialized = true;
}
int bytesWaiting;
ioctl(STDIN, FIONREAD, &bytesWaiting);
return bytesWaiting;
}
+1 -8
View File
@@ -14,16 +14,9 @@
#include <sys/ipc.h>
#include "mstpmodule.h"
#include "bacnet/bacint.h"
#include "dlmstp_linux.h"
#include "dlmstp_port.h"
#include <termios.h>
#define MSTP_THREAD_PRINT_ENABLED
#ifdef MSTP_THREAD_PRINT_ENABLED
#define mstp_thread_debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define mstp_thread_debug(...)
#endif
void *dl_mstp_thread(void *pArgs)
{
ROUTER_PORT *port = (ROUTER_PORT *)pArgs;
+3 -2
View File
@@ -25,6 +25,8 @@ process_network_message(const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
int16_t buff_len = 0;
int apdu_offset;
int apdu_len;
int net_count;
int i;
memmove(data, msg->data, sizeof(MSG_DATA));
@@ -68,8 +70,7 @@ process_network_message(const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: {
PRINT(INFO, "Recieved I-Am-Router-To-Network message\n");
int net_count = apdu_len / 2;
int i;
net_count = apdu_len / 2;
for (i = 0; i < net_count; i++) {
decode_unsigned16(
&data->pdu[apdu_offset + 2 * i],
+1 -1
View File
@@ -25,7 +25,7 @@
#define INFO 2
#define DEBUG 3
#define DEBUG_LEVEL 3
/* #define DEBUG_LEVEL 3 */
#ifdef DEBUG_LEVEL
#define PRINT(debug_level, ...) \
if (debug_level <= DEBUG_LEVEL) \