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_13;
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_mma655x = 4;
34 static final int idle_ms5607 = 5;
35 static final int idle_adxl375 = 6;
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_emini1 = 13;
41 static final int idle_sensor_emini2 = 14;
42 static final int idle_sensor_tmini2 = 15;
43 static final int idle_sensor_tgps = 16;
44 static final int idle_sensor_tmini3 = 17;
46 public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, TimeoutException, AltosUnknownProduct {
47 for (int idler : idlers) {
50 AltosGPS.provide_data(listener, link);
53 AltosIMU.provide_data(listener, link);
56 AltosMag.provide_data(listener, link);
59 AltosMma655x.provide_data(listener, link);
62 AltosAdxl375.provide_data(listener, link);
65 AltosMs5607.provide_data(listener, link);
68 AltosSensorTM.provide_data(listener, link);
70 case idle_sensor_metrum:
71 AltosSensorMetrum.provide_data(listener, link);
73 case idle_sensor_mega:
74 AltosSensorMega.provide_data(listener, link);
76 case idle_sensor_emini1:
77 AltosSensorEMini.provide_data(listener, link, 1);
79 case idle_sensor_emini2:
80 AltosSensorEMini.provide_data(listener, link, 2);
82 case idle_sensor_tmini2:
83 AltosSensorTMini2.provide_data(listener, link);
85 case idle_sensor_tgps:
86 AltosSensorTGPS.provide_data(listener, link);
88 case idle_sensor_tmini3:
89 AltosSensorTMini3.provide_data(listener, link);
95 public boolean matches(AltosConfigData config_data) {
96 return config_data.product.startsWith(prefix);
99 public AltosIdler(String prefix, int ... idlers) {
100 this.prefix = prefix;
101 this.idlers = idlers;
106 public class AltosIdleFetch implements AltosDataProvider {
108 static final AltosIdler[] idlers = {
110 new AltosIdler("EasyMini-v1",
111 AltosIdler.idle_ms5607,
112 AltosIdler.idle_sensor_emini1),
114 new AltosIdler("EasyMini-v2",
115 AltosIdler.idle_ms5607,
116 AltosIdler.idle_sensor_emini2),
118 new AltosIdler("TeleMini-v1",
119 AltosIdler.idle_sensor_tm),
121 new AltosIdler("TeleMini-v2",
122 AltosIdler.idle_ms5607,
123 AltosIdler.idle_sensor_tmini2),
125 new AltosIdler("TeleMini-v3",
126 AltosIdler.idle_ms5607,
127 AltosIdler.idle_sensor_tmini3),
129 new AltosIdler("TeleMetrum-v1",
131 AltosIdler.idle_sensor_tm),
133 new AltosIdler("TeleMetrum-v2",
135 AltosIdler.idle_mma655x,
136 AltosIdler.idle_ms5607,
137 AltosIdler.idle_sensor_metrum),
139 new AltosIdler("TeleMega-v0",
141 AltosIdler.idle_mma655x,
142 AltosIdler.idle_ms5607,
143 AltosIdler.idle_imu, AltosIdler.idle_mag,
144 AltosIdler.idle_sensor_mega),
145 new AltosIdler("TeleMega-v1",
147 AltosIdler.idle_mma655x,
148 AltosIdler.idle_ms5607,
149 AltosIdler.idle_imu, AltosIdler.idle_mag,
150 AltosIdler.idle_sensor_mega),
151 new AltosIdler("TeleMega-v2",
153 AltosIdler.idle_mma655x,
154 AltosIdler.idle_ms5607,
155 AltosIdler.idle_imu, AltosIdler.idle_mag,
156 AltosIdler.idle_sensor_mega),
157 new AltosIdler("TeleMega-v3",
159 AltosIdler.idle_mma655x,
160 AltosIdler.idle_ms5607,
162 AltosIdler.idle_sensor_mega),
163 new AltosIdler("EasyMega-v1",
164 AltosIdler.idle_mma655x,
165 AltosIdler.idle_ms5607,
166 AltosIdler.idle_imu, AltosIdler.idle_mag,
167 AltosIdler.idle_sensor_mega),
168 new AltosIdler("EasyMega-v2",
169 AltosIdler.idle_adxl375,
170 AltosIdler.idle_ms5607,
172 AltosIdler.idle_sensor_mega),
173 new AltosIdler("TeleGPS",
175 AltosIdler.idle_sensor_tgps),
180 public void provide_data(AltosDataListener listener) throws InterruptedException, AltosUnknownProduct {
182 boolean matched = false;
183 /* Fetch config data from remote */
184 AltosConfigData config_data = new AltosConfigData(link);
185 listener.set_state(AltosLib.ao_flight_stateless);
186 for (AltosIdler idler : idlers) {
187 if (idler.matches(config_data)) {
188 idler.provide_data(listener, link);
194 throw new AltosUnknownProduct(config_data.product);
195 listener.set_received_time(System.currentTimeMillis());
196 } catch (TimeoutException te) {
201 public AltosIdleFetch(AltosLink link) {