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

Commit ea30334d authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "RootCanal: Add address prefix parameter to TestModel()" am: d441cb82 am: 0fd9d486

parents 0f66822a 0fd9d486
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -42,8 +42,10 @@ TestModel::TestModel(
    std::function<void(AsyncUserId)> cancel_tasks_from_user,
    std::function<void(AsyncTaskId)> cancel,
    std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)>
        connect_to_remote)
    : get_user_id_(std::move(get_user_id)),
        connect_to_remote,
    std::array<uint8_t, 5> bluetooth_address_prefix)
    : bluetooth_address_prefix_(std::move(bluetooth_address_prefix)),
      get_user_id_(std::move(get_user_id)),
      schedule_task_(std::move(event_scheduler)),
      schedule_periodic_task_(std::move(periodic_event_scheduler)),
      cancel_task_(std::move(cancel)),
@@ -181,15 +183,23 @@ void TestModel::AddRemote(const std::string& server, int port,

size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) {
  size_t index = Add(std::static_pointer_cast<Device>(dev));
  auto bluetooth_address = Address{{
      uint8_t(index),
      bluetooth_address_prefix_[4],
      bluetooth_address_prefix_[3],
      bluetooth_address_prefix_[2],
      bluetooth_address_prefix_[1],
      bluetooth_address_prefix_[0],
  }};
  dev->SetAddress(bluetooth_address);

  LOG_INFO("Initialized device with address %s",
           bluetooth_address.ToString().c_str());

  uint8_t raw[] = {0xda, 0x4c, 0x10, 0xde, 0x17, uint8_t(index)};  // Da HCI dev
  auto addr = Address{{raw[5], raw[4], raw[3], raw[2], raw[1], raw[0]}};
  dev->SetAddress(addr);

  LOG_INFO("initialized %s", addr.ToString().c_str());
  for (size_t i = 0; i < phys_.size(); i++) {
    AddDeviceToPhy(index, i);
  }

  AsyncUserId user_id = get_user_id_();
  dev->RegisterTaskScheduler([user_id, this](std::chrono::milliseconds delay,
                                             TaskCallback task_callback) {
+7 −1
Original line number Diff line number Diff line
@@ -48,7 +48,9 @@ class TestModel {
      std::function<void(AsyncUserId)> cancel_user_tasks,
      std::function<void(AsyncTaskId)> cancel,
      std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)>
          connect_to_remote);
          connect_to_remote,
      std::array<uint8_t, 5> bluetooth_address_prefix = {0xda, 0x4c, 0x10, 0xde,
                                                         0x17});
  virtual ~TestModel();

  TestModel(TestModel& model) = delete;
@@ -108,6 +110,10 @@ class TestModel {
  std::vector<std::shared_ptr<Device>> devices_;
  std::string list_string_;

  // Prefix used to generate public device addresses for hosts
  // connecting over TCP.
  std::array<uint8_t, 5> bluetooth_address_prefix_;

  // Callbacks to schedule tasks.
  std::function<AsyncUserId()> get_user_id_;
  std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds,