/** * Execute the requested transaction on an object. * \param[in] obj Object * \param[in] type Transaction type * TYPE_OBJ: send object, * TYPE_OBJ_REQ: request object update * TYPE_OBJ_ACK: send object with an ack * \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false) */ bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances) { // Send object depending on if a response is needed if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ) { if ( transmitObject(obj, type, allInstances) ) { respObj = obj; respAllInstances = allInstances; return true; } else { return false; } } else if (type == TYPE_OBJ) { return transmitObject(obj, TYPE_OBJ, allInstances); } else { return false; } }
/** * Execute the requested transaction on an object. * \param[in] obj Object * \param[in] type Transaction type * TYPE_OBJ: send object, * TYPE_OBJ_REQ: request object update * TYPE_OBJ_ACK: send object with an ack * \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false) */ bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances) { // Send object depending on if a response is needed if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ) { if ( transmitObject(obj, type, allInstances) ) { Transaction *trans = new Transaction(); trans->obj = obj; trans->allInstances = allInstances; transMap.insert(obj->getObjID(), trans); return true; } else { return false; } } else if (type == TYPE_OBJ) { return transmitObject(obj, TYPE_OBJ, allInstances); } else { return false; } }
/** * Execute the requested transaction on an object. * \param[in] obj Object * \param[in] type Transaction type * TYPE_OBJ: send object with no ack, * TYPE_OBJ_REQ: request object update * TYPE_OBJ_ACK: send object with an ack * \param[in] allInstances If set true then all instances will be updated * \return Success (true), Failure (false) */ bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances) { if (type == TYPE_OBJ_ACK || type == TYPE_OBJ_REQ || type == TYPE_OBJ) { return transmitObject(obj, type, allInstances); } else { return false; } }
/** * Receive an object. This function process objects received through the telemetry stream. * \param[in] type Type of received message (TYPE_OBJ, TYPE_OBJ_REQ, TYPE_OBJ_ACK, TYPE_ACK, TYPE_NACK) * \param[in] obj Handle of the received object * \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances. * \param[in] data Data buffer * \param[in] length Buffer length * \return Success (true), Failure (false) */ bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length) { Q_UNUSED(length); UAVObject* obj = NULL; bool error = false; bool allInstances = (instId == ALL_INSTANCES); // Process message type switch (type) { case TYPE_OBJ: // All instances, not allowed for OBJ messages if (!allInstances) { // Get object and update its data obj = updateObject(objId, instId, data); // Check if an ack is pending if ( obj != NULL ) { updateAck(obj); } else { error = true; } } else { error = true; } break; case TYPE_OBJ_ACK: // All instances, not allowed for OBJ_ACK messages if (!allInstances) { // Get object and update its data obj = updateObject(objId, instId, data); // Transmit ACK if ( obj != NULL ) { transmitObject(obj, TYPE_ACK, false); } else { error = true; } } else { error = true; } break; case TYPE_OBJ_REQ: // Get object, if all instances are requested get instance 0 of the object if (allInstances) { obj = objMngr->getObject(objId); } else { obj = objMngr->getObject(objId, instId); } // If object was found transmit it if (obj != NULL) { transmitObject(obj, TYPE_OBJ, allInstances); } else { // Object was not found, transmit a NACK with the // objId which was not found. transmitNack(objId); error = true; } break; case TYPE_NACK: // All instances, not allowed for NACK messages if (!allInstances) { // Get object obj = objMngr->getObject(objId, instId); // Check if object exists: if (obj != NULL) { updateNack(obj); } else { error = true; } } break; case TYPE_ACK: // All instances, not allowed for ACK messages if (!allInstances) { // Get object obj = objMngr->getObject(objId, instId); // Check if an ack is pending if (obj != NULL) { updateAck(obj); } else { error = true; } } break; default: error = true; } // Done return !error; }
/** * Receive an object. This function process objects received through the telemetry stream. * \param[in] type Type of received message (TYPE_OBJ, TYPE_OBJ_REQ, TYPE_OBJ_ACK, TYPE_ACK, TYPE_NACK) * \param[in] obj Handle of the received object * \param[in] instId The instance ID of UAVOBJ_ALL_INSTANCES for all instances. * \param[in] data Data buffer * \param[in] length Buffer length * \return Success (true), Failure (false) */ bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8* data, qint32 length) { Q_UNUSED(length); UAVObject* obj = NULL; bool error = false; bool allInstances = (instId == ALL_INSTANCES); // Process message type switch (type) { case TYPE_OBJ: // We have received an object. // All instances, not allowed for OBJ messages if (!allInstances) { // Get object and update its data obj = updateObject(objId, instId, data); if (obj == NULL) error = true; } else { error = true; } break; case TYPE_OBJ_ACK: // We have received an object and are asked for an ACK // All instances, not allowed for OBJ_ACK messages if (!allInstances) { // Get object and update its data obj = updateObject(objId, instId, data); // Transmit ACK if ( obj != NULL ) { transmitObject(obj, TYPE_ACK, false); } else { error = true; } } else { error = true; } break; case TYPE_OBJ_REQ: // We are being asked for an object // Get object, if all instances are requested get instance 0 of the object if (allInstances) { obj = objMngr->getObject(objId); } else { obj = objMngr->getObject(objId, instId); } // If object was found transmit it if (obj != NULL) { transmitObject(obj, TYPE_OBJ, allInstances); } else { // Object was not found, transmit a NACK with the // objId which was not found. transmitNack(objId); error = true; } break; case TYPE_NACK: // We have received a NACK for an object that does not exist on the far end. // (but should exist on our end) // All instances, not allowed for NACK messages if (!allInstances) { // Get object obj = objMngr->getObject(objId, instId); // Check if object exists: if (obj != NULL) { emit nackReceived(obj); } else { error = true; } } break; case TYPE_ACK: // We have received a ACK, supposedly after sending an object with OBJ_ACK // All instances, not allowed for ACK messages if (!allInstances) { qDebug() << "Got ack for instance: " << instId; // Get object obj = objMngr->getObject(objId, instId); // Check if we actually know this object (tiny chance the ObjID // could be unknown and got through CRC check...) if (obj != NULL) { emit ackReceived(obj); } else { error = true; } } break; default: error = true; } // Done (exit value is "success", hence the "!" below) return !error; }