Skip to content

Commit 68bce61

Browse files
Ryan-CW-Codehydevcode
authored andcommitted
[components][at] 适配new serialv2不再判断RTT版本号
1 parent 3703120 commit 68bce61

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

components/net/at/include/at.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct at_server
9191
char recv_buffer[AT_SERVER_RECV_BUFF_LEN];
9292
rt_size_t cur_recv_len;
9393

94-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
94+
#if (!defined(RT_USING_SERIAL_V2))
9595
rt_sem_t rx_notice;
9696
#endif
9797

@@ -169,7 +169,7 @@ struct at_client
169169
/* The maximum supported receive data length */
170170
rt_size_t recv_bufsz;
171171

172-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
172+
#if (!defined(RT_USING_SERIAL_V2))
173173
rt_sem_t rx_notice;
174174
#endif
175175

components/net/at/src/at_client.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -11,6 +11,7 @@
1111
* 2021-03-17 Meco Man fix a buf of leaking memory
1212
* 2021-07-14 Sszl fix a buf of leaking memory
1313
* 2025-01-02 dongly support SERIAL_V2
14+
* 2025-04-18 RyanCw support New SERIAL_V2
1415
*/
1516

1617
#include <at.h>
@@ -225,7 +226,8 @@ int at_resp_parse_line_args(at_response_t resp, rt_size_t resp_line, const char
225226
RT_ASSERT(resp);
226227
RT_ASSERT(resp_expr);
227228

228-
if ((resp_line_buf = at_resp_get_line(resp, resp_line)) == RT_NULL)
229+
resp_line_buf = at_resp_get_line(resp, resp_line);
230+
if (resp_line_buf == RT_NULL)
229231
{
230232
return -1;
231233
}
@@ -259,7 +261,8 @@ int at_resp_parse_line_args_by_kw(at_response_t resp, const char *keyword, const
259261
RT_ASSERT(resp);
260262
RT_ASSERT(resp_expr);
261263

262-
if ((resp_line_buf = at_resp_get_line_by_kw(resp, keyword)) == RT_NULL)
264+
resp_line_buf = at_resp_get_line_by_kw(resp, keyword);
265+
if (resp_line_buf == RT_NULL)
263266
{
264267
return -1;
265268
}
@@ -541,7 +544,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
541544
{
542545
rt_err_t result = RT_EOK;
543546

544-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
547+
#if (!defined(RT_USING_SERIAL_V2))
545548
while (rt_device_read(client->device, 0, ch, 1) == 0)
546549
{
547550
result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout));
@@ -592,7 +595,7 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
592595
return 0;
593596
}
594597

595-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
598+
#if (!defined(RT_USING_SERIAL_V2))
596599
while (size)
597600
{
598601
rt_size_t read_len;
@@ -800,7 +803,8 @@ static int at_recv_readline(at_client_t client)
800803
}
801804

802805
/* is newline or URC data */
803-
if ((client->urc = get_urc_obj(client)) != RT_NULL || (ch == '\n' && last_ch == '\r')
806+
client->urc = get_urc_obj(client);
807+
if (client->urc != RT_NULL || (ch == '\n' && last_ch == '\r')
804808
|| (client->end_sign != 0 && ch == client->end_sign))
805809
{
806810
if (is_full)
@@ -897,7 +901,7 @@ static void client_parser(at_client_t client)
897901
}
898902
}
899903

900-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
904+
#if (!defined(RT_USING_SERIAL_V2))
901905
static rt_err_t at_client_rx_ind(rt_device_t dev, rt_size_t size)
902906
{
903907
int idx = 0;
@@ -955,7 +959,7 @@ static int at_client_para_init(at_client_t client)
955959
goto __exit;
956960
}
957961

958-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
962+
#if (!defined(RT_USING_SERIAL_V2))
959963
rt_snprintf(name, RT_NAME_MAX, "%s%d", AT_CLIENT_SEM_NAME, at_client_num);
960964
client->rx_notice = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);
961965
if (client->rx_notice == RT_NULL)
@@ -983,7 +987,8 @@ static int at_client_para_init(at_client_t client)
983987
(void (*)(void *parameter))client_parser,
984988
client,
985989
1024 + 512,
986-
RT_THREAD_PRIORITY_MAX / 3 - 1,
990+
6,
991+
/* RT_THREAD_PRIORITY_MAX / 3 - 1,*/
987992
5);
988993
if (client->parser == RT_NULL)
989994
{
@@ -998,7 +1003,7 @@ static int at_client_para_init(at_client_t client)
9981003
rt_mutex_delete(client->lock);
9991004
}
10001005

