Skip to content

Commit

Permalink
Fix the XML for ModeOptionStruct to match spec. (#18637)
Browse files Browse the repository at this point in the history
Also fixes some ZAP templates that were generating incorrect code for
lists in struct fields, noticed while looking at the codegen from
these changes.

Fixes #14077

Fixes #11748
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 22, 2023
1 parent 07eddd4 commit 4333681
Show file tree
Hide file tree
Showing 26 changed files with 760 additions and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,12 @@ server cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;

using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType;
using SemanticTag = Structs::SemanticTag::Type;
template <typename T>
using List = app::DataModel::List<T>;
using storage_value_type = const ModeOptionStructType;
namespace {
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag)
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode,
const List<const SemanticTag> & semanticTags)
{
Structs::ModeOptionStruct::Type option;
option.label = CharSpan::fromCharString(label);
option.mode = mode;
option.semanticTag = semanticTag;
option.label = CharSpan::fromCharString(label);
option.mode = mode;
option.semanticTags = semanticTags;
return option;
}
} // namespace

constexpr SemanticTag semanticTagsBlack[] = { { .value = 0 } };
constexpr SemanticTag semanticTagsCappucino[] = { { .value = 0 } };
constexpr SemanticTag semanticTagsEspresso[] = { { .value = 0 } };

