X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosPreferences.java;h=de926b38ca2abca9dfbd5a6fc78b3651c39682a4;hp=c8dee743f2318950efc834da3a917d92aa5d0ddd;hb=cbf54a826d12c49b1b1996be247869d5ff4e2236;hpb=941b90a4905e34936d24a25ca90ac04eb6f5a792 diff --git a/altosui/AltosPreferences.java b/altosui/AltosPreferences.java index c8dee743..de926b38 100644 --- a/altosui/AltosPreferences.java +++ b/altosui/AltosPreferences.java @@ -34,6 +34,9 @@ class AltosPreferences { /* channel preference name */ final static String channelPreferenceFormat = "CHANNEL-%d"; + /* frequency preference name */ + final static String frequencyPreferenceFormat = "FREQUENCY-%d"; + /* telemetry format preference name */ final static String telemetryPreferenceFormat = "TELEMETRY-%d"; @@ -49,6 +52,9 @@ class AltosPreferences { /* serial debug preference name */ final static String serialDebugPreference = "SERIAL-DEBUG"; + /* scanning telemetry preferences name */ + final static String scanningTelemetryPreference = "SCANNING-TELEMETRY"; + /* Default logdir is ~/TeleMetrum */ final static String logdirName = "TeleMetrum"; @@ -61,8 +67,8 @@ class AltosPreferences { /* Map directory -- hangs of logdir */ static File mapdir; - /* Channel (map serial to channel) */ - static Hashtable channels; + /* Frequency (map serial to frequency) */ + static Hashtable frequencies; /* Telemetry (map serial to telemetry format) */ static Hashtable telemetries; @@ -79,6 +85,58 @@ class AltosPreferences { /* Serial debug */ static boolean serial_debug; + /* Scanning telemetry */ + static int scanning_telemetry; + + /* List of frequencies */ + final static String common_frequencies_node_name = "COMMON-FREQUENCIES"; + static AltosFrequency[] common_frequencies; + + final static String frequency_count = "COUNT"; + final static String frequency_format = "FREQUENCY-%d"; + final static String description_format = "DESCRIPTION-%d"; + + static AltosFrequency[] load_common_frequencies() { + AltosFrequency[] frequencies = null; + boolean existing = false; + try { + existing = preferences.nodeExists(common_frequencies_node_name); + } catch (BackingStoreException be) { + existing = false; + } + if (existing) { + Preferences node = preferences.node(common_frequencies_node_name); + int count = node.getInt(frequency_count, 0); + + frequencies = new AltosFrequency[count]; + for (int i = 0; i < count; i++) { + double frequency; + String description; + + frequency = node.getDouble(String.format(frequency_format, i), 0.0); + description = node.get(String.format(description_format, i), null); + frequencies[i] = new AltosFrequency(frequency, description); + } + } else { + frequencies = new AltosFrequency[10]; + for (int i = 0; i < 10; i++) { + frequencies[i] = new AltosFrequency(434.550 + i * .1, + String.format("Channel %d", i)); + } + } + return frequencies; + } + + static void save_common_frequencies(AltosFrequency[] frequencies) { + Preferences node = preferences.node(common_frequencies_node_name); + + node.putInt(frequency_count, frequencies.length); + for (int i = 0; i < frequencies.length; i++) { + node.putDouble(String.format(frequency_format, i), frequencies[i].frequency); + node.put(String.format(description_format, i), frequencies[i].description); + } + } + public static void init() { preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); @@ -96,7 +154,7 @@ class AltosPreferences { if (!mapdir.exists()) mapdir.mkdirs(); - channels = new Hashtable(); + frequencies = new Hashtable(); telemetries = new Hashtable(); @@ -104,6 +162,8 @@ class AltosPreferences { callsign = preferences.get(callsignPreference,"N0CALL"); + scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << Altos.ao_telemetry_standard)); + String firmwaredir_string = preferences.get(firmwaredirPreference, null); if (firmwaredir_string != null) firmwaredir = new File(firmwaredir_string); @@ -112,6 +172,8 @@ class AltosPreferences { serial_debug = preferences.getBoolean(serialDebugPreference, false); AltosSerial.set_debug(serial_debug); + + common_frequencies = load_common_frequencies(); } static { init(); } @@ -188,20 +250,24 @@ class AltosPreferences { return mapdir; } - public static void set_channel(int serial, int new_channel) { - channels.put(serial, new_channel); + public static void set_frequency(int serial, double new_frequency) { + frequencies.put(serial, new_frequency); synchronized (preferences) { - preferences.putInt(String.format(channelPreferenceFormat, serial), new_channel); + preferences.putDouble(String.format(frequencyPreferenceFormat, serial), new_frequency); flush_preferences(); } } - public static int channel(int serial) { - if (channels.containsKey(serial)) - return channels.get(serial); - int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); - channels.put(serial, channel); - return channel; + public static double frequency(int serial) { + if (frequencies.containsKey(serial)) + return frequencies.get(serial); + double frequency = preferences.getDouble(String.format(frequencyPreferenceFormat, serial), 0); + if (frequency == 0.0) { + int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); + frequency = AltosConvert.radio_channel_to_frequency(channel); + } + frequencies.put(serial, frequency); + return frequency; } public static void set_telemetry(int serial, int new_telemetry) { @@ -221,6 +287,18 @@ class AltosPreferences { return telemetry; } + public static void set_scanning_telemetry(int new_scanning_telemetry) { + scanning_telemetry = new_scanning_telemetry; + synchronized (preferences) { + preferences.putInt(scanningTelemetryPreference, scanning_telemetry); + flush_preferences(); + } + } + + public static int scanning_telemetry() { + return scanning_telemetry; + } + public static void set_voice(boolean new_voice) { voice = new_voice; synchronized (preferences) { @@ -273,4 +351,33 @@ class AltosPreferences { public static Preferences bt_devices() { return preferences.node("bt_devices"); } + + public static AltosFrequency[] common_frequencies() { + return common_frequencies; + } + + public static void set_common_frequencies(AltosFrequency[] frequencies) { + common_frequencies = frequencies; + synchronized(preferences) { + save_common_frequencies(frequencies); + flush_preferences(); + } + } + + public static void add_common_frequency(AltosFrequency frequency) { + AltosFrequency[] new_frequencies = new AltosFrequency[common_frequencies.length + 1]; + int i; + + for (i = 0; i < common_frequencies.length; i++) { + if (frequency.frequency == common_frequencies[i].frequency) + return; + if (frequency.frequency < common_frequencies[i].frequency) + break; + new_frequencies[i] = common_frequencies[i]; + } + new_frequencies[i] = frequency; + for (; i < common_frequencies.length; i++) + new_frequencies[i+1] = common_frequencies[i]; + set_common_frequencies(new_frequencies); + } }