From a72a89a468ff3611e121d3da0b0ea1dd0df17bc8 Mon Sep 17 00:00:00 2001 From: 30hours Date: Sun, 12 May 2024 13:44:54 +0000 Subject: [PATCH] Fix gains and valid SDR error --- config/config-kraken.yml | 2 +- src/capture/Capture.cpp | 24 ++++++++++++------------ src/capture/Capture.h | 2 +- src/capture/kraken/Kraken.cpp | 9 +++++++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/config/config-kraken.yml b/config/config-kraken.yml index ef44faf..aed4480 100644 --- a/config/config-kraken.yml +++ b/config/config-kraken.yml @@ -12,7 +12,7 @@ capture: replay: state: false loop: true - file: '/opt/blah2/replay/file.hackrf' + file: '/opt/blah2/replay/file.kraken' process: data: diff --git a/src/capture/Capture.cpp b/src/capture/Capture.cpp index 0eb0d1a..b734528 100644 --- a/src/capture/Capture.cpp +++ b/src/capture/Capture.cpp @@ -8,7 +8,7 @@ #include // constants -const std::vector Capture::VALID_TYPE = {"RspDuo", "Usrp", "HackRF", "Kraken"}; +const std::string Capture::VALID_TYPE[4] = {"RspDuo", "Usrp", "HackRF", "Kraken"}; // constructor Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _path) @@ -127,17 +127,17 @@ std::unique_ptr Capture::factory_source(const std::string& type, c4::yml serial, gainLna, gainVga, ampEnable); } // Kraken - // else if (type == VALID_TYPE[3]) - // { - // std::vector gain; - // float _gain; - // for (auto child : config["gain"].children()) - // { - // c4::atof(child.val(), &_gain); - // gain.push_back(static_cast(_gain)); - // } - // return std::make_unique(type, fc, fs, path, &saveIq, gain); - // } + else if (type == VALID_TYPE[3]) + { + std::vector gain; + float _gain; + for (auto child : config["gain"].children()) + { + c4::atof(child.val(), &_gain); + gain.push_back(static_cast(_gain)); + } + return std::make_unique(type, fc, fs, path, &saveIq, gain); + } // handle unknown type std::cerr << "Error: Source type does not exist." << std::endl; return nullptr; diff --git a/src/capture/Capture.h b/src/capture/Capture.h index dddc7a1..9994d4b 100644 --- a/src/capture/Capture.h +++ b/src/capture/Capture.h @@ -20,7 +20,7 @@ class Capture { private: /// @brief The valid capture devices. - static const std::vector VALID_TYPE; + static const std::string VALID_TYPE[4]; /// @brief The capture device type. std::string type; diff --git a/src/capture/kraken/Kraken.cpp b/src/capture/kraken/Kraken.cpp index bc04b74..b85b971 100644 --- a/src/capture/kraken/Kraken.cpp +++ b/src/capture/kraken/Kraken.cpp @@ -32,8 +32,13 @@ Kraken::Kraken(std::string _type, uint32_t _fc, uint32_t _fs, for (int i = 0; i <= _gain.size(); i++) { int adjustedGain = static_cast(_gain[i] * 10); - gain.push_back(std::lower_bound(validGains.begin(), - validGains.end(), adjustedGain)); + auto it = std::lower_bound(validGains.begin(), + validGains.end(), adjustedGain); + if (it != validGains.end()) { + gain.push_back(*it); + } else { + gain.push_back(validGains.back()); + } std::cout << "[Kraken] Gain update on channel " << i << " from " << adjustedGain << " to " << gain[i] << "." << std::endl; }