// TODO: Configure your options for each endpoint
storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0),
buildModeOptionStruct("Cappuccino", 4, 0),
buildModeOptionStruct("Espresso", 7, 0) };
storage_value_type StaticSupportedModesManager::coffeeOptions[] = {
buildModeOptionStruct("Black", 0, List<const SemanticTag>(semanticTagsBlack)),
buildModeOptionStruct("Cappuccino", 4, List<const SemanticTag>(semanticTagsCappucino)),
buildModeOptionStruct("Espresso", 7, List<const SemanticTag>(semanticTagsEspresso))
};
const StaticSupportedModesManager::EndpointSpanPair
StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointSpanPair(1, Span<storage_value_type>(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1
Expand Down
6 changes: 3 additions & 3 deletions examples/chip-tool/templates/tests/partials/value_equals.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
auto iter_{{depth}} = {{actual}}.begin();
{{#each expected}}
VerifyOrReturn(CheckNextListItemDecodes<decltype({{../actual}})>("{{../label}}", iter_{{../depth}}, {{@index}}));
{{>valueEquals label=(concat ../label "[" @index "]") actual=(concat "iter_" ../depth ".GetValue()") expected=this isArray=false type=../type chipType=../chipType depth=(incrementDepth depth) parent=../parent}}
{{>valueEquals label=(concat ../label "[" @index "]") actual=(concat "iter_" ../depth ".GetValue()") expected=this isArray=false type=../type chipType=../chipType depth=(incrementDepth ../depth) parent=../parent}}
{{/each}}
VerifyOrReturn(CheckNoMoreListItems<decltype({{actual}})>("{{label}}", iter_{{depth}}, {{expected.length}}));
}
{{else if isEvent}}
{{#zcl_events_fields_by_event_name type}}
{{#if (hasProperty ../expected label)}}
{{>valueEquals label=(concat ../label "." (asLowerCamelCase label)) actual=(concat ../actual "." (asLowerCamelCase label)) expected=(lookup ../expected label) depth=(incrementDepth depth)}}
{{>valueEquals label=(concat ../label "." (asLowerCamelCase label)) actual=(concat ../actual "." (asLowerCamelCase label)) expected=(lookup ../expected label) depth=(incrementDepth ../depth)}}
{{/if}}
{{/zcl_events_fields_by_event_name}}
{{else}}
Expand All @@ -43,7 +43,7 @@
call. }}
{{#zcl_struct_items_by_struct_name type}}
{{#if (hasProperty ../expected label)}}
{{>valueEquals label=(concat ../label "." (asLowerCamelCase label)) actual=(concat ../actual "." (asLowerCamelCase label)) expected=(lookup ../expected label) depth=(incrementDepth depth)}}
{{>valueEquals label=(concat ../label "." (asLowerCamelCase label)) actual=(concat ../actual "." (asLowerCamelCase label)) expected=(lookup ../expected label) depth=(incrementDepth ../depth)}}
{{/if}}
{{/zcl_struct_items_by_struct_name}}
{{! Maybe we should add a check for properties in the expected object (other
Expand Down
14 changes: 12 additions & 2 deletions examples/placeholder/linux/apps/app1/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,12 @@ client cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down Expand Up @@ -1232,7 +1237,12 @@ server cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down
14 changes: 12 additions & 2 deletions examples/placeholder/linux/apps/app2/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,12 @@ client cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down Expand Up @@ -1232,7 +1237,12 @@ server cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down
26 changes: 18 additions & 8 deletions examples/placeholder/linux/static-supported-modes-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;

using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType;
using SemanticTag = Structs::SemanticTag::Type;
template <typename T>
using List = app::DataModel::List<T>;
using storage_value_type = const ModeOptionStructType;
namespace {
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag)
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode,
const List<const SemanticTag> & semanticTags)
{
Structs::ModeOptionStruct::Type option;
option.label = CharSpan::fromCharString(label);
option.mode = mode;
option.semanticTag = semanticTag;
option.label = CharSpan::fromCharString(label);
option.mode = mode;
option.semanticTags = semanticTags;
return option;
}
} // namespace

constexpr SemanticTag semanticTagsBlack[] = { { .value = 0 } };
constexpr SemanticTag semanticTagsCappucino[] = { { .value = 0 } };
constexpr SemanticTag semanticTagsEspresso[] = { { .value = 0 } };

// TODO: Configure your options for each endpoint
storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0),
buildModeOptionStruct("Cappuccino", 4, 0),
buildModeOptionStruct("Espresso", 7, 0) };
storage_value_type StaticSupportedModesManager::coffeeOptions[] = {
buildModeOptionStruct("Black", 0, List<const SemanticTag>(semanticTagsBlack)),
buildModeOptionStruct("Cappuccino", 4, List<const SemanticTag>(semanticTagsCappucino)),
buildModeOptionStruct("Espresso", 7, List<const SemanticTag>(semanticTagsEspresso))
};
const StaticSupportedModesManager::EndpointSpanPair
StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointSpanPair(1, Span<storage_value_type>(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1
Expand Down
14 changes: 11 additions & 3 deletions src/app/tests/suites/TestModeSelectCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ tests:
response:
value:
[
{ Label: "Black", Mode: 0, SemanticTag: 0 },
{ Label: "Cappuccino", Mode: 4, SemanticTag: 0 },
{ Label: "Espresso", Mode: 7, SemanticTag: 0 },
{ Label: "Black", Mode: 0, SemanticTags: [{ "value": 0 }] },
{
Label: "Cappuccino",
Mode: 4,
SemanticTags: [{ "value": 0 }],
},
{
Label: "Espresso",
Mode: 7,
SemanticTags: [{ "value": 0 }],
},
]
constraints:
- type: list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ limitations under the License.
<cluster code="0x0050"/>
<item name="Label" type="CHAR_STRING" optional="false" length="32"/>
<item name="Mode" type="INT8U" optional="false"/>
<!-- TODO: A list of list is not supported yet. Otherwise this should be a list of SemanticTags -->
<!-- <item name="SemanticTags" type="SemanticTag" array="true" optional="false"/> -->
<item name="SemanticTag" type="INT32U" optional="false"/>
<item name="SemanticTags" type="SemanticTag" array="true" optional="false"/>
</struct>

<cluster>
Expand Down
7 changes: 6 additions & 1 deletion src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,12 @@ client cluster ModeSelect = 80 {
struct ModeOptionStruct {
char_string<32> label = 0;
int8u mode = 1;
int32u semanticTag = 2;
SemanticTag semanticTags[] = 2;
}

struct SemanticTag {
enum16 mfgCode = 0;
enum16 value = 1;
}

readonly attribute char_string<32> description = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/partials/decode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if ({{source}}.IsNull()) {
{{else}}
{{#if_is_struct type}}
{{#zcl_struct_items_by_struct_name type}}
{{>decode_value target=(concat ../target "_" (asLowerCamelCase label)) source=(concat ../source "." (asLowerCamelCase label)) cluster=../cluster depth=(incrementDepth depth) omitDeclaration=false earlyReturn=../earlyReturn}}
{{>decode_value target=(concat ../target "_" (asLowerCamelCase label)) source=(concat ../source "." (asLowerCamelCase label)) cluster=../cluster depth=(incrementDepth ../depth) omitDeclaration=false earlyReturn=../earlyReturn}}
{{/zcl_struct_items_by_struct_name}}

jclass {{asLowerCamelCase type}}StructClass;
Expand Down
Loading

0 comments on commit 4333681

Please sign in to comment.