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; 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_14;
22 import org.altusmetrum.altoslib_14.*;
24 public class AltosBTDevice extends altos_bt_device implements AltosDevice {
26 public String getProductName() {
27 String name = getName();
29 return "Altus Metrum";
30 int dash = name.lastIndexOf("-");
33 return name.substring(0,dash);
36 public int getProduct() {
37 if (AltosLib.bt_product_telebt.equals(getProductName()))
38 return AltosLib.product_telebt;
42 public String getPath() {
46 public String getErrorString() {
47 altos_error error = new altos_error();
49 libaltos.altos_get_last_error(error);
50 return String.format("%s (%d)", error.getString(), error.getCode());
53 public int getSerial() {
54 String name = getName();
57 int dash = name.lastIndexOf("-");
58 if (dash < 0 || dash >= name.length())
60 String sn = name.substring(dash + 1, name.length());
62 return Integer.parseInt(sn);
63 } catch (NumberFormatException ne) {
68 public String toString() {
69 return String.format("%-20.20s %4d %s",
70 getProductName(), getSerial(), getAddr());
73 public String toShortString() {
74 return String.format("%s %d %s",
75 getProductName(), getSerial(), getAddr());
79 public SWIGTYPE_p_altos_file open() {
80 return libaltos.altos_bt_open(this);
84 private boolean isAltusMetrum() {
85 if (getName().startsWith(Altos.bt_product_telebt))
91 public boolean matchProduct(int want_product) {
93 // if (!isAltusMetrum())
96 if (want_product == AltosLib.product_any)
99 if (want_product == AltosLib.product_basestation)
100 return matchProduct(AltosLib.product_telebt);
102 if (want_product == getProduct())
108 public int hashCode() {
109 return getName().hashCode() ^ getAddr().hashCode();
112 public boolean equals(Object o) {
116 if (!(o instanceof AltosBTDevice))
118 AltosBTDevice other = (AltosBTDevice) o;
119 return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
122 public AltosBTDevice(String name, String addr) {
123 AltosUILib.load_library();
124 libaltos.altos_bt_fill_in(name, addr,this);
127 public AltosBTDevice() {