-
Notifications
You must be signed in to change notification settings - Fork 1
/
relays.sh
executable file
·103 lines (89 loc) · 2.37 KB
/
relays.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e # be trigger-happy to be reliable
set -o pipefail # be trigger-happy to be reliable
#set -x
RELAYS="lap mount roof rest"
TASKLIST="wake sleep all $RELAYS"
declare -A TASKS
for task in $TASKLIST; do
TASKS[$task]=0
done
for arg in $@; do
for task in "${!TASKS[@]}"; do
if [[ ${arg,,} == $task ]]; then
TASKS[$task]=1
fi
done
done
readStates() {
imaging_computer_power=$(cat /dev/shm/state_relay3 || echo "low")
imaging_equipment_power=$(cat /dev/shm/state_relay4 || echo "low")
mount_power=$(cat /dev/shm/state_relay6 || echo "low")
roof_motor_power=$(cat /dev/shm/state_relay7 || echo "low")
echo "$1 relay state: lap=$imaging_computer_power mount=$mount_power roof=$roof_motor_power rest=$imaging_equipment_power"
}
readStates Begin
if [[ ${TASKS['wake']} -eq 1 ]]; then
ACTION_STR="Wake"
ACTION_IF="low"
ACTION_ALREADY="on"
ACTION_RELAY="high"
elif [[ ${TASKS['sleep']} -eq 1 ]]; then
ACTION_STR="Sleep"
ACTION_IF="high"
ACTION_ALREADY="off"
ACTION_RELAY="low"
else
echo "Usage: $0 Wake|Sleep [all] [lap] [mount] [roof] [rest]"
exit 1
fi
if [[ ${TASKS['all']} -eq 1 ]]; then
for task in $RELAYS; do
TASKS[$task]=1
done
fi
if [[ ${TASKS['lap']} -eq 1 ]]; then
if [[ $imaging_computer_power == $ACTION_IF ]]; then
echo "$ACTION_STR lap now:"
if [[ ${TASKS['wake']} -eq 1 ]]; then
./relay_0-7_low-high.py 3 $ACTION_RELAY
# echo "sleep 5"
# sleep 5
# echo "Send etherwake"
# etherwake 00:1c:23:53:ca:cc
else
# echo "ssh lap2 poweroff"
# ssh lap2 poweroff ||:
# echo "sleep 60"
# sleep 60
./relay_0-7_low-high.py 3 $ACTION_RELAY
fi
else
echo "Skip $ACTION_STR lap, it's already $ACTION_ALREADY"
fi
fi
if [[ ${TASKS['mount']} -eq 1 ]]; then
if [[ $mount_power == $ACTION_IF ]]; then
echo "$ACTION_STR mount now:"
./relay_0-7_low-high.py 6 $ACTION_RELAY
else
echo "Skip $ACTION_STR mount, it's already $ACTION_ALREADY"
fi
fi
if [[ ${TASKS['rest']} -eq 1 ]]; then
if [[ $imaging_equipment_power == $ACTION_IF ]]; then
echo "$ACTION_STR rest now:"
./relay_0-7_low-high.py 4 $ACTION_RELAY
else
echo "Skip $ACTION_STR rest, it's already $ACTION_ALREADY"
fi
fi
if [[ ${TASKS['roof']} -eq 1 ]]; then
if [[ $roof_motor_power == $ACTION_IF ]]; then
echo "$ACTION_STR roof motor now:"
./relay_0-7_low-high.py 7 $ACTION_RELAY
else
echo "Skip $ACTION_STR roof motor, it's already $ACTION_ALREADY"
fi
fi
readStates End