altos: Eliminate implicit 1 byte offset in uint16/int16 functions
[fw/altos] / src / test / ao_flight_test.c
index 9bb03d682f55c3c97fe2de9da639fdee5aecdb2c..3231194d519467843bff13b798761622e826bf34 100644 (file)
@@ -54,6 +54,15 @@ struct ao_adc {
 #define __code
 #define __reentrant
 
+#define HAS_FLIGHT 1
+#define HAS_IGNITE 1
+#define HAS_USB 1
+#define HAS_GPS 1
+#ifndef HAS_ACCEL
+#define HAS_ACCEL 1
+#define HAS_ACCEL_REF 0
+#endif
+
 #include <ao_data.h>
 
 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
@@ -180,6 +189,7 @@ struct ao_cmds {
 #define ao_xmemset(d,v,c) memset(d,v,c)
 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
 
+#define AO_NEED_ALTITUDE_TO_PRES 1
 #include "ao_convert.c"
 
 struct ao_config {
@@ -199,24 +209,17 @@ struct ao_config ao_config;
 
 #define DATA_TO_XDATA(x) (x)
 
-#define HAS_FLIGHT 1
-#define HAS_IGNITE 1
-#define HAS_ADC 1
-#define HAS_USB 1
-#define HAS_GPS 1
-#ifndef HAS_ACCEL
-#define HAS_ACCEL 1
-#define HAS_ACCEL_REF 0
-#endif
 
 #define GRAVITY 9.80665
 extern int16_t ao_ground_accel, ao_flight_accel;
 extern int16_t ao_accel_2g;
 
+typedef int16_t        accel_t;
+
 extern uint16_t        ao_sample_tick;
 
 extern int16_t ao_sample_height;
-extern int16_t ao_sample_accel;
+extern accel_t ao_sample_accel;
 extern int32_t ao_accel_scale;
 extern int16_t ao_ground_height;
 extern int16_t ao_sample_alt;
@@ -466,7 +469,6 @@ union ao_telemetry_all {
 uint16_t
 uint16(uint8_t *bytes, int off)
 {
-       off++;
        return (uint16_t) bytes[off] | (((uint16_t) bytes[off+1]) << 8);
 }
 
@@ -605,22 +607,22 @@ ao_sleep(void *wchan)
                                        }
                                } else if (len == 99) {
                                        ao_flight_started = 1;
-                                       tick = uint16(bytes, 21);
-                                       ao_flight_ground_accel = int16(bytes, 7);
-                                       ao_config.accel_plus_g = int16(bytes, 17);
-                                       ao_config.accel_minus_g = int16(bytes, 19);
+                                       tick = uint16(bytes+1, 21);
+                                       ao_flight_ground_accel = int16(bytes+1, 7);
+                                       ao_config.accel_plus_g = int16(bytes+1, 17);
+                                       ao_config.accel_minus_g = int16(bytes+1, 19);
                                        type = 'A';
-                                       a = int16(bytes, 23);
-                                       b = int16(bytes, 25);
+                                       a = int16(bytes+1, 23);
+                                       b = int16(bytes+1, 25);
                                } else if (len == 98) {
                                        ao_flight_started = 1;
-                                       tick = uint16(bytes, 20);
-                                       ao_flight_ground_accel = int16(bytes, 6);
-                                       ao_config.accel_plus_g = int16(bytes, 16);
-                                       ao_config.accel_minus_g = int16(bytes, 18);
+                                       tick = uint16(bytes+1, 20);
+                                       ao_flight_ground_accel = int16(bytes+1, 6);
+                                       ao_config.accel_plus_g = int16(bytes+1, 16);
+                                       ao_config.accel_minus_g = int16(bytes+1, 18);
                                        type = 'A';
-                                       a = int16(bytes, 22);
-                                       b = int16(bytes, 24);
+                                       a = int16(bytes+1, 22);
+                                       b = int16(bytes+1, 24);
                                } else {
                                        printf("unknown len %d\n", len);
                                        continue;