From f88f5a3424b3c598f7ac88651bd396b4ad11f83e Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Thu, 31 Jul 2025 09:40:18 -0500 Subject: [PATCH] Fixed the Linux DLMSTP standalone test application Makefile. (#1055) --- Makefile | 6 ++++++ bin/readme.txt | 21 +++++++++++++++++++++ doc/README.utils | 5 ++++- ports/linux/dlmstp.c | 5 +++-- ports/linux/dlmstp.mak | 24 ++++++++++++++++++++---- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 33a758c1..051efd4c 100644 --- a/Makefile +++ b/Makefile @@ -369,6 +369,10 @@ xplained-clean: ports/xplained/Makefile mstpsnap: ports/linux/mstpsnap.mak $(MAKE) -s -C ports/linux -f mstpsnap.mak clean all +.PHONY: dlmstp-linux +dlmstp-linux: ports/linux/dlmstp.mak + $(MAKE) -s -C ports/linux -f dlmstp.mak clean all + .PHONY: lwip lwip: ports/lwip/Makefile $(MAKE) -s -C ports/lwip clean all @@ -520,6 +524,8 @@ clean: ports-clean $(MAKE) -s -C apps/fuzz-libfuzzer clean $(MAKE) -s -C ports/lwip clean $(MAKE) -s -C test clean + $(MAKE) -s -C ports/linux -f mstpsnap.mak clean + $(MAKE) -s -C ports/linux -f dlmstp.mak clean rm -rf ./build .PHONY: test diff --git a/bin/readme.txt b/bin/readme.txt index 928ee67a..700d0c80 100644 --- a/bin/readme.txt +++ b/bin/readme.txt @@ -117,6 +117,27 @@ BACNET_IP_NAT_ADDR - dotted IPv4 address of the public facing router BACNET_IP_BROADCAST_BIND_ADDR - dotted IPv4 address to bind broadcasts +When the tools are compiled to use MS/TP datalink, the following +environment variables are used: + +BACNET_MAX_INFO_FRAMES - BACnet MS/TP max-info-frames parameter. + Defaults to 127. + +BACNET_MAX_MASTER - BACnet MS/TP max-master parameter. + Defaults to 127. + +BACNET_MSTP_BAUD - BACnet MS/TP baud rate. + Defaults to 38400. + +BACNET_MSTP_MAC - BACnet MS/TP MAC address. + Defaults to 127. + +BACNET_IFACE - interface to use for the MS/TP datalink layer + For Linux, this is something like /dev/ttyS0 or /dev/ttyUSB0 + For Windows, this is something like COM4 or COM23 + Defaults to /dev/ttyUSB0 on Linux and COM4 on Windows + and /dev/cu.usbserial-7 on macOS. + Example Usage ------------- You can communicate with the virtual BACnet Device by using the other BACnet diff --git a/doc/README.utils b/doc/README.utils index f2b6f369..fd84437b 100644 --- a/doc/README.utils +++ b/doc/README.utils @@ -10,7 +10,7 @@ to configure the network. BACNET_IFACE - interface to use for the datalink layer For Linux, this is something like eth0 or /dev/ttyS0. For Windows, this is something like 192.168.0.1 or COM4 - Defaults to NULL. + Defaults to NULL which tries to discover the localhost. BACNET_IP_PORT - BACnet/IP port number. Defaults to 47808. @@ -27,6 +27,9 @@ BACNET_BBMD_ADDRESS - dotted IP address or domain name of BBMD. BACNET_MAX_INFO_FRAMES - BACnet MS/TP max-info-frames parameter. Defaults to 127. +BACNET_MAX_MASTER - BACnet MS/TP max-master parameter. + Defaults to 127. + BACNET_MSTP_BAUD - BACnet MS/TP baud rate. Defaults to 38400. diff --git a/ports/linux/dlmstp.c b/ports/linux/dlmstp.c index 00a1b4e3..73f72827 100644 --- a/ports/linux/dlmstp.c +++ b/ports/linux/dlmstp.c @@ -1159,9 +1159,9 @@ static char *Network_Interface = NULL; int main(int argc, char *argv[]) { - uint16_t pdu_len = 0; + uint16_t pdu_len; - /* argv has the "COM4" or some other device */ + /* argv has the "/dev/ttyUSB0" or some other device */ if (argc > 1) { Network_Interface = argv[1]; } @@ -1176,6 +1176,7 @@ int main(int argc, char *argv[]) MSTP_Create_And_Send_Frame( &MSTP_Port, FRAME_TYPE_TEST_REQUEST, MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0); + (void)pdu_len; } return 0; diff --git a/ports/linux/dlmstp.mak b/ports/linux/dlmstp.mak index 3c8b8a48..4a01b4cd 100644 --- a/ports/linux/dlmstp.mak +++ b/ports/linux/dlmstp.mak @@ -1,15 +1,30 @@ #Makefile to build test case -CC = gcc BASEDIR = . +BACNET_SRC_DIR ?= $(realpath ../../src) # -g for debugging with gdb DEFINES = -DBIG_ENDIAN=0 -DBACDL_MSTP=1 -DTEST_DLMSTP -INCLUDES = -I. -I../../ +DEFINES += -DBACNET_STACK_DEPRECATED_DISABLE +INCLUDES = -I. -I$(BACNET_SRC_DIR) CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g SRCS = rs485.c \ dlmstp.c \ - ../../mstp.c \ - ../../crc.c + mstimer-init.c \ + $(BACNET_SRC_DIR)/bacnet/datalink/cobs.c \ + $(BACNET_SRC_DIR)/bacnet/datalink/crc.c \ + $(BACNET_SRC_DIR)/bacnet/datalink/mstp.c \ + $(BACNET_SRC_DIR)/bacnet/datalink/mstptext.c \ + $(BACNET_SRC_DIR)/bacnet/basic/sys/debug.c \ + $(BACNET_SRC_DIR)/bacnet/basic/sys/fifo.c \ + $(BACNET_SRC_DIR)/bacnet/basic/sys/mstimer.c \ + $(BACNET_SRC_DIR)/bacnet/basic/sys/ringbuf.c \ + $(BACNET_SRC_DIR)/bacnet/bacaddr.c \ + $(BACNET_SRC_DIR)/bacnet/bacdcode.c \ + $(BACNET_SRC_DIR)/bacnet/bacint.c \ + $(BACNET_SRC_DIR)/bacnet/bacreal.c \ + $(BACNET_SRC_DIR)/bacnet/bacstr.c \ + $(BACNET_SRC_DIR)/bacnet/indtext.c \ + $(BACNET_SRC_DIR)/bacnet/npdu.c OBJS = ${SRCS:.c=.o} @@ -19,6 +34,7 @@ all: ${TARGET} ${TARGET}: ${OBJS} ${CC} -pthread -o $@ ${OBJS} + size $@ .c.o: ${CC} -c ${CFLAGS} $*.c -o $@