Skip to content

Commit

Permalink
MEI sample cluster. Chef device sample
Browse files Browse the repository at this point in the history
  • Loading branch information
rochaferraz committed Aug 22, 2023
1 parent fe51635 commit 933c2b1
Show file tree
Hide file tree
Showing 61 changed files with 3,083 additions and 371 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ MDNS
MediaInput
MediaPlayback
MediaTek
MEI
mem
memdf
MemMonitoring
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ jobs:
src/app/zap-templates/zcl/data-model/draft/input-output-value-clusters.xml \
src/app/zap-templates/zcl/data-model/draft/onoff-switch-configuration-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/resource-monitoring-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/sample-mei-cluster.xml \
"
- name: Build Apps
run: |
Expand Down
29 changes: 16 additions & 13 deletions examples/chef/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,26 @@ To add new devices for chef:
- This is gated by the workflow in `.github/workflows/zap_templates.yaml`.
- All devices added to the repository are built in CD.

## Vendor Defined Clusters
## Manufacturer Extensions / Custom Clusters

You may add vendor-defined features to chef. The rootnode_onofflight_meisample* device
showcases its usage by using the "cheftestcluster" which is defined on
`src/app/zap-templates/zcl/data-model/chip/chef-test-cluster.xml`
You may add vendor-defined features to chef. The `rootnode_onofflight_meisample*`
device showcases its usage by using the Sample Mei cluster which is defined on
`src/app/zap-templates/zcl/data-model/chip/sample-mei-cluster.xml`

This cluster has one boolean attribute and a command/response pair. The
command takes two uint8 arguments and the command response returns their sum.
This cluster has
- One boolean attribute: `flip-flop`
- A `ping` command with no arguments
- A command/response pair `add-arguments`. The command takes two uint8
arguments and the response command returns their sum.

You may test the chef-test-cluster via chip-tool using the following commands:
You may test the Sample `MEI` via chip-tool using the following commands:
```
# commissioning of on-network chef device
chip-tool pairing onnetwork 1 20202021
# tests command to sum arguments
chip-tool cheftestcluster test-add-arguments 1 1 10 20
# sets attribute1 to false
chip-tool cheftestcluster write attribute1 0 1 1
# reads attribute1
chip-tool cheftestcluster read attribute1 1 1
# tests command to sum arguments: returns 30
chip-tool samplemei add-arguments 1 1 10 20
# sets Flip-Flop to false
chip-tool samplemei write flip-flop 0 1 1
# reads Flip-Flop
chip-tool samplemei read flip-flop 1 1
```
Original file line number Diff line number Diff line change
Expand Up @@ -1329,15 +1329,27 @@ server cluster FixedLabel = 64 {
readonly attribute int16u clusterRevision = 65533;
}

