Shop OBEX P1 Docs P2 Docs Learn Events
String parsing BS2 to SPIN — Parallax Forums

String parsing BS2 to SPIN

Paul_HPaul_H Posts: 85
edited 2007-04-03 02:53 in Propeller 1
Hi All,

A friend (Earl) wrote this BS2 code to parse is he was receiving a valid GPS signal:

SERIN GPSpin, N4800, 3000, No_GPS,[noparse][[/noparse]WAIT("GPRMC,"), SKIP 7, STR Char\1] ' Get Status

This opens serial at 4800 baud, waits for the particular GPS string GPRMC, skips 7 characters and get the next character. (In this case we are looking for a serial "A"). It seems quite efficient, but is there a SPIN command to replicate the WAIT and SKIP functions so elegantly?

I looked through the BS2_Functions, but there are differing inputs (ie SERIN_CHAR and SERIN_DEC)

Paul
BTW - thanks Mike for an '06 post explaining strings are just arrays of bytes - Helpful!


"I love string, I love strings, I love strings......." he said as he rocked comfortingly in the corner.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-02 21:59
    There's nothing that does quite the same thing as the PBasic WAIT. For the "SKIP 7", just do a "REPEAT 7" followed by a call to SERIN_CHAR that ignores the result. A simple string match could look like:
    PRI matchString(strPtr) | sz
       sz := strlength(strPtr)                 ' do this here to save time
       repeat until waitString(strPtr,sz)  ' repeatedly lookfor a match
    
    PRI waitString(p,sz)
       repeat while BS2.SERIN_CHAR(GPSpin,GPSBaud,BS2#NInv,8) <> byte[noparse][[/noparse]p]
       repeat sz - 1
          if BS2.SERIN_CHAR(GPSpin,GPSBaud,BS2#NInv,8) <> byte[noparse][[/noparse]++p]
             return false
       return true
    
    PRI skipString(sz)
       repeat sz
          BS2.SERIN_CHAR(GPSpin,GPSBaud,BS2#NInv,8)
    
    


    Call: matchString(string("GPRMC,"))
    Then: skipString(7)
    Then: Char := BS2.SERIN_CHAR(GPSpin,GPSBaud,BS2#NInv,8)

    Note that this will match "GPXGPRMC," at the 4th character, but will not match "GPGPRMC," at the 3rd character. To handle the 2nd type of match, you need something called backtracking which this simple match routine doesn't do.
  • Paul_HPaul_H Posts: 85
    edited 2007-04-03 02:53
    Mike,

    You are Da man! Thanks for the assistance here (again!) . I'll try this and then expand it to read my other strings too.

    Paul
Sign In or Register to comment.