2 * Copyright © 2012 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;
20 import java.util.concurrent.*;
31 public AltosADCTM(AltosLink link) throws InterruptedException, TimeoutException {
34 String line = link.get_reply_no_dialog(5000);
36 throw new TimeoutException();
38 if (!line.startsWith("tick:"))
40 String[] items = line.split("\\s+");
41 for (int i = 0; i < items.length;) {
42 if (items[i].equals("tick:")) {
43 tick = Integer.parseInt(items[i+1]);
47 if (items[i].equals("accel:")) {
48 accel = Integer.parseInt(items[i+1]);
52 if (items[i].equals("pres:")) {
53 pres = Integer.parseInt(items[i+1]);
57 if (items[i].equals("temp:")) {
58 temp = Integer.parseInt(items[i+1]);
62 if (items[i].equals("batt:")) {
63 batt = Integer.parseInt(items[i+1]);
67 if (items[i].equals("drogue:")) {
68 drogue = Integer.parseInt(items[i+1]);
72 if (items[i].equals("main:")) {
73 main = Integer.parseInt(items[i+1]);
84 class AltosGPSQuery extends AltosGPS {
85 public AltosGPSQuery (AltosLink link, AltosConfigData config_data)
86 throws TimeoutException, InterruptedException {
87 boolean says_done = config_data.compare_version("1.0") >= 0;
90 String line = link.get_reply_no_dialog(5000);
92 throw new TimeoutException();
93 String[] bits = line.split("\\s+");
96 if (line.startsWith("Date:")) {
99 String[] d = bits[1].split(":");
102 year = Integer.parseInt(d[0]) + 2000;
103 month = Integer.parseInt(d[1]);
104 day = Integer.parseInt(d[2]);
107 if (line.startsWith("Time:")) {
110 String[] d = bits[1].split("/");
113 hour = Integer.parseInt(d[0]);
114 minute = Integer.parseInt(d[1]);
115 second = Integer.parseInt(d[2]);
118 if (line.startsWith("Lat/Lon:")) {
121 lat = Integer.parseInt(bits[1]) * 1.0e-7;
122 lon = Integer.parseInt(bits[2]) * 1.0e-7;
125 if (line.startsWith("Alt:")) {
128 alt = Integer.parseInt(bits[1]);
131 if (line.startsWith("Flags:")) {
134 int status = Integer.decode(bits[1]);
135 connected = (status & AltosLib.AO_GPS_RUNNING) != 0;
136 locked = (status & AltosLib.AO_GPS_VALID) != 0;
141 if (line.startsWith("Sats:")) {
144 nsat = Integer.parseInt(bits[1]);
145 cc_gps_sat = new AltosGPSSat[nsat];
146 for (int i = 0; i < nsat; i++) {
147 int svid = Integer.parseInt(bits[2+i*2]);
148 int cc_n0 = Integer.parseInt(bits[3+i*2]);
149 cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0);
152 if (line.startsWith("done"))
154 if (line.startsWith("Syntax error"))