altos: Report battery, apogee and main voltages over APRS
authorKeith Packard <keithp@keithp.com>
Wed, 15 Jan 2014 20:40:26 +0000 (12:40 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 15 Jan 2014 20:40:26 +0000 (12:40 -0800)
This makes APRS more usable when you mute the RF audio on the HT.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_convert_volt.c [new file with mode: 0644]
src/drivers/ao_aprs.c
src/stm/ao_arch.h
src/telemega-v0.1/Makefile
src/telemega-v0.1/ao_pins.h
src/telemega-v1.0/Makefile
src/telemetrum-v2.0/Makefile
src/telemetrum-v2.0/ao_pins.h

index 0b634a7994dd83ad0361649f66a6463c46645b85..29ad26031d9733cfe7409b31127c06c53698ec41 100644 (file)
@@ -307,6 +307,17 @@ ao_altitude_to_pa(alt_t alt);
 #include <ao_serial.h>
 #endif
 
+/*
+ * ao_convert_volt.c
+ *
+ * Convert ADC readings to decivolts
+ */
+
+int16_t
+ao_battery_decivolt(int16_t adc);
+
+int16_t
+ao_ignite_decivolt(int16_t adc);
 
 /*
  * ao_spi_slave.c
diff --git a/src/core/ao_convert_volt.c b/src/core/ao_convert_volt.c
new file mode 100644 (file)
index 0000000..8556d42
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2014 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "ao.h"
+
+#define scale(v,p,m)   ((int32_t) (v) * (AO_ADC_REFERENCE_DV * ((p) + (m))) / (AO_ADC_MAX * (m)))
+
+int16_t
+ao_battery_decivolt(int16_t adc)
+{
+       return scale(adc, AO_BATTERY_DIV_PLUS, AO_BATTERY_DIV_MINUS);
+}
+
+int16_t
+ao_ignite_decivolt(int16_t adc)
+{
+       return scale(adc, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS);
+}
+
index 96e90f0027f080faa4015d660bcdaab7ecaa85de..56d984375ba82f725875cddd1cc921e74c285aa5 100644 (file)
@@ -488,6 +488,28 @@ static void tncCompressInt(uint8_t *dest, int32_t value, int len) {
        }
 }
 
+#if HAS_ADC
+static int tncComment(uint8_t *buf)
+{
+       struct ao_data packet;
+       
+       ao_arch_critical(ao_data_get(&packet););
+
+       int16_t battery = ao_battery_decivolt(packet.adc.v_batt);
+       int16_t apogee = ao_ignite_decivolt(AO_SENSE_DROGUE(&packet));
+       int16_t main = ao_ignite_decivolt(AO_SENSE_MAIN(&packet));
+
+       return sprintf((char *) buf,
+                      "B:%d.%d A:%d.%d M:%d.%d",
+                      battery/10,
+                      battery % 10,
+                      apogee/10,
+                      apogee%10,
+                      main/10,
+                      main%10);
+}
+#endif
+
 /**
  *   Generate the plain text position packet.
  */
@@ -502,72 +524,8 @@ static int tncPositionPacket(void)
        altitude = 0;
     altitude = (altitude * (int32_t) 10000 + (3048/2)) / (int32_t) 3048;
     
-#if 0
-    char       lat_sign = 'N', lon_sign = 'E';
-    uint16_t   lat_deg;
-    uint16_t   lon_deg;
-    uint16_t   lat_min;
-    uint16_t   lat_frac;
-    uint16_t   lon_min;
-    uint16_t   lon_frac;
-
-    if (latitude < 0) {
-       lat_sign = 'S';
-       latitude = -latitude;
-    }
-
-    if (longitude < 0) {
-       lon_sign = 'W';
-       longitude = -longitude;
-    }
-
-    /* Round latitude and longitude by 0.005 minutes */
-    latitude = latitude + 833;
-    if (latitude > 900000000)
-       latitude = 900000000;
-    longitude = longitude + 833;
-    if (longitude > 1800000000)
-           longitude = 1800000000;
-
-    lat_deg = latitude / 10000000;
-    latitude -= lat_deg * 10000000;
-    latitude *= 60;
-    lat_min = latitude / 10000000;
-    latitude -= lat_min * 10000000;
-    lat_frac = latitude / 100000;
-
-    lon_deg = longitude / 10000000;
-    longitude -= lon_deg * 10000000;
-    longitude *= 60;
-    lon_min = longitude / 10000000;
-    longitude -= lon_min * 10000000;
-    lon_frac = longitude / 100000;
-
-#if 0
-    return sprintf ((char *) tncBuffer, "=%02u%02u.%02u%c\\%03u%02u.%02u%cO /A=%06u\015",
-                   lat_deg, lat_min, lat_frac, lat_sign,
-                   lon_deg, lon_min, lon_frac, lon_sign,
-                   altitude);
-#endif
-
-    return sprintf ((char *) tncBuffer, "/%02u%02u%02uh%02u%02u.%02u%c/%03u%02u.%02u%c'/A=%06u\015",
-                   ao_gps_data.hour,
-                   ao_gps_data.minute,
-                   ao_gps_data.second,
-                   lat_deg, lat_min, lat_frac, lat_sign,
-                   lon_deg, lon_min, lon_frac, lon_sign,
-                   altitude);
-#endif
     buf = tncBuffer;
-#if APRS_TIME
-    sprintf ((char *) buf, "/%02u%02u%02uh",
-            ao_gps_data.hour,
-            ao_gps_data.minute,
-            ao_gps_data.second);
-    buf += 8;
-#else
     *buf++ = '!';
-#endif
 
     /* Symbol table ID */
     *buf++ = '/';
@@ -591,7 +549,13 @@ static int tncPositionPacket(void)
     buf += 2;
 
     *buf++ = 33 + ((1 << 5) | (2 << 3));
-    *buf++ = '\0';
+
+#if HAS_ADC
+    buf += tncComment(buf);
+#else
+    *buf = '\0';
+#endif
+
     return buf - tncBuffer;
 }
 