/** The Chef Test Cluster showcases manufacturer extensions */
server cluster ChefTestCluster = 4294048800 {
attribute boolean attribute1 = 0;
/** The Sample MEI cluster showcases a cluster manufacturer extensions */
server cluster SampleMei = 4294048800 {
attribute boolean flipFlop = 0;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct AddArgumentsRequest {
INT8U arg1 = 0;
INT8U arg2 = 1;
}

response struct AddArgumentsResponse = 1 {
INT8U returnValue = 0;
}

command Ping(): DefaultSuccess = 0;
command AddArguments(AddArgumentsRequest): AddArgumentsResponse = 2;
}

endpoint 0 {
Expand Down Expand Up @@ -1571,8 +1583,8 @@ endpoint 1 {
ram attribute clusterRevision default = 1;
}

server cluster ChefTestCluster {
ram attribute attribute1 default = false;
server cluster SampleMei {
ram attribute flipFlop default = false;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"endpointTypes": [
{
"id": 4,
"id": 5,
"name": "MA-rootdevice",
"deviceTypeRef": {
"id": 2,
Expand Down Expand Up @@ -5420,7 +5420,7 @@
]
},
{
"id": 3,
"id": 6,
"name": "Anonymous Endpoint Type",
"deviceTypeRef": {
"id": 8,
Expand Down Expand Up @@ -7522,20 +7522,28 @@
]
},
{
"name": "Chef Test Cluster",
"name": "Sample MEI",
"code": 4294048800,
"mfgCode": null,
"define": "CHEF_TEST_CLUSTER",
"define": "SAMPLE_MEI_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [
{
"name": "Test",
"name": "Ping",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 0,
"incoming": 1,
"outgoing": 1
},
{
"name": "AddArguments",
"code": 2,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
Expand Down Expand Up @@ -7574,15 +7582,25 @@
]
},
{
"name": "Chef Test Cluster",
"name": "Sample MEI",
"code": 4294048800,
"mfgCode": null,
"define": "CHEF_TEST_CLUSTER",
"define": "SAMPLE_MEI_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [
{
"name": "AddArgumentsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
{
"name": "attribute1",
"name": "FlipFlop",
"code": 0,
"mfgCode": null,
"side": "server",
Expand All @@ -7604,7 +7622,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -7620,7 +7638,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -7636,7 +7654,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand All @@ -7652,7 +7670,7 @@
"side": "server",
"type": "array",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down
1 change: 0 additions & 1 deletion examples/chef/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ chip_data_model("chef-data-model") {
executable("${sample_name}") {
sources = [
"${project_dir}/common/chef-channel-manager.cpp",
"${project_dir}/common/chef-test-cluster-server.cpp",
"${project_dir}/common/stubs.cpp",
"${project_dir}/linux/main.cpp",
]
Expand Down
6 changes: 3 additions & 3 deletions examples/chef/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <app/ConcreteAttributePath.h>
#include <lib/shell/Engine.h>
#include <lib/support/logging/CHIPLogging.h>
#include <app/clusters/sample-mei-server/sample-mei-server.h>

#include "../common/chef-test-cluster-server.h"

using namespace chip;
using namespace chip::Shell;
Expand Down Expand Up @@ -54,8 +54,8 @@ int main(int argc, char * argv[])
#if CHIP_SHELL_ENABLE_CMD_SERVER
cmd_app_server_init();
#endif
app::Clusters::ChefTestCluster::ChefTestClusterServer chefTestClusterServer(1 /* endpoint */);
chefTestClusterServer.Init();
app::Clusters::SampleMei::SampleMeiServer sampleMeiServer(1 /* endpoint */);
sampleMeiServer.Init();

ChipLinuxAppMainLoop();

Expand Down
2 changes: 1 addition & 1 deletion scripts/rules.matterlint
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ load "../src/app/zap-templates/zcl/data-model/draft/input-output-value-clusters.
load "../src/app/zap-templates/zcl/data-model/draft/onoff-switch-configuration-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/air-quality-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/resource-monitoring-cluster.xml";

load "../src/app/zap-templates/zcl/data-model/chip/sample-mei-cluster.xml";

all endpoints {
// These attributes follow a different code path and do not have to be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "chef-test-cluster-server.h"
#include "sample-mei-server.h"

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
Expand All @@ -16,46 +16,46 @@
using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ChefTestCluster;
using namespace chip::app::Clusters::ChefTestCluster::Commands;
using namespace chip::app::Clusters::ChefTestCluster::Attributes;
using namespace chip::app::Clusters::SampleMei;
using namespace chip::app::Clusters::SampleMei::Commands;
using namespace chip::app::Clusters::SampleMei::Attributes;


namespace chip {
namespace app {
namespace Clusters {
namespace ChefTestCluster {
namespace SampleMei {

CHIP_ERROR ChefTestClusterServer::Init()
CHIP_ERROR SampleMeiServer::Init()
{
ChipLogProgress(Zcl,">>>>> ChefTest Init");
ChipLogProgress(Zcl,">>>>> Sample Mei Test Init");
ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this));
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);
attribute1 = true;
return CHIP_NO_ERROR;
}

void ChefTestClusterServer::InvokeCommand(HandlerContext & ctxt)
void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
{
ChipLogProgress(Zcl,">>>>> Invoke");
switch (ctxt.mRequestPath.mCommandId)
{
case Commands::Test::Id:
HandleCommand<Commands::Test::DecodableType>(ctxt, [this](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl,">>>>> TestCommand");
case Commands::Ping::Id:
HandleCommand<Commands::Ping::DecodableType>(ctxt, [this](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl,">>>>> Ping Command");
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
});
return;
case Commands::TestAddArguments::Id:
HandleCommand<Commands::TestAddArguments::DecodableType>(ctxt, [this](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl,">>>>> TestAddArgumentsCommand");
case Commands::AddArguments::Id:
HandleCommand<Commands::AddArguments::DecodableType>(ctxt, [this](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl,">>>>> AddArgumentsCommand");
if (req.arg1 > UINT8_MAX - req.arg2)
{
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::InvalidCommand);
return;
}

TestAddArgumentsResponse::Type responseData;
AddArgumentsResponse::Type responseData;
responseData.returnValue = static_cast<uint8_t>(req.arg1 + req.arg2);
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, responseData);
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
Expand All @@ -64,23 +64,23 @@ void ChefTestClusterServer::InvokeCommand(HandlerContext & ctxt)
}
}

CHIP_ERROR ChefTestClusterServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
CHIP_ERROR SampleMeiServer::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
switch (aPath.mAttributeId)
{
case Attributes::Attribute1::Id:
case Attributes::FlipFlop::Id:
return aEncoder.Encode(attribute1);

default:
return CHIP_NO_ERROR;
}
}

CHIP_ERROR ChefTestClusterServer::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
CHIP_ERROR SampleMeiServer::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
{
switch (aPath.mAttributeId)
{
case Attributes::Attribute1::Id:
case Attributes::FlipFlop::Id:
bool value;
ReturnErrorOnFailure(aDecoder.Decode(value));
attribute1 = value;
Expand All @@ -90,7 +90,7 @@ CHIP_ERROR ChefTestClusterServer::Write(const ConcreteDataAttributePath & aPath,
}
}

} // namespace ChefTestCluster
} // namespace SampleMei
} // namespace Clusters
} // namespace app
} // namespace chip
Expand All @@ -100,30 +100,30 @@ CHIP_ERROR ChefTestClusterServer::Write(const ConcreteDataAttributePath & aPath,
*********************************************************/

/**
* @brief Chef Test Cluster Cluster Test Command callback (from client)
* @brief Sample Mei Cluster Ping Command callback (from client)
*/
bool emberAfChefTestClusterClusterTestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Clusters::ChefTestCluster::Commands::Test::DecodableType & commandData)
bool emberAfSampleMeiClusterPingCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Clusters::SampleMei::Commands::Ping::DecodableType & commandData)
{
return true;
}

/**
* @brief Chef Test Cluster Cluster TestAddArgumentsResponse Command callback (from server)
* @brief Sample Mei Cluster AddArgumentsResponse Command callback (from server)
*/
bool emberAfChefTestClusterClusterTestAddArgumentsResponseCallback(EndpointId endpoint, CommandSender * commandObj,
bool emberAfSampleMeiClusterAddArgumentsResponseCallback(EndpointId endpoint, CommandSender * commandObj,
uint8_t returnValue)
{
return true;
}

/**
* @brief Chef Test Cluster Cluster TestAddArguments Command callback (from client)
* @brief Sample Mei Cluster AddArguments Command callback (from client)
*/
bool emberAfChefTestClusterClusterTestAddArgumentsCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::TestAddArguments::DecodableType & commandData)
bool emberAfSampleMeiClusterAddArgumentsCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::AddArguments::DecodableType & commandData)
{
return true;
}

void MatterChefTestClusterPluginServerInitCallback() {}
void MatterSampleMeiPluginServerInitCallback() {}
Loading

0 comments on commit 933c2b1

Please sign in to comment.