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