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