lightaprs / LightAPRS-1.0

Arduino based APRS Tracker
GNU General Public License v3.0
93 stars 49 forks source link

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

Open m1geo opened 3 years ago

m1geo commented 3 years ago

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:

https://github.com/lightaprs/LightAPRS-1.0/blob/82fba0337935b802f001e48789f66ba36653b793/LightAPRS-vehicle/LightAPRS-vehicle.ino#L282-L287

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 commented 3 years ago

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;