@@ -48,15 +48,18 @@ const char* sampleRatesTxt[] = {
4848 " 3.2MHz"
4949};
5050
51+ #define SAMPLE_RATE_COUNT (sizeof (sampleRates) / sizeof (double ))
52+
5153class RTLTCPSourceModule : public ModuleManager ::Instance {
5254public:
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
0 commit comments