From 5e2c2a0ec3868f5e3d61f8c5e927cf93de99fbe8 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sat, 19 Mar 2011 10:09:35 -0500 Subject: [PATCH] Clean up the logging somewhat --- .../androidgcs/OPTelemetryService.java | 62 ++++++++++++++++--- .../openpilot/uavtalk/TelemetryMonitor.java | 31 +++++----- flight/Revolution/Makefile.osx | 5 +- 3 files changed, 72 insertions(+), 26 deletions(-) diff --git a/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java b/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java index 2994be6d2..5a48bbc05 100644 --- a/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java +++ b/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java @@ -6,8 +6,14 @@ import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVTalk; import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.Service; +import android.content.Context; import android.content.Intent; +import android.net.Uri; +import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.util.Log; @@ -18,10 +24,16 @@ public class OPTelemetryService extends Service { public static boolean WARN = LOGLEVEL > 1; public static boolean DEBUG = LOGLEVEL > 0; + final int DISCONNECT_MESSAGE = 0; + final int CONNECT_MESSAGE = 1; + final int CONNECT_FAILED_MESSAGE = 2; + private UAVObjectManager objMngr; private UAVTalk uavTalk; private Telemetry tel; private TelemetryMonitor mon; + + private Handler handler; @Override public IBinder onBind(Intent arg0) { @@ -46,22 +58,38 @@ public class OPTelemetryService extends Service { private final Runnable telemetryRunnable = new Runnable() { public void run() { - Looper.prepare(); - if (DEBUG) Log.d(TAG, "Telemetry Thread started"); + + Looper.prepare(); objMngr = new UAVObjectManager(); UAVObjectsInitialize.register(objMngr); - + + postNotification(CONNECT_FAILED_MESSAGE, "Connecting"); BluetoothUAVTalk bt = new BluetoothUAVTalk(OPTelemetryService.this, BluetoothUAVTalk.DEVICE_NAME); - while(true) { + for( int i = 0; i < 10; i++ ) { if (DEBUG) Log.d(TAG, "Attempting Bluetooth Connection"); - if(! bt.getConnected() ) - bt.connect(objMngr); - else + + bt.connect(objMngr); + + if (DEBUG) Log.d(TAG, "Done attempting connection"); + if( bt.getConnected() ) break; - Looper.loop(); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Log.e(TAG, "Thread interrupted while trying to connect"); + e.printStackTrace(); + return; + } } + if( ! bt.getConnected() ) { + postNotification(CONNECT_FAILED_MESSAGE, "Could not connect to UAV"); + return; + } + + postNotification(CONNECT_MESSAGE, "Connected to UAV port"); if (DEBUG) Log.d(TAG, "Connected via bluetooth"); @@ -73,13 +101,29 @@ public class OPTelemetryService extends Service { while(true) { if( !uavTalk.processInputStream() ) break; - Looper.loop(); } if (DEBUG) Log.d(TAG, "UAVTalk stream disconnected"); + postNotification(DISCONNECT_MESSAGE,"UAVTalk stream disconnected"); } }; + void postNotification(int id, String message) { + String ns = Context.NOTIFICATION_SERVICE; + NotificationManager mNManager = (NotificationManager) getSystemService(ns); + final Notification msg = new Notification(R.drawable.icon, message, System.currentTimeMillis()); + + Context context = getApplicationContext(); + CharSequence contentTitle = "OpenPilot"; + CharSequence contentText = message; + Intent msgIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forums.openpilot.org")); + PendingIntent intent = PendingIntent.getActivity(this, 0, msgIntent, Intent.FLAG_ACTIVITY_NEW_TASK); + + msg.setLatestEventInfo(context, contentTitle, contentText, intent); + + mNManager.notify(id, msg); + } + public UAVObjectManager getObjMngr() { return objMngr; }; public UAVTalk getUavTalk() { return uavTalk; }; public Telemetry getTelemetry() { return tel; }; diff --git a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java index a5885e7bc..9b4474d8e 100644 --- a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java +++ b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java @@ -16,7 +16,10 @@ import android.util.Log; public class TelemetryMonitor { private static final String TAG = "TelemetryMonitor"; - + public static int LOGLEVEL = 0; + public static boolean WARN = LOGLEVEL > 1; + public static boolean DEBUG = LOGLEVEL > 0; + static final int STATS_UPDATE_PERIOD_MS = 4000; static final int STATS_CONNECT_PERIOD_MS = 1000; static final int CONNECTION_TIMEOUT_MS = 8000; @@ -57,7 +60,7 @@ public class TelemetryMonitor { */ public synchronized void startRetrievingObjects() { - Log.d(TAG, "Start retrieving objects"); + if (DEBUG) Log.d(TAG, "Start retrieving objects"); // Clear object queue queue.clear(); @@ -115,7 +118,7 @@ public class TelemetryMonitor { // If queue is empty return if ( queue.isEmpty() ) { - Log.d(TAG, "All objects retrieved: Connected Successfully"); + if (DEBUG) Log.d(TAG, "All objects retrieved: Connected Successfully"); //qxtLog->debug("Object retrieval completed"); //emit connected(); return; @@ -127,12 +130,12 @@ public class TelemetryMonitor { throw new Error("Got null object forom transaction queue"); } - Log.d(TAG, "Retrieving object: " + obj.getName()) ; + if (DEBUG) Log.d(TAG, "Retrieving object: " + obj.getName()) ; // Connect to object obj.addTransactionCompleted(new Observer() { public void update(Observable observable, Object data) { UAVObject.TransactionResult result = (UAVObject.TransactionResult) data; - Log.d(TAG,"Got transaction completed event from " + result.obj.getName() + " status: " + result.success); + if (DEBUG) Log.d(TAG,"Got transaction completed event from " + result.obj.getName() + " status: " + result.success); transactionCompleted(result.obj, result.success); } }); @@ -149,7 +152,7 @@ public class TelemetryMonitor { { //QMutexLocker locker(mutex); // Disconnect from sending object - Log.d(TAG,"transactionCompleted. Status: " + success); + if (DEBUG) Log.d(TAG,"transactionCompleted. Status: " + success); // TODO: Need to be able to disconnect signals //obj->disconnect(this); objPending = null; @@ -192,7 +195,7 @@ public class TelemetryMonitor { public synchronized void processStatsUpdates() { // Get telemetry stats - Log.d(TAG, "processStatsUpdates()"); + if (DEBUG) Log.d(TAG, "processStatsUpdates()"); Telemetry.TelemetryStats telStats = tel.getStats(); tel.resetStats(); @@ -232,7 +235,7 @@ public class TelemetryMonitor { UAVObjectField statusField = gcsStatsObj.getField("Status"); String oldStatus = new String((String) statusField.getValue()); - Log.d(TAG,"GCS: " + statusField.getValue() + " Flight: " + flightStatsObj.getField("Status").getValue()); + if (DEBUG) Log.d(TAG,"GCS: " + statusField.getValue() + " Flight: " + flightStatsObj.getField("Status").getValue()); if ( oldStatus.compareTo("Disconnected") == 0 ) { @@ -245,7 +248,7 @@ public class TelemetryMonitor { if ( ((String) flightStatsObj.getField("Status").getValue()).compareTo("HandshakeAck") == 0 ) { statusField.setValue("Connected"); - Log.d(TAG,"Connected" + statusField.toString()); + if (DEBUG) Log.d(TAG,"Connected" + statusField.toString()); } } else if ( oldStatus.compareTo("Connected") == 0 ) @@ -260,30 +263,26 @@ public class TelemetryMonitor { // Force telemetry update if not yet connected boolean gcsStatusChanged = !oldStatus.equals(statusField.getValue()); - if(gcsStatusChanged) { - Log.d(TAG,"GCS Status changed"); - Log.d(TAG,"GCS: " + statusField.getValue() + " Flight: " + flightStatsObj.getField("Status").getValue()); - } boolean gcsConnected = ((String) statusField.getValue()).compareTo("Connected") == 0; boolean gcsDisconnected = ((String) statusField.getValue()).compareTo("Disconnected") == 0; boolean flightConnected = ((String) flightStatsObj.getField("Status").getValue()).compareTo("Connected") == 0; if ( !gcsConnected || !flightConnected ) { - Log.d(TAG,"Sending gcs status"); + if (DEBUG) Log.d(TAG,"Sending gcs status"); gcsStatsObj.updated(); } // Act on new connections or disconnections if (gcsConnected && gcsStatusChanged) { - Log.d(TAG,"Connection with the autopilot established"); + if (DEBUG) Log.d(TAG,"Connection with the autopilot established"); setPeriod(STATS_UPDATE_PERIOD_MS); startRetrievingObjects(); } if (gcsDisconnected && gcsStatusChanged) { - Log.d(TAG,"Trying to connect to the autopilot"); + if (DEBUG) Log.d(TAG,"Trying to connect to the autopilot"); setPeriod(STATS_CONNECT_PERIOD_MS); //emit disconnected(); } diff --git a/flight/Revolution/Makefile.osx b/flight/Revolution/Makefile.osx index 91bddb9a5..e2c8ea694 100644 --- a/flight/Revolution/Makefile.osx +++ b/flight/Revolution/Makefile.osx @@ -41,7 +41,7 @@ USE_BOOTLOADER ?= NO CODE_SOURCERY ?= NO # Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) -TCHAIN_PREFIX ?= "" +TCHAIN_PREFIX ?= /usr/local/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi- # Remove command is different for Code Sourcery on Windows REMOVE_CMD ?= rm @@ -320,6 +320,9 @@ CFLAGS += -mtune=$(MCU) CFLAGS += $(CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. +#CFLAGS += ARCH=arm +#CROSS_COMPILE=/usr/local/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi- + CFLAGS += -fomit-frame-pointer ifeq ($(CODE_SOURCERY), YES) CFLAGS += -fpromote-loop-indices