1
1
/*
2
- * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2
+ * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
@@ -18,13 +18,13 @@ using namespace esp_modem;
18
18
19
19
command_result net_open (CommandableIf *term)
20
20
{
21
- ESP_LOGV (TAG, " %s" , __func__ );
21
+ ESP_LOGV (TAG, " %s" , __func__);
22
22
std::string response;
23
23
auto ret = dce_commands::generic_get_string (term, " AT+NETOPEN?\r " , response, 1000 );
24
24
if (ret != command_result::OK) {
25
25
return ret;
26
26
}
27
- ESP_LOGV (TAG, " %s" , response.data () );
27
+ ESP_LOGV (TAG, " %s" , response.data ());
28
28
if (response.find (" +NETOPEN: 1" ) != std::string::npos) {
29
29
ESP_LOGD (TAG, " Already there" );
30
30
ret = command_result::OK;
@@ -42,37 +42,37 @@ command_result net_open(CommandableIf *term)
42
42
43
43
command_result net_close (CommandableIf *term)
44
44
{
45
- ESP_LOGV (TAG, " %s" , __func__ );
45
+ ESP_LOGV (TAG, " %s" , __func__);
46
46
return dce_commands::generic_command (term, " AT+NETCLOSE\r " , " +NETCLOSE:" , " ERROR" , 30000 );
47
47
}
48
48
49
49
command_result tcp_open (CommandableIf *term, const std::string &host, int port, int timeout)
50
50
{
51
- ESP_LOGV (TAG, " %s" , __func__ );
51
+ ESP_LOGV (TAG, " %s" , __func__);
52
52
auto ret = dce_commands::generic_command (term, " AT+CIPRXGET=1\r " , " OK" , " ERROR" , 50000 );
53
53
if (ret != command_result::OK) {
54
54
ESP_LOGE (TAG, " Setting Rx mode failed!" );
55
55
return ret;
56
56
}
57
- ESP_LOGV (TAG, " %s" , __func__ );
57
+ ESP_LOGV (TAG, " %s" , __func__);
58
58
std::string ip_open = R"( AT+CIPOPEN=0,"TCP",")" + host + " \" ," + std::to_string (port) + " \r " ;
59
59
ret = dce_commands::generic_command (term, ip_open, " +CIPOPEN: 0,0" , " ERROR" , timeout);
60
60
if (ret != command_result::OK) {
61
- ESP_LOGE (TAG, " %s Failed" , __func__ );
61
+ ESP_LOGE (TAG, " %s Failed" , __func__);
62
62
return ret;
63
63
}
64
64
return command_result::OK;
65
65
}
66
66
67
67
command_result tcp_close (CommandableIf *term)
68
68
{
69
- ESP_LOGV (TAG, " %s" , __func__ );
69
+ ESP_LOGV (TAG, " %s" , __func__);
70
70
return dce_commands::generic_command (term, " AT+CIPCLOSE=0\r " , " +CIPCLOSE:" , " ERROR" , 10000 );
71
71
}
72
72
73
73
command_result tcp_send (CommandableIf *term, uint8_t *data, size_t len)
74
74
{
75
- ESP_LOGV (TAG, " %s" , __func__ );
75
+ ESP_LOGV (TAG, " %s" , __func__);
76
76
std::string send = " AT+CIPSEND=0," + std::to_string (len) + " \r " ;
77
77
auto ret = term->command (send, [&](uint8_t *data, size_t len) {
78
78
std::string_view response ((char *)data, len);
@@ -107,7 +107,7 @@ command_result tcp_send(CommandableIf *term, uint8_t *data, size_t len)
107
107
uint8_t ctrl_z = ' \x1A ' ;
108
108
term->write (&ctrl_z, 1 );
109
109
int count = 0 ;
110
- while (ret == command_result::TIMEOUT && count++ < 1000 ) {
110
+ while (ret == command_result::TIMEOUT && count++ < 1000 ) {
111
111
vTaskDelay (pdMS_TO_TICKS (1000 ));
112
112
}
113
113
term->on_read (nullptr );
@@ -116,7 +116,7 @@ command_result tcp_send(CommandableIf *term, uint8_t *data, size_t len)
116
116
117
117
command_result tcp_recv (CommandableIf *term, uint8_t *data, size_t len, size_t &out_len)
118
118
{
119
- ESP_LOGV (TAG, " %s" , __func__ );
119
+ ESP_LOGV (TAG, " %s" , __func__);
120
120
std::string out;
121
121
auto ret = dce_commands::generic_get_string (term, " AT+CIPRXGET=4,0\r " , out);
122
122
if (ret != command_result::OK) {
@@ -340,21 +340,26 @@ Responder::ret Responder::connect(std::string_view response)
340
340
return Responder::ret::IN_PROGRESS;
341
341
}
342
342
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
+
343
355
Responder::ret Responder::check_async_replies (status state, std::string_view &response)
344
356
{
345
- ESP_LOGD (TAG, " response %.*s" , static_cast <int >(response.size ()), response.data ());
346
357
if (response.find (" +CIPRXGET: 1" ) != std::string::npos) {
347
358
uint64_t data_ready = 1 ;
348
359
write (data_ready_fd, &data_ready, sizeof (data_ready));
349
360
ESP_LOGD (TAG, " Got data on modem!" );
350
361
}
351
- if (state == status::SENDING) {
352
- return send (response);
353
- } else if (state == status::CONNECTING) {
354
- return connect (response);
355
- }
356
362
return ret::IN_PROGRESS;
357
-
358
363
}
359
364
360
365
Responder::ret Responder::process_data (status state, uint8_t *data, size_t len)
0 commit comments