1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-1365 Flight code instrumentation API: Implementation of UAVObject wrapper layer

This commit is contained in:
Alessio Morale 2014-06-06 22:19:27 +02:00
parent 520e721bdd
commit 2396350f2f
4 changed files with 112 additions and 2 deletions

View File

@ -0,0 +1,34 @@
/**
******************************************************************************
*
* @file instrumentation.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief brief goes here.
* --
* @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 INSTRUMENTATION_H
#define INSTRUMENTATION_H
#include <perfcounter.h>
void InstrumentationInit();
void InstrumentationPublishAllCounters();
#endif /* INSTRUMENTATION_H */

View File

@ -0,0 +1,62 @@
/**
******************************************************************************
*
* @file instrumentation.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
* @brief brief goes here.
* --
* @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 <openpilot.h>
#include <instrumentation.h>
#include <pios_instrumentation.h>
static uint8_t publishedCountersInstances = 0;
static void counterCallback(const pios_perf_counter_t *counter, const int8_t index, void *context);
static xSemaphoreHandle sem;
void InstrumentationInit()
{
PerfCounterInitialize();
publishedCountersInstances = 1;
vSemaphoreCreateBinary(sem);
}
void InstrumentationPublishAllCounters()
{
if (xSemaphoreTake(sem, 0) != pdTRUE) {
return;
}
PIOS_Instrumentation_ForEachCounter(&counterCallback, NULL);
xSemaphoreGive(sem);
}
void counterCallback(const pios_perf_counter_t *counter, const int8_t index, __attribute__((unused)) void *context)
{
if (publishedCountersInstances < index) {
PerfCounterCreateInstance();
publishedCountersInstances++;
}
PerfCounterData data;
data.Id = counter->id;
data.Counter.Max = counter->max;
data.Counter.Min = counter->min;
data.Counter.Value = counter->value;
PerfCounterInstSet(index, &data);
}

View File

@ -126,7 +126,8 @@ HEADERS += \
$$UAVOBJECT_SYNTHETICS/waypoint.h \
$$UAVOBJECT_SYNTHETICS/waypointactive.h \
$$UAVOBJECT_SYNTHETICS/mpu6000settings.h \
$$UAVOBJECT_SYNTHETICS/takeofflocation.h
$$UAVOBJECT_SYNTHETICS/takeofflocation.h \
$$UAVOBJECT_SYNTHETICS/perfcounter.h
SOURCES += \
$$UAVOBJECT_SYNTHETICS/accelgyrosettings.cpp \
@ -229,4 +230,6 @@ SOURCES += \
$$UAVOBJECT_SYNTHETICS/waypoint.cpp \
$$UAVOBJECT_SYNTHETICS/waypointactive.cpp \
$$UAVOBJECT_SYNTHETICS/mpu6000settings.cpp \
$$UAVOBJECT_SYNTHETICS/takeofflocation.cpp
$$UAVOBJECT_SYNTHETICS/takeofflocation.cpp \
$$UAVOBJECT_SYNTHETICS/perfcounter.cpp

View File

@ -0,0 +1,11 @@
<xml>
<object name="PerfCounter" singleinstance="false" settings="false" category="System">
<description>A single performance counter, used to instrument flight code</description>
<field name="Id" units="" type="uint32" elements="1" />
<field name="Counter" units="" type="int32" elementnames="Value, Min, Max"/>
<access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="false" updatemode="manual" period="0"/>
<telemetryflight acked="false" updatemode="manual" period="0"/>
<logging updatemode="manual" period="0"/>
</object>
</xml>