Skip to content

Commit dcc17cd

Browse files
author
Ryzerth
committed
Fixed LimeSDR + Fixed FFTSize bug + added ppm option to RTL-SDR & RTL-TCP + Fixed RTL-TCP not saving settings
1 parent 9eb3ef0 commit dcc17cd

File tree

6 files changed

+99
-5
lines changed

6 files changed

+99
-5
lines changed

core/src/gui/main_window.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ void MainWindow::fftHandler(dsp::complex_t* samples, int count, void* ctx) {
213213
MainWindow* _this = (MainWindow*)ctx;
214214
std::lock_guard<std::mutex> lck(_this->fft_mtx);
215215

216+
// Check if the count is valid
217+
if (count > _this->fftSize) {
218+
return;
219+
}
220+
216221
// Apply window
217222
volk_32fc_32f_multiply_32fc((lv_32fc_t*)_this->fft_in, (lv_32fc_t*)samples, sigpath::signalPath.fftTaps, count);
218223

@@ -657,9 +662,9 @@ void MainWindow::setFFTSize(int size) {
657662
gui::waterfall.setRawFFTSize(fftSize);
658663
sigpath::signalPath.setFFTSize(fftSize);
659664

665+
fftwf_destroy_plan(fftwPlan);
660666
fftwf_free(fft_in);
661667
fftwf_free(fft_out);
662-
fftwf_destroy_plan(fftwPlan);
663668

664669
fft_in = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);
665670
fft_out = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);

core/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#pragma once
22

3-
#define VERSION_STR "1.0.2"
3+
#define VERSION_STR "1.0.3"

limesdr_source/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class LimeSDRSourceModule : public ModuleManager::Instance {
335335
// Setup and start stream
336336
int sampCount = _this->sampleRate / 200;
337337
_this->devStream.isTx = false;
338-
_this->devStream.channel = 0;
338+
_this->devStream.channel = _this->chanId;
339339
_this->devStream.fifoSize = sampCount; // TODO: Check what it's actually supposed to be
340340
_this->devStream.throughputVsLatency = 0.5f;
341341
_this->devStream.dataFmt = _this->devStream.LMS_FMT_F32;

rtl_sdr_source/src/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
162162
created = true;
163163
config.conf["devices"][selectedDevName]["sampleRate"] = 2400000.0;
164164
config.conf["devices"][selectedDevName]["directSampling"] = directSamplingMode;
165+
config.conf["devices"][selectedDevName]["ppm"] = 0;
165166
config.conf["devices"][selectedDevName]["biasT"] = biasT;
166167
config.conf["devices"][selectedDevName]["offsetTuning"] = offsetTuning;
167168
config.conf["devices"][selectedDevName]["rtlAgc"] = rtlAgc;
@@ -187,6 +188,10 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
187188
directSamplingMode = config.conf["devices"][selectedDevName]["directSampling"];
188189
}
189190

191+
if (config.conf["devices"][selectedDevName].contains("ppm")) {
192+
ppm = config.conf["devices"][selectedDevName]["ppm"];
193+
}
194+
190195
if (config.conf["devices"][selectedDevName].contains("biasT")) {
191196
biasT = config.conf["devices"][selectedDevName]["biasT"];
192197
}
@@ -256,6 +261,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
256261

257262
rtlsdr_set_sample_rate(_this->openDev, _this->sampleRate);
258263
rtlsdr_set_center_freq(_this->openDev, _this->freq);
264+
rtlsdr_set_freq_correction(_this->openDev, _this->ppm);
259265
rtlsdr_set_tuner_bandwidth(_this->openDev, 0);
260266
rtlsdr_set_direct_sampling(_this->openDev, _this->directSamplingMode);
261267
rtlsdr_set_bias_tee(_this->openDev, _this->biasT);
@@ -372,6 +378,21 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
372378
}
373379
}
374380

