From b98f75dbcccd40c8cbf32c3bfd21bd6f5648b861 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Mar 2012 22:54:17 -0700 Subject: [PATCH] altosui: Sanity check values from device configuration If someone has down-graded and re up-graded the firmware, the config entries may be garbage. Sanity check them to avoid crashing the UI. Signed-off-by: Keith Packard --- altosui/AltosConfig.java | 4 +++- altosui/AltosConfigData.java | 6 +++++- altosui/AltosConfigUI.java | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 84261ec7..8eb71e1f 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -194,7 +194,9 @@ 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, "Frequency:", radio_frequency); + if (get_int(line, "Frequency:", radio_frequency)) + if (radio_frequency.get() < 0) + radio_frequency.set(434550); get_int(line, "Radio enable:", radio_enable); get_int(line, "Storage size:", storage_size); get_int(line, "Storage erase unit:", storage_erase_unit); diff --git a/altosui/AltosConfigData.java b/altosui/AltosConfigData.java index 0608b4d3..53509dfa 100644 --- a/altosui/AltosConfigData.java +++ b/altosui/AltosConfigData.java @@ -156,7 +156,11 @@ public class AltosConfigData implements Iterable { try { apogee_delay = get_int(line, "Apogee delay:"); } catch (Exception e) {} try { radio_channel = get_int(line, "Radio channel:"); } catch (Exception e) {} try { radio_setting = get_int(line, "Radio setting:"); } catch (Exception e) {} - try { radio_frequency = get_int(line, "Frequency:"); } catch (Exception e) {} + try { + radio_frequency = get_int(line, "Frequency:"); + if (radio_frequency < 0) + radio_frequency = 434550; + } catch (Exception e) {} try { if (line.startsWith("Accel cal")) { String[] bits = line.split("\\s+"); diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index c8ec06d2..879605bc 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -708,6 +708,8 @@ public class AltosConfigUI } public void set_ignite_mode(int new_ignite_mode) { + if (new_ignite_mode >= ignite_mode_values.length) + new_ignite_mode = 0; if (new_ignite_mode < 0) { ignite_mode_value.setEnabled(false); new_ignite_mode = 0; @@ -727,6 +729,8 @@ public class AltosConfigUI public void set_pad_orientation(int new_pad_orientation) { + if (new_pad_orientation >= pad_orientation_values.length) + new_pad_orientation = 0; if (new_pad_orientation < 0) { pad_orientation_value.setEnabled(false); new_pad_orientation = 0; -- 2.30.2