X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosTelemetryReader.java;h=6c5a93978c69a4156e0e44fe3b94b3ea7a9c92c0;hp=f1f6788c0afbc17973574a0b98c5459647d153a8;hb=357826aa9c7b42c59f5d52b8eb016d73b6da0c7f;hpb=f317f1324b69b4241f4bb192e164b33d712d5a43 diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index f1f6788c..6c5a9397 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -17,55 +17,45 @@ package altosui; -import java.io.*; -import java.util.*; +import java.lang.*; import java.text.*; -import altosui.AltosTelemetry; - -public class AltosTelemetryReader extends AltosReader { - LinkedList records; +import java.io.*; +import java.util.concurrent.*; - Iterator record_iterator; +class AltosTelemetryReader extends AltosFlightReader { + AltosDevice device; + AltosSerial serial; + AltosLog log; - int boost_tick; + LinkedBlockingQueue 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 (); + 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; - 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 (IOException io) { - } catch (ParseException pe) { - } - record_iterator = records.iterator(); - try { - input.close(); - } catch (IOException ie) { - } + telem = new LinkedBlockingQueue(); + serial.set_radio(); + serial.add_monitor(telem); } }