当前位置:网站首页>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
边栏推荐
- What is the GPU usage for cloud desktops and servers? What can cloud desktop do?
- "Sharp weapon" for enterprise resumption? When the sale comes, the contract should be signed like this!
- What is the use of cloud desktop security server configuration? What should I do?
- How to register a trademark? Is the process troublesome?
- Why do cloud desktops use rack servers? Why choose cloud desktop?
- If the cloud knows that security is important
- QT creator tips
- Industrial security experts talk about how to build security protection capability for government big data platform?
- ClickHouse Buffer
- Velocitytracker use
猜你喜欢

Sorting out of key vulnerabilities identified by CMS in the peripheral management of red team (I)
![[51nod] 2102 or minus and](/img/68/0d966b0322ac1517dd2800234d386d.jpg)
[51nod] 2102 or minus and
![[summary of interview questions] zj5](/img/d8/ece82f8b2479adb948ba706f6f5039.jpg)
[summary of interview questions] zj5

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

Get to know MySQL database

Community pycharm installation visual database
![[51nod] 3216 Awards](/img/94/fdb32434d1343040d711c76568b281.jpg)
[51nod] 3216 Awards

QT creator tips

Ar 3D map technology

Simple and beautiful weather code
随机推荐
What is fortress resource authorization? What is barrier machine?
Why can't the fortress machine open the port? There is a problem with the use of the fortress machine port
The server size of the cloud desktop. The cloud desktop faces the server configuration requirements
The medical technology giant was blackmailed and Microsoft announced 74 security vulnerabilities | global network security hotspot
[51nod] 3216 Awards
Why do I need a code signing certificate? Where can I get a code signing certificate?
US Treasury secretary says extortion software poses a threat to the economy, Google warns 2billion chrome users | global network security hotspot
How does the fortress machine connect to the server? Which is easy to use, fortress machine or firewall?
Cloud desktop server resource planning, what are the advantages of cloud desktop
How does cloud computing achieve elastic scaling? What are the characteristics of elasticity?
How to select a server with appropriate configuration when planning to build a live broadcast platform
Cp/rm/mv parameters
Troubleshooting and resolution of errors in easycvr calling batch deletion interface
Why can't the fortress machine log in? What are the ways to solve the problem
What are the advantages of EIP? What is the relationship between EIP and fixed IP?
LeetCode 1047. Delete all adjacent duplicates in the string
Coding CD of Devops
Simple and beautiful weather code
Understanding Devops from the perspective of decision makers
What is the all-in-one backup machine? How about its cost performance