libcyberradio 22.01.24
WbddcComponent.cpp
1/***************************************************************************
2 * \file WbddcComponent.cpp
3 * \brief Defines the WBDDC interface for the NDR551.
4 * \author DA
5 * \author NH
6 * \author MN
7 * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
8 *
9 ***************************************************************************/
10
11#include "LibCyberRadio/Driver/NDR551/WbddcComponent.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include <boost/format.hpp>
14#include <json/json.h>
15#include <boost/lexical_cast.hpp>
16#include <iostream>
17
18
19namespace LibCyberRadio
20{
21 namespace Driver
22 {
23
24 namespace NDR551
25 {
26
29 bool debug,
30 int dataPort,
31 int rateIndex,
32 int udpDestination,
33 int vitaEnable,
34 int streamId) :
35 m551Parent( parent ),
37 /* const std::string& name */ (boost::format("NDR551-WBDDC%02d") % \
38 index).str(),
39 /* int index */ index,
40 /* ::LibCyberRadio::Driver::RadioHandler* parent */ parent,
41 /* bool debug */ debug,
42 /* bool tunable */ true,
43 /* bool selectableSource */ true,
44 /* bool selectableDataPort */ true,
45 /* bool agc */ true,
46 /* double freqRangeMin */ 0.0,
47 /* double freqRangeMax */ 0.0,
48 /* double freqRes */ 1e6,
49 /* double freqUnits */ 1e6,
50 /* int source */ index,
51 /* int dataPort */ dataPort,
52 /* double frequency */ 0.0,
53 /* int rateIndex */ rateIndex,
54 /* int udpDestination */ udpDestination,
55 /* int vitaEnable */ vitaEnable,
56 /* unsigned int streamId */ streamId)
57 {
58 this->debug("[NDR551::WbddcComponent] index - %d\n", index);
59
61 // Set rate set
62 _rateSet[40] = 128.0e6;
63 _rateSet[39] = 64.0e6;
64 _rateSet[38] = 32.0e6;
65 _rateSet[37] = 32.0e6;
66 _rateSet[36] = 16.0e6;
67 _rateSet[35] = 16.0e6;
68 _rateSet[34] = 16.0e6;
69 _rateSet[33] = 8.0e6;
70 _rateSet[32] = 8.0e6;
71 }
72
76
81
83 {
84 ::LibCyberRadio::Driver::WbddcComponent::operator=(other);
85 if ( this != &other )
86 {
87 }
88 return *this;
89 }
90
92 {
93 //this->debug("[WbddcComponent::initConfigurationDict] Called\n");
94 _config.clear();
95 // Call the base-class version
97 // Define tuner-specific keys
98 _config["filter"] = 40;
99 _config["dest"] = 0;
100 _config["enable"] = false;
101 _config["vita"] = 0;
102 _config["type"] = "auto";
103 _config["decimation"] = _decimation;
104 _config["ovs"] = 1;
105 _config["mode"] = _mode;
106 _config["dgv"] = _dgv;
107 _config["dul"] = _dul;
108 _config["dll"] = _dll;
109 _config["dtl"] = _dtl;
110 _config["dal"] = _dal;
111 _config["ddl"] = _ddl;
112 _config["dao"] = _dao;
113 _config["ddo"] = _ddo;
114 _config["datc"] = _datc;
115 _config["ddtc"] = _ddtc;
116 _config["ddt"] = 90;
117 if ( _tunable )
118 {
119 _config["offset"] = 0.0f;
120 }
121 if ( _selectableSource )
122 {
123 _config["rfch"] = "0";
124 }
125 if ( _selectableDataPort )
126 {
127 _config["link"] = 0;
128 }
129 //this->debug("[WbddcComponent::initConfigurationDict] Returning\n");
130 }
131
133 {
134 bool ret = false;
135 this->debug("[NDR551WbddcComponent::setConfiguration] Called\n");
136 // Setup the JSON Command.
137 Json::Value command;
138 Json::Value params;
139 command["cmd"] = "wbddc";
140 command["msg"] = _parent->getMessageId();
141 command["params"] = Json::objectValue;
142 command["params"]["id"] = _index;
143
144 for( ConfigurationDict::const_iterator it = cfg.begin();
145 it != cfg.end(); ++it)
146 {
147 if ( (it->first == "mode") ||
148 (it->first == "rfch") ||
149 (it->first == "type") )
150 {
151 command["params"][it->first.c_str()] = it->second.c_str();
152 }
153 else if ( (it->first == "enable") )
154 {
155 command["params"][it->first.c_str()] = it->second.asBool();
156 }
157 else
158 {
159 command["params"][it->first.c_str()] = it->second.asInt();
160 }
161 }
162 Json::FastWriter fastWriter;
163 std::string output = fastWriter.write(command);
164 std::cout << output << std::endl;
165 BasicStringList rsp = _parent->sendCommand(output);
166 Json::Reader reader;
167 Json::Value returnVal;
168 std::string t = rsp.at(0);
169 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
170 ret = returnVal["success"].asBool();
171 return ret;
172 }
173
175 {
176 this->debug("[NDR551WbddcComponent::updateConfigurationDict] Called\n");
178 if ( _config.hasKey("filter") )
179 setConfigurationValueToInt("filter", _rateIndex);
180 if ( _config.hasKey("dest") )
181 setConfigurationValueToInt("dest", _udpDestination);
182 if ( _config.hasKey("enable") )
183 setConfigurationValueToInt("enable", _vitaEnable);
184 if ( _config.hasKey("vita") )
185 setConfigurationValueToUInt("vita", _streamId);
186 if ( _tunable && _config.hasKey("offset") )
187 {
188 setConfigurationValueToDbl("offset", _frequency);
189 }
190 if ( _selectableSource && _config.hasKey("rfch") )
191 {
192 setConfigurationValueToInt("rfch", _source);
193 }
194 if ( _selectableDataPort && _config.hasKey("link") )
195 {
196 setConfigurationValueToInt("link", _dataPort);
197 }
198 if ( _config.hasKey("mode") )
199 {
200 setConfigurationValue("mode", _mode);
201 }
202 if ( _config.hasKey("decimation") )
203 {
204 setConfigurationValueToInt("decimation", _decimation);
205 }
206 if ( _config.hasKey("dgv" ) )
207 {
208 setConfigurationValueToInt("dgv", _dgv);
209 }
210 if ( _config.hasKey("dul" ) )
211 {
212 setConfigurationValueToInt("dul", _dul);
213 }
214 if ( _config.hasKey("dll" ) )
215 {
216 setConfigurationValueToInt("dll", _dll);
217 }
218 if ( _config.hasKey("dtl" ) )
219 {
220 setConfigurationValueToInt("dtl", _dtl);
221 }
222 if ( _config.hasKey("dal" ) )
223 {
224 setConfigurationValueToInt("dal", _dal);
225 }
226 if ( _config.hasKey("ddl" ) )
227 {
228 setConfigurationValueToInt("ddl", _ddl);
229 }
230 if ( _config.hasKey("dao" ) )
231 {
232 setConfigurationValueToInt("dao", _dao);
233 }
234 if ( _config.hasKey("ddo" ) )
235 {
236 setConfigurationValueToInt("ddo", _ddo);
237 }
238 if ( _config.hasKey("datc") )
239 {
240 setConfigurationValueToInt("datc", _datc);
241 }
242 if ( _config.hasKey("ddtc") )
243 {
244 setConfigurationValueToInt("ddtc", _ddtc);
245 }
246 if ( _config.hasKey("ddt" ) )
247 {
248 setConfigurationValueToInt("ddt", _ddt);
249 }
250 if ( _config.hasKey("type") )
251 {
252 setConfigurationValue("type", _type);
253 }
254 }
255
257 {
258 this->debug("[WbddcComponent::queryConfiguration] Called\n");
259 Json::Value command;
260 Json::Value params;
261 command["cmd"] = "qwbddc";
262 command["msg"] = _parent->getMessageId();
263 command["params"] = Json::objectValue;
264 command["params"]["id"] = _index;
265 Json::FastWriter fastWriter;
266 std::string output = fastWriter.write(command);
267 BasicStringList rsp = _parent->sendCommand(output);
268 Json::Reader reader;
269 Json::Value returnVal;
270 std::string t = rsp.at(0);
271 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
272 if( parsingSuccessful && returnVal.isMember("result") ) {
273 _enabled = boost::lexical_cast<bool>(returnVal["result"]["enable"].asBool());
274 _frequency = boost::lexical_cast<double>(returnVal["result"]["offset"].asDouble());
275 _source = boost::lexical_cast<int>(returnVal["result"]["rfch"].asString());
276 _dataPort = boost::lexical_cast<int>(returnVal["result"]["link"].asInt());
277 _udpDestination = boost::lexical_cast<int>(returnVal["result"]["dest"].asInt());
278 _rateIndex = boost::lexical_cast<int>(returnVal["result"]["filter"].asInt());
279 _streamId = boost::lexical_cast<int>(returnVal["result"]["vita"].asUInt());
280 _ovs = boost::lexical_cast<int>(returnVal["result"]["ovs"].asInt());
281 _decimation = boost::lexical_cast<int>(returnVal["result"]["decimation"].asInt());
282 _type = boost::lexical_cast<std::string>(returnVal["result"]["type"].asString());
283 _mode = boost::lexical_cast<std::string>(returnVal["result"]["mode"].asString());
284 _dgv = boost::lexical_cast<int>(returnVal["result"]["dgv"].asInt());
285 _dul = boost::lexical_cast<int>(returnVal["result"]["dul"].asInt());
286 _dll = boost::lexical_cast<int>(returnVal["result"]["dll"].asInt());
287 _dtl = boost::lexical_cast<int>(returnVal["result"]["dtl"].asInt());
288 _dal = boost::lexical_cast<int>(returnVal["result"]["dal"].asInt());
289 _ddl = boost::lexical_cast<int>(returnVal["result"]["ddl"].asInt());
290 _dao = boost::lexical_cast<int>(returnVal["result"]["dao"].asInt());
291 _ddo = boost::lexical_cast<int>(returnVal["result"]["ddo"].asInt());
292 _datc = boost::lexical_cast<int>(returnVal["result"]["datc"].asInt());
293 _ddtc = boost::lexical_cast<int>(returnVal["result"]["ddtc"].asInt());
294 _dat = boost::lexical_cast<int>(returnVal["result"]["dat"].asInt());
295 _ddt = boost::lexical_cast<int>(returnVal["result"]["ddt"].asInt());
297 }
298 this->debug("[WbddcComponent::queryConfiguration] Returning\n");
299 }
300
305 bool WbddcComponent::executeWbddcQuery(int index, int& rateIndex,
306 int& udpDestination, bool& enabled, int& vitaEnable,
307 unsigned int& streamId)
308 {
309 bool ret = false;
310 if ( (_parent != NULL) && (_parent->isConnected()) )
311 {
312 Json::Value root(Json::objectValue);
313 root["msg"] = m551Parent->getMessageId();
314 Json::Value params(Json::objectValue);
315 params["id"] = index;
316 root["params"] = params;
317 Json::FastWriter fastWriter;
318 std::string output = fastWriter.write(root);
319 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
320 Json::Reader reader;
321 Json::Value returnVal;
322 std::string t = recv.at(0);
323 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
324 Json::Value result = returnVal["result"];
325 rateIndex = boost::lexical_cast<int>(result["filter"].asInt());
326 udpDestination = boost::lexical_cast<int>(result["dest"].asInt());
327 enabled = boost::lexical_cast<int>(result["enable"].asBool());
328 vitaEnable = boost::lexical_cast<int>(result["enable"].asBool());
329 streamId = boost::lexical_cast<unsigned int>(result["vita"].asUInt());
330 }
331 return ret;
332 }
333
334 bool WbddcComponent::executeDataPortCommand(int index, int& dataPort)
335 {
336 bool ret = false;
337 if ( (_parent != NULL) && (_parent->isConnected()) )
338 {
339 Json::Value root(Json::objectValue);
340 root["msg"] = m551Parent->getMessageId();
341 root["cmd"] = "wbddc";
342 Json::Value params(Json::objectValue);
343 params["id"] = index;
344 params["link"] = dataPort;
345 root["params"] = params;
346 Json::FastWriter fastWriter;
347 std::string output = fastWriter.write(root);
348 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
349 Json::Reader reader;
350 Json::Value returnVal;
351 std::string t = recv.at(0);
352 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
353 ret = returnVal["success"].asBool();
354 }
355 return ret;
356 }
357
358 // Default implementation returns false, since it is based on
359 // the NDR308, which does not support selectable-source WBDDCs.
360 bool WbddcComponent::executeSourceCommand(int index, int& source)
361 {
362 bool ret = false;
363 if ( (_parent != NULL) && (_parent->isConnected()) )
364 {
365 Json::Value root(Json::objectValue);
366 root["msg"] = m551Parent->getMessageId();
367 root["cmd"] = "wbddc";
368 Json::Value params(Json::objectValue);
369 params["id"] = index;
370
371 params["rfch"] = std::to_string(source);
372 root["params"] = params;
373 Json::FastWriter fastWriter;
374 std::string output = fastWriter.write(root);
375 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
376 Json::Reader reader;
377 Json::Value returnVal;
378 std::string t = recv.at(0);
379 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
380 ret = returnVal["success"].asBool();
381 }
382 return ret;
383 }
384 // Default implementation returns false, since it is based on
385 // the NDR308, which does not support tunable WBDDCs.
386 bool WbddcComponent::executeFreqCommand(int index, double& freq)
387 {
388 bool ret = false;
389 if ( (_parent != NULL) && (_parent->isConnected()) )
390 {
391 Json::Value root(Json::objectValue);
392 root["msg"] = m551Parent->getMessageId();
393 root["cmd"] = "wbddc";
394 Json::Value params(Json::objectValue);
395 params["id"] = index;
396 params["offset"] = freq;
397 root["params"] = params;
398 Json::FastWriter fastWriter;
399 std::string output = fastWriter.write(root);
400 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
401 Json::Reader reader;
402 Json::Value returnVal;
403 std::string t = recv.at(0);
404 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
405 ret = returnVal["success"].asBool();
406 }
407 return ret;
408 }
409
410 // Default implementation uses the NDR308 syntax.
411 // WBDDC <index>, <rate index>, <udp dest>, <enable>, <vita enable>, <stream id>
412 bool WbddcComponent::executeWbddcCommand(int index, int& rateIndex,
413 int& udpDestination, bool& enabled, int& vitaEnable,
414 unsigned int& streamId)
415 {
416 bool ret = false;
417 if ( (_parent != NULL) && (_parent->isConnected()) )
418 {
419 Json::Value root(Json::objectValue);
420 root["msg"] = m551Parent->getMessageId();
421 root["cmd"] = "wbddc";
422 Json::Value params(Json::objectValue);
423 params["id"] = index;
424 params["filter"] = rateIndex;
425 params["dest"] = udpDestination;
426 params["enable"] = boost::lexical_cast<bool>(enabled);
427 params["vita"] = streamId;
428 root["params"] = params;
429 Json::FastWriter fastWriter;
430 std::string output = fastWriter.write(root);
431 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
432 Json::Reader reader;
433 Json::Value returnVal;
434 std::string t = recv.at(0);
435 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
436 ret = returnVal["success"].asBool();
437 }
438 return ret;
439 }
440
442 {
443 bool ret = false;
444 if ( _config.hasKey("filter") )
445 {
446 int adjRateIndex = index;
447 int adjUdpDest = _udpDestination;
448 int adjVita = _vitaEnable;
449 unsigned int adjStream = _streamId;
450 bool adjEnabled = _enabled;
451 ret = executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
452 if ( ret )
453 {
454 _rateIndex = adjRateIndex;
456 }
457 }
458 return ret;
459 }
460
462 {
463 bool ret = false;
464 if ( _tunable && _config.hasKey("offset") )
465 {
466 double adjFreq = freq;
467 ret = executeFreqCommand(_index, adjFreq);
468 if ( ret )
469 {
470 _frequency = adjFreq;
472 }
473 }
474 return ret;
475 }
476
478 {
479 bool ret = false;
480 if ( _config.hasKey("rfch") )
481 {
482 int adjSource = source;
483 ret = executeSourceCommand(_index, adjSource);
484 if ( ret )
485 {
486 _source = adjSource;
488 }
489 }
490 return ret;
491 }
492
494 {
495 bool ret = false;
496 if ( _config.hasKey("dest") )
497 {
498 int adjRateIndex = _rateIndex;
499 int adjUdpDest = dest;
500 int adjVita = _vitaEnable;
501 unsigned int adjStream = _streamId;
502 bool adjEnabled = _enabled;
503 ret = executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
504 if ( ret )
505 {
506 _udpDestination = adjUdpDest;
508 }
509 }
510 return ret;
511 }
512
513 } /* namespace NDR551 */
514
515 } // namespace Driver
516
517} // namespace LibCyberRadio
518
virtual int debug(const char *format,...)
Outputs debug information.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
virtual bool setConfigurationValueToUInt(const std::string &key, const unsigned int value)
Sets a named configuration value to an unsigned integer value.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
A configuration dictionary.
bool executeFreqCommand(int index, double &freq) override
Executes the WBDDC frequency set command.
bool setRateIndex(int index) override
Sets the WBDDC's rate index.
bool executeWbddcCommand(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId) override
Executes the WBDDC configuration set command.
virtual WbddcComponent & operator=(const WbddcComponent &other)
Assignment operator for WbddcComponent objects.
virtual bool setConfiguration(ConfigurationDict &cfg) override
Sets the configuration dictionary for this component.
bool setSource(int source) override
Sets the WBDDC's source (which tuner is supplying the signal).
bool setUdpDestination(int dest) override
Sets the WBDDC's UDP destination.
bool executeWbddcQuery(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId)
Execute a JSON wbddc Query.
void queryConfiguration() override
Tells the component to query its hardware configuration in order to create its configuration dictiona...
bool setFrequency(double freq) override
Sets the WBDDC tuned frequency.
WbddcComponent(int index=1, ::LibCyberRadio::Driver::RadioHandler *parent=NULL, bool debug=false, int dataPort=1, int rateIndex=0, int udpDestination=0, int vitaEnable=0, int streamId=0)
Constructs a WbddcComponent object.
void initConfigurationDict() override
Setup Config Dict.
bool executeSourceCommand(int index, int &source) override
Executes the WBDDC source set command.
bool executeDataPortCommand(int index, int &dataPort) override
Executes the WBDDC data port set command.
virtual ~WbddcComponent()
Destroys a WbddcComponent object.
virtual void updateConfigurationDict() override
Updates the configuration dictionary from component settings.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Generic radio handler class.
Provides programming elements for driving NDR551 radios.
Definition DataPort.h:36
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
Definition App.h:24
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition BasicList.h:25