From: Dan White Date: Fri, 5 May 2017 19:47:04 +0000 (-0500) Subject: add comments in the shell script decoder X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=64d5e403aa142779834380c971ecb64e0b07ecfe;p=valpo-ValpoSensorNet.git add comments in the shell script decoder --- diff --git a/extract-data.sh b/extract-data.sh index 1d1f405..6fadeca 100755 --- a/extract-data.sh +++ b/extract-data.sh @@ -2,18 +2,49 @@ nodeID=$1 -protofile=$2 +shift +logfiles="$*" + +if [ "$nodeID" == "42" -o "$nodeID" == "43" ]; then + protoname="NodeData" + protofile="NodeData.proto" +else + protoname="SensorData" + protofile="RAPID.proto" +fi + +echo $logfiles + + +# a bash function acts almost like an external program +# protoc will only decode one string at a time, so we need to loop over each +# line in the input stream outside of protoc +# +# "xxd" is a nice utility that can convert a file to hex strings or convert hex +# strings to bytes. This takes a hex string on stdin and outputs the +# corresponding bytes on stdout. +function decode() { + while IFS= read -r line; do + echo "$line" | xxd -r -p | protoc --decode $protoname $protofile + done +} #this is one long pipeline of commands, # the trailing "\" means that I'm not done with the line yet # but allows breaking up the commands so they are easier to read -grep -E "(NA|9150*) $nodeID" \ - | awk '{print $8}' \ - | while read line; do \ - echo "$line" \ - | xxd -r -p \ - | protoc --decode NodeData NodeData.proto \ - | grep vbatt; \ - done + +# 0 - you know what cat does.. +# +# 1 - grep filters the database log lines for a certain nodeID from either the +# nRF24 or RFM69 radio networks +# +# 2 - This awk program prints the 8th space-separated field from each line +# +# 3 - decode takes the hex string data and decodes to a line for each data +# element +cat $logfiles \ + | grep -E " (NA|9150*) $nodeID" \ + | awk '{print $8}' \ + | decode