【修改】at_client_recv 函数添加超时时间

Signed-off-by: chenyong <1521761801@qq.com>
This commit is contained in:
chenyong 2018-09-14 19:54:11 +08:00
parent 0421779dd7
commit be2b875e40
3 changed files with 24 additions and 11 deletions

View File

@ -32,6 +32,10 @@
#include <at.h>
#include <at_socket.h>
#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10100
#error "This AT Client version is older, please check and update latest AT Client!"
#endif
#ifndef AT_DEVICE_NOT_SELECTED
#define EC20_MODULE_SEND_MAX_SIZE 1460
@ -916,12 +920,15 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
int socket = 0;
rt_size_t bfsz = 0, temp_size = 0;
rt_int32_t timeout;
char *recv_buf = RT_NULL, temp[8];
RT_ASSERT(data && size);
/* get the current socket and receive buffer size by receive data */
sscanf(data, "+QIURC: \"recv\",%d,%d", &socket, (int *) &bfsz);
/* get receive timeout by receive buffer length */
timeout = bfsz;
if (socket < 0 || bfsz == 0)
return;
@ -935,11 +942,11 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
if (bfsz - temp_size > sizeof(temp))
{
at_client_recv(temp, sizeof(temp));
at_client_recv(temp, sizeof(temp), timeout);
}
else
{
at_client_recv(temp, bfsz - temp_size);
at_client_recv(temp, bfsz - temp_size, timeout);
}
temp_size += sizeof(temp);
}
@ -947,7 +954,7 @@ static void urc_recv_func(const char *data, rt_size_t size)
}
/* sync receive data */
if (at_client_recv(recv_buf, bfsz) != bfsz)
if (at_client_recv(recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("receive size(%d) data failed!", bfsz);
rt_free(recv_buf);

View File

@ -31,7 +31,7 @@
#include <at_socket.h>
#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10000
#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10100
#error "This AT Client version is older, please check and update latest AT Client!"
#endif
@ -441,12 +441,15 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
int socket = 0;
rt_size_t bfsz = 0, temp_size = 0;
rt_int32_t timeout;
char *recv_buf = RT_NULL, temp[8];
RT_ASSERT(data && size);
/* get the current socket and receive buffer size by receive data */
sscanf(data, "+IPD,%d,%d:", &socket, (int *) &bfsz);
/* get receive timeout by receive buffer length */
timeout = bfsz;
if (socket < 0 || bfsz == 0)
return;
@ -460,11 +463,11 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
if (bfsz - temp_size > sizeof(temp))
{
at_client_recv(temp, sizeof(temp));
at_client_recv(temp, sizeof(temp), timeout);
}
else
{
at_client_recv(temp, bfsz - temp_size);
at_client_recv(temp, bfsz - temp_size, timeout);
}
temp_size += sizeof(temp);
}
@ -472,7 +475,7 @@ static void urc_recv_func(const char *data, rt_size_t size)
}
/* sync receive data */
if (at_client_recv(recv_buf, bfsz) != bfsz)
if (at_client_recv(recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("receive size(%d) data failed!", bfsz);
rt_free(recv_buf);

View File

@ -31,7 +31,7 @@
#include <at.h>
#include <at_socket.h>
#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10000
#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10100
#error "This AT Client version is older, please check and update latest AT Client!"
#endif
@ -516,12 +516,15 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
int socket = 0;
rt_size_t bfsz = 0, temp_size = 0;
rt_int32_t timeout;
char *recv_buf = RT_NULL, temp[8];
RT_ASSERT(data && size);
/* get the current socket and receive buffer size by receive data */
sscanf(data, "+RECEIVE: %d, %d", &socket, (int *) &bfsz);
/* get receive timeout by receive buffer length */
timeout = bfsz;
if (socket < 0 || bfsz == 0)
return;
@ -535,11 +538,11 @@ static void urc_recv_func(const char *data, rt_size_t size)
{
if (bfsz - temp_size > sizeof(temp))
{
at_client_recv(temp, sizeof(temp));
at_client_recv(temp, sizeof(temp), timeout);
}
else
{
at_client_recv(temp, bfsz - temp_size);
at_client_recv(temp, bfsz - temp_size, timeout);
}
temp_size += sizeof(temp);
}
@ -547,7 +550,7 @@ static void urc_recv_func(const char *data, rt_size_t size)
}
/* sync receive data */
if (at_client_recv(recv_buf, bfsz) != bfsz)
if (at_client_recv(recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("receive size(%d) data failed!", bfsz);
rt_free(recv_buf);