-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
What type of issue is this?
permanent - occurring repeatedly
What issue are you facing?
After changing the frequency in my C++ application (using libhackrf), the expected block header 0x7F 0x7F is not the first two bytes of the data buffer. Instead, it consistently appears at an offset of 15872 bytes. This behavior is reproducible on a Raspberry Pi Zero 2W but does not seem to occur on a Raspberry Pi 4.
What are the steps to reproduce this?
Steps to Reproduce
- Initialize HackRF device and libhackrf.
- Set a specific frequency and sample rate.
- Initialize sweep mode, start sweep mode
- Run 10 seconds
- Stop, change frequency, start sweep mode
- Check sweep mode
C++ code
#include <hackrf.h>
#include <iostream>
#include <thread>
#include <chrono>
#define EXPECTED_BLOCKS 262144
static bool sweep_running = true;
static int iteration = 0;
static int rx_callback(hackrf_transfer* transfer) {
iteration++;
if (iteration % 10000 == 0) {
std::cout << "Iteration: " << iteration << std::endl;
}
if (transfer->valid_length != EXPECTED_BLOCKS) {
std::cerr << "[" << iteration << "] Received less than " << EXPECTED_BLOCKS << " bytes; valid_length=" << transfer->valid_length << std::endl;
}
int8_t* buf = (int8_t*) transfer->buffer;
uint8_t* ubuf = (uint8_t*) buf;
for (size_t i = 0; i < EXPECTED_BLOCKS - 1; ++i) {
if (ubuf[i] == 0x7F && ubuf[i + 1] == 0x7F) {
if (i != 0) {
std::cout << "[" << iteration << "] 7F 7F found at offset: " << i << std::endl;
}
break;
}
}
return sweep_running ? 0 : -1;
}
bool run_sweep(hackrf_device* device, uint16_t* frequencies, size_t freq_len) {
sweep_running = true;
iteration = 0;
auto res = hackrf_init_sweep(device, frequencies, freq_len, BYTES_PER_BLOCK, 20000000, 0, LINEAR);
if (res != HACKRF_SUCCESS) {
std::cerr << "Failed to initialize sweep: " << hackrf_error_name((hackrf_error)res) << std::endl;
return false;
}
int ret = hackrf_start_rx_sweep(device, rx_callback, nullptr);
if (ret != HACKRF_SUCCESS) {
std::cerr << "Failed to start sweep: " << hackrf_error_name((hackrf_error)ret) << std::endl;
return false;
}
std::this_thread::sleep_for(std::chrono::seconds(10)); // Use 10s for demo; adjust as needed
sweep_running = false;
hackrf_stop_rx(device);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
return true;
}
int main() {
hackrf_device* device = nullptr;
if (hackrf_init() != HACKRF_SUCCESS) {
std::cerr << "hackrf_init failed\n";
return -1;
}
if (hackrf_open(&device) != HACKRF_SUCCESS || device == nullptr) {
std::cerr << "Failed to open HackRF device\n";
hackrf_exit();
return -1;
}
hackrf_set_sample_rate(device, 20000000);
hackrf_set_lna_gain(device, 16);
hackrf_set_vga_gain(device, 20);
hackrf_set_amp_enable(device, 0);
// First sweep
uint16_t frequencies1[2] = {5000, 5300}; // MHz
std::cout << "Starting sweep 1..." << std::endl;
if (!run_sweep(device, frequencies1, 2)) {
std::cerr << "Sweep 1 failed" << std::endl;
hackrf_close(device);
hackrf_exit();
return -1;
}
std::cout << "Sweep 1 completed successfully" << std::endl;
// Full reset and re-initialization
hackrf_close(device);
hackrf_exit();
if (hackrf_init() != HACKRF_SUCCESS) {
std::cerr << "hackrf_init failed after reset\n";
return -1;
}
if (hackrf_open(&device) != HACKRF_SUCCESS || device == nullptr) {
std::cerr << "Failed to re-open HackRF device\n";
hackrf_exit();
return -1;
}
hackrf_set_sample_rate(device, 20000000);
hackrf_set_lna_gain(device, 16);
hackrf_set_vga_gain(device, 20);
hackrf_set_amp_enable(device, 0);
std::cout << "HackRF device re-initialized successfully" << std::endl;
// Second sweep with different frequencies
uint16_t frequencies2[2] = {6000, 6300}; // MHz
std::cout << "Starting sweep 2..." << std::endl;
if (!run_sweep(device, frequencies2, 2)) {
std::cerr << "Sweep 2 failed" << std::endl;
hackrf_close(device);
hackrf_exit();
return -1;
}
std::cout << "Sweep 2 completed successfully" << std::endl;
hackrf_close(device);
hackrf_exit();
return 0;
}
Can you provide any logs? (output, errors, etc.)
Operating system:
pi@rasp:~ $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
pi@rasp:~ $ lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Vendor Specific Class, Driver=usbfs, 480M
pi@rasp:~ $ ldconfig -p | grep libusb
libusb-1.0.so.0 (libc6,AArch64) => /lib/aarch64-linux-gnu/libusb-1.0.so.0
pi@rasp:~ $ dpkg -s libusb-1.0-0 | grep Version
Version: 2:1.0.26-1
hackrf_info output:
hackrf_info version: 2024.02.1
libhackrf version: 2024.02.1 (0.9)
Found HackRF
Index: 0
Serial number: 0000000000000000a31c64dc2160920f
Board ID Number: 2 (HackRF One)
Firmware Version: 2024.02.1 (API:1.08)
Part ID Number: 0xa000cb3c 0x004f475a
Hardware Revision: older than r6
Hardware supported by installed firmware:
HackRF One
I have collected two libusb debug log files for analysis:
libusb_debug.log: Collected on the Raspberry Pi Zero 2W, where the issue is reproducible
libusb_debug_nonrepro_1.log: Collected on the Raspberry Pi 4
Metadata
Metadata
Assignees
Labels
No labels