2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
\r
3 * Copyright © 2012 Mike Beattie <mike@ethernal.org>
\r
5 * This program is free software; you can redistribute it and/or modify
\r
6 * it under the terms of the GNU General Public License as published by
\r
7 * the Free Software Foundation; version 2 of the License.
\r
9 * This program is distributed in the hope that it will be useful, but
\r
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
12 * General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License along
\r
15 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
20 package org.altusmetrum.AltosDroid;
\r
24 import java.util.concurrent.*;
\r
25 import android.util.Log;
\r
26 import android.os.Handler;
\r
28 import org.altusmetrum.altoslib_1.*;
\r
31 public class TelemetryReader extends Thread {
\r
33 private static final String TAG = "TelemetryReader";
\r
40 AltosRecord previous;
\r
42 LinkedBlockingQueue<AltosLine> telem;
\r
44 public AltosRecord read() throws ParseException, AltosCRCException, InterruptedException, IOException {
\r
45 AltosLine l = telem.take();
\r
47 throw new IOException("IO error");
\r
48 AltosRecord next = AltosTelemetry.parse(l.line, previous);
\r
53 public void close() {
\r
55 link.remove_monitor(telem);
\r
62 AltosState state = null;
\r
67 AltosRecord record = read();
\r
70 state = new AltosState(record, state);
\r
72 handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget();
\r
73 } catch (ParseException pp) {
\r
74 Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage()));
\r
75 } catch (AltosCRCException ce) {
\r
79 } catch (InterruptedException ee) {
\r
80 } catch (IOException ie) {
\r
86 public TelemetryReader (AltosLink in_link, Handler in_handler) {
\r
88 handler = in_handler;
\r
91 telem = new LinkedBlockingQueue<AltosLine>();
\r
92 link.add_monitor(telem);
\r