new toolchain for STM32L is in /usr/bin, not /opt/cortex/bin
[fw/altos] / altoslib / AltosEepromRecord.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.altoslib_1;
19
20 import java.text.*;
21
22 public class AltosEepromRecord {
23         public int      cmd;
24         public int      tick;
25         public int      a;
26         public int      b;
27         public String   data;
28         public boolean  tick_valid;
29
30         public static final int record_length = 8;
31
32         public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException {
33
34                 cmd = chunk.data(start);
35                 tick_valid = true;
36
37                 tick_valid = !chunk.erased(start, record_length);
38                 if (tick_valid) {
39                         if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
40                                 throw new ParseException(String.format("invalid checksum at 0x%x",
41                                                                        chunk.address + start), 0);
42                 } else {
43                         cmd = AltosLib.AO_LOG_INVALID;
44                 }
45
46                 tick = chunk.data16(start + 2);
47                 a = chunk.data16(start + 4);
48                 b = chunk.data16(start + 6);
49
50                 data = null;
51         }
52
53         public AltosEepromRecord (String line) {
54                 tick_valid = false;
55                 tick = 0;
56                 a = 0;
57                 b = 0;
58                 data = null;
59                 if (line == null) {
60                         cmd = AltosLib.AO_LOG_INVALID;
61                         data = "";
62                 } else {
63                         try {
64                                 String[] tokens = line.split("\\s+");
65
66                                 if (tokens[0].length() == 1) {
67                                         if (tokens.length != 4) {
68                                                 cmd = AltosLib.AO_LOG_INVALID;
69                                                 data = line;
70                                         } else {
71                                                 cmd = tokens[0].codePointAt(0);
72                                                 tick = Integer.parseInt(tokens[1],16);
73                                                 tick_valid = true;
74                                                 a = Integer.parseInt(tokens[2],16);
75                                                 b = Integer.parseInt(tokens[3],16);
76                                         }
77                                 } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
78                                         cmd = AltosLib.AO_LOG_CONFIG_VERSION;
79                                         data = tokens[2];
80                                 } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
81                                         cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
82                                         a = Integer.parseInt(tokens[2]);
83                                 } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
84                                         cmd = AltosLib.AO_LOG_APOGEE_DELAY;
85                                         a = Integer.parseInt(tokens[2]);
86                                 } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
87                                         cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
88                                         a = Integer.parseInt(tokens[2]);
89                                 } else if (tokens[0].equals("Callsign:")) {
90                                         cmd = AltosLib.AO_LOG_CALLSIGN;
91                                         data = tokens[1].replaceAll("\"","");
92                                 } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
93                                         cmd = AltosLib.AO_LOG_ACCEL_CAL;
94                                         a = Integer.parseInt(tokens[3]);
95                                         b = Integer.parseInt(tokens[5]);
96                                 } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
97                                         cmd = AltosLib.AO_LOG_RADIO_CAL;
98                                         a = Integer.parseInt(tokens[2]);
99                                 } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
100                                         cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
101                                         a = Integer.parseInt(tokens[3]);
102                                 } else if (tokens[0].equals("manufacturer")) {
103                                         cmd = AltosLib.AO_LOG_MANUFACTURER;
104                                         data = tokens[1];
105                                 } else if (tokens[0].equals("product")) {
106                                         cmd = AltosLib.AO_LOG_PRODUCT;
107                                         data = tokens[1];
108                                 } else if (tokens[0].equals("serial-number")) {
109                                         cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
110                                         a = Integer.parseInt(tokens[1]);
111                                 } else if (tokens[0].equals("log-format")) {
112                                         cmd = AltosLib.AO_LOG_LOG_FORMAT;
113                                         a = Integer.parseInt(tokens[1]);
114                                 } else if (tokens[0].equals("software-version")) {
115                                         cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
116                                         data = tokens[1];
117                                 } else {
118                                         cmd = AltosLib.AO_LOG_INVALID;
119                                         data = line;
120                                 }
121                         } catch (NumberFormatException ne) {
122                                 cmd = AltosLib.AO_LOG_INVALID;
123                                 data = line;
124                         }
125                 }
126         }
127
128         public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) {
129                 tick_valid = true;
130                 cmd = in_cmd;
131                 tick = in_tick;
132                 a = in_a;
133                 b = in_b;
134         }
135 }