Fix gains and valid SDR error

This commit is contained in:
30hours 2024-05-12 13:44:54 +00:00
parent 3b670a740f
commit a72a89a468
4 changed files with 21 additions and 16 deletions

View file

@ -12,7 +12,7 @@ capture:
replay:
state: false
loop: true
file: '/opt/blah2/replay/file.hackrf'
file: '/opt/blah2/replay/file.kraken'
process:
data:

View file

@ -8,7 +8,7 @@
#include <httplib.h>
// constants
const std::vector<std::string> 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<Source> Capture::factory_source(const std::string& type, c4::yml
serial, gainLna, gainVga, ampEnable);
}
// Kraken
// else if (type == VALID_TYPE[3])
// {
// std::vector<double> gain;
// float _gain;
// for (auto child : config["gain"].children())
// {
// c4::atof(child.val(), &_gain);
// gain.push_back(static_cast<double>(_gain));
// }
// return std::make_unique<Kraken>(type, fc, fs, path, &saveIq, gain);
// }
else if (type == VALID_TYPE[3])
{
std::vector<double> gain;
float _gain;
for (auto child : config["gain"].children())
{
c4::atof(child.val(), &_gain);
gain.push_back(static_cast<double>(_gain));
}
return std::make_unique<Kraken>(type, fc, fs, path, &saveIq, gain);
}
// handle unknown type
std::cerr << "Error: Source type does not exist." << std::endl;
return nullptr;

View file

@ -20,7 +20,7 @@ class Capture
{
private:
/// @brief The valid capture devices.
static const std::vector<std::string> VALID_TYPE;
static const std::string VALID_TYPE[4];
/// @brief The capture device type.
std::string type;

View file

@ -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<int>(_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;
}