diff --git a/conf/airframes/ENAC/fixed-wing/apogee.xml b/conf/airframes/ENAC/fixed-wing/apogee.xml index be0f44ee21c..3ab7562012a 100644 --- a/conf/airframes/ENAC/fixed-wing/apogee.xml +++ b/conf/airframes/ENAC/fixed-wing/apogee.xml @@ -11,21 +11,22 @@ - + + - - - + + + diff --git a/conf/telemetry/fixedwing_flight_recorder.xml b/conf/telemetry/fixedwing_flight_recorder.xml new file mode 100644 index 00000000000..cd89f5dc681 --- /dev/null +++ b/conf/telemetry/fixedwing_flight_recorder.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sw/airborne/modules/loggers/flight_recorder.c b/sw/airborne/modules/loggers/flight_recorder.c new file mode 100644 index 00000000000..48c172239dd --- /dev/null +++ b/sw/airborne/modules/loggers/flight_recorder.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2015 Gautier Hattenberger + * + * This file is part of paparazzi + * + * paparazzi 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 2, or (at your option) + * any later version. + * + * paparazzi 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 paparazzi; see the file COPYING. If not, see + * . + */ +/** + * @file "modules/loggers/flight_recorder.c" + * @author Gautier Hattenberger + * Record flight data according to your telemetry file + */ + +#define PERIODIC_C_FLIGHTRECORDER + +#include "modules/loggers/flight_recorder.h" + +#include "subsystems/datalink/telemetry.h" +#include "subsystems/datalink/pprzlog_transport.h" + +#if FLIGHTRECORDER_SDLOG + +#include "sdLog.h" +#include "subsystems/chibios-libopencm3/chibios_sdlog.h" +static struct chibios_sdlog flightrecorder_sdlog; +#ifndef FLIGHTRECORDER_DEVICE +#define FLIGHTRECORDER_DEVICE flightrecorder_sdlog +#else +#warning "SD log is activated, but FLIGHTRECORDER_DEVICE is alreay set (should not be defined)" +#endif + +// Functions for the generic device API +static int sdlog_check_free_space(struct chibios_sdlog* p __attribute__((unused)), uint8_t len __attribute__((unused))) +{ + return TRUE; +} + +static void sdlog_transmit(struct chibios_sdlog* p __attribute__((unused)), uint8_t byte) +{ + sdLogWriteByte(&flightRecorderLogFile, byte); +} + +static void sdlog_send(struct chibios_sdlog* p __attribute__((unused))) { } + +#else +// include downlink for other devices +#include "subsystems/datalink/downlink.h" +#endif + +void flight_recorder_init() +{ +#if FLIGHTRECORDER_SDLOG + flightrecorder_sdlog.device.periph = (void *)(&flightrecorder_sdlog); + flightrecorder_sdlog.device.check_free_space = (check_free_space_t) sdlog_check_free_space; + flightrecorder_sdlog.device.transmit = (transmit_t) sdlog_transmit; + flightrecorder_sdlog.device.send_message = (send_message_t) sdlog_send; +#endif +} + +void flight_recorder_periodic() +{ +#if FLIGHTRECORDER_SDLOG + // test if sd log is ready + if (flightRecorderLogFile.fs == NULL) return; +#endif + +#if PERIODIC_TELEMETRY + periodic_telemetry_send_FlightRecorder(DefaultPeriodic, &pprzlog_tp.trans_tx, &(FLIGHTRECORDER_DEVICE).device); +#endif +} + + diff --git a/sw/airborne/modules/loggers/flight_recorder.h b/sw/airborne/modules/loggers/flight_recorder.h new file mode 100644 index 00000000000..844cf3aec25 --- /dev/null +++ b/sw/airborne/modules/loggers/flight_recorder.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2015 Gautier Hattenberger + * + * This file is part of paparazzi + * + * paparazzi 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 2, or (at your option) + * any later version. + * + * paparazzi 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 paparazzi; see the file COPYING. If not, see + * . + */ +/** + * @file "modules/loggers/flight_recorder.h" + * @author Gautier Hattenberger + * Record flight data according to your telemetry file + */ + +#ifndef FLIGHT_RECORDER_H +#define FLIGHT_RECORDER_H + +/** Init function + */ +extern void flight_recorder_init(void); + +/** Periodic function + * + * should be called at TELEMETRY_FREQUENCY + */ +extern void flight_recorder_periodic(void); + +#endif + diff --git a/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.c b/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.c index 4d1c5592e6a..1647f736d10 100644 --- a/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.c +++ b/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.c @@ -46,13 +46,14 @@ EventListener powerOutageListener; FIL pprzLogFile = {0}; -#if LOG_FLIGHTRECORDER +struct chibios_sdlog chibios_sdlog; + +#if FLIGHTRECORDER_SDLOG static const char FLIGHTRECORDER_LOG_NAME[] = "fr_"; +static const char FR_LOG_DIR[] = "FLIGHT_RECORDER"; FIL flightRecorderLogFile = {0}; #endif -struct chibios_sdlog chibios_sdlog; - static WORKING_AREA(waThdBatterySurvey, 4096); static void launchBatterySurveyThread (void) { @@ -96,8 +97,8 @@ bool_t chibios_logInit(const bool_t binaryFile) if (sdLogOpenLog (&pprzLogFile, PPRZ_LOG_DIR, PPRZ_LOG_NAME) != SDLOG_OK) goto error; -#if LOG_FLIGHTRECORDER - if (sdLogOpenLog (&flightRecorderLogFile, FLIGHTRECORDER_LOG_NAME) != SDLOG_OK) +#if FLIGHTRECORDER_SDLOG + if (sdLogOpenLog (&flightRecorderLogFile, FR_LOG_DIR, FLIGHTRECORDER_LOG_NAME) != SDLOG_OK) goto error; #endif @@ -120,7 +121,7 @@ void chibios_logFinish(void) if (pprzLogFile.fs != NULL) { sdLogStopThread (); sdLogCloseLog (&pprzLogFile); -#if LOG_FLIGHTRECORDER +#if FLIGHTRECORDER_SDLOG sdLogCloseLog (&flightRecorderLogFile); #endif sdLogFinish (); diff --git a/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.h b/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.h index c128fa727be..dcf6f5e8ef1 100644 --- a/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.h +++ b/sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.h @@ -40,7 +40,7 @@ extern FIL pprzLogFile; -#if LOG_FLIGHTRECORDER +#if FLIGHTRECORDER_SDLOG // if activated, will log all process states extern FIL flightRecorderLogFile; #endif diff --git a/sw/airborne/subsystems/chibios-libopencm3/ffconf.h b/sw/airborne/subsystems/chibios-libopencm3/ffconf.h index df32e77b783..5edef24c8ce 100644 --- a/sw/airborne/subsystems/chibios-libopencm3/ffconf.h +++ b/sw/airborne/subsystems/chibios-libopencm3/ffconf.h @@ -185,7 +185,12 @@ / function must be added to the project. */ -#define _FS_SHARE 2 /* 0:Disable or >=1:Enable */ +/* 0:Disable or >=1:Enable */ +#if FLIGHTRECORDER_SDLOG +#define _FS_SHARE 2 // Open a second file if flight recorder is used +#else +#define _FS_SHARE 0 +#endif /* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value defines how many files can be opened simultaneously. */