Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 supports the rsil and ws assembly commands #28

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading