set_absolute_volume.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include "vendor_packet.h"
  18. // TODO (apanicke): Set Absolute Volume request vs response have the same
  19. // packet structure, the only difference between the two is the CType.
  20. // Adding a passed flag as a parameter would be possible but I feel that
  21. // this would break the design pattern of request vs response. Look into
  22. // this for the future.
  23. namespace bluetooth {
  24. namespace avrcp {
  25. class SetAbsoluteVolumeRequestBuilder : public VendorPacketBuilder {
  26. public:
  27. virtual ~SetAbsoluteVolumeRequestBuilder() = default;
  28. static std::unique_ptr<SetAbsoluteVolumeRequestBuilder> MakeBuilder(
  29. uint8_t volume);
  30. virtual size_t size() const override;
  31. virtual bool Serialize(
  32. const std::shared_ptr<::bluetooth::Packet>& pkt) override;
  33. protected:
  34. uint8_t volume_;
  35. SetAbsoluteVolumeRequestBuilder(uint8_t volume)
  36. : VendorPacketBuilder(CType::CONTROL, CommandPdu::SET_ABSOLUTE_VOLUME,
  37. PacketType::SINGLE),
  38. volume_(volume){};
  39. };
  40. class SetAbsoluteVolumeResponse : public VendorPacket {
  41. public:
  42. virtual ~SetAbsoluteVolumeResponse() = default;
  43. /**
  44. * AVRCP Play Item Request Packet Layout
  45. * AvrcpPacket:
  46. * CType c_type_;
  47. * uint8_t subunit_type_ : 5;
  48. * uint8_t subunit_id_ : 3;
  49. * Opcode opcode_;
  50. * VendorPacket:
  51. * uint8_t company_id[3];
  52. * uint8_t command_pdu;
  53. * uint8_t packet_type;
  54. * uint16_t parameter_length;
  55. * SetAbsoluteVolumeResponse:
  56. * uint8_t volume;
  57. */
  58. static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 1; }
  59. uint8_t GetVolume() const;
  60. virtual bool IsValid() const override;
  61. virtual std::string ToString() const override;
  62. protected:
  63. using VendorPacket::VendorPacket;
  64. };
  65. } // namespace avrcp
  66. } // namespace bluetooth