forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridgedDeviceBasicInformationImpl.cpp
107 lines (93 loc) · 4.34 KB
/
BridgedDeviceBasicInformationImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (c) 2024 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.
*/
#include "BridgedDeviceBasicInformationImpl.h"
#include "BridgedDeviceManager.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterfaceRegistry.h>
static constexpr unsigned kBridgedDeviceBasicInformationClusterRevision = 4;
using namespace ::chip;
using namespace ::chip::app;
using namespace ::chip::app::Clusters;
CHIP_ERROR BridgedDeviceBasicInformationImpl::Read(const ConcreteReadAttributePath & path, AttributeValueEncoder & encoder)
{
// Registration is done for the bridged device basic information only
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);
switch (path.mAttributeId)
{
case BasicInformation::Attributes::Reachable::Id:
encoder.Encode(dev->IsReachable());
break;
case BasicInformation::Attributes::NodeLabel::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().nodeLabel.c_str()));
break;
case BasicInformation::Attributes::ClusterRevision::Id:
encoder.Encode(kBridgedDeviceBasicInformationClusterRevision);
break;
case BasicInformation::Attributes::FeatureMap::Id: {
BitMask<Clusters::BridgedDeviceBasicInformation::Feature> features;
features.Set(Clusters::BridgedDeviceBasicInformation::Feature::kBridgedICDSupport, dev->IsIcd());
encoder.Encode(features);
}
break;
case BasicInformation::Attributes::UniqueID::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().uniqueId.c_str()));
break;
case BasicInformation::Attributes::VendorName::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().vendorName.c_str()));
break;
case BasicInformation::Attributes::VendorID::Id:
encoder.Encode(dev->GetBridgedAttributes().vendorId);
break;
case BasicInformation::Attributes::ProductName::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().productName.c_str()));
break;
case BasicInformation::Attributes::ProductID::Id:
encoder.Encode(dev->GetBridgedAttributes().productId);
break;
case BasicInformation::Attributes::HardwareVersion::Id:
encoder.Encode(dev->GetBridgedAttributes().hardwareVersion);
break;
case BasicInformation::Attributes::HardwareVersionString::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().hardwareVersionString.c_str()));
break;
case BasicInformation::Attributes::SoftwareVersion::Id:
encoder.Encode(dev->GetBridgedAttributes().softwareVersion);
break;
case BasicInformation::Attributes::SoftwareVersionString::Id:
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().softwareVersionString.c_str()));
break;
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR BridgedDeviceBasicInformationImpl::Write(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder)
{
VerifyOrDie(path.mClusterId == app::Clusters::BridgedDeviceBasicInformation::Id);
BridgedDevice * dev = BridgeDeviceMgr().GetDevice(path.mEndpointId);
VerifyOrReturnError(dev != nullptr, CHIP_ERROR_NOT_FOUND);
if (!dev->IsReachable())
{
return CHIP_ERROR_NOT_CONNECTED;
}
ChipLogProgress(NotSpecified, "Bridged device basic information attempt to write attribute: ep=%d", path.mAttributeId);
// nothing writable right now ...
return CHIP_ERROR_INVALID_ARGUMENT;
}