Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
sdlog_linux.c File Reference

SD logger for Linux based autopilots (Bebop, ...) and NPS. More...

#include "modules/loggers/sdlog_chibios.h"
#include "modules/loggers/sdlog_chibios/usbStorage.h"
#include "mcu_periph/sys_time.h"
#include "generated/airframe.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "modules/datalink/telemetry.h"
Include dependency graph for sdlog_linux.c:

Go to the source code of this file.

Data Structures

struct  sdlog_msg
 Message under construction, one per thread so threads can't mix messages (the fd argument of the device functions is only used with PPRZLINK_ENABLE_FD). More...

Macros

#define SDLOG_DIR   "/data/ftp/internal_000/sdlog"
 Directory where the logs are stored, the default in simulation is $PAPARAZZI_HOME/var/logs/sdlog/<AIRCRAFT>.
#define SDLOG_AUTO_FLUSH_PERIOD   10
 Flush period in seconds.
#define SDLOG_MAX_FILES   4
#define SDLOG_MAX_MSG_LEN   512
#define SDLOG_CONF   TRUE
 Write the configuration of the firmware next to the logs (PPRZ/<md5>_<aircraft>.conf.gz), so sd2log can decode them without the var/conf of the computer that built the firmware.

Enumerations

enum  { SDLOG_STOPPED = 0 , SDLOG_RUNNING , SDLOG_ERROR }

Functions

void usbStorage_enable_usb_storage (float e)
static FILE * sdlog_file (FileDes fd)
static SdioError sdlog_errno_error (int err)
 Error of a failed write or close: only a full disk is "SD card full".
static void sdlog_write (FileDes fd, const uint8_t *data, size_t len)
SdioError sdLogWriteLog (const FileDes fd, const char *fmt,...)
SdioError sdLogWriteRaw (const FileDes fd, const uint8_t *buffer, const size_t len)
SdioError sdLogWriteByte (const FileDes fd, const uint8_t value)
SdioError sdLogFlushLog (const FileDes fd)
SdioError sdLogFlushAllLogs (void)
size_t sdLogGetNbBytesWrittenToStorage (void)
SdioError sdLogGetStorageStatus (void)
static int sdlog_check_free_space (struct chibios_sdlog *p, long *fd, uint16_t len)
static void sdlog_put_buffer (struct chibios_sdlog *p, long fd, const uint8_t *data, uint16_t len)
static void sdlog_put_byte (struct chibios_sdlog *p, long fd, uint8_t byte)
static void sdlog_send (struct chibios_sdlog *p, long fd)
static int null_function (struct chibios_sdlog *p)
static uint8_t null_byte_function (struct chibios_sdlog *p)
void chibios_sdlog_init (struct chibios_sdlog *sdlog, FileDes *file)
 init chibios_sdlog structure
static int sdlog_mkdir (const char *path)
 Create a directory and its parents.
static int sdlog_next_number (const char *dir, const char *prefix)
 Remove the empty logs and get the next free log number.
static FileDes sdlog_open (const char *base, const char *dir, const char *prefix, char *name, size_t name_len)
 Open the next log file in base/dir, returns the descriptor or -1.
static void sdlog_report_status (struct transport_tx *trans, struct link_device *dev)
 Tell the GCS in words why the logger does not run (no SD card, card full, ...): at the start and every time it goes into error later, and when the configuration could not be written.
static void send_sdlog_status (struct transport_tx *trans, struct link_device *dev)
static void sdlog_atexit (void)
void sdlog_chibios_init (void)
void sdlog_chibios_finish (const bool flush)
void logger_log_msg_up (uint8_t *buf)

Variables

static const char PPRZ_LOG_NAME [] = "pprzlog_"
static const char PPRZ_LOG_DIR [] = "PPRZ"
static SdioError sdlog_conf_error = SDLOG_OK
 Result of writing the configuration, reported to the GCS.
FileDes pprzLogFile = -1
struct chibios_sdlog chibios_sdlog
float usb_storage_status = 0
 Not available on Linux, only there for the settings.
static FILE * sdlog_files [SDLOG_MAX_FILES]
static size_t sdlog_bytes = 0
static float sdlog_last_flush = 0
static enum { ... }  sdlog_status = SDLOG_STOPPED
static SdioError sdlog_error = SDLOG_OK
static char sdlog_filenames [68]
static __thread struct sdlog_msg sdlog_msg

