#!/bin/bash #set -x # ############################################################## # Copyright (c) 2005 by KK7VN Curt Jutzi ############################################################## # # ------- COPYRIGHT NOTICE ----------- # # Permission to use, copy, modify, and distribute this # software and its documentation for any purpose and # without fee is hereby granted, provided that the above # copyright notice appear in all copies and that both the # copyright notice and this permission notice and warranty # disclaimer appear in supporting documentation, and that # the author or entity using, copying, modifying or # distributing this software acquire any (no) financial # revenue from its use, and that written notification # and premission be granted from Curt Jutzi KK7VN # (kk7vn@arrl.net, curtjutzi@yahoo.com) before its use. # # Curt Jutzi or KK7VN may not be used in advertising # or publicity pertaining to distribution of the software # without specific, written prior permission. # # Curt Jutzi (KK7VN) disclaims all warranties with regard # to this software, including all implied warranties of # merchantability and fitness. In no event shall Curt Jutzi # (KK7VN) be liable for any special, indirect or # consequential damages or any damages whatsoever resulting # from loss of use, data or profits, whether in an action # of contract, negligence or other tortious action, arising # out of or in connection with the use or performance of # this software,or its distribution. # ############################################################## ############################################################################# # # Author: Curt Jutzi KK7VN # # Script: weather-test # # DESCRIPTION: # USAGE: weather_test [nonotify] [nowait] # # HISTORY: # Aug 24th 2005 - Curt Jutzi : Created and published # Aug 25th 2005 - Curt Jutzi : Fixed key'n bug if there was an ID're # added lockout and unlockout around final # announcement # Aug 26th 2005 - Curt Jutzi : Added a bunch of fixes # Aug 27th 2005 - kk7vn: - moved ulockout from the bottom # because it would unkey durrning an # active qso on the link. Chaned, so it # had to be active to call unlockout. # - Aggregated the state parsing change # rather than having each state do'n it's # own thing. # # DEPENDENCIES: # idmon (id're), # idlemon (monitors freq. idle), # flite (audio text 2 speech) # waitclear ( wait until channel is clear) # ############################################################################ # # DECLARE CONSTANTS HERE # ### ### DEBUG AIDS ### ### DEBUG - only output string, not push to flite ### Set this to true otherwise, false ### DEBUG_NO_FLITE=false ### ### ### ### if [ "$CAP_PROXY" == "" ] then # # you can set proxy here.. # CAP_PROXY="" fi DISABLE_IDLEMON=${LOCAL}/disable_idlemon # for weathermon with idlemon DISABLE_IDMON=${LOCAL}/disable_idmon # for weathermon with idlemon DISABLE_CALLS=${LOCAL}/nocalls # for idlemon if ( $DEBUG_NO_FLITE ) then FLITE=" cat -" else FLITE="${CAPDIR}/flite/flite --setf duration_stretch=1.2 --setf int_f0_target_mean=145" fi # # CHECK TO ENSURE YOU'VE GOT CAPDIR ASSIGNED # if [ "$CAPDIR" == "" ] then echo "INVALID CAPDIR" exit 0 fi # # Creat log directory in noocheck # mkdir -p ${CAPDIR}/logs # # Load common functions # [ -z "$CUSTOM" ] && CUSTOM=/home/irlp/custom source ${SCRIPT}/common-functions.sh # # Load common functions # source ${CAPDIR}/scripts/noaacheck_common_functions.sh # # ASSIGN NOWAIT and NO-NOTIFY # if [ "$5" != "nowait" ] && [ "$6" != "nowait" ] then SHOULDWAIT=true else SHOULDWAIT=false fi if [ "$5" != "nonotify" ] && [ "$6" != "nonotify" ] then SHOULDNOTIFY=true else SHOULDNOTIFY=false fi # # Level set # if [ "$4" == "none" ] || [ "$4" == "None" ] then LEVEL="" else LEVEL=" -l $4" fi # # check to see if there are any alerts.. based on Geo Code.. if # if Geo Code is 0.. get all alerts # if level is non.. don't set level # # # Geocode set # if [ "$3" == "0" ] then GEOCODE="" else GEOCODE=" -g $3" fi ################################# # proceedure announce_no_alerts ################################# # # - one location to announce # there are no new alerts # ################################# announce_no_alerts () { if ($SHOULDNOTIFY) then # # wait until clear - see idlemon # if ( $SHOULDWAIT ) then ${SCRIPT}/waitclear # remove if you don't use idlemon fi lockout ${BIN}/forcekey echo "NO WEATHER WARNINGS REGISTERED AT THE NOAA WEB SITE, THE AUTOMATED CAP ALERT SYSTEM FROM K7RPT IS NOW CLEAR" | ${FLITE} #echo "NO WEATHER WARNINGS REGISTERED AT THE NOAA WEB SITE, THE AUTOMATED CAP ALERT SYSTEM FROM K7RPT IS NOW CLEAR" ${BIN}/forceunkey unlockout fi # notify } ################################# ####### START OF MAIN ########## ################################# # # - loop forever # while (true) do # if ($SHOULDNOTIFY) then # if [ "$3" == "0" ] then REGION="ALL GEO REGIONS" else REGION="GEO REGIONS $3" fi lockout ${BIN}/forcekey echo "THE SYSTEM IS EXECUTING A WEATHER QUERY FOR $REGION: THIS WILL TAKE A MOMENT, PLEASE STAND BUY" | ${FLITE} ${BIN}/forceunkey unlockout fi # should notify ALERTCNT=`java noaacheck -u http://www.weather.gov/alerts/$2.cap $CAP_PROXY $LEVEL $GEOCODE -c ` #ALERTCNT=`java noaacheck -u $2 $CAP_PROXY $LEVEL $GEOCODE -c ` # # if there was any alerts.. # if [ "$ALERTCNT" != "" ] && [ "$ALERTCNT" != "0" ] then # # tell them if they asked # if ($SHOULDNOTIFY) then lockout ${BIN}/forcekey # # proper english here :-) # if [ "$ALERTCNT" == "1" ] then echo "$ALERTCNT ALERT WAS FOUND, PLEASE STAND BUY WHILE THE ANNOUNCEMENT IS ACQUIRED" | ${FLITE} else echo "$ALERTCNT ALERTS WERE FOUND, PLEASE STAND BUY WHILE THE ANNOUNCEMENTS ARE ACQUIRED" | ${FLITE} fi ${BIN}/forceunkey unlockout fi # should notify # # get the descriptor cap object so you can parse out the id and check if you've # announced it.. # java noaacheck -u http://www.weather.gov/alerts/$2.cap $CAP_PROXY $LEVEL $GEOCODE -d -h -e -w -n > /tmp/weather_desc$$ # -- debug -- # java noaacheck -u $2 $CAP_PROXY $LEVEL $GEOCODE -d -h -e -w -n > /tmp/weather_desc$$ cp /tmp/weather_desc$$ /tmp/weather_desc_last # # go through each alert.. # ACTALERT=1; ALERTSANNOUNCED=0; # lock out for the entire announcment set.. # I had problems with the ID're.. there is a race condition and # for me to solve the audio mixer issues, I just bagged the id're # lOCKOUT locks out incoming calls, and the id'er from firing. # lockout # # For each alert in the list # while [ $ACTALERT -le $ALERTCNT ] do # # acqure the announcment id - this is unique in the NOAA # setup. Grab this and use it as the unique id for checking # later to see if you've already sent it. # WEBID=`cat /tmp/weather_desc$$ | grep -m $ACTALERT "WB:" | tail -n 1 | sed -e "s/WB://g" | sed -e "s/ //g"` # # found that oregon put's an info structure in # even if there is not real ALERT.. i.e. no WEBID nothing.. # this causes the noaacheck.class to throw an exception # -- here I check for no WEBID -- if not.. I go to the next # if [ "$WEBID" == "" ] then # # add the ALERT COUNT # ACTALERT=`expr $ACTALERT + 1` continue; fi # # see if you've played it # OLDALERT=false; if [ -f ${CAPDIR}/logs/weather.log ] then for oldWEBID in `cat ${CAPDIR}/logs/weather.log` do if [ "$oldWEBID" == "$WEBID" ] then echo -e "\r\t\t\t\t\t already registered $WEBID\_" `date -d "\`date\`" "+%Y%m%d%H%M%S"` OLDALERT=true; break; fi # if already done this announcement done fi # if there is a log created? # # if this alert has been covered.. skip it.. move to the next one # if ($OLDALERT) then # # add the ALERT COUNT # ACTALERT=`expr $ACTALERT + 1` continue; fi # # get the rest of the stuff you need # DESC=`cat /tmp/weather_desc$$ | grep -m $ACTALERT "DS:" | tail -n 1 | sed -e "s/DS://g"` HEADLN=`cat /tmp/weather_desc$$ | grep -m $ACTALERT "HL:" | tail -n 1 | sed -e "s/HL://g"` EFFUNTL=`cat /tmp/weather_desc$$ | grep -m $ACTALERT "EU:" | tail -n 1 | sed -e "s/EU://g"` EFFUNTL_FORMAL=`date -d "$EFFUNTL" "+%A, %B %d, %l:%M %p" | sed -e "s/AM/A.M./g" | sed -e "s/PM/P.M./g"` # # add the ALERT COUNT # ACTALERT=`expr $ACTALERT + 1` # # check the effective until date and ensure that it's still in effect # EFU_NUM=`date -d "$EFFUNTL" "+%Y%m%d%H%M%S"` NOW_NUM=`date -d "\`date\`" "+%Y%m%d%H%M%S"` if [ $EFU_NUM -lt $NOW_NUM ] then echo "********** THIS IS NOT A GOOD ALERT ******** EFFECTIVE TIL DATE ($EFFUNTL_FORMAL) NOW DATE `date` ID=($WEBID)" continue; fi # # save the alert # in the log and use it later so you don't re-announce it. # log "weathermon - REGISTERING ALERT: $WEBID " log "weathermon - EffectiveUntil: $EFFUNTL_FORMAL " log "weathermon - HEADLINE: $HEADLN" echo -n " $WEBID" >> ${CAPDIR}/logs/weather.log echo -e "\n ****** REGISTERING NEW ALERT : $WEBID" `date -d "\`date\`" "+%Y%m%d%H%M%S"` # # - noaa has some isues with flite.. # this script tries to fix that.. # TMPDESC=`echo "$DESC" | ${CAPDIR}/scripts/noaa_time_nm_fix` DESC=$TMPDESC; #****************************************************** # # Every State has there deal.. put the sed/awk scripts here # # BEGIN #****************************************************** # # FLORDIA --- The seminal State !! - Go Gaters.. # if [ "$2"=="fl" ] || [ "$2"=="FL" ] then TMPDESC=`echo "$DESC" | sed -r "s/$AMZ(.*)[0-9]- //g"| sed -r "s/\/X(.*)Z\///g"` DESC=$TMPDESC; fi # ############################################## # #### ALL LOCATIONS / STATES ################## # ############################################## # # ######################################## # # * * * * * * * # # # # * * * * * * * ####################### # # * * * * * * * # # # # * * * * * * * ####################### # # * * * * * * * # # # # * * * * * * * ####################### # # * * * * * * * # # # ######################################## # # # # ######################################## # # # # ######################################## # # # # ######################################## # # "...[0-9]- " and "/X... Z/" # # - STATEPREFIX - Awk SCRIPT simply takes lower case to upper case.. # .. and NO I'm not an AWK programmer :0-).. # STATEPREFIX=`echo "" | awk -v PARM=$2 '{ \ { \ digit=substr(PARM,1,1);\ i=index("abcdefghijklmnopqrstuvwxyz",digit); \ if (i > 0) \ { \ OUTPARM=sprintf("%c",substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)); \ } \ else \ OUTPARM=digit; \ digit=substr(PARM,2,1);\ if ((i=index("abcdefghijklmnopqrstuvwxyz",digit)) > 0) \ OUTPARM=sprintf("%c%c",OUTPARM,substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)); \ else \ OUTPARM=sprintf("%c%c",OUTPARM,digit);\ printf("%s",OUTPARM);\ }\ }'`; TMPDESC=`echo "$DESC" | sed -r "s/${STATEPREFIX}Z(.*)[0-9]- //g"| sed -r "s/\/X(.*)Z\///g"| sed -e "s/NF-//g" | sed -e "s/\// /g"| sed -e "s/-/,/g" ` DESC=$TMPDESC; #****************************************************** # END # # Every State has there deal.. put the sed/awk scripts here # #****************************************************** # # sound the alarm if this the first announcment (remove if you wish) # if [ "$ALERTSANNOUNCED" == "0" ] then dtmfdial 33339999 fi # # .. aggregate all the stuff here.. put it in a temp # .. file and play it out below # echo "THIS IS AN AUTOMATED WEATHER MESSAGE." > /tmp/warning$$ echo "THE SUBJECT FOR THIS ANNOUNCMENT IS: $HEADLN." >> /tmp/warning$$ echo "THIS MESSAGE IS EFFECTIVE UNTIL: $EFFUNTL_FORMAL." >> /tmp/warning$$ echo "MESSAGE TO FOLLOW:" >> /tmp/warning$$ echo "$DESC." >> /tmp/warning$$ # -- debug -- #cat /tmp/warning$$ # # keep track of the alerts I've announced to see if # we've announced - used only for the notification # process # ALERTSANNOUNCED=`expr $ALERTSANNOUNCED + 1` # # announce it.. (push this thing out) # ${BIN}/forcekey cat /tmp/warning$$ | ${FLITE} # -- debug -- # cat /tmp/warning$$ ${BIN}/forceunkey rm -f /tmp/warning$$ done # while -- for each alert unlockout # # clean up # rm -f /tmp/weather_desc$$ # # announce no alerts if no new ones were found to announce # if [ $ALERTSANNOUNCED -le 0 ] then echo -e -n "\rNo NEW Alerts " `date -d "\`date\`" "+%Y%m%d%H%M%S"` announce_no_alerts; else lockout ${BIN}/forcekey echo ": THIS HAS BEEN AN AUTOMATED WEATHER ALERT, GENERATED USING THE AUTOMATED NOAA CAP ALERT SYSTEM ON THE K7RPT IRLP REPEATER SYSTEM, QUESTIONS ON THE SYSTEM, PLEASE ASK KK7VN or visit www dot qsl dot net/kk7vn for more information." | ${FLITE} ${BIN}/forceunkey unlockout fi else # if alert count echo -e -n "\rNo Alerts Found " `date -d "\`date\`" "+%Y%m%d%H%M%S"` announce_no_alerts fi # alert count # # if wait 0 sec, that means.. bail otherwise .. wait # if [ "$1" == "0" ] then break; else sleep $1 # every 10+ min fi done # end infinite loop