@@ -565,93 +565,82 @@ void handleNotifications()
565565 return ;
566566 }
567567
568- if (!receiveDirect) return ;
569-
570- // TPM2.NET
571- if (udpIn[0 ] == 0x9c )
572- {
573- // WARNING: this code assumes that the final TMP2.NET payload is evenly distributed if using multiple packets (ie. frame size is constant)
574- // if the number of LEDs in your installation doesn't allow that, please include padding bytes at the end of the last packet
575- byte tpmType = udpIn[1 ];
576- if (tpmType == 0xaa ) { // TPM2.NET polling, expect answer
577- sendTPM2Ack (); return ;
578- }
579- if (tpmType != 0xda ) return ; // return if notTPM2.NET data
580-
581- realtimeIP = (isSupp) ? notifier2Udp.remoteIP () : notifierUdp.remoteIP ();
582- realtimeLock (realtimeTimeoutMs, REALTIME_MODE_TPM2NET);
583- if (realtimeOverride) return ;
584-
585- tpmPacketCount++; // increment the packet count
586- if (tpmPacketCount == 1 ) tpmPayloadFrameSize = (udpIn[2 ] << 8 ) + udpIn[3 ]; // save frame size for the whole payload if this is the first packet
587- byte packetNum = udpIn[4 ]; // starts with 1!
588- byte numPackets = udpIn[5 ];
589-
590- unsigned id = (tpmPayloadFrameSize/3 )*(packetNum-1 ); // start LED
591- unsigned totalLen = strip.getLengthTotal ();
592- for (size_t i = 6 ; i < tpmPayloadFrameSize + 4U && id < totalLen; i += 3 , id++) {
593- setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], 0 );
594- }
595- if (tpmPacketCount == numPackets) { // reset packet count and show if all packets were received
596- tpmPacketCount = 0 ;
597- if (useMainSegmentOnly) strip.trigger ();
598- else strip.show ();
599- }
600- return ;
601- }
568+ if (receiveDirect) {
569+ // TPM2.NET
570+ if (udpIn[0 ] == 0x9c ) {
571+ // WARNING: this code assumes that the final TMP2.NET payload is evenly distributed if using multiple packets (ie. frame size is constant)
572+ // if the number of LEDs in your installation doesn't allow that, please include padding bytes at the end of the last packet
573+ byte tpmType = udpIn[1 ];
574+ if (tpmType == 0xaa ) { // TPM2.NET polling, expect answer
575+ sendTPM2Ack (); return ;
576+ }
577+ if (tpmType != 0xda ) return ; // return if notTPM2.NET data
602578
603- // UDP realtime: 1 warls 2 drgb 3 drgbw 4 dnrgb 5 dnrgbw
604- if (udpIn[0 ] > 0 && udpIn[0 ] < 6 )
605- {
606- realtimeIP = (isSupp) ? notifier2Udp.remoteIP () : notifierUdp.remoteIP ();
607- DEBUG_PRINTLN (realtimeIP);
608- if (packetSize < 2 ) return ;
579+ realtimeIP = (isSupp) ? notifier2Udp.remoteIP () : notifierUdp.remoteIP ();
580+ realtimeLock (realtimeTimeoutMs, REALTIME_MODE_TPM2NET);
581+ if (realtimeOverride) return ;
609582
610- if (udpIn[1 ] == 0 ) {
611- realtimeTimeout = 0 ; // cancel realtime mode immediately
612- return ;
613- } else {
614- realtimeLock (udpIn[1 ]*1000 +1 , REALTIME_MODE_UDP);
615- }
616- if (realtimeOverride) return ;
583+ tpmPacketCount++; // increment the packet count
584+ if (tpmPacketCount == 1 ) tpmPayloadFrameSize = (udpIn[2 ] << 8 ) + udpIn[3 ]; // save frame size for the whole payload if this is the first packet
585+ byte packetNum = udpIn[4 ]; // starts with 1!
586+ byte numPackets = udpIn[5 ];
617587
618- unsigned totalLen = strip.getLengthTotal ();
619- if (udpIn[0 ] == 1 && packetSize > 5 ) // warls
620- {
621- for (size_t i = 2 ; i < packetSize -3 ; i += 4 )
622- {
623- setRealtimePixel (udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ], 0 );
624- }
625- } else if (udpIn[0 ] == 2 && packetSize > 4 ) // drgb
626- {
627- for (size_t i = 2 , id = 0 ; i < packetSize -2 && id < totalLen; i += 3 , id++)
628- {
588+ unsigned id = (tpmPayloadFrameSize/3 )*(packetNum-1 ); // start LED
589+ unsigned totalLen = strip.getLengthTotal ();
590+ for (size_t i = 6 ; i < tpmPayloadFrameSize + 4U && id < totalLen; i += 3 , id++) {
629591 setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], 0 );
630592 }
631- } else if (udpIn[0 ] == 3 && packetSize > 6 ) // drgbw
632- {
633- for (size_t i = 2 , id = 0 ; i < packetSize -3 && id < totalLen; i += 4 , id++)
634- {
635- setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ]);
593+ if (tpmPacketCount == numPackets) { // reset packet count and show if all packets were received
594+ tpmPacketCount = 0 ;
595+ if (useMainSegmentOnly) strip.trigger ();
596+ else strip.show ();
636597 }
637- } else if (udpIn[0 ] == 4 && packetSize > 7 ) // dnrgb
638- {
639- unsigned id = ((udpIn[3 ] << 0 ) & 0xFF ) + ((udpIn[2 ] << 8 ) & 0xFF00 );
640- for (size_t i = 4 ; i < packetSize -2 && id < totalLen; i += 3 , id++)
641- {
642- setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], 0 );
598+ return ;
599+ }
600+
601+ // UDP realtime: 1 warls 2 drgb 3 drgbw 4 dnrgb 5 dnrgbw
602+ if (udpIn[0 ] > 0 && udpIn[0 ] < 6 ) {
603+ realtimeIP = (isSupp) ? notifier2Udp.remoteIP () : notifierUdp.remoteIP ();
604+ DEBUG_PRINTLN (realtimeIP);
605+ if (packetSize < 2 ) return ;
606+
607+ if (udpIn[1 ] == 0 ) {
608+ realtimeTimeout = 0 ; // cancel realtime mode immediately
609+ return ;
610+ } else {
611+ realtimeLock (udpIn[1 ]*1000 +1 , REALTIME_MODE_UDP);
643612 }
644- } else if (udpIn[0 ] == 5 && packetSize > 8 ) // dnrgbw
645- {
646- unsigned id = ((udpIn[3 ] << 0 ) & 0xFF ) + ((udpIn[2 ] << 8 ) & 0xFF00 );
647- for (size_t i = 4 ; i < packetSize -2 && id < totalLen; i += 4 , id++)
648- {
649- setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ]);
613+ if (realtimeOverride) return ;
614+
615+ unsigned totalLen = strip.getLengthTotal ();
616+ if (udpIn[0 ] == 1 && packetSize > 5 ) { // warls
617+ for (size_t i = 2 ; i < packetSize -3 ; i += 4 ) {
618+ setRealtimePixel (udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ], 0 );
619+ }
620+ } else if (udpIn[0 ] == 2 && packetSize > 4 ) { // drgb
621+ for (size_t i = 2 , id = 0 ; i < packetSize -2 && id < totalLen; i += 3 , id++)
622+ {
623+ setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], 0 );
624+ }
625+ } else if (udpIn[0 ] == 3 && packetSize > 6 ) { // drgbw
626+ for (size_t i = 2 , id = 0 ; i < packetSize -3 && id < totalLen; i += 4 , id++) {
627+ setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ]);
628+ }
629+ } else if (udpIn[0 ] == 4 && packetSize > 7 ) { // dnrgb
630+ unsigned id = ((udpIn[3 ] << 0 ) & 0xFF ) + ((udpIn[2 ] << 8 ) & 0xFF00 );
631+ for (size_t i = 4 ; i < packetSize -2 && id < totalLen; i += 3 , id++) {
632+ setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], 0 );
633+ }
634+ } else if (udpIn[0 ] == 5 && packetSize > 8 ) { // dnrgbw
635+ unsigned id = ((udpIn[3 ] << 0 ) & 0xFF ) + ((udpIn[2 ] << 8 ) & 0xFF00 );
636+ for (size_t i = 4 ; i < packetSize -2 && id < totalLen; i += 4 , id++) {
637+ setRealtimePixel (id, udpIn[i], udpIn[i+1 ], udpIn[i+2 ], udpIn[i+3 ]);
638+ }
650639 }
640+ if (useMainSegmentOnly) strip.trigger ();
641+ else strip.show ();
642+ return ;
651643 }
652- if (useMainSegmentOnly) strip.trigger ();
653- else strip.show ();
654- return ;
655644 }
656645
657646 // API over UDP
@@ -669,6 +658,8 @@ void handleNotifications()
669658 }
670659 releaseJSONBufferLock ();
671660 }
661+
662+ UsermodManager::onUdpPacket (udpIn, packetSize);
672663}
673664
674665
0 commit comments