add 4g cat1 module ec600s support

This commit is contained in:
mculover666
2021-02-06 21:17:11 +08:00
parent b62461615a
commit 4bb2038a56
6 changed files with 705 additions and 32 deletions

View File

@@ -1,11 +1,19 @@
#include "stm32l4xx_hal.h"
#include "mcu_init.h"
#include "tos_k.h"
#include "esp8266.h"
#include "mqttclient.h"
#define USE_ESP8266
//#define USE_NB_BC35
//#define USE_EC600S
#ifdef USE_ESP8266
#include "esp8266.h"
#endif
#ifdef USE_EC600S
#include "ec600s.h"
#endif
/* Tencent IoThub Device Info */
#define IOTHUB_MQTT_IP "111.230.189.156"
@@ -48,6 +56,11 @@ void mqttclient_task(void)
bc35_28_95_sal_init(HAL_UART_PORT_0);
#endif
#ifdef USE_EC600S
ec600s_sal_init(HAL_UART_PORT_0);
#endif
mqtt_log_init();
client = mqtt_lease();

View File

@@ -1242,6 +1242,18 @@
<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\ec600s\ec600s.c</PathWithFileName>
<FilenameWithoutPath>ec600s.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@@ -1252,7 +1264,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>13</GroupNumber>
<FileNumber>76</FileNumber>
<FileNumber>77</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1272,7 +1284,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>14</GroupNumber>
<FileNumber>77</FileNumber>
<FileNumber>78</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1292,7 +1304,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>78</FileNumber>
<FileNumber>79</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1304,7 +1316,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>79</FileNumber>
<FileNumber>80</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1316,7 +1328,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>80</FileNumber>
<FileNumber>81</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1328,7 +1340,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>81</FileNumber>
<FileNumber>82</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1340,7 +1352,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>82</FileNumber>
<FileNumber>83</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1352,7 +1364,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>83</FileNumber>
<FileNumber>84</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1364,7 +1376,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>84</FileNumber>
<FileNumber>85</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1376,7 +1388,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>85</FileNumber>
<FileNumber>86</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1388,7 +1400,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>86</FileNumber>
<FileNumber>87</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1400,7 +1412,7 @@
</File>
<File>
<GroupNumber>15</GroupNumber>
<FileNumber>87</FileNumber>
<FileNumber>88</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1420,7 +1432,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>16</GroupNumber>
<FileNumber>88</FileNumber>
<FileNumber>89</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1432,7 +1444,7 @@
</File>
<File>
<GroupNumber>16</GroupNumber>
<FileNumber>89</FileNumber>
<FileNumber>90</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1444,7 +1456,7 @@
</File>
<File>
<GroupNumber>16</GroupNumber>
<FileNumber>90</FileNumber>
<FileNumber>91</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1456,7 +1468,7 @@
</File>
<File>
<GroupNumber>16</GroupNumber>
<FileNumber>91</FileNumber>
<FileNumber>92</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1468,7 +1480,7 @@
</File>
<File>
<GroupNumber>16</GroupNumber>
<FileNumber>92</FileNumber>
<FileNumber>93</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1488,7 +1500,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>17</GroupNumber>
<FileNumber>93</FileNumber>
<FileNumber>94</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1500,7 +1512,7 @@
</File>
<File>
<GroupNumber>17</GroupNumber>
<FileNumber>94</FileNumber>
<FileNumber>95</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1512,7 +1524,7 @@
</File>
<File>
<GroupNumber>17</GroupNumber>
<FileNumber>95</FileNumber>
<FileNumber>96</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1524,7 +1536,7 @@
</File>
<File>
<GroupNumber>17</GroupNumber>
<FileNumber>96</FileNumber>
<FileNumber>97</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1544,7 +1556,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>18</GroupNumber>
<FileNumber>97</FileNumber>
<FileNumber>98</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1556,7 +1568,7 @@
</File>
<File>
<GroupNumber>18</GroupNumber>
<FileNumber>98</FileNumber>
<FileNumber>99</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1568,7 +1580,7 @@
</File>
<File>
<GroupNumber>18</GroupNumber>
<FileNumber>99</FileNumber>
<FileNumber>100</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1588,7 +1600,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>19</GroupNumber>
<FileNumber>100</FileNumber>
<FileNumber>101</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1600,7 +1612,7 @@
</File>
<File>
<GroupNumber>19</GroupNumber>
<FileNumber>101</FileNumber>
<FileNumber>102</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1612,7 +1624,7 @@
</File>
<File>
<GroupNumber>19</GroupNumber>
<FileNumber>102</FileNumber>
<FileNumber>103</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1624,7 +1636,7 @@
</File>
<File>
<GroupNumber>19</GroupNumber>
<FileNumber>103</FileNumber>
<FileNumber>104</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1636,7 +1648,7 @@
</File>
<File>
<GroupNumber>19</GroupNumber>
<FileNumber>104</FileNumber>
<FileNumber>105</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
@@ -1656,7 +1668,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>20</GroupNumber>
<FileNumber>105</FileNumber>
<FileNumber>106</FileNumber>
<FileType>5</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>

