11/*
2- * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -18,13 +18,13 @@ using namespace esp_modem;
1818
1919command_result net_open (CommandableIf *term)
2020{
21- ESP_LOGV (TAG, " %s" , __func__ );
21+ ESP_LOGV (TAG, " %s" , __func__);
2222 std::string response;
2323 auto ret = dce_commands::generic_get_string (term, " AT+NETOPEN?\r " , response, 1000 );
2424 if (ret != command_result::OK) {
2525 return ret;
2626 }
27- ESP_LOGV (TAG, " %s" , response.data () );
27+ ESP_LOGV (TAG, " %s" , response.data ());
2828 if (response.find (" +NETOPEN: 1" ) != std::string::npos) {
2929 ESP_LOGD (TAG, " Already there" );
3030 ret = command_result::OK;
@@ -42,37 +42,37 @@ command_result net_open(CommandableIf *term)
4242
4343command_result net_close (CommandableIf *term)
4444{
45- ESP_LOGV (TAG, " %s" , __func__ );
45+ ESP_LOGV (TAG, " %s" , __func__);
4646 return dce_commands::generic_command (term, " AT+NETCLOSE\r " , " +NETCLOSE:" , " ERROR" , 30000 );
4747}
4848
4949command_result tcp_open (CommandableIf *term, const std::string &host, int port, int timeout)
5050{
51- ESP_LOGV (TAG, " %s" , __func__ );
51+ ESP_LOGV (TAG, " %s" , __func__);
5252 auto ret = dce_commands::generic_command (term, " AT+CIPRXGET=1\r " , " OK" , " ERROR" , 50000 );
5353 if (ret != command_result::OK) {
5454 ESP_LOGE (TAG, " Setting Rx mode failed!" );
5555 return ret;
5656 }
57- ESP_LOGV (TAG, " %s" , __func__ );
57+ ESP_LOGV (TAG, " %s" , __func__);
5858 std::string ip_open = R"( AT+CIPOPEN=0,"TCP",")" + host + " \" ," + std::to_string (port) + " \r " ;
5959 ret = dce_commands::generic_command (term, ip_open, " +CIPOPEN: 0,0" , " ERROR" , timeout);
6060 if (ret != command_result::OK) {
61- ESP_LOGE (TAG, " %s Failed" , __func__ );
61+ ESP_LOGE (TAG, " %s Failed" , __func__);
6262 return ret;
6363 }
6464 return command_result::OK;
6565}
6666
6767command_result tcp_close (CommandableIf *term)
6868{
69- ESP_LOGV (TAG, " %s" , __func__ );
69+ ESP_LOGV (TAG, " %s" , __func__);
7070 return dce_commands::generic_command (term, " AT+CIPCLOSE=0\r " , " +CIPCLOSE:" , " ERROR" , 10000 );
7171}
7272
7373command_result tcp_send (CommandableIf *term, uint8_t *data, size_t len)
7474{
75- ESP_LOGV (TAG, " %s" , __func__ );
75+ ESP_LOGV (TAG, " %s" , __func__);
7676 std::string send = " AT+CIPSEND=0," + std::to_string (len) + " \r " ;
7777 auto ret = term->command (send, [&](uint8_t *data, size_t len) {
7878 std::string_view response ((char *)data, len);
@@ -107,7 +107,7 @@ command_result tcp_send(CommandableIf *term, uint8_t *data, size_t len)
107107 uint8_t ctrl_z = ' \x1A ' ;
108108 term->write (&ctrl_z, 1 );
109109 int count = 0 ;
110- while (ret == command_result::TIMEOUT && count++ < 1000 ) {
110+ while (ret == command_result::TIMEOUT && count++ < 1000 ) {
111111 vTaskDelay (pdMS_TO_TICKS (1000 ));
112112 }
113113 term->on_read (nullptr );
@@ -116,7 +116,7 @@ command_result tcp_send(CommandableIf *term, uint8_t *data, size_t len)
116116
117117command_result tcp_recv (CommandableIf *term, uint8_t *data, size_t len, size_t &out_len)
118118{
119- ESP_LOGV (TAG, " %s" , __func__ );
119+ ESP_LOGV (TAG, " %s" , __func__);
120120 std::string out;
121121 auto ret = dce_commands::generic_get_string (term, " AT+CIPRXGET=4,0\r " , out);
122122 if (ret != command_result::OK) {
@@ -340,21 +340,26 @@ Responder::ret Responder::connect(std::string_view response)
340340 return Responder::ret::IN_PROGRESS;
341341}
342342
343+ Responder::ret Responder::check_urc (status state, std::string_view &response)
344+ {
345+ // Handle data notifications - in multiple connections mode, format is +IPD,<link ID>,<len>
346+ std::string expected_urc = " +IPD," + std::to_string (link_id);
347+ if (response.find (expected_urc) != std::string::npos) {
348+ uint64_t data_ready = 1 ;
349+ write (data_ready_fd, &data_ready, sizeof (data_ready));
350+ ESP_LOGD (TAG, " Data available notification" );
351+ }
352+ return ret::IN_PROGRESS;
353+ }
354+
343355Responder::ret Responder::check_async_replies (status state, std::string_view &response)
344356{
345- ESP_LOGD (TAG, " response %.*s" , static_cast <int >(response.size ()), response.data ());
346357 if (response.find (" +CIPRXGET: 1" ) != std::string::npos) {
347358 uint64_t data_ready = 1 ;
348359 write (data_ready_fd, &data_ready, sizeof (data_ready));
349360 ESP_LOGD (TAG, " Got data on modem!" );
350361 }
351- if (state == status::SENDING) {
352- return send (response);
353- } else if (state == status::CONNECTING) {
354- return connect (response);
355- }
356362 return ret::IN_PROGRESS;
357-
358363}
359364
360365Responder::ret Responder::process_data (status state, uint8_t *data, size_t len)
0 commit comments