Merge pull request #1213 from Aircoookie/ddp-protocol

DDP protocol
This commit is contained in:
Aircoookie 2020-09-29 01:18:05 +02:00 committed by GitHub
commit 5d6e214e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 186 additions and 98 deletions

View File

@ -2,9 +2,14 @@
### Development versions after the 0.10.2 release ### Development versions after the 0.10.2 release
#### Build 2009290
- Added basic DDP protocol support
- Added Washing Machine effect (PR #1208)
#### Build 2009260 #### Build 2009260
- Added Loxone parser - Added Loxone parser (PR #1185)
- Added support for kelvin input via `K=` HTTP and `"col":[[val]]` JSON API calls - Added support for kelvin input via `K=` HTTP and `"col":[[val]]` JSON API calls
- Added supplementary UDP socket (#1205) - Added supplementary UDP socket (#1205)
- TMP2.net receivable by default - TMP2.net receivable by default

View File

@ -57,6 +57,7 @@
#define REALTIME_MODE_ADALIGHT 5 #define REALTIME_MODE_ADALIGHT 5
#define REALTIME_MODE_ARTNET 6 #define REALTIME_MODE_ARTNET 6
#define REALTIME_MODE_TPM2NET 7 #define REALTIME_MODE_TPM2NET 7
#define REALTIME_MODE_DDP 8
//realtime override modes //realtime override modes
#define REALTIME_OVERRIDE_NONE 0 #define REALTIME_OVERRIDE_NONE 0

View File

@ -5,7 +5,7 @@ function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-
function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.DA.value == 1) d.Sf.DA.value = 0; if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;} function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.DA.value == 1) d.Sf.DA.value = 0; if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;}
else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} } else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} }
function SP(){var p = d.Sf.DI.value; d.getElementById("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;} function SP(){var p = d.Sf.DI.value; d.getElementById("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;}
function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; }; SP();} function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; case 4048: d.Sf.DI.value = 4048; break; }; SP();}
function S(){GetV();SetVal();} function S(){GetV();SetVal();}
function GetV(){var d=document;} function GetV(){var d=document;}
</script> </script>
@ -47,6 +47,7 @@ Type:
<select name=DI onchange="SP(); adj();"> <select name=DI onchange="SP(); adj();">
<option value=5568>E1.31 (sACN)</option> <option value=5568>E1.31 (sACN)</option>
<option value=6454>Art-Net</option> <option value=6454>Art-Net</option>
<option value=4048>DDP</option>
<option value=0 selected>Custom port</option> <option value=0 selected>Custom port</option>
</select><br> </select><br>
<div id=xp>Port: <input name="EP" type="number" min="1" max="65535" value="5568" class="d5" required><br></div> <div id=xp>Port: <input name="EP" type="number" min="1" max="65535" value="5568" class="d5" required><br></div>

View File

@ -7,25 +7,66 @@
* E1.31 handler * E1.31 handler
*/ */
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, bool isArtnet){ //DDP protocol support, called by handleE131Packet
//E1.31 protocol support //handles RGB data only
void handleDDPPacket(e131_packet_t* p) {
int lastPushSeq = e131LastSequenceNumber[0];
//reject late packets belonging to previous frame (assuming 4 packets max. before push)
if (e131SkipOutOfSequence && lastPushSeq) {
int sn = p->sequenceNum & 0xF;
if (sn) {
if (lastPushSeq > 5) {
if (sn > (lastPushSeq -5) && sn < lastPushSeq) return;
} else {
if (sn > (10 + lastPushSeq) || sn < lastPushSeq) return;
}
}
}
uint32_t offsetLeds = htonl(p->channelOffset) /3;
uint16_t packetLeds = htons(p->dataLen) /3;
uint8_t* data = p->data;
uint16_t c = 0;
if (p->flags & DDP_TIMECODE_FLAG) c = 4; //packet has timecode flag, we do not support it, but data starts 4 bytes later
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_DDP);
for (uint16_t i = offsetLeds; i < offsetLeds + packetLeds; i++) {
setRealtimePixel(i, data[c++], data[c++], data[c++], 0);
}
bool push = p->flags & DDP_PUSH_FLAG;
if (push) {
e131NewData = true;
byte sn = p->sequenceNum & 0xF;
if (sn) e131LastSequenceNumber[0] = sn;
}
}
//E1.31 and Art-Net protocol support
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
uint16_t uni = 0, dmxChannels = 0; uint16_t uni = 0, dmxChannels = 0;
uint8_t* e131_data = nullptr; uint8_t* e131_data = nullptr;
uint8_t seq = 0, mde = REALTIME_MODE_E131; uint8_t seq = 0, mde = REALTIME_MODE_E131;
if (isArtnet) if (protocol == P_ARTNET)
{ {
uni = p->art_universe; uni = p->art_universe;
dmxChannels = htons(p->art_length); dmxChannels = htons(p->art_length);
e131_data = p->art_data; e131_data = p->art_data;
seq = p->art_sequence_number; seq = p->art_sequence_number;
mde = REALTIME_MODE_ARTNET; mde = REALTIME_MODE_ARTNET;
} else { } else if (protocol == P_E131) {
uni = htons(p->universe); uni = htons(p->universe);
dmxChannels = htons(p->property_value_count) -1; dmxChannels = htons(p->property_value_count) -1;
e131_data = p->property_values; e131_data = p->property_values;
seq = p->sequence_number; seq = p->sequence_number;
} else { //DDP
realtimeIP = clientIP;
handleDDPPacket(p);
return;
} }
#ifdef WLED_ENABLE_DMX #ifdef WLED_ENABLE_DMX
@ -133,7 +174,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, bool isArtnet){
} }
} else { } else {
// All subsequent universes start at the first channel. // All subsequent universes start at the first channel.
dmxOffset = isArtnet ? 0 : 1; dmxOffset = (protocol == P_ARTNET) ? 0 : 1;
uint16_t ledsInFirstUniverse = (MAX_CHANNELS_PER_UNIVERSE - DMXAddress) / 3; uint16_t ledsInFirstUniverse = (MAX_CHANNELS_PER_UNIVERSE - DMXAddress) / 3;
previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * MAX_LEDS_PER_UNIVERSE; previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * MAX_LEDS_PER_UNIVERSE;
} }

