2 * Copyright © 2011 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 AltosBTDevice extends altos_bt_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 String bt_product_telebt() {
44 return libaltosConstants.BLUETOOTH_PRODUCT_TELEBT;
48 public final static String bt_product_telebt = bt_product_telebt();
49 public final static String bt_product_any = "Any";
50 public final static String bt_product_basestation = "Basestation";
52 public String getProduct() {
53 String name = getName();
55 return "Altus Metrum";
56 int dash = name.lastIndexOf("-");
59 return name.substring(0,dash);
62 public int getSerial() {
63 String name = getName();
66 int dash = name.lastIndexOf("-");
67 if (dash < 0 || dash >= name.length())
69 String sn = name.substring(dash + 1, name.length());
71 return Integer.parseInt(sn);
72 } catch (NumberFormatException ne) {
77 public String toString() {
78 String name = getName();
80 name = "Altus Metrum";
81 return String.format("%-20.20s %4d %s",
82 getProduct(), getSerial(), getAddr());
85 public String toShortString() {
86 String name = getName();
88 name = "Altus Metrum";
89 return String.format("%s %d %s",
90 getProduct(), getSerial(), getAddr());
94 public boolean isAltusMetrum() {
95 if (getName().startsWith(bt_product_telebt))
100 public boolean matchProduct(String want_product) {
102 if (!isAltusMetrum())
105 if (want_product.equals(bt_product_any))
108 if (want_product.equals(bt_product_basestation))
109 return matchProduct(bt_product_telebt);
111 if (want_product.equals(getProduct()))