added simple TPM2.net support to UDP output (#627)

Former-commit-id: 59356ae53c90e178a4bc198c6babc5832bb15d12
This commit is contained in:
recliq 2016-05-15 18:39:26 +02:00 committed by brindosch
parent a960894d14
commit 8310a6d9d0
2 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -155,6 +155,47 @@ int LedDeviceUdp::write(const std::vector<ColorRgb> & 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;
}