Detailed Description

SD logger for Linux based autopilots (Bebop, ...) and NPS.

Same interface and file layout as the ChibiOS SD logger, so the same modules (flight recorder, high speed IMU logging, ...) can log, and the files can be converted with sd2log: <SDLOG_DIR>/PPRZ/pprzlog_0001.LOG <SDLOG_DIR>/FLIGHT_RECORDER/fr_0001.LOG

Definition in file sdlog_linux.c.


Data Structure Documentation

◆ sdlog_msg

struct sdlog_msg

Message under construction, one per thread so threads can't mix messages (the fd argument of the device functions is only used with PPRZLINK_ENABLE_FD).

Definition at line 107 of file sdlog_linux.c.

Data Fields
uint8_t buf[SDLOG_MAX_MSG_LEN]
uint16_t len

Macro Definition Documentation

◆ SDLOG_AUTO_FLUSH_PERIOD

#define SDLOG_AUTO_FLUSH_PERIOD   10

Flush period in seconds.

Definition at line 61 of file sdlog_linux.c.

◆ SDLOG_CONF

#define SDLOG_CONF   TRUE

Write the configuration of the firmware next to the logs (PPRZ/<md5>_<aircraft>.conf.gz), so sd2log can decode them without the var/conf of the computer that built the firmware.

Definition at line 74 of file sdlog_linux.c.

◆ SDLOG_DIR

#define SDLOG_DIR   "/data/ftp/internal_000/sdlog"

Directory where the logs are stored, the default in simulation is $PAPARAZZI_HOME/var/logs/sdlog/<AIRCRAFT>.

Definition at line 52 of file sdlog_linux.c.

Referenced by sdlog_chibios_init().

◆ SDLOG_MAX_FILES

#define SDLOG_MAX_FILES   4

Definition at line 65 of file sdlog_linux.c.

Referenced by sdlog_chibios_finish(), sdlog_file(), sdlog_open(), and sdLogFlushAllLogs().

◆ SDLOG_MAX_MSG_LEN

#define SDLOG_MAX_MSG_LEN   512

Definition at line 66 of file sdlog_linux.c.

Referenced by sdlog_check_free_space(), sdlog_put_buffer(), and sdLogWriteLog().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SDLOG_STOPPED 
SDLOG_RUNNING 
SDLOG_ERROR 

Definition at line 97 of file sdlog_linux.c.

Function Documentation

◆ chibios_sdlog_init()

void chibios_sdlog_init ( struct chibios_sdlog * sdlog,
FileDes * file )

init chibios_sdlog structure

Definition at line 245 of file sdlog_linux.c.

References chibios_sdlog::device, chibios_sdlog::file, null_byte_function(), null_function(), sdlog_check_free_space(), sdlog_put_buffer(), sdlog_put_byte(), and sdlog_send().

Referenced by sdlog_chibios_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logger_log_msg_up()

void logger_log_msg_up ( uint8_t * buf)

Definition at line 520 of file sdlog_linux.c.

References DEST_INFO_MSG_ALL, DEST_INFO_MSG_PPRZLOG, fd, msg, pprzLogFile, sdLogWriteByte(), and sdLogWriteRaw().

Here is the call graph for this function:

◆ null_byte_function()

uint8_t null_byte_function ( struct chibios_sdlog * p)
static

Definition at line 243 of file sdlog_linux.c.

References p.

◆ null_function()

int null_function ( struct chibios_sdlog * p)
static

Definition at line 242 of file sdlog_linux.c.

References p.

◆ sdlog_atexit()

void sdlog_atexit ( void )
static

Definition at line 450 of file sdlog_linux.c.

References sdlog_chibios_finish().

Referenced by sdlog_chibios_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdlog_check_free_space()

int sdlog_check_free_space ( struct chibios_sdlog * p,
long * fd,
uint16_t len )
static

Definition at line 212 of file sdlog_linux.c.

References fd, sdlog_msg::len, p, sdlog_file(), and SDLOG_MAX_MSG_LEN.

Here is the call graph for this function:

◆ sdlog_chibios_finish()

void sdlog_chibios_finish ( const bool flush)

