11#include " config.h"
22
3+ #include < toml/toml.h>
4+
35#include < iostream>
46#include < sstream>
57#include < stdexcept>
68
7- #include < toml/toml.h>
8-
99namespace {
1010
1111void throwInvalidKey (const std::string& key) {
@@ -24,7 +24,8 @@ void setIfZero(T& out, T value) {
2424std::unique_ptr<SamplePublisher> createSamplePublisher (const toml::Value& v) {
2525 auto bind = v.find (" bind" );
2626 if (!bind) {
27- throw std::invalid_argument (" Expected publisher section to have \" bind\" key" );
27+ throw std::invalid_argument (
28+ " Expected publisher section to have \" bind\" key" );
2829 }
2930
3031 // Only need bind value to create publisher
@@ -42,7 +43,8 @@ std::unique_ptr<SamplePublisher> createSamplePublisher(const toml::Value& v) {
4243std::unique_ptr<SoftBitPublisher> createSoftBitPublisher (const toml::Value& v) {
4344 auto bind = v.find (" bind" );
4445 if (!bind) {
45- throw std::invalid_argument (" Expected publisher section to have \" bind\" key" );
46+ throw std::invalid_argument (
47+ " Expected publisher section to have \" bind\" key" );
4648 }
4749
4850 // Only need bind value to create publisher
@@ -60,7 +62,8 @@ std::unique_ptr<SoftBitPublisher> createSoftBitPublisher(const toml::Value& v) {
6062std::unique_ptr<PacketPublisher> createPacketPublisher (const toml::Value& v) {
6163 auto bind = v.find (" bind" );
6264 if (!bind) {
63- throw std::invalid_argument (" Expected publisher section to have \" bind\" key" );
65+ throw std::invalid_argument (
66+ " Expected publisher section to have \" bind\" key" );
6467 }
6568
6669 // Only need bind value to create publisher
@@ -78,7 +81,8 @@ std::unique_ptr<PacketPublisher> createPacketPublisher(const toml::Value& v) {
7881Config::StatsPublisher createStatsPublisher (const toml::Value& v) {
7982 auto bind = v.find (" bind" );
8083 if (!bind) {
81- throw std::invalid_argument (" Expected publisher section to have \" bind\" key" );
84+ throw std::invalid_argument (
85+ " Expected publisher section to have \" bind\" key" );
8286 }
8387
8488 Config::StatsPublisher out;
@@ -198,6 +202,51 @@ void loadRTLSDRSource(Config::RTLSDR& out, const toml::Value& v) {
198202 }
199203}
200204
205+ void loadHackRfSource (Config::HackRf& out, const toml::Value& v) {
206+ const auto & table = v.as <toml::Table>();
207+ for (const auto & it : table) {
208+ const auto & key = it.first ;
209+ const auto & value = it.second ;
210+
211+ if (key == " frequency" ) {
212+ out.frequency = value.as <int >();
213+ continue ;
214+ }
215+
216+ if (key == " sample_rate" ) {
217+ out.sampleRate = value.as <int >();
218+ continue ;
219+ }
220+
221+ if (key == " if_gain" ) {
222+ out.if_gain = value.as <int >();
223+ continue ;
224+ }
225+
226+ if (key == " bb_gain" ) {
227+ out.bb_gain = value.as <int >();
228+ continue ;
229+ }
230+
231+ if (key == " rf_amp_enabled" ) {
232+ out.rf_amp_enabled = value.as <bool >();
233+ continue ;
234+ }
235+
236+ if (key == " sample_publisher" ) {
237+ out.samplePublisher = createSamplePublisher (value);
238+ continue ;
239+ }
240+
241+ if (key == " bias_tee" ) {
242+ out.bias_tee = value.as <bool >();
243+ continue ;
244+ }
245+
246+ throwInvalidKey (key);
247+ }
248+ }
249+
201250void loadNanomsgSource (Config::Nanomsg& out, const toml::Value& v) {
202251 const auto & table = v.as <toml::Table>();
203252 for (const auto & it : table) {
@@ -241,12 +290,12 @@ void loadAGC(Config::AGC& out, const toml::Value& v) {
241290 const auto & value = it.second ;
242291
243292 if (key == " min" ) {
244- out.min = (float ) value.as <double >();
293+ out.min = (float )value.as <double >();
245294 continue ;
246295 }
247296
248297 if (key == " max" ) {
249- out.max = (float ) value.as <double >();
298+ out.max = (float )value.as <double >();
250299 continue ;
251300 }
252301
@@ -266,7 +315,7 @@ void loadCostas(Config::Costas& out, const toml::Value& v) {
266315 const auto & value = it.second ;
267316
268317 if (key == " max_deviation" ) {
269- out.maxDeviation = (int ) value.as <double >();
318+ out.maxDeviation = (int )value.as <double >();
270319 if (out.maxDeviation <= 0 ) {
271320 throw std::invalid_argument (" Expected 'max_deviation' to be positive" );
272321 }
@@ -362,7 +411,7 @@ void loadMonitor(Config::Monitor& out, const toml::Value& v) {
362411 }
363412}
364413
365- } // namespace
414+ } // namespace
366415
367416Config Config::load (const std::string& file) {
368417 Config out;
@@ -392,6 +441,11 @@ Config Config::load(const std::string& file) {
392441 continue ;
393442 }
394443
444+ if (key == " hackrf" ) {
445+ loadHackRfSource (out.hackrf , value);
446+ continue ;
447+ }
448+
395449 if (key == " nanomsg" ) {
396450 loadNanomsgSource (out.nanomsg , value);
397451 continue ;
@@ -446,10 +500,12 @@ Config Config::load(const std::string& file) {
446500 if (out.demodulator .downlinkType == " lrit" ) {
447501 setIfZero (out.airspy .frequency , 1691000000u );
448502 setIfZero (out.rtlsdr .frequency , 1691000000u );
503+ setIfZero (out.hackrf .frequency , 1691000000u );
449504 }
450505 if (out.demodulator .downlinkType == " hrit" ) {
451506 setIfZero (out.airspy .frequency , 1694100000u );
452507 setIfZero (out.rtlsdr .frequency , 1694100000u );
508+ setIfZero (out.hackrf .frequency , 1694100000u );
453509 }
454510
455511 return out;
0 commit comments