Please Review; Need Help moving bytes from byte array to longs;
mre_rob
Posts: 31
Please review the attached code that is not working.... I am not sure why· but I think it has to do with my mis-understanding of how to move bytes from an array to longs... TIA
The code below is supposed to parse the GPRMC sentence of the Parrallax GPS into a memory map ala Matteo. Thanks to him for all of his support thus far.....
I figured I throw this out for a little help.
The code below is supposed to parse the GPRMC sentence of the Parrallax GPS into a memory map ala Matteo. Thanks to him for all of his support thus far.....
I figured I throw this out for a little help.
Pri ParseGPRMC(PtrSentence)|i, j, idxField, delimiter, delimiter2, tmp {{ NMEA 0183 version 3.00 active the Mode indicator field is added $GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a,m*hh Field # 1 = UTC time of fix 2 = Data status (A=Valid position, V=navigation receiver warning) 3 = Latitude of fix 4 = N or S of longitude 5 = Longitude of fix 6 = E or W of longitude 7 = Speed over ground in knots 8 = Track made good in degrees True 9 = UTC date of fix 10 = Magnetic variation degrees (Easterly var. subtracts from true course) 11 = E or W of magnetic variation 12 = Mode indicator, (A=Autonomous, D=Differential, E=Estimated, N=Data not valid) 13 = Checksum }} delimiter:="," delimiter2:="*" i:=6 'move off of the head to the first "," idxField:=1 objVGA.str(PtrSentence) objVGA.out(_crlf) repeat while i< _sentenceSize and idxField< 13 j:=0 longfill(@tmp,0,1) repeat while byte[noparse][[/noparse]PtrSentence+i] <> delimiter and i< _sentenceSize and byte[noparse][[/noparse]PtrSentence+i] <> delimiter2 tmp.byte[noparse][[/noparse]j] := byte[noparse][[/noparse]PtrSentence+i] j++ i++ case (idxField) 1: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcUtcTime)]:=tmp 2: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcValid)] :=tmp 3: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcLat)] :=tmp 4: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcNs)] :=tmp 5: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcLon)] :=tmp 6: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcEw)] :=tmp 7: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcSpeed)] :=tmp 8: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcCourse)] :=tmp 9: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcUtcDate)] :=tmp 10: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcVariation)] :=tmp 11: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcVarEw)] :=tmp 12: long[noparse][[/noparse]constant(objMem#SensorDataAddress + objMem#GprmcMode)] :=tmp idxField++ 'bump i i++ longfill(@tmp,0,1) tmp.byte[noparse][[/noparse]0]:= byte[noparse][[/noparse]PtrSentence+i] i++ tmp.byte[noparse][[/noparse]1]:=byte[noparse][[/noparse]PtrSentence+i] tmp.byte[noparse][[/noparse]2]:=0 longMove(long[noparse][[/noparse]objMem#SensorDataAddress + objMem#GprmcCheckSum],@tmp,1)
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
I don't know how the other part of your code looks like, but the code in the case statement looks complicated for me.
I would use the data in buffer to separate each field as strings. The format of GPS data permits this solution. The separated fields are not copied to another location of memory. Then you can convert the fields to numeric values you are interested as M. K. Borri has mentioned.
Ok, here is my preferred solution.
Thomas
Post Edited (Kaio) : 5/17/2007 7:34:09 PM GMT
This said, Thomas' code is a lot neater than mine [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
· I know my initial code was a little complex, but being new to Spin and coming from another OO language, I was trying to apply the other languages constructs... maybe they don't translate and that might be my learning cureve with SPin...
Post Edited (mre_rob) : 5/17/2007 10:42:27 AM GMT
My code should be to inspire you for a possible variant to parse the GPS data. I don't know if this code is what you need, but it can be useful to find the right way.
Thomas