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..43a7a83c7a163b 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,17 @@ void EchoDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, int } } +extern ClusterServer server; +/* 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); + printf("endpoint: %d, clusterId: %d, attrId: %d type: %d\n", endpoint, clusterId, attributeId, type); + Value cValue(kCHIPValueType_Bool); + memcpy((void *) &cValue.Int64, (void *) value, size); + printf("Value is %lld type is %d\n", cValue.Int64, type); + + server.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..0540d0fbe23cc2 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..f9e815ac390de9 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..69d83bd0aa8179 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,11 @@ LEDWidget statusLED; const char * TAG = "wifi-echo-demo"; static EchoDeviceCallbacks EchoCallbacks; +const uint8_t ZCLVersion = 10; +const uint8_t applicationVersion = 20; +const uint8_t stackVersion = 1; +const uint8_t HWVersion = 1; +ClusterServer server(ZCLVersion, applicationVersion, stackVersion, HWVersion); namespace { @@ -111,37 +118,37 @@ std::vector