Revision 2ea7698ff7e59d1867a9ea1375c95e75e00ae1a6

HW/Radiation/Monitoring/Fluke451P/SWdevelop/OG/main.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

# PARAMETERS
gnome232_address="192.168.2.249"
socket_port="10001"

# UTILITY FUNCTIONS
send_command() {
	echo -n "$1" | socat STDIN TCP:$gnome232_address:$socket_port
}

recv_data() {
	socat -T 1 -u TCP:$gnome232_address:$socket_port$1 STDOUT
}

activate_measurement() {
	send_command T
}

terminate_measurement() {
	for i in `seq $1` ; do 
		send_command "          "
		sleep $2
	done
}

get_integrated() {
	send_command F
	# terminate stream if "h" (in Sv/h in T mode) is encountered 
	recv_data ",escape=104" | sed -n -e 's/ MICRO/u/' -e 's/\(.*\) Sieverts integrated/\1/p'
}

make_icon() {
	convert -size 150x120 -gravity center label:"${1}Sv" icon.png
}

save_integrated_value() {
	value=""
	while [ -z "$value" ] ; do
		terminate_measurement 3 0.2
		value=$(get_integrated)
	done
	echo $value > $1
	activate_measurement
}

display_difference(){
	cat $1 | read pre unit_pre
	cat $1 | read post unit_post
	diff=$(awk "BEGIN{print $post - $pre}")
	echo $diff $unit > $3
	make_icon "$diff $unit"
}

# EXECUTION

case $1 in
	arming)
		save_integrated_value pre_Sv
		;;
	acquisition)
		save_integrated_value post_Sv
		display_difference pre_Sv post_SV diff_Sv
		;;
esac