X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosEepromRecord.java;h=52acb43568c11e48f3a43feb6fc7c475ef45187d;hp=e61a7159f19af1e4673b80ed560623ebeb7c3a47;hb=e905042879147dd86241bf2dcc7437e5a6eb7578;hpb=bd2480fd757b67557d9c7de42e402034002c3e37 diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java index e61a7159..52acb435 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/AltosEepromRecord.java @@ -38,6 +38,8 @@ public class AltosEepromRecord { public String data; public boolean tick_valid; + static final int record_length = 8; + int[] ParseHex(String line) { String[] tokens = line.split("\\s+"); int[] array = new int[tokens.length]; @@ -51,34 +53,36 @@ public class AltosEepromRecord { return array; } - int checksum(int[] line) { + int checksum(int[] data, int start) { int csum = 0x5a; - for (int i = 1; i < line.length; i++) - csum += line[i]; + for (int i = 0; i < record_length; i++) + csum += data[i + start]; return csum & 0xff; } - public AltosEepromRecord (AltosSerial serial_line, int addr) - throws TimeoutException, ParseException, InterruptedException { - String line = serial_line.get_reply(5000); - if (line == null) - throw new TimeoutException(); - int[] values = ParseHex(line); - - if (values == null) - throw new ParseException(String.format("invalid line %s", line), 0); - if (values[0] != (addr & 0xff)) - throw new ParseException(String.format("data address out of sync at 0x%x", - addr), 0); - if (checksum(values) != 0) - throw new ParseException(String.format("invalid checksum at 0x%x", addr), 0); - - cmd = values[1]; - tick = values[3] + (values[4] << 8); - a = values[5] + (values[6] << 8); - b = values[7] + (values[8] << 8); - data = null; + public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException { + + cmd = chunk.data(start); tick_valid = true; + + int i; + for (i = 0; i < record_length; i++) + if (chunk.data[start + i] != 0xff) + break; + if (i != 8) { + if (checksum(chunk.data, start) != 0) + throw new ParseException(String.format("invalid checksum at 0x%x", + chunk.address + start), 0); + } else { + cmd = Altos.AO_LOG_INVALID; + tick_valid = false; + } + + tick = chunk.data16(start + 2); + a = chunk.data16(start + 4); + b = chunk.data16(start + 6); + + data = null; } public AltosEepromRecord (String line) { @@ -127,6 +131,9 @@ public class AltosEepromRecord { } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) { cmd = Altos.AO_LOG_RADIO_CAL; a = Integer.parseInt(tokens[2]); + } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) { + cmd = Altos.AO_LOG_MAX_FLIGHT_LOG; + a = Integer.parseInt(tokens[3]); } else if (tokens[0].equals("manufacturer")) { cmd = Altos.AO_LOG_MANUFACTURER; data = tokens[1];