diff --git a/Makefile b/Makefile index acfb024..f13e34b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PROGRAMS_INIT= archtester PROGRAMS_BIN= archtesterd \ + archtesterd_leds \ archtesterd_connectivity \ archtesterd_tlds \ archtesterd_tlsver \ @@ -9,6 +10,7 @@ PROGRAMS= $(PROGRAMS_INIT) \ $(PROGRAMS_BIN) SOURCES= archtester \ archtesterd \ + archtesterd_leds \ archtesterd_connectivity \ archtesterd_tlds \ archtesterd_tlsver \ diff --git a/archtesterd b/archtesterd index 8079aa6..b868dff 100755 --- a/archtesterd +++ b/archtesterd @@ -14,9 +14,6 @@ else testerid=dev0001 fi version=0.5 -ledredpin=17 -ledgreenpin=27 -ledyellowpin=22 logfile=/var/log/archtesterd.log resultfile=/var/log/archtesterd.res.log cmdlogfile=/var/log/archtesterd.cmd.log @@ -31,11 +28,10 @@ wgetopts="--dns-timeout=4 --connect-timeout=4 --read-timeout=10" daemon=1 debug=1 deepdebug=0 -sleeptime=2 -blinkhalftime=0.3 useleds=1 allowinstall=1 originalarguments="$*" +sleeptime=2 # # Initialize ------------------------------------------------------------ @@ -69,9 +65,9 @@ function archtester_debug { then if [ $daemon = 1 ] then - echo "archtester: debug: $*" >> $debugoutputfile + echo "archtesterd: debug: $*" >> $debugoutputfile else - echo "archtester: debug: $*" + echo "archtesterd: debug: $*" fi fi } @@ -81,9 +77,9 @@ function archtester_deepdebug { then if [ $daemon = 1 ] then - echo "archtester: debug: $*" >> $debugoutputfile + echo "archtesterd: debug: $*" >> $debugoutputfile else - echo "archtester: debug: $*" + echo "archtesterd: debug: $*" fi fi } @@ -193,127 +189,6 @@ function archtester_softwareupdate { fi } -# -# Initialize leds -# - -function archtester_ledinit { - if [ $useleds = 1 ] - then - gpio -g mode $ledredpin out - gpio -g mode $ledgreenpin out - gpio -g mode $ledyellowpin out - fi -} - -# -# Blink a led -# -# Input: pin number (gpw numbering) -# - -function archtester_ledblink { - if [ $useleds = 1 ] - then - pin=$1 - sleeptimearg=$2 - archtester_deepdebug Led $pin set to blink - sleeptimeargm=`(echo scale=0; echo "$sleeptimearg * 100") | bc | cut -f1 -d.` - archtester_deepdebug "Sleeptime $sleeptimearg, sleeptimem $sleeptimeargm" - tused=0 - tusedm=0 - while [ $tusedm -lt $sleeptimeargm ] - do - gpio -g write $pin 1 - sleep $blinkhalftime - gpio -g write $pin 0 - sleep $blinkhalftime - tused=`(echo scale=4; echo $tused + $blinkhalftime + $blinkhalftime) | bc` - tusedm=`(echo scale=0; echo "$tused * 100") | bc | cut -f1 -d.` - archtester_deepdebug "Tused $tused, tusedm $tusedm" - done - fi -} - -# -# Set one led mode -# -# Input: pin number (gpw numbering), state (on, off, blink), sleeptime (seconds) -# - -function archtester_ledset { - if [ $useleds = 1 ] - then - pinni=$1 - state=$2 - sleeparg=$3 - case $state in - off) - archtester_deepdebug Led $pinni set to off - gpio -g write $pinni 0;; - on) - archtester_deepdebug Led $pinni set to on - gpio -g write $pinni 1;; - blink) - archtester_ledblink $pinni $sleeparg & - nop=nop;; - *) nop=nop;; - esac - fi -} - -# -# Set the led bank mode -# -# Input: mode (off, flash, search, good, bad), sleeptime (seconds) -# - -function archtester_ledsmode { - - if [ $useleds = 1 ] - then - - modforleds=$1 - sleepytime=$2 - - redstate=off - greenstate=off - yellowstate=off - - case $modforleds in - off) - redstate=off - greenstate=off - yellowstate=off;; - flash) - redstate=on - greenstate=on - yellowstate=on;; - search) - redstate=off - greenstate=off - yellowstate=blink;; - good) - redstate=off - greenstate=on - yellowstate=off;; - bad) - redstate=on - greenstate=off - yellowstate=off;; - *) - redstate=blinking - greenstate=blinking - yellowstate=blinking;; - esac - - archtester_ledset $ledredpin $redstate $sleepytime - archtester_ledset $ledgreenpin $greenstate $sleepytime - archtester_ledset $ledyellowpin $yellowstate $sleepytime - - fi -} - # # Analyzer main loop # @@ -327,13 +202,14 @@ function archtester_loop { # archtester_debug initialize - archtester_ledinit - archtester_ledsmode off 0.5 - sleep 0.5 - archtester_ledsmode flash 10 - sleep 1.5 - archtester_ledsmode off 0.5 - + if [ $useleds = 1 ] + then + archtesterd_leds init + archtesterd_leds off + sleep 0.5 + archtesterd_leds flashall + fi + if [ $debug = 1 ] then opts="-debug"; @@ -344,7 +220,12 @@ function archtester_loop { # # Handle confifguration # - + + sleep 10 + if [ $useleds = 1 ] + then + archtesterd_leds flashtwo + fi archtester_fetchconfig archtester_readconfig @@ -352,12 +233,20 @@ function archtester_loop { # Handle software updates # + if [ $useleds = 1 ] + then + archtesterd_leds flashtwolast + fi archtester_softwareupdate # # Main loop # + if [ $useleds = 1 ] + then + archtesterd_leds search + fi archtester_debug main loop while true do @@ -367,7 +256,7 @@ function archtester_loop { fullresult=`cat $resultfile` mode=`echo $fullresult | cut -f1 -d:` archtester_debug "full result $fullresult mode $mode" - archtester_ledsmode $mode $sleeptime + archtester_leds $mode sleep $sleeptime done @@ -418,7 +307,7 @@ do shift debug=0;; *) - echo "archtester: unexpected argument: $1" + echo "archtesterd: unexpected argument: $1" exit 1;; esac done diff --git a/archtesterd_leds b/archtesterd_leds new file mode 100755 index 0000000..09f363e --- /dev/null +++ b/archtesterd_leds @@ -0,0 +1,201 @@ +#!/bin/bash + +# +# Settings ---------------------------------------------------------- +# + +ledredpin=17 +ledgreenpin=27 +ledyellowpin=22 +blinkhalftime=0.3 +ledsprocessesfile=/tmp/archtesterd_leds.processes +ledsdebugoutputfile=/tmp/archtesterd_leds.debug +deepdebug=1 + +# +# Functions --------------------------------------------------------- +# + +# +# Debug message printout +# +# Input: echoed text +# + +function archtesterd_deepdebug { + if [ $deepdebug = 1 ] + then + echo "archtesterd: debug: $*" >> $ledsdebugoutputfile + fi +} + +# +# Initialize the led system +# +# Input: none +# + +function archtesterd_leds_init { + archtesterd_deepdebug ledinit + gpio -g mode $ledredpin out + gpio -g mode $ledgreenpin out + gpio -g mode $ledyellowpin out +} + +# +# Blink a led +# +# Input: pin number (gpw numbering) +# + +function archtesterd_leds_blink { + pin=$1 + archtesterd_deepdebug Led $pin set to blink + while true + do + gpio -g write $pin 1 + sleep $blinkhalftime + gpio -g write $pin 0 + sleep $blinkhalftime + done +} + +# +# Set one led mode +# +# Input: pin number (gpw numbering), state (on, off, blink) +# + +function archtesterd_leds_set { + pinni=$1 + state=$2 + case $state in + off) + archtesterd_deepdebug Led $pinni set to off + gpio -g write $pinni 0;; + on) + archtesterd_deepdebug Led $pinni set to on + gpio -g write $pinni 1;; + blink) + archtesterd_leds_blink $pinni & + echo $! >> $ledsprocessesfile + archtesterd_deepdebug registered a blinker background process $! + nop=nop;; + *) nop=nop;; + esac +} + +# +# Set the led bank mode +# +# Input: mode (off, flashall, flashtwo, flashtwolast, search, good, bad), sleeptime (seconds) +# + +function archtesterd_leds_mode { + + modforleds=$1 + + archtesterd_deepdebug leds_mode $modforleds + + redstate=off + greenstate=off + yellowstate=off + + case $modforleds in + off) + redstate=off + greenstate=off + yellowstate=off;; + flashall) + redstate=on + greenstate=on + yellowstate=on;; + flashtwo) + redstate=off + greenstate=on + yellowstate=on;; + flashtwolast) + redstate=on + greenstate=on + yellowstate=off;; + search) + redstate=off + greenstate=off + yellowstate=blink;; + good) + redstate=off + greenstate=on + yellowstate=off;; + bad) + redstate=on + greenstate=off + yellowstate=off;; + *) + redstate=blinking + greenstate=blinking + yellowstate=blinking;; + esac + + archtesterd_leds_set $ledredpin $redstate + archtesterd_leds_set $ledgreenpin $greenstate + archtesterd_leds_set $ledyellowpin $yellowstate +} + +# +# Main program ---------------------------------------------- +# + +# +# Terminate any ongoing leds programs that may still be blinking leds +# + +if [ -s $ledsprocessesfile ] +then + archtesterd_deepdebug kill processes `cat $ledsprocessesfile` from $$ + kill `cat $ledsprocessesfile` 2> /dev/null > /dev/null + rm -f $ledsprocessesfile + archtesterd_deepdebug killing done from $$ +fi + +# +# Process arguments +# + +while [ $# -gt 0 ] +do + case x$1 in + x-debug) + shift + deepdebug=1;; + x-quiet) + shift + deepdebug=0;; + xoff) + archtesterd_leds_mode off + exit 0;; + xflashall) + archtesterd_leds_mode flashall + exit 0;; + xflashtwo) + archtesterd_leds_mode flashtwo + exit 0;; + xsearch) + archtesterd_leds_mode search + exit 0;; + xgood) + archtesterd_leds_mode good + exit 0;; + xbad) + archtesterd_leds_mode bad + exit 0;; + xinit) + archtesterd_leds_init + exit 0;; + *) + echo "archtesterd_leds: unexpected argument: $1" + exit 1;; + esac +done + +echo "archtesterd_leds: no command given" +exit 1