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,14 +18,14 @@ using namespace esp_modem;
1818
1919command_result net_open (CommandableIf *t)
2020{
21- ESP_LOGV (TAG, " %s" , __func__ );
21+ ESP_LOGV (TAG, " %s" , __func__);
2222 std::string out;
2323 auto ret = dce_commands::generic_get_string (t, " AT+QISTATE?\r " , out, 1000 );
2424 if (ret != command_result::OK) {
2525 return ret;
2626 }
2727 if (out.find (" +QISTATE: 0" ) != std::string::npos) {
28- ESP_LOGV (TAG, " %s" , out.data () );
28+ ESP_LOGV (TAG, " %s" , out.data ());
2929 ESP_LOGD (TAG, " Already there" );
3030 return command_result::FAIL;
3131 } else if (out.empty ()) {
@@ -36,47 +36,47 @@ command_result net_open(CommandableIf *t)
3636
3737command_result net_close (CommandableIf *t)
3838{
39- ESP_LOGV (TAG, " %s" , __func__ );
39+ ESP_LOGV (TAG, " %s" , __func__);
4040 dce_commands::generic_command (t, " AT+QICLOSE=0\r " , " OK" , " ERROR" , 10000 );
4141 esp_modem::Task::Delay (1000 );
4242 return dce_commands::generic_command (t, " AT+QIDEACT=1\r " , " OK" , " ERROR" , 40000 );
4343}
4444
4545command_result tcp_open (CommandableIf *t, const std::string &host, int port, int timeout)
4646{
47- ESP_LOGV (TAG, " %s" , __func__ );
47+ ESP_LOGV (TAG, " %s" , __func__);
4848 std::string ip_open = R"( AT+QIOPEN=1,0,"TCP",")" + host + " \" ," + std::to_string (port) + " \r " ;
4949 auto ret = dce_commands::generic_command (t, ip_open, " +QIOPEN: 0,0" , " ERROR" , timeout);
5050 if (ret != command_result::OK) {
51- ESP_LOGE (TAG, " %s Failed" , __func__ );
51+ ESP_LOGE (TAG, " %s Failed" , __func__);
5252 return ret;
5353 }
5454 return command_result::OK;
5555}
5656
5757command_result tcp_close (CommandableIf *t)
5858{
59- ESP_LOGV (TAG, " %s" , __func__ );
59+ ESP_LOGV (TAG, " %s" , __func__);
6060 return dce_commands::generic_command (t, " AT+QICLOSE=0\r " , " OK" , " ERROR" , 10000 );
6161}
6262
6363command_result tcp_send (CommandableIf *t, uint8_t *data, size_t len)
6464{
65- ESP_LOGV (TAG, " %s" , __func__ );
65+ ESP_LOGV (TAG, " %s" , __func__);
6666 assert (0 ); // Remove when fix done
6767 return command_result::FAIL;
6868}
6969
7070command_result tcp_recv (CommandableIf *t, uint8_t *data, size_t len, size_t &out_len)
7171{
72- ESP_LOGV (TAG, " %s" , __func__ );
72+ ESP_LOGV (TAG, " %s" , __func__);
7373 assert (0 ); // Remove when fix done
7474 return command_result::FAIL;
7575}
7676
7777command_result get_ip (CommandableIf *t, std::string &ip)
7878{
79- ESP_LOGV (TAG, " %s" , __func__ );
79+ ESP_LOGV (TAG, " %s" , __func__);
8080 std::string out;
8181 auto ret = dce_commands::generic_get_string (t, " AT+QIACT?\r " , out, 5000 );
8282 if (ret != command_result::OK) {
@@ -130,12 +130,15 @@ Responder::ret Responder::recv(uint8_t *data, size_t len)
130130 auto *recv_data = (char *)data;
131131 if (data_to_recv == 0 ) {
132132 const std::string_view head = " +QIRD: " ;
133- auto head_pos = std::search (recv_data, recv_data + len, head.begin (), head.end ());
134- if (head_pos == recv_data + len) {
133+ const std::string_view recv_data_view = std::string_view (recv_data, len);
134+ auto head_pos_found = recv_data_view.find (head);
135+ if (head_pos_found == std::string_view::npos) {
135136 return ret::FAIL;
136137 }
137138
139+ auto *head_pos = recv_data + head_pos_found;
138140 auto next_nl = (char *)memchr (head_pos + head.size (), ' \n ' , MIN_MESSAGE);
141+
139142 if (next_nl == nullptr ) {
140143 return ret::FAIL;
141144 }
0 commit comments