Skip to content

Commit 4257b6b

Browse files
author
tedazhao
committed

33 files changed

+2531
-45
lines changed

CMakeLists.txt

+43-8
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,164 @@
11
# 项目信息
2+
# Project information
23
project (QCloud_IoT_SDK C)
34

45
# CMake 最低版本号要求
6+
# Cmake minimum version required
57
cmake_minimum_required (VERSION 3.5)
68

79
######################CONFIG BEGIN####################################
810
# 编译类型: release/debug
11+
# Compilation Type: release/debug
912
set(BUILD_TYPE "release")
1013

1114
# 代码抽取,ON表示根据配置抽取源码到ouput/qcloud_iot_c_sdk目录
15+
# Code extraction, ON means to extract the source code according to the configuration to ouput/qcloud_iot_c_sdk directory
1216
set(EXTRACT_SRC OFF)
1317

1418
# 编译工具链
19+
# Compilation Toolchain
1520
set(COMPILE_TOOLS "gcc")
1621
set(PLATFORM "linux")
1722

1823
#set(COMPILE_TOOLS "MSVC")
1924
#set(PLATFORM "windows")
2025

2126
# 是否打开MQTT通道的总开关
27+
# Whether to Turn on Master Switch for MQTT Channel
2228
set(FEATURE_MQTT_COMM_ENABLED ON)
2329

2430
# 是否打开设备影子的总开关
31+
# Whether to Turn on Master Switch for Device Shadow
2532
set(FEATURE_MQTT_DEVICE_SHADOW ON)
2633

2734
# 是否打开CoAP通道的总开关
35+
# Whether to Turn on Master Switch for CoAP Channel
2836
set(FEATURE_COAP_COMM_ENABLED OFF)
2937

3038
# 是否打开MQTT通道网关功能
39+
# Whether to Turn on Master Switch for MQTT Gateway Channel
3140
set(FEATURE_GATEWAY_ENABLED ON)
3241

3342
# 是否打开OTA固件升级总开关
43+
# Whether to Turn on Master Switch for OTA Firmware Update
3444
set(FEATURE_OTA_COMM_ENABLED ON)
3545

3646
# OTA信令通道类型:MQTT/COAP
47+
# OTA Signaling Channel Type:MQTT/COAP
3748
set(FEATURE_OTA_SIGNAL_CHANNEL "MQTT")
3849

3950
# MQTT/CoAP接入认证方式,使用证书认证:CERT;使用密钥认证:KEY
51+
# MQTT/CoAP Access Authentication Method,Certificate Authentication:CERT;Key Authentication:KEY
4052
set(FEATURE_AUTH_MODE "KEY")
4153

4254
# 接入认证是否不使用TLS,证书方式必须选择使用TLS,密钥认证可选择不使用TLS
55+
# Whether access authentication uses TLS, certificate authentication must use TLS, key authentication can choose not to use TLS
4356
set(FEATURE_AUTH_WITH_NOTLS ON)
4457

4558
# 是否打开多线程功能支持
59+
# Whether to turn on multi-threading support
4660
set(FEATURE_MULTITHREAD_ENABLED ON)
4761

4862
# 是否使能设备动态注册
63+
# Whether to enable dynamic device registration
4964
set(FEATURE_DEV_DYN_REG_ENABLED ON)
5065

5166
# 是否打开日志上报云端功能
67+
# Whether to enable the log report cloud feature
5268
set(FEATURE_LOG_UPLOAD_ENABLED OFF)
5369

5470
# 是否打开代码中获取设备信息功能,OFF时将从device_info.json中读取设备信息
71+
# Whether to turn on the function of getting device information in the code, if set to OFF, the device information will be read from device_info.json
5572
set(FEATURE_DEBUG_DEV_INFO_USED OFF)
5673

5774
# 是否打开获取iot后台时间功能
75+
# Whether to access the feature of getting iot background time
5876
set(FEATURE_SYSTEM_COMM_ENABLED ON)
5977

6078
# 是否使用HTTPS下载固件
79+
# Whether to use HTTPS to download firmware
6180
set(FEATURE_OTA_USE_HTTPS ON)
6281

6382
# 是否打开AT模组TCP功能
83+
# Whether to use the AT method to achieve TCP communication
6484
set(FEATURE_AT_TCP_ENABLED OFF)
6585

6686
# 设置AT模组设备(目前只支持esp8266)
87+
# Set AT module device (only support ESP8266 so far)
6788
set(AT_DEVICE_NAME "esp8266")
6889

