Skip to content

Commit 27e4bd7

Browse files
committed
Refactor ArtNet poll reply handling and fixes
Refactor ArtNet poll reply flow and apply various cleanups across libraries. - Change ArtNetNode::ProcessPollReply signature (remove num_ports_input/num_ports_output) and consolidate port determination into SendPollReply. - SendPollReply: early-return for disabled ports, set NumPortsLo and PortTypes (respect ARTNET_HAVE_DMXIN), increment/reset poll_reply_count correctly, always create node report and send UDP packet, and clear state_.is_changed. - Minor code style and whitespace fixes in artnet sources. - Update node type name from "Artnet" to "Art-Net" and reformat output type name array for dmxnode; small header/footer comment adjustments. - GD32 DMA memcpy: bump copyright years, add stricter alignment asserts for GD32F4 path, guard IRQ setup with DMA_MEMCPY32_DISABLE_IRQ, remove unused include. - Add missing debug include in pixeldmxparams and fix minor formatting. - Bump copyright years in several headers. These changes simplify poll reply logic, improve portability and conditional compilation for DMA memcpy, and tidy up naming/formatting across the codebase.
1 parent 092b978 commit 27e4bd7

8 files changed

Lines changed: 47 additions & 58 deletions

File tree

lib-artnet/include/artnetnode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file artnetnode.h
33
*
44
*/
5-
/* Copyright (C) 2016-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2016-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -395,7 +395,7 @@ class ArtNetNode
395395
void UpdateMergeStatus(uint32_t port_index);
396396
void CheckMergeTimeouts(uint32_t port_index);
397397

398-
void ProcessPollReply(uint32_t port_index, uint32_t& num_ports_input, uint32_t& num_ports_output);
398+
void ProcessPollReply(uint32_t port_index);
399399
void SendPollReply(uint32_t port_index, uint32_t destination_ip, artnet::ArtPollQueue* poll_queue = nullptr);
400400

401401
void SendTodRequest(uint32_t port_index);

lib-artnet/src/node/artnetnode.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ArtNetNode::ArtNetNode()
8484
art_poll_reply_.Oem = ArtNetConst::kOemId[1];
8585
art_poll_reply_.EstaMan[0] = ArtNetConst::kEstaId[1];
8686
art_poll_reply_.EstaMan[1] = ArtNetConst::kEstaId[0];
87-
network::iface::CopyMacAddressTo(art_poll_reply_.MAC);
87+
network::iface::CopyMacAddressTo(art_poll_reply_.MAC);
8888
#if (ARTNET_VERSION >= 4)
8989
art_poll_reply_.AcnPriority = e131::priority::kDefault;
9090
#endif
@@ -165,9 +165,9 @@ void ArtNetNode::Start()
165165
art_poll_reply_.Status2 |=
166166
artnet::Status2::kPortAddress15Bit | (artnet::kVersion >= 4 ? artnet::Status2::kSacnAbleToSwitch : artnet::Status2::kSacnNoSwitch);
167167
art_poll_reply_.Status2 &= static_cast<uint8_t>(~artnet::Status2::kIpDhcp);
168-
art_poll_reply_.Status2 |= network::iface::Dhcp() ? artnet::Status2::kIpDhcp : artnet::Status2::kIpManualy;
168+
art_poll_reply_.Status2 |= network::iface::Dhcp() ? artnet::Status2::kIpDhcp : artnet::Status2::kIpManualy;
169169
art_poll_reply_.Status2 &= static_cast<uint8_t>(~artnet::Status2::kDhcpCapable);
170-
art_poll_reply_.Status2 |= network::iface::IsDhcpCapable() ? artnet::Status2::kDhcpCapable : static_cast<uint8_t>(0);
170+
art_poll_reply_.Status2 |= network::iface::IsDhcpCapable() ? artnet::Status2::kDhcpCapable : static_cast<uint8_t>(0);
171171
#if defined(ENABLE_HTTPD) && defined(ENABLE_CONTENT)
172172
art_poll_reply_.Status2 |= artnet::Status2::kWebBrowserSupport;
173173
#endif
@@ -738,7 +738,8 @@ void ArtNetNode::Print()
738738
printf(" Port %-2u %-4u", static_cast<unsigned int>(port_index), static_cast<unsigned int>(kUniverse));
739739
if (node_.port[port_index].protocol == artnet::PortProtocol::kArtnet)
740740
{
741-
const auto kDestinationIp = (input_port_[port_index].destination_ip == 0 ? network::GetBroadcastIp() : input_port_[port_index].destination_ip);
741+
const auto kDestinationIp =
742+
(input_port_[port_index].destination_ip == 0 ? network::GetBroadcastIp() : input_port_[port_index].destination_ip);
742743
printf(" -> " IPSTR, IP2STR(kDestinationIp));
743744
}
744745
#if (ARTNET_VERSION >= 4)

lib-artnet/src/node/artnetnodehandlepoll.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "artnet.h"
4343
#include "hal_millis.h"
4444
#include "network.h"
45-
#include "firmware/debug/debug_debug.h"
45+
#include "firmware/debug/debug_debug.h"
4646

4747
template <uint8_t N> static inline void Uitoa(uint32_t v, uint8_t* p)
4848
{
@@ -141,7 +141,7 @@ union uip
141141
uint8_t u8[4];
142142
} static ip;
143143

144-
void ArtNetNode::ProcessPollReply(uint32_t port_index, [[maybe_unused]] uint32_t& num_ports_input, uint32_t& num_ports_output)
144+
void ArtNetNode::ProcessPollReply(uint32_t port_index)
145145
{
146146
if (node_.port[port_index].direction == dmxnode::PortDirection::kOutput)
147147
{
@@ -155,13 +155,11 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index, [[maybe_unused]] uint32_t
155155
output_port_[port_index].good_output = good_output;
156156
}
157157
#endif
158-
art_poll_reply_.PortTypes[0] = artnet::PortType::kOutputArtnet;
159158
art_poll_reply_.GoodOutput[0] = output_port_[port_index].good_output;
160159
art_poll_reply_.GoodOutputB[0] = output_port_[port_index].good_output_b;
161160
art_poll_reply_.GoodInput[0] = 0;
162161
art_poll_reply_.SwOut[0] = node_.port[port_index].sw;
163162
art_poll_reply_.SwIn[0] = 0;
164-
num_ports_output = 1;
165163
DEBUG_EXIT();
166164
return;
167165
}
@@ -175,24 +173,24 @@ void ArtNetNode::ProcessPollReply(uint32_t port_index, [[maybe_unused]] uint32_t
175173
input_port_[port_index].good_input |= artnet::GoodInput::kInputIsSacn;
176174
}
177175
#endif
178-
art_poll_reply_.PortTypes[0] = artnet::PortType::kInputArtnet;
179176
art_poll_reply_.GoodOutput[0] = 0;
180177
art_poll_reply_.GoodOutputB[0] = 0;
181178
art_poll_reply_.GoodInput[0] = input_port_[port_index].good_input;
182179
art_poll_reply_.SwOut[0] = 0;
183180
art_poll_reply_.SwIn[0] = node_.port[port_index].sw;
184-
num_ports_input = 1;
185181
DEBUG_EXIT();
186182
return;
187183
}
188184
#endif
189-
190-
num_ports_output = 0;
191-
num_ports_input = 0;
192185
}
193186

194187
void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, artnet::ArtPollQueue* queue)
195188
{
189+
if (node_.port[port_index].direction == dmxnode::PortDirection::kDisable)
190+
{
191+
return;
192+
}
193+
196194
ip.u32 = network::GetPrimaryIp();
197195
memcpy(art_poll_reply_.IPAddress, ip.u8, sizeof(art_poll_reply_.IPAddress));
198196
#if (ARTNET_VERSION >= 4)
@@ -213,6 +211,12 @@ void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, art
213211
art_poll_reply_.NetSwitch = node_.port[port_index].net_switch;
214212
art_poll_reply_.SubSwitch = node_.port[port_index].sub_switch;
215213
art_poll_reply_.bind_index = static_cast<uint8_t>(port_index + 1);
214+
art_poll_reply_.NumPortsLo = 1;
215+
#if defined(ARTNET_HAVE_DMXIN)
216+
art_poll_reply_.PortTypes[0] = artnet::PortType::kOutputArtnet | artnet::PortType::kInputArtnet;
217+
#else
218+
art_poll_reply_.PortTypes[0] = artnet::PortType::kOutputArtnet;
219+
#endif
216220

217221
const auto* shortname = DmxNode::Instance().GetShortName(port_index);
218222
memcpy(art_poll_reply_.ShortName, shortname, artnet::kShortNameLength);
@@ -227,24 +231,17 @@ void ArtNetNode::SendPollReply(uint32_t port_index, uint32_t destination_ip, art
227231
art_poll_reply_.UserHi = static_cast<uint8_t>(kUserData >> 8);
228232
}
229233

230-
uint32_t ports_output = 0;
231-
uint32_t ports_input = 0;
232-
ProcessPollReply(port_index, ports_input, ports_output);
233-
234-
art_poll_reply_.NumPortsLo = ports_input | ports_output;
234+
ProcessPollReply(port_index);
235235

236-
if (art_poll_reply_.NumPortsLo != 0)
236+
state_.art.poll_reply_count++;
237+
if (state_.art.poll_reply_count == 10000)
237238
{
238-
state_.art.poll_reply_count++;
239-
if (state_.art.poll_reply_count == 10000)
240-
{
241-
state_.art.poll_reply_count = 0;
242-
}
243-
244-
CreateNodeReport(art_poll_reply_.NodeReport, state_.report_code, state_.art.poll_reply_count);
245-
network::udp::Send(handle_, reinterpret_cast<const uint8_t*>(&art_poll_reply_), sizeof(artnet::ArtPollReply), destination_ip, artnet::kUdpPort);
239+
state_.art.poll_reply_count = 0;
246240
}
247241

242+
CreateNodeReport(art_poll_reply_.NodeReport, state_.report_code, state_.art.poll_reply_count);
243+
network::udp::Send(handle_, reinterpret_cast<const uint8_t*>(&art_poll_reply_), sizeof(artnet::ArtPollReply), destination_ip, artnet::kUdpPort);
244+
248245
state_.is_changed = false;
249246
}
250247

lib-dmxnode/include/dmxnode_nodetype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ enum class NodeType
4747

4848
inline constexpr const char* kNodeTypeNames[static_cast<uint32_t>(NodeType::kUndefined)] =
4949
{
50-
"Artnet",
50+
"Art-Net",
5151
"sACN E1.31",
5252
"DDP Display",
5353
"PixelPusher",

lib-dmxnode/include/dmxnode_outputtype.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file dmxnode_outputtype.h
33
*/
4-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
4+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,12 +21,11 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
2524

