mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Fixed bug in object signals that stopped updates sending. Various tweaks.
This commit is contained in:
parent
55e0834051
commit
7b20773100
@ -1,5 +1,6 @@
|
|||||||
package org.openpilot.uavtalk;
|
package org.openpilot.uavtalk;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
@ -91,6 +92,15 @@ public class Telemetry {
|
|||||||
|
|
||||||
// Setup transaction timer
|
// Setup transaction timer
|
||||||
transPending = false;
|
transPending = false;
|
||||||
|
// Setup and start the periodic timer
|
||||||
|
timeToNextUpdateMs = 0;
|
||||||
|
updateTimerSetPeriod(1000);
|
||||||
|
// Setup and start the stats timer
|
||||||
|
txErrors = 0;
|
||||||
|
txRetries = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void transTimerSetPeriod(int periodMs) {
|
||||||
transTimer = new Timer();
|
transTimer = new Timer();
|
||||||
transTimerTask = new TimerTask() {
|
transTimerTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
@ -98,9 +108,10 @@ public class Telemetry {
|
|||||||
transactionTimeout();
|
transactionTimeout();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Setup and start the periodic timer
|
transTimer.schedule(transTimerTask, periodMs, periodMs);
|
||||||
timeToNextUpdateMs = 0;
|
}
|
||||||
|
|
||||||
|
synchronized void updateTimerSetPeriod(int periodMs) {
|
||||||
updateTimer = new Timer();
|
updateTimer = new Timer();
|
||||||
updateTimerTask = new TimerTask() {
|
updateTimerTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
@ -108,10 +119,8 @@ public class Telemetry {
|
|||||||
processPeriodicUpdates();
|
processPeriodicUpdates();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
updateTimer.scheduleAtFixedRate(updateTimerTask, 1000, 1000);
|
updateTimer.schedule(updateTimerTask, periodMs, periodMs);
|
||||||
// Setup and start the stats timer
|
|
||||||
txErrors = 0;
|
|
||||||
txRetries = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,7 +350,7 @@ public class Telemetry {
|
|||||||
// Start timer if a response is expected
|
// Start timer if a response is expected
|
||||||
if ( transInfo.objRequest || transInfo.acked == Acked.TRUE )
|
if ( transInfo.objRequest || transInfo.acked == Acked.TRUE )
|
||||||
{
|
{
|
||||||
transTimer.scheduleAtFixedRate(transTimerTask, REQ_TIMEOUT_MS, REQ_TIMEOUT_MS);
|
transTimerSetPeriod(REQ_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -433,6 +442,7 @@ public class Telemetry {
|
|||||||
|
|
||||||
// Check if a connection has been established, only process GCSTelemetryStats updates
|
// Check if a connection has been established, only process GCSTelemetryStats updates
|
||||||
// (used to establish the connection)
|
// (used to establish the connection)
|
||||||
|
gcsStatsObj = objMngr.getObject("GCSTelemetryStats");
|
||||||
if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 )
|
if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 )
|
||||||
{
|
{
|
||||||
objQueue.clear();
|
objQueue.clear();
|
||||||
@ -538,8 +548,7 @@ public class Telemetry {
|
|||||||
timeToNextUpdateMs = minDelay;
|
timeToNextUpdateMs = minDelay;
|
||||||
|
|
||||||
// Restart timer
|
// Restart timer
|
||||||
//updateTimer->start(timeToNextUpdateMs);
|
updateTimerSetPeriod(timeToNextUpdateMs);
|
||||||
updateTimer.scheduleAtFixedRate(updateTimerTask, timeToNextUpdateMs, timeToNextUpdateMs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelemetryStats getStats()
|
public TelemetryStats getStats()
|
||||||
@ -607,10 +616,10 @@ public class Telemetry {
|
|||||||
private UAVObjectManager objMngr;
|
private UAVObjectManager objMngr;
|
||||||
private UAVTalk utalk;
|
private UAVTalk utalk;
|
||||||
private UAVObject gcsStatsObj;
|
private UAVObject gcsStatsObj;
|
||||||
private List<ObjectTimeInfo> objList;
|
private List<ObjectTimeInfo> objList = new ArrayList<ObjectTimeInfo>();
|
||||||
private Queue<ObjectQueueInfo> objQueue = new LinkedList<ObjectQueueInfo>();
|
private Queue<ObjectQueueInfo> objQueue = new LinkedList<ObjectQueueInfo>();
|
||||||
private Queue<ObjectQueueInfo> objPriorityQueue = new LinkedList<ObjectQueueInfo>();
|
private Queue<ObjectQueueInfo> objPriorityQueue = new LinkedList<ObjectQueueInfo>();
|
||||||
private ObjectTransactionInfo transInfo;
|
private ObjectTransactionInfo transInfo = new ObjectTransactionInfo();
|
||||||
private boolean transPending;
|
private boolean transPending;
|
||||||
|
|
||||||
private Timer updateTimer;
|
private Timer updateTimer;
|
||||||
|
@ -92,7 +92,7 @@ public class TelemetryMonitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Start retrieving
|
// Start retrieving
|
||||||
Log.d(TAG,"Starting to retrieve meta and settings objects from the autopilot (%1 objects)" + queue.size()) ;
|
System.out.println(TAG + "Starting to retrieve meta and settings objects from the autopilot (" + queue.size() + " objects)");
|
||||||
retrieveNextObject();
|
retrieveNextObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public class TelemetryMonitor {
|
|||||||
// Get next object from the queue
|
// Get next object from the queue
|
||||||
UAVObject obj = queue.remove(0);
|
UAVObject obj = queue.remove(0);
|
||||||
|
|
||||||
Log.d(TAG, "Retrieving object: " + obj.getName()) ;
|
// Log.d(TAG, "Retrieving object: " + obj.getName()) ;
|
||||||
// Connect to object
|
// Connect to object
|
||||||
obj.addTransactionCompleted(new Observer() {
|
obj.addTransactionCompleted(new Observer() {
|
||||||
public void update(Observable observable, Object data) {
|
public void update(Observable observable, Object data) {
|
||||||
@ -161,6 +161,10 @@ public class TelemetryMonitor {
|
|||||||
public synchronized void flightStatsUpdated(UAVObject obj)
|
public synchronized void flightStatsUpdated(UAVObject obj)
|
||||||
{
|
{
|
||||||
// Force update if not yet connected
|
// Force update if not yet connected
|
||||||
|
gcsStatsObj = objMngr.getObject("GCSTelemetryStats");
|
||||||
|
flightStatsObj = objMngr.getObject("FlightTelemetryStats");
|
||||||
|
|
||||||
|
System.out.println(flightStatsObj.toString());
|
||||||
if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 ||
|
if ( ((String) gcsStatsObj.getField("Status").getValue()).compareTo("Connected") != 0 ||
|
||||||
((String) flightStatsObj.getField("Status").getValue()).compareTo("Connected") == 0 )
|
((String) flightStatsObj.getField("Status").getValue()).compareTo("Connected") == 0 )
|
||||||
{
|
{
|
||||||
@ -204,8 +208,17 @@ public class TelemetryMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update connection state
|
// Update connection state
|
||||||
UAVObjectField statusField = gcsStatsObj.getField("Connection");
|
gcsStatsObj = objMngr.getObject("GCSTelemetryStats");
|
||||||
|
flightStatsObj = objMngr.getObject("FlightTelemetryStats");
|
||||||
|
if(gcsStatsObj == null) {
|
||||||
|
System.out.println("No GCS stats yet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UAVObjectField statusField = gcsStatsObj.getField("Status");
|
||||||
String oldStatus = (String) statusField.getValue();
|
String oldStatus = (String) statusField.getValue();
|
||||||
|
|
||||||
|
System.out.println("GCS: " + statusField.getValue() + " Flight: " + flightStatsObj.getField("Status").getValue());
|
||||||
|
|
||||||
if ( oldStatus.compareTo("Disconnected") == 0 )
|
if ( oldStatus.compareTo("Disconnected") == 0 )
|
||||||
{
|
{
|
||||||
// Request connection
|
// Request connection
|
||||||
@ -217,6 +230,7 @@ public class TelemetryMonitor {
|
|||||||
if ( ((String) flightStatsObj.getField("Status").getValue()).compareTo("HandshakeAck") == 0 )
|
if ( ((String) flightStatsObj.getField("Status").getValue()).compareTo("HandshakeAck") == 0 )
|
||||||
{
|
{
|
||||||
statusField.setValue("Connected");
|
statusField.setValue("Connected");
|
||||||
|
System.out.println("Connected" + statusField.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( oldStatus.compareTo("Connected") == 0 )
|
else if ( oldStatus.compareTo("Connected") == 0 )
|
||||||
@ -230,11 +244,18 @@ public class TelemetryMonitor {
|
|||||||
|
|
||||||
// Force telemetry update if not yet connected
|
// Force telemetry update if not yet connected
|
||||||
boolean gcsStatusChanged = !oldStatus.equals(statusField.getValue());
|
boolean gcsStatusChanged = !oldStatus.equals(statusField.getValue());
|
||||||
|
|
||||||
|
if(gcsStatusChanged)
|
||||||
|
System.out.println("GCS Status changed");
|
||||||
boolean gcsConnected = ((String) statusField.getValue()).compareTo("Connected") == 0;
|
boolean gcsConnected = ((String) statusField.getValue()).compareTo("Connected") == 0;
|
||||||
boolean gcsDisconnected = ((String) statusField.getValue()).compareTo("Disconnected") == 0;
|
boolean gcsDisconnected = ((String) statusField.getValue()).compareTo("Disconnected") == 0;
|
||||||
|
|
||||||
|
if(gcsConnected)
|
||||||
|
System.out.println("Detected here");
|
||||||
if ( gcsStatusChanged ||
|
if ( gcsStatusChanged ||
|
||||||
((String) flightStatsObj.getField("Status").getValue()).compareTo("Disconnected") != 0 )
|
((String) flightStatsObj.getField("Status").getValue()).compareTo("Disconnected") != 0 )
|
||||||
{
|
{
|
||||||
|
System.out.println("Sending gcs status\n\n\n");
|
||||||
gcsStatsObj.updated();
|
gcsStatsObj.updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,14 +263,15 @@ public class TelemetryMonitor {
|
|||||||
if (gcsConnected && gcsStatusChanged)
|
if (gcsConnected && gcsStatusChanged)
|
||||||
{
|
{
|
||||||
setPeriod(STATS_UPDATE_PERIOD_MS);
|
setPeriod(STATS_UPDATE_PERIOD_MS);
|
||||||
Log.d(TAG,"Connection with the autopilot established");
|
System.out.println(TAG + " Connection with the autopilot established");
|
||||||
|
//Log.d(TAG,"Connection with the autopilot established");
|
||||||
startRetrievingObjects();
|
startRetrievingObjects();
|
||||||
}
|
}
|
||||||
if (gcsDisconnected && gcsStatusChanged)
|
if (gcsDisconnected && gcsStatusChanged)
|
||||||
{
|
{
|
||||||
setPeriod(STATS_CONNECT_PERIOD_MS);
|
setPeriod(STATS_CONNECT_PERIOD_MS);
|
||||||
Log.d(TAG,"Connection with the autopilot lost");
|
System.out.println(TAG + " Connection with the autopilot lost");
|
||||||
Log.d(TAG,"Trying to connect to the autopilot");
|
//Log.d(TAG,"Trying to connect to the autopilot");
|
||||||
//emit disconnected();
|
//emit disconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,6 +282,7 @@ public class TelemetryMonitor {
|
|||||||
|
|
||||||
periodicTask.cancel();
|
periodicTask.cancel();
|
||||||
currentPeriod = ms;
|
currentPeriod = ms;
|
||||||
|
periodicTask = new Timer();
|
||||||
periodicTask.scheduleAtFixedRate(new TimerTask() {
|
periodicTask.scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -24,7 +24,7 @@ public abstract class UAVDataObject extends UAVObject {
|
|||||||
super.initialize(instID);
|
super.initialize(instID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMetadata() { return true; };
|
public boolean isMetadata() { return false; };
|
||||||
/**
|
/**
|
||||||
* Assign a metaobject
|
* Assign a metaobject
|
||||||
*/
|
*/
|
||||||
|
@ -53,11 +53,14 @@ public abstract class UAVObject {
|
|||||||
updatedListeners.addObserver(o);
|
updatedListeners.addObserver(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void updated() {
|
void updated(boolean manually) {
|
||||||
synchronized(updatedListeners) {
|
synchronized(updatedListeners) {
|
||||||
updatedListeners.event();
|
updatedListeners.event();
|
||||||
}
|
}
|
||||||
|
if(manually)
|
||||||
|
updatedManual();
|
||||||
}
|
}
|
||||||
|
void updated() { updated(true); };
|
||||||
|
|
||||||
private CallbackListener unpackedListeners = new CallbackListener(this);
|
private CallbackListener unpackedListeners = new CallbackListener(this);
|
||||||
public void addUnpackedObserver(Observer o) {
|
public void addUnpackedObserver(Observer o) {
|
||||||
@ -67,7 +70,6 @@ public abstract class UAVObject {
|
|||||||
}
|
}
|
||||||
void unpacked() {
|
void unpacked() {
|
||||||
synchronized(unpackedListeners) {
|
synchronized(unpackedListeners) {
|
||||||
System.out.println("Unpacked!: " + unpackedListeners.countObservers() + " " + getName());
|
|
||||||
unpackedListeners.event();
|
unpackedListeners.event();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,7 +389,7 @@ public abstract class UAVObject {
|
|||||||
|
|
||||||
// Trigger all the listeners for the unpack event
|
// Trigger all the listeners for the unpack event
|
||||||
unpacked();
|
unpacked();
|
||||||
updated();
|
updated(false);
|
||||||
|
|
||||||
return numBytes;
|
return numBytes;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class UAVObjectField {
|
|||||||
case UINT32:
|
case UINT32:
|
||||||
// TODO: Deal properly with unsigned
|
// TODO: Deal properly with unsigned
|
||||||
for (int index = 0; index < numElements; ++index) {
|
for (int index = 0; index < numElements; ++index) {
|
||||||
Integer val = (Integer) getValue(index);
|
Integer val = (int) ( ((Long) getValue(index)).longValue() & 0xffffffffL);
|
||||||
dataOut.putInt(val);
|
dataOut.putInt(val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -364,7 +364,7 @@ public class UAVObjectField {
|
|||||||
|
|
||||||
public double getDouble() { return getDouble(0); };
|
public double getDouble() { return getDouble(0); };
|
||||||
public double getDouble(int index) {
|
public double getDouble(int index) {
|
||||||
return Double.valueOf((Double) getValue(index));
|
return ((Number) getValue(index)).doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDouble(double value) { setDouble(value, 0); };
|
public void setDouble(double value) { setDouble(value, 0); };
|
||||||
|
@ -200,9 +200,9 @@ public class UAVTalk extends Observable{
|
|||||||
* \param[in] allInstances If set true then all instances will be updated
|
* \param[in] allInstances If set true then all instances will be updated
|
||||||
* \return Success (true), Failure (false)
|
* \return Success (true), Failure (false)
|
||||||
*/
|
*/
|
||||||
public boolean sendObject(UAVObject obj, boolean acked, boolean allInstances)
|
public synchronized boolean sendObject(UAVObject obj, boolean acked, boolean allInstances)
|
||||||
{
|
{
|
||||||
//QMutexLocker locker(mutex);
|
System.out.println("Sending obj: " + obj.toString());
|
||||||
if (acked)
|
if (acked)
|
||||||
{
|
{
|
||||||
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
|
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
|
||||||
@ -216,9 +216,8 @@ public class UAVTalk extends Observable{
|
|||||||
/**
|
/**
|
||||||
* Cancel a pending transaction
|
* Cancel a pending transaction
|
||||||
*/
|
*/
|
||||||
public void cancelTransaction()
|
public synchronized void cancelTransaction()
|
||||||
{
|
{
|
||||||
//QMutexLocker locker(mutex);
|
|
||||||
respObj = null;
|
respObj = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,6 +249,7 @@ public class UAVTalk extends Observable{
|
|||||||
}
|
}
|
||||||
else if (type == TYPE_OBJ)
|
else if (type == TYPE_OBJ)
|
||||||
{
|
{
|
||||||
|
System.out.println("Transmitting object: " + obj.toString());
|
||||||
return transmitObject(obj, TYPE_OBJ, allInstances);
|
return transmitObject(obj, TYPE_OBJ, allInstances);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -763,7 +763,12 @@ public class UAVTalk extends Observable{
|
|||||||
bbuf.put((byte) (updateCRC(0, bbuf.array()) & 0xff));
|
bbuf.put((byte) (updateCRC(0, bbuf.array()) & 0xff));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
outStream.write(bbuf.array());
|
int packlen = bbuf.position();
|
||||||
|
bbuf.position(0);
|
||||||
|
byte [] dst = new byte[packlen];
|
||||||
|
bbuf.get(dst,0,packlen);
|
||||||
|
System.out.println("Outputting: " + dst.length);
|
||||||
|
outStream.write(dst);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user