@@ -48,15 +48,18 @@ const char* sampleRatesTxt[] = {
48
48
" 3.2MHz"
49
49
};
50
50
51
+ #define SAMPLE_RATE_COUNT (sizeof (sampleRates) / sizeof (double ))
52
+
51
53
class RTLTCPSourceModule : public ModuleManager ::Instance {
52
54
public:
53
55
RTLTCPSourceModule (std::string name) {
54
56
this ->name = name;
55
57
56
58
sampleRate = 2400000.0 ;
57
59
58
- int srCount = sizeof (sampleRatesTxt) / sizeof (char *);
59
- for (int i = 0 ; i < srCount; i++) {
60
+ int _24id = 0 ;
61
+ for (int i = 0 ; i < SAMPLE_RATE_COUNT; i++) {
62
+ if (sampleRates[i] == 2400000 ) { _24id = i; }
60
63
srTxt += sampleRatesTxt[i];
61
64
srTxt += ' \0 ' ;
62
65
}
@@ -65,7 +68,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
65
68
config.acquire ();
66
69
std::string hostStr = config.conf [" host" ];
67
70
port = config.conf [" port" ];
71
+ double wantedSr = config.conf [" sampleRate" ];
68
72
directSamplingMode = config.conf [" directSamplingMode" ];
73
+ ppm = config.conf [" ppm" ];
69
74
rtlAGC = config.conf [" rtlAGC" ];
70
75
tunerAGC = config.conf [" tunerAGC" ];
71
76
gain = std::clamp<int >(config.conf [" gainIndex" ], 0 , 28 );
@@ -75,6 +80,20 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
75
80
strcpy (ip, hostStr.c_str ());
76
81
config.release ();
77
82
83
+ bool found = false ;
84
+ for (int i = 0 ; i < SAMPLE_RATE_COUNT; i++) {
85
+ if (sampleRates[i] == wantedSr) {
86
+ found = true ;
87
+ srId = i;
88
+ sampleRate = sampleRates[i];
89
+ break ;
90
+ }
91
+ }
92
+ if (!found) {
93
+ srId = _24id;
94
+ sampleRate = sampleRates[_24id];
95
+ }
96
+
78
97
handler.ctx = this ;
79
98
handler.selectHandler = menuSelected;
80
99
handler.deselectHandler = menuDeselected;
@@ -127,6 +146,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
127
146
spdlog::warn (" Setting sample rate to {0}" , _this->sampleRate );
128
147
_this->client .setFrequency (_this->freq );
129
148
_this->client .setSampleRate (_this->sampleRate );
149
+ _this->client .setPPM (_this->ppm );
130
150
_this->client .setDirectSampling (_this->directSamplingMode );
131
151
_this->client .setAGCMode (_this->rtlAGC );
132
152
_this->client .setBiasTee (_this->biasTee );
@@ -191,6 +211,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
191
211
if (ImGui::Combo (CONCAT (" ##_rtltcp_sr_" , _this->name ), &_this->srId , _this->srTxt .c_str ())) {
192
212
_this->sampleRate = sampleRates[_this->srId ];
193
213
core::setInputSampleRate (_this->sampleRate );
214
+ config.acquire ();
215
+ config.conf [" sampleRate" ] = _this->sampleRate ;
216
+ config.release (true );
194
217
}
195
218
196
219
if (_this->running ) { style::endDisabled (); }
@@ -203,18 +226,39 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
203
226
_this->client .setDirectSampling (_this->directSamplingMode );
204
227
_this->client .setGainIndex (_this->gain );
205
228
}
229
+ config.acquire ();
230
+ config.conf [" directSamplingMode" ] = _this->directSamplingMode ;
231
+ config.release (true );
232
+ }
233
+
234
+ ImGui::Text (" PPM Correction" );
235
+ ImGui::SameLine ();
236
+ ImGui::SetNextItemWidth (menuWidth - ImGui::GetCursorPosX ());
237
+ if (ImGui::InputInt (CONCAT (" ##_rtltcp_ppm_" , _this->name ), &_this->ppm , 1 , 10 )) {
238
+ if (_this->running ) {
239
+ _this->client .setPPM (_this->ppm );
240
+ }
241
+ config.acquire ();
242
+ config.conf [" ppm" ] = _this->ppm ;
243
+ config.release (true );
206
244
}
207
245
208
246
if (ImGui::Checkbox (CONCAT (" Bias-T##_biast_select_" , _this->name ), &_this->biasTee )) {
209
247
if (_this->running ) {
210
248
_this->client .setBiasTee (_this->biasTee );
211
249
}
250
+ config.acquire ();
251
+ config.conf [" biasTee" ] = _this->biasTee ;
252
+ config.release (true );
212
253
}
213
254
214
255
if (ImGui::Checkbox (CONCAT (" Offset Tuning##_biast_select_" , _this->name ), &_this->offsetTuning )) {
215
256
if (_this->running ) {
216
257
_this->client .setOffsetTuning (_this->offsetTuning );
217
258
}
259
+ config.acquire ();
260
+ config.conf [" offsetTuning" ] = _this->offsetTuning ;
261
+ config.release (true );
218
262
}
219
263
220
264
if (ImGui::Checkbox (" RTL AGC" , &_this->rtlAGC )) {
@@ -224,6 +268,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
224
268
_this->client .setGainIndex (_this->gain );
225
269
}
226
270
}
271
+ config.acquire ();
272
+ config.conf [" rtlAGC" ] = _this->rtlAGC ;
273
+ config.release (true );
227
274
}
228
275
229
276
if (ImGui::Checkbox (" Tuner AGC" , &_this->tunerAGC )) {
@@ -233,6 +280,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
233
280
_this->client .setGainIndex (_this->gain );
234
281
}
235
282
}
283
+ config.acquire ();
284
+ config.conf [" tunerAGC" ] = _this->tunerAGC ;
285
+ config.release (true );
236
286
}
237
287
238
288
if (_this->tunerAGC ) { style::beginDisabled (); }
@@ -241,6 +291,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
241
291
if (_this->running ) {
242
292
_this->client .setGainIndex (_this->gain );
243
293
}
294
+ config.acquire ();
295
+ config.conf [" gainIndex" ] = _this->gain ;
296
+ config.release (true );
244
297
}
245
298
if (_this->tunerAGC ) { style::endDisabled (); }
246
299
}
@@ -275,6 +328,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
275
328
char ip[1024 ] = " localhost" ;
276
329
int port = 1234 ;
277
330
int gain = 0 ;
331
+ int ppm = 0 ;
278
332
bool rtlAGC = false ;
279
333
bool tunerAGC = false ;
280
334
int directSamplingMode = 0 ;
@@ -290,7 +344,9 @@ MOD_EXPORT void _INIT_() {
290
344
json defConf;
291
345
defConf[" host" ] = " localhost" ;
292
346
defConf[" port" ] = 1234 ;
347
+ defConf[" sampleRate" ] = 2400000.0 ;
293
348
defConf[" directSamplingMode" ] = 0 ;
349
+ defConf[" ppm" ] = 0 ;
294
350
defConf[" rtlAGC" ] = false ;
295
351
defConf[" tunerAGC" ] = false ;
296
352
defConf[" gainIndex" ] = 0 ;
@@ -306,6 +362,12 @@ MOD_EXPORT void _INIT_() {
306
362
if (!config.conf .contains (" offsetTuning" )) {
307
363
config.conf [" offsetTuning" ] = false ;
308
364
}
365
+ if (!config.conf .contains (" ppm" )) {
366
+ config.conf [" ppm" ] = 0 ;
367
+ }
368
+ if (!config.conf .contains (" sampleRate" )) {
369
+ config.conf [" sampleRate" ] = 2400000.0 ;
370
+ }
309
371
config.release (true );
310
372
}
311
373
0 commit comments