Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sdLog.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2016 Gautier Hattenberger, Alexandre Bustico
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 /*
23  * @file modules/loggers/sdlog_chibios/sdLog.h
24  * @brief sdlog API using ChibiOS and Fatfs
25  *
26  */
27 
28 #pragma once
29 #include "std.h"
30 #include "mcuconf.h"
31 
32 //#include "ff.h"
33 #include <stdarg.h>
34 
35 #define NUMBERLEN 4
36 #define NUMBERMAX 9999
37 #define NUMBERFMF "%s\\%s%.04d.LOG"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  This module is highly coupled with fatfs, and mcuconf.h
45  several MACRO should be defined before use
46 
47  FATFS (ffconf.h) :
48  ° _FS_LOCK : number of simultaneously open file
49  ° _FS_REENTRANT : If you need to open / close file during log, this should be set to 1 at
50  the expense of more used cam and cpu.
51  If you open all files prior to log data on them, it should be left to 0
52 
53  MCUCONF.H (or any other header included before sdLog.h
54  ° SDLOG_ALL_BUFFERS_SIZE : (in bytes) cache buffer size shared between all opened log file
55  ° SDLOG_MAX_MESSAGE_LEN : (in bytes) maximum length of a message
56  ° SDLOG_QUEUE_BUCKETS : number of entries in queue
57 
58  use of the api :
59  sdLogInit (initialize peripheral, verify sdCard availibility)
60  sdLogOpenLog : open file
61  sdLogWriteXXX
62  sdLogFlushLog : flush buffer (optional)
63  sdLogCloseLog
64  sdLogFinish
65 
66  and asynchronous emergency close (power outage detection by example) :
67  sdLogCloseAllLogs
68  sdLogFinish
69 
70  */
71 
72 
73 #if SDLOG_ALL_BUFFERS_SIZE == 0 || SDLOG_MAX_MESSAGE_LEN == 0 || \
74  SDLOG_QUEUE_BUCKETS == 0
75 #undef SDLOG_NEED_QUEUE
76 #else
77 #define SDLOG_NEED_QUEUE
78 #endif
79 
80 
81 #ifdef SDLOG_NEED_QUEUE
82 typedef struct LogMessage LogMessage;
83 #endif
84 
85 typedef enum {
97 } SdioError;
98 
99 typedef struct _SdLogBuffer SdLogBuffer;
100 typedef int8_t FileDes;
101 
102 
103 
113 SdioError sdLogInit(uint32_t *freeSpaceInKo);
114 
129 SdioError getFileName(const char *prefix, const char *directoryName,
130  char *nextFileName, const size_t nameLength, const int indexOffset);
131 
132 
133 
134 
146 SdioError removeEmptyLogs(const char *directoryName, const char *prefix,
147  const size_t sizeConsideredEmpty);
155 SdioError sdLogFinish(void);
156 
157 
158 #ifdef SDLOG_NEED_QUEUE
159 
170 SdioError sdLogOpenLog(FileDes *fileObject, const char *directoryName, const char *fileName,
171  bool appendTagAtClose);
172 
173 
179 SdioError sdLogFlushLog(const FileDes fileObject);
180 
181 
187 SdioError sdLogCloseLog(const FileDes fileObject);
188 
197 SdioError sdLogCloseAllLogs(bool flush);
198 
199 
206 SdioError sdLogWriteLog(const FileDes fileObject, const char *fmt, ...);
207 
208 
216 SdioError sdLogWriteRaw(const FileDes fileObject, const uint8_t *buffer, const size_t len);
217 
232 SdioError sdLogAllocSDB(SdLogBuffer **sdb, const size_t len);
233 
241 char *sdLogGetBufferFromSDB(SdLogBuffer *sdb);
242 
243 
253 bool sdLogSeekBufferFromSDB(SdLogBuffer *sdb, uint32_t offset);
254 
255 
263 size_t sdLogGetBufferLenFromSDB(SdLogBuffer *sdb);
264 
272 SdioError sdLogWriteSDB(const FileDes fd, SdLogBuffer *sdb);
273 
274 
281 SdioError sdLogWriteByte(const FileDes fileObject, const uint8_t value);
282 #endif
283 
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 
SdioError sdLogFinish(void)
unmount filesystem
Definition: sdLog.c:224
static struct EcefCoor_d offset
int8_t FileDes
Definition: sdLog.h:100
SdioError getFileName(const char *prefix, const char *directoryName, char *nextFileName, const size_t nameLength, const int indexOffset)
get last used name for a pattern, then add offset and return valid filename
Definition: sdLog.c:640
Definition: sdLog.h:86
SdioError removeEmptyLogs(const char *directoryName, const char *prefix, const size_t sizeConsideredEmpty)
remove spurious log file left on sd
Definition: sdLog.c:708
unsigned long uint32_t
Definition: types.h:18
SdioError
Definition: sdLog.h:85
unsigned char uint8_t
Definition: types.h:14
int fd
Definition: serial.c:26
signed char int8_t
Definition: types.h:15
struct _SdLogBuffer SdLogBuffer
Definition: sdLog.h:99
SdioError sdLogInit(uint32_t *freeSpaceInKo)
initialise sdLog
Definition: sdLog.c:166