diff --git a/androidgcs/AndroidManifest.xml b/androidgcs/AndroidManifest.xml
index dad23f2c2..8fa646a95 100644
--- a/androidgcs/AndroidManifest.xml
+++ b/androidgcs/AndroidManifest.xml
@@ -26,9 +26,11 @@
-
+
+
diff --git a/androidgcs/res/layout/logger.xml b/androidgcs/res/layout/logger.xml
new file mode 100644
index 000000000..204c100a8
--- /dev/null
+++ b/androidgcs/res/layout/logger.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/androidgcs/src/org/openpilot/androidgcs/HomePage.java b/androidgcs/src/org/openpilot/androidgcs/HomePage.java
index a2a82924a..c67605ee6 100644
--- a/androidgcs/src/org/openpilot/androidgcs/HomePage.java
+++ b/androidgcs/src/org/openpilot/androidgcs/HomePage.java
@@ -41,6 +41,13 @@ public class HomePage extends ObjectManagerActivity {
}
});
+ Button logger = (Button) findViewById(R.id.launch_logger);
+ logger.setOnClickListener(new OnClickListener() {
+ public void onClick(View arg0) {
+ startActivity(new Intent(HomePage.this, Logger.class));
+ }
+ });
+
}
}
diff --git a/androidgcs/src/org/openpilot/androidgcs/Logger.java b/androidgcs/src/org/openpilot/androidgcs/Logger.java
new file mode 100644
index 000000000..43c9a9de7
--- /dev/null
+++ b/androidgcs/src/org/openpilot/androidgcs/Logger.java
@@ -0,0 +1,37 @@
+package org.openpilot.androidgcs;
+
+import java.util.List;
+
+import org.openpilot.uavtalk.UAVObject;
+
+import android.os.Bundle;
+import android.util.Log;
+
+
+public class Logger extends ObjectManagerActivity {
+
+ final String TAG = "Logger";
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.logger);
+ }
+
+ @Override
+ void onOPConnected() {
+ Log.d(TAG, "onOPConnected()");
+
+ List> allObjects = objMngr.getObjects();
+ registerObjectUpdates(allObjects);
+ }
+
+ /**
+ * Called whenever any objects subscribed to via registerObjects
+ */
+ @Override
+ protected void objectUpdated(UAVObject obj) {
+ Log.d(TAG,"Updated: " + obj.toString());
+ }
+}
diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java b/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java
index 5027d4d24..fe6d807b4 100644
--- a/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java
+++ b/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java
@@ -1,7 +1,13 @@
package org.openpilot.androidgcs;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Observable;
+import java.util.Observer;
+
import org.openpilot.androidgcs.OPTelemetryService.LocalBinder;
import org.openpilot.androidgcs.OPTelemetryService.TelemTask;
+import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectManager;
import android.app.Activity;
@@ -12,6 +18,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
@@ -24,11 +31,15 @@ public abstract class ObjectManagerActivity extends Activity {
private static int LOGLEVEL = 0;
// private static boolean WARN = LOGLEVEL > 1;
private static boolean DEBUG = LOGLEVEL > 0;
-
+
+ //! Object manager, populated by parent for the children to use
UAVObjectManager objMngr;
- boolean mBound = false;
- boolean mConnected = false;
- LocalBinder binder;
+ //! Indicates if the activity is bound to the service
+ boolean mBound = false;
+ //! Indicates if telemetry is connected
+ boolean mConnected = false;
+ //! The binder to access the telemetry task, and thus the object manager
+ LocalBinder binder;
/** Called when the activity is first created. */
@@ -42,7 +53,6 @@ public abstract class ObjectManagerActivity extends Activity {
Log.d(TAG, "Received intent");
TelemTask task;
if(intent.getAction().compareTo(OPTelemetryService.INTENT_ACTION_CONNECTED) == 0) {
-
if(binder == null)
return;
if((task = binder.getTelemTask(0)) == null)
@@ -67,10 +77,57 @@ public abstract class ObjectManagerActivity extends Activity {
registerReceiver(connectedReceiver, filter);
}
+ /**
+ * Called whenever any objects subscribed to via registerObjects
+ */
+ protected void objectUpdated(UAVObject obj) {
+
+ }
+
+ /**
+ * A message handler and a custom Observer to use it which calls
+ * objectUpdated with the right object type
+ */
+ final Handler uavobjHandler = new Handler();
+ private class UpdatedObserver implements Observer {
+ UAVObject obj;
+ UpdatedObserver(UAVObject obj) { this.obj = obj; };
+ public void update(Observable observable, Object data) {
+ uavobjHandler.post(new Runnable() {
+ @Override
+ public void run() { objectUpdated(obj); }
+ });
+ }
+ };
+
+ /**
+ * Register an activity to receive updates from this object
+ *
+ * the objectUpdated() method will be called in the original UI thread
+ */
+ protected void registerObjectUpdates(UAVObject object) {
+ object.addUpdatedObserver(new UpdatedObserver(object));
+ }
+ protected void registerObjectUpdates(List> objects) {
+ ListIterator> li = objects.listIterator();
+ while(li.hasNext()) {
+ ListIterator li2 = li.next().listIterator();
+ while(li2.hasNext())
+ registerObjectUpdates(li2.next());
+ }
+ }
+
+ /**
+ * Called when either the telemetry establishes a connection or
+ * if it already has on creation of this activity
+ */
void onOPConnected() {
}
+ /**
+ * Called when telemetry drops the connection
+ */
void onOPDisconnected() {
}