1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

AndroidGCS TelemetryMonitor: Now that transactions are working more reliably we

can emit the connected signal at the end of fetching all the objects.
This commit is contained in:
James Cotton 2012-08-10 16:11:20 -05:00
parent 38117f6e69
commit 9985910969

View File

@ -48,6 +48,8 @@ public class TelemetryMonitor extends Observable {
static final int STATS_CONNECT_PERIOD_MS = 1000; static final int STATS_CONNECT_PERIOD_MS = 1000;
static final int CONNECTION_TIMEOUT_MS = 8000; static final int CONNECTION_TIMEOUT_MS = 8000;
private final boolean HANDSHAKE_IS_CONNECTED = false;
private final UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private final Telemetry tel; private final Telemetry tel;
// private UAVObject objPending; // private UAVObject objPending;
@ -147,6 +149,20 @@ public class TelemetryMonitor extends Observable {
queue.clear(); 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 * Retrieve the next object in the queue
* *
@ -155,11 +171,12 @@ public class TelemetryMonitor extends Observable {
public synchronized void retrieveNextObject() throws IOException { public synchronized void retrieveNextObject() throws IOException {
// If queue is empty return // If queue is empty return
if (queue.isEmpty()) { if (queue.isEmpty()) {
if (DEBUG) if (DEBUG || true) Log.d(TAG, "All objects retrieved: Connected Successfully");
Log.d(TAG, "All objects retrieved: Connected Successfully");
objects_updated = true; objects_updated = true;
//setChanged(); if (!HANDSHAKE_IS_CONNECTED) {
//notifyObservers(); setChanged();
notifyObservers();
}
return; return;
} }
// Get next object from the queue // 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 // TODO: Does this need to stay here permanently? This appears to be
// used for setup mainly // used for setup mainly
obj.addTransactionCompleted(new Observer() { obj.addTransactionCompleted(transactionObserver);
@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);
}
}
});
// Request update // Request update
obj.updateRequested(); obj.updateRequested();
@ -206,6 +207,9 @@ public class TelemetryMonitor extends Observable {
if (DEBUG) if (DEBUG)
Log.d(TAG, "transactionCompleted. Status: " + success); Log.d(TAG, "transactionCompleted. Status: " + success);
// Remove the listener for the event that just finished
obj.removeTransactionCompleted(transactionObserver);
if (!success) { if (!success) {
// Right now success = false means received a NAK so don't // Right now success = false means received a NAK so don't
// re-attempt // re-attempt
@ -213,8 +217,7 @@ public class TelemetryMonitor extends Observable {
} }
// Process next object if telemetry is still available // Process next object if telemetry is still available
if (((String) gcsStatsObj.getField("Status").getValue()) if (((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") == 0) {
.compareTo("Connected") == 0) {
retrieveNextObject(); retrieveNextObject();
} else { } else {
stopRetrievingObjects(); stopRetrievingObjects();
@ -348,7 +351,7 @@ public class TelemetryMonitor extends Observable {
connected = true; connected = true;
objects_updated = false; objects_updated = false;
startRetrievingObjects(); startRetrievingObjects();
setChanged(); if (HANDSHAKE_IS_CONNECTED) setChanged(); // Enabling this line makes the opConnected signal occur whenever we get a handshake
} }
if (gcsDisconnected && gcsStatusChanged) { if (gcsDisconnected && gcsStatusChanged) {
if (DEBUG) if (DEBUG)