1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

more intelligent log interfacing, including flash formatting option

This commit is contained in:
Corvus Corax 2013-11-17 20:14:50 +01:00
parent 3d8625abaf
commit fcc479f5cb
9 changed files with 108 additions and 22 deletions

View File

@ -33,22 +33,28 @@
#include "openpilot.h"
#include "debuglogsettings.h"
#include "debuglogcontrol.h"
#include "debuglogstatus.h"
#include "debuglogentry.h"
#include "flightstatus.h"
// private variables
static DebugLogSettingsData settings;
static DebugLogControlData control;
static DebugLogStatusData status;
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);
static void StatusUpdatedCb(UAVObjEvent *ev);
int32_t LoggingInitialize(void)
{
DebugLogSettingsInitialize();
DebugLogControlInitialize();
DebugLogStatusInitialize();
DebugLogEntryInitialize();
FlightStatusInitialize();
PIOS_DEBUGLOG_Initialize();
entry = pvPortMalloc(sizeof(DebugLogEntryData));
if (!entry) {
@ -63,10 +69,21 @@ int32_t LoggingStart(void)
DebugLogSettingsConnectCallback(SettingsUpdatedCb);
DebugLogControlConnectCallback(ControlUpdatedCb);
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;
}
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)
{
@ -77,26 +94,24 @@ static void SettingsUpdatedCb(__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);
if (PIOS_DEBUGLOG_Read(entry, control.Flight, control.Entry) != 0) {
// reading from log failed, mark as non existent in output
if (control.Operation == DEBUGLOGCONTROL_OPERATION_RETRIEVE) {
memset(entry, 0, sizeof(DebugLogEntryData));
entry->Flight = control.Flight;
entry->Entry = control.Entry;
entry->Type = DEBUGLOGENTRY_TYPE_EMPTY;
if (PIOS_DEBUGLOG_Read(entry, control.Flight, control.Entry) != 0) {
// reading from log failed, mark as non existent in output
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);
ignore = 1; // set ignore flag before setting object - creates loop otherwise!!!
DebugLogEntrySet(entry);
DebugLogControlSet(&control);
StatusUpdatedCb(ev);
}

View File

@ -120,6 +120,7 @@ void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8
size = sizeof(buffer->Data);
}
buffer->Size = size;
memset(buffer->Data, 0, sizeof(buffer->Data));
memcpy(buffer->Data, data, size);
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_start(args, format);
mutexlock();
memset(buffer->Data, 0, sizeof(buffer->Data));
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
buffer->Flight = flightnum;
#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
* @param[out] current flight 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) {
*flight = flightnum;
@ -192,8 +196,27 @@ void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
if (entry) {
*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();
}
/**
* @}

View File

@ -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
* @param[out] buffer where to store the uavobject
* @param[in] log entry from which flight
* @param[out] current flight 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);
/**
* @brief Format entire flash memory!!!
*/
void PIOS_DEBUGLOG_Format(void);
#endif // ifndef PIOS_DEBUGLOG_H

View File

@ -120,6 +120,7 @@ void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8
size = sizeof(buffer->Data);
}
buffer->Size = size;
memset(buffer->Data, 0, sizeof(buffer->Data));
memcpy(buffer->Data, data, size);
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_start(args, format);
mutexlock();
memset(buffer->Data, 0, sizeof(buffer->Data));
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
buffer->Flight = flightnum;
#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
* @param[out] current flight 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) {
*flight = flightnum;
@ -192,8 +196,27 @@ void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
if (entry) {
*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();
}
/**
* @}

View File

@ -38,6 +38,7 @@ UAVOBJSRCFILENAMES += airspeedsettings
UAVOBJSRCFILENAMES += airspeedstate
UAVOBJSRCFILENAMES += debuglogsettings
UAVOBJSRCFILENAMES += debuglogcontrol
UAVOBJSRCFILENAMES += debuglogstatus
UAVOBJSRCFILENAMES += debuglogentry
UAVOBJSRCFILENAMES += flightbatterysettings
UAVOBJSRCFILENAMES += firmwareiapobj

View File

@ -44,6 +44,7 @@ UAVOBJSRCFILENAMES += airspeedsettings
UAVOBJSRCFILENAMES += airspeedstate
UAVOBJSRCFILENAMES += debuglogsettings
UAVOBJSRCFILENAMES += debuglogcontrol
UAVOBJSRCFILENAMES += debuglogstatus
UAVOBJSRCFILENAMES += debuglogentry
UAVOBJSRCFILENAMES += flightbatterysettings
UAVOBJSRCFILENAMES += firmwareiapobj

View File

@ -36,6 +36,7 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.h \
$$UAVOBJECT_SYNTHETICS/debuglogsettings.h \
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.h \
$$UAVOBJECT_SYNTHETICS/debuglogstatus.h \
$$UAVOBJECT_SYNTHETICS/debuglogentry.h \
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.h \
$$UAVOBJECT_SYNTHETICS/ekfstatevariance.h \
@ -125,6 +126,7 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \
$$UAVOBJECT_SYNTHETICS/altitudeholdsettings.cpp \
$$UAVOBJECT_SYNTHETICS/debuglogsettings.cpp \
$$UAVOBJECT_SYNTHETICS/debuglogcontrol.cpp \
$$UAVOBJECT_SYNTHETICS/debuglogstatus.cpp \
$$UAVOBJECT_SYNTHETICS/debuglogentry.cpp \
$$UAVOBJECT_SYNTHETICS/altitudefiltersettings.cpp \
$$UAVOBJECT_SYNTHETICS/ekfconfiguration.cpp \

View File

@ -1,6 +1,7 @@
<xml>
<object name="DebugLogControl" singleinstance="true" settings="false" category="System">
<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="Entry" units="" type="uint16" elements="1" />
<access gcs="readwrite" flight="readwrite"/>

View 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>