altosui: Add support for downloading TeleMini/TeleNano flight logs
[fw/altos] / altosui / AltosEepromLog.java
index 36289b427f48c8a8d5a3786488df4300d691e4ad..4c6deaa065f232dd09f63119e7297708e3d08cf2 100644 (file)
@@ -30,6 +30,10 @@ import java.util.concurrent.*;
 
 import libaltosJNI.*;
 
+/*
+ * Extract a bit of information from an eeprom-stored flight log.
+ */
+
 public class AltosEepromLog {
        int             serial;
        boolean         has_flight;
@@ -42,6 +46,9 @@ public class AltosEepromLog {
        int             hour, minute, second;
        double          lat, lon;
 
+       boolean         download;
+       boolean         delete;
+
        public AltosEepromLog(AltosSerial serial_line, int in_serial,
                              int in_start_block, int in_end_block)
                throws InterruptedException, TimeoutException {
@@ -53,11 +60,29 @@ public class AltosEepromLog {
                end_block = in_end_block;
                serial = in_serial;
 
+               /*
+                * By default, request that every log be downloaded but not deleted
+                */
+               download = true;
+               delete = false;
+               /*
+                * Only look in the first two blocks so that this
+                * process doesn't take a long time
+                */
                if (in_end_block > in_start_block + 2)
                        in_end_block = in_start_block + 2;
 
                for (block = in_start_block; block < in_end_block; block++) {
-                       AltosEepromBlock eeblock = new AltosEepromBlock(serial_line, block);
+                       AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block);
+
+                       if (block == in_start_block) {
+                               if (eechunk.data(0) != Altos.AO_LOG_FLIGHT) {
+                                       flight = eechunk.data16(0);
+                                       has_flight = true;
+                                       break;
+                               }
+                       }
+                       AltosEepromBlock eeblock = new AltosEepromBlock(eechunk);
                        if (eeblock.has_flight) {
                                flight = eeblock.flight;
                                has_flight = true;
@@ -87,12 +112,5 @@ public class AltosEepromLog {
                        if (has_gps && has_flight)
                                break;
                }
-               System.out.printf("Serial %d start block %d end block %d\n",
-                                 serial, start_block, end_block);
-               if (has_flight)
-                       System.out.printf("Flight %d\n", flight);
-               if (has_gps)
-                       System.out.printf("%d-%d-%d %d:%02d:%02d Lat %f Lon %f\n",
-                                         year, month, day, hour, minute, second, lat, lon);
        }
 }