Skip to content

Commit

Permalink
Fixed LimeSDR + Fixed FFTSize bug + added ppm option to RTL-SDR & RTL…
Browse files Browse the repository at this point in the history
…-TCP + Fixed RTL-TCP not saving settings
  • Loading branch information
Ryzerth committed Aug 9, 2021
1 parent 9eb3ef0 commit dcc17cd
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
7 changes: 6 additions & 1 deletion core/src/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ void MainWindow::fftHandler(dsp::complex_t* samples, int count, void* ctx) {
MainWindow* _this = (MainWindow*)ctx;
std::lock_guard<std::mutex> lck(_this->fft_mtx);

// Check if the count is valid
if (count > _this->fftSize) {
return;
}

// Apply window
volk_32fc_32f_multiply_32fc((lv_32fc_t*)_this->fft_in, (lv_32fc_t*)samples, sigpath::signalPath.fftTaps, count);

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

fftwf_destroy_plan(fftwPlan);
fftwf_free(fft_in);
fftwf_free(fft_out);
fftwf_destroy_plan(fftwPlan);

fft_in = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);
fft_out = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);
Expand Down
2 changes: 1 addition & 1 deletion core/src/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#define VERSION_STR "1.0.2"
#define VERSION_STR "1.0.3"
2 changes: 1 addition & 1 deletion limesdr_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class LimeSDRSourceModule : public ModuleManager::Instance {
// Setup and start stream
int sampCount = _this->sampleRate / 200;
_this->devStream.isTx = false;
_this->devStream.channel = 0;
_this->devStream.channel = _this->chanId;
_this->devStream.fifoSize = sampCount; // TODO: Check what it's actually supposed to be
_this->devStream.throughputVsLatency = 0.5f;
_this->devStream.dataFmt = _this->devStream.LMS_FMT_F32;
Expand Down
23 changes: 23 additions & 0 deletions rtl_sdr_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
created = true;
config.conf["devices"][selectedDevName]["sampleRate"] = 2400000.0;
config.conf["devices"][selectedDevName]["directSampling"] = directSamplingMode;
config.conf["devices"][selectedDevName]["ppm"] = 0;
config.conf["devices"][selectedDevName]["biasT"] = biasT;
config.conf["devices"][selectedDevName]["offsetTuning"] = offsetTuning;
config.conf["devices"][selectedDevName]["rtlAgc"] = rtlAgc;
Expand All @@ -187,6 +188,10 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
directSamplingMode = config.conf["devices"][selectedDevName]["directSampling"];
}

if (config.conf["devices"][selectedDevName].contains("ppm")) {
ppm = config.conf["devices"][selectedDevName]["ppm"];
}

if (config.conf["devices"][selectedDevName].contains("biasT")) {
biasT = config.conf["devices"][selectedDevName]["biasT"];
}
Expand Down Expand Up @@ -256,6 +261,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance {

rtlsdr_set_sample_rate(_this->openDev, _this->sampleRate);
rtlsdr_set_center_freq(_this->openDev, _this->freq);
rtlsdr_set_freq_correction(_this->openDev, _this->ppm);
rtlsdr_set_tuner_bandwidth(_this->openDev, 0);
rtlsdr_set_direct_sampling(_this->openDev, _this->directSamplingMode);
rtlsdr_set_bias_tee(_this->openDev, _this->biasT);
Expand Down Expand Up @@ -372,6 +378,21 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
}
}

ImGui::Text("PPM Correction");
ImGui::SameLine();
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
if (ImGui::InputInt(CONCAT("##_rtlsdr_ppm_", _this->name), &_this->ppm, 1, 10)) {
_this->ppm = std::clamp<int>(_this->ppm, -1000000, 1000000);
if (_this->running) {
rtlsdr_set_freq_correction(_this->openDev, _this->ppm);
}
if (_this->selectedDevName != "") {
config.acquire();
config.conf["devices"][_this->selectedDevName]["ppm"] = _this->ppm;
config.release(true);
}
}

