libcyberradio 22.01.24
WbddcComponent.cpp
1/***************************************************************************
2 * \file WbddcComponent.cpp
3 * \brief Defines the WBDDC interface for the NDR324.
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/NDR324/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 NDR324
25 {
26
29 bool debug,
30 int dataPort,
31 int rateIndex,
32 int udpDestination,
33 int vitaEnable,
34 int streamId) :
35 m324Parent( parent ),
37 /* const std::string& name */ (boost::format("NDR324-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("[NDR324::WbddcComponent] index - %d\n", index);
59
61 // Set rate set
62 _rateSet[0] = 225.28e6;
63 _rateSet[1] = 168.96e6;
64 _rateSet[2] = 42.24e6;
65 _rateSet[3] = 21.12e6;
66 _rateSet[4] = 10.56e6;
67 _rateSet[5] = 660e3;
68 }
69
74
79
81 {
82 ::LibCyberRadio::Driver::WbddcComponent::operator=(other);
83 if ( this != &other )
84 {
85 }
86 return *this;
87 }
88
90 {
91 //this->debug("[WbddcComponent::initConfigurationDict] Called\n");
92 _config.clear();
93 // Call the base-class version
95 // Define tuner-specific keys
96 _config["filter"] = 40;
97 _config["dest"] = 0;
98 _config["enable"] = false;
99 _config["vita"] = 0;
100 _config["type"] = "auto";
101 _config["decimation"] = _decimation;
102 _config["ovs"] = 1;
103 _config["mode"] = _mode;
104 _config["dgv"] = _dgv;
105 _config["dul"] = _dul;
106 _config["dll"] = _dll;
107 _config["dtl"] = _dtl;
108 _config["dal"] = _dal;
109 _config["ddl"] = _ddl;
110 _config["dao"] = _dao;
111 _config["ddo"] = _ddo;
112 _config["datc"] = _datc;
113 _config["ddtc"] = _ddtc;
114 _config["ddt"] = 90;
115 if ( _tunable )
116 {
117 _config["offset"] = 0.0f;
118 }
119 if ( _selectableSource )
120 {
121 _config["rfch"] = "0";
122 }
123 if ( _selectableDataPort )
124 {
125 _config["link"] = 0;
126 }
127 //this->debug("[WbddcComponent::initConfigurationDict] Returning\n");
128 }
129
131 {
132 bool ret = false;
133 this->debug("[NDR324WbddcComponent::setConfiguration] Called\n");
134 // Setup the JSON Command.
135 Json::Value command;
136 Json::Value params;
137 command["cmd"] = "wbddc";
138 command["msg"] = _parent->getMessageId();
139 command["params"] = Json::objectValue;
140 command["params"]["id"] = _index;
141
142 for( ConfigurationDict::const_iterator it = cfg.begin();
143 it != cfg.end(); ++it)
144 {
145 if ( (it->first == "mode") ||
146 (it->first == "rfch") ||
147 (it->first == "type") )
148 {
149 command["params"][it->first.c_str()] = it->second.c_str();
150 }
151 else if ( (it->first == "enable") )
152 {
153 command["params"][it->first.c_str()] = it->second.asBool();
154 }
155 else
156 {
157 command["params"][it->first.c_str()] = it->second.asInt();
158 }
159 }
160 Json::FastWriter fastWriter;
161 std::string output = fastWriter.write(command);
162 std::cout << output << std::endl;
163 BasicStringList rsp = _parent->sendCommand(output);
164 Json::Reader reader;
165 Json::Value returnVal;
166 std::string t = rsp.at(0);
167 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
168 ret = returnVal["success"].asBool();
169 return ret;
170 }
171
173 {
174 this->debug("[NDR324WbddcComponent::updateConfigurationDict] Called\n");
176 if ( _config.hasKey("filter") )
177 setConfigurationValueToInt("filter", _rateIndex);
178 if ( _config.hasKey("dest") )
179 setConfigurationValueToInt("dest", _udpDestination);
180 if ( _config.hasKey("enable") )
181 setConfigurationValueToInt("enable", _vitaEnable);
182 if ( _config.hasKey("vita") )
183 setConfigurationValueToUInt("vita", _streamId);
184 if ( _tunable && _config.hasKey("offset") )
185 {
186 setConfigurationValueToDbl("offset", _frequency);
187 }
188 if ( _selectableSource && _config.hasKey("rfch") )
189 {
190 setConfigurationValueToInt("rfch", _source);
191 }
192 if ( _selectableDataPort && _config.hasKey("link") )
193 {
194 setConfigurationValueToInt("link", _dataPort);
195 }
196 if ( _config.hasKey("mode") )
197 {
198 setConfigurationValue("mode", _mode);
199 }
200 if ( _config.hasKey("decimation") )
201 {
202 setConfigurationValueToInt("decimation", _decimation);
203 }
204 if ( _config.hasKey("dgv" ) )
205 {
206 setConfigurationValueToInt("dgv", _dgv);
207 }
208 if ( _config.hasKey("dul" ) )
209 {
210 setConfigurationValueToInt("dul", _dul);
211 }
212 if ( _config.hasKey("dll" ) )
213 {
214 setConfigurationValueToInt("dll", _dll);
215 }
216 if ( _config.hasKey("dtl" ) )
217 {
218 setConfigurationValueToInt("dtl", _dtl);
219 }
220 if ( _config.hasKey("dal" ) )
221 {
222 setConfigurationValueToInt("dal", _dal);
223 }
224 if ( _config.hasKey("ddl" ) )
225 {
226 setConfigurationValueToInt("ddl", _ddl);
227 }
228 if ( _config.hasKey("dao" ) )
229 {
230 setConfigurationValueToInt("dao", _dao);
231 }
232 if ( _config.hasKey("ddo" ) )
233 {
234 setConfigurationValueToInt("ddo", _ddo);
235 }
236 if ( _config.hasKey("datc") )
237 {
238 setConfigurationValueToInt("datc", _datc);
239 }
240 if ( _config.hasKey("ddtc") )
241 {
242 setConfigurationValueToInt("ddtc", _ddtc);
243 }
244 if ( _config.hasKey("ddt" ) )
245 {
246 setConfigurationValueToInt("ddt", _ddt);
247 }
248 if ( _config.hasKey("type") )
249 {
250 setConfigurationValue("type", _type);
251 }
252 }
253
255 {
256 this->debug("[WbddcComponent::queryConfiguration] Called\n");
257 Json::Value command;
258 Json::Value params;
259 command["cmd"] = "qwbddc";
260 command["msg"] = _parent->getMessageId();
261 command["params"] = Json::objectValue;
262 command["params"]["id"] = _index;
263 Json::FastWriter fastWriter;
264 std::string output = fastWriter.write(command);
265 BasicStringList rsp = _parent->sendCommand(output);
266 Json::Reader reader;
267 Json::Value returnVal;
268 std::string t = rsp.at(0);
269 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
270 _enabled = boost::lexical_cast<bool>(returnVal["result"]["enable"].asBool());
271 _frequency = boost::lexical_cast<double>(returnVal["result"]["offset"].asDouble());
272 _source = boost::lexical_cast<int>(returnVal["result"]["rfch"].asInt());
273 _dataPort = boost::lexical_cast<int>(returnVal["result"]["link"].asInt());
274 _udpDestination = boost::lexical_cast<int>(returnVal["result"]["dest"].asInt());
275 _rateIndex = boost::lexical_cast<int>(returnVal["result"]["filter"].asInt());
276 _streamId = boost::lexical_cast<int>(returnVal["result"]["vita"].asUInt());
277 _ovs = boost::lexical_cast<int>(returnVal["result"]["ovs"].asInt());
278 _decimation = boost::lexical_cast<int>(returnVal["result"]["decimation"].asInt());
279 _type = boost::lexical_cast<std::string>(returnVal["result"]["type"].asString());
280 _mode = boost::lexical_cast<std::string>(returnVal["result"]["mode"].asString());
281 _dgv = boost::lexical_cast<int>(returnVal["result"]["dgv"].asInt());
282 _dul = boost::lexical_cast<int>(returnVal["result"]["dul"].asInt());
283 _dll = boost::lexical_cast<int>(returnVal["result"]["dll"].asInt());
284 _dtl = boost::lexical_cast<int>(returnVal["result"]["dtl"].asInt());
285 _dal = boost::lexical_cast<int>(returnVal["result"]["dal"].asInt());
286 _ddl = boost::lexical_cast<int>(returnVal["result"]["ddl"].asInt());
287 _dao = boost::lexical_cast<int>(returnVal["result"]["dao"].asInt());
288 _ddo = boost::lexical_cast<int>(returnVal["result"]["ddo"].asInt());
289 _datc = boost::lexical_cast<int>(returnVal["result"]["datc"].asInt());
290 _ddtc = boost::lexical_cast<int>(returnVal["result"]["ddtc"].asInt());
291 _dat = boost::lexical_cast<int>(returnVal["result"]["dat"].asInt());
292 _ddt = boost::lexical_cast<int>(returnVal["result"]["ddt"].asInt());
294 this->debug("[WbddcComponent::queryConfiguration] Returning\n");
295 }
296
301 bool WbddcComponent::executeWbddcQuery(int index, int& rateIndex,
302 int& udpDestination, bool& enabled, int& vitaEnable,
303 unsigned int& streamId)
304 {
305 bool ret = false;
306 if ( (_parent != NULL) && (_parent->isConnected()) )
307 {
308 Json::Value root(Json::objectValue);
309 root["msg"] = m324Parent->getMessageId();
310 root["cmd"] = "qwbddc";
311 Json::Value params(Json::objectValue);
312 params["id"] = index;
313 root["params"] = params;
314 Json::FastWriter fastWriter;
315 std::string output = fastWriter.write(root);
316 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
317 Json::Reader reader;
318 Json::Value returnVal;
319 std::string t = recv.at(0);
320 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
321 Json::Value result = returnVal["result"];
322 rateIndex = boost::lexical_cast<int>(result["filter"].asInt());
323 udpDestination = boost::lexical_cast<int>(result["dest"].asInt());
324 enabled = boost::lexical_cast<int>(result["enable"].asBool());
325 vitaEnable = boost::lexical_cast<int>(result["enable"].asBool());
326 streamId = boost::lexical_cast<unsigned int>(result["vita"].asUInt());
327 }
328 return ret;
329 }
330
331 bool WbddcComponent::executeDataPortCommand(int index, int& dataPort)
332 {
333 bool ret = false;
334 if ( (_parent != NULL) && (_parent->isConnected()) )
335 {
336 Json::Value root(Json::objectValue);
337 root["msg"] = m324Parent->getMessageId();
338 root["cmd"] = "wbddc";
339 Json::Value params(Json::objectValue);
340 params["id"] = index;
341 params["link"] = dataPort;
342 root["params"] = params;
343 Json::FastWriter fastWriter;
344 std::string output = fastWriter.write(root);
345 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
346 Json::Reader reader;
347 Json::Value returnVal;
348 std::string t = recv.at(0);
349 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
350 ret = returnVal["success"].asBool();
351 }
352 return ret;
353 }
354
355 // Default implementation returns false, since it is based on
356 // the NDR308, which does not support selectable-source WBDDCs.
357 bool WbddcComponent::executeSourceCommand(int index, int& source)
358 {
359 bool ret = false;
360 if ( (_parent != NULL) && (_parent->isConnected()) )
361 {
362 Json::Value root(Json::objectValue);
363 root["msg"] = m324Parent->getMessageId();
364 root["cmd"] = "wbddc";
365 Json::Value params(Json::objectValue);
366 params["id"] = index;
367
368 params["rfch"] = source;
369 root["params"] = params;
370 Json::FastWriter fastWriter;
371 std::string output = fastWriter.write(root);
372 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
373 Json::Reader reader;
374 Json::Value returnVal;
375 std::string t = recv.at(0);
376 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
377 ret = returnVal["success"].asBool();
378 }
379 return ret;
380 }
381 // Default implementation returns false, since it is based on
382 // the NDR308, which does not support tunable WBDDCs.
383 bool WbddcComponent::executeFreqCommand(int index, double& freq)
384 {
385 bool ret = false;
386 if ( (_parent != NULL) && (_parent->isConnected()) )
387 {
388 Json::Value root(Json::objectValue);
389 root["msg"] = m324Parent->getMessageId();
390 root["cmd"] = "wbddc";
391 Json::Value params(Json::objectValue);
392 params["id"] = index;
393 params["offset"] = freq;
394 root["params"] = params;
395 Json::FastWriter fastWriter;
396 std::string output = fastWriter.write(root);
397 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
398 Json::Reader reader;
399 Json::Value returnVal;
400 std::string t = recv.at(0);
401 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
402 ret = returnVal["success"].asBool();
403 }
404 return ret;
405 }
406
407 // Default implementation uses the NDR308 syntax.
408 // WBDDC <index>, <rate index>, <udp dest>, <enable>, <vita enable>, <stream id>
409 bool WbddcComponent::executeWbddcCommand(int index, int& rateIndex,
410 int& udpDestination, bool& enabled, int& vitaEnable,
411 unsigned int& streamId)
412 {
413 bool ret = false;
414 if ( (_parent != NULL) && (_parent->isConnected()) )
415 {
416 Json::Value root(Json::objectValue);
417 root["msg"] = m324Parent->getMessageId();
418 root["cmd"] = "wbddc";
419 Json::Value params(Json::objectValue);
420 params["id"] = index;
421 params["filter"] = rateIndex;
422 params["dest"] = udpDestination;
423 params["enable"] = boost::lexical_cast<bool>(enabled);
424 params["vita"] = streamId;
425 root["params"] = params;
426 Json::FastWriter fastWriter;
427 std::string output = fastWriter.write(root);
428 this->debug("CMD: %s\n", output.c_str());
429 LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
430 Json::Reader reader;
431 Json::Value returnVal;
432 std::string t = recv.at(0);
433 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
434 ret = returnVal["success"].asBool();
435 }
436 return ret;
437 }
438
440 {
441 this->debug("Index: %d\n", index);
442 bool ret = false;
443 if ( _config.hasKey("filter") )
444 {
445 int adjRateIndex = index;
446 int adjUdpDest = _udpDestination;
447 int adjVita = _vitaEnable;
448 unsigned int adjStream = _streamId;
449 bool adjEnabled = _enabled;
450 this->debug("Index: %d\n", index);
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 NDR324 */
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.
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