1 /* 2 * Copyright 2022 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 17 #pragma once 18 19 #include <cstdint> 20 #include <unordered_set> 21 22 #include "model/devices/device.h" 23 #include "phy.h" 24 25 namespace rootcanal { 26 27 class PhyLayer; 28 class Device; 29 30 class PhyDevice { 31 public: 32 using Identifier = uint32_t; 33 34 PhyDevice(std::string type, std::shared_ptr<Device> device); 35 PhyDevice(PhyDevice &&) = delete; 36 ~PhyDevice() = default; 37 38 void Register(PhyLayer* phy); 39 void Unregister(PhyLayer* phy); 40 41 void Tick(); 42 void Receive(std::vector<uint8_t> const& packet, Phy::Type type, int8_t rssi); 43 void Send(std::vector<uint8_t> const& packet, Phy::Type type, 44 int8_t tx_power); 45 46 bluetooth::hci::Address GetAddress() const; 47 std::shared_ptr<Device> GetDevice() const; 48 void SetAddress(bluetooth::hci::Address address); 49 std::string ToString(); 50 51 // Id and type are public but immutable. 52 const Identifier id; 53 const std::string type; 54 55 private: 56 const std::shared_ptr<Device> device_; 57 std::unordered_set<PhyLayer*> phy_layers_; 58 }; 59 60 } // namespace rootcanal 61