未验证 提交 59060216 编写于 作者: S Supowang 提交者: GitHub

Merge pull request #161 from Mculover666/master

modify ec20 recv mode
/**
* @brief Quectel EC20 LTGE Cat4 Module
* @author Mculover666 <2412828003@qq.com>
* @date 2020/05/07
* @brief Quectel EC20 LTGE Cat4 Module
* @author Mculover666 <2412828003@qq.com>
* @date 2020/05/07
* @changelog
2020/05/21 Mculover666 Change recv mode is Direct Push Mode
*/
#include "ec20.h"
......@@ -18,7 +20,7 @@ static int ec20_echo_close(void)
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "ATE0\r\n");
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
......@@ -30,11 +32,12 @@ static int ec20_sim_card_check(void)
at_echo_t echo;
int try = 0;
char echo_buffer[32];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+CPIN?\r\n");
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
......@@ -55,10 +58,9 @@ static int ec20_signal_quality_check(void)
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
......@@ -81,9 +83,9 @@ static int ec20_gsm_network_check(void)
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
......@@ -105,9 +107,10 @@ static int ec20_gprs_network_check(void)
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
......@@ -166,7 +169,7 @@ static int ec20_init(void)
if (ec20_echo_close() != 0)
{
printf("echo close failed\n");
printf("echo close failed,please check your module\n");
return -1;
}
......@@ -221,7 +224,7 @@ static int ec20_connect(const char *ip, const char *port, sal_proto_t proto)
}
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK");
tos_at_cmd_exec(&echo, 4000, "AT+QIOPEN=1,%d,\"%s\",\"%s\",%d,0,0\r\n",
tos_at_cmd_exec(&echo, 4000, "AT+QIOPEN=1,%d,\"%s\",\"%s\",%d,0,1\r\n",
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
if (echo.status == AT_ECHO_STATUS_OK)
{
......@@ -246,6 +249,10 @@ int ec20_send(int id, const void *buf, size_t len)
{
at_echo_t echo;
if (!tos_at_channel_is_working(id)) {
return -1;
}
if (tos_at_global_lock_pend() != 0)
{
return -1;
......@@ -262,7 +269,7 @@ int ec20_send(int id, const void *buf, size_t len)
}
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post();
......@@ -373,11 +380,10 @@ __STATIC__ void ec20_incoming_data_process(void)
uint8_t buffer[128];
/*
+QIURC: "recv",0
+QIURC: prefix
0: scoket id
+QIURC: "recv",<sockid>,<datalen>
<data content>
*/
if (tos_at_uart_read(&data, 1) != 1)
{
return;
......@@ -390,34 +396,13 @@ __STATIC__ void ec20_incoming_data_process(void)
return;
}
if (data == '\r')
if (data == ',')
{
break;
}
channel_id = channel_id * 10 + (data - '0');
}
printf("channel id = %d\n", channel_id);
tos_at_cmd_exec(NULL, 0, "AT+QIRD=%d,%d\r\n", channel_id, sizeof(buffer));
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == ':')
{
break;
}
}
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
......@@ -431,7 +416,6 @@ __STATIC__ void ec20_incoming_data_process(void)
}
data_len = data_len * 10 + (data - '0');
}
printf("data_len = %d\n", data_len);
if (tos_at_uart_read(&data, 1) != 1)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册