GPS $GPRMB parser and decoder
Here is a routine that will extract all fields of the RMB sentence. You can modify it for other strings.
Cheers
Brian
GetData:
' Add code here for GPRMC, etc
GetRMBData: ' capture 84 character frame in real time
serin2 rx232, 188, 2000, nogps,[WAIT("$GPRMB")] ' find header
for i = 0 to 83 'grab data stream
serin2 rx232, 188, [a[i]]
next i
' now we have an 84 character array starting with the first comma after
' $GPRMB. $GPRMB is of variable length depending on field values.
' Processing is now done while the next GPS frames pass by. Need a bigger
' RAM to handle RMB & RMC on every GPS frame.
UnpackRMB: ' unpack frame & show on SEROUT
CommaCnt = 0
for i = 0 to 83
if a[i] = "," then
CommaCnt = CommaCnt + 1 ' found a new field
serout bootout, 2, [$0D, $0A, #CommaCnt , ","]
if CommaCnt = 1 then getvalidity
if CommaCnt = 2 then getxte
if CommaCnt = 3 then getsteer
if CommaCnt = 4 then getorigin
if CommaCnt = 5 then getdestination
' if CommaCnt = 6 then getdestnlatt
' if CommaCnt = 7 then gethemisphere
' if CommaCnt = 8 then getdestlong
' if CommaCnt = 9 then geteorw
' if CommaCnt = 10 then getrangetogo
if CommaCnt = 11 then getbearing
' if CommaCnt = 12 then getclosingvelocity
if CommaCnt = 13 then getarrival
if CommaCnt = 14 then getdata 'all done so get next RMC
GetFieldData:
for j = i+1 to (i+15) 'get the next character
if a[j] = "," then
goto getnextfield
endif
serout bootout, 2, [a[j]]
next j
endif
GetNextField:
next i
goto getdata
GetValidity:
' This is needed since both Track and Bearing collapses to 0.0 when no
' GPS data is being received. This could be falsely interpreted as
' traveling due North with the destination dead ahead.
' A FailSafe check must be done here to prevent this. Currently omitted.
if a[i+1] = "V" then
serout bootout, 2, ["V = bad frame"]
goto GetNextField
endif
if a[i+1] = "A" then
serout bootout, 2, [ "A = good frame"]
goto GetNextField
endif
serout bootout, 2, [ "NO sync"]
goto GetNextField
GetXTE:
xte = 0
for j = (i+1) to (i+8) ' get (up to) the next 8 characters
if a[j]="," then xtedone ' end of field or blank field found
if a[j]<>"." then ' ignore any decimal point
e = a[j] - 48
'ASCII representation - subtract 48 to get numeric value
xte = 10* xte + e
endif
next j
XTEDone:
' at this point we have XTE * 10
serout bootout, 2, ["XTE = ", #xte/10, ".", #xte//10]
goto GetNextField
GetSteer:
if a[i+1] = "L" then
serout bootout, 2, ["Turn LEFT"]
goto GetNextField
endif
if a[i+1] = "R" then
serout bootout, 2, [ "Turn RIGHT"]
goto GetNextField
endif
serout bootout, 2, [ "NO turn info"]
goto GetNextField
GetOrigin:
'This is an alphanumeric field - needs unpacking
serout bootout, 2, ["Origin = "]
for j = (i+1) to (i+15) ' get (up to) the next 15 characters
if a[j]="," then origindone ' end of field or blank field found
serout bootout, 2, [ a[j]]
next j
OriginDone:
goto GetNextField
GetDestination:
'This is an alphanumeric field - needs unpacking
serout bootout, 2, ["Destination = "]
for j = (i+1) to (i+15) ' get (up to) the next 15 characters
if a[j]="," then destinationdone ' end of field or blank field found
serout bootout, 2, [ a[j]]
next j
DestinationDone:
goto GetNextField
GetBearing:
bearing = 0
for j = (i+1) to (i+8) ' get (up to) the next 8 characters
if a[j]="," then bearingdone ' end of field or blank field found
if a[j]<>"." then ' ignore any decimal point
e = a[j] - 48
'ASCII representation - subtract 48 to get numeric value
bearing = 10* bearing + e
endif
next j
BearingDone:
' at this point we have BEARING * 10
serout bootout, 2, ["Bearing = ", #bearing/10, ".", #bearing//10]
lcdout $FE, $01, "Track ", #track/10, ".", #track//10
lcdout $FE, $C0, "Bearing ",#bearing/10, ".", #bearing//10
goto GetNextField
GetArrival:
if a[i+1] = "A" then
serout bootout, 2, ["Arrived"]
goto GetNextField
endif
if a[i+1] = "V" then
serout bootout, 2, [ "not there yet"]
goto GetNextField
endif
serout bootout, 2, [ "NO arrival info"]
goto GetNextField
NoGPS:
lcdout $FE, $01, "No GPS data " , $FE, $C0, "Check GPS "
pause 1000
goto startup
Re: GPS decoding problems
Anyway does anyone have experience with GPS data string decoding for pic18LF4620?
Re: GPS decoding problems
Quote:
Originally Posted by
piceighteen
Anyway does anyone have experience with GPS data string decoding for pic18LF4620?
It would be the same as with any other MCU.
Re: GPS decoding problems
can you post schematic of GPS receiver
Re: GPS decoding problems
Quote:
Originally Posted by
nguyenphuocho
can you post schematic of GPS receiver
Do you mean how the receiver is connected to a MCU?