1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

AndroidGCS: Make the telemetry monitor deal with loading the UAVO set before

starting to retrieve all the objects.
This commit is contained in:
James Cotton 2012-10-14 14:28:24 -05:00
parent c6936870c1
commit 16adf27082
2 changed files with 45 additions and 34 deletions

View File

@ -8,8 +8,6 @@ import java.util.Observer;
import org.openpilot.uavtalk.Telemetry; import org.openpilot.uavtalk.Telemetry;
import org.openpilot.uavtalk.TelemetryMonitor; import org.openpilot.uavtalk.TelemetryMonitor;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField;
import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVTalk; import org.openpilot.uavtalk.UAVTalk;
import org.openpilot.uavtalk.uavobjects.TelemObjectsInitialize; import org.openpilot.uavtalk.uavobjects.TelemObjectsInitialize;
@ -93,32 +91,6 @@ public abstract class TelemetryTask implements Runnable {
*/ */
abstract boolean attemptConnection(); abstract boolean attemptConnection();
private final Observer firmwareIapUpdated = new Observer() {
@Override
public void update(Observable observable, Object data) {
if (DEBUG) Log.d(TAG, "Received firmware IAP Updated message");
UAVObject obj = objMngr.getObject("FirmwareIAPObj");
UAVObjectField description = obj.getField("Description");
if(description == null || description.getNumElements() < 100) {
telemService.toastMessage("Failed to determine UAVO set");
} else {
final int HASH_SIZE_USED = 8;
String jarName = new String();
for(int i = 0; i < HASH_SIZE_USED; i++)
jarName += Integer.toHexString((int) description.getDouble(i+60));
jarName += ".jar";
if (DEBUG) Log.d(TAG, "Attempting to load: " + jarName);
if (telemService.loadUavobjects(jarName, objMngr) ) {
telemService.toastMessage("Loaded appropriate UAVO set");
} else
telemService.toastMessage("Failed to determine UAVO set");
}
obj.removeUpdatedObserver(this);
}
};
/** /**
* Called when a physical channel is opened * Called when a physical channel is opened
* *
@ -133,11 +105,6 @@ public abstract class TelemetryTask implements Runnable {
objMngr = new UAVObjectManager(); objMngr = new UAVObjectManager();
TelemObjectsInitialize.register(objMngr); TelemObjectsInitialize.register(objMngr);
// Register to get an update from FirmwareIAP in order to register
// the appropriate objects
UAVObject obj = objMngr.getObject("FirmwareIAPObj");
obj.addUpdatedObserver(firmwareIapUpdated);
// Create the required telemetry objects attached to this // Create the required telemetry objects attached to this
// data stream // data stream
uavTalk = new UAVTalk(inStream, outStream, objMngr); uavTalk = new UAVTalk(inStream, outStream, objMngr);

View File

@ -54,9 +54,12 @@ public class TelemetryMonitor extends Observable {
private final UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private final Telemetry tel; private final Telemetry tel;
private boolean objectsRegistered;
// private UAVObject objPending; // private UAVObject objPending;
private UAVObject gcsStatsObj; private UAVObject gcsStatsObj;
private UAVObject flightStatsObj; private UAVObject flightStatsObj;
private final UAVObject firmwareIapObj;
private Timer periodicTask; private Timer periodicTask;
private int currentPeriod; private int currentPeriod;
private long lastUpdateTime; private long lastUpdateTime;
@ -85,9 +88,15 @@ public class TelemetryMonitor extends Observable {
// this.objPending = null; // this.objPending = null;
queue = new ArrayList<UAVObject>(); queue = new ArrayList<UAVObject>();
objectsRegistered = false;
// Get stats objects // Get stats objects
gcsStatsObj = objMngr.getObject("GCSTelemetryStats"); gcsStatsObj = objMngr.getObject("GCSTelemetryStats");
flightStatsObj = objMngr.getObject("FlightTelemetryStats"); flightStatsObj = objMngr.getObject("FlightTelemetryStats");
firmwareIapObj = objMngr.getObject("FirmwareIAPObj");
// The first update of the firmwareIapObj will trigger registering the objects
firmwareIapObj.addUpdatedObserver(firmwareIapUpdated);
flightStatsObj.addUpdatedObserver(new Observer() { flightStatsObj.addUpdatedObserver(new Observer() {
@Override @Override
@ -360,7 +369,10 @@ public class TelemetryMonitor extends Observable {
setPeriod(STATS_UPDATE_PERIOD_MS); setPeriod(STATS_UPDATE_PERIOD_MS);
connected = true; connected = true;
objects_updated = false; objects_updated = false;
if (objectsRegistered)
startRetrievingObjects(); startRetrievingObjects();
else
firmwareIapObj.updateRequested();
if (HANDSHAKE_IS_CONNECTED) setChanged(); // Enabling this line makes the opConnected signal occur whenever we get a handshake if (HANDSHAKE_IS_CONNECTED) setChanged(); // Enabling this line makes the opConnected signal occur whenever we get a handshake
} }
if (gcsDisconnected && gcsStatusChanged) { if (gcsDisconnected && gcsStatusChanged) {
@ -405,4 +417,36 @@ public class TelemetryMonitor extends Observable {
periodicTask = null; periodicTask = null;
} }
private final Observer firmwareIapUpdated = new Observer() {
@Override
public void update(Observable observable, Object data) {
if (DEBUG) Log.d(TAG, "Received firmware IAP Updated message");
UAVObjectField description = firmwareIapObj.getField("Description");
if(description == null || description.getNumElements() < 100) {
telemService.toastMessage("Failed to determine UAVO set");
} else {
final int HASH_SIZE_USED = 8;
String jarName = new String();
for(int i = 0; i < HASH_SIZE_USED; i++)
jarName += Integer.toHexString((int) description.getDouble(i+60));
jarName += ".jar";
if (DEBUG) Log.d(TAG, "Attempting to load: " + jarName);
if (telemService.loadUavobjects(jarName, objMngr) ) {
telemService.toastMessage("Loaded appropriate UAVO set");
objectsRegistered = true;
try {
startRetrievingObjects();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
telemService.toastMessage("Failed to load UAVO set: " + jarName);
}
firmwareIapObj.removeUpdatedObserver(this);
}
};
} }