eoasap
- 14th February 2006, 18:22
this thread was in the "off topic" thread, but i thought i'd post at least my contribution into the proper forum. The code takes a variable length string input (GPS Sentence) and converts it to a constant length string output. this is required for many FAT processing chips.
-----------------------------------------------------------------------
this is what i do for GPS data. (simplified, but this will work). NMEA sentences are ended with a CR, LF, so i loop through the data, checking for a CR, once its received i set a flag and pad with zeros. this gives me a constant length output of the complete NMEA sentence without chopping off any data. There are probably more efficient ways which dont add extra bytes, and the loop takes a bit of time, but at least it works
'record in 70 bytes
SERIN2 GPS_TXA, GBAUD, [wait("$GPGGA"),str GPGGA_IN\80]
'CLEAN UP THE GPGGA Read, for faster reads, start i at a higher number
'(ex:i = 50)
CR_BYTE = 0
for i = 0 to 77
if GPGGA_IN[i] = 13 then
CR_BYTE = 1 'set flag that CR has been recorded
GPGGA_IN[i] = 160 'replace CR with a space
endif
if CR_BYTE = 1 then
GPGGA_IN[i] = 160 'pad with zeros
endif
next i
GPGGA_IN[78] = 13
GPGGA_IN[79] = 10
'END CLEAN GPRMC READ
-----------------------------------------------------------------------
this is what i do for GPS data. (simplified, but this will work). NMEA sentences are ended with a CR, LF, so i loop through the data, checking for a CR, once its received i set a flag and pad with zeros. this gives me a constant length output of the complete NMEA sentence without chopping off any data. There are probably more efficient ways which dont add extra bytes, and the loop takes a bit of time, but at least it works
'record in 70 bytes
SERIN2 GPS_TXA, GBAUD, [wait("$GPGGA"),str GPGGA_IN\80]
'CLEAN UP THE GPGGA Read, for faster reads, start i at a higher number
'(ex:i = 50)
CR_BYTE = 0
for i = 0 to 77
if GPGGA_IN[i] = 13 then
CR_BYTE = 1 'set flag that CR has been recorded
GPGGA_IN[i] = 160 'replace CR with a space
endif
if CR_BYTE = 1 then
GPGGA_IN[i] = 160 'pad with zeros
endif
next i
GPGGA_IN[78] = 13
GPGGA_IN[79] = 10
'END CLEAN GPRMC READ