Skip to content

Commit cf7a5d2

Browse files
committed
Migrate UUID API, gd32 headers & style cleanup
Rename and consolidate UUID API and gd32 headers, plus broad stylistic and small functional cleanups across ArtNet/E1.31/RDM code. - Replaced hal::UuidCopy/hal_uuid.h with UuidCopy/uuid.h and moved/renamed uuid.cpp into lib-gd32/src; updated all includes to use "uuid.h" and removed hal namespace usage. - Renamed various gd32 header include guards to GD32_* (panelled, serialnumber, timing, uart0, watchdog, uuid) and adjusted file paths accordingly. - Adjusted copyright years and minor header file content (uuid/header comment tweaks). - Updated network include usages (network.h -> network_udp.h, network_config.h, network_iface.h) and related code to use network::iface::Dhcp()/GetBroadcastIp(). - ArtNet changes: guard time include with DISABLE_RTC, make kArtnetMinHeaderSize unsigned, rename showfile::record -> showfile::Record and update call sites, many small formatting/brace adjustments and minor refactors in poll/input/failsafe/rdm handlers. - RDM changes: small logic/formatting cleanups in ArtNet RDM controller, discovery and TOD handling; added bounds check for SetBackgroundIntervalMinutes (validates 1..240). - E1.31 changes: updated includes to new uuid header and calls to UuidCopy. These changes are mostly API migrations, header hygiene, formatting/consistency improvements and a few defensive checks; no large behavioral changes except the added parameter validation.
1 parent 1b1c499 commit cf7a5d2

21 files changed

Lines changed: 158 additions & 270 deletions

lib-artnet/src/node/artnetnode.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include <cstdint>
3131
#include <cstdio>
3232
#include <cstring>
33+
#if !defined(DISABLE_RTC)
3334
#include <ctime>
35+
#endif
3436
#include <cassert>
3537

3638
#include "artnetnode.h"
@@ -67,12 +69,12 @@
6769

6870
#if defined(ARTNET_SHOWFILE)
6971
namespace showfile {
70-
void record(const struct artnet::ArtDmx* artdmx, uint32_t millis);
71-
void record(const struct artnet::ArtSync* artsync, uint32_t millis);
72+
void Record(const struct artnet::ArtDmx* artdmx, uint32_t millis);
73+
void Record(const struct artnet::ArtSync* artsync, uint32_t millis);
7274
} // namespace showfile
7375
#endif
7476

75-
static constexpr auto kArtnetMinHeaderSize = 12;
77+
static constexpr auto kArtnetMinHeaderSize = 12U;
7678

7779
ArtNetNode::ArtNetNode() {
7880
DEBUG_ENTRY();
@@ -765,7 +767,7 @@ void ArtNetNode::InputUdp(const uint8_t* buffer, uint32_t size, uint32_t from_ip
765767
state_.art.dmx_ip = ip_address_from_;
766768
#if defined(ARTNET_SHOWFILE)
767769
if (state_.do_record) {
768-
showfile::record(reinterpret_cast<const artnet::ArtDmx*>(buffer), current_millis_);
770+
showfile::Record(reinterpret_cast<const artnet::ArtDmx*>(buffer), current_millis_);
769771
}
770772
#endif
771773
}
@@ -788,7 +790,7 @@ void ArtNetNode::InputUdp(const uint8_t* buffer, uint32_t size, uint32_t from_ip
788790
}
789791
#if defined(ARTNET_SHOWFILE)
790792
if (state_.do_record) {
791-
showfile::record(reinterpret_cast<const artnet::ArtSync*>(buffer), current_millis_);
793+
showfile::Record(reinterpret_cast<const artnet::ArtSync*>(buffer), current_millis_);
792794
}
793795
#endif
794796
}

lib-artnet/src/node/artnetnodehandlepoll.cpp

Lines changed: 46 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,29 @@
4040
#include "artnetnode.h"
4141
#include "artnet.h"
4242
#include "timing.h"
43-
#include "network.h"
43+
#include "network_udp.h"
44+
#include "network_config.h"
45+
#include "network_iface.h"
4446
#include "firmware/debug/debug_debug.h"
4547

