fix at_client.c
This commit is contained in:
parent
5fb6cb8b41
commit
c229d8b2b5
|
@ -310,7 +310,6 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
|
|||
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
|
||||
|
||||
client->resp_status = AT_RESP_OK;
|
||||
client->resp = resp;
|
||||
|
||||
if (resp != RT_NULL)
|
||||
{
|
||||
|
@ -318,6 +317,9 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
|
|||
resp->line_counts = 0;
|
||||
}
|
||||
|
||||
client->resp = resp;
|
||||
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
|
||||
va_start(args, cmd_expr);
|
||||
at_vprintfln(client->device, cmd_expr, args);
|
||||
va_end(args);
|
||||
|
@ -327,7 +329,7 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
|
|||
if (rt_sem_take(client->resp_notice, resp->timeout) != RT_EOK)
|
||||
{
|
||||
cmd = at_get_last_cmd(&cmd_size);
|
||||
LOG_D("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout);
|
||||
LOG_W("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout);
|
||||
client->resp_status = AT_RESP_TIMEOUT;
|
||||
result = -RT_ETIMEOUT;
|
||||
goto __exit;
|
||||
|
@ -381,6 +383,7 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
|
|||
|
||||
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
|
||||
client->resp = resp;
|
||||
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
|
||||
start_time = rt_tick_get();
|
||||
|
||||
|
@ -480,9 +483,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
|
|||
*/
|
||||
rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_int32_t timeout)
|
||||
{
|
||||
rt_size_t read_idx = 0;
|
||||
rt_err_t result = RT_EOK;
|
||||
char ch;
|
||||
rt_size_t len = 0;
|
||||
|
||||
RT_ASSERT(buf);
|
||||
|
||||
|
@ -494,28 +495,28 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
|
|||
|
||||
while (1)
|
||||
{
|
||||
if (read_idx < size)
|
||||
{
|
||||
result = at_client_getchar(client, &ch, timeout);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_E("AT Client receive failed, uart device get data error(%d)", result);
|
||||
return 0;
|
||||
}
|
||||
rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
|
||||
buf[read_idx++] = ch;
|
||||
}
|
||||
else
|
||||
rt_size_t read_len = rt_device_read(client->device, 0, buf + len, size);
|
||||
if(read_len > 0)
|
||||
{
|
||||
break;
|
||||
len += read_len;
|
||||
size -= read_len;
|
||||
if(size == 0)
|
||||
break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout)) != RT_EOK)
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef AT_PRINT_RAW_CMD
|
||||
at_print_raw_cmd("urc_recv", buf, size);
|
||||
at_print_raw_cmd("urc_recv", buf, len);
|
||||
#endif
|
||||
|
||||
return read_idx;
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue