+ class DeviceThread extends AltosDisplayThread {
+ AltosSerial serial;
+ LinkedBlockingQueue<AltosLine> telem;
+
+ AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
+ AltosLine l = telem.take();
+ if (l.line == null)
+ throw new IOException("IO error");
+ return new AltosTelemetry(l.line);
+ }
+
+ void close(boolean interrupted) {
+ serial.close();
+ serial.remove_monitor(telem);
+ }
+
+ public DeviceThread(AltosSerial s, String in_name, AltosVoice voice, AltosStatusTable status, AltosInfoTable info) {
+ super(AltosUI.this, voice, status, info);
+ serial = s;
+ telem = new LinkedBlockingQueue<AltosLine>();
+ serial.add_monitor(telem);
+ name = in_name;
+ }
+ }
+
+ private void ConnectToDevice() {
+ AltosDevice device = AltosDeviceDialog.show(AltosUI.this,
+ AltosDevice.product_basestation);
+
+ if (device != null) {
+ try {
+ stop_display();
+ serial_line.open(device);
+ DeviceThread thread = new DeviceThread(serial_line, device.getPath(), voice, flightStatus, flightInfo);
+ serial_line.set_channel(AltosPreferences.channel());
+ serial_line.set_callsign(AltosPreferences.callsign());
+ run_display(thread);
+ } catch (FileNotFoundException ee) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ String.format("Cannot open device \"%s\"",
+ device.getPath()),
+ "Cannot open target device",
+ JOptionPane.ERROR_MESSAGE);
+ } catch (IOException ee) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ device.getPath(),
+ "Unkonwn I/O error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+
+ void DisconnectFromDevice () {
+ stop_display();
+ }
+
+ void ConfigureCallsign() {
+ String result;
+ result = JOptionPane.showInputDialog(AltosUI.this,
+ "Configure Callsign",
+ AltosPreferences.callsign());
+ if (result != null) {
+ AltosPreferences.set_callsign(result);
+ if (serial_line != null)
+ serial_line.set_callsign(result);
+ }
+ }
+
+ void ConfigureTeleMetrum() {
+ new AltosConfig(AltosUI.this);
+ }
+
+ void FlashImage() {
+ new AltosFlashUI(AltosUI.this);
+ }
+
+
+ Thread display_thread;
+
+ private void stop_display() {
+ if (display_thread != null && display_thread.isAlive()) {
+ display_thread.interrupt();
+ try {
+ display_thread.join();
+ } catch (InterruptedException ie) {}
+ }
+ display_thread = null;
+ }
+
+ private void run_display(Thread thread) {
+ stop_display();
+ display_thread = thread;
+ display_thread.start();
+ }
+
+ /*
+ * Replay a flight from telemetry data
+ */
+ private void Replay() {
+ AltosLogfileChooser chooser = new AltosLogfileChooser(
+ AltosUI.this);
+ AltosRecordIterable iterable = chooser.runDialog();
+ if (iterable != null)
+ run_display(new AltosReplayThread(this, iterable.iterator(),
+ chooser.filename(),
+ voice,
+ flightStatus,
+ flightInfo));
+ }
+
+ /* Connect to TeleMetrum, either directly or through
+ * a TeleDongle over the packet link
+ */
+ private void SaveFlightData() {
+ new AltosEepromDownload(AltosUI.this);
+ }
+
+ /* Load a flight log file and write out a CSV file containing
+ * all of the data in standard units
+ */
+
+ private void ExportData() {
+ new AltosCSVUI(AltosUI.this);
+ }
+
+ /* Load a flight log CSV file and display a pretty graph.
+ */
+
+ private void GraphData() {
+ new AltosGraphUI(AltosUI.this);
+ }
+
+ /* Create the AltosUI menus
+ */