diff --git a/BUILD.gn b/BUILD.gn index d389987140676e..534a0b7cffa267 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -40,6 +40,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/inet", "${chip_root}/src/lib", "${chip_root}/src/lib/core", + "${chip_root}/src/lib/datamodel", "${chip_root}/src/lib/shell", "${chip_root}/src/lib/support", "${chip_root}/src/lwip:all", @@ -73,6 +74,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/crypto/tests", "${chip_root}/src/inet/tests", "${chip_root}/src/lib/core/tests", + "${chip_root}/src/lib/datamodel/tests", "${chip_root}/src/lib/support/tests", "${chip_root}/src/lwip/tests", "${chip_root}/src/platform/tests", diff --git a/configure.ac b/configure.ac index b48c5c0761fa09..9c060bf0b7bb7b 100644 --- a/configure.ac +++ b/configure.ac @@ -2231,6 +2231,8 @@ src/inet/Makefile src/inet/tests/Makefile src/lib/Makefile src/lib/core/tests/Makefile +src/lib/datamodel/Makefile +src/lib/datamodel/tests/Makefile src/lib/shell/Makefile src/lib/shell/tests/Makefile src/lib/support/Makefile diff --git a/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp b/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp index 1428c770658635..a7fc7d89bd268f 100644 --- a/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp +++ b/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp @@ -25,6 +25,7 @@ #include "EchoDeviceCallbacks.h" #include "esp_log.h" +#include #include #include @@ -34,6 +35,7 @@ static const char * TAG = "echo-devicecallbacks"; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; +using namespace ::chip::DataModel; extern LEDWidget statusLED; // In wifi-echo.cpp @@ -70,22 +72,15 @@ void EchoDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, int } } +extern ClusterServer gServer; +/* This function can be eliminated, and instead its contents will get executed */ void EchoDeviceCallbacks::PostAttributeChangeCallback(uint8_t endpoint, ChipZclClusterId clusterId, ChipZclAttributeId attributeId, uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value) { - if (clusterId != CHIP_ZCL_CLUSTER_ON_OFF) - { - ESP_LOGI(TAG, "Unknown cluster ID: %d", clusterId); - return; - } - - if (attributeId != CHIP_ZCL_CLUSTER_ON_OFF_SERVER_ATTRIBUTE_ON_OFF) - { - ESP_LOGI(TAG, "Unknown attribute ID: %d", attributeId); - return; - } - ESP_LOGI(TAG, "Got the post attribute callback"); // At this point we can assume that value points to a boolean value. - statusLED.Set(*value); + Value cValue(kCHIPValueType_Bool); + memcpy((void *) &cValue.Int64, (void *) value, size); + + gServer.SetValue(endpoint, clusterId, attributeId, cValue); } diff --git a/examples/wifi-echo/server/esp32/main/LEDWidget.cpp b/examples/wifi-echo/server/esp32/main/LEDWidget.cpp index 502a4b0a4f1899..aef6e284162ded 100644 --- a/examples/wifi-echo/server/esp32/main/LEDWidget.cpp +++ b/examples/wifi-echo/server/esp32/main/LEDWidget.cpp @@ -31,6 +31,7 @@ #include "esp_log.h" #include "esp_system.h" #include "esp_timer.h" +#include #if CONFIG_HAVE_DISPLAY // The Y position of the LED Status message on screen as a @@ -46,7 +47,7 @@ static const char * onMsg = "LIGHT: ON"; static const char * offMsg = "LIGHT: OFF"; #endif - +using namespace ::chip::DataModel; extern const char * TAG; void LEDWidget::Init(gpio_num_t gpioNum) @@ -71,6 +72,19 @@ void LEDWidget::Set(bool state) { mBlinkOnTimeMS = mBlinkOffTimeMS = 0; DoSet(state); + Cluster::Set(kAttributeIdOnOff, ValueBool(state)); +} + +CHIP_ERROR LEDWidget::Set(uint16_t attrId, const Value & value) +{ + if (attrId == kAttributeIdOnOff) + { + printf("Setting value to %d\n", ValueToBool(value)); + DoSet(ValueToBool(value)); + /* Update our internal data model as well */ + Cluster::Set(attrId, value); + } + return CHIP_NO_ERROR; } void LEDWidget::Blink(uint32_t changeRateMS) diff --git a/examples/wifi-echo/server/esp32/main/include/LEDWidget.h b/examples/wifi-echo/server/esp32/main/include/LEDWidget.h index 9941845adfd61c..6eb98d2c0c2a80 100644 --- a/examples/wifi-echo/server/esp32/main/include/LEDWidget.h +++ b/examples/wifi-echo/server/esp32/main/include/LEDWidget.h @@ -27,12 +27,14 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/timers.h" +#include -class LEDWidget +class LEDWidget : public chip::DataModel::ClusterOnOff { public: void Init(gpio_num_t gpioNum); void Set(bool state); + int Set(uint16_t attrId, const chip::DataModel::Value & value); void Blink(uint32_t changeRateMS); void Blink(uint32_t onTimeMS, uint32_t offTimeMS); void BlinkOnError(); diff --git a/examples/wifi-echo/server/esp32/main/wifi-echo.cpp b/examples/wifi-echo/server/esp32/main/wifi-echo.cpp index 3410e1d12dd3db..e7f1710da29f01 100644 --- a/examples/wifi-echo/server/esp32/main/wifi-echo.cpp +++ b/examples/wifi-echo/server/esp32/main/wifi-echo.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ using namespace ::chip; using namespace ::chip::DeviceLayer; +using namespace ::chip::DataModel; extern void startServer(); @@ -104,6 +106,9 @@ LEDWidget statusLED; const char * TAG = "wifi-echo-demo"; static EchoDeviceCallbacks EchoCallbacks; +const uint8_t applicationVersion = 20; +const uint8_t HWVersion = 1; +ClusterServer gServer(applicationVersion, HWVersion); namespace { @@ -111,37 +116,37 @@ std::vector