Skip to content

Commit

Permalink
Merge pull request #28 from MartinMueller2003/master
Browse files Browse the repository at this point in the history
ESP32 supports the rsil and ws assembly commands
  • Loading branch information
forkineye authored Jun 26, 2024
2 parents 7ff3c94 + 6785d04 commit 9655aae
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
80 changes: 62 additions & 18 deletions ESPAsyncE131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,79 @@ bool ESPAsyncE131::initMulticast(uint16_t universe, uint8_t n) {
//
/////////////////////////////////////////////////////////

void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet)
{
e131_error_t error = ERROR_NONE;

sbuff = reinterpret_cast<e131_packet_t *>(_packet.data());
if (memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id)))
error = ERROR_ACN_ID;
if (htonl(sbuff->root_vector) != ESPAsyncE131::VECTOR_ROOT)
error = ERROR_VECTOR_ROOT;
if (htonl(sbuff->frame_vector) != ESPAsyncE131::VECTOR_FRAME)
error = ERROR_VECTOR_FRAME;
if (sbuff->dmp_vector != ESPAsyncE131::VECTOR_DMP)
error = ERROR_VECTOR_DMP;
if (sbuff->property_values[0] != 0)
error = ERROR_IGNORE;


if (!error) {

do // once
{
if (memcmp(sbuff->acn_id, ESPAsyncE131::ACN_ID, sizeof(sbuff->acn_id)))
{
error = ERROR_ACN_ID;
break;
}

if (htonl(sbuff->root_vector) != ESPAsyncE131::VECTOR_ROOT)
{
error = ERROR_VECTOR_ROOT;
break;
}

if (htonl(sbuff->frame_vector) != ESPAsyncE131::VECTOR_FRAME)
{
error = ERROR_VECTOR_FRAME;
break;
}

if (sbuff->dmp_vector != ESPAsyncE131::VECTOR_DMP)
{
error = ERROR_VECTOR_DMP;
break;
}

if (sbuff->property_values[0] != 0)
{
error = ERROR_IGNORE;
break;
}

// Are we looknig for a new source?
if((0 != LastAcceptedSource.PdusToIgnore) &&
(sbuff->priority < LastAcceptedSource.priority))
{
// pdu priority is from a lower priority source.
// do not accept until we do not hear from the
// higher priority source for a while.
if(0 != LastAcceptedSource.PdusToIgnore)
{
LastAcceptedSource.PdusToIgnore --;
}
error = ERROR_IGNORE;
break;
}

// remember the priority of the data source and
// set up the delay counter
LastAcceptedSource.PdusToIgnore = NumPdusToIgnoreBeforeSwitchingSources;
LastAcceptedSource.priority = sbuff->priority;

if (PacketCallback) { (*PacketCallback) (sbuff, UserInfo); }
if (pbuff) { pbuff->add (pbuff, sbuff); }

stats.num_packets++;
stats.last_clientIP = _packet.remoteIP();
stats.last_clientPort = _packet.remotePort();
stats.last_seen = millis();
} else if (error == ERROR_IGNORE) {
// Do nothing
} else {

} while(false);

if (error != ERROR_IGNORE)
{
if (Serial)
{
dumpError(error);
}
stats.packet_errors++;
}
}
Expand Down
7 changes: 7 additions & 0 deletions ESPAsyncE131.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class ESPAsyncE131 {
RingBuf *pbuff; // Ring Buffer of universe packet buffers
void * UserInfo = nullptr;

#define NumPdusToIgnoreBeforeSwitchingSources 5
struct LastAcceptedSource_t
{
uint8_t priority = 0;
uint8_t PdusToIgnore = 0;
} LastAcceptedSource;

// Internal Initializers
bool initUnicast();
bool initMulticast(uint16_t universe, uint8_t n = 1);
Expand Down
2 changes: 1 addition & 1 deletion RingBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define RB_ATOMIC_END }


#elif defined(ARDUINO_ARCH_ESP8266)
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#ifndef __STRINGIFY
#define __STRINGIFY(a) #a
#endif
Expand Down

0 comments on commit 9655aae

Please sign in to comment.