summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-05-30 17:30:08 -0700
committerKeith Packard <keithp@keithp.com>2014-05-30 17:32:52 -0700
commit12c408c5aa1d234fe9c946078d8a343b4fda7ebb (patch)
treef564c5c09b0e9cf932a135c5e665738a9506b772 /src
parenta7b0a5613c8e59b4c672b21f8d0890fd5cffd4dc (diff)
altos: Test APRS altitude encoding
Verify fixed point version against naïve implementation Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/test/ao_aprs_test.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ao_aprs_test.c b/src/test/ao_aprs_test.c
index b1d17d3f..86cf527a 100644
--- a/src/test/ao_aprs_test.c
+++ b/src/test/ao_aprs_test.c
@@ -97,9 +97,36 @@ audio_gap(int secs)
#endif
}
+#include <math.h>
+
+int
+ao_aprs_encode_altitude_expensive(int meters)
+{
+ double feet = meters / 0.3048;
+
+ double encode = log(feet) / log(1.002);
+ return floor(encode + 0.5);
+}
+
// This is where we go after reset.
int main(int argc, char **argv)
{
+ int e, x;
+ int a;
+
+ for (a = 1; a < 100000; a++) {
+ e = ao_aprs_encode_altitude(a);
+ x = ao_aprs_encode_altitude_expensive(a);
+
+ if (e != x) {
+ double back_feet, back_meters;
+ back_feet = pow(1.002, e);
+ back_meters = back_feet * 0.3048;
+ fprintf (stderr, "APRS altitude encoding failure: altitude %d actual %d expected %d actual meters %f\n",
+ a, e, x, back_meters);
+ }
+ }
+
audio_gap(1);
ao_gps_data.latitude = (45.0 + 28.25 / 60.0) * 10000000;