Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emu: add configurations for emulator #1677

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ target_link_libraries(
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SCOPY_DLL_INSTALL_PATH}
RUNTIME DESTINATION ${SCOPY_DLL_INSTALL_PATH}
)

file(COPY ${CMAKE_SOURCE_DIR}/resources/scopy_emu_options_config.json DESTINATION ${CMAKE_BINARY_DIR}/resources/)
file(GLOB EMU_FILES ${CMAKE_SOURCE_DIR}/resources/emuXml/*.xml)
foreach(_emu_file ${EMU_FILES})
file(COPY ${_emu_file} DESTINATION ${CMAKE_BINARY_DIR}/resources/emuXml/)
endforeach()
9 changes: 8 additions & 1 deletion core/include/core/emuwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ private Q_SLOTS:
bool startIioEmuProcess(QString processPath, QStringList arg = {});
void killEmuProcess();

void getEmuOptions();
void configureOption(QString option);
void getJsonConfiguration();

QWidget *m_emuWidget;
QComboBox *m_demoOptCb;
MenuLineEdit *m_xmlPathEdit;
Expand All @@ -57,7 +61,10 @@ private Q_SLOTS:
QString m_emuPath;
bool m_enableDemo;
QProcess *m_emuProcess;
const QStringList m_availableOptions{"adalm2000", "generic"};
QStringList m_availableOptions;

QString m_jsonConfigVal;
QString m_emuType = "generic";
};
} // namespace scopy

Expand Down
96 changes: 91 additions & 5 deletions core/src/emuwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <stylehelper.h>

#include <filesystem>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

Q_LOGGING_CATEGORY(CAT_EMU_ADD_PAGE, "EmuAddPage")
using namespace scopy;
Expand All @@ -26,6 +29,9 @@ EmuWidget::EmuWidget(QWidget *parent)
vLay->setMargin(0);
vWidget->setLayout(vLay);

getJsonConfiguration();
getEmuOptions();

m_emuWidget = new QWidget(vWidget);
QGridLayout *emuWidgetLay = new QGridLayout(m_emuWidget);
emuWidgetLay->setSpacing(10);
Expand Down Expand Up @@ -103,10 +109,18 @@ void EmuWidget::init()

void EmuWidget::enGenericOptWidget(QWidget *xmlPathWidget, QWidget *rxTxDevWidget, QString crtOpt)
{
bool isGeneric = crtOpt.contains("generic");
xmlPathWidget->setEnabled(isGeneric);
rxTxDevWidget->setEnabled(isGeneric);
// when a new option is selected clear all fields
m_xmlPathEdit->edit()->setText("");
m_rxTxDevEdit->edit()->setText("");
m_uriEdit->edit()->setText("");

bool isNotAdalm2000 = !crtOpt.contains("adalm2000");

xmlPathWidget->setEnabled(isNotAdalm2000);
rxTxDevWidget->setEnabled(isNotAdalm2000);
m_enDemoBtn->setFocus();

configureOption(crtOpt);
}

void EmuWidget::setStatusMessage(QString msg)
Expand Down Expand Up @@ -141,11 +155,13 @@ QStringList EmuWidget::createArgList()
{
QString option = m_demoOptCb->currentText();
QStringList arguments;
arguments.append(option);
if(option.compare("generic") == 0) {
arguments.append(m_emuType);

if(option.compare("adalm2000") != 0) {
IonutMuthi marked this conversation as resolved.
Show resolved Hide resolved
arguments.append(m_xmlPathEdit->edit()->text());
arguments.append(m_rxTxDevEdit->edit()->text());
}

return arguments;
}

Expand Down Expand Up @@ -194,6 +210,76 @@ void EmuWidget::killEmuProcess()
m_enableDemo = !m_enableDemo;
}

void EmuWidget::getEmuOptions()
{
// Populate emu devices from json
QJsonDocument d = QJsonDocument::fromJson(m_jsonConfigVal.toUtf8());
QJsonArray valuesList = d.array();

for(auto object : valuesList) {
QString device = object.toObject().value(QString("device")).toString();
m_availableOptions.append(device);
}
}

void EmuWidget::configureOption(QString option)
{
QJsonDocument d = QJsonDocument::fromJson(m_jsonConfigVal.toUtf8());
QJsonArray valuesList = d.array();

for(auto jsonArrayItem : valuesList) {
QJsonObject jsonObject = jsonArrayItem.toObject();
QString device = jsonObject.value(QString("device")).toString();
if(device == option) {
QString currentPath = QDir::currentPath();

if(jsonObject.contains("xml_path")) {
QString xmlPath = jsonObject.value(QString("xml_path")).toString();
m_xmlPathEdit->edit()->setText(currentPath + xmlPath);
}

if(jsonObject.contains("rx_tx_device")) {
QString rxTxDevice = jsonObject.value(QString("rx_tx_device")).toString();
rxTxDevice += "@";
rxTxDevice += currentPath;
rxTxDevice += jsonObject.value(QString("rx_tx_bin_path")).toString();
m_rxTxDevEdit->edit()->setText(rxTxDevice);
}

if(jsonObject.contains("uri")) {
QString uri = jsonObject.value(QString("uri")).toString();
m_uriEdit->edit()->setText(uri);
}

if(jsonObject.contains("emu-type")) {
m_emuType = jsonObject.value(QString("emu-type")).toString();
} else {
m_emuType = "generic";
}

break;
}
}
}

void EmuWidget::getJsonConfiguration()
{
QString currentPath = QDir::currentPath();
QString filePath = currentPath + "/resources/scopy_emu_options_config.json";
QFile file;

file.setFileName(filePath);

if(file.exists()) {
file.open(QIODevice::ReadOnly | QIODevice::Text);
m_jsonConfigVal = file.readAll();
file.close();
} else {
qWarning(CAT_EMU_ADD_PAGE) << "Emu configuration file is missing ";
m_availableOptions.append("generic");
}
}

void EmuWidget::browseFile(QLineEdit *lineEditPath)
{
QString filePath =
Expand Down
3 changes: 3 additions & 0 deletions plugins/pqm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
configureinstallersettings(${SCOPY_MODULE} ${INSTALLER_DESCRIPTION} TRUE)
endif()

file(COPY ${CMAKE_SOURCE_DIR}/plugins/pqm/res/pqm1.xml DESTINATION ${CMAKE_BINARY_DIR}/plugins/pqm/res/)
file(COPY ${CMAKE_SOURCE_DIR}/plugins/pqm/res/data.bin DESTINATION ${CMAKE_BINARY_DIR}/plugins/pqm/res/)

set(PQM_TARGET_NAME ${PROJECT_NAME} PARENT_SCOPE)
5 changes: 5 additions & 0 deletions plugins/swiot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
configureinstallersettings(${SCOPY_MODULE} ${INSTALLER_DESCRIPTION} TRUE)
endif()

file(GLOB EMU_FILES ${CMAKE_SOURCE_DIR}/plugins/swiot/res/emu_xml/*.xml)
foreach(_emu_file ${EMU_FILES})
file(COPY ${_emu_file} DESTINATION ${CMAKE_BINARY_DIR}/plugins/swiot/res/emu_xml/)
endforeach()

set(SWIOT_TARGET_NAME ${PROJECT_NAME} PARENT_SCOPE)
34 changes: 34 additions & 0 deletions resources/scopy_emu_options_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"device": "adalm2000",
"uri": "ip:127.0.0.1",
"emu-type": "adalm2000"
},
{
"device": "pluto",
"xml_path": "/resources/emuXml/pluto.xml",
"uri": "ip:127.0.0.1"
},
{
"device": "pqm",
"xml_path": "/plugins/pqm/res/pqm1.xml",
"uri": "ip:127.0.0.1",
"rx_tx_device":"iio:device0",
"rx_tx_bin_path": "/plugins/pqm/res/data.bin"
},
{
"device": "swiot_config",
"xml_path": "/plugins/swiot/res/emu_xml/config.xml",
"uri": "ip:127.0.0.1"
},
{
"device": "swiot_runtime",
"xml_path": "/plugins/swiot/res/emu_xml/runtime1.xml",
"uri": "ip:127.0.0.1"
},
{
"device": "generic",
"uri": "ip:127.0.0.1"
}

]
Loading