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

Part 1: feature/temperature measurement cluster #7026

Merged
merged 11 commits into from May 31, 2021
4 changes: 2 additions & 2 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t>(n * 100));
emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(1, static_cast<int16_t>(n * 100));
}
value = buffer;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ void SetupPretendDevices()
AddCluster("Thermometer");
AddAttribute("Temperature", "21");
// write the temp attribute
emberAfPluginTemperatureMeasurementSetValueCallback(1, static_cast<int16_t>(21 * 100));
emberAfTemperatureMeasurementClusterSetMeasuredValueCallback(1, static_cast<int16_t>(21 * 100));

AddDevice("Door Lock");
AddEndpoint("Default");
Expand Down
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,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 <app/util/af.h>
Expand All @@ -48,44 +25,46 @@
#include <app/util/af-event.h>
#include <app/util/attribute-storage.h>

#include <support/logging/CHIPLogging.h>

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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
9 changes: 1 addition & 8 deletions src/app/util/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down