Doesn't track flight state changes correctly.
Signed-off-by: Keith Packard <keithp@keithp.com>
#ifndef _AO_ADC_H_
#define _AO_ADC_H_
-
-
/*
* One set of samples read from the A/D converter or telemetry
*/
-
+#if AO_ADC_RING
/*
* ao_adc.c
*/
#if HAS_ACCEL_REF
extern volatile __xdata uint16_t ao_accel_ref[AO_ADC_RING];
#endif
+#endif
/* Trigger a conversion sequence (called from the timer interrupt) */
void
*/
#include "ao.h"
+#include "ao_log.h"
+#include <ao_sample.h>
+#include <ao_data.h>
__xdata struct ao_config ao_config;
__pdata uint8_t ao_config_loaded;
}
#endif
+#if HAS_RADIO
void
ao_config_set_radio(void)
{
ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal);
}
+#endif /* HAS_RADIO */
static void
_ao_config_get(void)
ao_config.accel_minus_g = 0;
}
/* Fixups for minor version 3 */
+#if HAS_RADIO
if (ao_config.minor < 3)
ao_config.radio_cal = ao_radio_cal;
+#endif
/* Fixups for minor version 4 */
if (ao_config.minor < 4)
ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
ao_config.minor = AO_CONFIG_MINOR;
ao_config_dirty = 1;
}
+#if HAS_RADIO
ao_config_set_radio();
+#endif
ao_config_loaded = 1;
}
_ao_config_edit_finish();
}
+#if HAS_RADIO
void
ao_config_frequency_show(void) __reentrant
{
_ao_config_edit_finish();
ao_radio_recv_abort();
}
+#endif
#if HAS_FLIGHT
{
uint16_t i;
int32_t accel_total;
- uint8_t cal_adc_ring;
+ uint8_t cal_data_ring;
printf("Orient antenna %s and press a key...", orientation);
flush();
puts("Calibrating..."); flush();
i = ACCEL_CALIBRATE_SAMPLES;
accel_total = 0;
- cal_adc_ring = ao_sample_adc;
+ cal_data_ring = ao_sample_data;
while (i) {
- ao_sleep(DATA_TO_XDATA(&ao_sample_adc));
- while (i && cal_adc_ring != ao_sample_adc) {
- accel_total += (int32_t) ao_adc_ring[cal_adc_ring].accel;
- cal_adc_ring = ao_adc_ring_next(cal_adc_ring);
+ ao_sleep(DATA_TO_XDATA(&ao_sample_data));
+ while (i && cal_data_ring != ao_sample_data) {
+ int16_t accel = ao_data_accel(&ao_data_ring[cal_data_ring]);
+ printf ("accel %d\n", accel);
+ accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]);
+ cal_data_ring = ao_data_ring_next(cal_data_ring);
i--;
}
}
#endif /* HAS_FLIGHT */
+#if HAS_RADIO
void
ao_config_radio_cal_show(void) __reentrant
{
ao_config_set_radio();
_ao_config_edit_finish();
}
+#endif
#if HAS_LOG
void
}
#endif
+#if HAS_RADIO
void
ao_config_radio_enable_show(void) __reentrant
{
ao_config.radio_enable = ao_cmd_lex_i;
_ao_config_edit_finish();
}
+#endif /* HAS_RADIO */
#if HAS_AES
void
{ "L <seconds>\0Apogee detect lockout (s)",
ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, },
#endif /* HAS_FLIGHT */
+#if HAS_RADIO
{ "F <freq>\0Frequency (kHz)",
ao_config_frequency_set, ao_config_frequency_show },
{ "c <call>\0Callsign (8 char max)",
ao_config_callsign_set, ao_config_callsign_show },
{ "e <0 disable, 1 enable>\0Enable telemetry and RDF",
ao_config_radio_enable_set, ao_config_radio_enable_show },
+#endif /* HAS_RADIO */
#if HAS_ACCEL
{ "a <+g> <-g>\0Accel calib (0 for auto)",
ao_config_accel_calibrate_set,ao_config_accel_calibrate_show },
#endif /* HAS_ACCEL */
+#if HAS_RADIO
{ "f <cal>\0Radio calib (cal = rf/(xtal/2^16))",
ao_config_radio_cal_set, ao_config_radio_cal_show },
+#endif /* HAS_RADIO */
#if HAS_LOG
{ "l <size>\0Flight log size (kB)",
ao_config_log_set, ao_config_log_show },
#ifndef AO_FLIGHT_TEST
#include "ao.h"
+#include "ao_flight.h"
#endif
+#include "ao_sample.h"
#include "ao_kalman.h"
+
static __pdata int32_t ao_k_height;
static __pdata int32_t ao_k_speed;
static __pdata int32_t ao_k_accel;
*/
#include "ao.h"
+#include <ao_log.h>
__pdata uint32_t ao_log_current_pos;
__pdata uint32_t ao_log_end_pos;
__pdata uint32_t ao_log_start_pos;
__xdata uint8_t ao_log_running;
-__pdata enum flight_state ao_log_state;
+__pdata enum ao_flight_state ao_log_state;
__xdata uint16_t ao_flight_number;
__code uint8_t ao_log_format = AO_LOG_FORMAT_FULL;
#ifndef _AO_LOG_H_
#define _AO_LOG_H_
+#include <ao_flight.h>
+
/*
* ao_log.c
*/
extern __pdata uint32_t ao_log_end_pos;
extern __pdata uint32_t ao_log_start_pos;
extern __xdata uint8_t ao_log_running;
-extern __pdata enum flight_state ao_log_state;
+extern __pdata enum ao_flight_state ao_log_state;
/* required functions from the underlying log system */
#define AO_LOG_FORMAT_TINY 2 /* two byte state/baro records */
#define AO_LOG_FORMAT_TELEMETRY 3 /* 32 byte ao_telemetry records */
#define AO_LOG_FORMAT_TELESCIENCE 4 /* 32 byte typed telescience records */
+#define AO_LOG_FORMAT_MEGAMETRUM 5 /* 32 byte typed megametrum records */
#define AO_LOG_FORMAT_NONE 127 /* No log at all */
extern __code uint8_t ao_log_format;
} u;
};
+struct ao_log_mega {
+ char type; /* 0 */
+ uint8_t csum; /* 1 */
+ uint16_t tick; /* 2 */
+ union { /* 4 */
+ struct {
+ uint16_t flight; /* 4 */
+ int16_t ground_accel; /* 6 */
+ uint32_t ground_pres; /* 8 */
+ uint32_t ground_temp; /* 12 */
+ } flight; /* 16 */
+ struct {
+ uint16_t state;
+ uint16_t reason;
+ } state;
+ struct {
+ uint32_t pres; /* 4 */
+ uint32_t temp; /* 8 */
+ int16_t accel_x; /* 12 */
+ int16_t accel_y; /* 14 */
+ int16_t accel_z; /* 16 */
+ int16_t gyro_x; /* 18 */
+ int16_t gyro_y; /* 20 */
+ int16_t gyro_z; /* 22 */
+ } sensor; /* 24 */
+ struct {
+ int16_t v_batt; /* 4 */
+ int16_t v_pbatt; /* 8 */
+ int16_t n_sense; /* 10 */
+ int16_t sense[10]; /* 12 */
+ } volt; /* 32 */
+ struct {
+ int32_t latitude; /* 4 */
+ int32_t longitude; /* 8 */
+ int16_t altitude; /* 12 */
+ uint8_t hour; /* 14 */
+ uint8_t minute; /* 15 */
+ uint8_t second; /* 16 */
+ uint8_t flags; /* 17 */
+ uint8_t year; /* 18 */
+ uint8_t month; /* 19 */
+ uint8_t day; /* 20 */
+ uint8_t pad; /* 21 */
+ } gps; /* 22 */
+ struct {
+ uint16_t channels; /* 4 */
+ struct {
+ uint8_t svid;
+ uint8_t c_n;
+ } sats[12]; /* 6 */
+ } gps_sat; /* 30 */
+ } u;
+};
+
/* Write a record to the eeprom log */
uint8_t
ao_log_data(__xdata struct ao_log_record *log) __reentrant;
+uint8_t
+ao_log_mega(__xdata struct ao_log_mega *log) __reentrant;
+
#endif /* _AO_LOG_H_ */
#ifndef _AO_SAMPLE_H_
#define _AO_SAMPLE_H_
+#include <ao_data.h>
+
/*
* ao_sample.c
*/
#define AO_MSS_TO_ACCEL(mss) ((int16_t) ((mss) * 16))
extern __pdata uint16_t ao_sample_tick; /* time of last data */
-extern __pdata int16_t ao_sample_pres; /* most recent pressure sensor reading */
-extern __pdata int16_t ao_sample_alt; /* MSL of ao_sample_pres */
-extern __pdata int16_t ao_sample_height; /* AGL of ao_sample_pres */
+extern __pdata pres_t ao_sample_pres; /* most recent pressure sensor reading */
+extern __pdata alt_t ao_sample_alt; /* MSL of ao_sample_pres */
+extern __pdata alt_t ao_sample_height; /* AGL of ao_sample_pres */
extern __data uint8_t ao_sample_adc; /* Ring position of last processed sample */
+extern __data uint8_t ao_sample_data; /* Ring position of last processed sample */
#if HAS_ACCEL
-extern __pdata int16_t ao_sample_accel; /* most recent accel sensor reading */
+extern __pdata accel_t ao_sample_accel; /* most recent accel sensor reading */
#endif
-extern __pdata int16_t ao_ground_pres; /* startup pressure */
-extern __pdata int16_t ao_ground_height; /* MSL of ao_ground_pres */
+extern __pdata pres_t ao_ground_pres; /* startup pressure */
+extern __pdata alt_t ao_ground_height; /* MSL of ao_ground_pres */
#if HAS_ACCEL
-extern __pdata int16_t ao_ground_accel; /* startup acceleration */
-extern __pdata int16_t ao_accel_2g; /* factory accel calibration */
+extern __pdata accel_t ao_ground_accel; /* startup acceleration */
+extern __pdata accel_t ao_accel_2g; /* factory accel calibration */
extern __pdata int32_t ao_accel_scale; /* sensor to m/s² conversion */
#endif
ao.h \
ao_arch.h \
ao_arch_funcs.h \
+ ao_data.h \
+ ao_sample.h \
ao_pins.h \
altitude.h \
ao_kalman.h \
#
# Common AltOS sources
#
+
+# ao_cc1120.c \
+# ao_packet.c \
+# ao_packet_slave.c \
+
ALTOS_SRC = \
ao_interrupt.c \
ao_product.c \
ao_mutex.c \
ao_serial_stm.c \
ao_gps_skytraq.c \
- ao_cc1120.c \
ao_freq.c \
ao_dma_stm.c \
ao_spi_stm.c \
ao_m25.c \
ao_usb_stm.c \
ao_exti_stm.c \
- ao_packet.c \
- ao_packet_slave.c \
+ ao_report.c \
ao_i2c_stm.c \
ao_hmc5883.c \
ao_mpu6000.c \
- ao_convert_pa.c
+ ao_convert_pa.c \
+ ao_log.c \
+ ao_log_mega.c \
+ ao_sample_mm.c \
+ ao_kalman.c \
+ ao_flight_mm.c
+
PRODUCT=MegaMetrum-v0.1
PRODUCT_DEF=-DMEGAMETRUM
#include <ao.h>
#include <ao_hmc5883.h>
#include <ao_mpu6000.h>
+#include <ao_log.h>
#include <ao_exti.h>
void
ao_timer_init();
ao_cmd_init();
ao_gps_init();
- ao_config_init();
ao_dma_init();
ao_spi_init();
ao_ms5607_init();
ao_storage_init();
ao_usb_init();
ao_exti_init();
- ao_radio_init();
+// ao_radio_init();
ao_i2c_init();
ao_hmc5883_init();
ao_mpu6000_init();
+ ao_flight_init();
+ ao_log_init();
+ ao_report_init();
+ ao_config_init();
ao_cmd_register(&ao_mm_cmds[0]);
ao_start_scheduler();
#define LEDS_AVAILABLE (AO_LED_RED | AO_LED_GREEN)
+#define HAS_GPS 1
+#define HAS_FLIGHT 1
#define HAS_ADC 1
+#define HAS_ACCEL 1
-#define AO_ADC_RING 32
+#define AO_DATA_RING 32
#define AO_ADC_NUM_SENSE 6
struct ao_adc {
/*
* Pressure sensor settings
*/
+#define HAS_MS5607 1
#define AO_MS5607_CS_GPIO stm_gpioc
#define AO_MS5607_CS 4
#define AO_MS5607_CS_MASK (1 << AO_MS5607_CS)
* mpu6000
*/
+#define HAS_MPU6000 1
#define AO_MPU6000_INT_PORT stm_gpioc
#define AO_MPU6000_INT_PIN 13
#define AO_MPU6000_I2C_INDEX STM_I2C_INDEX(1)
*/
#include <ao.h>
+#include <ao_data.h>
+#if HAS_MPU6000
+#include <ao_mpu6000.h>
+#endif
+#if HAS_MS5607
+#include <ao_ms5607.h>
+#endif
+volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING];
+volatile __data uint8_t ao_data_head;
-volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
-volatile __data uint8_t ao_adc_head;
static uint8_t ao_adc_ready;
#define AO_ADC_CR2_VAL ((0 << STM_ADC_CR2_SWSTART) | \
*/
static void ao_adc_done(int index)
{
- ao_adc_ring[ao_adc_head].tick = ao_time();
- ao_adc_head = ao_adc_ring_next(ao_adc_head);
- ao_wakeup((void *) &ao_adc_head);
+ ao_data_ring[ao_data_head].adc.tick = ao_time();
+#if HAS_MPU6000
+ ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current;
+#endif
+#if HAS_MS5607
+ ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current;
+#endif
+ ao_data_head = ao_data_ring_next(ao_data_head);
+ ao_wakeup((void *) &ao_data_head);
ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
ao_adc_ready = 1;
}
stm_adc.sr = 0;
ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1),
&stm_adc.dr,
- (void *) (&ao_adc_ring[ao_adc_head].tick + 1),
+ (void *) (&ao_data_ring[ao_data_head].tick + 1),
AO_NUM_ADC,
(0 << STM_DMA_CCR_MEM2MEM) |
(STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) |
void
ao_adc_get(__xdata struct ao_adc *packet)
{
- uint8_t i = ao_adc_ring_prev(ao_adc_head);
- memcpy(packet, (void *) &ao_adc_ring[i], sizeof (struct ao_adc));
+ uint8_t i = ao_data_ring_prev(ao_data_head);
+ memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc));
+}
+
+void
+ao_data_get(__xdata struct ao_data *packet)
+{
+ uint8_t i = ao_data_ring_prev(ao_data_head);
+ memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data));
}
static void
ao_adc_dump(void) __reentrant
{
- struct ao_adc packet;
+ struct ao_data packet;
int16_t *d;
uint8_t i;
- ao_adc_get(&packet);
+ ao_data_get(&packet);
printf("tick: %5u", packet.tick);
- d = (int16_t *) (&packet.tick + 1);
+ d = (int16_t *) (&packet.adc);
for (i = 0; i < AO_NUM_ADC; i++)
printf (" %2d: %5d", i, d[i]);
printf("\n");