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_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_tmini2 = 14;
41 static final int idle_sensor_tgps = 15;
42 static final int idle_sensor_tmini3 = 16;
44 public void provide_data(AltosDataListener listener, AltosLink link, AltosCalData cal_data) throws InterruptedException, TimeoutException, AltosUnknownProduct {
45 for (int idler : idlers) {
48 AltosGPS.provide_data(listener, link, cal_data);
51 AltosIMU.provide_data(listener, link, cal_data);
54 AltosMag.provide_data(listener, link, cal_data);
57 AltosMma655x.provide_data(listener, link, cal_data);
59 /* case idle_sensor_tm:
60 AltosSensorTM.provide_data(listener, link, cal_data);
62 case idle_sensor_metrum:
63 AltosSensorMetrum.provide_data(listener, link, cal_data);
65 case idle_sensor_mega:
66 AltosSensorMega.provide_data(listener, link, cal_data);
68 case idle_sensor_emini:
69 AltosSensorEMini.provide_data(listener, link, cal_data);
71 case idle_sensor_tmini2:
72 AltosSensorTMini2.provide_data(listener, link, cal_data);
74 case idle_sensor_tgps:
75 AltosSensorTGPS.provide_data(listener, link, cal_data);
77 case idle_sensor_tmini3:
78 AltosSensorTMini3.provide_data(listener, link, cal_data);
85 public boolean matches(AltosConfigData config_data) {
86 return config_data.product.startsWith(prefix);
89 public AltosIdler(String prefix, int ... idlers) {
96 public class AltosIdleFetch implements AltosDataProvider {
98 static final AltosIdler[] idlers = {
100 new AltosIdler("EasyMini",
101 AltosIdler.idle_sensor_emini),
103 new AltosIdler("TeleMini-v1",
104 AltosIdler.idle_sensor_tm),
106 new AltosIdler("TeleMini-v2",
107 AltosIdler.idle_sensor_tmini2),
109 new AltosIdler("TeleMini-v3",
110 AltosIdler.idle_sensor_tmini3),
112 new AltosIdler("TeleMetrum-v1",
114 AltosIdler.idle_sensor_tm),
116 new AltosIdler("TeleMetrum-v2",
118 AltosIdler.idle_mma655x,
119 AltosIdler.idle_sensor_metrum),
121 new AltosIdler("TeleMega",
123 AltosIdler.idle_mma655x,
124 AltosIdler.idle_imu, AltosIdler.idle_mag,
125 AltosIdler.idle_sensor_mega),
126 new AltosIdler("EasyMega",
127 AltosIdler.idle_mma655x,
128 AltosIdler.idle_imu, AltosIdler.idle_mag,
129 AltosIdler.idle_sensor_mega),
130 new AltosIdler("TeleGPS",
132 AltosIdler.idle_sensor_tgps),
137 public void provide_data(AltosDataListener listener, AltosCalData cal_data) throws InterruptedException, AltosUnknownProduct {
139 boolean matched = false;
140 /* Fetch config data from remote */
141 AltosConfigData config_data = new AltosConfigData(link);
142 listener.set_state(AltosLib.ao_flight_stateless);
143 for (AltosIdler idler : idlers) {
144 if (idler.matches(config_data)) {
145 idler.provide_data(listener, link, cal_data);
151 throw new AltosUnknownProduct(config_data.product);
152 listener.set_received_time(System.currentTimeMillis());
153 } catch (TimeoutException te) {
158 public AltosIdleFetch(AltosLink link) {