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.
23 public class AltosDevice extends altos_device {
25 static public boolean initialized = false;
26 static public boolean loaded_library = false;
28 public static boolean load_library() {
31 System.loadLibrary("altos");
32 libaltos.altos_init();
33 loaded_library = true;
34 } catch (UnsatisfiedLinkError e) {
35 loaded_library = false;
39 return loaded_library;
42 static int usb_vendor_altusmetrum() {
44 return libaltosConstants.USB_VENDOR_ALTUSMETRUM;
48 static int usb_product_altusmetrum() {
50 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
54 static int usb_product_altusmetrum_min() {
56 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN;
60 static int usb_product_altusmetrum_max() {
62 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX;
66 static int usb_product_telemetrum() {
68 return libaltosConstants.USB_PRODUCT_TELEMETRUM;
72 static int usb_product_teledongle() {
74 return libaltosConstants.USB_PRODUCT_TELEDONGLE;
78 static int usb_product_teleterra() {
80 return libaltosConstants.USB_PRODUCT_TELETERRA;
84 static int usb_product_telebt() {
86 return libaltosConstants.USB_PRODUCT_TELEBT;
90 public final static int vendor_altusmetrum = usb_vendor_altusmetrum();
91 public final static int product_altusmetrum = usb_product_altusmetrum();
92 public final static int product_telemetrum = usb_product_telemetrum();
93 public final static int product_teledongle = usb_product_teledongle();
94 public final static int product_teleterra = usb_product_teleterra();
95 public final static int product_telebt = usb_product_telebt();
96 public final static int product_altusmetrum_min = usb_product_altusmetrum_min();
97 public final static int product_altusmetrum_max = usb_product_altusmetrum_max();
99 public final static int product_any = 0x10000;
100 public final static int product_basestation = 0x10000 + 1;
102 public String toString() {
103 String name = getName();
105 name = "Altus Metrum";
106 return String.format("%-20.20s %4d %s",
107 name, getSerial(), getPath());
110 public String toShortString() {
111 String name = getName();
113 name = "Altus Metrum";
114 return String.format("%s %d %s",
115 name, getSerial(), getPath());
119 public boolean isAltusMetrum() {
120 if (getVendor() != vendor_altusmetrum)
122 if (getProduct() < product_altusmetrum_min)
124 if (getProduct() > product_altusmetrum_max)
129 public boolean matchProduct(int want_product) {
131 if (!isAltusMetrum())
134 if (want_product == product_any)
137 if (want_product == product_basestation)
138 return matchProduct(product_teledongle) ||
139 matchProduct(product_teleterra) ||
140 matchProduct(product_telebt);
142 int have_product = getProduct();
144 if (have_product == product_altusmetrum) /* old devices match any request */
147 if (want_product == have_product)
153 static AltosDevice[] list(int product) {
157 SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
159 ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
161 SWIGTYPE_p_altos_file file;
164 AltosDevice device = new AltosDevice();
165 if (libaltos.altos_list_next(list, device) == 0)
167 if (device.matchProduct(product))
168 device_list.add(device);
170 libaltos.altos_list_finish(list);
173 AltosDevice[] devices = new AltosDevice[device_list.size()];
174 for (int i = 0; i < device_list.size(); i++)
175 devices[i] = device_list.get(i);