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

View File

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

View File

@ -145,9 +145,10 @@ static void TaskTick(void *pvParameters)
for(;;) 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,"utc: %s alt:%d\r\n",GpsInfo.TimeOfFix,(int)GpsInfo.alt);
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"SV: %u\r\n",GpsInfo.numSVs); 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_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART,"Heading: %s Speed: %s\r\n",GpsInfo.heading,GpsInfo.speed);
*/ */
PIOS_LED_Toggle(LED1); PIOS_LED_Toggle(LED1);