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() {
55 return AltosConvert.checksum(eeprom.data, start, length) == 0;
59 if (cmd() == AltosLib.AO_LOG_FLIGHT)
64 public int compareTo(AltosEepromRecord o) {
65 int cmd_diff = cmdi() - o.cmdi();
70 int tick_diff = tick() - o.tick();
74 return start - o.start;
77 public void update_state(AltosState state) {
78 if (cmd() == AltosLib.AO_LOG_FLIGHT)
79 state.set_boost_tick(tick());
81 state.set_tick(tick());
84 public boolean hasNext() {
85 return start + length * 2 < eeprom.data.size();
88 public abstract AltosEepromRecord next();
90 public AltosEepromRecord(AltosEepromNew eeprom, int start, int length) {