summaryrefslogtreecommitdiff
path: root/altosdroid
diff options
context:
space:
mode:
authorMike Beattie <mike@ethernal.org>2013-09-03 15:11:33 +1200
committerKeith Packard <keithp@keithp.com>2013-09-05 11:46:36 -0700
commite9e9c6592c49109288a4e02e780b130fadb97db7 (patch)
tree409bd53fbf1f9d27434f39b9a983d11bd90ed5f1 /altosdroid
parent93e66b4911b7285f9095712ef746571153c3f088 (diff)
altosdroid: convert rogue files to unix line endings
Signed-off-by: Mike Beattie <mike@ethernal.org>
Diffstat (limited to 'altosdroid')
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java366
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java190
2 files changed, 278 insertions, 278 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java b/altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java
index 17e4cf5b..2797fc5e 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java
@@ -1,183 +1,183 @@
-package org.altusmetrum.AltosDroid;
-
- import java.lang.reflect.Array;
- import java.lang.reflect.Field;
- import java.util.HashMap;
-
- public class Dumper {
- private static Dumper instance = new Dumper();
-
- protected static Dumper getInstance() {
- return instance;
- }
-
- class DumpContext {
- int maxDepth = 0;
- int maxArrayElements = 0;
- int callCount = 0;
- HashMap<String, String> ignoreList = new HashMap<String, String>();
- HashMap<Object, Integer> visited = new HashMap<Object, Integer>();
- }
-
- public static String dump(Object o) {
- return dump(o, 0, 0, null);
- }
-
- public static String dump(Object o, int maxDepth, int maxArrayElements, String[] ignoreList) {
- DumpContext ctx = Dumper.getInstance().new DumpContext();
- ctx.maxDepth = maxDepth;
- ctx.maxArrayElements = maxArrayElements;
-
- if (ignoreList != null) {
- for (int i = 0; i < Array.getLength(ignoreList); i++) {
- int colonIdx = ignoreList[i].indexOf(':');
- if (colonIdx == -1)
- ignoreList[i] = ignoreList[i] + ":";
- ctx.ignoreList.put(ignoreList[i], ignoreList[i]);
- }
- }
-
- return dump(o, ctx);
- }
-
- protected static String dump(Object o, DumpContext ctx) {
- if (o == null) {
- return "<null>";
- }
-
- ctx.callCount++;
- StringBuffer tabs = new StringBuffer();
- for (int k = 0; k < ctx.callCount; k++) {
- tabs.append("\t");
- }
- StringBuffer buffer = new StringBuffer();
- @SuppressWarnings("rawtypes")
- Class oClass = o.getClass();
-
- String oSimpleName = getSimpleNameWithoutArrayQualifier(oClass);
-
- if (ctx.ignoreList.get(oSimpleName + ":") != null)
- return "<Ignored>";
-
- if (oClass.isArray()) {
- buffer.append("\n");
- buffer.append(tabs.toString().substring(1));
- buffer.append("[\n");
- int rowCount = ctx.maxArrayElements == 0 ? Array.getLength(o) : Math.min(ctx.maxArrayElements, Array.getLength(o));
- for (int i = 0; i < rowCount; i++) {
- buffer.append(tabs.toString());
- try {
- Object value = Array.get(o, i);
- buffer.append(dumpValue(value, ctx));
- } catch (Exception e) {
- buffer.append(e.getMessage());
- }
- if (i < Array.getLength(o) - 1)
- buffer.append(",");
- buffer.append("\n");
- }
- if (rowCount < Array.getLength(o)) {
- buffer.append(tabs.toString());
- buffer.append(Array.getLength(o) - rowCount + " more array elements...");
- buffer.append("\n");
- }
- buffer.append(tabs.toString().substring(1));
- buffer.append("]");
- } else {
- buffer.append("\n");
- buffer.append(tabs.toString().substring(1));
- buffer.append("{\n");
- buffer.append(tabs.toString());
- buffer.append("hashCode: " + o.hashCode());
- buffer.append("\n");
- while (oClass != null && oClass != Object.class) {
- Field[] fields = oClass.getDeclaredFields();
-
- if (ctx.ignoreList.get(oClass.getSimpleName()) == null) {
- if (oClass != o.getClass()) {
- buffer.append(tabs.toString().substring(1));
- buffer.append(" Inherited from superclass " + oSimpleName + ":\n");
- }
-
- for (int i = 0; i < fields.length; i++) {
-
- String fSimpleName = getSimpleNameWithoutArrayQualifier(fields[i].getType());
- String fName = fields[i].getName();
-
- fields[i].setAccessible(true);
- buffer.append(tabs.toString());
- buffer.append(fName + "(" + fSimpleName + ")");
- buffer.append("=");
-
- if (ctx.ignoreList.get(":" + fName) == null &&
- ctx.ignoreList.get(fSimpleName + ":" + fName) == null &&
- ctx.ignoreList.get(fSimpleName + ":") == null) {
-
- try {
- Object value = fields[i].get(o);
- buffer.append(dumpValue(value, ctx));
- } catch (Exception e) {
- buffer.append(e.getMessage());
- }
- buffer.append("\n");
- } else {
- buffer.append("<Ignored>");
- buffer.append("\n");
- }
- }
- oClass = oClass.getSuperclass();
- oSimpleName = oClass.getSimpleName();
- } else {
- oClass = null;
- oSimpleName = "";
- }
- }
- buffer.append(tabs.toString().substring(1));
- buffer.append("}");
- }
- ctx.callCount--;
- return buffer.toString();
- }
-
- protected static String dumpValue(Object value, DumpContext ctx) {
- if (value == null) {
- return "<null>";
- }
- if (value.getClass().isPrimitive() ||
- value.getClass() == java.lang.Short.class ||
- value.getClass() == java.lang.Long.class ||
- value.getClass() == java.lang.String.class ||
- value.getClass() == java.lang.Integer.class ||
- value.getClass() == java.lang.Float.class ||
- value.getClass() == java.lang.Byte.class ||
- value.getClass() == java.lang.Character.class ||
- value.getClass() == java.lang.Double.class ||
- value.getClass() == java.lang.Boolean.class) {
-
- return value.toString();
-
- } else {
-
- Integer visitedIndex = ctx.visited.get(value);
- if (visitedIndex == null) {
- ctx.visited.put(value, ctx.callCount);
- if (ctx.maxDepth == 0 || ctx.callCount < ctx.maxDepth) {
- return dump(value, ctx);
- } else {
- return "<Reached max recursion depth>";
- }
- } else {
- return "<Previously visited - see hashCode " + value.hashCode() + ">";
- }
- }
- }
-
-
- private static String getSimpleNameWithoutArrayQualifier(@SuppressWarnings("rawtypes") Class clazz) {
- String simpleName = clazz.getSimpleName();
- int indexOfBracket = simpleName.indexOf('[');
- if (indexOfBracket != -1)
- return simpleName.substring(0, indexOfBracket);
- return simpleName;
- }
-}
+package org.altusmetrum.AltosDroid;
+
+ import java.lang.reflect.Array;
+ import java.lang.reflect.Field;
+ import java.util.HashMap;
+
+ public class Dumper {
+ private static Dumper instance = new Dumper();
+
+ protected static Dumper getInstance() {
+ return instance;
+ }
+
+ class DumpContext {
+ int maxDepth = 0;
+ int maxArrayElements = 0;
+ int callCount = 0;
+ HashMap<String, String> ignoreList = new HashMap<String, String>();
+ HashMap<Object, Integer> visited = new HashMap<Object, Integer>();
+ }
+
+ public static String dump(Object o) {
+ return dump(o, 0, 0, null);
+ }
+
+ public static String dump(Object o, int maxDepth, int maxArrayElements, String[] ignoreList) {
+ DumpContext ctx = Dumper.getInstance().new DumpContext();
+ ctx.maxDepth = maxDepth;
+ ctx.maxArrayElements = maxArrayElements;
+
+ if (ignoreList != null) {
+ for (int i = 0; i < Array.getLength(ignoreList); i++) {
+ int colonIdx = ignoreList[i].indexOf(':');
+ if (colonIdx == -1)
+ ignoreList[i] = ignoreList[i] + ":";
+ ctx.ignoreList.put(ignoreList[i], ignoreList[i]);
+ }
+ }
+
+ return dump(o, ctx);
+ }
+
+ protected static String dump(Object o, DumpContext ctx) {
+ if (o == null) {
+ return "<null>";
+ }
+
+ ctx.callCount++;
+ StringBuffer tabs = new StringBuffer();
+ for (int k = 0; k < ctx.callCount; k++) {
+ tabs.append("\t");
+ }
+ StringBuffer buffer = new StringBuffer();
+ @SuppressWarnings("rawtypes")
+ Class oClass = o.getClass();
+
+ String oSimpleName = getSimpleNameWithoutArrayQualifier(oClass);
+
+ if (ctx.ignoreList.get(oSimpleName + ":") != null)
+ return "<Ignored>";
+
+ if (oClass.isArray()) {
+ buffer.append("\n");
+ buffer.append(tabs.toString().substring(1));
+ buffer.append("[\n");
+ int rowCount = ctx.maxArrayElements == 0 ? Array.getLength(o) : Math.min(ctx.maxArrayElements, Array.getLength(o));
+ for (int i = 0; i < rowCount; i++) {
+ buffer.append(tabs.toString());
+ try {
+ Object value = Array.get(o, i);
+ buffer.append(dumpValue(value, ctx));
+ } catch (Exception e) {
+ buffer.append(e.getMessage());
+ }
+ if (i < Array.getLength(o) - 1)
+ buffer.append(",");
+ buffer.append("\n");
+ }
+ if (rowCount < Array.getLength(o)) {
+ buffer.append(tabs.toString());
+ buffer.append(Array.getLength(o) - rowCount + " more array elements...");
+ buffer.append("\n");
+ }
+ buffer.append(tabs.toString().substring(1));
+ buffer.append("]");
+ } else {
+ buffer.append("\n");
+ buffer.append(tabs.toString().substring(1));
+ buffer.append("{\n");
+ buffer.append(tabs.toString());
+ buffer.append("hashCode: " + o.hashCode());
+ buffer.append("\n");
+ while (oClass != null && oClass != Object.class) {
+ Field[] fields = oClass.getDeclaredFields();
+
+ if (ctx.ignoreList.get(oClass.getSimpleName()) == null) {
+ if (oClass != o.getClass()) {
+ buffer.append(tabs.toString().substring(1));
+ buffer.append(" Inherited from superclass " + oSimpleName + ":\n");
+ }
+
+ for (int i = 0; i < fields.length; i++) {
+
+ String fSimpleName = getSimpleNameWithoutArrayQualifier(fields[i].getType());
+ String fName = fields[i].getName();
+
+ fields[i].setAccessible(true);
+ buffer.append(tabs.toString());
+ buffer.append(fName + "(" + fSimpleName + ")");
+ buffer.append("=");
+
+ if (ctx.ignoreList.get(":" + fName) == null &&
+ ctx.ignoreList.get(fSimpleName + ":" + fName) == null &&
+ ctx.ignoreList.get(fSimpleName + ":") == null) {
+
+ try {
+ Object value = fields[i].get(o);
+ buffer.append(dumpValue(value, ctx));
+ } catch (Exception e) {
+ buffer.append(e.getMessage());
+ }
+ buffer.append("\n");
+ } else {
+ buffer.append("<Ignored>");
+ buffer.append("\n");
+ }
+ }
+ oClass = oClass.getSuperclass();
+ oSimpleName = oClass.getSimpleName();
+ } else {
+ oClass = null;
+ oSimpleName = "";
+ }
+ }
+ buffer.append(tabs.toString().substring(1));
+ buffer.append("}");
+ }
+ ctx.callCount--;
+ return buffer.toString();
+ }
+
+ protected static String dumpValue(Object value, DumpContext ctx) {
+ if (value == null) {
+ return "<null>";
+ }
+ if (value.getClass().isPrimitive() ||
+ value.getClass() == java.lang.Short.class ||
+ value.getClass() == java.lang.Long.class ||
+ value.getClass() == java.lang.String.class ||
+ value.getClass() == java.lang.Integer.class ||
+ value.getClass() == java.lang.Float.class ||
+ value.getClass() == java.lang.Byte.class ||
+ value.getClass() == java.lang.Character.class ||
+ value.getClass() == java.lang.Double.class ||
+ value.getClass() == java.lang.Boolean.class) {
+
+ return value.toString();
+
+ } else {
+
+ Integer visitedIndex = ctx.visited.get(value);
+ if (visitedIndex == null) {
+ ctx.visited.put(value, ctx.callCount);
+ if (ctx.maxDepth == 0 || ctx.callCount < ctx.maxDepth) {
+ return dump(value, ctx);
+ } else {
+ return "<Reached max recursion depth>";
+ }
+ } else {
+ return "<Previously visited - see hashCode " + value.hashCode() + ">";
+ }
+ }
+ }
+
+
+ private static String getSimpleNameWithoutArrayQualifier(@SuppressWarnings("rawtypes") Class clazz) {
+ String simpleName = clazz.getSimpleName();
+ int indexOfBracket = simpleName.indexOf('[');
+ if (indexOfBracket != -1)
+ return simpleName.substring(0, indexOfBracket);
+ return simpleName;
+ }
+}
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java
index cdd1decd..45604284 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java
@@ -1,95 +1,95 @@
-/*
- * Copyright © 2011 Keith Packard <keithp@keithp.com>
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
- *
- * 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
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-
-package org.altusmetrum.AltosDroid;
-
-import java.text.*;
-import java.io.*;
-import java.util.concurrent.*;
-import android.util.Log;
-import android.os.Handler;
-
-import org.altusmetrum.altoslib_2.*;
-
-
-public class TelemetryReader extends Thread {
-
- private static final String TAG = "TelemetryReader";
-
- int crc_errors;
-
- Handler handler;
-
- AltosLink link;
- AltosState state = null;
-
- LinkedBlockingQueue<AltosLine> telemQueue;
-
- public AltosState read() throws ParseException, AltosCRCException, InterruptedException, IOException {
- AltosLine l = telemQueue.take();
- if (l.line == null)
- throw new IOException("IO error");
- 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() {
- state = null;
- link.remove_monitor(telemQueue);
- link = null;
- telemQueue.clear();
- telemQueue = null;
- }
-
- public void run() {
- AltosState state = null;
-
- try {
- for (;;) {
- try {
- 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) {
- } catch (IOException ie) {
- } finally {
- close();
- }
- }
-
- public TelemetryReader (AltosLink in_link, Handler in_handler) {
- link = in_link;
- handler = in_handler;
-
- state = null;
- telemQueue = new LinkedBlockingQueue<AltosLine>();
- link.add_monitor(telemQueue);
- }
-}
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ *
+ * 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
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+
+package org.altusmetrum.AltosDroid;
+
+import java.text.*;
+import java.io.*;
+import java.util.concurrent.*;
+import android.util.Log;
+import android.os.Handler;
+
+import org.altusmetrum.altoslib_2.*;
+
+
+public class TelemetryReader extends Thread {
+
+ private static final String TAG = "TelemetryReader";
+
+ int crc_errors;
+
+ Handler handler;
+
+ AltosLink link;
+ AltosState state = null;
+
+ LinkedBlockingQueue<AltosLine> telemQueue;
+
+ public AltosState read() throws ParseException, AltosCRCException, InterruptedException, IOException {
+ AltosLine l = telemQueue.take();
+ if (l.line == null)
+ throw new IOException("IO error");
+ 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() {
+ state = null;
+ link.remove_monitor(telemQueue);
+ link = null;
+ telemQueue.clear();
+ telemQueue = null;
+ }
+
+ public void run() {
+ AltosState state = null;
+
+ try {
+ for (;;) {
+ try {
+ 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) {
+ } catch (IOException ie) {
+ } finally {
+ close();
+ }
+ }
+
+ public TelemetryReader (AltosLink in_link, Handler in_handler) {
+ link = in_link;
+ handler = in_handler;
+
+ state = null;
+ telemQueue = new LinkedBlockingQueue<AltosLine>();
+ link.add_monitor(telemQueue);
+ }
+}