initial commit
[ETG_Helmet] / SOFTWARE / OMEGA2 / intro.sh
1 #/bin/bash
2
3 if [ "$TMPFS" == "" ]; then 
4         . "common.sh"
5 fi
6
7 echo $$ > $PID/$0
8
9 mkdir -p $TMPFS
10 touch $TMPFS/$state
11
12 # -------- check for connection to Leading Device (for Follower) ------------------------
13
14 led main midd
15
16 MODE=$(cat mode)
17
18 if [ "$MODE" == "f" ]; then 
19
20         if ping -W 4 -w 4 -c 2 $LEADER_IP &> /dev/null; then 
21                 led wifi slow
22                 myLog "Connection to group network has been esteblished."
23         else 
24                 : > "$wifiState"
25                 wifiOff
26                 myLog "No connection has been esteblished. WiFi interface deactivated."
27         fi 
28 fi
29
30 # ----------------- playing back Intro until GPS fixation ------------------------------
31
32 pauseOn=0
33 startFrom=0
34
35 while [ 1 ]; do 
36
37         if  [ ! -s "$TMPFS/$state" ]; then      # no side messages (state file is empty)
38
39                 fragment_1="$SYSMESSAGES/$DEV_JINGLE"
40                 fragment_2="$SYSMESSAGES/$INTRO_HELLO"
41                 fragment_3="$SYSMESSAGES/$INTRO_INSTRUCTION_QUESTION"
42
43                 # ------- playing intro -------------------------------------------------
44
45                 if [ "$pauseOn" != "0" ]; then 
46                         startFrom=$(( $startFrom + ($pauseOn - $startOn) - $REWIND ))
47                         if [ $startFrom -lt 0 ]; then startFrom=0; fi
48                         pauseOn=0
49                         echo "Resume $file from" $(date +%H:%M:%S -d @$startFrom -u) | myLog
50                 fi
51
52                 startOn=$(date +%s)
53
54                 currentL=$(cat $TMPFS/$currentLang)
55
56                 echo "startFrom: $startFrom"
57
58                 echo "Intro: $fragment_1, $fragment_2, $fragment_3"
59                 playFile $startFrom "$CONTENT/$currentL/$fragment_1" "$CONTENT/$currentL/$fragment_2" "$CONTENT/$currentL/$fragment_3"
60
61                 # -------- end of playing -----------------------------------------------
62
63                 if [ "$(cat $TMPFS/$state)" == "MESSAGE" ]; then 
64                         pauseOn=$(date +%s)
65                         echo "pauseOn: $pauseOn" | myLog
66                 else 
67                         break
68                 fi 
69         
70                 # -----------------------------------------------------------------------
71
72         else 
73                 # echo "[$0] Intro playback is busy (message playing?)"
74 #               printf .
75                 sleep 1
76         fi
77 done 
78
79 # ------------------ playing SO TODAY .... message -------------------------------------
80
81 {
82
83 echo "waiting for GPS fixation..." | myLog
84
85 nmeaTimeDate=$(cat $TIMENMEA) # wait and read FIFO (waiting for GPS fixation)
86
87 nmeaDate=$(echo $nmeaTimeDate | awk -F'|' '{print $1; exit}')
88 nmeaTime=$(echo $nmeaTimeDate | awk -F'|' '{print $2; exit}')
89
90
91 timeMessage=""  # TODO: GET TIME NMEA HERE 
92
93 date=$(echo $timeMessage | awk '{print $1; exit}')
94 month=$(echo $timeMessage | awk '{print $2; exit}')
95 itis=$(echo $timeMessage | awk '{print "$" $3; exit}')
96 hrs=$(echo $timeMessage | awk '{print $4; exit}')
97 hrsWord=$(echo $timeMessage | awk '{print "$" $5; exit}')
98 min=$(echo $timeMessage | awk '{print $6; exit}')
99 minWord=$(echo $timeMessage | awk '{print "$" $7; exit}')
100
101
102 currentL=$(cat $TMPFS/$currentLang)
103
104 # date 
105
106 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$DAY | grep -v '/' | awk -v a=$date 'NR == a {print; exit}')
107 echo "date: $number" | myLog
108 SDay="$DAY/$number"
109
110 # month
111
112 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$MONTH | grep -v '/' | awk -v a=$month 'NR == a {print; exit}')
113 echo "month: $number" | myLog
114 SMon="$MONTH/$number"
115
116 # it is 
117
118 SItis=$(eval "echo $itis")
119
120 # hours 
121
122 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$TIME_NUMBERS_1 | grep -v '/' | awk -v a=$hrs 'NR == a+1 {print; exit}')
123 echo "hrs: $number" | myLog
124 SHrs="$TIME_NUMBERS_1/$number"
125 SHrsH=$(eval "echo $hrsWord")
126
127 # minutes 
128
129 if [ "$min" != "0" ]; then 
130         number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$TIME_NUMBERS_2 | grep -v '/' | awk -v a=$min 'NR == a+1 {print; exit}')
131         echo "min: $number" | myLog
132         Smin="$TIME_NUMBERS_2/$number"
133         SminM=$(eval "echo $minWord")
134 fi
135
136 intorFin1="$INTRO_COORDINATES"
137 introFin2="$DEV_JINGLE_OUT"
138
139 echo "$INTRO_SO_TODAY|$SDay|$SMon|$SItis|$SHrs|$SHrsH|$Smin|$SminM|$intorFin1|$introFin2" > $TMPFS/$message
140
141 }&
142
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717