--- /dev/null
+/*
+ * 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);
+}
+
}
}
+#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.
*/
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++ = '/';
buf += 2;
*buf++ = 33 + ((1 << 5) | (2 << 3));
- *buf++ = '\0';
+
+#if HAS_ADC
+ buf += tncComment(buf);
+#else
+ *buf = '\0';
+#endif
+
return buf - tncBuffer;
}
#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
*/
#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
*/