2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @see The GNU Public License (GPL) Version 3
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup UAVObjectsPlugin UAVObjects Plugin
11 * @brief The UAVUObjects GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "uavobjects_global.h"
35 #include <QMutexLocker>
41 #include "uavobjectfield.h"
43 #define UAVOBJ_ACCESS_SHIFT 0
44 #define UAVOBJ_GCS_ACCESS_SHIFT 1
45 #define UAVOBJ_TELEMETRY_ACKED_SHIFT 2
46 #define UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT 3
47 #define UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT 4
48 #define UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT 6
49 #define UAVOBJ_LOGGING_UPDATE_MODE_SHIFT 8
50 #define UAVOBJ_UPDATE_MODE_MASK 0x3
53 class QXmlStreamWriter
;
54 class QXmlStreamReader
;
57 class UAVOBJECTS_EXPORT UAVObject
: public QObject
{
61 Q_PROPERTY(QString Name READ getName
)
67 UPDATEMODE_MANUAL
= 0, /** Manually update object, by calling the updated() function */
68 UPDATEMODE_PERIODIC
= 1, /** Automatically update object at periodic intervals */
69 UPDATEMODE_ONCHANGE
= 2, /** Only update object when its data changes */
70 UPDATEMODE_THROTTLED
= 3 /** Object is updated on change, but not more often than the interval time */
82 * Object metadata, each object has a meta object that holds its metadata. The metadata define
83 * properties for each object and can be used by multiple modules (e.g. telemetry and logger)
85 * The object metadata flags are packed into a single 16 bit integer.
86 * The bits in the flag field are defined as:
90 * 0 access Defines the access level for the local transactions (readonly=0 and readwrite=1)
91 * 1 gcsAccess Defines the access level for the local GCS transactions (readonly=0 and readwrite=1), not used in the flight s/w
92 * 2 telemetryAcked Defines if an ack is required for the transactions of this object (1:acked, 0:not acked)
93 * 3 gcsTelemetryAcked Defines if an ack is required for the transactions of this object (1:acked, 0:not acked)
94 * 4-5 telemetryUpdateMode Update mode used by the telemetry module (UAVObjUpdateMode)
95 * 6-7 gcsTelemetryUpdateMode Update mode used by the GCS (UAVObjUpdateMode)
96 * 8-9 loggingUpdateMode Update mode used by the logging module (UAVObjUpdateMode)
99 quint16 flags
; /** Defines flags for update and logging modes and whether an update should be ACK'd (bits defined above) */
100 quint16 flightTelemetryUpdatePeriod
; /** Update period used by the telemetry module (only if telemetry mode is PERIODIC) */
101 quint16 gcsTelemetryUpdatePeriod
; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
102 quint16 loggingUpdatePeriod
; /** Update period used by the logging module (only if logging mode is PERIODIC) */
103 } __attribute__((packed
)) Metadata
;
106 UAVObject(quint32 objID
, bool isSingleInst
, const QString
& name
);
107 void initialize(quint32 instID
);
110 bool isSingleInstance();
112 QString
getCategory();
113 QString
getDescription();
114 quint32
getNumBytes();
115 qint32
pack(quint8
*dataOut
);
116 qint32
unpack(const quint8
*dataIn
);
117 quint8
updateCRC(quint8 crc
= 0);
119 bool save(QFile
& file
);
121 bool load(QFile
& file
);
122 virtual void setMetadata(const Metadata
& mdata
) = 0;
123 virtual Metadata
getMetadata() = 0;
124 virtual Metadata
getDefaultMetadata() = 0;
126 void lock(int timeoutMs
);
129 qint32
getNumFields();
130 QList
<UAVObjectField
*> getFields();
131 UAVObjectField
*getField(const QString
& name
);
133 QString
toStringBrief();
134 QString
toStringData();
136 void toXML(QXmlStreamWriter
*xmlWriter
);
137 void fromXML(QXmlStreamReader
*xmlReader
);
139 void toJson(QJsonObject
&jsonObject
);
140 void fromJson(const QJsonObject
&jsonObject
);
142 void emitTransactionCompleted(bool success
);
143 void emitNewInstance(UAVObject
*);
145 bool isKnown() const;
146 void setIsKnown(bool isKnown
);
148 virtual bool isSettingsObject();
149 virtual bool isDataObject();
150 virtual bool isMetaDataObject();
152 // Metadata accessors
153 static void MetadataInitialize(Metadata
& meta
);
154 static AccessMode
GetFlightAccess(const Metadata
& meta
);
155 static void SetFlightAccess(Metadata
& meta
, AccessMode mode
);
156 static AccessMode
GetGcsAccess(const Metadata
& meta
);
157 static void SetGcsAccess(Metadata
& meta
, AccessMode mode
);
158 static quint8
GetFlightTelemetryAcked(const Metadata
& meta
);
159 static void SetFlightTelemetryAcked(Metadata
& meta
, quint8 val
);
160 static quint8
GetGcsTelemetryAcked(const Metadata
& meta
);
161 static void SetGcsTelemetryAcked(Metadata
& meta
, quint8 val
);
162 static UpdateMode
GetFlightTelemetryUpdateMode(const Metadata
& meta
);
163 static void SetFlightTelemetryUpdateMode(Metadata
& meta
, UpdateMode val
);
164 static UpdateMode
GetGcsTelemetryUpdateMode(const Metadata
& meta
);
165 static void SetGcsTelemetryUpdateMode(Metadata
& meta
, UpdateMode val
);
166 static UpdateMode
GetLoggingUpdateMode(const Metadata
& meta
);
167 static void SetLoggingUpdateMode(Metadata
& meta
, UpdateMode val
);
170 void requestUpdate();
171 void requestUpdateAll();
176 void objectUpdated(UAVObject
*obj
);
177 void objectUpdatedAuto(UAVObject
*obj
);
178 void objectUpdatedManual(UAVObject
*obj
, bool all
= false);
179 void objectUpdatedPeriodic(UAVObject
*obj
);
180 void objectUnpacked(UAVObject
*obj
);
181 void updateRequested(UAVObject
*obj
, bool all
= false);
182 void transactionCompleted(UAVObject
*obj
, bool success
);
183 void newInstance(UAVObject
*obj
);
184 void isKnownChanged(UAVObject
*obj
);
196 QList
<UAVObjectField
*> fields
;
198 void initializeFields(QList
<UAVObjectField
*> & fields
, quint8
*data
, quint32 numBytes
);
199 void setDescription(const QString
& description
);
200 void setCategory(const QString
& category
);
206 void fieldUpdated(UAVObjectField
*field
);
209 #endif // UAVOBJECT_H