mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Logging facility: logs debug data to logfs and exports it through container UAVObject
This commit is contained in:
parent
adfbdfae38
commit
a0746d87fa
106
flight/modules/Logging/Logging.c
Normal file
106
flight/modules/Logging/Logging.c
Normal file
@ -0,0 +1,106 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||
* @{
|
||||
* @addtogroup LoggingModule Logging Module
|
||||
* @brief Features for on board logging
|
||||
* @{
|
||||
*
|
||||
* @file Logging.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
|
||||
* @brief Logging module, provides features for on board logging
|
||||
* @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 "debuglogsettings.h"
|
||||
#include "debuglogcontrol.h"
|
||||
#include "debuglogentry.h"
|
||||
|
||||
// private variables
|
||||
static DebugLogSettingsData settings;
|
||||
static DebugLogControlData control;
|
||||
static DebugLogEntryData *entry; // would be better on stack but event dispatcher stack might be insufficient
|
||||
|
||||
// private functions
|
||||
static void SettingsUpdatedCb(UAVObjEvent *ev);
|
||||
static void ControlUpdatedCb(UAVObjEvent *ev);
|
||||
|
||||
int32_t LoggingInitialize(void)
|
||||
{
|
||||
DebugLogSettingsInitialize();
|
||||
DebugLogControlInitialize();
|
||||
DebugLogEntryInitialize();
|
||||
PIOS_DEBUGLOG_Initialize();
|
||||
entry = pvPortMalloc(sizeof(DebugLogEntryData));
|
||||
if (!entry) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t LoggingStart(void)
|
||||
{
|
||||
DebugLogSettingsConnectCallback(SettingsUpdatedCb);
|
||||
DebugLogControlConnectCallback(ControlUpdatedCb);
|
||||
SettingsUpdatedCb(DebugLogSettingsHandle());
|
||||
return 0;
|
||||
}
|
||||
MODULE_INITCALL(LoggingInitialize, LoggingStart);
|
||||
|
||||
|
||||
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
||||
{
|
||||
DebugLogSettingsGet(&settings);
|
||||
PIOS_DEBUGLOG_Enable(settings.LoggingEnabled);
|
||||
PIOS_DEBUGLOG_Printf("Logging enabled");
|
||||
}
|
||||
|
||||
static void ControlUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
||||
{
|
||||
static bool ignore = 0; // this little hack allows us to set our own uavobject in the callback
|
||||
|
||||
if (ignore) {
|
||||
ignore = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLogControlGet(&control);
|
||||
if (PIOS_DEBUGLOG_Read(entry, control.Flight, control.Entry) != 0) {
|
||||
// reading from log failed, mark as non existent in output
|
||||
memset(entry, 0, sizeof(DebugLogEntryData));
|
||||
entry->Flight = control.Flight;
|
||||
entry->Entry = control.Entry;
|
||||
entry->Type = DEBUGLOGENTRY_TYPE_EMPTY;
|
||||
}
|
||||
PIOS_DEBUGLOG_Info(&control.Flight, &control.Entry);
|
||||
|
||||
ignore = 1; // set ignore flag before setting object - creates loop otherwise!!!
|
||||
DebugLogEntrySet(entry);
|
||||
DebugLogControlSet(&control);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
90
flight/pios/inc/pios_debuglog.h
Normal file
90
flight/pios/inc/pios_debuglog.h
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @defgroup PIOS_DEBUGLOG Flash log debugging Functions
|
||||
* @brief Debugging functionality
|
||||
* @{
|
||||
*
|
||||
* @file pios_debuglog.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
|
||||
* @brief Debugging Functions
|
||||
* @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 PIOS_DEBUGLOG_H
|
||||
#define PIOS_DEBUGLOG_H
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the log facility
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Initialize();
|
||||
|
||||
/**
|
||||
* @brief Enables or Disables logging globally
|
||||
* @param[in] enable or disable logging
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Enable(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Write a debug log entry with a uavobject
|
||||
* @param[in] objectid
|
||||
* @param[in] instanceid
|
||||
* @param[in] instanceid
|
||||
* @param[in] size of object
|
||||
* @param[in] data buffer
|
||||
*/
|
||||
void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Write a debug log entry with text
|
||||
* @param[in] format - as in printf
|
||||
* @param[in] variable arguments for printf
|
||||
* @param...
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Printf(char *format, ...);
|
||||
|
||||
/**
|
||||
* @brief Load one object instance from the filesystem
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
* @param[in] log entry sequence number
|
||||
* @return 0 if success or error code
|
||||
* @retval -1 if fs_id is not a valid filesystem instance
|
||||
* @retval -2 if failed to start transaction
|
||||
* @retval -3 if object not found in filesystem
|
||||
* @retval -4 if object size in filesystem does not exactly match buffer size
|
||||
* @retval -5 if reading the object data from flash fails
|
||||
*/
|
||||
int32_t PIOS_DEBUGLOG_Read(void *buffer, uint16_t flight, uint16_t inst);
|
||||
|
||||
/**
|
||||
* @brief Retrieve run time info of logging system
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry);
|
||||
|
||||
#endif // ifndef PIOS_DEBUGLOG_H
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -78,6 +78,7 @@ extern void PIOS_LED_Init(void);
|
||||
#include <pios_servo.h>
|
||||
#include <pios_wdg.h>
|
||||
#include <pios_debug.h>
|
||||
#include <pios_debuglog.h>
|
||||
#include <pios_crc.h>
|
||||
#include <pios_rcvr.h>
|
||||
#include <pios_flash.h>
|
||||
|
192
flight/pios/posix/pios_debuglog.c
Normal file
192
flight/pios/posix/pios_debuglog.c
Normal file
@ -0,0 +1,192 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @defgroup PIOS_DEBUGLOG Flash log debugging Functions
|
||||
* @brief Debugging functionality
|
||||
* @{
|
||||
*
|
||||
* @file pios_debuglog.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
|
||||
* @brief Debugging Functions
|
||||
* @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
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "debuglogentry.h"
|
||||
|
||||
// global definitions
|
||||
|
||||
|
||||
// Global variables
|
||||
extern uintptr_t pios_user_fs_id; // flash filesystem for logging
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static xSemaphoreHandle mutex = 0;
|
||||
#define mutexlock() xSemaphoreTakeRecursive(mutex, portMAX_DELAY)
|
||||
#define mutexunlock() xSemaphoreGiveRecursive(mutex)
|
||||
#else
|
||||
#define mutexlock()
|
||||
#define mutexunlock()
|
||||
#endif
|
||||
|
||||
static bool logging_enabled = false;
|
||||
static uint16_t flightnum = 0;
|
||||
static uint16_t lognum = 0;
|
||||
static DebugLogEntryData buffer;
|
||||
|
||||
/* Private Function Prototypes */
|
||||
|
||||
/**
|
||||
* @brief Initialize the log facility
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Initialize()
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (!mutex) {
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
#endif
|
||||
mutexlock();
|
||||
lognum = 0;
|
||||
flightnum = 0;
|
||||
while (PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
flightnum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables or Disables logging globally
|
||||
* @param[in] enable or disable logging
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Enable(bool enabled)
|
||||
{
|
||||
logging_enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a debug log entry with a uavobject
|
||||
* @param[in] objectid
|
||||
* @param[in] instanceid
|
||||
* @param[in] instanceid
|
||||
* @param[in] size of object
|
||||
* @param[in] data buffer
|
||||
*/
|
||||
void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8_t *data)
|
||||
{
|
||||
if (!logging_enabled) {
|
||||
return;
|
||||
}
|
||||
mutexlock();
|
||||
buffer.Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer.FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer.FlightTime = 0;
|
||||
#endif
|
||||
buffer.Type = DEBUGLOGENTRY_TYPE_UAVOBJECT;
|
||||
buffer.ObjectID = objid;
|
||||
buffer.InstanceID = instid;
|
||||
buffer.Size = size;
|
||||
uint16_t t = 0;
|
||||
for (; t < size && t < sizeof(buffer.Data); t++) {
|
||||
buffer.Data[t] = data[t];
|
||||
}
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
/**
|
||||
* @brief Write a debug log entry with text
|
||||
* @param[in] format - as in printf
|
||||
* @param[in] variable arguments for printf
|
||||
* @param...
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Printf(char *format, ...)
|
||||
{
|
||||
if (!logging_enabled) {
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
mutexlock();
|
||||
vsnprintf((char *)buffer.Data, sizeof(buffer.Data), (char *)format, args);
|
||||
buffer.Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer.FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer.FlightTime = 0;
|
||||
#endif
|
||||
buffer.Entry = lognum;
|
||||
buffer.Type = DEBUGLOGENTRY_TYPE_TEXT;
|
||||
buffer.ObjectID = 0;
|
||||
buffer.InstanceID = 0;
|
||||
buffer.Size = strlen((const char *)buffer.Data);
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Load one object instance from the filesystem
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
* @param[in] log entry sequence number
|
||||
* @return 0 if success or error code
|
||||
* @retval -1 if fs_id is not a valid filesystem instance
|
||||
* @retval -2 if failed to start transaction
|
||||
* @retval -3 if object not found in filesystem
|
||||
* @retval -4 if object size in filesystem does not exactly match buffer size
|
||||
* @retval -5 if reading the object data from flash fails
|
||||
*/
|
||||
int32_t PIOS_DEBUGLOG_Read(void *buffer, uint16_t flight, uint16_t inst)
|
||||
{
|
||||
PIOS_Assert(buffer);
|
||||
return PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flight * 256, inst, (uint8_t *)buffer, sizeof(DebugLogEntryData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve run time info of logging system
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
||||
{
|
||||
if (flight) {
|
||||
*flight = flightnum;
|
||||
}
|
||||
if (entry) {
|
||||
*entry = lognum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -37,6 +37,7 @@ MODULES += FixedWingPathFollower
|
||||
MODULES += VtolPathFollower
|
||||
MODULES += CameraStab
|
||||
MODULES += Telemetry
|
||||
MODULES += Logging
|
||||
MODULES += FirmwareIAP
|
||||
MODULES += StateEstimation
|
||||
#MODULES += Sensors/simulated/Sensors
|
||||
|
@ -42,6 +42,9 @@ UAVOBJSRCFILENAMES += barosensor
|
||||
UAVOBJSRCFILENAMES += airspeedsensor
|
||||
UAVOBJSRCFILENAMES += airspeedsettings
|
||||
UAVOBJSRCFILENAMES += airspeedstate
|
||||
UAVOBJSRCFILENAMES += debuglogsettings
|
||||
UAVOBJSRCFILENAMES += debuglogcontrol
|
||||
UAVOBJSRCFILENAMES += debuglogentry
|
||||
UAVOBJSRCFILENAMES += flightbatterysettings
|
||||
UAVOBJSRCFILENAMES += firmwareiapobj
|
||||
UAVOBJSRCFILENAMES += flightbatterystate
|
||||
|
@ -34,6 +34,9 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudeholddesired.h \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudeholdsettings.h \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.h \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogsettings.h \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.h \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogentry.h \
|
||||
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.h \
|
||||
$$UAVOBJECT_SYNTHETICS/ekfstatevariance.h \
|
||||
$$UAVOBJECT_SYNTHETICS/revocalibration.h \
|
||||
@ -120,6 +123,9 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/altholdsmoothed.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudeholddesired.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudeholdsettings.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogsettings.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/debuglogentry.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.cpp \
|
||||
$$UAVOBJECT_SYNTHETICS/ekfstatevariance.cpp \
|
||||
|
11
shared/uavobjectdefinition/debuglogcontrol.xml
Normal file
11
shared/uavobjectdefinition/debuglogcontrol.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<xml>
|
||||
<object name="DebugLogControl" singleinstance="true" settings="false" category="System">
|
||||
<description>Log Control Object</description>
|
||||
<field name="Flight" units="" type="uint16" elements="1" />
|
||||
<field name="Entry" units="" type="uint16" elements="1" />
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="manual" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="manual" period="0"/>
|
||||
<logging updatemode="manual" period="0"/>
|
||||
</object>
|
||||
</xml>
|
17
shared/uavobjectdefinition/debuglogentry.xml
Normal file
17
shared/uavobjectdefinition/debuglogentry.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<xml>
|
||||
<object name="DebugLogEntry" singleinstance="true" settings="false" category="System">
|
||||
<description>Log Entry in Flash</description>
|
||||
<field name="Flight" units="" type="uint16" elements="1" />
|
||||
<field name="FlightTime" units="ms" type="uint32" elements="1" />
|
||||
<field name="Entry" units="" type="uint16" elements="1" />
|
||||
<field name="Type" units="" type="enum" elements="1" options="Empty, Text, UAVObject" />
|
||||
<field name="ObjectID" units="" type="uint32" elements="1"/>
|
||||
<field name="InstanceID" units="" type="uint16" elements="1"/>
|
||||
<field name="Size" units="" type="uint16" elements="1" />
|
||||
<field name="Data" units="" type="uint8" elements="200" />
|
||||
<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>
|
11
shared/uavobjectdefinition/debuglogsettings.xml
Normal file
11
shared/uavobjectdefinition/debuglogsettings.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<xml>
|
||||
<object name="DebugLogSettings" singleinstance="true" settings="true" category="System">
|
||||
<description>Configure On Board Logging Facilities</description>
|
||||
<field name="LoggingEnabled" units="bool" type="enum" elements="1" options="False,True" defaultvalue="False" />
|
||||
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="onchange" period="0"/>
|
||||
<logging updatemode="manual" period="0"/>
|
||||
</object>
|
||||
</xml>
|
Loading…
x
Reference in New Issue
Block a user