mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-05 21:52:10 +01:00
AndroidGCS Telemetry: Get rid of a tier of redirection through annoymous
classes that was legacy from the GCS port.
This commit is contained in:
parent
6ebf4fe87c
commit
de26c3297e
@ -26,6 +26,7 @@ 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;
|
||||||
@ -40,7 +41,7 @@ import android.util.Log;
|
|||||||
public class Telemetry {
|
public class Telemetry {
|
||||||
|
|
||||||
private final String TAG = "Telemetry";
|
private final String TAG = "Telemetry";
|
||||||
public static int LOGLEVEL = 0;
|
public static int LOGLEVEL = 3;
|
||||||
public static boolean WARN = LOGLEVEL > 2;
|
public static boolean WARN = LOGLEVEL > 2;
|
||||||
public static boolean ERROR = LOGLEVEL > 1;
|
public static boolean ERROR = LOGLEVEL > 1;
|
||||||
public static boolean DEBUG = LOGLEVEL > 0;
|
public static boolean DEBUG = LOGLEVEL > 0;
|
||||||
@ -66,6 +67,10 @@ public class Telemetry {
|
|||||||
UAVObject obj;
|
UAVObject obj;
|
||||||
int event;
|
int event;
|
||||||
boolean allInstances;
|
boolean allInstances;
|
||||||
|
|
||||||
|
boolean equals(ObjectQueueInfo e) {
|
||||||
|
return (e.obj.getObjID() == obj.getObjID() && e.event == event && e.allInstances == allInstances) || true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ObjectTransactionInfo {
|
class ObjectTransactionInfo {
|
||||||
@ -112,9 +117,9 @@ public class Telemetry {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen to transaction completions
|
// Listen to transaction completions from uavtalk
|
||||||
this.utalk.setOnTransactionCompletedListener(
|
utalk.setOnTransactionCompletedListener(
|
||||||
this.utalk.new OnTransactionCompletedListener() {
|
utalk.new OnTransactionCompletedListener() {
|
||||||
@Override
|
@Override
|
||||||
void TransactionSucceeded(UAVObject data) {
|
void TransactionSucceeded(UAVObject data) {
|
||||||
try {
|
try {
|
||||||
@ -250,6 +255,54 @@ public class Telemetry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Observer unpackedObserver = new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable observable, Object data) {
|
||||||
|
try {
|
||||||
|
processObjectUpdates((UAVObject) data, EV_UNPACKED, false, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Observer updatedAutoObserver = new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable observable, Object data) {
|
||||||
|
try {
|
||||||
|
processObjectUpdates((UAVObject) data, EV_UPDATED, false, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Observer updatedManualObserver = new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable observable, Object data) {
|
||||||
|
try {
|
||||||
|
processObjectUpdates((UAVObject) data, EV_UPDATED_MANUAL, false, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Observer updatedRequestedObserver = new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable observable, Object data) {
|
||||||
|
try {
|
||||||
|
processObjectUpdates((UAVObject) data, EV_UPDATE_REQ, false, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to all instances of an object depending on the event mask specified
|
* Connect to all instances of an object depending on the event mask specified
|
||||||
*/
|
*/
|
||||||
@ -260,65 +313,25 @@ public class Telemetry {
|
|||||||
while(li.hasNext())
|
while(li.hasNext())
|
||||||
{
|
{
|
||||||
obj = li.next();
|
obj = li.next();
|
||||||
//TODO: Disconnect all
|
// TODO: Disconnect all previous observers from telemetry. This is imortant as this can
|
||||||
// obj.disconnect(this);
|
// be called multiple times
|
||||||
|
|
||||||
// Connect only the selected events
|
// Connect only the selected events
|
||||||
if ( (eventMask&EV_UNPACKED) != 0)
|
if ( (eventMask&EV_UNPACKED) != 0)
|
||||||
{
|
{
|
||||||
obj.addUnpackedObserver(new Observer() {
|
obj.addUnpackedObserver(unpackedObserver);
|
||||||
@Override
|
|
||||||
public void update(Observable observable, Object data) {
|
|
||||||
try {
|
|
||||||
objectUnpacked( (UAVObject) data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if ( (eventMask&EV_UPDATED) != 0)
|
if ( (eventMask&EV_UPDATED) != 0)
|
||||||
{
|
{
|
||||||
obj.addUpdatedAutoObserver(new Observer() {
|
obj.addUpdatedAutoObserver(updatedAutoObserver);
|
||||||
@Override
|
|
||||||
public void update(Observable observable, Object data) {
|
|
||||||
try {
|
|
||||||
objectUpdatedAuto( (UAVObject) data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if ( (eventMask&EV_UPDATED_MANUAL) != 0)
|
if ( (eventMask&EV_UPDATED_MANUAL) != 0)
|
||||||
{
|
{
|
||||||
obj.addUpdatedManualObserver(new Observer() {
|
obj.addUpdatedManualObserver(updatedManualObserver);
|
||||||
@Override
|
|
||||||
public void update(Observable observable, Object data) {
|
|
||||||
try {
|
|
||||||
objectUpdatedManual( (UAVObject) data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if ( (eventMask&EV_UPDATE_REQ) != 0)
|
if ( (eventMask&EV_UPDATE_REQ) != 0)
|
||||||
{
|
{
|
||||||
obj.addUpdateRequestedObserver(new Observer() {
|
obj.addUpdateRequestedObserver(updatedRequestedObserver);
|
||||||
@Override
|
|
||||||
public void update(Observable observable, Object data) {
|
|
||||||
try {
|
|
||||||
updateRequested( (UAVObject) data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,7 +476,7 @@ public class Telemetry {
|
|||||||
* Process the event received from an object
|
* Process the event received from an object
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private synchronized void processObjectUpdates(UAVObject obj, int event, boolean allInstances, boolean priority) throws IOException
|
private void processObjectUpdates(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);
|
||||||
@ -475,28 +488,44 @@ public class Telemetry {
|
|||||||
objInfo.allInstances = allInstances;
|
objInfo.allInstances = allInstances;
|
||||||
if (priority)
|
if (priority)
|
||||||
{
|
{
|
||||||
if ( objPriorityQueue.size() < MAX_QUEUE_SIZE )
|
Iterator <ObjectQueueInfo> it = objPriorityQueue.iterator();
|
||||||
{
|
boolean found = false;
|
||||||
objPriorityQueue.add(objInfo);
|
while(it.hasNext()) {
|
||||||
}
|
ObjectQueueInfo test = it.next();
|
||||||
else
|
if (test.obj.getObjID() == obj.getObjID())
|
||||||
{
|
found = true;
|
||||||
++txErrors;
|
}
|
||||||
obj.transactionCompleted(false);
|
found= false;
|
||||||
Log.w(TAG,"Telemetry: priority event queue is full, event lost " + obj.getName());
|
if(found) {
|
||||||
}
|
Log.w(TAG, "Identical event already in transaction queue: " + objInfo);
|
||||||
|
} else {
|
||||||
|
if ( objPriorityQueue.size() < MAX_QUEUE_SIZE )
|
||||||
|
{
|
||||||
|
objPriorityQueue.add(objInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++txErrors;
|
||||||
|
obj.transactionCompleted(false);
|
||||||
|
Log.w(TAG,"Telemetry: priority event queue is full, event lost " + obj.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( objQueue.size() < MAX_QUEUE_SIZE )
|
if(objQueue.contains(objInfo)) {
|
||||||
{
|
Log.w(TAG, "Identical event already in queue: " + objInfo);
|
||||||
objQueue.add(objInfo);
|
} else {
|
||||||
}
|
if ( objQueue.size() < MAX_QUEUE_SIZE )
|
||||||
else
|
{
|
||||||
{
|
objQueue.add(objInfo);
|
||||||
++txErrors;
|
}
|
||||||
obj.transactionCompleted(false);
|
else
|
||||||
}
|
{
|
||||||
|
++txErrors;
|
||||||
|
obj.transactionCompleted(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no transaction in progress then process event
|
// If there is no transaction in progress then process event
|
||||||
@ -679,25 +708,6 @@ public class Telemetry {
|
|||||||
txRetries = 0;
|
txRetries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void objectUpdatedAuto(UAVObject obj) throws IOException
|
|
||||||
{
|
|
||||||
processObjectUpdates(obj, EV_UPDATED, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void objectUpdatedManual(UAVObject obj) throws IOException
|
|
||||||
{
|
|
||||||
processObjectUpdates(obj, EV_UPDATED_MANUAL, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void objectUnpacked(UAVObject obj) throws IOException
|
|
||||||
{
|
|
||||||
processObjectUpdates(obj, EV_UNPACKED, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void updateRequested(UAVObject obj) throws IOException
|
|
||||||
{
|
|
||||||
processObjectUpdates(obj, EV_UPDATE_REQ, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void newObject(UAVObject obj)
|
private void newObject(UAVObject obj)
|
||||||
{
|
{
|
||||||
|
@ -193,7 +193,7 @@ public class TelemetryMonitor extends Observable {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Request update
|
// Request update
|
||||||
tel.updateRequested(obj);
|
obj.updateRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user