1001-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
1006+
#if (!defined(RT_USING_SERIAL_V2))
10021007
if (client->rx_notice)
10031008
{
10041009
rt_sem_delete(client->rx_notice);
@@ -1081,7 +1086,7 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
10811086
if (client->device)
10821087
{
10831088
RT_ASSERT(client->device->type == RT_Device_Class_Char);
1084-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
1089+
#if (!defined(RT_USING_SERIAL_V2))
10851090
rt_device_set_rx_indicate(client->device, at_client_rx_ind);
10861091

10871092
#ifdef RT_USING_SERIAL_V2

components/net/at/src/at_server.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -8,6 +8,7 @@
88
* 2018-03-30 chenyong first version
99
* 2018-04-14 chenyong modify parse arguments
1010
* 2025-01-02 dongly support SERIAL_V2
11+
* 2025-04-18 RyanCw support New SERIAL_V2
1112
*/
1213

1314
#include <at.h>
@@ -223,23 +224,24 @@ rt_size_t at_server_recv(at_server_t server, char *buf, rt_size_t size, rt_int32
223224
return 0;
224225
}
225226

226-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
227-
while (size)
227+
#if (!defined(RT_USING_SERIAL_V2))
228+
while (1)
228229
{
229-
rt_size_t read_len;
230-
231-
rt_sem_control(server->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
232-
233-
read_len = rt_device_read(server->device, 0, buf + read_idx, size);
234-
if (read_len > 0)
230+
if (read_idx < size)
235231
{
236-
read_idx += read_len;
237-
size -= read_len;
232+
/* check get data value */
233+
result = server->get_char(server, &ch, timeout);
234+
if (result != RT_EOK)
235+
{
236+
LOG_E("AT Server receive failed, uart device get data error.");
237+
return 0;
238+
}
239+
240+
buf[read_idx++] = ch;
238241
}
239242
else
240243
{
241-
if (rt_sem_take(server->rx_notice, rt_tick_from_millisecond(timeout)) != RT_EOK)
242-
break;
244+
break;
243245
}
244246
}
245247
#else
@@ -418,7 +420,7 @@ static rt_err_t at_server_getchar(at_server_t server, char *ch, rt_int32_t timeo
418420
{
419421
rt_err_t result = RT_EOK;
420422

421-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
423+
#if (!defined(RT_USING_SERIAL_V2))
422424
while (rt_device_read(at_server_local->device, 0, ch, 1) == 0)
423425
{
424426
result = rt_sem_take(at_server_local->rx_notice, rt_tick_from_millisecond(timeout));
@@ -516,7 +518,7 @@ static void server_parser(at_server_t server)
516518
}
517519
}
518520

519-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
521+
#if (!defined(RT_USING_SERIAL_V2))
520522
static rt_err_t at_rx_ind(rt_device_t dev, rt_size_t size)
521523
{
522524
if (size > 0)
@@ -572,7 +574,7 @@ int at_server_init(void)
572574
rt_memset(at_server_local->recv_buffer, 0x00, AT_SERVER_RECV_BUFF_LEN);
573575
at_server_local->cur_recv_len = 0;
574576

575-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
577+
#if (!defined(RT_USING_SERIAL_V2))
576578
at_server_local->rx_notice = rt_sem_create("at_svr", 0, RT_IPC_FLAG_FIFO);
577579
if (!at_server_local->rx_notice)
578580
{
@@ -587,7 +589,7 @@ int at_server_init(void)
587589
if (at_server_local->device)
588590
{
589591
RT_ASSERT(at_server_local->device->type == RT_Device_Class_Char);
590-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
592+
#if (!defined(RT_USING_SERIAL_V2))
591593
rt_device_set_rx_indicate(at_server_local->device, at_rx_ind);
592594

593595
#ifdef RT_USING_SERIAL_V2
@@ -642,7 +644,7 @@ int at_server_init(void)
642644
if (at_server_local)
643645
{
644646

645-
#if (!defined(RT_USING_SERIAL_V2) || RT_VER_NUM < 0x50200)
647+
#if (!defined(RT_USING_SERIAL_V2))
646648
if (at_server_local->rx_notice)
647649
{
648650
rt_sem_delete(at_server_local->rx_notice);

0 commit comments

Comments
 (0)