Shop OBEX P1 Docs P2 Docs Learn Events
Need to extract information from packet (FDS) — Parallax Forums

Need to extract information from packet (FDS)

computer guycomputer guy Posts: 1,113
edited 2012-07-25 22:51 in Propeller 1
I am using FullDuplexSerial (FDS) to get packets of information from a module.
I need to read in the packet and extract parts of information.

Key:
<cr_lf> = 0x0D0A (carriage return, linefeed)

Packets are constructed like so:
<cr_lf>RESPONSE<cr_lf>

They can be as simple as:
<cr_lf>OK<cr_lf>

Or as complex as:
<cr_lf>OK<cr_lf>
<cr_lf>0,1,0,ECFE7E000000<cr_lf>

I basically need to extract it like this:
1.
status := "OK"
data := ""

2.
status := "OK"
data := "0,1,0,ECFE7E000000"

can someone please get me started on how I might go about doing this?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-25 20:32
    There are several string manipulation objects in the Object Exchange (like this one). Several also have routines to convert from numbers to strings and vice versa. Have a look at them. Also look at Extended Full Duplex Serial for routines that handle delimiters in forming and filling strings. It should be straightforward to recognize CRLF as a two character delimiter and then copy everything up to the next CRLF into a string buffer for processing by the string manipulation routines.
  • AribaAriba Posts: 2,690
    edited 2012-07-25 21:40
    Here some ideas to play with:
    VAR
      long i,c, status
      byte buff[32]
      byte dataStr[32]
    
    PUB
      ...
      repeat                           'read string into buffer
        c := ser.rx
        case c
          10: i := 0                   'after LF a new string begins
          13: buff[i] := 0             'CR is end of string
              if i > 0
                quit
          other: buff[i++] := c        'char into string
    
      'decode string
      if strcomp(@buff, string("OK"))  'compare to "OK"
        status := 1                    'set to OK
      elseif strcomp(@buff, string("ERR"))  'compare to other possible words 
        status := 0
      elseif strsize(@buff) > 5        'data?
        bytemove(@dataStr, @buff, strsize(@buff)+1)   'copy string
    

    Andy
  • computer guycomputer guy Posts: 1,113
    edited 2012-07-25 22:51
    Thank you Mike and Andy.
    I think I've managed to pull something together. After doing some more testing I will post the code, so it might help others. :)
Sign In or Register to comment.