if (ImGui::Checkbox(CONCAT("Bias T##_rtlsdr_rtl_biast_", _this->name), &_this->biasT)) {
if (_this->running) {
rtlsdr_set_bias_tee(_this->openDev, _this->biasT);
Expand Down Expand Up @@ -471,6 +492,8 @@ class RTLSDRSourceModule : public ModuleManager::Instance {
int devCount = 0;
std::thread workerThread;

int ppm = 0;

bool biasT = false;

int gainId = 0;
Expand Down
66 changes: 64 additions & 2 deletions rtl_tcp_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ const char* sampleRatesTxt[] = {
"3.2MHz"
};

#define SAMPLE_RATE_COUNT (sizeof(sampleRates) / sizeof(double))

class RTLTCPSourceModule : public ModuleManager::Instance {
public:
RTLTCPSourceModule(std::string name) {
this->name = name;

sampleRate = 2400000.0;

int srCount = sizeof(sampleRatesTxt) / sizeof(char*);
for (int i = 0; i < srCount; i++) {
int _24id = 0;
for (int i = 0; i < SAMPLE_RATE_COUNT; i++) {
if (sampleRates[i] == 2400000) { _24id = i; }
srTxt += sampleRatesTxt[i];
srTxt += '\0';
}
Expand All @@ -65,7 +68,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
config.acquire();
std::string hostStr = config.conf["host"];
port = config.conf["port"];
double wantedSr = config.conf["sampleRate"];
directSamplingMode = config.conf["directSamplingMode"];
ppm = config.conf["ppm"];
rtlAGC = config.conf["rtlAGC"];
tunerAGC = config.conf["tunerAGC"];
gain = std::clamp<int>(config.conf["gainIndex"], 0, 28);
Expand All @@ -75,6 +80,20 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
strcpy(ip, hostStr.c_str());
config.release();

bool found = false;
for (int i = 0; i < SAMPLE_RATE_COUNT; i++) {
if (sampleRates[i] == wantedSr) {
found = true;
srId = i;
sampleRate = sampleRates[i];
break;
}
}
if (!found) {
srId = _24id;
sampleRate = sampleRates[_24id];
}

handler.ctx = this;
handler.selectHandler = menuSelected;
handler.deselectHandler = menuDeselected;
Expand Down Expand Up @@ -127,6 +146,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
spdlog::warn("Setting sample rate to {0}", _this->sampleRate);
_this->client.setFrequency(_this->freq);
_this->client.setSampleRate(_this->sampleRate);
_this->client.setPPM(_this->ppm);
_this->client.setDirectSampling(_this->directSamplingMode);
_this->client.setAGCMode(_this->rtlAGC);
_this->client.setBiasTee(_this->biasTee);
Expand Down Expand Up @@ -191,6 +211,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
if (ImGui::Combo(CONCAT("##_rtltcp_sr_", _this->name), &_this->srId, _this->srTxt.c_str())) {
_this->sampleRate = sampleRates[_this->srId];
core::setInputSampleRate(_this->sampleRate);
config.acquire();
config.conf["sampleRate"] = _this->sampleRate;
config.release(true);
}

if (_this->running) { style::endDisabled(); }
Expand All @@ -203,18 +226,39 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
_this->client.setDirectSampling(_this->directSamplingMode);
_this->client.setGainIndex(_this->gain);
}
config.acquire();
config.conf["directSamplingMode"] = _this->directSamplingMode;
config.release(true);
}

ImGui::Text("PPM Correction");
ImGui::SameLine();
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
if (ImGui::InputInt(CONCAT("##_rtltcp_ppm_", _this->name), &_this->ppm, 1, 10)) {
if (_this->running) {
_this->client.setPPM(_this->ppm);
}
config.acquire();
config.conf["ppm"] = _this->ppm;
config.release(true);
}

if (ImGui::Checkbox(CONCAT("Bias-T##_biast_select_", _this->name), &_this->biasTee)) {
if (_this->running) {
_this->client.setBiasTee(_this->biasTee);
}
config.acquire();
config.conf["biasTee"] = _this->biasTee;
config.release(true);
}

if (ImGui::Checkbox(CONCAT("Offset Tuning##_biast_select_", _this->name), &_this->offsetTuning)) {
if (_this->running) {
_this->client.setOffsetTuning(_this->offsetTuning);
}
config.acquire();
config.conf["offsetTuning"] = _this->offsetTuning;
config.release(true);
}

if (ImGui::Checkbox("RTL AGC", &_this->rtlAGC)) {
Expand All @@ -224,6 +268,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
_this->client.setGainIndex(_this->gain);
}
}
config.acquire();
config.conf["rtlAGC"] = _this->rtlAGC;
config.release(true);
}

if (ImGui::Checkbox("Tuner AGC", &_this->tunerAGC)) {
Expand All @@ -233,6 +280,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
_this->client.setGainIndex(_this->gain);
}
}
config.acquire();
config.conf["tunerAGC"] = _this->tunerAGC;
config.release(true);
}

if (_this->tunerAGC) { style::beginDisabled(); }
Expand All @@ -241,6 +291,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
if (_this->running) {
_this->client.setGainIndex(_this->gain);
}
config.acquire();
config.conf["gainIndex"] = _this->gain;
config.release(true);
}
if (_this->tunerAGC) { style::endDisabled(); }
}
Expand Down Expand Up @@ -275,6 +328,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance {
char ip[1024] = "localhost";
int port = 1234;
int gain = 0;
int ppm = 0;
bool rtlAGC = false;
bool tunerAGC = false;
int directSamplingMode = 0;
Expand All @@ -290,7 +344,9 @@ MOD_EXPORT void _INIT_() {
json defConf;
defConf["host"] = "localhost";
defConf["port"] = 1234;
defConf["sampleRate"] = 2400000.0;
defConf["directSamplingMode"] = 0;
defConf["ppm"] = 0;
defConf["rtlAGC"] = false;
defConf["tunerAGC"] = false;
defConf["gainIndex"] = 0;
Expand All @@ -306,6 +362,12 @@ MOD_EXPORT void _INIT_() {
if (!config.conf.contains("offsetTuning")) {
config.conf["offsetTuning"] = false;
}
if (!config.conf.contains("ppm")) {
config.conf["ppm"] = 0;
}
if (!config.conf.contains("sampleRate")) {
config.conf["sampleRate"] = 2400000.0;
}
config.release(true);
}

Expand Down
4 changes: 4 additions & 0 deletions rtl_tcp_source/src/rtltcp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ class RTLTCPClient {
sendCommand(4, gain);
}

void setPPM(int ppm) {
sendCommand(5, (uint32_t)ppm);
}

void setAGCMode(int mode) {
sendCommand(8, mode);
}
Expand Down

0 comments on commit dcc17cd

Please sign in to comment.