Shop OBEX P1 Docs P2 Docs Learn Events
Don't understand strings as parameters — Parallax Forums

Don't understand strings as parameters

John AbshierJohn Abshier Posts: 1,116
edited 2006-07-13 20:36 in Propeller 1
CON
  _clkmode = xtal1 + pll16x                             ' use crystal x 16
  _xinfreq = 5_000_000                                  ' 5 MHz cyrstal (sys clock = 80 MHz)
  LCD_PIN   = 0                                         ' for Parallax 4x20 serial LCD on P0
  LCD_BAUD  = 19_200
  LCD_LINES = 4    
VAR
  byte token[noparse][[/noparse]10]
  byte head
  byte tail
OBJ
  lcd : "debug_lcd"
PUB main 
  if !lcd.start(LCD_PIN, LCD_BAUD, LCD_LINES)            ' start lcd
    abort
  lcd.cls
  head := 0
  lcd.cursor(0)                                       ' cursor off
  lcd.backLight(true)                                 ' backlight on (if available)
  bytefill(@token,0,10)
  lcd.str(string("test 2", 13))
  GetToken(@teststring,@token)
  lcd.str(string("returned from GetToken", 13))
  lcd.str(@token)
pub GetToken(instring, tok) | curChar
  tail := 0
  lcd.str(string("in GetToken", 13))
  lcd.putc(instring[noparse][[/noparse]0])
  repeat
    curChar := instring[noparse][[/noparse]head + tail]
    if curChar == ","
      quit
    elseif curChar == "*"
      quit
    elseif curChar == $0
      quit
    tok[noparse][[/noparse]tail++] := curChar
  head := ++tail
  return
DAT
'   teststring byte "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47",0
   teststring byte "$GPGGA,123519,4807.038,N,01131.000,E,1,08,,,,46.9,M,,*47",0
                                                         

I am passing the address of teststring and token to GetToken.· But I don't understand how to address them as strings/array of bytes named instring and tok in GetToken.· GetToken never returns and the lcd.putc call writes nothing to the lcd.· I guess I could not use token a an argument to GetToken and use the global variable token, but I really would prefer to use it as an argument so other objects could call it.

Comments

  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2006-07-13 18:06
    Do not have a propeller infront of me but you might try using the BYTE command using syntax 3

    pub GetToken(instring, tok) | curChar
      tail := 0
      lcd.str(string("in GetToken", 13))
      lcd.putc(byte[noparse][[/noparse]instring][noparse][[/noparse]0])               <----------------
      repeat
        curChar := byte[noparse][[/noparse]instring][noparse][[/noparse]head + tail]  <----------------
        if curChar == ","
          quit
        elseif curChar == "*"
          quit
        elseif curChar == $0
          quit
        byte[noparse][[/noparse]tok][noparse][[/noparse]tail++] := curChar            <----------------
      head := ++tail
      return
    

    Charlie
  • John AbshierJohn Abshier Posts: 1,116
    edited 2006-07-13 20:36
    Thanks, I don't know how long it would have taken me to find that.
Sign In or Register to comment.