@@ -310,14 +310,16 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
310310 rt_mutex_take (client -> lock , RT_WAITING_FOREVER );
311311
312312 client -> resp_status = AT_RESP_OK ;
313- client -> resp = resp ;
314313
315314 if (resp != RT_NULL )
316315 {
317316 resp -> buf_len = 0 ;
318317 resp -> line_counts = 0 ;
319318 }
320319
320+ client -> resp = resp ;
321+ rt_sem_control (client -> resp_notice , RT_IPC_CMD_RESET , RT_NULL );
322+
321323 va_start (args , cmd_expr );
322324 at_vprintfln (client -> device , cmd_expr , args );
323325 va_end (args );
@@ -327,7 +329,7 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
327329 if (rt_sem_take (client -> resp_notice , resp -> timeout ) != RT_EOK )
328330 {
329331 cmd = at_get_last_cmd (& cmd_size );
330- LOG_D ("execute command (%.*s) timeout (%d ticks)!" , cmd_size , cmd , resp -> timeout );
332+ LOG_W ("execute command (%.*s) timeout (%d ticks)!" , cmd_size , cmd , resp -> timeout );
331333 client -> resp_status = AT_RESP_TIMEOUT ;
332334 result = - RT_ETIMEOUT ;
333335 goto __exit ;
@@ -381,6 +383,7 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
381383
382384 rt_mutex_take (client -> lock , RT_WAITING_FOREVER );
383385 client -> resp = resp ;
386+ rt_sem_control (client -> resp_notice , RT_IPC_CMD_RESET , RT_NULL );
384387
385388 start_time = rt_tick_get ();
386389
@@ -480,9 +483,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
480483 */
481484rt_size_t at_client_obj_recv (at_client_t client , char * buf , rt_size_t size , rt_int32_t timeout )
482485{
483- rt_size_t read_idx = 0 ;
484- rt_err_t result = RT_EOK ;
485- char ch ;
486+ rt_size_t len = 0 ;
486487
487488 RT_ASSERT (buf );
488489
@@ -494,28 +495,28 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
494495
495496 while (1 )
496497 {
497- if (read_idx < size )
498+ rt_sem_control (client -> rx_notice , RT_IPC_CMD_RESET , RT_NULL );
499+
500+ rt_size_t read_len = rt_device_read (client -> device , 0 , buf + len , size );
501+ if (read_len > 0 )
498502 {
499- result = at_client_getchar (client , & ch , timeout );
500- if (result != RT_EOK )
501- {
502- LOG_E ("AT Client receive failed, uart device get data error(%d)" , result );
503- return 0 ;
504- }
503+ len += read_len ;
504+ size -= read_len ;
505+ if (size == 0 )
506+ break ;
505507
506- buf [ read_idx ++ ] = ch ;
508+ continue ;
507509 }
508- else
509- {
510+
511+ if ( rt_sem_take ( client -> rx_notice , rt_tick_from_millisecond ( timeout )) != RT_EOK )
510512 break ;
511- }
512513 }
513514
514515#ifdef AT_PRINT_RAW_CMD
515- at_print_raw_cmd ("urc_recv" , buf , size );
516+ at_print_raw_cmd ("urc_recv" , buf , len );
516517#endif
517518
518- return read_idx ;
519+ return len ;
519520}
520521
521522/**
0 commit comments