From 6adf97553f4385be8450f54252e68989c3aaa26d Mon Sep 17 00:00:00 2001 From: skarg Date: Wed, 29 Jul 2009 17:53:32 +0000 Subject: [PATCH] Updated code to handle Borland 5.5 Compile. --- bacnet-stack/demo/mstpcap/main.c | 10 ++++----- bacnet-stack/demo/mstpcap/readme.txt | 33 ++++++++++++++++++++++++++++ bacnet-stack/lib/makefile.b32 | 1 + bacnet-stack/makefile.b32 | 1 + bacnet-stack/ports/linux/dlmstp.c | 10 +++++++++ bacnet-stack/ports/win32/dlmstp.c | 11 ++++++++++ bacnet-stack/ports/win32/timer.c | 7 ------ bacnet-stack/ports/win32/timer.h | 8 +++++++ 8 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 bacnet-stack/demo/mstpcap/readme.txt diff --git a/bacnet-stack/demo/mstpcap/main.c b/bacnet-stack/demo/mstpcap/main.c index 6b92f451..5c7e7d23 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -39,9 +39,6 @@ #include #include #include -#if defined(_WIN32) -#include -#endif /* OS specific include*/ #include "net.h" #include "timer.h" @@ -203,7 +200,9 @@ static void packet_statistics_save(void) "\tTusage\tTrpfm\tTder\tTpostpd"); fprintf(stdout, "\r\n"); for (i = 0; i < 256; i++) { - if (MSTP_Statistics[i].token_count) { + /* check for masters or slaves */ + if ((MSTP_Statistics[i].token_count) || + (MSTP_Statistics[i].der_reply)) { fprintf(stdout, "%u\t%u", i, (unsigned)MSTP_Statistics[i].max_master); fprintf(stdout, @@ -396,6 +395,7 @@ static BOOL WINAPI CtrlCHandler(DWORD dwCtrlType) { dwCtrlType = dwCtrlType; exit(0); + return TRUE; } #else static void sig_int( @@ -505,6 +505,4 @@ int main( packet_count = 0; } } - - return 0; } diff --git a/bacnet-stack/demo/mstpcap/readme.txt b/bacnet-stack/demo/mstpcap/readme.txt new file mode 100644 index 00000000..d00b217d --- /dev/null +++ b/bacnet-stack/demo/mstpcap/readme.txt @@ -0,0 +1,33 @@ +MSTP Capture Tool + +This tool captures MS/TP packets on an RS485 serial interface, +and saves the packets to a file in Wireshark PCAP format for +the MS/TP dissector to read. The filename has a date and time +code in it, and will contain up to 65535 packets. A new file +will be created at each 65535 packet interval. + +Here is a sample of the tool running (use CTRL-C to quit). +D:\code\bacnet-stack\bin>mstpcap COM3 38400 +Adjusted interface name to \\.\COM3 +mstpcap: Using \\.\COM3 for capture at 38400 bps. +mstpcap: saving capture to mstp_20090729123548.cap +1400 packets +MAC MaxMstr Tokens Retries Treply Tusage Trpfm Tder Tpostpd +0 0 525 0 32 0 0 0 0 +1 127 525 0 16 79 0 0 0 + +MS/TP capture tool also includes statistics which are listed for +any MAC addresses found passing a token, +or any MAC address replying to a DER message. +The statistics are emitted when CTRL-C is pressed, or when +65535 packets are captured and the new file is created. +The statistics are cleared when the new file is created. + +MaxMstr = highest destination MAC during PFM +Tokens = number of tokens transmitted +Retries = number of second tokens sent to this MAC +Treply = max milliseconds it took to reply with a token after receiving a token +Tusage = max Tusage_delay in milliseconds based on PFM and subsequent token +Trpfm = max milliseconds to respond to PFM with RPFM. +Tder = max milliseconds to respond to DER request with DNER +Tpostpd = max milliseconds to respond to DER request with Reply Postponed. diff --git a/bacnet-stack/lib/makefile.b32 b/bacnet-stack/lib/makefile.b32 index cb076579..b20a5820 100644 --- a/bacnet-stack/lib/makefile.b32 +++ b/bacnet-stack/lib/makefile.b32 @@ -126,6 +126,7 @@ OBJECT_SRC = $(BACNET_OBJECT)\device.c \ PORT_SRC = $(BACNET_PORT)\bip-init.c \ $(BACNET_PORT)\rs485.c \ $(BACNET_PORT)\dlmstp.c \ + $(BACNET_PORT)\timer.c \ $(BACNET_CORE)\crc.c \ $(BACNET_CORE)\mstp.c \ $(BACNET_CORE)\mstptext.c \ diff --git a/bacnet-stack/makefile.b32 b/bacnet-stack/makefile.b32 index b3bcd2d8..9c1ceae3 100644 --- a/bacnet-stack/makefile.b32 +++ b/bacnet-stack/makefile.b32 @@ -13,6 +13,7 @@ MAKE=$(BORLAND_DIR)\bin\make.exe all: library \ readprop writeprop readfile writefile server dcc reinit \ whois whohas timesync ucov epics readpropm \ + mstpcap \ whoisrouter iamrouter initrouter @echo "demo utilities are in the bin directory" diff --git a/bacnet-stack/ports/linux/dlmstp.c b/bacnet-stack/ports/linux/dlmstp.c index 0b0e87c6..c5afa253 100644 --- a/bacnet-stack/ports/linux/dlmstp.c +++ b/bacnet-stack/ports/linux/dlmstp.c @@ -55,6 +55,16 @@ static volatile struct mstp_port_struct_t MSTP_Port; /* buffers needed by mstp port struct */ static uint8_t TxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU]; +/* The minimum time without a DataAvailable or ReceiveError event */ +/* that a node must wait for a station to begin replying to a */ +/* confirmed request: 255 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 300 milliseconds.) */ +static uint8_t Treply_timeout = 260; +/* The minimum time without a DataAvailable or ReceiveError event that a */ +/* node must wait for a remote node to begin using a token or replying to */ +/* a Poll For Master frame: 20 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 100 milliseconds.) */ +static uint8_t Tusage_timeout = 50; /* Timer that indicates line silence - and functions */ static uint16_t SilenceTime; #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index e8a662f6..2d552953 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -54,6 +54,17 @@ volatile struct mstp_port_struct_t MSTP_Port; /* buffers needed by mstp port struct */ static uint8_t TxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU]; +/* The minimum time without a DataAvailable or ReceiveError event */ +/* that a node must wait for a station to begin replying to a */ +/* confirmed request: 255 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 300 milliseconds.) */ +static uint8_t Treply_timeout = 260; +/* The minimum time without a DataAvailable or ReceiveError event that a */ +/* node must wait for a remote node to begin using a token or replying to */ +/* a Poll For Master frame: 20 milliseconds. (Implementations may use */ +/* larger values for this timeout, not to exceed 100 milliseconds.) */ +static uint8_t Tusage_timeout = 50; + /* Timer that indicates line silence - and functions */ static uint16_t SilenceTime; #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} diff --git a/bacnet-stack/ports/win32/timer.c b/bacnet-stack/ports/win32/timer.c index edd29eb4..59e1f21b 100644 --- a/bacnet-stack/ports/win32/timer.c +++ b/bacnet-stack/ports/win32/timer.c @@ -30,15 +30,8 @@ #define STRICT 1 #include #include -#include -#include #include "timer.h" -#if defined(__BORLANDC__) -#define _timeb timeb -#define _ftime(param) ftime(param) -#endif - /* counter for the various timers */ static volatile uint32_t Millisecond_Counter[MAX_MILLISECOND_TIMERS]; diff --git a/bacnet-stack/ports/win32/timer.h b/bacnet-stack/ports/win32/timer.h index 89bbc4a6..45b31782 100644 --- a/bacnet-stack/ports/win32/timer.h +++ b/bacnet-stack/ports/win32/timer.h @@ -30,8 +30,16 @@ #define WIN32_LEAN_AND_MEAN #define STRICT 1 #include +#if defined(__BORLANDC__) +#include +#else #include +#endif #include +#if defined(__BORLANDC__) +#define _timeb timeb +#define _ftime(param) ftime(param) +#endif /* Timer Module */ #ifndef MAX_MILLISECOND_TIMERS