add support for luat air724UG module

This commit is contained in:
mculover666
2020-07-03 10:53:43 +08:00
parent 26afeca15d
commit 66a674d73e
8 changed files with 753 additions and 35 deletions

View File

@@ -380,7 +380,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>
@@ -1160,7 +1160,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>
@@ -1171,6 +1171,18 @@
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <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>73</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\devices\esp8266\esp8266.c</PathWithFileName> <PathWithFileName>..\..\..\..\devices\esp8266\esp8266.c</PathWithFileName>
<FilenameWithoutPath>esp8266.c</FilenameWithoutPath> <FilenameWithoutPath>esp8266.c</FilenameWithoutPath>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -1180,13 +1192,13 @@
<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>74</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1206,7 +1218,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>14</GroupNumber> <GroupNumber>14</GroupNumber>
<FileNumber>74</FileNumber> <FileNumber>75</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1226,7 +1238,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>15</GroupNumber> <GroupNumber>15</GroupNumber>
<FileNumber>75</FileNumber> <FileNumber>76</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1238,7 +1250,7 @@
</File> </File>
<File> <File>
<GroupNumber>15</GroupNumber> <GroupNumber>15</GroupNumber>
<FileNumber>76</FileNumber> <FileNumber>77</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1250,7 +1262,7 @@
</File> </File>
<File> <File>
<GroupNumber>15</GroupNumber> <GroupNumber>15</GroupNumber>
<FileNumber>77</FileNumber> <FileNumber>78</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>

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.0.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.4.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>
@@ -338,7 +339,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>STM32L431xx</Define> <Define>STM32L431xx</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;..\..\..\..\net\socket_wrapper\include</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;..\..\..\..\net\socket_wrapper\include;..\..\..\..\devices\air724</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@@ -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>
@@ -792,6 +793,11 @@
<Group> <Group>
<GroupName>devices</GroupName> <GroupName>devices</GroupName>
<Files> <Files>
<File>
<FileName>air724.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\air724\air724.c</FilePath>
</File>
<File> <File>
<FileName>esp8266.c</FileName> <FileName>esp8266.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -859,4 +865,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

@@ -443,7 +443,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>
@@ -1223,7 +1223,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,6 +1239,18 @@
<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\air724\air724.c</PathWithFileName>
<FilenameWithoutPath>air724.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group> </Group>
<Group> <Group>
@@ -1249,7 +1261,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>13</GroupNumber> <GroupNumber>13</GroupNumber>
<FileNumber>73</FileNumber> <FileNumber>74</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
@@ -1269,7 +1281,7 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<File> <File>
<GroupNumber>14</GroupNumber> <GroupNumber>14</GroupNumber>
<FileNumber>74</FileNumber> <FileNumber>75</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>

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.0.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.4.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>
@@ -336,9 +337,9 @@
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER,USE_ESP8266</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</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\air724</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@@ -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>
@@ -797,6 +798,11 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\..\devices\esp8266\esp8266.c</FilePath> <FilePath>..\..\..\..\devices\esp8266\esp8266.c</FilePath>
</File> </File>
<File>
<FileName>air724.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\air724\air724.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@@ -839,4 +845,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>

594
devices/air724/air724.c Normal file
View File

