mirror of
https://github.com/30hours/blah2.git
synced 2024-11-08 12:25:42 +00:00
Add while loop and make LNA/VGA gain uint32_t
This commit is contained in:
parent
660618716c
commit
19132589ed
4 changed files with 38 additions and 34 deletions
|
@ -9,7 +9,6 @@ capture:
|
||||||
gain_lna: [32, 32]
|
gain_lna: [32, 32]
|
||||||
gain_vga: [30, 30]
|
gain_vga: [30, 30]
|
||||||
amp_enable: [false, false]
|
amp_enable: [false, false]
|
||||||
|
|
||||||
replay:
|
replay:
|
||||||
state: false
|
state: false
|
||||||
loop: true
|
loop: true
|
||||||
|
|
|
@ -94,23 +94,28 @@ std::unique_ptr<Source> Capture::factory_source(const std::string& type, c4::yml
|
||||||
else if (type == VALID_TYPE[2])
|
else if (type == VALID_TYPE[2])
|
||||||
{
|
{
|
||||||
std::vector<std::string> serial;
|
std::vector<std::string> serial;
|
||||||
std::vector<uint8_t> gainLna, gainVga;
|
std::vector<uint32_t> gainLna, gainVga;
|
||||||
std::vector<bool> ampEnable;
|
std::vector<bool> ampEnable;
|
||||||
std::string _serial;
|
std::string _serial;
|
||||||
uint8_t _gainLna, _gainVga;
|
uint32_t gain;
|
||||||
|
int _gain;
|
||||||
bool _ampEnable;
|
bool _ampEnable;
|
||||||
config["serial"][0] >> _serial;
|
config["serial"][0] >> _serial;
|
||||||
serial.push_back(_serial);
|
serial.push_back(_serial);
|
||||||
config["serial"][1] >> _serial;
|
config["serial"][1] >> _serial;
|
||||||
serial.push_back(_serial);
|
serial.push_back(_serial);
|
||||||
config["gain_lna"][0] >> _gainLna;
|
config["gain_lna"][0] >> _gain;
|
||||||
gainLna.push_back(_gainLna);
|
gain = static_cast<uint32_t> (_gain);
|
||||||
config["gain_lna"][1] >> _gainLna;
|
gainLna.push_back(gain);
|
||||||
gainLna.push_back(_gainLna);
|
config["gain_lna"][1] >> _gain;
|
||||||
config["gain_vga"][0] >> _gainVga;
|
gain = static_cast<uint32_t>(_gain);
|
||||||
gainVga.push_back(_gainVga);
|
gainLna.push_back(gain);
|
||||||
config["gain_vga"][1] >> _gainVga;
|
config["gain_vga"][0] >> _gain;
|
||||||
gainVga.push_back(_gainVga);
|
gain = static_cast<uint32_t>(_gain);
|
||||||
|
gainVga.push_back(gain);
|
||||||
|
config["gain_vga"][1] >> _gain;
|
||||||
|
gain = static_cast<uint32_t>(_gain);
|
||||||
|
gainVga.push_back(gain);
|
||||||
config["amp_enable"][0] >> _ampEnable;
|
config["amp_enable"][0] >> _ampEnable;
|
||||||
ampEnable.push_back(_ampEnable);
|
ampEnable.push_back(_ampEnable);
|
||||||
config["amp_enable"][1] >> _ampEnable;
|
config["amp_enable"][1] >> _ampEnable;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// constructor
|
// constructor
|
||||||
HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs,
|
HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs,
|
||||||
std::string _path, bool *_saveIq, std::vector<std::string> _serial,
|
std::string _path, bool *_saveIq, std::vector<std::string> _serial,
|
||||||
std::vector<uint8_t> _gainLna, std::vector<uint8_t> _gainVga,
|
std::vector<uint32_t> _gainLna, std::vector<uint32_t> _gainVga,
|
||||||
std::vector<bool> _ampEnable)
|
std::vector<bool> _ampEnable)
|
||||||
: Source(_type, _fc, _fs, _path, _saveIq)
|
: Source(_type, _fc, _fs, _path, _saveIq)
|
||||||
{
|
{
|
||||||
|
@ -16,11 +16,11 @@ HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs,
|
||||||
ampEnable = _ampEnable;
|
ampEnable = _ampEnable;
|
||||||
|
|
||||||
// validate LNA gain
|
// validate LNA gain
|
||||||
std::unordered_set<uint8_t> validLna;
|
std::unordered_set<uint32_t> validLna;
|
||||||
for (uint8_t gain = 0; gain <= 40; gain += 8) {
|
for (uint32_t gain = 0; gain <= 40; gain += 8) {
|
||||||
validLna.insert(gain);
|
validLna.insert(gain);
|
||||||
}
|
}
|
||||||
for (uint8_t gain : _gainLna) {
|
for (uint32_t gain : _gainLna) {
|
||||||
if (validLna.find(gain) == validLna.end()) {
|
if (validLna.find(gain) == validLna.end()) {
|
||||||
throw std::invalid_argument("Invalid LNA gain value");
|
throw std::invalid_argument("Invalid LNA gain value");
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,11 @@ HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs,
|
||||||
gainLna = _gainLna;
|
gainLna = _gainLna;
|
||||||
|
|
||||||
// validate VGA gain
|
// validate VGA gain
|
||||||
std::unordered_set<uint8_t> validVga;
|
std::unordered_set<uint32_t> validVga;
|
||||||
for (uint8_t gain = 0; gain <= 62; gain += 2) {
|
for (uint32_t gain = 0; gain <= 62; gain += 2) {
|
||||||
validVga.insert(gain);
|
validVga.insert(gain);
|
||||||
}
|
}
|
||||||
for (uint8_t gain : _gainVga) {
|
for (uint32_t gain : _gainVga) {
|
||||||
if (validVga.find(gain) == validVga.end()) {
|
if (validVga.find(gain) == validVga.end()) {
|
||||||
throw std::invalid_argument("Invalid LNA gain value");
|
throw std::invalid_argument("Invalid LNA gain value");
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,9 @@ void HackRf::start()
|
||||||
check_status(status, "Failed to set sample rate.");
|
check_status(status, "Failed to set sample rate.");
|
||||||
status = hackrf_set_amp_enable(dev[1], ampEnable[1] ? 1 : 0);
|
status = hackrf_set_amp_enable(dev[1], ampEnable[1] ? 1 : 0);
|
||||||
check_status(status, "Failed to set AMP status.");
|
check_status(status, "Failed to set AMP status.");
|
||||||
//status = hackrf_set_lna_gain(dev[1], gainLna[1]); //needs fixing + 3 others below.. var isn't populated
|
status = hackrf_set_lna_gain(dev[1], gainLna[1]);
|
||||||
status = hackrf_set_lna_gain(dev[1], 32);
|
|
||||||
check_status(status, "Failed to set LNA gain.");
|
check_status(status, "Failed to set LNA gain.");
|
||||||
//status = hackrf_set_vga_gain(dev[1], gainVga[1]);
|
status = hackrf_set_vga_gain(dev[1], gainVga[1]);
|
||||||
status = hackrf_set_vga_gain(dev[1], 30);
|
|
||||||
check_status(status, "Failed to set VGA gain.");
|
check_status(status, "Failed to set VGA gain.");
|
||||||
status = hackrf_set_hw_sync_mode(dev[1], 1);
|
status = hackrf_set_hw_sync_mode(dev[1], 1);
|
||||||
check_status(status, "Failed to enable hardware synchronising.");
|
check_status(status, "Failed to enable hardware synchronising.");
|
||||||
|
@ -88,13 +86,10 @@ void HackRf::start()
|
||||||
check_status(status, "Failed to set sample rate.");
|
check_status(status, "Failed to set sample rate.");
|
||||||
status = hackrf_set_amp_enable(dev[0], ampEnable[0] ? 1 : 0);
|
status = hackrf_set_amp_enable(dev[0], ampEnable[0] ? 1 : 0);
|
||||||
check_status(status, "Failed to set AMP status.");
|
check_status(status, "Failed to set AMP status.");
|
||||||
//status = hackrf_set_lna_gain(dev[0], gainLna[0]);
|
status = hackrf_set_lna_gain(dev[0], gainLna[0]);
|
||||||
status = hackrf_set_lna_gain(dev[0], 32);
|
|
||||||
check_status(status, "Failed to set LNA gain.");
|
check_status(status, "Failed to set LNA gain.");
|
||||||
//status = hackrf_set_vga_gain(dev[0], gainVga[0]);
|
status = hackrf_set_vga_gain(dev[0], gainVga[0]);
|
||||||
status = hackrf_set_vga_gain(dev[0], 30);
|
|
||||||
check_status(status, "Failed to set VGA gain.");
|
check_status(status, "Failed to set VGA gain.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HackRf::stop()
|
void HackRf::stop()
|
||||||
|
@ -109,11 +104,15 @@ void HackRf::stop()
|
||||||
void HackRf::process(IqData *buffer1, IqData *buffer2)
|
void HackRf::process(IqData *buffer1, IqData *buffer2)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
status = hackrf_start_rx(dev[1], rx_callback, buffer2);
|
status = hackrf_start_rx(dev[1], rx_callback, buffer2);
|
||||||
check_status(status, "Failed to start RX streaming.");
|
check_status(status, "Failed to start RX streaming.");
|
||||||
status = hackrf_start_rx(dev[0], rx_callback, buffer1);
|
status = hackrf_start_rx(dev[0], rx_callback, buffer1);
|
||||||
check_status(status, "Failed to start RX streaming.");
|
check_status(status, "Failed to start RX streaming.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int HackRf::rx_callback(hackrf_transfer* transfer)
|
int HackRf::rx_callback(hackrf_transfer* transfer)
|
||||||
{
|
{
|
||||||
|
@ -138,3 +137,4 @@ void HackRf::replay(IqData *buffer1, IqData *buffer2, std::string _file, bool _l
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ private:
|
||||||
std::vector<std::string> serial;
|
std::vector<std::string> serial;
|
||||||
|
|
||||||
/// @brief RX LNA (IF) gain, 0-40dB, 8dB steps.
|
/// @brief RX LNA (IF) gain, 0-40dB, 8dB steps.
|
||||||
std::vector<uint8_t> gainLna;
|
std::vector<uint32_t> gainLna;
|
||||||
|
|
||||||
/// @brief RX VGA (baseband) gain, 0-62dB, 2dB steps.
|
/// @brief RX VGA (baseband) gain, 0-62dB, 2dB steps.
|
||||||
std::vector<uint8_t> gainVga;
|
std::vector<uint32_t> gainVga;
|
||||||
|
|
||||||
/// @brief Enable extra amplifier U13 on receive.
|
/// @brief Enable extra amplifier U13 on receive.
|
||||||
std::vector<bool> ampEnable;
|
std::vector<bool> ampEnable;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
/// @return The object.
|
/// @return The object.
|
||||||
HackRf(std::string type, uint32_t fc, uint32_t fs, std::string path,
|
HackRf(std::string type, uint32_t fc, uint32_t fs, std::string path,
|
||||||
bool *saveIq, std::vector<std::string> serial,
|
bool *saveIq, std::vector<std::string> serial,
|
||||||
std::vector<uint8_t> gainLna, std::vector<uint8_t> gainVga,
|
std::vector<uint32_t> gainLna, std::vector<uint32_t> gainVga,
|
||||||
std::vector<bool> ampEnable);
|
std::vector<bool> ampEnable);
|
||||||
|
|
||||||
/// @brief Implement capture function on HackRF.
|
/// @brief Implement capture function on HackRF.
|
||||||
|
|
Loading…
Reference in a new issue