Skip to content

Commit

Permalink
openmv: Improve responsiveness.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Nov 22, 2024
1 parent 3b3c4c9 commit bcc78d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions src/plugins/openmv/tools/driveserialnumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ extern QMutex dfu_util_working;

QString serialPortDriveSerialNumber(const QString &portName)
{
#if defined(Q_OS_WIN)
Utils::Process process;
std::chrono::seconds timeout(10);
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine);
process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("powershell")),
QStringList()
<< QStringLiteral("-Command")
<< QString(QStringLiteral("(Get-PnpDeviceProperty -InstanceId (Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -eq '%1' }).PNPDeviceId | Where-Object { $_.KeyName -eq 'DEVPKEY_Device_Parent' }).Data")).arg(QString(portName))));
process.runBlocking(timeout, Utils::EventLoopMode::Off);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
QRegularExpressionMatch match = QRegularExpression("\\\\(\\w+)$").match(process.stdOut().trimmed());
if (match.hasMatch()) return match.captured(1);
}
#elif (defined(Q_OS_LINUX) || defined(Q_OS_MAC))
// #if defined(Q_OS_WIN)
// Utils::Process process;
// std::chrono::seconds timeout(10);
// process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine);
// process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine);
// process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("powershell")),
// QStringList()
// << QStringLiteral("-Command")
// << QString(QStringLiteral("(Get-PnpDeviceProperty -InstanceId (Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -eq '%1' }).PNPDeviceId | Where-Object { $_.KeyName -eq 'DEVPKEY_Device_Parent' }).Data")).arg(QString(portName))));
// process.runBlocking(timeout, Utils::EventLoopMode::On);

// if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
// {
// QRegularExpressionMatch match = QRegularExpression("\\\\(\\w+)$").match(process.stdOut().trimmed());
// if (match.hasMatch()) return match.captured(1);
// }
// #elif (defined(Q_OS_LINUX) || defined(Q_OS_MAC))
MyQSerialPortInfo info = MyQSerialPortInfo(QSerialPortInfo(portName));
return info.serialNumber();
#endif
// #endif

return QString();
// return QString();
}

QString driveSerialNumber(const QString &drivePath)
Expand All @@ -48,7 +48,7 @@ QString driveSerialNumber(const QString &drivePath)
QStringList()
<< QStringLiteral("-Command")
<< QString(QStringLiteral("(Get-Disk -Number (Get-Partition -DriveLetter '%1').DiskNumber).SerialNumber")).arg(QString(drivePath).remove(QStringLiteral(":")).remove(QStringLiteral("/")))));
process.runBlocking(timeout, Utils::EventLoopMode::Off);
process.runBlocking(timeout, Utils::EventLoopMode::On);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand All @@ -67,7 +67,7 @@ QString driveSerialNumber(const QString &drivePath)
<< QStringLiteral("-J")
<< QStringLiteral("-o")
<< QStringLiteral("MOUNTPOINT,NAME,SERIAL")));
process.runBlocking(timeout, Utils::EventLoopMode::Off);
process.runBlocking(timeout, Utils::EventLoopMode::On);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand Down Expand Up @@ -114,7 +114,7 @@ QString driveSerialNumber(const QString &drivePath)
process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("system_profiler")), QStringList()
<< QStringLiteral("SPUSBDataType")
<< QStringLiteral("-json")));
process.runBlocking(timeout, Utils::EventLoopMode::Off);
process.runBlocking(timeout, Utils::EventLoopMode::On);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ QString driveSerialNumber(const QString &drivePath)
<< QStringLiteral("list")
<< QStringLiteral("-plist")
<< diskName));
process.runBlocking(timeout, Utils::EventLoopMode::Off);
process.runBlocking(timeout, Utils::EventLoopMode::On);

if (process.stdOut().contains(QString(QStringLiteral("<string>%1</string>")).arg(drivePath)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/openmv/tools/myqserialportinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ MyQSerialPortInfo::MyQSerialPortInfo(const QSerialPortInfo &info)
<< QStringLiteral("-v")
<< QStringLiteral("-d")
<< QString(QStringLiteral("%1:%2")).arg(m_vendorIdentifier, 4, 16, QLatin1Char('0')).arg(m_productIdentifier, 4, 16, QLatin1Char('0'))));
process.runBlocking(timeout, Utils::EventLoopMode::Off);
process.runBlocking(timeout, Utils::EventLoopMode::On);

if(process.result() == Utils::ProcessResult::FinishedWithSuccess)
{
Expand Down

0 comments on commit bcc78d4

Please sign in to comment.