first cut at turnon scripts for EasyTimer v2
[fw/altos] / micropeak / MicroData.java
index 4a795dffa2337edd97c2dc8a8c3f9bd0b0671a55..4a53482c74ad95e93f43daa968cb7c320472c70d 100644 (file)
@@ -34,8 +34,10 @@ public class MicroData {
 
        private double          time_step;
        private ArrayList<Integer>      bytes;
+       public int              nsamples;
        public int              log_id;
        String                  name;
+       String                  unique_id;
 
        public static final int LOG_ID_MICROPEAK = 0;
        public static final int LOG_ID_MICROKITE = 1;
@@ -134,12 +136,29 @@ public class MicroData {
                return v;
        }
 
+       private String get_line(InputStream f) throws IOException, FileEndedException, NonHexcharException {
+               int c;
+               StringBuffer line = new StringBuffer();
+
+               do {
+                       c = f.read();
+               } while (Character.isWhitespace(c));
+
+               do {
+                       line.append((char) c);
+                       c = f.read();
+               } while (!Character.isWhitespace(c));
+               return new String(line);
+       }
+
        private int swap16(int i) {
                return ((i << 8) & 0xff00) | ((i >> 8) & 0xff);
        }
 
        public boolean  crc_valid;
 
+       public boolean  log_empty;
+
        int mix_in (int high, int low) {
                return  high - (high & 0xffff) + low;
        }
@@ -229,6 +248,15 @@ public class MicroData {
                f.write('\n');
        }
 
+       public boolean is_empty() {
+               boolean empty = true;
+               for (int c : bytes) {
+                       if (!Character.isWhitespace(c) && c != 'f')
+                               empty = false;
+               }
+               return empty;
+       }
+
        public void export (Writer f) throws IOException {
                PrintWriter     pw = new PrintWriter(f);
                pw.printf("  Time, Press(Pa), Height(m), Height(f), Speed(m/s), Speed(mph), Speed(mach), Accel(m/s²), Accel(ft/s²),  Accel(g)\n");
@@ -277,10 +305,14 @@ public class MicroData {
                        file_crc = 0xffff;
                        ground_pressure = get_32(f);
                        min_pressure = get_32(f);
-                       int nsamples = get_16(f);
+                       nsamples = get_16(f);
 
                        log_id = nsamples >> 12;
                        nsamples &= 0xfff;
+                       if (log_id == LOG_ID_MICROPEAK2) {
+                               int nsamples_high = get_16(f);
+                               nsamples |= (nsamples_high << 12);
+                       }
 
                        cal_data.set_ground_pressure(ground_pressure);
 
@@ -328,6 +360,20 @@ public class MicroData {
                                flight_series.set_pressure(cur);
                        }
 
+                       int current_crc = swap16(~file_crc & 0xffff);
+                       int crc = get_16(f);
+
+                       crc_valid = (crc == current_crc);
+
+                       if (!crc_valid && is_empty()) {
+                               crc_valid = true;
+                               nsamples = 0;
+                       }
+
+                       if (log_id == LOG_ID_MICROPEAK2) {
+                               unique_id = get_line(f);
+                       }
+
                        flight_series.finish();
 
                        /* Build states */
@@ -335,8 +381,10 @@ public class MicroData {
                        flight_series.set_time(0);
                        flight_series.set_state(AltosLib.ao_flight_boost);
 
-                       flight_series.set_time(flight_series.speed_series.max().time);
-                       flight_series.set_state(AltosLib.ao_flight_coast);
+                       if (flight_series.speed_series != null && flight_series.speed_series.max() != null) {
+                               flight_series.set_time(flight_series.speed_series.max().time);
+                               flight_series.set_state(AltosLib.ao_flight_coast);
+                       }
 
                        flight_series.set_time(flight_series.height_series.max().time);
                        flight_series.set_state(AltosLib.ao_flight_drogue);
@@ -351,10 +399,6 @@ public class MicroData {
 
                        flight_stats = new AltosFlightStats(flight_series);
 
-                       int current_crc = swap16(~file_crc & 0xffff);
-                       int crc = get_16(f);
-
-                       crc_valid = crc == current_crc;
 
                } catch (FileEndedException fe) {
                        throw new IOException("File Ended Unexpectedly");