2625
#ifndef DMXNODE_OUTPUTTYPE_H_
2726
#define DMXNODE_OUTPUTTYPE_H_
2827

29-
#include <cstdint>
28+
#include <cstdint>
3029

3130
namespace dmxnode
3231
{
@@ -49,23 +48,8 @@ enum class OutputType
4948
kUndefined
5049
};
5150

52-
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] =
53-
{
54-
"DMX",
55-
"DMX/RDM",
56-
"Pixel",
57-
"Pixel/DMX",
58-
"PWM",
59-
"RGB Panel",
60-
"Serial",
61-
"OSC",
62-
"Monitor",
63-
"Stepper",
64-
"Player",
65-
"Art-Net",
66-
"Timecode",
67-
"None"
68-
};
51+
inline constexpr const char* kOutputTypeNames[static_cast<uint32_t>(OutputType::kUndefined)] = {
52+
"DMX", "DMX/RDM", "Pixel", "Pixel/DMX", "PWM", "RGB Panel", "Serial", "OSC", "Monitor", "Stepper", "Player", "Art-Net", "Timecode", "None"};
6953

7054
inline const char* GetOutputType(OutputType type)
7155
{
@@ -76,7 +60,7 @@ inline const char* GetOutputType(OutputType type)
7660

7761
return "Undefined";
7862
}
79-
} // namespace dmxnode
63+
} // namespace dmxnode
8064

