Show
Ignore:
Timestamp:
03/30/09 21:38:53 (15 years ago)
Author:
trnewman
Message:

Added libvtcross functionality. Made socketcomm a little more robust. Added libvtcross demo application to illustrate how to use the lib.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/libvtcross/libvtcross.cpp

    r161 r222  
    1313#include "vtcross/libvtcross.h" 
    1414#include "vtcross/common.h" 
     15#include "vtcross/debug.h" 
    1516 
     17uint32_t 
     18ConnectToRemoteComponent() 
     19{ 
     20        uint32_t socket;  
     21    socket = ClientSocket("localhost", "40000"); 
     22     
     23    return socket; 
     24} 
     25 
     26/* Given a certain set of observables, ask the radio to find the optimum radio 
     27 * parameters and return them.  
     28 * 
     29 * TODO I'm a little confused about this function... why would anyone need to 
     30 * use this?  Shouldn't this be internal to the radio operation?  
     31 */ 
     32Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables) { 
     33    uint32_t i,socketfd,numParameters; 
     34    char var[50]; 
     35    char counter[55]; 
     36        char buffer[256]; 
     37 
     38    socketfd = ConnectToRemoteComponent(); 
     39    SendMessage(socketfd,"request_optimization"); 
     40 
     41    /* Get number of observables to send.  This information needs to be  
     42     * sent to the Cognitive Radio Shell also.    
     43     */ 
     44 
     45    // Send Observables 
     46    sprintf(counter,"%i",numObservables); 
     47    SendMessage(socketfd,counter); 
     48    for(i = 0; i < numObservables; i++) { 
     49        SendMessage(socketfd,radioObservables[i].name.c_str()); 
     50        sprintf(var,"%f",radioObservables[i].value); 
     51        SendMessage(socketfd,var);       
     52    } 
     53 
     54    /* Receive Set of Parameters */ 
     55    memset(buffer, 0, 256); 
     56    ReadMessage(socketfd, buffer); 
     57    numParameters = atoi(buffer); 
     58    Parameter * pList = new Parameter[numParameters]; 
     59     
     60    for(size_t i = 0; i < numParameters; i++) { 
     61        memset(buffer, 0, 256); 
     62        ReadMessage(socketfd, buffer); 
     63        pList[i].name = std::string(buffer); 
     64         
     65                memset(buffer, 0, 256); 
     66        ReadMessage(socketfd, buffer); 
     67        pList[i].value = atof(buffer); 
     68    }    
     69 
     70    return pList; 
     71}