2 * Copyright 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "pass_through_packet.h"
22 std::unique_ptr<PassThroughPacketBuilder> PassThroughPacketBuilder::MakeBuilder(
23 bool response, bool pushed, uint8_t opperation_id) {
24 auto builder = std::unique_ptr<PassThroughPacketBuilder>(
25 new PassThroughPacketBuilder(response, pushed, opperation_id));
30 size_t PassThroughPacketBuilder::size() const {
31 return PassThroughPacket::kMinSize();
34 bool PassThroughPacketBuilder::Serialize(
35 const std::shared_ptr<::bluetooth::Packet>& pkt) {
36 ReserveSpace(pkt, size());
38 PacketBuilder::PushHeader(pkt);
40 uint8_t byte = opperation_id_ & 0b01111111;
41 if (!pushed_) byte |= 0b10000000;
42 AddPayloadOctets1(pkt, byte);
43 // Data length, for this packet it's always 0;
44 AddPayloadOctets1(pkt, 0x00);
49 KeyState PassThroughPacket::GetKeyState() const {
50 auto it = begin() + Packet::kMinSize();
51 return static_cast<KeyState>(((*it) & 0b10000000) >> 7);
54 uint8_t PassThroughPacket::GetOperationId() const {
55 return *(begin() + Packet::kMinSize()) & 0b01111111;
58 bool PassThroughPacket::IsValid() const { return size() == kMinSize(); }
60 std::string PassThroughPacket::ToString() const {
62 ss << "Avrcp::AvrcpPacket: " << std::endl;
63 ss << " └ cType = " << GetCType() << std::endl;
64 ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl;
65 ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl;
66 ss << " └ OpCode = " << GetOpcode() << std::endl;
67 ss << " └ Pushed = " << GetKeyState() << std::endl;
68 ss << " └ Opperation ID = " << loghex(GetOperationId()) << std::endl;
74 } // namespace bluetooth