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; 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.altosuilib_13;
24 public class AltosUSBDevice extends altos_device implements AltosDevice {
26 public String toString() {
27 String name = getName();
29 name = "Altus Metrum";
30 return String.format("%-20.20s %4d %s",
31 name, getSerial(), getPath());
34 public String toShortString() {
35 String name = getName();
37 name = "Altus Metrum";
38 return String.format("%s %d %s",
39 name, getSerial(), getPath());
43 public String getErrorString() {
44 altos_error error = new altos_error();
46 libaltos.altos_get_last_error(error);
47 return String.format("%s (%d)", error.getString(), error.getCode());
50 public SWIGTYPE_p_altos_file open() {
51 return libaltos.altos_open(this);
54 public boolean isAltusMetrum() {
55 if (getVendor() != AltosUILib.vendor_altusmetrum)
57 if (getProduct() < AltosUILib.product_altusmetrum_min)
59 if (getProduct() > AltosUILib.product_altusmetrum_max)
64 public boolean matchProduct(int want_product) {
69 if (want_product == AltosUILib.product_any)
72 int have_product = getProduct();
74 if (want_product == AltosUILib.product_basestation)
75 return have_product == AltosUILib.product_teledongle ||
76 have_product == AltosUILib.product_teleterra ||
77 have_product == AltosUILib.product_telebt ||
78 have_product == AltosUILib.product_megadongle;
80 if (want_product == AltosUILib.product_altimeter)
81 return have_product == AltosUILib.product_telemetrum ||
82 have_product == AltosUILib.product_telemega ||
83 have_product == AltosUILib.product_easymega ||
84 have_product == AltosUILib.product_telegps ||
85 have_product == AltosUILib.product_easymini ||
86 have_product == AltosUILib.product_telemini;
88 if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */
91 if (want_product == have_product)
97 static public java.util.List<AltosDevice> list(int product) {
98 if (!AltosUILib.load_library())
101 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
103 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
106 AltosUSBDevice device = new AltosUSBDevice();
107 if (libaltos.altos_list_next(list, device) == 0)
109 if (device.matchProduct(product))
110 device_list.add(device);
112 libaltos.altos_list_finish(list);