Definition at line 502 of file sdlog_linux.c.

References pprzLogFile, sdlog_files, SDLOG_MAX_FILES, sdlog_status, and SDLOG_STOPPED.

Referenced by sdlog_atexit().

Here is the caller graph for this function:

◆ sdlog_chibios_init()

◆ sdlog_errno_error()

SdioError sdlog_errno_error ( int err)
static

Error of a failed write or close: only a full disk is "SD card full".

Definition at line 122 of file sdlog_linux.c.

References SDLOG_FATFS_ERROR, and SDLOG_FSFULL.

Referenced by sdlog_write().

Here is the caller graph for this function:

◆ sdlog_file()

FILE * sdlog_file ( FileDes fd)
static

Definition at line 113 of file sdlog_linux.c.

References fd, sdlog_files, and SDLOG_MAX_FILES.

Referenced by sdlog_check_free_space(), sdlog_write(), and sdLogFlushLog().

Here is the caller graph for this function:

◆ sdlog_mkdir()

int sdlog_mkdir ( const char * path)
static

Create a directory and its parents.

Definition at line 260 of file sdlog_linux.c.

Referenced by sdlog_open().

Here is the caller graph for this function:

◆ sdlog_next_number()

int sdlog_next_number ( const char * dir,
const char * prefix )
static

Remove the empty logs and get the next free log number.

Definition at line 280 of file sdlog_linux.c.

References dir.

Referenced by sdlog_open().

Here is the caller graph for this function:

◆ sdlog_open()

FileDes sdlog_open ( const char * base,
const char * dir,
const char * prefix,
char * name,
size_t name_len )
static

Open the next log file in base/dir, returns the descriptor or -1.

Definition at line 310 of file sdlog_linux.c.

References dir, fd, sdlog_error, SDLOG_FATFS_ERROR, SDLOG_FDFULL, sdlog_files, SDLOG_LOGNUM_ERROR, SDLOG_MAX_FILES, sdlog_mkdir(), sdlog_next_number(), and SDLOG_NOCARD.

Referenced by sdlog_chibios_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdlog_put_buffer()

void sdlog_put_buffer ( struct chibios_sdlog * p,
long fd,
const uint8_t * data,
uint16_t len )
static

Definition at line 221 of file sdlog_linux.c.

References sdlog_msg::buf, fd, sdlog_msg::len, p, and SDLOG_MAX_MSG_LEN.

Referenced by chibios_sdlog_init(), and sdlog_put_byte().

Here is the caller graph for this function:

◆ sdlog_put_byte()

void sdlog_put_byte ( struct chibios_sdlog * p,
long fd,
uint8_t byte )
static

Definition at line 231 of file sdlog_linux.c.

References fd, p, and sdlog_put_buffer().

Referenced by chibios_sdlog_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdlog_report_status()

void sdlog_report_status ( struct transport_tx * trans,
struct link_device * dev )
static

Tell the GCS in words why the logger does not run (no SD card, card full, ...): at the start and every time it goes into error later, and when the configuration could not be written.

A normal start is not reported. Sent with the LOGGER_STATUS message, from the main thread.

Definition at line 411 of file sdlog_linux.c.

References dev, Min, msg, sdlog_conf_error, SDLOG_ERROR, sdlog_error, sdlog_error_string(), SDLOG_OK, SDLOG_RUNNING, sdlog_status, SDLOG_STOPPED, and status.

Referenced by send_sdlog_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdlog_send()

void sdlog_send ( struct chibios_sdlog * p,
long fd )
static

Definition at line 236 of file sdlog_linux.c.

References sdlog_msg::buf, fd, sdlog_msg::len, p, and sdlog_write().

Here is the call graph for this function:

◆ sdlog_write()

void sdlog_write ( FileDes fd,
const uint8_t * data,
size_t len )
static

Definition at line 132 of file sdlog_linux.c.

References f, fd, get_sys_time_float(), sdlog_msg::len, SDLOG_AUTO_FLUSH_PERIOD, sdlog_bytes, sdlog_errno_error(), SDLOG_ERROR, sdlog_error, sdlog_file(), sdlog_last_flush, sdlog_status, and sdLogFlushAllLogs().

Referenced by sdlog_send(), sdLogWriteByte(), sdLogWriteLog(), and sdLogWriteRaw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdLogFlushAllLogs()

