2013-11-17 02:54:26 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @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"
|
2013-11-17 20:14:50 +01:00
|
|
|
#include "debuglogstatus.h"
|
2013-11-17 02:54:26 +01:00
|
|
|
#include "debuglogentry.h"
|
2013-11-17 20:14:50 +01:00
|
|
|
#include "flightstatus.h"
|
2013-11-17 02:54:26 +01:00
|
|
|
|
|
|
|
// private variables
|
|
|
|
static DebugLogSettingsData settings;
|
|
|
|
static DebugLogControlData control;
|
2013-11-17 20:14:50 +01:00
|
|
|
static DebugLogStatusData status;
|
2013-11-19 19:29:24 +01:00
|
|
|
static FlightStatusData flightstatus;
|
2013-11-17 02:54:26 +01:00
|
|
|
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);
|
2013-11-17 20:14:50 +01:00
|
|
|
static void StatusUpdatedCb(UAVObjEvent *ev);
|
2013-11-19 19:29:24 +01:00
|
|
|
static void FlightStatusUpdatedCb(UAVObjEvent *ev);
|
2013-11-17 02:54:26 +01:00
|
|
|
|
|
|
|
int32_t LoggingInitialize(void)
|
|
|
|
{
|
|
|
|
DebugLogSettingsInitialize();
|
|
|
|
DebugLogControlInitialize();
|
2013-11-17 20:14:50 +01:00
|
|
|
DebugLogStatusInitialize();
|
2013-11-17 02:54:26 +01:00
|
|
|
DebugLogEntryInitialize();
|
2013-11-17 20:14:50 +01:00
|
|
|
FlightStatusInitialize();
|
2013-11-17 02:54:26 +01:00
|
|
|
PIOS_DEBUGLOG_Initialize();
|
|
|
|
entry = pvPortMalloc(sizeof(DebugLogEntryData));
|
|
|
|
if (!entry) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t LoggingStart(void)
|
|
|
|
{
|
|
|
|
DebugLogSettingsConnectCallback(SettingsUpdatedCb);
|
|
|
|
DebugLogControlConnectCallback(ControlUpdatedCb);
|
2013-11-19 19:29:24 +01:00
|
|
|
FlightStatusConnectCallback(FlightStatusUpdatedCb);
|
2013-11-17 02:54:26 +01:00
|
|
|
SettingsUpdatedCb(DebugLogSettingsHandle());
|
2013-11-17 20:14:50 +01:00
|
|
|
|
2014-02-18 01:04:43 +01:00
|
|
|
UAVObjEvent ev = {
|
2014-03-09 16:43:31 +01:00
|
|
|
.obj = DebugLogSettingsHandle(),
|
|
|
|
.instId = 0,
|
|
|
|
.event = EV_UPDATED_PERIODIC,
|
|
|
|
.lowPriority = true,
|
|
|
|
};
|
2013-11-17 20:14:50 +01:00
|
|
|
EventPeriodicCallbackCreate(&ev, StatusUpdatedCb, 1000);
|
|
|
|
// invoke a periodic dispatcher callback - the event struct is a dummy, it could be filled with anything!
|
|
|
|
StatusUpdatedCb(&ev);
|
|
|
|
|
2013-11-17 02:54:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MODULE_INITCALL(LoggingInitialize, LoggingStart);
|
|
|
|
|
2013-11-17 20:14:50 +01:00
|
|
|
static void StatusUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
|
|
|
{
|
|
|
|
PIOS_DEBUGLOG_Info(&status.Flight, &status.Entry, &status.FreeSlots, &status.UsedSlots);
|
|
|
|
DebugLogStatusSet(&status);
|
|
|
|
}
|
2013-11-17 02:54:26 +01:00
|
|
|
|
2013-11-19 19:29:24 +01:00
|
|
|
static void FlightStatusUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
|
|
|
{
|
|
|
|
FlightStatusGet(&flightstatus);
|
2013-12-01 00:03:24 +01:00
|
|
|
if (settings.LoggingEnabled == DEBUGLOGSETTINGS_LOGGINGENABLED_ONLYWHENARMED) {
|
|
|
|
if (flightstatus.Armed != FLIGHTSTATUS_ARMED_ARMED) {
|
|
|
|
PIOS_DEBUGLOG_Printf("FlightStatus Disarmed: On board Logging disabled.");
|
|
|
|
PIOS_DEBUGLOG_Enable(0);
|
|
|
|
} else {
|
|
|
|
PIOS_DEBUGLOG_Enable(1);
|
|
|
|
PIOS_DEBUGLOG_Printf("FlightStatus Armed: On board logging enabled.");
|
|
|
|
}
|
2013-11-19 19:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-17 02:54:26 +01:00
|
|
|
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
|
|
|
{
|
|
|
|
DebugLogSettingsGet(&settings);
|
2013-12-01 00:03:24 +01:00
|
|
|
if (settings.LoggingEnabled == DEBUGLOGSETTINGS_LOGGINGENABLED_ALWAYS) {
|
|
|
|
PIOS_DEBUGLOG_Enable(1);
|
|
|
|
PIOS_DEBUGLOG_Printf("On board logging enabled.");
|
|
|
|
} else if (settings.LoggingEnabled == DEBUGLOGSETTINGS_LOGGINGENABLED_DISABLED) {
|
|
|
|
PIOS_DEBUGLOG_Printf("On board logging disabled.");
|
|
|
|
PIOS_DEBUGLOG_Enable(0);
|
|
|
|
} else {
|
|
|
|
FlightStatusUpdatedCb(NULL);
|
|
|
|
}
|
2013-11-17 02:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ControlUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
|
|
|
|
{
|
|
|
|
DebugLogControlGet(&control);
|
2013-11-17 20:14:50 +01:00
|
|
|
if (control.Operation == DEBUGLOGCONTROL_OPERATION_RETRIEVE) {
|
2013-11-17 02:54:26 +01:00
|
|
|
memset(entry, 0, sizeof(DebugLogEntryData));
|
2013-11-17 20:14:50 +01:00
|
|
|
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();
|
|
|
|
}
|
2013-11-17 02:54:26 +01:00
|
|
|
}
|
2013-11-17 20:14:50 +01:00
|
|
|
StatusUpdatedCb(ev);
|
2013-11-17 02:54:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|