From f5e950b649909b6c5539f58f664e920137bef160 Mon Sep 17 00:00:00 2001 From: sdn-ninja Date: Wed, 8 May 2024 21:31:22 +0100 Subject: [PATCH 1/4] Update config-hackrf.yml cosmetic improvement --- config/config-hackrf.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config-hackrf.yml b/config/config-hackrf.yml index cba6840..1df4e45 100644 --- a/config/config-hackrf.yml +++ b/config/config-hackrf.yml @@ -4,8 +4,8 @@ capture: device: type: "HackRF" serial: - - "FIRST_DEVICE_SERIAL_NUMBER" - - "SECOND_DEVICE_SERIAL_NUMBER" + - "REFERENCE_DEVICE_SERIAL_NUMBER" + - "SURVILLANCE_DEVICE_SERIAL_NUMBER" gain_lna: [32, 32] gain_vga: [30, 30] amp_enable: [false, false] @@ -13,7 +13,7 @@ capture: replay: state: false loop: true - file: '/opt/blah2/replay/file.rspduo' + file: '/opt/blah2/replay/file.hackrf' process: data: From ea3011afd1a7b28df69ebb23755cf89b54caefe4 Mon Sep 17 00:00:00 2001 From: sdn-ninja Date: Wed, 8 May 2024 21:42:27 +0100 Subject: [PATCH 2/4] Update HackRf.h fixing data types that didn't work and fixing items that needed to be private/public --- src/capture/hackrf/HackRf.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/capture/hackrf/HackRf.h b/src/capture/hackrf/HackRf.h index 6bb1329..2100f10 100644 --- a/src/capture/hackrf/HackRf.h +++ b/src/capture/hackrf/HackRf.h @@ -33,14 +33,15 @@ private: /// @brief Enable extra amplifier U13 on receive. std::vector ampEnable; - /// @brief Vector of pointers to HackRF devices. - std::vector dev; - /// @brief Check status of HackRF API returns. /// @param status Return code of API call. /// @param message Message if API call error. void check_status(uint8_t status, std::string message); +protected: + /// @brief Array of pointers to HackRF devices. + hackrf_device* dev[2]; + /// @brief Callback function for HackRF samples. /// @param transfer HackRF transfer object. /// @return Void. @@ -81,4 +82,4 @@ public: }; -#endif \ No newline at end of file +#endif From 660618716c82c19fb13c6210198bd73580717ea2 Mon Sep 17 00:00:00 2001 From: sdn-ninja Date: Wed, 8 May 2024 21:54:59 +0100 Subject: [PATCH 3/4] Update HackRf.cpp gainLna and gainVga not populated so insert static values for now. this needs fixing (I presume in blah2.cpp?) fixed the device check, previously it only triggered if 1 device was connected, but not 0 devices. other fixes for using pointers instead of deferenced pointers, etc. --- src/capture/hackrf/HackRf.cpp | 49 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/capture/hackrf/HackRf.cpp b/src/capture/hackrf/HackRf.cpp index 42ad7b5..8b19dab 100644 --- a/src/capture/hackrf/HackRf.cpp +++ b/src/capture/hackrf/HackRf.cpp @@ -56,25 +56,11 @@ void HackRf::start() check_status(status, "Failed to initialise HackRF"); hackrf_device_list_t *list; list = hackrf_device_list(); - if (list->devicecount < 2) + if (!list || list->devicecount < 2) { check_status(-1, "Failed to find 2 HackRF devices."); } - // reference config - status = hackrf_open_by_serial(serial[0].c_str(), &dev[0]); - check_status(status, "Failed to open device."); - status = hackrf_set_freq(dev[0], fc); - check_status(status, "Failed to set frequency."); - status = hackrf_set_sample_rate(dev[0], fs); - check_status(status, "Failed to set sample rate."); - status = hackrf_set_amp_enable(dev[0], ampEnable[0] ? 1 : 0); - check_status(status, "Failed to set AMP status."); - status = hackrf_set_lna_gain(dev[0], gainLna[0]); - check_status(status, "Failed to set LNA gain."); - status = hackrf_set_vga_gain(dev[0], gainVga[0]); - check_status(status, "Failed to set VGA gain."); - // surveillance config status = hackrf_open_by_serial(serial[1].c_str(), &dev[1]); check_status(status, "Failed to open device."); @@ -84,12 +70,31 @@ void HackRf::start() check_status(status, "Failed to set sample rate."); status = hackrf_set_amp_enable(dev[1], ampEnable[1] ? 1 : 0); check_status(status, "Failed to set AMP status."); - status = hackrf_set_lna_gain(dev[1], gainLna[1]); + //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], 32); 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."); status = hackrf_set_hw_sync_mode(dev[1], 1); check_status(status, "Failed to enable hardware synchronising."); + + // reference config + status = hackrf_open_by_serial(serial[0].c_str(), &dev[0]); + check_status(status, "Failed to open device."); + status = hackrf_set_freq(dev[0], fc); + check_status(status, "Failed to set frequency."); + status = hackrf_set_sample_rate(dev[0], fs); + check_status(status, "Failed to set sample rate."); + status = hackrf_set_amp_enable(dev[0], ampEnable[0] ? 1 : 0); + check_status(status, "Failed to set AMP status."); + //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."); + //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."); + } void HackRf::stop() @@ -104,9 +109,9 @@ void HackRf::stop() void HackRf::process(IqData *buffer1, IqData *buffer2) { int status; - 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."); - 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."); } @@ -116,14 +121,14 @@ int HackRf::rx_callback(hackrf_transfer* transfer) int8_t* buffer_hackrf = (int8_t*) transfer->buffer; buffer_blah2->lock(); - - for (size_t i = 0; i < transfer->valid_length; i+2) + + for (size_t i = 0; i < transfer->buffer_length; i=i+2) { double iqi = static_cast(buffer_hackrf[i]); double iqq = static_cast(buffer_hackrf[i+1]); buffer_blah2->push_back({iqi, iqq}); } - + buffer_blah2->unlock(); return 0; From 19132589ed4bcb6a953e3f3360c2dd2b7e90719a Mon Sep 17 00:00:00 2001 From: 30hours Date: Thu, 9 May 2024 11:40:26 +0000 Subject: [PATCH 4/4] Add while loop and make LNA/VGA gain uint32_t --- config/config-hackrf.yml | 1 - src/capture/Capture.cpp | 25 +++++++++++++--------- src/capture/hackrf/HackRf.cpp | 40 +++++++++++++++++------------------ src/capture/hackrf/HackRf.h | 6 +++--- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/config/config-hackrf.yml b/config/config-hackrf.yml index 1df4e45..21a8c9a 100644 --- a/config/config-hackrf.yml +++ b/config/config-hackrf.yml @@ -9,7 +9,6 @@ capture: gain_lna: [32, 32] gain_vga: [30, 30] amp_enable: [false, false] - replay: state: false loop: true diff --git a/src/capture/Capture.cpp b/src/capture/Capture.cpp index f1a7844..ad636d7 100644 --- a/src/capture/Capture.cpp +++ b/src/capture/Capture.cpp @@ -94,23 +94,28 @@ std::unique_ptr Capture::factory_source(const std::string& type, c4::yml else if (type == VALID_TYPE[2]) { std::vector serial; - std::vector gainLna, gainVga; + std::vector gainLna, gainVga; std::vector ampEnable; std::string _serial; - uint8_t _gainLna, _gainVga; + uint32_t gain; + int _gain; bool _ampEnable; config["serial"][0] >> _serial; serial.push_back(_serial); config["serial"][1] >> _serial; serial.push_back(_serial); - config["gain_lna"][0] >> _gainLna; - gainLna.push_back(_gainLna); - config["gain_lna"][1] >> _gainLna; - gainLna.push_back(_gainLna); - config["gain_vga"][0] >> _gainVga; - gainVga.push_back(_gainVga); - config["gain_vga"][1] >> _gainVga; - gainVga.push_back(_gainVga); + config["gain_lna"][0] >> _gain; + gain = static_cast (_gain); + gainLna.push_back(gain); + config["gain_lna"][1] >> _gain; + gain = static_cast(_gain); + gainLna.push_back(gain); + config["gain_vga"][0] >> _gain; + gain = static_cast(_gain); + gainVga.push_back(gain); + config["gain_vga"][1] >> _gain; + gain = static_cast(_gain); + gainVga.push_back(gain); config["amp_enable"][0] >> _ampEnable; ampEnable.push_back(_ampEnable); config["amp_enable"][1] >> _ampEnable; diff --git a/src/capture/hackrf/HackRf.cpp b/src/capture/hackrf/HackRf.cpp index 8b19dab..4aefa01 100644 --- a/src/capture/hackrf/HackRf.cpp +++ b/src/capture/hackrf/HackRf.cpp @@ -8,7 +8,7 @@ // constructor HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs, std::string _path, bool *_saveIq, std::vector _serial, - std::vector _gainLna, std::vector _gainVga, + std::vector _gainLna, std::vector _gainVga, std::vector _ampEnable) : Source(_type, _fc, _fs, _path, _saveIq) { @@ -16,11 +16,11 @@ HackRf::HackRf(std::string _type, uint32_t _fc, uint32_t _fs, ampEnable = _ampEnable; // validate LNA gain - std::unordered_set validLna; - for (uint8_t gain = 0; gain <= 40; gain += 8) { + std::unordered_set validLna; + for (uint32_t gain = 0; gain <= 40; gain += 8) { validLna.insert(gain); } - for (uint8_t gain : _gainLna) { + for (uint32_t gain : _gainLna) { if (validLna.find(gain) == validLna.end()) { 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; // validate VGA gain - std::unordered_set validVga; - for (uint8_t gain = 0; gain <= 62; gain += 2) { + std::unordered_set validVga; + for (uint32_t gain = 0; gain <= 62; gain += 2) { validVga.insert(gain); } - for (uint8_t gain : _gainVga) { + for (uint32_t gain : _gainVga) { if (validVga.find(gain) == validVga.end()) { throw std::invalid_argument("Invalid LNA gain value"); } @@ -70,11 +70,9 @@ void HackRf::start() check_status(status, "Failed to set sample rate."); status = hackrf_set_amp_enable(dev[1], ampEnable[1] ? 1 : 0); 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], 32); + status = hackrf_set_lna_gain(dev[1], gainLna[1]); check_status(status, "Failed to set LNA gain."); - //status = hackrf_set_vga_gain(dev[1], gainVga[1]); - status = hackrf_set_vga_gain(dev[1], 30); + status = hackrf_set_vga_gain(dev[1], gainVga[1]); check_status(status, "Failed to set VGA gain."); status = hackrf_set_hw_sync_mode(dev[1], 1); check_status(status, "Failed to enable hardware synchronising."); @@ -88,13 +86,10 @@ void HackRf::start() check_status(status, "Failed to set sample rate."); status = hackrf_set_amp_enable(dev[0], ampEnable[0] ? 1 : 0); check_status(status, "Failed to set AMP status."); - //status = hackrf_set_lna_gain(dev[0], gainLna[0]); - status = hackrf_set_lna_gain(dev[0], 32); + status = hackrf_set_lna_gain(dev[0], gainLna[0]); check_status(status, "Failed to set LNA gain."); - //status = hackrf_set_vga_gain(dev[0], gainVga[0]); - status = hackrf_set_vga_gain(dev[0], 30); + status = hackrf_set_vga_gain(dev[0], gainVga[0]); check_status(status, "Failed to set VGA gain."); - } void HackRf::stop() @@ -109,10 +104,14 @@ void HackRf::stop() void HackRf::process(IqData *buffer1, IqData *buffer2) { int status; - status = hackrf_start_rx(dev[1], rx_callback, buffer2); - check_status(status, "Failed to start RX streaming."); - status = hackrf_start_rx(dev[0], rx_callback, buffer1); - check_status(status, "Failed to start RX streaming."); + + while (true) + { + status = hackrf_start_rx(dev[1], rx_callback, buffer2); + check_status(status, "Failed to start RX streaming."); + status = hackrf_start_rx(dev[0], rx_callback, buffer1); + check_status(status, "Failed to start RX streaming."); + } } int HackRf::rx_callback(hackrf_transfer* transfer) @@ -138,3 +137,4 @@ void HackRf::replay(IqData *buffer1, IqData *buffer2, std::string _file, bool _l { return; } + diff --git a/src/capture/hackrf/HackRf.h b/src/capture/hackrf/HackRf.h index 2100f10..42bbb74 100644 --- a/src/capture/hackrf/HackRf.h +++ b/src/capture/hackrf/HackRf.h @@ -25,10 +25,10 @@ private: std::vector serial; /// @brief RX LNA (IF) gain, 0-40dB, 8dB steps. - std::vector gainLna; + std::vector gainLna; /// @brief RX VGA (baseband) gain, 0-62dB, 2dB steps. - std::vector gainVga; + std::vector gainVga; /// @brief Enable extra amplifier U13 on receive. std::vector ampEnable; @@ -55,7 +55,7 @@ public: /// @return The object. HackRf(std::string type, uint32_t fc, uint32_t fs, std::string path, bool *saveIq, std::vector serial, - std::vector gainLna, std::vector gainVga, + std::vector gainLna, std::vector gainVga, std::vector ampEnable); /// @brief Implement capture function on HackRF.