2 * Copyright © 2010 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;
22 public class AltosEepromRecord {
28 public boolean tick_valid;
30 public static final int record_length = 8;
32 public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException {
34 cmd = chunk.data(start);
37 tick_valid = !chunk.erased(start, record_length);
39 if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
40 throw new ParseException(String.format("invalid checksum at 0x%x",
41 chunk.address + start), 0);
43 cmd = AltosLib.AO_LOG_INVALID;
46 tick = chunk.data16(start + 2);
47 a = chunk.data16(start + 4);
48 b = chunk.data16(start + 6);
53 public AltosEepromRecord (String line) {
60 cmd = AltosLib.AO_LOG_INVALID;
64 String[] tokens = line.split("\\s+");
66 if (tokens[0].length() == 1) {
67 if (tokens.length != 4) {
68 cmd = AltosLib.AO_LOG_INVALID;
71 cmd = tokens[0].codePointAt(0);
72 tick = Integer.parseInt(tokens[1],16);
74 a = Integer.parseInt(tokens[2],16);
75 b = Integer.parseInt(tokens[3],16);
77 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
78 cmd = AltosLib.AO_LOG_CONFIG_VERSION;
80 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
81 cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
82 a = Integer.parseInt(tokens[2]);
83 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
84 cmd = AltosLib.AO_LOG_APOGEE_DELAY;
85 a = Integer.parseInt(tokens[2]);
86 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
87 cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
88 a = Integer.parseInt(tokens[2]);
89 } else if (tokens[0].equals("Callsign:")) {
90 cmd = AltosLib.AO_LOG_CALLSIGN;
91 data = tokens[1].replaceAll("\"","");
92 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
93 cmd = AltosLib.AO_LOG_ACCEL_CAL;
94 a = Integer.parseInt(tokens[3]);
95 b = Integer.parseInt(tokens[5]);
96 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
97 cmd = AltosLib.AO_LOG_RADIO_CAL;
98 a = Integer.parseInt(tokens[2]);
99 } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
100 cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
101 a = Integer.parseInt(tokens[3]);
102 } else if (tokens[0].equals("manufacturer")) {
103 cmd = AltosLib.AO_LOG_MANUFACTURER;
105 } else if (tokens[0].equals("product")) {
106 cmd = AltosLib.AO_LOG_PRODUCT;
108 } else if (tokens[0].equals("serial-number")) {
109 cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
110 a = Integer.parseInt(tokens[1]);
111 } else if (tokens[0].equals("log-format")) {
112 cmd = AltosLib.AO_LOG_LOG_FORMAT;
113 a = Integer.parseInt(tokens[1]);
114 } else if (tokens[0].equals("software-version")) {
115 cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
118 cmd = AltosLib.AO_LOG_INVALID;
121 } catch (NumberFormatException ne) {
122 cmd = AltosLib.AO_LOG_INVALID;
128 public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) {