1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

AndroidGCS Telemetry: Telemetry no longer enqueues identical object

transactions multiple times so only the most recent will occur.  Since it
doesn't enqueue the data the end behavior to the UAV should be identical.

Also renamed processObjectUpdates to enqueueObjectUpdates to make it more
intuitive.
This commit is contained in:
James Cotton 2012-08-10 15:58:52 -05:00
parent 1d361a53cd
commit 38117f6e69
2 changed files with 34 additions and 32 deletions

View File

@ -26,7 +26,6 @@ package org.openpilot.uavtalk;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -41,10 +40,10 @@ import android.util.Log;
public class Telemetry { public class Telemetry {
private final String TAG = "Telemetry"; private final String TAG = "Telemetry";
public static int LOGLEVEL = 3; public static int LOGLEVEL = 1;
public static boolean WARN = LOGLEVEL > 2; public static boolean WARN = LOGLEVEL > 2;
public static boolean ERROR = LOGLEVEL > 1; public static boolean DEBUG = LOGLEVEL > 1;
public static boolean DEBUG = LOGLEVEL > 0; public static boolean ERROR = LOGLEVEL > 0;
public class TelemetryStats { public class TelemetryStats {
public int txBytes; public int txBytes;
public int rxBytes; public int rxBytes;
@ -68,8 +67,15 @@ public class Telemetry {
int event; int event;
boolean allInstances; boolean allInstances;
boolean equals(ObjectQueueInfo e) { @Override
return (e.obj.getObjID() == obj.getObjID() && e.event == event && e.allInstances == allInstances) || true; public boolean equals(Object e) {
try {
ObjectQueueInfo o = (ObjectQueueInfo) e;
return o.obj.getObjID() == obj.getObjID() && o.event == event && o.allInstances == allInstances;
} catch (Exception err) {
};
return false;
} }
}; };
@ -133,6 +139,7 @@ public class Telemetry {
void TransactionFailed(UAVObject data) { void TransactionFailed(UAVObject data) {
try { try {
if (DEBUG) Log.d(TAG, "TransactionFailed(" + data.getName() + ")"); if (DEBUG) Log.d(TAG, "TransactionFailed(" + data.getName() + ")");
transactionCompleted(data, false); transactionCompleted(data, false);
} catch (IOException e) { } catch (IOException e) {
// Disconnect when stream fails // Disconnect when stream fails
@ -259,7 +266,7 @@ public class Telemetry {
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
processObjectUpdates((UAVObject) data, EV_UNPACKED, false, true); enqueueObjectUpdates((UAVObject) data, EV_UNPACKED, false, true);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -271,7 +278,7 @@ public class Telemetry {
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
processObjectUpdates((UAVObject) data, EV_UPDATED, false, true); enqueueObjectUpdates((UAVObject) data, EV_UPDATED, false, true);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -283,7 +290,7 @@ public class Telemetry {
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
processObjectUpdates((UAVObject) data, EV_UPDATED_MANUAL, false, true); enqueueObjectUpdates((UAVObject) data, EV_UPDATED_MANUAL, false, true);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -295,7 +302,7 @@ public class Telemetry {
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
processObjectUpdates((UAVObject) data, EV_UPDATE_REQ, false, true); enqueueObjectUpdates((UAVObject) data, EV_UPDATE_REQ, false, true);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -404,6 +411,7 @@ public class Telemetry {
} else } else
{ {
if (ERROR) Log.e(TAG,"Error: received a transaction completed when did not expect it."); if (ERROR) Log.e(TAG,"Error: received a transaction completed when did not expect it.");
transPending = false;
} }
} }
@ -427,9 +435,13 @@ public class Telemetry {
} }
else else
{ {
if (ERROR) Log.e(TAG, "Transaction failed for: " + transInfo.obj.getName());
// Terminate transaction. This triggers UAVTalk to send a transaction // Terminate transaction. This triggers UAVTalk to send a transaction
// failed signal which will make the next queue entry be processed // failed signal which will make the next queue entry be processed
//utalk.cancelPendingTransaction(); // Note this is UAVTalk listener TransactionFailed function and not the
// object specific transaction failed.
utalk.cancelPendingTransaction(transInfo.obj);
++txErrors; ++txErrors;
} }
} }
@ -470,10 +482,10 @@ public class Telemetry {
} }
/** /**
* Process the event received from an object * Enqueue the event received from an object. This is the main method that handles all the callbacks
* @throws IOException * from UAVObjects (due to updates, or update requests)
*/ */
private void processObjectUpdates(UAVObject obj, int event, boolean allInstances, boolean priority) throws IOException private synchronized void enqueueObjectUpdates(UAVObject obj, int event, boolean allInstances, boolean priority) throws IOException
{ {
// Push event into queue // Push event into queue
if (DEBUG) Log.d(TAG, "Push event into queue for obj " + obj.getName() + " event " + event); if (DEBUG) Log.d(TAG, "Push event into queue for obj " + obj.getName() + " event " + event);
@ -485,17 +497,8 @@ public class Telemetry {
objInfo.allInstances = allInstances; objInfo.allInstances = allInstances;
if (priority) if (priority)
{ {
Iterator <ObjectQueueInfo> it = objPriorityQueue.iterator(); // Only enqueue if an identical transaction does not already exist
boolean found = false; if(!objPriorityQueue.contains(objInfo)) {
while(it.hasNext()) {
ObjectQueueInfo test = it.next();
if (test.obj.getObjID() == obj.getObjID())
found = true;
}
found= false;
if(found) {
Log.w(TAG, "Identical event already in transaction queue: " + objInfo);
} else {
if ( objPriorityQueue.size() < MAX_QUEUE_SIZE ) if ( objPriorityQueue.size() < MAX_QUEUE_SIZE )
{ {
objPriorityQueue.add(objInfo); objPriorityQueue.add(objInfo);
@ -510,9 +513,8 @@ public class Telemetry {
} }
else else
{ {
if(objQueue.contains(objInfo)) { // Only enqueue if an identical transaction does not already exist
Log.w(TAG, "Identical event already in queue: " + objInfo); if(!objQueue.contains(objInfo)) {
} else {
if ( objQueue.size() < MAX_QUEUE_SIZE ) if ( objQueue.size() < MAX_QUEUE_SIZE )
{ {
objQueue.add(objInfo); objQueue.add(objInfo);
@ -543,7 +545,7 @@ public class Telemetry {
// Don nothing if a transaction is already in progress (should not happen) // Don nothing if a transaction is already in progress (should not happen)
if (transPending) if (transPending)
{ {
if (ERROR) Log.e(TAG,"Dequeue while a transaction pending"); if (WARN) Log.e(TAG,"Dequeue while a transaction pending");
return; return;
} }
@ -611,7 +613,7 @@ public class Telemetry {
// we do not have additional objects still in the queue, // we do not have additional objects still in the queue,
// so we have to reschedule queue processing to make sure they are not // so we have to reschedule queue processing to make sure they are not
// stuck: // stuck:
if ( objInfo.event == EV_UNPACKED ) if ( objInfo.event == EV_UNPACKED && !transPending)
processObjectQueue(); processObjectQueue();
} }
@ -651,7 +653,7 @@ public class Telemetry {
objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs - offset; objinfo.timeToNextUpdateMs = objinfo.updatePeriodMs - offset;
// Send object // Send object
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
processObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false); enqueueObjectUpdates(objinfo.obj, EV_UPDATED_MANUAL, true, false);
elapsedMs = (int) (System.currentTimeMillis() - startTime); elapsedMs = (int) (System.currentTimeMillis() - startTime);
// Update timeToNextUpdateMs with the elapsed delay of sending the object; // Update timeToNextUpdateMs with the elapsed delay of sending the object;
timeToNextUpdateMs += elapsedMs; timeToNextUpdateMs += elapsedMs;

View File

@ -38,7 +38,7 @@ import android.util.Log;
public class UAVTalk { public class UAVTalk {
static final String TAG = "UAVTalk"; static final String TAG = "UAVTalk";
public static int LOGLEVEL = 0; public static int LOGLEVEL = 1;
public static boolean VERBOSE = LOGLEVEL > 3; public static boolean VERBOSE = LOGLEVEL > 3;
public static boolean WARN = LOGLEVEL > 2; public static boolean WARN = LOGLEVEL > 2;
public static boolean DEBUG = LOGLEVEL > 1; public static boolean DEBUG = LOGLEVEL > 1;