private Messenger mService = null;
final Messenger mMessenger = new Messenger(new IncomingHandler(this));
- // Preferences
- private AltosDroidPreferences prefs = null;
-
// TeleBT Config data
private AltosConfigData mConfigData = null;
// Local Bluetooth adapter
}
// Initialise preferences
- prefs = new AltosDroidPreferences(this);
- AltosPreferences.init(prefs);
+ AltosDroidPreferences.init(this);
// Set up the window layout
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
}
}
- private void connectDevice(Intent data) {
- // Get the device MAC address
- String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
+ private void connectDevice(String address) {
// Get the BLuetoothDevice object
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
// Attempt to connect to the device
}
}
+ private void connectDevice(Intent data) {
+ // Get the device MAC address
+ String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
+ connectDevice(address);
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
/*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ * 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
* 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.AltosDroid;
-import java.io.File;
-import java.util.Map;
import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Environment;
-
import org.altusmetrum.altoslib_5.*;
-public class AltosDroidPreferences implements AltosPreferencesBackend {
- public final static String NAME = "org.altusmetrum.AltosDroid";
- private Context context = null;
- private SharedPreferences prefs = null;
- private SharedPreferences.Editor editor = null;
+public class AltosDroidPreferences extends AltosPreferences {
- public AltosDroidPreferences(Context in_context) {
- this(in_context, NAME);
- }
+ /* Active device preference name */
+ final static String activeDevicePreference = "ACTIVE-DEVICE";
- public AltosDroidPreferences(Context in_context, String in_prefs) {
- context = in_context;
- prefs = context.getSharedPreferences(in_prefs, 0);
- editor = prefs.edit();
- }
+ static String active_device_address;
- public String[] keys() {
- Map<String, ?> all = prefs.getAll();
- return (String[])all.keySet().toArray();
- }
-
- public AltosPreferencesBackend node(String key) {
- return new AltosDroidPreferences(context, key);
- }
-
- public boolean nodeExists(String key) {
- return prefs.contains(key);
- }
-
- public boolean getBoolean(String key, boolean def) {
- return prefs.getBoolean(key, def);
- }
-
- public double getDouble(String key, double def) {
- Float f = Float.valueOf(prefs.getFloat(key, (float)def));
- return f.doubleValue();
- }
-
- public int getInt(String key, int def) {
- return prefs.getInt(key, def);
- }
-
- public String getString(String key, String def) {
- return prefs.getString(key, def);
- }
-
- public void putBoolean(String key, boolean value) {
- editor.putBoolean(key, value);
- }
-
- public void putDouble(String key, double value) {
- editor.putFloat(key, (float)value);
- }
-
- public void putInt(String key, int value) {
- editor.putInt(key, value);
- }
-
- public void putString(String key, String value) {
- editor.putString(key, value);
- }
+ public static void init(Context context) {
+ AltosPreferences.init(new AltosDroidPreferencesBackend(context));
- public void remove(String key) {
- editor.remove(key);
+ active_device_address = backend.getGetString(activeDevicePreference, null);
}
- public void flush() {
- editor.apply();
+ public static void set_active_device(String address) {
+ synchronized(backend) {
+ active_device_address = address;
+ backend.putString(activeDevicePreference, active_device_address);
+ flush_preferences();
+ }
}
- public File homeDirectory() {
- return Environment.getExternalStorageDirectory();
+ public static String active_device() {
+ synchronized(backend) {
+ return active_device_address;
+ }
}
}
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 { }
}
log_file.flush();
file = a;
+ AltosPreferences.set_logfile(link.serial, file);
}
return log_file != null;
}
/* 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";
/* 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;
}
}
+ 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;
public class AltosReplayReader extends AltosFlightReader {
Iterator<AltosState> iterator;
File file;
+ boolean real_time;
public AltosState read() {
if (iterator.hasNext())
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);
+ }
}
}
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);
+ }
}
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");
}
public void close(boolean interrupted) {
+
+ if (stacked != null) {
+ stacked.close(interrupted);
+ stacked = null;
+ }
+
link.remove_monitor(telem);
log.close();
try {
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);
close(true);
}
}
+
+ private static AltosFlightReader existing_data(AltosLink link) {
+ 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));
+ }
}