diff --git a/ports/linux/bip-init.c b/ports/linux/bip-init.c index 4e830d68..4c347464 100644 --- a/ports/linux/bip-init.c +++ b/ports/linux/bip-init.c @@ -67,7 +67,7 @@ static void debug_print_ipv4( const unsigned int count) { if (BIP_Debug) { - fprintf( + debug_fprintf( stderr, "BIP: %s %s:%hu (%u bytes)\n", str, inet_ntoa(*addr), ntohs(port), count); fflush(stderr); @@ -301,7 +301,7 @@ int bip_send_mpdu( /* assumes that the driver has already been initialized */ if (BIP_Socket < 0) { if (BIP_Debug) { - fprintf(stderr, "BIP: driver not initialized!\n"); + debug_fprintf(stderr, "BIP: driver not initialized!\n"); fflush(stderr); } return BIP_Socket; @@ -423,7 +423,7 @@ uint16_t bip_receive( } } else { if (BIP_Debug) { - fprintf(stderr, "BIP: NPDU dropped!\n"); + debug_fprintf(stderr, "BIP: NPDU dropped!\n"); fflush(stderr); } npdu_len = 0; @@ -613,20 +613,20 @@ static void printRoute(struct route_info *rtInfo) { if (BIP_Debug) { /* Print Destination address */ - fprintf( + debug_fprintf( stderr, "%s\t", rtInfo->dstAddr ? ntoa(rtInfo->dstAddr) : "0.0.0.0 "); /* Print Gateway address */ - fprintf( + debug_fprintf( stderr, "%s\t", rtInfo->gateWay ? ntoa(rtInfo->gateWay) : "*.*.*.*"); /* Print Interface Name */ - fprintf(stderr, "%s\t", rtInfo->ifName); + debug_fprintf(stderr, "%s\t", rtInfo->ifName); /* Print Source address */ - fprintf( + debug_fprintf( stderr, "%s\n", rtInfo->srcAddr ? ntoa(rtInfo->srcAddr) : "*.*.*.*"); } @@ -707,19 +707,19 @@ static char *ifname_default(void) /* Send the request */ if (send(sock, nlMsg, nlMsg->nlmsg_len, 0) < 0) { - fprintf(stderr, "BIP: Write To Socket Failed...\n"); + debug_fprintf(stderr, "BIP: Write To Socket Failed...\n"); return BIP_Interface_Name; } /* Read the response */ if ((len = readNlSock(sock, msgBuf, sizeof(msgBuf), msgSeq, getpid())) < 0) { - fprintf(stderr, "BIP: Read From Socket Failed...\n"); + debug_fprintf(stderr, "BIP: Read From Socket Failed...\n"); return BIP_Interface_Name; } /* Parse and print the response */ rtInfo = (struct route_info *)malloc(sizeof(struct route_info)); if (BIP_Debug) { - fprintf(stderr, "Destination\tGateway\tInterface\tSource\n"); + debug_fprintf(stderr, "Destination\tGateway\tInterface\tSource\n"); } for (; NLMSG_OK(nlMsg, len); nlMsg = NLMSG_NEXT(nlMsg, len)) { memset(rtInfo, 0, sizeof(struct route_info)); @@ -790,8 +790,8 @@ void bip_set_interface(const char *ifname) } BIP_Address.s_addr = local_address.s_addr; if (BIP_Debug) { - fprintf(stderr, "BIP: Interface: %s\n", ifname); - fprintf(stderr, "BIP: Address: %s\n", inet_ntoa(local_address)); + debug_fprintf(stderr, "BIP: Interface: %s\n", ifname); + debug_fprintf(stderr, "BIP: Address: %s\n", inet_ntoa(local_address)); fflush(stderr); } /* cache interface netmask */ @@ -833,10 +833,10 @@ void bip_set_interface(const char *ifname) } #endif if (BIP_Debug) { - fprintf( + debug_fprintf( stderr, "BIP: Broadcast Address: %s\n", inet_ntoa(BIP_Broadcast_Addr)); - fprintf( + debug_fprintf( stderr, "BIP: UDP Port: 0x%04X [%hu]\n", ntohs(BIP_Port), ntohs(BIP_Port)); fflush(stderr); @@ -926,7 +926,7 @@ bool bip_init(char *ifname) bip_set_interface(ifname_default()); } if (BIP_Address.s_addr == 0) { - fprintf( + debug_fprintf( stderr, "BIP: Failed to get an IP address from %s!\n", BIP_Interface_Name); fflush(stderr); diff --git a/ports/linux/bsc-event.c b/ports/linux/bsc-event.c index ecb37618..bc42c232 100644 --- a/ports/linux/bsc-event.c +++ b/ports/linux/bsc-event.c @@ -17,7 +17,7 @@ #undef DEBUG_PRINTF #if DEBUG_BSC_EVENT -#define DEBUG_PRINTF printf +#define DEBUG_PRINTF debug_printf #else #undef DEBUG_ENABLED #define DEBUG_PRINTF debug_printf_disabled diff --git a/ports/linux/datetime-init.c b/ports/linux/datetime-init.c index 9b5a244a..a1075a03 100644 --- a/ports/linux/datetime-init.c +++ b/ports/linux/datetime-init.c @@ -15,6 +15,7 @@ #include #include #include +#include "bacnet/basic/sys/debug.h" #include "bacport.h" #include "bacnet/datetime.h" @@ -61,7 +62,7 @@ void datetime_timesync(BACNET_DATE *bdate, BACNET_TIME *btime, bool utc) Time_Offset = time_difference(tv_inp, tv_sys); } #if PRINT_ENABLED - printf("Time offset = %d\n", Time_Offset); + debug_printf("Time offset = %d\n", Time_Offset); #endif } return; diff --git a/ports/linux/dlmstp.c b/ports/linux/dlmstp.c index c4076096..1cf85ad9 100644 --- a/ports/linux/dlmstp.c +++ b/ports/linux/dlmstp.c @@ -982,26 +982,26 @@ bool dlmstp_init(char *ifname) MSTP_Port.BaudRateSet = dlmstp_set_baud_rate; MSTP_Init(&MSTP_Port); #if PRINT_ENABLED - fprintf(stderr, "MS/TP MAC: %02X\n", MSTP_Port.This_Station); - fprintf(stderr, "MS/TP Max_Master: %02X\n", MSTP_Port.Nmax_master); - fprintf( + debug_fprintf(stderr, "MS/TP MAC: %02X\n", MSTP_Port.This_Station); + debug_fprintf(stderr, "MS/TP Max_Master: %02X\n", MSTP_Port.Nmax_master); + debug_fprintf( stderr, "MS/TP Max_Info_Frames: %u\n", (unsigned)MSTP_Port.Nmax_info_frames); - fprintf( + debug_fprintf( stderr, "MS/TP RxBuf[%u] TxBuf[%u]\n", (unsigned)MSTP_Port.InputBufferSize, (unsigned)MSTP_Port.OutputBufferSize); - fprintf( + debug_fprintf( stderr, "MS/TP SlaveModeEnabled" ": %s\n", (MSTP_Port.SlaveNodeEnabled ? "true" : "false")); - fprintf( + debug_fprintf( stderr, "MS/TP ZeroConfigEnabled" ": %s\n", (MSTP_Port.ZeroConfigEnabled ? "true" : "false")); - fprintf( + debug_fprintf( stderr, "MS/TP CheckAutoBaud" ": %s\n", diff --git a/ports/linux/rs485.c b/ports/linux/rs485.c index d16c9e87..146cc9c9 100644 --- a/ports/linux/rs485.c +++ b/ports/linux/rs485.c @@ -35,6 +35,7 @@ #include "bacnet/datalink/mstp.h" #include "rs485.h" #include "bacnet/basic/sys/fifo.h" +#include "bacnet/basic/sys/debug.h" #include #include @@ -156,7 +157,7 @@ bool RS485_Set_Baud_Rate(uint32_t baud) termios2_tcsetattr(RS485_Handle, TCSAFLUSH, &newtio); #if PRINT_ENABLED - fprintf(stdout, "RS485 Baud Rate %u\n", RS485_Baud); + debug_fprintf(stdout, "RS485 Baud Rate %u\n", RS485_Baud); fflush(stdout); #endif } @@ -296,7 +297,7 @@ void RS485_Cleanup(void) void RS485_Initialize(void) { #if PRINT_ENABLED - fprintf(stdout, "RS485 Interface: %s\n", RS485_Port_Name); + debug_printf("RS485 Interface: %s\n", RS485_Port_Name); #endif /* Open device for reading and writing. diff --git a/ports/linux/websocket-global.c b/ports/linux/websocket-global.c index 1ed0c91c..6b8734ef 100644 --- a/ports/linux/websocket-global.c +++ b/ports/linux/websocket-global.c @@ -51,13 +51,13 @@ static volatile int websocket_dispatch_mutex_cnt = 0; void bsc_websocket_global_lock_dbg(char *f, int line) { - printf( + debug_printf( "bsc_websocket_global_lock_dbg() >>> %s:%d lock_cnt %d tid = %ld\n", f, line, websocket_mutex_cnt, pthread_self()); websocket_mutex_cnt++; fflush(stdout); pthread_mutex_lock(&websocket_mutex); - printf( + debug_printf( "bsc_websocket_global_lock_dbg() <<< lock_cnt %d tid = %ld\n", websocket_mutex_cnt, pthread_self()); fflush(stdout); @@ -65,13 +65,13 @@ void bsc_websocket_global_lock_dbg(char *f, int line) void bsc_websocket_global_unlock_dbg(char *f, int line) { - printf( + debug_printf( "bsc_websocket_global_unlock_dbg() >>> %s:%d lock_cnt %d tid = %ld\n", f, line, websocket_mutex_cnt, pthread_self()); websocket_mutex_cnt--; fflush(stdout); pthread_mutex_unlock(&websocket_mutex); - printf( + debug_printf( "bsc_websocket_global_unlock_dbg() <<< lock_cnt %d tid = %ld\n", websocket_mutex_cnt, pthread_self()); fflush(stdout); @@ -79,13 +79,13 @@ void bsc_websocket_global_unlock_dbg(char *f, int line) void bws_dispatch_lock_dbg(char *f, int line) { - printf( + debug_printf( "bws_dispatch_lock_dbg() >>> %s:%d lock_cnt %d tid = %ld\n", f, line, websocket_dispatch_mutex_cnt, pthread_self()); websocket_dispatch_mutex_cnt++; fflush(stdout); pthread_mutex_lock(&websocket_dispatch_mutex); - printf( + debug_printf( "bws_dispatch_lock_dbg() <<< lock_cnt %d tid = %ld\n", websocket_dispatch_mutex_cnt, pthread_self()); fflush(stdout); @@ -93,13 +93,13 @@ void bws_dispatch_lock_dbg(char *f, int line) void bws_dispatch_unlock_dbg(char *f, int line) { - printf( + debug_printf( "bws_dispatch_unlock_dbg() >>> %s:%d lock_cnt %d tid = %ld\n", f, line, websocket_dispatch_mutex_cnt, pthread_self()); websocket_dispatch_mutex_cnt--; fflush(stdout); pthread_mutex_unlock(&websocket_dispatch_mutex); - printf( + debug_printf( "bws_dispatch_unlock_dbg() <<< lock_cnt %d tid = %ld\n", websocket_dispatch_mutex_cnt, pthread_self()); fflush(stdout); @@ -115,7 +115,7 @@ void bsc_websocket_init_log(void) if (!bsc_websocket_log_initialized) { bsc_websocket_log_initialized = true; #if DEBUG_LIBWEBSOCKETS_ENABLED == 1 - printf("LWS_MAX_SMP = %d", LWS_MAX_SMP); + debug_printf("LWS_MAX_SMP = %d", LWS_MAX_SMP); lws_set_log_level( LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_PARSER | LLL_HEADER | LLL_EXT | LLL_CLIENT | LLL_LATENCY | diff --git a/src/bacnet/basic/npdu/h_npdu.c b/src/bacnet/basic/npdu/h_npdu.c index 26284025..8611bffc 100644 --- a/src/bacnet/basic/npdu/h_npdu.c +++ b/src/bacnet/basic/npdu/h_npdu.c @@ -256,13 +256,14 @@ void npdu_handler(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t pdu_len) } } else { #if PRINT_ENABLED - printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net); + debug_printf( + "NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net); #endif } } } else { #if PRINT_ENABLED - printf( + debug_printf( "NPDU: BACnet Protocol Version=%u. Discarded!\n", (unsigned)pdu[0]); #endif diff --git a/src/bacnet/basic/service/h_cov.c b/src/bacnet/basic/service/h_cov.c index 78620902..8a67b520 100644 --- a/src/bacnet/basic/service/h_cov.c +++ b/src/bacnet/basic/service/h_cov.c @@ -459,7 +459,7 @@ static bool cov_send_request( return status; } #if PRINT_ENABLED - fprintf(stderr, "COVnotification: requested\n"); + debug_fprintf(stderr, "COVnotification: requested\n"); #endif if (!cov_subscription) { return status; @@ -467,7 +467,7 @@ static bool cov_send_request( dest = cov_address_get(cov_subscription->dest_index); if (!dest) { #if PRINT_ENABLED - fprintf(stderr, "COVnotification: dest not found!\n"); + debug_fprintf(stderr, "COVnotification: dest not found!\n"); #endif return status; } @@ -514,7 +514,7 @@ static bool cov_send_request( if (bytes_sent > 0) { status = true; #if PRINT_ENABLED - fprintf(stderr, "COVnotification: Sent!\n"); + debug_fprintf(stderr, "COVnotification: Sent!\n"); #endif } @@ -540,18 +540,13 @@ static void cov_lifetime_expiration_handler( if (COV_Subscriptions[index].lifetime == 0) { /* expire the subscription */ #if PRINT_ENABLED - fprintf( - stderr, "COVtimer: PID=%u ", - COV_Subscriptions[index].subscriberProcessIdentifier); - fprintf( - stderr, "%s %u ", + debug_fprintf( + stderr, "COVtimer: PID=%u %s %u time remaining=%u seconds\n", + COV_Subscriptions[index].subscriberProcessIdentifier, bactext_object_type_name( COV_Subscriptions[index].monitoredObjectIdentifier.type), - COV_Subscriptions[index].monitoredObjectIdentifier.instance); - fprintf( - stderr, "time remaining=%u seconds ", + COV_Subscriptions[index].monitoredObjectIdentifier.instance, COV_Subscriptions[index].lifetime); - fprintf(stderr, "\n"); #endif /* initialize with invalid COV address */ COV_Subscriptions[index].flag.valid = false; @@ -641,7 +636,7 @@ bool handler_cov_fsm(void) if (status) { COV_Subscriptions[index].flag.send_requested = true; #if PRINT_ENABLED - fprintf(stderr, "COVtask: Marking...\n"); + debug_fprintf(stderr, "COVtask: Marking...\n"); #endif } } @@ -707,7 +702,7 @@ bool handler_cov_fsm(void) object_instance = COV_Subscriptions[index] .monitoredObjectIdentifier.instance; #if PRINT_ENABLED - fprintf(stderr, "COVtask: Sending...\n"); + debug_fprintf(stderr, "COVtask: Sending...\n"); #endif /* configure the linked list for the two properties */ bacapp_property_value_list_init( diff --git a/src/bacnet/datalink/dlenv.c b/src/bacnet/datalink/dlenv.c index f9eca4ae..99199693 100644 --- a/src/bacnet/datalink/dlenv.c +++ b/src/bacnet/datalink/dlenv.c @@ -167,7 +167,7 @@ static int bbmd_register_as_foreign_device(void) } if (BBMD_Address_Valid) { if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "Registering with BBMD at %u.%u.%u.%u:%u for %u seconds\n", (unsigned)BBMD_Address.address[0], @@ -199,7 +199,7 @@ static int bbmd_register_as_foreign_device(void) bip_get_addr_by_name(pEnv, &BBMD_Table_Entry.dest_address); if (entry_number == 1) { if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "BBMD 1 address overridden %s=%s!\n", bbmd_env, pEnv); } @@ -218,7 +218,7 @@ static int bbmd_register_as_foreign_device(void) bdt_entry_port = strtol(pEnv, NULL, 0); if (entry_number == 1) { if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "BBMD 1 port overridden %s=%s!\n", bbmd_env, pEnv); } @@ -248,7 +248,7 @@ static int bbmd_register_as_foreign_device(void) bvlc_broadcast_distribution_table_entry_append( bdt_table, &BBMD_Table_Entry); if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "BBMD %4u: %u.%u.%u.%u:%u %u.%u.%u.%u\n", entry_number, (unsigned)BBMD_Table_Entry.dest_address.address[0], @@ -311,7 +311,7 @@ static int bbmd6_register_as_foreign_device(void) pEnv = getenv("BACNET_BBMD6_ADDRESS"); if (bvlc6_address_from_ascii(&bip6_addr, pEnv)) { if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "Registering with BBMD6 at %s:0x%04x for %u seconds\n", pEnv, (unsigned)bip6_port, (unsigned)BBMD_TTL_Seconds); } @@ -417,7 +417,7 @@ static void dlenv_network_port_bip_init(uint32_t instance) bip_get_addr(&addr); prefix = bip_get_subnet_prefix(); if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "BIP: Setting Network Port %lu address %u.%u.%u.%u:%u/%u\n", (unsigned long)instance, (unsigned)addr.address[0], (unsigned)addr.address[1], (unsigned)addr.address[2], @@ -492,7 +492,7 @@ void dlenv_network_port_mstp_init(uint32_t instance) mac_address = strtol(pEnv, NULL, 0); } if (Datalink_Debug) { - fprintf( + debug_fprintf( stderr, "Network Port[%lu] mode=MSTP bitrate=%ld mac[0]=%ld " "max_info_frames=%ld, max_master=%ld\n", @@ -880,7 +880,7 @@ void dlenv_maintenance_timer(uint16_t elapsed_seconds) if (Datalink_Debug) { #ifdef BACDL_MSTP dlmstp_fill_statistics(&statistics); - fprintf( + debug_fprintf( stderr, "MSTP: Frames Rx:%u/%u/%u Tx:%u PDU Rx:%u Tx:%u " "Lost:%u BadCRC:%u PFM:%u\n", @@ -1091,7 +1091,7 @@ void dlenv_init(void) /* === INIT - Initialize the Datalink Here === */ pEnv = getenv("BACNET_IFACE"); if (Datalink_Debug) { - fprintf(stderr, "BACNET_IFACE=%s\n", pEnv ? pEnv : "none"); + debug_fprintf(stderr, "BACNET_IFACE=%s\n", pEnv ? pEnv : "none"); } if (!datalink_init(pEnv)) { exit(1); diff --git a/test/ports/linux/bip_subnet/CMakeLists.txt b/test/ports/linux/bip_subnet/CMakeLists.txt index c5bc7732..50ab25c5 100644 --- a/test/ports/linux/bip_subnet/CMakeLists.txt +++ b/test/ports/linux/bip_subnet/CMakeLists.txt @@ -40,6 +40,7 @@ include_directories( add_executable(${PROJECT_NAME} ${PORTS_DIR}/linux/bip-init.c + ${SRC_DIR}/bacnet/basic/sys/debug.c ./src/bvlc_stubs.c ./src/main.c ${ZTST_DIR}/ztest_mock.c