2 * Copyright © 2011 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 AltosEepromMini {
27 public int config_a, config_b;
31 public static final int record_length = 16;
32 static final int header_length = 4;
33 static final int data_length = record_length - header_length;
35 public int data8(int i) {
39 public int data16(int i) {
40 return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16;
43 public int data24(int i) {
44 return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16);
47 public int data32(int i) {
48 return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
51 /* AO_LOG_FLIGHT elements */
52 public int flight() { return data16(0); }
53 public int ground_pres() { return data32(4); }
55 /* AO_LOG_STATE elements */
56 public int state() { return data16(0); }
57 public int reason() { return data16(2); }
59 /* AO_LOG_SENSOR elements */
60 public int pres() { return data24(0); }
61 public int temp() { return data24(3); }
62 public int sense_a() { return data16(6); }
63 public int sense_m() { return data16(8); }
64 public int v_batt() { return data16(10); }
66 public AltosEepromMini (AltosEepromChunk chunk, int start) throws ParseException {
67 cmd = chunk.data(start);
69 valid = !chunk.erased(start, record_length);
71 if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
72 throw new ParseException(String.format("invalid checksum at 0x%x",
73 chunk.address + start), 0);
75 cmd = AltosLib.AO_LOG_INVALID;
78 tick = chunk.data16(start+2);
80 data8 = new int[data_length];
81 for (int i = 0; i < data_length; i++)
82 data8[i] = chunk.data(start + header_length + i);
85 public AltosEepromMini (String line) {
90 cmd = AltosLib.AO_LOG_INVALID;
94 String[] tokens = line.split("\\s+");
96 if (tokens[0].length() == 1) {
97 if (tokens.length != 2 + data_length) {
98 cmd = AltosLib.AO_LOG_INVALID;
101 cmd = tokens[0].codePointAt(0);
102 tick = Integer.parseInt(tokens[1],16);
104 data8 = new int[data_length];
105 for (int i = 0; i < data_length; i++)
106 data8[i] = Integer.parseInt(tokens[2 + i],16);
108 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
109 cmd = AltosLib.AO_LOG_CONFIG_VERSION;
111 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
112 cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
113 config_a = Integer.parseInt(tokens[2]);
114 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
115 cmd = AltosLib.AO_LOG_APOGEE_DELAY;
116 config_a = Integer.parseInt(tokens[2]);
117 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
118 cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
119 config_a = Integer.parseInt(tokens[2]);
120 } else if (tokens[0].equals("Callsign:")) {
121 cmd = AltosLib.AO_LOG_CALLSIGN;
122 data = tokens[1].replaceAll("\"","");
123 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
124 cmd = AltosLib.AO_LOG_ACCEL_CAL;
125 config_a = Integer.parseInt(tokens[3]);
126 config_b = Integer.parseInt(tokens[5]);
127 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
128 cmd = AltosLib.AO_LOG_RADIO_CAL;
129 config_a = Integer.parseInt(tokens[2]);
130 } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
131 cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
132 config_a = Integer.parseInt(tokens[3]);
133 } else if (tokens[0].equals("manufacturer")) {
134 cmd = AltosLib.AO_LOG_MANUFACTURER;
136 } else if (tokens[0].equals("product")) {
137 cmd = AltosLib.AO_LOG_PRODUCT;
139 } else if (tokens[0].equals("serial-number")) {
140 cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
141 config_a = Integer.parseInt(tokens[1]);
142 } else if (tokens[0].equals("log-format")) {
143 cmd = AltosLib.AO_LOG_LOG_FORMAT;
144 config_a = Integer.parseInt(tokens[1]);
145 } else if (tokens[0].equals("software-version")) {
146 cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
148 } else if (tokens[0].equals("ms5607")) {
149 if (tokens[1].equals("reserved:")) {
150 cmd = AltosLib.AO_LOG_BARO_RESERVED;
151 config_a = Integer.parseInt(tokens[2]);
152 } else if (tokens[1].equals("sens:")) {
153 cmd = AltosLib.AO_LOG_BARO_SENS;
154 config_a = Integer.parseInt(tokens[2]);
155 } else if (tokens[1].equals("off:")) {
156 cmd = AltosLib.AO_LOG_BARO_OFF;
157 config_a = Integer.parseInt(tokens[2]);
158 } else if (tokens[1].equals("tcs:")) {
159 cmd = AltosLib.AO_LOG_BARO_TCS;
160 config_a = Integer.parseInt(tokens[2]);
161 } else if (tokens[1].equals("tco:")) {
162 cmd = AltosLib.AO_LOG_BARO_TCO;
163 config_a = Integer.parseInt(tokens[2]);
164 } else if (tokens[1].equals("tref:")) {
165 cmd = AltosLib.AO_LOG_BARO_TREF;
166 config_a = Integer.parseInt(tokens[2]);
167 } else if (tokens[1].equals("tempsens:")) {
168 cmd = AltosLib.AO_LOG_BARO_TEMPSENS;
169 config_a = Integer.parseInt(tokens[2]);
170 } else if (tokens[1].equals("crc:")) {
171 cmd = AltosLib.AO_LOG_BARO_CRC;
172 config_a = Integer.parseInt(tokens[2]);
174 cmd = AltosLib.AO_LOG_INVALID;
178 cmd = AltosLib.AO_LOG_INVALID;
181 } catch (NumberFormatException ne) {
182 cmd = AltosLib.AO_LOG_INVALID;
188 public AltosEepromMini(int in_cmd, int in_tick) {