AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/gateway/main.c
static void Initialize_Device_Addresses(
    )
{
    int i = 0;  /* First entry is Gateway Device */
    uint32_t virtual_mac = 0;
    DEVICE_OBJECT_DATA *pDev = NULL;
    /* Setup info for the main gateway device first */
#if defined(BACDL_BIP)
    uint16_t myPort;
    struct in_addr *netPtr;     /* Lets us cast to this type */
    uint8_t *gatewayMac = NULL;
    uint32_t myAddr = bip_get_addr();
    pDev = Get_Routed_Device_Object(i);
    gatewayMac = pDev->bacDevAddr.mac;  /* Keep pointer to the main MAC */
    memcpy(pDev->bacDevAddr.mac, &myAddr, 4);
    myPort = bip_get_port();
    memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
    pDev->bacDevAddr.mac_len = 6;
#elif defined(BACDL_MSTP)
    /* Todo: */
    pDev->bacDevAddr.mac_len = 2;
#else
#error "No support for this Data Link Layer type "
#endif
    /* broadcast an I-Am on startup */
    Send_I_Am(&Handler_Transmit_Buffer[0]);

    for (i = 1; i < MAX_NUM_DEVICES; i++) {
        pDev = Get_Routed_Device_Object(i);
        if (pDev == NULL)
            continue;
#if defined(BACDL_BIP)
        virtual_mac = i;
        netPtr = (struct in_addr *) pDev->bacDevAddr.mac;
#if (MAX_NUM_DEVICES > 0xFFFFFF)
        pDev->bacDevAddr.mac[0] = ((virtual_mac & 0xff000000) >> 24);
#else
        pDev->bacDevAddr.mac[0] = gatewayMac[3];
#endif
#if (MAX_NUM_DEVICES > 0xFFFF)
        pDev->bacDevAddr.mac[1] = ((virtual_mac & 0xff0000) >> 16);
#else
        pDev->bacDevAddr.mac[1] = gatewayMac[2];
#endif
#if (MAX_NUM_DEVICES > 0xFF)
        pDev->bacDevAddr.mac[2] = ((virtual_mac & 0xff00) >> 8);
#else
        pDev->bacDevAddr.mac[2] = gatewayMac[1];
#endif
        pDev->bacDevAddr.mac[3] = (virtual_mac & 0xff);
        memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
        pDev->bacDevAddr.mac_len = 6;
        pDev->bacDevAddr.net = VIRTUAL_DNET;
        memcpy(&pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6);
        pDev->bacDevAddr.len = 6;
        printf(" - Routed device [%d] ID %u at %s \n", i,
            pDev->bacObj.Object_Instance_Number, inet_ntoa(*netPtr));
#elif defined(BACDL_MSTP)
        /* Todo: set MS/TP net and port #s */
        pDev->bacDevAddr.mac_len = 2;
#endif
        /* broadcast an I-Am for each routed Device now */
        Send_I_Am(&Handler_Transmit_Buffer[0]);

    }
}
/** Initialize the BACnet Device Addresses for each Device object.
 * The gateway has already gotten the normal address (eg, PC's IP for BIP) and
 * the remote devices get
 * - For BIP, the IP address reversed, and 4th byte equal to index.
 * (Eg, 11.22.33.44 for the gateway becomes 44.33.22.01 for the first remote
 * device.) This is sure to be unique! The port number stays the same.
 * - For MS/TP, [Steve inserts a good idea here]
 */
