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.
This commit is contained in:
@@ -16,6 +16,7 @@ SRCS = bacdcode.c \
|
|||||||
indtext.c \
|
indtext.c \
|
||||||
apdu.c \
|
apdu.c \
|
||||||
dcc.c \
|
dcc.c \
|
||||||
|
version.c \
|
||||||
demo/object/device.c \
|
demo/object/device.c \
|
||||||
test/ctest.c
|
test/ctest.c
|
||||||
|
|
||||||
|
|||||||
+39
-4
@@ -1184,8 +1184,12 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
|
|||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "ringbuf.h"
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
|
|
||||||
|
static uint8_t RxBuffer[MAX_MPDU];
|
||||||
|
static uint8_t TxBuffer[MAX_MPDU];
|
||||||
|
|
||||||
/* test stub functions */
|
/* test stub functions */
|
||||||
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
|
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) */
|
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)
|
void testReceiveNodeFSM(Test * pTest)
|
||||||
{
|
{
|
||||||
volatile struct mstp_port_struct_t mstp_port; /* port data */
|
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 buffer[MAX_MPDU] = { 0 };
|
||||||
uint8_t data[MAX_MPDU - 8 /*header */ - 2 /*CRC*/] = { 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 */
|
/* check the receive error during idle */
|
||||||
mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE;
|
mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||||
@@ -1613,11 +1641,18 @@ void testReceiveNodeFSM(Test * pTest)
|
|||||||
|
|
||||||
void testMasterNodeFSM(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 */
|
uint8_t my_mac = 0x05; /* local MAC address */
|
||||||
|
|
||||||
MSTP_Init(&mstp_port, my_mac);
|
MSTP_Port.InputBuffer = &RxBuffer[0];
|
||||||
ct_test(pTest, mstp_port.master_state == MSTP_MASTER_STATE_INITIALIZE);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ BASEDIR = .
|
|||||||
#CFLAGS = -Wall -I.
|
#CFLAGS = -Wall -I.
|
||||||
# -g for debugging with gdb
|
# -g for debugging with gdb
|
||||||
#CFLAGS = -Wall -I. -g
|
#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
|
OBJS = mstp.o crc.o ringbuf.o test/ctest.o
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
|||||||
/* if error, */
|
/* if error, */
|
||||||
/* ReceiveError = TRUE; */
|
/* ReceiveError = TRUE; */
|
||||||
/* return; */
|
/* return; */
|
||||||
if (count) {
|
if (count > 0) {
|
||||||
mstp_port->DataRegister = buf[0];
|
mstp_port->DataRegister = buf[0];
|
||||||
/* if data is ready, */
|
/* if data is ready, */
|
||||||
mstp_port->DataAvailable = true;
|
mstp_port->DataAvailable = true;
|
||||||
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
|
|||||||
written = write(RS485_Handle, wbuf, wlen);
|
written = write(RS485_Handle, wbuf, wlen);
|
||||||
rlen = read(RS485_Handle,buf,sizeof(buf));
|
rlen = read(RS485_Handle,buf,sizeof(buf));
|
||||||
/* print any characters received */
|
/* print any characters received */
|
||||||
if (rlen) {
|
if (rlen > 0) {
|
||||||
for (i = 0; i < rlen; i++) {
|
for (i = 0; i < rlen; i++) {
|
||||||
fprintf(stderr,"%02X ",buf[i]);
|
fprintf(stderr,"%02X ",buf[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ extern "C" {
|
|||||||
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||||
uint16_t nbytes); /* number of bytes of data (up to 501) */
|
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 */
|
volatile struct mstp_port_struct_t *mstp_port); /* port specific data */
|
||||||
uint32_t RS485_Get_Baud_Rate(void);
|
uint32_t RS485_Get_Baud_Rate(void);
|
||||||
bool RS485_Set_Baud_Rate(uint32_t baud);
|
bool RS485_Set_Baud_Rate(uint32_t baud);
|
||||||
|
|||||||
@@ -67,15 +67,15 @@ void *milliseconds_task(void *pArg)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
nanosleep(&timeOut, &remains);
|
nanosleep(&timeOut, &remains);
|
||||||
dlmstp_millisecond_timer();
|
INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
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 */
|
/* 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;
|
volatile struct mstp_port_struct_t *mstp_port;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
pthread_t hThread;
|
pthread_t hThread;
|
||||||
|
int my_mac = 127;
|
||||||
|
|
||||||
/* mimic our pointer in the state machine */
|
/* mimic our pointer in the state machine */
|
||||||
mstp_port = &MSTP_Port;
|
mstp_port = &MSTP_Port;
|
||||||
/* initialize our interface */
|
/* initialize our interface */
|
||||||
if (argc > 1)
|
if (argc > 1) {
|
||||||
RS485_Set_Interface(argv[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_Set_Baud_Rate(38400);
|
||||||
RS485_Initialize();
|
RS485_Initialize();
|
||||||
MSTP_Port.InputBuffer = &RxBuffer[0];
|
MSTP_Port.InputBuffer = &RxBuffer[0];
|
||||||
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
||||||
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
||||||
MSTP_Port.OutputBufferSize = sizeof(TxBuffer);
|
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_Init(mstp_port);
|
||||||
mstp_port->Lurking = true;
|
mstp_port->Lurking = true;
|
||||||
/* start our MilliSec task */
|
/* start our MilliSec task */
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# Makefile for mingw32 on Linux
|
||||||
|
# Written by Steve Karg <skarg@users.sourceforge.net> 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,<options> Pass comma-separated <options> 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)
|
||||||
@@ -307,7 +307,7 @@ void RS485_Send_Frame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* called by timer, interrupt(?) or other thread */
|
/* 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];
|
char lpBuf[1];
|
||||||
DWORD dwRead = 0;
|
DWORD dwRead = 0;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ extern "C" {
|
|||||||
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
|
||||||
uint16_t nbytes); /* number of bytes of data (up to 501) */
|
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);
|
uint32_t RS485_Get_Baud_Rate(void);
|
||||||
bool RS485_Set_Baud_Rate(uint32_t baud);
|
bool RS485_Set_Baud_Rate(uint32_t baud);
|
||||||
|
|||||||
@@ -53,6 +53,8 @@
|
|||||||
|
|
||||||
/* local port data - shared with RS-485 */
|
/* local port data - shared with RS-485 */
|
||||||
volatile struct mstp_port_struct_t MSTP_Port;
|
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)
|
void *milliseconds_task(void *pArg)
|
||||||
{
|
{
|
||||||
@@ -137,6 +139,7 @@ int main(int argc, char *argv[])
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
unsigned long hThread = 0;
|
unsigned long hThread = 0;
|
||||||
uint32_t arg_value = 0;
|
uint32_t arg_value = 0;
|
||||||
|
int my_mac = 127;
|
||||||
|
|
||||||
/* mimic our pointer in the state machine */
|
/* mimic our pointer in the state machine */
|
||||||
mstp_port = &MSTP_Port;
|
mstp_port = &MSTP_Port;
|
||||||
@@ -144,11 +147,23 @@ int main(int argc, char *argv[])
|
|||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
Network_Interface = argv[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 */
|
/* initialize our interface */
|
||||||
RS485_Set_Interface(Network_Interface);
|
RS485_Set_Interface(Network_Interface);
|
||||||
RS485_Set_Baud_Rate(38400);
|
RS485_Set_Baud_Rate(38400);
|
||||||
RS485_Initialize();
|
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;
|
mstp_port->Lurking = true;
|
||||||
/* start our MilliSec task */
|
/* start our MilliSec task */
|
||||||
hThread = _beginthread(milliseconds_task,4096,&arg_value);
|
hThread = _beginthread(milliseconds_task,4096,&arg_value);
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ BASEDIR = .
|
|||||||
#CFLAGS = -Wall -I.
|
#CFLAGS = -Wall -I.
|
||||||
# -g for debugging with gdb
|
# -g for debugging with gdb
|
||||||
#CFLAGS = -Wall -I. -g
|
#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 \
|
SRCS = bacdcode.c \
|
||||||
bacint.c \
|
bacint.c \
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ SRCS = address.c \
|
|||||||
npdu.c \
|
npdu.c \
|
||||||
apdu.c \
|
apdu.c \
|
||||||
tsm.c \
|
tsm.c \
|
||||||
|
version.c \
|
||||||
test/ctest.c
|
test/ctest.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|||||||
Reference in New Issue
Block a user