#!/bin/bash SUBDIR=Infrastructure ThisDev=Charger source Commons.sh PowerSupplyOscCMD="netcat -w 1 PowerSupplyOsc 5555" PowerSupplyOscSTREAM="netcat PowerSupplyOsc 5555" PowerSupplyOscCMD="LogIt netcat -w 1 PowerSupplyOsc 5555" PowerSupplyOscSTREAM="echo netcat PowerSupplyOsc 5555" #./Dirigent.sh -r "Charger RelayON 1" #./Charger.sh -r "RelayON 1" function BtShortCircuitsDisEngage() { RelayON 3; } function BtShortCircuitsEngage() { RelayOFF 3; } function CdShortCircuitsDisEngage() { RelayON 1; } function CdShortCircuitsEngage() { RelayOFF 1; } function HVlighON() { RelayON 7; } function HVlighOFF() { RelayOFF 7; } #**************************************** function PowerSupplyHVcontactorON() { RelayON 16; } function PowerSupplyHVcontactorOFF() { RelayOFF 16; } #function PowerSupplyHVcontactorON() { RelayON 13; } #Test na Gabove Zdroji #function PowerSupplyHVcontactorOFF() { RelayOFF 13; } #Test na Gabove Zdroji #**************************************** function BtHVrelayON() { RelayON 4 ; } function BtHVrelayOFF() { RelayOFF 4 ; } function CdHVrelayON() { RelayON 2 ; } function CdHVrelayOFF() { RelayOFF 2 ; } function ChargingResistor_I_DisEngage() { RelayON 15 ; } function ChargingResistor_I_Engage() { RelayOFF 15 ; } #function ChargingResistor_II_DisEngage() { RelayON 6 ; } #function ChargingResistor_II_Engage() { RelayOFF 6 ; } ChargingFlag=0 ChargingResistors=0 function InitDischarge() { $LogFunctionGoingThrough CommonInitDischarge echo OK } #./Charger.sh -r "PrepareDischarge 10 15" #./Charger.sh -r "PostDischarge" function PrepareDischarge() { $LogFunctionStart UBtRequest=$1;UCdRequest=$2 OpenOscDVMAcquiring HVOsc 1 if [ $UBtRequest -gt 0 ]; then BtStatus=Charging; BtShortCircuitsDisEngage; BtHVrelayON; LogIt "Bt capacitor charging started" else LogIt "Bt capacitor charging not requested" BtStatus=Charged; fi if [ $UCdRequest -gt 0 ]; then CdStatus=Charging; CdShortCircuitsDisEngage; CdHVrelayON; LogIt "Cd capacitor charging started" else LogIt "Cd capacitor charging not requested" CdStatus=Charged; fi Relax;HVon;Relax ChargingResistorsAllOFF while [ $BtStatus == Charging ] || [ $CdStatus == Charging ]; do PowSupVoltage=`ReadDVMOscilloscope HVOsc` LogIt "Charging ... HV=$PowSupVoltage V" if [ $PowSupVoltage -ge $UBtRequest ] && [ "$BtStatus" = "Charging" ]; then BtHVrelayOFF; BtStatus=Charged; LogIt "Bt capacitor charging finished @ $PowSupVoltage V" fi if [ $PowSupVoltage -ge $UCdRequest ] && [ "$CdStatus" = "Charging" ]; then CdStatus=Charged; CdHVrelayOFF; LogIt "Cd capacitor charging finished @ $PowSupVoltage V" fi sleep 0.1 done HVoff echo OK } function ZMB() { if [ $UBtRequest -gt 200 ]; then ChargingResistorsAllOFF; fi BtSlowLine=`echo "0.01725*$UBtRequest + 76.43956"|bc|xargs printf '%4.0f\n'` LogIt "U_Bt: $UBtRequest, Hrana: $BtSlowLine" CdSlowLine=85 LogIt "U_Et: $UCdRequest, Hrana: $CdSlowLine" while [ $BtStatus == Charging ] || [ $CdStatus == Charging ]; do UBt=`ReadOscilloscope Capacitor 1` Ucd=`ReadOscilloscope Capacitor 2` LogIt "$UBt $Ucd" if [ $UBt -gt $UBtRequest ]; then BtStatus=Charged;fi if [ $UCd -gt $UCdRequest ]; then CdStatus=Charged;fi if [ $UBt -gt $(($UBtRequest*$BtSlowLine/100)) ] && [ $ChargingResistors == 0 ] && [ "$BtStatus" = "Charging" ]; then LogIt "Bt slow PowSup";ChargingResistorsAllON;fi if [ $CdStatus == Charging ] && [ $UCd -gt $(($UCdRequest*$CdSlowLine/100)) ] && [ $ChargingResistors == 0 ] && [ "$CdStatus" = "Charging" ]; then LogIt "Cd slow PowSup";ChargingResistorsAllON;fi if [ "$CdStatus" = "Charged" ] && [ $ChargingResistors == 1 ] && [ $UBt -lt $(($UBtRequest*$BtSlowLine/100)) ]; then LogIt "Bt boost PowSup";ChargingResistorsAllOFF;fi sleep 1 done HVoff $LogFunctionEnd echo OK } function Arming() { $LogFunctionGoingThrough echo OK } function Final() { $LogFunctionGoingThrough CloseOscDVMAcquiring HVOsc GetOscScreenShot HVOsc echo OK } function PostDisch() { GoToSafeState $LogFunctionGoingThrough echo OK } function GoToSafeState() { HVoff; CdHVrelayOFF; BtHVrelayOFF; Relax; CdShortCircuitsEngage; BtShortCircuitsEngage; } function Emergency() { GoToSafeState $LogFunctionStart echo OK } function HVon() { $LogFunctionPassing HVlighON PowerSupplyHVcontactorON Relax } function HVoff() { PowerSupplyHVcontactorOFF $LogFunctionPassing HVlighOFF mRelax ChargingResistorsAllON } function ChargingResistorsAllOFF() { $LogFunctionStart ChargingResistors=0 ChargingResistor_I_DisEngage #ChargingResistor_II_DisEngage echo "Fast">$SHM/Charging } function ChargingResistorsAllON() { $LogFunctionStart ChargingResistors=1 ChargingResistor_I_Engage ChargingResistor_II_Engage echo "Slow">$SHM/Charging } TASK=$1 COMMANDLINE=`echo $@|sed 's/-r //g'` case "$TASK" in "") RETVAL=1 ;; --raw_command|-r) $COMMANDLINE ;; --rsync) RsyncDeviceFromDirigent ;; esac