|
| 1 | +#! /usr/bin/python3 |
| 2 | +##--------------------------------------------------------------------\ |
| 3 | +# hackrfpy 'examples/device_explorer.py' |
| 4 | +# The "first thing you run": detect the board, identify it, report |
| 5 | +# firmware + capabilities + any device warnings. Read-only. This is the |
| 6 | +# HackRF analog of a serial-port autodetect -- it confirms the device is |
| 7 | +# present and usable before you build anything on top of it. |
| 8 | +##--------------------------------------------------------------------\ |
| 9 | +import sys |
| 10 | +from hackrfpy import HackRF |
| 11 | + |
| 12 | + |
| 13 | +def main(): |
| 14 | + h = HackRF() |
| 15 | + |
| 16 | + print("=" * 52) |
| 17 | + print(" hackrfpy device explorer") |
| 18 | + print("=" * 52) |
| 19 | + |
| 20 | + det = h.detect() |
| 21 | + if not det["found"]: |
| 22 | + print(f"\n No HackRF detected: {det['problem']}") |
| 23 | + print(" Check the USB cable, and on Windows the WinUSB driver (Zadig).") |
| 24 | + return 1 |
| 25 | + |
| 26 | + print(f"\n boards found : {det['count']}") |
| 27 | + print(f" hackrf-tools : {det['tools_version']}") |
| 28 | + print(f" libhackrf : {det['libhackrf_version']}") |
| 29 | + |
| 30 | + for b in det["boards"]: |
| 31 | + tag = "HackRF" if b["is_hackrf"] else "UNCONFIRMED" |
| 32 | + print(f"\n [{b['index']}] {tag}") |
| 33 | + print(f" serial : {b['serial']}") |
| 34 | + print(f" name : {b['name']}") |
| 35 | + print(f" firmware : {b['firmware']}" |
| 36 | + + (" (stale: <2021)" if b["firmware_stale"] else "")) |
| 37 | + |
| 38 | + if det["multiple"]: |
| 39 | + print("\n ! multiple boards -- target one with HackRF(serial=...)") |
| 40 | + for w in det.get("warnings", []): |
| 41 | + print(f" ! device warning: {w}") |
| 42 | + |
| 43 | + # capability flags derived from firmware/tools version |
| 44 | + feats = h.features() |
| 45 | + print("\n capabilities:") |
| 46 | + for k in ("stdout_streaming", "sweep_num_sweeps", "bias_tee"): |
| 47 | + print(f" {k:18}: {'yes' if feats[k] else 'no'}") |
| 48 | + |
| 49 | + print(f"\n ready: {'YES' if det['ready'] else 'no'}") |
| 50 | + print("=" * 52) |
| 51 | + return 0 if det["ready"] else 1 |
| 52 | + |
| 53 | + |
| 54 | +if __name__ == "__main__": |
| 55 | + sys.exit(main()) |
0 commit comments