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_13;
17 public abstract class AltosEepromRecord implements Comparable<AltosEepromRecord> {
26 public final static int header_length = 4;
29 return eeprom.data8(start);
33 return eeprom.data16(start+2);
36 public int data8(int i) {
37 i += start + header_length;
38 return eeprom.data8(i);
41 public int data16(int i) {
42 return ((data8(i) | (data8(i+1) << 8)) << 16) >> 16;
45 public int data24(int i) {
46 return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16);
49 public int data32(int i) {
50 return data8(i) | (data8(i+1) << 8) | (data8(i+2) << 16) | (data8(i+3) << 24);
53 public boolean empty(int s) {
54 for (int i = 0; i < length; i++)
55 if (eeprom.data8(s + i) != 0xff)
60 public boolean valid(int s) {
61 int ck = AltosConvert.checksum(eeprom.data, s, length);
65 System.out.printf("invalid checksum 0x%x at 0x%x\n", ck, s);
71 public boolean valid() {
76 if (cmd() == AltosLib.AO_LOG_FLIGHT)
81 public AltosConfigData config_data() {
82 return eeprom.config_data();
85 public int compareTo(AltosEepromRecord o) {
86 int cmd_diff = cmdi() - o.cmdi();
91 int tick_diff = wide_tick - o.wide_tick;
95 return start - o.start;
98 /* AltosDataProvider */
99 public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
100 listener.set_tick(tick());
101 if (cmd() == AltosLib.AO_LOG_FLIGHT)
102 cal_data.set_boost_tick();
103 listener.set_time(cal_data.time());
105 /* Flush any pending GPS changes */
106 if (!AltosLib.is_gps_cmd(cmd())) {
107 AltosGPS gps = listener.temp_gps();
109 listener.set_gps(gps);
113 public int next_start() {
114 int s = start + length;
116 while (s + length <= eeprom.data.size()) {
117 if (!empty(s) && valid(s))
124 public abstract AltosEepromRecord next();
126 public AltosEepromRecord(AltosEeprom eeprom, int start, int length) {
127 this.eeprom = eeprom;
129 this.length = length;