2013-04-05 22:46:56 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file uavobjectparser.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief Parses XML files and extracts object information.
|
|
|
|
*
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UAVOBJECTPARSER_H
|
|
|
|
#define UAVOBJECTPARSER_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QList>
|
|
|
|
#include <QDomNode>
|
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
// Types
|
|
|
|
typedef enum {
|
|
|
|
FIELDTYPE_INT8 = 0,
|
|
|
|
FIELDTYPE_INT16,
|
|
|
|
FIELDTYPE_INT32,
|
|
|
|
FIELDTYPE_UINT8,
|
|
|
|
FIELDTYPE_UINT16,
|
|
|
|
FIELDTYPE_UINT32,
|
|
|
|
FIELDTYPE_FLOAT32,
|
|
|
|
FIELDTYPE_ENUM
|
|
|
|
} FieldType;
|
|
|
|
|
|
|
|
typedef struct {
|
2013-05-19 16:37:30 +02:00
|
|
|
QString name;
|
2014-10-11 16:12:58 +02:00
|
|
|
QString description;
|
2013-05-19 16:37:30 +02:00
|
|
|
QString units;
|
|
|
|
FieldType type;
|
2013-04-05 22:46:56 +02:00
|
|
|
int numElements;
|
|
|
|
int numBytes;
|
|
|
|
QStringList elementNames;
|
|
|
|
QStringList options; // for enums only
|
|
|
|
bool defaultElementNames;
|
|
|
|
QStringList defaultValues;
|
2013-05-19 16:37:30 +02:00
|
|
|
QString limitValues;
|
2013-04-05 22:46:56 +02:00
|
|
|
} FieldInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object update mode
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2013-05-19 16:37:30 +02:00
|
|
|
UPDATEMODE_MANUAL = 0, /** Manually update object, by calling the updated() function */
|
|
|
|
UPDATEMODE_PERIODIC = 1, /** Automatically update object at periodic intervals */
|
2013-04-05 22:46:56 +02:00
|
|
|
UPDATEMODE_ONCHANGE = 2, /** Only update object when its data changes */
|
2013-05-19 16:37:30 +02:00
|
|
|
UPDATEMODE_THROTTLED = 3 /** Object is updated on change, but not more often than the interval time */
|
2013-04-05 22:46:56 +02:00
|
|
|
} UpdateMode;
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ACCESS_READWRITE = 0,
|
2013-05-19 16:37:30 +02:00
|
|
|
ACCESS_READONLY = 1
|
2013-04-05 22:46:56 +02:00
|
|
|
} AccessMode;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2013-05-19 16:37:30 +02:00
|
|
|
QString name;
|
|
|
|
QString namelc; /** name in lowercase */
|
|
|
|
QString filename;
|
|
|
|
quint32 id;
|
|
|
|
bool isSingleInst;
|
|
|
|
bool isSettings;
|
2014-02-04 21:03:42 +01:00
|
|
|
bool isPriority;
|
2013-04-05 22:46:56 +02:00
|
|
|
AccessMode gcsAccess;
|
|
|
|
AccessMode flightAccess;
|
2013-05-19 16:37:30 +02:00
|
|
|
bool flightTelemetryAcked;
|
2013-04-05 22:46:56 +02:00
|
|
|
UpdateMode flightTelemetryUpdateMode; /** Update mode used by the autopilot (UpdateMode) */
|
|
|
|
int flightTelemetryUpdatePeriod; /** Update period used by the autopilot (only if telemetry mode is PERIODIC) */
|
2013-05-19 16:37:30 +02:00
|
|
|
bool gcsTelemetryAcked;
|
2013-04-05 22:46:56 +02:00
|
|
|
UpdateMode gcsTelemetryUpdateMode; /** Update mode used by the GCS (UpdateMode) */
|
|
|
|
int gcsTelemetryUpdatePeriod; /** Update period used by the GCS (only if telemetry mode is PERIODIC) */
|
|
|
|
UpdateMode loggingUpdateMode; /** Update mode used by the logging module (UpdateMode) */
|
|
|
|
int loggingUpdatePeriod; /** Update period used by the logging module (only if logging mode is PERIODIC) */
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<FieldInfo *> fields; /** The data fields for the object **/
|
|
|
|
QString description; /** Description used for Doxygen **/
|
|
|
|
QString category; /** Description used for Doxygen **/
|
2013-04-05 22:46:56 +02:00
|
|
|
} ObjectInfo;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
class UAVObjectParser {
|
2013-04-05 22:46:56 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Functions
|
|
|
|
UAVObjectParser();
|
2013-05-19 16:37:30 +02:00
|
|
|
QString parseXML(QString & xml, QString & filename);
|
2013-04-05 22:46:56 +02:00
|
|
|
int getNumObjects();
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<ObjectInfo *> getObjectInfo();
|
2013-04-05 22:46:56 +02:00
|
|
|
QString getObjectName(int objIndex);
|
|
|
|
quint32 getObjectID(int objIndex);
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
ObjectInfo *getObjectByIndex(int objIndex);
|
2013-04-05 22:46:56 +02:00
|
|
|
int getNumBytes(int objIndex);
|
|
|
|
QStringList all_units;
|
|
|
|
|
|
|
|
private:
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<ObjectInfo *> objInfo;
|
2013-04-05 22:46:56 +02:00
|
|
|
QStringList fieldTypeStrXML;
|
|
|
|
QList<int> fieldTypeNumBytes;
|
|
|
|
QStringList updateModeStr;
|
|
|
|
QStringList updateModeStrXML;
|
|
|
|
QStringList accessModeStr;
|
|
|
|
QStringList accessModeStrXML;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
QString processObjectAttributes(QDomNode & node, ObjectInfo *info);
|
|
|
|
QString processObjectFields(QDomNode & childNode, ObjectInfo *info);
|
|
|
|
QString processObjectAccess(QDomNode & childNode, ObjectInfo *info);
|
|
|
|
QString processObjectDescription(QDomNode & childNode, QString *description);
|
|
|
|
QString processObjectCategory(QDomNode & childNode, QString *category);
|
|
|
|
QString processObjectMetadata(QDomNode & childNode, UpdateMode *mode, int *period, bool *acked);
|
|
|
|
void calculateID(ObjectInfo *info);
|
2013-04-05 22:46:56 +02:00
|
|
|
quint32 updateHash(quint32 value, quint32 hash);
|
2013-05-19 16:37:30 +02:00
|
|
|
quint32 updateHash(QString & value, quint32 hash);
|
2013-04-05 22:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // UAVOBJECTPARSER_H
|