MatterCallbacks.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. *
  3. * Copyright (c) 2021 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. #pragma once
  19. #include "InteractiveServer.h"
  20. #include "Options.h"
  21. #include <app/ConcreteAttributePath.h>
  22. #include <app/ConcreteCommandPath.h>
  23. #include <lib/support/CodeUtils.h>
  24. #include <platform/CHIPDeviceLayer.h>
  25. #include <zap-generated/test/Commands.h>
  26. TestCommand * GetTargetTest()
  27. {
  28. const char * command = LinuxDeviceOptions::GetInstance().command;
  29. if (command == nullptr)
  30. {
  31. return nullptr;
  32. }
  33. static auto test = GetTestCommand(command);
  34. if (test.get() == nullptr)
  35. {
  36. ChipLogError(chipTool, "Specified test command does not exist: %s", command);
  37. PrintTestCommands();
  38. return nullptr;
  39. }
  40. const char * PICSFilePath = LinuxDeviceOptions::GetInstance().PICS;
  41. if (PICSFilePath != nullptr)
  42. {
  43. test->PICS.SetValue(PICSBooleanReader::Read(PICSFilePath));
  44. }
  45. return test.get();
  46. }
  47. void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath,
  48. const chip::Access::SubjectDescriptor & subjectDescriptor)
  49. {
  50. VerifyOrReturn(!InteractiveServer::GetInstance().Command(commandPath));
  51. auto test = GetTargetTest();
  52. VerifyOrReturn(test != nullptr && test->isRunning);
  53. ChipLogError(Zcl, "Receive command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Command: " ChipLogFormatMEI,
  54. commandPath.mEndpointId, ChipLogValueMEI(commandPath.mClusterId), ChipLogValueMEI(commandPath.mCommandId));
  55. test->CheckCommandPath(commandPath);
  56. }
  57. void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath)
  58. {
  59. VerifyOrReturn(!InteractiveServer::GetInstance().ReadAttribute(attributePath));
  60. auto test = GetTargetTest();
  61. VerifyOrReturn(test != nullptr && test->isRunning);
  62. ChipLogError(Zcl, "Receive READ attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI,
  63. attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId));
  64. test->CheckAttributePath(attributePath);
  65. }
  66. void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath)
  67. {
  68. VerifyOrReturn(!InteractiveServer::GetInstance().WriteAttribute(attributePath));
  69. auto test = GetTargetTest();
  70. VerifyOrReturn(test != nullptr && test->isRunning);
  71. ChipLogError(Zcl, "Receive WRITE attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI,
  72. attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId));
  73. test->CheckAttributePath(attributePath);
  74. }