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_8;
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 int have_product = getProduct();
73 if (want_product == AltosUILib.product_basestation)
74 return have_product == AltosUILib.product_teledongle ||
75 have_product == AltosUILib.product_teleterra ||
76 have_product == AltosUILib.product_telebt ||
77 have_product == AltosUILib.product_megadongle;
79 if (want_product == AltosUILib.product_altimeter)
80 return have_product == AltosUILib.product_telemetrum ||
81 have_product == AltosUILib.product_telemega ||
82 have_product == AltosUILib.product_easymega ||
83 have_product == AltosUILib.product_telegps ||
84 have_product == AltosUILib.product_easymini ||
85 have_product == AltosUILib.product_telemini;
87 if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */
90 if (want_product == have_product)
96 static public java.util.List<AltosDevice> list(int product) {
97 if (!AltosUILib.load_library())
100 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
102 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
105 AltosUSBDevice device = new AltosUSBDevice();
106 if (libaltos.altos_list_next(list, device) == 0)
108 if (device.matchProduct(product))
109 device_list.add(device);
111 libaltos.altos_list_finish(list);