improve at firmware

This commit is contained in:
mculover666
2021-01-26 10:59:47 +08:00
parent 4cbeadbc19
commit 5ecbc13f64
15 changed files with 497 additions and 537 deletions

View File

@@ -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;
}
}