#!/usr/bin/perl -w # # August 24, 2004 Updated example tones to match tone_0.2 version syntax. # November 17, 2003 Changed "$LOCAL/ctone-enable" to "$LOCAL/ctone_enable" # Added example lines for tone program from KC6HUR. # Enable upon starting ctone script. # November 2, 2003 Corrected to set $READINPUTPID for all open statments. # The confirm.wav file is from the confirm script by KC6HUR, # which is also find in the IRLP Yahoo group files area. # October 31, 2003 # Author: David I. McAnally KF7FLY # Provided AS IS. If you use this, you support it. # If it breaks something, you accept full responsibility. # Problems can be posted on the IRLP or EchoIRLP Yahoo groups, # but there is no guarantee problems will be resolved. # Usage: Run from repeater as a background process to play courtesy tone # during an active IRLP or EchoIRLP connection. As configured, # it should play a short two tones after the remote connection unkeys. # It is not configured to play tones after local transmissions, but # could be modified to do so. # If you add it to rc.local, be sure to kill it before starting so # only one copy is running. # killall ctone # /bin/su - -c "$CUSTOM/ctone" repeater &>/dev/null & # my $CHKPID; # place to store process IDs. my $keyed=0; # use to unkey on exit from script. my $cosactive=0; # use to remove cos_active file on exit. my $READINPUTPID; # holds the process ID of the readinput process. my $BIN=$ENV{'BIN'}; # bring some environment vars into local vars my $AUDIO=$ENV{'AUDIO'}; my $CUSTOM=$ENV{'CUSTOM'}; my $SCRIPT=$ENV{'SCRIPT'}; my $LOCAL=$ENV{'LOCAL'}; my $LOG=$ENV{'LOG'}; # # catch signals and exit gracefully # sub catch_zap { local ($signame) = @_; system("$BIN/forceunkey") if ( $keyed ); unlink("$LOCAL/cos_active") if ( $cosactive ); #close(CMD); # Close might wait on CMD to exit, so use kill instead. kill('TERM',"$READINPUTPID"); system("$SCRIPT/sfswrapper") if ( -f "$LOCAL/active" ); print STDERR "Caught SIG$signame--closing readinput pipe, exiting $0!\n"; exit; }; sub LOG { local ($text) = @_; $TD=`date '+%b %d %Y %T %z'`; chomp $TD; print "$TD $text\n"; return; } $SIG{TERM} = \&catch_zap; # catch INT signals to exit $SIG{INT} = \&catch_zap; $SIG{HUP} = \&catch_zap; $SIG{KILL} = \&catch_zap; # # The CTONE subroutine plays the courtesy tone after suitable delays # and activity checks. # sub CTONE { # local ($tone) = @_; &LOG("Attempting courtesy tone"); system("usleep","250000"); # pause briefly if ( ! -f "$LOCAL/active" ) { # return if not active &LOG("No longer active"); return; } if ( -f "$LOCAL/cos_active" ) { # return if busy local &LOG("node is busy"); return; } if ( system("$BIN/cosstate") ) { # return if busy local &LOG("COS is busy"); return; } if ( system("$BIN/pttstate") ) { # return if busy local &LOG("PTT is busy"); return; } # Try to avoid interfering with any other transmission # Not sure if this will do anything, but worth a try. $CHKPID=`/sbin/pidof -o %PPID -x wavplay`; chop $CHKPID; if ( "$CHKPID" ne "" ) { # return if process is running &LOG("wavplay is running PID=$CHKPID"); return; } $CHKPID=`/sbin/pidof -o %PPID -x echo_wavplay`; chop $CHKPID; if ( "$CHKPID" ne "" ) { # return if process is running &LOG("echo_wavplay is running PID=$CHKPID"); return; } # # Do steps necessary to play audio courtesy tone # Only one program can use audio device at a time, # so we kill ispeaker/sfswrapper, key, play audio, # unkey and restart sfswrapper. # system("$BIN/forcekey"); $keyed=1; # set this just in case we kill the script while keyed. system("pkill","-u","repeater","-f","ispeaker"); system("pkill","-u","repeater","-f","ispeaker_PCI"); system("pkill","-u","repeater","-f","sfswrapper"); system("usleep","250000"); #wait for transmitter if ( -f "/usr/local/bin/tone" ) { system("/usr/local/bin/tone","82","70","70","1600","0","70","70","1200","0"); #Palomar RBC-xxx #system("/usr/local/bin/tone","82","100","0","330","0","100","0","500","0","100","0","660","0"); #ACC-850 Bumble Bee #system("/usr/local/bin/tone","82","50","0","330","0","50","0","500","0","50","0","660","0"); #ACC-850 Yellow Jacket } elsif ( -f "$AUDIO/custom/confirm.wav" ) { system("$BIN/play","$AUDIO/custom/4up.wav"); } system("$BIN/forceunkey"); $keyed=0; # safe to unset this now. system("usleep","250000"); #wait for audio device system("$SCRIPT/sfswrapper") if ( -f "$LOCAL/active" ); &LOG("Courtesy tone complete"); return; }; # # Main processing starts here. # &LOG("Starting $0, enter \^c to exit..."); system("/bin/touch","$LOCAL/ctone_enable"); # Enable upon start # # Open a pipe to read the output from the readinput program. # Then start a while loop to process the output. # $READINPUTPID=open(CMD,"$BIN/readinput|") or die "Can't open readinput: $!"; while() { $input=$_; chomp $input; &LOG("$input"); next if ( ! -f "$LOCAL/ctone_enable" ); # This file must exist or we just loop. if ( -f "$LOCAL/active" ) { # If we only want tone during active connection if ( "$input" eq "PTT INACTIVE" ) { # PTT has dropped. #&LOG("$input"); &CTONE("i"); # Play the courtesy tone. # reopen readinput to flush. $READINPUTPID=open(CMD,"$BIN/readinput|") or die "Can't open readinput: $!"; } elsif ( "$input" eq "COS INACTIVE" ) { # COS had dropped. # I tried playing the tone after local transmissions, # and decided I didn't like it there. So I don't # run run it here. #&LOG("$input"); #&CTONE("i"); # Play the courtesy tone. # reopen readinput to flush. #$READINPUTPID=open(CMD,"$BIN/readinput|") or die "Can't open readinput: $!"; } } } # # We should not get past here, but... # system("$BIN/forceunkey") if ( $keyed ); unlink("$LOCAL/cos_active") if ( $cosactive ); kill('TERM',"$READINPUTPID"); system("$SCRIPT/sfswrapper") if ( -f "$LOCAL/active" ); print STDERR "exiting abnormally but tried to clean up $0!\n"; exit(0);