Initialize the BACnet Device Addresses for each Device object.
The gateway has already gotten the normal address  and
the remote devices get
- For BIP, the IP address reversed, and 4th byte equal to index.
This is sure to be unique. The port number stays the same.
- For MS/TP, [Steve inserts a good idea here]
Initialize the BACnet Device Addresses for each Device object . The gateway has already gotten the normal address and the remote devices get - For BIP the IP address reversed and 4th byte equal to index . This is sure to be unique . The port number stays the same . - For MS / TP [ Steve inserts a good idea here ]
static void Initialize_Device_Addresses(
    )
{
    int i = 0;  
    uint32_t virtual_mac = 0;
    DEVICE_OBJECT_DATA *pDev = NULL;
#if defined(BACDL_BIP)
    uint16_t myPort;
    struct in_addr *netPtr;     
    uint8_t *gatewayMac = NULL;
    uint32_t myAddr = bip_get_addr();
    pDev = Get_Routed_Device_Object(i);
    gatewayMac = pDev->bacDevAddr.mac;  
    memcpy(pDev->bacDevAddr.mac, &myAddr, 4);
    myPort = bip_get_port();
    memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
    pDev->bacDevAddr.mac_len = 6;
#elif defined(BACDL_MSTP)
    pDev->bacDevAddr.mac_len = 2;
#else
#error "No support for this Data Link Layer type "
#endif
    Send_I_Am(&Handler_Transmit_Buffer[0]);
    for (i = 1; i < MAX_NUM_DEVICES; i++) {
        pDev = Get_Routed_Device_Object(i);
        if (pDev == NULL)
            continue;
#if defined(BACDL_BIP)
        virtual_mac = i;
        netPtr = (struct in_addr *) pDev->bacDevAddr.mac;
#if (MAX_NUM_DEVICES > 0xFFFFFF)
        pDev->bacDevAddr.mac[0] = ((virtual_mac & 0xff000000) >> 24);
#else
        pDev->bacDevAddr.mac[0] = gatewayMac[3];
#endif
#if (MAX_NUM_DEVICES > 0xFFFF)
        pDev->bacDevAddr.mac[1] = ((virtual_mac & 0xff0000) >> 16);
#else
        pDev->bacDevAddr.mac[1] = gatewayMac[2];
#endif
#if (MAX_NUM_DEVICES > 0xFF)
        pDev->bacDevAddr.mac[2] = ((virtual_mac & 0xff00) >> 8);
#else
        pDev->bacDevAddr.mac[2] = gatewayMac[1];
#endif
        pDev->bacDevAddr.mac[3] = (virtual_mac & 0xff);
        memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
        pDev->bacDevAddr.mac_len = 6;
        pDev->bacDevAddr.net = VIRTUAL_DNET;
        memcpy(&pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6);
        pDev->bacDevAddr.len = 6;
        printf(" - Routed device [%d] ID %u at %s \n", i,
            pDev->bacObj.Object_Instance_Number, inet_ntoa(*netPtr));
#elif defined(BACDL_MSTP)
        pDev->bacDevAddr.mac_len = 2;
#endif
        Send_I_Am(&Handler_Transmit_Buffer[0]);
    }
}
static void Initialize_Device_Addresses ( ) { int i = 0 ; uint32_t virtual_mac = 0 ; DEVICE_OBJECT_DATA * pDev = NULL ; #if defined ( BACDL_BIP ) uint16_t myPort ; struct in_addr * netPtr ; uint8_t * gatewayMac = NULL ; uint32_t myAddr = bip_get_addr ( ) ; pDev = Get_Routed_Device_Object ( i ) ; gatewayMac = pDev -> bacDevAddr . mac ; memcpy ( pDev -> bacDevAddr . mac , & myAddr , 4 ) ; myPort = bip_get_port ( ) ; memcpy ( & pDev -> bacDevAddr . mac [ 4 ] , & myPort , 2 ) ; pDev -> bacDevAddr . mac_len = 6 ; #elif defined ( BACDL_MSTP ) pDev -> bacDevAddr . mac_len = 2 ; #else #error  "No support for this Data Link Layer type " #endif Send_I_Am ( & Handler_Transmit_Buffer [ 0 ] ) ; for ( i = 1 ; i < MAX_NUM_DEVICES ; i ++ ) { pDev = Get_Routed_Device_Object ( i ) ; if ( pDev == NULL ) continue ; #if defined ( BACDL_BIP ) virtual_mac = i ; netPtr = ( struct in_addr * ) pDev -> bacDevAddr . mac ; #if ( MAX_NUM_DEVICES > 0xFFFFFF ) pDev -> bacDevAddr . mac [ 0 ] = ( ( virtual_mac & 0xff000000 ) >> 24 ) ; #else pDev -> bacDevAddr . mac [ 0 ] = gatewayMac [ 3 ] ; #endif #if ( MAX_NUM_DEVICES > 0xFFFF ) pDev -> bacDevAddr . mac [ 1 ] = ( ( virtual_mac & 0xff0000 ) >> 16 ) ; #else pDev -> bacDevAddr . mac [ 1 ] = gatewayMac [ 2 ] ; #endif #if ( MAX_NUM_DEVICES > 0xFF ) pDev -> bacDevAddr . mac [ 2 ] = ( ( virtual_mac & 0xff00 ) >> 8 ) ; #else pDev -> bacDevAddr . mac [ 2 ] = gatewayMac [ 1 ] ; #endif pDev -> bacDevAddr . mac [ 3 ] = ( virtual_mac & 0xff ) ; memcpy ( & pDev -> bacDevAddr . mac [ 4 ] , & myPort , 2 ) ; pDev -> bacDevAddr . mac_len = 6 ; pDev -> bacDevAddr . net = VIRTUAL_DNET ; memcpy ( & pDev -> bacDevAddr . adr [ 0 ] , & pDev -> bacDevAddr . mac [ 0 ] , 6 ) ; pDev -> bacDevAddr . len = 6 ; printf ( " \n " , i , pDev -> bacObj . Object_Instance_Number , inet_ntoa ( * netPtr ) ) ; #elif defined ( BACDL_MSTP ) pDev -> bacDevAddr . mac_len = 2 ; #endif Send_I_Am ( & Handler_Transmit_Buffer [ 0 ] ) ; } }
Initialize the BACnet Device Addresses for each Device object.
Initialize the BACnet Device Addresses for each Device object .
/* First entry is Gateway Device */ /* Setup info for the main gateway device first */ /* Lets us cast to this type */ /* Keep pointer to the main MAC */ /* Todo: */ /* broadcast an I-Am on startup */ /* Todo: set MS/TP net and port #s */ /* broadcast an I-Am for each routed Device now */