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.
18 package org.altusmetrum.altosuilib_1;
23 public class AltosUSBDevice extends altos_device implements AltosDevice {
25 public String toString() {
26 String name = getName();
28 name = "Altus Metrum";
29 return String.format("%-20.20s %4d %s",
30 name, getSerial(), getPath());
33 public String toShortString() {
34 String name = getName();
36 name = "Altus Metrum";
37 return String.format("%s %d %s",
38 name, getSerial(), getPath());
42 public String getErrorString() {
43 altos_error error = new altos_error();
45 libaltos.altos_get_last_error(error);
46 return String.format("%s (%d)", error.getString(), error.getCode());
49 public SWIGTYPE_p_altos_file open() {
50 return libaltos.altos_open(this);
53 public boolean isAltusMetrum() {
54 if (getVendor() != AltosUILib.vendor_altusmetrum)
56 if (getProduct() < AltosUILib.product_altusmetrum_min)
58 if (getProduct() > AltosUILib.product_altusmetrum_max)
63 public boolean matchProduct(int want_product) {
68 if (want_product == AltosUILib.product_any)
71 if (want_product == AltosUILib.product_basestation)
72 return matchProduct(AltosUILib.product_teledongle) ||
73 matchProduct(AltosUILib.product_teleterra) ||
74 matchProduct(AltosUILib.product_telebt) ||
75 matchProduct(AltosUILib.product_telemega);
77 if (want_product == AltosUILib.product_altimeter)
78 return matchProduct(AltosUILib.product_telemetrum) ||
79 matchProduct(AltosUILib.product_telemega) ||
80 matchProduct(AltosUILib.product_telegps);
82 int have_product = getProduct();
84 if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */
87 if (want_product == have_product)
93 static public java.util.List<AltosDevice> list(int product) {
94 if (!AltosUILib.load_library())
97 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
99 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
102 AltosUSBDevice device = new AltosUSBDevice();
103 if (libaltos.altos_list_next(list, device) == 0)
105 if (device.matchProduct(product))
106 device_list.add(device);
108 libaltos.altos_list_finish(list);