View File

@@ -339,7 +339,7 @@
<MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32L431xx</Define>
<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\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\examples\helloworld;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\examples\mqtt;..\..\..\..\devices\bc35_28_95;..\..\..\..\devices\esp8266;..\..\..\..\devices\m26;..\..\..\..\components\connectivity\mqttclient\common;..\..\..\..\components\connectivity\mqttclient\common\log;..\..\..\..\components\connectivity\mqttclient\mqtt;..\..\..\..\components\connectivity\mqttclient\mqttclient;..\..\..\..\components\connectivity\mqttclient\network;..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny</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\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\examples\helloworld;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\sal_module_wrapper;..\..\..\..\examples\mqtt;..\..\..\..\devices\bc35_28_95;..\..\..\..\devices\esp8266;..\..\..\..\devices\ec600s;..\..\..\..\components\connectivity\mqttclient\common;..\..\..\..\components\connectivity\mqttclient\common\log;..\..\..\..\components\connectivity\mqttclient\mqtt;..\..\..\..\components\connectivity\mqttclient\mqttclient;..\..\..\..\components\connectivity\mqttclient\network;..\..\..\..\components\connectivity\mqttclient\platform\TencentOS-tiny</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -813,6 +813,11 @@
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\esp8266\esp8266.c</FilePath>
</File>
<File>
<FileName>ec600s.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\devices\ec600s\ec600s.c</FilePath>
</File>
</Files>
</Group>
<Group>

36
devices/ec600s/Makefile Normal file
View File

@@ -0,0 +1,36 @@
###################################################################
#automatic detection QTOP and LOCALDIR
CUR_DIR := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
TRYQTOP := $(shell if [ -n "$$QTOP" ] ; then\
echo $$QTOP;\
else\
cd $(CUR_DIR); while /usr/bin/test ! -d qmk ; do \
dir=`cd ../;pwd`; \
if [ "$$dir" = "/" ] ; then \
echo Cannot find QTOP in $(firstword $(MAKEFILE_LIST)) 1>&2; \
exit 1; \
fi ; \
cd $$dir; \
done ; \
pwd; \
fi)
QTOP ?= $(realpath ${TRYQTOP})
ifeq ($(QTOP),)
$(error Please run this in a tree)
endif
LOCALDIR = $(patsubst %/,%,$(subst $(realpath $(QTOP))/,,$(CUR_DIR)))
####################################################################
TREE_LIB_ENABLE=0
lib=
subdirs=
CFGFLAGS += -I$(QTOP)/net/at/include
CFGFLAGS += -I$(QTOP)/net/sal_module_wrapper
include ${QTOP}/qmk/generic/Make.tpl

580
devices/ec600s/ec600s.c Normal file
View File

