Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / uavobjects / uavobjectfield.h
blob2c82cce950ed9e82411f60465469f5bbf86e8037
1 /**
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
8 * @{
9 * @addtogroup UAVObjectsPlugin UAVObjects Plugin
10 * @{
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
22 * for more details.
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>
35 #include <QVariant>
36 #include <QList>
37 #include <QMap>
39 class UAVObject;
41 class QXmlStreamWriter;
42 class QXmlStreamReader;
43 class QJsonObject;
45 class UAVOBJECTS_EXPORT UAVObjectField : public QObject {
46 Q_OBJECT
48 public:
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;
51 typedef struct {
52 LimitType type;
53 QList<QVariant> values;
54 int board;
55 } LimitStruct;
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();
61 FieldType getType();
62 QString getTypeAsString();
63 QString getName();
64 QString getDescription();
65 QString getUnits();
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();
78 bool isNumeric();
79 bool isInteger();
80 bool isText();
81 QString toString();
83 void clear();
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);
95 signals:
96 void fieldUpdated(UAVObjectField *field);
98 protected:
99 QString name;
100 QString description;
101 QString units;
102 FieldType type;
103 QStringList elementNames;
104 QStringList options;
105 quint32 numElements;
106 quint32 numBytesPerElement;
107 quint32 offset;
108 quint8 *data;
109 UAVObject *obj;
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