libcyberradio  22.01.24
NbddcComponent.cpp
1 /***************************************************************************
2  * \file NbddcComponent.cpp
3  * \brief Defines the NBDDC 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/NbddcComponent.h"
12 #include "LibCyberRadio/Driver/RadioHandler.h"
13 #include <boost/format.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <json/json.h>
16 
17 namespace LibCyberRadio
18 {
19 
20  namespace Driver
21  {
22 
23  namespace NDR551
24  {
25 
28  bool debug,
29  int dataPort,
30  int rateIndex,
31  int udpDestination,
32  int vitaEnable,
33  int streamId,
34  double frequency,
35  int source) :
36  m551Parent( parent ),
37  ::LibCyberRadio::Driver::NbddcComponent(
38  /* const std::string& name */ (boost::format("NDR551-NBDDC%02d") % \
39  index).str(),
40  /* int index */ index,
41  /* ::LibCyberRadio::Driver::RadioHandler* parent */ parent,
42  /* bool debug */ debug,
43  /* bool nbddcCommandSetsFreq */ true,
44  /* bool nbddcCommandSetsSource */ true,
45  /* bool selectableDataPort */ false,
46  /* double freqRangeMin */ -64.0e6,
47  /* double freqRangeMax */ 64.0e6,
48  /* double freqRes */ 1.0,
49  /* double freqUnits */ 1.0,
50  /* int source */ source,
51  /* int dataPort */ dataPort,
52  /* double frequency */ frequency,
53  /* int rateIndex */ rateIndex,
54  /* int udpDestination */ udpDestination,
55  /* int vitaEnable */ vitaEnable,
56  /* unsigned int streamId */ streamId)
57  {
59  _rateSet[15] = 4.0e6;
60  _rateSet[14] = 3.2e6;
61  _rateSet[13] = 1.28e6;
62  _rateSet[12] = 400e3;
63  _rateSet[11] = 256e3;
64  _rateSet[10] = 200e3;
65  _rateSet[9] = 128e3;
66  _rateSet[8] = 64e3;
67  _rateSet[7] = 32e3;
68  _rateSet[6] = 16e3;
69  _rateSet[5] = 8.0e3;
70  _rateSet[4] = 4.0e3;
71  _rateSet[3] = 2.0e3;
72  _rateSet[2] = 1.0e3;
73  _rateSet[1] = 0.5e3;
74  _rateSet[0] = 0.25e3;
75  }
76 
78  {
79  }
80 
82  ::LibCyberRadio::Driver::NbddcComponent(other)
83  {
84  }
85 
87  {
88  ::LibCyberRadio::Driver::NbddcComponent::operator=(other);
89  if ( this != &other )
90  {
91  }
92  return *this;
93  }
94 
96  {
97  //this->debug("[NbddcComponent::initConfigurationDict] Called\n");
98  _config.clear();
99  // Call the base-class version
101  // Define tuner-specific keys
102  _config["rateIndex"] = _rateIndex;
103  _config["udpDestination"] = _udpDestination;
104  _config["vitaEnable"] = _vitaEnable;
105  _config["streamId"] = _streamId;
106  _config["frequency"] = _frequency;
107  _config["source"] = _source;
108  _config["mode"] = _mode;
109  _config["audio" ] = false;
110  _config["bfo" ] = 0;
111  _config["cic0" ] = 0;
112  _config["cic1" ] = 0;
113  _config["dal" ] = 0;
114  _config["dao" ] = 0;
115  _config["dat" ] = 0;
116  _config["datc" ] = 0;
117  _config["ddl" ] = 0;
118  _config["ddo" ] = 0;
119  _config["ddt" ] = 0;
120  _config["ddtc" ] = 0;
121  _config["demod" ] = "none";
122  _config["dest" ] = 0;
123  _config["dgv" ] = 0;
124  _config["dll" ] = 0;
125  _config["dmdgain"] = 0;
126  _config["dtl" ] = 0;
127  _config["dul" ] = 0;
128  _config["ovs" ] = 0;
129  //this->debug("[NbddcComponent::initConfigurationDict] Returning\n");
130  }
131 
133  {
134  this->debug("[NbddcComponent::updateConfigurationDict] Called\n");
136  if ( _config.hasKey("rateIndex") )
137  setConfigurationValueToInt("rateIndex", _rateIndex);
138  if ( _config.hasKey("udpDestination") )
139  setConfigurationValueToInt("udpDestination", _udpDestination);
140  if ( _config.hasKey("vitaEnable") )
141  setConfigurationValueToInt("vitaEnable", _vitaEnable);
142  if ( _config.hasKey("streamId") )
143  setConfigurationValueToUInt("streamId", _streamId);
144  if ( _config.hasKey("frequency") )
145  setConfigurationValueToDbl("frequency", _frequency);
146  if ( _config.hasKey("source") )
147  setConfigurationValueToInt("source", _source);
148  if ( _config.hasKey("mode") ){
149  setConfigurationValue("mode", _mode);
150  }
151  if ( _selectableDataPort && _config.hasKey("dataPort") )
152  {
153  setConfigurationValueToInt("dataPort", _dataPort);
154  }
155  this->debug("[NbddcComponent::updateConfigurationDict] Returning\n");
156  }
157 
159  {
160  this->debug("[NbddcComponent::queryConfiguration] Called\n");
161  Json::Value command;
162  Json::Value params;
163  command["cmd"] = "qnbddc";
164  command["msg"] = _parent->getMessageId();
165  command["params"] = Json::objectValue;
166  command["params"]["id"] = _index;
167  Json::FastWriter fastWriter;
168  std::string output = fastWriter.write(command);
169  BasicStringList rsp = _parent->sendCommand(output);
170  Json::Reader reader;
171  Json::Value returnVal;
172  std::string t = rsp.at(0);
173  bool parsingSuccessful = reader.parse( t.c_str(), returnVal["result"] ); //parse process
174  _enabled = boost::lexical_cast<bool>(returnVal["enable"].asBool());
175  _frequency = boost::lexical_cast<double>(returnVal["freq"].asDouble());
176  _source = boost::lexical_cast<int>(returnVal["source"].asInt());
177  _udpDestination = boost::lexical_cast<int>(returnVal["dest"].asInt());
178  _rateIndex = boost::lexical_cast<int>(returnVal["filter"].asInt());
179  _streamId = boost::lexical_cast<int>(returnVal["vita"].asUInt());
180  _mode = boost::lexical_cast<std::string>(returnVal["mode"].asString());
181  }
182 
183  // Default implementation uses the NDR308 syntax.
184  // WBDDC? <index>
186  int& rateIndex,
187  int& udpDestination,
188  bool& enabled,
189  int& vitaEnable,
190  unsigned int& streamId,
191  double& frequency,
192  int& source)
193  {
194  bool ret = false;
195  if ( (_parent != NULL) && (_parent->isConnected()) )
196  {
197  Json::Value root(Json::objectValue);
198  root["msg"] = _parent->getMessageId();
199  root["cmd"] = "qnbddc";
200  Json::Value params(Json::objectValue);
201  params["id"] = index;
202  root["params"] = params;
203  Json::FastWriter fastWriter;
204  std::string output = fastWriter.write(root);
205  LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
206  Json::Reader reader;
207  Json::Value returnVal;
208  std::string t = recv.at(0);
209  bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
210  Json::Value result = returnVal["result"];
211  rateIndex = boost::lexical_cast<int>(result["filter"].asInt());
212  udpDestination = boost::lexical_cast<int>(result["dest"].asInt());
213  enabled = boost::lexical_cast<bool>(result["enable"].asBool());
214  vitaEnable = boost::lexical_cast<int>(result["enable"].asBool());
215  streamId = boost::lexical_cast<unsigned int>(result["vita"].asUInt());
216  }
217  return ret;
218  }
219 
220  // Default implementation returns false, since it is based on
221  // the NDR308, which does not support selectable-source WBDDCs.
222  bool NbddcComponent::executeSourceCommand(int index, int& source)
223  {
224  bool ret = false;
225  if ( (_parent != NULL) && (_parent->isConnected()) )
226  {
227  Json::Value root(Json::objectValue);
228  root["msg"] = m551Parent->getMessageId();
229  root["cmd"] = "nbddc";
230  Json::Value params(Json::objectValue);
231  params["id"] = index;
232  params["rfch"] = std::to_string(source);
233  root["params"] = params;
234  Json::FastWriter fastWriter;
235  std::string output = fastWriter.write(root);
236  LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
237  Json::Reader reader;
238  Json::Value returnVal;
239  std::string t = recv.at(0);
240  bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
241  ret = returnVal["success"].asBool();
242  }
243  return ret;
244  }
245 
246  // Default implementation returns false, since it is based on
247  // the NDR308, which does not support tunable WBDDCs.
248  bool NbddcComponent::executeFreqCommand(int index, double& freq)
249  {
250  bool ret = false;
251  if ( (_parent != NULL) && (_parent->isConnected()) )
252  {
253  Json::Value root(Json::objectValue);
254  root["msg"] = m551Parent->getMessageId();
255  root["cmd"] = "nbddc";
256  Json::Value params(Json::objectValue);
257  params["id"] = index;
258  params["offset"] = freq;
259  root["params"] = params;
260  Json::FastWriter fastWriter;
261  std::string output = fastWriter.write(root);
262  LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
263  Json::Reader reader;
264  Json::Value returnVal;
265  std::string t = recv.at(0);
266  bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
267  ret = returnVal["success"].asBool();
268  }
269  return ret;
270  }
271 
272  // Default implementation uses the NDR308 syntax.
273  // WBDDC <index>, <rate index>, <udp dest>, <enable>, <vita enable>, <stream id>
275  int& rateIndex,
276  int& udpDestination,
277  bool& enabled,
278  int& vitaEnable,
279  unsigned int& streamId,
280  double& frequency,
281  int& source)
282  {
283  bool ret = false;
284  if ( (_parent != NULL) && (_parent->isConnected()) )
285  {
286  Json::Value root(Json::objectValue);
287  root["msg"] = _parent->getMessageId();
288  root["cmd"] = "nbddc";
289  Json::Value params(Json::objectValue);
290  params["id"] = index;
291  params["filter"] = rateIndex;
292  params["dest"] = udpDestination;
293  params["enable"] = boost::lexical_cast<bool>(vitaEnable);
294  params["vita"] = streamId;
295  params["rfch"] = std::to_string(source);
296  root["params"] = params;
297  Json::FastWriter fastWriter;
298  std::string output = fastWriter.write(root);
299  LibCyberRadio::BasicStringList recv = _parent->sendCommand(output,1.0);
300  Json::Reader reader;
301  Json::Value returnVal;
302  std::string t = recv.at(0);
303  bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
304  ret = returnVal["success"].asBool();
305  }
306  return ret;
307  }
308 
309  } /* namespace NDR551 */
310 
311  } // namespace Driver
312 
313 } // namespace LibCyberRadio
314 
void updateConfigurationDict() override
Updates the configuration dictionary from component settings.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
bool executeFreqCommand(int index, double &freq) override
Executes the NBDDC frequency set command.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
bool executeSourceCommand(int index, int &source) override
Executes the NBDDC source set command.
void initConfigurationDict() override
Setup Config Dict.
NBDDC component class for the NDR551.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual bool setConfigurationValueToUInt(const std::string &key, const unsigned int value)
Sets a named configuration value to an unsigned integer value.
Generic radio handler class.
Definition: RadioHandler.h:54
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition: BasicList.h:25
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
bool executeNbddcCommand(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId, double &frequency, int &source) override
Executes the NBDDC configuration set command.
void queryConfiguration() override
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
bool executeNbddcQuery(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId, double &frequency, int &source) override
Executes the NBDDC configuration query command.
virtual ~NbddcComponent()
Destroys a NbddcComponent object.
virtual uint32_t getMessageId(void)
Get a json Message ID.
virtual NbddcComponent & operator=(const NbddcComponent &other)
Assignment operator for NbddcComponent objects.
NbddcComponent(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, double frequency=0.0, int source=1)
Constructs a NbddcComponent object.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.