ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
InputDDP.h
Go to the documentation of this file.
1#pragma once
2/*
3* InputDDP.h
4*
5* Project: InputDDP - Asynchronous DDP library for Arduino ESP8266 and ESP32
6* Copyright (c) 2019, 2025 Daniel Kulp, Shelby Merrick
7*
8* This program is provided free for you to use in any way that you wish,
9* subject to the laws and regulations where you are using it. Due diligence
10* is strongly suggested before using this code. Please give credit where due.
11*
12* The Author makes no warranty of any kind, express or implied, with regard
13* to this program or the documentation contained in this document. The
14* Author shall not be liable in any event for incidental or consequential
15* damages in connection with, or arising out of, the furnishing, performance
16* or use of these programs.
17*
18*/
19
20#include "ESPixelStick.h"
21#include "InputCommon.hpp"
22
23#ifdef ESP32
24#include <WiFi.h>
25#include <AsyncUDP.h>
26#elif defined (ESP8266)
27#include <ESPAsyncUDP.h>
28#include <ESP8266WiFi.h>
29#include <ESP8266WiFiMulti.h>
30#else
31#error Platform not supported
32#endif
33
35{
36private:
37
38#define DDP_PORT 4048
39
40#define DDP_Header_t_LEN (sizeof(struct ddp_hdr_struct))
41#define DDP_MAX_DATALEN (480*3) // fits nicely in an ethernet packet
42
43#define DDP_FLAGS1_VERMASK 0xc0 // version mask
44#define DDP_FLAGS1_VER1 0x40 // version=1
45#define DDP_FLAGS1_PUSH 0x01
46#define DDP_FLAGS1_QUERY 0x02
47#define DDP_FLAGS1_REPLY 0x04
48#define DDP_FLAGS1_STORAGE 0x08
49#define DDP_FLAGS1_TIME 0x10
50#define DDP_FLAGS1_DATAMASK (DDP_FLAGS1_QUERY | DDP_FLAGS1_REPLY | DDP_FLAGS1_STORAGE | DDP_FLAGS1_TIME)
51#define DDP_FLAGS1_DATA 0x00
52
53#define DDP_ID_DEFAULT_ID 1
54#define DDP_ID_CONTROL 246
55#define DDP_ID_CONFIG 250
56#define DDP_ID_STATUS 251
57#define DDP_ID_DMXTRANSIT 254
58#define DDP_ID_ALL 255
59
60#define IsData(f) (DDP_FLAGS1_DATA == ((f) & DDP_FLAGS1_DATAMASK))
61#define IsPush(f) (DDP_FLAGS1_PUSH == ((f) & DDP_FLAGS1_PUSH))
62#define IsQuery(f) (DDP_FLAGS1_QUERY == ((f) & DDP_FLAGS1_QUERY))
63#define IsReply(f) (DDP_FLAGS1_REPLY == ((f) & DDP_FLAGS1_REPLY))
64#define IsStorage(f) (DDP_FLAGS1_STORAGE == ((f) & DDP_FLAGS1_STORAGE))
65#define IsTime(f) (DDP_FLAGS1_TIME == ((f) & DDP_FLAGS1_TIME))
66
67 struct __attribute__ ((packed)) DDP_Header_t
68 {
69 byte flags1;
70 byte flags2;
71 byte type;
72 byte id;
73 uint32_t channelOffset;
74 uint16_t dataLen;
75 };
76
77 struct __attribute__ ((packed)) DDP_packet_t
78 {
79 DDP_Header_t header; // header may or may not be time code
80 byte data[DDP_MAX_DATALEN];
81 };
82
83 struct __attribute__ ((packed)) DDP_TimeCode_packet_t
84 {
85 DDP_Header_t header; // header may or may not be time code
86 uint32_t TimeCode;
87 byte data[DDP_MAX_DATALEN - sizeof(TimeCode)];
88 };
89
90 struct __attribute__ ((packed)) DDP_stats_t
91 {
92 uint32_t packetsReceived;
93 uint64_t bytesReceived;
94 uint32_t errors;
95 };
96 String lastError;
97
98 AsyncUDP * udp = nullptr; // UDP
100 bool suspend = false;
101 DDP_stats_t stats; // Statistics tracker
102
103 void NetworkStateChanged (bool NetwokState);
104
105 // Packet parser callback
106 void ProcessReceivedUdpPacket (AsyncUDPPacket _packet);
107 void ProcessReceivedData (DDP_packet_t & Packet);
108 void ProcessReceivedQuery ();
109
116
124
126
127public:
128
129 c_InputDDP (c_InputMgr::e_InputChannelIds NewInputChannelId,
130 c_InputMgr::e_InputType NewChannelType,
131 uint32_t BufferSize);
132
133 virtual ~c_InputDDP ();
134
135 // Generic UDP listener, no physical or IP configuration
136 void Begin ();
137 bool SetConfig (JsonObject& jsonConfig);
138 void GetConfig (JsonObject& jsonConfig);
139 void GetStatus (JsonObject& jsonStatus);
140 void Process ();
141 void GetDriverName (String& sDriverName) { sDriverName = "DDP"; }
142 void SetBufferInfo (uint32_t BufferSize);
144
145};
RecordType type
Definition EFUpdate.h:0
#define DDP_MAX_DATALEN
Definition InputDDP.h:41
Definition InputCommon.hpp:27
bool HasBeenInitialized
Definition InputCommon.hpp:51
Definition InputDDP.h:35
c_InputDDP(c_InputMgr::e_InputChannelIds NewInputChannelId, c_InputMgr::e_InputType NewChannelType, uint32_t BufferSize)
Definition InputDDP.cpp:34
PacketBuffer_t PacketBuffer
Definition InputDDP.h:125
void NetworkStateChanged(bool NetwokState)
Definition InputDDP.cpp:132
void ProcessReceivedQuery()
Definition InputDDP.cpp:292
PacketBufferStatus_t
Definition InputDDP.h:111
@ BufferIsBeingProcessed
Definition InputDDP.h:114
@ BufferIsFilled
Definition InputDDP.h:113
@ BufferIsAvailable
Definition InputDDP.h:112
void GetDriverName(String &sDriverName)
get the name for the instantiated driver
Definition InputDDP.h:141
bool SetConfig(JsonObject &jsonConfig)
Set a new config in the driver.
Definition InputDDP.cpp:107
void Process()
Call from loop(), renders Input data.
Definition InputDDP.cpp:196
void ProcessReceivedData(DDP_packet_t &Packet)
Definition InputDDP.cpp:241
bool isShutDownRebootNeeded()
Definition InputDDP.h:143
void GetStatus(JsonObject &jsonStatus)
Definition InputDDP.cpp:89
bool suspend
Definition InputDDP.h:100
void GetConfig(JsonObject &jsonConfig)
Get the current config used by the driver.
Definition InputDDP.cpp:79
AsyncUDP * udp
Definition InputDDP.h:98
void ProcessReceivedUdpPacket(AsyncUDPPacket _packet)
Definition InputDDP.cpp:150
virtual ~c_InputDDP()
Definition InputDDP.cpp:48
void SetBufferInfo(uint32_t BufferSize)
Definition InputDDP.cpp:118
DDP_stats_t stats
Definition InputDDP.h:101
uint8_t lastReceivedSequenceNumber
Definition InputDDP.h:99
String lastError
Definition InputDDP.h:96
void Begin()
set up the operating environment based on the current config (or defaults)
Definition InputDDP.cpp:59
e_InputType
Definition InputMgr.hpp:71
e_InputChannelIds
Definition InputMgr.hpp:40
uint8_t id[8]
Definition fseq.h:13
uint8_t header[4]
Definition fseq.h:0
struct FSEQParsedRangeEntry __attribute__
uint8_t flags2
Definition fseq.h:12
Definition InputDDP.h:118
uint16_t ResponsePort
Definition InputDDP.h:122
DDP_packet_t Packet
Definition InputDDP.h:120
PacketBufferStatus_t PacketBufferStatus
Definition InputDDP.h:119
IPAddress ResponseAddress
Definition InputDDP.h:121