Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Lat/Long conversion near absolute longitude lines and equator #10

Open
m1geo opened this issue Jan 22, 2021 · 1 comment
Open

Comments

@m1geo
Copy link

m1geo commented Jan 22, 2021

When referring to the code converting to Lat/Long for APRS transmission, there is a bug. The code only covers when dm_lon is less than 1000, but, should be extended to include <100 and <10:

if (dm_lon < 10000) {
lonStr[0] = '0';
}
if (dm_lon < 1000) {
lonStr[1] = '0';
}

Otherwise, this causes cases similar to below, where you can see that the longitude has a space in it since the case where dm_lon is less than 100 (as 10.83 is) is not covered.

2021-01-21 16:56:30 GMT: M1GEO-9>APLIGA,WIDE1-1,WIDE2-1,qAR,MB7UM:=5210.94N/00 10.83E>037/000/A=000090 056TXP 791RXP 27.70C 985.01hPa 4.59V 12S [Invalid uncompressed location]

I added a the following to resolve the issue:

  if (dm_lon < 100) {
    lonStr[2] = '0';
  }
  if (dm_lon < 10) {
    lonStr[3] = '0';
  }

2021-01-21 18:57:27 GMT: M1GEO-9>APLIGA,WIDE1-1,WIDE2-1,qAR,MB7UM:=5210.99N/00010.83E>095/028/A=000067 013TXP 081RXP 23.80C 984.81hPa 4.57V 12S

There should probably be similar tweaks to the latitude, allowing for operation close to the equator - however, this is not an issue for me...

Cheers, George - M1GEO.

@dl9sau
Copy link

dl9sau commented Jul 25, 2021

dtostrf() adds leading blanks if the number is smaller than the reserved field.
This should be the nicer approach (diff):

@@ -439,6 +532,7 @@ void updatePosition() {
// Convert and set latitude NMEA string Degree Minute Hundreths of minutes ddmm.hh[S,N].
char latStr[10];
int temp = 0;

  • char *p;

    double d_lat = gps.location.lat();
    double dm_lat = 0.0;
    @@ -452,11 +546,10 @@ void updatePosition() {
    }

    dtostrf(dm_lat, 7, 2, latStr);

  • if (dm_lat < 1000) {
  • latStr[0] = '0';
  • }
  • // smaller numbers lead to leading blanks. Replace by '0', for correct aprs positions

  • for (p = latStr; *p && *p == ' '; p++)

  • *p = '0';

  • if (d_lat >= 0.0) {
    latStr[7] = 'N';
    } else {
    @@ -480,13 +573,9 @@ void updatePosition() {

    dtostrf(dm_lon, 8, 2, lonStr);

  • if (dm_lon < 10000) {
  • lonStr[0] = '0';
  • }
  • if (dm_lon < 1000) {
  • lonStr[1] = '0';
  • }
  • // smaller numbers lead to leading blanks. Replace by '0', for correct aprs positions
  • for (p = lonStr; *p && *p == ' '; p++)
  • *p = '0';
    if (d_lon >= 0.0) {
    lonStr[8] = 'E';
    } else {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants