diff options
author | Keith Packard <keithp@keithp.com> | 2017-05-09 02:11:25 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-05-09 02:12:16 -0700 |
commit | 17e20a6d2dab1f4bd1375bfd9e1c5230ee2c1119 (patch) | |
tree | d709aa13da89a8d9a1d35dccaf679430356c78ac /altoslib/AltosEepromRecord.java | |
parent | e311cefae19d7dc71fb10e9a943daa8e2313c8f8 (diff) |
altoslib: Save eeprom data in new .eeprom format
A chunk of json for the config values followed by hex numbers for the data.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosEepromRecord.java')
-rw-r--r-- | altoslib/AltosEepromRecord.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index efcca857..c0edb952 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -51,8 +51,12 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16) | (data8(i+3) << 24); } + public boolean valid(int s) { + return AltosConvert.checksum(eeprom.data, s, length) == 0; + } + public boolean valid() { - return AltosConvert.checksum(eeprom.data, start, length) == 0; + return valid(start); } private int cmdi() { @@ -81,8 +85,19 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> state.set_tick(tick()); } + public int next_start() { + int s = start + length; + + while (s + length < eeprom.data.size()) { + if (valid(s)) + return s; + s += length; + } + return -1; + } + public boolean hasNext() { - return start + length * 2 < eeprom.data.size(); + return next_start() >= 0; } public abstract AltosEepromRecord next(); @@ -91,5 +106,8 @@ public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> this.eeprom = eeprom; this.start = start; this.length = length; + + while (start + length < eeprom.data.size() && !valid()) + start += length; } } |