Shop OBEX P1 Docs P2 Docs Learn Events
How do I compare value in memory to a string value — Parallax Forums

How do I compare value in memory to a string value

mre_robmre_rob Posts: 31
edited 2007-05-15 12:06 in Propeller 1
I have in memory, values loaded and I need to compare to a string. The line in purple never is true. Any help would be appreciated.....

<code>
dat
' THIS MUST BE HERE IN FRONT FOR ABSOLUTE ADDRESSING TO WORK!!!!!
SensorDatum
SensorData··· file "memorymap.txt"' padding used by the memory map
SensorDataPad byte 0,0,0,0
GPRMC········ byte "GPRMC",0
OBJ
· objVGA······· :"VGA_Text"
· objSerial···· :"SerialReceive"
· objMem······· :"GPSSensors_Lib"
CON
· _clkmode··············· = xtal1 + pll16x
· _xinfreq··············· = 5_000_000
· _crlf·················· = $0D
· _rxPin················· = 0
· _baud·················· = 4800
· _serMode··············· = 0
· _vgaPin················ = 16
con
· _sentenceSize = 256
· _serialBuffer = 256·································
VAR
· byte NmeaSentence[noparse][[/noparse]_sentenceSize]
· byte serialBuffer[noparse][[/noparse]_serialBuffer]
· long bootest
PUB Start
· 'bytefill(objMem#SensorDataAddress, 0, objMem#LastVar)
· objVGA.start(_vgaPin)
· objSerial.start(_rxPin,_baud,_serMode)
· repeat 4
··· GetSentence(@NmeaSentence)
··· GetHeader(@NmeaSentence)
··· if (long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#head)]==GPRMC)
····· ParseGPRMC

··
PUB Stop
· objVGA.stop
· objSerial.stop
Pri ParseGPRMC
· objVGA.str(string("test: "))
· objVGA.out(_crlf)
Pri GetHeader(ptrSentence)
· byteMove(long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#head)],ptrSentence,5)
·
Pri GetSentence(strPtr) | ptr, haveFoundDelimiter, rxChar, delimiter
· delimiter:="$"
· ptr:=0
· haveFoundDelimiter~
· bytefill(@serialBuffer,0,256)
· repeat while !haveFoundDelimiter
··· if (rxChar:=objSerial.rxcheck)=>0
····· if(rxChar==delimiter)···························
······· serialBuffer[noparse][[/noparse]ptr] :=· objSerial.rx······
······· ptr++·················································
······· repeat while ((serialBuffer[noparse][[/noparse]ptr-1] <> 13) and (serialBuffer[noparse][[/noparse]ptr-1] <> delimiter)) and (ptr < 255)·······
········· serialBuffer[noparse][[/noparse]ptr] :=· objSerial.rx··
········· ptr++
······· haveFoundDelimiter~~·····
· serialBuffer[noparse][[/noparse]ptr-1]:=0·······································
· byteMove(strPtr,@serialBuffer,256)·
</code>

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-14 19:06
    There is a string compare built-in function in Spin. Look at the description of STRCOMP. This will compare two strings for equality. You pass it the starting addresses of two byte arrays (strings) that contain zero-terminated strings. They must be of the same length and contain the same byte values for the function to return TRUE.
  • mre_robmre_rob Posts: 31
    edited 2007-05-15 10:24
    Thanks Mike... I'll look at this method of comparing strings... I'm having the ptr vs var symbol issue again.....
  • M. K. BorriM. K. Borri Posts: 279
    edited 2007-05-15 11:19
    Since you're comparing a small string that doesn't end where you want it to, what you could do is just check for "R" then "M" then "C" byte wise...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://forums.parallax.com/showthread.php?p=650217

    meow, i have my own topic now? (sorta)
  • mre_robmre_rob Posts: 31
    edited 2007-05-15 12:06
    M. K. Borri said...
    Since you're comparing a small string that doesn't end where you want it to, what you could do is just check for "R" then "M" then "C" byte wise...

    Thanks.... Got your PM and implementing as we speak....
Sign In or Register to comment.