Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adisuciu committed Jun 30, 2023
1 parent 21465c5 commit c81d3b7
Show file tree
Hide file tree
Showing 28 changed files with 359 additions and 166 deletions.
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ if(${WITH_PYTHON})
set(PYTHON_VERSION python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
endif()

option(SCOPY_DEV_MODE "Enable development specific scopy behavior - autoconnect to a context on start" FALSE)

configure_file(include/${SCOPY_MODULE}/${PROJECT_NAME}_config.h.cmakein
${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_config.h @ONLY)
set(SRC_LIST ${SRC_LIST} ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_config.h)
Expand Down
7 changes: 4 additions & 3 deletions core/include/core/deviceloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ class DeviceLoader : public QObject {
public:
DeviceLoader(DeviceImpl *d, QObject *parent = nullptr);
~DeviceLoader();
void init();
void init(bool async = threaded);
void asyncInit();
void syncInit();
Q_SIGNALS:
void initialized();

private:
DeviceImpl *d;
QObject *oldParent;
static constexpr bool threaded = false;

static constexpr bool threaded = true;
};
}

Expand Down
2 changes: 1 addition & 1 deletion core/include/core/devicemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SCOPY_CORE_EXPORT DeviceManager : public QObject
public Q_SLOTS:

void addDevice(Device *d);
QString createDevice(QString category, QString param);
QString createDevice(QString category, QString param, bool async = true);
void removeDevice(QString category, QString id);

void removeDeviceById(QString id);
Expand Down
1 change: 1 addition & 0 deletions core/include/core/scopy-core_config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

#cmakedefine WITH_PYTHON
#cmakedefine PYTHON_VERSION "@PYTHON_VERSION@"
#cmakedefine SCOPY_DEV_MODE

#endif // SCOPY_CORE_CONFIG_H_CMAKEIN
43 changes: 26 additions & 17 deletions core/src/deviceloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,36 @@ DeviceLoader::~DeviceLoader()

}

