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; 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.
19 package org.altusmetrum.altoslib_11;
24 import java.util.concurrent.*;
30 static final int idle_gps = 0;
31 static final int idle_imu = 1;
32 static final int idle_mag = 2;
33 static final int idle_ms5607 = 3;
34 static final int idle_mma655x = 4;
37 static final int idle_sensor_tm = 10;
38 static final int idle_sensor_metrum = 11;
39 static final int idle_sensor_mega = 12;
40 static final int idle_sensor_emini = 13;
41 static final int idle_sensor_tmini = 14;
42 static final int idle_sensor_tgps = 15;
44 public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException, AltosUnknownProduct {
45 for (int idler : idlers) {
46 AltosIdle idle = null;
49 AltosGPS.update_state(state, link, config_data);
52 AltosIMU.update_state(state, link, config_data);
55 AltosMag.update_state(state, link, config_data);
58 AltosMs5607.update_state(state, link, config_data);
61 AltosMma655x.update_state(state, link, config_data);
64 AltosSensorTM.update_state(state, link, config_data);
66 case idle_sensor_metrum:
67 AltosSensorMetrum.update_state(state, link, config_data);
69 case idle_sensor_mega:
70 AltosSensorMega.update_state(state, link, config_data);
72 case idle_sensor_emini:
73 AltosSensorEMini.update_state(state, link, config_data);
75 case idle_sensor_tmini:
76 AltosSensorTMini.update_state(state, link, config_data);
78 case idle_sensor_tgps:
79 AltosSensorTGPS.update_state(state, link, config_data);
83 idle.update_state(state);
87 public boolean matches(AltosConfigData config_data) {
88 return config_data.product.startsWith(prefix);
91 public AltosIdler(String prefix, int ... idlers) {
98 public class AltosIdleFetch implements AltosStateUpdate {
100 static final AltosIdler[] idlers = {
102 new AltosIdler("EasyMini",
103 AltosIdler.idle_ms5607,
104 AltosIdler.idle_sensor_emini),
106 new AltosIdler("TeleMini-v1",
107 AltosIdler.idle_sensor_tm),
109 new AltosIdler("TeleMini-v2",
110 AltosIdler.idle_ms5607,
111 AltosIdler.idle_sensor_tmini),
113 new AltosIdler("TeleMetrum-v1",
115 AltosIdler.idle_sensor_tm),
117 new AltosIdler("TeleMetrum-v2",
119 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
120 AltosIdler.idle_sensor_metrum),
122 new AltosIdler("TeleMega",
124 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
125 AltosIdler.idle_imu, AltosIdler.idle_mag,
126 AltosIdler.idle_sensor_mega),
127 new AltosIdler("EasyMega",
128 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
129 AltosIdler.idle_imu, AltosIdler.idle_mag,
130 AltosIdler.idle_sensor_mega),
131 new AltosIdler("TeleGPS",
133 AltosIdler.idle_sensor_tgps),
138 public void update_state(AltosState state) throws InterruptedException, AltosUnknownProduct {
140 boolean matched = false;
141 /* Fetch config data from remote */
142 AltosConfigData config_data = new AltosConfigData(link);
143 state.set_state(AltosLib.ao_flight_stateless);
144 state.set_serial(config_data.serial);
145 state.set_callsign(config_data.callsign);
146 state.set_ground_accel(config_data.accel_cal_plus);
147 state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
148 state.set_product(config_data.product);
149 state.set_firmware_version(config_data.version);
150 state.set_log_space(config_data.log_space);
151 for (AltosIdler idler : idlers) {
152 if (idler.matches(config_data)) {
153 idler.update_state(state, link, config_data);
159 throw new AltosUnknownProduct(config_data.product);
160 state.set_received_time(System.currentTimeMillis());
161 } catch (TimeoutException te) {
166 public AltosIdleFetch(AltosLink link) {