From 53f2fc3f356b478e779abf4cd78f8dfee04d20b5 Mon Sep 17 00:00:00 2001 From: skarg Date: Sat, 18 Aug 2007 16:14:06 +0000 Subject: [PATCH] Updated the unit test make files. Fixed the init sections of MS/TP monitor (rx_fsm) modules. Corrected the rx_fsm code to check the correct return value of the read. Fixed the return value of the RS485 prototypes. --- bacnet-stack/demo/object/device.mak | 1 + bacnet-stack/mstp.c | 43 +++++++++++-- bacnet-stack/mstp.mak | 2 +- bacnet-stack/ports/linux/rs485.c | 4 +- bacnet-stack/ports/linux/rs485.h | 2 +- bacnet-stack/ports/linux/rx_fsm.c | 19 ++++-- bacnet-stack/ports/win32/makefile.mgw | 89 +++++++++++++++++++++++++++ bacnet-stack/ports/win32/rs485.c | 2 +- bacnet-stack/ports/win32/rs485.h | 2 +- bacnet-stack/ports/win32/rx_fsm.c | 17 ++++- bacnet-stack/rp.mak | 2 +- bacnet-stack/tsm.mak | 1 + 12 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 bacnet-stack/ports/win32/makefile.mgw diff --git a/bacnet-stack/demo/object/device.mak b/bacnet-stack/demo/object/device.mak index 4093e038..8063d6a9 100644 --- a/bacnet-stack/demo/object/device.mak +++ b/bacnet-stack/demo/object/device.mak @@ -16,6 +16,7 @@ SRCS = bacdcode.c \ indtext.c \ apdu.c \ dcc.c \ + version.c \ demo/object/device.c \ test/ctest.c diff --git a/bacnet-stack/mstp.c b/bacnet-stack/mstp.c index bb7363a5..5368b9f8 100644 --- a/bacnet-stack/mstp.c +++ b/bacnet-stack/mstp.c @@ -1184,8 +1184,12 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port) #ifdef TEST #include #include +#include "ringbuf.h" #include "ctest.h" +static uint8_t RxBuffer[MAX_MPDU]; +static uint8_t TxBuffer[MAX_MPDU]; + /* test stub functions */ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ @@ -1238,6 +1242,23 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) } } +uint16_t MSTP_Put_Receive( + volatile struct mstp_port_struct_t *mstp_port) +{ + return mstp_port->DataLength; +} + +/* for the MS/TP state machine to use for getting data to send */ +/* Return: amount of PDU data */ +uint16_t MSTP_Get_Send( + uint8_t src, /* source MS/TP address for creating packet */ + uint8_t * pdu, /* data to send */ + uint16_t max_pdu, /* amount of space available */ + unsigned timeout) /* milliseconds to wait for a packet */ +{ + return 0; +} + void testReceiveNodeFSM(Test * pTest) { volatile struct mstp_port_struct_t mstp_port; /* port data */ @@ -1250,7 +1271,14 @@ void testReceiveNodeFSM(Test * pTest) uint8_t buffer[MAX_MPDU] = { 0 }; uint8_t data[MAX_MPDU - 8 /*header */ - 2 /*CRC*/] = { 0 }; - MSTP_Init(&mstp_port, my_mac); + mstp_port.InputBuffer = &RxBuffer[0]; + mstp_port.InputBufferSize = sizeof(RxBuffer); + mstp_port.OutputBuffer = &TxBuffer[0]; + mstp_port.OutputBufferSize = sizeof(TxBuffer); + mstp_port.This_Station = my_mac; + mstp_port.Nmax_info_frames = 1; + mstp_port.Nmax_master = 127; + MSTP_Init(&mstp_port); /* check the receive error during idle */ mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -1613,11 +1641,18 @@ void testReceiveNodeFSM(Test * pTest) void testMasterNodeFSM(Test * pTest) { - volatile struct mstp_port_struct_t mstp_port; /* port data */ + volatile struct mstp_port_struct_t MSTP_Port; /* port data */ uint8_t my_mac = 0x05; /* local MAC address */ - MSTP_Init(&mstp_port, my_mac); - ct_test(pTest, mstp_port.master_state == MSTP_MASTER_STATE_INITIALIZE); + MSTP_Port.InputBuffer = &RxBuffer[0]; + MSTP_Port.InputBufferSize = sizeof(RxBuffer); + MSTP_Port.OutputBuffer = &TxBuffer[0]; + MSTP_Port.OutputBufferSize = sizeof(TxBuffer); + MSTP_Port.This_Station = my_mac; + MSTP_Port.Nmax_info_frames = 1; + MSTP_Port.Nmax_master = 127; + MSTP_Init(&MSTP_Port); + ct_test(pTest, MSTP_Port.master_state == MSTP_MASTER_STATE_INITIALIZE); } diff --git a/bacnet-stack/mstp.mak b/bacnet-stack/mstp.mak index d93124de..a2c7d535 100644 --- a/bacnet-stack/mstp.mak +++ b/bacnet-stack/mstp.mak @@ -4,7 +4,7 @@ BASEDIR = . #CFLAGS = -Wall -I. # -g for debugging with gdb #CFLAGS = -Wall -I. -g -CFLAGS = -Wall -I. -Itest -DTEST -DTEST_MSTP -g +CFLAGS = -Wall -I. -Iports/linux -Itest -DTEST -DTEST_MSTP -g OBJS = mstp.o crc.o ringbuf.o test/ctest.o diff --git a/bacnet-stack/ports/linux/rs485.c b/bacnet-stack/ports/linux/rs485.c index 164f24b6..921b586d 100644 --- a/bacnet-stack/ports/linux/rs485.c +++ b/bacnet-stack/ports/linux/rs485.c @@ -195,7 +195,7 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port) /* if error, */ /* ReceiveError = TRUE; */ /* return; */ - if (count) { + if (count > 0) { mstp_port->DataRegister = buf[0]; /* if data is ready, */ mstp_port->DataAvailable = true; @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) written = write(RS485_Handle, wbuf, wlen); rlen = read(RS485_Handle,buf,sizeof(buf)); /* print any characters received */ - if (rlen) { + if (rlen > 0) { for (i = 0; i < rlen; i++) { fprintf(stderr,"%02X ",buf[i]); } diff --git a/bacnet-stack/ports/linux/rs485.h b/bacnet-stack/ports/linux/rs485.h index 6435fcd3..e52e4dcf 100644 --- a/bacnet-stack/ports/linux/rs485.h +++ b/bacnet-stack/ports/linux/rs485.h @@ -51,7 +51,7 @@ extern "C" { uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint16_t nbytes); /* number of bytes of data (up to 501) */ - uint8_t RS485_Check_UART_Data( + void RS485_Check_UART_Data( volatile struct mstp_port_struct_t *mstp_port); /* port specific data */ uint32_t RS485_Get_Baud_Rate(void); bool RS485_Set_Baud_Rate(uint32_t baud); diff --git a/bacnet-stack/ports/linux/rx_fsm.c b/bacnet-stack/ports/linux/rx_fsm.c index 065cf307..180d6a28 100644 --- a/bacnet-stack/ports/linux/rx_fsm.c +++ b/bacnet-stack/ports/linux/rx_fsm.c @@ -67,15 +67,15 @@ void *milliseconds_task(void *pArg) for (;;) { nanosleep(&timeOut, &remains); - dlmstp_millisecond_timer(); + INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer); } return NULL; } -void dlmstp_millisecond_timer(void) +volatile uint16_t *dlmstp_millisecond_timer_address(void) { - INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer); + return (&(MSTP_Port.SilenceTimer)); } /* functions used by the MS/TP state machine to put or get data */ @@ -170,19 +170,28 @@ int main(int argc, char *argv[]) volatile struct mstp_port_struct_t *mstp_port; int rc = 0; pthread_t hThread; - + int my_mac = 127; /* mimic our pointer in the state machine */ mstp_port = &MSTP_Port; /* initialize our interface */ - if (argc > 1) + if (argc > 1) { RS485_Set_Interface(argv[1]); + } + if (argc > 2) { + my_mac = strtol(argv[2], NULL, 0); + if (my_mac > 127) + my_mac = 127; + } RS485_Set_Baud_Rate(38400); RS485_Initialize(); MSTP_Port.InputBuffer = &RxBuffer[0]; MSTP_Port.InputBufferSize = sizeof(RxBuffer); MSTP_Port.OutputBuffer = &TxBuffer[0]; MSTP_Port.OutputBufferSize = sizeof(TxBuffer); + MSTP_Port.This_Station = my_mac; + MSTP_Port.Nmax_info_frames = 1; + MSTP_Port.Nmax_master = 127; MSTP_Init(mstp_port); mstp_port->Lurking = true; /* start our MilliSec task */ diff --git a/bacnet-stack/ports/win32/makefile.mgw b/bacnet-stack/ports/win32/makefile.mgw new file mode 100644 index 00000000..6aefddae --- /dev/null +++ b/bacnet-stack/ports/win32/makefile.mgw @@ -0,0 +1,89 @@ +# Makefile for mingw32 on Linux +# Written by Steve Karg 06-Aug-2007 + +TARGET=bacnet + +# Tools +CC=i586-mingw32msvc-gcc +RANLIB = /usr/i586-mingw32msvc/bin/ranlib +ASM = /usr/i586-mingw32msvc/bin/as +MKLIB = /usr/i586-mingw32msvc/bin/ar r +DLLWRAP = /usr/bin/i586-mingw32msvc-dllwrap + +BACNET_FLAGS = -DBACDL_MSTP +BACNET_FLAGS += -DPRINT_ENABLED=0 +BACNET_FLAGS += -DBIG_ENDIAN=0 +BACNET_FLAGS += -DMAX_APDU=480 +#BACNET_FLAGS += -DDLMSTP_TEST + +INCLUDES = -I. -I../.. -I../../demo/handler -I../../demo/object +OPTIMIZATION = -O0 +#OPTIMIZATION = -Os +CFLAGS = $(OPTIMIZATION) $(INCLUDES) $(BACNET_FLAGS) -Wall -g +LIBRARY = lib$(TARGET).a +# -Wl, Pass comma-separated on to the linker +LIBRARIES=-lc,-lgcc,-lm,-lwsock32,-L=.,-l$(TARGET) +LDFLAGS = -Wl,-nostdlib,-Map=$(TARGET).map,$(LIBRARIES) + +PORTSRC = main.c \ + rs485.c \ + dlmstp.c \ + ../../crc.c \ + ../../mstp.c + +DEMOSRC = ai.c \ + ../../demo/object/av.c \ + ../../demo/object/bi.c \ + ../../demo/object/bv.c \ + ../../demo/object/h_rp.c \ + ../../demo/object/h_wp.c \ + ../../demo/object/device.c \ + ../../demo/handler/txbuf.c \ + ../../demo/handler/h_whois.c \ + ../../demo/handler/h_rd.c \ + ../../demo/handler/h_dcc.c + +CORESRC = ../../npdu.c \ + ../../bacint.c \ + ../../apdu.c \ + ../../bacdcode.c \ + ../../bacstr.c \ + ../../abort.c \ + ../../bacerror.c \ + ../../reject.c \ + ../../bacapp.c \ + ../../datetime.c \ + ../../rp.c \ + ../../wp.c \ + ../../dcc.c \ + ../../rd.c \ + ../../whois.c \ + ../../iam.c \ + ../../version.c + +CSRC = $(PORTSRC) $(DEMOSRC) + +COBJ = $(CSRC:.c=.o) +COREOBJ = $(CORESRC:.c=.o) + +all: $(TARGET).exe + +$(TARGET).exe: $(COBJ) $(LIBRARY) Makefile + $(CC) $(CFLAGS) $(COBJ) $(LDFLAGS) -o $@ + +lib: $(LIBRARY) + +$(LIBRARY): $(COREOBJ) Makefile + $(AR) rcs $@ $(COREOBJ) + +.c.o: + $(CC) -c $(CFLAGS) $*.c -o $@ + +.s.o: + $(CC) -c $(AFLAGS) $*.s -o $@ + +clean: + touch Makefile + rm $(COBJ) $(COREOBJ) + rm $(TARGET).exe + rm $(LIBRARY) diff --git a/bacnet-stack/ports/win32/rs485.c b/bacnet-stack/ports/win32/rs485.c index 13bf930c..15b70da4 100644 --- a/bacnet-stack/ports/win32/rs485.c +++ b/bacnet-stack/ports/win32/rs485.c @@ -307,7 +307,7 @@ void RS485_Send_Frame( } /* called by timer, interrupt(?) or other thread */ -void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port) +void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) { char lpBuf[1]; DWORD dwRead = 0; diff --git a/bacnet-stack/ports/win32/rs485.h b/bacnet-stack/ports/win32/rs485.h index 8a9dd490..078e319c 100644 --- a/bacnet-stack/ports/win32/rs485.h +++ b/bacnet-stack/ports/win32/rs485.h @@ -51,7 +51,7 @@ extern "C" { uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint16_t nbytes); /* number of bytes of data (up to 501) */ - uint8_t RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port); /* port specific data */ + void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port); /* port specific data */ uint32_t RS485_Get_Baud_Rate(void); bool RS485_Set_Baud_Rate(uint32_t baud); diff --git a/bacnet-stack/ports/win32/rx_fsm.c b/bacnet-stack/ports/win32/rx_fsm.c index 7f71bdfe..8382ab29 100644 --- a/bacnet-stack/ports/win32/rx_fsm.c +++ b/bacnet-stack/ports/win32/rx_fsm.c @@ -53,6 +53,8 @@ /* 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]; void *milliseconds_task(void *pArg) { @@ -137,6 +139,7 @@ int main(int argc, char *argv[]) int rc = 0; unsigned long hThread = 0; uint32_t arg_value = 0; + int my_mac = 127; /* mimic our pointer in the state machine */ mstp_port = &MSTP_Port; @@ -144,11 +147,23 @@ int main(int argc, char *argv[]) if (argc > 1) { Network_Interface = argv[1]; } + if (argc > 2) { + my_mac = strtol(argv[2], NULL, 0); + if (my_mac > 127) + my_mac = 127; + } /* initialize our interface */ RS485_Set_Interface(Network_Interface); RS485_Set_Baud_Rate(38400); RS485_Initialize(); - MSTP_Init(mstp_port); + MSTP_Port.InputBuffer = &RxBuffer[0]; + MSTP_Port.InputBufferSize = sizeof(RxBuffer); + MSTP_Port.OutputBuffer = &TxBuffer[0]; + MSTP_Port.OutputBufferSize = sizeof(TxBuffer); + MSTP_Port.This_Station = my_mac; + MSTP_Port.Nmax_info_frames = 1; + MSTP_Port.Nmax_master = 127; + MSTP_Init(&MSTP_Port); mstp_port->Lurking = true; /* start our MilliSec task */ hThread = _beginthread(milliseconds_task,4096,&arg_value); diff --git a/bacnet-stack/rp.mak b/bacnet-stack/rp.mak index 3085c12c..0388656e 100644 --- a/bacnet-stack/rp.mak +++ b/bacnet-stack/rp.mak @@ -4,7 +4,7 @@ BASEDIR = . #CFLAGS = -Wall -I. # -g for debugging with gdb #CFLAGS = -Wall -I. -g -CFLAGS = -Wall -I. -Itest -DTEST -DTEST_READ_PROPERTY -g +CFLAGS = -Wall -I. -Itest -DTEST -DBIG_ENDIAN=0 -DTEST_READ_PROPERTY -g SRCS = bacdcode.c \ bacint.c \ diff --git a/bacnet-stack/tsm.mak b/bacnet-stack/tsm.mak index 5e0565ed..7c9ce5df 100644 --- a/bacnet-stack/tsm.mak +++ b/bacnet-stack/tsm.mak @@ -28,6 +28,7 @@ SRCS = address.c \ npdu.c \ apdu.c \ tsm.c \ + version.c \ test/ctest.c OBJS = ${SRCS:.c=.o}