2 * Copyright © 2017 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 package org.altusmetrum.altoslib_11;
18 public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> {
20 AltosEepromNew eeprom;
27 public final static int header_length = 4;
30 return eeprom.data8(start);
34 return eeprom.data16(start+2);
37 public int data8(int i) {
38 i += start + header_length;
39 return eeprom.data8(i);
42 public int data16(int i) {
43 return ((data8(i) | (data8(i+1) << 8)) << 16) >> 16;
46 public int data24(int i) {
47 return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16);
50 public int data32(int i) {
51 return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16) | (data8(i+3) << 24);
54 public boolean valid(int s) {
55 return AltosConvert.checksum(eeprom.data, s, length) == 0;
58 public boolean valid() {
63 if (cmd() == AltosLib.AO_LOG_FLIGHT)
68 public int compareTo(AltosEepromRecord o) {
69 int cmd_diff = cmdi() - o.cmdi();
74 int tick_diff = tick() - o.tick();
78 return start - o.start;
81 public void update_state(AltosState state) {
82 if (cmd() == AltosLib.AO_LOG_FLIGHT)
83 state.set_boost_tick(tick());
85 state.set_tick(tick());
88 public int next_start() {
89 int s = start + length;
91 while (s + length < eeprom.data.size()) {
99 public boolean hasNext() {
100 return next_start() >= 0;
103 public abstract AltosEepromRecord next();
105 public AltosEepromRecord(AltosEepromNew eeprom, int start, int length) {
106 this.eeprom = eeprom;
108 this.length = length;
110 while (start + length < eeprom.data.size() && !valid())