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 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)