Skip to content

Commit d62a536

Browse files
author
Spike Lin
committed
v3.1.1
1. 集成RT-Thread平台支持 2. 修复一些代码bug以及MQTT construct失败后资源释放不完整的问题 3. OTA HTTPS或HTTP下载方式可以通过编译选项控制
1 parent e517183 commit d62a536

File tree

21 files changed

+3932
-15
lines changed

21 files changed

+3932
-15
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ set(FEATURE_AT_DEBUG OFF)
7575
# 是否编译Linux多线程测试例程
7676
set(FEATURE_MULTITHREAD_TEST_ENABLED ON)
7777

78+
# 是否使用HTTPS下载固件
79+
set(FEATURE_OTA_USE_HTTPS ON)
80+
7881
######################CONFIG END######################################
7982

8083
# 设置CMAKE使用编译工具及编译选项
@@ -145,7 +148,7 @@ option(EVENT_POST_ENABLED "Enable EVENT_POST" ${FEATURE_EVENT_POST_ENABLED})
145148
option(DEV_DYN_REG_ENABLED "Enable DEV_DYN_REG" ${FEATURE_DEV_DYN_REG_ENABLED})
146149
option(LOG_UPLOAD "Enable LOG_UPLOAD" ${FEATURE_LOG_UPLOAD_ENABLED})
147150
option(DEBUG_DEV_INFO_USED "Enable DEBUG_DEV_INFO_USED" ${FEATURE_DEBUG_DEV_INFO_USED})
148-
151+
option(OTA_USE_HTTPS "Enable OTA_USE_HTTPS" ${FEATURE_OTA_USE_HTTPS})
149152
option(AT_TCP_ENABLED "Enable AT_TCP" ${FEATURE_AT_TCP_ENABLED})
150153

151154
if(AT_TCP_ENABLED STREQUAL "ON")

docs/FreeRTOS+lwIP平台移植说明.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sdk_src为SDK的核心逻辑及协议相关代码,一般不需要修改,其
3939
用户可将qcloud_iot_c_sdk拷贝到其目标平台的编译开发环境,并根据具体情况修改编译选项。
4040