46-
template <uint8_t N> static inline void Uitoa(uint32_t v, uint8_t* p)
47-
{
48+
template <uint8_t N>
49+
static inline void Uitoa(uint32_t v, uint8_t* p) {
4850
static_assert(N >= 1);
4951
auto* o = p + (N - 1);
50-
do
51-
{
52+
do {
5253
*o-- = static_cast<uint8_t>('0' + (v % 10U));
5354
v /= 10U;
5455
} while ((o >= p) && (v > 0));
5556

5657
// If there are remaining digits, fill with zeros
57-
while (o >= p)
58-
{
58+
while (o >= p) {
5959
*o-- = '0';
6060
}
6161
}
6262

63-
/*
64-
* Table 3 – NodeReport Codes
65-
*/
66-
static const char* GetReportCodeString(artnet::ReportCode code)
67-
{
68-
switch (code)
69-
{
63+
// Table 3 – NodeReport Codes
64+
static const char* GetReportCodeString(artnet::ReportCode code) {
65+
switch (code) {
7066
case artnet::ReportCode::kRcdebug:
7167
return "Booted in debug mode (Only used in development)";
7268
case artnet::ReportCode::kRcpowerok:
@@ -113,8 +109,7 @@ static const char* GetReportCodeString(artnet::ReportCode code)
113109
* xxxx is a hex status code as defined in Table 3.
114110
* yyyy is a decimal counter that increments every time the Node sends an ArtPollResponse.
115111
*/
116-
static void CreateNodeReport(uint8_t* node_report, artnet::ReportCode code, uint32_t counter)
117-
{
112+
static void CreateNodeReport(uint8_t* node_report, artnet::ReportCode code, uint32_t counter) {
118113
[[maybe_unused]] const auto* begin = node_report;
119114

120115
*node_report++ = '#';
@@ -134,18 +129,15 @@ static void CreateNodeReport(uint8_t* node_report, artnet::ReportCode code, uint
134129
strncpy(reinterpret_cast<char*>(node_report), preport_string, kRemainingSize);
135130
}
136131

137-
union uip
138-
{
132+
union uip {
139133
uint32_t u32;
140134
uint8_t u8[4];
141135
} static ip;
142136

143-
void ArtNetNode::ProcessPollReply(uint32_t port_index)
144-
{
137+
void ArtNetNode::ProcessPollReply(uint32_t port_index) {
145138
// preventing: src/node/artnetnodehandlepoll.cpp:157:36: error: array subscript 2 is above array bounds of 'artnetnode::OutputPort [2]'
146139
// [-Werror=array-bounds=]
147-
if (__builtin_expect(port_index >= dmxnode::kMaxPorts, 0))
148-
{
140+
if (__builtin_expect(port_index >= dmxnode::kMaxPorts, 0)) {
149141
#ifndef NDEBUG
150142
assert(0 && "port_index >= dmxnode::kMaxPorts");
151143
return;
@@ -154,11 +146,9 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index)
154146
#endif
155147
}
156148

157-
if (node_.port[port_index].direction == dmxnode::Direction::kOutput)
158-
{
149+
if (node_.port[port_index].direction == dmxnode::Direction::kOutput) {
159150
#if (ARTNET_VERSION >= 4)
160-
if (node_.port[port_index].protocol == artnet::PortProtocol::kSacn)
161-
{
151+
if (node_.port[port_index].protocol == artnet::PortProtocol::kSacn) {
162152
constexpr auto kMask = artnet::GoodOutput::kOutputIsMerging | artnet::GoodOutput::kDataIsBeingTransmitted | artnet::GoodOutput::kOutputIsSacn;
163153
auto good_output = output_port_[port_index].good_output;
164154
good_output &= static_cast<uint8_t>(~kMask);
@@ -167,12 +157,9 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index)
167157
}
168158
#endif
169159
#if defined(RDM_CONTROLLER)
170-
if (rdm_controller_.IsRunning(port_index))
171-
{
160+
if (rdm_controller_.IsRunning(port_index)) {
172161
GoodOutputBClear(port_index, artnet::GoodOutputB::kDiscoveryNotRunning);
173-
}
174-
else
175-
{
162+
} else {
176163
GoodOutputBSet(port_index, artnet::GoodOutputB::kDiscoveryNotRunning);
177164
}
178165
#endif
@@ -187,11 +174,9 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index)
187174
}
188175

189176
#if defined(ARTNET_HAVE_DMXIN)
190-
if (node_.port[port_index].direction == dmxnode::Direction::kInput)
191-
{
177+
if (node_.port[port_index].direction == dmxnode::Direction::kInput) {
192178
#if (ARTNET_VERSION >= 4)
193-
if (node_.port[port_index].protocol == artnet::PortProtocol::kSacn)
194-
{
179+
if (node_.port[port_index].protocol == artnet::PortProtocol::kSacn) {
195180
input_port_[port_index].good_input |= artnet::GoodInput::kInputIsSacn;
196181
}
197182
#endif
@@ -207,12 +192,10 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index)
207192
#endif
208193
}
209194

210-
void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, artnet::ArtPollQueue* queue)
211-
{
195+
void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, artnet::ArtPollQueue* queue) {
212196
assert(port_index < dmxnode::kMaxPorts);
213197

214-
if (node_.port[port_index].direction == dmxnode::Direction::kDisable)
215-
{
198+
if (node_.port[port_index].direction == dmxnode::Direction::kDisable) {
216199
return;
217200
}
218201

@@ -222,13 +205,9 @@ void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, art
222205
memcpy(art_poll_reply_.bind_ip, ip.u8, sizeof(art_poll_reply_.bind_ip));
223206
#endif
224207

225-
if (queue != nullptr)
226-
{
227-
if (!((node_.port[port_index].port_address >= queue->art_poll_reply.target_port_address_bottom) &&
228-
(node_.port[port_index].port_address <= queue->art_poll_reply.target_port_address_top)))
229-
{
230-
DEBUG_PRINTF("NOT: %u >= %u && %u <= %u", node_.port[port_index].port_address, queue->art_poll_reply.target_port_address_bottom,
231-
node_.port[port_index].port_address, queue->art_poll_reply.target_port_address_top);
208+
if (queue != nullptr) {
209+
if (!((node_.port[port_index].port_address >= queue->art_poll_reply.target_port_address_bottom) && (node_.port[port_index].port_address <= queue->art_poll_reply.target_port_address_top))) {
210+
DEBUG_PRINTF("NOT: %u >= %u && %u <= %u", node_.port[port_index].port_address, queue->art_poll_reply.target_port_address_bottom, node_.port[port_index].port_address, queue->art_poll_reply.target_port_address_top);
232211
return;
233212
}
234213
}
@@ -241,24 +220,22 @@ void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, art
241220
const auto* const kPortName = DmxNode::Instance().GetPortName(port_index);
242221
memcpy(art_poll_reply_.port_name, kPortName, artnet::kPortNameLength);
243222

244-
if (__builtin_expect((dmxnode_output_type_ != nullptr), 1))
245-
{
223+
if (__builtin_expect((dmxnode_output_type_ != nullptr), 1)) {
246224
const auto kRefreshRate = dmxnode_output_type_->GetRefreshRate();
247225
art_poll_reply_.refresh_rate_lo = static_cast<uint8_t>(kRefreshRate);
248226
art_poll_reply_.refresh_rate_hi = static_cast<uint8_t>(kRefreshRate >> 8);
249227
const auto kUserData = dmxnode_output_type_->GetUserData();
250228
art_poll_reply_.user_lo = static_cast<uint8_t>(kUserData);
251229
art_poll_reply_.user_hi = static_cast<uint8_t>(kUserData >> 8);
252230
}
253-
254-
art_poll_reply_.status2 &= static_cast<uint8_t>(~artnet::Status2::kIpDhcp);
255-
art_poll_reply_.status2 |= network::iface::Dhcp() ? artnet::Status2::kIpDhcp : artnet::Status2::kIpManualy;
231+
232+
art_poll_reply_.status2 &= static_cast<uint8_t>(~artnet::Status2::kIpDhcp);
233+
art_poll_reply_.status2 |= network::iface::Dhcp() ? artnet::Status2::kIpDhcp : artnet::Status2::kIpManualy;
256234

257235
ProcessPollReply(port_index);
258236

259237
state_.art.poll_reply_count++;
260-
if (state_.art.poll_reply_count == 10000)
261-
{
238+
if (state_.art.poll_reply_count == 10000) {
262239
state_.art.poll_reply_count = 0;
263240
}
264241

@@ -268,80 +245,60 @@ void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, art
268245
state_.is_changed = false;
269246
}
270247

271-
void ArtNetNode::HandlePoll()
272-
{
248+
void ArtNetNode::HandlePoll() {
273249
const auto* const kArtPoll = reinterpret_cast<artnet::ArtPoll*>(receive_buffer_);
274250

275251
state_.send_art_poll_reply_on_change = ((kArtPoll->flags & artnet::Flags::kSendArtpOnChange) == artnet::Flags::kSendArtpOnChange);
276252

277253
// If any controller requests diagnostics, the node will send diagnostics. (ArtPoll->Flags->2).
278-
if (kArtPoll->flags & artnet::Flags::kSendDiagMessages)
279-
{
254+
if (kArtPoll->flags & artnet::Flags::kSendDiagMessages) {
280255
state_.send_art_diag_data = true;
281256

282-
if (state_.art.poll_ip == 0)
283-
{
257+
if (state_.art.poll_ip == 0) {
284258
state_.art.poll_ip = ip_address_from_;
285-
}
286-
else if (!state_.is_multiple_controllers_req_diag && (state_.art.poll_ip != ip_address_from_))
287-
{
259+
} else if (!state_.is_multiple_controllers_req_diag && (state_.art.poll_ip != ip_address_from_)) {
288260
// If there are multiple controllers requesting diagnostics, diagnostics shall be broadcast.
289261
state_.art.diag_ip = network::GetBroadcastIp();
290262
state_.is_multiple_controllers_req_diag = true;
291263
}
292264

293-
if (state_.is_multiple_controllers_req_diag)
294-
{
265+
if (state_.is_multiple_controllers_req_diag) {
295266
// The lowest minimum value of Priority shall be used. (Ignore ArtPoll->diag_priority).
296267
state_.diag_priority = std::min(state_.diag_priority, kArtPoll->diag_priority);
297-
}
298-
else
299-
{
268+
} else {
300269
state_.diag_priority = kArtPoll->diag_priority;
301270
}
302271

303272
// If there are multiple controllers requesting diagnostics, diagnostics shall be broadcast. (Ignore ArtPoll->Flags->3).
304-
if (!state_.is_multiple_controllers_req_diag && (kArtPoll->flags & artnet::Flags::kSendDiagUnicast))
305-
{
273+
if (!state_.is_multiple_controllers_req_diag && (kArtPoll->flags & artnet::Flags::kSendDiagUnicast)) {
306274
state_.art.diag_ip = ip_address_from_;
307-
}
308-
else
309-
{
275+
} else {
310276
state_.art.diag_ip = network::GetBroadcastIp();
311277
}
312-
}
313-
else
314-
{
278+
} else {
315279
state_.send_art_diag_data = false;
316280
state_.art.diag_ip = 0;
317281
}
318282

319283
auto target_port_address_bottom = artnet::kPortAddressFirst;
320284
auto target_port_address_top = artnet::kPortAddressLast;
321285

322-
if (kArtPoll->flags & artnet::Flags::kUseTargetPortAddress)
323-
{
324-
target_port_address_top =
325-
static_cast<uint16_t>((static_cast<uint16_t>(kArtPoll->target_port_address_top_hi) >> 8) | kArtPoll->target_port_address_top_lo);
326-
target_port_address_bottom =
327-
static_cast<uint16_t>((static_cast<uint16_t>(kArtPoll->target_port_address_bottom_hi) >> 8) | kArtPoll->target_port_address_bottom_lo);
286+
if (kArtPoll->flags & artnet::Flags::kUseTargetPortAddress) {
287+
target_port_address_top = static_cast<uint16_t>((static_cast<uint16_t>(kArtPoll->target_port_address_top_hi) >> 8) | kArtPoll->target_port_address_top_lo);
288+
target_port_address_bottom = static_cast<uint16_t>((static_cast<uint16_t>(kArtPoll->target_port_address_bottom_hi) >> 8) | kArtPoll->target_port_address_bottom_lo);
328289
}
329290

330291
PollReplyQueueAdd(target_port_address_bottom, target_port_address_top);
331292
}
332293

333-
void ArtNetNode::PollReplyQueueAdd(uint16_t target_port_address_bottom, uint16_t target_port_address_top)
334-
{
335-
for (auto& entry : state_.art.poll_reply_queue)
336-
{
337-
if ((entry.art_poll_reply_ip_address == ip_address_from_) && (entry.art_poll_millis != 0)) [[unlikely]]
338-
{
294+
void ArtNetNode::PollReplyQueueAdd(uint16_t target_port_address_bottom, uint16_t target_port_address_top) {
295+
for (auto& entry : state_.art.poll_reply_queue) {
296+
if ((entry.art_poll_reply_ip_address == ip_address_from_) && (entry.art_poll_millis != 0)) [[unlikely]] {
339297
DEBUG_PRINTF("PollReply already queued for " IPSTR, IP2STR(entry.art_poll_reply_ip_address));
340298
return;
341299
}
342300

343-
if (entry.art_poll_millis == 0)
344-
{
301+
if (entry.art_poll_millis == 0) {
345302
entry.art_poll_millis = timing::Millis();
346303
entry.art_poll_reply_ip_address = ip_address_from_;
347304
entry.art_poll_reply.target_port_address_top = target_port_address_top;

lib-artnet/src/node/dmxin/handleinput.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,22 @@
3030
#if (ARTNET_VERSION >= 4) && defined(E131_HAVE_DMXIN)
3131
#include "e131bridge.h"
3232
#endif
33-
3433
#include "firmware/debug/debug_debug.h"
3534

36-
/**
37-
* A Controller or monitoring device on the network can
38-
* enable or disable individual DMX512 inputs on any of the network nodes.
39-
* This allows the Controller to directly control network traffic and
40-
* ensures that unused inputs are disabled and therefore not wasting bandwidth.
41-
*/
35+
// A Controller or monitoring device on the network can
36+
// enable or disable individual DMX512 inputs on any of the network nodes.
37+
// This allows the Controller to directly control network traffic and
38+
// ensures that unused inputs are disabled and therefore not wasting bandwidth.
4239

43-
void ArtNetNode::HandleInput()
44-
{
40+
void ArtNetNode::HandleInput() {
4541
DEBUG_ENTRY();
4642

4743
const auto* const kArtInput = reinterpret_cast<artnet::ArtInput*>(receive_buffer_);
4844

4945
#if (ARTNET_VERSION >= 4)
5046
// Art-Net 4: BindIndex is used to discriminate packets from the same IP.
5147
// Treat bind_index == 0 as legacy / invalid for strict Art-Net 4 behavior.
52-
if (kArtInput->bind_index == 0) [[unlikely]]
53-
{
48+
if (kArtInput->bind_index == 0) [[unlikely]] {
5449
DEBUG_EXIT();
5550
return;
5651
}
@@ -59,26 +54,20 @@ void ArtNetNode::HandleInput()
5954
const auto kPortIndex = static_cast<uint32_t>(kArtInput->bind_index > 0 ? kArtInput->bind_index - 1 : 0);
6055

6156
// Bounds check
62-
if (kPortIndex >= dmxnode::kMaxPorts) [[unlikely]]
63-
{
57+
if (kPortIndex >= dmxnode::kMaxPorts) [[unlikely]] {
6458
DEBUG_EXIT();
6559
return;
6660
}
6761

6862
// Controllers might send NumPortsLo = 4
6963
// We only act on Input[0] because bind_index selects the logical port instance.
70-
if (kArtInput->num_ports_lo >= 1)
71-
{
72-
if (node_.port[kPortIndex].direction == dmxnode::Direction::kInput)
73-
{
64+
if (kArtInput->num_ports_lo >= 1) {
65+
if (node_.port[kPortIndex].direction == dmxnode::Direction::kInput) {
7466
const auto kDisabled = (kArtInput->input[0] & 0x01U) != 0U;
7567

76-
if (kDisabled)
77-
{
68+
if (kDisabled) {
7869
input_port_[kPortIndex].good_input |= static_cast<uint8_t>(artnet::GoodInput::kDisabled);
79-
}
80-
else
81-
{
70+
} else {
8271
input_port_[kPortIndex].good_input &= static_cast<uint8_t>(~static_cast<uint8_t>(artnet::GoodInput::kDisabled));
8372
}
8473
#if (ARTNET_VERSION >= 4) && defined(E131_HAVE_DMXIN)
@@ -87,8 +76,7 @@ void ArtNetNode::HandleInput()
8776
}
8877
}
8978

90-
if (state_.send_art_poll_reply_on_change)
91-
{
79+
if (state_.send_art_poll_reply_on_change) {
9280
SendPollReply(kPortIndex, ip_address_from_);
9381
}
9482

0 commit comments

Comments
 (0)