CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Argument extraction from string

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
EVIERA



Joined: 10 Jul 2011
Posts: 3

View user's profile Send private message

Argument extraction from string
PostPosted: Sun Jul 10, 2011 12:28 am     Reply with quote

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 Very Happy
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 10, 2011 1:59 am     Reply with quote

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: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jul 10, 2011 7:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 10, 2011 1:29 pm     Reply with quote

FvM.

Thank you for your advice...
Wink
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jul 11, 2011 9:44 am     Reply with quote

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 Laughing !

John
EVIERA



Joined: 10 Jul 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Jul 19, 2011 10:49 pm     Reply with quote

Hello John.

So sorry for my delayed answer. Thank you very much for your help... was very helpful. Laughing Thank you very much again...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group