SdioError sdLogFlushAllLogs ( void )

Definition at line 191 of file sdlog_linux.c.

References sdlog_error, sdlog_files, and SDLOG_MAX_FILES.

Referenced by sdlog_write().

Here is the caller graph for this function:

◆ sdLogFlushLog()

SdioError sdLogFlushLog ( const FileDes fd)

Definition at line 182 of file sdlog_linux.c.

References f, fd, sdlog_error, and sdlog_file().

Here is the call graph for this function:

◆ sdLogGetNbBytesWrittenToStorage()

size_t sdLogGetNbBytesWrittenToStorage ( void )

Definition at line 201 of file sdlog_linux.c.

References sdlog_bytes.

Referenced by send_sdlog_status().

Here is the caller graph for this function:

◆ sdLogGetStorageStatus()

SdioError sdLogGetStorageStatus ( void )

Definition at line 206 of file sdlog_linux.c.

References sdlog_error.

Referenced by send_sdlog_status(), and thd_startlog().

Here is the caller graph for this function:

◆ sdLogWriteByte()

SdioError sdLogWriteByte ( const FileDes fd,
const uint8_t value )

Definition at line 176 of file sdlog_linux.c.

References fd, sdlog_error, and sdlog_write().

Referenced by gps_ubx_parse(), and logger_log_msg_up().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdLogWriteLog()

SdioError sdLogWriteLog ( const FileDes fd,
const char * fmt,
... )

◆ sdLogWriteRaw()

SdioError sdLogWriteRaw ( const FileDes fd,
const uint8_t * buffer,
const size_t len )

Definition at line 170 of file sdlog_linux.c.

References fd, sdlog_msg::len, sdlog_error, and sdlog_write().

Referenced by logger_log_msg_up().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_sdlog_status()

void send_sdlog_status ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 436 of file sdlog_linux.c.

References dev, sdlog_bytes, sdlog_error, sdlog_filenames, sdlog_report_status(), sdlog_status, and status.

Here is the call graph for this function:

◆ usbStorage_enable_usb_storage()

void usbStorage_enable_usb_storage ( float e)

Definition at line 92 of file sdlog_linux.c.

References usb_storage_status.

Variable Documentation

◆ chibios_sdlog

struct chibios_sdlog chibios_sdlog

Definition at line 88 of file sdlog_linux.c.

◆ PPRZ_LOG_DIR

const char PPRZ_LOG_DIR[] = "PPRZ"
static

Definition at line 69 of file sdlog_linux.c.

◆ PPRZ_LOG_NAME

const char PPRZ_LOG_NAME[] = "pprzlog_"
static

Definition at line 68 of file sdlog_linux.c.

◆ pprzLogFile

FileDes pprzLogFile = -1

Definition at line 87 of file sdlog_linux.c.

◆ sdlog_bytes

size_t sdlog_bytes = 0
static

Definition at line 95 of file sdlog_linux.c.

Referenced by sdlog_write(), sdLogGetNbBytesWrittenToStorage(), and send_sdlog_status().

◆ sdlog_conf_error

SdioError sdlog_conf_error = SDLOG_OK
static

Result of writing the configuration, reported to the GCS.

Definition at line 80 of file sdlog_linux.c.

◆ sdlog_error

◆ sdlog_filenames

char sdlog_filenames[68]
static

Definition at line 103 of file sdlog_linux.c.

Referenced by sdlog_chibios_init(), and send_sdlog_status().

◆ sdlog_files

FILE* sdlog_files[SDLOG_MAX_FILES]
static

Definition at line 94 of file sdlog_linux.c.

Referenced by sdlog_chibios_finish(), sdlog_file(), sdlog_open(), and sdLogFlushAllLogs().

◆ sdlog_last_flush

float sdlog_last_flush = 0
static

Definition at line 96 of file sdlog_linux.c.

Referenced by sdlog_chibios_init(), and sdlog_write().

◆ sdlog_msg

__thread struct sdlog_msg sdlog_msg
static

Definition at line 111 of file sdlog_linux.c.

◆ []

◆ usb_storage_status

float usb_storage_status = 0

Not available on Linux, only there for the settings.

Definition at line 91 of file sdlog_linux.c.