1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

Accidentally used floating point when parsing NEMA. Lost resolution on

position.
This commit is contained in:
James Cotton 2011-12-21 16:38:53 -06:00
parent 0024cbaa51
commit 5d4da2213f

View File

@ -239,27 +239,28 @@ static bool NMEA_latlon_to_fixed_point(int32_t * latlon, char *nmea_latlon, bool
}
/* scale up the mmmm[mm] field apropriately depending on # of digits */
/* not using 1eN notation because that forces fixed point and lost precision */
switch (units) {
case 0:
/* no digits, value is zero so no scaling */
break;
case 1: /* m */
num_m *= 1e6f; /* m000000 */
num_m *= 1000000; /* m000000 */
break;
case 2: /* mm */
num_m *= 1e5f; /* mm00000 */
num_m *= 100000; /* mm00000 */
break;
case 3: /* mmm */
num_m *= 1e4f; /* mmm0000 */
num_m *= 10000; /* mmm0000 */
break;
case 4: /* mmmm */
num_m *= 1e3f; /* mmmm000 */
num_m *= 1000; /* mmmm000 */
break;
case 5: /* mmmmm */
num_m *= 1e2f; /* mmmmm00 */
num_m *= 100; /* mmmmm00 */
break;
case 6: /* mmmmmm */
num_m *= 1e1f; /* mmmmmm0 */
num_m *= 10; /* mmmmmm0 */
break;
default:
/* unhandled format */
@ -267,9 +268,9 @@ static bool NMEA_latlon_to_fixed_point(int32_t * latlon, char *nmea_latlon, bool
break;
}
*latlon = (num_DDDMM / 100) * 1e7f; /* scale the whole degrees */
*latlon += (num_DDDMM % 100) * 1e7f / 60.0f; /* add in the scaled decimal whole minutes */
*latlon += num_m / 60.0f; /* add in the scaled decimal fractional minutes */
*latlon = (num_DDDMM / 100) * 10000000; /* scale the whole degrees */
*latlon += (num_DDDMM % 100) * 10000000 / 60; /* add in the scaled decimal whole minutes */
*latlon += num_m / 60; /* add in the scaled decimal fractional minutes */
if (negative)
*latlon *= -1;