MicroPeak v2.0 sends a 'unique id' with the log data; capture that and
included it in the file name.
MicroPeak v2.0 can be directly connected to the host using the µP I/O
board. Handle that case by sending the 'l' command which will cause
the device to dump the log.
Signed-off-by: Keith Packard <keithp@keithp.com>
private double time_step;
private ArrayList<Integer> bytes;
private double time_step;
private ArrayList<Integer> bytes;
public int log_id;
String name;
public int log_id;
String name;
public static final int LOG_ID_MICROPEAK = 0;
public static final int LOG_ID_MICROKITE = 1;
public static final int LOG_ID_MICROPEAK = 0;
public static final int LOG_ID_MICROKITE = 1;
+ private String get_line(InputStream f) throws IOException, FileEndedException, NonHexcharException {
+ int c;
+ StringBuffer line = new StringBuffer();
+
+ do {
+ c = f.read();
+ } while (Character.isWhitespace(c));
+
+ do {
+ line.append((char) c);
+ c = f.read();
+ } while (!Character.isWhitespace(c));
+ return new String(line);
+ }
+
private int swap16(int i) {
return ((i << 8) & 0xff00) | ((i >> 8) & 0xff);
}
private int swap16(int i) {
return ((i << 8) & 0xff00) | ((i >> 8) & 0xff);
}
file_crc = 0xffff;
ground_pressure = get_32(f);
min_pressure = get_32(f);
file_crc = 0xffff;
ground_pressure = get_32(f);
min_pressure = get_32(f);
- int nsamples = get_16(f);
log_id = nsamples >> 12;
nsamples &= 0xfff;
log_id = nsamples >> 12;
nsamples &= 0xfff;
+ if (log_id == LOG_ID_MICROPEAK2) {
+ int nsamples_high = get_16(f);
+ nsamples |= (nsamples_high << 12);
+ }
cal_data.set_ground_pressure(ground_pressure);
cal_data.set_ground_pressure(ground_pressure);
flight_series.set_pressure(cur);
}
flight_series.set_pressure(cur);
}
+ int current_crc = swap16(~file_crc & 0xffff);
+ int crc = get_16(f);
+
+ crc_valid = crc == current_crc;
+
+ if (log_id == LOG_ID_MICROPEAK2) {
+ unique_id = get_line(f);
+ }
+
flight_series.finish();
/* Build states */
flight_series.finish();
/* Build states */
flight_series.set_time(0);
flight_series.set_state(AltosLib.ao_flight_boost);
flight_series.set_time(0);
flight_series.set_state(AltosLib.ao_flight_boost);
- flight_series.set_time(flight_series.speed_series.max().time);
- flight_series.set_state(AltosLib.ao_flight_coast);
+ if (flight_series.speed_series != null && flight_series.speed_series.max() != null) {
+ flight_series.set_time(flight_series.speed_series.max().time);
+ flight_series.set_state(AltosLib.ao_flight_coast);
+ }
flight_series.set_time(flight_series.height_series.max().time);
flight_series.set_state(AltosLib.ao_flight_drogue);
flight_series.set_time(flight_series.height_series.max().time);
flight_series.set_state(AltosLib.ao_flight_drogue);
flight_stats = new AltosFlightStats(flight_series);
flight_stats = new AltosFlightStats(flight_series);
- int current_crc = swap16(~file_crc & 0xffff);
- int crc = get_16(f);
-
- crc_valid = crc == current_crc;
} catch (FileEndedException fe) {
throw new IOException("File Ended Unexpectedly");
} catch (FileEndedException fe) {
throw new IOException("File Ended Unexpectedly");
} catch (MicroData.NonHexcharException nhe) {
}
}
} catch (MicroData.NonHexcharException nhe) {
}
}
} catch (FileNotFoundException fe) {
} catch (IOException ioe) {
} catch (InterruptedException ie) {
} catch (FileNotFoundException fe) {
} catch (IOException ioe) {
} catch (InterruptedException ie) {
+ Thread write_thread;
+
+ public class SerialWriter implements Runnable {
+ MicroSerial serial;
+
+ public void run () {
+ try {
+ Thread.sleep(100);
+ serial.write('l');
+ serial.write('\n');
+ serial.flush();
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ public SerialWriter(MicroSerial serial) {
+ this.serial = serial;
+ }
+ }
public void start() {
try {
public void start() {
try {
}
serial_thread = new Thread(this);
serial_thread.start();
}
serial_thread = new Thread(this);
serial_thread.start();
+
+ SerialWriter writer = new SerialWriter(serial);
+ write_thread = new Thread(writer);
+ write_thread.start();
}
public void actionPerformed(ActionEvent ae) {
}
public void actionPerformed(ActionEvent ae) {
- public static File make(File directory, int year, int month, int day) {
+ public static File make(MicroData data, File directory, int year, int month, int day) {
+ String unique = "";
+ if (data != null && data.unique_id != null)
+ unique = String.format("-%s", data.unique_id);
for (int sequence = 1;; sequence++) {
for (int sequence = 1;; sequence++) {
- String s = String.format("%04d-%02d-%02d-flight-%03d.mpd",
- year, month, day, sequence);
+ String s = String.format("%04d-%02d-%02d%s-flight-%03d.mpd",
+ year, month, day, unique, sequence);
File file = new File(directory, s);
if (!file.exists())
return file;
}
}
File file = new File(directory, s);
if (!file.exists())
return file;
}
}
- public static File make(File directory) {
+ public static File make(MicroData data, File directory) {
Calendar cal = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
- return make(directory, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH));
+ return make(data, directory, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH));
+ }
+
+ public static File make(MicroData data) {
+ return make(data, AltosUIPreferences.logdir());
}
public static File make() {
}
public static File make() {
- return make(AltosUIPreferences.logdir());
-}
\ No newline at end of file
JOptionPane.YES_NO_OPTION);
if (r != JOptionPane.YES_OPTION)
continue;
JOptionPane.YES_NO_OPTION);
if (r != JOptionPane.YES_OPTION)
continue;
if (!file.canWrite()) {
JOptionPane.showMessageDialog(frame,
String.format("\"%s\" is not writable",
if (!file.canWrite()) {
JOptionPane.showMessageDialog(frame,
String.format("\"%s\" is not writable",
setFileFilter(new FileNameExtensionFilter("MicroPeak data file",
"mpd"));
setCurrentDirectory(AltosUIPreferences.last_logdir());
setFileFilter(new FileNameExtensionFilter("MicroPeak data file",
"mpd"));
setCurrentDirectory(AltosUIPreferences.last_logdir());
- setSelectedFile(MicroFile.make());
+ setSelectedFile(MicroFile.make(data));
private MicroSerialLog log;
public int read() {
private MicroSerialLog log;
public int read() {
+ if (file == null)
+ return -1;
int c = libaltos.altos_getchar(file, 0);
if (Thread.interrupted())
return -1;
int c = libaltos.altos_getchar(file, 0);
if (Thread.interrupted())
return -1;
+ public void write(char c) {
+ libaltos.altos_putchar(file, c);
+ }
+
+ public void flush() {
+ libaltos.altos_flush(file);
+ }
+
public void close() {
if (file != null) {
libaltos.altos_close(file);
public void close() {
if (file != null) {
libaltos.altos_close(file);