View File

@ -44,7 +44,7 @@ void initDMX();
void handleDMX(); void handleDMX();
//e131.cpp //e131.cpp
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, bool isArtnet); void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol);
//file.cpp //file.cpp
bool handleFileRead(AsyncWebServerRequest*, String path); bool handleFileRead(AsyncWebServerRequest*, String path);

View File

@ -357,7 +357,7 @@ onclick="Save()">Save</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_sync.htm, do not edit!! // Autogenerated from wled00/data/settings_sync.htm, do not edit!!
const char PAGE_settings_sync[] PROGMEM = R"=====(<!DOCTYPE html><html><head><meta name="viewport" content="width=500"><meta const char PAGE_settings_sync[] PROGMEM = R"=====(<!DOCTYPE html><html><head><meta name="viewport" content="width=500"><meta
charset="utf-8"><title>Sync Settings</title><script> charset="utf-8"><title>Sync Settings</title><script>
var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings")}function B(){window.open("/settings","_self")}function adj(){6454==d.Sf.DI.value?(1==d.Sf.DA.value&&(d.Sf.DA.value=0),1==d.Sf.EU.value&&(d.Sf.EU.value=0)):5568==d.Sf.DI.value&&(0==d.Sf.DA.value&&(d.Sf.DA.value=1),0==d.Sf.EU.value&&(d.Sf.EU.value=1))}function SP(){var e=d.Sf.DI.value;d.getElementById("xp").style.display=0<e?"none":"block",0<e&&(d.Sf.EP.value=e)}function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568:d.Sf.DI.value=5568;break;case 6454:d.Sf.DI.value=6454}SP()}function S(){GetV(),SetVal()}function GetV() { var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#sync-settings")}function B(){window.open("/settings","_self")}function adj(){6454==d.Sf.DI.value?(1==d.Sf.DA.value&&(d.Sf.DA.value=0),1==d.Sf.EU.value&&(d.Sf.EU.value=0)):5568==d.Sf.DI.value&&(0==d.Sf.DA.value&&(d.Sf.DA.value=1),0==d.Sf.EU.value&&(d.Sf.EU.value=1))}function SP(){var e=d.Sf.DI.value;d.getElementById("xp").style.display=0<e?"none":"block",0<e&&(d.Sf.EP.value=e)}function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568:d.Sf.DI.value=5568;break;case 6454:d.Sf.DI.value=6454;break;case 4048:d.Sf.DI.value=4048}SP()}function S(){GetV(),SetVal()}function GetV() {
%CSS%%SCSS%</head><body onload="S()"><form %CSS%%SCSS%</head><body onload="S()"><form
id="form_s" name="Sf" method="post"><div class="helpB"><button type="button" id="form_s" name="Sf" method="post"><div class="helpB"><button type="button"
onclick="H()">?</button></div><button type="button" onclick="B()">Back</button> onclick="H()">?</button></div><button type="button" onclick="B()">Back</button>
@ -383,18 +383,18 @@ Send notifications twice: <input type="checkbox" name="S2"><br><i>
Reboot required to apply changes.</i><h3>Realtime</h3>Receive UDP realtime: Reboot required to apply changes.</i><h3>Realtime</h3>Receive UDP realtime:
<input type="checkbox" name="RD"><br><br><i>Network DMX input</i><br>Type: <input type="checkbox" name="RD"><br><br><i>Network DMX input</i><br>Type:
<select name="DI" onchange="SP(),adj()"><option value="5568">E1.31 (sACN) <select name="DI" onchange="SP(),adj()"><option value="5568">E1.31 (sACN)
</option><option value="6454">Art-Net</option><option value="0" </option><option value="6454">Art-Net</option><option value="4048">DDP</option>
selected="selected">Custom port</option></select><br><div id="xp">Port: <input <option value="0" selected="selected">Custom port</option></select><br><div
name="EP" type="number" min="1" max="65535" value="5568" class="d5" required> id="xp">Port: <input name="EP" type="number" min="1" max="65535" value="5568"
<br></div>Multicast: <input type="checkbox" name="EM"><br>Start universe: <input class="d5" required><br></div>Multicast: <input type="checkbox" name="EM"><br>
name="EU" type="number" min="0" max="63999" required><br><i>Reboot required. Start universe: <input name="EU" type="number" min="0" max="63999" required><br>
</i> Check out <a href="https://github.com/ahodges9/LedFx" target="_blank">LedFx <i>Reboot required.</i> Check out <a href="https://github.com/ahodges9/LedFx"
</a>!<br>Skip out-of-sequence packets: <input type="checkbox" name="ES"><br> target="_blank">LedFx</a>!<br>Skip out-of-sequence packets: <input
DMX start address: <input name="DA" type="number" min="0" max="510" required> type="checkbox" name="ES"><br>DMX start address: <input name="DA" type="number"
<br>DMX mode: <select name="DM"><option value="0">Disabled</option><option min="0" max="510" required><br>DMX mode: <select name="DM"><option value="0">
value="1">Single RGB</option><option value="2">Single DRGB</option><option Disabled</option><option value="1">Single RGB</option><option value="2">
value="3">Effect</option><option value="4">Multi RGB</option><option value="5"> Single DRGB</option><option value="3">Effect</option><option value="4">Multi RGB
Dimmer + Multi RGB</option></select><br><a </option><option value="5">Dimmer + Multi RGB</option></select><br><a
href="https://github.com/Aircoookie/WLED/wiki/E1.31-DMX" target="_blank"> href="https://github.com/Aircoookie/WLED/wiki/E1.31-DMX" target="_blank">
E1.31 info</a><br>Timeout: <input name="ET" type="number" min="1" max="65000" E1.31 info</a><br>Timeout: <input name="ET" type="number" min="1" max="65000"
required> ms<br>Force max brightness: <input type="checkbox" name="FB"><br> required> ms<br>Force max brightness: <input type="checkbox" name="FB"><br>

View File

@ -392,6 +392,7 @@ void serializeInfo(JsonObject root)
case REALTIME_MODE_ADALIGHT: root["lm"] = F("USB Adalight/TPM2"); break; case REALTIME_MODE_ADALIGHT: root["lm"] = F("USB Adalight/TPM2"); break;
case REALTIME_MODE_ARTNET: root["lm"] = F("Art-Net"); break; case REALTIME_MODE_ARTNET: root["lm"] = F("Art-Net"); break;
case REALTIME_MODE_TPM2NET: root["lm"] = F("tpm2.net"); break; case REALTIME_MODE_TPM2NET: root["lm"] = F("tpm2.net"); break;
case REALTIME_MODE_DDP: root["lm"] = F("DDP"); break;
} }
if (realtimeIP[0] == 0) if (realtimeIP[0] == 0)

