commit 125e88ccbad2d1e51315b972461669ade00a4761 Author: xdrm-brackets Date: Sun Jan 28 17:42:13 2018 +0100 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fe43c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.lock diff --git a/com b/com new file mode 160000 index 0000000..e84678a --- /dev/null +++ b/com @@ -0,0 +1 @@ +Subproject commit e84678ac6b9524a2c8a270f2af88a79a59fd2923 diff --git a/daemon b/daemon new file mode 100755 index 0000000..15cfdb8 --- /dev/null +++ b/daemon @@ -0,0 +1,32 @@ +#!/bin/bash + + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); + +# (2) Check required arguments +test $# -lt 1 && echo -e "ERR: Missing argument\n\n\tSATS_IP\tThe ip for the SATS system\n" && exit 1; +SATS_IP=$1; + +# (3) Check lock file # +test -f $ROOT/.lock && echo "Daemon already started ($ROOT/.lock)" && exit 1; +touch $ROOT/.lock; + + + +# (2) Set traps before starting any subproccess +#--------------------------------------------------------# +trap "kill -9 $SERV_PID 2>/dev/null; pkill nc 2>/dev/null; rm $ROOT/.lock 2>/dev/null; exit 1;" INT; +trap "kill -9 $SERV_PID 2>/dev/null; pkill nc 2>/dev/null; rm $ROOT/.lock 2>/dev/null; exit 1;" KILL; + + + +# (3) Wait for trigger to launch server +#--------------------------------------------------------# +# (1) Wait for trigger # +$ROOT/com/trigger 9999; + +# (2) Launch server in background # +$ROOT/com/launch ioemu $SATS_IP 44440 44441; \ No newline at end of file diff --git a/src/disp-led b/src/disp-led new file mode 100755 index 0000000..b9b4a49 --- /dev/null +++ b/src/disp-led @@ -0,0 +1,21 @@ +#!/bin/bash + + +# (1) Declare association state <-> color_id +#--------------------------------------------------------# +# (1) Create associative array # +declare -A COLCODE; + +# (2) States # +COLCODE[0]=90; +COLCODE[R]=31; +COLCODE[G]=32; +COLCODE[B]=34; + +# (2) Check argument + display led +#--------------------------------------------------------# +# (1) Check argument # +test $# -ge 1 && state="$1" || state="0"; + +# (2) Display led # +echo -e "\e[${COLCODE[$state]}m⬤\e[0m"; \ No newline at end of file diff --git a/src/disp-relay b/src/disp-relay new file mode 100755 index 0000000..4e76594 --- /dev/null +++ b/src/disp-relay @@ -0,0 +1,19 @@ +#!/bin/bash + + +# (1) Declare association state <-> color_id +#--------------------------------------------------------# +# (1) Create associative array # +declare -A COLCODE; + +# (2) States # +COLCODE[0]=90; +COLCODE[1]=32; + +# (2) Check argument + display led +#--------------------------------------------------------# +# (1) Check argument # +test $# -ge 1 && state="$1" || state="0"; + +# (2) Display led # +echo -e "\e[${COLCODE[$state]}m⏺\e[0m"; \ No newline at end of file diff --git a/sub-view/gpio b/sub-view/gpio new file mode 100755 index 0000000..084c5ae --- /dev/null +++ b/sub-view/gpio @@ -0,0 +1,50 @@ +#!/bin/bash + + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); +ROOT=`dirname $ROOT`; + +# (2) Check lock file # +test ! -f $ROOT/.lock && echo "Daemon not started" && exit 1; + + + +# (2) While viewing loop +#--------------------------------------------------------# +# (1) Initialise vars # +LED="0"; Rx=(0 0 0); # led; relays +SYSTD_TREE=""; # service_log + +# (2) Get BUF_IN # +source $ROOT/com/config_ioemu; + + +while sleep 2; clear; do + + # (3) Get last value from lines beginning by 'GSTA' # + STATE="`cat $BUF_IN | grep -Po "^GPIO(.+)$" | sed 's/^GPIO\(....\)$/\1/g' | tail -n1`"; + + echo "state: $STATE"; + + # (4) Apply to values if not 'x' (means 'ignore' that chip) # + if [ ! -z "$STATE" ]; then + + test "${STATE:0:1}" != "x" && LED="${STATE:0:1}"; # if set to 'x', ignore + test "${STATE:1:1}" != "x" && Rx[1]="${STATE:1:1}"; # if set to 'x', ignore + test "${STATE:2:1}" != "x" && Rx[2]="${STATE:2:1}"; # if set to 'x', ignore + test "${STATE:3:1}" != "x" && Rx[3]="${STATE:3:1}"; # if set to 'x', ignore + + fi; + + # (5) Display led # + echo -n "LED: "; $ROOT/src/disp-led $LED; + + # (6) Display relays # + echo -n "R1: "; $ROOT/src/disp-relay ${Rx[1]}; + echo -n "R2: "; $ROOT/src/disp-relay ${Rx[2]}; + echo -n "R3: "; $ROOT/src/disp-relay ${Rx[3]}; + +done; \ No newline at end of file diff --git a/view b/view new file mode 100755 index 0000000..c7488d7 --- /dev/null +++ b/view @@ -0,0 +1,21 @@ +#!/bin/bash + + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); + +# (2) Check lock file # +test ! -f $ROOT/.lock && echo "Daemon not started" && exit 1; + +# (3) Check argument # +test $# -lt 1 && echo -e "ERR: Missing argument\n\n\tgpio\tGPIO real-time view\n\tsystemd\tSystemd real-time dependency tree\n\tlogs\tLogs real-time view\n" && exit 1; + +# (4) Check argument binds to an actual file # +test ! -f $ROOT/sub-view/$1 && echo -e "ERR: No such value for argument" && exit 1; + + +# (2) Start sub-view +#--------------------------------------------------------# +$ROOT/sub-view/$1; \ No newline at end of file