Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version of the Descriptor cluster #5020

Merged
merged 11 commits into from
Apr 9, 2021

Conversation

vivien-apple
Copy link
Contributor

Problem

The Descriptor cluster is not implemented in CHIP. The Descriptor cluster is meant to replace ZDO for the discovery of endpoints and clusters on a target node.

This PR introduce a first version of the Descriptor cluster with basic support for List[T] in the attributes store.

This PR contains the Descriptor cluster source code into src/app/clusters/descriptor. As a result the attributes are defined during the setup phase of the cluster.
I first did an initial version where the values of the attributes were statically defined when ZAP generates the file. It brings some size optimisations to the amount of memory consumes by the global attribute array but it may be hard to fit this model for the Bridge cluster.
I think we may still want to do that for devices with low capacity thought. So maybe a different PR could fix the ZAP tool, to optimise the data if the Bridge cluster is not activated.

Also this PR contains some basic support for List[T]. The tricky part was to get T to work with the current attribute code since this one expects T to be one of the defined basic ZCL types (e.g INT8U).
At the moment the current code support List[BASIC_TYPE] and List[Struct]. It does not yet support nested List. I have started to dig into it with the ACLcluster (intosrc/app/zap-templates/zcl/acl-cluster.xml`) but it it not fully done yet.

Finally, this PR needs to come up with a patch into the ZAP repo (PR # to come).

Summary of Changes

  • Add the definition of the Descriptor cluster into src/app/zap-templates/zcl/descriptor-cluster.xml
  • Add the definition of the ACL cluster into src/app/zap-templates/zcl/acl-cluster.xml
  • Add src/app/clusters/descriptor
  • Enable the descriptor server side into all-clusters-app.zap
  • Enable the descriptor server side into controller-clusters.zap
  • Enable the descriptor client side into chip-tool.zap
  • Add a template to encode/decode List[T] attribute

<code>0xF003</code>
<define>DESCRIPTOR_CLUSTER</define>
<description>The Descriptor Cluster is meant to replace the support from the Zigbee Device Object (ZDO) for describing a node, its endpoints and clusters.</description>
<attribute side="server" code="0x0000" define="DEVICE" type="ARRAY" entryType="DeviceType" length="254" writable="false" optional="false">device</attribute>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other way to represent list other than type "ARRAY" to not use fixed length? The spec says the list should have one or more elements, why we set the length to 254 not other number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other way to represent list other than type "ARRAY" to not use fixed length? The spec says the list should have one or more elements, why we set the length to 254 not other number?

I agree this is confusing, but the length argument here does not represent the size of the list, but the length in bytes of the related attribute.

In ZAP this argument is used for 2 things.

The first one is to generate the GENERATED_DEFAULTS macro and store potential defaults for the attribute. In this case, it is basically unused, but at some point we could likely generate it directly for simple accessories and it may save some spaces.

The second case where it is used is to set the EmberAfAttributeMetadata size field. This field is then used to allocate some spaces in the generatedData global array, that will be used to store the attribute value itself.

I end up using 254 since this is the maximum value authorised in EmberAfAttributeMedata currently, as it is a uint8_t. But the actual length of the list is stored in the first 2 bytes of the attribute value in this patch and is retrieved as an uint16_t.

The good thing about the current mechanism, where the length in bytes of attributes is defined ahead of time, is that you know how much space you need to store the attributes. The bad thing, is that it makes it harder for things such as list where the number of elements may vary.

I guess at some point we would have to look more deeper into the code that deals with attributes in the current ZCL stack...

@vivien-apple
Copy link
Contributor Author

FTR, this PR needs project-chip/zap#114 to land in order to work properly.

@andy31415
Copy link
Contributor

@vivien-apple - could you fix merge errors (likely regenerate stuff)?

it would be nice to have this within this week - probably TE1 cannot directly use it, but it still seems a good thing to have very early to iterate upon.

@CLAassistant
Copy link

CLAassistant commented Mar 4, 2021

CLA assistant check
All committers have signed the CLA.

@woody-apple
Copy link
Contributor

ping @vivien-apple

// The Descriptor Cluster instance on Endpoint 0 (zero) SHALL have a Parts attribute that lists all endpoint instances on a
// node instance.
// All local endpoints required by the device type(s) in the Device attribute SHALL be included in the Parts list.
if (endpoint == 0x00 || (emberAfDeviceIdFromIndex(endpoint) == emberAfDeviceIdFromIndex(endpointIndex)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite following that second condition. You can have multiple same-type devices on the node, and devices don't span endpoints...

This hierarchical endpoint relationship will need to be expressed in the app config (i.e. the .zap file) and get spit out by codegen somewhere; I don't think our current generated code representes it. Please file a followup issue to do that?

@vivien-apple
Copy link
Contributor Author

ping @vivien-apple

Sorry. I'm still waiting on project-chip/zap#114 to be reviewed and landed before rebasing. This PR can not land without it as it will break the tree otherwise :/

@pullapprove pullapprove bot requested a review from Damian-Nordic March 10, 2021 20:29
@woody-apple woody-apple requested a review from dhrishi April 8, 2021 00:19
@vivien-apple vivien-apple force-pushed the DescriptorCluster_v1 branch from 8e9ab5c to 6af9d6e Compare April 8, 2021 09:19
examples/chip-tool/templates/commands.zapt Outdated Show resolved Hide resolved
Comment on lines 116 to 115
static void On{{asCamelCased parent.name false}}{{asCamelCased name false}}ListAttributeResponse(void * context, uint16_t count, _{{type}} * entries)
{{else}}
static void On{{asCamelCased parent.name false}}{{asCamelCased name false}}ListAttributeResponse(void * context, uint16_t count, {{chipType}} * entries)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a followup: we should strongly consider making the arg a Span<whatever-type>....

examples/chip-tool/templates/commands.zapt Show resolved Hide resolved
src/app/clusters/descriptor/descriptor.cpp Outdated Show resolved Hide resolved
src/app/util/attribute-storage.cpp Show resolved Hide resolved
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with the remaining suggestions applied.

src/app/clusters/descriptor/descriptor.cpp Outdated Show resolved Hide resolved
src/app/clusters/descriptor/descriptor.cpp Outdated Show resolved Hide resolved
src/app/util/af.h Outdated Show resolved Hide resolved
src/app/util/af.h Show resolved Hide resolved
src/app/util/af.h Show resolved Hide resolved
src/app/util/attribute-storage.cpp Outdated Show resolved Hide resolved
examples/chip-tool/templates/commands.zapt Outdated Show resolved Hide resolved
src/app/util/af.h Outdated Show resolved Hide resolved
@vivien-apple vivien-apple force-pushed the DescriptorCluster_v1 branch from f17ba9b to cfa1db0 Compare April 9, 2021 18:37
@github-actions
Copy link

github-actions bot commented Apr 9, 2021

Size increase report for "esp32-example-build" from 524bafa

File Section File VM
chip-all-clusters-app.elf .flash.text 1648 1648
chip-all-clusters-app.elf .flash.rodata 1296 1296
chip-all-clusters-app.elf .dram0.bss 0 1016
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-pigweed-app.elf and ./pull_artifact/chip-pigweed-app.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,30791
.debug_line,0,13234
.debug_loc,0,4651
.debug_abbrev,0,3022
.debug_str,0,1858
.flash.text,1648,1648
.flash.rodata,1296,1296
.dram0.bss,1016,0
.strtab,0,543
.debug_frame,0,464
.debug_ranges,0,360
.symtab,0,304
.debug_aranges,0,184
.shstrtab,0,1
[Unmapped],0,-1296


@github-actions
Copy link

github-actions bot commented Apr 9, 2021

Size increase report for "nrfconnect-example-build" from 524bafa

File Section File VM
chip-lighting.elf text 208 208
chip-lighting.elf rodata 48 52
chip-lock.elf text 208 208
chip-lock.elf rodata 48 48
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-lighting.elf and ./pull_artifact/chip-lighting.elf:

sections,vmsize,filesize
.debug_info,0,15320
.debug_loc,0,4296
.debug_line,0,3758
.debug_abbrev,0,1542
.debug_str,0,1000
.debug_frame,0,388
text,208,208
.debug_ranges,0,176
.symtab,0,176
.strtab,0,159
.debug_aranges,0,104
rodata,52,48
.shstrtab,0,-3

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,15320
.debug_loc,0,4300
.debug_line,0,3754
.debug_abbrev,0,1542
.debug_str,0,992
.debug_frame,0,388
text,208,208
.debug_ranges,0,176
.symtab,0,176
.strtab,0,159
.debug_aranges,0,104
rodata,48,48
.shstrtab,0,1


@mspang mspang merged commit fca1757 into project-chip:master Apr 9, 2021
jimlyall-q pushed a commit to jimlyall-q/connectedhomeip that referenced this pull request Apr 13, 2021
* Add List[T] attribute support to src/app

* Update the templates for List[T] supports

* Add Descriptor cluster source code

* Activate NetworkProvisiong, Descriptor and Group Key Management clusters

* Update ZAP repo

* Update the templates to fit ZAP update

* Update gen/ folder

* Update src/app/clusters/descriptor/descriptor.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Apply suggestions from code review

* Update src/app/util/af.h

* Add 'descriptor' to the list of built cluster for the all-clusters-app

Co-authored-by: Boris Zbarsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.