void DeviceLoader::init() {
if(threaded) {
QThread *th = QThread::create([=]{
// initializer thread
d->init();
});
oldParent = d->parent();
d->setParent(nullptr);
d->moveToThread(th);

connect(th,&QThread::destroyed, this,[=]() {;
void DeviceLoader::init(bool async) {
if(async) {
asyncInit();
} else {
syncInit();
}
}

void DeviceLoader::asyncInit()
{
QThread *th = QThread::create([=]{
// initializer thread
d->init();
});
oldParent = d->parent();
d->setParent(nullptr);
d->moveToThread(th);

connect(th,&QThread::destroyed, this,[=]() {;
// back to main thread
d->moveToThread(QThread::currentThread());
d->setParent(oldParent);
Q_EMIT initialized();
}, Qt::QueuedConnection);
connect(th,&QThread::finished, th, &QThread::deleteLater);
connect(th,&QThread::finished, th, &QThread::deleteLater);

th->start();
} else {
d->init();
Q_EMIT initialized();
}
th->start();
}

void DeviceLoader::syncInit() {
d->init();
Q_EMIT initialized();
}
4 changes: 2 additions & 2 deletions core/src/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DeviceManager::addDevice(Device* d) {
Q_EMIT deviceAdded(id, d);
}

QString DeviceManager::createDevice(QString category, QString param)
QString DeviceManager::createDevice(QString category, QString param, bool async)
{
qInfo(CAT_DEVICEMANAGER) <<category<< "device with params" << param << "added";
Q_EMIT deviceAddStarted(param);
Expand All @@ -52,7 +52,7 @@ QString DeviceManager::createDevice(QString category, QString param)

connect(dl, &DeviceLoader::initialized, this, [=](){addDevice(d);}); // add device to manager once it is initialized
connect(dl, &DeviceLoader::initialized, dl, &QObject::deleteLater); // don't forget to delete loader once we're done
dl->init();
dl->init(async);

return d->id();
}
Expand Down
14 changes: 9 additions & 5 deletions core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
connect(dm,SIGNAL(deviceChangedToolList(QString,QList<ToolMenuEntry*>)),toolman,SLOT(changeToolListContents(QString,QList<ToolMenuEntry*>)));
sbc->startScan();

// dm->createDevice("m2k","ip:127.0.0.1");
// auto id = dm->createDevice("iio","ip:10.48.65.163");
// auto id = dm->createDevice("iio","ip:192.168.2.1");
auto id = dm->createDevice("test","");
#ifdef SCOPY_DEV_MODE
// auto id = dm->createDevice("m2k","ip:127.0.0.1"), false;
// auto id = dm->createDevice("iio","ip:10.48.65.163", false);
// auto id = dm->createDevice("iio","ip:192.168.2.1", false);
auto id = dm->createDevice("test","", false);

auto d = dm->getDevice(id);
d->connectDev();
Q_EMIT tb->requestTool("tme_TestPlugin_test1second_2");
auto tool_id = dynamic_cast<DeviceImpl*>(d)->plugins()[0]->toolList()[0]->uuid();
Q_EMIT tb->requestTool(tool_id);
#endif



Expand Down
1 change: 0 additions & 1 deletion gr-util/include/gr-util/grtimechanneladdon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class SCOPY_GR_UTIL_EXPORT GRTimeChannelAddon : public QObject, public ToolAddon
Q_OBJECT
public:
GRTimeChannelAddon(GRSignalPath* path, GRTimePlotAddon* plotAddon, QObject *parent = nullptr);

~GRTimeChannelAddon();

QString getName() override;
Expand Down
2 changes: 1 addition & 1 deletion gr-util/include/gr-util/grtimeplotaddonsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SCOPY_GR_UTIL_EXPORT GRTimePlotAddonSettings : public QObject, public Tool
Q_OBJECT
public:
GRTimePlotAddonSettings(GRTimePlotAddon *p, QObject *parent = nullptr) :
QObject(parent),p(p) {
QObject(parent),p(p) {
name = p->getName()+"_settings";
widget = new QLabel(name);
}
Expand Down
4 changes: 4 additions & 0 deletions gr-util/include/gr-util/tooladdon.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class SCOPY_GR_UTIL_EXPORT ToolAddon {
virtual void onChannelRemoved(ToolAddon* ) = 0;
};
}

#define ToolAddon_iid "org.adi.Scopy.Plugins.ToolAddon/0.1"
Q_DECLARE_INTERFACE(scopy::ToolAddon, ToolAddon_iid)

#endif // TOOLADDON_H
2 changes: 1 addition & 1 deletion gr-util/src/grdeviceaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using namespace scopy::grutil;

GRDeviceAddon::GRDeviceAddon(GRIIODeviceSource *src, QObject *parent) {
GRDeviceAddon::GRDeviceAddon(GRIIODeviceSource *src, QObject *parent) : QObject(parent){
name = src->deviceName();
widget = new QLabel("devicename" + src->deviceName());
m_src = src;
Expand Down
2 changes: 1 addition & 1 deletion gr-util/src/grtimechanneladdon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using namespace scopy::grutil;

GRTimeChannelAddon::GRTimeChannelAddon(GRSignalPath *path, GRTimePlotAddon *plotAddon, QObject *parent) : m_plotAddon(plotAddon) {
GRTimeChannelAddon::GRTimeChannelAddon(GRSignalPath *path, GRTimePlotAddon *plotAddon, QObject *parent) : QObject(parent), m_plotAddon(plotAddon) {
this->ch = dynamic_cast<GRIIOChannel*>(path->path()[0]);
name = ch->getChannelName();
widget = new QLabel(name);
Expand Down
61 changes: 47 additions & 14 deletions gr-util/src/grtimeplotaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ GRTimePlotAddon::GRTimePlotAddon(QString name, GRTopBlock *top, QObject *parent)
QGridLayout *gridPlot = new QGridLayout(m_plotWidget);
gridPlot->setVerticalSpacing(0);
gridPlot->setHorizontalSpacing(0);
gridPlot->setContentsMargins(9, 0, 9, 0);
gridPlot->setContentsMargins(0, 0, 0, 0);
m_plotWidget->setLayout(gridPlot);

QSpacerItem *plotSpacer = new QSpacerItem(0, 5,
QSizePolicy::Fixed, QSizePolicy::Fixed);

gridPlot->addWidget(m_plot->topArea(), 1, 0, 1, 4);
gridPlot->addWidget(m_plot->leftHandlesArea(), 1, 0, 4, 1);
gridPlot->addWidget(m_plot, 3, 1, 1, 1);
gridPlot->addItem(plotSpacer, 5, 0, 1, 4);
gridPlot->addWidget(m_plot->topArea(), 0, 0, 1, 4);
gridPlot->addWidget(m_plot->leftHandlesArea(), 0, 0, 4, 1);
gridPlot->addWidget(m_plot, 1, 1, 1, 1);
gridPlot->addItem(plotSpacer, 2, 0, 1, 4);

m_plot->setSampleRate(1000, 1, "Hz");
m_plot->setActiveVertAxis(0);
Expand Down Expand Up @@ -81,30 +81,63 @@ void GRTimePlotAddon::onRemove() {}

void GRTimePlotAddon::onChannelAdded(ToolAddon *t) {
GRTimeChannelAddon *ch = dynamic_cast<GRTimeChannelAddon*>(t);
QString sinkName = (name + ch->getDevice()->getName() + t->getName());
bool ret = m_plot->registerSink(sinkName.toStdString(),1,0);
qInfo()<<"created plot_sinks "<<sinkName << ret;
QString sinkName = (name /*+ ch->getDevice()->getName() + t->getName()*/);
// m_plot->unregisterSink(sinkName.toStdString());
// bool ret = m_plot->registerSink(sinkName.toStdString(),1,0);
// qInfo()<<"created plot_sinks "<<sinkName << ret;
}

void GRTimePlotAddon::onChannelRemoved(ToolAddon *) {}

void GRTimePlotAddon::connectSignalPaths() {
QList<GRSignalPath*> sigpaths;
for(auto &sigpath : m_top->signalPaths()) {
qInfo()<<sigpath->name();
if(!sigpath->enabled())
continue;
if(!sigpath->name().startsWith(name))
continue;
sigpaths.append(sigpath);

auto sink = scope_sink_f::make(1024,1000,sigpath->name().toStdString(),1,m_plot);
sinks.append(sink);
sink->set_update_time(0.1);
sink->set_trigger_mode(TRIG_MODE_FREE,1,"");

qInfo()<<"created scope_sink_f with name" << sigpath->name();
m_top->connect(sigpath->getGrEndPoint(), 0, sink, 0);
m_plot->setAllYAxis(-1000000,1000000);

}
auto sink = scope_sink_f::make(1024,1000,name.toStdString(),sigpaths.count(),m_plot);
sinks.append(sink);
sink->set_update_time(0.01);
sink->set_trigger_mode(TRIG_MODE_FREE,1,"");
m_plot->registerSink(name.toStdString(),sigpaths.count(),0);
m_plot->setAllYAxis(-(1<<11),1<<11);

int i=0;
for(auto &sigpath : sigpaths) {
m_top->connect(sigpath->getGrEndPoint(), 0, sink, i);
i++;
}

for(int i=0;i<sigpaths.count();i++) {
auto curveId = m_plot->getAnalogChannels() - 1;
auto color = m_plot->getLineColor(curveId);
// btn->setColor(color);
m_plot->Curve(curveId)->setAxes(
QwtAxisId(QwtAxis::XBottom, 0),
QwtAxisId(QwtAxis::YLeft, curveId));
m_plot->DetachCurve(curveId);
m_plot->AttachCurve(curveId);
m_plot->addZoomer(curveId);


}
m_plot->setSampleRatelabelValue(1234);
m_plot->setBufferSizeLabelValue(4321);
m_plot->setTimeBaseLabelValue(12.5e-5);
// TO DO: Give user the option to make these axes visible
m_plot->setAxisVisible(QwtAxisId(QwtAxis::YLeft, 0), false);
m_plot->setAxisVisible(QwtAxisId(QwtAxis::XBottom,0), false);
// m_plot->setUsingLeftAxisScales(false);


}

void GRTimePlotAddon::tearDownSignalPaths() {
Expand Down
2 changes: 1 addition & 1 deletion gui/include/gui/DisplayPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class SCOPY_GUI_EXPORT EdgelessPlotScaleItem: public QwtPlotScaleItem
/*
* EdgelessPlotGrid class ensures that the first and last major ticks are ignored
*/
class EdgelessPlotGrid: public QwtPlotGrid
class SCOPY_GUI_EXPORT EdgelessPlotGrid: public QwtPlotGrid
{
public:
explicit EdgelessPlotGrid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
#include <QStyle>
#include <QPainter>

#include <scopy-testplugin_export.h>
#include <gui/utils.h>
#include <gui/dynamicWidget.h>
#include <gui/menu_anim.hpp>
#include <scopy-gui_export.h>
#include <utils.h>
#include <dynamicWidget.h>
#include <menu_anim.hpp>

#include <gui/semiexclusivebuttongroup.h>
#include <semiexclusivebuttongroup.h>
#include <QVBoxLayout>


namespace scopy {
class SCOPY_TESTPLUGIN_EXPORT StyleHelper : public QObject {
class SCOPY_GUI_EXPORT StyleHelper : public QObject {
Q_OBJECT
protected:
StyleHelper(QObject *parent = nullptr);
Expand Down Expand Up @@ -50,7 +50,7 @@ class SCOPY_TESTPLUGIN_EXPORT StyleHelper : public QObject {
};


class SCOPY_TESTPLUGIN_EXPORT VerticalChannelManager : public QWidget {
class SCOPY_GUI_EXPORT VerticalChannelManager : public QWidget {
Q_OBJECT
public:
VerticalChannelManager(QWidget *parent = nullptr) : QWidget(parent) {
Expand All @@ -77,7 +77,7 @@ class SCOPY_TESTPLUGIN_EXPORT VerticalChannelManager : public QWidget {



class SCOPY_TESTPLUGIN_EXPORT MenuControlButton : public QAbstractButton {
class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton {
Q_OBJECT
public:
typedef enum {
Expand Down Expand Up @@ -167,7 +167,7 @@ class SCOPY_TESTPLUGIN_EXPORT MenuControlButton : public QAbstractButton {
CheckboxStyle m_cs;
};

class SCOPY_TESTPLUGIN_EXPORT CollapsableMenuControlButton : public QWidget {
class SCOPY_GUI_EXPORT CollapsableMenuControlButton : public QWidget {
Q_OBJECT
public:
CollapsableMenuControlButton(QWidget *parent = nullptr) : QWidget(parent) {
Expand Down Expand Up @@ -212,7 +212,7 @@ class SCOPY_TESTPLUGIN_EXPORT CollapsableMenuControlButton : public QWidget {



class SCOPY_TESTPLUGIN_EXPORT PrintBtn : public QPushButton {
class SCOPY_GUI_EXPORT PrintBtn : public QPushButton {
Q_OBJECT
public:
PrintBtn(QWidget *parent = nullptr) : QPushButton(parent) {
Expand All @@ -221,7 +221,7 @@ class SCOPY_TESTPLUGIN_EXPORT PrintBtn : public QPushButton {
}
};

class SCOPY_TESTPLUGIN_EXPORT OpenLastMenuBtn : public QPushButton {
class SCOPY_GUI_EXPORT OpenLastMenuBtn : public QPushButton {
Q_OBJECT
public:
OpenLastMenuBtn(MenuAnim *menu, bool opened, QWidget *parent = nullptr) : QPushButton(parent), m_menu(menu) {
Expand Down Expand Up @@ -258,7 +258,7 @@ class SCOPY_TESTPLUGIN_EXPORT OpenLastMenuBtn : public QPushButton {
gui::SemiExclusiveButtonGroup *grp;
};

class SCOPY_TESTPLUGIN_EXPORT GearBtn : public QPushButton {
class SCOPY_GUI_EXPORT GearBtn : public QPushButton {
Q_OBJECT
public:
GearBtn(QWidget *parent = nullptr) : QPushButton(parent) {
Expand All @@ -269,7 +269,7 @@ class SCOPY_TESTPLUGIN_EXPORT GearBtn : public QPushButton {
}
};

class SCOPY_TESTPLUGIN_EXPORT InfoBtn : public QPushButton {
class SCOPY_GUI_EXPORT InfoBtn : public QPushButton {
Q_OBJECT
public:
InfoBtn(QWidget *parent = nullptr) : QPushButton(parent) {
Expand All @@ -281,7 +281,7 @@ class SCOPY_TESTPLUGIN_EXPORT InfoBtn : public QPushButton {
};


class SCOPY_TESTPLUGIN_EXPORT RunBtn : public QPushButton {
class SCOPY_GUI_EXPORT RunBtn : public QPushButton {
Q_OBJECT
public:
RunBtn (QWidget *parent = nullptr) : QPushButton(parent) {
Expand Down Expand Up @@ -325,7 +325,7 @@ class SCOPY_TESTPLUGIN_EXPORT RunBtn : public QPushButton {
}
};

class SCOPY_TESTPLUGIN_EXPORT SingleShotBtn : public QPushButton {
class SCOPY_GUI_EXPORT SingleShotBtn : public QPushButton {
Q_OBJECT
public:
SingleShotBtn (QWidget *parent = nullptr) : QPushButton(parent) {
Expand Down
Loading

0 comments on commit c81d3b7

Please sign in to comment.