mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-349 CC-32: Improved the object save confirmation logic. It's got a lot of
checks in there so pleaes let me know if people get any segfaults. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3099 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
4326a323e4
commit
cebca6f67e
@ -25,18 +25,18 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include "configtaskwidget.h"
|
#include "configtaskwidget.h"
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
|
|
||||||
|
|
||||||
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent)
|
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
saveState = IDLE;
|
||||||
|
queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigTaskWidget::~ConfigTaskWidget()
|
ConfigTaskWidget::~ConfigTaskWidget()
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
|
void ConfigTaskWidget::saveObjectToSD(UAVObject *obj)
|
||||||
@ -56,10 +56,15 @@ void ConfigTaskWidget::saveNextObject()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(saveState == IDLE);
|
||||||
|
|
||||||
// Get next object from the queue
|
// Get next object from the queue
|
||||||
UAVObject* obj = queue.head();
|
UAVObject* obj = queue.head();
|
||||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
|
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( getObjectManager()->getObject(ObjectPersistence::NAME) );
|
||||||
connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(transactionCompleted(UAVObject*,bool)));
|
connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
|
||||||
|
connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *)));
|
||||||
|
saveState = AWAITING_ACK;
|
||||||
if (obj != NULL)
|
if (obj != NULL)
|
||||||
{
|
{
|
||||||
ObjectPersistence::DataFields data;
|
ObjectPersistence::DataFields data;
|
||||||
@ -72,13 +77,46 @@ void ConfigTaskWidget::saveNextObject()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTaskWidget::transactionCompleted(UAVObject* obj, bool success)
|
/**
|
||||||
|
* @brief Process the transactionCompleted message from Telemetry indicating request sent successfully
|
||||||
|
* @param[in] The object just transsacted. Must be ObjectPersistance
|
||||||
|
* @param[in] success Indicates that the transaction did not time out
|
||||||
|
*
|
||||||
|
* After a failed transaction (usually timeout) resends the save request. After a succesful
|
||||||
|
* transaction will then wait for a save completed update from the autopilot.
|
||||||
|
*/
|
||||||
|
void ConfigTaskWidget::objectPersistenceTransactionCompleted(UAVObject* obj, bool success)
|
||||||
{
|
{
|
||||||
if(success &&
|
if(success) {
|
||||||
obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 ) {
|
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
|
||||||
// Disconnect from sending object
|
Q_ASSERT(saveState == AWAITING_ACK);
|
||||||
|
saveState = AWAITING_COMPLETED;
|
||||||
|
disconnect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool)));
|
||||||
|
} else if (!success) {
|
||||||
|
// Can be caused by timeout errors on sending. Send again.
|
||||||
|
saveNextObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Process the ObjectPersistence updated message to confirm the right object saved
|
||||||
|
* then requests next object be saved.
|
||||||
|
* @param[in] The object just received. Must be ObjectPersistance
|
||||||
|
*/
|
||||||
|
void ConfigTaskWidget::objectPersistenceUpdated(UAVObject * obj)
|
||||||
|
{
|
||||||
|
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
|
||||||
|
if(saveState == AWAITING_COMPLETED) {
|
||||||
|
// Check flight is saying it completed. This is the only thing flight should do to trigger an update.
|
||||||
|
Q_ASSERT( obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 );
|
||||||
|
|
||||||
|
// Check right object saved
|
||||||
|
UAVObject* savingObj = queue.head();
|
||||||
|
Q_ASSERT( obj->getField("ObjectID")->getValue() == savingObj->getObjID() );
|
||||||
|
|
||||||
obj->disconnect(this);
|
obj->disconnect(this);
|
||||||
queue.dequeue(); // We can now remove the object, it's done.
|
queue.dequeue(); // We can now remove the object, it's done.
|
||||||
|
saveState = IDLE;
|
||||||
saveNextObject();
|
saveNextObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,14 @@ public:
|
|||||||
|
|
||||||
static double listMean(QList<double> list);
|
static double listMean(QList<double> list);
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void transactionCompleted(UAVObject* obj, bool success);
|
void objectPersistenceTransactionCompleted(UAVObject* obj, bool success);
|
||||||
|
void objectPersistenceUpdated(UAVObject * obj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQueue<UAVObject*> queue;
|
QQueue<UAVObject*> queue;
|
||||||
void saveNextObject();
|
void saveNextObject();
|
||||||
|
enum {IDLE, AWAITING_ACK, AWAITING_COMPLETED} saveState;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user