altosui: Report error message back from libaltos
[fw/altos] / altosui / AltosBTDevice.java
index ff2be49a66279009c6fc0f32ea69dce4d6ad89b7..55b8f8fc8bf5f28c2b7f848bbe56bf9b2434ff17 100644 (file)
@@ -42,6 +42,13 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
                return getAddr();
        }
 
+       public String getErrorString() {
+               altos_error     error = new altos_error();
+
+               libaltos.altos_get_last_error(error);
+               return String.format("%s (%d)", error.getString(), error.getCode());
+       }
+
        public int getSerial() {
                String name = getName();
                if (name == null)
@@ -58,19 +65,13 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
        }
 
        public String toString() {
-               String  name = getName();
-               if (name == null)
-                       name = "Altus Metrum";
                return String.format("%-20.20s %4d %s",
                                     getProductName(), getSerial(), getAddr());
        }
 
        public String toShortString() {
-               String  name = getName();
-               if (name == null)
-                       name = "Altus Metrum";
                return String.format("%s %d %s",
-                                    getProduct(), getSerial(), getAddr());
+                                    getProductName(), getSerial(), getAddr());
 
        }
 
@@ -86,8 +87,9 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
 
        public boolean matchProduct(int want_product) {
 
-               if (!isAltusMetrum())
-                       return false;
+               System.out.printf("matchProduct %s %d\n", toString(), want_product);
+//             if (!isAltusMetrum())
+//                     return false;
 
                if (want_product == Altos.product_any)
                        return true;
@@ -100,4 +102,23 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
 
                return false;
        }
+
+       public boolean equals(Object o) {
+               if (!(o instanceof AltosBTDevice))
+                       return false;
+               AltosBTDevice other = (AltosBTDevice) o;
+               System.out.printf("AltosBTDevice equals %s == %s\n", toString(), other.toString());
+               return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
+       }
+
+       public int hashCode() {
+               return getName().hashCode() ^ getAddr().hashCode();
+       }
+
+       public AltosBTDevice(String name, String addr) {
+               libaltos.altos_bt_fill_in(name, addr,this);
+       }
+
+       public AltosBTDevice() {
+       }
 }
\ No newline at end of file