#!/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 # BUFFER=""; LED="0"; Rx=(0 0 0); # led; relays SYSTD_TREE=""; # service_log while sleep 2; clear; do # (1) Read buffer into local one (but without flushing buffers) # BUFFER="$BUFFER`$ROOT/com/read ioemu -`"; # (2) Parse each line # line_id=0; while IFS= read -r line; do # check if line is about GSTA if [ "${line:0:4}" = "GSTA" ]; then test "${line:4:1}" != "x" && LED="${line:4:1}"; # if set to 'x', ignore test "${line:5:1}" != "x" && Rx[1]="${line:5:1}"; # if set to 'x', ignore test "${line:6:1}" != "x" && Rx[2]="${line:6:1}"; # if set to 'x', ignore test "${line:7:1}" != "x" && Rx[3]="${line:7:1}"; # if set to 'x', ignore BUFFER=""; # empty buffer break; fi; # increment line count line_id=`expr $line_id + 1`; done <<< "$BUFFER"; # (3) Display led # echo -n "LED: "; $ROOT/src/disp-led $LED; # (4) 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;