3939#include " firmware/debug/debug_dump.h"
4040#include " firmware/debug/debug_debug.h"
4141
42- using namespace ddp ;
43-
44- namespace json
45- {
42+ namespace json {
4643static constexpr char kStart [] = " {\" status\" :{\" update\" :\" change\" ,\" state\" :\" up\" }}" ;
4744static constexpr char kDiscoverReply [] = " {\" status\" :{\" man\" :\" %s\" ,\" mod\" :\" Pixel\" ,\" ver\" :\" 1.0\" ,\" mac\" :\" %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\" }}" ;
4845static constexpr char kConfigReply [] =
@@ -73,14 +70,12 @@ static constexpr char kConfigReply[] =
7370#endif
7471 " ]}}" ;
7572
76- namespace size
77- {
73+ namespace size {
7874static constexpr auto kStart = sizeof (json::kStart ) - 1U ;
7975} // namespace size
8076} // namespace json
8177
82- DdpDisplay::DdpDisplay ()
83- {
78+ DdpDisplay::DdpDisplay () {
8479 DEBUG_ENTRY ();
8580 assert (s_this == nullptr );
8681 s_this = this ;
@@ -90,21 +85,18 @@ DdpDisplay::DdpDisplay()
9085 DEBUG_EXIT ();
9186}
9287
93- DdpDisplay::~DdpDisplay ()
94- {
88+ DdpDisplay::~DdpDisplay () {
9589 DEBUG_ENTRY ();
9690
9791 Stop ();
9892
9993 DEBUG_EXIT ();
10094}
10195
102- void DdpDisplay::CalculateOffsets ()
103- {
96+ void DdpDisplay::CalculateOffsets () {
10497 uint32_t sum = 0 ;
10598
106- for (uint32_t pixel_port_index = 0 ; pixel_port_index < ddpdisplay::configuration::pixel::kMaxPorts ; pixel_port_index++)
107- {
99+ for (uint32_t pixel_port_index = 0 ; pixel_port_index < ddpdisplay::configuration::pixel::kMaxPorts ; pixel_port_index++) {
108100 sum = sum + strip_data_length_;
109101 s_offset_compare[pixel_port_index] = sum;
110102 }
@@ -119,8 +111,7 @@ void DdpDisplay::CalculateOffsets()
119111#pragma GCC diagnostic ignored "-Wtype-limits" // FIXME ignored "-Wtype-limits"
120112#endif
121113
122- for (uint32_t dmx_port_index = 0 ; dmx_port_index < ddpdisplay::configuration::dmx::kMaxPorts ; dmx_port_index++)
123- {
114+ for (uint32_t dmx_port_index = 0 ; dmx_port_index < ddpdisplay::configuration::dmx::kMaxPorts ; dmx_port_index++) {
124115 sum = sum + dmxnode::kUniverseSize ;
125116 const auto kIndexOffset = dmx_port_index + ddpdisplay::configuration::pixel::kMaxPorts ;
126117 s_offset_compare[kIndexOffset ] = sum;
@@ -131,8 +122,7 @@ void DdpDisplay::CalculateOffsets()
131122#endif
132123}
133124
134- void DdpDisplay::Start ()
135- {
125+ void DdpDisplay::Start () {
136126 DEBUG_ENTRY ();
137127 assert (dmxnode_output_type_ != nullptr );
138128
@@ -143,23 +133,21 @@ void DdpDisplay::Start()
143133
144134 ddp::Packet packet;
145135
146- memset (&packet.header , 0 , HEADER_LEN );
147- packet.header .flags1 = flags1::VER1 | flags1::REPLY ;
148- packet.header .id = id::STATUS ;
136+ memset (&packet.header , 0 , ddp:: HEADER_LEN );
137+ packet.header .flags1 = ddp:: flags1::VER1 | ddp:: flags1::REPLY ;
138+ packet.header .id = ddp:: id::STATUS ;
149139 packet.header .len [1 ] = json::size::kStart ;
150140 memcpy (packet.data , json::kStart , json::size::kStart );
151141
152- network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), HEADER_LEN + json::size::kStart , network::GetPrimaryIp () | ~(network::GetNetmask ()),
153- ddp::kUdpPort );
142+ network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), ddp::HEADER_LEN + json::size::kStart , network::GetPrimaryIp () | ~(network::GetNetmask ()), ddp::kUdpPort );
154143
155- debug::Dump (&packet, HEADER_LEN + json::size::kStart );
144+ debug::Dump (&packet, ddp:: HEADER_LEN + json::size::kStart );
156145
157146 CalculateOffsets ();
158147 DEBUG_EXIT ();
159148}
160149
161- void DdpDisplay::Stop ()
162- {
150+ void DdpDisplay::Stop () {
163151 DEBUG_ENTRY ();
164152
165153 network::apps::mdns::ServiceRecordDelete (network::apps::mdns::Services::kDdp );
@@ -170,76 +158,65 @@ void DdpDisplay::Stop()
170158 DEBUG_EXIT ();
171159}
172160
173- void DdpDisplay::HandleQuery ()
174- {
161+ void DdpDisplay::HandleQuery () {
175162 DEBUG_ENTRY ();
176163
177164 auto * packet = reinterpret_cast <ddp::Packet*>(receive_buffer_);
178165
179- if ((packet->header .id & id::STATUS ) == id::STATUS )
180- {
166+ if ((packet->header .id & ddp::id::STATUS ) == ddp::id::STATUS ) {
181167 DEBUG_PUTS (" id::STATUS" );
182168
183- const auto kLength =
184- snprintf (reinterpret_cast <char *>(packet->data ), network::udp::kDataSize - 1 , json::kDiscoverReply , board::Website (), MAC2STR (mac_address_));
169+ const auto kLength = snprintf (reinterpret_cast <char *>(packet->data ), network::udp::kDataSize - 1 , json::kDiscoverReply , board::Website (), MAC2STR (mac_address_));
185170
186- packet->header .flags1 = flags1::VER1 | flags1::REPLY | flags1::PUSH ;
171+ packet->header .flags1 = ddp:: flags1::VER1 | ddp:: flags1::REPLY | ddp:: flags1::PUSH ;
187172 packet->header .len [0 ] = static_cast <uint8_t >(kLength >> 8 );
188173 packet->header .len [1 ] = static_cast <uint8_t >(kLength );
189174
190- network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), (HEADER_LEN + static_cast <uint16_t >(kLength )),
191- network::GetPrimaryIp () | ~(network::GetNetmask ()), ddp::kUdpPort );
175+ network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), (ddp::HEADER_LEN + static_cast <uint16_t >(kLength )), network::GetPrimaryIp () | ~(network::GetNetmask ()), ddp::kUdpPort );
192176 }
193177
194- if ((packet->header .id & id::STATUS ) == id::CONFIG )
195- {
178+ if ((packet->header .id & ddp::id::STATUS ) == ddp::id::CONFIG ) {
196179 DEBUG_PUTS (" id::CONFIG" );
197180
198181 const auto kLength =
199- snprintf (reinterpret_cast <char *>(packet->data ), network::udp::kDataSize - 1 , json::kConfigReply , IP2STR (network::GetPrimaryIp ()),
200- IP2STR ( network::GetNetmask ()), IP2STR ( network::GetGatewayIp ()), active_ports_ > 0 ? count_ : 0 , active_ports_ > 1 ? count_ : 0 ,
182+ static_cast < uint32_t >( snprintf (reinterpret_cast <char *>(packet->data ), network::udp::kDataSize - 1 , json::kConfigReply , IP2STR (network::GetPrimaryIp ()), IP2STR ( network::GetNetmask ()), IP2STR ( network::GetGatewayIp ()),
183+ active_ports_ > 0 ? count_ : 0 , active_ports_ > 1 ? count_ : 0 ,
201184#if CONFIG_DMXNODE_PIXEL_MAX_PORTS > 2
202- active_ports_ > 2 ? count_ : 0 , active_ports_ > 3 ? count_ : 0 , active_ports_ > 4 ? count_ : 0 , active_ports_ > 5 ? count_ : 0 ,
203- active_ports_ > 6 ? count_ : 0 , active_ports_ > 7 ? count_ : 0 ,
185+ active_ports_ > 2 ? count_ : 0 , active_ports_ > 3 ? count_ : 0 , active_ports_ > 4 ? count_ : 0 , active_ports_ > 5 ? count_ : 0 , active_ports_ > 6 ? count_ : 0 , active_ports_ > 7 ? count_ : 0 ,
204186#endif
205187#if CONFIG_DMXNODE_PIXEL_MAX_PORTS == 16
206- active_ports_ > 8 ? count_ : 0 , active_ports_ > 9 ? count_ : 0 , active_ports_ > 10 ? count_ : 0 , active_ports_ > 11 ? count_ : 0 ,
207- active_ports_ > 12 ? count_ : 0 , active_ports_ > 13 ? count_ : 0 , active_ports_ > 14 ? count_ : 0 , active_ports_ > 15 ? count_ : 0 ,
188+ active_ports_ > 8 ? count_ : 0 , active_ports_ > 9 ? count_ : 0 , active_ports_ > 10 ? count_ : 0 , active_ports_ > 11 ? count_ : 0 , active_ports_ > 12 ? count_ : 0 , active_ports_ > 13 ? count_ : 0 ,
189+ active_ports_ > 14 ? count_ : 0 , active_ports_ > 15 ? count_ : 0 ,
208190#endif
209- ddpdisplay::configuration::dmx::kMaxPorts == 0 ? 0 : dmxnode::kUniverseSize ,
210- ddpdisplay::configuration::dmx::kMaxPorts == 0 ? 0 : dmxnode::kUniverseSize );
191+ ddpdisplay::configuration::dmx::kMaxPorts == 0 ? 0 : dmxnode::kUniverseSize , ddpdisplay::configuration::dmx::kMaxPorts == 0 ? 0 : dmxnode::kUniverseSize ));
211192
212- packet->header .flags1 = flags1::VER1 | flags1::REPLY | flags1::PUSH ;
193+ packet->header .flags1 = ddp:: flags1::VER1 | ddp:: flags1::REPLY | ddp:: flags1::PUSH ;
213194 packet->header .len [0 ] = static_cast <uint8_t >(kLength >> 8 );
214195 packet->header .len [1 ] = static_cast <uint8_t >(kLength );
215196
216- network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), HEADER_LEN + kLength , from_ip_, ddp::kUdpPort );
197+ network::udp::Send (handle_, reinterpret_cast <const uint8_t *>(&packet), ddp:: HEADER_LEN + kLength , from_ip_, ddp::kUdpPort );
217198
218- debug::Dump (&packet, HEADER_LEN + kLength );
199+ debug::Dump (&packet, ddp:: HEADER_LEN + kLength );
219200 }
220201
221202 DEBUG_EXIT ();
222203}
223204
224- void DdpDisplay::HandleData ()
225- {
205+ void DdpDisplay::HandleData () {
226206 const auto * const kPacket = reinterpret_cast <ddp::Packet*>(receive_buffer_);
227- auto offset = static_cast <uint32_t >((kPacket ->header .offset [0 ] << 24 ) | (kPacket ->header .offset [1 ] << 16 ) | (kPacket ->header .offset [2 ] << 8 ) |
228- kPacket ->header .offset [3 ]);
207+ auto offset = static_cast <uint32_t >((kPacket ->header .offset [0 ] << 24 ) | (kPacket ->header .offset [1 ] << 16 ) | (kPacket ->header .offset [2 ] << 8 ) | kPacket ->header .offset [3 ]);
229208 auto length = ((static_cast <uint32_t >(kPacket ->header .len [0 ]) << 8 ) | kPacket ->header .len [1 ]);
230209 const auto * const kReceivedData = kPacket ->data ;
231210
232211 uint32_t data_source_index = 0 ;
233212 uint32_t receiver_buffer_index = 0 ;
234213
235- for (uint32_t port_index = 0 ; (port_index < active_ports_) && (length != 0 ); port_index++)
236- {
214+ for (uint32_t port_index = 0 ; (port_index < active_ports_) && (length != 0 ); port_index++) {
237215 data_source_index = port_index * 4 ;
238216
239217 const auto kOutportIndexEnd = data_source_index + 4 ;
240218
241- while ((offset < s_offset_compare[port_index]) && (data_source_index < kOutportIndexEnd ))
242- {
219+ while ((offset < s_offset_compare[port_index]) && (data_source_index < kOutportIndexEnd )) {
243220 const auto kOutLength = std::min (std::min (length, dmxnode_output_type_data_max_length_), strip_data_length_);
244221
245222 dmxnode::Data::SetSourceA (data_source_index, &kReceivedData [receiver_buffer_index], kOutLength );
@@ -260,10 +237,8 @@ void DdpDisplay::HandleData()
260237
261238 DEBUG_PRINTF (" nLightSetPortIndex=%u" , data_source_index);
262239
263- for (uint32_t port_index = ddpdisplay::configuration::pixel::kMaxPorts ; (port_index < ddpdisplay::configuration::kMaxPorts ) && (length != 0 ); port_index++)
264- {
265- if (offset < s_offset_compare[port_index])
266- {
240+ for (uint32_t port_index = ddpdisplay::configuration::pixel::kMaxPorts ; (port_index < ddpdisplay::configuration::kMaxPorts ) && (length != 0 ); port_index++) {
241+ if (offset < s_offset_compare[port_index]) {
267242 const auto kLength = std::min (length, dmxnode::kUniverseSize );
268243
269244 // DEBUG_PRINTF("==> nPortIndex=%u, nOffset=%u, nLength=%u, nLightSetLength=%u, nLightSetPortIndex=%u", nPortIndex, nOffset, nLength,
@@ -282,52 +257,43 @@ void DdpDisplay::HandleData()
282257 }
283258 }
284259
285- if ((kPacket ->header .flags1 & flags1::PUSH ) == flags1::PUSH )
286- {
287- for (uint32_t data_output_port_index = 0 ; data_output_port_index < ddpdisplay::lightset::kMaxPorts ; data_output_port_index++)
288- {
260+ if ((kPacket ->header .flags1 & ddp::flags1::PUSH ) == ddp::flags1::PUSH ) {
261+ for (uint32_t data_output_port_index = 0 ; data_output_port_index < ddpdisplay::lightset::kMaxPorts ; data_output_port_index++) {
289262 dmxnode::DataOutput (dmxnode_output_type_, data_output_port_index);
290263 dmxnode::Data::ClearLength (data_output_port_index);
291264 }
292265 }
293266}
294267
295- void DdpDisplay::Input (const uint8_t * buffer, uint32_t size, [[maybe_unused]] uint32_t from_ip, [[maybe_unused]] uint16_t from_port)
296- {
297- if (__builtin_expect ((size < HEADER_LEN ), 0 ))
298- {
268+ void DdpDisplay::Input (const uint8_t * buffer, uint32_t size, [[maybe_unused]] uint32_t from_ip, [[maybe_unused]] uint16_t from_port) {
269+ if (__builtin_expect ((size < ddp::HEADER_LEN ), 0 )) {
299270 return ;
300271 }
301272
302- if (from_ip_ == network::GetPrimaryIp ())
303- {
273+ if (from_ip_ == network::GetPrimaryIp ()) {
304274 DEBUG_PUTS (" Own message" );
305275 return ;
306276 }
307277
308278 const auto * packet = reinterpret_cast <const ddp::Packet*>(buffer);
309279
310- if ((packet->header .flags1 & flags1::VER_MASK ) != flags1::VER1 )
311- {
280+ if ((packet->header .flags1 & ddp::flags1::VER_MASK ) != ddp::flags1::VER1 ) {
312281 DEBUG_PUTS (" Invalid version" );
313282 return ;
314283 }
315284
316- if (packet->header .id == id::DISPLAY )
317- {
285+ if (packet->header .id == ddp::id::DISPLAY ) {
318286 HandleData ();
319287 return ;
320288 }
321289
322- if ((packet->header .flags1 & flags1::QUERY ) == flags1::QUERY )
323- {
290+ if ((packet->header .flags1 & ddp::flags1::QUERY ) == ddp::flags1::QUERY ) {
324291 HandleQuery ();
325292 return ;
326293 }
327294}
328295
329- void DdpDisplay::Print ()
330- {
296+ void DdpDisplay::Print () {
331297 puts (" DDP Display" );
332298 printf (" Count : %u\n " , count_);
333299 printf (" Channels per pixel: %u\n " , GetChannelsPerPixel ());
0 commit comments