How we got hackrf_sweep to work with ΓRF on the Raspberry Pi

raspi.png

ΓRF can use the HackRF to track of power over a broad frequency range.  It does this with the hackrf_sweep tool.  Currently the scanner, snapshot, and freqwatch modules use this capability.

Getting hackrf_sweep to work efficiently with the ΓRF client was not trivial.  It took hours of reading hackrf_sweep code and experimentation on the client before we reached an acceptable performance level (i.e. before were able to use the data coming in from the hackrf in near-real-time, and avoid overflowing buffers).  The time spent was worth it: we optimized so well that ΓRF can work with hackrf_sweep even on (newer) Raspberry Pis!

Here’s what we had to do to get it to work:

  1. We used the binary output of the hackrf_sweep command (instead of the default text output).  The binary output format doesn’t seem to be documented anywhere online, so it was necessary to read over hackrf_sweep.c and figure out what was going on.  You can see how we decode the binary output here.
  2. Before we were using hackrf_sweep to get frequency information, we used rtl_power (and of course, took the readings from rtl-sdr devices).  This limited the amount of bandwidth we could process at once, but it made it easy to store frequency/power pairs.  We could simply keep them in a dictionary.  A Python dictionary is efficient, but it does have a necessary amount of overhead.  This overhead precluded its use with hackrf_sweep with ΓRF in many systems.  Replacing the frequency map with a numpy array (as opposed to a Python dict), and storing power values at calculated offsets in the array, drastically sped things up.
  3. Because we were using a numpy array and offsets for frequencies, more calculations were necessary to store and find data.

The end result is an efficient ΓRF spectrum module that can provide frequency to power mapping across a relatively large bandwidth to any module that requires it, on hardware as puny as a Raspberry Pi.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s