2 * Copyright © 2017 Bdale Garbee <bdale@gag.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #include <ao_flight.h>
24 static struct ao_log_telestatic log_data;
26 const uint8_t ao_log_format = AO_LOG_FORMAT_TELESTATIC;
29 ao_log_csum(uint8_t *b)
34 for (i = 0; i < sizeof (struct ao_log_telestatic); i++)
40 ao_log_telestatic(void)
45 log_data.csum = ao_log_csum((uint8_t *) &log_data);
46 ao_mutex_get(&ao_log_mutex); {
47 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
51 ao_storage_write(ao_log_current_pos,
53 sizeof (struct ao_log_telestatic));
54 ao_log_current_pos += sizeof (struct ao_log_telestatic);
56 } ao_mutex_put(&ao_log_mutex);
61 static uint8_t ao_log_data_pos;
63 /* a hack to make sure that ao_log_metrums fill the eeprom block in even units */
64 typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_telestatic))] ;
75 while (!ao_log_running)
76 ao_sleep(&ao_log_running);
78 log_data.type = AO_LOG_FLIGHT;
79 log_data.tick = ao_time();
80 log_data.u.flight.flight = ao_flight_number;
83 /* Write the whole contents of the ring to the log
86 ao_log_data_pos = ao_data_ring_next(ao_data_head);
88 /* Write samples to EEPROM */
89 while (ao_log_data_pos != ao_data_head) {
90 log_data.tick = ao_data_ring[ao_log_data_pos].tick;
91 log_data.type = AO_LOG_SENSOR;
93 log_data.u.sensor.pressure = ao_data_ring[ao_log_data_pos].ads131a0x.ain[0];
94 log_data.u.sensor.pressure2 = ao_data_ring[ao_log_data_pos].ads131a0x.ain[1];
95 log_data.u.sensor.thrust = ao_data_ring[ao_log_data_pos].ads131a0x.ain[2];
96 log_data.u.sensor.mass = ao_data_ring[ao_log_data_pos].ads131a0x.ain[3];
98 log_data.u.sensor.t_low = ao_data_ring[ao_log_data_pos].max6691.sensor[0].t_low;
100 for (i = 0; i < 4; i++)
101 log_data.u.sensor.t_high[i] = ao_data_ring[ao_log_data_pos].max6691.sensor[i].t_high;
103 ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
108 if (!ao_log_running) break;
110 /* Wait for a while */
111 ao_delay(AO_MS_TO_TICKS(100));
113 } while (ao_log_running);