Shop OBEX P1 Docs P2 Docs Learn Events
GPS time parsing — Parallax Forums

GPS time parsing

baysidecontrolsbaysidecontrols Posts: 2
edited 2011-01-09 09:17 in Propeller 1
Using GPS_IO_mini.spin, I am looking for a method to parse the hours,minutes and seconds from the GPGGA sentence. I can get the time but can not figure out a modification that will allow me to parse out the hours, minutes and seconds separately.

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-09 07:01
    It's pretty easy to create a routine that extracts a decimal value from a string -- here's one idea:
    pub str2dec(pntr, digits) | c
    
    '' extracts decimal value from string
    
      result := 0                                                   ' clear result
    
      repeat digits
        c := byte[pntr++]                                           ' get chracter
        if (c => "0") and (c =< "9")
          result *= 10                                              ' prep for digit
          result += (c - "0")                                       ' convert from ASCII
        else
          quit                                                      ' exit if not digit
    

    Just pass the starting address of the section you want and the number of digits. For example, in that program to get hours you should be able to do this:
    hrs := str2dec(gps.time, 2)
    

    It appears that the .time() method returns a pointer so you just have to modify that. For minutes you'd do this:
    mns := str2dec(gps.time+2, 2)
    

    I've tested the str2dec() method so I know it works, you'll just have to experiment with using it and the GPS object.
  • baysidecontrolsbaysidecontrols Posts: 2
    edited 2011-01-09 09:17
    I knew it would be easy for someone. It worked perfectly the first time. Thanks for the help.

    Roger Hummel
    Bayside Controls, Inc.
Sign In or Register to comment.