X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FTelemetryReader.java;h=cdd1decdc68b9189a77812b6676c5dcee204d76d;hp=c47e4942040dd911a1d44f4e3b05f7df33dc145e;hb=ee14ad16c242e8bd7a9d33ebf569211d1490b8e1;hpb=162c640d382b9f823573578fe97584adc94cd9b6 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java index c47e4942..cdd1decd 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java @@ -1,6 +1,6 @@ /* - * Copyright © 2011 Keith Packard - * Copyright © 2012 Mike Beattie + * Copyright © 2011 Keith Packard + * Copyright © 2012 Mike Beattie * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ import java.util.concurrent.*; import android.util.Log; import android.os.Handler; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_2.*; public class TelemetryReader extends Thread { @@ -37,25 +37,29 @@ public class TelemetryReader extends Thread { Handler handler; AltosLink link; - AltosRecord previous; + AltosState state = null; - LinkedBlockingQueue telem; + LinkedBlockingQueue telemQueue; - public AltosRecord read() throws ParseException, AltosCRCException, InterruptedException, IOException { - AltosLine l = telem.take(); + public AltosState read() throws ParseException, AltosCRCException, InterruptedException, IOException { + AltosLine l = telemQueue.take(); if (l.line == null) throw new IOException("IO error"); - AltosRecord next = AltosTelemetry.parse(l.line, previous); - previous = next; - return next; + AltosTelemetry telem = AltosTelemetryLegacy.parse(l.line); + if (state == null) + state = new AltosState(); + else + state = state.clone(); + telem.update_state(state); + return state; } public void close() { - previous = null; - link.remove_monitor(telem); + state = null; + link.remove_monitor(telemQueue); link = null; - telem.clear(); - telem = null; + telemQueue.clear(); + telemQueue = null; } public void run() { @@ -64,16 +68,13 @@ public class TelemetryReader extends Thread { try { for (;;) { try { - AltosRecord record = read(); - if (record == null) - break; - state = new AltosState(record, state); - + state = read(); handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget(); } catch (ParseException pp) { Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage())); } catch (AltosCRCException ce) { ++crc_errors; + handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget(); } } } catch (InterruptedException ee) { @@ -87,8 +88,8 @@ public class TelemetryReader extends Thread { link = in_link; handler = in_handler; - previous = null; - telem = new LinkedBlockingQueue(); - link.add_monitor(telem); + state = null; + telemQueue = new LinkedBlockingQueue(); + link.add_monitor(telemQueue); } }