Skip to content

Commit fddd89f

Browse files
committed
[component][net][at] at_client优化serial_v2适配
1 parent a822d6d commit fddd89f

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

components/net/at/src/at_client.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -533,31 +533,6 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
533533
return len;
534534
}
535535

536-
static rt_err_t at_client_getchar(at_client_t client, char *ch)
537-
{
538-
rt_err_t result = RT_EOK;
539-
rt_ssize_t recvLen = 0;
540-
#if (!defined(RT_USING_SERIAL_V2))
541-
recvLen = rt_device_read(client->device, 0, ch, 1);
542-
if (recvLen <= 0)
543-
{
544-
result = -RT_ERROR;
545-
}
546-
#else
547-
rt_int32_t rx_timeout = 0;
548-
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
549-
recvLen = rt_device_read(client->device, 0, ch, 1);
550-
if (recvLen <= 0)
551-
{
552-
result = -RT_ERROR;
553-
}
554-
rx_timeout = RT_WAITING_FOREVER;
555-
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
556-
#endif
557-
558-
return result;
559-
}
560-
561536
/**
562537
* AT client receive fixed-length data.
563538
*
@@ -583,7 +558,7 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
583558
return 0;
584559
}
585560

586-
#if (!defined(RT_USING_SERIAL_V2))
561+
#ifndef RT_USING_SERIAL_V2
587562
while (size)
588563
{
589564
rt_size_t read_len;
@@ -606,7 +581,7 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
606581
rt_int32_t rx_timeout = rt_tick_from_millisecond(timeout);
607582
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
608583
read_idx = rt_device_read(client->device, 0, buf, size);
609-
rx_timeout = RT_WAITING_FOREVER;
584+
rx_timeout = RT_WAITING_NO;
610585
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
611586
#endif
612587

@@ -776,6 +751,28 @@ static const struct at_urc *get_urc_obj(at_client_t client)
776751
return RT_NULL;
777752
}
778753

754+
static rt_err_t at_client_getchar(at_client_t client, char *ch)
755+
{
756+
rt_err_t result = RT_EOK;
757+
rt_ssize_t recvLen = 0;
758+
/* Temporarily retain the distinction */
759+
#ifndef RT_USING_SERIAL_V2
760+
recvLen = rt_device_read(client->device, 0, ch, 1);
761+
if (recvLen <= 0)
762+
{
763+
result = -RT_ERROR;
764+
}
765+
#else
766+
recvLen = rt_device_read(client->device, 0, ch, 1);
767+
if (recvLen != 1)
768+
{
769+
result = -RT_ERROR;
770+
}
771+
#endif
772+
773+
return result;
774+
}
775+
779776
static int at_recv_readline(at_client_t client)
780777
{
781778
char ch = 0, last_ch = 0;
@@ -1030,7 +1027,7 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
10301027
if (client->device)
10311028
{
10321029
RT_ASSERT(client->device->type == RT_Device_Class_Char);
1033-
#if (!defined(RT_USING_SERIAL_V2))
1030+
#ifndef RT_USING_SERIAL_V2
10341031
/* using DMA mode first */
10351032
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_DMA_RX);
10361033
/* using interrupt mode when DMA mode not supported */
@@ -1042,6 +1039,8 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
10421039
#else
10431040
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
10441041
RT_ASSERT(open_result == RT_EOK);
1042+
rt_int32_t rx_timeout = RT_WAITING_NO;
1043+
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
10451044
#endif
10461045
}
10471046
else

0 commit comments

Comments
 (0)