11 #include "LibCyberRadio/Driver/NDR358/RadioHandler.h" 12 #include "LibCyberRadio/Driver/NDR551/DataPort.h" 13 #include "LibCyberRadio/Driver/NDR551/NbddcComponent.h" 14 #include "LibCyberRadio/Driver/NDR551/TunerComponent.h" 15 #include "LibCyberRadio/Driver/NDR551/VitaIfSpec.h" 16 #include "LibCyberRadio/Driver/NDR551/WbddcComponent.h" 19 #include "LibCyberRadio/Common/Pythonesque.h" 20 #include <json/json.h> 26 static uint32_t msgCounter = 1;
36 RadioHandler::RadioHandler(
bool debug) :
65 _connModesSupported.push_back(
"udp");
66 _defaultDeviceInfo = 19091;
71 for (
int tuner = _tunerIndexBase;
72 tuner < (_tunerIndexBase + _numTuner); tuner++)
75 _tuners[tuner] =
new NDR551::TunerComponent(
84 for (
int wbddc = _wbddcIndexBase;
85 wbddc < (_wbddcIndexBase + _numWbddc); wbddc++)
87 _wbddcs[wbddc] =
new NDR551::WbddcComponent(
98 for (
int nbddc = _nbddcIndexBase;
99 nbddc < (_nbddcIndexBase + _numNbddc); nbddc++)
101 _nbddcs[nbddc] =
new NDR551::NbddcComponent(
115 for (
int group = _wbddcGroupIndexBase;
116 group < (_wbddcGroupIndexBase + _numWbddcGroups); group++)
118 _wbddcGroups[group] =
new NDR551::WbddcGroupComponent(
124 for (
int group = _nbddcGroupIndexBase;
125 group < (_nbddcGroupIndexBase + _numNbddcGroups); group++)
127 _nbddcGroups[group] =
new NDR551::NbddcGroupComponent(
134 for (
int dataPort = _dataPortIndexBase;
135 dataPort < (_dataPortIndexBase + _numDataPorts); dataPort++)
137 _dataPorts[dataPort] =
new NDR551::DataPort(
158 _config[
"referenceMode"] = _referenceMode;
164 ::LibCyberRadio::Driver::RadioHandler::operator=(other);
174 this->
debug(
"[NDR358]::RadioHandler::queryConfiguration] Called\n");
179 Json::Value root(Json::objectValue);
181 root[
"cmd"] =
"qstatus";
182 Json::Value params(Json::objectValue);
183 root[
"params"] = params;
184 Json::FastWriter fastWriter;
185 std::string output = fastWriter.write(root);
187 if ( _config.
hasKey(
"referenceMode") )
189 this->executeReferenceModeQuery(_referenceMode);
191 this->
debug(
"[NDR358::RadioHandler::queryConfiguration] Returning\n");
193 for ( TunerComponentDict::iterator it = _tuners.begin();
194 it != _tuners.end(); it++)
196 it->second->queryConfiguration();
198 for ( WbddcComponentDict::iterator it = _wbddcs.begin();
199 it != _wbddcs.end(); it++)
201 it->second->queryConfiguration();
203 for ( DataPortDict::iterator it = _dataPorts.begin();
204 it != _dataPorts.end(); it++)
206 it->second->queryConfiguration();
208 this->queryVersionInfo();
211 bool RadioHandler::query358Specifics()
213 Json::Value root(Json::objectValue);
216 Json::Value params(Json::objectValue);
217 params[
"input"] =
"version";
218 root[
"params"] = params;
219 Json::FastWriter fastWriter;
220 std::string output = fastWriter.write(root);
223 Json::Value returnVal;
224 std::string t = rsp.at(0);
225 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
226 if( parsingSuccessful ){
227 if ( returnVal[
"result"].isString() ) {
228 std::string result = returnVal[
"result"].asString();
230 for(
int i = 0; i < l.size(); i++)
232 std::string temp = l.at(i);
235 const char *unitsn =
"UnitSN";
236 if ( std::strstr(temp.c_str(), unitsn) !=
nullptr )
238 _versionInfo[
"serialNumber"] = J.at(1).c_str();
242 _versionInfo[
"serialNumber"] =
"SNxxxx";
248 bool RadioHandler::queryVersionInfo()
250 this->
debug(
"[RadioHandler::queryVersionInfo] Called\n");
253 Json::Value root(Json::objectValue);
255 root[
"cmd"] =
"qstatus";
256 Json::Value params(Json::objectValue);
257 root[
"params"] = params;
258 Json::FastWriter fastWriter;
259 std::string output = fastWriter.write(root);
262 Json::Value returnVal;
263 std::string t = rsp.at(0);
264 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
265 if( parsingSuccessful ){
266 _versionInfo[
"model"] = returnVal[
"result"][
"model"].asString();
267 _versionInfo[
"softwareVersion"] = returnVal[
"result"][
"sw"].asString();
268 _versionInfo[
"firmwareVersion"] = returnVal[
"result"][
"fw"].asString();
269 _versionInfo[
"unitRevision"] = returnVal[
"result"][
"unit"].asString();
270 _versionInfo[
"hardwareVersion"] = returnVal[
"result"][
"unit"].asString();
272 this->query358Specifics();
273 this->
debug(
"[NDR358::RadioHandler::queryVersionInfo] Returning %s\n",
debugBool(ret));
279 bool RadioHandler::executeQueryIDN(std::string& model,
280 std::string& serialNumber)
282 return ::LibCyberRadio::Driver::RadioHandler::executeQueryIDN(model, serialNumber);
287 bool RadioHandler::executeQueryVER(std::string& softwareVersion,
288 std::string& firmwareVersion,
289 std::string& referenceVersion,
290 std::string& firmwareDate)
293 return ::LibCyberRadio::Driver::RadioHandler::executeQueryVER(softwareVersion,
301 bool RadioHandler::executeQueryHREV(std::string& hardwareInfo)
303 return ::LibCyberRadio::Driver::RadioHandler::executeQueryHREV(hardwareInfo);
311 bool RadioHandler::executeReferenceModeQuery(
int& refMode)
313 this->
debug(
"[NDR358::RadioHandler::queryVersionInfo] Called\n");
316 Json::Value root(Json::objectValue);
318 root[
"cmd"] =
"qref";
319 Json::Value params(Json::objectValue);
320 root[
"params"] = params;
321 Json::FastWriter fastWriter;
322 std::string output = fastWriter.write(root);
325 Json::Value returnVal;
326 std::string t = rsp.at(0);
327 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
328 if( parsingSuccessful ){
329 refMode = boost::lexical_cast<
int>(returnVal[
"result"][
"cfg10m"].asInt());
335 bool RadioHandler::executeReferenceModeCommand(
int& refMode)
337 this->
debug(
"[NDR358::RadioHandler::queryVersionInfo] Called\n");
340 Json::Value root(Json::objectValue);
343 Json::Value params(Json::objectValue);
344 params[
"cfg10m"] = refMode;
345 root[
"params"] = params;
346 Json::FastWriter fastWriter;
347 std::string output = fastWriter.write(root);
350 Json::Value returnVal;
351 std::string t = rsp.at(0);
352 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
353 if( parsingSuccessful ){
354 ret = boost::lexical_cast<
bool>(returnVal[
"success"].asBool());
virtual ~RadioHandler()
Destroys a RadioHandler object.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
virtual int debug(const char *format,...)
Outputs debug information.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Radio handler class for the NDR551.
Defines functionality for LibCyberRadio applications.
static std::string Lstrip(const std::string &str, const std::string &chars=" \\\)
Strips leading whitespace from the given string.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual void queryConfiguration()
Tells the radio to query its hardware configuration in order to create its configuration dictionary (...
uint32_t getMessageId(void)
Returns a Time for the msg parameter.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
void setJson(bool json)
Allows user to set JSON.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.