libcyberradio 22.01.24
TunerComponent.cpp
1/***************************************************************************
2 * \file TunerComponent.cpp
3 * \brief Defines the tuner 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/TunerComponent.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include <boost/format.hpp>
14#include <boost/lexical_cast.hpp>
15#include <json/json.h>
16
17namespace LibCyberRadio
18{
19 namespace Driver
20 {
21
22 namespace NDR324
23 {
24
27 bool debug,
28 double frequency,
29 double attenuation,
30 int filter) :
32 /* const std::string& name */ (boost::format("NDR324-TUNER%02d") % \
33 index).str(),
34 /* int index */ index,
35 /* ::LibCyberRadio::Driver::RadioHandler* parent */ parent,
36 /* bool debug */ debug,
37 /* double freqRangeMin */ 20e6,
38 /* double freqRangeMax */ 6000e6,
39 /* double freqRes */ 10e6,
40 /* double freqUnits */ 1e6,
41 /* double attRangeMin */ 0.0,
42 /* double attRangeMax */ 40.0,
43 /* double attRes */ 1.0,
44 /* bool agc */ true,
45 /* double frequency */ frequency,
46 /* double attenuation */ attenuation,
47 /* int filter */ filter)
48 {
49 this->debug("[NDR324::TunerComponent] index - %d\n", index);
51 }
52
54 {
55 this->debug("[TunerComponent::updateConfigurationDict] Called\n");
57 bool res;
58 if ( _config.hasKey("frequency") )
59 {
60 res = setConfigurationValueToDbl("frequency", _frequency);
61 }
62 if ( _config.hasKey("attenuation") )
63 {
64 res = setConfigurationValueToDbl("attenuation", _attenuation);
65 }
66 if ( _config.hasKey("filter") )
67 {
68 res = setConfigurationValueToInt("filter", _filter);
69 }
70 if ( _config.hasKey("timingAdj") )
71 {
72 res = setConfigurationValueToInt("timingAdj", _timingAdj);
73 }
74 if ( _config.hasKey("if") )
75 {
76 res = setConfigurationValueToUInt("if", _if);
77 }
78 if ( _config.hasKey("mode") )
79 {
80 setConfigurationValue("mode", _mode);
81 }
82 this->debug("[TunerComponent::updateConfigurationDict] Current configuration\n");
83 this->dumpConfiguration();
84 this->debug("[TunerComponent::updateConfigurationDict] Returning\n");
85 }
86
88 {
89 this->debug("[TunerComponent::setConfiguration] Called\n");
90 // Call the base-class version to modify the configuration dictionary
91 // (this including any enabling/disabling)
93 // Use the keys provided in the *incoming* dictionary to determine
94 // what needs to be changed via hardware calls.
95 double adjFrequency = _frequency;
96 double adjAttenuation = _attenuation;
97 int adjFilter = _filter;
98 int adjAdj = _timingAdj;
99 unsigned int adjIf = _if;
100 bool freqCmdNeedsExecuting = false;
101 bool attCmdNeedsExecuting = false;
102 bool filCmdNeedsExecuting = false;
103 bool adjCmdNeedsExecuting = false;
104 bool ifCmdNeedsExecuting = false;
105 if ( cfg.hasKey("frequency") && _config.hasKey("frequency") )
106 {
107 adjFrequency = getConfigurationValueAsDbl("frequency");
108 freqCmdNeedsExecuting = true;
109 }
110 if ( cfg.hasKey("attenuation") && _config.hasKey("attenuation") )
111 {
112 adjAttenuation = getConfigurationValueAsDbl("attenuation");
113 attCmdNeedsExecuting = true;
114 }
115 if ( cfg.hasKey("filter") && _config.hasKey("filter") )
116 {
117 adjFilter = getConfigurationValueAsInt("filter");
118 filCmdNeedsExecuting = true;
119 }
120 if ( cfg.hasKey("timingAdj") && _config.hasKey("timingAdj") )
121 {
122 adjAdj = getConfigurationValueAsInt("timingAdj");
123 adjCmdNeedsExecuting = true;
124 }
125 if ( cfg.hasKey("if") && _config.hasKey("if") )
126 {
127 _if = getConfigurationValueAsInt("if");
128 ifCmdNeedsExecuting = true;
129 }
130 if ( freqCmdNeedsExecuting )
131 {
132 ret &= executeFreqCommand(_index, adjFrequency);
133 }
134 if ( attCmdNeedsExecuting )
135 {
136 ret &= executeAttenCommand(_index, adjAttenuation);
137 }
138 if ( filCmdNeedsExecuting )
139 {
140 ret &= executeFilterCommand(_index, adjFilter);
141 }
142 if ( adjCmdNeedsExecuting )
143 {
144 ret &= executeTimingAdjustmentCommand(_index, adjAdj);
145 }
146 if ( ifCmdNeedsExecuting )
147 {
148 ret &= executeCommand();
149 }
150 this->debug("[TunerComponent::setConfiguration] Returning %s\n", debugBool(ret));
151 return ret;
152 }
153
155 {
156 _config.clear();
157 _config["enable"] = "";
158 _config["frequency"] = "";
159 _config["attenuation"] = "";
160 _config["mode"] = "auto";
161 _config["if"] = "80";
162
163 }
164
168
173
175 {
176 ::LibCyberRadio::Driver::TunerComponent::operator=(other);
177 if ( this != &other )
178 {
179 }
180 return *this;
181 }
182
183 bool TunerComponent::executeFreqCommand(int index, double& freq)
184 {
185 bool ret = false;
186 if ( (_parent != NULL) && (_parent->isConnected()) )
187 {
188 Json::Value command;
189 Json::Value params;
190 command["cmd"] = "tuner";
191 command["msg"] = _parent->getMessageId();
192 command["params"] = Json::objectValue;
193 command["params"]["id"] = index;
194 command["params"]["freq"] = freq;
195 Json::FastWriter fastWriter;
196 std::string output = fastWriter.write(command);
197 BasicStringList rsp = _parent->sendCommand(output);
198 Json::Reader reader;
199 Json::Value returnVal;
200 std::string t = rsp.at(0);
201 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
202 ret = true;
204 //ret = boost::lexical_cast<bool>(result["success"]);
205 }
206 return ret;
207 }
208
210 {
211 this->debug("[TunerComponent::queryConfiguration] Called\n");
212 Json::Value command;
213 Json::Value params;
214 command["cmd"] = "qtuner";
215 command["msg"] = _parent->getMessageId();
216 command["params"] = Json::objectValue;
217 command["params"]["id"] = _index;
218 Json::FastWriter fastWriter;
219 std::string output = fastWriter.write(command);
220 BasicStringList rsp = _parent->sendCommand(output);
221 Json::Reader reader;
222 Json::Value returnVal;
223 std::string t = rsp.at(0);
224 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
225 _enabled = boost::lexical_cast<bool>(returnVal["result"]["enable"].asBool());
226 _frequency = boost::lexical_cast<double>(returnVal["result"]["freq"].asDouble());
227 _attenuation = boost::lexical_cast<double>(returnVal["result"]["atten"].asDouble());
228 _mode = boost::lexical_cast<std::string>(returnVal["result"]["mode"].asString());
229 _if = boost::lexical_cast<unsigned int>(returnVal["result"]["if"].asUInt());
231 this->debug("[NDR324] [TunerComponent::queryConfiguration] Returning\n");
232 }
233
234 bool TunerComponent::executeEnableCommand(int index, bool& enabled)
235 {
236 bool ret = false;
237 if ( (_parent != NULL) && (_parent->isConnected()) )
238 {
239 Json::Value command;
240 Json::Value params;
241 command["cmd"] = "tuner";
242 command["msg"] = _parent->getMessageId();
243 command["params"] = Json::objectValue;
244 command["params"]["id"] = index;
245 command["params"]["enable"] = enabled;
246 Json::FastWriter fastWriter;
247 std::string output = fastWriter.write(command);
248 BasicStringList rsp = _parent->sendCommand(output);
249 Json::Reader reader;
250 Json::Value returnVal;
251 std::string t = rsp.at(0);
252 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
253 ret = returnVal["success"].asBool();
254 }
255 return ret;
256 }
257
258 bool TunerComponent::executeAttenCommand(int index, double& atten)
259 {
260 bool ret = false;
261 if ( (_parent != NULL) && (_parent->isConnected()) )
262 {
263 Json::Value command;
264 Json::Value params;
265 command["cmd"] = "tuner";
266 command["msg"] = _parent->getMessageId();
267 command["params"] = Json::objectValue;
268 command["params"]["id"] = index;
269 command["params"]["atten"] = atten;
270 Json::FastWriter fastWriter;
271 std::string output = fastWriter.write(command);
272 BasicStringList rsp = _parent->sendCommand(output);
273 Json::Reader reader;
274 Json::Value returnVal;
275 std::string t = rsp.at(0);
276 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
277 ret = returnVal["success"].asBool();
278 }
279 return ret;
280 }
281
282 bool TunerComponent::executeCommand( void )
283 {
284 bool ret = false;
285 if ( (_parent != NULL) && (_parent->isConnected()) )
286 {
287 Json::Value command;
288 Json::Value params;
289 command["cmd"] = "tuner";
290 command["msg"] = _parent->getMessageId();
291 command["params"] = Json::objectValue;
292 command["params"]["id"] = _index;
293 command["params"]["atten"] = _attenuation;
294 command["params"]["freq"] = _frequency;
295 command["if"] = _if;
296 command["mode"] = _mode;
297 Json::FastWriter fastWriter;
298 std::string output = fastWriter.write(command);
299 BasicStringList rsp = _parent->sendCommand(output);
300 Json::Reader reader;
301 Json::Value returnVal;
302 std::string t = rsp.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
310 } /* namespace NDR324 */
311
312 } // namespace Driver
313
314} // namespace LibCyberRadio
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual int debug(const char *format,...)
Outputs debug information.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
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 void dumpConfiguration()
Dumps this object's configuration dictionary to debug output.
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.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
bool executeFreqCommand(int index, double &freq) override
Executes the tuner frequency set command.
bool executeAttenCommand(int index, double &atten) override
Executes the tuner attenuation set command.
bool setConfiguration(ConfigurationDict &cfg) override
Sets the configuration dictionary for this component.
virtual TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
void initConfigurationDict() override
Initializes the configuration dictionary, defining the allowed keys.
TunerComponent(int index=1, ::LibCyberRadio::Driver::RadioHandler *parent=NULL, bool debug=false, double frequency=800e6, double attenuation=0.0, int filter=0)
Constructs a TunerComponent object.
virtual ~TunerComponent()
Destroys a TunerComponent object.
bool executeEnableCommand(int index, bool &enabled) override
Executes the tuner enable command.
void updateConfigurationDict() override
Updates the configuration dictionary from component settings.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
Generic radio handler class.
virtual uint32_t getMessageId(void)
Get a json Message ID.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual bool executeTimingAdjustmentCommand(int index, int &timingAdj)
Executes the tuner timing adjustment command.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
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