altosui: Adjust max log setting for storage block size
authorKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 03:52:09 +0000 (20:52 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 04:17:55 +0000 (21:17 -0700)
Need to round log sizes down to a multiple of the block size so that
erasing works sensibly on the device.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConfigData.java
altosui/AltosConfigFC.java
altosui/AltosConfigFCUI.java
altosuilib/AltosEepromDelete.java
telegps/TeleGPSConfigUI.java

index dc9fd6b378ec6708ac2aaebede9c18fc0b729ec8..2d22e7b677dfba0b4ebd1e9efbb2bea9c9ac27ca 100644 (file)
@@ -735,7 +735,7 @@ public class AltosConfigData {
 
                dest.set_flight_log_max_enabled(max_enabled);
                dest.set_radio_enable(radio_enable);
-               dest.set_flight_log_max_limit(log_space() / 1024);
+               dest.set_flight_log_max_limit(log_space() >> 10, storage_erase_unit >> 10);
                dest.set_flight_log_max(flight_log_max);
                dest.set_ignite_mode(ignite_mode);
                dest.set_pad_orientation(pad_orientation);
@@ -828,7 +828,7 @@ public class AltosConfigData {
                        link.printf("c a %d %d\n", plus, minus);
 
                /* HAS_LOG */
-               if (flight_log_max != 0)
+               if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
                        link.printf("c l %d\n", flight_log_max);
 
                /* HAS_IGNITE */
index 66afd8a0d3521f89d01ddd1e9aa4ea8fbc1aab1c..20ca311e30d1ce7b9e4e67d6f8f38c27606b0ea3 100644 (file)
@@ -232,7 +232,9 @@ public class AltosConfigFC implements ActionListener {
 
                try {
                        /* bounds check stuff */
-                       if (config_ui.flight_log_max() > data.log_space() / 1024) {
+                       if (config_ui.flight_log_max() != AltosLib.MISSING &&
+                           config_ui.flight_log_max() > data.log_space() / 1024)
+                       {
                                JOptionPane.showMessageDialog(owner,
                                                              String.format("Requested flight log, %dk, is larger than the available space, %dk.\n",
                                                                            config_ui.flight_log_max(),
index 2eb6ae752c73f70ba7eed833ebce4ff1ab95eda2..b7dc70bf4cb9d1aa6d0fbca9456b63e08e885932 100644 (file)
@@ -1271,16 +1271,18 @@ public class AltosConfigFCUI
                return AltosLib.MISSING;
        }
 
-       public void set_flight_log_max_limit(int new_flight_log_max_limit) {
+       public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
                flight_log_max_limit = new_flight_log_max_limit;
                if (new_flight_log_max_limit != AltosLib.MISSING) {
                        flight_log_max_value.removeAllItems();
                        for (int i = 8; i >= 1; i--) {
                                int     size = flight_log_max_limit / i;
+                               if (new_storage_erase_unit != 0)
+                                       size &= ~(new_storage_erase_unit - 1);
                                flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
                        }
                }
-               if (flight_log_max != 0)
+               if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
                        set_flight_log_max(flight_log_max);
        }
 
index ff1b15c85719c319a616ddd2fb763b5ab1ce96b3..214ae530fafc92bd3e1196676efad5c134494698 100644 (file)
@@ -45,11 +45,13 @@ public class AltosEepromDelete implements Runnable {
                        serial_line.printf("d %d\n", log.flight);
                        for (;;) {
                                /* It can take a while to erase the flash... */
-                               String line = serial_line.get_reply(20000);
+                               String line = serial_line.get_reply(200000);
                                if (line == null)
                                        throw new TimeoutException();
                                if (line.equals("Erased"))
                                        break;
+                               if (line.equals("Failed to erase"))
+                                       throw new IOException(line);
                                if (line.startsWith("No such"))
                                        throw new IOException(line);
                        }
index 1a951309e331cec9644e7cbafd4f9705ead52558..7c5d186e9864728f5b959b69e594e21c69314768 100644 (file)
@@ -874,14 +874,18 @@ public class TeleGPSConfigUI
                return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
        }
 
-       public void set_flight_log_max_limit(int new_flight_log_max_limit) {
+       public void set_flight_log_max_limit(int new_flight_log_max_limit, int new_storage_erase_unit) {
                flight_log_max_limit = new_flight_log_max_limit;
-               flight_log_max_value.removeAllItems();
-               for (int i = 8; i >= 1; i--) {
-                       int     size = flight_log_max_limit / i;
-                       flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
+               if (new_flight_log_max_limit != AltosLib.MISSING) {
+                       flight_log_max_value.removeAllItems();
+                       for (int i = 8; i >= 1; i--) {
+                               int     size = flight_log_max_limit / i;
+                               if (new_storage_erase_unit != 0)
+                                       size &= ~(new_storage_erase_unit - 1);
+                               flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
+                       }
                }
-               if (flight_log_max != 0)
+               if (flight_log_max != 0 && flight_log_max != AltosLib.MISSING)
                        set_flight_log_max(flight_log_max);
        }