#!/usr/bin/perl use File::Basename; ######################################################################## # filename: contax # description: IRLP script describes latest connections # version: 2.01 May 9 2007 # history: 1.01 VA7YAK April 2007 initial # 1.02 " April 2007 remove calls to cut # 1.03 " April 2007 today, yesterday, recent # 1.04 " April 2007 inout, time, query, E, V # 1.05 " May 2007 bug fixes # 2.01 " May 2007 convert to perl ######################################################################## ######################################################### # SetGlobals # # set the global variables to their default values # ######################################################### sub SetGlobals { ## these globals are calculated in various functions $CONNS[0]=""; # array of connections $DOW=""; # day of week $DATE=""; # expanded date $JM=""; # month number $MODE="contax"; # default mode is to announce connections $NODE=""; # expanded node numbers $REJECT=0; # count of connections rejected due to date $SEQ=""; # sequential connection number $TEST="false"; # if true, use test messages $TIME=""; # expanded hour & minutes $TODAY=""; # month day & year corresponding to today $VERSION="contax 2.01"; $YESTERDAY=""; # month day & year corresponding to yesterday ## these variables are set by the environment file ## $BIN $CUSTOM $LOCAL $SCRIPT ## defaults the user is unlikely to change ## because they are changed by command line arguments $INOUT="in"; # what connections do we look for $QUERY="X"; # which node we query for $SOUND="radio"; # what kind of sound the script produces $TESTDATE="any"; # what dates we are interested in $V0=0; # echo input args $V1=0; # show sound files as text $V2=0; # show sound files but do not play $V3=0; # show variables after input args processed $V4=0; # show selected connections $V5=0; # $V6=0; # $V7=0; # $V8=0; # $V9=0; # use verbose echo ## defaults the user might change $CRON_ANNOUNCE="node 11 44 the_time_is_now"; $CUSTOM_AUDIO="/home/irlp/audio/custom/CONTAX"; # where the audio files are $EXPAND=3; # how we expand numbers $LOG="/home/irlp/log/"; # where the log file is $TESTLOG="/home/irlp/downloads/contax/TEST."; # where the test log file is ## how many connections do we speak/show $NSEQ=3; # speak/show 3 connections as a default ## what order do we speak/show connections ## lilo is a computer term meaning "last in last out" ## lifo is a computer term meaning "last in first out" #$ORDER="lilo"; # last connection is spoken last $ORDER="lifo"; # last connection is spoken first ## which type of audio file do we want #$PLAYTYPE="ul"; # cat *.ul > /dev/audio $PLAYTYPE="wav"; # $BIN/play *.wav #$PLAYTYPE="wavcat"; # $BIN/play concatenated.wav $SAYDATE="true"; # true if we are to speak the date ## set text mode to true or false $TEXT="false"; # do not show text } # end of SetGlobals ######################################################### # ShowHelp # # show some standard sequences # ######################################################### sub ShowHelp { print "Here are some standard sequences: \n"; print "-- to speak the last 3 incoming calls -- \n"; print " contax \n"; print "-- to speak the last 3 outgoing calls -- \n"; print " contax out \n"; print "-- to show as text the last 20 calls (in & out) -- \n"; print " contax inout N20 text mute \n"; print "-- to speak the last 3 calls today -- \n"; print " contax today \n"; print "-- to speak (and text) the last 7 in/out calls today & yesterday -- \n"; print " contax N7 text recent inout \n"; print "-- to speak the last incoming call from node 1605 -- \n"; print " contax Q1605 \n"; print "-- to speak the last 5 in/out calls from node 1826 -- \n"; print " contax Q1826 N5 inout \n"; } # end of ShowHelp ######################################################### # ShowOptions # # show options for this script # ######################################################### sub ShowOptions { print "Available options for script contax: \n"; print " contax lifo # last in first out \n"; print " contax lilo # last in last out \n"; print " contax text # show connections as text \n"; print " contax notext # do not show text \n"; print " contax E3 # normal way to expand numbers \n"; print " contax N5 # or 2 or 7 etc \n"; print " contax N10 # 20 is the maximum \n"; print " contax V123456 # which test options to turn on \n"; print " contax V0 # print input args \n"; print " contax V1 # show sound files as text \n"; print " contax V2 # show sound files but do not play \n"; print " contax V3 # show variables after input args processed\n"; print " contax V4 # show selected connections \n"; print " contax V9 # show debug messages \n"; print " contax V03 # echo input args and show variables \n"; print " contax V24 # show sound files and selected connections \n"; print " contax audio # speech to speakers \n"; print " contax mute # no speech \n"; print " contax radio # speech to radio \n"; print " contax today # show only connections made today \n"; print " contax out # show outgoing connections \n"; print " contax inout # show incoming & outgoing connections \n"; print " contax Q2345 # show last incoming call from node 1234 \n"; print " contax recent # show only connections made today & yesterday \n"; print " contax saydate # speak the date as well as day of week \n"; print " contax mutedate # do not speak the date \n"; print " contax version # show version \n"; print " contax ul # use cat on UL files \n"; print " contax wav # do not concatenate WAV files \n"; print " contax wavcat # concatenate WAV files \n"; print "options may be combined \n"; print " contax lifo text N6 \n"; print "some options can be compressed (see DOC) \n"; print " contax -5AST \n"; print "Common usages: \n"; print " contax N3 # speak the last 3 incoming calls \n"; print " contax Q1722 # speak the last incoming call from node 1722 \n"; print " contax time # speak the time \n"; print " contax N3 out # speak the last 3 outgoing calls \n"; print " contax text N5 mute # print the last 5 incoming calls \n"; } # end of ShowOptions ######################################################### ######################################################### sub ExtraPrint { if ($V9) {print " @_ \n";} } # end of ExtraPrint ######################################################### # CheckState # # check initial conditions # ######################################################### sub CheckState { my ($curtime, $user); $curtime=`date +"%b %d, %Y %T"`; ExtraPrint "the time is $curtime"; # getlogin returns root if we login as root and then su - repeater # $user= getlogin; # Make sure we are user repeater!!! $user= `/usr/bin/whoami`; chomp $user; print "current user is $user\n"; if ($user ne "repeater") {print "$0: must be run as user REPEATER!\n"; exit 1; } # get the environment variables we need $BIN= $ENV{"BIN"}; $CUSTOM= $ENV{"CUSTOM"}; $LOCAL= $ENV{"LOCAL"}; if ($V9) {print " BIN= $BIN \n"; print " CUSTOM= $CUSTOM \n"; print " LOCAL= $LOCAL \n"; print " SCRIPT= $SCRIPT \n"; } # out if the node is active if (! -f "$LOCAL/enable" || -f "$LOCAL/active") {exit 1;} # we are getting no output from cosstate or pttstate, even when run manually # if we received DTMF tones, then the node should not be locally active $cos= `$BIN/cosstate`; $ptt= `$BIN/pttstate`; print "cos= <$cos> ptt= <$ptt> \n"; # COS & PTT Test - wait for COS unkey # while (1) # {if (`$BIN/cosstate` == 0) # {print "B/c\n"; # if (`$BIN/pttstate` == 0) # {print "B/p\n"; # break; # } # } # system(usleep 5000); # } } # end of CheckState ######################################################### # SoundStart # # prep code if we invoke speech # ######################################################### sub SoundStart { if ($SOUND eq "radio") {CheckState; system("${BIN}/aux3on"); system("${BIN}/key"); system(usleep 500000); } } # end of SoundStart ######################################################### # SoundFinish # # cleanup code if we invoke speech # ######################################################### sub SoundFinish { if ($SOUND eq "radio") {system(usleep 500000); system("${BIN}/unkey"); system("${BIN}/aux3off"); } } # end of SoundFinish ######################################################### # SetupRemoteTest # # set variables so we can test on a non-IRLP box # ######################################################### sub SetupRemoteTest { $CUSTOM_AUDIO="/home/alan/contax/audio1"; $LOG="/home/alan/contax/"; $TESTLOG="/home/alan/contax/TEST."; $BIN="/home/alan/contax"; $CUSTOM="/home/alan/contax"; $SOUND="audio"; # assume remote node does not have a radio $SAYDATE="true"; $TEXT="true"; } # end of SetupRemoteTest ######################################################### # TalkUlFiles # # talk via UL sound files sent to audio device # ######################################################### sub TalkUlFiles { my $arg; foreach $arg (@_) {system("cat $arg.ul > /dev/audio");} } # end of TalkUlFiles ######################################################### # TalkWavFiles # # use wav files without concatenation # ######################################################### sub TalkWavFiles { my ($arg, $wavfiles); ExtraPrint "[TWF1] inargs= @_ \n"; # build the list of wav files $wavfiles=""; foreach $arg (@_) {$wavfiles="$wavfiles $arg.wav"; } system("$BIN/play $wavfiles"); } # end of TalkWavFiles ######################################################### # TalkWavcatFiles # # use wav files with concatenation # ######################################################### sub TalkWavcatFiles { my ($files, $tmpfile, $wavfile); # remove the temp files if they exist (from /tmp directory) if (-f "/tmp/temp.raw" || -f "/tmp/temp.wav" ) {system("/bin/rm -f /tmp/temp.raw /tmp/temp.wav");} # convert wav to ul if needed; concatenate each ul file to temp.ul foreach $arg (@_) {$tmpfile= "/tmp/$arg.raw"; $wavfile= "$arg.wav"; if (-f $tmpfile) {system("cat $tmpfile >> /tmp/temp.raw");} elsif (-f $wavfile) {system("/usr/bin/sox $wavfile -r 44100 -s -w $tmpfile"); system("cat $tmpfile >> /tmp/temp.raw"); } else {print "$wavfile does not exist in $CUSTOM_AUDIO\n";} } # convert temp.raw to temp.wav system("/usr/bin/sox -r 44100 -s -w /tmp/temp.raw /tmp/temp.wav"); # ls -l /tmp/temp.ul /tmp/temp.wav; # play the temp.wav system("${BIN}/play /tmp/temp.wav"); } # end of TalkWavcatFiles ######################################################### # TalkConnection # # send sound files to audio script or device # ######################################################### sub TalkConnection { my @list; # we need to convert the N args into one big string ExtraPrint "[TC1] narg= $#_ args= @_ \n"; # convert the one input string into a list of args @list= split " ", $_[0]; ExtraPrint "[TC2] narg= $#list args= @list \n"; # user might want a printout of sound files called if ($V1 || $V2) {print " [TC3] $SEQ: @list\n";} if ($V2) {return;} # show sound files but do not play them # user wants UL files only if ($PLAYTYPE eq "ul") {TalkUlFiles @list;} # user wants WAV files without concatenation elsif ($PLAYTYPE eq "wav") {TalkWavFiles @list;} # user wants WAV files with concatenation elsif ($PLAYTYPE eq "wavcat") {TalkWavcatFiles @list;} } # end of TalkConnection ######################################################### # MonthAsNumber # # convert month name to a number # # produces global variable JM # ######################################################### sub MonthAsNumber { #month my ($im, $mtext, $month_list, $add_one); @month_list=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); @add_one=(1,2,3,4,5,6,7,8,9,10,11,12); ExtraPrint "[MAN0] arg0= $_[0]"; foreach $im (0..11) {$mtext= $month_list[$im]; ExtraPrint "[MAN1] im= $im mtext= $mtext"; if ($_[0] eq $mtext) {$JM= $add_one[$im]; ExtraPrint "[MAN2] $JM $_[0]"; return; } } } # end of MonthAsNumber ######################################################### # DayOfWeek # # convert date to dayofweek # # args: month day year (as in Apr 07 2007) # # uses global variable JM # # produces global variable DOW # ######################################################### sub DayOfWeek { #month day year my ($month, $year, $day, $smtwtfs); @smtwtfs= (sunday,monday,tuesday,wednesday,thursday,friday,saturday); $month= $_[0]; $day= $_[1]; $year= $_[2]; ExtraPrint "DOW1 $month $day $year"; # convert month to a number (global variable JM) MonthAsNumber $month; ExtraPrint "[DOW2] JM= $JM" ; # get a date that is on a sunday $asunday=`cal $JM $year | tail -4 | head -1 | cut -f1 -d" "`; chomp $asunday; ExtraPrint "[DOW3] asunday= $asunday" ; # remove any leading 0 from the day if (substr($day, 0, 1) eq "0") {$day= substr($day, 1, 1);} # convert our two dates into an index into days_of_the_week array $index= ($day-$asunday+28)%7; ExtraPrint "[DOW4] index= $index $DOW" ; $DOW= $smtwtfs[$index]; ExtraPrint "[DOW5] $DOW $month $day $year" ; } # end of DayOfWeek ######################################################### # WhatDayIsIt # # convert date to today, yesterday, or dayofweek # ######################################################### sub WhatDayIsIt { #month day year # is it today's date if ("$_[0] $_[1] $_[2]" eq "$TODAY") {$DOW="today"; return; } # is it yesterday's date if ("$_[0] $_[1] $_[2]" eq "$YESTERDAY") {$DOW="yesterday"; return; } # calculate the correct day of the week DayOfWeek @_[0], $_[1], $_[2]; } # end of WhatDayIsIt ######################################################### # MinutesExpand # # expand minutes 00-59 into sound files # # example 56 expands to 50 6 # ######################################################### sub MinutesExpand { # minutes my ($tens, $ones); $tens= substr($_[0], 0, 1) . "0"; $ones= substr($_[0], 1, 1); ExtraPrint "[ME1] tens= $tens ones= $ones minutes= $_[0] \n"; # if minutes = 00, we don't announce the minutes if ($_[0] eq "00") {return "";} # if minutes from 01 to 09, we announce oh and minutes elsif ($_[0] ge "01" && $_[0] le "09") {return "oh $ones";} # if minutes from 10 to 19, we announce minutes as is elsif ($_[0] ge "10" && $_[0] le "19") {return "$_[0]";} # if minutes ends in a zero, we announce minutes as is elsif ($_[0] eq $tens) {return "$_[0]";} # announce minutes as tens and ones (ie forty eight) else {return "$tens $ones";} } # end of MinutesExpand ######################################################### # NumberExpand # # expand a number 00-99 into sound files # # example 56 expands to 50 6 # ######################################################### sub NumberExpand { # number my ($tens, $ones); $tens= substr($_[0], 0, 1) . "0"; $ones= substr($_[0], 1, 1); # if number = 00, announce zero if ($_[0] eq "00") {return "0";} # if number from 01 to 09, we announce single digit elsif ($_[0] ge "01" && $_[0] le "09") {return $ones;} # if number from 10 to 19, we announce number as is elsif ($_[0] ge "10" && $_[0] le "19") {return "$_[0]";} # if number ends in a zero, we announce number as is elsif ($_[0] eq $tens) {return "$_[0]";} # announce number as tens and ones (ie forty eight) else {return "$tens $ones";} } # end of NumberExpand ######################################################### # NodeExpand # # expand node number into sound files # ######################################################### sub NodeExpand { # node my ($n1, $n2, $n3, $n4, $n12, $n34); # test for X000 if (substr($_[0],1,3) eq "000") {$n1= substr($_[0],0,1); $NODE="$n1 thousand"; return; } # we might want all 4 digits spoken separately # ie break 1722 into 1 7 2 2 if ($EXPAND == 4) {$n1= substr($_[0],0,1); $n2= substr($_[0],1,1); $n3= substr($_[0],2,1); $n4= substr($_[0],3,1); $NODE="$n1 $n2 $n3 $n4"; return; } # we might want the 4 digits broken into two groups of 2 digits # ie break 1722 into 17 22 if ($EXPAND == 2) {$n12= substr($_[0],0,2); $n34= substr($_[0],2,2); if ($n34 eq "00") {$n34= "hundred";} $NODE="$n12 $n34"; return; } # we might want the 4 digits broken into discrete words # ie break 1722 into 17 20 2 if ($EXPAND == 3) {$n12= substr($_[0],0,2); $n34= substr($_[0],2,2); $n12= NumberExpand $n12; if ($n34 eq "00") {$n34= "hundred"} else {$n34= NumberExpand $n34;} $NODE="$n12 $n34"; $return; } } # end of NodeExpand ######################################################### # TimeFix # # change 24 hour time to 12 hour time # ######################################################### sub TimeFix { #time my ($hour, $minutes, $ampm); ($hour, $minutes) = split /:/, $_[0]; # need am or pm; convert hour $ampm= "am"; if ($hour == 12) {$ampm= "pm"} elsif ($hour > 12) {$ampm= "pm"; $hour= $hour-12; } # remove any leading zero from hour if(substr($hour, 0, 1) eq "0") {$hour= substr($hour, 1, 1);} # reassemble return "$hour:$minutes $ampm"; } # end of TimeFix ######################################################### # TimeExpand # # expand time into sound files # ######################################################### sub TimeExpand { #time my ($hour, $minutes, $ampm, $time); ($time, $ampm) = split / /, $_[0]; ($hour, $minutes) = split /:/, $time; ExtraPrint "[TE1] hour= $hour minute= $minutes input= $_[0] ampm= $ampm\n"; # speak the minutes as one hyphenated word # ie say 46 as forty-six if ($EXPAND == 2) {$TIME="$hour $minutes $ampm"; return; } # speak the minutes as two words # ie say 46 as forty six if ($EXPAND == 3 || $EXPAND == 4) {$minutes= MinutesExpand $minutes; $TIME="$hour $minutes $ampm"; return; } } # end of TimeExpand ######################################################### # DateExpand # # expand date into sound files # ######################################################### sub DateExpand { #month day_of_month # speak the date as one hyphenated word # ie say 23 as twenty-three if ($EXPAND == 2) {$DATE= "$_[0] $_[1]"; return; } # speak the date as two words # ie say 23 as twenty three if ($EXPAND == 3 || $EXPAND == 4) {$DATE= "$_[0] " . NumberExpand $_[1]; return; } } # end of DateExpand ######################################################### # PrintText # # show text but change underscores to blanks # # and get rid of extra spaces # ######################################################### sub PrintText { #text my $list; # print $@ | tr \"_\" \" \"; $list= join '', @_; # get rid of underscores $list =~ s/_/ /g; # get rid of double (or more) spaces $list =~ s/ */ /g; # get rid of a trailing space $list =~ s/ $//g; print " $list\n"; } # end of PrintText ######################################################### # ProcessConnection # # process one of the 5 connections # ######################################################### sub ProcessConnection { #month day year time junk node junk junk my ($ampm, $hour, $minutes, $ones, $tens, $time); my ($io, $node, $tx1, $tx2); my ($talk1, $talk2); ExtraPrint "[PC0] args: @_ "; ExtraPrint "[PC0] args: @_[0] @_[1] @_[2] @_[3] @_[4] @_[5] @_[6] "; # test for today if requested if ($TESTDATE eq "today" && "$_[0] $_[1] $_[2]" ne $TODAY) {$REJECT++; return; } # test for recent (today & yesterday) if requested if ($TESTDATE eq "recent") {if ("$_[0] $_[1] $_[2]" ne $TODAY && "$_[0] $_[1] $_[2]" ne $YESTERDAY) {$REJECT++; return; } } # extract node number and make sure node is 4 digits $node= substr($_[5], 3, 4); ExtraPrint "[PC00] args: @_[0] @_[1] @_[2] @_[3] @_[4] @_[5] @_[6] "; ExtraPrint "[PC00] arg0 @_[0]"; ExtraPrint "[PC00] arg5 @_[5] node= $node"; if (length($node) < 4) {$node= $node . "0";} # day of week WhatDayIsIt $_[0], $_[1], $_[2]; # convert 24 hour time to 12 hour time $time= substr($_[3], 0, 5); ExtraPrint "[PC1] arg3= $_[3] arg5= $_[5] time=$time node= $node"; $time= TimeFix $time; ExtraPrint "[PC2] after TimeFix time= $time \n"; # change our message wrt IN or OUT if ($_[6] eq "OUT") {$tx1="outgoing_call_to node"; $tx2=""; } elsif ($_[6] eq "IN") {$tx1="node"; $tx2="called"; } ExtraPrint "[PC3] $SEQ: $tx1 $node $tx2 $DOW at $time " ; # print text version # note that most recent call always get sequential number 1 regardless # of what ORDER we use (lilo or lifo) if ($TEXT eq "true") {PrintText "$SEQ: $tx1 $node $tx2 $DOW $_[0] $_[1] at $time";} # we are done if we don't want any kind of speech output if ($SOUND eq "mute" && $V9 == 0) {return;} # get $NODE from $node (expand $node into sound files) NodeExpand $node; # get $TIME from $time (expand $time into sound files) TimeExpand $time; # do we say the date # get $DATE from month and day_of_month (expand day_of_month into sound files) if ($SAYDATE eq "true") {DateExpand ($_[0], $_[1]);} else {$DATE="";} # send to speech functions TalkConnection "$tx1 $NODE $tx2 $DOW $DATE at $TIME"; } # end of ProcessConnection ######################################################### # SeparateConnections # # separate the N incoming calls # ######################################################### sub SeparateConnections { my ($count, $fix, $line, $size, $size0); $size=$#CONNS +1; $size0= length(@CONNS[0]); if ($size0 == 0) {$size= 0;} if ($size > $NSEQ) {$size=$NSEQ;} ExtraPrint "[SC1] size= $size" ; $count=0; while ($count < $size) {if ($ORDER eq "lilo") {$SEQ=$NSEQ-$count} elsif ($ORDER eq "lifo") {$SEQ=$count+1;} $line= @CONNS[$count]; ExtraPrint "[SC2] $SEQ: $line" ; # we change the messages # Mar 21 2007 11:49:26 -0700 stn1811 connect UNCOMP # Mar 21 2007 11:01:23 -0700 IRLP call initiated to stn2080 # Mar 16 2007 17:16:52 -0700 Node Connected to reflector ref9200 on channel 5 # to # Mar 21 2007 11:49:26 -0700 stn1811 IN # Mar 21 2007 11:01:23 -0700 stn2080 OUT # Mar 16 2007 17:16:52 -0700 ref9205 OUT ExtraPrint "[SC3] $SEQ: $line \n"; $test= index($line, "connect "); if ($test > -1) {substr($line, $test, 20) = "IN"; } $test= index($line, "IRLP call initiated to"); if ($test > -1) {substr($line, $test, 23) = ""; $line= $line . " OUT"; } $test= index($line, "Node Connected to reflector"); if ($test > -1) {substr($line, $test, 28) = ""; $test= index($line, "0 on channel"); substr($line, $test, 13) = ""; $line= $line . " OUT"; } ExtraPrint "[SC4] $SEQ: $line \n"; @line= split ' ', $line; ExtraPrint "[SC5] $SEQ: @line \n"; ProcessConnection @line; $count++;; } # end of while } # end of SeparateConnections ######################################################### # GetConnections # # extract last N incoming calls from message log # ######################################################### sub GetConnections { my ($channel, $count, $file, @list, @list2); my ($query, $search, $size, $want, $want2); # do we want incoming or outgoing if ($INOUT eq "out") {$search= "call initiated|to reflector ref";} elsif ($INOUT eq "in") {$search= "connect [AUG]";} else # in and out {$search= "connect [AUG]|call initiated|to reflector ref";} ExtraPrint "[GC1] search term = $search "; ExtraPrint "[GC2] query node = $QUERY" ; ExtraPrint "[GC3] grep -E $search ${LOG}messages | tail -$_[0]" ; # fix up query to get nodes that connect with only 3 digits # example: Mar 05 2007 13:15:44 -0800 stn105 connect ADPCM if ($QUERY ne "X") {$query="stn$QUERY"; if (substr($QUERY,3,1) eq "0") {$query="stn$QUERY|stn" . substr($QUERY, 0, 3) . " ";} # we need to do some extra work if we are looking for a reflector $channel="X"; if (substr($QUERY,0,1) eq "9") {$channel= "channel " . substr($QUERY,3,1); $query="ref" . substr($QUERY,0,3) . "0." . $channel; } ExtraPrint "[GC4] query search term = <$query>" ; } # IRLP call initiated to stn1722 # stn1722 connect ADPCM # Node Connected to reflector ref9200 on channel 5 # get the N connect lines from messages file $want= $_[0]; $file= $LOG . "messages"; if ($QUERY eq "X") # search for regular connections {@list=`grep -E "$search" $file | tail -$want`;} elsif ($channel eq "X") # search for a specific node {@list=`grep -E "$search" $file | grep -E "$query" | tail -$want`;} else # search for a particular reflector {@list=`grep -E "$search" $file | grep -E "$query" | tail -$want`;} ### $count=`echo "@list" | wc -l`; chop($count); $count= $#list +1; $size= length(@list); if ($size eq "0") {$count="0";} ExtraPrint "[GC5] count= $count want= $want size= $size list= \n @list"; # if needed, get more connect lines from file messages.1 $file= $LOG . "messages.1"; if ($count < $want && -e $file) {$want2= $want - $count; ExtraPrint "[GC6] file= $file" ; ExtraPrint "[GC6] want2= $want2" ; if ($QUERY eq "X") {@list2=`grep -E "$search" $file | tail -$want2`} elsif ($channel eq "X") # search for a specific node {@list2=`grep -E "$search" $file | grep -E "$query" | tail -$want2`;} else # search for a particular reflector {@list2=`grep -E "$search" $file | grep -E "$query" | tail -$want2`;} ExtraPrint "[GC7] list2= @list2" ; push @list2, @list; @list= @list2; ExtraPrint "[GC8] list= @list" ; } # do we want the last connection spoken first (LIFO last in first out) if ($ORDER eq "lifo") {ExtraPrint "[GC9] reverse list order"; @list= reverse(@list); } # get rid of newlines $count= $#list; for $i (0..$count) {chomp @list[$i];} # V6 says print the list if ($V4 && ! $V9 ) {print "[GC10] list = \n"; for $i (0..$count) {ExtraPrint "list[$i]= @list[$i]";} } # transfer to CONNS array for $i (0..$count) {@CONNS[$i]= @list[$i];} } # end of GetConnections ######################################################### # HandleCompressedArgs # # handle an argument of the form -xyz # # where xyz are some of 123456789lstAIMORST # ######################################################### sub HandleCompressedArgs { my ($count, $char, $size); $size= length($_[0]); $count=0; while ($count < $size) {$char= substr($_[0], $count, 1); if ($char eq "L") {$ORDER="lilo";} elsif ($char eq "l") {$ORDER="lifo";} elsif ($char eq "T") {$TEXT="true";} elsif ($char eq "t") {$TEXT="false";} elsif ($char eq "A") {$SOUND="audio";} elsif ($char eq "M") {$SOUND="mute";} elsif ($char eq "R") {$SOUND="radio";} # elsif ($1 eq "today") # $TESTDATE="today" # elsif ($1 eq "recent") # $TESTDATE="recent" elsif ($char eq "O") {$INOUT="out";} elsif ($char eq "I") {$INOUT="in";} # elsif ($char eq "???") # $INOUT="inout" elsif ($char eq "S") {$SAYDATE="true";} elsif ($char eq "s") {$SAYDATE="false";} elsif ($char eq "1") {$NSEQ=1;} elsif ($char eq "2") {$NSEQ=2;} elsif ($char eq "3") {$NSEQ=3;} elsif ($char eq "4") {$NSEQ=4;} elsif ($char eq "5") {$NSEQ=5;} elsif ($char eq "6") {$NSEQ=6;} elsif ($char eq "7") {$NSEQ=7;} elsif ($char eq "8") {$NSEQ=8;} elsif ($char eq "9") {$NSEQ=9;} $count++; } } # end of HandleCompressedArgs ######################################################### # HandleVerboseArg # # handle an argument of the form V123 # ######################################################### sub HandleVerboseArg { #V456 my ($args, $char, $i, $size); $args= substr($_[0], 1, 9); $size= length($args); $i=0; while ($i < $size) {$char= substr($args, $i, 1); if ($char eq "0") {$V0=1;} # input args elsif ($char eq "1") {$V1=1;} # show sound files elsif ($char eq "2") {$V2=1;} # quietly show sound files elsif ($char eq "3") {$V3=1;} # show variables elsif ($char eq "4") {$V4=1;} # show selected connections elsif ($char eq "5") {$V5=1;} # elsif ($char eq "6") {$V6=1;} # elsif ($char eq "7") {$V7=1;} # elsif ($char eq "8") {$V8=1;} # elsif ($char eq "9") {$V9=1;} # verbose print $i++; } } # end of HandleVerboseArg ######################################################### # CheckArgs # # are there any input arguments # ######################################################### sub CheckArgs { my ($ab, $args); ExtraPrint ("CheckArgs args= @_ "); foreach $arg (@_) { $ab= substr($arg, 0, 1); ExtraPrint "CheckArgs arg= $arg ab= $ab \n"; if ($ab eq "-") {HandleCompressedArgs $arg} elsif ($ab eq "E") {$EXPAND= substr($arg, 1, 1)} elsif ($ab eq "N") {$NSEQ= substr($arg, 1, 8); if (length($NSEQ) == 0) {$NSEQ= 3;} if ($NSEQ < 1) {$NSEQ= 3;} if ($NSEQ > 20) {$NSEQ=20; print "NSEQ has been reduced to $NSEQ"; } } elsif ($ab eq "Q") {$QUERY= substr($arg, 1, 4); $NSEQ=1; } elsif ($ab eq "V") {HandleVerboseArg $arg} elsif ($arg eq "audio") {$SOUND="audio";} elsif ($arg eq "cron") {$MODE="cron";} elsif ($arg eq "help") {ShowHelp; exit 0; } elsif ($arg eq "in") {$INOUT="in";} elsif ($arg eq "inout") {$INOUT="inout";} elsif ($arg eq "lifo") {$ORDER="lifo";} elsif ($arg eq "lilo") {$ORDER="lilo";} elsif ($arg eq "mute") {$SOUND="mute";} elsif ($arg eq "mutedate") {$SAYDATE="false";} elsif ($arg eq "notext") {$TEXT="false";} elsif ($arg eq "options") {ShowOptions; exit 0; } elsif ($arg eq "out") {$INOUT="out";} elsif ($arg eq "probe") {ProbeFiles();} elsif ($arg eq "radio") {$SOUND="radio";} elsif ($arg eq "recent") {$TESTDATE="recent";} elsif ($arg eq "remote") {SetupRemoteTest();} elsif ($arg eq "saydate") {$SAYDATE="true";} elsif ($arg eq "TEST") {$TEST= "true"; $LOG= $TESTLOG; } elsif ($arg eq "text") {$TEXT="true";} elsif ($arg eq "time") {$MODE="time";} elsif ($arg eq "today") {$TESTDATE="today";} elsif ($arg eq "ul") {$PLAYTYPE="ul";} elsif ($arg eq "version") {print "$VERSION \n"; exit 0; } elsif ($arg eq "wav") {$PLAYTYPE="wav";} elsif ($arg eq "wavcat") {$PLAYTYPE="wavcat";} else {print "argument $arg is not recognized"; ShowUsage; exit 0; } } # we need /usr/bin/sox # if ($PLAYTYPE eq "wavcat" && ! -f /usr/bin/sox) # {print "wavcat option requires /usr/bin/sox"; # $PLAYTYPE="wav"; # } # handle Verbose flags if ($V0) { print ("INPUT ARGS: @_\n");} # user might want to see results of CheckArgs if ($V3) { print "CheckArgs INOUT= $INOUT \n"; print "CheckArgs MODE= $MODE \n"; print "CheckArgs N= $NSEQ \n"; print "CheckArgs ORDER= $ORDER \n"; print "CheckArgs PLAYTYPE= $PLAYTYPE \n"; print "CheckArgs QUERY= $QUERY \n"; print "CheckArgs SOUND= $SOUND \n"; print "CheckArgs TESTDATE= $TESTDATE \n"; print "CheckArgs TEXT= $TEXT \n"; if ($V0) { print "CheckArgs V0 print input args \n";} if ($V1) { print "CheckArgs V1 show sound files \n";} if ($V2) { print "CheckArgs V2 quietly show sound files \n";} if ($V3) { print "CheckArgs V3 show variables \n";} if ($V4) { print "CheckArgs V4 show selected connections \n";} if ($V9) { print "CheckArgs V9 turn on verbose print \n";} } } # end of CheckArgs ######################################################### # SpeakTime # # get and speak the time # ######################################################### sub SpeakTime { my $time; # get the 12 hour time $time=`date '+%H:%M %P'`; chomp $time; if ($TEXT eq "true") {PrintText ("the time is now $time");} if ($SOUND ne "mute" || $V2) {$time= TimeFix $time; TimeExpand $time; TalkConnection "the_time_is_now $TIME"; } } # end of SpeakTime ######################################################### # SpeakCron # # speak the cron announcement # ######################################################### sub SpeakCron { my $time; # get the 12 hour time $time=`date '+%l:%M %P'`; chomp $time; TimeExpand $time; if ($TEXT eq "true") {PrintText ("$CRON_ANNOUNCE $time");} if ($SOUND ne "mute" || $V2) {TalkConnection "$CRON_ANNOUNCE $TIME";} } # end of SpeakCron ######################################################### # ProbeFiles # show a text report on needed files ######################################################### sub ProbeFiles { my ($nu, $nw); print "in ProbeFiles\n"; # get the environment variables we need $BIN= $ENV{"BIN"}; $CUSTOM= $ENV{"CUSTOM"}; # what if we are running remote foreach $arg (@ARGV) {if ($arg eq "remote") {SetupRemoteTest();} } # info about contax print "invoked as $0\n"; print "version= "; system("$0 version"); chdir $CUSTOM; print "contax files:\n"; system("ls -lrt contax"); system("ls -lrt contax.???"); print "contax references in custom_decode:\n"; system("grep contax custom_decode"); # how many wav files in audio directory print "audio files:\n"; $nw= `ls ${CUSTOM_AUDIO}/*.wav | wc -l`; print "Number of wave files = $nw\n"; # how many ul files in audio directory $nu= `ls ${CUSTOM_AUDIO}/*.ul | wc -l`; print "Number of ul files = $nu\n"; if ($nu < 50 && $nw < 50) {print "ERROR: not enough ul/wav files\n";} # do we have a message file if (-f "${LOG}messages") {system("ls -l ${LOG}messages"); print "wc: "; system("wc -l ${LOG}messages"); } else {print "ERROR: message file is not in LOG directory $LOG\n";} # do we have TEST message file if (-f "${TESTLOG}messages") {system("ls -l ${TESTLOG}messages");} else {print "WARNING: TEST message file is not in TESTLOG"; print " path ${TESTLOG}messages\n"; } # do we have cal & tac if (-f "/usr/bin/cal") {system("ls -l /usr/bin/cal");} else {print "ERROR: /usr/bin/cal does not exist\n";} if (-f "/usr/bin/tac") {system("ls -l /usr/bin/tac");} else {print "ERROR: /usr/bin/tac does not exist\n";} # test cal by showing today's day of the week # do we have BIN/play BIN/key BIN/unkey if (-f "${BIN}/play") {system("ls -l ${BIN}/play");} else {print "ERROR: BIN/play does not exist in directory $BIN\n";} if (-f "${BIN}/key") {system("ls -l ${BIN}/key");} else {print "ERROR: BIN/key does not exist in directory $BIN\n";} if (-f "${BIN}/unkey") {system("ls -l ${BIN}/unkey");} else {print "ERROR: BIN/unkey does not exist in directory $BIN\n";} exit 0; } # end of ProbeFiles ######################################################### # SayNone # # do we need to convey that there were no connections # ######################################################### sub SayNone { my ($count, $tx1, $tx2, $tx3, $tx4); my ($lastindex, $size, $size0); $count= @CONNS; if (@CONNS[0] eq "") {$count= 0;} ExtraPrint "[TU1] count= $count REJECT= $REJECT" ; ExtraPrint "[TU2] testdate= $TESTDATE query= $QUERY" ; if ($count > $REJECT) {return;} $tx1=""; $tx2=""; $tx3=""; $tx4=""; if ($QUERY eq "X") {if ($TESTDATE eq "any") {$tx2=" ";} elsif ($TESTDATE eq "today") {$tx2="today";} elsif ($TESTDATE eq "recent") {$tx1="recent";} } else {NodeExpand $QUERY; if ($TESTDATE eq "any") {$tx3="for node $QUERY"; $tx4="for node $NODE"; } elsif ($TESTDATE eq "today") {$tx3="for node $QUERY today"; $tx4="for node $NODE today"; } elsif ($TESTDATE eq "recent") {$tx1="recent"; $tx3="for node $QUERY"; $tx4="for node $NODE"; } } # do we need to indicate via text that there were no connections if ($TEXT eq "true") {PrintText "there were no $tx1 connections $tx2 $tx3";} # do we need to indicate via sound that there were no connections if ($SOUND ne "mute" || $V2) {TalkConnection "there_were_no $tx1 connections $tx2 $tx4";} } # end of SayNone ######################################################### # DoConnections # # get and process connections # ######################################################### sub DoConnections { # get the last N incoming connections GetConnections $NSEQ; # get today's date string $TODAY=`date +"%b %d %Y"`; # get yesterday's date string $YESTERDAY=`date -d '1 day ago' +"%b %d %Y"`; $REJECT=0; # process each connection SeparateConnections; # if there were no connections, say so SayNone; } # end of DoConnections ######################################################### # Begin Mailine Code # ######################################################### ###print "initial args= @ARGV \n"; ###print "first arg= $ARGV[0] \n"; #print " arg= $0 \n"; # initialize the global parameters SetGlobals; # check command line parameters CheckArgs @ARGV; # prep if speech is involved SoundStart; # change directory to where the audio files are chdir $CUSTOM_AUDIO || die "can't cd to $CUSTOM_AUDIO \n"; if ($MODE eq "contax") {DoConnections;} elsif ($MODE eq "time") {SpeakTime;} elsif ($MODE eq "cron") {SpeakCron;} # clean up if speech was involved SoundFinish exit 0; ######################################################### # end of script contax ######################################################### # TODO # can I use sox to chop the pause between 20 2 when saying 22 NO ????? # sound files recorded from AT&T using voice of Mike us-english # http://www.research.att.com/~ttsweb/tts/demo.php # need to shave dead time off end of 20 30 etc so 20 6 sounds good # should I have a BLANK wavefile and trim all others ??? # ie the_time_is_now B 8 B twenty two B am # probe argument tells us about audio files etc # PERL version: # in text mode, show how long each connection lasted # in text node, associate a name with node# for previously contacted nodes # (have a separate node-name file which we periodically update) # in text node, get a summary for a given month # echoirlp