diff options
author | Ajay Panicker <apanicke@google.com> | 2018-03-28 16:02:36 -0700 |
---|---|---|
committer | Ajay Panicker <apanicke@google.com> | 2018-03-28 16:08:37 -0700 |
commit | a03a7724d6600723e6bb09fbb56dd37ceb7e8f90 (patch) | |
tree | ed4a723f94b36ac81ff51951958894d643bb03b0 /packet/avrcp | |
parent | eaacbe8f0b82cf05326adf293f07c5cb094e5461 (diff) | |
download | bt-a03a7724d6600723e6bb09fbb56dd37ceb7e8f90.tar.gz |
Add missing AVRCP Set Addressed Player Response
Bug: 77237301
Test: run host native tests net-test-btpackets and net-test-avrcp
Change-Id: Ic9a2c8d8cf5dd4c5be02a83975caa92e335ca2b9
Diffstat (limited to 'packet/avrcp')
-rw-r--r-- | packet/avrcp/Android.bp | 1 | ||||
-rw-r--r-- | packet/avrcp/avrcp_browse_packet.h | 5 | ||||
-rw-r--r-- | packet/avrcp/set_addressed_player.cc | 77 | ||||
-rw-r--r-- | packet/avrcp/set_addressed_player.h | 75 |
4 files changed, 155 insertions, 3 deletions
diff --git a/packet/avrcp/Android.bp b/packet/avrcp/Android.bp index 60271f011..728e32780 100644 --- a/packet/avrcp/Android.bp +++ b/packet/avrcp/Android.bp @@ -20,6 +20,7 @@ cc_library_static { "play_item.cc", "register_notification_packet.cc", "set_absolute_volume.cc", + "set_addressed_player.cc", "set_browsed_player.cc", "vendor_packet.cc", ], diff --git a/packet/avrcp/avrcp_browse_packet.h b/packet/avrcp/avrcp_browse_packet.h index f40deedc7..d62f0e24f 100644 --- a/packet/avrcp/avrcp_browse_packet.h +++ b/packet/avrcp/avrcp_browse_packet.h @@ -20,13 +20,12 @@ #include <base/macros.h> #include <iostream> +#include "avrcp_common.h" +#include "avrcp_logging_helper.h" #include "iterator.h" #include "packet.h" #include "packet_builder.h" -#include "avrcp_common.h" -#include "avrcp_logging_helper.h" - namespace bluetooth { namespace avrcp { diff --git a/packet/avrcp/set_addressed_player.cc b/packet/avrcp/set_addressed_player.cc new file mode 100644 index 000000000..f4b4dddb5 --- /dev/null +++ b/packet/avrcp/set_addressed_player.cc @@ -0,0 +1,77 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "set_addressed_player.h" + +namespace bluetooth { +namespace avrcp { + +std::unique_ptr<SetAddressedPlayerResponseBuilder> +SetAddressedPlayerResponseBuilder::MakeBuilder(Status status) { + std::unique_ptr<SetAddressedPlayerResponseBuilder> builder( + new SetAddressedPlayerResponseBuilder(status)); + + return builder; +} + +size_t SetAddressedPlayerResponseBuilder::size() const { + size_t len = VendorPacket::kMinSize(); + len += 1; // Status + return len; +} + +bool SetAddressedPlayerResponseBuilder::Serialize( + const std::shared_ptr<::bluetooth::Packet>& pkt) { + ReserveSpace(pkt, size()); + + PacketBuilder::PushHeader(pkt); + + VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize()); + + AddPayloadOctets1(pkt, (uint8_t)status_); + + return true; +} + +uint16_t SetAddressedPlayerRequest::GetPlayerId() const { + auto it = begin() + VendorPacket::kMinSize(); + return base::ByteSwap(it.extract<uint16_t>()); +} + +bool SetAddressedPlayerRequest::IsValid() const { + if (!VendorPacket::IsValid()) return false; + return size() == kMinSize(); +} + +std::string SetAddressedPlayerRequest::ToString() const { + std::stringstream ss; + ss << "SetAddressedPlayerRequest: " << std::endl; + ss << " └ cType = " << GetCType() << std::endl; + ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl; + ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl; + ss << " └ OpCode = " << GetOpcode() << std::endl; + ss << " └ Company ID = " << loghex(GetCompanyId()) << std::endl; + ss << " └ Command PDU = " << GetCommandPdu() << std::endl; + ss << " └ PacketType = " << GetPacketType() << std::endl; + ss << " └ Parameter Length = " << loghex(GetParameterLength()) << std::endl; + ss << " └ Player ID = " << loghex(GetPlayerId()) << std::endl; + ss << std::endl; + + return ss.str(); +} + +} // namespace avrcp +} // namespace bluetooth
\ No newline at end of file diff --git a/packet/avrcp/set_addressed_player.h b/packet/avrcp/set_addressed_player.h new file mode 100644 index 000000000..823411603 --- /dev/null +++ b/packet/avrcp/set_addressed_player.h @@ -0,0 +1,75 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "vendor_packet.h" + +namespace bluetooth { +namespace avrcp { + +class SetAddressedPlayerResponseBuilder : public VendorPacketBuilder { + public: + virtual ~SetAddressedPlayerResponseBuilder() = default; + + static std::unique_ptr<SetAddressedPlayerResponseBuilder> MakeBuilder( + Status status); + + virtual size_t size() const override; + virtual bool Serialize( + const std::shared_ptr<::bluetooth::Packet>& pkt) override; + + protected: + Status status_; + + SetAddressedPlayerResponseBuilder(Status status) + : VendorPacketBuilder(CType::ACCEPTED, CommandPdu::SET_ADDRESSED_PLAYER, + PacketType::SINGLE), + status_(status){}; +}; + +class SetAddressedPlayerRequest : public VendorPacket { + public: + virtual ~SetAddressedPlayerRequest() = default; + + /** + * Register Notificaiton Request Packet Layout + * AvrcpPacket: + * CType c_type_; + * uint8_t subunit_type_ : 5; + * uint8_t subunit_id_ : 3; + * Opcode opcode_; + * VendorPacket: + * uint8_t company_id[3]; + * uint8_t command_pdu; + * uint8_t packet_type; + * uint16_t param_length; + * SetAddressedPlayerRequest: + * uint16_t player_id; + */ + static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 2; } + + uint16_t GetPlayerId() const; + + virtual bool IsValid() const override; + virtual std::string ToString() const override; + + protected: + using VendorPacket::VendorPacket; +}; + +} // namespace avrcp +} // namespace bluetooth
\ No newline at end of file |