CHIPDeviceManager.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @file
  19. * This file implements the CHIP Device Interface that is used by
  20. * applications to interact with the CHIP stack
  21. *
  22. */
  23. #include <stdlib.h>
  24. #include "CHIPDeviceManager.h"
  25. #include <app/ConcreteAttributePath.h>
  26. #include <app/util/basic-types.h>
  27. #include <app/util/config.h>
  28. #include <support/CHIPMem.h>
  29. #include <support/CodeUtils.h>
  30. #include <support/ErrorStr.h>
  31. #ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
  32. #include <app/clusters/identify-server/identify-server.h>
  33. #endif
  34. using namespace ::chip;
  35. using namespace ::chip::app;
  36. namespace chip {
  37. namespace DeviceManager {
  38. using namespace ::chip::DeviceLayer;
  39. void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
  40. {
  41. CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
  42. if (cb != nullptr)
  43. {
  44. cb->DeviceEventCallback(event, reinterpret_cast<intptr_t>(cb));
  45. }
  46. }
  47. CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
  48. {
  49. mCB = cb;
  50. PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
  51. return CHIP_NO_ERROR;
  52. }
  53. } // namespace DeviceManager
  54. } // namespace chip
  55. void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t type, uint16_t size, uint8_t * value)
  56. {
  57. chip::DeviceManager::CHIPDeviceManagerCallbacks * cb =
  58. chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks();
  59. ChipLogProgress(Zcl,
  60. "MatterPostAttributeChangeCallback - Cluster ID: " ChipLogFormatMEI
  61. ", EndPoint ID: '0x%02x', Attribute ID: " ChipLogFormatMEI,
  62. ChipLogValueMEI(path.mClusterId), path.mEndpointId, ChipLogValueMEI(path.mAttributeId));
  63. if (cb != nullptr)
  64. {
  65. cb->PostAttributeChangeCallback(path.mEndpointId, path.mClusterId, path.mAttributeId, type, size, value);
  66. }
  67. }
  68. #ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
  69. void OnIdentifyStart(Identify *)
  70. {
  71. ChipLogProgress(Zcl, "OnIdentifyStart");
  72. }
  73. void OnIdentifyStop(Identify *)
  74. {
  75. ChipLogProgress(Zcl, "OnIdentifyStop");
  76. }
  77. void OnTriggerEffect(Identify * identify)
  78. {
  79. switch (identify->mCurrentEffectIdentifier)
  80. {
  81. case Clusters::Identify::EffectIdentifierEnum::kBlink:
  82. ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBlink");
  83. break;
  84. case Clusters::Identify::EffectIdentifierEnum::kBreathe:
  85. ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBreathe");
  86. break;
  87. case Clusters::Identify::EffectIdentifierEnum::kOkay:
  88. ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kOkay");
  89. break;
  90. case Clusters::Identify::EffectIdentifierEnum::kChannelChange:
  91. ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kChannelChange");
  92. break;
  93. default:
  94. ChipLogProgress(Zcl, "No identifier effect");
  95. return;
  96. }
  97. }
  98. static Identify gIdentify1 = {
  99. chip::EndpointId{ 1 }, OnIdentifyStart, OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator,
  100. OnTriggerEffect,
  101. };
  102. #endif