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 support for adding codegen for interaction model #4298

Merged
merged 48 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ce94756
Initial commit for adding codegen for interaction model
erjiaqing Jan 8, 2021
985c180
Restyled by clang-format
restyled-commits Jan 8, 2021
2b6955c
Restyled by gn
restyled-commits Jan 8, 2021
9c96f22
Update templates
erjiaqing Jan 12, 2021
a36e832
Update template
erjiaqing Jan 12, 2021
8025933
Move flags
erjiaqing Jan 12, 2021
0495551
Code cleanup
erjiaqing Jan 12, 2021
d68c569
dmLib -> chipLib
erjiaqing Jan 12, 2021
d4c885f
Merge remote-tracking branch 'chip/master' into im-onoff-cluster
erjiaqing Jan 13, 2021
8bd2e32
Cleanup chip-device-ctrl python cli
erjiaqing Jan 13, 2021
0fc9435
Address comments
erjiaqing Jan 14, 2021
22d4b27
Restyled by clang-format
restyled-commits Jan 14, 2021
ad17020
Move Handler to src/app/clusters to avoid misleading
erjiaqing Jan 14, 2021
3575e10
Add comment for on-off-im.cpp
erjiaqing Jan 14, 2021
99f183c
Move CommandSender to ChipDevice
erjiaqing Jan 14, 2021
b07106c
Fix CHIP Device
erjiaqing Jan 14, 2021
19a979e
Add VerifyOrExit check for ime
erjiaqing Jan 14, 2021
2821af0
Address comments
erjiaqing Jan 14, 2021
4793938
Restyled by clang-format
restyled-commits Jan 14, 2021
f908c8a
Use return macros
erjiaqing Jan 15, 2021
53b6c53
Fix typo
erjiaqing Jan 15, 2021
d943b36
Add missing storage delegate
erjiaqing Jan 15, 2021
464cdb3
Fix
erjiaqing Jan 15, 2021
375bd5e
Fix
erjiaqing Jan 15, 2021
6c9cd33
Fix
erjiaqing Jan 15, 2021
bfa1bec
Fix
erjiaqing Jan 15, 2021
8c55141
Fix
erjiaqing Jan 15, 2021
39a7ea5
Fix
erjiaqing Jan 15, 2021
b3ac301
Revert "Fix"
erjiaqing Jan 18, 2021
0f77b89
Merge remote-tracking branch 'chip/master' into im-onoff-cluster
erjiaqing Jan 21, 2021
f91173a
Merge remote-tracking branch 'chip/master' into im-onoff-cluster
erjiaqing Jan 25, 2021
1d62044
Fix build
erjiaqing Jan 25, 2021
bc8d316
Address comments
erjiaqing Jan 26, 2021
2af3084
Address comments
erjiaqing Jan 26, 2021
30ec612
Fix
erjiaqing Jan 26, 2021
f36d0c7
Restyled by clang-format
restyled-commits Jan 26, 2021
e51686b
Address comments
erjiaqing Jan 27, 2021
9ee85c8
Merge remote-tracking branch 'chip/master' into im-onoff-cluster
erjiaqing Jan 27, 2021
1d6d2ac
fix build failure
erjiaqing Jan 27, 2021
a44c5d2
Restyled by whitespace
restyled-commits Jan 27, 2021
cea3c04
Restyled by clang-format
restyled-commits Jan 27, 2021
4193657
Remove mistakenly added changes
erjiaqing Jan 27, 2021
8072f39
Fill issue id in TODO
erjiaqing Jan 27, 2021
23de978
temaple cleanup
erjiaqing Jan 27, 2021
3a995e0
Merge remote-tracking branch 'chip/master' into im-onoff-cluster
erjiaqing Jan 28, 2021
8a007c1
Restyled by gn
restyled-commits Jan 28, 2021
5d7370f
Merge remote-tracking branch 'origin/master' into im-onoff-cluster
erjiaqing Jan 29, 2021
49ceaf9
address comments
erjiaqing Jan 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/lighting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ int main(int argc, char * argv[])
chip::app::cluster::OnOff::InitCluster(chip::app::InteractionModelEngine::GetInstance());
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
erjiaqing marked this conversation as resolved.
Show resolved Hide resolved
if (LinuxDeviceOptions::GetInstance().mWiFi)
{
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
Expand Down
4 changes: 3 additions & 1 deletion src/app/chip-zcl-zpro-codec-api.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
* limitations under the License.
*/

// THIS FILE IS GENERATED BY ZAP

// Prevent multiple inclusion
#pragma once

Expand Down
8 changes: 4 additions & 4 deletions src/app/clusters/on-off-server/on-off-im.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,17 +36,17 @@ namespace OnOff {
// TODO: Call handler in on-off.cpp here.
void HandleOffCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj)
{
// Simplily does nothing, should be replaced by actual logic.
// Simply does nothing, should be replaced by actual logic.
}

void HandleOnCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj)
{
// Simplily does nothing, should be replaced by actual logic.
// Simply does nothing, should be replaced by actual logic.
}

void HandleToggleCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj)
{
// Simplily does nothing, should be replaced by actual logic.
// Simply does nothing, should be replaced by actual logic.
}

} // namespace OnOff
Expand Down
4 changes: 3 additions & 1 deletion src/app/encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
* limitations under the License.
*/

// THIS FILE IS GENERATED BY ZAP

#include "chip-zcl-zpro-codec.h"

#include <support/BufBound.h>
Expand Down
28 changes: 28 additions & 0 deletions src/app/im-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

erjiaqing marked this conversation as resolved.
Show resolved Hide resolved
// THIS FILE IS GENERATED BY ZAP

#include "im-handler.h"

#include <app/CommandHandler.h>
Expand Down Expand Up @@ -54,19 +56,43 @@ namespace Basic {
void InitCluster(chip::app::InteractionModelEngine * ime)
{
VerifyOrReturn(ime != nullptr);
ime->RegisterClusterCommandHandler(Basic::kClusterId, Basic::kMfgSpecificPingCommandId,
Command::CommandRoleId::kCommandHandlerId, HandleMfgSpecificPingCommandReceived);
ime->RegisterClusterCommandHandler(Basic::kClusterId, Basic::kResetToFactoryDefaultsCommandId,
Command::CommandRoleId::kCommandHandlerId, HandleResetToFactoryDefaultsCommandReceived);
}

void ShutdownCluster(chip::app::InteractionModelEngine * ime)
{
VerifyOrReturn(ime != nullptr);
ime->DeregisterClusterCommandHandler(Basic::kClusterId, Basic::kMfgSpecificPingCommandId,
Command::CommandRoleId::kCommandHandlerId);
ime->DeregisterClusterCommandHandler(Basic::kClusterId, Basic::kResetToFactoryDefaultsCommandId,
Command::CommandRoleId::kCommandHandlerId);
}

} // namespace Basic

namespace Binding {

void InitCluster(chip::app::InteractionModelEngine * ime)
{
VerifyOrReturn(ime != nullptr);
ime->RegisterClusterCommandHandler(Binding::kClusterId, Binding::kBindCommandId, Command::CommandRoleId::kCommandHandlerId,
HandleBindCommandReceived);
ime->RegisterClusterCommandHandler(Binding::kClusterId, Binding::kUnbindCommandId, Command::CommandRoleId::kCommandHandlerId,
HandleUnbindCommandReceived);
}

void ShutdownCluster(chip::app::InteractionModelEngine * ime)
{
VerifyOrReturn(ime != nullptr);
ime->DeregisterClusterCommandHandler(Binding::kClusterId, Binding::kBindCommandId, Command::CommandRoleId::kCommandHandlerId);
ime->DeregisterClusterCommandHandler(Binding::kClusterId, Binding::kUnbindCommandId, Command::CommandRoleId::kCommandHandlerId);
}

} // namespace Binding

namespace ColorControl {

void InitCluster(chip::app::InteractionModelEngine * ime)
Expand Down Expand Up @@ -445,6 +471,7 @@ void InitClusters(chip::app::InteractionModelEngine * ime)
VerifyOrReturn(ime != nullptr);
BarrierControl::InitCluster(ime);
Basic::InitCluster(ime);
Binding::InitCluster(ime);
ColorControl::InitCluster(ime);
DoorLock::InitCluster(ime);
Groups::InitCluster(ime);
Expand All @@ -461,6 +488,7 @@ void ShutdownClusters(chip::app::InteractionModelEngine * ime)
VerifyOrReturn(ime != nullptr);
BarrierControl::ShutdownCluster(ime);
Basic::ShutdownCluster(ime);
Binding::ShutdownCluster(ime);
ColorControl::ShutdownCluster(ime);
DoorLock::ShutdownCluster(ime);
Groups::ShutdownCluster(ime);
Expand Down
28 changes: 28 additions & 0 deletions src/app/im-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

// THIS FILE IS GENERATED BY ZAP

#pragma once

#include <app/CommandHandler.h>
Expand Down Expand Up @@ -60,6 +62,7 @@ namespace Basic {
| Cluster Basic | 0x0000 |
|------------------------------------------------------------------------------|
| Commands: | |
| * MfgSpecificPing | 0x00 |
| * ResetToFactoryDefaults | 0x00 |
|------------------------------------------------------------------------------|
| Attributes: | |
Expand All @@ -68,15 +71,40 @@ namespace Basic {
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/
constexpr uint16_t kClusterId = 0x0000;
constexpr uint8_t kMfgSpecificPingCommandId = 0x00;
constexpr uint8_t kResetToFactoryDefaultsCommandId = 0x00;

void HandleMfgSpecificPingCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj);
void HandleResetToFactoryDefaultsCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj);

void InitCluster(chip::app::InteractionModelEngine * ime);
void ShutdownCluster(chip::app::InteractionModelEngine * ime);

} // namespace Basic

