docs: Document altosui "Graph Data" button
[fw/altos] / ao-tools / altosui / AltosTelemetryReader.java
index fdedbde279345499e1ac926104478ade2106fa24..6c5a93978c69a4156e0e44fe3b94b3ea7a9c92c0 100644 (file)
 
 package altosui;
 
-import java.io.*;
-import java.util.*;
+import java.lang.*;
 import java.text.*;
-import altosui.AltosTelemetry;
-
-public class AltosTelemetryReader extends AltosReader {
-       LinkedList<AltosRecord> records;
+import java.io.*;
+import java.util.concurrent.*;
 
-       Iterator<AltosRecord> record_iterator;
+class AltosTelemetryReader extends AltosFlightReader {
+       AltosDevice     device;
+       AltosSerial     serial;
+       AltosLog        log;
 
-       int     boost_tick;
+       LinkedBlockingQueue<AltosLine> telem;
 
-       public AltosRecord read() throws IOException, ParseException {
-               AltosRecord     r;
-               if (!record_iterator.hasNext())
-                       return null;
+       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);
+       }
 
-               r = record_iterator.next();
-               r.time = (r.tick - boost_tick) / 100.0;
-               return r;
+       void close(boolean interrupted) {
+               serial.remove_monitor(telem);
+               log.close();
+               serial.close();
        }
 
-       public AltosTelemetryReader (FileInputStream input) {
-               boolean saw_boost = false;
+       void set_channel(int channel) {
+               serial.set_channel(channel);
+               AltosPreferences.set_channel(device.getSerial(), channel);
+       }
 
-               records = new LinkedList<AltosRecord> ();
+       public AltosTelemetryReader (AltosDevice in_device)
+               throws FileNotFoundException, AltosSerialInUseException, IOException {
+               device = in_device;
+               serial = new AltosSerial(device);
+               log = new AltosLog(serial);
+               name = device.toShortString();
 
-               try {
-                       for (;;) {
-                               String line = AltosRecord.gets(input);
-                               if (line == null) {
-                                       break;
-                               }
-                               try {
-                                       AltosTelemetry record = new AltosTelemetry(line);
-                                       if (record == null)
-                                               break;
-                                       if (!saw_boost && record.state >= Altos.ao_flight_boost)
-                                       {
-                                               saw_boost = true;
-                                               boost_tick = record.tick;
-                                       }
-                                       records.add(record);
-                               } catch (ParseException pe) {
-                                       System.out.printf("parse exception %s\n", pe.getMessage());
-                               } catch (AltosCRCException ce) {
-                                       System.out.printf("crc error\n");
-                               }
-                       }
-               } catch (IOException io) {
-                       System.out.printf("io exception\n");
-               }
-               record_iterator = records.iterator();
-               try {
-                       input.close();
-               } catch (IOException ie) {
-               }
+               telem = new LinkedBlockingQueue<AltosLine>();
+               serial.set_radio();
+               serial.add_monitor(telem);
        }
 }