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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
25 public class AltosEepromTMini extends AltosEeprom {
30 public static final int record_length = 2;
32 public void write(PrintStream out) {
33 out.printf("%c %4x %4x %4x\n", cmd, tick, a, b);
36 public int record_length() { return record_length; }
38 public String string() {
39 return String.format("%c %4x %4x %4x\n", cmd, tick, a, b);
42 public void update_state(AltosState state) {
43 super.update_state(state);
46 case AltosLib.AO_LOG_FLIGHT:
47 state.set_state(AltosLib.ao_flight_boost);
50 case AltosLib.AO_LOG_PRESSURE:
52 state.set_ground_pressure(AltosConvert.barometer_to_pressure(b));
54 state.set_pressure(AltosConvert.barometer_to_pressure(b));
56 case AltosLib.AO_LOG_STATE:
62 public AltosEepromTMini (AltosEepromChunk chunk, int start, AltosState state) throws ParseException {
63 int value = chunk.data16(start);
65 int i = (chunk.address + start) / record_length;
67 cmd = chunk.data(start);
70 valid = !chunk.erased(start, record_length);
74 cmd = AltosLib.AO_LOG_FLIGHT;
80 cmd = AltosLib.AO_LOG_PRESSURE;
86 if ((value & 0x8000) != 0) {
87 cmd = AltosLib.AO_LOG_STATE;
93 tick = state.tick + 10;
95 tick = state.tick + 100;
96 cmd = AltosLib.AO_LOG_PRESSURE;
104 public AltosEepromTMini (String line) {
110 cmd = AltosLib.AO_LOG_INVALID;
113 String[] tokens = line.split("\\s+");
115 if (tokens[0].length() == 1) {
116 if (tokens.length != 4) {
117 cmd = AltosLib.AO_LOG_INVALID;
119 cmd = tokens[0].codePointAt(0);
120 tick = Integer.parseInt(tokens[1],16);
122 a = Integer.parseInt(tokens[2],16);
123 b = Integer.parseInt(tokens[3],16);
126 cmd = AltosLib.AO_LOG_INVALID;
128 } catch (NumberFormatException ne) {
129 cmd = AltosLib.AO_LOG_INVALID;
134 public AltosEepromTMini(int in_cmd, int in_tick, int in_a, int in_b) {
142 static public LinkedList<AltosEeprom> read(FileInputStream input) {
143 LinkedList<AltosEeprom> tms = new LinkedList<AltosEeprom>();
147 String line = AltosLib.gets(input);
150 AltosEepromTMini tm = new AltosEepromTMini(line);
152 } catch (IOException ie) {