X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosEepromRecord.java;h=5787af86e6d53fc60640bc35f803c7d71be2c931;hp=5a6738177601a8e60dc9008d01e5ee22599936d6;hb=08e6bbef2c3529dfd468ef221c526fc9f3ed5b81;hpb=f01096c4b42f9a4720ed0414826c2a283a992545 diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java index 5a673817..5787af86 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/AltosEepromRecord.java @@ -26,7 +26,9 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.*; + +import libaltosJNI.*; public class AltosEepromRecord { public int cmd; @@ -36,6 +38,53 @@ 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]; + + for (int i = 0; i < tokens.length; i++) + try { + array[i] = Integer.parseInt(tokens[i], 16); + } catch (NumberFormatException ne) { + return null; + } + return array; + } + + int checksum(int[] data, int start) { + int csum = 0x5a; + for (int i = 0; i < record_length; i++) + csum += data[i + start]; + return csum & 0xff; + } + + 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) { tick_valid = false; tick = 0;