Loading tools/rootcanal/model/setup/test_model.cc +17 −7 Original line number Original line Diff line number Diff line Loading @@ -42,8 +42,10 @@ TestModel::TestModel( std::function<void(AsyncUserId)> cancel_tasks_from_user, std::function<void(AsyncUserId)> cancel_tasks_from_user, std::function<void(AsyncTaskId)> cancel, std::function<void(AsyncTaskId)> cancel, std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> connect_to_remote) connect_to_remote, : get_user_id_(std::move(get_user_id)), 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_task_(std::move(event_scheduler)), schedule_periodic_task_(std::move(periodic_event_scheduler)), schedule_periodic_task_(std::move(periodic_event_scheduler)), cancel_task_(std::move(cancel)), cancel_task_(std::move(cancel)), Loading Loading @@ -181,15 +183,23 @@ void TestModel::AddRemote(const std::string& server, int port, size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) { size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) { size_t index = Add(std::static_pointer_cast<Device>(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++) { for (size_t i = 0; i < phys_.size(); i++) { AddDeviceToPhy(index, i); AddDeviceToPhy(index, i); } } AsyncUserId user_id = get_user_id_(); AsyncUserId user_id = get_user_id_(); dev->RegisterTaskScheduler([user_id, this](std::chrono::milliseconds delay, dev->RegisterTaskScheduler([user_id, this](std::chrono::milliseconds delay, TaskCallback task_callback) { TaskCallback task_callback) { Loading tools/rootcanal/model/setup/test_model.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,9 @@ class TestModel { std::function<void(AsyncUserId)> cancel_user_tasks, std::function<void(AsyncUserId)> cancel_user_tasks, std::function<void(AsyncTaskId)> cancel, std::function<void(AsyncTaskId)> cancel, std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> 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(); virtual ~TestModel(); TestModel(TestModel& model) = delete; TestModel(TestModel& model) = delete; Loading Loading @@ -108,6 +110,10 @@ class TestModel { std::vector<std::shared_ptr<Device>> devices_; std::vector<std::shared_ptr<Device>> devices_; std::string list_string_; 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. // Callbacks to schedule tasks. std::function<AsyncUserId()> get_user_id_; std::function<AsyncUserId()> get_user_id_; std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, Loading Loading
tools/rootcanal/model/setup/test_model.cc +17 −7 Original line number Original line Diff line number Diff line Loading @@ -42,8 +42,10 @@ TestModel::TestModel( std::function<void(AsyncUserId)> cancel_tasks_from_user, std::function<void(AsyncUserId)> cancel_tasks_from_user, std::function<void(AsyncTaskId)> cancel, std::function<void(AsyncTaskId)> cancel, std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> connect_to_remote) connect_to_remote, : get_user_id_(std::move(get_user_id)), 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_task_(std::move(event_scheduler)), schedule_periodic_task_(std::move(periodic_event_scheduler)), schedule_periodic_task_(std::move(periodic_event_scheduler)), cancel_task_(std::move(cancel)), cancel_task_(std::move(cancel)), Loading Loading @@ -181,15 +183,23 @@ void TestModel::AddRemote(const std::string& server, int port, size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) { size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) { size_t index = Add(std::static_pointer_cast<Device>(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++) { for (size_t i = 0; i < phys_.size(); i++) { AddDeviceToPhy(index, i); AddDeviceToPhy(index, i); } } AsyncUserId user_id = get_user_id_(); AsyncUserId user_id = get_user_id_(); dev->RegisterTaskScheduler([user_id, this](std::chrono::milliseconds delay, dev->RegisterTaskScheduler([user_id, this](std::chrono::milliseconds delay, TaskCallback task_callback) { TaskCallback task_callback) { Loading
tools/rootcanal/model/setup/test_model.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,9 @@ class TestModel { std::function<void(AsyncUserId)> cancel_user_tasks, std::function<void(AsyncUserId)> cancel_user_tasks, std::function<void(AsyncTaskId)> cancel, std::function<void(AsyncTaskId)> cancel, std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> 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(); virtual ~TestModel(); TestModel(TestModel& model) = delete; TestModel(TestModel& model) = delete; Loading Loading @@ -108,6 +110,10 @@ class TestModel { std::vector<std::shared_ptr<Device>> devices_; std::vector<std::shared_ptr<Device>> devices_; std::string list_string_; 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. // Callbacks to schedule tasks. std::function<AsyncUserId()> get_user_id_; std::function<AsyncUserId()> get_user_id_; std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, Loading