Skip to content

Commit

Permalink
winusb: DriverHost_PX4: チューナーオープン処理のバグを修正
Browse files Browse the repository at this point in the history
同じチューナーを何度も開こうとして無限ループに陥ることのあるバグを修正

https://mevius.5ch.net/test/read.cgi/avi/1629554684/129
https://mevius.5ch.net/test/read.cgi/avi/1629554684/131
  • Loading branch information
nns779 committed Sep 9, 2021
1 parent 9e3483d commit cfe0712
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
19 changes: 3 additions & 16 deletions winusb/src/DriverHost_PX4/ctrl_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,12 @@ void CtrlServer::CtrlConnection::Worker() noexcept
}

px4::command::CtrlOpenCmd *open = reinterpret_cast<px4::command::CtrlOpenCmd *>(buf.get());
std::uint32_t data_id;

while (true) {
receiver = receiver_manager_.Search(open->receiver_info, info);
if (!receiver)
break;

if (receiver->Open())
continue;

std::uint32_t data_id;

if (!receiver_manager_.GenerateDataId(receiver, data_id)) {
receiver->Close();
continue;
}

receiver = receiver_manager_.SearchAndOpen(open->receiver_info, info, data_id);
if (receiver) {
open->receiver_info = info;
open->receiver_info.data_id = data_id;
break;
}

open->status = (receiver) ? px4::command::CtrlStatusCode::SUCCEEDED : px4::command::CtrlStatusCode::FAILED;
Expand Down
14 changes: 12 additions & 2 deletions winusb/src/DriverHost_PX4/receiver_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool ReceiverManager::Unregister(px4::ReceiverBase *receiver)

static GUID empty_guid = { 0 };

px4::ReceiverBase* ReceiverManager::Search(px4::command::ReceiverInfo &key, px4::command::ReceiverInfo &info)
px4::ReceiverBase* ReceiverManager::SearchAndOpen(px4::command::ReceiverInfo &key, px4::command::ReceiverInfo &info, std::uint32_t &data_id)
{
std::shared_lock<std::shared_mutex> lock(mtx_);

Expand Down Expand Up @@ -58,9 +58,19 @@ px4::ReceiverBase* ReceiverManager::Search(px4::command::ReceiverInfo &key, px4:
if ((key.index >= 0) && (key.index != k.index))
continue;

px4::ReceiverBase *r = it->first;

if (r->Open())
continue;

if (!GenerateDataId(r, data_id)) {
r->Close();
continue;
}

info = k;

return it->first;
return r;
}

return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion winusb/src/DriverHost_PX4/receiver_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReceiverManager final {

bool Register(px4::command::ReceiverInfo &info, px4::ReceiverBase *receiver);
bool Unregister(px4::ReceiverBase *receiver);
px4::ReceiverBase* Search(px4::command::ReceiverInfo &key, px4::command::ReceiverInfo &info);
px4::ReceiverBase* SearchAndOpen(px4::command::ReceiverInfo &key, px4::command::ReceiverInfo &info, std::uint32_t &data_id);
px4::ReceiverBase* SearchByDataId(std::uint32_t data_id);
bool GenerateDataId(px4::ReceiverBase *receiver, std::uint32_t &data_id);
void ClearDataId(px4::ReceiverBase *receiver);
Expand Down

0 comments on commit cfe0712

Please sign in to comment.