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 implements AltosDevice {
25 public String getProductName() {
26 String name = getName();
28 return "Altus Metrum";
29 int dash = name.lastIndexOf("-");
32 return name.substring(0,dash);
35 public int getProduct() {
36 if (Altos.bt_product_telebt.equals(getProductName()))
37 return Altos.product_telebt;
41 public String getPath() {
45 public int getSerial() {
46 String name = getName();
49 int dash = name.lastIndexOf("-");
50 if (dash < 0 || dash >= name.length())
52 String sn = name.substring(dash + 1, name.length());
54 return Integer.parseInt(sn);
55 } catch (NumberFormatException ne) {
60 public String toString() {
61 return String.format("%-20.20s %4d %s",
62 getProductName(), getSerial(), getAddr());
65 public String toShortString() {
66 return String.format("%s %d %s",
67 getProductName(), getSerial(), getAddr());
71 public SWIGTYPE_p_altos_file open() {
72 return libaltos.altos_bt_open(this);
75 private boolean isAltusMetrum() {
76 if (getName().startsWith(Altos.bt_product_telebt))
81 public boolean matchProduct(int want_product) {
83 System.out.printf("matchProduct %s %d\n", toString(), want_product);
84 // if (!isAltusMetrum())
87 if (want_product == Altos.product_any)
90 if (want_product == Altos.product_basestation)
91 return matchProduct(Altos.product_telebt);
93 if (want_product == getProduct())
99 public boolean equals(Object o) {
100 if (!(o instanceof AltosBTDevice))
102 AltosBTDevice other = (AltosBTDevice) o;
103 System.out.printf("AltosBTDevice equals %s == %s\n", toString(), other.toString());
104 return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
107 public int hashCode() {
108 return getName().hashCode() ^ getAddr().hashCode();
111 public AltosBTDevice(String name, String addr) {
112 libaltos.altos_bt_fill_in(name, addr,this);
115 public AltosBTDevice() {