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

@@ -699,7 +699,7 @@
<Group> <Group>
<GroupName>tos/kernel</GroupName> <GroupName>tos/kernel</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@@ -4,17 +4,17 @@
#include "esp8266.h" #include "esp8266.h"
#include "mqttclient.h" #include "mqttclient.h"
//#define USE_ESP8266 #define USE_ESP8266
//#define USE_NB_BC35
#define USE_NB_BC35 /* Tencent IoThub Device Info */
#define IOTHUB_MQTT_IP "111.230.189.156"
#ifdef USE_ESP8266 #define IOTHUB_MQTT_PORT "1883"
static hal_uart_port_t esp8266_port = HAL_UART_PORT_0; #define IOTHUB_MQTT_CLIENT_ID "KHHIXM0JJ5dev001"
#define IOTHUB_MQTT_USERNAME "KHHIXM0JJ5dev001;12010126;9K3WO;1647628324"
void mqtt_set_esp8266_port(hal_uart_port_t port) { #define IOTHUB_MQTT_PASSWD "53696f22a061ed2524b1de185815ad2fcae7739afd3f395cb6131521da7f0bb7;hmacsha256"
esp8266_port = port; #define IOTHUB_MQTT_PUB_TOPIC "KHHIXM0JJ5/dev001/data"
} #define IOTHUB_MQTT_SUB_TOPIC "KHHIXM0JJ5/dev001/control"
#endif
static void tos_topic_handler(void* client, message_data_t* msg) static void tos_topic_handler(void* client, message_data_t* msg)
{ {
@@ -39,8 +39,8 @@ void mqttclient_task(void)
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
#ifdef USE_ESP8266 #ifdef USE_ESP8266
esp8266_sal_init(esp8266_port); esp8266_sal_init(HAL_UART_PORT_0);
esp8266_join_ap("Supowang", "13975428888"); esp8266_join_ap("Mculover666", "mculover666");
#endif #endif
#ifdef USE_NB_BC35 #ifdef USE_NB_BC35
@@ -52,18 +52,18 @@ void mqttclient_task(void)
client = mqtt_lease(); client = mqtt_lease();
mqtt_set_port(client, "1883"); mqtt_set_port(client, IOTHUB_MQTT_PORT);
mqtt_set_host(client, "111.230.189.156"); mqtt_set_host(client, IOTHUB_MQTT_IP);
mqtt_set_client_id(client, "RUAP1R610Vsupowang"); mqtt_set_client_id(client, IOTHUB_MQTT_CLIENT_ID);
mqtt_set_user_name(client, "RUAP1R610Vsupowang;12010126;80LJ2;1621294860"); mqtt_set_user_name(client, IOTHUB_MQTT_USERNAME);
mqtt_set_password(client, "2e90a9f1e604f2f0473355228c3d59276951aa8e6ed4d27f270f05ee8a4d0983;hmacsha256"); mqtt_set_password(client, IOTHUB_MQTT_PASSWD);
mqtt_set_clean_session(client, 1); mqtt_set_clean_session(client, 1);
error = mqtt_connect(client); error = mqtt_connect(client);
MQTT_LOG_D("mqtt connect error is %#x", error); 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); MQTT_LOG_D("mqtt subscribe error is %#x", error);
@@ -76,7 +76,7 @@ void mqttclient_task(void)
msg.qos = QOS0; msg.qos = QOS0;
msg.payload = (void *) buf; 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); tos_task_delay(4000);
} }

View File

@@ -410,7 +410,7 @@
<Group> <Group>
<GroupName>examples</GroupName> <GroupName>examples</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@@ -10,14 +10,14 @@
<TargetName>TencentOS_tiny</TargetName> <TargetName>TencentOS_tiny</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed> <pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32L431RCTx</Device> <Device>STM32L431RCTx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32L4xx_DFP.2.2.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack</PackURL> <PackURL>https://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu> <Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
@@ -185,6 +185,7 @@
<uocXRam>0</uocXRam> <uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP> <RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve> <RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
@@ -351,7 +352,7 @@
<NoWarn>0</NoWarn> <NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc> <uSurpInc>0</uSurpInc>
<useXO>0</useXO> <useXO>0</useXO>
<uClangAs>0</uClangAs> <ClangAsOpt>4</ClangAsOpt>
<VariousControls> <VariousControls>
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define></Define> <Define></Define>
@@ -1024,4 +1025,19 @@
<files/> <files/>
</RTE> </RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>&lt;Project Info&gt;</LayName>
<LayDesc></LayDesc>
<LayUrl></LayUrl>
<LayKeys></LayKeys>
<LayCat></LayCat>
<LayLic></LayLic>
<LayTarg>0</LayTarg>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project> </Project>

View File

