/* 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";
/* Map directory -- hangs of logdir */
static File mapdir;
- /* Channel (map serial to channel) */
- static Hashtable<Integer, Integer> channels;
+ /* Frequency (map serial to frequency) */
+ static Hashtable<Integer, Double> frequencies;
/* Telemetry (map serial to telemetry format) */
static Hashtable<Integer, Integer> telemetries;
/* Serial debug */
static boolean serial_debug;
+ /* 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");
if (!mapdir.exists())
mapdir.mkdirs();
- channels = new Hashtable<Integer,Integer>();
+ frequencies = new Hashtable<Integer, Double>();
telemetries = new Hashtable<Integer,Integer>();
serial_debug = preferences.getBoolean(serialDebugPreference, false);
AltosSerial.set_debug(serial_debug);
+
+ common_frequencies = load_common_frequencies();
}
static { init(); }
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) {
if (telemetries.containsKey(serial))
return telemetries.get(serial);
int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
- Altos.ao_telemetry_full);
+ Altos.ao_telemetry_standard);
telemetries.put(serial, telemetry);
return telemetry;
}
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);
+ }
}