diff options
Diffstat (limited to 'altoslib')
-rw-r--r-- | altoslib/AltosEepromGPS.java | 6 | ||||
-rw-r--r-- | altoslib/AltosFlightReader.java | 8 | ||||
-rw-r--r-- | altoslib/AltosLog.java | 1 | ||||
-rw-r--r-- | altoslib/AltosPreferences.java | 33 | ||||
-rw-r--r-- | altoslib/AltosReplayReader.java | 11 | ||||
-rw-r--r-- | altoslib/AltosStateIterable.java | 14 | ||||
-rw-r--r-- | altoslib/AltosTelemetryMegaData.java | 4 | ||||
-rw-r--r-- | altoslib/AltosTelemetryReader.java | 34 |
8 files changed, 100 insertions, 11 deletions
diff --git a/altoslib/AltosEepromGPS.java b/altoslib/AltosEepromGPS.java index 482f0b5f..8c991a6e 100644 --- a/altoslib/AltosEepromGPS.java +++ b/altoslib/AltosEepromGPS.java @@ -91,8 +91,10 @@ public class AltosEepromGPS extends AltosEeprom { switch (cmd) { case AltosLib.AO_LOG_FLIGHT: - state.set_boost_tick(tick); - state.set_flight(flight()); + if (state.flight == AltosLib.MISSING) { + state.set_boost_tick(tick); + state.set_flight(flight()); + } /* no place to log start lat/lon yet */ break; case AltosLib.AO_LOG_GPS_TIME: diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index c0565e88..be103838 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -21,16 +21,16 @@ import java.text.*; import java.io.*; import java.util.concurrent.*; -public class AltosFlightReader { +public abstract class AltosFlightReader { public String name; public int serial; - public void init() { } + public void init() {} - public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + public abstract AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException; - public void close(boolean interrupted) { } + public abstract void close(boolean interrupted); public void set_frequency(double frequency) throws InterruptedException, TimeoutException { } diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 1cac6b52..28116e3d 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -72,6 +72,7 @@ public class AltosLog implements Runnable { } log_file.flush(); file = a; + AltosPreferences.set_logfile(link.serial, file); } return log_file != null; } diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 72cfeb4b..dba57dcb 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -38,6 +38,9 @@ public class AltosPreferences { /* telemetry rate format preference name */ public final static String telemetryRatePreferenceFormat = "RATE-%d"; + /* log file format preference name */ + public final static String logfilePreferenceFormat = "LOGFILE-%d"; + /* voice preference name */ public final static String voicePreference = "VOICE"; @@ -83,6 +86,9 @@ public class AltosPreferences { /* Telemetry rate (map serial to telemetry format) */ public static Hashtable<Integer, Integer> telemetry_rates; + /* Log file (map serial to logfile name) */ + public static Hashtable<Integer, File> logfiles; + /* Voice preference */ public static boolean voice; @@ -151,6 +157,10 @@ public class AltosPreferences { public static int launcher_channel; public static void init(AltosPreferencesBackend in_backend) { + + if (backend != null) + return; + backend = in_backend; /* Initialize logdir from preferences */ @@ -172,6 +182,8 @@ public class AltosPreferences { telemetry_rates = new Hashtable<Integer,Integer>(); + logfiles = new Hashtable<Integer,File>(); + voice = backend.getBoolean(voicePreference, true); callsign = backend.getString(callsignPreference,"N0CALL"); @@ -300,6 +312,27 @@ public class AltosPreferences { } } + public static void set_logfile(int serial, File new_logfile) { + synchronized(backend) { + logfiles.put(serial, new_logfile); + backend.putString(String.format(logfilePreferenceFormat, serial), new_logfile.getPath()); + flush_preferences(); + } + } + + public static File logfile(int serial) { + synchronized(backend) { + if (logfiles.containsKey(serial)) + return logfiles.get(serial); + String logfile_string = backend.getString(String.format(logfilePreferenceFormat, serial), null); + if (logfile_string == null) + return null; + File logfile = new File(logfile_string); + logfiles.put(serial, logfile); + return logfile; + } + } + public static void set_scanning_telemetry(int new_scanning_telemetry) { synchronized (backend) { scanning_telemetry = new_scanning_telemetry; diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index 15093af1..2864e02a 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -27,6 +27,7 @@ import java.util.*; public class AltosReplayReader extends AltosFlightReader { Iterator<AltosState> iterator; File file; + boolean real_time; public AltosState read() { if (iterator.hasNext()) @@ -39,16 +40,22 @@ public class AltosReplayReader extends AltosFlightReader { public void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > AltosLib.ao_flight_pad && state.time_change > 0) + if (real_time && state.state > AltosLib.ao_flight_pad && state.time_change > 0) Thread.sleep((int) (Math.min(state.time_change,10) * 1000)); state.set_received_time(System.currentTimeMillis()); } public File backing_file() { return file; } - public AltosReplayReader(Iterator<AltosState> in_iterator, File in_file) { + public AltosReplayReader(Iterator<AltosState> in_iterator, File in_file, + boolean in_real_time) { iterator = in_iterator; file = in_file; + real_time = in_real_time; name = file.getName(); } + + public AltosReplayReader(Iterator<AltosState> in_iterator, File in_file) { + this(in_iterator, in_file, false); + } } diff --git a/altoslib/AltosStateIterable.java b/altoslib/AltosStateIterable.java index f7cd424d..4154b71c 100644 --- a/altoslib/AltosStateIterable.java +++ b/altoslib/AltosStateIterable.java @@ -26,4 +26,18 @@ public abstract class AltosStateIterable implements Iterable<AltosState> { } public abstract void write(PrintStream out); + + public static AltosStateIterable iterable(File file) { + FileInputStream in; + try { + in = new FileInputStream(file); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + return null; + } + if (file.getName().endsWith("telem")) + return new AltosTelemetryFile(in); + else + return new AltosEepromFile(in); + } } diff --git a/altoslib/AltosTelemetryMegaData.java b/altoslib/AltosTelemetryMegaData.java index 8b1869bb..d949c02f 100644 --- a/altoslib/AltosTelemetryMegaData.java +++ b/altoslib/AltosTelemetryMegaData.java @@ -36,7 +36,7 @@ public class AltosTelemetryMegaData extends AltosTelemetryStandard { public AltosTelemetryMegaData(int[] bytes) { super(bytes); - state = int8(5); + state = uint8(5); v_batt = int16(6); v_pyro = int16(8); @@ -44,7 +44,7 @@ public class AltosTelemetryMegaData extends AltosTelemetryStandard { sense = new int[6]; for (int i = 0; i < 6; i++) { - sense[i] = int8(10 + i) << 4; + sense[i] = uint8(10 + i) << 4; sense[i] |= sense[i] >> 8; } diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index 5ed50134..7539452d 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -28,10 +28,17 @@ public class AltosTelemetryReader extends AltosFlightReader { int telemetry; int telemetry_rate; AltosState state = null; + AltosFlightReader stacked; LinkedBlockingQueue<AltosLine> telem; public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { + if (stacked != null) { + state = stacked.read(); + if (state != null) + return state; + stacked = null; + } AltosLine l = telem.take(); if (l.line == null) throw new IOException("IO error"); @@ -53,6 +60,12 @@ public class AltosTelemetryReader extends AltosFlightReader { } public void close(boolean interrupted) { + + if (stacked != null) { + stacked.close(interrupted); + stacked = null; + } + link.remove_monitor(telem); log.close(); try { @@ -148,9 +161,10 @@ public class AltosTelemetryReader extends AltosFlightReader { return link.monitor_battery(); } - public AltosTelemetryReader (AltosLink in_link) + public AltosTelemetryReader (AltosLink in_link, AltosFlightReader in_stacked) throws IOException, InterruptedException, TimeoutException { link = in_link; + stacked = in_stacked; boolean success = false; try { log = new AltosLog(link); @@ -169,4 +183,22 @@ public class AltosTelemetryReader extends AltosFlightReader { close(true); } } + + private static AltosFlightReader existing_data(AltosLink link) { + if (link == null) + return null; + + File file = AltosPreferences.logfile(link.serial); + if (file != null) { + AltosStateIterable iterable = AltosStateIterable.iterable(file); + if (iterable != null) + return new AltosReplayReader(iterable.iterator(), file, false); + } + return null; + } + + public AltosTelemetryReader(AltosLink link) + throws IOException, InterruptedException, TimeoutException { + this(link, existing_data(link)); + } } |