dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
telemetry.h
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  *
31  * Additional note on redistribution: The copyright and license notices above
32  * must be maintained in each individual source file that is a derivative work
33  * of this source file; otherwise redistribution is prohibited.
34  */
35 
36 #ifndef TELEMETRY_H
37 #define TELEMETRY_H
38 
39 #include "uavtalk.h"
41 #include "gcstelemetrystats.h"
42 #include <QTimer>
43 #include <QQueue>
44 #include <QMap>
45 
46 class TransactionKey;
47 
48 class ObjectTransactionInfo : public QObject
49 {
50  Q_OBJECT
51 
52 public:
53  ObjectTransactionInfo(QObject *parent);
57  bool objRequest;
59  bool acked;
60  QPointer<class Telemetry> telem;
61  QTimer *timer;
62 private slots:
63  void timeout();
64 };
65 
66 class Telemetry : public QObject
67 {
68  Q_OBJECT
69 
70 public:
71  typedef struct
72  {
73  quint32 txBytes;
74  quint32 rxBytes;
75  quint32 txObjectBytes;
76  quint32 rxObjectBytes;
77  quint32 rxObjects;
78  quint32 txObjects;
79  quint32 txErrors;
80  quint32 rxErrors;
81  quint32 txRetries;
83 
84  Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr);
85  ~Telemetry();
87  QByteArray *downloadFile(quint32 fileId, quint32 maxSize,
88  std::function<void(quint32)>progressCb = nullptr);
89 
91 
92 signals:
93 
94 private:
95  // Constants
96 
97  // TODO: Would be nice to dynamically scale the request timeout...
98  // This 1500 value is about what's necessary for 9600bps uavtalk links.
99  static const int REQ_TIMEOUT_MS = 2000;
100  static const int MAX_RETRIES = 5;
101  static const int MAX_UPDATE_PERIOD_MS = 1000;
102  static const int MIN_UPDATE_PERIOD_MS = 1;
103  static const int MAX_QUEUE_SIZE = 20;
104 
105  // Types
109  typedef enum {
110  EV_NONE = 0x00,
111  EV_UNPACKED = 0x01,
112  EV_UPDATED = 0x02,
113  EV_UPDATED_MANUAL = 0x04,
114  EV_UPDATED_PERIODIC = 0x8,
115  EV_UPDATE_REQ = 0x010
116  } EventMask;
117 
118  typedef struct
119  {
121  qint32 updatePeriodMs;
123  } ObjectTimeInfo;
124 
125  typedef struct
126  {
128  EventMask event;
130  } ObjectQueueInfo;
131 
132  // Variables
133  UAVObjectManager *objMngr;
134  UAVTalk *utalk;
135  GCSTelemetryStats *gcsStatsObj;
136  QVector<ObjectTimeInfo> objList;
137  QQueue<ObjectQueueInfo> objQueue;
138  QQueue<ObjectQueueInfo> objPriorityQueue;
139  QMap<TransactionKey, ObjectTransactionInfo *> transMap;
140  QTimer *updateTimer;
141  QTimer *statsTimer;
142  qint32 timeToNextUpdateMs;
143  quint32 txErrors;
144  quint32 txRetries;
145 
146  // Methods
147  void registerObject(UAVObject *obj);
148  void addObject(UAVObject *obj);
149  void setUpdatePeriod(UAVObject *obj, qint32 periodMs);
150  void connectToObjectInstances(UAVObject *obj, quint32 eventMask);
151  void updateObject(UAVObject *obj, quint32 eventMask);
152  void processObjectUpdates(UAVObject *obj, EventMask event, bool allInstances, bool priority);
153  void processObjectTransaction(ObjectTransactionInfo *transInfo);
154  void processObjectQueue();
155  bool updateTransactionMap(UAVObject *obj, bool request);
156 
157 private slots:
158  void objectUpdatedAuto(UAVObject *obj);
159  void objectUpdatedManual(UAVObject *obj);
160  void objectUpdatedPeriodic(UAVObject *obj);
161  void objectUnpacked(UAVObject *obj);
162  void updateRequested(UAVObject *obj);
163  void updateAllInstancesRequested(UAVObject *obj);
164  void newObject(UAVObject *obj);
165  void newInstance(UAVObject *obj);
166  void processPeriodicUpdates();
167  void transactionSuccess(UAVObject *obj);
168  void transactionFailure(UAVObject *obj);
169  void transactionRequestCompleted(UAVObject *obj);
170 };
171 
172 #endif // TELEMETRY_H
QPointer< class Telemetry > telem
Definition: telemetry.h:60
function[]
QByteArray * downloadFile(quint32 fileId, quint32 maxSize, std::function< void(quint32)>progressCb=nullptr)
Definition: telemetry.cpp:406
ObjectTransactionInfo(QObject *parent)
Definition: telemetry.cpp:766
UAVObject * obj
Definition: telemetry.h:55
void transactionTimeout(ObjectTransactionInfo *info)
Definition: telemetry.cpp:375
TelemetryStats getStats()
Definition: telemetry.cpp:702
The TransactionKey class A key for the QMap to track transactions.
Definition: telemetry.cpp:53
Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr)
Definition: telemetry.cpp:90