diff --git a/flight/modules/Logging/Logging.c b/flight/modules/Logging/Logging.c index 3abb76477..3cf7d2a78 100644 --- a/flight/modules/Logging/Logging.c +++ b/flight/modules/Logging/Logging.c @@ -41,12 +41,14 @@ static DebugLogSettingsData settings; static DebugLogControlData control; static DebugLogStatusData status; +static FlightStatusData flightstatus; 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); +static void FlightStatusUpdatedCb(UAVObjEvent *ev); int32_t LoggingInitialize(void) { @@ -68,6 +70,7 @@ int32_t LoggingStart(void) { DebugLogSettingsConnectCallback(SettingsUpdatedCb); DebugLogControlConnectCallback(ControlUpdatedCb); + FlightStatusConnectCallback(FlightStatusUpdatedCb); SettingsUpdatedCb(DebugLogSettingsHandle()); UAVObjEvent ev = { .obj = DebugLogSettingsHandle(), .instId = 0, .event = EV_UPDATED_PERIODIC }; @@ -85,11 +88,26 @@ static void StatusUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) DebugLogStatusSet(&status); } +static void FlightStatusUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) +{ + FlightStatusGet(&flightstatus); + switch (settings.LoggingEnabled) { + case DEBUGLOGSETTINGS_LOGGINGENABLED_ALWAYS: + PIOS_DEBUGLOG_Enable(1); + break; + case DEBUGLOGSETTINGS_LOGGINGENABLED_ONLYWHENARMED: + PIOS_DEBUGLOG_Enable(flightstatus.Armed == FLIGHTSTATUS_ARMED_ARMED); + break; + default: + PIOS_DEBUGLOG_Enable(0); + } +} + static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { DebugLogSettingsGet(&settings); - PIOS_DEBUGLOG_Enable(settings.LoggingEnabled); - PIOS_DEBUGLOG_Printf("Logging enabled"); + FlightStatusUpdatedCb(NULL); + PIOS_DEBUGLOG_Printf("On board logging enabled."); } static void ControlUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) diff --git a/shared/uavobjectdefinition/debuglogsettings.xml b/shared/uavobjectdefinition/debuglogsettings.xml index 05587dedc..cb5fef6ed 100644 --- a/shared/uavobjectdefinition/debuglogsettings.xml +++ b/shared/uavobjectdefinition/debuglogsettings.xml @@ -1,7 +1,7 @@ Configure On Board Logging Facilities - +