summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-08-13 18:36:18 -0700
committerKeith Packard <keithp@keithp.com>2011-08-13 18:46:12 -0700
commit5a3e96bef31959a287b8696778d7d8cf911a7dc4 (patch)
treeff79067dfa7e8cc2477016717951338d789a1e5d
parentb0ec30de37aa822ba66d25ceaa8cf8dc967b4371 (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>
-rw-r--r--altosui/AltosConvert.java20
-rw-r--r--altosui/AltosEepromChunk.java7
-rw-r--r--altosui/AltosEepromRecord.java30
3 files changed, 30 insertions, 27 deletions
diff --git a/altosui/AltosConvert.java b/altosui/AltosConvert.java
index c2ae9a50..207470a5 100644
--- a/altosui/AltosConvert.java
+++ b/altosui/AltosConvert.java
@@ -220,4 +220,24 @@ public class AltosConvert {
static double radio_channel_to_frequency(int channel) {
return 434.550 + channel * 0.100;
}
+
+ static 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;
+ }
+
+ static int checksum(int[] data, int start, int length) {
+ int csum = 0x5a;
+ for (int i = 0; i < length; i++)
+ csum += data[i + start];
+ return csum & 0xff;
+ }
}
diff --git a/altosui/AltosEepromChunk.java b/altosui/AltosEepromChunk.java
index 1e42077f..fb632a3f 100644
--- a/altosui/AltosEepromChunk.java
+++ b/altosui/AltosEepromChunk.java
@@ -52,6 +52,13 @@ public class AltosEepromChunk {
return data[offset] | (data[offset + 1] << 8);
}
+ boolean erased(int start, int len) {
+ for (int i = 0; i < len; i++)
+ if (data[start+i] != 0xff)
+ return false;
+ return true;
+ }
+
public AltosEepromChunk(AltosSerial serial_line, int block)
throws TimeoutException, InterruptedException {
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);