Go Down

Topic: programmung question (Read 801 times) previous topic - next topic

Ben1306

hello ,

i've extracted an GPs string looks like:

$GPRMC,163931.000,A,5131.2865,N,00727.3957,E,0.37,303.93,240312,,,A*6C

and now i want to grab only the Longitude and latidue
i worked with comma positions but the program only give me the string after first comma up to last comma.... looks like:

$GPRMC
164137.000
A
5131.2847
N
00727.4010
E
0.85
65.61
240312

is there any way to say give me the text between comma 3 and 4 and 5 to 6????

thank a lot for answer :)



James C4S

What code did you use to extract those?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Ben1306

#include <string.h>
#include <ctype.h>

  int ledpin = 13;     // LED test pin
  char speicher[80];
  int commaPosition;
  int i;
 
  void setup(){
   
    pinMode(ledpin, OUTPUT);
    Serial.begin(4800);
    Serial1.begin(4800);
   
  }
 
   void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // char speicher to string new string kopoieren
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',');
       if(commaPosition!=-1)
       {
       Serial.println(newStr.substring(0,commaPosition));
       newStr=newStr.substring(commaPosition+1,newStr.length());
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}

 
   
 
 

   

AWOL

Again, with CODE TAGS please.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ben1306

  void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // make char to string
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',').
       if(commaPosition!=-1).   // if there is a comma 
       {
       Serial.println(newStr.substring(0,commaPosition)); //write text after first comma in substring and give it to serial port 
       newStr=newStr.substring(commaPosition+1,newStr.length()); // copy after. Comma till end of string in newstr
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}
In arduino cookbook at chapter 2.5 is a description about comma position if u dont understand my tags :))

Thx for interest :)

Ben1306

http://www.poliedit.com/vroc/AC.pdf
Heres a link to cookbook

dxw00d

Quote
Again, with CODE TAGS please.


AWOL didn't mean adding comments, he meant for you to repost your sketch wrapped in [code]...[/code] tags. Paste the code in, then select it and press the '#' button above the text entry box.

Ben1306

Code: [Select]
#include <string.h>
#include <ctype.h>
 
  int ledpin = 13;     // LED test pin
  char speicher[80];
  int commaPosition;
  int i;
 
  void setup(){
   
    pinMode(ledpin, OUTPUT);
    Serial.begin(4800);
    Serial1.begin(4800);
   
  }
 
   void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // char speicher to string new string kopoieren
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',');
       if(commaPosition!=-1)
       {
       Serial.println(newStr.substring(0,commaPosition));
       newStr=newStr.substring(commaPosition+1,newStr.length());
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}

 
   
 
 

   

Ben1306


PaulS

There is a TinyGPS library for collecting GPS data with the waste of using Strings, AND it knows how to parse the data. Why are you not using that?

Ben1306

jeps i know ^^ but i will do it in my own way and now i have the solution ;)

working with pointers
works really nice 4 me


thx

danimath

Perhaps you will try the function "strtok".

best regards
Andreas
http://danimathblog.blogspot.com

#define true '/'/'/'
#define false '-'-'-'

Go Up