@@ -148,40 +148,7 @@
<Name>-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)</Name> <Name>-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)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint/>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>69</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134234708</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\..\..\..\examples\tcp_through_module\tcp_through_module.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TencentOS_tiny\../../../../examples/tcp_through_module/tcp_through_module.c\69</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>66</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\..\..\..\examples\tcp_through_module\tcp_through_module.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@@ -303,7 +270,7 @@
<Group> <Group>
<GroupName>Application/User</GroupName> <GroupName>Application/User</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -1203,7 +1170,7 @@
<Group> <Group>
<GroupName>at</GroupName> <GroupName>at</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -1223,7 +1190,7 @@
<Group> <Group>
<GroupName>devices</GroupName> <GroupName>devices</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -1239,17 +1206,65 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </File>
<File>
<GroupNumber>12</GroupNumber>
<FileNumber>73</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\devices\ec200s\ec200s.c</PathWithFileName>
<FilenameWithoutPath>ec200s.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>12</GroupNumber>
<FileNumber>74</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\devices\ec20\ec20.c</PathWithFileName>
<FilenameWithoutPath>ec20.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>12</GroupNumber>
<FileNumber>75</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\devices\air724\air724.c</PathWithFileName>
<FilenameWithoutPath>air724.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>12</GroupNumber>
<FileNumber>76</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\devices\l610\l610.c</PathWithFileName>
<FilenameWithoutPath>l610.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group> </Group>
<Group> <Group>
<GroupName>sal_module_wrapper</GroupName> <GroupName>sal_module_wrapper</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>13</GroupNumber> <GroupNumber>13</GroupNumber>
<FileNumber>73</FileNumber> <FileNumber>77</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1269,7 +1284,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>14</GroupNumber> <GroupNumber>14</GroupNumber>
<FileNumber>74</FileNumber> <FileNumber>78</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>

View File

@@ -16,8 +16,8 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32L431RCTx</Device> <Device>STM32L431RCTx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32L4xx_DFP.2.4.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL> <PackURL>https://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu> <Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
@@ -339,7 +339,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER</Define> <Define>USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>..\..\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</IncludePath> <IncludePath>..\..\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</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@@ -798,6 +798,26 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\..\devices\esp8266\esp8266.c</FilePath> <FilePath>..\..\..\..\devices\esp8266\esp8266.c</FilePath>
</File> </File>
<File>
<FileName>ec200s.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\ec200s\ec200s.c</FilePath>
</File>
<File>
<FileName>ec20.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\ec20\ec20.c</FilePath>
</File>
<File>
<FileName>air724.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\air724\air724.c</FilePath>
</File>
<File>
<FileName>l610.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\l610\l610.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>

View File

