Make sure that the modules res_agi.so and format_sln.so are enabled on /etc/asterisk/modules.conf:
... ; Formats load => format_sln.so ... ; Channels load => res_agi.so ...
Normally, Asterisk is run as asterisk user. Then, the phonepatch must also set its UID to asterisk, in other case it cannot be stopped and continued (using signals) from the asterisk process. As the phonepatch will load as asterisk user, we must assure that it has access to all hardware involved: soundcard, serial/parallel ports:
# ls /dev/dsp* /dev/ttyS* /dev/parport* crw-rw---- 1 root audio 14, 3 2006-07-04 09:33 /dev/dsp crw-rw---- 1 root dialout 4, 64 2006-07-04 11:32 /dev/ttyS0 crw-rw---- 1 root lp 4, 64 2006-07-04 11:32 /dev/parport0
In that case, you should do:
usermod -G asterisk,audio,dialout,lp asterisk
On the Asterisk extensions file configuration (/etc/asterisk/extensions.conf) we have to add all the radio stations for which we want to enable the phonepatch. Although not really necessary, it's recomendable that yout create a new context (for example: radio) for these special users.
On this example, we will asign extensions for PuertoSaija (151) and Munichis (152).
[radio] ; Phonepatch exten => 151,1,Answer() exten => 151,2,EAGI(phonepatch.agi|puertosaija) exten => 151,3,Hangup exten => 152,1,Answer() exten => 152,2,EAGI(phonepatch.agi|munichis) exten => 152,3,Hangup
This extensions are used in both ingoing and outgoing calls. If you plan to use anonymous calls (where the extension is only for ingoing calls), it's not necessary to add another extension. For simplicity, use the same context that you choose for the incoming calls:
[radio] ... ; Static outgoing extension exten => 160,1,Answer() exten => 160,2,EAGI(phonepatch.agi|outcall) exten => 160,3,Hangup
Configuration file is place by default at /etc/asterisk/phonepatch. Global parameters and included in [general] section, options regarding a phonepatch (soundcard, PTT/Carrier) must be included in a [phonepatchname] section. Numeric sections are reserved to the phonepatch extensions.
When the phonepatch needs to get the value of a parameter, it searchs the configuration file in that order:
Extension
Phonepatch definition
General
Default values (defined by template: /usr/share/asterisk-phonepatch/phonepatch.conf.template)
If you need to define more than one phonepatch, you have to specify another soundcard and PTT/Carrier interface. Example using 2 phonepatchs:
; Asterisk Phonepatch configuration [phonepatch1] soundcard_device=/dev/dsp soundcard_samplerate=8000 soundcard_latency=0.01 ptt=off carrier_detection=off radio_control=serial[dtr,dsr,rts]:/dev/ttyUSB0 outcall_daemon=enabled [phonepatch2] outcall_daemon=off soundcard_device=/dev/dsp1 soundcard_samplerate=8000 soundcard_latency=0.05 ptt=off carrier_detection=off radio_control=serial[dtr,dsr,rts]:/dev/ttyUSB1 [general] language="es" sounds_dir="/usr/share/asterisk-phonepatch/sounds/" spool_dir="/var/spool/asterisk/outgoing/" dtmf_noisy_mode_button= dtmf_sensibility=1.0 festival_audio_gain=5.0 telephony_audio_gain=1.0 radio_audio_gain=1.0 carrier_polling_time=0.5 carrier_threshold_signal=0.1 carrier_tail_time=2 carrier_max_time=20 carrier_wait_time=5 full_duplex=off ptt_threshold_signal=0.01 ptt_tail_time=2 ptt_max_time=30 ptt_wait_time=5 ptt_txdelay=0.5 ctcss_tx_amplitude=0.001 hangup_button=# end_audio=php_endcall.ogg call_limit=600 incall_report_audio=@%d incall_report_audio_wait=5 incall_report_timeout=60 incall_report_timeout_audio=php_notanswered.ogg incall_answer_mode=dtmf incall_answer_button=* outcall_channel = IAX2/guest:violin@localhost outcall_context=metadistro outcall_timeout=10 outcall_priority=1 askfortone_button="*" tone_audio=php_tone.ogg tone_audio_time=3 tone_timeout=20 tone_timeout_audio=php_timeoutcall.ogg outcall_button="*" clear_button="#" ring_audio=php_ring.ogg ring_audio_time=1 ring_audio_wait=3 ring_timeout_audio=php_ringtimeout.ogg ctcss_tx= ctcss_rx= outcall=on incall=on name=default phonepatch=phonepatch1 outcall_askfortone_mode=dtmf outcall_dmtf_extension_mode=on [puertosaija] name="estacion puertosaija" ctcss_tx=1Z ctcss_tx_amplitude=0.02 outcall_dtmf_id=1 outcall_extension=151 incall_answer_mode=ctcss phonepatch=phonepatch2 [munichis] name="estacion munichis" outcall_dtmf_id=2 outcall_extension=152 ctcss_rx=200.0 ctcss_tx_amplitude=0.02 ctcss_tx=150.0
As base configuration file, you can also use the example located at /usr/share/asterisk-phonepatch/phonepatch.conf.example. Copy it to /etc/asterisk/phonepatch.conf and costumize it. Take a look on the manual page (man phonepatch.conf) to see a detailed explanation of all the variables. Default values are good for most situations, but take care on the following ones:
ptt
On most cases you will have to enable this options to turn PTT on when sending audio to the radio.
radio_control
Use serial:device, parallel:device or command:external_command. Valid values are for example serial:/dev/ttyS0, parallel:/dev/parport0 or command: /usr/sbin/external-app-to-interface-board.
When using parallel port, make sure that the module ppdev is loaded.
The command option runs an external command which is supposed to accept commands from the stdin and returning its output through stdout. When using the command option, you have to fill ptt_on, ptt_off, get_carrier and get_carrier_response parameters. The first three are the strings that would be sent to process to turn ptt of, turn it off, and get carrier state. The last one, get_carrier_response, expects a special regular expression: let's imagine that the external application returns "get carrier: on" to say there is carrier and "get carrier: off" if there is not. In that case you would have to set get_carrier_response parameter to "get carrier: (on|off)".
If your board don't use the standard lines, you can set the ones you have that way (device_name[ptt,carrierdetection,power]:device). Examples:
serial[dtr,dcd,rts]:/dev/ttyS0
parallel[data0,paperout,autofeed]:/dev/parpot0
Use the negative prefix ("-") to logically negate a line.
carrier_detection
It prevents PTT activation when the carrier is detected. Must be enabled for VHF/UHF transceivers, but of course only if your interface board is able to read the carrier_detection state, otherwise the phonepatch won't work. Sometimes enabling carrier_detection is optional, but in other cases is compulsory, because the radio outputs noise on the Rx audio signal (noise that the phone user will listen!). Motorola transceivers are known to behave that way.
If carrier_detection is enabled, the carrier_polling_time applies. This is the time that the phonepatch waits between succesive looks to carrier state. Use small values carefully as it is likely to load the CPU. 0.5 seconds should be enough for most cases.
full_duplex
You should enable this parameter only if you have a full duplex transceiver (notice that it will only work if carrier_detection is also enabled). Notice that most transceivers are half-duplex and this options should remain disabled.
outcall_extension
Here you specify the asterisk extension used for outgoing calls. For anonymous calls set outcall_extension_mode=static and simply give the extension used. For outcall_extension_mode=ctcss, write the specifica asterisk extension inside the station's configuration. For outcall_extension_mode=dtmf, add a outcall_dtmf_id (different for each extension) to allow the phonepatch to identify the radio user. If you want to append this id to the final asterisk extension, enable the outcall_extension_append_id option inside the phonepatch extension's section).
ptt_threshold_signal
Phones don't have a PTT, so we need to guess when the phone user is talking or not, and activate the PTT automatically (this is called a VOX mechanism). The ptt_threshold_signal is the parameter you need to adjust depending on your phoneline and soundcard levels. Maximum received power is the unity (1.0), so values around 0.05-0.2 should work in most scenarios.
dtmf_noisy_mode_button
It has been implemented for very noisy links (i.e. HF) where a tone can be decoded accidentally more than once. With this DTMF button you indicate that you are going to push next number. Example (using #): user pressed "1#2#3#4#", but the number was decoded, due to noise, as 1111#2#333333###4444##; however, this will be correctly interpreted as 1234. Therefore, you can repeat as many times as you want a number to assure it's decoded, and then press noisy_mode_button (also so the times you want).
outcall_channel
That's the channel used on outgoing calls. Example: IAX2/user:password@IP