View File

@ -419,7 +419,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req)
byte main = strip.getMainSegmentId(); byte main = strip.getMainSegmentId();
if (main != prevMain) setValuesFromMainSeg(); if (main != prevMain) setValuesFromMainSeg();
bool segGiven = false;
pos = req.indexOf(F("SS=")); pos = req.indexOf(F("SS="));
if (pos > 0) { if (pos > 0) {
byte t = getNumVal(&req, pos); byte t = getNumVal(&req, pos);

View File

@ -59,8 +59,7 @@ bool ESPAsyncE131::initUnicast(uint16_t port) {
bool success = false; bool success = false;
if (udp.listen(port)) { if (udp.listen(port)) {
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this, udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this, std::placeholders::_1));
std::placeholders::_1));
success = true; success = true;
} }
return success; return success;
@ -84,8 +83,7 @@ bool ESPAsyncE131::initMulticast(uint16_t port, uint16_t universe, uint8_t n) {
igmp_joingroup(&ifaddr, &multicast_addr); igmp_joingroup(&ifaddr, &multicast_addr);
} }
udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this, udp.onPacket(std::bind(&ESPAsyncE131::parsePacket, this, std::placeholders::_1));
std::placeholders::_1));
success = true; success = true;
} }
@ -99,15 +97,16 @@ bool ESPAsyncE131::initMulticast(uint16_t port, uint16_t universe, uint8_t n) {
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) { void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
bool error = false, isArtnet = false; bool error = false;
uint8_t protocol = P_E131;
sbuff = reinterpret_cast<e131_packet_t *>(_packet.data()); sbuff = reinterpret_cast<e131_packet_t *>(_packet.data());
//E1.31 packet identifier ("ACS-E1.17") //E1.31 packet identifier ("ACS-E1.17")
if (memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id))) if (memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id)))
isArtnet = true; //not E1.31 protocol = P_ARTNET;
if (isArtnet) { if (protocol == P_ARTNET) {
if (memcmp(sbuff->art_id, ESPAsyncE131::ART_ID, sizeof(sbuff->art_id))) if (memcmp(sbuff->art_id, ESPAsyncE131::ART_ID, sizeof(sbuff->art_id)))
error = true; //not "Art-Net" error = true; //not "Art-Net"
if (sbuff->art_opcode != ARTNET_OPCODE_OPDMX) if (sbuff->art_opcode != ARTNET_OPCODE_OPDMX)
@ -123,7 +122,16 @@ void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
error = true; error = true;
} }
if (error && _packet.localPort() == DDP_DEFAULT_PORT) { //DDP packet
int pushSeq = 0;
error = false;
protocol = P_DDP;
//bool push = sbuff->flags & DDP_PUSH_FLAG;
//if (push) pushSeq = sbuff->sequenceNum;
//else if (sbuff->sequenceNum > pushSeq -5) error = true;
}
if (!error) { if (!error) {
_callback(sbuff, _packet.remoteIP(), isArtnet); _callback(sbuff, _packet.remoteIP(), protocol);
} }
} }