8165
#if defined(OUTPUT_DMX_SEND) || defined(OUTPUT_DMX_SEND_MULTI)
8266
#define DMXNODE_OUTPUT_DMX
@@ -195,4 +179,4 @@ inline constexpr auto kOutputType = OutputType::kUndefined;
195179
#endif
196180
} // namespace dmxnode
197181

198-
#endif // DMXNODE_OUTPUTTYPE_H_
182+
#endif // DMXNODE_OUTPUTTYPE_H_

lib-gd32/include/gd32_dma_memcpy32.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_dma_memcpy32.h
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -37,10 +37,10 @@ void Init();
3737

3838
inline void StartDma(const void* destination, const void* source, uint32_t length)
3939
{
40+
#if !defined(GD32F4XX)
4041
assert((reinterpret_cast<uint32_t>(source) & 0x3) == 0);
4142
assert((reinterpret_cast<uint32_t>(destination) & 0x3) == 0);
4243

43-
#if !defined(GD32F4XX)
4444
uint32_t dma_chctl = DMA_CHCTL(DMA0, DMA_CH3);
4545
dma_chctl &= ~DMA_CHXCTL_CHEN;
4646
DMA_CHCTL(DMA0, DMA_CH3) = dma_chctl;
@@ -52,6 +52,9 @@ inline void StartDma(const void* destination, const void* source, uint32_t lengt
5252
dma_chctl |= (DMA_CHXCTL_CHEN | DMA_INT_FTF);
5353
DMA_CHCTL(DMA0, DMA_CH3) = dma_chctl;
5454
#else
55+
assert((reinterpret_cast<uint32_t>(source) & 0xF) == 0);
56+
assert((reinterpret_cast<uint32_t>(destination) & 0xF) == 0);
57+
5558
uint32_t dma_chctl = DMA_CHCTL(DMA1, DMA_CH0);
5659
dma_chctl &= ~DMA_CHXCTL_CHEN;
5760
DMA_CHCTL(DMA1, DMA_CH0) = dma_chctl;

lib-gd32/src/f/gd32_dma_memcpy32.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file gd32_dma_memcpy32.cpp
33
*
44
*/
5-
/* Copyright (C) 2024-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2024-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,6 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#include "gd32.h"
2726
#include "gd32_dma.h"
2827

2928
namespace dma::memcpy32
@@ -49,10 +48,12 @@ void Init()
4948
dma_circulation_disable(DMA0, DMA_CH3);
5049
dma_memory_to_memory_enable(DMA0, DMA_CH3);
5150

51+
#if !defined(DMA_MEMCPY32_DISABLE_IRQ)
5252
Gd32DmaInterruptFlagClear<DMA0, DMA_CH3, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_G)>();
5353

5454
NVIC_SetPriority(DMA0_Channel3_IRQn, 0);
5555
NVIC_EnableIRQ(DMA0_Channel3_IRQn);
56+
#endif
5657
#else
5758
rcu_periph_clock_enable(RCU_DMA1);
5859
dma_deinit(DMA1, DMA_CH0);
@@ -73,10 +74,12 @@ void Init()
7374

7475
dma_multi_data_mode_init(DMA1, DMA_CH0, &dma_init_parameter);
7576

76-
Gd32DmaInterruptFlagClear<DMA1, DMA_CH3, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_TAE)>();
77+
#if !defined(DMA_MEMCPY32_DISABLE_IRQ)
78+
Gd32DmaInterruptFlagClear<DMA1, DMA_CH0, (DMA_INT_FLAG_FTF | DMA_INT_FLAG_TAE)>();
7779

7880
NVIC_SetPriority(DMA1_Channel0_IRQn, 0);
7981
NVIC_EnableIRQ(DMA1_Channel0_IRQn);
8082
#endif
83+
#endif
8184
}
8285
} // namespace dma::memcpy32

lib-pixeldmx/src/json/pixeldmxparams.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
25+
2626
#include <cstdint>
2727
#include <algorithm>
2828

@@ -44,6 +44,7 @@
4444
#include "dmxnode.h"
4545
#include "dmxnode_nodetype.h"
4646
#include "pixeltestpattern.h"
47+
#include "firmware/debug/debug_debug.h"
4748

4849
static constexpr uint32_t kConfigMaxPorts = CONFIG_DMXNODE_PIXEL_MAX_PORTS;
4950

0 commit comments

Comments
 (0)