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_3;
24 public class AltosEepromTm extends AltosEeprom {
29 public static final int record_length = 2;
31 public void write(PrintStream out) {
32 out.printf("%c %4x %4x %4x\n", cmd, tick, a, b);
35 public int record_length() { return record_length; }
37 public String string() {
38 return String.format("%c %4x %4x %4x\n", cmd, tick, a, b);
41 public void update_state(AltosState state) {
42 super.update_state(state);
45 case AltosLib.AO_LOG_FLIGHT:
46 state.set_state(AltosLib.ao_flight_boost);
49 case AltosLib.AO_LOG_PRESSURE:
51 state.set_ground_pressure(AltosConvert.barometer_to_pressure(b));
53 state.set_pressure(AltosConvert.barometer_to_pressure(b));
55 case AltosLib.AO_LOG_STATE:
61 public AltosEepromTm (AltosEepromChunk chunk, int start, AltosState state) throws ParseException {
62 int value = chunk.data16(start);
64 int i = (chunk.address + start) / record_length;
66 cmd = chunk.data(start);
69 valid = !chunk.erased(start, record_length);
73 cmd = AltosLib.AO_LOG_FLIGHT;
79 cmd = AltosLib.AO_LOG_PRESSURE;
85 if ((value & 0x8000) != 0) {
86 cmd = AltosLib.AO_LOG_STATE;
92 tick = state.tick + 10;
94 tick = state.tick + 100;
95 cmd = AltosLib.AO_LOG_PRESSURE;
103 public AltosEepromTm (String line) {
109 cmd = AltosLib.AO_LOG_INVALID;
112 String[] tokens = line.split("\\s+");
114 if (tokens[0].length() == 1) {
115 if (tokens.length != 4) {
116 cmd = AltosLib.AO_LOG_INVALID;
118 cmd = tokens[0].codePointAt(0);
119 tick = Integer.parseInt(tokens[1],16);
121 a = Integer.parseInt(tokens[2],16);
122 b = Integer.parseInt(tokens[3],16);
125 cmd = AltosLib.AO_LOG_INVALID;
127 } catch (NumberFormatException ne) {
128 cmd = AltosLib.AO_LOG_INVALID;
133 public AltosEepromTm(int in_cmd, int in_tick, int in_a, int in_b) {
141 static public LinkedList<AltosEeprom> read(FileInputStream input) {
142 LinkedList<AltosEeprom> tms = new LinkedList<AltosEeprom>();
146 String line = AltosLib.gets(input);
149 AltosEepromTm tm = new AltosEepromTm(line);
151 } catch (IOException ie) {