SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
devicesoapysdrparams.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <sstream>
19 #include <iostream>
20 
21 #include <QDebug>
22 
23 #include "devicesoapysdrparams.h"
24 
25 DeviceSoapySDRParams::DeviceSoapySDRParams(SoapySDR::Device *device) :
26  m_device(device)
27 {
28  fillParams();
29  printParams();
30 }
31 
33 {}
34 
36 {
37  if (index < m_nbRx)
38  {
39  return std::string("RF");
40  }
41  else
42  {
43  const ChannelSettings& channelSettings = m_RxChannelsSettings[index];
44 
45  if (channelSettings.m_frequencySettings.size() > 0) {
46  return channelSettings.m_frequencySettings.front().m_name;
47  } else {
48  return std::string("RF");
49  }
50  }
51 }
52 
54 {
55  if (index < m_nbRx)
56  {
57  return std::string("RF");
58  }
59  else
60  {
61  const ChannelSettings& channelSettings = m_RxChannelsSettings[index];
62 
63  if (channelSettings.m_frequencySettings.size() > 0) {
64  return channelSettings.m_frequencySettings.front().m_name;
65  } else {
66  return std::string("RF");
67  }
68  }
69 }
70 
72 {
73  m_deviceSettingsArgs = m_device->getSettingInfo();
74  m_nbRx = m_device->getNumChannels(SOAPY_SDR_RX);
75  m_nbTx = m_device->getNumChannels(SOAPY_SDR_TX);
76 
77  for (unsigned int ichan = 0; ichan < m_nbRx; ichan++) {
78  fillChannelParams(m_RxChannelsSettings, SOAPY_SDR_RX, ichan);
79  }
80 
81  for (unsigned int ichan = 0; ichan < m_nbTx; ichan++) {
82  fillChannelParams(m_TxChannelsSettings, SOAPY_SDR_TX, ichan);
83  }
84 }
85 
86 void DeviceSoapySDRParams::fillChannelParams(std::vector<ChannelSettings>& channelSettings, int direction, unsigned int ichan)
87 {
88  channelSettings.push_back(ChannelSettings());
89 
90  channelSettings.back().m_streamSettingsArgs = m_device->getStreamArgsInfo(direction, ichan);
91  channelSettings.back().m_antennas = m_device->listAntennas(direction, ichan);
92  channelSettings.back().m_hasDCAutoCorrection = m_device->hasDCOffsetMode(direction, ichan);
93  channelSettings.back().m_hasDCOffsetValue = m_device->hasDCOffset(direction, ichan);
94  channelSettings.back().m_hasIQBalanceValue = m_device->hasIQBalance(direction, ichan);
95  channelSettings.back().m_hasFrequencyCorrectionValue = m_device->hasFrequencyCorrection(direction, ichan);
96 
97  // gains
98 
99  channelSettings.back().m_hasAGC = m_device->hasGainMode(direction, ichan);
100  channelSettings.back().m_gainRange = m_device->getGainRange(direction, ichan);
101  std::vector<std::string> gainsList = m_device->listGains(direction, ichan);
102 
103  for (const auto &it : gainsList)
104  {
105  channelSettings.back().m_gainSettings.push_back(GainSetting());
106  channelSettings.back().m_gainSettings.back().m_name = it;
107  channelSettings.back().m_gainSettings.back().m_range = m_device->getGainRange(direction, ichan, it);
108  }
109 
110  // frequencies
111 
112  std::vector<std::string> freqsList = m_device->listFrequencies(direction, ichan);
113 
114  for (const auto &it : freqsList)
115  {
116  channelSettings.back().m_frequencySettings.push_back(FrequencySetting());
117  channelSettings.back().m_frequencySettings.back().m_name = it;
118  channelSettings.back().m_frequencySettings.back().m_ranges = m_device->getFrequencyRange(direction, ichan, it);
119  }
120 
121  channelSettings.back().m_frequencySettingsArgs = m_device->getFrequencyArgsInfo(direction, ichan);
122 
123  // sample rates
124  channelSettings.back().m_ratesRanges = m_device->getSampleRateRange(direction, ichan);
125 
126  // bandwidths
127  channelSettings.back().m_bandwidthsRanges = m_device->getBandwidthRange(direction, ichan);
128 }
129 
131 {
132  qDebug() << "DeviceSoapySDRParams::printParams: m_deviceSettingsArgs:\n" << argInfoListToString(m_deviceSettingsArgs).c_str();
133  int ichan = 0;
134 
135  for (const auto &it : m_RxChannelsSettings)
136  {
137  qDebug() << "DeviceSoapySDRParams::printParams: Rx channel " << ichan;
138  printChannelParams(it);
139  ichan++;
140  }
141 
142  ichan = 0;
143 
144  for (const auto &it : m_TxChannelsSettings)
145  {
146  qDebug() << "DeviceSoapySDRParams::printParams: Tx channel " << ichan;
147  printChannelParams(it);
148  ichan++;
149  }
150 }
151 
153 {
154  qDebug() << "DeviceSoapySDRParams::printParams: m_streamSettingsArgs:\n" << argInfoListToString(channelSetting.m_streamSettingsArgs).c_str();
155  qDebug() << "DeviceSoapySDRParams::printParams:"
156  << " m_hasDCAutoCorrection: " << channelSetting.m_hasDCAutoCorrection
157  << " m_hasDCOffsetValue: " << channelSetting.m_hasDCOffsetValue
158  << " m_hasIQBalanceValue: " << channelSetting.m_hasIQBalanceValue
159  << " m_hasFrequencyCorrectionValue: " << channelSetting.m_hasFrequencyCorrectionValue
160  << " m_hasAGC: " << channelSetting.m_hasAGC;
161  qDebug() << "DeviceSoapySDRParams::printParams: m_antennas: " << vectorToString(channelSetting.m_antennas).c_str();
162  qDebug() << "DeviceSoapySDRParams::printParams: m_gainRange: " << rangeToString(channelSetting.m_gainRange).c_str();
163 
164  qDebug() << "DeviceSoapySDRParams::printParams: individual gains...";
165 
166  for (const auto &gainIt : channelSetting.m_gainSettings)
167  {
168  qDebug() << "DeviceSoapySDRParams::printParams: m_name: " << gainIt.m_name.c_str();
169  qDebug() << "DeviceSoapySDRParams::printParams: m_range: " << rangeToString(gainIt.m_range).c_str();
170  }
171 
172  qDebug() << "DeviceSoapySDRParams::printParams: tunable elements...";
173 
174  for (const auto &freqIt : channelSetting.m_frequencySettings)
175  {
176  qDebug() << "DeviceSoapySDRParams::printParams: m_name: " << freqIt.m_name.c_str();
177  qDebug() << "DeviceSoapySDRParams::printParams: m_range (kHz): " << rangeListToString(freqIt.m_ranges, 1e3).c_str();
178  }
179 
180  qDebug() << "DeviceSoapySDRParams::printParams: m_frequencySettingsArgs:\n" << argInfoListToString(channelSetting.m_frequencySettingsArgs).c_str();
181  qDebug() << "DeviceSoapySDRParams::printParams: m_ratesRanges (kHz): " << rangeListToString(channelSetting.m_ratesRanges, 1e3).c_str();
182  qDebug() << "DeviceSoapySDRParams::printParams: m_bandwidthsRanges (kHz): " << rangeListToString(channelSetting.m_bandwidthsRanges, 1e3).c_str();
183 }
184 
185 std::string DeviceSoapySDRParams::argInfoToString(const SoapySDR::ArgInfo &argInfo, const std::string indent)
186 {
187  std::stringstream ss;
188 
189  //name, or use key if missing
190  std::string name = argInfo.name;
191  if (argInfo.name.empty()) name = argInfo.key;
192  ss << indent << " * " << name;
193 
194  //optional description
195  std::string desc = argInfo.description;
196  const std::string replace("\n"+indent+" ");
197 
198  for (std::size_t pos = 0; (pos=desc.find("\n", pos)) != std::string::npos; pos+=replace.size()) {
199  desc.replace(pos, 1, replace);
200  }
201 
202  if (not desc.empty()) {
203  ss << " - " << desc << std::endl << indent << " ";
204  }
205 
206  //other fields
207  ss << " [key=" << argInfo.key;
208 
209  if (not argInfo.units.empty()) {
210  ss << ", units=" << argInfo.units;
211  }
212 
213  if (not argInfo.value.empty()) {
214  ss << ", default=" << argInfo.value;
215  }
216 
217  //type
218  switch (argInfo.type)
219  {
221  ss << ", type=bool";
222  break;
223  case SoapySDR::ArgInfo::INT:
224  ss << ", type=int";
225  break;
226  case SoapySDR::ArgInfo::FLOAT:
227  ss << ", type=float";
228  break;
229  case SoapySDR::ArgInfo::STRING:
230  ss << ", type=string";
231  break;
232  }
233 
234  //optional range/enumeration
235  if (argInfo.range.minimum() < argInfo.range.maximum()) {
236  ss << ", range=" << rangeToString(argInfo.range);
237  }
238 
239  if (not argInfo.options.empty()) {
240  ss << ", options=(" << vectorToString(argInfo.options) << ")";
241  }
242 
243  ss << "]";
244 
245  return ss.str();
246 }
247 
248 std::string DeviceSoapySDRParams::argInfoListToString(const SoapySDR::ArgInfoList &argInfos)
249 {
250  std::stringstream ss;
251 
252  for (std::size_t i = 0; i < argInfos.size(); i++) {
253  ss << argInfoToString(argInfos[i]) << std::endl;
254  }
255 
256  return ss.str();
257 }
258 
259 std::string DeviceSoapySDRParams::rangeToString(const SoapySDR::Range &range)
260 {
261  std::stringstream ss;
262  ss << "[" << range.minimum() << ", " << range.maximum();
263 
264  if (range.step() != 0.0) {
265  ss << ", " << range.step();
266  }
267 
268  ss << "]";
269  return ss.str();
270 }
271 
272 std::string DeviceSoapySDRParams::rangeListToString(const SoapySDR::RangeList &range, const double scale)
273 {
274  std::stringstream ss;
275 
276  for (std::size_t i = 0; i < range.size(); i++)
277  {
278  if (not ss.str().empty()) {
279  ss << ", ";
280  }
281 
282  if (range[i].minimum() == range[i].maximum())
283  {
284  ss << (range[i].minimum()/scale);
285  }
286  else
287  {
288  ss << "[" << (range[i].minimum()/scale) << ", " << (range[i].maximum()/scale);
289 
290  if (range[i].step() != 0.0) {
291  ss << ", " << (range[i].step()/scale);
292  }
293 
294  ss << "]";
295  }
296  }
297 
298  return ss.str();
299 }
SoapySDR::Device * m_device
std::vector< ChannelSettings > m_RxChannelsSettings
std::string argInfoToString(const SoapySDR::ArgInfo &argInfo, const std::string indent=" ")
uint32_t m_nbRx
number of Rx channels
std::string getTxChannelMainTunableElementName(uint32_t index)
SoapySDR::ArgInfoList m_deviceSettingsArgs
list (vector) of device settings arguments
SoapySDR::ArgInfoList m_frequencySettingsArgs
common tuning parameters
std::string getRxChannelMainTunableElementName(uint32_t index)
bool m_hasFrequencyCorrectionValue
Frequency correction value flag.
bool m_hasDCOffsetValue
DC offset value flag.
uint32_t m_nbTx
number of Tx channels
bool m_hasDCAutoCorrection
DC offset auto correction flag.
std::vector< ChannelSettings > m_TxChannelsSettings
std::vector< FrequencySetting > m_frequencySettings
tunable elements settings
unsigned int uint32_t
Definition: rtptypes_win.h:46
void fillChannelParams(std::vector< ChannelSettings > &channelSettings, int direction, unsigned int ichan)
std::vector< std::string > m_antennas
Antenna ports names.
SoapySDR::RangeList m_ratesRanges
list of ranges of sample rates
int32_t i
Definition: decimators.h:244
std::string rangeListToString(const SoapySDR::RangeList &range, const double scale)
void printChannelParams(const ChannelSettings &channelSetting)
int BOOL
Definition: fcdhid.h:37
SoapySDR::RangeList m_bandwidthsRanges
list of ranges of bandwidths
std::string argInfoListToString(const SoapySDR::ArgInfoList &argInfos)
std::string rangeToString(const SoapySDR::Range &range)
std::string vectorToString(const std::vector< Type > &options)
std::vector< GainSetting > m_gainSettings
gain elements settings
SoapySDR::ArgInfoList m_streamSettingsArgs
common stream parameters
DeviceSoapySDRParams(SoapySDR::Device *device)
bool m_hasIQBalanceValue
IQ correction value flag.
SoapySDR::Range m_gainRange
Global gain range.