Loading system/vendor_libs/test_vendor_lib/model/devices/beacon.cc +2 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,8 @@ void Beacon::Initialize(const vector<std::string>& args) { } void Beacon::TimerTick() { if (IsAdvertisementAvailable(std::chrono::milliseconds(5000))) { if (IsAdvertisementAvailable()) { last_advertisement_ = std::chrono::steady_clock::now(); std::unique_ptr<packets::LeAdvertisementBuilder> ad = packets::LeAdvertisementBuilder::Create( LeAdvertisement::AddressType::PUBLIC, static_cast<LeAdvertisement::AdvertisementType>(properties_.GetLeAdvertisementType()), Loading system/vendor_libs/test_vendor_lib/model/devices/device.cc +3 −11 Original line number Diff line number Diff line Loading @@ -50,17 +50,9 @@ void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) { } } bool Device::IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const { if (advertising_interval_ms_ == std::chrono::milliseconds(0)) return false; std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point last_interval = ((now - time_stamp_) / advertising_interval_ms_) * advertising_interval_ms_ + time_stamp_; std::chrono::steady_clock::time_point next_interval = last_interval + advertising_interval_ms_; return ((now + scan_time) >= next_interval); bool Device::IsAdvertisementAvailable() const { return (advertising_interval_ms_ > std::chrono::milliseconds(0)) && (std::chrono::steady_clock::now() >= last_advertisement_ + advertising_interval_ms_); } void Device::SendLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> to_send, Phy::Type phy_type) { Loading system/vendor_libs/test_vendor_lib/model/devices/device.h +4 −5 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ namespace test_vendor_lib { class Device { public: Device(const std::string properties_filename = "") : time_stamp_(std::chrono::steady_clock::now()), properties_(properties_filename) {} : last_advertisement_(std::chrono::steady_clock::now()), properties_(properties_filename) {} virtual ~Device() = default; // Initialize the device based on the values of |args|. Loading @@ -60,9 +60,8 @@ class Device { advertising_interval_ms_ = ms; } // Returns true if the host could see an advertisement in the next // |scan_time| milliseconds. virtual bool IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const; // Returns true if the host could see an advertisement about now. virtual bool IsAdvertisementAvailable() const; // Let the device know that time has passed. virtual void TimerTick() {} Loading @@ -80,7 +79,7 @@ class Device { protected: std::map<Phy::Type, std::vector<std::shared_ptr<PhyLayer>>> phy_layers_; std::chrono::steady_clock::time_point time_stamp_; std::chrono::steady_clock::time_point last_advertisement_; // The time between page scans. std::chrono::milliseconds page_scan_delay_ms_; Loading Loading
system/vendor_libs/test_vendor_lib/model/devices/beacon.cc +2 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,8 @@ void Beacon::Initialize(const vector<std::string>& args) { } void Beacon::TimerTick() { if (IsAdvertisementAvailable(std::chrono::milliseconds(5000))) { if (IsAdvertisementAvailable()) { last_advertisement_ = std::chrono::steady_clock::now(); std::unique_ptr<packets::LeAdvertisementBuilder> ad = packets::LeAdvertisementBuilder::Create( LeAdvertisement::AddressType::PUBLIC, static_cast<LeAdvertisement::AdvertisementType>(properties_.GetLeAdvertisementType()), Loading
system/vendor_libs/test_vendor_lib/model/devices/device.cc +3 −11 Original line number Diff line number Diff line Loading @@ -50,17 +50,9 @@ void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) { } } bool Device::IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const { if (advertising_interval_ms_ == std::chrono::milliseconds(0)) return false; std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point last_interval = ((now - time_stamp_) / advertising_interval_ms_) * advertising_interval_ms_ + time_stamp_; std::chrono::steady_clock::time_point next_interval = last_interval + advertising_interval_ms_; return ((now + scan_time) >= next_interval); bool Device::IsAdvertisementAvailable() const { return (advertising_interval_ms_ > std::chrono::milliseconds(0)) && (std::chrono::steady_clock::now() >= last_advertisement_ + advertising_interval_ms_); } void Device::SendLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> to_send, Phy::Type phy_type) { Loading
system/vendor_libs/test_vendor_lib/model/devices/device.h +4 −5 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ namespace test_vendor_lib { class Device { public: Device(const std::string properties_filename = "") : time_stamp_(std::chrono::steady_clock::now()), properties_(properties_filename) {} : last_advertisement_(std::chrono::steady_clock::now()), properties_(properties_filename) {} virtual ~Device() = default; // Initialize the device based on the values of |args|. Loading @@ -60,9 +60,8 @@ class Device { advertising_interval_ms_ = ms; } // Returns true if the host could see an advertisement in the next // |scan_time| milliseconds. virtual bool IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const; // Returns true if the host could see an advertisement about now. virtual bool IsAdvertisementAvailable() const; // Let the device know that time has passed. virtual void TimerTick() {} Loading @@ -80,7 +79,7 @@ class Device { protected: std::map<Phy::Type, std::vector<std::shared_ptr<PhyLayer>>> phy_layers_; std::chrono::steady_clock::time_point time_stamp_; std::chrono::steady_clock::time_point last_advertisement_; // The time between page scans. std::chrono::milliseconds page_scan_delay_ms_; Loading