6990
# 是否打开AT模组中断接收功能
91+
# Whether to turn on the AT module interrupt reception feature
7092
set(FEATURE_AT_UART_RECV_IRQ OFF)
7193

7294
# 是否打开AT模组多线程功能
95+
# Whether to open the AT module multi-threading feature
7396
set(FEATURE_AT_OS_USED ON)
7497

7598
# 是否打开AT模组调试功能
99+
# Whether to open the AT module debugging feature
76100
set(FEATURE_AT_DEBUG OFF)
77101

78102
# 是否打开广播功能
103+
# Whether to turn on the broadcast feature
79104
set(FEATURE_BROADCAST_ENABLED ON)
80105

81106
# 是否打开RRPC功能
107+
# Whether to turn on the RRPC feature
82108
set(FEATURE_RRPC_ENABLED ON)
83109

84110
# 是否打开远程配置功能
111+
# Whether to turn on the MQTT remote configuration
85112
set(FEATURE_REMOTE_CONFIG_MQTT_ENABLED ON)
86113

87114
# 是否打开资源管理总开关
115+
# Whether to turn on Master Switch for the resource manage
88116
set(FEATURE_RESOURCE_COMM_ENABLED ON)
89117

90118
# 资源管理通道类型:MQTT
119+
# resource manage Signaling Channel Type:MQTT
91120
set(FEATURE_RESOURCE_SIGNAL_CHANNEL "MQTT")
92121

93122
# 资源管理使用 https 通信
123+
# Whether to use HTTPS for resource manage
94124
set(FEATURE_RESOURCE_USE_HTTPS ON)
95125

96126
######################CONFIG END######################################
97127

