Skip to content

Commit

Permalink
Make tlvmeta recognize feature map bitmaps. (#28084)
Browse files Browse the repository at this point in the history
* Make tlvmeta recognize feature map bitmaps.

zap does not support per cluster featuremap types because types
are global, however we can use naming conventions to select
the correct featuremap values.

This makes decoded data more user friendly.

* Make flake8 happy

* Support "Feature" as a name for features

* Fix unit tests

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
2 people authored and pull[bot] committed Feb 13, 2024
1 parent d3b13a3 commit 3799926
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ def __init__(self, cluster: Cluster):
for b in self.cluster.bitmaps:
self.item_type_map[b.name] = "kBitmap"

def FieldEntry(self, field: Field, tag_type: str = 'ContextTag') -> TableEntry:
type_reference = "%s_%s" % (self.cluster.name, field.data_type.name)
def FieldEntry(self, field: Field, tag_type: str = 'ContextTag', type_override: Optional[str] = None) -> TableEntry:
data_type_name = type_override or field.data_type.name
type_reference = "%s_%s" % (self.cluster.name, data_type_name)

if type_reference not in self.known_types:
type_reference = None

item_type = self.item_type_map.get(field.data_type.name, 'kDefault')
item_type = self.item_type_map.get(data_type_name, 'kDefault')

real_type = "%s::%s" % (self.cluster.name, field.data_type.name)
real_type = "%s::%s" % (self.cluster.name, data_type_name)
if field.is_list:
real_type = real_type + "[]"
item_type = "kList"
Expand Down Expand Up @@ -142,11 +144,21 @@ def CommandEntries(self) -> Generator[TableEntry, None, None]:
def GenerateTables(self) -> Generator[Table, None, None]:
self.ComputeKnownTypes()

cluster_feature_map = None
for b in self.cluster.bitmaps:
# Older matter files use `ClusterNameFeature` as naming, newer code was
# updated to just `Feature`. For now support both.
if b.name in {'Feature', f'{self.cluster.name}Feature'} and b.base_type.lower() == 'bitmap32':
cluster_feature_map = b.name

# Clusters have attributes. They are direct descendants for
# attributes
cluster_entries = []
cluster_entries.extend([self.FieldEntry(
a.definition, tag_type='AttributeTag') for a in self.cluster.attributes])
cluster_entries.extend([
self.FieldEntry(a.definition, tag_type='AttributeTag',
type_override=(cluster_feature_map if a.definition.code == 0xFFFC else None))
for a in self.cluster.attributes
])

cluster_entries.extend([
# events always reference an existing struct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace chip::TLV;

const Entry<ItemInfo> _OnOff[] = {
{ { AttributeTag(0), "onOff", ItemType::kDefault }, kInvalidNodeIndex }, // OnOff::boolean
{ { AttributeTag(65532), "featureMap", ItemType::kDefault }, kInvalidNodeIndex }, // OnOff::bitmap32
{ { AttributeTag(65532), "featureMap", ItemType::kBitmap }, 8 }, // OnOff::OnOffFeature
{ { AttributeTag(65533), "clusterRevision", ItemType::kDefault }, kInvalidNodeIndex }, // OnOff::int16u
{ { CommandTag(0), "Off", ItemType::kDefault }, kInvalidNodeIndex }, // OnOff::Off::()
{ { CommandTag(1), "On", ItemType::kDefault }, kInvalidNodeIndex }, // OnOff::On::()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/format/tests/TestDecoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
" endpoint_id: 0\n"
" cluster_id: 49 == 'NetworkCommissioning'\n"
" attribute_id: 65532 == 'featureMap'\n"
" NetworkCommissioning::featureMap: 4\n"
" NetworkCommissioning::featureMap: 4 == kEthernetNetworkInterface\n"
" suppress_response: true\n"
" interaction_model_revison: 1\n");

Expand Down

0 comments on commit 3799926

Please sign in to comment.