namespace Binding {
/*----------------------------------------------------------------------------*\
| Cluster Binding | 0xF000 |
|------------------------------------------------------------------------------|
| Commands: | |
| * Bind | 0x00 |
| * Unbind | 0x01 |
|------------------------------------------------------------------------------|
| Attributes: | |
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/
constexpr uint16_t kClusterId = 0xF000;
constexpr uint8_t kBindCommandId = 0x00;
constexpr uint8_t kUnbindCommandId = 0x01;

void HandleBindCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj);
void HandleUnbindCommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj);

void InitCluster(chip::app::InteractionModelEngine * ime);
void ShutdownCluster(chip::app::InteractionModelEngine * ime);

} // namespace Binding

namespace ColorControl {
/*----------------------------------------------------------------------------*\
| Cluster ColorControl | 0x0300 |
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/partials/header.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// THIS FILE IS GENERATED BY ZAP
13 changes: 6 additions & 7 deletions src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#include "CHIPClusters.h"

#include <app/chip-zcl-zpro-codec-api.h>
#include <app/im-handler.h>
#include <support/ReturnMacros.h>

namespace chip {
namespace Controller {

// TODO(@vivien-apple): onCompletion is not used by IM for now.
// TODO: length should be passed to commands when byte string is in argument list.
// TODO: Commands should take group id as an argument.
// TODO(#4502): onCompletion is not used by IM for now.
// TODO(#4503): length should be passed to commands when byte string is in argument list.
// TODO(#4503): Commands should take group id as an argument.

{{#chip_server_clusters}}

Expand All @@ -22,13 +21,13 @@ CHIP_ERROR {{asCamelCased clusterName false}}Cluster::{{asCamelCased name false}
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
(void) onCompletion;

Command::CommandParams cmdParams = { ZCLendpointId, ZCLgroupId, {{asCamelCased clusterName false}}::kClusterId, {{asCamelCased clusterName false}}::k{{asCamelCased name false}}CommandId,
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, k{{asCamelCased name false}}CommandId,
(chip::app::Command::kCommandPathFlag_EndpointIdValid) };
Command::Command * ZCLcommand = mDevice->GetCommandSender();
app::Command * ZCLcommand = mDevice->GetCommandSender();

TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();

TLV::TLVType dummyType = TLV::kTLVType_NotSpecified;

ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag, TLV::kTLVType_Structure, dummyType));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a macro or something else for both the footer and the header ? The only thing that changes here is some ids that can be passed as parameters. It would make the generated code easier to read for humans.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to use macros in this part.
These lines are not bounded logically, for example, line 27, 28 gets the command object and then the writer object, line 30 and 32 creates a struct in tlv. The spacing in generated files and the loop tag in template should be enough.


{{#chip_server_cluster_command_arguments}}
Expand Down
9 changes: 8 additions & 1 deletion src/app/zap-templates/templates/chip/CHIPClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class DLL_EXPORT {{asCamelCased name false}}Cluster : public ClusterBase
public:
{{asCamelCased name false}}Cluster() : ClusterBase(k{{asCamelCased name false}}ClusterId) {}
~{{asCamelCased name false}}Cluster() {}

{{#chip_server_cluster_commands}}
{{#first}}

// Cluster Commands
{{/first}}
CHIP_ERROR {{asCamelCased name false}}(Callback::Callback<> * onCompletion{{#chip_server_cluster_command_arguments}}, {{chipType}} {{asCamelCased label}}{{/chip_server_cluster_command_arguments}});
Expand All @@ -42,6 +42,13 @@ public:
CHIP_ERROR ReportAttribute{{asCamelCased name false}}(Callback::Callback<> * onCompletion, Callback::Callback<> * onChange, uint16_t minInterval, uint16_t maxInterval{{#unless (isDiscreteType)}}, {{chipType}} change{{/unless}});
{{/if}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_commands}}
{{#first}}

private:
{{/first}}
static constexpr CommandId k{{asCamelCased name false}}CommandId = {{asHex code 2}};
{{/chip_server_cluster_commands}}
};

{{/chip_server_clusters}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <app/CommandSender.h>
#include <app/InteractionModelEngine.h>
#include <app/im-handler.h>
#include <support/ReturnMacros.h>

#include <controller/CHIPClusters.h>
Expand All @@ -13,23 +12,6 @@
using namespace chip;
using namespace chip::app;

namespace chip {
namespace app {
namespace cluster {

// Empty command handlers
{{#chip_server_clusters}}
namespace {{asCamelCased name false}} {
{{#chip_server_cluster_commands}}
void Handle{{asType name}}CommandReceived(chip::TLV::TLVReader & aReader, chip::app::Command * apCommandObj) {}
{{/chip_server_cluster_commands}}
} // namespace {{asCamelCased name false}}

{{/chip_server_clusters}}
} // namespace cluster
} // namespace app
} // namespace chip

extern "C" {

{{#chip_server_clusters}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import ctypes
from .ChipStack import *
from .ChipExceptions import *

'''
TODO(#4511): This file only sends cluster commands, should add more functions.
'''

__all__ = ["ChipCluster"]
erjiaqing marked this conversation as resolved.
Show resolved Hide resolved

class ChipCluster:
Expand Down
Loading