summaryrefslogtreecommitdiff
path: root/altoslib
diff options
context:
space:
mode:
Diffstat (limited to 'altoslib')
-rw-r--r--altoslib/AltosAccel.java6
-rw-r--r--altoslib/AltosCSV.java2
-rw-r--r--altoslib/AltosCompanion.java4
-rw-r--r--altoslib/AltosGPS.java3
-rw-r--r--altoslib/AltosGreatCircle.java3
-rw-r--r--altoslib/AltosIMU.java3
-rw-r--r--altoslib/AltosIdleMonitor.java32
-rw-r--r--altoslib/AltosIdleMonitorListener.java3
-rw-r--r--altoslib/AltosLib.java1
-rw-r--r--altoslib/AltosLink.java25
-rw-r--r--altoslib/AltosListenerState.java4
-rw-r--r--altoslib/AltosMag.java3
-rw-r--r--altoslib/AltosMs5607.java3
-rw-r--r--altoslib/AltosPreferences.java45
-rw-r--r--altoslib/AltosPreferencesBackend.java3
-rw-r--r--altoslib/AltosSavedState.java30
-rw-r--r--altoslib/AltosState.java24
-rw-r--r--altoslib/Makefile.am1
18 files changed, 145 insertions, 50 deletions
diff --git a/altoslib/AltosAccel.java b/altoslib/AltosAccel.java
index d91da4da..e40a47b4 100644
--- a/altoslib/AltosAccel.java
+++ b/altoslib/AltosAccel.java
@@ -17,7 +17,9 @@
package org.altusmetrum.altoslib_5;
-public class AltosAccel extends AltosUnits {
+import java.io.*;
+
+public class AltosAccel extends AltosUnits implements Serializable {
public double value(double v, boolean imperial_units) {
if (imperial_units)
@@ -46,4 +48,4 @@ public class AltosAccel extends AltosUnits {
public int show_fraction(int width, boolean imperial_units) {
return width / 9;
}
-} \ No newline at end of file
+}
diff --git a/altoslib/AltosCSV.java b/altoslib/AltosCSV.java
index 2357dbc7..2ad50097 100644
--- a/altoslib/AltosCSV.java
+++ b/altoslib/AltosCSV.java
@@ -158,7 +158,7 @@ public class AltosCSV implements AltosWriter {
}
void write_advanced_header() {
- out.printf("accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z");
+ out.printf("accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z,mag_x,mag_y,mag_z");
}
void write_advanced(AltosState state) {
diff --git a/altoslib/AltosCompanion.java b/altoslib/AltosCompanion.java
index 47deb2a3..7e9ab2f1 100644
--- a/altoslib/AltosCompanion.java
+++ b/altoslib/AltosCompanion.java
@@ -17,7 +17,9 @@
package org.altusmetrum.altoslib_5;
-public class AltosCompanion {
+import java.io.*;
+
+public class AltosCompanion implements Serializable {
public final static int board_id_telescience = 0x0a;
public final static int MAX_CHANNELS = 12;
diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java
index 0154e95d..285b5b45 100644
--- a/altoslib/AltosGPS.java
+++ b/altoslib/AltosGPS.java
@@ -19,8 +19,9 @@ package org.altusmetrum.altoslib_5;
import java.text.*;
import java.util.concurrent.*;
+import java.io.*;
-public class AltosGPS implements Cloneable {
+public class AltosGPS implements Cloneable, Serializable {
public final static int MISSING = AltosLib.MISSING;
diff --git a/altoslib/AltosGreatCircle.java b/altoslib/AltosGreatCircle.java
index 716eeef9..22a8e0e5 100644
--- a/altoslib/AltosGreatCircle.java
+++ b/altoslib/AltosGreatCircle.java
@@ -18,8 +18,9 @@
package org.altusmetrum.altoslib_5;
import java.lang.Math;
+import java.io.*;
-public class AltosGreatCircle implements Cloneable {
+public class AltosGreatCircle implements Cloneable, Serializable {
public double distance;
public double bearing;
public double range;
diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java
index d7373f3c..02b458b8 100644
--- a/altoslib/AltosIMU.java
+++ b/altoslib/AltosIMU.java
@@ -18,8 +18,9 @@
package org.altusmetrum.altoslib_5;
import java.util.concurrent.*;
+import java.io.*;
-public class AltosIMU implements Cloneable {
+public class AltosIMU implements Cloneable, Serializable {
public int accel_along;
public int accel_across;
public int accel_through;
diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java
index 85bcff10..57c77c47 100644
--- a/altoslib/AltosIdleMonitor.java
+++ b/altoslib/AltosIdleMonitor.java
@@ -35,20 +35,6 @@ public class AltosIdleMonitor extends Thread {
AltosConfigData config_data;
AltosGPS gps;
- int AltosRSSI() throws TimeoutException, InterruptedException {
- link.printf("s\n");
- String line = link.get_reply_no_dialog(5000);
- if (line == null)
- throw new TimeoutException();
- String[] items = line.split("\\s+");
- if (items.length < 2)
- return 0;
- if (!items[0].equals("RSSI:"))
- return 0;
- int rssi = Integer.parseInt(items[1]);
- return rssi;
- }
-
void start_link() throws InterruptedException, TimeoutException {
if (remote) {
link.set_radio_frequency(frequency);
@@ -58,26 +44,30 @@ public class AltosIdleMonitor extends Thread {
link.flush_input();
}
- void stop_link() throws InterruptedException, TimeoutException {
+ boolean stop_link() throws InterruptedException, TimeoutException {
if (remote)
link.stop_remote();
+ return link.reply_abort;
}
- void update_state(AltosState state) throws InterruptedException, TimeoutException {
+ boolean update_state(AltosState state) throws InterruptedException, TimeoutException {
boolean worked = false;
+ boolean aborted = false;
try {
start_link();
fetch.update_state(state);
- worked = true;
+ if (!link.has_error && !link.reply_abort)
+ worked = true;
} finally {
- stop_link();
+ aborted = stop_link();
if (worked) {
if (remote)
state.set_rssi(link.rssi(), 0);
listener_state.battery = link.monitor_battery();
}
}
+ return aborted;
}
public void set_frequency(double in_frequency) {
@@ -102,13 +92,17 @@ public class AltosIdleMonitor extends Thread {
public void run() {
AltosState state = new AltosState();
try {
- while (!link.has_error) {
+ for (;;) {
try {
link.config_data();
update_state(state);
listener.update(state, listener_state);
} catch (TimeoutException te) {
}
+ if (link.has_error || link.reply_abort) {
+ listener.failed();
+ break;
+ }
Thread.sleep(1000);
}
} catch (InterruptedException ie) {
diff --git a/altoslib/AltosIdleMonitorListener.java b/altoslib/AltosIdleMonitorListener.java
index 4382430c..36484763 100644
--- a/altoslib/AltosIdleMonitorListener.java
+++ b/altoslib/AltosIdleMonitorListener.java
@@ -19,4 +19,5 @@ package org.altusmetrum.altoslib_5;
public interface AltosIdleMonitorListener {
public void update(AltosState state, AltosListenerState listener_state);
-} \ No newline at end of file
+ public void failed();
+}
diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java
index 0edc0b43..be69519b 100644
--- a/altoslib/AltosLib.java
+++ b/altoslib/AltosLib.java
@@ -188,6 +188,7 @@ public class AltosLib {
};
public static final String launch_sites_url = "http://www.altusmetrum.org/AltOS/launch-sites.txt";
+// public static final String launch_sites_url = "file:///home/keithp/misc/text/altusmetrum/AltOS/launch-sites.txt";
public static final int ao_telemetry_standard_len = 32;
public static final int ao_telemetry_0_9_len = 95;
diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java
index 62bd82b9..639d2ac7 100644
--- a/altoslib/AltosLink.java
+++ b/altoslib/AltosLink.java
@@ -55,8 +55,11 @@ public abstract class AltosLink implements Runnable {
public void printf(String format, Object ... arguments) {
String line = String.format(format, arguments);
- if (debug)
- pending_output.add(line);
+ if (debug) {
+ synchronized (pending_output) {
+ pending_output.add(line);
+ }
+ }
try {
print(line);
} catch (InterruptedException ie) {
@@ -286,12 +289,14 @@ public abstract class AltosLink implements Runnable {
binary_queue.put(dup);
}
- public void flush_output() {
+ public synchronized void flush_output() {
if (pending_output == null)
return;
- for (String s : pending_output)
- System.out.print(s);
- pending_output.clear();
+ synchronized (pending_output) {
+ for (String s : pending_output)
+ System.out.print(s);
+ pending_output.clear();
+ }
}
public void flush_input(int timeout) throws InterruptedException {
@@ -422,8 +427,10 @@ public abstract class AltosLink implements Runnable {
public void set_callsign(String callsign) {
this.callsign = callsign;
- printf ("c c %s\n", callsign);
- flush_output();
+ if (callsign != null) {
+ printf ("c c %s\n", callsign);
+ flush_output();
+ }
}
public boolean is_loader() throws InterruptedException {
@@ -462,7 +469,7 @@ public abstract class AltosLink implements Runnable {
if (telemetry_rate < 0)
telemetry_rate = AltosPreferences.telemetry_rate(serial);
set_telemetry_rate(telemetry_rate);
- if (callsign.equals(""))
+ if (callsign == null || callsign.equals(""))
callsign = AltosPreferences.callsign();
set_callsign(callsign);
printf("p\nE 0\n");
diff --git a/altoslib/AltosListenerState.java b/altoslib/AltosListenerState.java
index 054ff1d0..ed1f0f19 100644
--- a/altoslib/AltosListenerState.java
+++ b/altoslib/AltosListenerState.java
@@ -17,7 +17,9 @@
package org.altusmetrum.altoslib_5;
-public class AltosListenerState {
+import java.io.*;
+
+public class AltosListenerState implements Serializable {
public int crc_errors;
public double battery;
diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java
index 1fa8877b..8784bb81 100644
--- a/altoslib/AltosMag.java
+++ b/altoslib/AltosMag.java
@@ -18,8 +18,9 @@
package org.altusmetrum.altoslib_5;
import java.util.concurrent.*;
+import java.io.*;
-public class AltosMag implements Cloneable {
+public class AltosMag implements Cloneable, Serializable {
public int along;
public int across;
public int through;
diff --git a/altoslib/AltosMs5607.java b/altoslib/AltosMs5607.java
index 81e0641c..97e17164 100644
--- a/altoslib/AltosMs5607.java
+++ b/altoslib/AltosMs5607.java
@@ -18,8 +18,9 @@
package org.altusmetrum.altoslib_5;
import java.util.concurrent.*;
+import java.io.*;
-public class AltosMs5607 {
+public class AltosMs5607 implements Serializable {
public int reserved;
public int sens;
public int off;
diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java
index dba57dcb..5fe810d7 100644
--- a/altoslib/AltosPreferences.java
+++ b/altoslib/AltosPreferences.java
@@ -41,6 +41,9 @@ public class AltosPreferences {
/* log file format preference name */
public final static String logfilePreferenceFormat = "LOGFILE-%d";
+ /* state preference name */
+ public final static String statePreferenceFormat = "STATE-%d";
+
/* voice preference name */
public final static String voicePreference = "VOICE";
@@ -333,6 +336,48 @@ public class AltosPreferences {
}
}
+ public static void set_state(int serial, AltosState state, AltosListenerState listener_state) {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ AltosSavedState saved_state = new AltosSavedState(state, listener_state);
+ oos.writeObject(saved_state);
+
+ byte[] bytes = baos.toByteArray();
+
+ synchronized(backend) {
+ backend.putBytes(String.format(statePreferenceFormat, serial), bytes);
+ flush_preferences();
+ }
+ } catch (IOException ie) {
+ }
+ }
+
+ public static AltosSavedState state(int serial) {
+ byte[] bytes = null;
+
+ synchronized(backend) {
+ bytes = backend.getBytes(String.format(statePreferenceFormat, serial), null);
+ }
+
+ if (bytes == null)
+ return null;
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+
+ try {
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ AltosSavedState saved_state = (AltosSavedState) ois.readObject();
+ return saved_state;
+ } catch (IOException ie) {
+ } catch (ClassNotFoundException ce) {
+ }
+ return null;
+ }
+
public static void set_scanning_telemetry(int new_scanning_telemetry) {
synchronized (backend) {
scanning_telemetry = new_scanning_telemetry;
diff --git a/altoslib/AltosPreferencesBackend.java b/altoslib/AltosPreferencesBackend.java
index 76a99acb..9bb4c99b 100644
--- a/altoslib/AltosPreferencesBackend.java
+++ b/altoslib/AltosPreferencesBackend.java
@@ -33,6 +33,9 @@ public interface AltosPreferencesBackend {
public boolean getBoolean(String key, boolean def);
public void putBoolean(String key, boolean value);
+ public byte[] getBytes(String key, byte[] def);
+ public void putBytes(String key, byte[] value);
+
public boolean nodeExists(String key);
public AltosPreferencesBackend node(String key);
diff --git a/altoslib/AltosSavedState.java b/altoslib/AltosSavedState.java
new file mode 100644
index 00000000..4b010b31
--- /dev/null
+++ b/altoslib/AltosSavedState.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2014 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_5;
+
+import java.io.*;
+
+public class AltosSavedState implements Serializable {
+ public AltosState state;
+ public AltosListenerState listener_state;
+
+ public AltosSavedState(AltosState state, AltosListenerState listener_state) {
+ this.state = state;
+ this.listener_state = listener_state;
+ }
+}
diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java
index 830e95f3..5be008b7 100644
--- a/altoslib/AltosState.java
+++ b/altoslib/AltosState.java
@@ -21,7 +21,9 @@
package org.altusmetrum.altoslib_5;
-public class AltosState implements Cloneable {
+import java.io.*;
+
+public class AltosState implements Cloneable, Serializable {
public static final int set_position = 1;
public static final int set_gps = 2;
@@ -43,7 +45,7 @@ public class AltosState implements Cloneable {
private int prev_tick;
public int boost_tick;
- class AltosValue {
+ class AltosValue implements Serializable{
double value;
double prev_value;
private double max_value;
@@ -179,9 +181,9 @@ public class AltosState implements Cloneable {
}
}
- class AltosCValue {
+ class AltosCValue implements Serializable {
- class AltosIValue extends AltosValue {
+ class AltosIValue extends AltosValue implements Serializable {
boolean can_max() {
return c_can_max();
}
@@ -312,7 +314,7 @@ public class AltosState implements Cloneable {
ground_altitude.set_measured(a, time);
}
- class AltosGpsGroundAltitude extends AltosValue {
+ class AltosGpsGroundAltitude extends AltosValue implements Serializable {
void set(double a, double t) {
super.set(a, t);
pad_alt = value();
@@ -336,7 +338,7 @@ public class AltosState implements Cloneable {
gps_ground_altitude.set(a, time);
}
- class AltosGroundPressure extends AltosCValue {
+ class AltosGroundPressure extends AltosCValue implements Serializable {
void set_filtered(double p, double time) {
computed.set_filtered(p, time);
if (!is_measured())
@@ -359,7 +361,7 @@ public class AltosState implements Cloneable {
ground_pressure.set_measured(pressure, time);
}
- class AltosAltitude extends AltosCValue {
+ class AltosAltitude extends AltosCValue implements Serializable {
private void set_speed(AltosValue v) {
if (!acceleration.is_measured() || !ascent)
@@ -381,7 +383,7 @@ public class AltosState implements Cloneable {
private AltosAltitude altitude;
- class AltosGpsAltitude extends AltosValue {
+ class AltosGpsAltitude extends AltosValue implements Serializable {
private void set_gps_height() {
double a = value();
@@ -464,7 +466,7 @@ public class AltosState implements Cloneable {
return gps_speed.max();
}
- class AltosPressure extends AltosValue {
+ class AltosPressure extends AltosValue implements Serializable {
void set(double p, double time) {
super.set(p, time);
if (state == AltosLib.ao_flight_pad)
@@ -534,7 +536,7 @@ public class AltosState implements Cloneable {
return AltosLib.MISSING;
}
- class AltosSpeed extends AltosCValue {
+ class AltosSpeed extends AltosCValue implements Serializable {
boolean can_max() {
return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
@@ -588,7 +590,7 @@ public class AltosState implements Cloneable {
return AltosLib.MISSING;
}
- class AltosAccel extends AltosCValue {
+ class AltosAccel extends AltosCValue implements Serializable {
boolean can_max() {
return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am
index 2805742e..8aff2767 100644
--- a/altoslib/Makefile.am
+++ b/altoslib/Makefile.am
@@ -82,6 +82,7 @@ altoslib_JAVA = \
AltosProgrammer.java \
AltosReplayReader.java \
AltosRomconfig.java \
+ AltosSavedState.java \
AltosSelfFlash.java \
AltosSensorMM.java \
AltosSensorEMini.java \