micropeak: detect empty log received from device
authorKeith Packard <keithp@keithp.com>
Thu, 16 Dec 2021 21:36:10 +0000 (13:36 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 11 Jan 2022 22:46:48 +0000 (14:46 -0800)
Avoid reporting a failure to the user when the device has no flight
log.

Signed-off-by: Keith Packard <keithp@keithp.com>
micropeak/MicroData.java

index 359ccd7aea592bced582a440e87d8f3f6d66a02c..4a53482c74ad95e93f43daa968cb7c320472c70d 100644 (file)
@@ -157,6 +157,8 @@ public class MicroData {
 
        public boolean  crc_valid;
 
+       public boolean  log_empty;
+
        int mix_in (int high, int low) {
                return  high - (high & 0xffff) + low;
        }
@@ -246,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");
@@ -352,7 +363,12 @@ public class MicroData {
                        int current_crc = swap16(~file_crc & 0xffff);
                        int crc = get_16(f);
 
-                       crc_valid = crc == current_crc;
+                       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);