Show
Ignore:
Timestamp:
02/09/09 16:51:58 (15 years ago)
Author:
trnewman
Message:

Cleaned up the code and put in the hooks for optimization request messages

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/CR_shell/src/main_cognitive_radio.cpp

    r90 r95  
    5959        for(i = 0; i < ce_info->numParameters; i++) { 
    6060                cout << "Parameter:  " << pList[i]->name << endl; 
     61        printf("Radio Operation Profile has been sucessfully sent.\n"); 
    6162                cout << "       Units:   " << pList[i]->units << endl; 
    6263                cout << "       Min:     " << pList[i]->min << endl; 
     
    115116        } 
    116117        ce_info->numUtilities = i;       
    117         cout << "Parsed " << ce_info->numUtilities << " utilities." << endl; 
     118        cout << "Initialize:: Parsed " << ce_info->numUtilities << " utilities." << endl; 
    118119 
    119120        // Pull observable information from XML file. 
     
    157158        } 
    158159        ce_info->numObservables = i;     
    159         cout << "Parsed " << ce_info->numObservables << " observables." << endl; 
     160        cout << "Initialize:: Parsed " << ce_info->numObservables << " observables." << endl; 
    160161         
    161162 
     
    210211        } 
    211212        ce_info->numParameters = i;      
    212         cout << "Parsed " << ce_info->numParameters << " parameters." << endl; 
     213        cout << "Initialize:: Parsed " << ce_info->numParameters << " parameters." << endl; 
    213214        return 1; 
    214215} 
     
    269270        //int total_bytes;    
    270271 
    271         printf("Sending configuration to CE.\n"); 
     272        printf("Sending Radio Operating Profile to Cognitive Engine.\n\n"); 
    272273  
    273274        // utilities 
     
    319320        } 
    320321         
    321         printf("Configuration sent, waiting for ACK...\n"); 
    322322        // Receive ACK for utils 
    323323    char buffer[256]; 
    324324        string message; 
    325325        n = ReceiveMessage(socketfd, buffer); 
    326     printf("%s\n", buffer); 
     326    //printf("%s\n", buffer); 
    327327        //cout << message << endl; 
    328         printf("ACK received.\n"); 
     328        //printf("ACK received.\n"); 
    329329 
    330330} 
     
    368368    } 
    369369 
    370     printf("experience sent\n"); 
    371370} 
    372371 
     
    389388    float var; 
    390389 
    391     /*// utility 
    392     for (i = 0; i < ce_info->numUtilities; i++){ 
    393         bzero(buffer,256); 
    394         ReceiveMessage(sockfd,buffer); 
    395         var = atof(buffer); 
    396         uList[i]->value = var; 
    397         printf("utility %s, value %f\n" 
    398                 , uList[i]->name.c_str(), uList[i]->value); 
    399     }*/ 
    400      
    401     // paramter 
     390    // Send request optimization message followed by the current environment parameters. 
     391    /* 
     392    SendMessage(sockfd,"request");  
     393    for (i = 0; i < ce_info->numObservables; i++){ 
     394        SendMessage(sockfd,..); 
     395    } 
     396    */ 
     397 
     398    // Receive optimized values from the Cognitive Engine  
    402399    for (i = 0; i < ce_info->numParameters; i++){ 
    403400        bzero(buffer,256); 
     
    405402        var = atof(buffer); 
    406403        pList[i]->value = var; 
    407         printf("parameter %s, value %f\n" 
    408                 , pList[i]->name.c_str(), pList[i]->value); 
    409404    } 
    410405 
    411     /*// observable 
    412     for (i = 0; i < ce_info->numObservables; i++){ 
    413         bzero(buffer,256); 
    414         ReceiveMessage(sockfd,buffer); 
    415         var = atof(buffer); 
    416         oList[i]->value = var; 
    417         printf("observable %s, value %f\n" 
    418                 , oList[i]->name.c_str(), oList[i]->value); 
    419     }*/ 
    420406 
    421407    return 1; 
     
    476462 
    477463        // update ce with experience 
     464    printf("Sending Previous Experience to New Cognitive Engine.\n\n"); 
    478465    UpdateCEExperience(socketfd, num_rows, num_cols, past_exp);  
    479466 
     
    484471        // Start socket server 
    485472        int sockfd, newsockfd, clilen; 
     473        int peer_len = sizeof(struct sockaddr); 
    486474        struct sockaddr_in serv_addr, cli_addr; 
     475        struct sockaddr_in peer; 
     476 
    487477 
    488478        // Setup server socket connection 
     
    507497                        error("ERROR on accept"); 
    508498 
     499        if(getpeername(newsockfd, (struct sockaddr *) &peer, (socklen_t*)&peer_len) == -1) { 
     500            perror("getpeername() failed"); 
     501            return -1; 
     502        } 
     503 
     504        printf("Received a connection from a Cognitive Engine with IP address: %s\n\n",inet_ntoa(peer.sin_addr)); 
     505 
    509506                // Begin parsing the messages 
    510507                StartMessaging(newsockfd, uList, pList, oList, ce_info); 
     
    541538        } 
    542539 
    543         cout << "Attemping to parse " << pFilename << "." << endl; 
     540        cout << "\n\nInitialize:: Attemping to parse " << pFilename << "." << endl; 
    544541        parse_ce_config( &doc , uList, pList, oList, &ce_info); 
    545         cout << "Configuration file parsing completed." << endl; 
     542        cout << "Initialize:: Configuration file parsing completed.\n" << endl; 
    546543 
    547544    //print_current_config(uList, pList, oList, &ce_info);