2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
3 * Copyright © 2012 Mike Beattie <mike@ethernal.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 package org.altusmetrum.AltosDroid;
25 import java.util.concurrent.*;
26 import android.os.Handler;
28 import org.altusmetrum.altoslib_7.*;
31 public class TelemetryReader extends Thread {
39 LinkedBlockingQueue<AltosLine> telemQueue;
41 public AltosTelemetry read() throws ParseException, AltosCRCException, InterruptedException, IOException {
42 AltosLine l = telemQueue.take();
44 throw new IOException("IO error");
45 AltosTelemetry telem = AltosTelemetryLegacy.parse(l.line);
50 link.remove_monitor(telemQueue);
58 AltosDebug.debug("starting loop");
59 while (telemQueue != null) {
61 AltosTelemetry telem = read();
62 handler.obtainMessage(TelemetryService.MSG_TELEMETRY, telem).sendToTarget();
63 } catch (ParseException pp) {
64 AltosDebug.error("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage());
65 } catch (AltosCRCException ce) {
67 handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget();
70 } catch (InterruptedException ee) {
71 } catch (IOException ie) {
72 AltosDebug.error("IO exception in telemetry reader");
73 handler.obtainMessage(TelemetryService.MSG_DISCONNECTED, link).sendToTarget();
79 public TelemetryReader (AltosLink in_link, Handler in_handler) {
80 AltosDebug.debug("connected TelemetryReader create started");
84 telemQueue = new LinkedBlockingQueue<AltosLine>();
85 link.add_monitor(telemQueue);
86 link.set_telemetry(AltosLib.ao_telemetry_standard);
88 AltosDebug.debug("connected TelemetryReader created");