From 55698a6232bde408ce7e12bb7ee52ba72985fc78 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 16 Dec 2021 13:36:10 -0800 Subject: [PATCH] micropeak: detect empty log received from device Avoid reporting a failure to the user when the device has no flight log. Signed-off-by: Keith Packard --- micropeak/MicroData.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index 359ccd7a..4a53482c 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -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); -- 2.30.2