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 17 #pragma once 18 19 #include <list> 20 #include <memory> 21 #include <vector> 22 23 #include "phy.h" 24 #include "phy_device.h" 25 26 namespace rootcanal { 27 28 using rootcanal::PhyDevice; 29 30 class PhyLayer { 31 public: 32 using Identifier = uint32_t; 33 34 PhyLayer(Identifier id, Phy::Type type); ~PhyLayer()35 virtual ~PhyLayer() {} 36 37 void Tick(); 38 virtual void Send(std::vector<uint8_t> const& packet, int8_t tx_power, 39 PhyDevice::Identifier sender_id); 40 41 // Compute the RSSI for a packet sent from one device to the other 42 // with the specified TX power. 43 virtual int8_t ComputeRssi(PhyDevice::Identifier sender_id, 44 PhyDevice::Identifier receiver_id, 45 int8_t tx_power); 46 47 void Register(std::shared_ptr<PhyDevice> device); 48 void Unregister(PhyDevice::Identifier device_id); 49 void UnregisterAll(); 50 51 std::string ToString() const; 52 53 // Id and type are public but immutable. 54 const Identifier id; 55 const Phy::Type type; 56 57 protected: 58 // List of devices currently connected to the phy. 59 std::list<std::shared_ptr<rootcanal::PhyDevice>> phy_devices_; 60 }; 61 62 } // namespace rootcanal 63