updated linux rs485 functional test to compile and run

This commit is contained in:
skarg
2013-12-23 19:36:32 +00:00
parent 1a94b076e5
commit 92559791ba
2 changed files with 50 additions and 25 deletions
+34 -15
View File
@@ -391,7 +391,11 @@ void RS485_Send_Frame(
uint32_t baud; uint32_t baud;
ssize_t written = 0; ssize_t written = 0;
int greska; int greska;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = NULL;
if (mstp_port) {
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
}
if (!poSharedData) { if (!poSharedData) {
baud = RS485_Get_Baud_Rate(); baud = RS485_Get_Baud_Rate();
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
@@ -626,27 +630,42 @@ int main(
int argc, int argc,
char *argv[]) char *argv[])
{ {
uint8_t buf[8]; volatile struct mstp_port_struct_t mstp_port = {0};
char *wbuf = { "BACnet!" }; uint8_t token_buf[8] = {0x55, 0xFF, 0x00, 0x7E, 0x07, 0x00, 0x00, 0xFD};
size_t wlen = strlen(wbuf) + 1; uint8_t pfm_buf[8] = {0x55, 0xFF, 0x01, 0x67, 0x07, 0x00, 0x00, 0x3E};
unsigned i = 0; long baud = 38400;
size_t written = 0; bool write_token = false;
int rlen; bool write_pfm = false;
/* argv has the "/dev/ttyS0" or some other device */ /* argv has the "/dev/ttyS0" or some other device */
if (argc > 1) { if (argc > 1) {
RS485_Set_Interface(argv[1]); RS485_Set_Interface(argv[1]);
} }
RS485_Set_Baud_Rate(38400); if (argc > 2) {
baud = strtol(argv[2], NULL, 0);
}
if (argc > 3) {
if (strcmp("token", argv[3]) == 0) {
write_token = true;
}
if (strcmp("pfm", argv[3]) == 0) {
write_pfm = true;
}
}
RS485_Set_Baud_Rate(baud);
RS485_Initialize(); RS485_Initialize();
for (;;) { for (;;) {
written = write(RS485_Handle, wbuf, wlen); if (write_token) {
rlen = read(RS485_Handle, buf, sizeof(buf)); RS485_Send_Frame(NULL,token_buf, sizeof(token_buf));
/* print any characters received */ usleep(25000);
if (rlen > 0) { } else if (write_pfm) {
for (i = 0; i < rlen; i++) { RS485_Send_Frame(NULL,pfm_buf, sizeof(pfm_buf));
fprintf(stderr, "%02X ", buf[i]); usleep(100000);
} else {
RS485_Check_UART_Data(&mstp_port);
if (mstp_port.DataAvailable) {
fprintf(stderr, "%02X ", mstp_port.DataRegister);
mstp_port.DataAvailable = false;
} }
} }
} }
+13 -7
View File
@@ -1,21 +1,27 @@
#Makefile to build test case #Makefile to build test case
CC = gcc #CC = gcc
BASEDIR = . TARGET = rs485
# Directories
BACNET_SOURCE_DIR = ../../src
BACNET_INCLUDE = ../../include
# -g for debugging with gdb # -g for debugging with gdb
DEFINES = -DBIG_ENDIAN=0 -DTEST_RS485 -DBACDL_TEST DEFINES = -DBIG_ENDIAN=0 -DTEST_RS485 -DBACDL_TEST
INCLUDES = -I. -I../../ INCLUDES = -I. -I../../ -I$(BACNET_INCLUDE)
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
LIBRARIES=-lc,-lgcc,-lrt,-lm
LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES),--gc-sections
SRCS = rs485.c SRCS = rs485.c \
${BACNET_SOURCE_DIR}/fifo.c
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}
TARGET = rs485
all: ${TARGET} all: ${TARGET}
${TARGET}: ${OBJS} ${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS} ${CC} ${OBJS} ${LFLAGS} -o $@
.c.o: .c.o:
${CC} -c ${CFLAGS} $*.c -o $@ ${CC} -c ${CFLAGS} $*.c -o $@