2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup UAVTalkPlugin UAVTalk Plugin
10 * @brief The UAVTalk protocol plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "uavobjectmanager.h"
33 #include "gcstelemetrystats.h"
35 #include <QMutexLocker>
40 class ObjectTransactionInfo
: public QObject
{
44 ObjectTransactionInfo(QObject
*parent
);
45 ~ObjectTransactionInfo();
49 qint32 retriesRemaining
;
51 QPointer
<class Telemetry
>telem
;
57 class Telemetry
: public QObject
{
63 quint32 txObjectBytes
;
69 quint32 rxObjectBytes
;
76 Telemetry(UAVTalk
*utalk
, UAVObjectManager
*objMngr
);
78 TelemetryStats
getStats();
80 void transactionTimeout(ObjectTransactionInfo
*info
);
84 static const int REQ_TIMEOUT_MS
= 250;
85 static const int MAX_RETRIES
= 2;
86 static const int MAX_UPDATE_PERIOD_MS
= 1000;
87 static const int MIN_UPDATE_PERIOD_MS
= 1;
88 static const int MAX_QUEUE_SIZE
= 20;
92 * Events generated by objects
95 EV_NONE
= 0x00, /** No event */
96 EV_UNPACKED
= 0x01, /** Object data updated by unpacking */
97 EV_UPDATED
= 0x02, /** Object data updated by changing the data structure */
98 EV_UPDATED_MANUAL
= 0x04, /** Object update event manually generated */
99 EV_UPDATED_PERIODIC
= 0x08, /** Object update event generated by timer */
100 EV_UPDATE_REQ
= 0x10 /** Request to update object data */
105 qint32 updatePeriodMs
; /** Update period in ms or 0 if no periodic updates are needed */
106 qint32 timeToNextUpdateMs
; /** Time delay to the next update */
116 UAVObjectManager
*objMngr
;
118 GCSTelemetryStats
*gcsStatsObj
;
119 QList
<ObjectTimeInfo
> objList
;
120 QQueue
<ObjectQueueInfo
> objQueue
;
121 QQueue
<ObjectQueueInfo
> objPriorityQueue
;
122 QMap
<quint32
, QMap
<quint32
, ObjectTransactionInfo
*> *> transMap
;
126 qint32 timeToNextUpdateMs
;
131 void registerObject(UAVObject
*obj
);
132 void addObject(UAVObject
*obj
);
133 void setUpdatePeriod(UAVObject
*obj
, qint32 periodMs
);
134 void connectToObjectInstances(UAVObject
*obj
, quint32 eventMask
);
135 void connectToObject(UAVObject
*obj
, quint32 eventMask
);
136 void updateObject(UAVObject
*obj
, quint32 eventMask
);
137 void processObjectUpdates(UAVObject
*obj
, EventMask event
, bool allInstances
, bool priority
);
138 void processObjectTransaction(ObjectTransactionInfo
*transInfo
);
139 void processObjectQueue();
141 ObjectTransactionInfo
*findTransaction(UAVObject
*obj
);
142 void openTransaction(ObjectTransactionInfo
*trans
);
143 void closeTransaction(ObjectTransactionInfo
*trans
);
144 void closeAllTransactions();
147 void objectUpdatedAuto(UAVObject
*obj
);
148 void objectUpdatedManual(UAVObject
*obj
, bool all
= false);
149 void objectUpdatedPeriodic(UAVObject
*obj
);
150 void objectUnpacked(UAVObject
*obj
);
151 void updateRequested(UAVObject
*obj
, bool all
= false);
152 void newObject(UAVObject
*obj
);
153 void newInstance(UAVObject
*obj
);
154 void processPeriodicUpdates();
155 void transactionCompleted(UAVObject
*obj
, bool success
);
158 #endif // TELEMETRY_H