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.
SWGBladeRF2InputReport.cpp
Go to the documentation of this file.
1 
14 #include "SWGBladeRF2InputReport.h"
15 
16 #include "SWGHelpers.h"
17 
18 #include <QJsonDocument>
19 #include <QJsonArray>
20 #include <QObject>
21 #include <QDebug>
22 
23 namespace SWGSDRangel {
24 
26  init();
27  this->fromJson(*json);
28 }
29 
31  frequency_range = nullptr;
33  sample_rate_range = nullptr;
35  bandwidth_range = nullptr;
37  global_gain_range = nullptr;
39  gain_modes = nullptr;
40  m_gain_modes_isSet = false;
41 }
42 
44  this->cleanup();
45 }
46 
47 void
53  bandwidth_range = new SWGRange();
57  gain_modes = new QList<SWGNamedEnum*>();
58  m_gain_modes_isSet = false;
59 }
60 
61 void
63  if(frequency_range != nullptr) {
64  delete frequency_range;
65  }
66  if(sample_rate_range != nullptr) {
67  delete sample_rate_range;
68  }
69  if(bandwidth_range != nullptr) {
70  delete bandwidth_range;
71  }
72  if(global_gain_range != nullptr) {
73  delete global_gain_range;
74  }
75  if(gain_modes != nullptr) {
76  auto arr = gain_modes;
77  for(auto o: *arr) {
78  delete o;
79  }
80  delete gain_modes;
81  }
82 }
83 
86  QByteArray array (json.toStdString().c_str());
87  QJsonDocument doc = QJsonDocument::fromJson(array);
88  QJsonObject jsonObject = doc.object();
89  this->fromJsonObject(jsonObject);
90  return this;
91 }
92 
93 void
95  ::SWGSDRangel::setValue(&frequency_range, pJson["frequencyRange"], "SWGFrequencyRange", "SWGFrequencyRange");
96 
97  ::SWGSDRangel::setValue(&sample_rate_range, pJson["sampleRateRange"], "SWGRange", "SWGRange");
98 
99  ::SWGSDRangel::setValue(&bandwidth_range, pJson["bandwidthRange"], "SWGRange", "SWGRange");
100 
101  ::SWGSDRangel::setValue(&global_gain_range, pJson["globalGainRange"], "SWGRange", "SWGRange");
102 
103 
104  ::SWGSDRangel::setValue(&gain_modes, pJson["gainModes"], "QList", "SWGNamedEnum");
105 }
106 
107 QString
109 {
110  QJsonObject* obj = this->asJsonObject();
111 
112  QJsonDocument doc(*obj);
113  QByteArray bytes = doc.toJson();
114  delete obj;
115  return QString(bytes);
116 }
117 
118 QJsonObject*
120  QJsonObject* obj = new QJsonObject();
121  if((frequency_range != nullptr) && (frequency_range->isSet())){
122  toJsonValue(QString("frequencyRange"), frequency_range, obj, QString("SWGFrequencyRange"));
123  }
124  if((sample_rate_range != nullptr) && (sample_rate_range->isSet())){
125  toJsonValue(QString("sampleRateRange"), sample_rate_range, obj, QString("SWGRange"));
126  }
127  if((bandwidth_range != nullptr) && (bandwidth_range->isSet())){
128  toJsonValue(QString("bandwidthRange"), bandwidth_range, obj, QString("SWGRange"));
129  }
130  if((global_gain_range != nullptr) && (global_gain_range->isSet())){
131  toJsonValue(QString("globalGainRange"), global_gain_range, obj, QString("SWGRange"));
132  }
133  if(gain_modes->size() > 0){
134  toJsonArray((QList<void*>*)gain_modes, obj, "gainModes", "SWGNamedEnum");
135  }
136 
137  return obj;
138 }
139 
142  return frequency_range;
143 }
144 void
146  this->frequency_range = frequency_range;
147  this->m_frequency_range_isSet = true;
148 }
149 
150 SWGRange*
152  return sample_rate_range;
153 }
154 void
156  this->sample_rate_range = sample_rate_range;
157  this->m_sample_rate_range_isSet = true;
158 }
159 
160 SWGRange*
162  return bandwidth_range;
163 }
164 void
166  this->bandwidth_range = bandwidth_range;
167  this->m_bandwidth_range_isSet = true;
168 }
169 
170 SWGRange*
172  return global_gain_range;
173 }
174 void
176  this->global_gain_range = global_gain_range;
177  this->m_global_gain_range_isSet = true;
178 }
179 
180 QList<SWGNamedEnum*>*
182  return gain_modes;
183 }
184 void
186  this->gain_modes = gain_modes;
187  this->m_gain_modes_isSet = true;
188 }
189 
190 
191 bool
193  bool isObjectUpdated = false;
194  do{
195  if(frequency_range != nullptr && frequency_range->isSet()){ isObjectUpdated = true; break;}
196  if(sample_rate_range != nullptr && sample_rate_range->isSet()){ isObjectUpdated = true; break;}
197  if(bandwidth_range != nullptr && bandwidth_range->isSet()){ isObjectUpdated = true; break;}
198  if(global_gain_range != nullptr && global_gain_range->isSet()){ isObjectUpdated = true; break;}
199  if(gain_modes->size() > 0){ isObjectUpdated = true; break;}
200  }while(false);
201  return isObjectUpdated;
202 }
203 }
204 
void toJsonValue(QString name, void *value, QJsonObject *output, QString type)
Definition: SWGHelpers.cpp:383
virtual QJsonObject * asJsonObject() override
void setFrequencyRange(SWGFrequencyRange *frequency_range)
void setGlobalGainRange(SWGRange *global_gain_range)
void setValue(void *value, QJsonValue obj, QString type, QString complexType)
Definition: SWGHelpers.cpp:25
void setBandwidthRange(SWGRange *bandwidth_range)
void toJsonArray(QList< void *> *value, QJsonObject *output, QString innerName, QString innerType)
Definition: SWGHelpers.cpp:445
void setSampleRateRange(SWGRange *sample_rate_range)
void setGainModes(QList< SWGNamedEnum *> *gain_modes)
virtual void fromJsonObject(QJsonObject &json) override
virtual bool isSet() override
Definition: SWGRange.cpp:138
virtual SWGBladeRF2InputReport * fromJson(QString &jsonString) override