@@ -55,8 +55,7 @@ static int air724_echo_close(void)
while(try++ < 10) { while(try++ < 10) {
tos_at_cmd_exec(&echo, 300, "ATE0\r\n"); 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; return 0;
} }
} }
@@ -71,8 +70,7 @@ static int air724_cscon_close(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 300, "AT+CSCON=0\r\n"); 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; return 0;
} }
tos_sleep_ms(1000); tos_sleep_ms(1000);
@@ -85,16 +83,14 @@ static int air724_sim_card_check(void)
int try = 0; int try = 0;
char echo_buffer[32]; char echo_buffer[32];
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+CPIN?\r\n"); tos_at_cmd_exec(&echo, 2000, "AT+CPIN?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) { if (echo.status != AT_ECHO_STATUS_OK) {
return -1; return -1;
} }
if(strstr(echo.buffer, "READY")) if(strstr(echo.buffer, "READY")) {
{
return 0; return 0;
} }
@@ -111,18 +107,15 @@ static int air724_signal_quality_check(void)
char echo_buffer[32], *str; char echo_buffer[32], *str;
int try = 0; int try = 0;
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n"); 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; return -1;
} }
str = strstr(echo.buffer, "+CSQ:"); str = strstr(echo.buffer, "+CSQ:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CSQ:%d,%d", &rssi, &ber); sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
@@ -142,27 +135,23 @@ static int air724_gsm_network_check(void)
char echo_buffer[32], *str; char echo_buffer[32], *str;
int try = 0; int try = 0;
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n"); 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; return -1;
} }
str = strstr(echo.buffer, "+CREG:"); str = strstr(echo.buffer, "+CREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CREG:%d,%d", &n, &stat); sscanf(str, "+CREG:%d,%d", &n, &stat);
if (stat == 1) if (stat == 1) {
{
return 0; return 0;
} }
tos_sleep_ms(1000); tos_sleep_ms(2000);
} }
return -1; return -1;
} }
@@ -174,23 +163,19 @@ static int air724_gprs_network_check(void)
char echo_buffer[32], *str; char echo_buffer[32], *str;
int try = 0; int try = 0;
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n"); 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; return -1;
} }
str = strstr(echo.buffer, "+CGREG:"); str = strstr(echo.buffer, "+CGREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CGREG:%d,%d", &n, &stat); sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) if (stat == 1) {
{
return 0; 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_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 3000, "AT+CIPSHUT\r\n"); 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; return -1;
} }
@@ -224,12 +208,10 @@ static int air724_send_mode_set(air724_send_mode_t mode)
int try = 0; int try = 0;
at_echo_t echo; at_echo_t echo;
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, NULL, 0, NULL); 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); 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; return 0;
} }
} }
@@ -244,12 +226,10 @@ static int air724_multilink_set(air724_multilink_state_t state)
int try = 0; int try = 0;
at_echo_t echo; at_echo_t echo;
while (try++ < 10) while (try++ < 10) {
{
tos_at_echo_create(&echo, NULL, 0, NULL); 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); 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; return 0;
} }
} }
@@ -262,15 +242,13 @@ static int air724_set_apn(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "AT+CSTT=\"CMNET\"\r\n"); 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; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 50000, "AT+CIICR\r\n"); 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; return -1;
} }
@@ -295,63 +273,53 @@ static int air724_init(void)
return -1; return -1;
} }
if (air724_echo_close() != 0) if (air724_echo_close() != 0) {
{
printf("echo close failed\n"); printf("echo close failed\n");
return -1; return -1;
} }
if (air724_cscon_close() != 0) if (air724_cscon_close() != 0) {
{
printf("cscon close failed\n"); printf("cscon close failed\n");
return -1; return -1;
} }
if(air724_sim_card_check() != 0) if(air724_sim_card_check() != 0) {
{
printf("sim card check failed,please insert your card\n"); printf("sim card check failed,please insert your card\n");
return -1; return -1;
} }
if (air724_signal_quality_check() != 0) if (air724_signal_quality_check() != 0) {
{
printf("signal quality check status failed\n"); printf("signal quality check status failed\n");
return -1; return -1;
} }
if(air724_gsm_network_check() != 0) if(air724_gsm_network_check() != 0) {
{
printf("GSM network register status check fail\n"); printf("GSM network register status check fail\n");
return -1; return -1;
} }
if(air724_gprs_network_check() != 0) if(air724_gprs_network_check() != 0) {
{
printf("GPRS network register status check fail\n"); printf("GPRS network register status check fail\n");
return -1; return -1;
} }
if(air724_close_apn() != 0) if(air724_close_apn() != 0) {
{
printf("close apn failed\n"); printf("close apn failed\n");
return -1; return -1;
} }
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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"); printf("multilink set FAILED\n");
return -1; return -1;
} }
#else #else
if (air724_multilink_set(AIR724_MULTILINK_STATE_ENABLE) != 0) if (air724_multilink_set(AIR724_MULTILINK_STATE_ENABLE) != 0) {
{
printf("multilink set FAILED\n"); printf("multilink set FAILED\n");
return -1; return -1;
} }
#endif #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"); printf("send mode set FAILED\n");
return -1; 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_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) { if (echo.status != AT_ECHO_STATUS_OK) {
tos_at_channel_free(id); tos_at_channel_free(id);
return -1; 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 #if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK"); 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)); proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
if (echo.status == AT_ECHO_STATUS_OK) { if (echo.status != AT_ECHO_STATUS_EXPECT) {
return id; tos_at_channel_free(id);
return -1;
} }
#else #else
char result[20]; 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_echo_create(&echo, NULL, 0, result);
tos_at_cmd_exec_until(&echo, 8000, "AT+CIPSTART=%d,%s,%s,%d\r\n", 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)); id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
if (echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status != AT_ECHO_STATUS_EXPECT) {
return id; tos_at_channel_free(id);
return -1;
} }
#endif #endif
tos_at_channel_free(id); return id;
return -1;
} }
static int air724_recv_timeout(int id, void *buf, size_t len, uint32_t timeout) 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) int air724_send(int id, const void *buf, size_t len)
{ {
at_echo_t echo; 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; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); tos_at_echo_create(&echo, NULL, 0, ">");
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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", "AT+CIPSEND=%d\r\n",
len); len);
#else #else
tos_at_cmd_exec(&echo, 1000, tos_at_cmd_exec_until(&echo, 1000,
"AT+CIPSEND=%d,%d\r\n", "AT+CIPSEND=%d,%d\r\n",
id, len); id, len);
#endif #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(); tos_at_global_lock_post();
return -1; return -1;
} }
sprintf(expect, "%d, SEND OK", id); sprintf(expect_str, "%d, SEND OK", id);
tos_at_echo_create(&echo, NULL, 0, expect); tos_at_echo_create(&echo, NULL, 0, expect_str);
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) if (echo.status != AT_ECHO_STATUS_EXPECT) {
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; 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; at_echo_t echo;
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); tos_at_echo_create(&echo, NULL, 0, ">");
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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", "AT+CIPSEND=%d\r\n",
len); len);
#else #else
tos_at_cmd_exec(&echo, 1000, tos_at_cmd_exec_until(&echo, 1000,
"AT+CIPSEND=%d,%d\r\n", "AT+CIPSEND=%d,%d\r\n",
id, len); id, len);
#endif #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(); tos_at_global_lock_post();
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 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(); tos_at_global_lock_post();
return -1; return -1;
} }
@@ -513,12 +476,16 @@ static void air724_transparent_mode_exit(void)
static int air724_close(int id) static int air724_close(int id)
{ {
at_echo_t echo;
air724_transparent_mode_exit(); air724_transparent_mode_exit();
tos_at_echo_create(&echo, NULL, 0, NULL);
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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 #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 #endif
tos_at_channel_free(id); 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_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CDNSGIP=\"%s\"\r\n", host_name); 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; return -1;
} }
@@ -563,48 +529,38 @@ __STATIC__ void air724_incoming_data_process(void)
+RECEIVE: prefix +RECEIVE: prefix
0: scoket id 0: scoket id
*/ */
if (tos_at_uart_read(&data, 1) != 1) if (tos_at_uart_read(&data, 1) != 1) {
{
return; return;
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
channel_id = channel_id * 10 + (data - '0'); channel_id = channel_id * 10 + (data - '0');
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ':') if (data == ':') {
{
break; break;
} }
data_len = data_len * 10 + (data - '0'); data_len = data_len * 10 + (data - '0');
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == '\n') if (data == '\n') {
{
break; break;
} }
} }
@@ -639,15 +595,12 @@ __STATIC__ void air724_domain_data_process(void)
return; return;
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
@@ -658,15 +611,12 @@ __STATIC__ void air724_domain_data_process(void)
return; return;
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
} }

View File

@@ -32,7 +32,7 @@ typedef struct ip_addr_st {
}ip_addr_t; }ip_addr_t;
static ip_addr_t domain_parser_addr = {0}; 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) 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_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n"); 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 0;
} }
return -1; return -1;
@@ -53,8 +52,7 @@ static int ec20_sim_card_check(void)
char echo_buffer[32]; char echo_buffer[32];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) { if (echo.status != AT_ECHO_STATUS_OK) {
@@ -77,8 +75,7 @@ static int ec20_signal_quality_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
if (echo.status != AT_ECHO_STATUS_OK) if (echo.status != AT_ECHO_STATUS_OK)
{ {
@@ -106,16 +103,14 @@ static int ec20_gsm_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CREG:"); str = strstr(echo.buffer, "+CREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CREG:%d,%d", &n, &stat); sscanf(str, "+CREG:%d,%d", &n, &stat);
@@ -134,23 +129,19 @@ static int ec20_gprs_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CGREG:"); str = strstr(echo.buffer, "+CGREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CGREG:%d,%d", &n, &stat); sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) if (stat == 1) {
{
return 0; return 0;
} }
} }
@@ -164,8 +155,7 @@ static int ec20_close_apn(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n"); 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; return 0;
} }
@@ -178,14 +168,12 @@ static int ec20_set_apn(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "AT+QICSGP=1,1,\"CMNET\"\r\n"); 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; return -1;
} }
tos_at_cmd_exec_until(&echo, 3000, "AT+QIACT=1\r\n"); 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; return -1;
} }
@@ -196,38 +184,32 @@ static int ec20_init(void)
{ {
printf("Init ec20 ...\n" ); printf("Init ec20 ...\n" );
if (ec20_echo_close() != 0) if (ec20_echo_close() != 0) {
{
printf("echo close failed,please check your module\n"); printf("echo close failed,please check your module\n");
return -1; return -1;
} }
if(ec20_sim_card_check() != 0) if(ec20_sim_card_check() != 0) {
{
printf("sim card check failed,please insert your card\n"); printf("sim card check failed,please insert your card\n");
return -1; return -1;
} }
if (ec20_signal_quality_check() != 0) if (ec20_signal_quality_check() != 0) {
{
printf("signal quality check status failed\n"); printf("signal quality check status failed\n");
return -1; return -1;
} }
if(ec20_gsm_network_check() != 0) if(ec20_gsm_network_check() != 0) {
{
printf("GSM network register status check fail\n"); printf("GSM network register status check fail\n");
return -1; return -1;
} }
if(ec20_gprs_network_check() != 0) if(ec20_gprs_network_check() != 0) {
{
printf("GPRS network register status check fail\n"); printf("GPRS network register status check fail\n");
return -1; return -1;
} }
if(ec20_close_apn() != 0) if(ec20_close_apn() != 0) {
{
printf("close apn failed\n"); printf("close apn failed\n");
return -1; return -1;
} }
@@ -245,27 +227,32 @@ static int ec20_connect(const char *ip, const char *port, sal_proto_t proto)
{ {
int id; int id;
at_echo_t echo; at_echo_t echo;
char except_str[16];
id = tos_at_channel_alloc(ip, port); id = tos_at_channel_alloc(ip, port);
if (id == -1) if (id == -1) {
{
return -1; return -1;
} }
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_echo_create(&echo, NULL, 0, "CONNECT OK"); if (echo.status != AT_ECHO_STATUS_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_channel_free(id); tos_at_channel_free(id);
return -1; 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) static int ec20_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{ {
return tos_at_channel_read_timed(id, buf, len, timeout); return tos_at_channel_read_timed(id, buf, len, timeout);
@@ -284,25 +271,22 @@ int ec20_send(int id, const void *buf, size_t len)
return -1; return -1;
} }
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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(); tos_at_global_lock_post();
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) if (echo.status != AT_ECHO_STATUS_EXPECT) {
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; 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; at_echo_t echo;
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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(); tos_at_global_lock_post();
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len); tos_at_raw_data_send(&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(); tos_at_global_lock_post();
return -1; 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) 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, "+++"); tos_at_cmd_exec(NULL, 500, "+++");
} }
static int ec20_close(int id) static int ec20_close(int id)
{ {
at_echo_t echo;
ec20_transparent_mode_exit(); 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); tos_at_channel_free(id);
@@ -404,36 +391,28 @@ __STATIC__ void ec20_incoming_data_process(void)
<data content> <data content>
*/ */
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') {
if (data == ',')
{
break; break;
} }
channel_id = channel_id * 10 + (data - '0'); channel_id = channel_id * 10 + (data - '0');
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == '\r') if (data == '\r') {
{
break; break;
} }
data_len = data_len * 10 + (data - '0'); data_len = data_len * 10 + (data - '0');
} }
if (tos_at_uart_read(&data, 1) != 1) if (tos_at_uart_read(&data, 1) != 1) {
{
return; return;
} }

View File

@@ -32,8 +32,8 @@ typedef struct ip_addr_st {
}ip_addr_t; }ip_addr_t;
static ip_addr_t domain_parser_addr = {0}; static ip_addr_t domain_parser_addr = {0};
k_sem_t domain_parser_sem; static k_sem_t domain_parser_sem;
k_sem_t module_ready_sem; static k_sem_t module_ready_sem;
static int ec200s_check_ready(void) static int ec200s_check_ready(void)
{ {
@@ -92,19 +92,17 @@ static int ec200s_signal_quality_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CSQ:"); str = strstr(echo.buffer, "+CSQ:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CSQ:%d,%d", &rssi, &ber); sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99) { if (rssi != 99) {
return 0; return 0;
@@ -121,16 +119,14 @@ static int ec200s_gsm_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CREG:"); str = strstr(echo.buffer, "+CREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CREG:%d,%d", &n, &stat); sscanf(str, "+CREG:%d,%d", &n, &stat);
@@ -138,6 +134,7 @@ static int ec200s_gsm_network_check(void)
return 0; return 0;
} }
} }
return -1; return -1;
} }
@@ -149,23 +146,19 @@ static int ec200s_gprs_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CGREG:"); str = strstr(echo.buffer, "+CGREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CGREG:%d,%d", &n, &stat); sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) if (stat == 1) {
{
return 0; return 0;
} }
} }
@@ -179,8 +172,7 @@ static int ec200s_close_apn(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n"); 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; return 0;
} }
@@ -193,14 +185,12 @@ static int ec200s_set_apn(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+QICSGP=1,1,\"CMNET\"\r\n"); 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; return -1;
} }
tos_at_cmd_exec(&echo, 3000, "AT+QIACT=1\r\n"); 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 -1;
} }
@@ -216,38 +206,32 @@ static int ec200s_init(void)
return -1; return -1;
} }
if (ec200s_echo_close() != 0) if (ec200s_echo_close() != 0) {
{
printf("echo close failed,please check your module\n"); printf("echo close failed,please check your module\n");
return -1; return -1;
} }
if(ec200s_sim_card_check() != 0) if(ec200s_sim_card_check() != 0) {
{
printf("sim card check failed,please insert your card\n"); printf("sim card check failed,please insert your card\n");
return -1; return -1;
} }
if (ec200s_signal_quality_check() != 0) if (ec200s_signal_quality_check() != 0) {
{
printf("signal quality check status failed\n"); printf("signal quality check status failed\n");
return -1; return -1;
} }
if(ec200s_gsm_network_check() != 0) if(ec200s_gsm_network_check() != 0) {
{
printf("GSM network register status check fail\n"); printf("GSM network register status check fail\n");
return -1; return -1;
} }
if(ec200s_gprs_network_check() != 0) if(ec200s_gprs_network_check() != 0) {
{
printf("GPRS network register status check fail\n"); printf("GPRS network register status check fail\n");
return -1; return -1;
} }
if(ec200s_close_apn() != 0) if(ec200s_close_apn() != 0) {
{
printf("close apn failed\n"); printf("close apn failed\n");
return -1; return -1;
} }
@@ -265,27 +249,32 @@ static int ec200s_connect(const char *ip, const char *port, sal_proto_t proto)
{ {
int id; int id;
at_echo_t echo; at_echo_t echo;
char except_str[16];
id = tos_at_channel_alloc(ip, port); id = tos_at_channel_alloc(ip, port);
if (id == -1) if (id == -1) {
{
return -1; return -1;
} }
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_echo_create(&echo, NULL, 0, "CONNECT OK"); if (echo.status != AT_ECHO_STATUS_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_channel_free(id); tos_at_channel_free(id);
return -1; 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) static int ec200s_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{ {
return tos_at_channel_read_timed(id, buf, len, timeout); return tos_at_channel_read_timed(id, buf, len, timeout);
@@ -304,25 +293,22 @@ int ec200s_send(int id, const void *buf, size_t len)
return -1; return -1;
} }
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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(); tos_at_global_lock_post();
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) if (echo.status != AT_ECHO_STATUS_EXPECT) {
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; 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; at_echo_t echo;
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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_EXPECT) {
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT)
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "SEND OK"); tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len); tos_at_raw_data_send(&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(); tos_at_global_lock_post();
return -1; 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) 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) static int ec200s_close(int id)
{ {
at_echo_t echo;
ec200s_transparent_mode_exit(); 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); tos_at_channel_free(id);
@@ -424,36 +412,28 @@ __STATIC__ void ec200s_incoming_data_process(void)
<data content> <data content>
*/ */
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') {
if (data == ',')
{
break; break;
} }
channel_id = channel_id * 10 + (data - '0'); channel_id = channel_id * 10 + (data - '0');
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == '\r') if (data == '\r') {
{
break; break;
} }
data_len = data_len * 10 + (data - '0'); data_len = data_len * 10 + (data - '0');
} }
if (tos_at_uart_read(&data, 1) != 1) if (tos_at_uart_read(&data, 1) != 1) {
{
return; return;
} }

View File

@@ -55,10 +55,10 @@ static int esp8266_net_mode_set(esp8266_net_mode_t mode)
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "no change"); tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, cmd); 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; return 0;
} }
} }
@@ -85,11 +85,13 @@ static int esp8266_multilink_set(esp8266_multilink_state_t state)
int try = 0; int try = 0;
at_echo_t echo; 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) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 500, "AT+CIPMUX=%d\r\n", state == ESP8266_MULTILINK_STATE_ENABLE ? 1 : 0); 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; return 0;
} else if (echo.status == AT_ECHO_STATUS_ERROR) {
return -1;
} }
} }
return -1; return -1;
@@ -100,10 +102,10 @@ int esp8266_join_ap(const char *ssid, const char *pwd)
int try = 0; int try = 0;
at_echo_t echo; at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "OK"); tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec_until(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd); tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
if (echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_OK) {
return 0; return 0;
} }
} }
@@ -141,24 +143,22 @@ static int esp8266_connect(const char *ip, const char *port, sal_proto_t proto)
int id; int id;
at_echo_t echo; at_echo_t echo;
esp8266_reconnect_init();
id = tos_at_channel_alloc(ip, port); id = tos_at_channel_alloc(ip, port);
if (id == -1) { if (id == -1) {
return -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 #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", "AT+CIPSTART=\"%s\",\"%s\",%s\r\n",
proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port); proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
#else #else
tos_at_cmd_exec_until(&echo, 10000, tos_at_cmd_exec(&echo, 10000,
"AT+CIPSTART=%d,\"%s\",\"%s\",%s\r\n", "AT+CIPSTART=%d,\"%s\",\"%s\",%s\r\n",
id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port); id, proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, port);
#endif #endif
if (echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_OK) {
return id; 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), ">"); tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), ">");
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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); "AT+CIPSEND=%d\r\n", len);
#else #else
tos_at_cmd_exec(&echo, 1000, tos_at_cmd_exec_until(&echo, 5000,
"AT+CIPSEND=%d,%d\r\n", "AT+CIPSEND=%d,%d\r\n",
id, len); id, len);
#endif #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)) { if (esp8266_is_link_broken((const char *)echo.buffer)) {
tos_at_channel_set_broken(id); 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 (ip && port) {
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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); "AT+CIPSEND=%d,\"%s\",%s\r\n", len, ip, port);
#else #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); "AT+CIPSEND=%d,%d,\"%s\",%s\r\n", id, len, ip, port);
#endif #endif
} else { } else {
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u #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); "AT+CIPSEND=%d\r\n", len);
#else #else
tos_at_cmd_exec(&echo, 1000, tos_at_cmd_exec_until(&echo, 1000,
"AT+CIPSEND=%d,%d\r\n", id, len); "AT+CIPSEND=%d,%d\r\n", id, len);
#endif #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)) { if (esp8266_is_link_broken((const char *)echo.buffer)) {
tos_at_channel_set_broken(id); 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) 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 #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 #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 #endif
tos_at_channel_free(id); tos_at_channel_free(id);
return 0; return 0;

View File

@@ -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_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); 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 0;
} }
return -1; 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"); tos_at_echo_create(&echo, NULL, 0, "+TCMQTTCONN:OK");
while (try++ < 10) { 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.command_timeout, init_params.keep_alive_interval_ms,
init_params.clean_session, init_params.auto_connect_enable); 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; 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_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2); 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_OK && echo.status != AT_ECHO_STATUS_EXPECT) { if (echo.status != AT_ECHO_STATUS_EXPECT) {
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK"); tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)payload, strlen(payload)); tos_at_raw_data_send_until(&echo, 1000, (uint8_t *)payload, strlen(payload));
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) { if (echo.status != AT_ECHO_STATUS_EXPECT) {
return -1; 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_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload); tos_at_cmd_exec_until(&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) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
return 0; return 0;
} }
return -1; 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_echo_create(&echo, NULL, 0, "+TCMQTTSUB:OK");
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos); tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
return 0; return 0;
} }
return -1; 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_echo_create(&echo, NULL, 0, "+TCMQTTUNSUB:OK");
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic); tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
return 0; return 0;
} }
return -1; return -1;
@@ -130,8 +130,7 @@ int esp8266_tencent_firmware_module_mqtt_state_get(mqtt_state_t *state)
} }
str = strstr(echo.buffer, "+TCMQTTSTATE:"); str = strstr(echo.buffer, "+TCMQTTSTATE:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+TCMQTTSTATE:%d", &ret_state); 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; int try = 0;
at_echo_t echo; at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, "WIFI CONNECTED"); tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 10000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd); tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_OK) {
return 0; return 0;
} }
} }
@@ -181,8 +180,8 @@ static int esp8266_tencent_firmware_restore(void)
tos_at_echo_create(&echo, NULL, 0, "ready"); tos_at_echo_create(&echo, NULL, 0, "ready");
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 5000, "AT+RESTORE\r\n"); tos_at_cmd_exec_until(&echo, 5000, "AT+RESTORE\r\n");
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
return 0; return 0;
} }
} }
@@ -221,10 +220,10 @@ static int esp8266_tencent_firmware_net_mode_set(sal_net_mode_t mode)
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "no change"); tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) { while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, cmd); 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; 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_echo_create(&echo, NULL, 0, "+TCOTASET:OK");
tos_at_cmd_exec(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version); tos_at_cmd_exec_until(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
return 0; return 0;
} }
return -1; 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_echo_create(&echo, echo_buffer, sizeof(echo_buffer), "+TCFWINFO:");
tos_at_cmd_exec(&echo, 2000, "AT+TCFWINFO?\r\n"); tos_at_cmd_exec_until(&echo, 2000, "AT+TCFWINFO?\r\n");
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) { if (echo.status == AT_ECHO_STATUS_EXPECT) {
sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5); sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5);
for(int i = 0; i<10; i++) for(int i = 0; i<10; i++)
@@ -478,9 +477,9 @@ int esp8266_tencent_firmware_start_smartconfig(void)
return -1; 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"); 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; return -1;
} }
@@ -504,10 +503,10 @@ int esp8266_tencent_firmware_stop_smartconfig(void)
{ {
at_echo_t echo; 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"); 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; return -1;
} }

View File

@@ -53,6 +53,8 @@ static int l610_echo_close(void)
if (echo.status == AT_ECHO_STATUS_OK) { if (echo.status == AT_ECHO_STATUS_OK) {
return 0; return 0;
} }
tos_sleep_ms(1000);
} }
return -1; return -1;
@@ -69,6 +71,7 @@ static int l610_sim_card_check(void)
if (strstr(echo_buffer, "READY")) { if (strstr(echo_buffer, "READY")) {
return 0; return 0;
} }
tos_sleep_ms(2000);
} }
return -1; return -1;
@@ -82,23 +85,21 @@ static int l610_signal_quality_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CSQ:"); str = strstr(echo.buffer, "+CSQ:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CSQ:%d,%d", &rssi, &ber); sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99) { if (rssi != 99) {
return 0; return 0;
} }
tos_sleep_ms(2000);
} }
return -1; return -1;
@@ -111,22 +112,21 @@ static int l610_gsm_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CREG:"); str = strstr(echo.buffer, "+CREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CREG:%d,%d", &n, &stat); sscanf(str, "+CREG:%d,%d", &n, &stat);
if (stat == 1) { if (stat == 1) {
return 0; return 0;
} }
tos_sleep_ms(2000);
} }
return -1; return -1;
} }
@@ -139,25 +139,23 @@ static int l610_gprs_network_check(void)
int try = 0; int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL); 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"); 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; return -1;
} }
str = strstr(echo.buffer, "+CGREG:"); str = strstr(echo.buffer, "+CGREG:");
if (!str) if (!str) {
{
return -1; return -1;
} }
sscanf(str, "+CGREG:%d,%d", &n, &stat); sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) if (stat == 1) {
{
return 0; return 0;
} }
tos_sleep_ms(2000);
} }
return -1; return -1;
@@ -169,8 +167,7 @@ static int l610_set_data_format(void)
tos_at_echo_create(&echo, NULL, 0, NULL); tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+GTSET=\"IPRFMT\",0\r\n"); 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; return -1;
} }
@@ -186,8 +183,7 @@ static int l610_check_apn(void)
tos_at_echo_create(&echo, buffer, 64, NULL); tos_at_echo_create(&echo, buffer, 64, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL?\r\n"); 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; return -1;
} }
@@ -223,8 +219,7 @@ static int l610_check_close_apn(void)
tos_at_echo_create(&echo, buffer, 64, NULL); tos_at_echo_create(&echo, buffer, 64, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+MIPCALL=0\r\n"); 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; return -1;
} }
@@ -247,8 +242,7 @@ static int l610_set_apn(void)
tos_at_echo_create(&echo, NULL, 0, "+MIPCALL"); tos_at_echo_create(&echo, NULL, 0, "+MIPCALL");
tos_at_cmd_exec_until(&echo, 10000, "AT+MIPCALL=1,\"CMNET\"\r\n"); 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; return -1;
} }
@@ -318,16 +312,14 @@ static int l610_connect(const char *ip, const char *port, sal_proto_t proto)
at_echo_t echo; at_echo_t echo;
id = tos_at_channel_alloc(ip, port); id = tos_at_channel_alloc(ip, port);
if (id == -1) if (id == -1) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, "+MIPOPEN"); 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); 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); tos_at_channel_free(id);
return -1; return -1;
} }
@@ -353,17 +345,15 @@ int l610_send(int id, const void *buf, size_t len)
return -1; return -1;
} }
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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(); tos_at_global_lock_post();
return -1; 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_echo_create(&echo, NULL, 0, "+MIPSEND");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) if (echo.status != AT_ECHO_STATUS_EXPECT) {
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; return -1;
} }
@@ -400,17 +389,15 @@ int l610_sendto(int id, char *ip, char *port, const void *buf, size_t len)
return -1; return -1;
} }
if (tos_at_global_lock_pend() != 0) if (tos_at_global_lock_pend() != 0) {
{
return -1; return -1;
} }
tos_at_echo_create(&echo, NULL, 0, ">"); 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(); tos_at_global_lock_post();
return -1; 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_echo_create(&echo, NULL, 0, "+MIPSEND");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len); tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) if (echo.status != AT_ECHO_STATUS_EXPECT) {
{
tos_at_global_lock_post(); tos_at_global_lock_post();
return -1; return -1;
} }
@@ -436,8 +422,11 @@ static void l610_transparent_mode_exit(void)
static int l610_close(int id) static int l610_close(int id)
{ {
at_echo_t echo;
l610_transparent_mode_exit(); 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_cmd_exec(NULL, 1000, "AT+MIPCLOSE=%d\r\n", id+1);
tos_at_channel_free(id); tos_at_channel_free(id);
@@ -507,30 +496,24 @@ __STATIC__ void l610_tcp_incoming_data_process(void)
+MIPRTCP: <socket id>,<leaf length>,<hex string> +MIPRTCP: <socket id>,<leaf length>,<hex string>
*/ */
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
channel_id = channel_id * 10 + (data - '0'); channel_id = channel_id * 10 + (data - '0');
} }
channel_id--; channel_id--;
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
leaf_data_len = leaf_data_len * 10 + (data - '0'); 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> +MIPRUDP: <src ip>,<src port>, <socket id>,<leaf length>,<hex string>
*/ */
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
} }
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
channel_id = channel_id * 10 + (data - '0'); channel_id = channel_id * 10 + (data - '0');
} }
channel_id--; channel_id--;
while (1) while (1) {
{ if (tos_at_uart_read(&data, 1) != 1) {
if (tos_at_uart_read(&data, 1) != 1)
{
return; return;
} }
if (data == ',') if (data == ',') {
{
break; break;
} }
leaf_data_len = leaf_data_len * 10 + (data - '0'); leaf_data_len = leaf_data_len * 10 + (data - '0');

View File

@@ -7,6 +7,8 @@
//#define USE_BC26 //#define USE_BC26
//#define USE_EC20 //#define USE_EC20
//#define USE_EC200S //#define USE_EC200S
//#define USE_AIR724
//#define USE_L610
#ifdef USE_ESP8266 #ifdef USE_ESP8266
#include "esp8266.h" #include "esp8266.h"
@@ -28,6 +30,14 @@
#include "ec200s.h" #include "ec200s.h"
#endif #endif
#ifdef USE_AIR724
#include "air724.h"
#endif
#ifdef USE_L610
#include "l610.h"
#endif
#define TCP_TEST_TASK0_STK_SIZE 4096 #define TCP_TEST_TASK0_STK_SIZE 4096
void tcp_test0(void); void tcp_test0(void);
osThreadDef(tcp_test0, osPriorityNormal, 1, TCP_TEST_TASK0_STK_SIZE); osThreadDef(tcp_test0, osPriorityNormal, 1, TCP_TEST_TASK0_STK_SIZE);
@@ -90,7 +100,7 @@ void application_entry(void *arg)
{ {
#if defined(USE_ESP8266) #if defined(USE_ESP8266)
esp8266_sal_init(HAL_UART_PORT_0); esp8266_sal_init(HAL_UART_PORT_0);
esp8266_join_ap("SheldonDai", "srnr6x9xbhmb0"); esp8266_join_ap("Mculover666", "mculover666");
#elif defined(USE_SIM800A) #elif defined(USE_SIM800A)
sim800a_power_on(); sim800a_power_on();
sim800a_sal_init(HAL_UART_PORT_2); sim800a_sal_init(HAL_UART_PORT_2);
@@ -99,7 +109,11 @@ void application_entry(void *arg)
#elif defined(USE_EC20) #elif defined(USE_EC20)
ec20_sal_init(HAL_UART_PORT_0); ec20_sal_init(HAL_UART_PORT_0);
#elif defined(USE_EC200S) #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 #endif
socket_id_0 = tos_sal_module_connect("117.50.111.72", "8080", TOS_SAL_PROTO_TCP); socket_id_0 = tos_sal_module_connect("117.50.111.72", "8080", TOS_SAL_PROTO_TCP);

View File

@@ -21,10 +21,6 @@
#include "tos_k.h" #include "tos_k.h"
#include "tos_hal.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_NUM 6
#define AT_DATA_CHANNEL_FIFO_BUFFER_SIZE (2048 + 1024) #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_EVENT,
AT_PARSE_STATUS_EXPECT, AT_PARSE_STATUS_EXPECT,
AT_PARSE_STATUS_OVERFLOW, AT_PARSE_STATUS_OVERFLOW,
AT_PARSE_STATUS_OK,
AT_PARSE_STATUS_FAIL,
AT_PARSE_STATUS_ERROR
} at_parse_status_t; } at_parse_status_t;
typedef enum at_echo_status_en { typedef enum at_echo_status_en {
@@ -92,6 +91,7 @@ typedef struct at_echo_st {
size_t __w_idx; size_t __w_idx;
int __is_expecting; int __is_expecting;
k_sem_t __expect_notify; k_sem_t __expect_notify;
k_sem_t __status_set_notify;
int __is_fuzzy_match; int __is_fuzzy_match;
} at_echo_t; } at_echo_t;

View File

@@ -228,6 +228,14 @@ __STATIC__ at_parse_status_t at_uart_line_parse(void)
return AT_PARSE_STATUS_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 if (data == '\n' && last_data == '\r') { // 0xd 0xa
curr_len -= 1; curr_len -= 1;
recv_cache->buffer[curr_len - 1] = '\n'; recv_cache->buffer[curr_len - 1] = '\n';
@@ -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) __STATIC__ void at_echo_buffer_copy(at_cache_t *at_cache, at_echo_t *echo)
{ {
uint8_t *recv_buffer = K_NULL; uint8_t *recv_buffer = K_NULL;
@@ -297,6 +287,8 @@ __STATIC__ void at_parser(void *arg)
while (K_TRUE) { while (K_TRUE) {
at_parse_status = at_uart_line_parse(); at_parse_status = at_uart_line_parse();
tos_kprintln("--->%s", recv_cache->buffer);
if (at_parse_status == AT_PARSE_STATUS_OVERFLOW) { if (at_parse_status == AT_PARSE_STATUS_OVERFLOW) {
tos_kprintln("AT parse overflow!"); tos_kprintln("AT parse overflow!");
continue; continue;
@@ -315,21 +307,31 @@ __STATIC__ void at_parser(void *arg)
continue; continue;
} }
if (at_echo->buffer) {
at_echo_buffer_copy(recv_cache, at_echo);
}
if (at_parse_status == AT_PARSE_STATUS_EXPECT) { if (at_parse_status == AT_PARSE_STATUS_EXPECT) {
at_echo->status = AT_ECHO_STATUS_EXPECT; at_echo->status = AT_ECHO_STATUS_EXPECT;
if (at_echo->__is_expecting) { if (at_echo->__is_expecting) {
tos_sem_post(&at_echo->__expect_notify); tos_sem_post(&at_echo->__expect_notify);
} }
} else if (at_parse_status == AT_PARSE_STATUS_NEWLINE && } else if (at_parse_status == AT_PARSE_STATUS_OK) {
at_echo->status == AT_ECHO_STATUS_NONE) { at_echo->status = AT_ECHO_STATUS_OK;
at_echo_status_set(at_echo); 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);
} }
} }
@@ -467,10 +469,16 @@ __API__ int tos_at_cmd_exec(at_echo_t *echo, uint32_t timeout, const char *cmd,
int ret = 0; int ret = 0;
va_list args; va_list args;
if (echo) { if (tos_sem_create(&echo->__status_set_notify, 0) != K_ERR_NONE) {
at_echo_attach(echo); return -1;
} }
if (!echo) {
return -1;
}
at_echo_attach(echo);
va_start(args, cmd); va_start(args, cmd);
ret = at_cmd_do_exec(cmd, args); ret = at_cmd_do_exec(cmd, args);
va_end(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; 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; 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, ...) __API__ int tos_at_cmd_exec_until(at_echo_t *echo, uint32_t timeout, const char *cmd, ...)