- if (tokens[0].length() == 1) {
- if (tokens.length == 2 + data_length) {
- cmd = tokens[0].codePointAt(0);
- tick = Integer.parseInt(tokens[1],16);
- valid = true;
- data8 = new int[data_length];
- for (int i = 0; i < data_length; i++)
- data8[i] = Integer.parseInt(tokens[2 + i],16);
+ /* Make sure there's at least a type and time */
+ if (tokens.length < 2)
+ break;
+
+ /* packet type */
+ if (tokens[0].length() != 1)
+ break;
+ int start = data.size();
+
+ if (config_data().log_format != AltosLib.AO_LOG_FORMAT_TINY) {
+ byte cmd = (byte) tokens[0].codePointAt(0);
+ data.add(cmd);
+
+ int time = AltosLib.fromhex(tokens[1]);
+
+ data.add((byte) 0);
+ data.add((byte) (time & 0xff));
+ data.add((byte) (time >> 8));
+ }
+ if (tokens.length == 4) {
+ /* Handle ancient log files */
+ if (config_data().log_format == AltosLib.AO_LOG_FORMAT_TINY) {
+ /*
+ * Ancient TeleMini log files stored "extra" data to pretend
+ * that it was a TeleMetrum device. Throw that away and
+ * just save the actual log data.
+ */
+ int a = AltosLib.fromhex(tokens[2]);
+ int b = AltosLib.fromhex(tokens[3]);
+ if (a != 0)
+ b = 0x8000 | a;
+ data.add((byte) (b & 0xff));
+ data.add((byte) ((b >> 8)));
+ } else {
+ for (int i = 2; i < tokens.length; i++) {
+ int v = AltosLib.fromhex(tokens[i]);
+ data.add((byte) (v & 0xff));
+ data.add((byte) ((v >> 8)));
+ }
+ /* Re-compute the checksum byte */
+ data.set(start + 1, (byte) (256 - AltosConvert.checksum(data, start, data.size() - start)));