diff --git a/doc/UDP_led_driver.txt b/doc/UDP_led_driver.txt index 646abe21..f7a3f589 100644 --- a/doc/UDP_led_driver.txt +++ b/doc/UDP_led_driver.txt @@ -55,3 +55,12 @@ Packet Format protocol 2: 3: 1st led# of this update - low byte 4..n 3 bytes per LED as R, G, B +Packet Format protocol 3: (simple TPM2.net implementation) +0: 0x9C +1: 0xDA +2: number of databytes (leds * 3) - high byte +3: number of databytes (leds * 3) - low byte +4: fragment number (1-255) +5: number of fragments (1-255) +6..n: 3 bytes per LED as R, G, B +n+1: 0x36 diff --git a/libsrc/leddevice/LedDeviceUdp.cpp b/libsrc/leddevice/LedDeviceUdp.cpp index 129eb47f..1fc67647 100644 --- a/libsrc/leddevice/LedDeviceUdp.cpp +++ b/libsrc/leddevice/LedDeviceUdp.cpp @@ -155,6 +155,47 @@ int LedDeviceUdp::write(const std::vector & ledValues) } } + + if (ledprotocol == 3) { + udpPtr = 0; + unsigned int ledCtr = 0; + unsigned int fragments = 1; + unsigned int datasize = ledValues.size() * 3; + if (ledValues.size() > leds_per_pkt) { + fragments = (ledValues.size() / leds_per_pkt) + 1; + } + fragment_number = 1; + udpbuffer[udpPtr++] = 0x9C; + udpbuffer[udpPtr++] = 0xDA; + udpbuffer[udpPtr++] = datasize/256; // high byte + udpbuffer[udpPtr++] = datasize%256; // low byte + udpbuffer[udpPtr++] = fragment_number++; + udpbuffer[udpPtr++] = fragments; + + + for (const ColorRgb& color : ledValues) + { + if (udpPtr<4090) { + udpbuffer[udpPtr++] = color.red; + udpbuffer[udpPtr++] = color.green; + udpbuffer[udpPtr++] = color.blue; + } + ledCtr++; + if ( (ledCtr % leds_per_pkt == 0) || (ledCtr == ledValues.size()) ) { + udpbuffer[udpPtr++] = 0x36; + sendto(sockfd, udpbuffer, udpPtr, 0, p->ai_addr, p->ai_addrlen); + memset(udpbuffer, 0, sizeof udpbuffer); + udpPtr = 0; + udpbuffer[udpPtr++] = 0x9C; + udpbuffer[udpPtr++] = 0xDA; + udpbuffer[udpPtr++] = datasize/256; // high byte + udpbuffer[udpPtr++] = datasize%256; // low byte + udpbuffer[udpPtr++] = fragment_number++; + udpbuffer[udpPtr++] = fragments; + } + } + } + return 0; }