diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index fad81186e81789..35d5e2c8ae9611 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -195,7 +195,7 @@ class EditAttributeListModel : public ListScreen::Model if (name == "Temperature") { // update the temp attribute here for hardcoded endpoint 1 - emberAfPluginTemperatureMeasurementSetValueCallback(1, static_cast(n * 100)); + emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(1, static_cast(n * 100)); } value = buffer; } @@ -389,7 +389,7 @@ void SetupPretendDevices() AddCluster("Thermometer"); AddAttribute("Temperature", "21"); // write the temp attribute - emberAfPluginTemperatureMeasurementSetValueCallback(1, static_cast(21 * 100)); + emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(1, static_cast(21 * 100)); AddDevice("Door Lock"); AddEndpoint("Default"); diff --git a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp index 106f17fe1af924..6cb13aedfa9180 100644 --- a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp +++ b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp @@ -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. @@ -15,29 +15,6 @@ * limitations under the License. */ -/** - * - * Copyright (c) 2020 Silicon Labs - * - * 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 - * @brief Routines for the Temperature Measurement Server - *plugin. - ******************************************************************************* - ******************************************************************************/ - #include "temperature-measurement-server.h" #include @@ -48,44 +25,46 @@ #include #include +#include + using namespace chip; -EmberEventControl emberAfPluginTemperatureMeasurementServerReadEventControl; +#ifndef emberAfTemperatureMeasurementClusterPrintln +#define emberAfTemperatureMeasurementClusterPrintln(...) ChipLogProgress(Zcl, __VA_ARGS__); +#endif -// TODO: There's no header that declares this event handler, and it's not 100% -// clear where best to declare it. -// https://github.com/project-chip/connectedhomeip/issues/3619 -void emberAfPluginTemperatureMeasurementServerReadEventHandler() {} +EmberAfStatus emberAfTemperatureMeasurementClusterGetMeasuredValue(chip::EndpointId endpoint, int16_t * measuredValue) +{ + return emberAfReadServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) measuredValue, sizeof(*measuredValue)); +} -void emberAfPluginTemperatureMeasurementServerStackStatusCallback(EmberStatus status) {} +EmberAfStatus emberAfTemperatureMeasurementClusterGetMinMeasuredValue(chip::EndpointId endpoint, int16_t * minMeasuredValue) +{ + return emberAfReadServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MIN_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) minMeasuredValue, sizeof(*minMeasuredValue)); +} -// ------------------------------------------------------------------------- -// ****** callback section ******* +EmberAfStatus emberAfTemperatureMeasurementClusterGetMaxMeasuredValue(chip::EndpointId endpoint, int16_t * maxMeasuredValue) +{ + return emberAfReadServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MAX_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) maxMeasuredValue, sizeof(*maxMeasuredValue)); +} -void emberAfPluginTemperatureMeasurementServerInitCallback(void) +EmberAfStatus emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(chip::EndpointId endpoint, int16_t measuredValue) { - EmberAfStatus status; - // FIXME Use real values for the temperature sensor polling the sensor using the - // EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER_MAX_MEASUREMENT_FREQUENCY_S macro - EndpointId endpointId = 1; // Hardcoded to 1 for now - int16_t newValue = 0x1234; + return emberAfWriteServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) &measuredValue, ZCL_INT16S_ATTRIBUTE_TYPE); +} - status = emberAfWriteAttribute(endpointId, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_CURRENT_TEMPERATURE_ATTRIBUTE_ID, - CLUSTER_MASK_SERVER, (uint8_t *) &newValue, ZCL_INT16S_ATTRIBUTE_TYPE); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - emberAfTempMeasurementClusterPrint("Err: writing temperature: %x", status); - return; - } +EmberAfStatus emberAfTemperatureMeasurementClusterSetMinMeasuredValueCallback(chip::EndpointId endpoint, int16_t minMeasuredValue) +{ + return emberAfWriteServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MIN_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) &minMeasuredValue, ZCL_INT16S_ATTRIBUTE_TYPE); } -EmberAfStatus emberAfPluginTemperatureMeasurementSetValueCallback(EndpointId endpoint, int16_t value) +EmberAfStatus emberAfTemperatureMeasurementClusterSetMaxMeasuredValueCallback(chip::EndpointId endpoint, int16_t maxMeasuredValue) { - EmberAfStatus status = emberAfWriteAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_CURRENT_TEMPERATURE_ATTRIBUTE_ID, - CLUSTER_MASK_SERVER, (uint8_t *) &value, ZCL_INT16S_ATTRIBUTE_TYPE); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - emberAfTempMeasurementClusterPrint("Err: writing temperature: %x", status); - } - return status; + return emberAfWriteServerAttribute(endpoint, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_TEMP_MAX_MEASURED_VALUE_ATTRIBUTE_ID, + (uint8_t *) &maxMeasuredValue, ZCL_INT16S_ATTRIBUTE_TYPE); } diff --git a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.h b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.h index aea53760e63612..9a5c5999d6653b 100644 --- a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.h +++ b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.h @@ -27,4 +27,10 @@ * @param value Ver.: always * */ -EmberAfStatus emberAfPluginTemperatureMeasurementSetValueCallback(chip::EndpointId endpoint, int16_t value); +EmberAfStatus emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(chip::EndpointId endpoint, int16_t measuredValue); +EmberAfStatus emberAfTemperatureMeasurementClusterSetMinMeasuredValueCallback(chip::EndpointId endpoint, int16_t minMeasuredValue); +EmberAfStatus emberAfTemperatureMeasurementClusterSetMaxMeasuredValueCallback(chip::EndpointId endpoint, int16_t maxMeasuredValue); + +EmberAfStatus emberAfTemperatureMeasurementClusterGetMeasuredValue(chip::EndpointId endpoint, int16_t * measuredValue); +EmberAfStatus emberAfTemperatureMeasurementClusterGetMinMeasuredValue(chip::EndpointId endpoint, int16_t * minMeasuredValue); +EmberAfStatus emberAfTemperatureMeasurementClusterGetMaxMeasuredValue(chip::EndpointId endpoint, int16_t * maxMeasuredValue); diff --git a/src/app/util/DataModelHandler.cpp b/src/app/util/DataModelHandler.cpp index d9202fdc2aff42..b83ce8bb41494f 100644 --- a/src/app/util/DataModelHandler.cpp +++ b/src/app/util/DataModelHandler.cpp @@ -32,9 +32,6 @@ #ifdef EMBER_AF_PLUGIN_REPORTING_SERVER void emberAfPluginReportingStackStatusCallback(EmberStatus status); #endif -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER -void emberAfPluginTemperatureMeasurementServerStackStatusCallback(EmberStatus status); -#endif #ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status); #endif @@ -48,17 +45,13 @@ void InitDataModelHandler(chip::Messaging::ExchangeManager * exchangeManager) emberAfEndpointConfigure(); emberAfInit(exchangeManager); -#if defined(EMBER_AF_PLUGIN_REPORTING_SERVER) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \ - defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER) +#if defined(EMBER_AF_PLUGIN_REPORTING_SERVER) || defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER) EmberStatus status = EMBER_NETWORK_UP; #endif #ifdef EMBER_AF_PLUGIN_REPORTING_SERVER emberAfPluginReportingStackStatusCallback(status); #endif -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER - emberAfPluginTemperatureMeasurementServerStackStatusCallback(status); -#endif #ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER emberAfPluginIasZoneServerStackStatusCallback(status); #endif diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index ee3af8322b7fc6..baa2595416054a 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -133,9 +133,6 @@ uint8_t emAfExtendedPanId[EXTENDED_PAN_ID_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, }; -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER -void emberAfPluginTemperatureMeasurementServerInitCallback(void); -#endif #ifdef EMBER_AF_PLUGIN_BARRIER_CONTROL_SERVER void emberAfPluginBarrierControlServerInitCallback(void); #endif @@ -303,9 +300,6 @@ void emberAfInit(chip::Messaging::ExchangeManager * exchangeMgr) // Initialize the reporting plugin emberAfPluginReportingInitCallback(); -#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER - emberAfPluginTemperatureMeasurementServerInitCallback(); -#endif #ifdef EMBER_AF_PLUGIN_BARRIER_CONTROL_SERVER emberAfPluginBarrierControlServerInitCallback(); #endif