@@ -0,0 +1,580 @@
/*----------------------------------------------------------------------------
* 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.
*---------------------------------------------------------------------------*/
#include "ec600s.h"
#include "tos_at.h"
#include "tos_hal.h"
#include "sal_module_wrapper.h"
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
typedef struct ip_addr_st {
uint8_t seg1;
uint8_t seg2;
uint8_t seg3;
uint8_t seg4;
}ip_addr_t;
static ip_addr_t domain_parser_addr = {0};
static k_sem_t domain_parser_sem;
static k_sem_t module_ready_sem;
static int ec600s_check_ready(void)
{
at_echo_t echo;
tos_sem_create_max(&module_ready_sem, 0, 1);
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT\r\n");
if (echo.status == AT_ECHO_STATUS_OK) {
return 0;
} else {
tos_sem_pend(&module_ready_sem, TOS_TIME_FOREVER);
return 0;
}
}
static int ec600s_echo_close(void)
{
at_echo_t echo;
int try = 0;
tos_at_echo_create(&echo, NULL, 0, NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "ATE0\r\n");
if (echo.status == AT_ECHO_STATUS_OK) {
return 0;
}
}
return -1;
}
static int ec600s_sim_card_check(void)
{
at_echo_t echo;
int try = 0;
char echo_buffer[32];
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CPIN?\r\n");
if (strstr(echo_buffer, "READY")) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int ec600s_signal_quality_check(void)
{
int rssi, ber;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CSQ\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CSQ:");
if (!str) {
return -1;
}
sscanf(str, "+CSQ:%d,%d", &rssi, &ber);
if (rssi != 99) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int ec600s_gsm_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CREG:");
if (!str) {
return -1;
}
sscanf(str, "+CREG:%d,%d", &n, &stat);
if (stat == 1) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int ec600s_gprs_network_check(void)
{
int n, stat;
at_echo_t echo;
char echo_buffer[32], *str;
int try = 0;
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
while (try++ < 10) {
tos_at_cmd_exec(&echo, 1000, "AT+CGREG?\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
str = strstr(echo.buffer, "+CGREG:");
if (!str) {
return -1;
}
sscanf(str, "+CGREG:%d,%d", &n, &stat);
if (stat == 1) {
return 0;
}
tos_sleep_ms(2000);
}
return -1;
}
static int ec600s_close_apn(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 3000, "AT+QIDEACT=1\r\n");
if (echo.status == AT_ECHO_STATUS_OK) {
return 0;
}
return -1;
}
static int ec600s_set_apn(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+QICSGP=1,1,\"CMNET\"\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
tos_at_cmd_exec(&echo, 3000, "AT+QIACT=1\r\n");
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
return 0;
}
static int ec600s_init(void)
{
printf("Init ec600s ...\n" );
if (ec600s_check_ready() != 0) {
printf("wait module ready timeout, please check your module\n");
return -1;
}
if (ec600s_echo_close() != 0) {
printf("echo close failed,please check your module\n");
return -1;
}
if(ec600s_sim_card_check() != 0) {
printf("sim card check failed,please insert your card\n");
return -1;
}
if (ec600s_signal_quality_check() != 0) {
printf("signal quality check status failed\n");
return -1;
}
if(ec600s_gsm_network_check() != 0) {
printf("GSM network register status check fail\n");
return -1;
}
if(ec600s_gprs_network_check() != 0) {
printf("GPRS network register status check fail\n");
return -1;
}
if(ec600s_close_apn() != 0) {
printf("close apn failed\n");
return -1;
}
if (ec600s_set_apn() != 0) {
printf("apn set FAILED\n");
return -1;
}
printf("Init ec600s ok\n" );
return 0;
}
static int ec600s_connect(const char *ip, const char *port, sal_proto_t proto)
{
int id;
at_echo_t echo;
char except_str[16];
id = tos_at_channel_alloc(ip, port);
if (id == -1) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 1000, "AT+QICLOSE=%d\r\n", id);
if (echo.status != AT_ECHO_STATUS_OK) {
tos_at_channel_free(id);
return -1;
}
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 ec600s_recv_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
static int ec600s_recv(int id, void *buf, size_t len)
{
return ec600s_recv_timeout(id, buf, len, (uint32_t)4000);
}
int ec600s_send(int id, const void *buf, size_t len)
{
at_echo_t echo;
if (!tos_at_channel_is_working(id)) {
return -1;
}
if (tos_at_global_lock_pend() != 0) {
return -1;
}
tos_at_echo_create(&echo, NULL, 0, ">");
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send_until(&echo, 10000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
int ec600s_recvfrom_timeout(int id, void *buf, size_t len, uint32_t timeout)
{
return tos_at_channel_read_timed(id, buf, len, timeout);
}
int ec600s_recvfrom(int id, void *buf, size_t len)
{
return ec600s_recvfrom_timeout(id, buf, len, (uint32_t)4000);
}
int ec600s_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, ">");
tos_at_cmd_exec_until(&echo, 1000, "AT+QISEND=%d,%d\r\n", id, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_echo_create(&echo, NULL, 0, "SEND OK");
tos_at_raw_data_send(&echo, 1000, (uint8_t *)buf, len);
if (echo.status != AT_ECHO_STATUS_EXPECT) {
tos_at_global_lock_post();
return -1;
}
tos_at_global_lock_post();
return len;
}
static void ec600s_transparent_mode_exit(void)
{
at_echo_t echo;
tos_at_echo_create(&echo, NULL, 0, NULL);
tos_at_cmd_exec(&echo, 500, "+++");
}
static int ec600s_close(int id)
{
at_echo_t echo;
ec600s_transparent_mode_exit();
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);
return 0;
}
static int ec600s_parse_domain(const char *host_name, char *host_ip, size_t host_ip_len)
{
at_echo_t echo;
char echo_buffer[128];
tos_sem_create_max(&domain_parser_sem, 0, 1);
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), NULL);
tos_at_cmd_exec(&echo, 2000, "AT+QIDNSGIP=1,\"%s\"\r\n", host_name);
if (echo.status != AT_ECHO_STATUS_OK) {
return -1;
}
tos_sem_pend(&domain_parser_sem, TOS_TIME_FOREVER);
snprintf(host_ip, host_ip_len, "%d.%d.%d.%d", domain_parser_addr.seg1, domain_parser_addr.seg2, domain_parser_addr.seg3, domain_parser_addr.seg4);
host_ip[host_ip_len - 1] = '\0';
printf("GOT IP: %s\n", host_ip);
return 0;
}
__STATIC__ void ec600s_incoming_data_process(void)
{
uint8_t data;
int channel_id = 0, data_len = 0, read_len;
uint8_t buffer[128];
/*
+QIURC: "recv",<sockid>,<datalen>
<data content>
*/
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 == '\r') {
break;
}
data_len = data_len * 10 + (data - '0');
}
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
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;
}
__STATIC__ void ec600s_domain_data_process(void)
{
uint8_t data;
/*
+QIURC: "dnsgip",0,1,600
+QIURC: "dnsgip","xxx.xxx.xxx.xxx"
*/
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == '0') {
return;
}
if (data == '\"') {
/* start parser domain */
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == '.') {
break;
}
domain_parser_addr.seg1 = domain_parser_addr.seg1 *10 + (data-'0');
}
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == '.') {
break;
}
domain_parser_addr.seg2 = domain_parser_addr.seg2 *10 + (data-'0');
}
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == '.') {
break;
}
domain_parser_addr.seg3 = domain_parser_addr.seg3 *10 + (data-'0');
}
while (1) {
if (tos_at_uart_read(&data, 1) != 1) {
return;
}
if (data == '\"') {
break;
}
domain_parser_addr.seg4 = domain_parser_addr.seg4 *10 + (data-'0');
}
tos_sem_post(&domain_parser_sem);
}
return;
}
__STATIC__ void ec600s_ready_data_process(void)
{
printf("module ready\r\n");
tos_sem_post(&module_ready_sem);
}
at_event_t ec600s_at_event[] = {
{ "+QIURC: \"recv\",", ec600s_incoming_data_process},
{ "+QIURC: \"dnsgip\",", ec600s_domain_data_process},
{ "RDY", ec600s_ready_data_process},
};
sal_module_t sal_module_ec600s = {
.init = ec600s_init,
.connect = ec600s_connect,
.send = ec600s_send,
.recv_timeout = ec600s_recv_timeout,
.recv = ec600s_recv,
.sendto = ec600s_sendto,
.recvfrom = ec600s_recvfrom,
.recvfrom_timeout = ec600s_recvfrom_timeout,
.close = ec600s_close,
.parse_domain = ec600s_parse_domain,
};
int ec600s_sal_init(hal_uart_port_t uart_port)
{
if (tos_at_init(uart_port, ec600s_at_event,
sizeof(ec600s_at_event) / sizeof(ec600s_at_event[0])) != 0) {
return -1;
}
if (tos_sal_module_register(&sal_module_ec600s) != 0) {
return -1;
}
if (tos_sal_module_init() != 0) {
return -1;
}
return 0;
}
int ec600s_sal_deinit()
{
int id = 0;
for (id = 0; id < AT_DATA_CHANNEL_NUM; ++id) {
tos_sal_module_close(id);
}
tos_sal_module_register_default();
tos_at_deinit();
return 0;
}

27
devices/ec600s/ec600s.h Normal file
View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------
* 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 __EC600S_H__
#define __EC600S_H__
#include "tos_hal.h"
int ec600s_sal_init(hal_uart_port_t uart_port);
int ec600s_sal_deinit(void);
#endif /* __EC600S_H__ */