Skip to content

Commit

Permalink
Remove support for optional manual TCP receive - all requests are don…
Browse files Browse the repository at this point in the history
…e manually from now on.
  • Loading branch information
MaJerle committed Aug 27, 2022
1 parent db52e39 commit a7bb54b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 146 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
"lwevt_opt.h": "c",
"cli.h": "c",
"windows.h": "c",
"lwesp_private.h": "c"
"lwesp_private.h": "c",
"lwesp_ll.h": "c",
"lwesp.h": "c",
"lwesp_includes.h": "c",
"lwesp_pbuf.h": "c",
"lwesp_opt.h": "c",
"lwesp_typedefs.h": "c",
"lwesp_opts.h": "c"
},
"esbonio.sphinx.confDir": ""
}
2 changes: 0 additions & 2 deletions dev/lwesp_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@

#define LWESP_CFG_RESET_ON_INIT 1

#define LWESP_CFG_CONN_MANUAL_TCP_RECEIVE 1

#define LWESP_CFG_ACCESS_POINT_STRUCT_FULL_FIELDS 1
#define LWESP_CFG_LIST_CMD 1

Expand Down
8 changes: 0 additions & 8 deletions lwesp/src/api/lwesp_netconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ netconn_evt(lwesp_evt_t* evt) {
nc = lwesp_conn_get_arg(conn); /* Get API from connection */
pbuf = lwesp_evt_conn_recv_get_buff(evt); /* Get received buff */

#if !LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
lwesp_conn_recved(conn, pbuf); /* Notify stack about received data */
#endif /* !LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

lwesp_pbuf_ref(pbuf); /* Increase reference counter */
if (nc == NULL || !lwesp_sys_mbox_isvalid(&nc->mbox_receive)
|| !lwesp_sys_mbox_putnow(&nc->mbox_receive, pbuf)) {
Expand All @@ -222,12 +218,10 @@ netconn_evt(lwesp_evt_t* evt) {
return lwespOKIGNOREMORE; /* Return OK to free the memory and ignore further data */
}
++nc->mbox_receive_entries; /* Increase number of packets in receive mbox */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
/* Check against 1 less to still allow potential close event to be written to queue */
if (nc->mbox_receive_entries >= (LWESP_CFG_NETCONN_RECEIVE_QUEUE_LEN - 1)) {
conn->status.f.receive_blocked = 1; /* Block reading more data */
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

++nc->rcv_packets; /* Increase number of packets received */
LWESP_DEBUGF(LWESP_CFG_DBG_NETCONN | LWESP_DBG_TYPE_TRACE,
Expand Down Expand Up @@ -756,14 +750,12 @@ lwesp_netconn_receive(lwesp_netconn_p nc, lwesp_pbuf_p* pbuf) {
*pbuf = NULL; /* Reset pbuf */
return lwespCLOSED;
}
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
else {
lwesp_core_lock();
nc->conn->status.f.receive_blocked = 0; /* Resume reading more data */
lwesp_conn_recved(nc->conn, *pbuf); /* Notify stack about received data */
lwesp_core_unlock();
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
return lwespOK; /* We have data available */
}

Expand Down
16 changes: 0 additions & 16 deletions lwesp/src/include/lwesp/lwesp_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,6 @@
#define LWESP_CFG_CONN_POLL_INTERVAL 500
#endif

/**
* \brief Enables `1` or disables `0` manual `TCP` data receive from ESP device
*
* Normally ESP automatically sends received TCP data to host device
* in async mode. When host device is slow or if there is memory constrain,
* it may happen that processing cannot handle all received data.
*
* When feature is enabled, ESP will notify host device about new data
* available for read and then user may start read process
*
* \note This feature is only available for `TCP` connections.
*/
#ifndef LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
#define LWESP_CFG_CONN_MANUAL_TCP_RECEIVE 1
#endif

/**
* \}
*/
Expand Down
8 changes: 0 additions & 8 deletions lwesp/src/include/lwesp/lwesp_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ typedef enum {
LWESP_CMD_TCPIP_CIPSERVERMAXCONN, /*!< Sets maximal number of connections allowed for server population */
LWESP_CMD_TCPIP_CIPMODE, /*!< Transmission mode, either transparent or normal one */
LWESP_CMD_TCPIP_CIPSTO, /*!< Sets connection timeout */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__
LWESP_CMD_TCPIP_CIPRECVMODE, /*!< Sets mode for TCP data receive (manual or automatic) */
LWESP_CMD_TCPIP_CIPRECVDATA, /*!< Manually reads TCP data from device */
LWESP_CMD_TCPIP_CIPRECVLEN, /*!< Gets number of available bytes in connection to be read */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__ */
LWESP_CMD_TCPIP_CIUPDATE, /*!< Perform self-update */
#if LWESP_CFG_SNTP || __DOXYGEN__
LWESP_CMD_TCPIP_CIPSNTPCFG, /*!< Configure SNTP servers */
Expand Down Expand Up @@ -186,15 +184,13 @@ typedef struct lwesp_conn {

size_t total_recved; /*!< Total number of bytes received */

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__
size_t tcp_available_bytes; /*!< Number of bytes in ESP ready to be read on connection.
This variable always holds last known info from ESP
device and is not decremented (or incremented) by application */
size_t tcp_not_ack_bytes; /*!< Number of bytes not acknowledge by application done with processing
This variable is increased everytime new packet is
read to be sent to application and decreased
when application acknowledges it */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__ */

union {
struct {
Expand All @@ -204,10 +200,8 @@ typedef struct lwesp_conn {
uint8_t in_closing: 1; /*!< Status if connection is in closing mode.
When in closing mode, ignore any possible
received data from function */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__
uint8_t receive_blocked: 1; /*!< Status whether we should block manual receive for some time */
uint8_t receive_is_command_queued: 1; /*!< Status whether manual read command is in the queue already */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE || __DOXYGEN__ */
} f; /*!< Connection flags */
} status; /*!< Connection status union with flag bits */
} lwesp_conn_t;
Expand Down Expand Up @@ -392,7 +386,6 @@ typedef struct lwesp_msg {
size_t* bw; /*!< Number of bytes written so far */
uint8_t val_id; /*!< Connection current validation ID when command was sent to queue */
} conn_send; /*!< Structure to send data on connection */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
struct {
lwesp_conn_t* conn; /*!< Connection handle */
size_t len; /*!< Number of bytes to read */
Expand All @@ -402,7 +395,6 @@ typedef struct lwesp_msg {
uint8_t is_last_check; /*!< Status indicating check for data length is at the end of command.
Do nothing after successful command */
} ciprecvdata; /*!< Structure to manually read TCP data */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

/* TCP/IP based commands */
struct {
Expand Down
4 changes: 0 additions & 4 deletions lwesp/src/lwesp/lwesp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
#error LWESP_CFG_OS must be set to 1 in current revision!
#endif /* LWESP_CFG_OS != 1 */

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
//#error LWESP_CFG_CONN_MANUAL_TCP_RECEIVE must be set to 0 in current revision!
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

static lwesp_evt_func_t def_evt_link;

/* Global ESP structure */
Expand Down
11 changes: 0 additions & 11 deletions lwesp/src/lwesp/lwesp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ prv_conn_timeout_cb(void* arg) {
LWESP_DEBUGF(LWESP_CFG_DBG_CONN | LWESP_DBG_TYPE_TRACE,
"[LWESP CONN] Poll event: %p\r\n", (void *)conn);
}

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
lwespi_conn_manual_tcp_try_read_data(conn); /* Try to read data manually */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
}

/**
Expand All @@ -85,8 +82,6 @@ lwespi_conn_start_timeout(lwesp_conn_p conn) {
lwesp_timeout_add(LWESP_CFG_CONN_POLL_INTERVAL, prv_conn_timeout_cb, conn); /* Add connection timeout */
}

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE

/**
* \brief Callback function when manual TCP receive finishes
* \param[in] res: Result of reading
Expand Down Expand Up @@ -173,7 +168,6 @@ lwespi_conn_check_available_rx_data(void) {

return lwespi_send_msg_to_producer_mbox(&LWESP_MSG_VAR_REF(msg), lwespi_initiate_cmd, 1000);
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

/**
* \brief Get connection validation ID
Expand Down Expand Up @@ -464,7 +458,6 @@ lwesp_conn_send(lwesp_conn_p conn, const void* data, size_t btw, size_t* const b
*/
lwespr_t
lwesp_conn_recved(lwesp_conn_p conn, lwesp_pbuf_p pbuf) {
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
size_t len;
len = lwesp_pbuf_length(pbuf, 1); /* Get length of pbuf */
if (conn->tcp_not_ack_bytes >= len) { /* Check length of not-acknowledged bytes */
Expand All @@ -473,10 +466,6 @@ lwesp_conn_recved(lwesp_conn_p conn, lwesp_pbuf_p pbuf) {
/* Warning here, de-sync happened somewhere! */
}
lwespi_conn_manual_tcp_try_read_data(conn); /* Try to read more connection data */
#else /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
LWESP_UNUSED(conn);
LWESP_UNUSED(pbuf);
#endif /* !LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
return lwespOK;
}

Expand Down
57 changes: 1 addition & 56 deletions lwesp/src/lwesp/lwesp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
if (rcv->data[0] == '+') {
if (!strncmp("+IPD", rcv->data, 4)) { /* Check received network data */
lwespi_parse_ipd(rcv->data); /* Parse IPD statement and start receiving network data */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
if (CMD_IS_DEF(LWESP_CMD_TCPIP_CIPRECVDATA) && CMD_IS_CUR(LWESP_CMD_TCPIP_CIPRECVLEN)) {
esp.msg->msg.ciprecvdata.ipd_recv = 1; /* Command repeat, try again later */
}
Expand All @@ -646,7 +645,6 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
lwespi_parse_ciprecvdata(rcv->data);/* Parse CIPRECVDATA statement and start receiving network data */
} else if (!strncmp("+CIPRECVLEN", rcv->data, 11)) {
lwespi_parse_ciprecvlen(rcv->data); /* Parse CIPRECVLEN statement */
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
#if LWESP_CFG_MODE_ACCESS_POINT
} else if (!strncmp(rcv->data, "+STA_CONNECTED", 14)) {
lwespi_parse_ap_conn_disconn_sta(&rcv->data[15], 1);/* Parse string and send to user layer */
Expand Down Expand Up @@ -1059,9 +1057,7 @@ lwespi_parse_received(lwesp_recv_t* rcv) {
esp.evt.evt.conn_active_close.forced = conn->status.f.client; /* Set if action was forced = if client mode */
lwespi_send_conn_cb(conn, NULL);/* Send event */
lwespi_conn_start_timeout(conn);/* Start connection timeout timer */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
lwespi_conn_check_available_rx_data();
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
}
}
/*
Expand Down Expand Up @@ -1250,15 +1246,13 @@ lwespi_process(const void* data, size_t data_len) {

/* Call user callback function with received data */
if (esp.m.ipd.buff != NULL) { /* Do we have valid buffer? */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
size_t pbuf_len;

pbuf_len = lwesp_pbuf_length(esp.m.ipd.buff, 1);
esp.m.ipd.conn->tcp_not_ack_bytes += pbuf_len;
if (esp.m.ipd.conn->tcp_available_bytes >= pbuf_len) {
esp.m.ipd.conn->tcp_available_bytes -= pbuf_len;
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

esp.m.ipd.conn->total_recved += esp.m.ipd.buff->tot_len;/* Increase number of bytes received */

Expand Down Expand Up @@ -1332,9 +1326,7 @@ lwespi_process(const void* data, size_t data_len) {
}
if (res == lwespOK) { /* Can we process the character(s) */
if (unicode.t == 1) { /* Totally 1 character? */
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
char* tmp_ptr;
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
switch (ch) {
case '\n':
RECV_ADD(ch); /* Add character to input buffer */
Expand All @@ -1357,7 +1349,6 @@ lwespi_process(const void* data, size_t data_len) {
}
}

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
/*
* Check if "+CIPRECVDATA" statement is in array and now we received colon,
* indicating end of +CIPRECVDATA statement and start of actual data
Expand Down Expand Up @@ -1389,47 +1380,7 @@ lwespi_process(const void* data, size_t data_len) {
} else {
/* ERROR handling */
}
} else
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */

/*
* Check if "+IPD" statement is in array and now we received colon,
* indicating end of +IPD and start of actual data
*/
if (ch == ':' && RECV_LEN() > 4 && RECV_IDX(0) == '+' && !strncmp(recv_buff.data, "+IPD", 4)) {
lwespi_parse_received(&recv_buff); /* Parse received string */
if (esp.m.ipd.read) { /* Shall we start read procedure? */
size_t len;
LWESP_DEBUGF(LWESP_CFG_DBG_IPD | LWESP_DBG_TYPE_TRACE,
"[LWESP IPD] Data on connection %d with total size %d byte(s)\r\n",
(int)esp.m.ipd.conn->num, (int)esp.m.ipd.tot_len);

len = LWESP_MIN(esp.m.ipd.rem_len, LWESP_CFG_CONN_MAX_RECV_BUFF_SIZE);

/*
* Read received data in case of:
*
* - Connection is active and
* - Connection is not in closing mode
*/
if (esp.m.ipd.conn->status.f.active && !esp.m.ipd.conn->status.f.in_closing) {
esp.m.ipd.buff = lwesp_pbuf_new(len); /* Allocate new packet buffer */
if (esp.m.ipd.buff != NULL) {
lwesp_pbuf_set_ip(esp.m.ipd.buff, &esp.m.ipd.ip, esp.m.ipd.port); /* Set IP and port for received data */
}
LWESP_DEBUGW(LWESP_CFG_DBG_IPD | LWESP_DBG_TYPE_TRACE | LWESP_DBG_LVL_WARNING, esp.m.ipd.buff == NULL,
"[LWESP IPD] Buffer allocation failed for %d byte(s)\r\n", (int)len);
} else {
esp.m.ipd.buff = NULL; /* Ignore reading on closed connection */
LWESP_DEBUGF(LWESP_CFG_DBG_IPD | LWESP_DBG_TYPE_TRACE,
"[LWESP IPD] Connection %d closed or in closing, skipping %d byte(s)\r\n",
(int)esp.m.ipd.conn->num, (int)len);
}
esp.m.ipd.conn->status.f.data_received = 1; /* We have first received data */
esp.m.ipd.buff_ptr = 0; /* Reset buffer write pointer */
}
RECV_RESET(); /* Reset received buffer */
}
}
} else { /* We have sequence of unicode characters */
/*
* Unicode sequence characters are not "meta" characters
Expand Down Expand Up @@ -1512,11 +1463,9 @@ lwespi_get_reset_sub_cmd(lwesp_msg_t* msg, uint8_t* is_ok, uint8_t* is_error, ui
SET_NEW_CMD(LWESP_CMD_TCPIP_CIPMUX);
break;
case LWESP_CMD_TCPIP_CIPMUX:
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
SET_NEW_CMD(LWESP_CMD_TCPIP_CIPRECVMODE);
break;
case LWESP_CMD_TCPIP_CIPRECVMODE:
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
#if LWESP_CFG_IPV6
SET_NEW_CMD(LWESP_CMD_WIFI_IPV6);
break;
Expand Down Expand Up @@ -1694,7 +1643,6 @@ lwespi_process_sub_cmd(lwesp_msg_t* msg, uint8_t* is_ok, uint8_t* is_error, uint
esp.evt.evt.conn_active_close.client = msg->msg.conn_close.conn->status.f.active && msg->msg.conn_close.conn->status.f.client;
lwespi_send_conn_cb(msg->msg.conn_close.conn, NULL);
}
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
} else if (CMD_IS_DEF(LWESP_CMD_TCPIP_CIPRECVDATA)) {
if (CMD_IS_CUR(LWESP_CMD_TCPIP_CIPRECVLEN) && msg->msg.ciprecvdata.is_last_check == 0) {
uint8_t set_error = 0;
Expand Down Expand Up @@ -1764,7 +1712,6 @@ lwespi_process_sub_cmd(lwesp_msg_t* msg, uint8_t* is_ok, uint8_t* is_error, uint
*is_ok = 1;
}
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
} else if (CMD_IS_DEF(LWESP_CMD_WIFI_CWDHCP_SET)) {
if (CMD_IS_CUR(LWESP_CMD_WIFI_CWDHCP_SET)) {
SET_NEW_CMD(LWESP_CMD_WIFI_CWDHCP_GET);
Expand Down Expand Up @@ -2348,7 +2295,6 @@ lwespi_initiate_cmd(lwesp_msg_t* msg) {
AT_PORT_SEND_END_AT();
break;
}
#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
case LWESP_CMD_TCPIP_CIPRECVMODE: { /* Set TCP data receive mode */
AT_PORT_SEND_BEGIN_AT();
AT_PORT_SEND_CONST_STR("+CIPRECVMODE=1");
Expand All @@ -2369,7 +2315,6 @@ lwespi_initiate_cmd(lwesp_msg_t* msg) {
AT_PORT_SEND_END_AT();
break;
}
#endif /* LWESP_CFG_CONN_MANUAL_TCP_RECEIVE */
#if LWESP_CFG_DNS
case LWESP_CMD_TCPIP_CIPDOMAIN: { /* DNS function */
AT_PORT_SEND_BEGIN_AT();
Expand Down

0 comments on commit a7bb54b

Please sign in to comment.