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

Revision 222, 1.9 KB (checked in by trnewman, 15 years ago)

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

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 "vtcross/libvtcross.h"
14#include "vtcross/common.h"
15#include "vtcross/debug.h"
16
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}
Note: See TracBrowser for help on using the browser.