Tetra Decoding on a RaspberryPi2

Published

Software Defined Radio (SDR) tranceivers become mainstream on RaspberryPi's. Similar to Tetra decoding. This tutorial helps you to install Gnuradio and Tetra decoding components on a RPi2, with ArchLinux as base image.

Using a RPi2 as an SDR receiver

I am using multiple RaspberryPi 2 devices as receiver for our OpenTetra.nl service. This website combines Tetra signalling with open data from public transit vehicles. While having prototyped the code on a regular Core i5 the power consumention of SDR on ARMv7 is more envirionmental friendly.

For the base platform we are using ArchLinux. Which - after Gentoo - is our preferred service platform. I'll outline the installation of ArchLinux here as well. The hardware requirements:

  • RaspberryPi 2
  • An RTL-SDR USB Stick
  • A microSD card of at least 4GB

Installation ArchLinux on a RPi2

  1. Make sure you have a RPi2; and not an 1.
  2. On a unix-like OS download the following file:
    cd /var/tmp
    wget http://de4.mirror.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
    While doing so continue with the following steps.
  3. Partition your microSD-card
    fdisk /dev/pathtoyoursdcard
    p [enter] make sure this is your SD-card
    o [enter] delete everything that is on it
    n [enter] first partition
    [enter] (default primary)
    [enter] (default 1)
    [enter] (default 2048)
    +32M [enter]
    t [enter]
    c [enter]
    
    n [enter]
    p [enter] (default p)
    [enter] (default 2)
    [enter] (default something like 67584)
    +4G [enter] (the installation fits within 2GB)
    
    Finally I create a remaining partition for storage.
    For this I typically use F2FS.
    
    n [enter]
    p [enter] (default primary)
    [enter] (default 3)
    [enter] (default something like 8456192)
    [enter] (the remainder)
    
    p [enter] (check everything looks ok)
    w [enter] write to microSD-card
    
  4. Format the partitions:
    mkfs.vfat /dev/pathtoyourdisk1
    mkfs.ext4 -O ^HUGE_FILE /dev/pathtoyourdisk2
    
    # if you don't have mkfs.f2fs installed skip this step
    # mkfs.f2fs /dev/pathtoyourdisk3
    
  5. Mount the microSD-card and install the basis system:
    mount -o loop /dev/pathtoyourdisk2 /mnt/pi
    mkdir /mnt/pi/boot
    mount -o loop /dev/pathtoyourdisk1 /mnt/pi/boot
    cd /mnt/pi
    tar zxpf /var/tmp/ArchLinuxARM-rpi-2-latest.tar.gz
    mkdir -p /mnt/pi/opt/tetra/{bin,src}
    echo "/dev/mmcblk0p2  /       ext4    noatime,nodiratime 0 0" >> /mnt/pi/etc/fstab
    
    # if you don't have mkfs.f2fs installed skip this step
    # echo "/dev/mmcblk0p3  /opt/tetra f2fs    noatime,nodiratime 0 0" >> /mnt/pi/etc/fstab
    
    cd /var/tmp
    umount /mnt/pi/boot
    umount /mnt/pi
    
  6. Your microSD card is now ready to be placed in the RPi2, boot it and continue the installation.
    username: alarm
    password: alarm
    
    su
    passwd: root
    
    pacman -Syu [enter]
    y [enter]
    
    Installation of the required packages;
    
    pacman -S make gcc autoconf automake pkg-config zeromq opus-tools screen alsa-utils vim gnuradio gnuradio-osmosdr sox f2fs-tools git vorbis-tools unzip wget patch libxml2 [enter]
    y [enter]
    
    ln -sf /usr/bin/python2 /usr/bin/python
    
  7. Gnuradio uses a powerfull way of optimisation. We are now going to tune which algoritms should be used:
    volk_profile [enter]
    (take a 15 minute coffee break now, alternatively do this after you are done)
  8. If you are interested in using your RPi2 as a remote unit together with a more powerfull gnuradio instance elsewhere in the network you can now invoke the command below. The SDR plugged in your RPi2 is now available on port 1234.
    rtl_tcp -a 0.0.0.0 -p 1234
    

The installation of Tetra decoding

  1. Cloning the Git repositories
    cd /opt/tetra/src
    git clone https://github.com/sq5bpf/libosmocore-sq5bpf
    git clone https://github.com/sq5bpf/osmo-tetra-sq5bpf
    git clone https://github.com/sq5bpf/telive
    
  2. Compiling libosmocore-sq5bpf
    cd /opt/tetra/src/libosmocore-sq5bpf
    autoreconf -i
    CFLAGS="-O2 -march=native" ./configure --prefix=/opt/tetra
    make
    make install
    
  3. Compiling osmo-tetra-sq5bpf
    cd /opt/tetra/src/osmo-tetra-sq5bpf/src
    sed -i.orig "s/-O0/-O2 -march=native/g" Makefile
    PKG_CONFIG_PATH=/opt/tetra/lib/pkgconfig make
  4. Compiling the ETSI Codec
    cd /opt/tetra/src/osmo-tetra-sq5bpf/etsi_codec-patches
    wget http://www.etsi.org/deliver/etsi_en/300300_300399/30039502/01.03.01_60/en_30039502v010301p0.zip
    unzip -L en_30039502v010301p0.zip
    patch -p1 -N -E -i codec.diff
    cd c-code
    sed -i.orig "s/-O3/-O3 -march=native/g" makefile
    make
    cp sdecoder scoder cdecoder ccoder /opt/tetra/bin/.
  5. Compiling Telive
    cd /opt/tetra/src/telive
    sed -i.orig "s/-O2/-O2 -march=native/g" Makefile
    sed -i.orig "s/\/tetra\//\/opt\/tetra\//g" rxx
    sed -i.orig "s/\/tetra\/in/\/opt\/tetra\/log\/in/g" telive.c
    make
    mkdir -p /opt/tetra/log/{in,out}
    mkdir -p /opt/tetra/var/run
    cp telive rxx /opt/tetra/bin/.
  6. Fetching the Gnuradio Block, in this file you set up frequency and ppm values.
    cd /opt/tetra/bin
    wget http://blog.opentetra.nl/contrib/tetra.py
    chmod +x tetra.py
  7. Get the linker to find our libraries
    echo "/opt/tetra/lib" > /etc/ld.so.conf.d/01-tetra.conf
    ldconfig
    

Starting Telive

  1. screen
  2. cd /opt/tetra/src/osmo-tetra-sq5bpf/src
    ./receiver1 1
  3. ctrl-a n
  4. cd /opt/tetra/bin
    ./tetra.py
  5. ctrl-a n
  6. cd /opt/tetra/bin
    ./rxx 1

The author wants to thank Jacek Lipkowski for the development of the above tools and his continuous support on the RadioReference fora. For a Dutch thread review ScannerForum.