98128
# 设置CMAKE使用编译工具及编译选项
129+
# Set CMAKE to use compilation tools and compilation options
99130
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
100131
if (PLATFORM STREQUAL "linux" AND COMPILE_TOOLS STREQUAL "gcc")
101132
set(CMAKE_C_COMPILER ${COMPILE_TOOLS})
102133
if(${BUILD_TYPE} STREQUAL "release")
103-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项
134+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项 Compilation options
104135
elseif(${BUILD_TYPE} STREQUAL "debug")
105-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项
136+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项 Compilation options
106137
endif()
107138
elseif (PLATFORM STREQUAL "linux" AND COMPILE_TOOLS STREQUAL "arm-none-linux-gnueabi-gcc")
108139
set(CMAKE_C_COMPILER ${COMPILE_TOOLS})
109140
if(${BUILD_TYPE} STREQUAL "release")
110-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项
141+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项 Compilation options
111142
elseif(${BUILD_TYPE} STREQUAL "debug")
112-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项
143+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os -pthread") # 编译选项 Compilation options
113144
endif()
114145
elseif (PLATFORM STREQUAL "windows" AND COMPILE_TOOLS STREQUAL "MSVC")
115-
# 去除相应的警告
146+
# 去除相应的警告 Remove the corresponding warning
116147
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_USE_32BIT_TIME_T)
117148
if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
118149
string(REGEX REPLACE "/W[0-4]" "/W2" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
119150
else()
120151
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2")
121152
endif()
122153
else ()
123-
#用户自定义
124-
set(CMAKE_C_COMPILER ${COMPILE_TOOLS}) # 编译工具
125-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os") # 编译选项
154+
#用户自定义 Custom
155+
set(CMAKE_C_COMPILER ${COMPILE_TOOLS}) # 编译工具 Compilation tools
156+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-error=sign-compare -Wno-error=format -Os") # 编译选项 Compilation option
126157
message(WARNING "User defined platform or compile tools!")
127158
endif()
128159

129160
# 解析配置
161+
# Parsing configuration
130162
if(${BUILD_TYPE} STREQUAL "release")
131163
option(IOT_DEBUG "Enable IOT_DEBUG" OFF)
132164
elseif(${BUILD_TYPE} STREQUAL "debug")
@@ -196,6 +228,7 @@ configure_file (
196228
)
197229

198230
# 头文件目录
231+
# Header file directory
199232
include_directories(${PROJECT_SOURCE_DIR}/include
200233
${PROJECT_SOURCE_DIR}/include/exports
201234
${PROJECT_SOURCE_DIR}/platform/at_device/esp8266
@@ -220,6 +253,7 @@ if(${EXTRACT_SRC} STREQUAL "ON" AND NOT DEFINED SAMPLE_ONLY)
220253
endif()
221254

222255
# 添加源代码目录
256+
# Add source code directory
223257
if(NOT DEFINED SAMPLE_ONLY)
224258
add_subdirectory(${PROJECT_SOURCE_DIR}/sdk_src)
225259
add_subdirectory(${PROJECT_SOURCE_DIR}/platform)
@@ -232,6 +266,7 @@ if(SAMPLE_ONLY STREQUAL "ON")
232266
endif()
233267

234268
# 证书及设备信息
269+
# Certificate and device information
235270
if(NOT DEFINED SAMPLE_ONLY)
236271
file(COPY ${PROJECT_SOURCE_DIR}/certs DESTINATION ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/bin)
237272
file(COPY ${PROJECT_SOURCE_DIR}/device_info.json DESTINATION ${PROJECT_SOURCE_DIR}/output/${BUILD_TYPE}/bin)

README_EN-US.md

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# IoT Hub Device C-SDK
2+
3+
IoT Hub device C-SDK relies on a secure and powerful data channel to enable IoT developers to quickly connect devices to the cloud for two-way communication.
4+
5+
After v3.1.0, the SDK refactored and optimized the compilation environment, code, and directory structure, increasing the availability and portability.
6+
7+
This SDK is applicable only to IoT Hub. For the SDK of IoT Explorer, please see [IoT Explorer C-SDK](https://github.com/tencentyun/qcloud-iot-explorer-sdk-embedded-c).
8+
9+
## 1. Scope of Application of C-SDK
10+
Featuring a modular design, the C-SDK separates the core protocol service from the hardware abstraction layer and provides flexible configuration options and multiple compilation methods, making it suitable for development platforms and use environments of different devices.
11+
12+
#### 1. Network communication-capable devices on Linux/Windows
13+
14+
For devices that have network communication capabilities and run on standard Linux/Windows, such as PCs, servers, and gateway devices, as well as advanced embedded devices such as Raspberry Pi, you can directly compile and run the SDK on them.
15+
For embedded Linux devices that require cross compilation, if the toolchain of the development environment has `glibc` or similar libraries which can provide system calls, including socket communication, SELECT sync IO, dynamic memory allocation, functions for getting time/sleeping/generating random number/printing, as well as critical data protection such as the mutex mechanism (only when multiple threads are required), only simple adaptation (e.g., changing the cross compiler settings in `CMakeLists.txt` or `make.settings`) is required before the SDK can be compiled and run.
16+
17+
#### 2. Network communication-capable devices on RTOS
18+
19+
For IoT devices that have network communication capabilities and run on RTOS, the C-SDK needs to be adapted to different RTOS systems for porting. Currently, it has been adapted to multiple IoT-oriented RTOS platforms, including FreeRTOS, RT-Thread, and TencentOS tiny.
20+
When porting the SDK to an RTOS device, if the platform provides C runtime libraries like `Newlib` and embedded TCP/IP protocol stacks like lwIP, adaptation for porting can be done easily.
21+
22+
#### 3. Devices with MCU + communication module
23+
24+
For MCUs that have no network communication capabilities, the "MCU + communication module" combination is often used. Communication modules (including Wi-Fi/2G/4G/NB-IoT) generally provide serial port-based AT instruction protocols for MCUs to communicate over the network. For this scenario, the C-SDK encapsulates the AT-socket network layer, where the core protocol and service layer don't need to be ported. In addition, it provides FreeRTOS-based and nonOS HAL implementation methods. For more information, please see the corresponding document in the `docs` directory.
25+
26+
In addition, IoT Hub provides a dedicated AT instruction set. If the communication module implements this instruction set, it will be easier for devices to connect and communicate, and less code will be required. For this scenario, please refer to the [SDK for MCU AT](https://github.com/tencentyun/qcloud-iot-sdk-tencent-at-based.git) dedicated to the Tencent Cloud customized AT module.
27+
28+
## 2. SDK Directory Structure Overview
29+
30+
#### 1. Directory structure and top-level documents
31+
32+
| Name | Description |
33+
| ------------------ | ------------------------------------------------------------ |
34+
| CMakeLists.txt | CMake compilation and description file |
35+
| CMakeSettings.json | CMake configuration file on Visual Studio |
36+
| cmake_build.sh | Compilation script with CMake on Linux |
37+
| make.settings | Configuration file compiled directly by Makefile on Linux |
38+
| Makefile | Direct compilation with Makefile on Linux |
39+
| device_info.json | Device information file. If `DEBUG_DEV_INFO_USED` = `OFF`, the device information will be parsed from this file |
40+
| docs | Documentation directory, i.e., the use instructions of the SDKs for different platforms |
41+
| external_libs | Third-party package components, such as Mbed TLS |
42+
| samples | Application demos |
43+
| include | External header files provided to users |
44+
| platform | Platform source code files. Currently, implementations are provided for different OS (Linux/Windows/FreeRTOS/nonOS), TLS (Mbed TLS), and AT module |
45+
| sdk_src | Core communication protocols and service code of the SDK |
46+
| tools | Compilation and code generation script tools supporting the SDK |
47+
48+
## 3. SDK Compilation Method Description
49+
50+
The C-SDK supports three compilation methods:
51+
52+
- CMake
53+
- Makefile
54+
- Code extraction
55+
56+
For more information on the compilation methods and compilation configuration options, please see **C-SDK_Build Compilation Environment and Configuration Description** in the `docs` directory.
57+
58+
## 4. SDK Demos
59+
60+
The `samples` directory of the C-SDK contains demos showing how to use the features. For more information on how to run the demos, please see the documents in the `docs` directory.
61+
62+
## 5. Notes
63+
64+
#### Multi-device connection
65+
Starting from v3.2.0, the SDK supports multiple devices as clients to connect to the IoT Hub backend at the same time and optimizes and enhances the use of APIs in a multithreaded environment. For more information, please see **C-SDK_MTMC Multithreaded Multi-Device Support** in the `docs` directory.
66+
This version encapsulates the status variables and parameters in an object-oriented way. Its impact on external APIs is that the initialization process of certificate-authenticated devices is changed, but there are no changes in other APIs. You only need to refer to the relevant demos to modify the `_setup_connect_init_params` function.
67+
68+
#### API changes for OTA update
69+
Starting from SDK v3.0.3, OTA update supports checkpoint restart. When the firmware download process is interrupted due to network exceptions or other issues, the downloaded part of the firmware can be saved, so that the download can start from where interrupted instead of from the beginning when it is resumed.
70+
After this new feature was supported, the methods of using relevant OTA APIs changed. If you have upgraded from v3.0.2 or below, you should modify your logic code; otherwise, firmware download will fail. For more information on how to modify it, please see **`samples/ota/ota_mqtt_sample.c`**.
71+
72+
#### Code name changes
73+
To improve the code readability and comply with the naming conventions, SDK v3.1.0 incorporated changes to certain variables, functions, and macro names. If you have upgraded from v3.0.3 or below, you can run the `tools/update_from_old_SDK.sh` script on Linux to replace the names in your own code, and then you can use the new version of the SDK directly.
74+
75+
| Old Name | New Name |
76+
| ------------------ | ------------------------------------------------------------ |
77+
| QCLOUD_ERR_SUCCESS | QCLOUD_RET_SUCCESS |
78+
| QCLOUD_ERR_MQTT_RECONNECTED | QCLOUD_RET_MQTT_RECONNECTED |
79+
| QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED | QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED |
80+
| QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED | QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED |
81+
| QCLOUD_ERR_MQTT_ALREADY_CONNECTED | QCLOUD_RET_MQTT_ALREADY_CONNECTED |
82+
| MAX_SIZE_OF_DEVICE_SERC | MAX_SIZE_OF_DEVICE_SECRET |
83+
| devCertFileName | dev_cert_file_name |
84+
| devPrivateKeyFileName | dev_key_file_name |
85+
| devSerc | device_secret |
86+
| MAX_SIZE_OF_PRODUCT_KEY | MAX_SIZE_OF_PRODUCT_SECRET |
87+
| product_key | product_secret |
88+
| DEBUG | eLOG_DEBUG |
89+
| INFO | eLOG_INFO |
90+
| WARN | eLOG_WARN |
91+
| ERROR | eLOG_ERROR |
92+
| DISABLE | eLOG_DISABLE |
93+
| Log_writter | IOT_Log_Gen |
94+
| qcloud_iot_dyn_reg_dev | IOT_DynReg_Device |
95+
| IOT_SYSTEM_GET_TIME | IOT_Get_SysTime |
96+
97+
```
98+
#! /bin/bash
99+
100+
sed -i "s/QCLOUD_ERR_SUCCESS/QCLOUD_RET_SUCCESS/g" `grep -rwl QCLOUD_ERR_SUCCESS ./*`
101+
sed -i "s/QCLOUD_ERR_MQTT_RECONNECTED/QCLOUD_RET_MQTT_RECONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_RECONNECTED ./*`
102+
sed -i "s/QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED/QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED ./*`
103+
sed -i "s/QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED/QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED/g" `grep -rwl QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED ./*`
104+
sed -i "s/QCLOUD_ERR_MQTT_ALREADY_CONNECTED/QCLOUD_RET_MQTT_ALREADY_CONNECTED/g" `grep -rwl QCLOUD_ERR_MQTT_ALREADY_CONNECTED ./*`
105+
sed -i "s/MAX_SIZE_OF_DEVICE_SERC/MAX_SIZE_OF_DEVICE_SECRET/g" `grep -rwl MAX_SIZE_OF_DEVICE_SERC ./*`
106+
sed -i "s/devCertFileName/dev_cert_file_name/g" `grep -rwl devCertFileName ./*`
107+
sed -i "s/devPrivateKeyFileName/dev_key_file_name/g" `grep -rwl devPrivateKeyFileName ./*`
108+
sed -i "s/devSerc/device_secret/g" `grep -rwl devSerc ./*`
109+
sed -i "s/MAX_SIZE_OF_PRODUCT_KEY/MAX_SIZE_OF_PRODUCT_SECRET/g" `grep -rwl MAX_SIZE_OF_PRODUCT_KEY ./*`
110+
sed -i "s/product_key/product_secret/g" `grep -rwl product_key ./*`
111+
sed -i "s/DEBUG/eLOG_DEBUG/g" `grep -rwl DEBUG ./*`
112+
sed -i "s/INFO/eLOG_INFO/g" `grep -rwl INFO ./*`
113+
sed -i "s/WARN/eLOG_WARN/g" `grep -rwl WARN ./*`
114+
sed -i "s/ERROR/eLOG_ERROR/g" `grep -rwl ERROR ./*`
115+
sed -i "s/DISABLE/eLOG_DISABLE/g" `grep -rwl DISABLE ./*`
116+
sed -i "s/Log_writter/IOT_Log_Gen/g" `grep -rwl Log_writter ./*`
117+
sed -i "s/qcloud_iot_dyn_reg_dev/IOT_DynReg_Device/g" `grep -rwl qcloud_iot_dyn_reg_dev ./*`
118+
sed -i "s/IOT_SYSTEM_GET_TIME/IOT_Get_SysTime/g" `grep -rwl IOT_SYSTEM_GET_TIME ./*`
119+
```

docs/C-SDK_API及可变参数说明.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ C-SDK 的使用可以根据具体场景需求,配置相应的参数,满足
5353
| 6 | IOT_MQTT_Unsubscribe | 取消订阅已订阅的 MQTT 主题 |
5454
| 7 | IOT_MQTT_IsConnected | 查看当前 MQTT 是否已连接 |
5555
| 8 | IOT_MQTT_IsSubReady | 查询对应的主题是否已经订阅成功 |
56-
| 9 | IOT_MQTT_GetDeviceInfo | 获取该 MQTTclien对应的设备信息 |
56+
| 9 | IOT_MQTT_GetDeviceInfo | 获取该 MQTTclient对应的设备信息 |
5757
| 10 | IOT_MQTT_StartLoop | 多线程环境下,启动 MQTTclient后台Yield线程 |
5858
| 11 | IOT_MQTT_StopLoop | 多线程环境下,停止 MQTTclient后台Yield线程 |
5959

@@ -99,7 +99,7 @@ MQTT构造时候除了提供设备信息,还需要提供一个回调函数,
9999
| 5 | IOT_COAP_GetMessageId | 获取 COAP Response 消息 msgId |
100100
| 6 | IOT_COAP_GetMessagePayload | 获取 COAP Response 消息内容 |
101101
| 7 | IOT_COAP_GetMessageCode | 获取 COAP Response 消息错误码 |
102-
| 9 | IOT_COAP_GetDeviceInfo | 获取该 COAPclien对应的设备信息 |
102+
| 9 | IOT_COAP_GetDeviceInfo | 获取该 COAPclient对应的设备信息 |
103103

104104
### OTA 接口
105105
关于 OTA 固件下载功能介绍,可以参考[设备固件升级](https://cloud.tencent.com/document/product/634/14674)

0 commit comments

Comments
 (0)