From 7df8a20df2c9e727e025698bda6e3d8a62dfa0e9 Mon Sep 17 00:00:00 2001 From: iseries1 Date: Wed, 21 Oct 2020 11:42:42 -0500 Subject: [PATCH 1/2] Fix UDP to allow receiving UDP Packets --- parallax/sscp-udp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/parallax/sscp-udp.c b/parallax/sscp-udp.c index 2f74258..c92003c 100644 --- a/parallax/sscp-udp.c +++ b/parallax/sscp-udp.c @@ -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: @@ -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; @@ -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"); } From b4e60289f2c571a8642cbb2e99db24fe3c59ca9d Mon Sep 17 00:00:00 2001 From: iseries1 Date: Sat, 20 Mar 2021 09:53:06 -0500 Subject: [PATCH 2/2] Fix TCP/IP Receive Data Flag --- parallax/sscp-tcp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/parallax/sscp-tcp.c b/parallax/sscp-tcp.c index 60571ae..69e8d8a 100644 --- a/parallax/sscp-tcp.c +++ b/parallax/sscp-tcp.c @@ -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)