Below is the one routine
the other is identical except it calls depthserial in stead of gps serial and it looks for the appropriate NMEA string.
buffer is global and used by both...
p
void getgps() {
char c;
uint8_t sum;
Serial.println("getgps");
// read one 'line'
if (gpsSerial.available()) {
c = gpsSerial.read();
#if ARDUINO >= 100
//Serial.write(c);
#else
//Serial.print(c, BYTE);
#endif
if (bufferidx == 0) {
while (c != '
)
c = gpsSerial.read(); // wait till we get a $
}
buffer[bufferidx] = c;
#if ARDUINO >= 100
//Serial.write(c);
#else
//Serial.print(c, BYTE);
#endif
if (c == '\n') {
//putstring_nl("EOL");
//Serial.print(buffer);
buffer[bufferidx+1] = 0; // terminate it
if (buffer[bufferidx-4] != '') {
// no checksum?
Serial.print("g");
bufferidx = 0;
return;
}
// get checksum
sum = parseHex(buffer[bufferidx-3]) * 16;
sum += parseHex(buffer[bufferidx-2]);
// check checksum
for (i=1; i < (bufferidx-4); i++) {
sum ^= buffer[i];
}
if (sum != 0) {
//putstring_nl("Cxsum mismatch");
Serial.print("g~");
bufferidx = 0;
return;
}
// got good data!
gotGPRMC = strstr(buffer, "GPRMC");
if (gotGPRMC) {
// find out if we got a fix
char *p = buffer;
p = strchr(p, ',')+1;
p = strchr(p, ',')+1; // skip to 3rd item
if (p[0] == 'V') {
digitalWrite(led1Pin, LOW);
fix = false;
} else {
digitalWrite(led1Pin, HIGH);
fix = true;
}
}
if (LOG_RMC_FIXONLY) {
if (!fix) {
Serial.print('_');
bufferidx = 0;
return;
}
}
// rad. lets log it!
Serial.print(buffer); //first, write it to the serial monitor
Serial.print('#');
if (gotGPRMC) //If we have a GPRMC string
{
// Bill Greiman - need to write bufferidx + 1 bytes to getCR/LF
bufferidx++;
digitalWrite(led2Pin, HIGH); // Turn on LED 2 (indicates write to SD)
logfile.write((uint8_t ) buffer, bufferidx); //write the string to the SD file
logfile.flush();
/
if( != bufferidx) {
putstring_nl("can't write!");
error(4);
}
*/
digitalWrite(led2Pin, LOW); //turn off LED2 (write to SD is finished)
bufferidx = 0; //reset buffer pointer
if (fix) { //(don't sleep if there's no fix)
if ((TURNOFFGPS) && (SLEEPDELAY)) { // turn off GPS module?
digitalWrite(powerPin, HIGH); //turn off GPS
delay(100); //wait for serial monitor write to finish
sleep_sec(SLEEPDELAY); //turn off CPU
digitalWrite(powerPin, LOW); //turn on GPS
} //if (TURNOFFGPS)
} //if (fix)
return;
}//if (gotGPRMC)
}
bufferidx++;
if (bufferidx == BUFFSIZE-1) {
Serial.print("g!");
bufferidx = 0;
}
} else {
}
}