Updated Guix package for HackRF

Am attempting to upload the revised package definition at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=38650, but haven’t seen it show up yet. So here is the package definition (added to gnu/packages/radio.scm):

(define-public hackrf
  ;; Using a git commit because there have been many many commits
  ;; since the relase two years ago, but no sign of a promised
  ;; release for many months now.
  (let ((commit "43e6f99fe8543094d18ff3a6550ed2066c398862")
        (revision "0"))
    (package
     (name "hackrf")
     (version (git-version "2018.01.1" revision commit))
     (source
      (origin (method git-fetch)
	      (uri (git-reference
		    (url "https://github.com/mossmann/hackrf.git")
		    (commit commit)))
	      (file-name (git-file-name name version))
	      (sha256
	       (base32 "0avnv693xi0zsnrvkbfn0ln1r3s1iyj0bz7sc3gxay909av0pvbc"))))
     (build-system cmake-build-system)
     (arguments
      '(#:configure-flags
        (list "-DUDEV_RULES_GROUP=dialout"
	      (string-append "-DUDEV_RULES_PATH="
                             (assoc-ref %outputs "out")
			     "/lib/udev/rules.d"))
        #:phases
	(modify-phases %standard-phases
	  (add-before 'configure 'enter-source-directory
		      (lambda _ (chdir "host") #t))
	  (add-before 'install-license-files 'leave-source-directory
		      (lambda _ (chdir "..") #t)))
        #:tests? #f))                  ; no test suite
     (native-inputs
      `(("pkg-config" ,pkg-config)))
     (inputs
      `(("fftw" ,fftw)
        ("fftwf" ,fftwf)
	("libusb" ,libusb)))
     (home-page "https://greatscottgadgets.com/hackrf/")
     (synopsis "User-space library and utilities for HackRF SDR")
     (description
      "Command line utilities and a C library for controlling the HackRF
Software Defined Radio (SDR) over USB.  Installing this package installs
the userspace hackrf utilities and C library.  To install the hackrf
udev rules, you must add this package as a system service via
modify-services.  E.g.:

@lisp
(services
 (modify-services
  %desktop-services
  (udev-service-type config =>
   (udev-configuration (inherit config)
    (rules (cons hackrf
            (udev-configuration-rules config)))))))
@end lisp")
     (license license:gpl2))))

WIP: HackRF Package Definition for Guix

I created this package definition, which I believe is in-and-of-itself complete:

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 Christopher Howard <christopher@librehacker.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages hackrf)
  #:use-module (gnu packages)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system cmake)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages algebra)
  #:use-module (gnu packages libusb))

(define-public hackrf
  (let ((commit "e9c6c2d2e6f9c2e903c1e69de9a48aa4b28a1e55")
        (revision "0"))
  (package
    (name "hackrf")
    (version (string-append "2018.01.1-" revision "." (string-take commit 7)))
    (home-page "https://greatscottgadgets.com/hackrf/")
    (synopsis "User-space library and utilities for HackRF SDR")
    (description
     "Command line utilities and a C library for controlling the HackRF
Software Defined Radio (SDR) over USB.")
    (license license:gpl2)
    (source
     (origin
      (method git-fetch)
      (uri (git-reference
            (url "https://github.com/mossmann/hackrf.git")
            (commit commit)))
      (sha256
       (base32 "0vqlr0nph9r7wpqn81ghhdbb131803b8wi328iaz37304mrr6hkw"))
      (file-name (git-file-name name version))))
    (build-system cmake-build-system)
    (arguments '(#:configure-flags
                 (list "-DUDEV_RULES_GROUP=dialout"
                       (string-append "-DUDEV_RULES_PATH="
                                      (assoc-ref
                                       %outputs "out") "/lib/udev/rules.d"))
                 #:phases (modify-phases %standard-phases
                            (add-before 'configure 'enter-source-directory
                              (lambda _ (chdir "host") #t))
                            (add-before 'install-license-files
                                'change-back (lambda _ (chdir "..") #t)))
                 #:tests? #f #| no test suite |# ))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (inputs `(("libusb" ,libusb)
              ("fftw" ,fftw)
              ("fftwf" ,fftwf))))))

However, I have not submitted it as a patch yet, as I wanted to test it with my HackRF SDR first, and that let me down a rabbit trail on how to install udev rules in Guix. I’m about out of time for this project for today, so I’ll finish this up next week, God willing.

HackRF Shell: RX Restart Bug

I spent quite a while troubleshooting a bug in which RX would mysteriously not restart, if you did a hackrf-stop-rx followed by another hackrf-start-rx. The problem actually was not in my code, but due to some old libhackrf bugs that had not been patched in the old Debian 9 version of libhackrf which I am using.

This is a serious enough annoyance that you won’t want to be using HackRF Shell with the unpatched version. So, I added instructions to my git repo (debian9-libhackrf-patch directory, see commit 346c50e) on how to get a patched version of the Debian 9 packages. I think that the Debian 10 library version is actually not new enough to avoid all the bugs, either, so the info I have provided might be of value to Debian 10 users as well.

I would like to switch my home system from Debian to Gnu Guix, and use Guix package management for development, but I’m not sure how soon that will happen.

git clone git://git.librehacker.com/pub/git/hackrf-rkt.git

HackRF Shell: Progress Update

I added in the baseband-filter-bandwidth control procedure, which is something I forgot to do earlier. This was critical for picking up the weaker stations, such as KJNP 100.3Mhz, which is around 20 or 30 miles away, I think. I coded some simple helper functions (in Scheme) to start and stop receiving data according to time parameters, which I will use to record my favorite radio program each morning. This example records data for one minute from 8:43pm to 8:44pm (code checkout a992f67).

scheme@(guile-user)> (define d (hackrf-open))
scheme@(guile-user)> (load "hackrf-shell-lib.scm")
scheme@(guile-user)> (hackrf-sensible-defaults d)
scheme@(guile-user)> (hackrf-set-baseband-filter-bandwidth d 2000000)
scheme@(guile-user)> (hackrf-enable-amp d)
scheme@(guile-user)> (timed-read d "out.bin" 20 43 20 44)

This still just dumps the floating point signal data to a file, rather that doing any demodulation, so the file size is very large, and I must feed it into GnuRadio. Yet, it is progress.

I need to go over the RX start/stop code again as I get an error if I try to start RX again after stopping it. I coded that part of the device management rather quickly so I am not surprised.

I started playing around with merging in FFT functionality. I added an fft-512 procedure which does FFT on a 512 byte buffer using libfftwf. I think it works, but I haven’t added any procedures yet to do anything useful with fft-512 so I don’t really know yet. I was going to code something which feeds data to GnuPlot for a spectrum analysis display, in the usual fashion like all the SDR software does:

I have been learning a lot lately about Fourier transform and DFT (Discrete Fourier Transform) and I think I have a mostly clear understanding of the basic math and concepts involved now. For fun, I did a DFT operation manually in Emacs Calc on a length 8 data sample, and the results came out making sense. This article is a nice introduction to the Fourier transform, though you need to have a good understanding of complex numbers to fully grasp the DFT equation:

An Interactive Guide to the Fourier Transform