dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobject.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 UAVOBJECT_H
37 #define UAVOBJECT_H
38 
40 #include <QtGlobal>
41 #include <QJsonObject>
42 #include <QObject>
43 #include <QString>
44 #include <QList>
45 #include <QFile>
46 #include <qglobal.h>
48 
49 #ifdef _MSC_VER
50 #define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
51 #else
52 #define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
53 #endif
54 
55 #define UAVOBJ_ACCESS_SHIFT 0
56 #define UAVOBJ_GCS_ACCESS_SHIFT 1
57 #define UAVOBJ_TELEMETRY_ACKED_SHIFT 2
58 #define UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT 3
59 #define UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT 4
60 #define UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT 6
61 #define UAVOBJ_UPDATE_MODE_MASK 0x3
62 
63 class UAVObjectField;
64 
65 class UAVOBJECTS_EXPORT UAVObject : public QObject
66 {
67  Q_OBJECT
68 
69 public:
73  typedef enum {
74  UPDATEMODE_MANUAL = 0,
75  UPDATEMODE_PERIODIC = 1,
76  UPDATEMODE_ONCHANGE = 2,
77  UPDATEMODE_THROTTLED =
78  3
79  } UpdateMode;
80 
84  typedef enum { ACCESS_READWRITE = 0, ACCESS_READONLY = 1 } AccessMode;
85 
107  PACK(
108  typedef struct {
109  quint8 flags;
111  quint16 flightTelemetryUpdatePeriod;
113  quint16 gcsTelemetryUpdatePeriod;
115  quint16 loggingUpdatePeriod;
117  })
118  Metadata;
119 
120  UAVObject(quint32 objID, bool isSingleInst, const QString &name);
121  void initialize(quint32 instID);
122  quint32 getObjID();
123  quint32 getInstID();
124  bool isSingleInstance();
125  QString getName();
126  QString getDescription();
127  quint32 getNumBytes();
128  qint32 pack(quint8 *dataOut);
129  qint32 unpack(const quint8 *dataIn);
130  virtual void setMetadata(const Metadata &mdata) = 0;
131  virtual Metadata getMetadata() = 0;
132  virtual Metadata getDefaultMetadata() = 0;
133  qint32 getNumFields();
134  QList<UAVObjectField *> getFields();
135  UAVObjectField *getField(const QString &name);
136  QString toString();
137  QString toStringBrief();
138  QString toStringData();
139  QJsonObject getJsonRepresentation();
140  void emitTransactionCompleted(bool success);
141  void emitTransactionCompleted(bool success, bool nacked);
142  void emitNewInstance(UAVObject *);
143  void emitInstanceRemoved(UAVObject *);
144 
145  // Metadata accessors
146  static void MetadataInitialize(Metadata &meta);
147  static AccessMode GetFlightAccess(const Metadata &meta);
148  static void SetFlightAccess(Metadata &meta, AccessMode mode);
149  static AccessMode GetGcsAccess(const Metadata &meta);
150  static void SetGcsAccess(Metadata &meta, AccessMode mode);
151  static quint8 GetFlightTelemetryAcked(const Metadata &meta);
152  static void SetFlightTelemetryAcked(Metadata &meta, quint8 val);
153  static quint8 GetGcsTelemetryAcked(const Metadata &meta);
154  static void SetGcsTelemetryAcked(Metadata &meta, quint8 val);
155  static UpdateMode GetFlightTelemetryUpdateMode(const Metadata &meta);
156  static void SetFlightTelemetryUpdateMode(Metadata &meta, UpdateMode val);
157  static UpdateMode GetGcsTelemetryUpdateMode(const Metadata &meta);
158  static void SetGcsTelemetryUpdateMode(Metadata &meta, UpdateMode val);
159 
160 public slots:
161  void requestUpdate();
162  void requestUpdateAllInstances();
163  void updated();
164 
165 signals:
176  void objectUpdated(UAVObject *obj);
177 
186  void objectUpdatedAuto(UAVObject *obj);
187 
194  void objectUpdatedManual(UAVObject *obj);
195 
200  void objectUpdatedPeriodic(UAVObject *obj);
201 
207  void objectUnpacked(UAVObject *obj);
208 
213  void updateRequested(UAVObject *obj);
214 
219  void updateAllInstancesRequested(UAVObject *obj);
227  void transactionCompleted(UAVObject *obj, bool success);
228  void transactionCompleted(UAVObject *obj, bool success, bool nack);
233  void newInstance(UAVObject *obj);
234 
239  void instanceRemoved(UAVObject *obj);
240 
241 private slots:
242  void fieldUpdated(UAVObjectField *field);
243 
244 protected:
245  quint32 objID;
246  quint32 instID;
248  QString name;
249  QString description;
250  QString category;
251  quint32 numBytes;
252  quint8 *data;
254  void initializeFields(QList<UAVObjectField *> &fields, quint8 *data, quint32 numBytes);
255  void setDescription(const QString &description);
256 };
257 
258 #endif // UAVOBJECT_H
quint8 * data
Definition: uavobject.h:252
Metadata getDefaultMetadata()
QString description
Definition: uavobject.h:249
QList< UAVObjectField * > fields
Definition: uavobject.h:253
bool isSingleInst
Definition: uavobject.h:247
PACK(typedef struct{uint VTOLMotorN:4;uint VTOLMotorS:4;uint VTOLMotorE:4;uint VTOLMotorW:4;uint VTOLMotorNW:4;uint VTOLMotorNE:4;uint VTOLMotorSW:4;uint VTOLMotorSE:4;uint TRIYaw:4;quint32 padding:28;quint32 padding1;quint32 padding2;}) multiGUISettingsStruct
QString name
Definition: uavobject.h:248
DataFields data
QString category
Definition: uavobject.h:250
quint32 instID
Definition: uavobject.h:246
quint32 objID
Definition: uavobject.h:245
quint32 numBytes
Definition: uavobject.h:251