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;
0 commit comments