Changeset 390

Show
Ignore:
Timestamp:
07/29/09 00:31:04 (15 years ago)
Author:
trnewman
Message:

Functional DSA CBR, although it picks a random row.

Location:
vtcross/trunk/src/cognitive_engines/DSA_CE
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/DSA_CE/DSA_CognitiveEngine.cpp

    r389 r390  
    4444    SML_present = false; 
    4545    commandSocketFD = -1; 
     46    srand ( time(NULL) ); 
    4647} 
    4748 
     
    274275            LOG("Cognitive Engine:: Processing parameters....\n"); 
    275276 
    276             Parameter *solutionSet; 
    277              
    278             //solutionSet = GetSolution(o,cp); 
    279  
    280277            // TODO need to actually do something with the observables here 
    281278            
    282279            LOG("Cognitive Engine:: Sending Optimal Parameters to Application.\n"); 
    283280            char numParametersChar[10]; 
    284             char solutionValue[50]; 
    285281            sprintf(numParametersChar, "%i", radioInfo->numParameters); 
    286282            SendMessage(commandSocketFD, numParametersChar); 
    287283            for(size_t i = 0; i < radioInfo->numParameters; i++) { 
    288                 //SendMessage(commandSocketFD, solutionSet[i].name.c_str()); 
    289284                SendMessage(commandSocketFD, "test"); 
    290                 //memset(solutionValue, 0, 50); 
    291                 //sprintf(solutionValue, "%f", solutionSet[i].value); 
    292                 //SendMessage(commandSocketFD, solutionValue); 
    293285                SendMessage(commandSocketFD, "00"); 
    294286            } 
     
    649641    /* Put together the CBR search array */ 
    650642 
    651     char *searchNames[radioInfo->numUtilities + 1]; 
    652     float searchVals[radioInfo->numUtilities + 1]; 
    653     int searchOps[radioInfo->numUtilities + 1]; 
     643    char *searchNames[1]; 
     644    float searchVals[1]; 
     645    int searchOps[1]; 
    654646    uint32_t numberColumns = radioInfo->numUtilities + 
    655647                                radioInfo->numParameters + 
    656648                                radioInfo->numObservables + 1; 
    657649 
    658     for(size_t i = 0; i < radioInfo->numUtilities; i++) { 
    659         searchNames[i] = (char*)uList[i].name.c_str(); 
    660          
    661         if(strcmp(uList[i].goal.c_str(), "max") == 0) { 
    662             searchOps[i] = GT; 
    663         } else if(strcmp(uList[i].goal.c_str(), "min") == 0) { 
    664             searchOps[i] = LT; 
    665         } 
    666     
    667         /* Set search target to utility target */ 
    668         /* This may be bad if no target is set */  
    669         searchVals[i] = uList[i].target; 
    670     } 
    671     
    672  
    673650    /* Make sure we do not return any entries for the current channel */ 
    674     searchNames[radioInfo->numUtilities+1] = "channel"; 
    675     searchOps[radioInfo->numUtilities+1] = NE; 
    676     searchVals[radioInfo->numUtilities+1] = currentParameters[0].value;  
     651    searchNames[0] = "channel"; 
     652    searchOps[0] = NE; 
     653    searchVals[0] = currentParameters[0].value;  
    677654  
    678655    float returnValues[numberColumns]; 
     
    680657    /* Execute CBR search and put output into returnValues */ 
    681658    uint32_t rc = cbr_search(myCBR, searchNames, searchOps, searchVals, 
    682             radioInfo->numUtilities, returnValues); 
     659            1, returnValues); 
    683660 
    684661    if(rc == 0){ 
     
    688665        LOG("Cognitive Engine:: Previous similar environment found\n"); 
    689666 
     667        /* generate random channel */ 
     668        returnValues[CHANNEL] = rand() % (int)pList[0].max + (int)pList[0].min;  
     669         
    690670        if(returnValues[numberColumns-1] < 0) { 
    691          
    692             returnValues[2] = returnValues[2] - 15; 
    693             returnValues[3] = returnValues[3] - 2; 
    694671         
    695672        } else { 
    696673        
    697             returnValues[2] = returnValues[2] + 15; 
    698             returnValues[3] = returnValues[3] + 2; 
    699          
    700674        } 
    701675    } else if(rc == 31337) { 
     
    703677        LOG("Cognitive Engine:: No previous similar environment found.\n"); 
    704678      
    705         /* In the DSA case, the default is to select a random channel */ 
    706   
    707         /* initialize random seed: */ 
    708         srand ( time(NULL) ); 
    709  
    710679        /* generate random channel */ 
    711         //returnValues[CHANNEL] = rand() % currentParameters[0].max + currentParameters[0].min;  
    712         returnValues[CHANNEL] = rand() % 5;  
    713         
    714         printf("One: %i Two: %i\n",(int)currentParameters[0].max,(int)currentParameters[0].min); 
    715   
     680        returnValues[CHANNEL] = rand() % (int)pList[0].max + (int)pList[0].min;  
    716681    } else { 
    717682        LOG("Cognitive Engine:: Search return an invalid value.\n"); 
  • vtcross/trunk/src/cognitive_engines/DSA_CE/cbr.c

    r389 r390  
    202202    unsigned int i; 
    203203    char str_buffer[64]; 
    204     printf("number of ops %d:\n", _n); 
    205204    for (i=0; i<_n; i++) { 
    206205        // ensure valid ops value 
     
    221220    } 
    222221 
    223     //printf("search command: %s\n", _cbr->command); 
     222    printf("search command: %s\n", _cbr->command); 
    224223 
    225224    rc = ExecuteSearchCommand(_cbr, _retvals); 
  • vtcross/trunk/src/cognitive_engines/DSA_CE/examples/gnuradio-examples/dsa.py

    r389 r390  
    4747        def send_pkt(self, payload='', eof=False): 
    4848                return self.txpath.send_pkt(payload, eof) 
    49          
     49 
     50        def get_real_channel(channel): 
     51 
     52                real_channel = 1; 
     53 
     54                if channel == 1: 
     55                        real_channel = 1 
     56                if channel == 2: 
     57                        real_channel = 7 
     58                if channel == 3: 
     59                        real_channel = 8 
     60                if channel == 4: 
     61                        real_channel = 14 
     62 
     63                return real_channel 
     64 
    5065        def get_freq(hop_freq,probe_level,absent_time): 
    5166 
     
    5570                        channel = 1 
    5671                if hop_freq == 462712500: 
    57                         channel = 7 
     72                        channel = 2 
    5873                if hop_freq == 467562500: 
    59                         channel = 8 
     74                        channel = 3 
    6075                if hop_freq == 467712500: 
    61                         channel = 14 
     76                        channel = 4 
    6277 
    6378                p = Parameter(1) 
     
    7287 
    7388                p = GetOptimalParameters(o,1,currentParameters,1); 
    74                 print p[0].name, p[0].value 
    75          
     89                print p[0].value 
     90                 
     91                channel = get_real_channel(int(p[0].value)) 
     92 
    7693                if channel < 8: 
    7794                        hop_freq = float(1e6 * (462.5625+(channel-1)*0.025))#setting the centre freq frequency for sending packets 
     
    153170                        help="use file for packet contents") 
    154171         
    155         transmit_path.add_options(parser_tx, expert_grp_tx) 
     172        transmit_path.add_options(parser_tx, expert_grp_tx) 
    156173 
    157174        for mod in mods.values(): 
     
    228245        ch_energy = tb.rxpath.probe.level() #setting initial value 
    229246        hop_freq = options_tx.tx_freq #  = options_rx.rx_freq...same for tx and rx side 
    230         while running: 
     247         
     248 
     249        # Scan all channels first for inital data 
     250 
     251        while running: 
    231252 
    232253                ################################################sync mode####################################