AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/object/gw_device.c
bool Routed_Device_GetNext(
    BACNET_ADDRESS * dest,
    int *DNET_list,
    int *cursor)
{
    int dnet = DNET_list[0];    /* Get the DNET of our virtual network */
    int idx = *cursor;
    bool bSuccess = false;

    /* First, see if the index is out of range.
     * Eg, last call to GetNext may have been the last successful one.
     */
    if ((idx < 0) || (idx >= MAX_NUM_DEVICES))
        idx = -1;

    /* Next, see if it's a BACnet broadcast.
     * For broadcasts, all Devices get a chance at it.
     */
    else if (dest->net == BACNET_BROADCAST_NETWORK) {
        /* Just take the entry indexed by the cursor */
        bSuccess = Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
    }
    /* Or see if it's for the main Gateway Device, because
     * there's no routing info.
     */
    else if (dest->net == 0) {
        /* Handle like a normal, non-routed access of the Gateway Device.
         * But first, make sure our internal access is pointing at
         * that Device in our table by telling it "no routing info" : */
        bSuccess = Routed_Device_Address_Lookup(0, dest->len, dest->adr);
        /* Next step: no more matches: */
        idx = -1;
    }
    /* Or if is our virtual DNET, check
     * against each of our virtually routed Devices.
     * If we get a match, have it handle the APDU.
     * For broadcasts, all Devices get a chance at it.
     */
    else if (dest->net == dnet) {
        if (idx == 0)   /* Step over this case (starting point) */
            idx = 1;
        while (idx < MAX_NUM_DEVICES) {
            bSuccess =
                Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
            if (bSuccess)
                break;  /* We don't need to keep looking */
        }
    }

    if (!bSuccess)
        *cursor = -1;
    else if (idx == MAX_NUM_DEVICES)    /* No more to GetNext */
        *cursor = -1;
    else
        *cursor = idx;
    return bSuccess;
}
/** Find the next Gateway or Routed Device at the given MAC address,
 * starting the search at the "cursor".
 * Has the desirable side-effect of setting internal iCurrent_Device_Idx
 * if a match is found, for use in the subsequent routing handling
 * functions.
 *
 * @param dest [in] The BACNET_ADDRESS of the message's destination.
 * 		   If the Length of the mac_adress[] field is 0, then this is a MAC
 * 		   broadcast.  Otherwise, size is determined
 *         by the DLL type (eg, 6 for BIP and 2 for MSTP).
 * @param DNET_list [in] List of our reachable downstream BACnet Network numbers.
 * 					 Normally just one valid entry; terminated with a -1 value.
 * @param cursor [in,out] The concept of the cursor is that it is a starting
 * 		   "hint" for the search; on return, it is updated to provide the
 * 		   cursor value to use with a subsequent GetNext call, or it
 *         equals -1 if there are no further matches.
 *         Set it to 0 on entry to access the main, gateway Device entry, or
 *         to start looping through the routed devices.
 *         Otherwise, its returned value is implementation-dependent and the
 *         calling function should not alter or interpret it.
 *
 * @return True if the MAC addresses match (or if BACNET_BROADCAST_NETWORK and
 * 		   the dest->len is 0, meaning MAC bcast, so it's an automatic match).
 *         Else False if no match or invalid idx is given; the cursor will
 *         be returned as -1 in these cases.
 */
Find the next Gateway or Routed Device at the given MAC address,
starting the search at the "cursor".
Has the desirable side-effect of setting internal iCurrent_Device_Idx
if a match is found, for use in the subsequent routing handling
functions.

@param dest [in] The BACNET_ADDRESS of the message's destination.
If the Length of the mac_adress[] field is 0, then this is a MAC
broadcast.  Otherwise, size is determined
by the DLL type .
@param DNET_list [in] List of our reachable downstream BACnet Network numbers.
Normally just one valid entry; terminated with a -1 value.
@param cursor [in,out] The concept of the cursor is that it is a starting
"hint" for the search; on return, it is updated to provide the
cursor value to use with a subsequent GetNext call, or it
equals -1 if there are no further matches.
Set it to 0 on entry to access the main, gateway Device entry, or
to start looping through the routed devices.
Otherwise, its returned value is implementation-dependent and the
calling function should not alter or interpret it.