@@ -0,0 +1,594 @@
#include "air724.h"
#include "tos_at.h"
#include "tos_hal.h"
#include "sal_module_wrapper.h"
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
static int air724_echo_close(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "ATE0\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
return -1;
}
static int air724_cscon_close(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "AT+CSCON=0\r\n");
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
return -1;
}
static int air724_sim_card_check(void)
{
at_echo_t echo;
int try = 0;
char echo_buffer[32];
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"))
{
return 0;
}
}
return -1;
}
static int air724_signal_quality_check(void)
{
int rssi, ber;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
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)
{
return -1;
}
str = strstr(echo.buffer, "+CSQ:");
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99) {
return 0;
}
}
return -1;
}
static int air724_gsm_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
while (try++ < 10)
{
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
str = strstr(echo.buffer, "+CREG:");
sscanf(str, "+CREG:%d,%d", &n, &stat);
if (stat == 1)
{
return 0;
}
}
return -1;
}
static int air724_gprs_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
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)
{
return -1;
}
str = strstr(echo.buffer, "+CGREG:");
sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1)
{
return 0;
}
}
return -1;
}
static int air724_close_apn(void)
{
at_echo_t echo;
char echo_buffer[32];
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)
{
return -1;
}
return 0;
}
static int air724_send_mode_set(sal_send_mode_t mode)
{
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
int try = 0;
at_echo_t echo;
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)
{
return 0;
}
}
return -1;
#else
return 0;
#endif
}
static int air724_multilink_set(sal_multilink_state_t state)
{
int try = 0;
at_echo_t echo;
while (try++ < 10)
{
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 300, "AT+CIPMUX=%d\r\n", state == SAL_MULTILINK_STATE_ENABLE ? 1 : 0);
if (echo.status == AT_ECHO_STATUS_OK)
{
return 0;
}
}
return -1;
}
static int air724_set_apn(void)
{
at_echo_t echo;
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)
{
return -1;
}
tos_at_cmd_exec(&echo, 3000, "AT+CIICR\r\n");
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
tos_at_cmd_exec(&echo, 300, "AT+CIFSR\r\n");
return 0;
}
static int air724_init(void)
{
printf("Init air724 ...\n" );
if (air724_echo_close() != 0)
{
printf("echo close failed\n");
return -1;
}
if (air724_cscon_close() != 0)
{
printf("cscon close failed\n");
return -1;
}
if(air724_sim_card_check() != 0)
{
printf("sim card check failed,please insert your card\n");
return -1;
}
if (air724_signal_quality_check() != 0)
{
printf("signal quality check status failed\n");
return -1;
}
if(air724_gsm_network_check() != 0)
{
printf("GSM network register status check fail\n");
return -1;
}
if(air724_gprs_network_check() != 0)
{
printf("GPRS network register status check fail\n");
return -1;
}
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)
{
printf("multilink set FAILED\n");
return -1;
}
#else
if (air724_multilink_set(SAL_MULTILINK_STATE_ENABLE) != 0)
{
printf("multilink set FAILED\n");
return -1;
}
#endif
if (air724_send_mode_set(SAL_SEND_MODE_NORMAL) != 0)
{
printf("send mode set FAILED\n");
return -1;
}
if (air724_set_apn() != 0) {
printf("apn set FAILED\n");
return -1;
}
printf("Init air724 ok\n" );
return 0;
}
static int air724_connect(const char *ip, const char *port, sal_proto_t proto)
{
int id;
at_echo_t echo;
id = tos_at_channel_alloc(ip, port);
if (id == -1) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 2000, "%s=1\r\n", "AT+CIPHEAD");
if (echo.status != AT_ECHO_STATUS_OK) {
tos_at_channel_free(id);
return -1;
}
#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",
proto == TOS_SAL_PROTO_UDP ? "UDP" : "TCP", ip, atoi(port));
if (echo.status == AT_ECHO_STATUS_OK) {
return id;
}
#else
tos_at_echo_create(&echo, NULL, 0, "CONNECT OK");
tos_at_cmd_exec(&echo, 4000, "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_OK) {
return id;
}
#endif
tos_at_channel_free(id);
return -1;
}
static int air724_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
static int air724_recv(int id, void *buf, size_t len)
{
return air724_recv_timeout(id, buf, len, (uint32_t)4000);
}
int air724_send(int id, const void *buf, size_t len)
{
at_echo_t echo;
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,
"AT+CIPSEND=%d\r\n",
len);
#else
tos_at_cmd_exec(&echo, 1000,
"AT+CIPSEND=%d,%d\r\n",
id, len);
#endif
if (echo.status != AT_ECHO_STATUS_OK && 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_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
int air724_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
int air724_recvfrom(int id, void *buf, size_t len)
{
return air724_recvfrom_timeout(id, buf, len, (uint32_t)4000);
}
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)
{
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
tos_at_cmd_exec(&echo, 1000,
"AT+CIPSEND=%d\r\n",
len);
#else
tos_at_cmd_exec(&echo, 1000,
"AT+CIPSEND=%d,%d\r\n",
id, len);
#endif
if (echo.status != AT_ECHO_STATUS_OK && 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_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
static void air724_transparent_mode_exit(void)
{
tos_at_cmd_exec(NULL, 500, "+++");
}
static int air724_close(int id)
{
air724_transparent_mode_exit();
#if TOS_CFG_MODULE_SINGLE_LINK_EN > 0u
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE\r\n");
#else
tos_at_cmd_exec(NULL, 1000, "AT+CIPCLOSE=%d\r\n", id);
#endif
tos_at_channel_free(id);
return 0;
}
static int air724_parse_domain(const char *host_name, char *host_ip, size_t host_ip_len)
{
char *str;
at_echo_t echo;
char echo_buffer[128];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+CDNSGIP=\"%s\"\r\n", host_name);
if (echo.status != AT_ECHO_STATUS_OK)
{
return -1;
}
/*
+CDNSGIP: 1,"domain","xxx.xxx.xxx.xxx"
*/
str = strstr(echo.buffer, ":");
str += 1;
if(*str == '0')
{
/* parse fail */
return -1;
}
str += strlen(host_name) + 7;
int seg1, seg2, seg3, seg4;
sscanf(str, "%d.%d.%d.%d", &seg1, &seg2, &seg3, &seg4);
snprintf(host_ip, host_ip_len, "%d.%d.%d.%d", seg1, seg2, seg3, seg4);
host_ip[host_ip_len - 1] = '\0';
printf("GOT IP: %s\n", host_ip);
return 0;
}
__STATIC__ void air724_incoming_data_process(void)
{
uint8_t data;
int channel_id = 0, data_len = 0, read_len;
uint8_t buffer[128];
/*
+RECEIVE,0,<data_len>:
<data context>
+RECEIVE: prefix
0: scoket id
*/
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == ',')
{
break;
}
channel_id = channel_id * 10 + (data - '0');
}
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == ':')
{
break;
}
data_len = data_len * 10 + (data - '0');
}
while (1)
{
if (tos_at_uart_read(&data, 1) != 1)
{
return;
}
if (data == '\n')
{
break;
}
}
do {
#define MIN(a, b) ((a) < (b) ? (a) : (b))
read_len = MIN(data_len, sizeof(buffer));
if (tos_at_uart_read(buffer, read_len) != read_len) {
return;
}
if (tos_at_channel_write(channel_id, buffer, read_len) <= 0) {
return;
}
data_len -= read_len;
} while (data_len > 0);
return;
}
at_event_t air724_at_event[] = {
{ "+RECEIVE,", air724_incoming_data_process},
};
sal_module_t sal_module_air724 = {
.init = air724_init,
.connect = air724_connect,
.send = air724_send,
.recv_timeout = air724_recv_timeout,
.recv = air724_recv,
.sendto = air724_sendto,
.recvfrom = air724_recvfrom,
.recvfrom_timeout = air724_recvfrom_timeout,
.close = air724_close,
.parse_domain = air724_parse_domain,
};
int air724_sal_init(hal_uart_port_t uart_port)
{
if (tos_at_init(uart_port, air724_at_event,
sizeof(air724_at_event) / sizeof(air724_at_event[0])) != 0) {
return -1;
}
if (tos_sal_module_register(&sal_module_air724) != 0) {
return -1;
}
if (tos_sal_module_init() != 0) {
return -1;
}
return 0;
}

