@@ -425,17 +425,22 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
425425 return rt_device_write (client -> device , 0 , buf , size );
426426}
427427
428- static char at_client_getchar (at_client_t client )
428+ static rt_err_t at_client_getchar (at_client_t client , char * ch , rt_int32_t timeout )
429429{
430- char ch ;
430+ rt_err_t result = RT_EOK ;
431431
432- while (rt_device_read (client -> device , 0 , & ch , 1 ) == 0 )
432+ while (rt_device_read (client -> device , 0 , ch , 1 ) == 0 )
433433 {
434434 rt_sem_control (client -> rx_notice , RT_IPC_CMD_RESET , RT_NULL );
435- rt_sem_take (client -> rx_notice , RT_WAITING_FOREVER );
435+
436+ result = rt_sem_take (client -> rx_notice , rt_tick_from_millisecond (timeout ));
437+ if (result != RT_EOK )
438+ {
439+ return result ;
440+ }
436441 }
437442
438- return ch ;
443+ return RT_EOK ;
439444}
440445
441446/**
@@ -444,15 +449,17 @@ static char at_client_getchar(at_client_t client)
444449 * @param client current AT client object
445450 * @param buf receive data buffer
446451 * @param size receive fixed data size
452+ * @param timeout receive data timeout (ms)
447453 *
448454 * @note this function can only be used in execution function of URC data
449455 *
450456 * @return >0: receive data size
451457 * =0: receive failed
452458 */
453- rt_size_t at_client_obj_recv (at_client_t client , char * buf , rt_size_t size )
459+ rt_size_t at_client_obj_recv (at_client_t client , char * buf , rt_size_t size , rt_int32_t timeout )
454460{
455461 rt_size_t read_idx = 0 ;
462+ rt_err_t result = RT_EOK ;
456463 char ch ;
457464
458465 RT_ASSERT (buf );
@@ -467,7 +474,12 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size)
467474 {
468475 if (read_idx < size )
469476 {
470- ch = at_client_getchar (client );
477+ result = at_client_getchar (client , & ch , timeout );
478+ if (result != RT_EOK )
479+ {
480+ LOG_E ("AT Client receive failed, uart device get data error(%d)" , result );
481+ return 0 ;
482+ }
471483
472484 buf [read_idx ++ ] = ch ;
473485 }
@@ -610,7 +622,7 @@ static int at_recv_readline(at_client_t client)
610622
611623 while (1 )
612624 {
613- ch = at_client_getchar (client );
625+ at_client_getchar (client , & ch , RT_WAITING_FOREVER );
614626
615627 if (read_len < client -> recv_bufsz )
616628 {
0 commit comments