1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/*
* Copyright © 2013 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
package org.altusmetrum.altoslib_14;
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.concurrent.*;
class AltosIdler {
String prefix;
int[] idlers;
static final int idle_gps = 0;
static final int idle_imu_tm_v1_v2 = 1;
static final int idle_imu_tm_v3 = 2;
static final int idle_imu_tm_v4 = 3;
static final int idle_imu_em_v1 = 4;
static final int idle_imu_em_v2 = 5;
static final int idle_imu_et_v1 = 6;
static final int idle_mag = 7;
static final int idle_mma655x = 8;
static final int idle_ms5607 = 9;
static final int idle_adxl375 = 10;
static final int idle_adxl375_easymotor_v2 = 11;
static final int idle_imu = 12;
static final int idle_imu_et_v2 = 13;
static final int idle_imu_em_v3 = 14;
static final int idle_sensor_tm = 100;
static final int idle_sensor_metrum = 101;
static final int idle_sensor_mega = 102;
static final int idle_sensor_emini1 = 103;
static final int idle_sensor_emini2 = 104;
static final int idle_sensor_tmini2 = 105;
static final int idle_sensor_tgps1 = 106;
static final int idle_sensor_tgps2 = 107;
static final int idle_sensor_tgps3 = 108;
static final int idle_sensor_tmini3 = 109;
static final int idle_sensor_easytimer1 = 110;
static final int idle_sensor_easymotor2 = 111;
static final int idle_sensor_emini3 = 112;
static final int idle_sensor_etimer2 = 113;
static final int idle_sensor_emega3 = 114;
static final int idle_sensor_tgps4 = 115;
public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException, TimeoutException, AltosUnknownProduct {
for (int idler : idlers) {
switch (idler) {
case idle_gps:
AltosGPS.provide_data(listener, link);
break;
case idle_imu_tm_v1_v2:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_telemega_v1_v2);
break;
case idle_imu_tm_v3:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_telemega_v3);
break;
case idle_imu_tm_v4:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_telemega_v4);
break;
case idle_imu_em_v1:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easymega_v1);
break;
case idle_imu_em_v2:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easymega_v2);
break;
case idle_imu_et_v1:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easytimer_v1);
break;
case idle_imu_et_v2:
AltosIMU.provide_data(listener, link, AltosIMU.imu_type_easytimer_v2);
break;
case idle_imu:
AltosIMU.provide_data(listener, link, AltosLib.MISSING);
break;
case idle_mag:
AltosMag.provide_data(listener, link);
break;
case idle_mma655x:
AltosMma655x.provide_data(listener, link);
break;
case idle_adxl375:
AltosAdxl375.provide_data(listener, link, false, AltosLib.MISSING);
break;
case idle_adxl375_easymotor_v2:
AltosAdxl375.provide_data(listener, link, true, AltosIMU.imu_type_easymotor_v2);
break;
case idle_ms5607:
AltosMs5607.provide_data(listener, link);
break;
case idle_sensor_tm:
AltosSensorTM.provide_data(listener, link);
break;
case idle_sensor_metrum:
AltosSensorMetrum.provide_data(listener, link);
break;
case idle_sensor_mega:
AltosSensorMega.provide_data(listener, link);
break;
case idle_sensor_emini1:
AltosSensorEMini.provide_data(listener, link, 1);
break;
case idle_sensor_emini2:
AltosSensorEMini.provide_data(listener, link, 2);
break;
case idle_sensor_emini3:
AltosSensorEMini.provide_data(listener, link, 3);
break;
case idle_sensor_tmini2:
AltosSensorTMini2.provide_data(listener, link);
break;
case idle_sensor_tgps1:
AltosSensorTGPS1.provide_data(listener, link);
break;
case idle_sensor_tgps2:
AltosSensorTGPS2.provide_data(listener, link);
break;
case idle_sensor_tgps3:
AltosSensorTGPS3.provide_data(listener, link);
break;
case idle_sensor_tgps4:
AltosSensorTGPS4.provide_data(listener, link);
break;
case idle_sensor_tmini3:
AltosSensorTMini3.provide_data(listener, link);
break;
case idle_sensor_easytimer1:
AltosSensorEasyTimer1.provide_data(listener, link);
break;
case idle_sensor_easymotor2:
AltosSensorEasyMotor2.provide_data(listener, link);
break;
}
}
}
public boolean matches(AltosConfigData config_data) {
return config_data.product.startsWith(prefix);
}
public AltosIdler(String prefix, int ... idlers) {
this.prefix = prefix;
this.idlers = idlers;
}
}
public class AltosIdleFetch implements AltosDataProvider {
static final AltosIdler[] idlers = {
new AltosIdler("EasyMini-v1",
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_emini1),
new AltosIdler("EasyMini-v2",
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_emini2),
new AltosIdler("EasyMini-v3",
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_emini3),
new AltosIdler("TeleMini-v1",
AltosIdler.idle_sensor_tm),
new AltosIdler("TeleMini-v2",
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_tmini2),
new AltosIdler("TeleMini-v3",
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_tmini3),
new AltosIdler("TeleMetrum-v1",
AltosIdler.idle_gps,
AltosIdler.idle_sensor_tm),
new AltosIdler("TeleMetrum-v2",
AltosIdler.idle_gps,
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_metrum),
new AltosIdler("TeleMetrum-v3",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_metrum),
new AltosIdler("TeleMetrum-v4",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_sensor_metrum),
new AltosIdler("TeleMega-v0",
AltosIdler.idle_gps,
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_tm_v1_v2, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v1",
AltosIdler.idle_gps,
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_tm_v1_v2, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v2",
AltosIdler.idle_gps,
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_tm_v1_v2, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v3",
AltosIdler.idle_gps,
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_tm_v3,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v4",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_tm_v4,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v5",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v6",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleMega-v7",
AltosIdler.idle_gps,
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("EasyMega-v1",
AltosIdler.idle_mma655x,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_em_v1, AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("EasyMega-v2",
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu_em_v2,
AltosIdler.idle_sensor_mega),
new AltosIdler("EasyMega-v3",
AltosIdler.idle_adxl375,
AltosIdler.idle_ms5607,
AltosIdler.idle_imu,
AltosIdler.idle_mag,
AltosIdler.idle_sensor_mega),
new AltosIdler("TeleGPS-v1",
AltosIdler.idle_gps,
AltosIdler.idle_sensor_tgps1),
new AltosIdler("TeleGPS-v2",
AltosIdler.idle_gps,
AltosIdler.idle_sensor_tgps2),
new AltosIdler("TeleGPS-v3",
AltosIdler.idle_gps,
AltosIdler.idle_sensor_tgps3),
new AltosIdler("TeleGPS-v4",
AltosIdler.idle_gps,
AltosIdler.idle_sensor_tgps4),
new AltosIdler("EasyTimer-v1",
AltosIdler.idle_imu_et_v1,
AltosIdler.idle_sensor_easytimer1),
new AltosIdler("EasyMotor-v2",
AltosIdler.idle_adxl375_easymotor_v2,
AltosIdler.idle_sensor_easymotor2),
new AltosIdler("EasyTimer-v2",
AltosIdler.idle_imu_et_v2,
AltosIdler.idle_sensor_easymotor2),
};
AltosLink link;
public void provide_data(AltosDataListener listener) throws InterruptedException, AltosUnknownProduct {
try {
boolean matched = false;
/* Fetch config data from remote */
AltosConfigData config_data = link.config_data();
listener.set_state(AltosLib.ao_flight_stateless);
for (AltosIdler idler : idlers) {
if (idler.matches(config_data)) {
idler.provide_data(listener, link);
matched = true;
break;
}
}
if (!matched)
throw new AltosUnknownProduct(config_data.product);
listener.set_received_time(System.currentTimeMillis());
} catch (TimeoutException te) {
}
}
public AltosIdleFetch(AltosLink link) {
this.link = link;
}
}
|