UAVTalk session management

guilhermito edited this page Mar 18, 2014 · 3 revisions
Clone this wiki locally

UAVTalk session management

Objective:

Let the GCS know what UAVOs(initiated) the FC has, including instances for multiple instance UAVO, and as such provides:

  • Faster reconnects if the FC is not rebooted since the GCS only fetches the UAVOs it knows the FC has.
  • Synchronization of instances not relying on the receiving of data for an unknown instance.
  • Prevents (when using the UAVObjectWidgetUtils framework) failed savings from the GCS when trying to save an UAVO not present on the FC
  • When using widgets set through the UAVObjectWidgetUtils framework. the framework disables the widgets connected to nonexistent UAVOs thus preventing user input and signaling (shaded widget) that the UAVO it relates to is not present on the FC.
  • The UAVO browser signals non existent objects by coloring them with a user selectable color and it allows filtering those same objects making them invisible in the browser.
  • Since sessions sets are saved on the GCS one can connect several FCs and have the fast connect capability, provided that the hw was not rebooted or had the objects changed elsewhere.

Technical aspects:

Nomenclature:

sessionID:32 bit unsigned int unequivocally identifying the set of objects present on the hw.

failsafe :when the session fails it is flagged as unmanaged and the system resumes the same old method and tries to fetch all object it knows and all the session special features don't work. All UAVOs are flagged present on FC

Session initialization:

  • After the initial handshake the connectionStatus is set as CON_INITIALIZING and the GCS requests the SessionManaging UAVO.
  • If it receives a nack for that object it goes into failsafe.
  • If it takes more than 2 seconds (long time to account for hw link instability on connection) to receive that object it retries 2 more times, if it still doesn't get it it goes into failsafe.
  • Upon receiving the SessionManaging UAV it tries to match the transmitted sessionID (SessionManaging field) with the list of know sessions, if it finds a match it goes to Known session, if not it goes to Unknown session.

Unknown session:

  • All UAVOS are flagged as nonexistent on the FC.
  • connectionStatus is set to CON_SESSION_INITIALIZING.
  • SessionManaging sessionID is set by the GCS to "0" and the object is sent to the FC.
  • The FC pauses all periodic updates to save bandwidth (the FC timesout this pause after 5secs)
  • The FC answers by populating the numberOfObjects field with the number of oUAVOs it has,
  • The GCS populates the sessionID with an ID based on unix time and the objectOfInterest field with the value "0" and sends it to the FC.
  • The FC saves the sessionID and populates the objectID and instancesID with the value from the object with the index passed by objectOfInterest field and sends it back to the GCS.
  • The GCS flags the UAV with the received objectID as present on the FC and makes sure that the number of instances present on the GCS are the ones received on the instancesID, it then increments the objectOfInterest field index and the process continues until the objectOfInterest index is equals the value first returned by numberOfObjects.
  • If the wrong index is received 2 more tries to receive the correct index are made if they fail the system goes to failsafe.
  • If this all process takes more than 5secs the system goes into failsafe.
  • By this time all objects present on the Hw are flagged on the GCS as present and the object number of instances are in sync to the ones on the FC.
  • object retrievel is now initiated.

Known session:

  • The GCS flags as present only the objects from the session that was saved and also manipulates the object instances according to that information.
  • SessionManaging object is sent from the GCS with the ObjectOfInterestIndex value set to 0xFE to pause the FC from sending periodic object updates.
  • object retrievel is now initiated.

Object Retrieval:

  • connectionStatus set to CON_RETRIEVING_OBJECTS
  • The GCS queries all settings and metadata objects flagged as present on the FC.
  • If this takes more than 5 seconds the GCS stops object retrieval.
  • The connection is flagged as MANAGED only if all the known objects were retrieved.
  • The periodic updates from the FC are resumed by sending the SessionManaging with the ObjectOfInterestIndex value set to 0xFF.

During Connection:

  • If the hw creates a new object instance (never happens until today), the hw flags that by incrementing sessionID by 1, populating the ObjectID and instancesID fields with the values from the changed object.
  • The GCS makes the necessary changes and saves the new sessionID.
  • If the GCS receives a different sessionID or sessionID+1 it starts a new Unknown session process.

Code Modifications:

For this to work a few necessary functions were created on both the flight and the ground side, also some modifications were made on ground side functions to ease the integration.

Flight side:

uavobjectmanager.c file:

  • _uint32_t _UAVObjIDByIndex(uint8_t index) - Returns the UAVO ID by index, index relates to the order the UAVO was initialized.
  • _uint8_t UAVObjCount() - Returns the number of registered UAVOs.

Ground side:

uavdataobject.cpp file:

  • bool UAVDataObject::getIsPresentOnHardware() const - returns if the object is present on the FC. Always true on an unmanaged session
  • void UAVDataObject::setIsPresentOnHardware(bool value) - sets if the object is present on the FC
  • SIGNAL void presentOnHardwareChanged(UAVDataObject*) - signals the the object presence on the FC as changed.

uavobject.cpp file:

  • void UAVObject::requestUpdateAllInstances() - requests that the hw sends all instances of this object.
  • void UAVObject::emitTransactionCompleted(bool success, bool nacked) - emits a transactionCompleted signal which also passes if the transaction was nacked, old function (still present) only passed if it was successful.
  • void UAVObject::emitInstanceRemoved(UAVObject * obj) - emits an UAVO instance removed signal, can happen on the GCS or on the HW (not yet implemented).

uavobjectmanager.cpp file:

  • bool UAVObjectManager::unRegisterObject(UAVDataObject* obj) - unregisters from the manager all objects with instance IDs equal and bigger than the one passed as argument, emits instanceRemoved for every removed object. Warning-for code integrity reasons the instances are not deleted, gadgets using instances should monitor the instanceRemoved signal and take care of house cleaning.
  • QVector< QVector > UAVObjectManager::getObjectsVector() - kept for legacy reasons, used to be called getObjects()
  • QVector > UAVObjectManager::getMetaObjectsVector() - kept for legacy reasons, used to be called getMetaObjects()
  • QVector UAVObjectManager::getObjectInstancesVector(const QString& name) - kept for legacy reasons, used to be called getInstancesObjects()
  • QHash > UAVObjectManager::getObjects() - base for the several rewritten legacy functions which greatly simplifies the code throughout the GCS. Returns QHash so that you don't have to iterate trough a vector to find an UAVO or UAVO instance.