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; 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_13;
21 import java.util.concurrent.*;
24 public class AltosMag implements Cloneable {
29 public static final double counts_per_gauss = 1090;
31 public static double convert_gauss(double counts) {
32 return counts / counts_per_gauss;
35 public boolean parse_string(String line) {
37 if (!line.startsWith("X:"))
40 String[] items = line.split("\\s+");
42 if (items.length >= 6) {
43 x = Integer.parseInt(items[1]);
44 z = Integer.parseInt(items[3]);
45 y = Integer.parseInt(items[5]);
50 public AltosMag clone() {
51 AltosMag n = new AltosMag();
65 static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
67 AltosMag mag = new AltosMag(link);
68 AltosCalData cal_data = listener.cal_data();
71 listener.set_mag(cal_data.mag_along(mag.y),
72 cal_data.mag_across(mag.x),
73 cal_data.mag_through(mag.z));
74 } catch (TimeoutException te) {
78 public AltosMag(AltosLink link) throws InterruptedException, TimeoutException {
82 String line = link.get_reply_no_dialog(5000);
84 throw new TimeoutException();
86 if (parse_string(line))