diff --git a/board/TencentOS_tiny_EVB_G0/KEIL/mqtt_iot_explorer_based_tencent_firmware/TencentOS_tiny_EVB_G0.uvoptx b/board/TencentOS_tiny_EVB_G0/KEIL/mqtt_iot_explorer_based_tencent_firmware/TencentOS_tiny_EVB_G0.uvoptx index e01ec1a8..de564e92 100644 --- a/board/TencentOS_tiny_EVB_G0/KEIL/mqtt_iot_explorer_based_tencent_firmware/TencentOS_tiny_EVB_G0.uvoptx +++ b/board/TencentOS_tiny_EVB_G0/KEIL/mqtt_iot_explorer_based_tencent_firmware/TencentOS_tiny_EVB_G0.uvoptx @@ -699,7 +699,7 @@ tos/kernel - 1 + 0 0 0 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c index 93dda2f4..49ee08ca 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/mqttclient.c @@ -4,17 +4,17 @@ #include "esp8266.h" #include "mqttclient.h" -//#define USE_ESP8266 +#define USE_ESP8266 +//#define USE_NB_BC35 -#define USE_NB_BC35 - -#ifdef USE_ESP8266 -static hal_uart_port_t esp8266_port = HAL_UART_PORT_0; - -void mqtt_set_esp8266_port(hal_uart_port_t port) { - esp8266_port = port; -} -#endif +/* Tencent IoThub Device Info */ +#define IOTHUB_MQTT_IP "111.230.189.156" +#define IOTHUB_MQTT_PORT "1883" +#define IOTHUB_MQTT_CLIENT_ID "KHHIXM0JJ5dev001" +#define IOTHUB_MQTT_USERNAME "KHHIXM0JJ5dev001;12010126;9K3WO;1647628324" +#define IOTHUB_MQTT_PASSWD "53696f22a061ed2524b1de185815ad2fcae7739afd3f395cb6131521da7f0bb7;hmacsha256" +#define IOTHUB_MQTT_PUB_TOPIC "KHHIXM0JJ5/dev001/data" +#define IOTHUB_MQTT_SUB_TOPIC "KHHIXM0JJ5/dev001/control" static void tos_topic_handler(void* client, message_data_t* msg) { @@ -39,8 +39,8 @@ void mqttclient_task(void) memset(&msg, 0, sizeof(msg)); #ifdef USE_ESP8266 - esp8266_sal_init(esp8266_port); - esp8266_join_ap("Supowang", "13975428888"); + esp8266_sal_init(HAL_UART_PORT_0); + esp8266_join_ap("Mculover666", "mculover666"); #endif #ifdef USE_NB_BC35 @@ -52,18 +52,18 @@ void mqttclient_task(void) client = mqtt_lease(); - mqtt_set_port(client, "1883"); - mqtt_set_host(client, "111.230.189.156"); - mqtt_set_client_id(client, "RUAP1R610Vsupowang"); - mqtt_set_user_name(client, "RUAP1R610Vsupowang;12010126;80LJ2;1621294860"); - mqtt_set_password(client, "2e90a9f1e604f2f0473355228c3d59276951aa8e6ed4d27f270f05ee8a4d0983;hmacsha256"); + mqtt_set_port(client, IOTHUB_MQTT_PORT); + mqtt_set_host(client, IOTHUB_MQTT_IP); + mqtt_set_client_id(client, IOTHUB_MQTT_CLIENT_ID); + mqtt_set_user_name(client, IOTHUB_MQTT_USERNAME); + mqtt_set_password(client, IOTHUB_MQTT_PASSWD); mqtt_set_clean_session(client, 1); error = mqtt_connect(client); MQTT_LOG_D("mqtt connect error is %#x", error); - mqtt_subscribe(client, "RUAP1R610V/supowang/data", QOS0, tos_topic_handler); + mqtt_subscribe(client, IOTHUB_MQTT_SUB_TOPIC, QOS0, tos_topic_handler); MQTT_LOG_D("mqtt subscribe error is %#x", error); @@ -76,7 +76,7 @@ void mqttclient_task(void) msg.qos = QOS0; msg.payload = (void *) buf; - error = mqtt_publish(client, "RUAP1R610V/supowang/data", &msg); + error = mqtt_publish(client, IOTHUB_MQTT_PUB_TOPIC, &msg); tos_task_delay(4000); } diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx index 380fa5e4..c62dfd1e 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvoptx @@ -410,7 +410,7 @@ examples - 0 + 1 0 0 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx index c5ef3a3b..6d82e351 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/mqttclient/TencentOS_tiny.uvprojx @@ -10,14 +10,14 @@ TencentOS_tiny 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 STM32L431RCTx STMicroelectronics - Keil.STM32L4xx_DFP.2.2.0 - http://www.keil.com/pack + Keil.STM32L4xx_DFP.2.3.0 + https://www.keil.com/pack/ IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") @@ -185,6 +185,7 @@ 0 2 0 + 0 0 0 8 @@ -351,7 +352,7 @@ 0 0 0 - 0 + 4 @@ -1024,4 +1025,19 @@ + + + + <Project Info> + + + + + + 0 + 1 + + + + diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx index 07c4baab..67ad7807 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvoptx @@ -148,40 +148,7 @@ -U303030303030303030303031 -O10446 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32L4xx_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32L431RCTx$CMSIS\Flash\STM32L4xx_256.FLM) - - - 0 - 0 - 69 - 1 -
134234708
- 0 - 0 - 0 - 0 - 0 - 1 - ..\..\..\..\examples\tcp_through_module\tcp_through_module.c - - \\TencentOS_tiny\../../../../examples/tcp_through_module/tcp_through_module.c\69 -
- - 1 - 0 - 66 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - ..\..\..\..\examples\tcp_through_module\tcp_through_module.c - - -
-
+ 0 @@ -303,7 +270,7 @@ Application/User - 0 + 1 0 0 0 @@ -1203,7 +1170,7 @@ at - 0 + 1 0 0 0 @@ -1223,7 +1190,7 @@ devices - 0 + 1 0 0 0 @@ -1239,17 +1206,65 @@ 0 0 + + 12 + 73 + 1 + 0 + 0 + 0 + ..\..\..\..\devices\ec200s\ec200s.c + ec200s.c + 0 + 0 + + + 12 + 74 + 1 + 0 + 0 + 0 + ..\..\..\..\devices\ec20\ec20.c + ec20.c + 0 + 0 + + + 12 + 75 + 1 + 0 + 0 + 0 + ..\..\..\..\devices\air724\air724.c + air724.c + 0 + 0 + + + 12 + 76 + 1 + 0 + 0 + 0 + ..\..\..\..\devices\l610\l610.c + l610.c + 0 + 0 + sal_module_wrapper - 0 + 1 0 0 0 13 - 73 + 77 1 0 0 @@ -1269,7 +1284,7 @@ 0 14 - 74 + 78 1 0 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx index d4c86d18..aec8a94f 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/tcp_through_module/TencentOS_tiny.uvprojx @@ -16,8 +16,8 @@ STM32L431RCTx STMicroelectronics - Keil.STM32L4xx_DFP.2.4.0 - http://www.keil.com/pack/ + Keil.STM32L4xx_DFP.2.3.0 + https://www.keil.com/pack/ IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") @@ -339,7 +339,7 @@ USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER - ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\BH1750;..\..\..\..\devices\esp8266;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\devices\ec20 + ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\BH1750;..\..\..\..\devices\esp8266;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\devices\ec20;..\..\..\..\devices\ec200s;..\..\..\..\devices\air724;..\..\..\..\devices\l610
@@ -798,6 +798,26 @@ 1 ..\..\..\..\devices\esp8266\esp8266.c + + ec200s.c + 1 + ..\..\..\..\devices\ec200s\ec200s.c + + + ec20.c + 1 + ..\..\..\..\devices\ec20\ec20.c + + + air724.c + 1 + ..\..\..\..\devices\air724\air724.c + + + l610.c + 1 + ..\..\..\..\devices\l610\l610.c +
diff --git a/devices/air724/air724.c b/devices/air724/air724.c index 1e3d9c51..1bb575de 100644 --- a/devices/air724/air724.c +++ b/devices/air724/air724.c @@ -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; } } diff --git a/devices/ec20/ec20.c b/devices/ec20/ec20.c index 565360f0..fc31d519 100644 --- a/devices/ec20/ec20.c +++ b/devices/ec20/ec20.c @@ -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) */ - 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; } diff --git a/devices/ec200s/ec200s.c b/devices/ec200s/ec200s.c index e2231fb9..2458849b 100644 --- a/devices/ec200s/ec200s.c +++ b/devices/ec200s/ec200s.c @@ -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) */ - 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; } diff --git a/devices/esp8266/esp8266.c b/devices/esp8266/esp8266.c index cd3df29f..809ea6fe 100644 --- a/devices/esp8266/esp8266.c +++ b/devices/esp8266/esp8266.c @@ -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; diff --git a/devices/esp8266_tencent_firmware/esp8266_tencent_firmware.c b/devices/esp8266_tencent_firmware/esp8266_tencent_firmware.c index f390e85a..14924571 100644 --- a/devices/esp8266_tencent_firmware/esp8266_tencent_firmware.c +++ b/devices/esp8266_tencent_firmware/esp8266_tencent_firmware.c @@ -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; } diff --git a/devices/l610/l610.c b/devices/l610/l610.c index dc813963..c82e5a75 100644 --- a/devices/l610/l610.c +++ b/devices/l610/l610.c @@ -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: ,, */ - 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: ,, ,, */ - 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'); diff --git a/examples/tcp_through_module/tcp_through_module.c b/examples/tcp_through_module/tcp_through_module.c index beb7e6f2..9c8e2f8b 100644 --- a/examples/tcp_through_module/tcp_through_module.c +++ b/examples/tcp_through_module/tcp_through_module.c @@ -7,6 +7,8 @@ //#define USE_BC26 //#define USE_EC20 //#define USE_EC200S +//#define USE_AIR724 +//#define USE_L610 #ifdef USE_ESP8266 #include "esp8266.h" @@ -28,6 +30,14 @@ #include "ec200s.h" #endif +#ifdef USE_AIR724 +#include "air724.h" +#endif + +#ifdef USE_L610 +#include "l610.h" +#endif + #define TCP_TEST_TASK0_STK_SIZE 4096 void tcp_test0(void); osThreadDef(tcp_test0, osPriorityNormal, 1, TCP_TEST_TASK0_STK_SIZE); @@ -90,7 +100,7 @@ void application_entry(void *arg) { #if defined(USE_ESP8266) esp8266_sal_init(HAL_UART_PORT_0); - esp8266_join_ap("SheldonDai", "srnr6x9xbhmb0"); + esp8266_join_ap("Mculover666", "mculover666"); #elif defined(USE_SIM800A) sim800a_power_on(); sim800a_sal_init(HAL_UART_PORT_2); @@ -99,7 +109,11 @@ void application_entry(void *arg) #elif defined(USE_EC20) ec20_sal_init(HAL_UART_PORT_0); #elif defined(USE_EC200S) - ec200s_sal_init(HAL_UART_PORT_2); + ec200s_sal_init(HAL_UART_PORT_0); +#elif defined(USE_AIR724) + air724_sal_init(HAL_UART_PORT_0); +#elif defined(USE_L610) + l610_sal_init(HAL_UART_PORT_0); #endif socket_id_0 = tos_sal_module_connect("117.50.111.72", "8080", TOS_SAL_PROTO_TCP); diff --git a/net/at/include/tos_at.h b/net/at/include/tos_at.h index a119fa42..d9ad252a 100644 --- a/net/at/include/tos_at.h +++ b/net/at/include/tos_at.h @@ -21,10 +21,6 @@ #include "tos_k.h" #include "tos_hal.h" -#define AT_AGENT_ECHO_OK "OK" -#define AT_AGENT_ECHO_FAIL "FAIL" -#define AT_AGENT_ECHO_ERROR "ERROR" - #define AT_DATA_CHANNEL_NUM 6 #define AT_DATA_CHANNEL_FIFO_BUFFER_SIZE (2048 + 1024) @@ -54,6 +50,9 @@ typedef enum at_parse_status_en { AT_PARSE_STATUS_EVENT, AT_PARSE_STATUS_EXPECT, AT_PARSE_STATUS_OVERFLOW, + AT_PARSE_STATUS_OK, + AT_PARSE_STATUS_FAIL, + AT_PARSE_STATUS_ERROR } at_parse_status_t; typedef enum at_echo_status_en { @@ -92,6 +91,7 @@ typedef struct at_echo_st { size_t __w_idx; int __is_expecting; k_sem_t __expect_notify; + k_sem_t __status_set_notify; int __is_fuzzy_match; } at_echo_t; diff --git a/net/at/src/tos_at.c b/net/at/src/tos_at.c index cead9cf6..8a9bf496 100644 --- a/net/at/src/tos_at.c +++ b/net/at/src/tos_at.c @@ -219,7 +219,7 @@ __STATIC__ at_parse_status_t at_uart_line_parse(void) recv_cache->buffer[recv_cache->buffer_size - 1] = '\0'; return AT_PARSE_STATUS_OVERFLOW; } - + if (at_get_event() != K_NULL) { return AT_PARSE_STATUS_EVENT; } @@ -227,6 +227,14 @@ __STATIC__ at_parse_status_t at_uart_line_parse(void) if (at_is_echo_expect()) { return AT_PARSE_STATUS_EXPECT; } + + if (strstr((char*)recv_cache->buffer, "OK")) { + return AT_PARSE_STATUS_OK; + } else if (strstr((char*)recv_cache->buffer, "FAIL")) { + return AT_PARSE_STATUS_FAIL; + } else if (strstr((char*)recv_cache->buffer, "ERROR")) { + return AT_PARSE_STATUS_ERROR; + } if (data == '\n' && last_data == '\r') { // 0xd 0xa curr_len -= 1; @@ -247,24 +255,6 @@ __STATIC__ at_parse_status_t at_uart_line_parse(void) } } -__STATIC__ void at_echo_status_set(at_echo_t *echo) -{ - char *buffer; - at_cache_t *at_cache; - - at_cache = &AT_AGENT->recv_cache; - - buffer = (char *)at_cache->buffer; - - if (strstr(buffer, AT_AGENT_ECHO_OK) != K_NULL) { - echo->status = AT_ECHO_STATUS_OK; - } else if (strstr(buffer, AT_AGENT_ECHO_ERROR) != K_NULL) { - echo->status = AT_ECHO_STATUS_ERROR; - } else if (strstr(buffer, AT_AGENT_ECHO_FAIL) != K_NULL) { - echo->status = AT_ECHO_STATUS_FAIL; - } -} - __STATIC__ void at_echo_buffer_copy(at_cache_t *at_cache, at_echo_t *echo) { uint8_t *recv_buffer = K_NULL; @@ -296,6 +286,8 @@ __STATIC__ void at_parser(void *arg) while (K_TRUE) { at_parse_status = at_uart_line_parse(); + + tos_kprintln("--->%s", recv_cache->buffer); if (at_parse_status == AT_PARSE_STATUS_OVERFLOW) { tos_kprintln("AT parse overflow!"); @@ -314,22 +306,32 @@ __STATIC__ void at_parser(void *arg) if (!at_echo) { continue; } + + if (at_echo->buffer) { + at_echo_buffer_copy(recv_cache, at_echo); + } if (at_parse_status == AT_PARSE_STATUS_EXPECT) { at_echo->status = AT_ECHO_STATUS_EXPECT; if (at_echo->__is_expecting) { tos_sem_post(&at_echo->__expect_notify); } - } else if (at_parse_status == AT_PARSE_STATUS_NEWLINE && - at_echo->status == AT_ECHO_STATUS_NONE) { - at_echo_status_set(at_echo); + } else if (at_parse_status == AT_PARSE_STATUS_OK) { + at_echo->status = AT_ECHO_STATUS_OK; + if (!at_echo->__is_expecting) { + tos_sem_post(&at_echo->__status_set_notify); + } + } else if (at_parse_status == AT_PARSE_STATUS_FAIL) { + at_echo->status = AT_ECHO_STATUS_FAIL; + if (!at_echo->__is_expecting) { + tos_sem_post(&at_echo->__status_set_notify); + } + } else if (at_parse_status == AT_PARSE_STATUS_ERROR) { + at_echo->status = AT_ECHO_STATUS_ERROR; + if (!at_echo->__is_expecting) { + tos_sem_post(&at_echo->__status_set_notify); + } } - - if (at_echo->buffer) { - at_echo_buffer_copy(recv_cache, at_echo); - } - - tos_kprintln("--->%s", recv_cache->buffer); } } @@ -466,11 +468,17 @@ __API__ int tos_at_cmd_exec(at_echo_t *echo, uint32_t timeout, const char *cmd, { int ret = 0; va_list args; - - if (echo) { - at_echo_attach(echo); + + if (tos_sem_create(&echo->__status_set_notify, 0) != K_ERR_NONE) { + return -1; + } + + if (!echo) { + return -1; } + at_echo_attach(echo); + va_start(args, cmd); ret = at_cmd_do_exec(cmd, args); va_end(args); @@ -480,11 +488,15 @@ __API__ int tos_at_cmd_exec(at_echo_t *echo, uint32_t timeout, const char *cmd, return -1; } - tos_task_delay(tos_millisec2tick(timeout)); + if (tos_sem_pend(&echo->__status_set_notify, tos_millisec2tick(timeout)) != K_ERR_NONE) { + ret = -1; + } + + tos_sem_destroy(&echo->__status_set_notify); AT_AGENT->echo = K_NULL; - return 0; + return ret; } __API__ int tos_at_cmd_exec_until(at_echo_t *echo, uint32_t timeout, const char *cmd, ...)