2 * Copyright © 2009 Keith Packard <keithp@keithp.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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 #define AO_ADC_RING 64
28 #define ao_adc_ring_next(n) (((n) + 1) & (AO_ADC_RING - 1))
29 #define ao_adc_ring_prev(n) (((n) - 1) & (AO_ADC_RING - 1))
32 * One set of samples read from the A/D converter
35 uint16_t tick; /* tick when the sample was read */
36 int16_t accel; /* accelerometer */
37 int16_t pres; /* pressure sensor */
38 int16_t temp; /* temperature sensor */
39 int16_t v_batt; /* battery voltage */
40 int16_t sense_d; /* drogue continuity sense */
41 int16_t sense_m; /* main continuity sense */
50 enum ao_flight_state {
51 ao_flight_startup = 0,
63 struct ao_adc ao_adc_ring[AO_ADC_RING];
68 #define ao_timer_set_adc_interval(i)
69 #define ao_wakeup(wchan) ao_dump_state()
70 #define ao_cmd_register(c)
71 #define ao_usb_disable()
72 #define ao_telemetry_set_interval(x)
73 #define ao_rdf_set(rdf)
74 #define ao_packet_slave_start()
77 ao_igniter_drogue = 0,
82 ao_ignite(enum ao_igniter igniter)
84 printf ("ignite %s\n", igniter == ao_igniter_drogue ? "drogue" : "main");
91 #define ao_add_task(t,f,n)
93 #define ao_log_start()
96 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
97 #define AO_SEC_TO_TICKS(s) ((s) * 100)
99 #define AO_FLIGHT_TEST
101 struct ao_adc ao_adc_static;
109 ao_sleep(void *wchan);
111 const char const * const ao_state_names[] = {
112 "startup", "idle", "pad", "boost", "fast",
113 "coast", "drogue", "main", "landed", "invalid"
121 #include "ao_convert.c"
124 uint16_t main_deploy;
125 int16_t accel_plus_g;
126 int16_t accel_minus_g;
129 #define ao_config_get()
131 struct ao_config ao_config;
133 #define DATA_TO_XDATA(x) (x)
142 #define HAS_ACCEL_REF 0
144 #include "ao_flight.c"
149 ao_adc_ring[ao_adc_head] = ao_adc_static;
150 ao_adc_head = ao_adc_ring_next(ao_adc_head);
151 if (ao_flight_state != ao_flight_startup) {
152 printf("time %g accel %d pres %d\n",
153 (double) ao_adc_static.tick / 100,
159 static int ao_records_read = 0;
160 static int ao_eof_read = 0;
161 static int ao_flight_ground_accel;
162 static int ao_flight_started = 0;
165 ao_sleep(void *wchan)
168 if (wchan == &ao_adc_head) {
180 if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)
182 ao_adc_static.accel = ao_flight_ground_accel;
187 if (!fgets(line, sizeof (line), emulator_in)) {
188 if (++ao_eof_read >= 1000) {
189 printf ("no more data, exiting simulation\n");
192 ao_adc_static.tick += 10;
197 for (nword = 0; nword < 64; nword++) {
198 words[nword] = strtok_r(l, " \t\n", &saveptr);
200 if (words[nword] == NULL)
205 tick = strtoul(words[1], NULL, 16);
206 a = strtoul(words[2], NULL, 16);
207 b = strtoul(words[3], NULL, 16);
208 } else if (nword >= 6 && strcmp(words[0], "Accel")) {
209 ao_config.accel_plus_g = atoi(words[3]);
210 ao_config.accel_minus_g = atoi(words[5]);
211 } else if (nword >= 4 && strcmp(words[0], "Main")) {
212 ao_config.main_deploy = atoi(words[2]);
213 } else if (nword >= 36 && strcmp(words[0], "CALL") == 0) {
214 tick = atoi(words[10]);
215 if (!ao_flight_started) {
218 ao_flight_started = 1;
225 if (type != 'F' && !ao_flight_started)
230 ao_flight_ground_accel = a;
231 if (ao_config.accel_plus_g == 0) {
232 ao_config.accel_plus_g = a;
233 ao_config.accel_minus_g = a + 530;
235 if (ao_config.main_deploy == 0)
236 ao_config.main_deploy = 250;
237 ao_flight_started = 1;
242 ao_adc_static.tick = tick;
243 ao_adc_static.accel = a;
244 ao_adc_static.pres = b;
249 ao_adc_static.tick = tick;
250 ao_adc_static.temp = a;
251 ao_adc_static.v_batt = b;
264 #define COUNTS_PER_G 264.8
269 if (ao_flight_state == ao_flight_startup)
271 printf ("\t\t\t\t\t%s accel %g vel %g alt %d main %d\n",
272 ao_state_names[ao_flight_state],
273 (ao_ground_accel - ao_flight_accel) / COUNTS_PER_G * GRAVITY,
274 (double) ao_flight_vel / 100 / COUNTS_PER_G * GRAVITY,
275 ao_pres_to_altitude(ao_flight_pres) - ao_pres_to_altitude(ao_ground_pres),
276 ao_pres_to_altitude(ao_main_pres) - ao_pres_to_altitude(ao_ground_pres));
277 if (ao_flight_state == ao_flight_landed)
282 main (int argc, char **argv)
284 emulator_in = fopen (argv[1], "r");