Skip to content

Commit ecc06e3

Browse files
committed
adrv9002: changes to assure cross platform functionality for cli tool
Signed-off-by: IonutMuthi <[email protected]>
1 parent 69f9e01 commit ecc06e3

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

packages/adrv9002/plugins/adrv9002plugin/src/profileclimanager.cpp

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include <profileclimanager.h>
22+
#include <QStandardPaths>
2223

2324
Q_LOGGING_CATEGORY(CAT_PROFILECLIMANAGER, "ProfileCliManager")
2425

@@ -60,24 +61,40 @@ QString ProfileCliManager::getCliPath() const { return m_cliPath; }
6061
// CLI Detection (based on iio-oscilloscope profile_gen_cli_get_cmd)
6162
bool ProfileCliManager::detectCli()
6263
{
63-
// Search for CLI tool in common locations
64-
QStringList searchPaths = {"/usr/bin/", "/usr/local/bin/", "/opt/analog/bin/",
65-
QCoreApplication::applicationDirPath() + "/", QDir::homePath() + "/.local/bin/"};
64+
QStringList searchPaths;
65+
// Search for CLI tool in common locations
66+
#ifdef Q_OS_WIN
67+
// Windows-specific paths
68+
searchPaths.append("C:/Program Files/Analog Devices/bin/");
69+
searchPaths.append("C:/Program Files (x86)/Analog Devices/bin/");
70+
searchPaths.append(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/");
71+
searchPaths.append(QCoreApplication::applicationDirPath() + "/");
72+
#else
73+
// Unix-like systems (Linux, macOS)
74+
searchPaths.append("/usr/bin/");
75+
searchPaths.append("/usr/local/bin/");
76+
searchPaths.append("/opt/analog/bin/");
77+
searchPaths.append(QCoreApplication::applicationDirPath() + "/");
78+
searchPaths.append(QDir::homePath() + "/.local/bin/");
79+
#endif
6680

6781
for(const QString &path : searchPaths) {
6882
QString fullPath = path + CLI_NAME;
83+
#ifdef Q_OS_WIN
84+
if(!fullPath.endsWith(".exe")) {
85+
fullPath += ".exe";
86+
}
87+
#endif
6988
if(QFile::exists(fullPath) && QFileInfo(fullPath).isExecutable()) {
70-
m_cliPath = fullPath;
89+
m_cliPath = QDir::toNativeSeparators(fullPath);
7190
return validateCliVersion();
7291
}
7392
}
7493

75-
// Also check PATH environment variable (like iio-oscilloscope)
76-
QProcess process;
77-
process.start("which", QStringList() << CLI_NAME);
78-
process.waitForFinished(3000);
79-
if(process.exitCode() == 0) {
80-
m_cliPath = process.readAllStandardOutput().trimmed();
94+
// Also check PATH environment variable
95+
QString pathResult = QStandardPaths::findExecutable(CLI_NAME);
96+
if(!pathResult.isEmpty()) {
97+
m_cliPath = QDir::toNativeSeparators(pathResult);
8198
return validateCliVersion();
8299
}
83100

@@ -347,10 +364,24 @@ bool ProfileCliManager::writeConfigToTempFile(const QString &filename, const Rad
347364
// CLI Execution
348365
bool ProfileCliManager::executeCli(const QStringList &arguments, QString &output, QString &errorOutput)
349366
{
367+
QString workingDir = QFileInfo(m_cliPath).absolutePath();
368+
350369
QProcess process;
351-
process.start(m_cliPath, arguments);
370+
process.setProgram(m_cliPath);
371+
process.setArguments(arguments);
372+
process.setWorkingDirectory(workingDir);
373+
process.start();
374+
375+
if(!process.waitForStarted(5000)) {
376+
errorOutput = QString("Failed to start CLI: %1").arg(process.errorString());
377+
return false;
378+
}
352379

353380
if(!process.waitForFinished(CLI_TIMEOUT_MS)) {
381+
process.kill();
382+
if(!process.waitForFinished(3000)) { // Give it time to cleanup
383+
process.terminate(); // Force terminate if kill didn't work
384+
}
354385
errorOutput = "CLI execution timeout";
355386
return false;
356387
}

0 commit comments

Comments
 (0)