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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
33 public class AltosEepromRecord {
39 public boolean tick_valid;
41 int[] ParseHex(String line) {
42 String[] tokens = line.split("\\s+");
43 int[] array = new int[tokens.length];
45 for (int i = 0; i < tokens.length; i++)
47 array[i] = Integer.parseInt(tokens[i], 16);
48 } catch (NumberFormatException ne) {
54 int checksum(int[] line) {
56 for (int i = 1; i < line.length; i++)
61 public AltosEepromRecord (AltosSerial serial_line, int addr)
62 throws TimeoutException, ParseException, InterruptedException {
63 String line = serial_line.get_reply(5000);
65 throw new TimeoutException();
66 int[] values = ParseHex(line);
68 if (values == null || values.length < 9) {
69 System.out.printf("invalid line %s", line);
70 throw new ParseException(String.format("inalid line %s", line), 0);
72 if (values[0] != (addr & 0xff))
73 throw new ParseException(String.format("data address out of sync at 0x%x",
75 if (checksum(values) != 0)
76 throw new ParseException(String.format("invalid checksum at 0x%x", addr), 0);
79 tick = values[3] + (values[4] << 8);
80 a = values[5] + (values[6] << 8);
81 b = values[7] + (values[8] << 8);
86 public AltosEepromRecord (String line) {
93 cmd = Altos.AO_LOG_INVALID;
97 String[] tokens = line.split("\\s+");
99 if (tokens[0].length() == 1) {
100 if (tokens.length != 4) {
101 cmd = Altos.AO_LOG_INVALID;
104 cmd = tokens[0].codePointAt(0);
105 tick = Integer.parseInt(tokens[1],16);
107 a = Integer.parseInt(tokens[2],16);
108 b = Integer.parseInt(tokens[3],16);
110 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
111 cmd = Altos.AO_LOG_CONFIG_VERSION;
113 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
114 cmd = Altos.AO_LOG_MAIN_DEPLOY;
115 a = Integer.parseInt(tokens[2]);
116 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
117 cmd = Altos.AO_LOG_APOGEE_DELAY;
118 a = Integer.parseInt(tokens[2]);
119 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
120 cmd = Altos.AO_LOG_RADIO_CHANNEL;
121 a = Integer.parseInt(tokens[2]);
122 } else if (tokens[0].equals("Callsign:")) {
123 cmd = Altos.AO_LOG_CALLSIGN;
124 data = tokens[1].replaceAll("\"","");
125 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
126 cmd = Altos.AO_LOG_ACCEL_CAL;
127 a = Integer.parseInt(tokens[3]);
128 b = Integer.parseInt(tokens[5]);
129 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
130 cmd = Altos.AO_LOG_RADIO_CAL;
131 a = Integer.parseInt(tokens[2]);
132 } else if (tokens[0].equals("manufacturer")) {
133 cmd = Altos.AO_LOG_MANUFACTURER;
135 } else if (tokens[0].equals("product")) {
136 cmd = Altos.AO_LOG_PRODUCT;
138 } else if (tokens[0].equals("serial-number")) {
139 cmd = Altos.AO_LOG_SERIAL_NUMBER;
140 a = Integer.parseInt(tokens[1]);
141 } else if (tokens[0].equals("software-version")) {
142 cmd = Altos.AO_LOG_SOFTWARE_VERSION;
145 cmd = Altos.AO_LOG_INVALID;
148 } catch (NumberFormatException ne) {
149 cmd = Altos.AO_LOG_INVALID;
155 public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) {