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> 32 (boost::format(
"NDR324-TUNER%02d") % \
49 this->
debug(
"[NDR324::TunerComponent] index - %d\n", index);
55 this->
debug(
"[TunerComponent::updateConfigurationDict] Called\n");
58 if ( _config.
hasKey(
"frequency") )
62 if ( _config.
hasKey(
"attenuation") )
66 if ( _config.
hasKey(
"filter") )
70 if ( _config.
hasKey(
"timingAdj") )
74 if ( _config.
hasKey(
"if") )
78 if ( _config.
hasKey(
"mode") )
82 this->
debug(
"[TunerComponent::updateConfigurationDict] Current configuration\n");
84 this->
debug(
"[TunerComponent::updateConfigurationDict] Returning\n");
89 this->
debug(
"[TunerComponent::setConfiguration] Called\n");
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") )
108 freqCmdNeedsExecuting =
true;
110 if ( cfg.
hasKey(
"attenuation") && _config.
hasKey(
"attenuation") )
113 attCmdNeedsExecuting =
true;
118 filCmdNeedsExecuting =
true;
120 if ( cfg.
hasKey(
"timingAdj") && _config.
hasKey(
"timingAdj") )
123 adjCmdNeedsExecuting =
true;
128 ifCmdNeedsExecuting =
true;
130 if ( freqCmdNeedsExecuting )
134 if ( attCmdNeedsExecuting )
138 if ( filCmdNeedsExecuting )
142 if ( adjCmdNeedsExecuting )
146 if ( ifCmdNeedsExecuting )
148 ret &= executeCommand();
150 this->
debug(
"[TunerComponent::setConfiguration] Returning %s\n",
debugBool(ret));
157 _config[
"enable"] =
"";
158 _config[
"frequency"] =
"";
159 _config[
"attenuation"] =
"";
160 _config[
"mode"] =
"auto";
161 _config[
"if"] =
"80";
176 ::LibCyberRadio::Driver::TunerComponent::operator=(other);
177 if (
this != &other )
186 if ( (_parent != NULL) && (_parent->
isConnected()) )
190 command[
"cmd"] =
"tuner";
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);
199 Json::Value returnVal;
200 std::string t = rsp.at(0);
201 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
211 this->
debug(
"[TunerComponent::queryConfiguration] Called\n");
214 command[
"cmd"] =
"qtuner";
216 command[
"params"] = Json::objectValue;
217 command[
"params"][
"id"] = _index;
218 Json::FastWriter fastWriter;
219 std::string output = fastWriter.write(command);
222 Json::Value returnVal;
223 std::string t = rsp.at(0);
224 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
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");
237 if ( (_parent != NULL) && (_parent->
isConnected()) )
241 command[
"cmd"] =
"tuner";
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);
250 Json::Value returnVal;
251 std::string t = rsp.at(0);
252 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
253 ret = returnVal[
"success"].asBool();
261 if ( (_parent != NULL) && (_parent->
isConnected()) )
265 command[
"cmd"] =
"tuner";
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);
274 Json::Value returnVal;
275 std::string t = rsp.at(0);
276 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
277 ret = returnVal[
"success"].asBool();
282 bool TunerComponent::executeCommand(
void )
285 if ( (_parent != NULL) && (_parent->
isConnected()) )
289 command[
"cmd"] =
"tuner";
291 command[
"params"] = Json::objectValue;
292 command[
"params"][
"id"] = _index;
293 command[
"params"][
"atten"] = _attenuation;
294 command[
"params"][
"freq"] = _frequency;
296 command[
"mode"] = _mode;
297 Json::FastWriter fastWriter;
298 std::string output = fastWriter.write(command);
301 Json::Value returnVal;
302 std::string t = rsp.at(0);
303 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
304 ret = returnVal[
"success"].asBool();
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool executeTimingAdjustmentCommand(int index, int &timingAdj)
Executes the tuner timing adjustment command.
virtual ~TunerComponent()
Destroys a TunerComponent object.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
bool setConfiguration(ConfigurationDict &cfg) override
Sets the configuration dictionary for this component.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
bool executeFreqCommand(int index, double &freq) override
Executes the tuner frequency set command.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
virtual bool isConnected() const
Gets whether or not the handler is connected.
Tuner component class for the NDR324.
bool executeEnableCommand(int index, bool &enabled) override
Executes the tuner enable command.
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 void dumpConfiguration()
Dumps this object's configuration dictionary to debug output.
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.
bool executeAttenCommand(int index, double &atten) override
Executes the tuner attenuation set command.
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.
A configuration dictionary.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
void updateConfigurationDict() override
Updates the configuration dictionary from component settings.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
void initConfigurationDict() override
Initializes the configuration dictionary, defining the allowed keys.
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 TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
virtual uint32_t getMessageId(void)
Get a json Message ID.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.