Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43c90f2d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "test_vendor_lib: Simplify Beacon ad timing"

parents 16bb5582 a637f4be
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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()),
+3 −11
Original line number Diff line number Diff line
@@ -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) {
+4 −5
Original line number Diff line number Diff line
@@ -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|.
@@ -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() {}
@@ -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_;