altosui: Finish moving AltosConfigData to altoslib
[fw/altos] / altosui / AltosEepromChunk.java
index 8eec407df395e4aa3ea3f4265f2a14ce6f7ffa1a..e4d116583db4e49b071983d99df8248e94f82cf5 100644 (file)
@@ -21,6 +21,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.concurrent.*;
+import org.altusmetrum.AltosLib.*;
 
 public class AltosEepromChunk {
 
@@ -52,13 +53,27 @@ public class AltosEepromChunk {
                return data[offset] | (data[offset + 1] << 8);
        }
 
-       public AltosEepromChunk(AltosSerial serial_line, int block)
+       int data32(int offset) {
+               return data[offset] | (data[offset + 1] << 8) |
+                       (data[offset+2] << 16) | (data[offset+3] << 24);
+       }
+
+       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, boolean flush)
                throws TimeoutException, InterruptedException {
 
                int     offset;
 
                data = new int[chunk_size];
                address = block * chunk_size;
+               if (flush)
+                       serial_line.flush_input();
                serial_line.printf("e %x\n", block);
 
                for (offset = 0; offset < chunk_size; offset += per_line) {