Dynamic modification method of ZCL information based on Zigbee SOC
By defining UART instructions and using NV RAM memory for dynamic management of ZCL information, the problem of firmware function limitations and complexity of Zigbee devices in ZCL protocol implementation is solved, and the flexible configuration and multi-functional support of the Zigbee SOC system are achieved.
Patent Information
- Application Number
- CN202410968660.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-19
AI Technical Summary
When existing Zigbee devices implement the ZCL protocol, the firmware function limitations of the single-chip SOC solution and the complexity and real-time issues of the third-party MCU combination solution result in a lack of flexibility and complexity in device functions and the inability to support all types of devices and multi-functions. design.
Create and modify ZCL information by defining UART instructions, including port information and attribute tables, use NV RAM memory for dynamic allocation and storage, realize the addition, deletion and modification of ZCL information, and interact with the Zigbee SOC system through a third-party MCU to simplify the ZCL protocol deal with.
It realizes the dynamic configuration and modification of ZCL information in the Zigbee SOC system, reduces firmware function restrictions, supports the simulation of multiple device types, simplifies the development difficulty of third-party MCUs, and improves the flexibility and functional strength of the device.
Smart Images

Figure CN118524162B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of communication technology, and in particular, relates to a method for dynamically modifying ZCL information based on Zigbee SOC. Background Art
[0002] Currently, there are two ways for Zigbee devices to implement the ZCL protocol: a single-chip SOC solution and a solution combining a Zigbee SOC chip and a third-party MCU.
[0003] The single-chip SOC solution is that the application of the Zigbee device runs on a SOC chip that supports the Zigbee protocol. Most Zigbee SOC chips are Harvard structures, and the storage space is divided into the Code area and the Data area. In most Zigbee SDKs, the ZCL attributes are directly allocated in the Code area in the form of a structure array. Since the ZCL attributes are stored in the Code area, they cannot be modified, including the number of ports supported by the Zigbee device, the total number of cluster lists supported by each port, and the number of ZCL attributes supported under each cluster. Since the value of the ZCL attribute is pointed to the fixed space in the Data area through the pointer in the Code area, the spatial location of the value of the ZCL attribute in the Data area cannot be modified.
[0004] When the Zigbee SOC has insufficient computing power or external resources, it is necessary to expand the MCU to support complex functions. The program functions provided in the SDK are simple, and very few products can be developed, which cannot cover all types of devices specified by the ZCL protocol. The device functions lack flexibility, and manufacturers who specialize in designing and manufacturing peripheral RF circuits for Zigbee SOC chips cannot design application layer firmware.
[0005] In the solution combining Zigbee SOC chip and third-party MCU, Zigbee SOC chip only supports the protocol support from the medium layer (Medium Access Control, referred to as MAC) to the APS layer, and the protocol processing and application of the ZCL layer (Zigbee ClusterLibrary, referred to as ZCL) are implemented on the external third-party chip. The processing mechanism of the ZCL protocol stack needs to be implemented in the external MCU, and the external MCU developers need to be familiar with the ZCL protocol design special program. Once a software bug occurs in the ZCL protocol development, it will have a greater impact; ZCL attributes are stored in the external MCU, and the real-time performance of operations such as reading, writing, and reporting ZCL attributes is not good. If the external MCU is abnormal and the Zigbee SOC runs well, the control end device will think that the Zigbee connection is normal when controlling the controlled end device, but no data is returned. Summary of the invention
[0006] In order to solve the above technical problems, the present invention provides a method for dynamically modifying ZCL information based on Zigbee SOC, comprising:
[0007] The Zigbee SOC system defines a UART instruction for creating a port; the UART instruction defines the port information, which includes the port number, profile ID, device ID, cluster list, and cumulative size of the ZCL attribute table;
[0008] When executing UART instructions, the Zigbee SOC system pre-allocates a temporary buffer for external input instructions, and at the same time allocates the space occupied by the ZCL attribute table to the temporary buffer according to the size of the ZCL attribute table;
[0009] The Zigbee SOC system defines a UART command for adding ZCL attribute data;
[0010] After creating a port and adding ZCL attribute tables for each cluster under the port, save the port and the port's ZCL attribute table to the NV RAM memory, and then release the temporary buffer;
[0011] Restart the Zigbee SOC system. The application of the Zigbee SOC system reads the port to be created and the ZCL attribute table to be added for the port from the NV RAM memory, and allocates continuous space in the Data area for the port and the ZCL attribute table of the port. At the same time, the RAM space in the Data area required for the ZCL attribute data is allocated according to the data type of each ZCL attribute in the ZCL attribute table.
[0012] The third-party MCU interacts with the Zigbee SOC system through UART commands;
[0013] When you need to modify the ZCL information definition, you must delete the defined ZCL information, including port information, ZCL attribute table and ZCL attribute data, and then restart the Zigbee device.
[0014] Based on the above technical solution, the present invention can also be improved as follows.
[0015] Further, the temporary buffer is a continuously allocated data cache area; the port space is continuously allocated, the ZCL attribute table is continuously allocated, and the ZCL attribute data space is continuously allocated.
[0016] Furthermore, the UART instruction for adding ZCL attributes only adds one ZCL attribute at a time. When adding ZCL attributes, the cluster IDs are from small to large, and the attribute IDs are from small to large. The ZCL attributes of the same cluster are placed at consecutive addresses. For operations that do not add ZCL attributes in sequence, the UART instruction for adding ZCL attributes returns a UART instruction that indicates that adding ZCL attributes is invalid.
[0017] Furthermore, the ZCL attribute includes a ZCL attribute cluster, a ZCL attribute ID, a ZCL attribute data type, and an operation mode supported by the ZCL attribute.
[0018] Further, the number of added ZCL attributes is less than or equal to the cumulative size of the ZCL attribute table preset when the port is created.
[0019] Furthermore, the Zigbee SOC system dynamically allocates the space required for the port information from the NVRAM according to the port information and the size of the port information in the NVRAM memory, copies the port information stored in the NVRAM storage to the allocated space, and then registers the dynamically allocated port information.
[0020] Further, the size of the NV RAM memory space occupied when the port and ZCL attribute table are stored in the NV RAM memory is the size occupied by the actually added ZCL attributes.
[0021] Further, the UART instruction reads and writes the value of the ZCL attribute in the Zigbee SOC system, reads and writes the data of the ZCL attribute by combining the port ID, cluster ID and ZCL attribute ID, limits the size of the write attribute data according to the data type of the ZCL attribute, returns an error reminder when reading and writing a non-existent ZCL attribute, and returns an error reminder when the size of the data written to the ZCL attribute exceeds the data type limit of the ZCL attribute;
[0022] When the value of the ZCL attribute data is modified using the UART command, the ZCL attribute automatic reporting mechanism in the SDK is used to trigger the active reporting of the ZCL attribute modification; the ZCL protocol layer program detects that the value of the ZCL attribute data has changed and the change exceeds the preset threshold, then triggers active reporting;
[0023] The Zigbee SOC system receives a write ZCL attribute instruction wirelessly sent by an external Zigbee device. When the instruction is valid, the Zigbee SOC system sends a UART command to the third-party MCU indicating that the ZCL attribute data has been modified, notifying the third-party MCU that the ZCL attribute data has been modified by the external Zigbee device.
[0024] Furthermore, after receiving the ZCL command sent by the external device, the Zigbee SOC system extracts the ZCL command ID and ZCL command parameters carried by the ZCL command, packages them into a UART control command and notifies the third-party MCU; the UART control command includes a receiving port, a command cluster ID, a command ID and command parameters.
[0025] The beneficial effects of the present invention are:
[0026] (1) The present invention can realize the addition, deletion and modification of ZCL information in the Zigbee SOC system, which is no longer limited by the firmware function, that is, there is no need to modify the firmware to enable the Zigbee SOC system to realize configuration;
[0027] (2) By modifying the ZCL information, the Zigbee SOC system can be recognized by other Zigbee devices as a device with corresponding application functions after being connected to the Zigbee network. The third-party MCU connected to the Zigbee SOC system does not need to design a complex ZCL protocol and can use a cheap MCU to implement the function.
[0028] (3) The present invention can realize the interaction of ZCL commands. The third-party MCU only focuses on processing the operations required by the ZCL control commands. It does not need to care who sends the control command or to whom the reply command is sent. It only needs to reply with its own processing results.
[0029] (4) Current Zigbee devices require specific firmware to be burned into the Zigbee SOC to realize device functions. The present invention only requires a unified firmware to be burned into the Zigbee SOC to simulate the control effects of different types of Zigbee devices, making the Zigbee SOC a standardized part, and cooperating with a third-party MCU with more powerful computing power to realize a more powerful Zigbee device. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 A schematic diagram of a method for dynamically modifying ZCL information based on Zigbee SOC provided in an embodiment of the present invention;
[0031] Figure 2 A schematic diagram of the operation location of the ZCL protocol;
[0032] Figure 3 This is the interactive operation flow chart of ZCL commands. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0034] As an example, Figure 1 As shown, in order to solve the above technical problems, this embodiment provides a method for dynamically modifying ZCL information based on Zigbee SOC, including:
[0035] The Zigbee SOC system defines a UART instruction for creating a port; the UART instruction defines the port information, which includes the port number, profile ID, device ID, cluster list, and cumulative size of the ZCL attribute table;
[0036] When executing UART instructions, the Zigbee SOC system pre-allocates a temporary buffer for external input instructions, and at the same time allocates the space occupied by the ZCL attribute table to the temporary buffer according to the size of the ZCL attribute table;
[0037] The Zigbee SOC system defines a UART command for adding ZCL attribute data;
[0038] After creating a port and adding ZCL attribute tables for each cluster under the port, save the port and the port's ZCL attribute table to the NV RAM memory, and then release the temporary buffer;
[0039] Restart the Zigbee SOC system. The application of the Zigbee SOC system reads the port to be created and the ZCL attribute table to be added for the port from the NV RAM memory, and allocates continuous space in the Data area for the port and the ZCL attribute table of the port. At the same time, the RAM space in the Data area required for the ZCL attribute data is allocated according to the data type of each ZCL attribute in the ZCL attribute table.
[0040] The third-party MCU interacts with the Zigbee SOC system through UART commands;
[0041] When you need to modify the ZCL information definition, you must delete the defined ZCL information, including port information, ZCL attribute table and ZCL attribute data, and then restart the Zigbee device. When you need to modify the ZCL information definition, you need to redefine the content in the ZCL information and no longer use the previously defined ZCL information.
[0042] The ZCL protocol is used for communication and interoperation between Zigbee devices and is located at the application layer of Zigbee devices. The ZCL protocol layer specifies the functions and operations of Zigbee devices. External Zigbee devices obtain the functions and status of Zigbee devices, as well as the operations that can be performed, by accessing the ZCL information of the Zigbee device.
[0043] In actual application, each Zigbee device has several ports. The ZCL protocol runs on the application and encapsulates the data so that each different application has a unified data format, namely the ZCL format.
[0044] In the application of Zzigbee protocol, each Zigbee node has several ports, and each port has corresponding application program instructions. ZCL protocol runs on the application program and encapsulates the data so that each different application corresponds to a unified data format, namely ZCL format. Figure 2 As shown in the figure, the block diagram shows the running position of the ZCL protocol. The ZCL protocol runs in the application object in the application framework layer in the figure, which represents an application in the ZigBee device. The more applications in the ZigBee device, the more functions it has. The application of the ZigBee device can choose whether to be compatible with the ZCL protocol. If the application of the ZigBee device is compatible with the ZCL protocol, it can be recognized and controlled by the other party when docking with other ZigBee devices.
[0045] The working mechanism of the network layer (Network), support layer (Application Support Sublayer, APS) and device object layer (ZDO) of the ZigBee protocol is defined by the ZigBee Alliance. The NWK layer is responsible for the relay and forwarding of ZigBee communications, the ZDO layer is responsible for the access network, device enumeration and identification of ZigBee devices, and the APS layer is used to support the application data communication of ZigBee devices. The APS layer can support multiple different applications for a ZigBee device, and each application will occupy a port. This mechanism enables a ZigBee device to support multiple different functions. The port in the ZigBee data communication can indicate which application of the device the data comes from and which application of the device the data goes to.
[0046] The working mechanism of the physical layer (PHY layer) and media layer of the ZigBee protocol is designed by the IEEE802.15.4 organization. The PHY layer defines the frequency band and modulation method of ZigBee, while the MAC layer is responsible for the most basic data transmission to ensure the stability of direct communication between two points.
[0047] In each port defined in the APS layer (Application Support Sublayer) of the Zigbee device, there is a unique profile ID to indicate the application scenario of the protocol, a unique device ID to indicate the device name, and several clusters to define the functions of the Zigbee device. Since a Zigbee device allows multiple ports and each port allows multiple clusters, a Zigbee device can implement multiple complex functions and integrate multiple identical or different sensors and external devices. Zigbee devices can also be identified as multifunctional devices after connecting to a Zigbee network that supports the ZCL protocol. The clusters under each port are also distinguished in the input and output lists. The clusters in the input list are called the server end, and the clusters in the output list are called the client end. The server end is controlled by other devices, and the client end actively controls other devices.
[0048] The ZCL layer is located between the application layer and the application framework layer. The ZCL layer is responsible for sending the application operations (such as turning on and off lights and reading and writing devices) to the application framework through interface call instructions, which are converted into ZigBee wireless data in the application framework and transmitted to the target device. After the ZigBee device receives the wireless data, it transmits it to the ZCL layer through the message queue in the application framework. In the ZCL layer, the wireless data is converted into callback instructions and sent to the application, allowing the application to perform the corresponding actions.
[0049] In the ZCL layer, each cluster is defined to have a corresponding ID number corresponding to the corresponding function. Each cluster has several ZCL attributes and several ZCL commands. The ZCL layer also defines ZCL frames, which are divided into general commands and proprietary commands.
[0050] The ZCL layer packages the wireless control of the application layer into ZCL frames and transmits them to the APS layer; the APS layer packages the ZCL frames into APS frames according to different applications and sends them to the NWK layer for data transmission; the NWK layer then passes the NWK frames to the MAC layer and packages them into MAC frames to execute the final wireless signal transmission.
[0051] The ZCL attribute is a fixed variable defined inside the Zigbee device, which is used to save the information and status of the Zigbee device. ZCL attributes include but are not limited to the following information of the Zigbee device: fixed information such as manufacturer name and software version, as well as physical quantities required for various applications such as light brightness, sensor detection value, alarm status, internal temperature and external temperature. Each ZCL attribute has its own fixed ID number under its own cluster, and a fixed data type is used to represent the byte size. Three operation modes are supported: reading, writing and active reporting. The general command frame is used to read, write and actively report ZCL attributes between Zigbee devices. A general command can simultaneously support the reading, writing and reporting of multiple attributes under the same cluster on the same port.
[0052] ZCL commands are used to control Zigbee devices, such as turning lights on and off, adjusting light brightness, adjusting the rotation of curtain motors and sensor data transmission, Zigbee device OTA upgrade file transmission... Each ZCL command has a fixed ID number, irregular command parameters and corresponding operation functions.
[0053] The present invention utilizes the ZCL protocol in the original SDK supporting the Zigbee SOC to reduce the difficulty of third-party MCU application development.
[0054] When creating a port, the port information is saved in the Data area and dynamically allocated. Modern Zigbee SOCs, whether based on the von Neumann structure or the Harvard structure, have unified addresses for the Code area and the Data area. At the same time, many Zigbee SOC SDKs will also allocate a portion of ROM from the Code area or use EEPROM to make NV RAM. The content of NV RAM can be modified during program execution and can also be saved when power is off.
[0055] Zigbee SOC writes the port and its profile ID, device ID, and cluster list required by the Zigbee application into NV RAM through an external bus (such as UART). Then, Zigbee SOC dynamically allocates the space required for the port information from RAM according to the port information and information size in NV RAM, and copies the port information saved in NV RAM to the allocated space, and then registers the dynamically allocated port information. This ensures that the APS layer of Zigbee SOC has the port information.
[0056] Initializing port information in NV RAM memory needs to be done when Zigbee SOC is not networked, so that other devices can determine the device type based on the port information of the Zigbee device when Zigbee SOC is networked for the first time. When initializing port information in NV RAM memory, multiple different ports can be initialized to allow Zigbee devices to support more functions; you can also initialize as many ports as possible according to the processing power of the external MCU, or add more clusters for each port.
[0057] In the prior art, the Zigbee SDK needs to define ZCL attributes in the program, and then associate the defined ZCL attributes with the corresponding port. In principle, the number of clusters on a port is such that the corresponding ZCL attributes must be managed on each cluster. ZCL attributes are usually defined in a continuous storage area (usually the Code area) in the form of a structure array, i.e., the ZCL attribute table, and each ZCL attribute also occupies a space in the Data area according to the defined data size (determined by the data type of the ZCL attribute), which is the ZCL attribute data.
[0058] The ZCL attribute table and ZCL attribute data are defined in the Data area of the Zigbee SOC system, that is, in the RAM. Since the RAM is lost when the power is off, the ZCL attribute table is first added to the NV RAM memory, and then the Zigbee SOC system is allowed to import it from the NV RAM memory to the RAM memory when it is booted. The RAM that stores the ZCL attribute table and ZCL attribute data is dynamically allocated. The address is allocated in advance each time the Zigbee SOC system is started. When the Zigbee SOC system runs the application in the future, the CPU accesses the ZCL attribute table and ZCL attribute data from a fixed storage area address. Since most of the ZCL attribute data does not need to be saved when the power is off, a small amount of NV RAM memory can be specially set to point to the ZCL attributes that need to be saved when the power is off, and the corresponding ZCL attribute data can be saved when the application is running.
[0059] The space occupied by the ZCL information of the Zigbee device is continuous, so when you need to modify the ZCL information definition, you must first delete all previously defined ZCL information, including port information, ZCL attribute table, and ZCL attribute data. Since the port information and ZCL attribute table are created in the NV RAM memory, as long as the records of the port information and ZCL attributes in the NV RAM memory are deleted and the Zigbee device is restarted, the ZCL information in the Zigbee device will be deleted, and the space occupied by the ZCL attribute data will not be created in the Data area.
[0060] In actual application, a fool-proof design is performed when deleting the port information records and ZCL attribute records in the NV RAM memory. The deletion operation must be performed when the Zigbee device is not networked.
[0061] After the Zigbee device creates the port and ZCL attributes, it joins the Zigbee network. The third-party MCU interacts with the Zigbee SOC system through UART instructions. UART instructions include the following functions:
[0062] (1) Read and write the value of a ZCL attribute in the Zigbee SOC system. Read and write the data of the ZCL attribute in the form of port ID + cluster ID + ZCL attribute ID. At the same time, the size of the attribute data to be written needs to be limited according to the data type of the ZCL attribute. When reading and writing a non-existent ZCL attribute, the UART instruction returns an error reminder. When the data size of a ZCL attribute written exceeds the data type limit of the ZCL attribute, an error reminder is also returned.
[0063] (2) For ZCL attributes that support active reporting, the value of the ZCL attribute data is modified using UART instructions, triggering active reporting. This mechanism can be implemented using the ZCL attribute automatic reporting mechanism built into the SDK. Usually, the ZCL protocol layer program detects that the ZCL attribute data value has changed and the change exceeds the preset threshold, triggering active reporting;
[0064] (3) The Zigbee SOC system receives the general command "write ZCL attribute" sent wirelessly by other Zigbee devices, and the command is valid. The Zigbee SOC system sends a UART command to the third-party MCU indicating that the ZCL attribute data has been modified, so as to notify the third-party MCU that the ZCL attribute data has been modified by other Zigbee devices.
[0065] For interactive operations of ZCL commands, UART commands directly carry ZCL command ID and ZCL command parameters. After receiving the ZCL command sent by other devices, the Zigbee SOC system extracts the command ID and command parameters of the command, packages them into the UART command and notifies the third-party MCU. The UART command, as a ZCL control command, contains the receiving port, command cluster ID, command ID and command parameters. The third-party MCU performs corresponding operations according to the ZCL control command, such as using PWM signals to adjust the brightness of external LEDs and control the rotation of curtain motors.
[0066] In the ZCL protocol specification, the control device usually sends the server-to-client ZCL command to the controlled device. This type of command is called a request command. After the controlled device completes the operation, it replies to the control device with the ZCL command. This type of command is called a response command. The ZCL protocol also specifies a general command called a default response, which can replace the response command in the ZCL command and reply to the corresponding request command according to the frame number that matches the request command. Figure 3 As shown in the figure, when the Zigbee SOC system receives a ZCL command, it caches the frame number and command ID of the ZCL command, and then notifies the third-party MCU of the ZCL control command. The third-party MCU needs to return the corresponding UART command, namely the ZCL response command, after executing the ZCL control command. The ZCL response command sent only needs to correspond to the corresponding ZCL control command. Therefore, the ZCL control command output by the Zigbee SOC system to the third-party MCU must also include a command serial number, which is used to mark the cached address when the Zigbee SOC system receives the ZCL request command. If the third-party MCU sends a ZCL response command to the Zigbee SOC system and matches the correct command serial number, the request command cached by the Zigbee SOC system is released, and the Zigbee SOC system replies with a ZCL response command to the Zigbee device that sent the request. If the third-party MCU does not reply to the ZCL response command to the Zigbee SOC system, the Zigbee SOC will automatically send a default response command to the other party's Zigbee device after a timeout period (such as 1 second or 2 seconds), and mark the command as an unsupported ZCL command.
[0067] Optionally, the temporary buffer is a contiguously allocated data cache; the port space is contiguously allocated, the ZCL attribute table is contiguously allocated, and the ZCL attribute data space is contiguously allocated.
[0068] When executing UART instructions, the Zigbee SOC system pre-allocates a temporary buffer for the port information. At the same time, the space occupied by the attribute table is also allocated to the buffer according to the size of the attribute table. The temporary buffer for the port information and the attribute table is a continuously allocated data, which can be deleted or cleared at power-off.
[0069] Since the size of the cluster list, ZCL attribute table, and ZCL attribute data space of each port are flexible and variable, the port space is continuously allocated, the ZCL attribute table is continuously allocated, and the ZCL attribute data space is continuously allocated. In the device, according to the number of registered ports, the number of ZCL attributes registered under each port, and the total space occupied by each ZCL attribute, a buffer area in RAM is pre-allocated. This buffer is first used to save all port information. Each port has its own outline address and device address, that is, the name of the application and a cluster list of different sizes. The clusters in the cluster list represent the functions supported by the application; then the buffer is allocated to the ZCL attributes under each port. The space occupied by a single ZCL attribute is fixed, including: affiliated port, affiliated cluster, data type (data space size) and data cache address. The space occupied by the ZCL attribute table is continuous. The attributes of the same port and the same cluster are arranged adjacently from small to large according to the attribute number (attribute ID). The attributes of different clusters under the same port are arranged adjacently from small to large according to the cluster ID, and the affiliated port IDs are arranged adjacently from small to large. Finally, according to the data space occupied by each ZCL attribute in the buffer area, the data space is allocated to each ZCL attribute from the remaining buffer in turn. Since the ZCL attributes are arranged in the order of the affiliated port ID in the ZCL attribute area of the buffer, the data space allocated to the ZCL attributes in the buffer will also be arranged in the order of the port ID.
[0070] Optionally, the UART instruction for adding ZCL attributes only adds one ZCL attribute at a time. When adding ZCL attributes, the cluster ID is from small to large, and the attribute ID is from small to large. The ZCL attributes of the same cluster are placed at consecutive addresses; for operations that add ZCL attributes out of sequence, the UART instruction for adding ZCL attributes returns a UART instruction indicating that adding ZCL attributes is invalid.
[0071] Optionally, the ZCL attribute includes a ZCL attribute cluster, a ZCL attribute ID, a ZCL attribute data type, and an operation mode supported by the ZCL attribute.
[0072] Optionally, the number of added ZCL attributes is less than or equal to the cumulative size of the ZCL attribute table preset when the port is created.
[0073] Optionally, the Zigbee SOC system dynamically allocates space required for port information from the NVRAM according to the port information and port information size in the NVRAM memory, copies the port information stored in the NVRAM storage to the allocated space, and then registers the dynamically allocated port information.
[0074] Optionally, the size of the NV RAM memory space occupied by the port and ZCL attribute table when stored in the NV RAM memory is the size occupied by the actually added ZCL attributes.
[0075] After creating a port and adding the required ZCL attribute table for the cluster under the port, save the port and its ZCL attribute table to the NV RAM memory, and then release the temporary buffer. The size of the NV RAM memory space occupied when the port and ZCL attribute table are saved in the NV RAM memory should be based on the size of the ZCL attributes actually added, rather than the cumulative size of the ZCL attribute table planned to be required when creating the port. At this time, repeat the steps of creating a port and adding ZCL attribute data, create a new port and add the required ZCL attribute table to it, and then repeat the creation of the port to save the port and ZCL attributes in the NV RAM memory.
[0076] The RAM space allocated for ports, ZCL attribute tables, and ZCL attribute data is allocated from the time the Zigbee SOC system program is initialized and is never released.
[0077] For SDKs that use the continuous heap solution, the port and attribute table can be directly read from the NV RAM storage and space can be allocated when the program is initialized; while for SDKs that use the discrete heap solution, the dynamically allocated memory space is limited, and a separate area is defined in the redundant Data area to store the port, ZCL attribute table and ZCL attribute data. The size of this separately defined area determines the maximum number of ports, the maximum number of ZCL attributes and the maximum size of ZCL attribute data supported by the Zigbee device.
[0078] Optionally, the UART instruction reads and writes the value of the ZCL attribute in the Zigbee SOC system, reads and writes the data of the ZCL attribute by combining the port ID, cluster ID and ZCL attribute ID, limits the size of the write attribute data according to the data type of the ZCL attribute, returns an error reminder when reading and writing a non-existent ZCL attribute, and returns an error reminder when the size of the data written to the ZCL attribute exceeds the data type limit of the ZCL attribute.
[0079] When the value of the ZCL attribute data is modified using the UART command, the ZCL attribute automatic reporting mechanism in the SDK is used to trigger the active reporting of the ZCL attribute modification; the ZCL protocol layer program detects that the value of the ZCL attribute data has changed and the change exceeds the preset threshold, then triggers active reporting;
[0080] The Zigbee SOC system receives a write ZCL attribute instruction wirelessly sent by an external Zigbee device. When the instruction is valid, the Zigbee SOC system sends a UART command to the third-party MCU indicating that the ZCL attribute data has been modified, notifying the third-party MCU that the ZCL attribute data has been modified by the external Zigbee device.
[0081] Optionally, after receiving the ZCL command sent by the external device, the Zigbee SOC system extracts the ZCL command ID and ZCL command parameters carried by the ZCL command, packages them into a UART control command and notifies the third-party MCU; the UART control command includes a receiving port, a command cluster ID, a command ID and command parameters.
[0082] This design method can configure the Zigbee SOC system without modifying the firmware. At the same time, the third-party MCU connected to the Zigbee SOC system does not need to design a complex ZCL protocol, and a cheap MCU can be used to implement the function.
[0083] When configuring the ports and ZCL properties in the Zigbee SOC system, connect the Zigbee SOC system to a PC and use the PC software to initialize the ports and ZCL properties supported by the Zigbee SOC system. In actual applications, the ZCL information in the Zigbee SOC system can be directly configured according to the latest ZCL protocol specification.
[0084] After the Zigbee SOC system completes the ZCL information configuration, it is connected to the third-party MCU to realize the functions of the Zigbee device. The third-party MCU is only responsible for interacting with the Zigbee SOC system and only processes the ZCL commands that need to be processed. It does not need to care who sent the ZCL command and who needs to reply to it, which greatly simplifies the operation of the third-party MCU, and the third-party MCU can focus on the operation of the application.
[0085] As an optional implementation, the Zigbee SOC system is configured as a dimmable lamp. First, a port that complies with the Zigbee HA specification is created. The device type of the port is a dimmable lamp. Then, the clusters and ZCL attributes required by the dimmable lamp are added to the port. After the Zigbee SOC system is connected to the Zigbee network, it will first be identified as a dimmable lamp by the Zigbee gateway. Then, after receiving the dimming command, the Zigbee SOC system only extracts the command ID and target brightness in the dimming command for use by the third-party MCU. The third-party MCU executes the corresponding PWM output according to the dimming command, and replies to the Zigbee SOC system with the execution result after the execution is completed. The Zigbee SOC system automatically replies the response of the command to the Zigbee device that initiated the dimming command. At the same time, the third-party MCU also needs to use the UART read and write attribute command to modify the ZCL attribute data used to represent the current dimming lamp brightness in the Zigbee SOC system so that the data is consistent with the output PWM signal. Other Zigbee devices in the Zigbee network obtain the PWM signal value currently output by the third-party MCU by accessing the ZCL attribute used to represent the current dimming lamp brightness in the Zigbee SOC system.
[0086] As an optional implementation, a Zigbee SOC system is configured as a Zigbee electric curtain. First, a ZCL-standard electric curtain port is created and the required clusters and ZCL attributes are added to it, and then it is connected to the Zigbee network. When the Zigbee SOC receives the ZCL command to open or close the curtain from the gateway or curtain remote control, it notifies the curtain motor MCU in the form of a ZCL request command (UART command), and the curtain motor MCU controls the rotation of the curtain motor. During the operation of the curtain motor, the curtain motor MCU writes the real-time position of the motor into the ZCL attribute representing the electric curtain travel in the Zigbee SOC system. During this process, the Zigbee SOC triggers the ZCL attribute reporting and reports it to the gateway or curtain remote control in real time. If an external force is used to pull the electric curtain, the curtain motor MCU also needs to write the real-time position of the motor into the ZCL attribute, and the Zigbee SOC system can also report the value of the ZCL attribute to the gateway or remote control.
[0087] The present invention can realize the addition, deletion and modification of ZCL information in the Zigbee SOC system, and is no longer limited by firmware functions. By modifying the ZCL information, the Zigbee SOC system can be recognized as a device with corresponding application functions by other Zigbee devices after being connected to the Zigbee network.
[0088] The present invention can realize the interaction of ZCL commands. The third-party MCU only focuses on processing the operations required by the ZCL control commands. It does not need to care who sends the control commands and to whom the reply commands are sent. It only needs to reply to its own processing results.
[0089] The current Zigbee devices require specific firmware to be burned into the Zigbee SOC to realize the device functions. The present invention only needs to burn a unified firmware into the Zigbee SOC to simulate the control effects of different types of Zigbee devices, making the Zigbee SOC a standardized part, and cooperating with a third-party MCU with more powerful computing power to realize a more powerful Zigbee device.
[0090] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for dynamically modifying ZCL information based on Zigbee SOC, characterized in that: include: The Zigbee SOC system defines a UART instruction for creating a port; The UART instruction defines the port information, which includes the port number, profile ID, device ID, cluster list and ZCL attribute table cumulative size; When executing UART instructions, the Zigbee SOC system pre-allocates a temporary buffer for external input instructions, and at the same time allocates the space occupied by the ZCL attribute table to the temporary buffer according to the size of the ZCL attribute table; The Zigbee SOC system defines a UART command for adding ZCL attribute data; After creating a port and adding ZCL attribute tables for each cluster under the port, save the port and the port's ZCL attribute table to the NV RAM memory, and then release the temporary buffer; Restart the Zigbee SOC system. The application of the Zigbee SOC system reads the port to be created and the ZCL attribute table to be added for the port from the NV RAM memory, and allocates continuous space in the Data area for the port and the ZCL attribute table of the port. At the same time, the RAM space in the Data area required for the ZCL attribute data is allocated according to the data type of each ZCL attribute in the ZCL attribute table. The third-party MCU interacts with the Zigbee SOC system through UART commands; When you need to modify the ZCL information definition, you must delete the defined ZCL information, including port information, ZCL attribute table and ZCL attribute data, and then restart the Zigbee device.
2. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The temporary buffer is a contiguously allocated data cache; the port space is contiguously allocated, the ZCL attribute table is contiguously allocated, and the ZCL attribute data space is contiguously allocated.
3. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The UART instruction for adding ZCL attributes only adds one ZCL attribute at a time. When adding ZCL attributes, the cluster ID is from small to large, and the attribute ID is from small to large. The ZCL attributes of the same cluster are placed at consecutive addresses. For operations that do not add ZCL attributes in sequence, the UART instruction for adding ZCL attributes returns a UART instruction indicating that adding ZCL attributes is invalid.
4. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The ZCL attribute includes the ZCL attribute cluster, ZCL attribute ID, ZCL attribute data type, and the operation mode supported by the ZCL attribute.
5. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The number of added ZCL attributes is less than or equal to the cumulative size of the ZCL attribute table that is preset when the port is created.
6. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The Zigbee SOC system dynamically allocates the space required for the port information from the NV RAM according to the port information and port information size in the NV RAM memory, copies the port information stored in the NV RAM storage to the allocated space, and then registers the dynamically allocated port information.
7. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The size of the NV RAM memory space occupied by the port and ZCL attribute table when it is saved in the NV RAM memory is the size occupied by the actual added ZCL attributes.
8. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: The UART instruction reads and writes the value of the ZCL attribute in the Zigbee SOC system. The data of the ZCL attribute is read and written by combining the port ID, cluster ID and ZCL attribute ID. The size of the attribute data to be written is limited according to the data type of the ZCL attribute. When reading and writing a non-existent ZCL attribute, the UART instruction returns an error reminder, and when the data size of the ZCL attribute to be written exceeds the data type limit of the ZCL attribute, an error reminder is returned; When the value of the ZCL attribute data is modified using the UART command, the ZCL attribute automatic reporting mechanism built into the SDK is used to trigger the active reporting of the ZCL attribute modification; The ZCL protocol layer program triggers active reporting when it detects that the ZCL attribute data value has changed and the change amount exceeds the preset threshold; The Zigbee SOC system receives a write ZCL attribute instruction wirelessly sent by an external Zigbee device. When the instruction is valid, the Zigbee SOC system sends a UART command to the third-party MCU indicating that the ZCL attribute data has been modified, notifying the third-party MCU that the ZCL attribute data has been modified by the external Zigbee device.
9. The method for dynamically modifying ZCL information based on Zigbee SOC according to claim 1, characterized in that: After receiving the ZCL command sent by the external device, the ZigbeeSOC system extracts the ZCL command ID and ZCL command parameters carried by the ZCL command, packages them into the UART control command and notifies the third-party MCU; the UART control command includes the receiving port, command cluster ID, command ID and command parameters.
