X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosTelemetryReader.java;h=03e694f8bc7dfef11338d43fba62d8e6dd0eacb9;hp=3564a0a5a7aa14acf5f98925dbef47f203f515d8;hb=1e7e02987276847274493312202d22222c953149;hpb=ec6da0824474e46de842845d7b53fe1a1dde33ed diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index 3564a0a5..03e694f8 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -17,72 +17,47 @@ package altosui; -import java.io.*; -import java.util.*; +import java.lang.*; import java.text.*; -import altosui.AltosTelemetry; +import java.io.*; +import java.util.concurrent.*; -public class AltosTelemetryReader extends AltosReader { - LinkedList records; +class AltosTelemetryReader extends AltosFlightReader { + AltosDevice device; + AltosSerial serial; + AltosLog log; - Iterator record_iterator; + LinkedBlockingQueue telem; - int boost_tick; + 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); + } - public AltosRecord read() throws IOException, ParseException { - AltosRecord r; - if (!record_iterator.hasNext()) - return null; + void close(boolean interrupted) { + serial.remove_monitor(telem); + log.close(); + serial.close(); + } - r = record_iterator.next(); - r.time = (r.tick - boost_tick) / 100.0; - return r; + void set_channel(int channel) { + serial.set_channel(channel); } - public AltosTelemetryReader (FileInputStream input) { - boolean saw_boost = false; - int current_tick = 0; + void set_callsign(String callsign) { + serial.set_callsign(callsign); + } - records = new LinkedList (); + public AltosTelemetryReader (AltosDevice in_device) throws FileNotFoundException, IOException { + device = in_device; + serial = new AltosSerial(); + log = new AltosLog(serial); + name = device.getPath(); - try { - for (;;) { - String line = AltosRecord.gets(input); - if (line == null) { - break; - } - try { - AltosTelemetry record = new AltosTelemetry(line); - if (record == null) - break; - if (records.isEmpty()) { - current_tick = record.tick; - } else { - int tick = record.tick | (current_tick & ~ 0xffff); - if (tick < current_tick - 0x1000) - tick += 0x10000; - current_tick = tick; - record.tick = current_tick; - } - 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(); + serial.add_monitor(telem); + serial.open(device); } }