altosui: Respect storage limits in flight log max config 0.9.6.0
authorKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 07:00:54 +0000 (00:00 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 07:00:54 +0000 (00:00 -0700)
Compute the maximum flight log using the data returned from the 'f'
command (total storage and erase block size). Limit menu to choices
which fall within this limit, complain if the user asks for too big a value.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfig.java
altosui/AltosConfigData.java
altosui/AltosConfigUI.java

index ffabe2092b0ffd1135529f3464bb8f03067a042c..9a44c1c5a273cd42dbf8c1e181371d3cf20cf4f6 100644 (file)
@@ -76,6 +76,8 @@ public class AltosConfig implements ActionListener {
        int_ref         ignite_mode;
        int_ref         pad_orientation;
        int_ref         radio_setting;
+       int_ref         storage_size;
+       int_ref         storage_erase_unit;
        string_ref      version;
        string_ref      product;
        string_ref      callsign;
@@ -127,6 +129,15 @@ public class AltosConfig implements ActionListener {
                        serial_line.stop_remote();
        }
 
+       int log_limit() {
+               if (storage_size.get() > 0 && storage_erase_unit.get() > 0) {
+                       int     log_limit = storage_size.get() - storage_erase_unit.get();
+                       if (log_limit > 0)
+                               return log_limit / 1024;
+               }
+               return 1024;
+       }
+
        void update_ui() {
                config_ui.set_serial(serial.get());
                config_ui.set_product(product.get());
@@ -135,6 +146,7 @@ public class AltosConfig implements ActionListener {
                config_ui.set_apogee_delay(apogee_delay.get());
                config_ui.set_radio_calibration(radio_calibration.get());
                config_ui.set_radio_frequency(frequency());
+               config_ui.set_flight_log_max_limit(log_limit());
                config_ui.set_flight_log_max(flight_log_max.get());
                config_ui.set_ignite_mode(ignite_mode.get());
                config_ui.set_pad_orientation(pad_orientation.get());
@@ -163,6 +175,8 @@ public class AltosConfig implements ActionListener {
                get_int(line, "Ignite mode:", ignite_mode);
                get_int(line, "Pad orientation:", pad_orientation);
                get_int(line, "Radio setting:", radio_setting);
+               get_int(line, "Storage size:", storage_size);
+               get_int(line, "Storage erase unit:", storage_erase_unit);
                get_string(line, "Callsign:", callsign);
                get_string(line,"software-version", version);
                get_string(line,"product", product);
@@ -192,7 +206,7 @@ public class AltosConfig implements ActionListener {
                void get_data() {
                        try {
                                config.start_serial();
-                               config.serial_line.printf("c s\nv\n");
+                               config.serial_line.printf("c s\nf\nv\n");
                                for (;;) {
                                        try {
                                                String line = config.serial_line.get_reply(5000);
@@ -230,9 +244,7 @@ public class AltosConfig implements ActionListener {
                                                                radio_calibration.get());
                                if (remote) {
                                        serial_line.stop_remote();
-                                       serial_line.set_radio_frequency(frequency,
-                                                                       has_setting,
-                                                                       radio_calibration.get());
+                                       serial_line.set_radio_frequency(frequency);
                                        AltosPreferences.set_frequency(device.getSerial(), frequency);
                                        serial_line.start_remote();
                                }
@@ -340,13 +352,27 @@ public class AltosConfig implements ActionListener {
        }
 
        void save_data() {
+
+               /* bounds check stuff */
+               if (config_ui.flight_log_max() > log_limit()) {
+                       JOptionPane.showMessageDialog(owner,
+                                                     String.format("Requested flight log, %dk, is larger than the available space, %dk.\n",
+                                                                   config_ui.flight_log_max(),
+                                                                   log_limit()),
+                                                     "Maximum Flight Log Too Large",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return;
+               }
+
                main_deploy.set(config_ui.main_deploy());
                apogee_delay.set(config_ui.apogee_delay());
                radio_calibration.set(config_ui.radio_calibration());
                set_frequency(config_ui.radio_frequency());
                flight_log_max.set(config_ui.flight_log_max());
-               ignite_mode.set(config_ui.ignite_mode());
-               pad_orientation.set(config_ui.pad_orientation());
+               if (ignite_mode.get() >= 0)
+                       ignite_mode.set(config_ui.ignite_mode());
+               if (pad_orientation.get() >= 0)
+                       pad_orientation.set(config_ui.pad_orientation());
                callsign.set(config_ui.callsign());
                run_serial_thread(serial_mode_save);
        }
@@ -385,6 +411,8 @@ public class AltosConfig implements ActionListener {
                flight_log_max = new int_ref(0);
                ignite_mode = new int_ref(-1);
                pad_orientation = new int_ref(-1);
+               storage_size = new int_ref(-1);
+               storage_erase_unit = new int_ref(-1);
                callsign = new string_ref("N0CALL");
                version = new string_ref("unknown");
                product = new string_ref("unknown");
index 710231d74c827fb7380c40f698dd5a04e6d8582f..272dd402aaae4713d134f4fc24c75e907079fa4a 100644 (file)
@@ -54,7 +54,8 @@ public class AltosConfigData implements Iterable<String> {
        int     radio_calibration;
        int     flight_log_max;
        int     ignite_mode;
-
+       int     storage_size;
+       int     storage_erase_unit;
 
        static String get_string(String line, String label) throws  ParseException {
                if (line.startsWith(label)) {
@@ -84,7 +85,7 @@ public class AltosConfigData implements Iterable<String> {
        }
 
        public AltosConfigData(AltosSerial serial_line) throws InterruptedException, TimeoutException {
-               serial_line.printf("c s\nv\n");
+               serial_line.printf("c s\nf\nv\n");
                lines = new LinkedList<String>();
                radio_setting = 0;
                for (;;) {
@@ -116,6 +117,9 @@ public class AltosConfigData implements Iterable<String> {
                        try { version = get_string(line,"software-version"); } catch (Exception e) {}
                        try { product = get_string(line,"product"); } catch (Exception e) {}
 
+                       try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
+                       try { storage_erase_unit = get_int(line, "Storage erase unit"); } catch (Exception e) {}
+
                        /* signals the end of the version info */
                        if (line.startsWith("software-version"))
                                break;
index 71664c915797a502c1aeeadfd13bdbde1ea94312..63e0ba78888105e32b8c746acb5b0918e5fddd91 100644 (file)
@@ -577,6 +577,18 @@ public class AltosConfigUI
                return Integer.parseInt(flight_log_max_value.getSelectedItem().toString());
        }
 
+       public void set_flight_log_max_limit(int flight_log_max_limit) {
+               boolean any_added = false;
+               flight_log_max_value.removeAllItems();
+               for (int i = 0; i < flight_log_max_values.length; i++) {
+                       if (Integer.parseInt(flight_log_max_values[i]) < flight_log_max_limit){
+                               flight_log_max_value.addItem(flight_log_max_values[i]);
+                               any_added = true;
+                       }
+               }
+               flight_log_max_value.addItem(String.format("%d", flight_log_max_limit));
+       }
+
        public void set_ignite_mode(int new_ignite_mode) {
                if (new_ignite_mode < 0) {
                        ignite_mode_value.setEnabled(false);
@@ -588,7 +600,10 @@ public class AltosConfigUI
        }
 
        public int ignite_mode() {
-               return ignite_mode_value.getSelectedIndex();
+               if (ignite_mode_value.isEnabled())
+                       return ignite_mode_value.getSelectedIndex();
+               else
+                       return -1;
        }
 
 
@@ -603,7 +618,10 @@ public class AltosConfigUI
        }
 
        public int pad_orientation() {
-               return pad_orientation_value.getSelectedIndex();
+               if (pad_orientation_value.isEnabled())
+                       return pad_orientation_value.getSelectedIndex();
+               else
+                       return -1;
        }
 
        public void set_clean() {