|
| 1 | +# How to Add New Device Types & Clusters |
| 2 | + |
| 3 | +This document outlines the process needed to add a new Matter device type and |
| 4 | +related clusters. Obviously, the steps below assume that the related Matter |
| 5 | +specifications were properly reviewed and approved. |
| 6 | + |
| 7 | +## Add the cluster definitions to the SDK |
| 8 | + |
| 9 | +The following steps should be followed to add new cluster definitions to the |
| 10 | +SDK. |
| 11 | + |
| 12 | +**Add your new cluster definition to an appropriately-name file in this |
| 13 | +directory:** |
| 14 | +[src/app/zap-templates/zcl/data-model/chip](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/chip) |
| 15 | + |
| 16 | +**Add references to each new cluster definition to these files:** |
| 17 | + |
| 18 | +1. [.github/workflows/tests.yaml](https://github.com/project-chip/connectedhomeip/tree/master/.github/workflows/tests.yaml) |
| 19 | +2. [scripts/rules.matterlint](https://github.com/project-chip/connectedhomeip/tree/master/scripts/rules.matterlint) |
| 20 | +3. [src/app/zap-templates/zcl/data-model/all.xml](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/all.xml) |
| 21 | +4. [src/app/zap-templates/zcl/zcl-with-test-extensions.json](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/zcl-with-test-extensions.json) |
| 22 | +5. [src/app/zap-templates/zcl/zcl.json](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/zcl.json) |
| 23 | +6. If it is a derived cluster, add a reference to the base cluster definition. |
| 24 | + (e.g. in mode-base-cluster.xml you may need to add cluster codes - otherwise |
| 25 | + you may get strange exceptions which aren't clear when running regen_all.py) |
| 26 | + |
| 27 | + > ``` |
| 28 | + > <struct name="ModeOptionStruct"> |
| 29 | + > <cluster code="0x0051"/> <!-- Laundry Washer Mode --> |
| 30 | + > <cluster code="YOUR NEW CLUSTER ID"/> |
| 31 | + > </struct> |
| 32 | + > ``` |
| 33 | +
|
| 34 | +7. [src/controller/python/chip/clusters/\_\_init\_\_.py](https://github.com/project-chip/connectedhomeip/tree/master/src/controller/python/chip/clusters/__init__.py) |
| 35 | +
|
| 36 | +**Enable your new cluster in the Python and Android clients** in |
| 37 | +[src/controller/data_model/controller-clusters.zap](https://github.com/project-chip/connectedhomeip/blob/master/src/controller/data_model/controller-clusters.zap) |
| 38 | +
|
| 39 | +You will need the ZAP tool to edit the ZAP file. |
| 40 | +
|
| 41 | +- Unless you already have the tool installed, you can use one of the |
| 42 | + [nightly builds](https://github.com/project-chip/zap/releases) |
| 43 | +- [ZAP tool info](https://developers.home.google.com/matter/tools/zap) |
| 44 | +- [ZAP tool repo](https://github.com/project-chip/zap) |
| 45 | +
|
| 46 | +Use the ZAP GUI tool to edit the file above: |
| 47 | +
|
| 48 | +1. From the command line, navigate to the directory containing |
| 49 | + [controller-clusters.zap](https://github.com/project-chip/connectedhomeip/blob/master/src/controller/data_model) |
| 50 | +2. Run zap: `../../../scripts/tools/zap/run_zaptool.sh controller-clusters.zap`. |
| 51 | + Alternatively, run the zap tool and navigate to the zap file that you wish to |
| 52 | + open, or run as |
| 53 | + `./scripts/tools/zap/run_zaptool.sh src/controller/data_model/controller-clusters.zap`. |
| 54 | +3. In the gui, select `Endpoint-1` from the left pane. |
| 55 | +4. Open the cluster group, for example, `Appliances`. |
| 56 | +5. Find the cluster to be enabled, e.g. `Dishwasher Control`. |
| 57 | +6. In the Enable column, select "Client" from the drop-down box. |
| 58 | +7. Click `File->Save` to save the configuration. |
| 59 | +8. Close the GUI. |
| 60 | +
|
| 61 | +**Add entries for your new cluster to |
| 62 | +[BUILD.gn](c/src/controller/data_model/BUILD.gn)** in the outputs section of the |
| 63 | +java-jni-generate bits. The entries should look like |
| 64 | +"jni/YourClusterNameClient-InvokeSubscribeImpl.cpp" and |
| 65 | +"jni/YourClusterNameClient-ReadImpl.cpp". |
| 66 | +
|
| 67 | +**Add an entry to the ClientDirectories** section of |
| 68 | +[src/app/zap_cluster_list.json](https://github.com/project-chip/connectedhomeip/blob/master/src/app/zap_cluster_list.json). |
| 69 | +
|
| 70 | +**Update `chip-tool`** |
| 71 | +
|
| 72 | +1. Regenerate all zap generated code using `./scripts/tools/zap_regen_all.py` |
| 73 | +2. Rebuild chip-tool and it will have new cluster support: |
| 74 | + `./scripts/examples/gn_build_example.sh examples/chip-tool SOME-PATH/` |
| 75 | +
|
| 76 | +## Add the device type definition to the SDK |
| 77 | +
|
| 78 | +1. Add the XML definition of the device to |
| 79 | + [matter-devices.xml](https://github.com/project-chip/connectedhomeip/blob/master/src/app/zap-templates/zcl/data-model/chip/matter-devices.xml) |
| 80 | +2. Implement the incoming command behaviors common to all applications. The |
| 81 | + parsing of the payload from TLV to a C++ struct is done by code |
| 82 | + auto-generated from the XML (see |
| 83 | + [zap-generated](https://github.com/project-chip/connectedhomeip/blob/master/zzz_generated/app-common/app-common/zap-generated)) |
| 84 | + The rest of the functionality must be manually implemented. Note: for the |
| 85 | + auto-generated code run one of the following: |
| 86 | + 1. for everything: `./scripts/tools/zap_regen_all.py` |
| 87 | + 2. just for the app-common part: |
| 88 | + `./scripts/tools/zap/generate.py -t src/app/common/templates/templates.json -o zzz_generated/app-common/app-common/zap-generated src/controller/data_model/controller-clusters.zap` |
| 89 | +3. Implement the read/write/storage operations for the attributes of any type, |
| 90 | + list, or struct which are not the global attributes present in all clusters. |
| 91 | + For example, there's no need to implement CommandList, AttributeList etc. For |
| 92 | + the attributes which are not list of struct type, the handling code is |
| 93 | + implemented generically so most likely no work is needed for them. |
| 94 | +4. Implement any attribute spec requirements that are common to all |
| 95 | + applications. For example: code to enforce specific ranges, code for handling |
| 96 | + the interactions between attributes etc. |
| 97 | +
|
| 98 | +## Implement Code and Tests |
| 99 | +
|
| 100 | +Implement the clusters, the example cluster server application and add the |
| 101 | +related SDK tests. |
| 102 | +
|
| 103 | +1. Implement new clusters here: |
| 104 | + [src/app/clusters](https://github.com/project-chip/connectedhomeip/tree/master/src/app/clusters) |
| 105 | +2. Implement tests here: |
| 106 | + [src/app/tests/suites](https://github.com/project-chip/connectedhomeip/tree/master/src/app/tests/suites) |
| 107 | +3. Implement the example cluster server application: |
| 108 | + 1. The YAML tests will run against this server |
| 109 | + 2. Depending on the clusters, there are two options: |
| 110 | + 1. Enable them in the all-clusters-app and use that as the example |
| 111 | + cluster server app. If choosing this option, consider adding an |
| 112 | + example application that has just the relevant clusters enabled; this |
| 113 | + part is a nice to have. |
| 114 | + 2. If the clusters have complicated global application requirements |
| 115 | + consider using a separate example app. see the door lock, bridge, TV, |
| 116 | + OTA clusters. |
| 117 | + 3. NOTES: If adding a new cluster derived from `mode-base` into |
| 118 | + [examples/all-clusters-app/](https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/) |
| 119 | + (Assume your new cluster is called `XZYMode`): |
| 120 | + 1. Create your new `xyz-mode-cluster.xml` in |
| 121 | + [src/app/zap-templates/zcl/data-model/chip](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/chip) |
| 122 | + (as above). Note that this is a much cut down cluster definition |
| 123 | + compared to normal clusters, since it derives from |
| 124 | + [mode-base-cluster.xml](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/chip/mode-base-cluster.xml). |
| 125 | + See |
| 126 | + [dishwasher-mode-cluster.xml](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/chip/dishwasher-mode-cluster.xml) |
| 127 | + as an example. Note you should review if you need the `StartUpMode` |
| 128 | + and `OnMode` attributes based on the spec. |
| 129 | + 2. Check that you have added your cluster code into |
| 130 | + [mode-base-cluster.xml](https://github.com/project-chip/connectedhomeip/tree/master/src/app/zap-templates/zcl/data-model/chip/mode-base-cluster.xml) |
| 131 | + 1. `<struct name="ModeTagStruct"> <cluster code="0xXXXX">` - replace |
| 132 | + `XXXX` with your cluster ID |
| 133 | + 2. `<struct name="ModeOptionStruct"> <cluster code="0xXXXX">` - |
| 134 | + replace `XXXX` with your cluster ID |
| 135 | + 3. `<bitmap name="Feature" type="bitmap32"> <cluster code="0xXXXX">` - |
| 136 | + replace `XXXX` with your cluster ID |
| 137 | + 3. Add your new Mode definitions in `xyz-mode.h`. In this header you |
| 138 | + define the modes / labels and tags. See |
| 139 | + [dishwasher-mode.h](https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h) |
| 140 | + as an example. |
| 141 | + 4. Add your new stub to instantiate the mode. See |
| 142 | + [dishwasher-mode.cpp](https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp) |
| 143 | + as an example. |
| 144 | + 5. In |
| 145 | + [examples/all-clusters-app/linux/main-common.cpp](https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/linux/main-common.cpp): |
| 146 | + 1. Add `#include "xyz-mode.h"` |
| 147 | + 2. In `ApplicationShutdown()`, add a call to your |
| 148 | + `Clusters::XYZMode::Shutdown();`. |
| 149 | + 6. In |
| 150 | + [examples/all-clusters-app/linux/BUILD.gn](https://github.com/project-chip/connectedhomeip/tree/master/examples/all-clusters-app/linux/BUILD.gn), |
| 151 | + add the `xyz-mode.cpp` file to the `sources` section. |
| 152 | + 7. In |
| 153 | + [src/app/common/templates/config-data.yaml](https://github.com/project-chip/connectedhomeip/blob/master/src/app/common/templates/config-data.yaml): |
| 154 | + 1. Add a `<XYZMode>::ModeTag` to the `EnumsNotUsedAsTypeInXML` |
| 155 | + section. |
| 156 | + 2. Add an `XYZ Mode` entry to the |
| 157 | + `CommandHandlerInterfaceOnlyClusters` section. |
| 158 | + 8. In |
| 159 | + [src/app/util/util.cpp](https://github.com/project-chip/connectedhomeip/blob/master/src/app/util/util.cpp), |
| 160 | + in the `// Cluster Init Functions...` section, add a void |
| 161 | + `MatterXYZModePluginServerInitCallback() {}` definition. |
| 162 | + 9. In |
| 163 | + [src/app/zap-templates/zcl/zcl-with-test-extensions.json](https://github.com/project-chip/connectedhomeip/blob/master/src/app/zap-templates/zcl/zcl-with-test-extensions.json): |
| 164 | + 1. Add the `xyz-mode-cluster.xml` to the `xmlFile` list |
| 165 | + 2. In the `attributeAccessInterfaceAttributes` entry, add your new |
| 166 | + entry |
| 167 | + `"XYZ Mode": [ "SupportedModes", "CurrentMode", "FeatureMap" ]` - |
| 168 | + this will mean ZAP won't generate code to handle these attributes |
| 169 | + 10. In |
| 170 | + [src/app/zap_cluster_list.json](https://github.com/project-chip/connectedhomeip/blob/master/src/app/zap_cluster_list.json): |
| 171 | + 1. Add your `XYZ_MODE_CLUSTER: []` to `ClientDirectories: { }` |
| 172 | + object |
| 173 | + 2. Add your `"XYZ_MODE_CLUSTER": ["mode-base-server"]` to |
| 174 | + `"ServerDirectories": { }` |
| 175 | + 4. The code under |
| 176 | + [src/app/tests/suites/certification](https://github.com/project-chip/connectedhomeip/blob/master/src/app/tests/suites/certification) |
| 177 | + for YAML or |
| 178 | + [src/python_testing](https://github.com/project-chip/connectedhomeip/tree/master/src/python_testing) |
| 179 | + for Python should ideally implement the test plan (section 4 below). |
| 180 | + 5. A test under |
| 181 | + [src/app/tests/suites](https://github.com/project-chip/connectedhomeip/blob/master/src/app/tests/suites) |
| 182 | + (not certification) can test anything, in addition to, or preceding the |
| 183 | + official YAML representing the official test plan. |
| 184 | +4. Add the test plan, using the templates below: |
| 185 | +
|
| 186 | + 1. [cluster_test_plan_template.adoc](https://github.com/CHIP-Specifications/chip-test-plans/blob/master/src/template/cluster_test_plan_template.adoc) |
| 187 | + 2. [test_plan_template.adoc](https://github.com/CHIP-Specifications/chip-test-plans/blob/master/src/template/test_plan_template.adoc) |
| 188 | +
|
| 189 | + Also, ask to be added to the private `csg-tt-test-plans` Slack channel. |
| 190 | +
|
| 191 | +5. Note: the CHIP-Tool reference client is generated from XML |
| 192 | +6. If applicable, add tests: |
| 193 | + 1. For relatively simple tests, add YAML tests here: |
| 194 | + [src/app/tests/suites/certification](https://github.com/project-chip/connectedhomeip/blob/master/src/app/tests/suites/certification). |
| 195 | + Remember to update this file: |
| 196 | + [src/app/tests/suites/certification/PICS.yaml](https://github.com/project-chip/connectedhomeip/blob/master/src/app/tests/suites/certification/PICS.yaml) |
| 197 | + 2. For more complex tests, add Python tests here: |
| 198 | + [src/python_testing](https://github.com/project-chip/connectedhomeip/tree/master/src/python_testing) |
| 199 | + 3. To add tests to CI, if applicable: |
| 200 | + 1. Add the Python tests here: |
| 201 | + [.github/workflows/tests.yaml](https://github.com/project-chip/connectedhomeip/tree/master/.github/workflows/tests.yaml). |
| 202 | + Remember to provide all arguments required for each Python script, |
| 203 | + such as the endpoint PIXIT. |
| 204 | + 2. Add the YAML tests by editing this file: |
| 205 | + [src/app/tests/suites/ciTests.json](https://github.com/project-chip/connectedhomeip/tree/master/src/app/tests/suites/ciTests.json) |
| 206 | + 1. Create a section ("MyDevice") which lists all YAML tests for your |
| 207 | + device |
| 208 | + 2. Add the section's name to the list of items named "collection" |
| 209 | + 3. Do a ZAP code regen: `./scripts/tools/zap_regen_all.py`. |
| 210 | +7. Add the device type spec to the test plan tools: |
| 211 | +
|
| 212 | + 1. [tools/device_type_requirements](https://github.com/CHIP-Specifications/chip-test-plans/tree/master/tools/device_type_requirements) |
| 213 | + 2. The file above is used by |
| 214 | + [src/app/tests/suites/certification/Test_TC_DESC_2_1.yaml](https://github.com/project-chip/connectedhomeip/blob/master/src/app/tests/suites/certification/Test_TC_DESC_2_1.yaml) |
| 215 | +
|
| 216 | + Note: the plan is to make the DM tools generate the device type requirements |
| 217 | + data based on the spec, so the above will become obsolete. |
| 218 | +
|
| 219 | +8. Add the device type to Chef: |
| 220 | + [examples/chef/devices](https://github.com/project-chip/connectedhomeip/tree/master/examples/chef/devices) |
| 221 | +
|
| 222 | +## Q & A |
| 223 | +
|
| 224 | +**Q1**: What kind of devices can be used for the test events? Can one of them be |
| 225 | +the example cluster server app running on a RasPI? Do the independent |
| 226 | +realizations need to run on vendor hardware or can they also run on generic |
| 227 | +hardware, such as ESP32 or RasPI? |
| 228 | +
|
| 229 | +**A1**: one realization can be the test harness + the all clusters example app + |
| 230 | +RasPI. the two independent realizations need to run on target hardware, which |
| 231 | +may be mock-ups, prototypes etc |
| 232 | +
|
| 233 | +**Q2**: How can the Chef tool be used for any of the deliverables above? |
| 234 | +
|
| 235 | +**A2**: TBD |
| 236 | +
|
| 237 | +**Q3**: What is the process for using the Zap tool in order to auto-generate |
| 238 | +code and to commit the results to the git repo? |
| 239 | +
|
| 240 | +**A3**: Search for zap_regen above. Add all the changed files to the repo after. |
| 241 | +
|
| 242 | +**Q4**: Where can the older cluster definitions be found? |
| 243 | +
|
| 244 | +**A4**: src/app/zap-templates/zcl/data-model/silabs/general.xml |
| 245 | +
|
| 246 | +**Q5**: Where can I find ZAP documentation? |
| 247 | +
|
| 248 | +**A5**: https://github.com/project-chip/zap/blob/master/README.md |
0 commit comments