UDPProto: added "ack request" + response packets

The ACK request packet contains a sequence number which is echoed back
to the client in a simple UDP packet. By evaluating the difference
between sent and received sequence number, the client can control how
much data is buffered on the way to the ESP.
This commit is contained in:
Thomas Kolb 2019-12-30 12:19:00 +01:00
parent a9cfcb16d9
commit 6a71074b4b
2 changed files with 18 additions and 12 deletions

View file

@ -11,7 +11,8 @@ public:
SET_COLOUR = 0, SET_COLOUR = 0,
FADE_COLOUR = 1, FADE_COLOUR = 1,
ADD_COLOUR = 2, ADD_COLOUR = 2,
SET_FADESTEP = 3 SET_FADESTEP = 3,
ACK_REQUEST = 255
}; };
UDPProto(Fader *fader); UDPProto(Fader *fader);

View file

@ -27,12 +27,7 @@ bool UDPProto::check(void)
{ {
int packetSize = m_udpServer.parsePacket(); int packetSize = m_udpServer.parsePacket();
if(packetSize) { if(packetSize) {
byte buf[1024]; m_udpServer.flush();
int len;
while((len = m_udpServer.read(buf, 1024)) == 1024) {
// do nothing
}
m_udpServer.endPacket();
return true; return true;
} else { } else {
return false; return false;
@ -45,6 +40,8 @@ bool UDPProto::loop(void)
byte action, strip, module, r, g, b, w; byte action, strip, module, r, g, b, w;
int len; int len;
int32_t seq = -1;
int packetSize = m_udpServer.parsePacket(); int packetSize = m_udpServer.parsePacket();
if(packetSize) if(packetSize)
{ {
@ -87,16 +84,24 @@ bool UDPProto::loop(void)
m_fader->set_fadestep(r); // red channel contains the fadestep in this case m_fader->set_fadestep(r); // red channel contains the fadestep in this case
break; break;
case ACK_REQUEST:
seq = ((int32_t)r) << 8 | (int32_t)g;
default: default:
break; break;
} }
} }
// send a reply, to the IP address and port that sent us the packet we received // send a reply, to the IP address and port that sent us the packet we received
/* if(seq >= 0) {
ws2801UDP.beginPacket(ws2801UDP.remoteIP(), ws2801UDP.remotePort()); uint8_t data[2];
ws2801UDP.write("OK\n"); data[0] = (seq >> 8) & 0xFF;
*/ data[1] = seq & 0xFF;
m_udpServer.endPacket(); m_udpServer.beginPacket(m_udpServer.remoteIP(), m_udpServer.remotePort());
m_udpServer.write(data, 2);
m_udpServer.endPacket();
}
m_udpServer.flush();
return true; // processed a packet return true; // processed a packet
} else { } else {