Skip to main content

This is a wrapper for hackrf. It includes both libhackrf and hackrf-tools

Project description

python_hackrf

python_hackrf is a cython wrapper for hackrf.

Before installing python_hackrf library, you must have hackrf host software installed. Because this library uses dynamic linking with an existing library file.

You can install this library using

pip install python_hackrf

If your hackrf files are in non-standard paths and during installation the python_hackrf cannot find hackrf.h or the library file, you can specify the paths via environment variables

export PYTHON_HACKRF_CFLAGS=path_to_hackrf.h
export PYTHON_HACKRF_LDFLAGS=path_to_hackrf.(so, dylib, dll)

Requirements:

  • Cython==0.29.36
  • Numpy>=1.26
  • Scipy (optional, for faster work)
  • pyFFTW (optional, for faster work)
  • pyjnius and android (only for android)

Scope:

All functions from libhackrf are ported. On Android, connection to hackrf and obtaining a list of devices are changed.

hackrf_tools

  • hackrf_info.c (Implemented)
  • hackrf_operacake.c (Implemented)
  • hackrf_sweep.c (Implemented)
  • hackrf_transfer.c (Implemented)
  • hackrf_clock.c (Will not be implemented)
  • hackrf_cpldjtag.c (Will not be implemented)
  • hackrf_debug.c (Will not be implemented)
  • hackrf_spiflash.c (Will not be implemented and features will not be ported)

Usage

usage: python_hackrf [-h] {info, sweep, operacake, transfer} ...

python_hackrf is a Python wrapper for libhackrf and hackrf-tools.

options:
  -h, --help            show this help message and exit

Available commands:
  {info,operacake,sweep,transfer}
    info                Read device information from HackRF such as serial number and firmware version.
    operacake           Specify either list, mode, or GPIO test option.
    sweep               Command-line spectrum analyzer.
    transfer            Send and receive signals using HackRF. Input/output files consist of complex64 quadrature samples.
python_hackrf info
usage: python_hackrf info [-h] [-f] [-s]

options:
  -h, --help            show this help message and exit
  -f, --full            show info like in hackrf_info
  -s, --serial_numbers  show only founded serial_numbers
python_hackrf sweep
usage: python_hackrf sweep [-h] [-d] [-a] [-f] [-p] [-l] [-g] [-w] [-1] [-N] [-B] [-S] [-s] [-b] [-r]

options:
  -h, --help  show this help message and exit
  -d          serial number of desired HackRF
  -a          RX RF amplifier. If specified = Enable
  -f          freq_min:freq_max. minimum and maximum frequencies in MHz start:stop or start1:stop1,start2:stop2 (MAX_SWEEP_RANGES = 10)
  -p          antenna port power. If specified = Enable
  -l          RX LNA (IF) gain, 0 - 40dB, 8dB steps
  -g          RX VGA (baseband) gain, 0 - 62dB, 2dB steps
  -w          FFT bin width (frequency resolution) in Hz, 245-5000000 Depends on sample rate min= sample rate * 1e6 / 8180, max = sample_rate
              * 1e6 / 4
  -1          one shot mode. If specified = Enable
  -N          number of sweeps to perform
  -B          binary output. If specified = Enable
  -S          sweep style ("L" - LINEAR, "I" - INTERLEAVED). Default is INTERLEAVED
  -s          sample rate in MHz (2, 4, 6, 8, 10, 12, 14, 16, 18, 20). Default is 20
  -b          baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default .75 * sample rate
  -r          <filename> output file
python_hackrf operacake
usage: python_hackrf operacake [-h] [-d] [-o] [-m] [-a] [-b] [-f] [-t] [-w] [-l] [-g]

options:
  -h, --help       show this help message and exit
  -d               serial number of desired HackRF
  -o , --address   specify a particular Opera Cake by address. Default is 0
  -m , --mode      specify switching mode [options: manual, frequency, time]
  -a               set port connected to port A0
  -b               set port connected to port B0
  -f               <port:min:max> or <port:min:max>,<port:min:max> automatically assign <port> for range <min:max> in MHz.
  -t               <port:dwell> or <port:dwell>,<port:dwell> in time mode, dwell on <port> for <dwell> samples. Specify only <port> to use the default
                   dwell time (with -w).
  -w               set default dwell time in samples for time mode
  -l, --list       list available Opera Cake boards
  -g, --gpio_test  test GPIO functionality of an Opera Cake
python_hackrf transfer

Be careful pyhackrf_transfer saves data in complex64 format!

usage: python_hackrf transfer [-h] [-d] [-r] [-t] [-f] [-i] [-o] [-m] [-a] [-p] [-l] [-g] [-x] [-s] [-N] [-R] -[b] [-H]

options:
  -d                  serial number of desired HackRF
  -r                  <filename> receive data into file (use "-" for stdout)
  -t                  <filename> transmit data from file (use "-" for stdout)
  -f, --freq_hz       frequency in Hz (0MHz to 7250MHz supported). Default is 900MHz
  -i, --i_freq_hz     intermediate frequency in Hz (2000MHz to 3000MHz supported)
  -o, --lo_freq_hz    front-end local oscillator frequency in Hz (84MHz to 5400MHz supported)
  -m, --image_reject  image rejection filter selection (bypass, low, high)
  -a                  RX RF amplifier. If specified = Enable
  -p                  antenna port power. If specified = Enable
  -l                  RX LNA (IF) gain, 0 - 40dB, 8dB steps
  -g                  RX VGA (baseband) gain, 0 - 62dB, 2dB steps
  -x                  TX VGA (IF) gain, 0 - 47dB, 1dB steps
  -s                  sample rate in MHz (2, 4, 6, 8, 10, 12, 14, 16, 18, 20). Default is 10
  -N                  number of samples to transfer (default is unlimited)
  -R                  repeat TX mode. Fefault is off
  -b                  baseband filter bandwidth in MHz (1.75, 2.5, 3.5, 5.0, 5.5, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0, 15.0 20.0, 24.0, 28.0). Default .75 * sample rate
  -H                  synchronize RX/TX to external trigger input

Android

This library can work on android. To do this, go to the android directory and download 3 recipes for p4a.

buildozer.spec

requirements = python3,android,pyjnius,numpy,libusb,libhackrf,python_hackrf
p4a.local_recipes = path_to_pythonforandroidrecipes_folder

Your recipes folder should contain at least the following files:

pythonforandroidrecipes/
    __init__.py
    libusb/
        __init__.py
    python_hackrf/
        __init__.py
    libhackrf/
        __init__.py
        hackrf_android.patch
        jni/
            Android.mk
            Application.mk
            libhackrf.mk

Examples

You can see a basic example of working with python_hackrf in this tutorial.

Please use the original hackrf documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_hackrf-1.2.3.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

python_hackrf-1.2.3-cp311-cp311-macosx_14_0_arm64.whl (286.8 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

File details

Details for the file python_hackrf-1.2.3.tar.gz.

File metadata

  • Download URL: python_hackrf-1.2.3.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.10

File hashes

Hashes for python_hackrf-1.2.3.tar.gz
Algorithm Hash digest
SHA256 326c5c21908fe21d13d1e27d48de995004ca65868d1902e935f73d58210c98cb
MD5 4a2cc132ca85e721f5c4a0d14bf261d7
BLAKE2b-256 e1a7ed6db879f760d96135ecf8823c82ba66133f9d9d8177fcdbed71f1339054

See more details on using hashes here.

File details

Details for the file python_hackrf-1.2.3-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for python_hackrf-1.2.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6c5d61ded7d75c082397cc823b5ff88cfea01eb8b98e859b2452919a548b04ff
MD5 b61c19d1074e242173c07efae9b888ea
BLAKE2b-256 c9f0b2cf0fdee78ddeb5f96d342031e2958258409881c534e252eb025debc2cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page