@@ -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
@@ -426,6 +429,8 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
426429 */
427430rt_size_t at_client_obj_send (at_client_t client , const char * buf , rt_size_t size )
428431{
432+ rt_size_t len ;
433+
429434 RT_ASSERT (buf );
430435
431436 if (client == RT_NULL )
@@ -440,7 +445,7 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
440445
441446 rt_mutex_take (client -> lock , RT_WAITING_FOREVER );
442447
443- rt_size_t len = at_utils_send (client -> device , 0 , buf , size );
448+ len = at_utils_send (client -> device , 0 , buf , size );
444449
445450 rt_mutex_release (client -> lock );
446451
@@ -480,9 +485,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
480485 */
481486rt_size_t at_client_obj_recv (at_client_t client , char * buf , rt_size_t size , rt_int32_t timeout )
482487{
483- rt_size_t read_idx = 0 ;
484- rt_err_t result = RT_EOK ;
485- char ch ;
488+ rt_size_t len = 0 ;
486489
487490 RT_ASSERT (buf );
488491
@@ -494,28 +497,30 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
494497
495498 while (1 )
496499 {
497- if (read_idx < size )
500+ rt_size_t read_len ;
501+
502+ rt_sem_control (client -> rx_notice , RT_IPC_CMD_RESET , RT_NULL );
503+
504+ read_len = rt_device_read (client -> device , 0 , buf + len , size );
505+ if (read_len > 0 )
498506 {
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- }
507+ len += read_len ;
508+ size -= read_len ;
509+ if (size == 0 )
510+ break ;
505511
506- buf [ read_idx ++ ] = ch ;
512+ continue ;
507513 }
508- else
509- {
514+
515+ if ( rt_sem_take ( client -> rx_notice , rt_tick_from_millisecond ( timeout )) != RT_EOK )
510516 break ;
511- }
512517 }
513518
514519#ifdef AT_PRINT_RAW_CMD
515- at_print_raw_cmd ("urc_recv" , buf , size );
520+ at_print_raw_cmd ("urc_recv" , buf , len );
516521#endif
517522
518- return read_idx ;
523+ return len ;
519524}
520525
521526/**
0 commit comments