diff --git a/bacnet-stack/demo/handler/dlenv.c b/bacnet-stack/demo/handler/dlenv.c index 586883ad..b6779963 100644 --- a/bacnet-stack/demo/handler/dlenv.c +++ b/bacnet-stack/demo/handler/dlenv.c @@ -38,10 +38,10 @@ /** @file dlenv.c Initialize the DataLink configuration. */ +#if defined(BACDL_BIP) && BBMD_ENABLED /* timer used to renew Foreign Device Registration */ static uint16_t BBMD_Timer_Seconds; - -#if defined(BACDL_BIP) && BBMD_ENABLED +/* BBMD variables */ static long bbmd_timetolive_seconds = 60000; static long bbmd_port = 0xBAC0; static long bbmd_address = 0; @@ -50,8 +50,8 @@ static int bbmd_result = 0; /* Simple setters for BBMD registration variables. */ /** Sets the IPv4 address for BBMD registration. - * If not set here or provided by Environment variables, - * no BBMD registration will occur. + * If not set here or provided by Environment variables, + * no BBMD registration will occur. * @param address - IPv4 address (long) of BBMD to register with, * in network byte order. */ @@ -60,7 +60,7 @@ void set_bbmd_address( long address ) bbmd_address = address; } -/** Set the port for BBMD registration. +/** Set the port for BBMD registration. * Default if not set is 0xBAC0. * @param port - The port number (provided in network byte order). */ @@ -77,10 +77,9 @@ void set_bbmd_ttl( int ttl_secs ) { bbmd_timetolive_seconds = ttl_secs; } -#endif /** Get the result of the last attempt to register with the indicated BBMD. - * @return Positive number (of bytes sent) if registration was successful, + * @return Positive number (of bytes sent) if registration was successful, * 0 if no registration request was made, or * -1 if registration attempt failed. */ @@ -88,18 +87,19 @@ int get_bbmd_result( void ) { return bbmd_result; } +#endif /** Register as a Foreign Device with the designated BBMD. * @ingroup DataLink * The BBMD's address, port, and lease time must be provided by * internal variables or Environment variables. - * If no address for the BBMD is provided, no BBMD registration will occur. + * If no address for the BBMD is provided, no BBMD registration will occur. * * The Environment Variables depend on defines BACDL_BIP and BBMD_ENABLED: * - BACNET_BBMD_PORT - 0..65534, defaults to 47808 * - BACNET_BBMD_TIMETOLIVE - 0..65535 seconds, defaults to 60000 * - BACNET_BBMD_ADDRESS - dotted IPv4 address - * @return Positive number (of bytes sent) on success, + * @return Positive number (of bytes sent) on success, * 0 if no registration request is sent, or * -1 if registration fails. */ @@ -134,7 +134,7 @@ int dlenv_register_as_foreign_device( fprintf(stderr, "Registering with BBMD at %s:%ld for %ld seconds\n", inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds); - retval = bvlc_register_with_bbmd(bbmd_address, + retval = bvlc_register_with_bbmd(bbmd_address, htons((uint16_t) bbmd_port), (uint16_t) bbmd_timetolive_seconds); if ( retval < 0 ) @@ -157,13 +157,13 @@ int dlenv_register_as_foreign_device( void dlenv_maintenance_timer( uint16_t elapsed_seconds) { +#if defined(BACDL_BIP) && BBMD_ENABLED if (BBMD_Timer_Seconds) { if (BBMD_Timer_Seconds <= elapsed_seconds) { BBMD_Timer_Seconds = 0; } else { BBMD_Timer_Seconds -= elapsed_seconds; } -#if defined(BACDL_BIP) && BBMD_ENABLED if (BBMD_Timer_Seconds == 0) { int retval; retval = dlenv_register_as_foreign_device(); @@ -172,8 +172,8 @@ void dlenv_maintenance_timer( if ( retval < 0 ) BBMD_Timer_Seconds = bbmd_timetolive_seconds; } -#endif } +#endif } /** Initialize the DataLink configuration from Environment variables,