diff options
| author | Keith Packard <keithp@keithp.com> | 2011-08-13 18:36:18 -0700 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2011-08-13 18:46:12 -0700 |
| commit | 5a3e96bef31959a287b8696778d7d8cf911a7dc4 (patch) | |
| tree | ff79067dfa7e8cc2477016717951338d789a1e5d /altosui/AltosEepromRecord.java | |
| parent | b0ec30de37aa822ba66d25ceaa8cf8dc967b4371 (diff) | |
altosui: Clean up eeprom parsing a bit
Export basic parsing and checksum functions for shared use.
Create 'erased' function to check a chunk of eeprom data for data.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosEepromRecord.java')
| -rw-r--r-- | altosui/AltosEepromRecord.java | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/altosui/AltosEepromRecord.java b/altosui/AltosEepromRecord.java index c0f97035..d8a07951 100644 --- a/altosui/AltosEepromRecord.java +++ b/altosui/AltosEepromRecord.java @@ -40,42 +40,18 @@ public class AltosEepromRecord { 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) + 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; - tick_valid = false; } tick = chunk.data16(start + 2); |
