Hey,
i am very much a total beginner in programming. So i have a question about a function i have written here.
I am using a Teensy and a A7 GPS/GSM Module, to build a GPS tracker. the NMEA data comes over "Serial2". my Debug output is "Serial". What i want to achieve is a function wich i can call and i get the last valid GPS coordinates back. So this is what i have done: (i know there is no "answer" right now...)
int8_t get_GPS() {
int8_t counter, answer, looptrigger;
long previous;
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For three seconds we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 3000;)
{
while (Serial2.available())
{
char c = Serial2.read();
//Serial.println("DEBUG");
//Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("LAT=");
Serial.println(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.println(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.println(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
}
gps.stats(&chars, &sentences, &failed);
Serial.print(" CHARS=");
Serial.println(chars);
Serial.print(" SENTENCES=");
Serial.println(sentences);
Serial.print(" CSUM ERR=");
Serial.println(failed);
if (chars == 0)
Serial.println("** No characters received from GPS: check wiring **");
Serial.println(); Serial.println();
return answer;
}
When i call that form loop() i get this outputted in my serial monitor:
LAT=50.975601
LON=11.322467
SAT=3
PREC=710
CHARS=2141
SENTENCES=18
CSUM ERR=0
which looks quite good, BUT there is something i dont understand: for testing i ran this function every second and what happens is, that i do get the actual position, but the "chars" and "sentences" counter grows extremely fast (for every char in the NMEA string...) Is that problematic?
So i tried to reset this counter every run, but i just have NO idea how!!
Or does this not matter at all? I am just concearned, that once this tracker runs for a couple of days some memory runs over and i am screwed...
Any Idea?
Cheers and Thanks!!!