Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / temperature-measurement-app / esp32 / main / DeviceCallbacks.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  * @file DeviceCallbacks.cpp
21  *
22  * Implements all the callbacks to the application from the CHIP Stack
23  *
24  **/
25 #include "DeviceCallbacks.h"
26
27 #include "../gen/attribute-id.h"
28 #include "../gen/cluster-id.h"
29 #include "esp_heap_caps.h"
30 #include "esp_log.h"
31 #include <support/CodeUtils.h>
32
33 static const char * TAG = "echo-devicecallbacks";
34
35 using namespace ::chip;
36 using namespace ::chip::Inet;
37 using namespace ::chip::System;
38 using namespace ::chip::DeviceLayer;
39
40 void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
41 {
42     switch (event->Type)
43     {
44     case DeviceEventType::kInternetConnectivityChange:
45         OnInternetConnectivityChange(event);
46         break;
47
48     case DeviceEventType::kSessionEstablished:
49         OnSessionEstablished(event);
50         break;
51     }
52
53     ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
54 }
55
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)
58 {
59     ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId,
60              endpointId, attributeId);
61
62     // TODO handle this callback in switch statement
63     ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId);
64
65     ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
66 }
67
68 void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
69 {
70     if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
71     {
72         ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
73     }
74     else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
75     {
76         ESP_LOGE(TAG, "Lost IPv4 connectivity...");
77     }
78     if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
79     {
80         ESP_LOGI(TAG, "IPv6 Server ready...");
81     }
82     else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
83     {
84         ESP_LOGE(TAG, "Lost IPv6 connectivity...");
85     }
86 }
87
88 void DeviceCallbacks::OnSessionEstablished(const ChipDeviceEvent * event)
89 {
90     if (event->SessionEstablished.IsCommissioner)
91     {
92         ESP_LOGI(TAG, "Commissioner detected!");
93     }
94 }