SUBDIR=
ThisDev=Dirig
STATUS=OK


include makefile.commons

snb:
	$(MAKE) PingCheck; echo $$STATUS
	
zmb:	
	$(Et) RsyncDevFromGM
	$(Et) snb

Discharge:
	#$(MAKE) PingCheck
	$(MAKE) InitIt
	$(MAKE) Arming 
	$(MAKE) Trigger 
	$(MAKE) PostDischarge

	
zmbs:	
	$(MAKE) Charging V@Et=100 V@Bt=100 WGp=20;

InitIt:	
	ShotNo=$$((`echo "SELECT shot_no FROM shots_new ORDER BY timestamp DESC LIMIT 1;" |$(DataB)`+1));export ShotNo=$$ShotNo;\
	rm -rf $(SHM);mkdir -p $(SHMdir);echo $$ShotNo>$(SHM)/ShotNo;$(SHMtouch)/$$ShotNo;mkdir -p $(SHM)/Controll; cp * *.* $(SHM)/Controll/; \
	echo Doing ShotNo: \#$$ShotNo;export ShotNo=$$ShotNo;\
	echo "`date '+%d:%m:%y %H/%M/%S'`:Discharge sequence #$$ShotNo Initiated"|$(GLOB_LGB);\
	make LogIt LOGINFO="Init";\
	for Dev in $(RASPs); do \
		echo -n Init $$Dev call .. ;\
		rsync -e ssh makefile.$$Dev makefile.commons golem@$$Dev:;\
		$(SSH) "$(MAKE) Init ShotNo=$(ShotNo)" & \
	done;\
	wait
	echo Init completed ...
	
Charging:	
	$(MAKE) LogIt LOGINFO="Charging";\
	for Dev in  $(RASPs); do \
		echo -n Charging $$Dev call .. ;\
		$(XTERM) "$(MAKE) Charging V@Et=$(V@Et) V@Bt=$(V@Bt) WGp=$(WGp) ShotNo=$(ShotNo)" & \
	done;\
	sleep 1;$(PowSup) HVon Et=$(V@Et) Bt=$(V@Bt);\
	wait
	$(PowSup) HVoff
	echo Charging completed ...
	

Arming:	
	make LogIt LOGINFO="Arming";\
	for Dev in $(RASPs); do \
		echo -n Arming $$Dev call .. ;\
		$(SSH) "$(MAKE) Arming ShotNo=$(ShotNo)" & \
	done;\
	wait
	echo Arming completed ...
	
Trigger:	
	make LogIt LOGINFO="Trigger";\
	for Dev in $(RASPs); do \
		echo -n Trigger $$Dev call .. ;\
		$(SSH) "$(MAKE) Trigger ShotNo=$(ShotNo)" & \
	done;\
	wait
	echo Trigger completed ...


	
PostDischarge:	
	make LogIt LOGINFO="PostDischarge";\
	for Dev in  $(RASPs); do \
		echo -n Postdischarge $$Dev call .. ;\
		$(SSH) "$(MAKE) PostDischarge ShotNo=$(ShotNo)" & \
	done;\
	wait;\
	#xterm -hold -e cat /GW/Sandbox/Dirigent/Shots/$(ShotNo)/Infrastructure/Bt.lgb &
	echo "Store it?"
	if [ `read store;echo $$store` -eq 1 ] ; then\
		echo "Store";\
		mkdir -p Shots/$$ShotNo;mkdir -p Shots/$$ShotNo/Infrastructure;\
		echo "INSERT INTO shots_new (shot_no, timestamp, pre_comment) VALUES ($$ShotNo, NOW(), 'testing');" |$(DataB);\
	else\
		echo "No Store";\
	fi	
	echo Postdischarge sequence  completed ...
	
	
PingCheck:
	#for Dev in $(RASPs) $(OSCs) $(ARDs) $(PAPs) ;
	STATUS=OK;\
	for Dev in $(RASPs) $(OSCs)  $(ARDs) $(PAPs) ;\
	do echo -n ping $$Dev; ping -q -c 1 $$Dev >/dev/null;if [ $$? -ne 0 ]; then echo -n ' ...problem;'; STATUS="ping $$Dev KO" ;else echo -n '...OK;';fi;done;\
	echo; echo exit: $$STATUS

	
		
	


	

RotPumpON:
	$(Chamber) RotPumpON
	
RotPumpOFF:
	$(Chamber) RotPumpOFF

PumpingON:
	$(Chamber) PumpingON
	
PumpingOFF:
	$(Chamber) PumpingOFF

	
TMPsON:
	$(Chamber) TMPsON

VentsON:
	$(Chamber) VentsON

TMPsOFF:
	$(Chamber) TMPsOFF

VentsOFF:
	$(Chamber) VentsOFF

	
	
	
	


RemSync:
	for Dev in $(RASPs);do rsync -e ssh makefile.`echo $$Dev| sed -e 's/\(.*\)/\L\1/'` $$Dev:;done # sed: to lower case
	
	


ZMBs:
	for Dev in  $(RASPs); do \
		echo -n Charging $$Dev .. ;\
		xterm -T $$Dev -e "sleep 5" & \
	done;\
	wait
	echo Done ...


	
	make -C /GW/Sandbox/Dirigent -iBs -f makefile.ps $(COMMAND)
	

	
	echo "Store it?"
	if [ `read store;echo $$store` -eq 1 ] ; then\
		echo "Store";\
	else\
		echo "No Store";\
	fi
