Skip to content

Commit

Permalink
emu: add configurations for emulator
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Aug 13, 2024
1 parent a574686 commit 86fbd2e
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 6 deletions.
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()
8 changes: 7 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,9 @@ private Q_SLOTS:
QString m_emuPath;
bool m_enableDemo;
QProcess *m_emuProcess;
const QStringList m_availableOptions{"adalm2000", "generic"};
QStringList m_availableOptions;

QString m_jsonConfigVal;
};
} // namespace scopy

Expand Down
87 changes: 82 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,8 @@ EmuWidget::EmuWidget(QWidget *parent)
vLay->setMargin(0);
vWidget->setLayout(vLay);

getEmuOptions();

m_emuWidget = new QWidget(vWidget);
QGridLayout *emuWidgetLay = new QGridLayout(m_emuWidget);
emuWidgetLay->setSpacing(10);
Expand Down Expand Up @@ -103,10 +108,20 @@ 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();

if(isNotAdalm2000) {
configureOption(crtOpt);
}
}

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

if(option.compare("adalm2000") != 0) {
arguments.append("generic");
arguments.append(m_xmlPathEdit->edit()->text());
arguments.append(m_rxTxDevEdit->edit()->text());
} else {
arguments.append("adalm2000");
}
return arguments;
}
Expand Down Expand Up @@ -194,6 +212,65 @@ void EmuWidget::killEmuProcess()
m_enableDemo = !m_enableDemo;
}

void EmuWidget::getEmuOptions()
{
getJsonConfiguration();

// 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 object : valuesList) {
QString device = object.toObject().value(QString("device")).toString();
if(device == option) {
QString currentPath = QDir::currentPath();

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

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

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

break;
}
}
}

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

file.setFileName(filePath);
file.open(QIODevice::ReadOnly | QIODevice::Text);
m_jsonConfigVal = file.readAll();
file.close();
}

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)
23 changes: 23 additions & 0 deletions resources/scopy_emu_options_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"device": "adalm2000",
"uri": "ip:127.0.0.1"
},
{
"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": "generic",
"uri": "ip:127.0.0.1"
}

]

0 comments on commit 86fbd2e

Please sign in to comment.