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 AltosEepromTM implements AltosStateUpdate {
28 public boolean tick_valid;
30 public static final int record_length = 8;
32 public void update_state(AltosState state) {
35 case AltosLib.AO_LOG_FLIGHT:
36 state.ground_accel = a;
38 state.set_boost_tick(tick);
41 case AltosLib.AO_LOG_SENSOR:
42 state.set_telemetrum(a, b);
44 case AltosLib.AO_LOG_PRESSURE:
45 state.set_telemetrum(AltosState.MISSING, b);
47 case AltosLib.AO_LOG_TEMP_VOLT:
52 eeprom_state.seen |= AltosRecord.seen_temp_volt;
55 case AltosLib.AO_LOG_DEPLOY:
59 eeprom_state.seen |= AltosRecord.seen_deploy;
63 case AltosLib.AO_LOG_STATE:
66 // case AltosLib.AO_LOG_GPS_TIME:
67 // eeprom_state.gps_tick = record.tick;
68 // eeprom_state.seen |= AltosRecord.seen_gps_time;
69 // AltosGPS old = state.gps;
70 // AltosGPS gps = new AltosGPS();
72 // /* GPS date doesn't get repeated through the file */
74 // gps.year = old.year;
75 // gps.month = old.month;
78 // gps.hour = (a & 0xff);
79 // gps.minute = (a >> 8);
80 // gps.second = (b & 0xff);
82 // int flags = (b >> 8);
83 // gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
84 // gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
85 // gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
86 // AltosLib.AO_GPS_NUM_SAT_SHIFT;
87 // state.temp_gps = gps;
89 // case AltosLib.AO_LOG_GPS_LAT:
90 // int lat32 = a | (b << 16);
91 // if (state.temp_gps == null)
92 // state.temp_gps = new AltosGPS();
93 // state.temp_gps.lat = (double) lat32 / 1e7;
95 // case AltosLib.AO_LOG_GPS_LON:
96 // int lon32 = a | (b << 16);
97 // if (state.temp_gps == null)
98 // state.temp_gps = new AltosGPS();
99 // state.temp_gps.lon = (double) lon32 / 1e7;
101 // case AltosLib.AO_LOG_GPS_ALT:
102 // if (state.temp_gps == null)
103 // state.temp_gps = new AltosGPS();
104 // state.temp_gps.alt = a;
106 // case AltosLib.AO_LOG_GPS_SAT:
107 // if (record.tick == eeprom_state.gps_tick) {
109 // int c_n0 = b >> 8;
110 // if (record.gps == null)
111 // record.gps = new AltosGPS();
112 // record.gps.add_sat(svid, c_n0);
115 // case AltosLib.AO_LOG_GPS_DATE:
116 // if (record.gps == null)
117 // record.gps = new AltosGPS();
118 // record.gps.year = (a & 0xff) + 2000;
119 // record.gps.month = a >> 8;
120 // record.gps.day = b & 0xff;
123 case AltosLib.AO_LOG_CONFIG_VERSION:
125 case AltosLib.AO_LOG_MAIN_DEPLOY:
127 case AltosLib.AO_LOG_APOGEE_DELAY:
129 case AltosLib.AO_LOG_RADIO_CHANNEL:
131 case AltosLib.AO_LOG_CALLSIGN:
132 state.callsign = data;
134 case AltosLib.AO_LOG_ACCEL_CAL:
135 state.accel_plus_g = a;
136 state.accel_minus_g = b;
138 case AltosLib.AO_LOG_RADIO_CAL:
140 case AltosLib.AO_LOG_MANUFACTURER:
142 case AltosLib.AO_LOG_PRODUCT:
144 case AltosLib.AO_LOG_SERIAL_NUMBER:
147 case AltosLib.AO_LOG_SOFTWARE_VERSION:
152 public AltosEepromTM (AltosEepromChunk chunk, int start) throws ParseException {
154 cmd = chunk.data(start);
157 tick_valid = !chunk.erased(start, record_length);
159 if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
160 throw new ParseException(String.format("invalid checksum at 0x%x",
161 chunk.address + start), 0);
163 cmd = AltosLib.AO_LOG_INVALID;
166 tick = chunk.data16(start + 2);
167 a = chunk.data16(start + 4);
168 b = chunk.data16(start + 6);
173 public AltosEepromTM (String line) {
180 cmd = AltosLib.AO_LOG_INVALID;
184 String[] tokens = line.split("\\s+");
186 if (tokens[0].length() == 1) {
187 if (tokens.length != 4) {
188 cmd = AltosLib.AO_LOG_INVALID;
191 cmd = tokens[0].codePointAt(0);
192 tick = Integer.parseInt(tokens[1],16);
194 a = Integer.parseInt(tokens[2],16);
195 b = Integer.parseInt(tokens[3],16);
197 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
198 cmd = AltosLib.AO_LOG_CONFIG_VERSION;
200 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
201 cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
202 a = Integer.parseInt(tokens[2]);
203 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
204 cmd = AltosLib.AO_LOG_APOGEE_DELAY;
205 a = Integer.parseInt(tokens[2]);
206 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
207 cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
208 a = Integer.parseInt(tokens[2]);
209 } else if (tokens[0].equals("Callsign:")) {
210 cmd = AltosLib.AO_LOG_CALLSIGN;
211 data = tokens[1].replaceAll("\"","");
212 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
213 cmd = AltosLib.AO_LOG_ACCEL_CAL;
214 a = Integer.parseInt(tokens[3]);
215 b = Integer.parseInt(tokens[5]);
216 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
217 cmd = AltosLib.AO_LOG_RADIO_CAL;
218 a = Integer.parseInt(tokens[2]);
219 } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
220 cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
221 a = Integer.parseInt(tokens[3]);
222 } else if (tokens[0].equals("manufacturer")) {
223 cmd = AltosLib.AO_LOG_MANUFACTURER;
225 } else if (tokens[0].equals("product")) {
226 cmd = AltosLib.AO_LOG_PRODUCT;
228 } else if (tokens[0].equals("serial-number")) {
229 cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
230 a = Integer.parseInt(tokens[1]);
231 } else if (tokens[0].equals("log-format")) {
232 cmd = AltosLib.AO_LOG_LOG_FORMAT;
233 a = Integer.parseInt(tokens[1]);
234 } else if (tokens[0].equals("software-version")) {
235 cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
238 cmd = AltosLib.AO_LOG_INVALID;
241 } catch (NumberFormatException ne) {
242 v cmd = AltosLib.AO_LOG_INVALID;
248 public AltosEepromTM(int in_cmd, int in_tick, int in_a, int in_b) {