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.
20 import org.altusmetrum.altosuilib.*;
22 public class AltosBTDevice extends altos_bt_device implements AltosDevice {
24 public String getProductName() {
25 String name = getName();
27 return "Altus Metrum";
28 int dash = name.lastIndexOf("-");
31 return name.substring(0,dash);
34 public int getProduct() {
35 if (Altos.bt_product_telebt.equals(getProductName()))
36 return Altos.product_telebt;
40 public String getPath() {
44 public String getErrorString() {
45 altos_error error = new altos_error();
47 libaltos.altos_get_last_error(error);
48 return String.format("%s (%d)", error.getString(), error.getCode());
51 public int getSerial() {
52 String name = getName();
55 int dash = name.lastIndexOf("-");
56 if (dash < 0 || dash >= name.length())
58 String sn = name.substring(dash + 1, name.length());
60 return Integer.parseInt(sn);
61 } catch (NumberFormatException ne) {
66 public String toString() {
67 return String.format("%-20.20s %4d %s",
68 getProductName(), getSerial(), getAddr());
71 public String toShortString() {
72 return String.format("%s %d %s",
73 getProductName(), getSerial(), getAddr());
77 public SWIGTYPE_p_altos_file open() {
78 return libaltos.altos_bt_open(this);
82 private boolean isAltusMetrum() {
83 if (getName().startsWith(Altos.bt_product_telebt))
89 public boolean matchProduct(int want_product) {
91 // if (!isAltusMetrum())
94 if (want_product == Altos.product_any)
97 if (want_product == Altos.product_basestation)
98 return matchProduct(Altos.product_telebt);
100 if (want_product == getProduct())
106 public boolean equals(Object o) {
107 if (!(o instanceof AltosBTDevice))
109 AltosBTDevice other = (AltosBTDevice) o;
110 return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
113 public int hashCode() {
114 return getName().hashCode() ^ getAddr().hashCode();
117 public AltosBTDevice(String name, String addr) {
118 Altos.load_library();
119 libaltos.altos_bt_fill_in(name, addr,this);
122 public AltosBTDevice() {