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_10;
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;
41 static final int idle_sensor_tgps = 15;
43 public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
44 for (int idler : idlers) {
45 AltosIdle idle = null;
48 AltosGPS.update_state(state, link, config_data);
51 AltosIMU.update_state(state, link, config_data);
54 AltosMag.update_state(state, link, config_data);
57 AltosMs5607.update_state(state, link, config_data);
60 AltosMma655x.update_state(state, link, config_data);
63 AltosSensorTM.update_state(state, link, config_data);
65 case idle_sensor_metrum:
66 AltosSensorMetrum.update_state(state, link, config_data);
68 case idle_sensor_mega:
69 AltosSensorMega.update_state(state, link, config_data);
71 case idle_sensor_emini:
72 AltosSensorEMini.update_state(state, link, config_data);
74 case idle_sensor_tmini:
75 AltosSensorTMini.update_state(state, link, config_data);
77 case idle_sensor_tgps:
78 AltosSensorTGPS.update_state(state, link, config_data);
82 idle.update_state(state);
86 public boolean matches(AltosConfigData config_data) {
87 return config_data.product.startsWith(prefix);
90 public AltosIdler(String prefix, int ... idlers) {
97 public class AltosIdleFetch implements AltosStateUpdate {
99 static final AltosIdler[] idlers = {
101 new AltosIdler("EasyMini",
102 AltosIdler.idle_ms5607,
103 AltosIdler.idle_sensor_emini),
105 new AltosIdler("TeleMini-v1",
106 AltosIdler.idle_sensor_tm),
108 new AltosIdler("TeleMini-v2",
109 AltosIdler.idle_ms5607,
110 AltosIdler.idle_sensor_tmini),
112 new AltosIdler("TeleMetrum-v1",
114 AltosIdler.idle_sensor_tm),
116 new AltosIdler("TeleMetrum-v2",
118 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
119 AltosIdler.idle_sensor_metrum),
121 new AltosIdler("TeleMega",
123 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
124 AltosIdler.idle_imu, AltosIdler.idle_mag,
125 AltosIdler.idle_sensor_mega),
126 new AltosIdler("EasyMega",
127 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
128 AltosIdler.idle_imu, AltosIdler.idle_mag,
129 AltosIdler.idle_sensor_mega),
130 new AltosIdler("TeleGPS",
132 AltosIdler.idle_sensor_tgps),
140 public void update_state(AltosState state) throws InterruptedException {
142 /* Fetch config data from remote */
143 AltosConfigData config_data = new AltosConfigData(link);
144 state.set_state(AltosLib.ao_flight_stateless);
145 state.set_serial(config_data.serial);
146 state.set_callsign(config_data.callsign);
147 state.set_ground_accel(config_data.accel_cal_plus);
148 state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
149 state.set_product(config_data.product);
150 for (AltosIdler idler : idlers) {
151 if (idler.matches(config_data)) {
152 idler.update_state(state, link, config_data);
156 state.set_received_time(System.currentTimeMillis());
157 } catch (TimeoutException te) {
162 public AltosIdleFetch(AltosLink link) {