Skip to content

Commit 8d65b95

Browse files
committed
Fix clang-tidy issues after rebase
1 parent aa28ee6 commit 8d65b95

File tree

6 files changed

+61
-55
lines changed

6 files changed

+61
-55
lines changed

flight_computer/src/cli/cli_commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ static void print_action_config() {
883883
config_action_t action{};
884884
for (int i = 0; i < NUM_EVENTS; i++) {
885885
const auto ev = static_cast<cats_event_e>(i);
886-
int nr_actions = cc_get_num_actions(ev);
886+
const int nr_actions = cc_get_num_actions(ev);
887887
if (nr_actions > 0) {
888888
cli_printf("\n%s\n", GetStr(ev, p_event_table));
889889
cli_printf(" Number of Actions: %d\n", nr_actions);

flight_computer/src/usb/msc/emfat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void emfat_read(emfat_t *emfat, uint8_t *data, uint32_t sector, int num_sectors)
9191
void emfat_write(emfat_t *emfat, const uint8_t *data, uint32_t sector, int num_sectors);
9292

9393
#define EMFAT_ENCODE_CMA_TIME(D, M, Y, h, m, s) \
94-
((((((Y)-1980) << 9) | ((M) << 5) | (D)) << 16) | (((h) << 11) | ((m) << 5) | ((s) >> 1)))
94+
((((((Y)-1980U) << 9U) | ((M) << 5U) | (D)) << 16U) | (((h) << 11U) | ((m) << 5U) | ((s) >> 1U)))
9595

9696
static inline uint32_t emfat_encode_cma_time(int D, int M, int Y, int h, int m, int s) {
9797
return EMFAT_ENCODE_CMA_TIME(D, M, Y, h, m, s);

flight_computer/src/usb/msc/emfat_file.cpp

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
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

6969
static 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

8484
static 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)
103104
static 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)
134138
static emfat_entry_t entries[EMFAT_MAX_ENTRY]{};
135-
136139
emfat_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

139144
static 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

149154
static 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
*/
176181
static 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

203206
static void emfat_find_logs(emfat_entry_t *entry) {

flight_computer/src/usb/msc_disk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
#include "tusb.h"
2727
#include "usb/msc/emfat.h"
28-
#include "usb/msc/emfat_file.h"
2928

3029
#include <string.h>
3130

31+
extern bool emfat_init_files();
32+
3233
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
3334
extern emfat_t emfat;
3435

flight_computer/src/util/enum_str_maps.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <cstdio>
2626

2727
// Filled later depending on tick frequency
28+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
2829
std::array<char*, NUM_REC_SPEEDS> recorder_speed_map = {};
2930

3031
void init_recorder_speed_map() {

flight_computer/src/util/enum_str_maps.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ inline constexpr std::array<const char *, 2> on_off_map{
6262

6363
inline constexpr std::array<const char *, 3> battery_map{"LI-ION", "LI-PO", "ALKALINE"};
6464

65+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
6566
extern std::array<char *, NUM_REC_SPEEDS> recorder_speed_map;
6667

6768
void init_recorder_speed_map();

0 commit comments

Comments
 (0)