Quellcode durchsuchen

setting up I2C to PIU connection

* cronjob will maintain socat and ichthyic (i2c-to-ttyPIU bridge)
* popufare_monitor cronjob script
abram vor 5 Jahren
Ursprung
Commit
f4b6b3fb47
2 geänderte Dateien mit 132 neuen und 0 gelöschten Zeilen
  1. 3 0
      busunit/scripts/crontab.root
  2. 129 0
      busunit/scripts/popufare_monitor

+ 3 - 0
busunit/scripts/crontab.root

@@ -0,0 +1,3 @@
+# min hour day-month month day-week cmd
+* * * * * /home/bus/bin/popufare_monitor
+

+ 129 - 0
busunit/scripts/popufare_monitor

@@ -0,0 +1,129 @@
+#!/bin/bash
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+# 
+# This file is part of PopuFare.
+# 
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+# This script expects to be called as root from a cron job.
+#
+# This script will do some basic monitoring of different pieces
+# of the system.
+# If a problem is discovered, this program will attemp to report
+# and, potentially, try to fix them.
+#
+
+VERBOSE=2
+
+bindir=/home/bus/bin
+cfgdir=/home/bus/config
+i2cdev=/dev/i2c-1
+piddir=/tmp
+ptydir=/tmp
+logdir=/tmp
+
+popmonlog=/tmp/popmon.log
+
+if [[ "$VERBOSE" -gt 0 ]] ; then
+  ts=`date -u +'%s.%N'`
+  echo "# $ts [$$] popufare_monitor running" >> $popmonlog
+fi
+
+function setup_PIU_socat() {
+  if [[ -e $piddir/socat.pid ]] ; then
+    _p=`cat $piddir/socat.pid`
+    if [[ -e /proc/${_p} ]] ; then kill -9 $_p ; fi
+    rm -f $piddir/socat.pid
+  fi
+
+  rm -f /dev/ttyPIU
+  rm -f $ptydir/ttyPIUich
+
+  if [[ "$VERBOSE" -gt 0 ]] ; then
+    ts=`date -u +'%s.%N'`
+    echo "# $ts [$$] popufare_monitor: starting socat" >> $popmonlog
+  fi
+
+  socat -d -d pty,raw,echo=0,link=$ptydir/ttyPIUich pty,raw,echo=0,link=/dev/ttyPIU > $logdir/socat.log 2>&1 &
+  echo "$!" > $piddir/socat.pid
+}
+
+function setup_I2C_PIU_bridge() {
+  if [[ -e $piddir/ichthyic.pid ]] ; then
+    _p=`cat $piddir/ichthyic.pid`
+    if [[ -e /proc/${_p} ]] ; then kill -9 $_p ; fi
+    rm -f $piddir/ichthyic.pid
+  fi
+
+  if [[ "$VERBOSE" -gt 0 ]] ; then
+    ts=`date -u +'%s.%N'`
+    echo "# $ts [$$] popufare_monitor: starting ichthyic i2c to PIU bridge" >> $popmonlog
+  fi
+
+  $bindir/ichthyic-passthrough --i2c $i2cdev --pty $ptydir/ttyPIUich -v -v -L $logdir/ichthyic.log >> $popmonlog 2>&1 &
+  echo "$!" > $piddir/ichthyic.pid
+}
+
+# If we have an appropriate drop file and I2C is enabled, 
+# make sure socat is running and our shim program is running.
+#
+if [[ -e $cfgdir/popufare.ichthyic &&  -e $i2cdev ]] ; then
+
+  ## make sure socat is running to tie ttyPIU to ttyPIUich
+  ## together
+  ##
+  if [[ ! -e $piddir/socat.pid ]] ; then
+    setup_PIU_socat
+  fi
+
+  p=`cat $piddir/socat.pid`
+  if [[ ! -e /proc/${p} ]] ; then
+
+    if [[ "$VERBOSE" -gt 1 ]] ; then
+      ts=`date -u +'%s.%N'`
+      echo "## $ts [$$] stale socat.pid file? no process id found for $p" >> $popmonlog
+    fi
+
+    setup_PIU_socat
+  fi
+
+  ## Now run the shim program to connect the I2C to the ttyPIUich line
+  ##
+  if [[ ! -e $piddir/ichthyic.pid ]] ; then
+    setup_I2C_PIU_bridge
+  fi
+
+  p=`cat $piddir/ichthyic.pid`
+  if [[ ! -e /proc/${p} ]] ; then
+
+    if [[ "$VERBOSE" -gt 1 ]] ; then
+      ts=`date -u +'%s.%N'`
+      echo "## $ts [$$] stale ichthyic.pid file? no process id found for $p" >> $popmonlog
+    fi
+
+    setup_I2C_PIU_bridge
+  fi
+
+fi
+
+if [[ "$VERBOSE" -gt 0 ]] ; then
+  ts=`date -u +'%s.%N'`
+  echo "# $ts [$$] popufare_monitor finished" >> $popmonlog
+fi
+
+exit 0
+
+