GPS decoding problems


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Posts
    41


    Did you find this post helpful? Yes | No

    Default 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

  2. #2
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    anybody can provide full description for this project ???

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default here's how I do it

    Here is how I decode the $gprmc sentence...

    Partial code below

    Code:
    GPRMC VAR BYTE[64]
    
    hh      VAR BYTE  'hours
    mm      VAR BYTE  'minutes
    ss      VAR BYTE  'seconds
    sss     var word  'milliseconds
    fix     VAR WORD  'GPS fix
    latdeg  VAR BYTE  'degrees latitude
    latmin  VAR BYTE  'minutes latitude  
    latminn var word  'fractional minutes latitude
    NS      VAR BYTE  'north or south
    londeg  VAR BYTE  'degrees longitude
    lonmin  VAR BYTE  'minutes longitude
    lonminn var word  'fractional minutes longitude
    EW      VAR BYTE  'east or west
    Knots   VAR byte  'speed in knots (units)
    Knotss  var byte  'speed in fractional knots
    course  var word  'heading
    dy      VAR BYTE  'day
    mt      VAR BYTE  'month
    yr      VAR BYTE  'year
    
    
    '============= Main Program ==========================================
    Main:
    high gpwr
    pause 3000
    
    GPSin:
        serin2 gps,188,3000,tmout,[WAIT("$GPRMC,"),STR GPRMC\63\"$"] 'Data IN from GPS
        
        arrayread gprmc,[DEC2 hh,DEC2 mm,dec2 ss,_
          wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait("."),dec4 latminn,_
          wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait("."),dec4 lonminn,_
          wait(","),EW,wait(","),dec knots,dec Knotss,dec course,_
          wait(","),DEC2 dy,DEC2 mt,DEC2 yr]      'parse the GPS array into parts
    
    if fix = "V" then gpsin  'jump to "waiting for fix" display
    
    low gpwr
    high xpwr
        pause 1000
        
        SEROUT2 xbtx,188,[$0D,$0A,"$GPRMC,",STR GPRMC\63]            'Data OUT to XBEE
        pause 500
    Hope this helps
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanx so much .. I really appreciate it
    Could you please provide me with GPS hardware connections with the pic ?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What are you using for the GPS? A handheld unit or a module?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    What are you using for the GPS? A handheld unit or a module?
    I am using a module.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The module data sheet should give the pin out. RX and TX.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 10:47
  2. GPS clock timing !
    By bethr in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 3rd July 2008, 21:11
  3. Replies: 2
    Last Post: - 28th April 2006, 13:10
  4. GPS Receiver
    By lester in forum Adverts
    Replies: 2
    Last Post: - 22nd February 2006, 13:47
  5. GPS decoding
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2005, 21:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts