From 1bdc03bb1c3fab03bba9c0556344059d56ffb6d5 Mon Sep 17 00:00:00 2001 From: vassilis Date: Sat, 8 Jan 2011 23:40:49 +0000 Subject: [PATCH] GCS/UAVObjects: Added TaskInfo object git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2348 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/uavobjects/taskinfo.cpp | 159 ++++++++++++++++++ ground/src/plugins/uavobjects/taskinfo.h | 91 ++++++++++ ground/src/plugins/uavobjects/taskinfo.py | 120 +++++++++++++ ground/src/plugins/uavobjects/uavobjects.pro | 6 +- .../src/plugins/uavobjects/uavobjectsinit.cpp | 2 + .../shared/uavobjectdefinition/taskinfo.xml | 11 ++ 6 files changed, 387 insertions(+), 2 deletions(-) create mode 100644 ground/src/plugins/uavobjects/taskinfo.cpp create mode 100644 ground/src/plugins/uavobjects/taskinfo.h create mode 100644 ground/src/plugins/uavobjects/taskinfo.py create mode 100644 ground/src/shared/uavobjectdefinition/taskinfo.xml diff --git a/ground/src/plugins/uavobjects/taskinfo.cpp b/ground/src/plugins/uavobjects/taskinfo.cpp new file mode 100644 index 000000000..13c342bfe --- /dev/null +++ b/ground/src/plugins/uavobjects/taskinfo.cpp @@ -0,0 +1,159 @@ +/** + ****************************************************************************** + * + * @file taskinfo.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectsPlugin UAVObjects Plugin + * @{ + * + * @note Object definition file: taskinfo.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @brief The UAVUObjects GCS plugin + *****************************************************************************/ +/* + * 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 + */ +#include "taskinfo.h" +#include "uavobjectfield.h" + +const QString TaskInfo::NAME = QString("TaskInfo"); +const QString TaskInfo::DESCRIPTION = QString("Task information"); + +/** + * Constructor + */ +TaskInfo::TaskInfo(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME) +{ + // Create fields + QList fields; + QStringList StackRemainingElemNames; + StackRemainingElemNames.append("System"); + StackRemainingElemNames.append("Actuator"); + StackRemainingElemNames.append("TelemetryTx"); + StackRemainingElemNames.append("TelemetryTxPri"); + StackRemainingElemNames.append("TelemetryRx"); + StackRemainingElemNames.append("GPS"); + StackRemainingElemNames.append("ManualControl"); + StackRemainingElemNames.append("Altitude"); + StackRemainingElemNames.append("AHRSComms"); + StackRemainingElemNames.append("Stabilization"); + StackRemainingElemNames.append("Guidance"); + StackRemainingElemNames.append("Watchdog"); + fields.append( new UAVObjectField(QString("StackRemaining"), QString("bytes"), UAVObjectField::UINT16, StackRemainingElemNames, QStringList()) ); + QStringList RunningElemNames; + RunningElemNames.append("System"); + RunningElemNames.append("Actuator"); + RunningElemNames.append("TelemetryTx"); + RunningElemNames.append("TelemetryTxPri"); + RunningElemNames.append("TelemetryRx"); + RunningElemNames.append("GPS"); + RunningElemNames.append("ManualControl"); + RunningElemNames.append("Altitude"); + RunningElemNames.append("AHRSComms"); + RunningElemNames.append("Stabilization"); + RunningElemNames.append("Guidance"); + RunningElemNames.append("Watchdog"); + QStringList RunningEnumOptions; + RunningEnumOptions.append("False"); + RunningEnumOptions.append("True"); + fields.append( new UAVObjectField(QString("Running"), QString("bool"), UAVObjectField::ENUM, RunningElemNames, RunningEnumOptions) ); + + // Initialize object + initializeFields(fields, (quint8*)&data, NUMBYTES); + // Set the default field values + setDefaultFieldValues(); + // Set the object description + setDescription(DESCRIPTION); +} + +/** + * Get the default metadata for this object + */ +UAVObject::Metadata TaskInfo::getDefaultMetadata() +{ + UAVObject::Metadata metadata; + metadata.flightAccess = ACCESS_READWRITE; + metadata.gcsAccess = ACCESS_READWRITE; + metadata.gcsTelemetryAcked = 1; + metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.flightTelemetryAcked = 1; + metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; + metadata.flightTelemetryUpdatePeriod = 10000; + metadata.loggingUpdateMode = UAVObject::UPDATEMODE_PERIODIC; + metadata.loggingUpdatePeriod = 1000; + return metadata; +} + +/** + * Initialize object fields with the default values. + * If a default value is not specified the object fields + * will be initialized to zero. + */ +void TaskInfo::setDefaultFieldValues() +{ + +} + +/** + * Get the object data fields + */ +TaskInfo::DataFields TaskInfo::getData() +{ + QMutexLocker locker(mutex); + return data; +} + +/** + * Set the object data fields + */ +void TaskInfo::setData(const DataFields& data) +{ + QMutexLocker locker(mutex); + // Get metadata + Metadata mdata = getMetadata(); + // Update object if the access mode permits + if ( mdata.gcsAccess == ACCESS_READWRITE ) + { + this->data = data; + emit objectUpdatedAuto(this); // trigger object updated event + emit objectUpdated(this); + } +} + +/** + * Create a clone of this object, a new instance ID must be specified. + * Do not use this function directly to create new instances, the + * UAVObjectManager should be used instead. + */ +UAVDataObject* TaskInfo::clone(quint32 instID) +{ + TaskInfo* obj = new TaskInfo(); + obj->initialize(instID, this->getMetaObject()); + return obj; +} + +/** + * Static function to retrieve an instance of the object. + */ +TaskInfo* TaskInfo::GetInstance(UAVObjectManager* objMngr, quint32 instID) +{ + return dynamic_cast(objMngr->getObject(TaskInfo::OBJID, instID)); +} diff --git a/ground/src/plugins/uavobjects/taskinfo.h b/ground/src/plugins/uavobjects/taskinfo.h new file mode 100644 index 000000000..d7dc53919 --- /dev/null +++ b/ground/src/plugins/uavobjects/taskinfo.h @@ -0,0 +1,91 @@ +/** + ****************************************************************************** + * + * @file taskinfo.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup UAVObjectsPlugin UAVObjects Plugin + * @{ + * + * @note Object definition file: taskinfo.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @brief The UAVUObjects GCS plugin + *****************************************************************************/ +/* + * 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 TASKINFO_H +#define TASKINFO_H + +#include "uavdataobject.h" +#include "uavobjectmanager.h" + +class UAVOBJECTS_EXPORT TaskInfo: public UAVDataObject +{ + Q_OBJECT + +public: + // Field structure + typedef struct { + quint16 StackRemaining[12]; + quint8 Running[12]; + + } __attribute__((packed)) DataFields; + + // Field information + // Field StackRemaining information + /* Array element names for field StackRemaining */ + typedef enum { STACKREMAINING_SYSTEM=0, STACKREMAINING_ACTUATOR=1, STACKREMAINING_TELEMETRYTX=2, STACKREMAINING_TELEMETRYTXPRI=3, STACKREMAINING_TELEMETRYRX=4, STACKREMAINING_GPS=5, STACKREMAINING_MANUALCONTROL=6, STACKREMAINING_ALTITUDE=7, STACKREMAINING_AHRSCOMMS=8, STACKREMAINING_STABILIZATION=9, STACKREMAINING_GUIDANCE=10, STACKREMAINING_WATCHDOG=11 } StackRemainingElem; + /* Number of elements for field StackRemaining */ + static const quint32 STACKREMAINING_NUMELEM = 12; + // Field Running information + /* Enumeration options for field Running */ + typedef enum { RUNNING_FALSE=0, RUNNING_TRUE=1 } RunningOptions; + /* Array element names for field Running */ + typedef enum { RUNNING_SYSTEM=0, RUNNING_ACTUATOR=1, RUNNING_TELEMETRYTX=2, RUNNING_TELEMETRYTXPRI=3, RUNNING_TELEMETRYRX=4, RUNNING_GPS=5, RUNNING_MANUALCONTROL=6, RUNNING_ALTITUDE=7, RUNNING_AHRSCOMMS=8, RUNNING_STABILIZATION=9, RUNNING_GUIDANCE=10, RUNNING_WATCHDOG=11 } RunningElem; + /* Number of elements for field Running */ + static const quint32 RUNNING_NUMELEM = 12; + + + // Constants + static const quint32 OBJID = 3297598544U; + static const QString NAME; + static const QString DESCRIPTION; + static const bool ISSINGLEINST = 1; + static const bool ISSETTINGS = 0; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + TaskInfo(); + + DataFields getData(); + void setData(const DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + + static TaskInfo* GetInstance(UAVObjectManager* objMngr, quint32 instID = 0); + +private: + DataFields data; + + void setDefaultFieldValues(); + +}; + +#endif // TASKINFO_H diff --git a/ground/src/plugins/uavobjects/taskinfo.py b/ground/src/plugins/uavobjects/taskinfo.py new file mode 100644 index 000000000..d87deccc9 --- /dev/null +++ b/ground/src/plugins/uavobjects/taskinfo.py @@ -0,0 +1,120 @@ +## +############################################################################## +# +# @file taskinfo.py +# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +# @brief Implementation of the TaskInfo object. This file has been +# automatically generated by the UAVObjectGenerator. +# +# @note Object definition file: taskinfo.xml. +# This is an automatically generated file. +# DO NOT modify manually. +# +# @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 +# + + +import uavobject + +import struct +from collections import namedtuple + +# This is a list of instances of the data fields contained in this object +_fields = [ \ + uavobject.UAVObjectField( + 'StackRemaining', + 'H', + 12, + [ + 'System', + 'Actuator', + 'TelemetryTx', + 'TelemetryTxPri', + 'TelemetryRx', + 'GPS', + 'ManualControl', + 'Altitude', + 'AHRSComms', + 'Stabilization', + 'Guidance', + 'Watchdog', + ], + { + } + ), + uavobject.UAVObjectField( + 'Running', + 'b', + 12, + [ + 'System', + 'Actuator', + 'TelemetryTx', + 'TelemetryTxPri', + 'TelemetryRx', + 'GPS', + 'ManualControl', + 'Altitude', + 'AHRSComms', + 'Stabilization', + 'Guidance', + 'Watchdog', + ], + { + '0' : 'False', + '1' : 'True', + } + ), +] + + +class TaskInfo(uavobject.UAVObject): + ## Object constants + OBJID = 3297598544 + NAME = "TaskInfo" + METANAME = "TaskInfoMeta" + ISSINGLEINST = 1 + ISSETTINGS = 0 + + def __init__(self): + uavobject.UAVObject.__init__(self, + self.OBJID, + self.NAME, + self.METANAME, + 0, + self.ISSINGLEINST) + + for f in _fields: + self.add_field(f) + + def __str__(self): + s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n" + % (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format)) + for f in self.get_tuple()._fields: + s += ("\t%s\n" % f) + return (s) + +def main(): + # Instantiate the object and dump out some interesting info + x = TaskInfo() + print (x) + +if __name__ == "__main__": + #import pdb ; pdb.run('main()') + main() diff --git a/ground/src/plugins/uavobjects/uavobjects.pro b/ground/src/plugins/uavobjects/uavobjects.pro index 6f1e54d83..2406868e1 100644 --- a/ground/src/plugins/uavobjects/uavobjects.pro +++ b/ground/src/plugins/uavobjects/uavobjects.pro @@ -48,7 +48,8 @@ HEADERS += uavobjects_global.h \ pipxtrememodemsettings.h \ pipxtrememodemstatus.h \ i2cstats.h \ - batterysettings.h + batterysettings.h \ + taskinfo.h SOURCES += uavobject.cpp \ uavmetaobject.cpp \ @@ -94,5 +95,6 @@ SOURCES += uavobject.cpp \ pipxtrememodemsettings.cpp \ pipxtrememodemstatus.cpp \ i2cstats.cpp \ - batterysettings.cpp + batterysettings.cpp \ + taskinfo.cpp OTHER_FILES += UAVObjects.pluginspec diff --git a/ground/src/plugins/uavobjects/uavobjectsinit.cpp b/ground/src/plugins/uavobjects/uavobjectsinit.cpp index 3b3514a5c..4c670ff23 100644 --- a/ground/src/plugins/uavobjects/uavobjectsinit.cpp +++ b/ground/src/plugins/uavobjects/uavobjectsinit.cpp @@ -65,6 +65,7 @@ #include "systemalarms.h" #include "systemsettings.h" #include "systemstats.h" +#include "taskinfo.h" #include "telemetrysettings.h" #include "velocityactual.h" #include "velocitydesired.h" @@ -111,6 +112,7 @@ void UAVObjectsInitialize(UAVObjectManager* objMngr) objMngr->registerObject( new SystemAlarms() ); objMngr->registerObject( new SystemSettings() ); objMngr->registerObject( new SystemStats() ); + objMngr->registerObject( new TaskInfo() ); objMngr->registerObject( new TelemetrySettings() ); objMngr->registerObject( new VelocityActual() ); objMngr->registerObject( new VelocityDesired() ); diff --git a/ground/src/shared/uavobjectdefinition/taskinfo.xml b/ground/src/shared/uavobjectdefinition/taskinfo.xml new file mode 100644 index 000000000..523376232 --- /dev/null +++ b/ground/src/shared/uavobjectdefinition/taskinfo.xml @@ -0,0 +1,11 @@ + + + Task information + + + + + + + +