From a81814147a4bd2ac1298d5068812c627c84151e8 Mon Sep 17 00:00:00 2001 From: skarg Date: Wed, 30 Jul 2008 20:33:00 +0000 Subject: [PATCH] Added some print info the mstpcap demo like packet count, baud rate, and interface. --- bacnet-stack/demo/mstpcap/Makefile | 5 +++-- bacnet-stack/demo/mstpcap/main.c | 16 ++++++++++++---- bacnet-stack/ports/linux/rs485.c | 15 ++++++++++++++- bacnet-stack/ports/linux/rs485.h | 1 + bacnet-stack/ports/win32/rs485.c | 9 ++++++++- bacnet-stack/ports/win32/rs485.h | 1 + 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/bacnet-stack/demo/mstpcap/Makefile b/bacnet-stack/demo/mstpcap/Makefile index 33b35846..e6935ac1 100644 --- a/bacnet-stack/demo/mstpcap/Makefile +++ b/bacnet-stack/demo/mstpcap/Makefile @@ -27,8 +27,9 @@ ifeq (${BACNET_PORT},win32) TARGET_BIN = ${TARGET}.exe LIBRARIES=-lws2_32,-lgcc,-lm,-liphlpapi endif -DEBUGGING = -g -OPTIMIZATION = -O0 +#DEBUGGING = -g +#OPTIMIZATION = -O0 +OPTIMIZATION = -Os CFLAGS = -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES) -fdata-sections -ffunction-sections LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES),--gc-sections diff --git a/bacnet-stack/demo/mstpcap/main.c b/bacnet-stack/demo/mstpcap/main.c index dab700e0..72c3aaa3 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -170,7 +170,7 @@ static void write_global_header(void) fprintf(stdout,"mstpcap: saving capture to %s\n", Capture_Filename); } else { - fprintf(stderr,"rx_fsm: failed to open %s: %s\n", + fprintf(stderr,"mstpcap: failed to open %s: %s\n", Capture_Filename, strerror(errno)); } } @@ -209,11 +209,11 @@ static void write_received_packet( fwrite(header,sizeof(header),1,pFile); if (mstp_port->DataLength) { fwrite(mstp_port->InputBuffer,mstp_port->DataLength,1,pFile); - fwrite(&(mstp_port->DataCRCActualMSB),1,1,pFile); - fwrite(&(mstp_port->DataCRCActualLSB),1,1,pFile); + fwrite((char *)&mstp_port->DataCRCActualMSB,1,1,pFile); + fwrite((char *)&mstp_port->DataCRCActualLSB,1,1,pFile); } } else { - fprintf(stderr,"rx_fsm: failed to open %s: %s\n", + fprintf(stderr,"mstpcap: failed to open %s: %s\n", Capture_Filename, strerror(errno)); } } @@ -252,6 +252,7 @@ int main( volatile struct mstp_port_struct_t *mstp_port; int my_mac = 127; long my_baud = 38400; + uint32_t packet_count = 0; #if defined(_WIN32) unsigned long hThread = 0; uint32_t arg_value = 0; @@ -287,6 +288,8 @@ int main( MSTP_Port.SilenceTimerReset = Timer_Silence_Reset; MSTP_Init(mstp_port); mstp_port->Lurking = true; + fprintf(stdout,"mstpcap: Using %s for capture at %lu bps.\n", + RS485_Interface(), RS485_Get_Baud_Rate()); #if defined(_WIN32) hThread = _beginthread(milliseconds_task, 4096, &arg_value); if (hThread == 0) { @@ -309,10 +312,15 @@ int main( if (mstp_port->ReceivedValidFrame) { mstp_port->ReceivedValidFrame = false; write_received_packet(mstp_port); + packet_count++; } else if (mstp_port->ReceivedInvalidFrame) { mstp_port->ReceivedInvalidFrame = false; fprintf(stderr, "ReceivedInvalidFrame\n"); write_received_packet(mstp_port); + packet_count++; + } + if (!(packet_count % 100)) { + fprintf(stdout,"\r%hu packets",packet_count); } } diff --git a/bacnet-stack/ports/linux/rs485.c b/bacnet-stack/ports/linux/rs485.c index 9dd627b9..22c32978 100644 --- a/bacnet-stack/ports/linux/rs485.c +++ b/bacnet-stack/ports/linux/rs485.c @@ -80,7 +80,20 @@ void RS485_Set_Interface( char *ifname) { /* note: expects a constant char, or char from the heap */ - RS485_Port_Name = ifname; + if (ifname) { + RS485_Port_Name = ifname; + } +} + +/********************************************************************* +* DESCRIPTION: Returns the interface name +* RETURN: none +* ALGORITHM: none +* NOTES: none +*********************************************************************/ +const char *RS485_Interface(void) +{ + return RS485_Port_Name; } /**************************************************************************** diff --git a/bacnet-stack/ports/linux/rs485.h b/bacnet-stack/ports/linux/rs485.h index 81e5b269..8fd25050 100644 --- a/bacnet-stack/ports/linux/rs485.h +++ b/bacnet-stack/ports/linux/rs485.h @@ -45,6 +45,7 @@ extern "C" { void RS485_Set_Interface( char *ifname); + const char * RS485_Interface(void); void RS485_Initialize( void); diff --git a/bacnet-stack/ports/win32/rs485.c b/bacnet-stack/ports/win32/rs485.c index f4ba123a..ee068b72 100644 --- a/bacnet-stack/ports/win32/rs485.c +++ b/bacnet-stack/ports/win32/rs485.c @@ -92,7 +92,14 @@ void RS485_Set_Interface( char *ifname) { /* note: expects a constant char, or char from the heap */ - RS485_Port_Name = ifname; + if (ifname) { + RS485_Port_Name = ifname; + } +} + +const char *RS485_Interface(void) +{ + return RS485_Port_Name; } static void RS485_Print_Error( diff --git a/bacnet-stack/ports/win32/rs485.h b/bacnet-stack/ports/win32/rs485.h index 10ac1f36..fdff55bc 100644 --- a/bacnet-stack/ports/win32/rs485.h +++ b/bacnet-stack/ports/win32/rs485.h @@ -45,6 +45,7 @@ extern "C" { void RS485_Set_Interface( char *ifname); + const char * RS485_Interface(void); void RS485_Initialize( void);