From b92cf530a559fa0525538ace26cc65d8b08bf525 Mon Sep 17 00:00:00 2001 From: vassilis Date: Sun, 18 Apr 2010 02:14:42 +0000 Subject: [PATCH] OP-4 GCS/System Created CPU utilization measurement and created object to report system information (load, heap and time) git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@520 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/uavobjects/systemalarms.cpp | 94 +++++++++++++++++++ ground/src/plugins/uavobjects/systemalarms.h | 76 +++++++++++++++ ground/src/plugins/uavobjects/systemstats.cpp | 81 ++++++++++++++++ ground/src/plugins/uavobjects/systemstats.h | 72 ++++++++++++++ ground/src/plugins/uavobjects/uavobjects.pro | 8 +- .../src/plugins/uavobjects/uavobjectsinit.cpp | 4 + .../uavobjectdefinition/systemalarms.xml | 11 +++ .../uavobjectdefinition/systemstats.xml | 10 ++ 8 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 ground/src/plugins/uavobjects/systemalarms.cpp create mode 100644 ground/src/plugins/uavobjects/systemalarms.h create mode 100644 ground/src/plugins/uavobjects/systemstats.cpp create mode 100644 ground/src/plugins/uavobjects/systemstats.h create mode 100644 ground/src/shared/uavobjectdefinition/systemalarms.xml create mode 100644 ground/src/shared/uavobjectdefinition/systemstats.xml diff --git a/ground/src/plugins/uavobjects/systemalarms.cpp b/ground/src/plugins/uavobjects/systemalarms.cpp new file mode 100644 index 000000000..0dfa58af3 --- /dev/null +++ b/ground/src/plugins/uavobjects/systemalarms.cpp @@ -0,0 +1,94 @@ +/** + ****************************************************************************** + * + * @file systemalarms.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SystemAlarms object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: systemalarms.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 + */ +#include "systemalarms.h" +#include "uavobjectfields.h" + +const QString SystemAlarms::NAME = QString("SystemAlarms"); + +SystemAlarms::SystemAlarms(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME) +{ + // Create fields + QList fields; + QStringList TypeEnumOptions; + TypeEnumOptions.append("None"); + TypeEnumOptions.append("StackOverflow"); + TypeEnumOptions.append("OutOfMemory"); + fields.append(new UAVObjectFieldEnum(QString("Type"), QString(""), 1, TypeEnumOptions)); + QStringList SeverityEnumOptions; + SeverityEnumOptions.append("Info"); + SeverityEnumOptions.append("Warning"); + SeverityEnumOptions.append("Error"); + SeverityEnumOptions.append("Critical"); + fields.append(new UAVObjectFieldEnum(QString("Severity"), QString(""), 1, SeverityEnumOptions)); + QStringList ActiveEnumOptions; + ActiveEnumOptions.append("True"); + ActiveEnumOptions.append("False"); + fields.append(new UAVObjectFieldEnum(QString("Active"), QString("bool"), 1, ActiveEnumOptions)); + fields.append(new UAVObjectFieldUInt32(QString("Info"), QString(""), 1)); + + // Initialize object + initializeFields(fields, (quint8*)&data, NUMBYTES); +} + +UAVObject::Metadata SystemAlarms::getDefaultMetadata() +{ + UAVObject::Metadata metadata; + metadata.gcsTelemetryAcked = 1; + metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.flightTelemetryAcked = 1; + metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; + metadata.flightTelemetryUpdatePeriod = 0; + metadata.loggingUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; + metadata.loggingUpdatePeriod = 0; + return metadata; +} + +SystemAlarms::DataFields SystemAlarms::getData() +{ + QMutexLocker locker(mutex); + return data; +} + +void SystemAlarms::setData(DataFields& data) +{ + QMutexLocker locker(mutex); + this->data = data; + emit objectUpdatedAuto(this); // trigger object updated event + emit objectUpdated(this); +} + +UAVDataObject* SystemAlarms::clone(quint32 instID) +{ + SystemAlarms* obj = new SystemAlarms(); + obj->initialize(instID, this->getMetaObject()); + return obj; +} diff --git a/ground/src/plugins/uavobjects/systemalarms.h b/ground/src/plugins/uavobjects/systemalarms.h new file mode 100644 index 000000000..0e7c7c3f1 --- /dev/null +++ b/ground/src/plugins/uavobjects/systemalarms.h @@ -0,0 +1,76 @@ +/** + ****************************************************************************** + * + * @file systemalarms.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SystemAlarms object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: systemalarms.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 + */ +#ifndef SYSTEMALARMS_H +#define SYSTEMALARMS_H + +#include "uavdataobject.h" + +class UAVOBJECTS_EXPORT SystemAlarms: public UAVDataObject +{ + Q_OBJECT + +public: + // Field structure + typedef struct { + quint8 Type; + quint8 Severity; + quint8 Active; + quint32 Info; + + } __attribute__((packed)) DataFields; + + // Enumeration types + typedef enum { TYPE_NONE=0, TYPE_STACKOVERFLOW=1, TYPE_OUTOFMEMORY=2, } TypeEnum; + typedef enum { SEVERITY_INFO=0, SEVERITY_WARNING=1, SEVERITY_ERROR=2, SEVERITY_CRITICAL=3, } SeverityEnum; + typedef enum { ACTIVE_TRUE=0, ACTIVE_FALSE=1, } ActiveEnum; + + + // Constants + static const quint32 OBJID = 1784134234U; + static const QString NAME; + static const bool ISSINGLEINST = 1; + static const bool ISSETTINGS = 0; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + SystemAlarms(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // SYSTEMALARMS_H diff --git a/ground/src/plugins/uavobjects/systemstats.cpp b/ground/src/plugins/uavobjects/systemstats.cpp new file mode 100644 index 000000000..9a52b6b24 --- /dev/null +++ b/ground/src/plugins/uavobjects/systemstats.cpp @@ -0,0 +1,81 @@ +/** + ****************************************************************************** + * + * @file systemstats.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SystemStats object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: systemstats.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 + */ +#include "systemstats.h" +#include "uavobjectfields.h" + +const QString SystemStats::NAME = QString("SystemStats"); + +SystemStats::SystemStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME) +{ + // Create fields + QList fields; + fields.append(new UAVObjectFieldUInt32(QString("FlightTime"), QString("ms"), 1)); + fields.append(new UAVObjectFieldUInt16(QString("HeapRemaining"), QString("bytes"), 1)); + fields.append(new UAVObjectFieldUInt8(QString("CPULoad"), QString("%"), 1)); + + // Initialize object + initializeFields(fields, (quint8*)&data, NUMBYTES); +} + +UAVObject::Metadata SystemStats::getDefaultMetadata() +{ + UAVObject::Metadata metadata; + metadata.gcsTelemetryAcked = 1; + metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_NEVER; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.flightTelemetryAcked = 1; + metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; + metadata.flightTelemetryUpdatePeriod = 1000; + metadata.loggingUpdateMode = UAVObject::UPDATEMODE_PERIODIC; + metadata.loggingUpdatePeriod = 1000; + return metadata; +} + +SystemStats::DataFields SystemStats::getData() +{ + QMutexLocker locker(mutex); + return data; +} + +void SystemStats::setData(DataFields& data) +{ + QMutexLocker locker(mutex); + this->data = data; + emit objectUpdatedAuto(this); // trigger object updated event + emit objectUpdated(this); +} + +UAVDataObject* SystemStats::clone(quint32 instID) +{ + SystemStats* obj = new SystemStats(); + obj->initialize(instID, this->getMetaObject()); + return obj; +} diff --git a/ground/src/plugins/uavobjects/systemstats.h b/ground/src/plugins/uavobjects/systemstats.h new file mode 100644 index 000000000..9e6b886f8 --- /dev/null +++ b/ground/src/plugins/uavobjects/systemstats.h @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * + * @file systemstats.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SystemStats object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: systemstats.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 + */ +#ifndef SYSTEMSTATS_H +#define SYSTEMSTATS_H + +#include "uavdataobject.h" + +class UAVOBJECTS_EXPORT SystemStats: public UAVDataObject +{ + Q_OBJECT + +public: + // Field structure + typedef struct { + quint32 FlightTime; + quint16 HeapRemaining; + quint8 CPULoad; + + } __attribute__((packed)) DataFields; + + // Enumeration types + + + // Constants + static const quint32 OBJID = 680908530U; + static const QString NAME; + static const bool ISSINGLEINST = 1; + static const bool ISSETTINGS = 0; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + SystemStats(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // SYSTEMSTATS_H diff --git a/ground/src/plugins/uavobjects/uavobjects.pro b/ground/src/plugins/uavobjects/uavobjects.pro index 810fa8ea8..cb67f1ecc 100644 --- a/ground/src/plugins/uavobjects/uavobjects.pro +++ b/ground/src/plugins/uavobjects/uavobjects.pro @@ -26,7 +26,9 @@ HEADERS += uavobjects_global.h \ settingspersistence.h \ gpsobject.h \ gcstelemetrystats.h \ - flighttelemetrystats.h + flighttelemetrystats.h \ + systemstats.h \ + systemalarms.h SOURCES += uavobject.cpp \ uavmetaobject.cpp \ uavobjectmanager.cpp \ @@ -49,6 +51,8 @@ SOURCES += uavobject.cpp \ settingspersistence.cpp \ gpsobject.cpp \ gcstelemetrystats.cpp \ - flighttelemetrystats.cpp + flighttelemetrystats.cpp \ + systemstats.cpp \ + systemalarms.cpp DEFINES += UAVOBJECTS_LIBRARY OTHER_FILES += UAVObjects.pluginspec diff --git a/ground/src/plugins/uavobjects/uavobjectsinit.cpp b/ground/src/plugins/uavobjects/uavobjectsinit.cpp index b04ada757..6f077ce0d 100644 --- a/ground/src/plugins/uavobjects/uavobjectsinit.cpp +++ b/ground/src/plugins/uavobjects/uavobjectsinit.cpp @@ -37,6 +37,8 @@ #include "gcstelemetrystats.h" #include "gpsobject.h" #include "settingspersistence.h" +#include "systemalarms.h" +#include "systemstats.h" /** @@ -52,5 +54,7 @@ void UAVObjectsInitialize(UAVObjectManager* objMngr) objMngr->registerObject( new GCSTelemetryStats() ); objMngr->registerObject( new GpsObject() ); objMngr->registerObject( new SettingsPersistence() ); + objMngr->registerObject( new SystemAlarms() ); + objMngr->registerObject( new SystemStats() ); } diff --git a/ground/src/shared/uavobjectdefinition/systemalarms.xml b/ground/src/shared/uavobjectdefinition/systemalarms.xml new file mode 100644 index 000000000..0f7690af2 --- /dev/null +++ b/ground/src/shared/uavobjectdefinition/systemalarms.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/ground/src/shared/uavobjectdefinition/systemstats.xml b/ground/src/shared/uavobjectdefinition/systemstats.xml new file mode 100644 index 000000000..40b31fc3c --- /dev/null +++ b/ground/src/shared/uavobjectdefinition/systemstats.xml @@ -0,0 +1,10 @@ + + + + + + + + + +