1 /* 2 * Copyright 2016 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 <chrono> 20 #include <cstdint> 21 #include <vector> 22 23 #include "device.h" 24 25 namespace rootcanal { 26 27 // Simple device that advertises with non-connectable advertising in general 28 // discoverable mode, and responds to LE scan requests. 29 class Beacon : public Device { 30 public: 31 Beacon(); 32 Beacon(const std::vector<std::string>& args); 33 virtual ~Beacon() = default; 34 Create(const std::vector<std::string> & args)35 static std::shared_ptr<Device> Create(const std::vector<std::string>& args) { 36 return std::make_shared<Beacon>(args); 37 } 38 GetTypeString()39 virtual std::string GetTypeString() const override { return "beacon"; } 40 41 virtual void Tick() override; 42 virtual void ReceiveLinkLayerPacket( 43 model::packets::LinkLayerPacketView packet, Phy::Type type, 44 int8_t rssi) override; 45 46 protected: 47 model::packets::LegacyAdvertisingType advertising_type_{}; 48 std::array<uint8_t, 31> advertising_data_{}; 49 std::array<uint8_t, 31> scan_response_data_{}; 50 std::chrono::steady_clock::duration advertising_interval_{}; 51 std::chrono::steady_clock::time_point advertising_last_{}; 52 53 private: 54 static bool registered_; 55 }; 56 57 } // namespace rootcanal 58