Software Phonepatch for the Asterisk PBX

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

1. Introduction

A phonepatch is a device that allows radio stations to make phone calls. On the past, that could only be achieved with a hardware device, connected to the PSTN (Public Switched Telephone Network) and with a radio transceiver. Nowadays, with the arise of software PBX, the versatility of a phonepatch is not constrained to hardware, and can be integrated as part of the software. This radio-phonepatch has been designed to work together with the Open-Source Asterisk PBX on a GNU/Linux operating system.

Figure 1. Hardware phonepatch

Figure 2. Software Asterisk-phonepatch

The phonepatch has been designed to work on centralized networks, so the phone link can be used for more than one radio station. The only limitation is, of course, that just one simultaneous talk is possible. In those networks, each radio-user will have its own Asterisk extension and will be able to receive and make (anoymously or not) phone calls

Figure 3. Typical network using an Asterisk phonepatch

1.1. Features

  • Incoming calls (from phoneline or VoIP links) to radio users.

  • Outgoing calls (from radio to phoneline or VoIP links)

  • Multiple phonepatch instances on the same computer (using each one a different sound card, interface board and radio transceiver)

  • Audio language configurable, available english and spanish.

  • Use festival for text-to-speech.

  • Phone, Radio and Festival audio-gain configurable.

  • Radio users can control phonepatch with DTMF tones.

  • CTCSS authentification

  • VOX (Voice Operated Transmitter) processing for automatic PTT keying (phoneline->radio)

  • Compatible with HF and VHF/UHF transceivers (with carrier detection if available)

  • Very tolerant DTMF decoding.

  • PTT control configurable: minimum on time, maximum on time, penalty for maximum_on_time reached.

  • Uses soundcard to send and receive voice.

  • Serial/parallel port (plus extenal apps) to interface PTT and carrier detection.

  • Phonepatch audio messages (incoming, outcoming call, errors...) are configurable. All audio formats (WAV, AU, GSM, PCM, ...) can be used.

  • Non-anonymous outgoing calls

1.2. Asterisk interface

There are several mechanism to interface an application with Asterisk. Probably the most obvious is to create a new Asterisk channel library (chan_phonepatch.so). This solution garranties full-integration, but needs to patch the Asterisk code directly, which means lots for maintenance work and incompatability issues between versions.

Another option is that the phonepatch replicates a SIP Phone. This option is interesting, but not easy to implement. SIP protocol is not trivial, although there are some SIP frameworks available. For example, for Python we have the (abandoned?) shttom project Interesting for future implementations.

The easiest mechanism to interface Asterisk, and the used in the present version of the Asterisk-Phonepatch, is the AGI (Asterisk Gateway Interface). However, the AGI do not provide directly the bidirectional audio we need: the special EAGI mode (Extended AGI) opens the file descriptor number 3 with the running API, wheren application can read the received audio directly in raw format (8000sps/16 bits/little-endian), but it does not provide a direct way to send audio to the asterisk link. This issue is solved with a simple trick, using the AGI command GET DATA (STREAM_FILE works fine also) to play an audio file. This audio file is not a normal one, but a pipe that where the phonepatch writes the audio to send. Asterisk didn't notice the difference and works without any apreciable latency.