Paparazzi UAS
v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
logger_utils.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2026 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18
* <http://www.gnu.org/licenses/>.
19
*
20
*/
21
26
#include "
modules/loggers/logger_utils.h
"
27
28
#if !USE_CHIBIOS_RTOS
29
30
#include <time.h>
31
#include <stdlib.h>
32
#include <stdint.h>
33
34
FILE
*
open_log
(
char
* path,
char
* name)
35
{
36
// Create output folder if necessary
37
if
(
access
(path,
F_OK
)) {
38
char
save_dir_cmd
[256];
39
sprintf
(
save_dir_cmd
,
"mkdir -p %s"
, path);
40
if
(
system
(
save_dir_cmd
) != 0) {
41
printf
(
"[logger] Could not create log file directory %s.\n"
, path);
42
return
NULL
;
43
}
44
}
45
46
uint32_t
counter
= 0;
47
char
filename
[512];
48
char
date_time
[80];
49
50
if
(name ==
NULL
) {
51
// Get current date/time for filename
52
time_t
now
=
time
(0);
53
struct
tm
tstruct
;
54
tstruct
= *
localtime
(&
now
);
55
strftime
(
date_time
,
sizeof
(
date_time
),
"%Y%m%d-%H%M%S"
, &
tstruct
);
56
sprintf
(
filename
,
"%s/%s.csv"
, path,
date_time
);
57
}
else
{
58
// use specified name
59
sprintf
(
filename
,
"%s/%s.csv"
, path, name);
60
}
61
62
// Check for available files
63
FILE
*file;
64
while
((file =
fopen
(
filename
,
"r"
))) {
65
fclose
(file);
66
67
if
(name ==
NULL
) {
68
sprintf
(
filename
,
"%s/%s_%05d.csv"
, path,
date_time
,
counter
);
69
}
else
{
70
sprintf
(
filename
,
"%s/%s_%05d.csv"
, path, name,
counter
);
71
}
72
counter
++;
73
}
74
75
file =
fopen
(
filename
,
"w"
);
76
if
(!file) {
77
printf
(
"[logger] ERROR opening log file %s!\n"
,
filename
);
78
return
NULL
;
79
}
80
81
printf
(
"[logger] Start logging to %s...\n"
,
filename
);
82
return
file;
83
}
84
85
#endif
86
time
float time
Definition
eff_scheduling_rotwing_V2.c:400
counter
uint32_t counter
Definition
ins_flow.c:187
open_log
FILE * open_log(char *path, char *name)
Open a log file.
Definition
logger_utils.c:34
logger_utils.h
Generic definitions and tools for logging on ChibiOS or Linux.
foo
uint16_t foo
Definition
main_demo5.c:58
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition
vl53l1_types.h:78
sw
airborne
modules
loggers
logger_utils.c
Generated on Wed Apr 8 2026 08:31:57 for Paparazzi UAS by
1.9.8