X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosEepromRecord.java;h=7a0cc8f92ac4be3d89d3b21e43fbc248450f0a3e;hb=9e1295ff74d03f940fc68e6795bf30687162a440;hp=efcca857d9e17ba7a1429c9a48a82a64ad30de4a;hpb=e67a5c6ffa7174d66e985483fab4bf52ccaea5ca;p=fw%2Faltos diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index efcca857..7a0cc8f9 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -14,7 +14,6 @@ package org.altusmetrum.altoslib_11; - public abstract class AltosEepromRecord implements Comparable { AltosEepromNew eeprom; @@ -51,8 +50,12 @@ public abstract class AltosEepromRecord implements Comparable 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() { @@ -61,6 +64,10 @@ public abstract class AltosEepromRecord implements Comparable return 1; } + public AltosConfigData config_data() { + return eeprom.config_data(); + } + public int compareTo(AltosEepromRecord o) { int cmd_diff = cmdi() - o.cmdi(); @@ -74,15 +81,36 @@ public abstract class AltosEepromRecord implements Comparable return start - o.start; } - public void update_state(AltosState state) { + /* AltosDataProvider */ + public void provide_data(AltosDataListener listener, AltosCalData cal_data) { + cal_data.set_tick(tick()); if (cmd() == AltosLib.AO_LOG_FLIGHT) - state.set_boost_tick(tick()); - else - state.set_tick(tick()); + cal_data.set_boost_tick(); + listener.set_time(cal_data.time()); + + /* Flush any pending GPS changes */ + if (!AltosLib.is_gps_cmd(cmd())) { + AltosGPS gps = cal_data.temp_gps(); + if (gps != null) { + listener.set_gps(gps); + cal_data.reset_temp_gps(); + } + } + } + + 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 +119,8 @@ public abstract class AltosEepromRecord implements Comparable this.eeprom = eeprom; this.start = start; this.length = length; + + while (start + length < eeprom.data.size() && !valid()) + start += length; } }