Skip to content

Instantly share code, notes, and snippets.

@dwhacks
Created September 12, 2013 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwhacks/6531603 to your computer and use it in GitHub Desktop.
Save dwhacks/6531603 to your computer and use it in GitHub Desktop.
test
/*not working*/
#include <TinyGPS.h>
#include <SD.h>
/* This sample code demonstrates the normal use of a TinyGPS object. */
TinyGPS gps;
/* On Teensy, the UART (real serial port) is always best to use. */
/* Unlike Arduino, there's no need to use NewSoftSerial because */
/* the "Serial" object uses the USB port, leaving the UART free. */
HardwareSerial Uart = HardwareSerial();
//Set the pins used
#define led2Pin 15 //Write to SD
#define led1Pin 16 //Indicate we have a fix
void gpsdump(TinyGPS &gps);
void printFloat(double f, int digits = 2);
#define BUFFSIZE 90 //90
char buffer[BUFFSIZE];
uint8_t counter = 0;
bool gotGPRMC; //true if current data is a GPRMC strinng
uint8_t sum;
// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
if (c < '0')
return 0;
if (c <= '9')
return c - '0';
if (c < 'A')
return 0;
if (c <= 'F')
return (c - 'A')+10;
}
void setup()
{
Serial.begin(115200);
Uart.begin(38400);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop()
{
bool newdata = false;
char c;
if (Uart.available()) {
c = Uart.read();
if (counter == 0){
while (c != '$')
c = Uart.read();
}
buffer[counter] = c;
if (c == '\n') {
buffer[counter+1] = 0;
if(buffer[counter-4] != '*'){
Serial.print('*');
counter = 0;
return;
}
sum = parseHex(buffer[counter-3]) * 16;
sum += parseHex(buffer[counter-2]);
for(int i=1; i < (counter-4); i++){
sum ^= buffer[i];
}
if(sum != 0){
Serial.print('~');
counter = 0;
return;
}
Serial.print(buffer);
gotGPRMC = strstr(buffer, "GPRMC");
if (gotGPRMC){
Serial.print(buffer);
}
}
counter++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment