3 if [ "$TMPFS" == "" ]; then
9 echo "---------- START GPS -------------"
24 # nmea=$(str=''; read -t 3 str < /dev/ttyS1; echo $str | grep -E 'GPRMC|GNRMC' | awk -F',' '{print $4 " " $5 " " $6 " " $7; exit}' | head -1)
25 # nmea=$(head -10 $GPSTTY | grep -E 'GPRMC|GNRMC' | awk -F',' '{print $4 " " $5 " " $6 " " $7; exit}' | head -1 ) # tr -d '\040\011\012\015'
27 NMEA=$(head -10 $GPSTTY | grep -E 'GPRMC|GNRMC')
28 nmea=$(echo $NMEA | awk -F',' '{print $4 " " $5 " " $6 " " $7; exit}' | head -1 )
29 GPSvalid=$(echo $NMEA | awk -F'[,*]' '{print $13; exit}' | head -1 )
31 # echo $nmea, $GPSdate, $GPStime, $GPSvalid
38 nmeaTrim=$(echo $nmea | tr -d '\040\011\012\015')
42 if [ "$nmeaTrim" != "" ] && ([ "$GPSvalid" == "A" ] || [ "$GPSvalid" == "D" ] || [ "$GPSvalid" == "E" ]); then
44 # save first fixation NMEA time
46 if [ "$firstFix" == "" ]; then
50 GPSdate=$(echo $NMEA | awk -F',' '{print $10; exit}' | head -1 )
51 GPStime=$(echo $NMEA | awk -F'[,.]' '{print $2; exit}' | head -1 )
53 echo "$GPSdate|$GPStime" > $TIMENMEA &
56 # mesure time from previous correct probe
58 tdiff=$(( $time - $prevtime ))
61 echo "$nmea|$prevGPS|$prevtime" > $CURRENTGPS
63 if [ "$tdiff" -gt "$STANDARD_DISTANCE_TIME" ]; then
74 # -------------- GPS dependent messages -------------
76 tdiff=$(( $time - $prevtime ))
78 if [ "$tdiff" -lt "$MAX_GPS_AGE_THRESHOLD" ]; then # gps is ok
80 # -------------- navigation -----------------
82 if [ -s "$navOn" ]; then # if navigation turned on
84 tdiffNav=$(( $time - $prevtimeNav ))
86 if [ "$tdiffNav" -gt "$NAV_MESSAGE_EACH_SEC" ]; then # time to infrom user
90 distance=0 # TODO: CALCULATE DISTANCE HERE BETWEEN $prevGPS AND $currentGPS
92 if [ "$distance" -ge "$MIN_DISTANCE" ]; then # motion detected
94 # direction determination
96 targetGPS=$(cat $navMemo)
98 angle=0 # CALCULATE ANGLE HERE BY 3 POINTS $prevGPS $currentGPS $targetGPS
100 NMESSang=$(sayDir $angle)
102 # distance between current and memorized points
104 navdDstanceOk=0 # TODO: CALCULATE DISTANCE HERE BETWEEN $targetGPS AND $currentGPS
106 km=$(echo $navdDstanceOk | awk '{print $1; exit}')
107 kmPfx=$(echo $navdDstanceOk | awk '{print "$" $2; exit}')
108 md=$(echo $navdDstanceOk | awk '{print $3; exit}')
109 m=$(echo $navdDstanceOk | awk '{print $4; exit}')
110 mPfx=$(echo $navdDstanceOk | awk '{print "$" $5; exit}')
114 currentL=$(cat $TMPFS/$currentLang)
116 if [ "$km" -gt "0" ]; then
117 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$NAV_NUMBERS_1 | grep -v '/' | awk -v a=$km 'NR == a+1 {print; exit}')
119 NMESSkmNum="$NAV_NUMBERS_1/$number"
120 NMESSkm=$(eval "echo $kmPfx")
125 if [ "$md" -gt "0" ]; then
126 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$NAV_NUMBERS_2_100 | grep -v '/' | awk -v a=$md 'NR == a+1 {print; exit}')
127 NMESSmNum="$NAV_NUMBERS_2_100/$number"
130 if [ "$m" -gt "0" ]; then
131 number=$(ls -p $CONTENT/$currentL/$SYSMESSAGES/$NAV_NUMBERS_2 | grep -v '/' | awk -v a=$m 'NR == a+1 {print; exit}')
133 NMESSm2Num="$NAV_NUMBERS_2/$number"
134 NMESSm=$(eval "echo $mPfx")
137 echo "$NMESSang|$NAV_DISTANCE_IS|$NMESSkmNum|$NMESSkm|$NMESSmNum|$NMESSm2Num|$NMESSm" > $TMPFS/$message
140 # no direction detected
142 echo $NAV_NO_DIR > $TMPFS/$message
147 # can't determine position
151 # -------------- no GPS position message -------------
155 if [ "$prevtimeGPSmess" == "0" ]; then
156 prevtimeGPSmess=$timeGPSmess;
159 tdiffGPSmess=$(( $timeGPSmess - $prevtimeGPSmess ))
162 if [ "$tdiffGPSmess" -gt "$NOGPS_MESSAGE_EACH_SEC" ]; then
163 prevtimeGPSmess=$timeGPSmess
165 echo "GPS lost" | myLog
167 echo "$DEV_JINGLE|$DEV_NO_COORD" > $TMPFS/$message
171 sleep $GPSREADINTERVAL # maybe not needed since NMEA has 1 sec period # look like NEEDED