4141
## 乐鑫ESP8266 RTOS平台移植示例
42-
在Linux开发环境基于乐鑫ESP8266 RTOS平台搭建一个工程示例
42+
在Linux开发环境基于乐鑫ESP8266 RTOS平台搭建一个工程示例,完整可实际运行例程可参考[基于ESP8266 Launcher开发板的工程](https://github.com/tencentyun/qcloud-iot-c-sdk-porting-examples/tree/master/QCloud_IoT_ESP8266_RTOS)
4343

4444
### 1. 获取 ESP8266_RTOS_SDK 并创建工程
4545

include/config.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
1+
/* #undef AUTH_MODE_CERT */
2+
#define AUTH_MODE_KEY
3+
/* #undef AUTH_WITH_NOTLS */
4+
#define GATEWAY_ENABLED
5+
#define COAP_COMM_ENABLED
6+
#define OTA_MQTT_CHANNEL
7+
#define SYSTEM_COMM
8+
#define EVENT_POST_ENABLED
9+
#define DEV_DYN_REG_ENABLED
10+
#define LOG_UPLOAD
11+
/* #undef IOT_DEBUG */
12+
/* #undef DEBUG_DEV_INFO_USED */
13+
/* #undef AT_TCP_ENABLED */
14+
/* #undef AT_UART_RECV_IRQ */
15+
/* #undef AT_OS_USED */
16+
/* #undef AT_DEBUG */
17+
#define OTA_USE_HTTPS

include/qcloud_iot_export.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525

2626

2727
/* IoT C-SDK version info */
28-
#define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.0"
28+
#define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.1"
2929

3030
/**************** QCloud IoT C-SDK constants begin ************************/
3131

make.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ FEATURE_AT_OS_USED = y
6969

7070
# 是否打开AT模组调试功能
7171
FEATURE_AT_DEBUG = y
72+
73+
# 是否使用HTTPS下载固件
74+
FEATURE_OTA_USE_HTTPS = y
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making IoT Hub available.
3+
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
4+
5+
* Licensed under the MIT License (the "License"); you may not use this file except in
6+
* compliance with the License. You may obtain a copy of the License at
7+
* http://opensource.org/licenses/MIT
8+
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*
14+
*/
15+
16+
#include <stdio.h>
17+
#include <stdlib.h>
18+
#include <string.h>
19+
20+
#include "qcloud_iot_import.h"
21+
#include "qcloud_iot_export.h"
22+
23+
#include "utils_param_check.h"
24+
25+
/* Enable this macro (also control by cmake) to use static string buffer to store device info */
26+
/* To use specific storing methods like files/flash, disable this macro and implement dedicated methods */
27+
#define DEBUG_DEV_INFO_USED
28+
29+
#ifdef DEBUG_DEV_INFO_USED
30+
/* product Id */
31+
static char sg_product_id[MAX_SIZE_OF_PRODUCT_ID + 1] = "PRODUCT_ID";
32+
33+
/* device name */
34+
static char sg_device_name[MAX_SIZE_OF_DEVICE_NAME + 1] = "YOUR_DEV_NAME";
35+
36+
#ifdef DEV_DYN_REG_ENABLED
37+
/* product secret for device dynamic Registration */
38+
static char sg_product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1] = "YOUR_PRODUCT_SECRET";
39+
#endif
40+
41+
#ifdef AUTH_MODE_CERT
42+
/* public cert file name of certificate device */
43+
static char sg_device_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1] = "YOUR_DEVICE_NAME_cert.crt";
44+
/* private key file name of certificate device */
45+
static char sg_device_privatekey_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1] = "YOUR_DEVICE_NAME_private.key";
46+
#else
47+
/* device secret of PSK device */
48+
static char sg_device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1] = "YOUR_IOT_PSK";
49+
#endif
50+
51+
#ifdef GATEWAY_ENABLED
52+
/* sub-device product id */
53+
static char sg_sub_device_product_id[MAX_SIZE_OF_PRODUCT_ID + 1] = "PRODUCT_ID";
54+
/* sub-device device name */
55+
static char sg_sub_device_name[MAX_SIZE_OF_DEVICE_NAME + 1] = "YOUR_SUB_DEV_NAME";
56+
#endif
57+
58+
static int device_info_copy(void *pdst, void *psrc, uint8_t max_len)
59+
{
60+
if(strlen(psrc) > max_len){
61+
return QCLOUD_ERR_FAILURE;
62+
}
63+
memset(pdst, '\0', max_len);
64+
strncpy(pdst, psrc, max_len);
65+
return QCLOUD_RET_SUCCESS;
66+
}
67+
68+
#endif
69+
70+
int HAL_SetDevInfo(void *pdevInfo)
71+
{
72+
POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO);
73+
int ret;
74+
DeviceInfo *devInfo = (DeviceInfo *)pdevInfo;
75+
76+
#ifdef DEBUG_DEV_INFO_USED
77+
ret = device_info_copy(sg_product_id, devInfo->product_id, MAX_SIZE_OF_PRODUCT_ID);//set product ID
78+
ret |= device_info_copy(sg_device_name, devInfo->device_name, MAX_SIZE_OF_DEVICE_NAME);//set dev name
79+
80+
#ifdef AUTH_MODE_CERT
81+
ret |= device_info_copy(sg_device_cert_file_name, devInfo->dev_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//set dev cert file name
82+
ret |= device_info_copy(sg_device_privatekey_file_name, devInfo->dev_key_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//set dev key file name
83+
#else
84+
ret |= device_info_copy(sg_device_secret, devInfo->device_secret, MAX_SIZE_OF_DEVICE_SECRET);//set dev secret
85+
#endif
86+
87+
#else
88+
Log_e("HAL_SetDevInfo not implement yet");
89+
ret = QCLOUD_ERR_DEV_INFO;
90+
#endif
91+
92+
if(QCLOUD_RET_SUCCESS != ret) {
93+
Log_e("Set device info err");
94+
ret = QCLOUD_ERR_DEV_INFO;
95+
}
96+
return ret;
97+
}
98+
99+
int HAL_GetDevInfo(void *pdevInfo)
100+
{
101+
POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO);
102+
int ret;
103+
DeviceInfo *devInfo = (DeviceInfo *)pdevInfo;
104+
memset((char *)devInfo, '\0', sizeof(DeviceInfo));
105+
106+
#ifdef DEBUG_DEV_INFO_USED
107+
ret = device_info_copy(devInfo->product_id, sg_product_id, MAX_SIZE_OF_PRODUCT_ID);//get product ID
108+
ret |= device_info_copy(devInfo->device_name, sg_device_name, MAX_SIZE_OF_DEVICE_NAME);//get dev name
109+
110+
#ifdef DEV_DYN_REG_ENABLED
111+
ret |= device_info_copy(devInfo->product_secret, sg_product_secret, MAX_SIZE_OF_PRODUCT_SECRET );//get product ID
112+
#endif
113+
114+
#ifdef AUTH_MODE_CERT
115+
ret |= device_info_copy(devInfo->dev_cert_file_name, sg_device_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//get dev cert file name
116+
ret |= device_info_copy(devInfo->dev_key_file_name, sg_device_privatekey_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//get dev key file name
117+
#else
118+
ret |= device_info_copy(devInfo->device_secret, sg_device_secret, MAX_SIZE_OF_DEVICE_SECRET);//get dev secret
119+
#endif
120+
121+
#else
122+
Log_e("HAL_GetDevInfo not implement yet");
123+
ret = QCLOUD_ERR_DEV_INFO;
124+
#endif
125+
126+
if(QCLOUD_RET_SUCCESS != ret){
127+
Log_e("Get device info err");
128+
ret = QCLOUD_ERR_DEV_INFO;
129+
}
130+
return ret;
131+
}
132+
133+
#ifdef GATEWAY_ENABLED
134+
int HAL_GetGwDevInfo(void *pgwDeviceInfo)
135+
{
136+
POINTER_SANITY_CHECK(pgwDeviceInfo, QCLOUD_ERR_DEV_INFO);
137+
int ret;
138+
GatewayDeviceInfo *gwDevInfo = (GatewayDeviceInfo *)pgwDeviceInfo;
139+
memset((char *)gwDevInfo, 0, sizeof(GatewayDeviceInfo));
140+
141+
#ifdef DEBUG_DEV_INFO_USED
142+
ret = HAL_GetDevInfo(&(gwDevInfo->gw_info));//get gw dev info
143+
//only one sub-device is supported now
144+
gwDevInfo->sub_dev_num = 1;
145+
gwDevInfo->sub_dev_info = (DeviceInfo *)HAL_Malloc(sizeof(DeviceInfo)*(gwDevInfo->sub_dev_num));
146+
memset((char *)gwDevInfo->sub_dev_info, '\0', sizeof(DeviceInfo));
147+
//copy sub dev info
148+
ret = device_info_copy(gwDevInfo->sub_dev_info->product_id, sg_sub_device_product_id, MAX_SIZE_OF_PRODUCT_ID);
149+
ret |= device_info_copy(gwDevInfo->sub_dev_info->device_name, sg_sub_device_name, MAX_SIZE_OF_DEVICE_NAME);
150+
151+
#else
152+
Log_e("HAL_GetDevInfo not implement yet");
153+
ret = QCLOUD_ERR_DEV_INFO;
154+
#endif
155+
156+
if(QCLOUD_RET_SUCCESS != ret) {
157+
Log_e("Get gateway device info err");
158+
ret = QCLOUD_ERR_DEV_INFO;
159+
}
160+
return ret;
161+
}
162+
#endif
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making IoT Hub available.
3+
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
4+
5+
* Licensed under the MIT License (the "License"); you may not use this file except in
6+
* compliance with the License. You may obtain a copy of the License at
7+
* http://opensource.org/licenses/MIT
8+
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*
14+
*/
15+
#include <stdarg.h>
16+
#include <string.h>
17+
#include <rtthread.h>
18+
#include "rtconfig.h"
19+
#include "qcloud_iot_import.h"
20+
#include "qcloud_iot_export.h"
21+
22+
23+
#define HAL_OS_LOG_MAXLEN 1024
24+
static uint16_t g_mutex_count = 0;
25+
26+
27+
28+
void HAL_Printf(_IN_ const char *fmt, ...)
29+
{
30+
va_list args;
31+
char log_buf[HAL_OS_LOG_MAXLEN];
32+
33+
va_start(args, fmt);
34+
rt_vsnprintf(log_buf, HAL_OS_LOG_MAXLEN, fmt, args);
35+
va_end(args);
36+
printf("%s", log_buf);
37+
}
38+
39+
40+
int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...)
41+
{
42+
va_list args;
43+
int rc;
44+
45+
va_start(args, fmt);
46+
rc = vsnprintf(str, len, fmt, args);
47+
va_end(args);
48+
49+
return rc;
50+
}
51+
52+
53+
int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap)
54+
{
55+
return vsnprintf(str, len, format, ap);
56+
}
57+
58+
59+
void *HAL_MutexCreate(void)
60+
{
61+
rt_mutex_t mutex;
62+
char mutexName[RT_NAME_MAX];
63+
64+
memset(mutexName, 0, RT_NAME_MAX);
65+
HAL_Snprintf(mutexName, RT_NAME_MAX, "tmutex_%d", g_mutex_count++);
66+
mutex = rt_mutex_create(mutexName, RT_IPC_FLAG_FIFO);
67+
if (NULL == mutex) {
68+
HAL_Printf("create mutex failed");
69+
70+
}
71+
72+
return mutex;
73+
74+
75+
}
76+
77+
void HAL_MutexDestroy(_IN_ void *mutex)
78+
{
79+
int err_num;
80+
81+
err_num = rt_mutex_delete((rt_mutex_t)mutex);
82+
83+
if (0 != err_num)
84+
{
85+
HAL_Printf("destroy mutex failed");
86+
}
87+
}
88+
89+
void HAL_MutexLock(_IN_ void *mutex)
90+
{
91+
int err_num;
92+
93+
err_num = rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_FOREVER);
94+
95+
if (0 != err_num)
96+
{
97+
HAL_Printf("lock mutex failed");
98+
}
99+
}
100+
101+
void HAL_MutexUnlock(_IN_ void *mutex)
102+
{
103+
int err_num;
104+
105+
err_num = rt_mutex_release((rt_mutex_t)mutex);
106+
107+
if (0 != err_num)
108+
{
109+
HAL_Printf("unlock mutex failed");
110+
}
111+
112+
}
113+
114+
int HAL_MutexTryLock(_IN_ void *mutex)
115+
{
116+
int err_num;
117+
118+
err_num = rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_NO);
119+
120+
if (0 != err_num)
121+
{
122+
HAL_Printf("trylock mutex failed");
123+
}
124+
return err_num;
125+
}
126+
127+
128+
void *HAL_Malloc(_IN_ uint32_t size)
129+
{
130+
return rt_malloc(size);
131+
}
132+
133+
void HAL_Free(_IN_ void *ptr)
134+
{
135+
rt_free(ptr);
136+
}
137+
138+
void HAL_SleepMs(_IN_ uint32_t ms)
139+
{
140+
(void)rt_thread_delay(rt_tick_from_millisecond(ms));
141+
}
142+
143+

0 commit comments

Comments
 (0)