X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosEepromRecord.java;h=d8a07951a72369f7a73fa7cecd45565bb3c51476;hp=584a04b7c6c053e9a261f1368a603bbb1790c844;hb=0820f5c6dfe067590f36e8201a4049719dcf3d7c;hpb=440d52e34364fdeeddc76a2d744cc6d1c934364f diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java index 584a04b7..d8a07951 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/AltosEepromRecord.java @@ -38,49 +38,27 @@ public class AltosEepromRecord { public String data; public boolean tick_valid; - int[] ParseHex(String line) { - String[] tokens = line.split("\\s+"); - int[] array = new int[tokens.length]; + static final int record_length = 8; - for (int i = 0; i < tokens.length; i++) - try { - array[i] = Integer.parseInt(tokens[i], 16); - } catch (NumberFormatException ne) { - return null; - } - return array; - } + public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException { - int checksum(int[] line) { - int csum = 0x5a; - for (int i = 1; i < line.length; i++) - csum += line[i]; - 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); + cmd = chunk.data(start); + tick_valid = true; - if (values == null || values.length < 9) { - System.out.printf("invalid line %s", line); - throw new ParseException(String.format("inalid line %s", line), 0); + tick_valid = !chunk.erased(start, record_length); + if (tick_valid) { + if (AltosConvert.checksum(chunk.data, start, record_length) != 0) + throw new ParseException(String.format("invalid checksum at 0x%x", + chunk.address + start), 0); + } else { + cmd = Altos.AO_LOG_INVALID; } - 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); + tick = chunk.data16(start + 2); + a = chunk.data16(start + 4); + b = chunk.data16(start + 6); + data = null; - tick_valid = true; } public AltosEepromRecord (String line) { @@ -129,6 +107,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]; @@ -138,6 +119,9 @@ public class AltosEepromRecord { } else if (tokens[0].equals("serial-number")) { cmd = Altos.AO_LOG_SERIAL_NUMBER; a = Integer.parseInt(tokens[1]); + } else if (tokens[0].equals("log-format")) { + cmd = Altos.AO_LOG_LOG_FORMAT; + a = Integer.parseInt(tokens[1]); } else if (tokens[0].equals("software-version")) { cmd = Altos.AO_LOG_SOFTWARE_VERSION; data = tokens[1];