Sitelet https://github.com/forkineye/ESPAsyncE131/commit/85da65bcbfb2a36e599438359f5d70ae9d77f39b
Skip to content

Commit 85da65b

Browse files
Added callback support.
1 parent 5c51167 commit 85da65b

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎ESPAsyncE131.cpp‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ const byte ESPAsyncE131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e
2525

2626
// Constructor
2727
ESPAsyncE131::ESPAsyncE131(uint8_t buffers) {
28-
pbuff = RingBuf_new(sizeof(e131_packet_t), buffers);
29-
30-
stats.num_packets = 0;
31-
stats.packet_errors = 0;
28+
29+
pbuff = nullptr;
30+
if (buffers)
31+
{
32+
pbuff = RingBuf_new (sizeof (e131_packet_t), buffers);
33+
}
34+
memset ((void*)&stats, 0x00, sizeof (stats));
3235
}
3336

3437
/////////////////////////////////////////////////////////
@@ -116,7 +119,9 @@ void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
116119

117120

118121
if (!error) {
119-
pbuff->add(pbuff, sbuff);
122+
if (PacketCallback) { (*PacketCallback) (sbuff, UserInfo); }
123+
if (pbuff) { pbuff->add (pbuff, sbuff); }
124+
120125
stats.num_packets++;
121126
stats.last_clientIP = _packet.remoteIP();
122127
stats.last_clientPort = _packet.remotePort();

‎ESPAsyncE131.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ESPAsyncE131 {
139139
e131_packet_t *sbuff; // Pointer to scratch packet buffer
140140
AsyncUDP udp; // AsyncUDP
141141
RingBuf *pbuff; // Ring Buffer of universe packet buffers
142+
void * UserInfo = nullptr;
142143

143144
// Internal Initializers
144145
bool initUnicast();
@@ -147,6 +148,8 @@ class ESPAsyncE131 {
147148
// Packet parser callback
148149
void parsePacket(AsyncUDPPacket _packet);
149150

151+
void (*PacketCallback)(e131_packet_t* ReceivedData, void* UserInfo) = nullptr;
152+
150153
public:
151154
e131_stats_t stats; // Statistics tracker
152155

@@ -158,7 +161,8 @@ class ESPAsyncE131 {
158161
// Ring buffer access
159162
inline bool isEmpty() { return pbuff->isEmpty(pbuff); }
160163
inline void *pull(e131_packet_t *packet) { return pbuff->pull(pbuff, packet); }
161-
164+
void RegisterCallback (void* _UserInfo, void (*cbFunction)(e131_packet_t*, void*)) { PacketCallback = cbFunction; UserInfo = _UserInfo; }
165+
162166
// Diag functions
163167
void dumpError(e131_error_t error);
164168
};

0 commit comments

Comments
 (0)