381+
ImGui::Text("PPM Correction");
382+
ImGui::SameLine();
383+
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
384+
if (ImGui::InputInt(CONCAT("##_rtlsdr_ppm_", _this->name), &_this->ppm, 1, 10)) {
385+
_this->ppm = std::clamp<int>(_this->ppm, -1000000, 1000000);
386+
if (_this->running) {
387+
rtlsdr_set_freq_correction(_this->openDev, _this->ppm);
388+
}
389+
if (_this->selectedDevName != "") {
390+
config.acquire();
391+
config.conf["devices"][_this->selectedDevName]["ppm"] = _this->ppm;
392+
config.release(true);
393+
}
394+
}
395+
375396
if (ImGui::Checkbox(CONCAT("Bias T##_rtlsdr_rtl_biast_", _this->name), &_this->biasT)) {
376397
if (_this->running) {
377398
rtlsdr_set_bias_tee(_this->openDev, _this->biasT);
@@ -471,6 +492,8 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
471492
int devCount = 0;
472493
std::thread workerThread;
473494

495+
int ppm = 0;
496+
474497
bool biasT = false;
475498

476499
int gainId = 0;

rtl_tcp_source/src/main.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ const char* sampleRatesTxt[] = {
4848
"3.2MHz"
4949
};
5050

51+
#define SAMPLE_RATE_COUNT (sizeof(sampleRates) / sizeof(double))
52+
5153
class RTLTCPSourceModule : public ModuleManager::Instance {
5254
public:
5355
RTLTCPSourceModule(std::string name) {
5456
this->name = name;
5557

5658
sampleRate = 2400000.0;
5759

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; }
6063
srTxt += sampleRatesTxt[i];
6164
srTxt += '\0';
6265
}
@@ -65,7 +68,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
6568
config.acquire();
6669
std::string hostStr = config.conf["host"];
6770
port = config.conf["port"];
71+
double wantedSr = config.conf["sampleRate"];
6872
directSamplingMode = config.conf["directSamplingMode"];
73+
ppm = config.conf["ppm"];
6974
rtlAGC = config.conf["rtlAGC"];
7075
tunerAGC = config.conf["tunerAGC"];
7176
gain = std::clamp<int>(config.conf["gainIndex"], 0, 28);
@@ -75,6 +80,20 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
7580
strcpy(ip, hostStr.c_str());
7681
config.release();
7782

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+
7897
handler.ctx = this;
7998
handler.selectHandler = menuSelected;
8099
handler.deselectHandler = menuDeselected;
@@ -127,6 +146,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
127146
spdlog::warn("Setting sample rate to {0}", _this->sampleRate);
128147
_this->client.setFrequency(_this->freq);
129148
_this->client.setSampleRate(_this->sampleRate);
149+
_this->client.setPPM(_this->ppm);
130150
_this->client.setDirectSampling(_this->directSamplingMode);
131151
_this->client.setAGCMode(_this->rtlAGC);
132152
_this->client.setBiasTee(_this->biasTee);
@@ -191,6 +211,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
191211
if (ImGui::Combo(CONCAT("##_rtltcp_sr_", _this->name), &_this->srId, _this->srTxt.c_str())) {
192212
_this->sampleRate = sampleRates[_this->srId];
193213
core::setInputSampleRate(_this->sampleRate);
214+
config.acquire();
215+
config.conf["sampleRate"] = _this->sampleRate;
216+
config.release(true);
194217
}
195218

196219
if (_this->running) { style::endDisabled(); }
@@ -203,18 +226,39 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
203226
_this->client.setDirectSampling(_this->directSamplingMode);
204227
_this->client.setGainIndex(_this->gain);
205228
}
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);
206244
}
207245

208246
if (ImGui::Checkbox(CONCAT("Bias-T##_biast_select_", _this->name), &_this->biasTee)) {
209247
if (_this->running) {
210248
_this->client.setBiasTee(_this->biasTee);
211249
}
250+
config.acquire();
251+
config.conf["biasTee"] = _this->biasTee;
252+
config.release(true);
212253
}
213254

214255
if (ImGui::Checkbox(CONCAT("Offset Tuning##_biast_select_", _this->name), &_this->offsetTuning)) {
215256
if (_this->running) {
216257
_this->client.setOffsetTuning(_this->offsetTuning);
217258
}
259+
config.acquire();
260+
config.conf["offsetTuning"] = _this->offsetTuning;
261+
config.release(true);
218262
}
219263

220264
if (ImGui::Checkbox("RTL AGC", &_this->rtlAGC)) {
@@ -224,6 +268,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
224268
_this->client.setGainIndex(_this->gain);
225269
}
226270
}
271+
config.acquire();
272+
config.conf["rtlAGC"] = _this->rtlAGC;
273+
config.release(true);
227274
}
228275

229276
if (ImGui::Checkbox("Tuner AGC", &_this->tunerAGC)) {
@@ -233,6 +280,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
233280
_this->client.setGainIndex(_this->gain);
234281
}
235282
}
283+
config.acquire();
284+
config.conf["tunerAGC"] = _this->tunerAGC;
285+
config.release(true);
236286
}
237287

238288
if (_this->tunerAGC) { style::beginDisabled(); }
@@ -241,6 +291,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
241291
if (_this->running) {
242292
_this->client.setGainIndex(_this->gain);
243293
}
294+
config.acquire();
295+
config.conf["gainIndex"] = _this->gain;
296+
config.release(true);
244297
}
245298
if (_this->tunerAGC) { style::endDisabled(); }
246299
}
@@ -275,6 +328,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
275328
char ip[1024] = "localhost";
276329
int port = 1234;
277330
int gain = 0;
331+
int ppm = 0;
278332
bool rtlAGC = false;
279333
bool tunerAGC = false;
280334
int directSamplingMode = 0;
@@ -290,7 +344,9 @@ MOD_EXPORT void _INIT_() {
290344
json defConf;
291345
defConf["host"] = "localhost";
292346
defConf["port"] = 1234;
347+
defConf["sampleRate"] = 2400000.0;
293348
defConf["directSamplingMode"] = 0;
349+
defConf["ppm"] = 0;
294350
defConf["rtlAGC"] = false;
295351
defConf["tunerAGC"] = false;
296352
defConf["gainIndex"] = 0;
@@ -306,6 +362,12 @@ MOD_EXPORT void _INIT_() {
306362
if (!config.conf.contains("offsetTuning")) {
307363
config.conf["offsetTuning"] = false;
308364
}
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+
}
309371
config.release(true);
310372
}
311373

rtl_tcp_source/src/rtltcp_client.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ class RTLTCPClient {
166166
sendCommand(4, gain);
167167
}
168168

169+
void setPPM(int ppm) {
170+
sendCommand(5, (uint32_t)ppm);
171+
}
172+
169173
void setAGCMode(int mode) {
170174
sendCommand(8, mode);
171175
}

0 commit comments

Comments
 (0)