/* Virginia Tech Cognitive Radio Open Source Systems * Virginia Tech, 2009 * * LICENSE INFORMATION GOES HERE */ /* Implementation file for the VCROSS Cognitive Radio public API defined in * include/libvtcross.h. * * MORE INFO HERE */ #include "vtcross/libvtcross.h" #include "vtcross/common.h" #include "vtcross/debug.h" uint32_t ConnectToRemoteComponent() { uint32_t socket; socket = ClientSocket("localhost", "40000"); return socket; } /* Given a certain set of observables, ask the radio to find the optimum radio * parameters and return them. * * TODO I'm a little confused about this function... why would anyone need to * use this? Shouldn't this be internal to the radio operation? */ Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables) { uint32_t i,socketfd,numParameters; char var[50]; char counter[55]; char buffer[256]; socketfd = ConnectToRemoteComponent(); SendMessage(socketfd,"request_optimization"); /* Get number of observables to send. This information needs to be * sent to the Cognitive Radio Shell also. */ // Send Observables sprintf(counter,"%i",numObservables); SendMessage(socketfd,counter); for(i = 0; i < numObservables; i++) { SendMessage(socketfd,radioObservables[i].name.c_str()); sprintf(var,"%f",radioObservables[i].value); SendMessage(socketfd,var); } /* Receive Set of Parameters */ memset(buffer, 0, 256); ReadMessage(socketfd, buffer); numParameters = atoi(buffer); Parameter * pList = new Parameter[numParameters]; for(size_t i = 0; i < numParameters; i++) { memset(buffer, 0, 256); ReadMessage(socketfd, buffer); pList[i].name = std::string(buffer); memset(buffer, 0, 256); ReadMessage(socketfd, buffer); pList[i].value = atof(buffer); } return pList; }