PX4 Firmware
PX4 Autopilot Software http://px4.io
util.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2018 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
36 #include <stdint.h>
37 #include <time.h>
38 
39 #include <uORB/uORB.h>
40 
41 #ifdef __PX4_NUTTX
42 #define LOG_DIR_LEN 64
43 #else
44 #define LOG_DIR_LEN 256
45 #endif
46 
47 namespace px4
48 {
49 namespace logger
50 {
51 namespace util
52 {
53 
54 /**
55  * Recursively remove a directory
56  * @return 0 on success, <0 otherwise
57  */
58 int remove_directory(const char *dir);
59 
60 /**
61  * check if a file exists
62  */
63 bool file_exist(const char *filename);
64 
65 /**
66  * Check if there is enough free space left on the SD Card.
67  * It will remove old log files if there is not enough space,
68  * and if that fails return 1, and send a user message
69  * @param log_root_dir log root directory: it's expected to contain directories in the form of sess%i or %d-%d-%d (year, month, day)
70  * @param max_log_dirs_to_keep maximum log directories to keep (set to 0 for unlimited)
71  * @param mavlink_log_pub
72  * @param sess_dir_index output argument: will be set to the next free directory sess%i index.
73  * @return 0 on success, 1 if not enough space, <0 on error
74  */
75 int check_free_space(const char *log_root_dir, int32_t max_log_dirs_to_keep, orb_advert_t &mavlink_log_pub,
76  int &sess_dir_index);
77 
78 /**
79  * Get the time for log file name
80  * @param tt returned time
81  * @param utc_offset_sec UTC time offset [s]
82  * @param boot_time use time when booted instead of current time
83  * @return true on success, false otherwise (eg. if no gps)
84  */
85 bool get_log_time(struct tm *tt, int utc_offset_sec = 0, bool boot_time = false);
86 
87 } //namespace util
88 } //namespace logger
89 } //namespace px4
static orb_advert_t * mavlink_log_pub
API for the uORB lightweight object broker.
bool get_log_time(struct tm *tt, int utc_offset_sec, bool boot_time)
Get the time for log file name.
Definition: util.cpp:74
int remove_directory(const char *dir)
Recursively remove a directory.
Definition: util.cpp:238
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
int check_free_space(const char *log_root_dir, int32_t max_log_dirs_to_keep, orb_advert_t &mavlink_log_pub, int &sess_dir_index)
Check if there is enough free space left on the SD Card.
Definition: util.cpp:114
Definition: bst.cpp:62
bool file_exist(const char *filename)
check if a file exists
Definition: util.cpp:68