mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
more intelligent log interfacing, including flash formatting option
This commit is contained in:
parent
3d8625abaf
commit
fcc479f5cb
@ -33,22 +33,28 @@
|
|||||||
#include "openpilot.h"
|
#include "openpilot.h"
|
||||||
#include "debuglogsettings.h"
|
#include "debuglogsettings.h"
|
||||||
#include "debuglogcontrol.h"
|
#include "debuglogcontrol.h"
|
||||||
|
#include "debuglogstatus.h"
|
||||||
#include "debuglogentry.h"
|
#include "debuglogentry.h"
|
||||||
|
#include "flightstatus.h"
|
||||||
|
|
||||||
// private variables
|
// private variables
|
||||||
static DebugLogSettingsData settings;
|
static DebugLogSettingsData settings;
|
||||||
static DebugLogControlData control;
|
static DebugLogControlData control;
|
||||||
|
static DebugLogStatusData status;
|
||||||
static DebugLogEntryData *entry; // would be better on stack but event dispatcher stack might be insufficient
|
static DebugLogEntryData *entry; // would be better on stack but event dispatcher stack might be insufficient
|
||||||
|
|
||||||
// private functions
|
// private functions
|
||||||
static void SettingsUpdatedCb(UAVObjEvent *ev);
|
static void SettingsUpdatedCb(UAVObjEvent *ev);
|
||||||
static void ControlUpdatedCb(UAVObjEvent *ev);
|
static void ControlUpdatedCb(UAVObjEvent *ev);
|
||||||
|
static void StatusUpdatedCb(UAVObjEvent *ev);
|
||||||
|
|
||||||
int32_t LoggingInitialize(void)
|
int32_t LoggingInitialize(void)
|
||||||
{
|
{
|
||||||
DebugLogSettingsInitialize();
|
DebugLogSettingsInitialize();
|
||||||
DebugLogControlInitialize();
|
DebugLogControlInitialize();
|
||||||
|
DebugLogStatusInitialize();
|
||||||
DebugLogEntryInitialize();
|
DebugLogEntryInitialize();
|
||||||
|
FlightStatusInitialize();
|
||||||
PIOS_DEBUGLOG_Initialize();
|
PIOS_DEBUGLOG_Initialize();
|
||||||
entry = pvPortMalloc(sizeof(DebugLogEntryData));
|
entry = pvPortMalloc(sizeof(DebugLogEntryData));
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
@ -63,10 +69,21 @@ int32_t LoggingStart(void)
|
|||||||
DebugLogSettingsConnectCallback(SettingsUpdatedCb);
|
DebugLogSettingsConnectCallback(SettingsUpdatedCb);
|
||||||
DebugLogControlConnectCallback(ControlUpdatedCb);
|
DebugLogControlConnectCallback(ControlUpdatedCb);
|
||||||
SettingsUpdatedCb(DebugLogSettingsHandle());
|
SettingsUpdatedCb(DebugLogSettingsHandle());
|
||||||
|
|
||||||
|
UAVObjEvent ev = { .obj = DebugLogSettingsHandle(), .instId = 0, .event = EV_UPDATED_PERIODIC };
|
||||||
|
EventPeriodicCallbackCreate(&ev, StatusUpdatedCb, 1000);
|
||||||
|
// invoke a periodic dispatcher callback - the event struct is a dummy, it could be filled with anything!
|
||||||
|
StatusUpdatedCb(&ev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
MODULE_INITCALL(LoggingInitialize, LoggingStart);
|
MODULE_INITCALL(LoggingInitialize, LoggingStart);
|
||||||
|
|
||||||
|
static void StatusUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
||||||
|
{
|
||||||
|
PIOS_DEBUGLOG_Info(&status.Flight, &status.Entry, &status.FreeSlots, &status.UsedSlots);
|
||||||
|
DebugLogStatusSet(&status);
|
||||||
|
}
|
||||||
|
|
||||||
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
||||||
{
|
{
|
||||||
@ -77,26 +94,24 @@ static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
|||||||
|
|
||||||
static void ControlUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
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);
|
DebugLogControlGet(&control);
|
||||||
if (PIOS_DEBUGLOG_Read(entry, control.Flight, control.Entry) != 0) {
|
if (control.Operation == DEBUGLOGCONTROL_OPERATION_RETRIEVE) {
|
||||||
// reading from log failed, mark as non existent in output
|
|
||||||
memset(entry, 0, sizeof(DebugLogEntryData));
|
memset(entry, 0, sizeof(DebugLogEntryData));
|
||||||
entry->Flight = control.Flight;
|
if (PIOS_DEBUGLOG_Read(entry, control.Flight, control.Entry) != 0) {
|
||||||
entry->Entry = control.Entry;
|
// reading from log failed, mark as non existent in output
|
||||||
entry->Type = DEBUGLOGENTRY_TYPE_EMPTY;
|
entry->Flight = control.Flight;
|
||||||
|
entry->Entry = control.Entry;
|
||||||
|
entry->Type = DEBUGLOGENTRY_TYPE_EMPTY;
|
||||||
|
}
|
||||||
|
DebugLogEntrySet(entry);
|
||||||
|
} else if (control.Operation == DEBUGLOGCONTROL_OPERATION_FORMATFLASH) {
|
||||||
|
uint8_t armed;
|
||||||
|
FlightStatusArmedGet(&armed);
|
||||||
|
if (armed == FLIGHTSTATUS_ARMED_DISARMED) {
|
||||||
|
PIOS_DEBUGLOG_Format();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PIOS_DEBUGLOG_Info(&control.Flight, &control.Entry);
|
StatusUpdatedCb(ev);
|
||||||
|
|
||||||
ignore = 1; // set ignore flag before setting object - creates loop otherwise!!!
|
|
||||||
DebugLogEntrySet(entry);
|
|
||||||
DebugLogControlSet(&control);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,6 +120,7 @@ void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8
|
|||||||
size = sizeof(buffer->Data);
|
size = sizeof(buffer->Data);
|
||||||
}
|
}
|
||||||
buffer->Size = size;
|
buffer->Size = size;
|
||||||
|
memset(buffer->Data, 0, sizeof(buffer->Data));
|
||||||
memcpy(buffer->Data, data, size);
|
memcpy(buffer->Data, data, size);
|
||||||
|
|
||||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||||
@ -141,6 +142,7 @@ void PIOS_DEBUGLOG_Printf(char *format, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
mutexlock();
|
mutexlock();
|
||||||
|
memset(buffer->Data, 0, sizeof(buffer->Data));
|
||||||
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
||||||
buffer->Flight = flightnum;
|
buffer->Flight = flightnum;
|
||||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||||
@ -183,8 +185,10 @@ int32_t PIOS_DEBUGLOG_Read(void *mybuffer, uint16_t flight, uint16_t inst)
|
|||||||
* @brief Retrieve run time info of logging system
|
* @brief Retrieve run time info of logging system
|
||||||
* @param[out] current flight number
|
* @param[out] current flight number
|
||||||
* @param[out] next entry number
|
* @param[out] next entry number
|
||||||
|
* @param[out] free slots in filesystem
|
||||||
|
* @param[out] used slots in filesystem
|
||||||
*/
|
*/
|
||||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry, uint16_t *free, uint16_t *used)
|
||||||
{
|
{
|
||||||
if (flight) {
|
if (flight) {
|
||||||
*flight = flightnum;
|
*flight = flightnum;
|
||||||
@ -192,8 +196,27 @@ void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
*entry = lognum;
|
*entry = lognum;
|
||||||
}
|
}
|
||||||
|
struct PIOS_FLASHFS_Stats stats = { 0, 0 };
|
||||||
|
PIOS_FLASHFS_GetStats(pios_user_fs_id, &stats);
|
||||||
|
if (free) {
|
||||||
|
*free = stats.num_free_slots;
|
||||||
|
}
|
||||||
|
if (used) {
|
||||||
|
*used = stats.num_active_slots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Format entire flash memory!!!
|
||||||
|
*/
|
||||||
|
void PIOS_DEBUGLOG_Format(void)
|
||||||
|
{
|
||||||
|
mutexlock();
|
||||||
|
PIOS_FLASHFS_Format(pios_user_fs_id);
|
||||||
|
lognum = 0;
|
||||||
|
flightnum = 0;
|
||||||
|
mutexunlock();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
@ -77,10 +77,17 @@ int32_t PIOS_DEBUGLOG_Read(void *buffer, uint16_t flight, uint16_t inst);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve run time info of logging system
|
* @brief Retrieve run time info of logging system
|
||||||
* @param[out] buffer where to store the uavobject
|
* @param[out] current flight number
|
||||||
* @param[in] log entry from which flight
|
* @param[out] next entry number
|
||||||
|
* @param[out] free slots in filesystem
|
||||||
|
* @param[out] used slots in filesystem
|
||||||
*/
|
*/
|
||||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry);
|
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry, uint16_t *free, uint16_t *used);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Format entire flash memory!!!
|
||||||
|
*/
|
||||||
|
void PIOS_DEBUGLOG_Format(void);
|
||||||
|
|
||||||
#endif // ifndef PIOS_DEBUGLOG_H
|
#endif // ifndef PIOS_DEBUGLOG_H
|
||||||
|
|
||||||
|
@ -120,6 +120,7 @@ void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8
|
|||||||
size = sizeof(buffer->Data);
|
size = sizeof(buffer->Data);
|
||||||
}
|
}
|
||||||
buffer->Size = size;
|
buffer->Size = size;
|
||||||
|
memset(buffer->Data, 0, sizeof(buffer->Data));
|
||||||
memcpy(buffer->Data, data, size);
|
memcpy(buffer->Data, data, size);
|
||||||
|
|
||||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||||
@ -141,6 +142,7 @@ void PIOS_DEBUGLOG_Printf(char *format, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
mutexlock();
|
mutexlock();
|
||||||
|
memset(buffer->Data, 0, sizeof(buffer->Data));
|
||||||
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
||||||
buffer->Flight = flightnum;
|
buffer->Flight = flightnum;
|
||||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||||
@ -183,8 +185,10 @@ int32_t PIOS_DEBUGLOG_Read(void *mybuffer, uint16_t flight, uint16_t inst)
|
|||||||
* @brief Retrieve run time info of logging system
|
* @brief Retrieve run time info of logging system
|
||||||
* @param[out] current flight number
|
* @param[out] current flight number
|
||||||
* @param[out] next entry number
|
* @param[out] next entry number
|
||||||
|
* @param[out] free slots in filesystem
|
||||||
|
* @param[out] used slots in filesystem
|
||||||
*/
|
*/
|
||||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry, uint16_t *free, uint16_t *used)
|
||||||
{
|
{
|
||||||
if (flight) {
|
if (flight) {
|
||||||
*flight = flightnum;
|
*flight = flightnum;
|
||||||
@ -192,8 +196,27 @@ void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
*entry = lognum;
|
*entry = lognum;
|
||||||
}
|
}
|
||||||
|
struct PIOS_FLASHFS_Stats stats = { 0, 0 };
|
||||||
|
PIOS_FLASHFS_GetStats(pios_user_fs_id, &stats);
|
||||||
|
if (free) {
|
||||||
|
*free = stats.num_free_slots;
|
||||||
|
}
|
||||||
|
if (used) {
|
||||||
|
*used = stats.num_active_slots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Format entire flash memory!!!
|
||||||
|
*/
|
||||||
|
void PIOS_DEBUGLOG_Format(void)
|
||||||
|
{
|
||||||
|
mutexlock();
|
||||||
|
PIOS_FLASHFS_Format(pios_user_fs_id);
|
||||||
|
lognum = 0;
|
||||||
|
flightnum = 0;
|
||||||
|
mutexunlock();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
@ -38,6 +38,7 @@ UAVOBJSRCFILENAMES += airspeedsettings
|
|||||||
UAVOBJSRCFILENAMES += airspeedstate
|
UAVOBJSRCFILENAMES += airspeedstate
|
||||||
UAVOBJSRCFILENAMES += debuglogsettings
|
UAVOBJSRCFILENAMES += debuglogsettings
|
||||||
UAVOBJSRCFILENAMES += debuglogcontrol
|
UAVOBJSRCFILENAMES += debuglogcontrol
|
||||||
|
UAVOBJSRCFILENAMES += debuglogstatus
|
||||||
UAVOBJSRCFILENAMES += debuglogentry
|
UAVOBJSRCFILENAMES += debuglogentry
|
||||||
UAVOBJSRCFILENAMES += flightbatterysettings
|
UAVOBJSRCFILENAMES += flightbatterysettings
|
||||||
UAVOBJSRCFILENAMES += firmwareiapobj
|
UAVOBJSRCFILENAMES += firmwareiapobj
|
||||||
|
@ -44,6 +44,7 @@ UAVOBJSRCFILENAMES += airspeedsettings
|
|||||||
UAVOBJSRCFILENAMES += airspeedstate
|
UAVOBJSRCFILENAMES += airspeedstate
|
||||||
UAVOBJSRCFILENAMES += debuglogsettings
|
UAVOBJSRCFILENAMES += debuglogsettings
|
||||||
UAVOBJSRCFILENAMES += debuglogcontrol
|
UAVOBJSRCFILENAMES += debuglogcontrol
|
||||||
|
UAVOBJSRCFILENAMES += debuglogstatus
|
||||||
UAVOBJSRCFILENAMES += debuglogentry
|
UAVOBJSRCFILENAMES += debuglogentry
|
||||||
UAVOBJSRCFILENAMES += flightbatterysettings
|
UAVOBJSRCFILENAMES += flightbatterysettings
|
||||||
UAVOBJSRCFILENAMES += firmwareiapobj
|
UAVOBJSRCFILENAMES += firmwareiapobj
|
||||||
|
@ -36,6 +36,7 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \
|
|||||||
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.h \
|
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.h \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogsettings.h \
|
$$UAVOBJECT_SYNTHETICS/debuglogsettings.h \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.h \
|
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.h \
|
||||||
|
$$UAVOBJECT_SYNTHETICS/debuglogstatus.h \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogentry.h \
|
$$UAVOBJECT_SYNTHETICS/debuglogentry.h \
|
||||||
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.h \
|
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.h \
|
||||||
$$UAVOBJECT_SYNTHETICS/ekfstatevariance.h \
|
$$UAVOBJECT_SYNTHETICS/ekfstatevariance.h \
|
||||||
@ -125,6 +126,7 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \
|
|||||||
$$UAVOBJECT_SYNTHETICS/altitudeholdsettings.cpp \
|
$$UAVOBJECT_SYNTHETICS/altitudeholdsettings.cpp \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogsettings.cpp \
|
$$UAVOBJECT_SYNTHETICS/debuglogsettings.cpp \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.cpp \
|
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.cpp \
|
||||||
|
$$UAVOBJECT_SYNTHETICS/debuglogstatus.cpp \
|
||||||
$$UAVOBJECT_SYNTHETICS/debuglogentry.cpp \
|
$$UAVOBJECT_SYNTHETICS/debuglogentry.cpp \
|
||||||
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.cpp \
|
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.cpp \
|
||||||
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.cpp \
|
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.cpp \
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<xml>
|
<xml>
|
||||||
<object name="DebugLogControl" singleinstance="true" settings="false" category="System">
|
<object name="DebugLogControl" singleinstance="true" settings="false" category="System">
|
||||||
<description>Log Control Object</description>
|
<description>Log Control Object</description>
|
||||||
|
<field name="Operation" units="" type="enum" elements="1" options="None, Retrieve, FormatFlash" />
|
||||||
<field name="Flight" units="" type="uint16" elements="1" />
|
<field name="Flight" units="" type="uint16" elements="1" />
|
||||||
<field name="Entry" units="" type="uint16" elements="1" />
|
<field name="Entry" units="" type="uint16" elements="1" />
|
||||||
<access gcs="readwrite" flight="readwrite"/>
|
<access gcs="readwrite" flight="readwrite"/>
|
||||||
|
13
shared/uavobjectdefinition/debuglogstatus.xml
Normal file
13
shared/uavobjectdefinition/debuglogstatus.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<xml>
|
||||||
|
<object name="DebugLogStatus" 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" />
|
||||||
|
<field name="UsedSlots" units="" type="uint16" elements="1" />
|
||||||
|
<field name="FreeSlots" units="" type="uint16" elements="1" />
|
||||||
|
<access gcs="readwrite" flight="readwrite"/>
|
||||||
|
<telemetrygcs acked="false" updatemode="manual" period="0"/>
|
||||||
|
<telemetryflight acked="false" updatemode="periodic" period="1000"/>
|
||||||
|
<logging updatemode="manual" period="0"/>
|
||||||
|
</object>
|
||||||
|
</xml>
|
Loading…
x
Reference in New Issue
Block a user