2 ******************************************************************************
4 * @file uavobjectfield.h
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
28 #ifndef UAVOBJECTFIELD_H
29 #define UAVOBJECTFIELD_H
31 #include "uavobjects_global.h"
32 #include "uavobject.h"
34 #include <QStringList>
41 class QXmlStreamWriter
;
42 class QXmlStreamReader
;
45 class UAVOBJECTS_EXPORT UAVObjectField
: public QObject
{
49 typedef enum { INT8
= 0, INT16
, INT32
, UINT8
, UINT16
, UINT32
, FLOAT32
, ENUM
, BITFIELD
, STRING
} FieldType
;
50 typedef enum { EQUAL
, NOT_EQUAL
, BETWEEN
, BIGGER
, SMALLER
, UNDEFINED
} LimitType
;
53 QList
<QVariant
> values
;
57 UAVObjectField(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, quint32 numElements
, const QStringList
& options
, const QString
& limits
= QString());
58 UAVObjectField(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, const QStringList
& elementNames
, const QStringList
& options
, const QString
& limits
= QString());
59 void initialize(quint8
*data
, quint32 dataOffset
, UAVObject
*obj
);
60 UAVObject
*getObject();
62 QString
getTypeAsString();
64 QString
getDescription();
66 quint32
getNumElements();
67 QStringList
getElementNames();
68 QStringList
getOptions();
69 qint32
pack(quint8
*dataOut
);
70 qint32
unpack(const quint8
*dataIn
);
71 QVariant
getValue(quint32 index
= 0);
72 bool checkValue(const QVariant
& data
, quint32 index
= 0);
73 void setValue(const QVariant
& data
, quint32 index
= 0);
74 double getDouble(quint32 index
= 0);
75 void setDouble(double value
, quint32 index
= 0);
76 quint32
getDataOffset();
77 quint32
getNumBytes();
85 void toXML(QXmlStreamWriter
*xmlWriter
);
86 void fromXML(QXmlStreamReader
*xmlReader
);
88 void toJson(QJsonObject
&jsonObject
);
89 void fromJson(const QJsonObject
&jsonObject
);
91 bool isWithinLimits(QVariant var
, quint32 index
, int board
= 0);
92 QString
getLimitsAsString(quint32 index
, int board
= 0);
93 QVariant
getMaxLimit(quint32 index
, int board
= 0);
94 QVariant
getMinLimit(quint32 index
, int board
= 0);
96 void fieldUpdated(UAVObjectField
*field
);
103 QStringList elementNames
;
106 quint32 numBytesPerElement
;
110 QMap
<quint32
, QList
<LimitStruct
> > elementLimits
;
111 void constructorInitialize(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, const QStringList
& elementNames
, const QStringList
& options
, const QString
&limits
);
112 void limitsInitialize(const QString
&limits
);
115 #endif // UAVOBJECTFIELD_H