SW/ControlSW/Archive/Dirigent/1219BeforeGit/Sessions/20191213_1920/0/Control/Tools.sh

#!/bin/bash

#./Dirigent.sh -r PingCheck
function PingCheck()
{
    $LogFunctionStart
	for Dev in $ALLDevs;
        do 
            ping -q -c 1 $Dev >/dev/null;
            if [ $? -ne 0 ]; then 
                LogIt "Ping $Dev ...KO, problem"; critical_error "ping $Dev KO";exit 1
            else 
                LogIt "Ping $Dev ...OK;"
            fi;
       done;\
    $LogFunctionEnd
}



function DataBaseQuerry
{
    #echo "$1"|psql -qAt -U golem golem_database #Real
    echo 100 #Offline
}



function RsyncDevices
{
    for Dev in $RASPs; do
       echo $Dev sync ..
       rsync --copy-links -e ssh $GWDirigentDir/Infrastructure/$Dev.sh $GWDirigentDir/Tools.sh $GWDirigentDir/Commons.sh golem@$Dev:
    done 
    for Dev in $DASs; do
       echo $Dev sync ..
       cp $GWDirigentDir/DASs/$Dev.sh $GWDirigentDir/Tools.sh $GWDirigentDir/Commons.sh DASs/
    done 
    echo Jeste Dirigent, Web, Miscs   sync ..
    cp $GWDirigentDir/Dirigent.sh $GWDirigentDir/Web.sh $GWDirigentDir/Tools.sh $GWDirigentDir/Commons.sh .
}

function RsyncDeviceFromDirigent
{
      echo "Syncing $ThisDev.sh ."
      rsync golem@Dirigent:$GWDirigentDir/$SUBDIR/$ThisDev.sh .
      rsync golem@Dirigent:$GWDirigentDir/Commons.sh .
      rsync golem@Dirigent:$GWDirigentDir/Tools.sh .
}


function RelayON()
{
    case  "$ThisDev" in
Chamber) echo "import lib as lib;lib.gpio_low($1)"|python  1>&- 2>&-
;;
Discharge) echo "import lib as lib;lib.gpio_low($1)"|python  1>&- 2>&-
;;
Charger) 
if [ $1 -le 8 ]; then
echo "from unipi.relays.controller20 import RelaysController;c = RelaysController();c.relay($1, True)"|python3  1>&- 2>&-; fi
if [ $1 -gt 8 ]; then
echo "from unipi.relays.controller25 import RelaysController;c = RelaysController();c.relay((($1-8)), True)"|python3  1>&- 2>&-; fi
    esac
}


function RelayOFF()
{
    case  "$ThisDev" in
Chamber) echo "import lib as lib;lib.gpio_high($1)"|python  1>&- 2>&-
;;
Discharge) echo "import lib as lib;lib.gpio_high($1)"|python  1>&- 2>&-
;;
Charger) 
if [ $1 -le 8 ]; then
echo "from unipi.relays.controller20 import RelaysController;c = RelaysController();c.relay($1, False)"|python3  1>&- 2>&-; fi
if [ $1 -gt 8 ]; then
echo "from unipi.relays.controller25 import RelaysController;c = RelaysController();c.relay((($1-8)), False)"|python3  1>&- 2>&-; fi
    esac
}


function mRelax
{
    sleep 0.1
}


function Relax
{
    sleep 1
}

#./Dirigent.sh -k
function KillAllGMs
{
    killall -u golem
}

function EditHosts
{
    for Dev in Dirigent $RASPs; do echo doing Dev: $Dev; ssh golem@$Dev -Y xterm -e "sudo emacs -nw /etc/hosts";done
}