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_tmini2 = 14;
42 static final int idle_sensor_tgps = 15;
43 static final int idle_sensor_tmini3 = 16;
45 public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException, AltosUnknownProduct {
46 for (int idler : idlers) {
47 AltosIdle idle = null;
50 AltosGPS.update_state(state, link, config_data);
53 AltosIMU.update_state(state, link, config_data);
56 AltosMag.update_state(state, link, config_data);
59 AltosMs5607.update_state(state, link, config_data);
62 AltosMma655x.update_state(state, link, config_data);
65 AltosSensorTM.update_state(state, link, config_data);
67 case idle_sensor_metrum:
68 AltosSensorMetrum.update_state(state, link, config_data);
70 case idle_sensor_mega:
71 AltosSensorMega.update_state(state, link, config_data);
73 case idle_sensor_emini:
74 AltosSensorEMini.update_state(state, link, config_data);
76 case idle_sensor_tmini2:
77 AltosSensorTMini2.update_state(state, link, config_data);
79 case idle_sensor_tgps:
80 AltosSensorTGPS.update_state(state, link, config_data);
82 case idle_sensor_tmini3:
83 AltosSensorTMini3.update_state(state, link, config_data);
87 idle.update_state(state);
91 public boolean matches(AltosConfigData config_data) {
92 return config_data.product.startsWith(prefix);
95 public AltosIdler(String prefix, int ... idlers) {
102 public class AltosIdleFetch implements AltosStateUpdate {
104 static final AltosIdler[] idlers = {
106 new AltosIdler("EasyMini",
107 AltosIdler.idle_ms5607,
108 AltosIdler.idle_sensor_emini),
110 new AltosIdler("TeleMini-v1",
111 AltosIdler.idle_sensor_tm),
113 new AltosIdler("TeleMini-v2",
114 AltosIdler.idle_ms5607,
115 AltosIdler.idle_sensor_tmini2),
117 new AltosIdler("TeleMini-v3",
118 AltosIdler.idle_ms5607,
119 AltosIdler.idle_sensor_tmini3),
121 new AltosIdler("TeleMetrum-v1",
123 AltosIdler.idle_sensor_tm),
125 new AltosIdler("TeleMetrum-v2",
127 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
128 AltosIdler.idle_sensor_metrum),
130 new AltosIdler("TeleMega",
132 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
133 AltosIdler.idle_imu, AltosIdler.idle_mag,
134 AltosIdler.idle_sensor_mega),
135 new AltosIdler("EasyMega",
136 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
137 AltosIdler.idle_imu, AltosIdler.idle_mag,
138 AltosIdler.idle_sensor_mega),
139 new AltosIdler("TeleGPS",
141 AltosIdler.idle_sensor_tgps),
146 public void update_state(AltosState state) throws InterruptedException, AltosUnknownProduct {
148 boolean matched = false;
149 /* Fetch config data from remote */
150 AltosConfigData config_data = new AltosConfigData(link);
151 state.set_state(AltosLib.ao_flight_stateless);
152 state.set_serial(config_data.serial);
153 state.set_callsign(config_data.callsign);
154 state.set_ground_accel(config_data.accel_cal_plus);
155 state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
156 state.set_product(config_data.product);
157 state.set_firmware_version(config_data.version);
158 state.set_log_space(config_data.log_space);
159 for (AltosIdler idler : idlers) {
160 if (idler.matches(config_data)) {
161 idler.update_state(state, link, config_data);
167 throw new AltosUnknownProduct(config_data.product);
168 state.set_received_time(System.currentTimeMillis());
169 } catch (TimeoutException te) {
174 public AltosIdleFetch(AltosLink link) {