update credits
[librepilot.git] / ground / uavobjgenerator / uavobjectparser.h
blobd8c140454305568a6af46d6cbffabba3640cfeda
1 /**
2 ******************************************************************************
4 * @file uavobjectparser.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @brief Parses XML files and extracts object information.
9 * @see The GNU Public License (GPL) Version 3
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef UAVOBJECTPARSER_H
29 #define UAVOBJECTPARSER_H
31 #include <QString>
32 #include <QStringList>
33 #include <QList>
34 #include <QDomNode>
35 #include <QByteArray>
37 // Types
38 typedef enum {
39 FIELDTYPE_INT8 = 0,
40 FIELDTYPE_INT16,
41 FIELDTYPE_INT32,
42 FIELDTYPE_UINT8,
43 FIELDTYPE_UINT16,
44 FIELDTYPE_UINT32,
45 FIELDTYPE_FLOAT32,
46 FIELDTYPE_ENUM
47 } FieldType;
49 typedef struct {
50 QString name;
51 QString description;
52 QString units;
53 FieldType type;
54 int numElements;
55 int numOptions;
56 int numBytes;
57 QStringList elementNames;
58 QStringList options; // for enums only
59 bool defaultElementNames;
60 QStringList defaultValues;
61 QString limitValues;
62 QString parentObjectName;
63 QString parentFieldName;
64 } FieldInfo;
66 /**
67 * Object update mode
69 typedef enum {
70 UPDATEMODE_MANUAL = 0, /** Manually update object, by calling the updated() function */
71 UPDATEMODE_PERIODIC = 1, /** Automatically update object at periodic intervals */
72 UPDATEMODE_ONCHANGE = 2, /** Only update object when its data changes */
73 UPDATEMODE_THROTTLED = 3 /** Object is updated on change, but not more often than the interval time */
74 } UpdateMode;
77 typedef enum {
78 ACCESS_READWRITE = 0,
79 ACCESS_READONLY = 1
80 } AccessMode;
83 typedef struct {
84 QString name;
85 QString namelc; /** name in lowercase */
86 QString filename;
87 quint32 id;
88 bool isSingleInst;
89 bool isSettings;
90 bool isPriority;
91 AccessMode gcsAccess;
92 AccessMode flightAccess;
93 bool flightTelemetryAcked;
94 UpdateMode flightTelemetryUpdateMode; /** Update mode used by the autopilot (UpdateMode) */
95 int flightTelemetryUpdatePeriod; /** Update period used by the autopilot (only if telemetry mode is PERIODIC) */
96 bool gcsTelemetryAcked;
97 UpdateMode gcsTelemetryUpdateMode; /** Update mode used by the GCS (UpdateMode) */
98 int gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
99 UpdateMode loggingUpdateMode; /** Update mode used by the logging module (UpdateMode) */
100 int loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */
101 QList<FieldInfo *> fields; /** The data fields for the object **/
102 QString description; /** Description used for Doxygen **/
103 QString category; /** Description used for Doxygen **/
104 } ObjectInfo;
106 class UAVObjectParser {
107 public:
109 // Functions
110 UAVObjectParser();
111 QString parseXML(QString & xml, QString & filename);
112 int getNumObjects();
113 QList<ObjectInfo *> getObjectInfo();
114 QString getObjectName(int objIndex);
115 quint32 getObjectID(int objIndex);
117 ObjectInfo *getObjectByIndex(int objIndex);
118 ObjectInfo *getObjectByName(const QString & objName);
119 int getNumBytes(int objIndex);
120 QStringList all_units;
122 private:
123 QList<ObjectInfo *> objInfo;
124 QStringList fieldTypeStrXML;
125 QList<int> fieldTypeNumBytes;
126 QStringList updateModeStr;
127 QStringList updateModeStrXML;
128 QStringList accessModeStr;
129 QStringList accessModeStrXML;
131 QString processObjectAttributes(QDomNode & node, ObjectInfo *info);
132 QString processObjectFields(QDomNode & childNode, ObjectInfo *info);
133 QString processObjectAccess(QDomNode & childNode, ObjectInfo *info);
134 QString processObjectDescription(QDomNode & childNode, QString *description);
135 QString processObjectCategory(QDomNode & childNode, QString *category);
136 QString processObjectMetadata(QDomNode & childNode, UpdateMode *mode, int *period, bool *acked);
137 void calculateID(ObjectInfo *info);
138 quint32 updateHash(quint32 value, quint32 hash);
139 quint32 updateHash(QString & value, quint32 hash);
142 #endif // UAVOBJECTPARSER_H