diff --git a/androidgcs/src/org/openpilot/androidgcs/telemetry/TelemetryTask.java b/androidgcs/src/org/openpilot/androidgcs/telemetry/TelemetryTask.java index 3f5122579..ad23b2e00 100644 --- a/androidgcs/src/org/openpilot/androidgcs/telemetry/TelemetryTask.java +++ b/androidgcs/src/org/openpilot/androidgcs/telemetry/TelemetryTask.java @@ -8,8 +8,6 @@ import java.util.Observer; import org.openpilot.uavtalk.Telemetry; import org.openpilot.uavtalk.TelemetryMonitor; -import org.openpilot.uavtalk.UAVObject; -import org.openpilot.uavtalk.UAVObjectField; import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVTalk; import org.openpilot.uavtalk.uavobjects.TelemObjectsInitialize; @@ -93,32 +91,6 @@ public abstract class TelemetryTask implements Runnable { */ 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 * @@ -133,11 +105,6 @@ public abstract class TelemetryTask implements Runnable { objMngr = new UAVObjectManager(); 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 // data stream uavTalk = new UAVTalk(inStream, outStream, objMngr); diff --git a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java index 121a5ebcc..b1313b578 100644 --- a/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java +++ b/androidgcs/src/org/openpilot/uavtalk/TelemetryMonitor.java @@ -54,9 +54,12 @@ public class TelemetryMonitor extends Observable { private final UAVObjectManager objMngr; private final Telemetry tel; + + private boolean objectsRegistered; // private UAVObject objPending; private UAVObject gcsStatsObj; private UAVObject flightStatsObj; + private final UAVObject firmwareIapObj; private Timer periodicTask; private int currentPeriod; private long lastUpdateTime; @@ -85,9 +88,15 @@ public class TelemetryMonitor extends Observable { // this.objPending = null; queue = new ArrayList(); + objectsRegistered = false; + // Get stats objects gcsStatsObj = objMngr.getObject("GCSTelemetryStats"); 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() { @Override @@ -360,7 +369,10 @@ public class TelemetryMonitor extends Observable { setPeriod(STATS_UPDATE_PERIOD_MS); connected = true; objects_updated = false; - startRetrievingObjects(); + if (objectsRegistered) + startRetrievingObjects(); + else + firmwareIapObj.updateRequested(); if (HANDSHAKE_IS_CONNECTED) setChanged(); // Enabling this line makes the opConnected signal occur whenever we get a handshake } if (gcsDisconnected && gcsStatusChanged) { @@ -405,4 +417,36 @@ public class TelemetryMonitor extends Observable { 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); + } + }; + }