Skip to content

Commit c6faa36

Browse files
committed
Code style cleanup in lib-rdm headers
Apply consistent formatting across rdm_discovery.h, rdm_tod.h, rdm_message_print.h, rdm_preset_playback.h, and rdm_selftest.h: - Consolidate namespace/class opening braces to same line - Expand single-line if/return statements to multi-line blocks - Rename ambiguous variable `i` to `entry` in Delete() - Rename `kI` to `kIndex` in mute methods - Add const to EnableBackground() - Fix `waiting_` check to explicit `!= 0` - Minor whitespace fixes
1 parent cdf84a5 commit c6faa36

5 files changed

Lines changed: 65 additions & 105 deletions

File tree

lib-rdm/include/rdm_discovery.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Discovery : rdm::discovery::StateMachine {
7171
enabled_ &= static_cast<uint8_t>(~Bit(port_index));
7272
}
7373

74-
void EnableBackground(uint32_t port_index) {
74+
void EnableBackground(uint32_t port_index) const {
7575
assert(port_index < kPorts);
7676
if ((Bit(port_index) & enabled_) == Bit(port_index)) {
7777
s_bg_discovery |= Bit(port_index);
@@ -159,7 +159,7 @@ class Discovery : rdm::discovery::StateMachine {
159159
}
160160

161161
void SetBackgroundIntervalMinutes(uint8_t background_interval_minutes) {
162-
if ((background_interval_minutes > 0) && (background_interval_minutes <= 240)) {
162+
if ((background_interval_minutes > 0) && (background_interval_minutes <= 240)) {
163163
background_interval_minutes_ = background_interval_minutes;
164164
}
165165
}
@@ -175,7 +175,9 @@ class Discovery : rdm::discovery::StateMachine {
175175
return;
176176
}
177177

178-
if (rdm::discovery::StateMachine::IsRunning()) return;
178+
if (rdm::discovery::StateMachine::IsRunning()) {
179+
return;
180+
}
179181

180182
bool is_incremental;
181183

@@ -186,15 +188,17 @@ class Discovery : rdm::discovery::StateMachine {
186188
rdm::discovery::Finished(port_index_, is_incremental ? rdm::discovery::Type::kIncremental : rdm::discovery::Type::kFull);
187189

188190
port_index_++;
189-
if (port_index_ == kPorts) port_index_ = 0;
191+
if (port_index_ == kPorts) {
192+
port_index_ = 0;
193+
}
190194

191195
if (waiting_ == 0) {
192196
running_ = false;
193197
port_index_ = 0;
194198
}
195199
}
196200

197-
if (waiting_) {
201+
if (waiting_ != 0) {
198202
if ((Bit(port_index_) & waiting_) == Bit(port_index_)) {
199203
if ((Bit(port_index_) & type_) == Bit(port_index_)) {
200204
rdm::discovery::Starting(port_index_, rdm::discovery::Type::kFull);

lib-rdm/include/rdm_message_print.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
#include <cstdint>
3030

31-
namespace rdm::message
32-
{
31+
namespace rdm::message {
3332
void Print(const uint8_t* rdm_data);
3433
void PrintNoStartcode(const uint8_t* rdm_data_no_sc);
3534
} // namespace rdm::message

lib-rdm/include/rdm_preset_playback.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
#include <cstdint>
3030

31-
namespace rdm::preset_playback
32-
{
31+
namespace rdm::preset_playback {
3332
inline constexpr uint16_t kOff = 0x0000;
3433
inline constexpr uint16_t kAll = 0xFFFF;
3534

lib-rdm/include/rdm_selftest.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828

2929
#include <cstdint>
3030

31-
namespace rdm::selftest
32-
{
31+
namespace rdm::selftest {
3332
uint8_t Get();
3433
bool Set(uint8_t self_test);
3534
const char* GetDescription(uint8_t self_test, uint32_t& length);
3635
} // namespace rdm::selftest
3736

38-
#endif // RDM_SELFTEST_H_
37+
#endif // RDM_SELFTEST_H_

lib-rdm/include/rdm_tod.h

Lines changed: 52 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636
#include "rdmconst.h"
3737
#include "firmware/debug/debug_debug.h"
3838

39-
namespace rdm
40-
{
41-
class Tod
42-
{
39+
namespace rdm {
40+
class Tod {
4341
public:
4442
#if !defined(RDM_DISCOVERY_TOD_TABLE_SIZE)
4543
#define RDM_DISCOVERY_TOD_TABLE_SIZE 200U
@@ -48,45 +46,36 @@ class Tod
4846
static constexpr uint32_t kMutesTableSize = (kTableSize + 32) / 32;
4947
static constexpr uint32_t kInvalidEntry = UINT32_MAX;
5048

51-
Tod()
52-
{
53-
for (uint32_t i = 0; i < kTableSize; i++)
54-
{
49+
Tod() {
50+
for (uint32_t i = 0; i < kTableSize; i++) {
5551
memcpy(&tod_[i], rdm::kUidAll, rdm::kUidSize);
5652
}
5753

58-
for (uint32_t i = 0; i < kMutesTableSize; i++)
59-
{
54+
for (uint32_t i = 0; i < kMutesTableSize; i++) {
6055
mutes_[i] = 0;
6156
}
6257
}
6358

6459
~Tod() = default;
6560

66-
void Reset()
67-
{
68-
for (uint32_t i = 0; i < entries_; i++)
69-
{
61+
void Reset() {
62+
for (uint32_t i = 0; i < entries_; i++) {
7063
memcpy(&tod_[i], rdm::kUidAll, rdm::kUidSize);
7164
}
7265

7366
entries_ = 0;
7467

75-
for (uint32_t i = 0; i < kMutesTableSize; i++)
76-
{
68+
for (uint32_t i = 0; i < kMutesTableSize; i++) {
7769
mutes_[i] = 0;
7870
}
7971
}
8072

81-
bool AddUid(const uint8_t* uid)
82-
{
83-
if (entries_ == kTableSize)
84-
{
73+
bool AddUid(const uint8_t* uid) {
74+
if (entries_ == kTableSize) {
8575
return false;
8676
}
8777

88-
if (Exist(uid))
89-
{
78+
if (Exist(uid)) {
9079
return false;
9180
}
9281

@@ -97,10 +86,8 @@ class Tod
9786

9887
uint32_t UidCount() const { return entries_; }
9988

100-
bool CopyUidEntry(uint32_t index, uint8_t uid[rdm::kUidSize])
101-
{
102-
if (index > entries_)
103-
{
89+
bool CopyUidEntry(uint32_t index, uint8_t uid[rdm::kUidSize]) {
90+
if (index > entries_) {
10491
memcpy(uid, rdm::kUidAll, rdm::kUidSize);
10592
return false;
10693
}
@@ -109,51 +96,41 @@ class Tod
10996
return true;
11097
}
11198

112-
void Copy(uint8_t* table)
113-
{
99+
void Copy(uint8_t* table) {
114100
DEBUG_ENTRY();
115101
DEBUG_PRINTF("entries_=%u", static_cast<unsigned int>(entries_));
116102
assert(table != nullptr);
117103

118104
const auto* src = reinterpret_cast<const uint8_t*>(tod_);
119105
auto* dst = table;
120106

121-
for (uint32_t i = 0; i < (entries_ * rdm::kUidSize); i++)
122-
{
107+
for (uint32_t i = 0; i < (entries_ * rdm::kUidSize); i++) {
123108
*dst++ = *src++;
124109
}
125110

126111
DEBUG_EXIT();
127112
}
128113

129-
bool Delete(const uint8_t* uid)
130-
{
114+
bool Delete(const uint8_t* uid) {
131115
bool found = false;
132-
uint32_t i;
116+
uint32_t entry;
133117

134-
for (i = 0; i < entries_; i++)
135-
{
136-
if (memcmp(&tod_[i], uid, rdm::kUidSize) == 0)
137-
{
118+
for (entry = 0; entry < entries_; entry++) {
119+
if (memcmp(&tod_[entry], uid, rdm::kUidSize) == 0) {
138120
found = true;
139121
break;
140122
}
141123
}
142124

143-
if (!found)
144-
{
125+
if (!found) {
145126
return false;
146127
}
147128

148-
if (i == kTableSize - 1)
149-
{
150-
memcpy(&tod_[i], rdm::kUidAll, rdm::kUidSize);
151-
}
152-
else
153-
{
154-
for (; i < entries_; i++)
155-
{
156-
memcpy(&tod_[i], &tod_[i + 1], rdm::kUidSize);
129+
if (entry == kTableSize - 1) {
130+
memcpy(&tod_[entry], rdm::kUidAll, rdm::kUidSize);
131+
} else {
132+
for (; entry < entries_; entry++) {
133+
memcpy(&tod_[entry], &tod_[entry + 1], rdm::kUidSize);
157134
}
158135
}
159136

@@ -162,12 +139,9 @@ class Tod
162139
return true;
163140
}
164141

165-
bool Exist(const uint8_t* uid)
166-
{
167-
for (uint32_t index = 0; index < entries_; index++)
168-
{
169-
if (memcmp(&tod_[index], uid, rdm::kUidSize) == 0)
170-
{
142+
bool Exist(const uint8_t* uid) {
143+
for (uint32_t index = 0; index < entries_; index++) {
144+
if (memcmp(&tod_[index], uid, rdm::kUidSize) == 0) {
171145
saved_index_ = index;
172146
return true;
173147
}
@@ -177,84 +151,70 @@ class Tod
177151
return false;
178152
}
179153

180-
const uint8_t* Next()
181-
{
154+
const uint8_t* Next() {
182155
saved_index_++;
183156

184-
if (saved_index_ == entries_)
185-
{
157+
if (saved_index_ == entries_) {
186158
saved_index_ = 0;
187159
}
188160

189161
return tod_[saved_index_].uid;
190162
}
191163

192-
void Mute()
193-
{
194-
if (saved_index_ == kInvalidEntry)
195-
{
164+
void Mute() {
165+
if (saved_index_ == kInvalidEntry) {
196166
return;
197167
}
198168

199-
const auto kI = saved_index_ / 32;
200-
const auto kShift = saved_index_ - (kI * 32);
169+
const auto kIndex = saved_index_ / 32;
170+
const auto kShift = saved_index_ - (kIndex * 32);
201171

202-
mutes_[kI] |= (1U << kShift);
172+
mutes_[kIndex] |= (1U << kShift);
203173
}
204174

205-
void UnMute()
206-
{
207-
if (saved_index_ == kInvalidEntry)
208-
{
175+
void UnMute() {
176+
if (saved_index_ == kInvalidEntry) {
209177
return;
210178
}
211179

212-
const auto kI = saved_index_ / 32;
213-
const auto kShift = saved_index_ - (kI * 32);
180+
const auto kIndex = saved_index_ / 32;
181+
const auto kShift = saved_index_ - (kIndex * 32);
214182

215-
mutes_[kI] &= ~(1U << kShift);
183+
mutes_[kIndex] &= ~(1U << kShift);
216184
}
217185

218-
void UnMuteAll()
219-
{
220-
for (uint32_t i = 0; i < kMutesTableSize; i++)
221-
{
186+
void UnMuteAll() {
187+
for (uint32_t i = 0; i < kMutesTableSize; i++) {
222188
mutes_[i] = 0;
223189
}
224190
}
225191

226-
bool IsMuted()
227-
{
228-
if (saved_index_ == kInvalidEntry)
229-
{
192+
bool IsMuted() {
193+
if (saved_index_ == kInvalidEntry) {
230194
return true;
231195
}
232196

233-
const auto kI = saved_index_ / 32;
234-
const auto kMutes = mutes_[kI];
235-
const auto kShift = saved_index_ - (kI * 32);
197+
const auto kIndex = saved_index_ / 32;
198+
const auto kMutes = mutes_[kIndex];
199+
const auto kShift = saved_index_ - (kIndex * 32);
236200

237201
return (kMutes & (1U << kShift)) == (1U << kShift);
238202
}
239203

240-
void Dump([[maybe_unused]] uint32_t count)
241-
{
204+
void Dump([[maybe_unused]] uint32_t count) {
242205
#ifndef NDEBUG
243-
if (count > kTableSize)
244-
{
206+
if (count > kTableSize) {
245207
count = kTableSize;
246208
}
247209

248210
printf("[%u]\n", static_cast<unsigned int>(count));
249-
for (uint32_t i = 0; i < count; i++)
250-
{
211+
for (uint32_t i = 0; i < count; i++) {
251212
printf("%.2x%.2x:%.2x%.2x%.2x%.2x\n", tod_[i].uid[0], tod_[i].uid[1], tod_[i].uid[2], tod_[i].uid[3], tod_[i].uid[4], tod_[i].uid[5]);
252213
}
253214
#endif
254215
}
255216

256-
void Dump()
257-
{
217+
void Dump() {
258218
#ifndef NDEBUG
259219
Dump(entries_);
260220
#endif
@@ -264,8 +224,7 @@ class Tod
264224
uint32_t entries_{0};
265225
uint32_t saved_index_{kInvalidEntry};
266226
uint32_t mutes_[kMutesTableSize];
267-
struct Uid
268-
{
227+
struct Uid {
269228
uint8_t uid[rdm::kUidSize];
270229
};
271230
Uid tod_[kTableSize];

0 commit comments

Comments
 (0)