Skip to content

Commit

Permalink
Temporary commit: Cluster DummyEcho
Browse files Browse the repository at this point in the history
  • Loading branch information
kedars committed Jul 21, 2020
1 parent d0fca83 commit 58dafee
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/lib/datamodel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static_library("datamodel") {
"Attribute.h",
"Cluster.h",
"ClusterBasic.h",
"ClusterDummyEcho.h",
"ClusterOnOff.h",
"ClusterServer.cpp",
"ClusterServer.h",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datamodel/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Cluster : public Deque<Cluster>
*
* @param cmd the command that needs to be processed
*/
virtual CHIP_ERROR HandleCommand(const Command & cmd)
virtual CHIP_ERROR HandleCommand(Command & cmd)
{
/* Do nothing */
return CHIP_NO_ERROR;
Expand Down
113 changes: 113 additions & 0 deletions src/lib/datamodel/ClusterDummyEcho.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
*
* Copyright (c) 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file contains definitions for a dummy CHIP Cluster 'Echo' that can be used for
* end-to-end testing.
*
*/

#ifndef CHIPCLUSTER_ECHO_H_
#define CHIPCLUSTER_ECHO_H_

#include <datamodel/Cluster.h>

namespace chip {
namespace DataModel {

/* Cluster ID */
static const ClusterId_t kClusterIdDummyEcho = 0xfc00;

/* Attribute IDs */
static const AttributeId_t kAttributeIdDummyEcho = 0x0000;

/* Command IDs */
static const CommandId_t kDummyEchoCmdIdEchoRequest = 0x00;
static const CommandId_t kDummyEchoCmdIdEchoResponse = 0x00;

static inline void ClusterDummyEchoGenerateCommand(Command & cmd, CommandId_t cmdId, uint16_t endpointId)
{
cmd.mEndpointId = endpointId;
cmd.mType = kCmdTypeCluster;
cmd.mClusterId = kClusterIdDummyEcho;
cmd.mId = cmdId;
cmd.mDirection = cmdId == kDummyEchoCmdIdEchoRequest ? kCmdDirectionClientToServer : kCmdDirectionServerToClient;
cmd.StartEncode();
cmd.EndEncode();
}

static inline void ClusterDummyEchoEncodeEchoRequest(Command & cmd, uint16_t endpointId)
{
ClusterDummyEchoGenerateCommand(cmd, kDummyEchoCmdIdEchoRequest, endpointId);
}

static inline void ClusterDummyEchoEncodeEchoResponse(Command & cmd, uint16_t endpointId)
{
ClusterDummyEchoGenerateCommand(cmd, kDummyEchoCmdIdEchoResponse, endpointId);
};

/**
* @brief
* This class implements the DummyEcho cluster as defined in the CHIP specification.
*/
class ClusterDummyEcho : public Cluster
{
private:
/* Just a placeholder attribute that is never assigned to */
AttributeSimple<bool> mDummyEcho;

public:
ClusterDummyEcho() : Cluster(kClusterIdDummyEcho), mDummyEcho(kAttributeIdDummyEcho)
{
AddAttribute(&mDummyEcho);
}

virtual CHIP_ERROR HandleCommandEchoRequest(Command & cmd)
{
/* TODO The endpoint is fake here */
ClusterDummyEchoEncodeEchoResponse(cmd, 1);
return CHIP_NO_ERROR;
}

/**
* @brief
* Handle commands for the Cluster DummyEcho. This is already handled in the ClusterDummyEcho
* class. Applications may choose to override this handling if required.
*
* @param cmd the command to handle
*
* @return CHIP_NO_ERROR on success or a failure-specific error code otherwise
*/
virtual CHIP_ERROR HandleCommand(Command & cmd)
{
switch (cmd.mId)
{
case kDummyEchoCmdIdEchoRequest:
return HandleCommandEchoRequest(cmd);
default:
/* Unsupported */
return CHIP_ERROR_INTERNAL;
}
return CHIP_ERROR_INTERNAL;
}
};

} // namespace DataModel
} // namespace chip

#endif /* CHIPCLUSTER_ECHO_H_ */
10 changes: 5 additions & 5 deletions src/lib/datamodel/ClusterOnOff.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ClusterOnOff : public Cluster
*
* @return CHIP_NO_ERROR on success or a failure-specific error code otherwise
*/
virtual CHIP_ERROR HandleCommand(const Command & cmd)
virtual CHIP_ERROR HandleCommand(Command & cmd)
{
switch (cmd.mId)
{
Expand All @@ -138,7 +138,7 @@ class ClusterOnOff : public Cluster
}
};

static inline void GenerateCommand(Command * cmd, CommandId_t cmdId, uint16_t endpointId)
static inline void ClusterOnOffGenerateCommand(Command * cmd, CommandId_t cmdId, uint16_t endpointId)
{
cmd->mType = kCmdTypeCluster;
cmd->mId = cmdId;
Expand All @@ -152,17 +152,17 @@ static inline void GenerateCommand(Command * cmd, CommandId_t cmdId, uint16_t en

static inline void ClusterOnOffEncodeOn(Command * cmd, uint16_t endpointId)
{
GenerateCommand(cmd, kOnOffCmdIdOn, endpointId);
ClusterOnOffGenerateCommand(cmd, kOnOffCmdIdOn, endpointId);
}

static inline void ClusterOnOffEncodeOff(Command * cmd, uint16_t endpointId)
{
GenerateCommand(cmd, kOnOffCmdIdOff, endpointId);
ClusterOnOffGenerateCommand(cmd, kOnOffCmdIdOff, endpointId);
}

static inline void ClusterOnOffEncodeToggle(Command * cmd, uint16_t endpointId)
{
GenerateCommand(cmd, kOnOffCmdIdToggle, endpointId);
ClusterOnOffGenerateCommand(cmd, kOnOffCmdIdToggle, endpointId);
}

} // namespace DataModel
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datamodel/ClusterServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace chip {
namespace DataModel {

CHIP_ERROR ClusterServer::HandleCommand(const Command & cmd)
CHIP_ERROR ClusterServer::HandleCommand(Command & cmd)
{
if (cmd.mDirection != kCmdDirectionClientToServer)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datamodel/ClusterServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ClusterServer
*
* @return CHIP_NO_ERROR on success or a failure-specific error code otherwise
*/
CHIP_ERROR HandleCommand(const Command & cmd);
CHIP_ERROR HandleCommand(Command & cmd);
};

} // namespace DataModel
Expand Down

0 comments on commit 58dafee

Please sign in to comment.