From e4ccba8310fd7ff34ef510b3604cd6a01db9a3af Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 21 Jan 2008 03:03:43 +0000 Subject: [PATCH] Added debugging. --- bacnet-stack/demo/dcc/main.c | 1 - bacnet-stack/src/bip.c | 24 ++++++++++++++++++++++-- bacnet-stack/src/npdu.c | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bacnet-stack/demo/dcc/main.c b/bacnet-stack/demo/dcc/main.c index a774f049..16a93fe7 100644 --- a/bacnet-stack/demo/dcc/main.c +++ b/bacnet-stack/demo/dcc/main.c @@ -157,7 +157,6 @@ int main( bool found = false; if (argc < 3) { - /* note: priority 16 and 0 should produce the same end results... */ printf("Usage: %s device-instance state timeout [password]\r\n" "Send BACnet DeviceCommunicationControl service to device.\r\n" "\r\n" "The device-instance can be 0 to %d.\r\n" diff --git a/bacnet-stack/src/bip.c b/bacnet-stack/src/bip.c index 80210a45..347c6a5e 100644 --- a/bacnet-stack/src/bip.c +++ b/bacnet-stack/src/bip.c @@ -231,6 +231,9 @@ uint16_t bip_receive( if ((sin.sin_addr.s_addr == htonl(BIP_Address.s_addr)) && (sin.sin_port == htonl(BIP_Port))) { pdu_len = 0; +#if PRINT_ENABLED + fprintf(stderr,"BIP: src is me. Discarded!\n"); +#endif } else { /* copy the source address FIXME: IPv6? */ @@ -244,16 +247,33 @@ uint16_t bip_receive( /* subtract off the BVLC header */ pdu_len -= 4; if (pdu_len < max_pdu) { +#if 0 + fprintf(stderr,"BIP: NPDU[%hu]:",pdu_len); +#endif /* shift the buffer to return a valid PDU */ for (i = 0; i < pdu_len; i++) { - pdu[i] = pdu[i + 4]; + pdu[i] = pdu[4 + i]; +#if 0 + fprintf(stderr,"%02X ",pdu[i]); +#endif } +#if 0 + fprintf(stderr,"\n"); +#endif } /* ignore packets that are too large */ /* clients should check my max-apdu first */ - else + else { pdu_len = 0; +#if PRINT_ENABLED + fprintf(stderr,"BIP: PDU too large. Discarded!.\n"); +#endif + } } + } else { +#if PRINT_ENABLED + fprintf(stderr,"BIP: BVLC discarded!\n"); +#endif } return pdu_len; diff --git a/bacnet-stack/src/npdu.c b/bacnet-stack/src/npdu.c index 49c21762..4fe26cbb 100644 --- a/bacnet-stack/src/npdu.c +++ b/bacnet-stack/src/npdu.c @@ -41,6 +41,10 @@ #include "npdu.h" #include "apdu.h" +#if PRINT_ENABLED +#include +#endif + void npdu_copy_data( BACNET_NPDU_DATA * dest, BACNET_NPDU_DATA * src) @@ -377,6 +381,9 @@ void npdu_handler( apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data); if (npdu_data.network_layer_message) { /*FIXME: network layer message received! Handle it! */ +#if PRINT_ENABLED + fprintf(stderr,"NPDU: Network Layer Message discarded!\n"); +#endif } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { /* only handle the version that we know how to handle */ if (npdu_data.protocol_version == BACNET_PROTOCOL_VERSION)