]> git.gag.com Git - fw/altos/blob - src/drivers/ao_science_slave.c
Add altoslib/.gitignore
[fw/altos] / src / drivers / ao_science_slave.c
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #include "ao.h"
19 #include "ao_product.h"
20 #include "ao_flight.h"
21 #include "ao_companion.h"
22
23 struct ao_companion_command     ao_companion_command;
24
25 static const struct ao_companion_setup  ao_telescience_setup = {
26         .board_id               = AO_idProduct_NUMBER,
27         .board_id_inverse       = ~AO_idProduct_NUMBER,
28         .update_period          = 50,
29         .channels               = AO_LOG_TELESCIENCE_NUM_ADC,
30 };
31
32 void ao_spi_slave(void)
33 {
34         if (!ao_spi_slave_recv((uint8_t *) &ao_companion_command,
35                                sizeof (ao_companion_command)))
36                 return;
37
38         /* Figure out the outbound data */
39         switch (ao_companion_command.command) {
40         case AO_COMPANION_SETUP:
41                 ao_spi_slave_send((uint8_t *) &ao_telescience_setup,
42                                   sizeof (ao_telescience_setup));
43                 break;
44         case AO_COMPANION_FETCH:
45                 ao_spi_slave_send((uint8_t *) &ao_data_ring[ao_data_ring_prev(ao_data_head)].adc,
46                                   AO_LOG_TELESCIENCE_NUM_ADC * sizeof (uint16_t));
47                 break;
48         case AO_COMPANION_NOTIFY:
49                 break;
50         default:
51                 return;
52         }
53
54 #if HAS_LOG
55         ao_log_single_write_data.telescience.tm_tick = ao_companion_command.tick;
56         if (ao_log_single_write_data.telescience.tm_state != ao_companion_command.flight_state) {
57                 ao_log_single_write_data.telescience.tm_state = ao_companion_command.flight_state;
58                 if (ao_flight_boost <= ao_log_single_write_data.telescience.tm_state) {
59                         if (ao_log_single_write_data.telescience.tm_state < ao_flight_landed)
60                                 ao_log_single_start();
61                         else
62                                 ao_log_single_stop();
63                 }
64         }
65 #endif
66 }