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_3;
20 import java.util.concurrent.TimeoutException;
22 class AltosSensorMega {
29 public AltosSensorMega() {
33 public AltosSensorMega(AltosLink link) throws InterruptedException, TimeoutException {
35 String[] items = link.adc();
36 for (int i = 0; i < items.length;) {
37 if (items[i].equals("tick:")) {
38 tick = Integer.parseInt(items[i+1]);
42 if (items[i].equals("A:")) {
43 sense[0] = Integer.parseInt(items[i+1]);
47 if (items[i].equals("B:")) {
48 sense[1] = Integer.parseInt(items[i+1]);
52 if (items[i].equals("C:")) {
53 sense[2] = Integer.parseInt(items[i+1]);
57 if (items[i].equals("D:")) {
58 sense[3] = Integer.parseInt(items[i+1]);
62 if (items[i].equals("drogue:")) {
63 sense[4] = Integer.parseInt(items[i+1]);
67 if (items[i].equals("main:")) {
68 sense[5] = Integer.parseInt(items[i+1]);
72 if (items[i].equals("batt:")) {
73 v_batt = Integer.parseInt(items[i+1]);
77 if (items[i].equals("pbatt:")) {
78 v_pbatt = Integer.parseInt(items[i+1]);
82 if (items[i].equals("temp:")) {
83 temp = Integer.parseInt(items[i+1]);
91 static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
93 AltosSensorMega sensor_mega = new AltosSensorMega(link);
95 state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_mega.v_batt));
96 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[4]));
97 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[5]));
99 double[] ignitor_voltage = new double[4];
100 for (int i = 0; i < 4; i++)
101 ignitor_voltage[i] = AltosConvert.mega_pyro_voltage(sensor_mega.sense[i]);
102 state.set_ignitor_voltage(ignitor_voltage);
104 } catch (TimeoutException te) {