View File

@ -5,6 +5,9 @@
* Copyright (c) 2019 Shelby Merrick * Copyright (c) 2019 Shelby Merrick
* http://www.forkineye.com * http://www.forkineye.com
* *
* Project: ESPAsyncDDP - Asynchronous DDP library for Arduino ESP8266 and ESP32
* Copyright (c) 2019 Daniel Kulp
*
* This program is provided free for you to use in any way that you wish, * This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence * subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due. * is strongly suggested before using this code. Please give credit where due.
@ -45,9 +48,17 @@ typedef struct ip_addr ip4_addr_t;
// Defaults // Defaults
#define E131_DEFAULT_PORT 5568 #define E131_DEFAULT_PORT 5568
#define ARTNET_DEFAULT_PORT 6454 #define ARTNET_DEFAULT_PORT 6454
#define DDP_DEFAULT_PORT 4048
#define DDP_PUSH_FLAG 0x01
#define DDP_TIMECODE_FLAG 0x10
#define ARTNET_OPCODE_OPDMX 0x5000 #define ARTNET_OPCODE_OPDMX 0x5000
#define P_E131 0
#define P_ARTNET 1
#define P_DDP 2
// E1.31 Packet Offsets // E1.31 Packet Offsets
#define E131_ROOT_PREAMBLE_SIZE 0 #define E131_ROOT_PREAMBLE_SIZE 0
#define E131_ROOT_POSTAMBLE_SIZE 2 #define E131_ROOT_POSTAMBLE_SIZE 2
@ -116,11 +127,32 @@ typedef union {
uint8_t art_data[512]; uint8_t art_data[512];
} __attribute__((packed)); } __attribute__((packed));
uint8_t raw[638]; struct { //DDP Header
uint8_t flags;
uint8_t sequenceNum;
uint8_t dataType;
uint8_t destination;
uint32_t channelOffset;
uint16_t dataLen;
uint8_t data[1];
} __attribute__((packed));
/*struct { //DDP Time code Header (unsupported)
uint8_t flags;
uint8_t sequenceNum;
uint8_t dataType;
uint8_t destination;
uint32_t channelOffset;
uint16_t dataLen;
uint32_t timeCode;
uint8_t data[1];
} __attribute__((packed));*/
uint8_t raw[1458];
} e131_packet_t; } e131_packet_t;
// new packet callback // new packet callback
typedef void (*e131_packet_callback_function) (e131_packet_t* p, IPAddress clientIP, bool isArtnet); typedef void (*e131_packet_callback_function) (e131_packet_t* p, IPAddress clientIP, byte protocol);
class ESPAsyncE131 { class ESPAsyncE131 {
private: private:

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2009260 #define VERSION 2009290
// ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS). // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).