improve at firmware
This commit is contained in:
@@ -55,8 +55,7 @@ static int air724_echo_close(void)
|
||||
|
||||
while(try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 300, "ATE0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -71,8 +70,7 @@ static int air724_cscon_close(void)
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 300, "AT+CSCON=0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
tos_sleep_ms(1000);
|
||||
@@ -85,16 +83,14 @@ static int air724_sim_card_check(void)
|
||||
int try = 0;
|
||||
char echo_buffer[32];
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+CPIN?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strstr(echo.buffer, "READY"))
|
||||
{
|
||||
if(strstr(echo.buffer, "READY")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,18 +107,15 @@ static int air724_signal_quality_check(void)
|
||||
char echo_buffer[32], *str;
|
||||
int try = 0;
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CSQ:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
|
||||
@@ -142,27 +135,23 @@ static int air724_gsm_network_check(void)
|
||||
char echo_buffer[32], *str;
|
||||
int try = 0;
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CREG:%d,%d", &n, &stat);
|
||||
if (stat == 1)
|
||||
{
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tos_sleep_ms(1000);
|
||||
tos_sleep_ms(2000);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -174,23 +163,19 @@ static int air724_gprs_network_check(void)
|
||||
char echo_buffer[32], *str;
|
||||
int try = 0;
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CGREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CGREG:%d,%d", &n, &stat);
|
||||
if (stat == 1)
|
||||
{
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -208,8 +193,7 @@ static int air724_close_apn(void)
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+CIPSHUT\r\n");
|
||||
|
||||
if(strstr(echo.buffer, "SHUT OK") == NULL)
|
||||
{
|
||||
if(strstr(echo.buffer, "SHUT OK") == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -224,12 +208,10 @@ static int air724_send_mode_set(air724_send_mode_t mode)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 300, "AT+CIPMODE=%d\r\n", mode == SAL_SEND_MODE_NORMAL ? 0 : 1);
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -244,12 +226,10 @@ static int air724_multilink_set(air724_multilink_state_t state)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 300, "AT+CIPMUX=%d\r\n", state == AIR724_MULTILINK_STATE_ENABLE ? 1 : 0);
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -262,15 +242,13 @@ static int air724_set_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 300, "AT+CSTT=\"CMNET\"\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 50000, "AT+CIICR\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -295,63 +273,53 @@ static int air724_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (air724_echo_close() != 0)
|
||||
{
|
||||
if (air724_echo_close() != 0) {
|
||||
printf("echo close failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (air724_cscon_close() != 0)
|
||||
{
|
||||
if (air724_cscon_close() != 0) {
|
||||
printf("cscon close failed\n");
|
||||
return -1;
|
||||
}
|
||||
if(air724_sim_card_check() != 0)
|
||||
{
|
||||
if(air724_sim_card_check() != 0) {
|
||||
printf("sim card check failed,please insert your card\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (air724_signal_quality_check() != 0)
|
||||
{
|
||||
if (air724_signal_quality_check() != 0) {
|
||||
printf("signal quality check status failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(air724_gsm_network_check() != 0)
|
||||
{
|
||||
if(air724_gsm_network_check() != 0) {
|
||||
printf("GSM network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(air724_gprs_network_check() != 0)
|
||||
{
|
||||
if(air724_gprs_network_check() != 0) {
|
||||
printf("GPRS network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(air724_close_apn() != 0)
|
||||
{
|
||||
if(air724_close_apn() != 0) {
|
||||
printf("close apn failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
if (air724_multilink_set(SAL_MULTILINK_STATE_DISABLE) != 0)
|
||||
{
|
||||
if (air724_multilink_set(SAL_MULTILINK_STATE_DISABLE) != 0) {
|
||||
printf("multilink set FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else
|
||||
if (air724_multilink_set(AIR724_MULTILINK_STATE_ENABLE) != 0)
|
||||
{
|
||||
if (air724_multilink_set(AIR724_MULTILINK_STATE_ENABLE) != 0) {
|
||||
printf("multilink set FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (air724_send_mode_set(AIR724_SEND_MODE_NORMAL) != 0)
|
||||
{
|
||||
if (air724_send_mode_set(AIR724_SEND_MODE_NORMAL) != 0) {
|
||||
printf("send mode set FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -376,7 +344,7 @@ static int air724_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "%s=1\r\n", "AT+CIPHEAD");
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+CIPHEAD=1\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
@@ -384,10 +352,11 @@ static int air724_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK");
|
||||
tos_at_cmd_exec(&echo, 4000, "AT+CIPSTART=%s,%s,%s\r\n",
|
||||
tos_at_cmd_exec_until(&echo, 4000, "AT+CIPSTART=%s,%s,%s\r\n",
|
||||
proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return id;
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
char result[20];
|
||||
@@ -395,13 +364,13 @@ static int air724_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
tos_at_echo_create(&echo, NULL, 0, result);
|
||||
tos_at_cmd_exec_until(&echo, 8000, "AT+CIPSTART=%d,%s,%s,%d\r\n",
|
||||
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return id;
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static int air724_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
@@ -417,36 +386,33 @@ static int air724_recv(int id, void *buf, size_t len)
|
||||
int air724_send(int id, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
char expect[10] = "";
|
||||
char expect_str[10];
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d\r\n",
|
||||
len);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,%d\r\n",
|
||||
id, len);
|
||||
#endif
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(expect, "%d, SEND OK", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, expect);
|
||||
sprintf(expect_str, "%d, SEND OK", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, expect_str);
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -470,33 +436,30 @@ int air724_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d\r\n",
|
||||
len);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,%d\r\n",
|
||||
id, len);
|
||||
#endif
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
tos_at_raw_data_send_until(&echo, 1000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -513,12 +476,16 @@ static void air724_transparent_mode_exit(void)
|
||||
|
||||
static int air724_close(int id)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
air724_transparent_mode_exit();
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE\r\n");
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE\r\n");
|
||||
#else
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
#endif
|
||||
|
||||
tos_at_channel_free(id);
|
||||
@@ -535,8 +502,7 @@ static int air724_parse_domain(const char *host_name, char *host_ip, size_t host
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CDNSGIP=\"%s\"\r\n", host_name);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -563,48 +529,38 @@ __STATIC__ void air724_incoming_data_process(void)
|
||||
+RECEIVE: prefix
|
||||
0: scoket id
|
||||
*/
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
channel_id = channel_id * 10 + (data - '0');
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ':')
|
||||
{
|
||||
if (data == ':') {
|
||||
break;
|
||||
}
|
||||
data_len = data_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == '\n')
|
||||
{
|
||||
if (data == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -639,15 +595,12 @@ __STATIC__ void air724_domain_data_process(void)
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -658,15 +611,12 @@ __STATIC__ void air724_domain_data_process(void)
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ typedef struct ip_addr_st {
|
||||
}ip_addr_t;
|
||||
|
||||
static ip_addr_t domain_parser_addr = {0};
|
||||
k_sem_t domain_parser_sem;
|
||||
static k_sem_t domain_parser_sem;
|
||||
|
||||
static int ec20_echo_close(void)
|
||||
{
|
||||
@@ -40,8 +40,7 @@ static int ec20_echo_close(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -53,8 +52,7 @@ static int ec20_sim_card_check(void)
|
||||
char echo_buffer[32];
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
@@ -77,8 +75,7 @@ static int ec20_signal_quality_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
@@ -106,16 +103,14 @@ static int ec20_gsm_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CREG:%d,%d", &n, &stat);
|
||||
@@ -134,23 +129,19 @@ static int ec20_gprs_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CGREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CGREG:%d,%d", &n, &stat);
|
||||
if (stat == 1)
|
||||
{
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -164,8 +155,7 @@ static int ec20_close_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -178,14 +168,12 @@ static int ec20_set_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 300, "AT+QICSGP=1,1,\"CMNET\"\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_cmd_exec_until(&echo, 3000, "AT+QIACT=1\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -196,38 +184,32 @@ static int ec20_init(void)
|
||||
{
|
||||
printf("Init ec20 ...\n" );
|
||||
|
||||
if (ec20_echo_close() != 0)
|
||||
{
|
||||
if (ec20_echo_close() != 0) {
|
||||
printf("echo close failed,please check your module\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec20_sim_card_check() != 0)
|
||||
{
|
||||
if(ec20_sim_card_check() != 0) {
|
||||
printf("sim card check failed,please insert your card\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ec20_signal_quality_check() != 0)
|
||||
{
|
||||
if (ec20_signal_quality_check() != 0) {
|
||||
printf("signal quality check status failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec20_gsm_network_check() != 0)
|
||||
{
|
||||
if(ec20_gsm_network_check() != 0) {
|
||||
printf("GSM network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec20_gprs_network_check() != 0)
|
||||
{
|
||||
if(ec20_gprs_network_check() != 0) {
|
||||
printf("GPRS network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec20_close_apn() != 0)
|
||||
{
|
||||
if(ec20_close_apn() != 0) {
|
||||
printf("close apn failed\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -245,25 +227,30 @@ static int ec20_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
{
|
||||
int id;
|
||||
at_echo_t echo;
|
||||
char except_str[16];
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
if (id == -1)
|
||||
{
|
||||
if (id == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK");
|
||||
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)
|
||||
{
|
||||
return id;
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
|
||||
sprintf(except_str, "+QIOPEN: %d,0", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, except_str);
|
||||
tos_at_cmd_exec_until(&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_EXPECT) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static int ec20_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
@@ -284,25 +271,22 @@ int ec20_send(int id, const void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -326,25 +310,22 @@ int ec20_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -356,14 +337,20 @@ int ec20_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
|
||||
static void ec20_transparent_mode_exit(void)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(NULL, 500, "+++");
|
||||
}
|
||||
|
||||
static int ec20_close(int id)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
ec20_transparent_mode_exit();
|
||||
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
|
||||
tos_at_channel_free(id);
|
||||
|
||||
@@ -404,36 +391,28 @@ __STATIC__ void ec20_incoming_data_process(void)
|
||||
<data content>
|
||||
*/
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
channel_id = channel_id * 10 + (data - '0');
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == '\r')
|
||||
{
|
||||
if (data == '\r') {
|
||||
break;
|
||||
}
|
||||
data_len = data_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -32,8 +32,8 @@ typedef struct ip_addr_st {
|
||||
}ip_addr_t;
|
||||
|
||||
static ip_addr_t domain_parser_addr = {0};
|
||||
k_sem_t domain_parser_sem;
|
||||
k_sem_t module_ready_sem;
|
||||
static k_sem_t domain_parser_sem;
|
||||
static k_sem_t module_ready_sem;
|
||||
|
||||
static int ec200s_check_ready(void)
|
||||
{
|
||||
@@ -92,19 +92,17 @@ static int ec200s_signal_quality_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CSQ:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
|
||||
if (rssi != 99) {
|
||||
return 0;
|
||||
@@ -121,16 +119,14 @@ static int ec200s_gsm_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CREG:%d,%d", &n, &stat);
|
||||
@@ -138,6 +134,7 @@ static int ec200s_gsm_network_check(void)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -149,28 +146,24 @@ static int ec200s_gprs_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CGREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CGREG:%d,%d", &n, &stat);
|
||||
if (stat == 1)
|
||||
{
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int ec200s_close_apn(void)
|
||||
@@ -179,8 +172,7 @@ static int ec200s_close_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -193,16 +185,14 @@ static int ec200s_set_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICSGP=1,1,\"CMNET\"\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_cmd_exec(&echo, 3000, "AT+QIACT=1\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -216,38 +206,32 @@ static int ec200s_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ec200s_echo_close() != 0)
|
||||
{
|
||||
if (ec200s_echo_close() != 0) {
|
||||
printf("echo close failed,please check your module\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec200s_sim_card_check() != 0)
|
||||
{
|
||||
if(ec200s_sim_card_check() != 0) {
|
||||
printf("sim card check failed,please insert your card\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ec200s_signal_quality_check() != 0)
|
||||
{
|
||||
if (ec200s_signal_quality_check() != 0) {
|
||||
printf("signal quality check status failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec200s_gsm_network_check() != 0)
|
||||
{
|
||||
if(ec200s_gsm_network_check() != 0) {
|
||||
printf("GSM network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec200s_gprs_network_check() != 0)
|
||||
{
|
||||
if(ec200s_gprs_network_check() != 0) {
|
||||
printf("GPRS network register status check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ec200s_close_apn() != 0)
|
||||
{
|
||||
if(ec200s_close_apn() != 0) {
|
||||
printf("close apn failed\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -265,25 +249,30 @@ static int ec200s_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
{
|
||||
int id;
|
||||
at_echo_t echo;
|
||||
char except_str[16];
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
if (id == -1)
|
||||
{
|
||||
if (id == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK");
|
||||
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)
|
||||
{
|
||||
return id;
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
|
||||
sprintf(except_str, "+QIOPEN: %d,0", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, except_str);
|
||||
tos_at_cmd_exec_until(&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_EXPECT) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static int ec200s_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
|
||||
@@ -304,25 +293,22 @@ int ec200s_send(int id, const void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -346,25 +332,21 @@ int ec200s_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -376,14 +358,20 @@ int ec200s_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
|
||||
static void ec200s_transparent_mode_exit(void)
|
||||
{
|
||||
tos_at_cmd_exec(NULL, 500, "+++");
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 500, "+++");
|
||||
}
|
||||
|
||||
static int ec200s_close(int id)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
ec200s_transparent_mode_exit();
|
||||
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
|
||||
|
||||
tos_at_channel_free(id);
|
||||
|
||||
@@ -424,36 +412,28 @@ __STATIC__ void ec200s_incoming_data_process(void)
|
||||
<data content>
|
||||
*/
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
channel_id = channel_id * 10 + (data - '0');
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == '\r')
|
||||
{
|
||||
if (data == '\r') {
|
||||
break;
|
||||
}
|
||||
data_len = data_len * 10 + (data - '0');
|
||||
}
|
||||
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -55,10 +55,10 @@ static int esp8266_net_mode_set(esp8266_net_mode_t mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "no change");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -85,11 +85,13 @@ static int esp8266_multilink_set(esp8266_multilink_state_t state)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "link is builded");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 500, "AT+CIPMUX=%d\r\n", state == ESP8266_MULTILINK_STATE_ENABLE ? 1 : 0);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
} else if (echo.status == AT_ECHO_STATUS_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -100,10 +102,10 @@ int esp8266_join_ap(const char *ssid, const char *pwd)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec_until(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -141,24 +143,22 @@ static int esp8266_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
int id;
|
||||
at_echo_t echo;
|
||||
|
||||
esp8266_reconnect_init();
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
if (id == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec_until(&echo, 10000,
|
||||
tos_at_cmd_exec(&echo, 10000,
|
||||
"AT+CIPSTART=\"%s\",\"%s\",%s\r\n",
|
||||
proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
|
||||
#else
|
||||
tos_at_cmd_exec_until(&echo, 10000,
|
||||
tos_at_cmd_exec(&echo, 10000,
|
||||
"AT+CIPSTART=%d,\"%s\",\"%s\",%s\r\n",
|
||||
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
|
||||
#endif
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -202,14 +202,14 @@ static int esp8266_send(int id, const void *buf, size_t len)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), ">");
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 5000,
|
||||
"AT+CIPSEND=%d\r\n", len);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 5000,
|
||||
"AT+CIPSEND=%d,%d\r\n",
|
||||
id, len);
|
||||
#endif
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
}
|
||||
@@ -255,23 +255,23 @@ static int esp8266_sendto(int id, char *ip, char *port, const void *buf, size_t
|
||||
|
||||
if (ip && port) {
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,\"%s\",%s\r\n", len, ip, port);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,%d,\"%s\",%s\r\n", id, len, ip, port);
|
||||
#endif
|
||||
} else {
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d\r\n", len);
|
||||
#else
|
||||
tos_at_cmd_exec(&echo, 1000,
|
||||
tos_at_cmd_exec_until(&echo, 1000,
|
||||
"AT+CIPSEND=%d,%d\r\n", id, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (esp8266_is_link_broken((const char *)echo.buffer)) {
|
||||
tos_at_channel_set_broken(id);
|
||||
}
|
||||
@@ -312,10 +312,14 @@ static int esp8266_recvfrom(int id, void *buf, size_t len)
|
||||
|
||||
static int esp8266_close(int id)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE\r\n");
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE\r\n");
|
||||
#else
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CIPCLOSE=%d\r\n", id);
|
||||
#endif
|
||||
tos_at_channel_free(id);
|
||||
return 0;
|
||||
|
@@ -15,9 +15,9 @@ int esp8266_tencent_firmware_module_info_set(device_info_t *info, tls_mode_t mod
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCDEVINFOSET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
mode, info->product_id, info->device_name, info->device_serc);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -31,10 +31,10 @@ int esp8266_tencent_firmware_module_mqtt_conn(mqtt_param_t init_params)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTCONN:OK");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
init_params.command_timeout, init_params.keep_alive_interval_ms,
|
||||
init_params.clean_session, init_params.auto_connect_enable);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -61,14 +61,14 @@ int esp8266_tencent_firmware_module_mqtt_publ(const char *topic, qos_t qos, char
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_raw_data_send_until(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ int esp8266_tencent_firmware_module_mqtt_pub(const char *topic, qos_t qos, char
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -95,8 +95,8 @@ int esp8266_tencent_firmware_module_mqtt_sub(char *topic, qos_t qos)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -108,8 +108,8 @@ int esp8266_tencent_firmware_module_mqtt_unsub(const char *topic)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTUNSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -130,8 +130,7 @@ int esp8266_tencent_firmware_module_mqtt_state_get(mqtt_state_t *state)
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+TCMQTTSTATE:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+TCMQTTSTATE:%d", &ret_state);
|
||||
@@ -164,10 +163,10 @@ int esp8266_tencent_firmware_join_ap(const char *ssid, const char *pwd)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "WIFI CONNECTED");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 10000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -181,8 +180,8 @@ static int esp8266_tencent_firmware_restore(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "ready");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -221,10 +220,10 @@ static int esp8266_tencent_firmware_net_mode_set(sal_net_mode_t mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "no change");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -281,8 +280,8 @@ int esp8266_tencent_firmware_ota_set(ota_mode_t mode, char *version)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCOTASET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -304,8 +303,8 @@ int esp8266_tencent_firmware_ota_read_fwinfo(ota_fw_info_t *ota_fw_info)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), "+TCFWINFO:");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
|
||||
sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5);
|
||||
for(int i = 0; i<10; i++)
|
||||
@@ -478,9 +477,9 @@ int esp8266_tencent_firmware_start_smartconfig(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTARTSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -504,10 +503,10 @@ int esp8266_tencent_firmware_stop_smartconfig(void)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTOPSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -53,6 +53,8 @@ static int l610_echo_close(void)
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
tos_sleep_ms(1000);
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -69,6 +71,7 @@ static int l610_sim_card_check(void)
|
||||
if (strstr(echo_buffer, "READY")) {
|
||||
return 0;
|
||||
}
|
||||
tos_sleep_ms(2000);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -82,23 +85,21 @@ static int l610_signal_quality_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CSQ:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
|
||||
if (rssi != 99) {
|
||||
return 0;
|
||||
}
|
||||
tos_sleep_ms(2000);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -111,22 +112,21 @@ static int l610_gsm_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CREG:%d,%d", &n, &stat);
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
tos_sleep_ms(2000);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -139,25 +139,23 @@ static int l610_gprs_network_check(void)
|
||||
int try = 0;
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
|
||||
while (try++ < 10)
|
||||
{
|
||||
while (try++ < 10) {
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+CGREG:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+CGREG:%d,%d", &n, &stat);
|
||||
if (stat == 1)
|
||||
{
|
||||
if (stat == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tos_sleep_ms(2000);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -169,8 +167,7 @@ static int l610_set_data_format(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+GTSET=\"IPRFMT\",0\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -186,8 +183,7 @@ static int l610_check_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, buffer, 64, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL?\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -223,8 +219,7 @@ static int l610_check_close_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, buffer, 64, NULL);
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL=0\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -247,8 +242,7 @@ static int l610_set_apn(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+MIPCALL");
|
||||
tos_at_cmd_exec_until(&echo, 10000, "AT+MIPCALL=1,\"CMNET\"\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -318,16 +312,14 @@ static int l610_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
at_echo_t echo;
|
||||
|
||||
id = tos_at_channel_alloc(ip, port);
|
||||
if (id == -1)
|
||||
{
|
||||
if (id == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+MIPOPEN");
|
||||
tos_at_cmd_exec(&echo, 4000, "AT+MIPOPEN=%d,,\"%s\",%d,%d\r\n",
|
||||
tos_at_cmd_exec_until(&echo, 4000, "AT+MIPOPEN=%d,,\"%s\",%d,%d\r\n",
|
||||
id + 1, ip, atoi(port), proto == TOS_SAL_PROTO_UDP ? 1 : 0);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_channel_free(id);
|
||||
return -1;
|
||||
}
|
||||
@@ -353,17 +345,15 @@ int l610_send(int id, const void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -371,8 +361,7 @@ int l610_send(int id, const void *buf, size_t len)
|
||||
tos_at_echo_create(&echo, NULL, 0, "+MIPSEND");
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -400,17 +389,15 @@ int l610_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tos_at_global_lock_pend() != 0)
|
||||
{
|
||||
if (tos_at_global_lock_pend() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+MIPSEND=%d,%d\r\n", id + 1, len);
|
||||
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -418,8 +405,7 @@ int l610_sendto(int id, char *ip, char *port, const void *buf, size_t len)
|
||||
tos_at_echo_create(&echo, NULL, 0, "+MIPSEND");
|
||||
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)
|
||||
{
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_global_lock_post();
|
||||
return -1;
|
||||
}
|
||||
@@ -436,8 +422,11 @@ static void l610_transparent_mode_exit(void)
|
||||
|
||||
static int l610_close(int id)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
l610_transparent_mode_exit();
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(NULL, 1000, "AT+MIPCLOSE=%d\r\n", id+1);
|
||||
|
||||
tos_at_channel_free(id);
|
||||
@@ -507,30 +496,24 @@ __STATIC__ void l610_tcp_incoming_data_process(void)
|
||||
+MIPRTCP: <socket id>,<leaf length>,<hex string>
|
||||
*/
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
channel_id = channel_id * 10 + (data - '0');
|
||||
}
|
||||
channel_id--;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
leaf_data_len = leaf_data_len * 10 + (data - '0');
|
||||
@@ -555,56 +538,44 @@ __STATIC__ void l610_udp_incoming_data_process(void)
|
||||
/*
|
||||
+MIPRUDP: <src ip>,<src port>, <socket id>,<leaf length>,<hex string>
|
||||
*/
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
channel_id = channel_id * 10 + (data - '0');
|
||||
}
|
||||
channel_id--;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tos_at_uart_read(&data, 1) != 1)
|
||||
{
|
||||
while (1) {
|
||||
if (tos_at_uart_read(&data, 1) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == ',')
|
||||
{
|
||||
if (data == ',') {
|
||||
break;
|
||||
}
|
||||
leaf_data_len = leaf_data_len * 10 + (data - '0');
|
||||
|
Reference in New Issue
Block a user