altoslib: Make sure AltosFlightSeries is filled in before use
[fw/altos] / altoslib / AltosEepromNew.java
index c8f44509d19e8a33b9dce623a01d506bc59c2909..0da3df71c98740f282f785894669dc1f24786cbe 100644 (file)
@@ -57,7 +57,8 @@ public class AltosEepromNew {
                        if (config_data == null)
                                config_data = new AltosConfigData();
 
-                       if (config_data.log_format == AltosLib.MISSING) {
+                       if (config_data.log_format == AltosLib.AO_LOG_FORMAT_UNKNOWN) {
+                               config_data.log_format = AltosLib.AO_LOG_FORMAT_FULL;
                                if (config_data.product != null) {
                                        if (config_data.product.startsWith("TeleMetrum"))
                                                config_data.log_format = AltosLib.AO_LOG_FORMAT_FULL;
@@ -69,10 +70,6 @@ public class AltosEepromNew {
                return config_data;
        }
 
-       public void reset_config_data() {
-               config_data = null;
-       }
-
        private void write_config(Writer w) throws IOException {
                config.write(w, 0, true);
                w.append('\n');
@@ -103,29 +100,22 @@ public class AltosEepromNew {
                return true;
        }
 
-       static private byte[] byte_list_to_array(List<Byte> bytes) {
-               byte[] data = new byte[bytes.size()];
-               int i = 0;
-
-               for (Byte b : bytes) {
-                       data[i++] = b;
-               }
-               return data;
-       }
-
        private boolean read_data(Reader r) throws IOException {
                BufferedReader  br = new BufferedReader(r);
                String          s;
 
                data = new ArrayList<Byte>();
                while ((s = br.readLine()) != null) {
+
                        String[] tokens = s.split("\\s+");
 
                        for (int i = 0; i < tokens.length; i++) {
-                               try {
-                                       data.add((byte) AltosLib.fromhex(tokens[i]));
-                               } catch (NumberFormatException e) {
-                                       throw new IOException(e.toString());
+                               if (tokens[i].length() > 0) {
+                                       try {
+                                               data.add((byte) AltosLib.fromhex(tokens[i]));
+                                       } catch (NumberFormatException e) {
+                                               throw new IOException(e.toString());
+                                       }
                                }
                        }
                }
@@ -175,7 +165,8 @@ public class AltosEepromNew {
                        int start = data.size();
 
                        if (config_data().log_format != AltosLib.AO_LOG_FORMAT_TINY) {
-                               data.add((byte) tokens[0].codePointAt(0));
+                               byte cmd = (byte) tokens[0].codePointAt(0);
+                               data.add(cmd);
 
                                int time = AltosLib.fromhex(tokens[1]);
 
@@ -270,6 +261,16 @@ public class AltosEepromNew {
                read(new StringReader(s));
        }
 
+       public AltosEepromNew(AltosJson config, ArrayList<Byte> data) {
+               this.config = config;
+               this.data = data;
+       }
+
+       public AltosEepromNew(AltosConfigData config_data, ArrayList<Byte> data) {
+               this.config = new AltosJson(config_data);
+               this.data = data;
+       }
+
        public AltosEepromNew() {
        }
 }