当前位置:网站首页>13. Tencent cloud IOT device side learning - data template function and Implementation
13. Tencent cloud IOT device side learning - data template function and Implementation
2022-06-24 03:26:00 【fancyxu】
The main purpose of this series is to record the learning notes of Tencent cloud Internet of things device , And on the device side SDK Make a supplementary explanation .
brief introduction
The concepts related to data templates and message formats have been introduced in previous articles , No more details here , Please see the Data template
The data template is designed as follows :
Design thinking
According to data template protocol , It is divided into 5 File :
- data_template_mqtt.c: Realization mqtt Related functions , Such as subscription , Unsubscribe , Release etc. .
- data_template_client.c: Realize external API Interface
- data_template_property.c: Including attribute downlink and uplink processing
- data_template_event.c: Including event downlink and uplink processing
- data_template_action.c: It includes the downstream and upstream processing of the behavior
Uplink message
Mainly through publish Send , I won't elaborate here . Among them, the attribute will involve a variety of uplink messages , Here you can go through Joint type To unify the interface :
typedef union {
const char *json;
int code;
struct {
int code;
UtilsJsonValue client_token;
} control_reply;
} PropertyPublishParams;Downlink message
among , Each is different topic(property/event/action) Will register a context Used as a context for managing downlink messages , The design is as follows :
typedef struct {
union {
PropertyMessageCallback property_callback;
EventMessageCallback event_callback;
ActionMessageCallback action_callback;
};
void *usr_data;
} DataTemplateContext;It mainly includes the corresponding callback and the user data to be used for the callback , It's used here Joint type , Thus, too many formal parameter types are avoided .
Memory optimization
Version before refactoring , In the use of , Because every time json Parsing all Dynamic applications To pass nodes , For resource constrained devices, it will bring great memory consumption and development difficulties .
Compared to the version before refactoring , This version is mainly for json The library has been transformed , When the corresponding message is delivered to the upper layer , use The pointer + length Instead of the previous Dynamic applications The way , This reduces memory . Here's why :
- Practical application , Most of the messages are consumed in the callback , So you can use mqtt The storage space of the package itself
- When processing string data , at present CI The tool recommends using safety functions such as (strncpy etc. ), So use The pointer + length More convenient
- The data retained after the callback is over should be handed over to the user for processing , instead of sdk Internal application to release , thus Reduce the risk of memory leaks
Please refer to utils_json_value_get
边栏推荐
- QT creator tips
- Gigabyte was attacked by blackmail software, and the FBI banned the hacker organization Revil | global network security hotspot
- Disaster recovery series (V) -- database disaster recovery construction
- What is distributed configuration center Nacos? What are the functions of distributed configuration center Nacos?
- Self built DNS to realize the automatic intranet resolution of tke cluster apiserver domain name
- How to use elastic scaling in cloud computing? What are the functions?
- Grpc: how to implement the restful API for file uploading?
- Windowsvpn client is coveted by vulnerabilities, 53% of companies face supply chain attacks | global network security hotspot
- How to register a trademark? Is the process troublesome?
- Ner's past, present and future Overview - past
猜你喜欢

Sorting out of key vulnerabilities identified by CMS in the peripheral management of red team (I)

On Sunday, I rolled up the uni app "uview excellent UI framework"

Ar 3D map technology

Community pycharm installation visual database

Simple and beautiful weather code
![[51nod] 3216 Awards](/img/94/fdb32434d1343040d711c76568b281.jpg)
[51nod] 3216 Awards
![[51nod] 2102 or minus and](/img/68/0d966b0322ac1517dd2800234d386d.jpg)
[51nod] 2102 or minus and

QT creator tips
![[summary of interview questions] zj5](/img/d8/ece82f8b2479adb948ba706f6f5039.jpg)
[summary of interview questions] zj5

Get to know MySQL database
随机推荐
Self built DNS to realize the automatic intranet resolution of tke cluster apiserver domain name
Interpreting Tencent cloud product experience through user experience elements
How to use elastic scaling in cloud computing? What are the functions?
How to register a trademark? What needs to be prepared?
JMeter uses JDBC to perform database pressure test
What are the functions of Fortress machine equipment
What is elastic scaling in cloud computing? What are the main applications of elastic scaling in cloud computing?
Double 11 will arrive soon. Is your website ready?
Ner's past, present and future Overview - past
What are the security guarantees for cloud desktop servers? What are the cloud desktop server platforms?
"Sharp weapon" for enterprise resumption? When the sale comes, the contract should be signed like this!
What does cloud desktop mean? What are the characteristics of cloud desktop?
An example of SPM manual binding execution plan
[summary of interview questions] zj5
What technology does cloud computing elasticity scale? What are the advantages of elastic scaling in cloud computing?
Why can't cloud games connect to the server? What if the cloud game fails to connect to the server?
Tencent Mu Lei: real scene 3D linking industrial Internet and consumer Internet
Grpc: how to add API Prometheus monitoring interceptors / Middleware?
LeetCode 1047. Delete all adjacent duplicates in the string
Ligature in font design