2 * Copyright © 2013 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.
18 package org.altusmetrum.altoslib_3;
23 import java.util.concurrent.*;
29 static final int idle_gps = 0;
30 static final int idle_imu = 1;
31 static final int idle_mag = 2;
32 static final int idle_ms5607 = 3;
33 static final int idle_mma655x = 4;
36 static final int idle_sensor_tm = 10;
37 static final int idle_sensor_metrum = 11;
38 static final int idle_sensor_mega = 12;
39 static final int idle_sensor_emini = 13;
40 static final int idle_sensor_tmini = 14;
42 public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
43 for (int idler : idlers) {
44 AltosIdle idle = null;
47 AltosGPS.update_state(state, link, config_data);
50 AltosIMU.update_state(state, link, config_data);
53 AltosMag.update_state(state, link, config_data);
56 AltosMs5607.update_state(state, link, config_data);
59 AltosMma655x.update_state(state, link, config_data);
62 AltosSensorTM.update_state(state, link, config_data);
64 case idle_sensor_metrum:
65 AltosSensorMetrum.update_state(state, link, config_data);
67 case idle_sensor_mega:
68 AltosSensorMega.update_state(state, link, config_data);
70 case idle_sensor_emini:
71 AltosSensorEMini.update_state(state, link, config_data);
73 case idle_sensor_tmini:
74 AltosSensorTMini.update_state(state, link, config_data);
77 idle.update_state(state);
81 public boolean matches(AltosConfigData config_data) {
82 return config_data.product.startsWith(prefix);
85 public AltosIdler(String prefix, int ... idlers) {
92 public class AltosIdleFetch implements AltosStateUpdate {
94 static final AltosIdler[] idlers = {
96 new AltosIdler("EasyMini",
97 AltosIdler.idle_ms5607,
98 AltosIdler.idle_sensor_emini),
100 new AltosIdler("TeleMini-v1",
101 AltosIdler.idle_sensor_tm),
103 new AltosIdler("TeleMini-v2",
104 AltosIdler.idle_ms5607,
105 AltosIdler.idle_sensor_tmini),
107 new AltosIdler("TeleMetrum-v1",
109 AltosIdler.idle_sensor_tm),
111 new AltosIdler("TeleMetrum-v2",
113 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
114 AltosIdler.idle_sensor_metrum),
116 new AltosIdler("TeleMega",
118 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
119 AltosIdler.idle_imu, AltosIdler.idle_mag,
120 AltosIdler.idle_sensor_mega),
128 public void update_state(AltosState state) throws InterruptedException {
130 AltosConfigData config_data = new AltosConfigData(link);
131 state.set_state(AltosLib.ao_flight_startup);
132 state.set_serial(config_data.serial);
133 state.set_callsign(config_data.callsign);
134 state.set_ground_accel(config_data.accel_cal_plus);
135 state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
136 for (AltosIdler idler : idlers) {
137 if (idler.matches(config_data)) {
138 idler.update_state(state, link, config_data);
142 state.set_received_time(System.currentTimeMillis());
143 } catch (TimeoutException te) {
148 public AltosIdleFetch(AltosLink link) {