SQ9MDD / TTGO-T-Beam-LoRa-APRS

Use TTGO T-Beam as LoRa APRS Tracker
64 stars 23 forks source link

If altitude negative: wrong notation #88

Closed dl9sau closed 2 years ago

dl9sau commented 2 years ago

If altitude is negative, /A= altitude is encoded wrong: /A=000-43 instead of /A=-00043

Fix:

TTGO_T-Beam_LoRa_APRS.ino:

@@ -274,7 +292,7 @@ void prepareAPRSFrame(){
   double Tspeed=0, Tcourse=0;
   uint32_t aprs_lat, aprs_lon;
   int i;
-  int Talt;
+  long Talt;
   Tlat=gps.location.lat();
   Tlon=gps.location.lng();
   Tcourse=gps.course.deg();
@ -310,13 +336,13 @@ void prepareAPRSFrame(){
     outString += "H";

     if (showAltitude){
-      Talt = gps.altitude.meters() * 3.28;
-      Altx = Talt;
+      Talt = gps.altitude.feet();
+      char buf[7];
       outString += "/A=";
-      for (i = 0; i < (6 - Altx.length()); ++i){
-        outString += "0";
-      }
-      outString += Talt;
+      if (Talt > 999999) Talt=999999;
+      else if (Talt < -99999) Talt=-99999;
+      sprintf(buf, "%06ld", Talt);
+      outString += buf;
     }
   }else{  //fixed position not compresed
     outString += aprsLatPreset;

Comments:

  1. Storage size of int may be not enough -> long Talt.
  2. TinyGPS++ alreadready comes with gps.altitude.feet(); -> no need to do it ourself (gps.altitude.meters() * 3.28;)
  3. /A=nnnnnn : n is exactly 6 bytes long. -> Assured Talt is in between -99999 and 999999
dl9sau commented 2 years ago

Feature is stable in my development version