From 99859109697c679780ed4124e344ed3f4f720535 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Fri, 10 Aug 2012 16:11:20 -0500 Subject: [PATCH] AndroidGCS TelemetryMonitor: Now that transactions are working more reliably we can emit the connected signal at the end of fetching all the objects. --- .../openpilot/uavtalk/TelemetryMonitor.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java index f0ee84fb3..a1e341197 100644 --- a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java +++ b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java @@ -48,6 +48,8 @@ public class TelemetryMonitor extends Observable { static final int STATS_CONNECT_PERIOD_MS = 1000; static final int CONNECTION_TIMEOUT_MS = 8000; + private final boolean HANDSHAKE_IS_CONNECTED = false; + private final UAVObjectManager objMngr; private final Telemetry tel; // private UAVObject objPending; @@ -147,6 +149,20 @@ public class TelemetryMonitor extends Observable { queue.clear(); } + final Observer transactionObserver = new Observer() { + @Override + public void update(Observable observable, Object data) { + try { + UAVObject.TransactionResult result = (UAVObject.TransactionResult) data; + transactionCompleted(result.obj, result.success); + } catch (IOException e) { + // When the telemetry stream is broken disconnect these + // updates + observable.deleteObserver(this); + } + } + }; + /** * Retrieve the next object in the queue * @@ -155,11 +171,12 @@ public class TelemetryMonitor extends Observable { public synchronized void retrieveNextObject() throws IOException { // If queue is empty return if (queue.isEmpty()) { - if (DEBUG) - Log.d(TAG, "All objects retrieved: Connected Successfully"); + if (DEBUG || true) Log.d(TAG, "All objects retrieved: Connected Successfully"); objects_updated = true; - //setChanged(); - //notifyObservers(); + if (!HANDSHAKE_IS_CONNECTED) { + setChanged(); + notifyObservers(); + } return; } // Get next object from the queue @@ -174,23 +191,7 @@ public class TelemetryMonitor extends Observable { // TODO: Does this need to stay here permanently? This appears to be // used for setup mainly - obj.addTransactionCompleted(new Observer() { - @Override - public void update(Observable observable, Object data) { - UAVObject.TransactionResult result = (UAVObject.TransactionResult) data; - if (DEBUG) - Log.d(TAG, "Got transaction completed event from " - + result.obj.getName() + " status: " - + result.success); - try { - transactionCompleted(result.obj, result.success); - } catch (IOException e) { - // When the telemetry stream is broken disconnect these - // updates - observable.deleteObserver(this); - } - } - }); + obj.addTransactionCompleted(transactionObserver); // Request update obj.updateRequested(); @@ -206,6 +207,9 @@ public class TelemetryMonitor extends Observable { if (DEBUG) Log.d(TAG, "transactionCompleted. Status: " + success); + // Remove the listener for the event that just finished + obj.removeTransactionCompleted(transactionObserver); + if (!success) { // Right now success = false means received a NAK so don't // re-attempt @@ -213,8 +217,7 @@ public class TelemetryMonitor extends Observable { } // Process next object if telemetry is still available - if (((String) gcsStatsObj.getField("Status").getValue()) - .compareTo("Connected") == 0) { + if (((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") == 0) { retrieveNextObject(); } else { stopRetrievingObjects(); @@ -348,7 +351,7 @@ public class TelemetryMonitor extends Observable { connected = true; objects_updated = false; startRetrievingObjects(); - setChanged(); + if (HANDSHAKE_IS_CONNECTED) setChanged(); // Enabling this line makes the opConnected signal occur whenever we get a handshake } if (gcsDisconnected && gcsStatusChanged) { if (DEBUG)