1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

OP-25: lat, lon and alt to float, lat and lon to desimal degrees format

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@435 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
sambas 2010-04-07 08:02:44 +00:00 committed by sambas
parent 5bf7b07437
commit 23aa2ea1cd
3 changed files with 32 additions and 23 deletions

View File

@ -284,7 +284,7 @@ void nmeaProcessGPGGA(char* packet)
char *pEnd;
uint8_t i=0;
long deg,desim;
long deg,min,desim;
double degrees, minutesfrac;
#ifdef NMEA_DEBUG_GGA
@ -319,17 +319,21 @@ void nmeaProcessGPGGA(char* packet)
// next field: latitude
// get latitude [ddmm.mmmmm]
tokens = strtok_r(NULL, delimiter, &last);
if(1) // 5 desimal output
if(strlen(tokens)==10)// 5 desimal output
{
deg=strtol (tokens,&pEnd,10);
min=deg%100;
deg=deg/100;
desim=strtol (pEnd+1,NULL,10);
GpsInfo.lat=deg*100000+desim;
GpsInfo.lat=deg+(min+desim/100000.0)/60.0; // to desimal degrees
}
else // 4 desimal output
else if(strlen(tokens)==9) // 4 desimal output
{
deg=strtol (tokens,&pEnd,10);
min=deg%100;
deg=deg/100;
desim=strtol (pEnd+1,NULL,10);
GpsInfo.lat=deg*10000+desim;
GpsInfo.lat=deg+(min+desim/10000.0)/60.0; // to desimal degrees
}
// convert to pure degrees [dd.dddd] format
/* minutesfrac = modf(GpsInfo.PosLLA.lat.f/100, &degrees);
@ -340,22 +344,26 @@ void nmeaProcessGPGGA(char* packet)
// next field: N/S indicator
// correct latitute for N/S
tokens = strtok_r(NULL, delimiter, &last);
//if(*tokens[3] == 'S') GpsInfo.PosLLA.lat.f = -GpsInfo.PosLLA.lat.f;
if(tokens[0] == 'S') GpsInfo.lat = -GpsInfo.lat;
// next field: longitude
// get longitude [ddmm.mmmmm]
// get longitude [dddmm.mmmmm]
tokens = strtok_r(NULL, delimiter, &last);
if(1) // 5 desimal output
if(strlen(tokens)==11)// 5 desimal output
{
deg=strtol (tokens,&pEnd,10);
min=deg%100;
deg=deg/100;
desim=strtol (pEnd+1,NULL,10);
GpsInfo.lon=deg*100000+desim;
GpsInfo.lon=deg+(min+desim/100000.0)/60.0; // to desimal degrees
}
else // 4 desimal output
else if(strlen(tokens)==10) // 4 desimal output
{
deg=strtol (tokens,&pEnd,10);
min=deg%100;
deg=deg/100;
desim=strtol (pEnd+1,NULL,10);
GpsInfo.lon=deg*10000+desim;
GpsInfo.lon=deg+(min+desim/10000.0)/60.0; // to desimal degrees
}
// convert to pure degrees [dd.dddd] format
@ -367,15 +375,15 @@ void nmeaProcessGPGGA(char* packet)
// next field: E/W indicator
// correct latitute for E/W
tokens = strtok_r(NULL, delimiter, &last);
//if(*tokens[5] == 'W') GpsInfo.PosLLA.lon.f = -GpsInfo.PosLLA.lon.f;
if(tokens[0] == 'W') GpsInfo.lon = -GpsInfo.lon;
// next field: position fix status
// position fix status
// 0 = Invalid, 1 = Valid SPS, 2 = Valid DGPS, 3 = Valid PPS
// check for good position fix
tokens = strtok_r(NULL, delimiter, &last);
//if(&tokens[6] != '0' || &tokens[6] != 0)
// GpsInfo.PosLLA.updates++;
if((tokens[0] != '0') || (tokens[0] != 0))
GpsInfo.updates++;
// next field: satellites used
// get number of satellites used in GPS solution
@ -389,9 +397,9 @@ void nmeaProcessGPGGA(char* packet)
// get altitude (in meters mm.m)
tokens = strtok_r(NULL, delimiter, &last);
//reuse variables for alt
deg=strtol (tokens,&pEnd,10);
deg=strtol (tokens,&pEnd,10); // always 0.1m resolution?
desim=strtol (pEnd+1,NULL,10);
GpsInfo.alt=deg*10+desim;
GpsInfo.alt=deg+desim/10.0;
// next field: altitude units, always 'M'
// next field: geoid seperation

View File

@ -34,9 +34,9 @@ typedef struct struct_GpsInfo
{
uint8_t numSVs;
signed long lat;
signed long lon;
signed int alt;
float lat;
float lon;
float alt;
char TimeOfFix[12];
// make these to values
@ -45,6 +45,6 @@ typedef struct struct_GpsInfo
uint16_t updates;
} GpsInfoType;
} __attribute__((packed)) GpsInfoType;
#endif // GPSINFO_H

View File

@ -145,9 +145,10 @@ static void TaskTick(void *pvParameters)
for(;;)
{
/*PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"utc: %s alt:%u\r\n",GpsInfo.TimeOfFix,GpsInfo.alt);
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"lat: %u lon:%u\r\n",GpsInfo.lat,GpsInfo.lon);
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"SV: %u\r\n",GpsInfo.numSVs);
/*
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"utc: %s alt:%d\r\n",GpsInfo.TimeOfFix,(int)GpsInfo.alt);
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"lat: %d lon: %d\r\n",(long)(GpsInfo.lat*10000),(long)(GpsInfo.lon*10000));
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"SV: %d\r\n",GpsInfo.numSVs);
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"Heading: %s Speed: %s\r\n",GpsInfo.heading,GpsInfo.speed);
*/
PIOS_LED_Toggle(LED1);