summaryrefslogtreecommitdiff
path: root/altosui/altoslib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-01-02 17:26:59 -0800
committerKeith Packard <keithp@keithp.com>2012-01-02 17:26:59 -0800
commit5a249bcabfa2a0f5ae5c620f2b3b93c7dff879fd (patch)
tree6b69cac2077a6c2f58e891f98953187e6925e0d8 /altosui/altoslib
parent7136fd03953a88a9989baff04bd155020a8b8a9a (diff)
altosui: Complete split out of separate java library
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/altoslib')
-rw-r--r--altosui/altoslib/Makefile.am3
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java44
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java4
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java56
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java4
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java14
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java365
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java121
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java14
-rw-r--r--altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java92
10 files changed, 496 insertions, 221 deletions
diff --git a/altosui/altoslib/Makefile.am b/altosui/altoslib/Makefile.am
index 9c655131..967c8d06 100644
--- a/altosui/altoslib/Makefile.am
+++ b/altosui/altoslib/Makefile.am
@@ -18,11 +18,12 @@ AltosLib_JAVA = \
$(SRC)/AltosGPSSat.java \
$(SRC)/AltosLine.java \
$(SRC)/AltosParse.java \
+ $(SRC)/AltosPreferences.java \
$(SRC)/AltosRecordCompanion.java \
$(SRC)/AltosRecordIterable.java \
$(SRC)/AltosRecord.java \
- $(SRC)/AltosTelemetryIterable.java \
$(SRC)/AltosTelemetry.java \
+ $(SRC)/AltosTelemetryIterable.java \
$(SRC)/AltosTelemetryMap.java \
$(SRC)/AltosTelemetryRecordCompanion.java \
$(SRC)/AltosTelemetryRecordConfiguration.java \
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java
index d79dcfd3..d2aa629c 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosConvert.java
@@ -41,27 +41,27 @@ public class AltosConvert {
* in Joules/(kilogram-Kelvin).
*/
- static final double GRAVITATIONAL_ACCELERATION = -9.80665;
- static final double AIR_GAS_CONSTANT = 287.053;
- static final double NUMBER_OF_LAYERS = 7;
- static final double MAXIMUM_ALTITUDE = 84852.0;
- static final double MINIMUM_PRESSURE = 0.3734;
- static final double LAYER0_BASE_TEMPERATURE = 288.15;
- static final double LAYER0_BASE_PRESSURE = 101325;
+ public static final double GRAVITATIONAL_ACCELERATION = -9.80665;
+ public static final double AIR_GAS_CONSTANT = 287.053;
+ public static final double NUMBER_OF_LAYERS = 7;
+ public static final double MAXIMUM_ALTITUDE = 84852.0;
+ public static final double MINIMUM_PRESSURE = 0.3734;
+ public static final double LAYER0_BASE_TEMPERATURE = 288.15;
+ public static final double LAYER0_BASE_PRESSURE = 101325;
/* lapse rate and base altitude for each layer in the atmosphere */
- static final double[] lapse_rate = {
+ public static final double[] lapse_rate = {
-0.0065, 0.0, 0.001, 0.0028, 0.0, -0.0028, -0.002
};
- static final int[] base_altitude = {
+ public static final int[] base_altitude = {
0, 11000, 20000, 32000, 47000, 51000, 71000
};
/* outputs atmospheric pressure associated with the given altitude.
* altitudes are measured with respect to the mean sea level
*/
- static double
+ public static double
altitude_to_pressure(double altitude)
{
double base_temperature = LAYER0_BASE_TEMPERATURE;
@@ -114,7 +114,7 @@ public class AltosConvert {
/* outputs the altitude associated with the given pressure. the altitude
returned is measured with respect to the mean sea level */
- static double
+ public static double
pressure_to_altitude(double pressure)
{
@@ -178,19 +178,19 @@ public class AltosConvert {
return altitude;
}
- static double
+ public static double
cc_battery_to_voltage(double battery)
{
return battery / 32767.0 * 5.0;
}
- static double
+ public static double
cc_ignitor_to_voltage(double ignite)
{
return ignite / 32767 * 15.0;
}
- static double radio_to_frequency(int setting, int cal, int channel) {
+ public static double radio_to_frequency(int setting, int cal, int channel) {
double f;
if (setting <= 0)
@@ -201,13 +201,13 @@ public class AltosConvert {
return f + channel * 0.100;
}
- static int radio_frequency_to_setting(double frequency, int cal) {
+ public static int radio_frequency_to_setting(double frequency, int cal) {
double set = frequency / 434.550 * cal;
return (int) Math.floor (set + 0.5);
}
- static int radio_frequency_to_channel(double frequency) {
+ public static int radio_frequency_to_channel(double frequency) {
int channel = (int) Math.floor ((frequency - 434.550) / 0.100 + 0.5);
if (channel < 0)
@@ -217,11 +217,11 @@ public class AltosConvert {
return channel;
}
- static double radio_channel_to_frequency(int channel) {
+ public static double radio_channel_to_frequency(int channel) {
return 434.550 + channel * 0.100;
}
- static int[] ParseHex(String line) {
+ public static int[] ParseHex(String line) {
String[] tokens = line.split("\\s+");
int[] array = new int[tokens.length];
@@ -234,19 +234,19 @@ public class AltosConvert {
return array;
}
- static double meters_to_feet(double meters) {
+ public static double meters_to_feet(double meters) {
return meters * (100 / (2.54 * 12));
}
- static double meters_to_mach(double meters) {
+ public static double meters_to_mach(double meters) {
return meters / 343; /* something close to mach at usual rocket sites */
}
- static double meters_to_g(double meters) {
+ public static double meters_to_g(double meters) {
return meters / 9.80665;
}
- static int checksum(int[] data, int start, int length) {
+ public static int checksum(int[] data, int start, int length) {
int csum = 0x5a;
for (int i = 0; i < length; i++)
csum += data[i + start];
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java
index d7224b16..57cb9c48 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosFrequency.java
@@ -22,8 +22,8 @@ import java.util.*;
import java.text.*;
public class AltosFrequency {
- double frequency;
- String description;
+ public double frequency;
+ public String description;
public String toString() {
return String.format("%7.3f MHz %-20.20s",
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java
index 8cc7aa69..f078a469 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPS.java
@@ -22,32 +22,32 @@ import java.text.*;
public class AltosGPS {
- final static int MISSING = AltosRecord.MISSING;
-
- int nsat;
- boolean locked;
- boolean connected;
- double lat; /* degrees (+N -S) */
- double lon; /* degrees (+E -W) */
- int alt; /* m */
- int year;
- int month;
- int day;
- int hour;
- int minute;
- int second;
-
- double ground_speed; /* m/s */
- int course; /* degrees */
- double climb_rate; /* m/s */
- double hdop; /* unitless */
- double vdop; /* unitless */
- int h_error; /* m */
- int v_error; /* m */
-
- AltosGPSSat[] cc_gps_sat; /* tracking data */
-
- void ParseGPSDate(String date) throws ParseException {
+ public final static int MISSING = AltosRecord.MISSING;
+
+ public int nsat;
+ public boolean locked;
+ public boolean connected;
+ public double lat; /* degrees (+N -S) */
+ public double lon; /* degrees (+E -W) */
+ public int alt; /* m */
+ public int year;
+ public int month;
+ public int day;
+ public int hour;
+ public int minute;
+ public int second;
+
+ public double ground_speed; /* m/s */
+ public int course; /* degrees */
+ public double climb_rate; /* m/s */
+ public double hdop; /* unitless */
+ public double vdop; /* unitless */
+ public int h_error; /* m */
+ public int v_error; /* m */
+
+ public AltosGPSSat[] cc_gps_sat; /* tracking data */
+
+ public void ParseGPSDate(String date) throws ParseException {
String[] ymd = date.split("-");
if (ymd.length != 3)
throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0);
@@ -56,7 +56,7 @@ public class AltosGPS {
day = AltosParse.parse_int(ymd[2]);
}
- void ParseGPSTime(String time) throws ParseException {
+ public void ParseGPSTime(String time) throws ParseException {
String[] hms = time.split(":");
if (hms.length != 3)
throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0);
@@ -65,7 +65,7 @@ public class AltosGPS {
second = AltosParse.parse_int(hms[2]);
}
- void ClearGPSTime() {
+ public void ClearGPSTime() {
year = month = day = 0;
hour = minute = second = 0;
}
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java
index 5fa8f987..faa1ec8d 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGPSSat.java
@@ -18,8 +18,8 @@
package org.altusmetrum.AltosLib;
public class AltosGPSSat {
- int svid;
- int c_n0;
+ public int svid;
+ public int c_n0;
public AltosGPSSat(int s, int c) {
svid = s;
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java
index 4c0a59cb..7d832f1a 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosParse.java
@@ -21,11 +21,11 @@ import java.text.*;
import java.lang.*;
public class AltosParse {
- static boolean isdigit(char c) {
+ public static boolean isdigit(char c) {
return '0' <= c && c <= '9';
}
- static int parse_int(String v) throws ParseException {
+ public static int parse_int(String v) throws ParseException {
try {
return AltosLib.fromdec(v);
} catch (NumberFormatException e) {
@@ -33,7 +33,7 @@ public class AltosParse {
}
}
- static int parse_hex(String v) throws ParseException {
+ public static int parse_hex(String v) throws ParseException {
try {
return AltosLib.fromhex(v);
} catch (NumberFormatException e) {
@@ -41,7 +41,7 @@ public class AltosParse {
}
}
- static double parse_double(String v) throws ParseException {
+ public static double parse_double(String v) throws ParseException {
try {
return Double.parseDouble(v);
} catch (NumberFormatException e) {
@@ -49,7 +49,7 @@ public class AltosParse {
}
}
- static double parse_coord(String coord) throws ParseException {
+ public static double parse_coord(String coord) throws ParseException {
String[] dsf = coord.split("\\D+");
if (dsf.length != 3) {
@@ -65,13 +65,13 @@ public class AltosParse {
return r;
}
- static String strip_suffix(String v, String suffix) {
+ public static String strip_suffix(String v, String suffix) {
if (v.endsWith(suffix))
return v.substring(0, v.length() - suffix.length());
return v;
}
- static void word(String v, String m) throws ParseException {
+ public static void word(String v, String m) throws ParseException {
if (!v.equals(m)) {
throw new ParseException("error matching '" + v + "' '" + m + "'", 0);
}
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java
new file mode 100644
index 00000000..43c7088d
--- /dev/null
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosPreferences.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.awt.Component;
+import javax.swing.*;
+import javax.swing.filechooser.FileSystemView;
+
+public class AltosPreferences {
+ public static Preferences preferences;
+
+ /* logdir preference name */
+ public final static String logdirPreference = "LOGDIR";
+
+ /* channel preference name */
+ public final static String channelPreferenceFormat = "CHANNEL-%d";
+
+ /* frequency preference name */
+ public final static String frequencyPreferenceFormat = "FREQUENCY-%d";
+
+ /* telemetry format preference name */
+ public final static String telemetryPreferenceFormat = "TELEMETRY-%d";
+
+ /* voice preference name */
+ public final static String voicePreference = "VOICE";
+
+ /* callsign preference name */
+ public final static String callsignPreference = "CALLSIGN";
+
+ /* firmware directory preference name */
+ public final static String firmwaredirPreference = "FIRMWARE";
+
+ /* serial debug preference name */
+ public final static String serialDebugPreference = "SERIAL-DEBUG";
+
+ /* scanning telemetry preferences name */
+ public final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
+
+ /* Launcher serial preference name */
+ public final static String launcherSerialPreference = "LAUNCHER-SERIAL";
+
+ /* Launcher channel preference name */
+ public final static String launcherChannelPreference = "LAUNCHER-CHANNEL";
+
+ /* Default logdir is ~/TeleMetrum */
+ public final static String logdirName = "TeleMetrum";
+
+ /* Log directory */
+ public static File logdir;
+
+ /* Map directory -- hangs of logdir */
+ public static File mapdir;
+
+ /* Frequency (map serial to frequency) */
+ public static Hashtable<Integer, Double> frequencies;
+
+ /* Telemetry (map serial to telemetry format) */
+ public static Hashtable<Integer, Integer> telemetries;
+
+ /* Voice preference */
+ public static boolean voice;
+
+ /* Callsign preference */
+ public static String callsign;
+
+ /* Firmware directory */
+ public static File firmwaredir;
+
+ /* Scanning telemetry */
+ public static int scanning_telemetry;
+
+ /* List of frequencies */
+ public final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
+ public static AltosFrequency[] common_frequencies;
+
+ public final static String frequency_count = "COUNT";
+ public final static String frequency_format = "FREQUENCY-%d";
+ public final static String description_format = "DESCRIPTION-%d";
+
+ public 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;
+ }
+
+ public 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 int launcher_serial;
+
+ public static int launcher_channel;
+
+ public static void init() {
+ preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
+
+ /* Initialize logdir from preferences */
+ String logdir_string = preferences.get(logdirPreference, null);
+ if (logdir_string != null)
+ logdir = new File(logdir_string);
+ else {
+ /* Use the file system view default directory */
+ logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
+ if (!logdir.exists())
+ logdir.mkdirs();
+ }
+ mapdir = new File(logdir, "maps");
+ if (!mapdir.exists())
+ mapdir.mkdirs();
+
+ frequencies = new Hashtable<Integer, Double>();
+
+ telemetries = new Hashtable<Integer,Integer>();
+
+ voice = preferences.getBoolean(voicePreference, true);
+
+ callsign = preferences.get(callsignPreference,"N0CALL");
+
+ scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard));
+
+ launcher_serial = preferences.getInt(launcherSerialPreference, 0);
+
+ launcher_channel = preferences.getInt(launcherChannelPreference, 0);
+
+ String firmwaredir_string = preferences.get(firmwaredirPreference, null);
+ if (firmwaredir_string != null)
+ firmwaredir = new File(firmwaredir_string);
+ else
+ firmwaredir = null;
+
+ common_frequencies = load_common_frequencies();
+
+ }
+
+ static { init(); }
+
+ public static void flush_preferences() {
+ try {
+ preferences.flush();
+ } catch (BackingStoreException ee) {
+/*
+ if (component != null)
+ JOptionPane.showMessageDialog(component,
+ preferences.absolutePath(),
+ "Cannot save prefernces",
+ JOptionPane.ERROR_MESSAGE);
+ else
+*/
+ System.err.printf("Cannot save preferences\n");
+ }
+ }
+
+ public static void set_logdir(File new_logdir) {
+ logdir = new_logdir;
+ mapdir = new File(logdir, "maps");
+ if (!mapdir.exists())
+ mapdir.mkdirs();
+ synchronized (preferences) {
+ preferences.put(logdirPreference, logdir.getPath());
+ flush_preferences();
+ }
+ }
+
+ public static File logdir() {
+ return logdir;
+ }
+
+ public static File mapdir() {
+ return mapdir;
+ }
+
+ public static void set_frequency(int serial, double new_frequency) {
+ frequencies.put(serial, new_frequency);
+ synchronized (preferences) {
+ preferences.putDouble(String.format(frequencyPreferenceFormat, serial), new_frequency);
+ flush_preferences();
+ }
+ }
+
+ 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) {
+ telemetries.put(serial, new_telemetry);
+ synchronized (preferences) {
+ preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry);
+ flush_preferences();
+ }
+ }
+
+ public static int telemetry(int serial) {
+ if (telemetries.containsKey(serial))
+ return telemetries.get(serial);
+ int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial),
+ AltosLib.ao_telemetry_standard);
+ telemetries.put(serial, telemetry);
+ 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) {
+ preferences.putBoolean(voicePreference, voice);
+ flush_preferences();
+ }
+ }
+
+ public static boolean voice() {
+ return voice;
+ }
+
+ public static void set_callsign(String new_callsign) {
+ callsign = new_callsign;
+ synchronized(preferences) {
+ preferences.put(callsignPreference, callsign);
+ flush_preferences();
+ }
+ }
+
+ public static String callsign() {
+ return callsign;
+ }
+
+ public static void set_firmwaredir(File new_firmwaredir) {
+ firmwaredir = new_firmwaredir;
+ synchronized (preferences) {
+ preferences.put(firmwaredirPreference, firmwaredir.getPath());
+ flush_preferences();
+ }
+ }
+
+ public static File firmwaredir() {
+ return firmwaredir;
+ }
+
+ public static void set_launcher_serial(int new_launcher_serial) {
+ launcher_serial = new_launcher_serial;
+ System.out.printf("set launcher serial to %d\n", new_launcher_serial);
+ synchronized (preferences) {
+ preferences.putInt(launcherSerialPreference, launcher_serial);
+ flush_preferences();
+ }
+ }
+
+ public static int launcher_serial() {
+ return launcher_serial;
+ }
+
+ public static void set_launcher_channel(int new_launcher_channel) {
+ launcher_channel = new_launcher_channel;
+ System.out.printf("set launcher channel to %d\n", new_launcher_channel);
+ synchronized (preferences) {
+ preferences.putInt(launcherChannelPreference, launcher_channel);
+ flush_preferences();
+ }
+ }
+
+ public static int launcher_channel() {
+ return launcher_channel;
+ }
+
+ 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);
+ }
+}
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java
index 06fe42b1..08d87410 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecord.java
@@ -23,61 +23,62 @@ import java.util.HashMap;
import java.io.*;
public class AltosRecord implements Comparable <AltosRecord> {
- final static int MISSING = 0x7fffffff;
-
- static final int seen_flight = 1;
- static final int seen_sensor = 2;
- static final int seen_temp_volt = 4;
- static final int seen_deploy = 8;
- static final int seen_gps_time = 16;
- static final int seen_gps_lat = 32;
- static final int seen_gps_lon = 64;
- static final int seen_companion = 128;
- int seen;
-
- int version;
- String callsign;
- int serial;
- int flight;
- int rssi;
- int status;
- int state;
- int tick;
-
- int accel;
- int pres;
- int temp;
- int batt;
- int drogue;
- int main;
-
- int ground_accel;
- int ground_pres;
- int accel_plus_g;
- int accel_minus_g;
-
- double acceleration;
- double speed;
- double height;
-
- int flight_accel;
- int flight_vel;
- int flight_pres;
-
- AltosGPS gps;
- boolean new_gps;
-
- double time; /* seconds since boost */
-
- int device_type;
- int config_major;
- int config_minor;
- int apogee_delay;
- int main_deploy;
- int flight_log_max;
- String firmware_version;
-
- AltosRecordCompanion companion;
+ public final static int MISSING = 0x7fffffff;
+
+ public static final int seen_flight = 1;
+ public static final int seen_sensor = 2;
+ public static final int seen_temp_volt = 4;
+ public static final int seen_deploy = 8;
+ public static final int seen_gps_time = 16;
+ public static final int seen_gps_lat = 32;
+ public static final int seen_gps_lon = 64;
+ public static final int seen_companion = 128;
+ public int seen;
+
+ public int version;
+ public String callsign;
+ public int serial;
+ public int flight;
+ public int rssi;
+ public int status;
+ public int state;
+ public int tick;
+
+ public int accel;
+ public int pres;
+ public int temp;
+ public int batt;
+ public int drogue;
+ public int main;
+
+ public int ground_accel;
+ public int ground_pres;
+ public int accel_plus_g;
+ public int accel_minus_g;
+
+ public double acceleration;
+ public double speed;
+ public double height;
+
+ public int flight_accel;
+ public int flight_vel;
+ public int flight_pres;
+
+ public AltosGPS gps;
+ public boolean new_gps;
+
+ public double time; /* seconds since boost */
+
+ public int device_type;
+ public int config_major;
+ public int config_minor;
+ public int apogee_delay;
+ public int main_deploy;
+ public int flight_log_max;
+ public String firmware_version;
+
+ public AltosRecordCompanion companion;
+
/*
* Values for our MP3H6115A pressure sensor
*
@@ -92,10 +93,10 @@ public class AltosRecord implements Comparable <AltosRecord> {
* 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
*/
- static final double counts_per_kPa = 27 * 2047 / 3300;
- static final double counts_at_101_3kPa = 1674.0;
+ public static final double counts_per_kPa = 27 * 2047 / 3300;
+ public static final double counts_at_101_3kPa = 1674.0;
- static double
+ public static double
barometer_to_pressure(double count)
{
return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
@@ -190,7 +191,7 @@ public class AltosRecord implements Comparable <AltosRecord> {
* = (value - 19791.268) / 32768 * 1.25 / 0.00247
*/
- static double
+ public static double
thermometer_to_temperature(double thermo)
{
return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
@@ -202,7 +203,7 @@ public class AltosRecord implements Comparable <AltosRecord> {
return thermometer_to_temperature(temp);
}
- double accel_counts_per_mss() {
+ public double accel_counts_per_mss() {
double counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
return counts_per_g / 9.80665;
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java
index 4f8e80dc..c8cc6cac 100644
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java
+++ b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosRecordCompanion.java
@@ -18,14 +18,14 @@
package org.altusmetrum.AltosLib;
public class AltosRecordCompanion {
- final static int board_id_telescience = 0x0a;
- final static int MAX_CHANNELS = 12;
+ public final static int board_id_telescience = 0x0a;
+ public final static int MAX_CHANNELS = 12;
- int tick;
- int board_id;
- int update_period;
- int channels;
- int[] companion_data;
+ public int tick;
+ public int board_id;
+ public int update_period;
+ public int channels;
+ public int[] companion_data;
public AltosRecordCompanion(int in_channels) {
channels = in_channels;
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java
deleted file mode 100644
index e0b0dfd6..00000000
--- a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosTelemetryReader.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright © 2010 Keith Packard <keithp@keithp.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-package org.altusmetrum.AltosLib;
-
-import java.lang.*;
-import java.text.*;
-import java.io.*;
-import java.util.concurrent.*;
-
-class AltosTelemetryReader extends AltosFlightReader {
- AltosDevice device;
- AltosSerial serial;
- AltosLog log;
- AltosRecord previous;
- double frequency;
- int telemetry;
-
- LinkedBlockingQueue<AltosLine> telem;
-
- AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
- AltosLine l = telem.take();
- if (l.line == null)
- throw new IOException("IO error");
- AltosRecord next = AltosTelemetry.parse(l.line, previous);
- previous = next;
- return next;
- }
-
- void flush() {
- telem.clear();
- }
-
- void close(boolean interrupted) {
- serial.remove_monitor(telem);
- log.close();
- serial.close();
- }
-
- public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
- frequency = in_frequency;
- serial.set_radio_frequency(frequency);
- }
-
- void save_frequency() {
- AltosUIPreferences.set_frequency(device.getSerial(), frequency);
- }
-
- void set_telemetry(int in_telemetry) {
- telemetry = in_telemetry;
- serial.set_telemetry(telemetry);
- }
-
- void save_telemetry() {
- AltosUIPreferences.set_telemetry(device.getSerial(), telemetry);
- }
-
- File backing_file() {
- return log.file();
- }
-
- public AltosTelemetryReader (AltosDevice in_device)
- throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException {
- device = in_device;
- serial = new AltosSerial(device);
- log = new AltosLog(serial);
- name = device.toShortString();
- previous = null;
-
- telem = new LinkedBlockingQueue<AltosLine>();
- frequency = AltosUIPreferences.frequency(device.getSerial());
- set_frequency(frequency);
- telemetry = AltosUIPreferences.telemetry(device.getSerial());
- set_telemetry(telemetry);
- serial.set_callsign(AltosUIPreferences.callsign());
- serial.add_monitor(telem);
- }
-}