3636#include " flash/lfs_custom.hpp"
3737#include " util/log.h"
3838
39- #define CMA_TIME EMFAT_ENCODE_CMA_TIME (1 , 1 , 2023 , 13 , 0 , 0 )
39+ #define CMA_TIME EMFAT_ENCODE_CMA_TIME (1U , 1U , 2023U , 13U , 0U , 0U )
4040#define CMA \
4141 { CMA_TIME, CMA_TIME, CMA_TIME }
4242
@@ -54,31 +54,31 @@ static void lfs_read_file(uint8_t *dest, int size, uint32_t offset, emfat_entry_
5454 }
5555
5656 // Assume the files starting with 'f' are flight logs; all others are considered to be stats files.
57- const bool flight_log = entry->name != NULL && entry->name [0 ] == ' f' ;
57+ const bool flight_log = entry->name != nullptr && entry->name [0 ] == ' f' ;
5858 snprintf (filename, 32 , flight_log ? " /flights/flight_%05hu" : " /stats/stats_%05hu.txt" , entry->lfs_flight_idx );
59- int err = lfs_file_open (&lfs, &curr_file, filename, LFS_O_RDONLY);
60- if (err) {
59+ const int err = lfs_file_open (&lfs, &curr_file, filename, LFS_O_RDONLY);
60+ if (err < 0 ) {
6161 return ;
6262 }
6363 file_open = true ;
6464 }
65- lfs_file_seek (&lfs, &curr_file, ( int32_t ) offset, LFS_SEEK_SET);
65+ lfs_file_seek (&lfs, &curr_file, static_cast < int32_t >( offset) , LFS_SEEK_SET);
6666 lfs_file_read (&lfs, &curr_file, dest, size);
6767}
6868
6969static void memory_read_proc (uint8_t *dest, int size, uint32_t offset, emfat_entry_t *entry) {
70- int len = 0 ;
70+ int32_t len = 0 ;
7171 if (offset > entry->curr_size ) {
7272 return ;
7373 }
7474
7575 if (offset + size > entry->curr_size ) {
76- len = entry->curr_size - offset;
76+ len = static_cast < int32_t >( entry->curr_size - offset) ;
7777 } else {
7878 len = size;
7979 }
80-
81- memcpy (dest, &(( char *) entry->user_data )[offset], len);
80+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
81+ memcpy (dest, &(reinterpret_cast < char *>( entry->user_data ) )[offset], len);
8282}
8383
8484static const char readme_file[] =
@@ -89,8 +89,8 @@ static const char readme_file[] =
8989 " The number of logs exposed via Mass Storage Controller is limited to 50 flight log files and 50 stats files.\r\n " ;
9090#define README_SIZE_BYTES (sizeof (readme_file) - 1 )
9191
92- # define PREDEFINED_ENTRY_COUNT 2
93- # define README_FILE_IDX 1
92+ constexpr uint8_t PREDEFINED_ENTRY_COUNT = 2 ;
93+ constexpr uint8_t README_FILE_IDX = 1 ;
9494
9595// We are limited to 50 flight logs & 50 stats files due to RAM memory limits
9696// TODO: It seems the number has to be 1 more than the actual limit, this should be investigated
@@ -100,41 +100,46 @@ static_assert(kMaxNumVisibleLogs > 0 && kMaxNumVisibleLogs % 2 == 0,
100100
101101#define EMFAT_MAX_ENTRY (PREDEFINED_ENTRY_COUNT + kMaxNumVisibleLogs )
102102
103+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
103104static char logNames[EMFAT_MAX_ENTRY][8 + 1 + 3 + 1 ] = {" " , " readme.txt" };
104105
105- static const emfat_entry_t entriesPredefined[] = {{
106- logNames[0 ], // name
107- true , // dir
108- ATTR_DIR, // attr
109- 0 , // level
110- 0 , // offset
111- 0 , // number
112- 0 , // curr_size
113- 0 , // max_size
114- 0 , // user_data
115- CMA, // cma_time[3]
116- NULL , // readcb
117- NULL // writecb
118- },
119- {
120- logNames[1 ], // name
121- false , // dir
122- ATTR_READ, // attr
123- 1 , // level
124- 0 , // offset
125- 0 , // number
126- README_SIZE_BYTES, // curr_size
127- README_SIZE_BYTES, // max_siize
128- (long )readme_file, // user_data
129- CMA, // cma_time[3]
130- memory_read_proc, // readcb
131- NULL // writecb
132- }};
133-
106+ static const emfat_entry_t entriesPredefined[] = {
107+ {
108+ logNames[0 ], // name
109+ true , // dir
110+ ATTR_DIR, // attr
111+ 0 , // level
112+ 0 , // offset
113+ 0 , // number
114+ 0 , // curr_size
115+ 0 , // max_size
116+ 0 , // user_data
117+ CMA, // cma_time[3]
118+ nullptr , // readcb
119+ nullptr // writecb
120+ },
121+ {
122+ logNames[1 ], // name
123+ false , // dir
124+ ATTR_READ, // attr
125+ 1 , // level
126+ 0 , // offset
127+ 0 , // number
128+ README_SIZE_BYTES, // curr_size
129+ README_SIZE_BYTES, // max_size
130+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,google-runtime-int)
131+ reinterpret_cast <long >(readme_file), // user_data
132+ CMA, // cma_time[3]
133+ memory_read_proc, // readcb
134+ nullptr // writecb
135+ }};
136+
137+ // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
134138static emfat_entry_t entries[EMFAT_MAX_ENTRY]{};
135-
136139emfat_t emfat;
137- static uint32_t cmaTime = CMA_TIME;
140+ // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
141+
142+ constexpr uint32_t cmaTime = CMA_TIME;
138143
139144static void emfat_set_entry_cma (emfat_entry_t *entry) {
140145 // Set file creation/modification/access times to be the same, either the default date or that from the RTC
@@ -144,39 +149,39 @@ static void emfat_set_entry_cma(emfat_entry_t *entry) {
144149 entry->cma_time [2 ] = cmaTime;
145150}
146151
147- typedef enum { FLIGHT_LOG, STATS_LOG } log_type_e ;
152+ enum log_type_e { FLIGHT_LOG, STATS_LOG };
148153
149154static void emfat_add_log (emfat_entry_t *entry, uint32_t size, const char *name, log_type_e log_type) {
150155 const uint64_t entry_idx = entry - entries;
151156
152157 uint16_t lfs_flight_idx = 0 ;
153- int idx_start = log_type == FLIGHT_LOG ? 7 : 6 ;
158+ const int idx_start = log_type == FLIGHT_LOG ? 7 : 6 ;
154159
155160 // flight_000xx, stats_000xx.txt
156161 if (sscanf (&name[idx_start], " %hu" , &lfs_flight_idx) > 0 ) {
157162 log_error (" Reading lfs_flight_idx failed: %hu" , lfs_flight_idx);
158163 }
159164
160- snprintf (logNames[entry_idx], 12 , " %s%03d.%s" , log_type == FLIGHT_LOG ? " fl" : " st" , ( uint8_t )lfs_flight_idx,
161- log_type == FLIGHT_LOG ? " cfl" : " txt" );
165+ snprintf (logNames[entry_idx], 12 , " %s%03d.%s" , log_type == FLIGHT_LOG ? " fl" : " st" ,
166+ static_cast < uint8_t >(lfs_flight_idx), log_type == FLIGHT_LOG ? " cfl" : " txt" );
162167 entry->name = logNames[entry_idx];
163168 entry->level = 1 ;
164- entry->number = entry_idx;
169+ entry->number = static_cast < int32_t >( entry_idx) ;
165170 entry->lfs_flight_idx = lfs_flight_idx;
166171 entry->curr_size = size;
167172 entry->max_size = entry->curr_size ;
168173 entry->readcb = lfs_read_file;
169- entry->writecb = NULL ;
174+ entry->writecb = nullptr ;
170175 emfat_set_entry_cma (entry);
171176}
172177
173178/* *
174179 * @brief Add file from path, returns 0 on success.
175180 */
176181static void add_logs_from_path (emfat_entry_t **entry, const char *path, log_type_e log_type, uint32_t max_logs_to_add) {
177- struct lfs_info info;
182+ struct lfs_info info {} ;
178183 lfs_dir_t dir;
179- int err = lfs_dir_open (&lfs, &dir, path);
184+ const int err = lfs_dir_open (&lfs, &dir, path);
180185 if (err < 0 ) {
181186 return ;
182187 }
@@ -196,8 +201,6 @@ static void add_logs_from_path(emfat_entry_t **entry, const char *path, log_type
196201 }
197202
198203 lfs_dir_close (&lfs, &dir);
199-
200- return ;
201204}
202205
203206static void emfat_find_logs (emfat_entry_t *entry) {
0 commit comments