Show
Ignore:
Timestamp:
05/17/10 03:14:03 (14 years ago)
Author:
nikhil
Message:
 
Location:
vtcross/branches/nikhil/crossmodel1
Files:
1 modified
1 copied

Legend:

Unmodified
Added
Removed
  • vtcross/branches/nikhil/crossmodel1/src/libvtcross/libvtcross.cpp

    r536 r554  
    5757// TODO the following three functions all do exactly the same thing.  Why not 
    5858// simply combine them? 
    59 uint32_t 
    60 GetNumObservables() 
    61 { 
    62     char buffer[256]; 
    6359 
    64     uint32_t socketfd = ConnectToShell(); 
    65     SendMessage(socketfd, "get_number_observables"); 
    66      
    67     memset(buffer, 0, 256); 
    68     ReadMessage(socketfd, buffer); 
    69     uint32_t numObservables = atoi(buffer); 
    70      
    71     return numObservables;  
    72 } 
    73  
    74 uint32_t 
    75 GetNumUtilities() 
    76 { 
    77     char buffer[256]; 
    78  
    79     uint32_t socketfd = ConnectToShell(); 
    80     SendMessage(socketfd, "get_number_utilities"); 
    81      
    82     memset(buffer, 0, 256); 
    83     ReadMessage(socketfd, buffer); 
    84     uint32_t numUtilities = atoi(buffer); 
    85      
    86     return numUtilities;  
    87 } 
    88  
    89 uint32_t 
    90 SetActiveMission(char * activeMission) 
    91 { 
    92     char buffer[256]; 
    93      
    94     uint32_t socketfd = ConnectToShell(); 
    95     SendMessage(socketfd, "set_active_mission"); 
    96  
    97     SendMessage(socketfd, activeMission); 
    98  
    99     //memset(buffer, 0, 256); 
    100     //ReadMessage(socketfd, buffer); 
    101  
    102     return 1; 
    103 } 
    104  
    105 uint32_t 
    106 GetNumParameters() 
    107 { 
    108     char buffer[256]; 
    109  
    110     uint32_t socketfd = ConnectToShell(); 
    111     SendMessage(socketfd, "get_number_parameters"); 
    112      
    113     memset(buffer, 0, 256); 
    114     ReadMessage(socketfd, buffer); 
    115     uint32_t numParameters = atoi(buffer); 
    116      
    117     return numParameters;  
    118 } 
    119 // end previous TODO 
    120  
    121 /* Given a certain set of observables, ask the radio to find the optimum radio 
    122  * parameters and return them.  
    123  * 
    124  * TODO I'm a little confused about this function... why would anyone need to 
    125  * use this?  Shouldn't this be internal to the radio operation?  
    126  * 
    127  * TODO this function is returning a pointer to allocated memory, which is fine, 
    128  * but we need to document this and make sure the caller is deallocating the 
    129  * memory when it is done using it. 
    130  */ 
    13160Parameter*  
    132 GetOptimalParameters(Observable *radioObservables, uint32_t numObservables, 
    133         Parameter *currentParameters, uint32_t numCurrentParameters) 
     61GetOptimalParameters(Observable *radioObservables, uint32_t numObservables, Parameter *currentParameters, uint32_t numCurrentParameters, Utility *radioUtilities, uint32_t numUtilities) 
    13462{ 
    13563    char var[50]; 
     
    16391    } 
    16492 
     93    /* Send Utilities */ 
     94    memset(counter, 0, 55); 
     95    sprintf(counter, "%i", numUtilities); 
     96    SendMessage(socketFD, counter); 
     97    for(size_t i = 0; i < numUtilities; i++) { 
     98        SendMessage(socketFD,radioUtilities[i].name.c_str()); 
     99        sprintf(var,"%f",radioUtilities[i].value); 
     100        SendMessage(socketFD,var); 
     101    } 
     102         
     103 
    165104    /* Receive Set of Parameters */ 
    166105    memset(buffer, 0, 256); 
     
    184123 
    185124bool 
    186 UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, 
    187         uint32_t numObservables) 
     125UpdateParameterPerformance(Parameter *p, uint32_t numParameters, Observable *o, uint32_t numObservables, Utility *u, uint32_t numUtilities) 
    188126{ 
    189127    char counter[55]; 
     
    205143     
    206144    // Send Observables 
     145    memset(counter, 0, 55); 
    207146    sprintf(counter, "%i", numObservables); 
    208147    SendMessage(socketFD, counter); 
     
    212151        SendMessage(socketFD, var);     
    213152    } 
     153 
     154    // Send Utilities 
     155    memset(counter, 0, 55); 
     156    sprintf(counter, "%i", numUtilities); 
     157    SendMessage(socketFD, counter); 
     158    for(size_t i = 0; i < numUtilities; i++) { 
     159        SendMessage(socketFD, u[i].name.c_str()); 
     160        sprintf(var, "%f", u[i].value); 
     161        SendMessage(socketFD, var); 
     162    } 
     163         
    214164} 
    215165 
    216 bool ActivateComponent(uint32_t id) { 
    217     return 1; 
    218 } 
    219 bool DeactivateComponent(uint32_t id) { 
    220     return 1; 
    221 }  
    222 bool DisconnectComponent(uint32_t id) { 
    223     return 1; 
    224 } 
     166uint32_t GetNum(string type) 
     167{ 
     168 
     169        char buffer[256]; 
     170        uint32_t socketfd = ConnectToShell(); 
     171         
     172        if (type == "parameters") 
     173                SendMessage(socketfd, "get_number_parameters"); 
     174        else if (type == "utilities") 
     175                SendMessage(socketfd, "get_number_utilities"); 
     176        else if (type == "observables") 
     177                SendMessage(socketfd, "get_number_observables");         
     178        else 
     179                LOG("Type not included, either 'parameters' or 'utilities' or 'observables'");   
     180 
     181        memset(buffer, 0, 256); 
     182        ReadMessage(socketfd, buffer); 
     183        uint32_t number = atoi(buffer); 
     184        return number; 
    225185 
    226186 
    227 /* View components currently connected to the radio by id.  
    228  * 
    229  * TODO Should there be another way to list components? If you have 10 cognitive 
    230  * engines, how are you going to know which is which just by id? 
    231  */ 
    232 uint32_t* GetConnectedCognitiveEngines() { 
    233187} 
    234 uint32_t* GetConnectedPolicyEngines(){ 
    235 } 
    236 uint32_t* GetConnectedManagementServiceLayers(){ 
    237 } 
    238 uint32_t* GetConnectedComponents(){ 
    239 } 
    240  
    241  
    242 /* View data from the current status of the radio.  
    243  * 
    244  * This function allows client code to capture radio properties at any certain 
    245  * instant.  Note, however, that these properties could be changing at very 
    246  * rapid rates. There is no guarantee that the return results from these 
    247  * functions will still be valid by the time the client code receives them. 
    248  */ 
    249 Observable* GetRadioObservables() { 
    250 } 
    251 Parameter* GetRadioParameters(){ 
    252 } 
    253 Utility* GetRadioUtilities(){ 
    254 } 
    255  
    256  
    257 /* Parses VTCROSS XML configuration file and uses it to configure the radio.  
    258  * 
    259  * This function *must* be called when the radio first starts up, and may be 
    260  * called at any point after that to reconfigure the radio. 
    261  */ 
    262 bool ParseRadioConfiguration(){ 
    263 } 
    264  
    265  
    266 /* Lists current radio configuration options loaded from the configuration XML 
    267  * file.  
    268  * 
    269  * TODO How are we listing these?  Are we simply returning them to stdout? 
    270  * Logging them? Returning strings?  Need to figure this out... 
    271  */ 
    272 void ListCurrentRadioConfiguration(){ 
    273 } 
    274  
    275 /* Shut down the radio. 
    276  * 
    277  * This function will deactivate and disconnect all radio components before 
    278  * finally shutting down the shell and stopping radio operations. 
    279  */ 
    280 bool Shutdown(){ 
    281 } 
    282