altosui: Build device constants into .java code
[fw/altos] / altosui / Altos.java
index 25d97bcf2b5c6fc35c145c201e12ee5c440caea1..9626379730a16f806170f487f1945047a7a35822 100644 (file)
@@ -231,10 +231,27 @@ public class Altos {
        static final Charset    unicode_set = Charset.forName("UTF-8");
 
        static String string(int[] bytes, int s, int l) {
-               byte[]  b = new byte[bytes.length];
-               for (int i = 0; i < l; i++)
+               if (s + l > bytes.length) {
+                       if (s > bytes.length) {
+                               s = bytes.length;
+                               l = 0;
+                       } else {
+                               l = bytes.length - s;
+                       }
+               }
+
+               int i;
+               for (i = l - 1; i >= 0; i--)
+                       if (bytes[s+i] != 0)
+                               break;
+
+               l = i + 1;
+               byte[]  b = new byte[l];
+
+               for (i = 0; i < l; i++)
                        b[i] = (byte) bytes[s+i];
-               return new String(b, unicode_set);
+               String n = new String(b, unicode_set);
+               return n;
        }
 
        static int hexbyte(String s, int i) {
@@ -307,50 +324,42 @@ public class Altos {
        }
 
        static int usb_vendor_altusmetrum() {
-               if (load_library())
-                       return libaltosConstants.USB_VENDOR_ALTUSMETRUM;
-               return 0x000a;
+               load_library();
+               return 0xfffe;
        }
 
        static int usb_product_altusmetrum() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
+               load_library();
                return 0x000a;
        }
 
        static int usb_product_altusmetrum_min() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN;
+               load_library();
                return 0x000a;
        }
 
        static int usb_product_altusmetrum_max() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX;
-               return 0x000d;
+               load_library();
+               return 0x0013;
        }
 
        static int usb_product_telemetrum() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_TELEMETRUM;
+               load_library();
                return 0x000b;
        }
 
        static int usb_product_teledongle() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_TELEDONGLE;
+               load_library();
                return 0x000c;
        }
 
        static int usb_product_teleterra() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_TELETERRA;
+               load_library();
                return 0x000d;
        }
 
        static int usb_product_telebt() {
-               if (load_library())
-                       return libaltosConstants.USB_PRODUCT_TELEBT;
+               load_library();
                return 0x000e;
        }
 
@@ -367,8 +376,7 @@ public class Altos {
        public final static int product_basestation = 0x10000 + 1;
 
        static String bt_product_telebt() {
-               if (load_library())
-                       return libaltosConstants.BLUETOOTH_PRODUCT_TELEBT;
+               load_library();
                return "TeleBT";
        }