diff options
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/ao_log.h | 28 | ||||
-rw-r--r-- | src/kernel/ao_log_telestatic.c | 115 |
2 files changed, 143 insertions, 0 deletions
diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h index 9e8f995e..0ab57448 100644 --- a/src/kernel/ao_log.h +++ b/src/kernel/ao_log.h @@ -56,6 +56,7 @@ extern enum ao_flight_state ao_log_state; #define AO_LOG_FORMAT_EASYMINI2 14 /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */ #define AO_LOG_FORMAT_TELEMEGA_3 15 /* 32 byte typed telemega records with 32 bit gyro cal and mpu9250 */ #define AO_LOG_FORMAT_EASYMEGA_2 16 /* 32 byte typed telemega records with 32 bit gyro cal, mpu9250 rotated 90° and adxl375 */ +#define AO_LOG_FORMAT_TELESTATIC 17 /* 32 byte typed telestatic records */ #define AO_LOG_FORMAT_NONE 127 /* No log at all */ /* Return the flight number from the given log slot, 0 if none, -slot on failure */ @@ -338,6 +339,33 @@ struct ao_log_firetwo { } u; /* 32 */ }; +struct ao_log_telestatic { + char type; /* 0 */ + uint8_t csum; /* 1 */ + uint16_t tick; /* 2 */ + union { /* 4 */ + /* AO_LOG_FLIGHT */ + struct { + uint16_t flight; /* 4 */ + } flight; /* 6 */ + /* AO_LOG_STATE */ + struct { + uint16_t state; /* 4 */ + uint16_t reason; /* 6 */ + } state; /* 8 */ + /* AO_LOG_SENSOR */ + struct { + uint32_t pressure; /* 4 */ + uint32_t pressure2; /* 8 */ + uint32_t thrust; /* 12 */ + uint32_t mass; /* 16 */ + uint16_t t_low; /* 20 */ + uint16_t t_high[4]; /* 22 */ + } sensor; /* 30 */ + uint8_t align[28]; /* 4 */ + } u; /* 32 */ +}; + struct ao_log_metrum { char type; /* 0 */ uint8_t csum; /* 1 */ diff --git a/src/kernel/ao_log_telestatic.c b/src/kernel/ao_log_telestatic.c new file mode 100644 index 00000000..fdf8da43 --- /dev/null +++ b/src/kernel/ao_log_telestatic.c @@ -0,0 +1,115 @@ +/* + * Copyright © 2017 Bdale Garbee <bdale@gag.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; either version 2 of the License, or + * (at your option) any later version. + * + * 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" +#include <ao_log.h> +#include <ao_data.h> +#include <ao_flight.h> + +static struct ao_log_telestatic log; + +const uint8_t ao_log_format = AO_LOG_FORMAT_TELESTATIC; + +static uint8_t +ao_log_csum(uint8_t *b) +{ + uint8_t sum = 0x5a; + uint8_t i; + + for (i = 0; i < sizeof (struct ao_log_telestatic); i++) + sum += *b++; + return -sum; +} + +static uint8_t +ao_log_telestatic(void) +{ + uint8_t wrote = 0; + /* set checksum */ + log.csum = 0; + log.csum = ao_log_csum((uint8_t *) &log); + ao_mutex_get(&ao_log_mutex); { + if (ao_log_current_pos >= ao_log_end_pos && ao_log_running) + ao_log_stop(); + if (ao_log_running) { + wrote = 1; + ao_storage_write(ao_log_current_pos, + &log, + sizeof (struct ao_log_telestatic)); + ao_log_current_pos += sizeof (struct ao_log_telestatic); + } + } ao_mutex_put(&ao_log_mutex); + return wrote; +} + +#if HAS_ADC +static uint8_t ao_log_data_pos; + +/* a hack to make sure that ao_log_metrums fill the eeprom block in even units */ +typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_telestatic))] ; +#endif + +void +ao_log(void) +{ + ao_storage_setup(); + + do { + ao_log_scan(); + + while (!ao_log_running) + ao_sleep(&ao_log_running); + + log.type = AO_LOG_FLIGHT; + log.tick = ao_time(); + log.u.flight.flight = ao_flight_number; + ao_log_telestatic(); + + /* Write the whole contents of the ring to the log + * when starting up. + */ + ao_log_data_pos = ao_data_ring_next(ao_data_head); + for (;;) { + /* Write samples to EEPROM */ + while (ao_log_data_pos != ao_data_head) { + log.tick = ao_data_ring[ao_log_data_pos].tick; + log.type = AO_LOG_SENSOR; +#if HAS_ADS131A0X + log.u.sensor.pressure = ao_data_ring[ao_log_data_pos].ads131a0x.ain[0]; + log.u.sensor.pressure2 = ao_data_ring[ao_log_data_pos].ads131a0x.ain[1]; + log.u.sensor.thrust = ao_data_ring[ao_log_data_pos].ads131a0x.ain[2]; + log.u.sensor.mass = ao_data_ring[ao_log_data_pos].ads131a0x.ain[3]; +#endif + log.u.sensor.t_low = ao_data_ring[ao_log_data_pos].max6691.sensor[0].t_low; + int i; + for (i = 0; i < 4; i++) + log.u.sensor.t_high[i] = ao_data_ring[ao_log_data_pos].max6691.sensor[i].t_high; + ao_log_telestatic(); + ao_log_data_pos = ao_data_ring_next(ao_log_data_pos); + } + + ao_log_flush(); + + if (!ao_log_running) break; + + /* Wait for a while */ + ao_delay(AO_MS_TO_TICKS(100)); + } + } while (ao_log_running); +} + |