@return True if the MAC addresses match (or if BACNET_BROADCAST_NETWORK and
the dest->len is 0, meaning MAC bcast, so it's an automatic match).
Else False if no match or invalid idx is given; the cursor will
be returned as -1 in these cases.
Find the next Gateway or Routed Device at the given MAC address starting the search at the " cursor " . Has the desirable side - effect of setting internal iCurrent_Device_Idx if a match is found for use in the subsequent routing handling functions . @param dest [ in ] The BACNET_ADDRESS of the message ' s destination . If the Length of the mac_adress [] field is 0 then this is a MAC broadcast . Otherwise size is determined by the DLL type . @param DNET_list [ in ] List of our reachable downstream BACnet Network numbers . Normally just one valid entry ; terminated with a - 1 value . @param cursor [ in out ] The concept of the cursor is that it is a starting " hint " for the search ; on return it is updated to provide the cursor value to use with a subsequent GetNext call or it equals - 1 if there are no further matches . Set it to 0 on entry to access the main gateway Device entry or to start looping through the routed devices . Otherwise its returned value is implementation - dependent and the calling function should not alter or interpret it . @return True if the MAC addresses match ( or if BACNET_BROADCAST_NETWORK and the dest - > len is 0 meaning MAC bcast so it ' s an automatic match ) . Else False if no match or invalid idx is given ; the cursor will be returned as - 1 in these cases .
bool Routed_Device_GetNext(
    BACNET_ADDRESS * dest,
    int *DNET_list,
    int *cursor)
{
    int dnet = DNET_list[0];    
    int idx = *cursor;
    bool bSuccess = false;
    if ((idx < 0) || (idx >= MAX_NUM_DEVICES))
        idx = -1;
    else if (dest->net == BACNET_BROADCAST_NETWORK) {
        bSuccess = Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
    }
    else if (dest->net == 0) {
        bSuccess = Routed_Device_Address_Lookup(0, dest->len, dest->adr);
        idx = -1;
    }
    else if (dest->net == dnet) {
        if (idx == 0)   
            idx = 1;
        while (idx < MAX_NUM_DEVICES) {
            bSuccess =
                Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
            if (bSuccess)
                break;  
        }
    }
    if (!bSuccess)
        *cursor = -1;
    else if (idx == MAX_NUM_DEVICES)    
        *cursor = -1;
    else
        *cursor = idx;
    return bSuccess;
}
bool Routed_Device_GetNext ( BACNET_ADDRESS * dest , int * DNET_list , int * cursor ) { int dnet = DNET_list [ 0 ] ; int idx = * cursor ; bool bSuccess = false ; if ( ( idx < 0 ) || ( idx >= MAX_NUM_DEVICES ) ) idx = -1 ; else if ( dest -> net == BACNET_BROADCAST_NETWORK ) { bSuccess = Routed_Device_Address_Lookup ( idx ++ , dest -> len , dest -> adr ) ; } else if ( dest -> net == 0 ) { bSuccess = Routed_Device_Address_Lookup ( 0 , dest -> len , dest -> adr ) ; idx = -1 ; } else if ( dest -> net == dnet ) { if ( idx == 0 ) idx = 1 ; while ( idx < MAX_NUM_DEVICES ) { bSuccess = Routed_Device_Address_Lookup ( idx ++ , dest -> len , dest -> adr ) ; if ( bSuccess ) break ; } } if ( ! bSuccess ) * cursor = -1 ; else if ( idx == MAX_NUM_DEVICES ) * cursor = -1 ; else * cursor = idx ; return bSuccess ; }
Find the next Gateway or Routed Device at the given MAC address,
 starting the search at the "cursor".
Find the next Gateway or Routed Device at the given MAC address starting the search at the " cursor " .
/* Get the DNET of our virtual network */ /* First, see if the index is out of range.
     * Eg, last call to GetNext may have been the last successful one.
     */ /* Next, see if it's a BACnet broadcast.
     * For broadcasts, all Devices get a chance at it.
     */ /* Just take the entry indexed by the cursor */ /* Or see if it's for the main Gateway Device, because
     * there's no routing info.
     */ /* Handle like a normal, non-routed access of the Gateway Device.
         * But first, make sure our internal access is pointing at
         * that Device in our table by telling it "no routing info" : */ /* Next step: no more matches: */ /* Or if is our virtual DNET, check
     * against each of our virtually routed Devices.
     * If we get a match, have it handle the APDU.
     * For broadcasts, all Devices get a chance at it.
     */ /* Step over this case (starting point) */ /* We don't need to keep looking */ /* No more to GetNext */