View previous topic :: View next topic |
Author |
Message |
EVIERA
Joined: 10 Jul 2011 Posts: 3
|
Argument extraction from string |
Posted: Sun Jul 10, 2011 12:28 am |
|
|
Hello Everybody,
I need your help in the following topic. I was working on the reception of NEMA0183 code, and from the chain I need to pick up just the altitude from the string. I tried to do a function to extract some characters, using the similar form like "mid()" function of Excel. Please help me with this.
Eduardo |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jul 10, 2011 1:59 am |
|
|
By specification, the fields in the NEMA protocol have to be indentified by the comma delimiters. Because the field length is variable, you can't simply use a fixed postion.
A general approach is to write a function, that extracts comma delimited arguments from a string. You can e.g. use strchr() to find the next delimiter. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sun Jul 10, 2011 7:02 am |
|
|
This has been discussed quite a few times before and there is a lot of info in
this forum. I recommend you try searching on NEMA and GPS before asking.... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
EVIERA
Joined: 10 Jul 2011 Posts: 3
|
|
Posted: Sun Jul 10, 2011 1:29 pm |
|
|
FvM.
Thank you for your advice...
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Jul 11, 2011 9:44 am |
|
|
Hi,
Frankly, receiving the NMEA string reliably is the hardest part of this effort, and generally requires an interrupt driven circular buffer. The CCS provided 'Ex_SISR.c' example details how to do this.
After you've got the NMEA string reliably (you should filter out all but the desired NMEA message), it's pretty easy to parse the string to get the desired value. As was already mentioned, the NMEA messages are variable length, so you've got to look at the comma delimiters to find the correct value.
Here is a simple parsing routine that will do what you want:
Code: |
void ParseNMEA(int8 NumComma)
{
// This subroutine will parse the Msg_Buffer string which contains the most recent NMEA comma delimited data string. The
// routine is passed a comma number, and the routine will return all the data BEFORE that comma number, and AFTER the
// comma number - 1. Example: NumComma = 1 - returns all the data before the 1st comma. NumComma = 2 - returns all the
// data between the 1st comma and the 2nd comma. The new string is null terminated before the subroutine exits.
int8 iIndex;
int8 CommaCount = 0;
int8 NMEAIndex = 0;
for(iIndex = 0 ; CommaCount < NumComma && Msg_Buffer[iIndex] != '\r' ; iIndex++)
{
if (Msg_Buffer[iIndex] == ',')
CommaCount++;
else
if (CommaCount >= NumComma-1){
NMEA_STR[NMEAIndex] = Msg_Buffer[iIndex];
NMEAIndex++;
}
}
NMEA_STR[NMEAIndex] = '\0';
}
|
I won't say this is the "best" way to do this, but it does work fine! I was brain-storming a NMEA parsing solution several years ago while waiting for a dental cleaning, and this is what came to me !
John |
|
|
EVIERA
Joined: 10 Jul 2011 Posts: 3
|
|
Posted: Tue Jul 19, 2011 10:49 pm |
|
|
Hello John.
So sorry for my delayed answer. Thank you very much for your help... was very helpful. Thank you very much again... |
|
|
|