2 * Copyright © 2013 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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_1;
24 public abstract class AltosEeprom implements AltosStateUpdate {
30 public final static int header_length = 4;
32 public abstract void update_state(AltosState state);
34 public void write(PrintStream out) {
35 out.printf("%c %04x", cmd, tick);
37 for (int i = 0; i < data8.length; i++)
38 out.printf (" %02x", data8[i]);
43 void parse_chunk(AltosEepromChunk chunk, int start, int record_length) throws ParseException {
44 cmd = chunk.data(start);
46 int data_length = record_length - header_length;
48 valid = !chunk.erased(start, record_length);
50 if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
51 throw new ParseException(String.format("invalid checksum at 0x%x",
52 chunk.address + start), 0);
54 cmd = AltosLib.AO_LOG_INVALID;
57 tick = chunk.data16(start+2);
59 data8 = new int[data_length];
60 for (int i = 0; i < data_length; i++)
61 data8[i] = chunk.data(start + header_length + i);
64 void parse_string(String line, int record_length) {
67 cmd = AltosLib.AO_LOG_INVALID;
69 int data_length = record_length - header_length;
74 String[] tokens = line.split("\\s+");
76 if (tokens[0].length() == 1) {
77 if (tokens.length == 2 + data_length) {
78 cmd = tokens[0].codePointAt(0);
79 tick = Integer.parseInt(tokens[1],16);
81 data8 = new int[data_length];
82 for (int i = 0; i < data_length; i++)
83 data8[i] = Integer.parseInt(tokens[2 + i],16);
86 } catch (NumberFormatException ne) {