root/vtcross/trunk/src/libvtcross/libvtcross.cpp @ 226

Revision 226, 1.9 KB (checked in by bhilburn, 15 years ago)

Fixing cstdlib include that shouldn't have compiled on any system, and
adding new libvtcross bins to gitignore.

Line 
1/* Virginia Tech Cognitive Radio Open Source Systems
2 * Virginia Tech, 2009
3 *
4 * LICENSE INFORMATION GOES HERE
5 */
6
7/* Implementation file for the VCROSS Cognitive Radio public API defined in
8 * include/libvtcross.h.
9 *
10 * MORE INFO HERE
11 */
12
13#include <cstdlib>
14
15#include "vtcross/common.h"
16#include "vtcross/debug.h"
17#include "vtcross/libvtcross.h"
18
19uint32_t
20ConnectToRemoteComponent()
21{
22        uint32_t socket;
23    socket = ClientSocket("localhost", "40000");
24   
25    return socket;
26}
27
28/* Given a certain set of observables, ask the radio to find the optimum radio
29 * parameters and return them.
30 *
31 * TODO I'm a little confused about this function... why would anyone need to
32 * use this?  Shouldn't this be internal to the radio operation?
33 */
34Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables) {
35    uint32_t i,socketfd,numParameters;
36    char var[50];
37    char counter[55];
38        char buffer[256];
39
40    socketfd = ConnectToRemoteComponent();
41    SendMessage(socketfd,"request_optimization");
42
43    /* Get number of observables to send.  This information needs to be
44     * sent to the Cognitive Radio Shell also.   
45     */
46
47    // Send Observables
48    sprintf(counter,"%i",numObservables);
49    SendMessage(socketfd,counter);
50    for(i = 0; i < numObservables; i++) {
51        SendMessage(socketfd,radioObservables[i].name.c_str());
52        sprintf(var,"%f",radioObservables[i].value);
53        SendMessage(socketfd,var);     
54    }
55
56    /* Receive Set of Parameters */
57    memset(buffer, 0, 256);
58    ReadMessage(socketfd, buffer);
59    numParameters = atoi(buffer);
60    Parameter * pList = new Parameter[numParameters];
61   
62    for(size_t i = 0; i < numParameters; i++) {
63        memset(buffer, 0, 256);
64        ReadMessage(socketfd, buffer);
65        pList[i].name = std::string(buffer);
66       
67                memset(buffer, 0, 256);
68        ReadMessage(socketfd, buffer);
69        pList[i].value = atof(buffer);
70    }   
71
72    return pList;
73}
Note: See TracBrowser for help on using the browser.