add comments in the shell script decoder
authorDan White <dan@whiteaudio.com>
Fri, 5 May 2017 19:47:04 +0000 (14:47 -0500)
committerDan White <dan@whiteaudio.com>
Fri, 5 May 2017 19:47:04 +0000 (14:47 -0500)
extract-data.sh

index 1d1f4056f0921ef331e2ea14b80b1d8ecabcbcfe..6fadecace384a6ede22a9dc8286fb252f2108725 100755 (executable)
@@ -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