3 * Copyright (c) 2020 Project CHIP Authors
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 * @file DeviceCallbacks.cpp
22 * Implements all the callbacks to the application from the CHIP Stack
25 #include "DeviceCallbacks.h"
27 #include "../gen/attribute-id.h"
28 #include "../gen/cluster-id.h"
29 #include "esp_heap_caps.h"
31 #include <support/CodeUtils.h>
33 static const char * TAG = "echo-devicecallbacks";
35 using namespace ::chip;
36 using namespace ::chip::Inet;
37 using namespace ::chip::System;
38 using namespace ::chip::DeviceLayer;
40 void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
44 case DeviceEventType::kInternetConnectivityChange:
45 OnInternetConnectivityChange(event);
48 case DeviceEventType::kSessionEstablished:
49 OnSessionEstablished(event);
53 ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
56 void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
57 uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value)
59 ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId,
60 endpointId, attributeId);
62 // TODO handle this callback in switch statement
63 ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId);
65 ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
68 void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
70 if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
72 ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
74 else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
76 ESP_LOGE(TAG, "Lost IPv4 connectivity...");
78 if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
80 ESP_LOGI(TAG, "IPv6 Server ready...");
82 else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
84 ESP_LOGE(TAG, "Lost IPv6 connectivity...");
88 void DeviceCallbacks::OnSessionEstablished(const ChipDeviceEvent * event)
90 if (event->SessionEstablished.IsCommissioner)
92 ESP_LOGI(TAG, "Commissioner detected!");