11 #include "LibCyberRadio/Driver/NDR551/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> 34 RadioHandler::RadioHandler(
bool debug) :
63 _connModesSupported.push_back(
"udp");
64 _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 _wbddcs[wbddc]->setRateIndex(40);
102 for (
int nbddc = _nbddcIndexBase;
103 nbddc < (_nbddcIndexBase + _numNbddc); nbddc++)
105 _nbddcs[nbddc] =
new NDR551::NbddcComponent(
109 (
int)((nbddc & 0x10) >> 4),
115 (
int)((nbddc & 0x10) >> 4));
119 for (
int group = _wbddcGroupIndexBase;
120 group < (_wbddcGroupIndexBase + _numWbddcGroups); group++)
122 _wbddcGroups[group] =
new NDR551::WbddcGroupComponent(
128 for (
int group = _nbddcGroupIndexBase;
129 group < (_nbddcGroupIndexBase + _numNbddcGroups); group++)
131 _nbddcGroups[group] =
new NDR551::NbddcGroupComponent(
138 for (
int dataPort = _dataPortIndexBase;
139 dataPort < (_dataPortIndexBase + _numDataPorts); dataPort++)
141 _dataPorts[dataPort] =
new NDR551::DataPort(
160 ::LibCyberRadio::Driver::RadioHandler::operator=(other);
173 _config[
"referenceMode"] = _referenceMode;
179 this->
debug(
"[NDR551::RadioHandler::queryConfiguration] Called\n");
184 Json::Value root(Json::objectValue);
186 root[
"cmd"] =
"qstatus";
187 Json::Value params(Json::objectValue);
188 root[
"params"] = params;
189 Json::FastWriter fastWriter;
190 std::string output = fastWriter.write(root);
192 if ( _config.
hasKey(
"referenceMode") )
194 this->executeReferenceModeQuery(_referenceMode);
196 this->
debug(
"[NDR551::RadioHandler::queryConfiguration] Returning\n");
198 for ( TunerComponentDict::iterator it = _tuners.begin();
199 it != _tuners.end(); it++)
201 it->second->queryConfiguration();
203 for ( WbddcComponentDict::iterator it = _wbddcs.begin();
204 it != _wbddcs.end(); it++)
206 it->second->queryConfiguration();
208 for ( DataPortDict::iterator it = _dataPorts.begin();
209 it != _dataPorts.end(); it++)
211 it->second->queryConfiguration();
215 bool RadioHandler::queryVersionInfo()
217 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Called\n");
220 Json::Value root(Json::objectValue);
222 root[
"cmd"] =
"qstatus";
223 Json::Value params(Json::objectValue);
224 root[
"params"] = params;
225 Json::FastWriter fastWriter;
226 std::string output = fastWriter.write(root);
237 int stateTracker = -1;
241 for (BasicStringList::iterator it = vec.begin(); it != vec.end(); it++)
244 if ( it->find(
"Unit") == 0 )
246 else if ( it->find(
"Digital Board") == 0 )
248 else if ( it->find(
"Tuner Quad") == 0 )
251 switch( stateTracker )
254 if ( it->find(
" Revision: ") != std::string::npos )
260 if ( ( it->find(
"Tuner Quad") == 0) && ( it->find(
"Not Installed") != std::string::npos) )
262 else if ( it->find(
"Bandwidth: ") == 0 )
265 std::istringstream iss(tmp);
281 _numTuner = std::min(_numTuner, _numTunerBoards * 4);
282 _numWbddc = _numTuner;
283 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Number of tuner boards=%d\n", _numTunerBoards);
284 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Number of tuners=%d\n", _numTuner);
286 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Deallocating nonexistent tuners/WBDDCs\n");
287 TunerComponentDict::iterator it = _tuners.begin();
288 for (; it != _tuners.end(); )
290 if ( it->first >= (_tunerIndexBase + _numTuner) )
292 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] -- Deallocating tuner=%d\n", it->first);
298 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] -- OK tuner=%d\n", it->first);
302 WbddcComponentDict::iterator it2 = _wbddcs.begin();
303 for (; it2 != _wbddcs.end(); )
305 if ( it2->first >= (_wbddcIndexBase + _numWbddc) )
307 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] -- Deallocating WBDDC=%d\n", it2->first);
309 _wbddcs.erase(it2++);
313 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] -- OK WBDDC=%d\n", it2->first);
318 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Max tuner bandwidth=%d MHz\n", _maxTunerBw);
319 for (it = _tuners.begin(); it != _tuners.end(); it++)
321 it->second->setFrequencyRangeMax(_maxTunerBw * 1e6);
326 for (BasicStringStringDict::iterator it = _versionInfo.begin(); it != _versionInfo.end(); it++)
328 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] %s = \"%s\"\n", it->first.c_str(), it->second.c_str());
331 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Returning %s\n",
debugBool(ret));
337 bool RadioHandler::executeQueryIDN(std::string& model,
338 std::string& serialNumber)
340 return ::LibCyberRadio::Driver::RadioHandler::executeQueryIDN(model, serialNumber);
345 bool RadioHandler::executeQueryVER(std::string& softwareVersion,
346 std::string& firmwareVersion,
347 std::string& referenceVersion,
348 std::string& firmwareDate)
351 return ::LibCyberRadio::Driver::RadioHandler::executeQueryVER(softwareVersion,
359 bool RadioHandler::executeQueryHREV(std::string& hardwareInfo)
361 return ::LibCyberRadio::Driver::RadioHandler::executeQueryHREV(hardwareInfo);
366 auto time = std::chrono::system_clock::now();
367 auto now_sec = std::chrono::time_point_cast<std::chrono::seconds>(time);
368 auto epoch = now_sec.time_since_epoch();
369 auto v = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
370 return (uint32_t)v.count();
372 bool RadioHandler::executeReferenceModeQuery(
int& refMode)
374 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Called\n");
377 Json::Value root(Json::objectValue);
379 root[
"cmd"] =
"qref";
380 Json::Value params(Json::objectValue);
381 root[
"params"] = params;
382 Json::FastWriter fastWriter;
383 std::string output = fastWriter.write(root);
386 Json::Value returnVal;
387 std::string t = rsp.at(0);
388 printf(
"%s\n",t.c_str());
389 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
390 refMode = boost::lexical_cast<
int>(returnVal[
"cfg10m"].asInt());
394 bool RadioHandler::executeReferenceModeCommand(
int& refMode)
396 this->
debug(
"[NDR551::RadioHandler::queryVersionInfo] Called\n");
399 Json::Value root(Json::objectValue);
402 Json::Value params(Json::objectValue);
403 root[
"params"] = params;
404 Json::FastWriter fastWriter;
405 std::string output = fastWriter.write(root);
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual void queryConfiguration()
Tells the radio to query its hardware configuration in order to create its configuration dictionary (...
virtual bool isConnected() const
Gets whether or not the handler is connected.
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 ~RadioHandler()
Destroys a RadioHandler object.
uint32_t getMessageId(void)
Returns a Time for the msg parameter.
Generic radio handler class.
virtual int debug(const char *format,...)
Outputs debug information.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Defines functionality for LibCyberRadio applications.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
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 queryConfiguration()
Tells the radio to query its hardware configuration in order to create its configuration dictionary (...
Radio handler class for the NDR551.