diff options
author | Keith Packard <keithp@keithp.com> | 2017-11-11 20:49:20 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-11-11 20:49:20 -0800 |
commit | 9a7b4f02ad32ca43a45ed9fe446b8db96e60b5e5 (patch) | |
tree | af009a016229cb6e377bc5d4cecd92874c89a839 /altoslib/AltosEepromRecord.java | |
parent | 10834eb60f7a44fee159d9e9ad5ffb2e013fe9cf (diff) |
altoslib: Improve EEprom download
* Catch and report CRC errors
* Deal with corrupted flight records
* Add ability to immediately graph new data
* Check before overwriting existing files
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosEepromRecord.java')
-rw-r--r-- | altoslib/AltosEepromRecord.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index 12519e6b..43e8ea4d 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -50,8 +50,22 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16) | (data8(i+3) << 24); } + public boolean empty(int s) { + for (int i = 0; i < length; i++) + if (eeprom.data8(s + i) != 0xff) + return false; + return true; + } + public boolean valid(int s) { - return AltosConvert.checksum(eeprom.data, s, length) == 0; + int ck = AltosConvert.checksum(eeprom.data, s, length); + + if (ck != 0) { + ++eeprom.errors; + System.out.printf("invalid checksum 0x%x at 0x%x\n", ck, s); + return false; + } + return true; } public boolean valid() { @@ -100,25 +114,18 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> int s = start + length; while (s + length <= eeprom.data.size()) { - if (valid(s)) + if (!empty(s) && valid(s)) return s; s += length; } return -1; } - public boolean hasNext() { - return next_start() >= 0; - } - public abstract AltosEepromRecord next(); public AltosEepromRecord(AltosEeprom eeprom, int start, int length) { this.eeprom = eeprom; this.start = start; this.length = length; - - while (start + length < eeprom.data.size() && !valid()) - start += length; } } |