libcyberradio 22.01.24
TunerComponent.cpp
1/***************************************************************************
2 * \file TunerComponent.cpp
3 * \brief Defines the tuner interface for the NDR472.
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/NDR472/TunerComponent.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include "LibCyberRadio/Common/Pythonesque.h"
14#include <boost/lexical_cast.hpp>
15#include <boost/format.hpp>
16
17
18namespace LibCyberRadio
19{
20 namespace Driver
21 {
22
23 namespace NDR472
24 {
25
28 bool debug,
29 double frequency,
30 double attenuation,
31 int filter) :
33 /* const std::string& name */ (boost::format("NDR472-TUNER%02d") % \
34 index).str(),
35 /* int index */ index,
36 /* ::LibCyberRadio::Driver::RadioHandler* parent */ parent,
37 /* bool debug */ debug,
38 /* double freqRangeMin */ 20e6,
39 /* double freqRangeMax */ 3000e6,
40 /* double freqRes */ 1e6,
41 /* double freqUnits */ 1e6,
42 /* double attRangeMin */ 0.0,
43 /* double attRangeMax */ 30.0,
44 /* double attRes */ 1.0,
45 /* bool agc */ false,
46 /* double frequency */ frequency,
47 /* double attenuation */ attenuation,
48 /* int filter */ filter)
49 {
50 // Call init function
52 }
53
57
62
64 {
65 ::LibCyberRadio::Driver::TunerComponent::operator=(other);
66 if ( this != &other )
67 {
68 }
69 return *this;
70 }
71
72 // OVERRIDE
74 {
75 this->debug("[NDR472::TunerComponent::initConfigurationDict] Called\n");
76 _config.clear();
77 // Call the base-class version
79 // Define tuner-specific keys
80 _config["frequency"] = "";
81 _config["attenuation"] = "";
82 _config["timingAdj"] = "";
83 this->debug("[NDR472::TunerComponent::initConfigurationDict] Returning\n");
84 }
85
86 // OVERRIDE
88 {
89 this->debug("[NDR472::TunerComponent::updateConfigurationDict] Called\n");
91 bool res;
92 res = setConfigurationValueToDbl("frequency", _frequency);
93 res = setConfigurationValueToDbl("attenuation", _attenuation);
94 res = setConfigurationValueToInt("timingAdj", _timingAdj);
95 //this->debug("[TunerComponent::updateConfigurationDict] Current configuration\n");
96 //this->dumpConfiguration();
97 this->debug("[NDR472::TunerComponent::updateConfigurationDict] Returning\n");
98 }
99
100 // OVERRIDE
102 {
103 this->debug("[NDR472::TunerComponent::queryConfiguration] Called\n");
104 executeEnableQuery(_index, _enabled);
105 executeFreqQuery(_index, _frequency);
106 executeAttenQuery(_index, _attenuation);
107 executeTimingAdjustmentQuery(_index, _timingAdj);
109 this->debug("[NDR472::TunerComponent::queryConfiguration] Returning\n");
110 }
111
112 // OVERRIDE
113 // On this radio, the query parameters are space-delimited, not comma-delimited.
114 bool TunerComponent::executeEnableQuery(int index, bool& enabled)
115 {
116 bool ret = false;
117 if ( (_parent != NULL) && (_parent->isConnected()) )
118 {
119 std::ostringstream oss;
120 oss << "TPWR? " << index << "\n";
121 BasicStringList rsp = _parent->sendCommand(oss.str(), 2.0);
122 if ( _parent->getLastCommandErrorInfo() == "" )
123 {
125 Pythonesque::Replace(rsp.front(), "TPWR ", ""),
126 " ");
127 // vec[0] = Index
128 // vec[1] = Powered state (0=off, 1=on)
129 enabled = (boost::lexical_cast<int>(vec[1]) == 1);
130 ret = true;
131 }
132 }
133 return ret;
134
135 }
136
137 // OVERRIDE
138 // On this radio, the query parameters are space-delimited, not comma-delimited.
139 // Also, the radio appends "Mhz" to the returned frequency values.
140 bool TunerComponent::executeFreqQuery(int index, double& freq)
141 {
142 bool ret = false;
143 if ( (_parent != NULL) && (_parent->isConnected()) )
144 {
145 std::ostringstream oss;
146 oss << "FRQ? " << index << "\n";
147 BasicStringList rsp = _parent->sendCommand(oss.str(), 2.0);
148 if ( _parent->getLastCommandErrorInfo() == "" )
149 {
150 std::string tmp = Pythonesque::Replace(rsp.front(), "FRQ ", "");
151 tmp = Pythonesque::Replace(tmp, "Mhz", "");
152 BasicStringList vec = Pythonesque::Split(tmp, " ");
153 // vec[0] = Index
154 // vec[1] = Frequency (MHz)
155 freq = boost::lexical_cast<int>(vec[1]) * _freqUnits;
156 ret = true;
157 }
158 }
159 return ret;
160 }
161
162 // OVERRIDE
163 // On this radio, the query parameters are space-delimited, not comma-delimited.
164 // Also, the radio appends "dB" to the returned attenuation values.
165 bool TunerComponent::executeAttenQuery(int index, double& atten)
166 {
167 bool ret = false;
168 if ( (_parent != NULL) && (_parent->isConnected()) )
169 {
170 std::ostringstream oss;
171 oss << "ATT? " << index << "\n";
172 BasicStringList rsp = _parent->sendCommand(oss.str(), 2.0);
173 if ( _parent->getLastCommandErrorInfo() == "" )
174 {
175 std::string tmp = Pythonesque::Replace(rsp.front(), "ATT ", "");
176 tmp = Pythonesque::Replace(tmp, "dB", "");
177 BasicStringList vec = Pythonesque::Split(tmp, " ");
178 // vec[0] = Index
179 // vec[1] = Atten (dB)
180 atten = boost::lexical_cast<double>(vec[1]);
181 ret = true;
182 }
183 }
184 return ret;
185 }
186
187 // OVERRIDE
188 // Filters are neither gettable or settable on this radio
189 bool TunerComponent::executeFilterQuery(int index, int& filter)
190 {
191 bool ret = false;
192 return ret;
193 }
194
195 // OVERRIDE
196 // On this radio, the query parameters are space-delimited, not comma-delimited.
197 bool TunerComponent::executeTimingAdjustmentQuery(int index, int& timingAdj)
198 {
199 bool ret = false;
200 if ( (_parent != NULL) && (_parent->isConnected()) )
201 {
202 std::ostringstream oss;
203 oss << "TADJ? " << index << "\n";
204 BasicStringList rsp = _parent->sendCommand(oss.str(), 2.0);
205 if ( _parent->getLastCommandErrorInfo() == "" )
206 {
208 Pythonesque::Replace(rsp.front(), "TADJ ", ""),
209 " ");
210 // vec[0] = Index
211 // vec[1] = Timing adjustment
212 timingAdj = boost::lexical_cast<int>(vec[1]);
213 ret = true;
214 }
215 }
216 return ret;
217 }
218
219 // OVERRIDE
220 // Filters are neither gettable or settable on this radio
221 bool TunerComponent::executeFilterCommand(int index, int& filter)
222 {
223 bool ret = false;
224 return ret;
225 }
226
227 } /* namespace NDR472 */
228
229 } // namespace Driver
230
231} // namespace LibCyberRadio
232
233
234
virtual int debug(const char *format,...)
Outputs debug information.
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.
virtual TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool executeFreqQuery(int index, double &freq)
Executes the tuner frequency query command.
virtual bool executeFilterQuery(int index, int &filter)
Executes the tuner filter query command.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual void initConfigurationDict()
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 bool executeEnableQuery(int index, bool &enabled)
Executes the tuner enabled query command.
virtual bool executeTimingAdjustmentQuery(int index, int &timingAdj)
Executes the tuner timing adjustment query.
virtual ~TunerComponent()
Destroys a TunerComponent object.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
virtual bool executeAttenQuery(int index, double &atten)
Executes the tuner attenuation query command.
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.
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
Provides programming elements for driving NDR472 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