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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_2;
23 import java.util.concurrent.*;
29 static final int idle_gps = 0;
30 static final int idle_imu = 1;
31 static final int idle_mag = 2;
32 static final int idle_ms5607 = 3;
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;
41 public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
42 for (int idler : idlers) {
43 AltosIdle idle = null;
46 AltosGPS.update_state(state, link, config_data);
49 AltosIMU.update_state(state, link, config_data);
52 AltosMag.update_state(state, link, config_data);
55 AltosMs5607.update_state(state, link, config_data);
58 AltosMma655x.update_state(state, link, config_data);
61 AltosSensorTM.update_state(state, link, config_data);
63 case idle_sensor_metrum:
64 AltosSensorMetrum.update_state(state, link, config_data);
66 case idle_sensor_mega:
67 AltosSensorMega.update_state(state, link, config_data);
69 case idle_sensor_emini:
70 AltosSensorEMini.update_state(state, link, config_data);
74 idle.update_state(state);
78 public boolean matches(AltosConfigData config_data) {
79 return config_data.product.startsWith(prefix);
82 public AltosIdler(String prefix, int ... idlers) {
89 public class AltosIdleFetch implements AltosStateUpdate {
91 static final AltosIdler[] idlers = {
93 new AltosIdler("EasyMini",
94 AltosIdler.idle_ms5607,
95 AltosIdler.idle_sensor_emini),
97 new AltosIdler("TeleMini-v1",
98 AltosIdler.idle_sensor_tm),
100 new AltosIdler("TeleMini-v2",
101 AltosIdler.idle_ms5607,
102 AltosIdler.idle_sensor_tm),
104 new AltosIdler("TeleMetrum-v1",
106 AltosIdler.idle_sensor_tm),
108 new AltosIdler("TeleMetrum-v2",
110 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
111 AltosIdler.idle_sensor_metrum),
113 new AltosIdler("TeleMega",
115 AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
116 AltosIdler.idle_imu, AltosIdler.idle_mag,
117 AltosIdler.idle_sensor_mega),
125 public void update_state(AltosState state) {
127 AltosConfigData config_data = new AltosConfigData(link);
128 state.set_state(AltosLib.ao_flight_startup);
129 state.set_serial(config_data.serial);
130 state.set_callsign(config_data.callsign);
131 state.set_ground_accel(config_data.accel_cal_plus);
132 state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
133 for (AltosIdler idler : idlers) {
134 if (idler.matches(config_data)) {
135 idler.update_state(state, link, config_data);
139 state.set_received_time(System.currentTimeMillis());
140 } catch (InterruptedException ie) {
141 } catch (TimeoutException te) {
146 public AltosIdleFetch(AltosLink link) {