Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2020-2021 Project CHIP Authors
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #include <app/util/util.h>
19 :
20 : #include <app-common/zap-generated/attribute-type.h>
21 : #include <app-common/zap-generated/attributes/Accessors.h>
22 : #include <app-common/zap-generated/ids/Clusters.h>
23 : #include <app/util/attribute-storage-detail.h>
24 : #include <app/util/attribute-storage.h>
25 : #include <app/util/config.h>
26 : #include <app/util/ember-strings.h>
27 : #include <app/util/generic-callbacks.h>
28 : #include <lib/core/CHIPConfig.h>
29 : #include <lib/core/CHIPEncoding.h>
30 : #include <protocols/interaction_model/StatusCode.h>
31 :
32 : // TODO: figure out a clear path for compile-time codegen
33 : #include <app/PluginApplicationCallbacks.h>
34 :
35 : using namespace chip;
36 :
37 : using chip::Protocols::InteractionModel::Status;
38 :
39 : // Calculates difference. See EmberAfDifferenceType for the maximum data size
40 : // that this function will support.
41 0 : EmberAfDifferenceType emberAfGetDifference(uint8_t * pData, EmberAfDifferenceType value, uint8_t dataSize)
42 : {
43 0 : EmberAfDifferenceType value2 = 0, diff;
44 : uint8_t i;
45 :
46 : // only support data types up to 8 bytes
47 0 : if (dataSize > sizeof(EmberAfDifferenceType))
48 : {
49 0 : return 0;
50 : }
51 :
52 : // get the value
53 0 : for (i = 0; i < dataSize; i++)
54 : {
55 0 : value2 = value2 << 8;
56 : #if (CHIP_CONFIG_BIG_ENDIAN_TARGET)
57 : value2 += pData[i];
58 : #else // BIGENDIAN
59 0 : value2 += pData[dataSize - i - 1];
60 : #endif // BIGENDIAN
61 : }
62 :
63 0 : if (value > value2)
64 : {
65 0 : diff = value - value2;
66 : }
67 : else
68 : {
69 0 : diff = value2 - value;
70 : }
71 :
72 0 : return diff;
73 : }
74 :
75 : // ****************************************
76 : // Initialize Clusters
77 : // ****************************************
78 15 : void emberAfInit()
79 : {
80 15 : emberAfInitializeAttributes(kInvalidEndpointId);
81 :
82 : MATTER_PLUGINS_INIT
83 :
84 15 : emAfCallInits();
85 15 : }
86 :
87 : // Cluster init functions that don't have a cluster implementation to define
88 : // them in.
89 0 : void MatterBallastConfigurationPluginServerInitCallback() {}
90 0 : void MatterBooleanStatePluginServerInitCallback() {}
91 0 : void MatterRelativeHumidityMeasurementPluginServerInitCallback() {}
92 0 : void MatterIlluminanceMeasurementPluginServerInitCallback() {}
93 0 : void MatterBinaryInputBasicPluginServerInitCallback() {}
94 0 : void MatterPressureMeasurementPluginServerInitCallback() {}
95 0 : void MatterTemperatureMeasurementPluginServerInitCallback() {}
96 0 : void MatterFlowMeasurementPluginServerInitCallback() {}
97 0 : void MatterThermostatUserInterfaceConfigurationPluginServerInitCallback() {}
98 0 : void MatterBridgedDeviceBasicInformationPluginServerInitCallback() {}
99 0 : void MatterPowerConfigurationPluginServerInitCallback() {}
100 0 : void MatterPowerProfilePluginServerInitCallback() {}
101 0 : void MatterPulseWidthModulationPluginServerInitCallback() {}
102 0 : void MatterAlarmsPluginServerInitCallback() {}
103 0 : void MatterTimePluginServerInitCallback() {}
104 0 : void MatterAclPluginServerInitCallback() {}
105 0 : void MatterPollControlPluginServerInitCallback() {}
106 0 : void MatterUnitLocalizationPluginServerInitCallback() {}
107 0 : void MatterProxyValidPluginServerInitCallback() {}
108 0 : void MatterProxyDiscoveryPluginServerInitCallback() {}
109 0 : void MatterProxyConfigurationPluginServerInitCallback() {}
110 0 : void MatterFanControlPluginServerInitCallback() {}
111 0 : void MatterActivatedCarbonFilterMonitoringPluginServerInitCallback() {}
112 0 : void MatterHepaFilterMonitoringPluginServerInitCallback() {}
113 0 : void MatterAirQualityPluginServerInitCallback() {}
114 0 : void MatterCarbonMonoxideConcentrationMeasurementPluginServerInitCallback() {}
115 0 : void MatterCarbonDioxideConcentrationMeasurementPluginServerInitCallback() {}
116 0 : void MatterFormaldehydeConcentrationMeasurementPluginServerInitCallback() {}
117 0 : void MatterNitrogenDioxideConcentrationMeasurementPluginServerInitCallback() {}
118 0 : void MatterOzoneConcentrationMeasurementPluginServerInitCallback() {}
119 0 : void MatterPm10ConcentrationMeasurementPluginServerInitCallback() {}
120 0 : void MatterPm1ConcentrationMeasurementPluginServerInitCallback() {}
121 0 : void MatterPm25ConcentrationMeasurementPluginServerInitCallback() {}
122 0 : void MatterRadonConcentrationMeasurementPluginServerInitCallback() {}
123 0 : void MatterTotalVolatileOrganicCompoundsConcentrationMeasurementPluginServerInitCallback() {}
124 0 : void MatterRvcRunModePluginServerInitCallback() {}
125 0 : void MatterRvcCleanModePluginServerInitCallback() {}
126 0 : void MatterDishwasherModePluginServerInitCallback() {}
127 0 : void MatterLaundryWasherModePluginServerInitCallback() {}
128 0 : void MatterRefrigeratorAndTemperatureControlledCabinetModePluginServerInitCallback() {}
129 0 : void MatterOperationalStatePluginServerInitCallback() {}
130 0 : void MatterRvcOperationalStatePluginServerInitCallback() {}
131 0 : void MatterOvenModePluginServerInitCallback() {}
132 0 : void MatterOvenCavityOperationalStatePluginServerInitCallback() {}
133 0 : void MatterDishwasherAlarmPluginServerInitCallback() {}
134 0 : void MatterMicrowaveOvenModePluginServerInitCallback() {}
135 0 : void MatterDeviceEnergyManagementModePluginServerInitCallback() {}
136 0 : void MatterEnergyEvseModePluginServerInitCallback() {}
137 0 : void MatterPowerTopologyPluginServerInitCallback() {}
138 0 : void MatterElectricalEnergyMeasurementPluginServerInitCallback() {}
139 0 : void MatterElectricalPowerMeasurementPluginServerInitCallback() {}
140 0 : void MatterServiceAreaPluginServerInitCallback() {}
141 0 : void MatterWaterHeaterManagementPluginServerInitCallback() {}
142 0 : void MatterWaterHeaterModePluginServerInitCallback() {}
143 :
144 0 : bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
145 : {
146 0 : return (emberAfGetServerAttributeIndexByAttributeId(endpoint, clusterId, attributeId) != UINT16_MAX);
147 : }
148 :
149 0 : bool emberAfIsKnownVolatileAttribute(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId)
150 : {
151 0 : const EmberAfAttributeMetadata * metadata = emberAfLocateAttributeMetadata(endpoint, clusterId, attributeId);
152 :
153 0 : if (metadata == nullptr)
154 : {
155 0 : return false;
156 : }
157 :
158 0 : return !metadata->IsAutomaticallyPersisted() && !metadata->IsExternal();
159 : }
|