Bugfix/router mstp builds (#630)

* Fixed example app router-ipv6 to build under ports/win32

* Fixed example app router-mstp to build under ports/win32 with MinGW

* Added win32 builds of router-ipv6 and router-mstp to the Github pipeline
This commit is contained in:
Steve Karg
2024-04-30 13:52:00 -05:00
committed by GitHub
parent b90b14e5f6
commit 96222574f8
11 changed files with 221 additions and 210 deletions
+4 -36
View File
@@ -5,7 +5,7 @@
# CC = gcc
# Executable file name
TARGET = bacroute
TARGET = router-ipv6
TARGET_BIN = ${TARGET}$(TARGET_EXT)
@@ -13,49 +13,17 @@ TARGET_BIN = ${TARGET}$(TARGET_EXT)
# BACNET_SRC_DIR is defined in common apps Makefile
BACNET_OBJECT_DIR = $(BACNET_SRC_DIR)/bacnet/basic/object
SRC = main.c \
$(BACNET_OBJECT_DIR)/netport.c \
$(BACNET_OBJECT_DIR)/client/device-client.c
PORT_BIP6_SRC = \
$(BACNET_PORT_DIR)/bip6.c \
$(BACNET_SRC_DIR)/bacnet/datalink/bvlc6.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd6/h_bbmd6.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd6/vmac.c
PORT_BIP_SRC = \
$(BACNET_PORT_DIR)/bip-init.c \
$(BACNET_SRC_DIR)/bacnet/datalink/bvlc.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd/h_bbmd.c
$(BACNET_SRC_DIR)/bacnet/basic/npdu/s_router.c
# WARNINGS, DEBUGGING, OPTIMIZATION are defined in common apps Makefile
# BACNET_DEFINES is defined in common apps Makefile
# put all the flags together
INCLUDES = -I$(BACNET_SRC_DIR) -I$(BACNET_PORT_DIR)
CFLAGS += $(WARNINGS) $(DEBUGGING) $(OPTIMIZATION) $(BACNET_DEFINES) $(INCLUDES)
LFLAGS += -Wl,$(SYSTEM_LIB)
ifneq (${BACNET_LIB},)
LFLAGS += -Wl,$(BACNET_LIB)
endif
# GCC dead code removal
CFLAGS += -ffunction-sections -fdata-sections
LFLAGS += -Wl,--gc-sections
BACNET_SRC = \
$(wildcard $(BACNET_SRC_DIR)/bacnet/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/binding/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/service/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/sys/*.c) \
$(BACNET_SRC_DIR)/bacnet/basic/npdu/h_routed_npdu.c \
$(BACNET_SRC_DIR)/bacnet/basic/npdu/s_router.c \
$(BACNET_SRC_DIR)/bacnet/basic/tsm/tsm.c
SRCS = ${SRC} ${BACNET_SRC} ${PORT_BIP6_SRC} ${PORT_BIP_SRC}
SRCS = ${SRC}
OBJS += ${SRCS:.c=.o}
.PHONY: all
all: Makefile ${TARGET_BIN}
all: ${BACNET_LIB_TARGET} Makefile ${TARGET_BIN}
${TARGET_BIN}: ${OBJS}
${CC} ${PFLAGS} ${OBJS} ${LFLAGS} -o $@
+26 -3
View File
@@ -62,6 +62,7 @@
/* current version of the BACnet stack */
static const char *BACnet_Version = BACNET_VERSION_TEXT;
static uint32_t Device_Instance_Number = BACNET_MAX_INSTANCE;
/**
* 6.6.1 Routing Tables
@@ -602,6 +603,8 @@ static void who_is_router_to_network_handler(uint16_t snet,
uint16_t network = 0;
uint16_t len = 0;
(void)src;
(void)npdu_data;
if (npdu) {
if (npdu_len >= 2) {
len += decode_unsigned16(&npdu[len], &network);
@@ -948,12 +951,16 @@ static void my_routing_npdu_handler(
uint16_t snet, BACNET_ADDRESS *src, uint8_t *pdu, uint16_t pdu_len)
{
int apdu_offset = 0;
unsigned protocol_version = 0;
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
if (!pdu) {
/* no packet */
} else if (pdu[0] == BACNET_PROTOCOL_VERSION) {
} else {
protocol_version = pdu[0];
}
if (protocol_version == BACNET_PROTOCOL_VERSION) {
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
if (apdu_offset <= 0) {
fprintf(stderr, "NPDU: Decoding failed; Discarded!\n");
@@ -994,7 +1001,9 @@ static void my_routing_npdu_handler(
}
}
} else {
/* unsupported protocol version */
fprintf(
stderr, "NPDU: unsupported protocol version %u. Discarded!\n",
protocol_version);
}
return;
@@ -1126,6 +1135,17 @@ static void control_c_hooks(void)
}
#endif
/**
* @brief Get the Device object instance number
* @return The Device object instance number
* @note This is a proxy function to satisfy the BACnet Stack IPv6 port layer
* requirements since this application omits a Device object.
*/
uint32_t Device_Object_Instance_Number(void)
{
return Device_Instance_Number;
}
/**
* Main function of simple router demo.
*
@@ -1141,8 +1161,11 @@ int main(int argc, char *argv[])
time_t current_seconds = 0;
uint32_t elapsed_seconds = 0;
printf("BACnet Simple IP Router Demo\n");
printf("BACnet Simple IP to IPv6 Router Demo\n");
printf("BACnet Stack Version %s\n", BACnet_Version);
if (argc > 1) {
Device_Instance_Number = strtol(argv[1], NULL, 0);
}
datalink_init();
atexit(cleanup);
control_c_hooks();