Last active
October 30, 2020 02:57
-
-
Save sukinull/95f433396680f507ddc6 to your computer and use it in GitHub Desktop.
Linkit One Corrected GPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LGPS.h> | |
gpsSentenceInfoStruct info; | |
char buff[256]; | |
char gmaps_buff[50]; | |
static unsigned char getComma(unsigned char num,const char *str) | |
{ | |
unsigned char i,j = 0; | |
int len=strlen(str); | |
for(i = 0;i < len;i ++) | |
{ | |
if(str[i] == ',') | |
j++; | |
if(j == num) | |
return i + 1; | |
} | |
return 0; | |
} | |
static double getDoubleNumber(const char *s) | |
{ | |
char buf[10]; | |
unsigned char i; | |
double rev; | |
i=getComma(1, s); | |
i = i - 1; | |
strncpy(buf, s, i); | |
buf[i] = 0; | |
rev=atof(buf); | |
return rev; | |
} | |
static double getIntNumber(const char *s) | |
{ | |
char buf[10]; | |
unsigned char i; | |
double rev; | |
i=getComma(1, s); | |
i = i - 1; | |
strncpy(buf, s, i); | |
buf[i] = 0; | |
rev=atoi(buf); | |
return rev; | |
} | |
void parseGPGGA(const char* GPGGAstr) | |
{ | |
/* Refer to http://www.gpsinformation.org/dale/nmea.htm#GGA | |
* Sample data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 | |
* Where: | |
* GGA Global Positioning System Fix Data | |
* 123519 Fix taken at 12:35:19 UTC | |
* 4807.038,N Latitude 48 deg 07.038' N | |
* 01131.000,E Longitude 11 deg 31.000' E | |
* 1 Fix quality: 0 = invalid | |
* 1 = GPS fix (SPS) | |
* 2 = DGPS fix | |
* 3 = PPS fix | |
* 4 = Real Time Kinematic | |
* 5 = Float RTK | |
* 6 = estimated (dead reckoning) (2.3 feature) | |
* 7 = Manual input mode | |
* 8 = Simulation mode | |
* 08 Number of satellites being tracked | |
* 0.9 Horizontal dilution of position | |
* 545.4,M Altitude, Meters, above mean sea level | |
* 46.9,M Height of geoid (mean sea level) above WGS84 | |
* ellipsoid | |
* (empty field) time in seconds since last DGPS update | |
* (empty field) DGPS station ID number | |
* *47 the checksum data, always begins with * | |
*/ | |
double latitude, latitude_g; | |
double longitude, longitude_g; | |
char latitude_dir, longitude_dir; | |
int tmp, hour, minute, second, num ; | |
if(GPGGAstr[0] == '$') | |
{ | |
tmp = getComma(1, GPGGAstr); | |
hour = (GPGGAstr[tmp + 0] - '0') * 10 + (GPGGAstr[tmp + 1] - '0'); | |
minute = (GPGGAstr[tmp + 2] - '0') * 10 + (GPGGAstr[tmp + 3] - '0'); | |
second = (GPGGAstr[tmp + 4] - '0') * 10 + (GPGGAstr[tmp + 5] - '0'); | |
sprintf(buff, "UTC timer %2d-%2d-%2d", hour, minute, second); | |
Serial.println(buff); | |
tmp = getComma(2, GPGGAstr); | |
latitude = getDoubleNumber(&GPGGAstr[tmp]); | |
tmp = getComma(4, GPGGAstr); | |
longitude = getDoubleNumber(&GPGGAstr[tmp]); | |
//get lat/lon direction | |
tmp = getComma(3, GPGGAstr); | |
latitude_dir = (GPGGAstr[tmp]); | |
tmp = getComma(5, GPGGAstr); | |
longitude_dir = (GPGGAstr[tmp]); | |
convertCoords(latitude, longitude, latitude_g, longitude_g); | |
sprintf(buff, "latitude = %10.4f, longitude = %10.4f", latitude, longitude); | |
sprintf(gmaps_buff,"http://maps.google.com/?q=%.6f%c,%.6f%c",latitude_g,latitude_dir,longitude_g,longitude_dir); | |
Serial.println(buff); | |
Serial.println(gmaps_buff); | |
tmp = getComma(7, GPGGAstr); | |
num = getIntNumber(&GPGGAstr[tmp]); | |
sprintf(buff, "satellites number = %d", num); | |
Serial.println(buff); | |
} | |
else | |
{ | |
Serial.println("Not get data"); | |
} | |
} | |
//---------------------------------------------------------------------- | |
//!\brief Convert GPGGA coordinates (degrees-mins-secs) to true decimal-degrees | |
//!\return - | |
//---------------------------------------------------------------------- | |
void convertCoords(double latitude, double longitude, double &lat_return, double &lon_return){ | |
int lat_deg_int = int(latitude/100); //extract the first 2 chars to get the latitudinal degrees | |
int lon_deg_int = int(longitude/100); //extract first 3 chars to get the longitudinal degrees | |
// must now take remainder/60 | |
//this is to convert from degrees-mins-secs to decimal degrees | |
// so the coordinates are "google mappable" | |
float latitude_float = latitude - lat_deg_int * 100; //remove the degrees part of the coordinates - so we are left with only minutes-seconds part of the coordinates | |
float longitude_float = longitude - lon_deg_int * 100; | |
lat_return = lat_deg_int + latitude_float / 60 ; //add back on the degrees part, so it is decimal degrees | |
lon_return = lon_deg_int + longitude_float / 60 ; | |
} | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
LGPS.powerOn(); | |
Serial.println("LGPS Power on, and waiting ..."); | |
delay(3000); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
Serial.println("LGPS loop"); | |
LGPS.getData(&info); | |
Serial.println((char*)info.GPGGA); | |
parseGPGGA((const char*)info.GPGGA); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i am not getting the output.what may be the prblm?
i hav copied the exact code.
i am not understanding where i am wrong.
plz help me.