36
devices/air724/air724.h Normal file
View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef __AIR724_H__
#define __AIR724_H__
#include "tos_hal.h"
typedef enum sal_send_mode {
SAL_SEND_MODE_NORMAL,
SAL_SEND_MODE_TRANSPARENT,
} sal_send_mode_t;
typedef enum sal_multilink_state {
SAL_MULTILINK_STATE_ENABLE,
SAL_MULTILINK_STATE_DISABLE,
} sal_multilink_state_t;
int air724_sal_init(hal_uart_port_t uart_port);
#endif /* __AIR724_H__ */

View File

@@ -1,8 +1,17 @@
#include "esp8266.h"
#include "mcu_init.h" #include "mcu_init.h"
#include "cmsis_os.h" #include "cmsis_os.h"
#include "tos_at_socket.h" #include "tos_at_socket.h"
#define USE_ESP8266
//#define USE_AIR724
#if defined(USE_ESP8266)
#include "esp8266.h"
#elif defined(USE_AIR724)
#include "air724.h"
#endif
#define TCP_TEST_TASK_STK_SIZE 4096 #define TCP_TEST_TASK_STK_SIZE 4096
void tcp_test(void); void tcp_test(void);
osThreadDef(tcp_test, osPriorityNormal, 1, TCP_TEST_TASK_STK_SIZE); osThreadDef(tcp_test, osPriorityNormal, 1, TCP_TEST_TASK_STK_SIZE);
@@ -19,8 +28,8 @@ void tcp_test(void)
bzero(&addr, sizeof(addr)); bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("39.108.190.129"); addr.sin_addr.s_addr = inet_addr("117.50.111.72");
addr.sin_port = htons(8080); addr.sin_port = htons(8001);
fd = socket(AF_INET, SOCK_STREAM, 0); fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) { if (fd < 0) {
@@ -58,7 +67,7 @@ void tcp_test(void)
close(fd); close(fd);
} }
#define USE_ESP8266
void application_entry(void *arg) void application_entry(void *arg)
{ {
@@ -72,6 +81,10 @@ void application_entry(void *arg)
sim800a_sal_init(HAL_UART_PORT_2); sim800a_sal_init(HAL_UART_PORT_2);
#endif #endif
#ifdef USE_AIR724
air724_sal_init(HAL_UART_PORT_0);
#endif
osThreadCreate(osThread(tcp_test), NULL); osThreadCreate(osThread(tcp_test), NULL);
} }

View File

@@ -1,8 +1,17 @@
#include "esp8266.h"
#include "mcu_init.h" #include "mcu_init.h"
#include "sal_module_wrapper.h" #include "sal_module_wrapper.h"
#include "cmsis_os.h" #include "cmsis_os.h"
#define USE_ESP8266
//#define USE_AIR724
#if defined(USE_ESP8266)
#include "esp8266.h"
#elif defined(USE_AIR724)
#include "air724.h"
#endif
#define UDP_TEST_TASK0_STK_SIZE 4096 #define UDP_TEST_TASK0_STK_SIZE 4096
void udp_test0(void); void udp_test0(void);
osThreadDef(udp_test0, osPriorityNormal, 1, UDP_TEST_TASK0_STK_SIZE); osThreadDef(udp_test0, osPriorityNormal, 1, UDP_TEST_TASK0_STK_SIZE);
@@ -62,28 +71,28 @@ void udp_test1(void)
} }
} }
#define USE_ESP8266
void application_entry(void *arg) void application_entry(void *arg)
{ {
#ifdef 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("SheldonDai", "srnr6x9xbhmb0");
#endif
#ifdef 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);
#elif defined(USE_AIR724)
air724_sal_init(HAL_UART_PORT_0);
#endif #endif
socket_id_0 = tos_sal_module_connect("47.107.78.107", "1234", TOS_SAL_PROTO_UDP); socket_id_0 = tos_sal_module_connect("117.50.111.72", "8081", TOS_SAL_PROTO_UDP);
if (socket_id_0 == -1) { if (socket_id_0 == -1) {
printf("UDP0 connect failed\r\n"); printf("UDP0 connect failed\r\n");
} else { } else {
printf("UDP0 connect success! fd: %d\n", socket_id_0); printf("UDP0 connect success! fd: %d\n", socket_id_0);
} }
socket_id_1 = tos_sal_module_connect("47.107.78.107", "4321", TOS_SAL_PROTO_UDP); socket_id_1 = tos_sal_module_connect("117.50.111.72", "8002", TOS_SAL_PROTO_UDP);
if (socket_id_1 == -1) { if (socket_id_1 == -1) {
printf("UDP1 connect failed\r\n"); printf("UDP1 connect failed\r\n");
} else { } else {