Shop OBEX P1 Docs P2 Docs Learn Events
NMEA (GPS) parsing of a string and serial question — Parallax Forums

NMEA (GPS) parsing of a string and serial question

arnoarno Posts: 43
edited 2006-03-11 08:01 in BASIC Stamp
Hello,
i try to use a basic stamp to interface a GPS with a GSM modem, but I have 2 problems:
1: how can parse the string I get from my GPS, the lenght is not define, but I have a comma as separator ?
in C it something like strcat

2: Is their a way to know how much data I got from the SERIN function ?


thanks for any help.

regards

arno

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2006-03-02 15:11
    have you gone through the nutz & voltz article off the Parallax site that describes how to ingest GPS string data?

    What kind of stamp do you have?· The BS2P is best suited (with its additional scratchpad ram) for storing GPS strings, but there are other ways to hammer it through.

    I'm attached a program by Jon Williams (sorry if I'm stepping on your toes Jon) where he uses a BS2 and the WAIT modifier in a SERIN command to get the data of a defined string.

    What string are you trying to bring in?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • arnoarno Posts: 43
    edited 2006-03-02 15:49
    I didn't read the Nust&Volts article before, now yes.
    Thanks for the code, I'm using a bs2p, and the problem with the code you give me is that the NMEA data are not allways full, sometime GPS receiver didn't give data in one or 2 field, but they have to put comma on it to make the separation. The code of Jon is nice, but it's not NMEA.
    For know I'm testing my code with $GPRMC, but i will ned 2 other more $GP code, so I realy need a way to parse the code for the coma. If I can know how mutch data I get from my SERIN function I can do a FOR loop and test every char until I reach the comma, but I can't get that information.
    Eventually I can a loop with DO WHILE and put my string in a temp array before working with it.

    But thanks for the sample of code.
  • ktekxktekx Posts: 71
    edited 2006-03-02 20:50
    You can parse the data using the "WAIT" and "SKIP" identifiers for the SERIN command. "WAIT" will wait until it sees specified characters before it reads and SKIP can ignore a specified character length.

    If the character length is fixed after the comma, you can read the serial into a string array, but using string arrays will eat up your variable space quick from my experience with the BS2...so you might want to store it as decimal.

    Post Edited (ktekx) : 3/2/2006 8:54:16 PM GMT
  • Robert@HCCRobert@HCC Posts: 80
    edited 2006-03-06 22:59
    here is an example of how I do it - hope it helps
    EX 1:

    ( getting lat/lon from $GPGGA. WordData1 and 2 - lat and lon, ByteData1 and 2 - N/S E/W)


    GetLatLong:
    SERIN RxD,Baud48, [noparse][[/noparse]WAIT("GPGGA,"),SKIP 9,DEC WordData1, ' Read the GGA sentence from LassenIQ GPS
    SKIP 6, ByteData1, DEC WordData2,SKIP 6, ByteData2,
    SKIP 2,DEC NibData]

    SEROUT TxD, Baud48, [noparse][[/noparse]CRSRXY, 7, 10, DEC WordData1 DIG 3, DEC WordData1 DIG 2,DegSym, " ", ' Then display it
    DEC WordData1 DIG 1, DEC WordData1 DIG 0,MinSym, " ", ByteData1,CLREOL,
    CRSRXY, 7,11,DEC WordData2 DIG 4, DEC WordData2 DIG 3, DEC WordData2 DIG 2,DegSym, " ",
    DEC WordData2 DIG 1, DEC WordData2 DIG 0,MinSym, " ", ByteData2,CLREOL,CRSRXY,20,9,
    DEC NibData, CLREOL]
    RETURN

    EX 2:
    (Getting speed from $GPVTG )

    GetSpeed:
    SERIN RxD, Baud48, [noparse][[/noparse]WAIT("VTG,"), WAIT(","), ' Read the VTG sentence from GPS -
    WAIT(","),WAIT(","),DEC WordData1]


    SEROUT Txd,Baud48, [noparse][[/noparse]CRSRXY, 7, 12, DEC WordData1,CLREOL ' Then display it

    RETURN
  • arnoarno Posts: 43
    edited 2006-03-09 12:45
    Hmm thanks that will help. yeah.gif
  • jcpolejcpole Posts: 92
    edited 2006-03-11 08:01
    ·Robert, would you mind posting the rest of those programs?· It looks like you're doing something that I'm trying to do right now, and I'd like to see how you approached it...

    Thanks...

    Jamie


    Robert@HCC said...
    here is an example of how I do it - hope it helps
    EX 1:

    ( getting lat/lon from $GPGGA. WordData1 and 2 - lat and lon, ByteData1 and 2 - N/S E/W)


    GetLatLong:
    SERIN RxD,Baud48, [noparse][[/noparse]WAIT("GPGGA,"),SKIP 9,DEC WordData1, ' Read the GGA sentence from LassenIQ GPS
    SKIP 6, ByteData1, DEC WordData2,SKIP 6, ByteData2,
    SKIP 2,DEC NibData]

    SEROUT TxD, Baud48, [noparse][[/noparse]CRSRXY, 7, 10, DEC WordData1 DIG 3, DEC WordData1 DIG 2,DegSym, " ", ' Then display it
    DEC WordData1 DIG 1, DEC WordData1 DIG 0,MinSym, " ", ByteData1,CLREOL,
    CRSRXY, 7,11,DEC WordData2 DIG 4, DEC WordData2 DIG 3, DEC WordData2 DIG 2,DegSym, " ",
    DEC WordData2 DIG 1, DEC WordData2 DIG 0,MinSym, " ", ByteData2,CLREOL,CRSRXY,20,9,
    DEC NibData, CLREOL]
    RETURN

    EX 2:
    (Getting speed from $GPVTG )

    GetSpeed:
    SERIN RxD, Baud48, [noparse][[/noparse]WAIT("VTG,"), WAIT(","), ' Read the VTG sentence from GPS -
    WAIT(","),WAIT(","),DEC WordData1]


    SEROUT Txd,Baud48, [noparse][[/noparse]CRSRXY, 7, 12, DEC WordData1,CLREOL ' Then display it

    RETURN
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --
    Jamie C. Pole
    Principal Consultant
    J.C. Pole & Associates, Inc.
    http://www.jcpa.com/
Sign In or Register to comment.