index 42fe727a84139d0ff47351681c868f81240ab435..76fa91947bd619d1884cbda63de15b94cd14db7e 100644 (file)
@@ -135,6 +135,9 @@ extern const uint32_t       ao_radio_cal;
 void
 ao_adc_init();
 
+/* ADC maximum reported value */
+#define AO_ADC_MAX                     4095
+
 #define AO_BOOT_APPLICATION_BASE       ((uint32_t *) 0x08001000)
 #define AO_BOOT_LOADER_BASE            ((uint32_t *) 0x0)
 #define HAS_BOOT_LOADER                        1
index 35f28b3020007aca5132740bd0fd5747d69796fa..28ed7c98e93194b5b804995a68da732a906aac37 100644 (file)
@@ -100,6 +100,7 @@ ALTOS_SRC = \
        ao_i2c_stm.c \
        ao_mpu6000.c \
        ao_convert_pa.c \
+       ao_convert_volt.c \
        ao_log.c \
        ao_log_mega.c \
        ao_sample.c \
index daeb9f1741d0e08aa6de2be1274dd8ac135a60a1..db397c669927630357a2103837df52f9627f84ba 100644 (file)
@@ -249,6 +249,23 @@ struct ao_adc {
 #define AO_ADC_SQ8             AO_ADC_V_PBATT
 #define AO_ADC_SQ9             AO_ADC_TEMP
 
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS    56      /* 5.6k */
+#define AO_BATTERY_DIV_MINUS   100     /* 10k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS     100     /* 100k */
+#define AO_IGNITE_DIV_MINUS    27      /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV    33
+
 /*
  * Pressure sensor settings
  */
index b5c1f4026aad1f0a420fbe994590dc5d8a215098..7a0c1195d534fb682a4715922ca000a5724c926d 100644 (file)
@@ -101,6 +101,7 @@ ALTOS_SRC = \
        ao_i2c_stm.c \
        ao_mpu6000.c \
        ao_convert_pa.c \
+       ao_convert_volt.c \
        ao_log.c \
        ao_log_mega.c \
        ao_sample.c \
index 0b9e6914a38b16a83be14dcc0845c4e7305d8cf4..83a364dcbdd4ea3d526352146919e76287a13aec 100644 (file)
@@ -76,6 +76,7 @@ ALTOS_SRC = \
        ao_eeprom_stm.c \
        ao_report.c \
        ao_convert_pa.c \
+       ao_convert_volt.c \
        ao_log.c \
        ao_log_metrum.c \
        ao_sample.c \
index 02f0f5e3efecc9b3648f02f7b0ecc61b9a937016..1b5cedc743607418fbef6e5a6d2d6ef60f895f8e 100644 (file)
@@ -189,6 +189,23 @@ struct ao_adc {
 #define AO_ADC_SQ3             AO_ADC_V_BATT
 #define AO_ADC_SQ4             AO_ADC_TEMP
 
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS    56      /* 5.6k */
+#define AO_BATTERY_DIV_MINUS   100     /* 10k */
+
+/*
+ * Voltage divider on ADC igniter samplers
+ */
+#define AO_IGNITE_DIV_PLUS     100     /* 100k */
+#define AO_IGNITE_DIV_MINUS    27      /* 27k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV    33
+
 /*
  * GPS
  */