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;
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 String toString() {
55 case AltosLib.AO_LOG_FLIGHT:
56 return String.format("tick %5d flight %5d ground_accel %6d\n",
58 case AltosLib.AO_LOG_SENSOR:
59 return String.format("tick %5d accel %5d pres %5d\n",
61 case AltosLib.AO_LOG_TEMP_VOLT:
62 case AltosLib.AO_LOG_DEPLOY:
63 case AltosLib.AO_LOG_STATE:
64 case AltosLib.AO_LOG_GPS_TIME:
65 case AltosLib.AO_LOG_GPS_LAT:
66 case AltosLib.AO_LOG_GPS_LON:
67 case AltosLib.AO_LOG_GPS_ALT:
68 case AltosLib.AO_LOG_GPS_SAT:
69 case AltosLib.AO_LOG_GPS_DATE:
70 case AltosLib.AO_LOG_PRESSURE:
76 public AltosEepromRecord (String line) {
83 cmd = AltosLib.AO_LOG_INVALID;
87 String[] tokens = line.split("\\s+");
89 if (tokens[0].length() == 1) {
90 if (tokens.length != 4) {
91 cmd = AltosLib.AO_LOG_INVALID;
94 cmd = tokens[0].codePointAt(0);
95 tick = Integer.parseInt(tokens[1],16);
97 a = Integer.parseInt(tokens[2],16);
98 b = Integer.parseInt(tokens[3],16);
100 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
101 cmd = AltosLib.AO_LOG_CONFIG_VERSION;
103 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
104 cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
105 a = Integer.parseInt(tokens[2]);
106 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
107 cmd = AltosLib.AO_LOG_APOGEE_DELAY;
108 a = Integer.parseInt(tokens[2]);
109 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
110 cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
111 a = Integer.parseInt(tokens[2]);
112 } else if (tokens[0].equals("Callsign:")) {
113 cmd = AltosLib.AO_LOG_CALLSIGN;
114 data = tokens[1].replaceAll("\"","");
115 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
116 cmd = AltosLib.AO_LOG_ACCEL_CAL;
117 a = Integer.parseInt(tokens[3]);
118 b = Integer.parseInt(tokens[5]);
119 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
120 cmd = AltosLib.AO_LOG_RADIO_CAL;
121 a = Integer.parseInt(tokens[2]);
122 } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
123 cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
124 a = Integer.parseInt(tokens[3]);
125 } else if (tokens[0].equals("manufacturer")) {
126 cmd = AltosLib.AO_LOG_MANUFACTURER;
128 } else if (tokens[0].equals("product")) {
129 cmd = AltosLib.AO_LOG_PRODUCT;
131 } else if (tokens[0].equals("serial-number")) {
132 cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
133 a = Integer.parseInt(tokens[1]);
134 } else if (tokens[0].equals("log-format")) {
135 cmd = AltosLib.AO_LOG_LOG_FORMAT;
136 a = Integer.parseInt(tokens[1]);
137 } else if (tokens[0].equals("software-version")) {
138 cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
141 cmd = AltosLib.AO_LOG_INVALID;
144 } catch (NumberFormatException ne) {
145 cmd = AltosLib.AO_LOG_INVALID;
151 public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) {