示例#1
0
/*---------------------------------------------------------------------------*/
void
cgroups_radio_arch_init(void)
{
    char* dom0mac_str = NULL;
    char* dom0ip_str = NULL;
    char* myip_str = NULL;
    char* port_str = NULL;
    char* mac_str = NULL;

    uint32_t ip[4];

    PRINTF("Cgroups radio setup\n\n\n\n");
    //get domain 0 mac address		
    do
    {
            XENbus_read(XBT_NIL, "dom0mac", &dom0mac_str);//change it to linux version --MYSQL
    } while(dom0mac_str == NULL);

    sscanf(dom0mac_str,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
                                    &dom0mac[0],
                                    &dom0mac[1],
                                    &dom0mac[2],
                                    &dom0mac[3],
                                    &dom0mac[4],
                                    &dom0mac[5]);
    
    PRINTF("Domain 0 mac: %s\n", dom0mac_str);

    // get domain 0 IP
    do
    {
            xenbus_read(XBT_NIL, "dom0ip", &dom0ip_str);//mysql
    } while(dom0ip_str == NULL);
//dom0ip_str = "11.1.1.1";
    PRINTF("Domain 0 ip : %s\n", dom0ip_str);

    // get this ContikiOS's IP
    do
    {
            xenbus_read(XBT_NIL, "myip", &myip_str);//mysql
    } while(myip_str == NULL);
    PRINTF("This domain ip: %s\n", myip_str);

    // convert domain IP string to int
    sscanf(dom0ip_str,"%u.%u.%u.%u",
                    &ip[0],&ip[1],&ip[2],&ip[3]);
    dom0ip = createIP(ip[0], ip[1], ip[2], ip[3]);

    // convert this ContikiOS's IP string to int
    sscanf(myip_str,"%u.%u.%u.%u",
                                    &ip[0],&ip[1],&ip[2],&ip[3]);

    myip = createIP(ip[0], ip[1], ip[2], ip[3]);

    // get port to send/receive data to/from
    do
    {
            xenbus_read(XBT_NIL, "port", &port_str);
    }while(port_str==NULL);
    PRINTF("This domains port : %s\n", port_str);

    sscanf(port_str,"%hu",&PORT);

    // get this nodes mac address
    do
    {
            xenbus_read(XBT_NIL, "device/vif/0/mac", &mac_str);
    }while(mac_str==NULL);

    PRINTF("My mac is %s\n", mac_str);
   	sscanf(mac_str,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
            &mymac[0],
            &mymac[1],
            &mymac[2],
            &mymac[3],
            &mymac[4],
            &mymac[5]);
	
    // generate ethernet checksum table
    chksum_crc32gentab();

  cgroups_radio_set_chan_pan_addr(11, 0xffff, 0x0000, NULL);
  process_start(&cgroups_radio_process, NULL);
}
示例#2
0
// Create a color gradient ranging from ZMin to Zmax using the color
// inflections defined in grid
int nwt_LoadColors( NWT_RGB * pMap, int mapSize, NWT_GRID * pGrd )
{
    int i;
    NWT_RGB sColor;
    int nWarkerMark = 0;

    createIP( 0, 255, 255, 255, pMap, &nWarkerMark );
    // If Zmin is less than the 1st inflection use the 1st inflections color to
    // the start of the ramp
    if( pGrd->fZMin <= pGrd->stInflection[0].zVal )
    {
        createIP( 1, pGrd->stInflection[0].r,
                     pGrd->stInflection[0].g,
                     pGrd->stInflection[0].b, pMap, &nWarkerMark );
    }
    // find what inflections zmin is between
    for( i = 0; i < pGrd->iNumColorInflections; i++ )
    {
        if( pGrd->fZMin < pGrd->stInflection[i].zVal )
        {
            // then we must be between i and i-1
            linearColor( &sColor, &pGrd->stInflection[i - 1],
                                  &pGrd->stInflection[i],
                                  pGrd->fZMin );
            createIP( 1, sColor.r, sColor.g, sColor.b, pMap, &nWarkerMark );
            break;
        }
    }
    // the interesting case of zmin beig higher than the max inflection value
    if( i >= pGrd->iNumColorInflections )
    {
        createIP( 1,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].r,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].g,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].b,
                  pMap, &nWarkerMark );
        createIP( mapSize - 1,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].r,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].g,
                  pGrd->stInflection[pGrd->iNumColorInflections - 1].b,
                  pMap, &nWarkerMark );
    }
    else
    {
        int index = 0;
        for( ; i < pGrd->iNumColorInflections; i++ )
        {
            if( pGrd->fZMax < pGrd->stInflection[i].zVal )
            {
                // then we must be between i and i-1
                linearColor( &sColor, &pGrd->stInflection[i - 1],
                                      &pGrd->stInflection[i], pGrd->fZMax );
                index = mapSize - 1;
                createIP( index, sColor.r, sColor.g, sColor.b, pMap,
                           &nWarkerMark );
                break;
            }
            // save the inflections between zmin and zmax
            index = (int)( ( (pGrd->stInflection[i].zVal - pGrd->fZMin) /
                                              (pGrd->fZMax - pGrd->fZMin) )
                           * mapSize);
                           
            if ( index >= mapSize )
                index = mapSize - 1;
            createIP( index,
                      pGrd->stInflection[i].r,
                      pGrd->stInflection[i].g,
                      pGrd->stInflection[i].b,
                      pMap, &nWarkerMark );
        }
        if( index < mapSize - 1 )
            createIP( mapSize - 1,
                      pGrd->stInflection[pGrd->iNumColorInflections - 1].r,
                      pGrd->stInflection[pGrd->iNumColorInflections - 1].g,
                      pGrd->stInflection[pGrd->iNumColorInflections - 1].b,
                      pMap, &nWarkerMark );
    }
    return 0;
}