From ce7e65115625e472991e432b9faba7ec951ddef4 Mon Sep 17 00:00:00 2001 From: tbrennan3 Date: Mon, 12 Sep 2011 21:21:39 +0000 Subject: [PATCH] Provided a feedback path, so we can find out if our foreign device registration has been NAK'd. --- bacnet-stack/demo/handler/dlenv.c | 7 +++++++ bacnet-stack/include/bvlc.h | 5 +++++ bacnet-stack/src/bvlc.c | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bacnet-stack/demo/handler/dlenv.c b/bacnet-stack/demo/handler/dlenv.c index e4af4ca4..b81107ab 100644 --- a/bacnet-stack/demo/handler/dlenv.c +++ b/bacnet-stack/demo/handler/dlenv.c @@ -79,12 +79,19 @@ void dlenv_bbmd_ttl_set( int ttl_secs ) } /** Get the result of the last attempt to register with the indicated BBMD. + * If we sent a foreign registration request, then see if we've received + * a NAK in our BVLC handler. + * * @return Positive number (of bytes sent) if registration was successful, * 0 if no registration request was made, or * -1 if registration attempt failed. */ int dlenv_bbmd_result( void ) { + if ( (bbmd_result > 0) && + (bvlc_get_last_result() == BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK) ) + return -1; + /* Else, show our send: */ return bbmd_result; } #endif diff --git a/bacnet-stack/include/bvlc.h b/bacnet-stack/include/bvlc.h index 0953ac55..e06c198d 100644 --- a/bacnet-stack/include/bvlc.h +++ b/bacnet-stack/include/bvlc.h @@ -101,6 +101,11 @@ struct sockaddr_in; /* Defined elsewhere, needed here. */ uint8_t * npdu, uint16_t received_bytes); + /** Returns the last BVLL Result we received, either as the result of a BBMD + * request we sent, or (if not a BBMD or Client), from trying to register + * as a foreign device. */ + BACNET_BVLC_RESULT bvlc_get_last_result(); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bacnet-stack/src/bvlc.c b/bacnet-stack/src/bvlc.c index 877e5972..8665519c 100644 --- a/bacnet-stack/src/bvlc.c +++ b/bacnet-stack/src/bvlc.c @@ -883,7 +883,7 @@ uint16_t bvlc_receive( Foreign-Device message. At the expiration of the timer, the foreign device shall re-register with the BBMD by sending a BVLL Register-Foreign-Device message */ - /* FIXME: clients may need this result */ + /* Clients can now get this result */ (void) decode_unsigned16(&npdu[4], &result_code); BVLC_Result_Code = (BACNET_BVLC_RESULT) result_code; debug_printf("BVLC: Result Code=%d\n", BVLC_Result_Code); @@ -1286,6 +1286,19 @@ void bvlc_for_non_bbmd( } } +/** Returns the last BVLL Result we received, either as the result of a BBMD + * request we sent, or (if not a BBMD or Client), from trying to register + * as a foreign device. + * + * @return BVLC_RESULT_SUCCESSFUL_COMPLETION on success, + * BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK if registration failed, + * or one of the other codes (if we are a BBMD). + */ +BACNET_BVLC_RESULT bvlc_get_last_result() +{ + return BVLC_Result_Code; +} + #ifdef TEST #include #include