2 * Copyright © 2010 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.
22 public class AltosUSBDevice extends altos_device implements AltosDevice {
24 public String toString() {
25 String name = getName();
27 name = "Altus Metrum";
28 return String.format("%-20.20s %4d %s",
29 name, getSerial(), getPath());
32 public String toShortString() {
33 String name = getName();
35 name = "Altus Metrum";
36 return String.format("%s %d %s",
37 name, getSerial(), getPath());
41 public String getErrorString() {
42 altos_error error = new altos_error();
44 libaltos.altos_get_last_error(error);
45 return String.format("%s (%d)", error.getString(), error.getCode());
48 public SWIGTYPE_p_altos_file open() {
49 return libaltos.altos_open(this);
52 private boolean isAltusMetrum() {
53 if (getVendor() != Altos.vendor_altusmetrum)
55 if (getProduct() < Altos.product_altusmetrum_min)
57 if (getProduct() > Altos.product_altusmetrum_max)
62 public boolean matchProduct(int want_product) {
67 if (want_product == Altos.product_any)
70 if (want_product == Altos.product_basestation)
71 return matchProduct(Altos.product_teledongle) ||
72 matchProduct(Altos.product_teleterra) ||
73 matchProduct(Altos.product_telebt) ||
74 matchProduct(Altos.product_megadongle);
76 if (want_product == Altos.product_altimeter)
77 return matchProduct(Altos.product_telemetrum) ||
78 matchProduct(Altos.product_megametrum);
80 int have_product = getProduct();
82 if (have_product == Altos.product_altusmetrum) /* old devices match any request */
85 if (want_product == have_product)
91 static java.util.List<AltosDevice> list(int product) {
92 if (!Altos.load_library())
95 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
97 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
100 AltosUSBDevice device = new AltosUSBDevice();
101 if (libaltos.altos_list_next(list, device) == 0)
103 if (device.matchProduct(product))
104 device_list.add(device);
106 libaltos.altos_list_finish(list);