Code:
'--------------------------------------------------------------------------------|
' |
' ---------------------------- [ MAIN ] ----------------------------------- |
' |
'--------------------------------------------------------------------------------|
main:
'-------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GNRMC ] /
' [$GNRMC,090045.000,A,3823.6645,N,02353.3600,E,0.02,195.80,170518,,,A*62] /
' /
'--------------------------------------------------------------------------/
;serin2 gps_tx,84,timeout,lostcable,[wait("$GNRMC"),_ ;we wait for $GNRMC
HSERIN timeout,lostcable,[wait("$GPRMC"),_ ;we wait for $GPRMC
wait(","),dec2 hh,dec2 mm,dec2 ss,wait("."),dec3 sss,_ ;we wait for 090045.000 which is the time when we got the info
wait(","),fix,_ ;we wait for A
wait(","),dec2 degrees,dec2 minutes,wait("."),dec4 minutesd,_ ;we wait for 3823.6645
wait(","),dir,_ ;we wait for N/S ;wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
wait(","),dir2,_ ;we wait for E/W
wait(","),wait(","),_
wait(","),dec2 day,dec2 month,dec2 year,_ ;we wait for 170518
wait(","),SKIP 3]
'------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GNGGA ] /
' [$GNGGA,140405.000,3823.6010,N,02353.3054,E,1,9,0.88,0.8,M,35.9,M,,*40 /
' /
'-------------------------------------------------------------------------/
'serin2 gps_tx,84,timeout,lostcable,[wait("$GNGGA"),_ ;we wait for GNGGA
HSERIN timeout,lostcable,[wait("$GPGGA"),_ ;we wait for GPGGA
wait(","),skip 35,_
wait(","),modefix,_ ;we wait for modefix 1,2 or 3 check gps manual for NMEA
wait(","),dec2 satno,_
wait(","),skip 19]
'------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GPGSA ] /
' [$GPGSA,A,3,18,08,10,11,14,27,22,32,01,,,,2.62,1.11,2.37*03] /
' /
'-------------------------------------------------------------------------/
HSERIN timeout,lostcable,[wait("$GPGSA"),_
wait(","),wait(","),mode2d3d,_
wait(","),SKIP 50]
'------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GPVTG ] /
' [$GPVTG,215.60,T,,M,0.44,N,0.82,K,A*37] /
' /
'-------------------------------------------------------------------------/
'serin2 gps_tx,84,timeout,lostcable,[wait("GNVTG"),_
HSERIN timeout,lostcable,[wait("GPVTG"),wait("N"),_
wait(","),TS[0],TS[1],TS[2],TS[3],TS[4],_
wait(","),SKIP 3]
for i = 1 to 3
if TS[i]="." then decimal = i 'TOTAL SPEED. find which character is the decimal point
next i
select case decimal 'if the gps shows 1.45 it may be 145
'for the conversion ASCII to number we can use the -48
case 1 'decimal position is x.xx
SPEED = (10*(TS[0]-48))+(TS[2]-48)
case 2 'decimal position is xx.xx
SPEED = (100*(TS[0]-48))+(10*(TS[1]-48))+(TS[3]-48)
case 3 'decimal position is xxx.xx
SPEED = (1000*(TS[0]-48))+(100*(TS[1]-48))+(10*(TS[2]-48))
end select
gosub OVERSPEED:
'---------------------------------------------------------------------------------/
' Here if the GPS module havent been fixed to any satellite will jump to notfix /
'-------------------------------------------------------------------------------/
if fix = "V" then notfix
;pause 100
'-----------------------------------------------------------------------------/
' [ Return from notfix ] /
' [ We clear any character on the display ] /
'--------------------------------------------------------------------------/
'serout2 lcd,6,[$45] 'Clear the ulcd 1'44
'pause 100
'-----------------------------------------------------------------------------/
' Here we start the calendar conversion /
'---------------------------------------------------------------------------/
arraywrite ndays,13,NDAY,[0,31,28,31,30,31,30,31,31,30,31,30,31]
if ndays = 2 then
if ((year//4 = 0) and (year//400 != 0)) then 'check the leap year
ndays[2] = 29 'then February has 29 days
else
ndays[2] = 28 'else has 28 days
endif
endif
hh = hh + 3 'the Hour from GPS is UTC so for our country in Greece we add +3
if hh>23 then 'if the hh+3 hour is greater than 23 (23:00) then
day = day + 1 'we check the day added is true
hh = hh//24 'but the hour not exceed the 24 so go to 00:00
if (day > ndays[month]) then
month = month + 1
day = 1
if (month > 12) then
year = year + 1
month = 1
endif
endif
endif
'--------------------------------------------------------------------------/
' here is where the code dispays the stored info from the NMEA sentenses /
'------------------------------------------------------------------------/
HSEROUT2 [$73,$03,$00,$00,$FF,$FF," Protocol:","NMEA",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$01,$02,$01,$07,$E0," Date:",dec2 day,"/",dec2 month,"/",dec2 year,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$00,$04,$00,$FF,$E0," TIME: ",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$00,$07,$00,$FF,$FF," Sats",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$01,$09,$11,$6D,$BF,dec2 satno,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$0E,$07,$00,$FF,$FF," Fixed",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$0B,$09,$11,$6D,$BF," ",fix," ",mode2d3d,"D",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$05,$06,$11,$FF,$E0," SPEED",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$06,$05,$12,$6D,$BF,TS[0],TS[1],TS[2],TS[3],$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$06,$06,$12,$FF,$E0,"Km/h",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$00,$0C,$00,$ff,$ff," Lat : ",dec2 degrees,"*",dec2 minutes,"'",dec4 minutesd,"@"," ",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$BE,$0C,$10,$f8,$00,dir,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$00,$0E,$00,$ff,$ff," Lon :",dec3 degrees2,"*",dec2 minutes2,"'",dec4 minutesd2,"@"," ",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$BE,$0E,$10,$f8,$00,dir2,$00]
Hserin2 timeout,lostcable,[wait(6)]
goto main
As you see in the main code there is a line that checking if there is no FIX, so will jump to a label notfix:
Code:
notfix: ' Still looking for fixed signal
hh = hh + 3
hh = hh//24
HSEROUT2 [$73,$00,$03,$11,$6D,$BF," Waiting for GPS",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$00,$07,$00,$07,$ff,rep "." \dots,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$07,$09,$10,$6D,$BF,"SATs :",dec2 satno,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$04,$07,$12,$F8,$00,"NOT FIXED",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$06,$0D,$11,$6D,$BF,fix," ",mode2d3d,"D",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2 [$73,$03,$06,$10,$ff,$E0," Time:",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
Hserin2 timeout,lostcable,[wait(6)]
pause 3000
HSEROUT2 [$45] ' clears the LCD
Hserin2 timeout,lostcable,[wait(6)]
goto main 'returns to main
Bookmarks