-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for HackRF One #57
Conversation
… along with the rest of the project.
I tested this and it works! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A couple of minor things I'll fix when merging.
I don't have hardware to test on, but it compiles OK and "runs" (up to the point of failing to find hardware) OK.
status = hackrf_init(); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_init failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_open(&HackRF.device); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_open failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_set_freq(HackRF.device, HackRF.freq); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_set_freq failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_set_sample_rate(HackRF.device, HackRF.rate); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_set_sample_rate failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_set_amp_enable(HackRF.device, HackRF.enable_amp); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_set_amp_enable failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_set_lna_gain(HackRF.device, HackRF.lna_gain); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_set_lna_gain failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_set_vga_gain(HackRF.device, HackRF.vga_gain); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_set_vga_gain failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing trailing \n on these error messages
|
||
struct timespec thread_cpu; | ||
|
||
int handle_hackrf_samples(hackrf_transfer *transfer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to become static now that we're building with -Wmissing-declarations
(that change postdates your PR)
status = hackrf_init(); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_init failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} | ||
|
||
status = hackrf_open(&HackRF.device); | ||
if (status != 0) { | ||
fprintf(stderr, "HackRF: hackrf_open failed with code %d", status); | ||
hackrf_close(HackRF.device); | ||
hackrf_exit(); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand the hackrf API correctly, the cleanup paths here need to be a little more careful (don't call exit if init failed; don't call close if open failed)
I have added support for HackRF One device using libhackrf. I tested all the new functions successfully for a few days.