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

Fix UDP to allow receiving UDP Packets #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions parallax/sscp-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,20 @@ static void ICACHE_FLASH_ATTR tcp_recv_cb(void *arg, char *data, unsigned short
struct espconn *conn = (struct espconn *)arg;
sscp_connection *c = (sscp_connection *)conn->reverse;
sscp_log("TCP: %d received %d bytes", c->hdr.handle, len);
if (!(c->flags & CONNECTION_RXFULL)) {
i = c->rxCount;
if ((len + i)> SSCP_RX_BUFFER_MAX)
len = SSCP_RX_BUFFER_MAX - i;
i = c->rxCount;
if ((len + i)> SSCP_RX_BUFFER_MAX)
len = SSCP_RX_BUFFER_MAX - i;
if (len > 0) {
os_memcpy(c->rxBuffer + i, data, len);
c->rxCount = i + len;
c->rxIndex = 0;
if (c->rxCount >= SSCP_RX_BUFFER_MAX)
c->flags |= CONNECTION_RXFULL;
sscp_log("TCP: added %d bytes to buffer", len);
if (flashConfig.sscp_events)
if (flashConfig.sscp_events && !(c->flags & CONNECTION_RXFULL))
send_data_event(c, '!');
}
c->flags |= CONNECTION_RXFULL;
}

static void ICACHE_FLASH_ATTR tcp_recon_cb(void *arg, sint8 errType)
Expand Down
8 changes: 6 additions & 2 deletions parallax/sscp-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ void ICACHE_FLASH_ATTR udp_do_connect(int argc, char *argv[])
conn->state = ESPCONN_NONE;
conn->proto.udp = &c->d.udp.udp;
conn->proto.udp->remote_port = atoi(argv[2]);
if (conn->proto.udp->remote_port > 1023) {
conn->proto.udp->local_port = conn->proto.udp->remote_port;
}
conn->reverse = (void *)c;

espconn_regist_recvcb(conn, udp_recv_cb);
espconn_regist_sentcb(conn, udp_sent_cb);

if (isdigit((int)*argv[1]))
ipAddr.addr = ipaddr_addr(argv[1]);
ipAddr.addr = ipaddr_addr(argv[1]);
else {
switch (espconn_gethostbyname(conn, argv[1], &ipAddr, dns_cb)) {
case ESPCONN_OK:
Expand Down Expand Up @@ -124,7 +127,7 @@ static void ICACHE_FLASH_ATTR udp_recv_cb(void *arg, char *data, unsigned short
{
struct espconn *conn = (struct espconn *)arg;
sscp_connection *c = (sscp_connection *)conn->reverse;
sscp_log("UDP: %d received %d bytes", c->hdr.handle, len);
sscp_log("UDP Handle: %d received %d bytes", c->hdr.handle, len);
if (!(c->flags & CONNECTION_RXFULL)) {
if (len > SSCP_RX_BUFFER_MAX)
len = SSCP_RX_BUFFER_MAX;
Expand All @@ -143,6 +146,7 @@ static void ICACHE_FLASH_ATTR udp_sent_cb(void *arg)
sscp_connection *c = (sscp_connection *)conn->reverse;
c->flags &= ~CONNECTION_TXFULL;
c->flags |= CONNECTION_TXDONE;
sscp_log("UDP Handle: %d sent %d bytes", c->hdr.handle, c->rxCount);
sscp_sendResponse("S,0");
}

Expand Down