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

SWIOT Ad tool refactoring #1608

Merged
merged 3 commits into from
May 7, 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
8 changes: 8 additions & 0 deletions plugins/swiotrefactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ file(
src/max14906/*.cc
src/faults/*.cpp
src/faults/*.cc
src/ad74413r/*.cpp
src/ad74413r/*.cc
src/*.cpp
src/*.cc
src/config/*.cpp
src/config/*.cc
model/*
)

Expand All @@ -49,6 +53,10 @@ file(
include/${SCOPY_MODULE}/max14906/*.hpp
include/${SCOPY_MODULE}/faults/*.h
include/${SCOPY_MODULE}/faults/*.hpp
include/${SCOPY_MODULE}/ad74413r/*.h
include/${SCOPY_MODULE}/ad74413r/*.hpp
include/${SCOPY_MODULE}/config/*.h
include/${SCOPY_MODULE}/config/*.hpp
)
file(GLOB UI_LIST ui/*.ui)

Expand Down
160 changes: 160 additions & 0 deletions plugins/swiotrefactor/include/swiotrefactor/ad74413r/ad74413r.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef AD74413R_H
#define AD74413R_H

#include "bufferlogic.h"
#include "bufferacquisitionhandler.h"
#include "pluginbase/toolmenuentry.h"
#include "readerthread.h"

#include <iio.h>

#include <gui/mapstackedwidget.h>
#include <gui/widgets/toolbuttons.h>
#include <gui/tooltemplate.h>
#include <gui/widgets/menucontrolbutton.h>
#include <gui/plotaxis.h>

#include <QVector>
#include <QWidget>
#include <measurementpanel.h>
#include <plotinfo.h>
#include <spinbox_a.hpp>
andreidanila1 marked this conversation as resolved.
Show resolved Hide resolved

#include <iioutil/connection.h>
#define MAX_CURVES_NUMBER 8
#define AD_NAME "ad74413r"
#define SWIOT_DEVICE_NAME "swiot"
#define MAX_SAMPLE_RATE 4800

namespace scopy {

namespace swiotrefactor {
class Ad74413r : public QWidget
{
Q_OBJECT
public:
explicit Ad74413r(QString uri = "", ToolMenuEntry *tme = 0, QWidget *parent = nullptr);

~Ad74413r();

public Q_SLOTS:
void onRunBtnPressed(bool toggled);
void onSingleBtnPressed(bool toggled);

void onReaderThreadFinished();
void onSingleCaptureFinished();

void onDiagnosticFunctionUpdated();

void onActivateRunBtns(bool activate);

void handleConnectionDestroyed();

void onSamplingFrequencyUpdated(int channelId, int sampFreq);

Q_SIGNALS:
void broadcastThreshold();
void updateDiagSamplingFreq(QString data);
void activateRunBtns(bool activate);
void configBtnPressed();

private Q_SLOTS:
void onConfigBtnPressed();
void showPlotLabels(bool b);
void setupChannel(int chnlIdx, QString function);
void onSamplingFreqComputed(double freq);
void onBufferRefilled(QMap<int, QVector<double>> chnlData);
void onChannelBtnChecked(int chnWidgetId, bool en);
void samplingFreqWritten(bool written);
void onThresholdWritten(bool written);

private:
void init();
bool eventFilter(QObject *watched, QEvent *event) override;
void updateXData(int dataSize);
void plotData(QVector<double> curveData, int chnlIdx);
void createDevicesMap(iio_context *ctx);
void setupConnections();
void verifyChnlsChanges();
void initTutorialProperties();
void initPlotData();
void initPlot();
void setupToolTemplate();
void setupDeviceBtn();
void setupChannelBtn(MenuControlButton *btn, PlotChannel *ch, QString chnlId, int chnlIdx);
void setupMeasureButtonHelper(MenuControlButton *btn);
void setupChannelsMenuControlBtn(MenuControlButton *btn, QString name);
void updateMeasurements(PlotAxis *axis, int chnlIdx);
void createMeasurementsLabel(int chnlIdx, QPen chPen, QStringList labels);
QPushButton *createConfigBtn();
QWidget *createSettingsMenu(QWidget *parent);
PlotAxis *createYChnlAxis(QPen pen, QString unitType = "V", int yMin = -1, int yMax = 1);

private:
ToolMenuEntry *m_tme;
PositionSpinButton *m_timespanSpin;

QVector<bool> m_enabledChannels;

QString m_uri;

BufferLogic *m_swiotAdLogic;
ReaderThread *m_readerThread;
BufferAcquisitionHandler *m_acqHandler;
CommandQueue *m_cmdQueue;
MeasurementsPanel *m_measurePanel;

struct iio_context *m_ctx;
Connection *m_conn;

ToolTemplate *m_tool;
RunBtn *m_runBtn;
SingleShotBtn *m_singleBtn;
QPushButton *m_configBtn;
GearBtn *m_settingsBtn;
InfoBtn *m_infoBtn;

PlotWidget *m_plot;
TimePlotInfo *m_info;
PlotSamplingInfo m_currentSamplingInfo;
QMap<int, PlotChannel *> m_plotChnls;

QMap<QString, iio_device *> m_iioDevicesMap;
CollapsableMenuControlButton *m_devBtn;
MenuControlButton *m_chnlsMenuBtn;
QButtonGroup *m_rightMenuBtnGrp;
QButtonGroup *m_chnlsBtnGroup;

MapStackedWidget *m_channelStack;

int m_currentChannelSelected = 0;
QVector<double> m_xTime;
QMap<int, QList<MeasurementLabel *>> m_labels;

QTimer *m_rstAcqTimer;
const QString channelsMenuId = "channels";
const QString measureMenuId = "measure";
};
} // namespace swiotrefactor
} // namespace scopy
#endif // AD74413R_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef BUFFERACQUISITIONHANDLER_H
#define BUFFERACQUISITIONHANDLER_H

#include <QObject>
#include <qmutex.h>
#include <QMap>

namespace scopy::swiotrefactor {
#define DIAG_CHNLS_NUMBER 4
class BufferAcquisitionHandler : public QObject
{
Q_OBJECT
public:
BufferAcquisitionHandler(QObject *parent);
~BufferAcquisitionHandler();

void setSingleCapture(bool en);
void resetPlotParameters();
bool singleCapture() const;
int getRequiredBuffersNumber();
public Q_SLOTS:
void onBufferRefilled(QMap<int, QVector<double>> data, int bufferCounter);
void onTimespanChanged(double value);
void onSamplingFrequencyComputed(double samplingFrequency);
Q_SIGNALS:
void bufferDataReady(QMap<int, QVector<double>> data);
void singleCaptureFinished();

private:
void resetDataPoints();

double m_plotSamplingFreq = 4800;
double m_timespan = 1;

int m_buffersNumber = 0;
int m_bufferIndex = 0;
int m_bufferSize = 0;

bool m_singleCapture = false;

QMap<int, QVector<double>> m_dataPoints;
QMutex *m_lock;
};
} // namespace scopy::swiotrefactor

#endif // BUFFERACQUISITIONHANDLER_H
95 changes: 95 additions & 0 deletions plugins/swiotrefactor/include/swiotrefactor/ad74413r/bufferlogic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef BUFFERLOGIC_H
#define BUFFERLOGIC_H

#include "chnlinfo.h"

#include <iio.h>

#include <QMap>
#include <QObject>

#include <cerrno>
#include <iioutil/command.h>
#include <iioutil/commandqueue.h>

Q_DECLARE_OPAQUE_POINTER(struct iio_buffer *)

#define MAX_BUFFER_SIZE 160
#define MIN_BUFFER_SIZE 5
#define SAMPLING_FREQ_ATTR_NAME "sampling_frequency"
#define MAX_INPUT_CHNLS_NO 8

namespace scopy::swiotrefactor {
class BufferLogic : public QObject
{
Q_OBJECT
public:
explicit BufferLogic(QMap<QString, iio_device *> devicesMap, CommandQueue *commandQueue);

~BufferLogic();

QMap<QString, iio_channel *> getIioChnl(int chnlIdx);

bool verifyChannelsEnabledChanges(QVector<bool> enabledChnls);
void applyChannelsEnabledChanges(QVector<bool> enabledChnls);

void applySamplingFrequencyChanges(int channelId, int value);

int getPlotChnlsNo();
QString getPlotChnlUnitOfMeasure(int channel);
QVector<QString> getPlotChnlsUnitOfMeasure();
std::pair<int, int> getPlotChnlRangeValues(int channel);
QVector<std::pair<int, int>> getPlotChnlsRangeValues();
std::pair<double, double> getChnlOffsetScale(int channel);
QMap<int, QString> getPlotChnlsId();
void initAd74413rChnlsFunctions();
void initDiagnosticChannels();

Q_SIGNALS:
void chnlsChanged(QMap<int, swiotrefactor::ChnlInfo *> chnlsInfo);
void samplingFrequencyComputed(double value);
void channelFunctionDetermined(unsigned int i, QString function);
void instantValueChanged(int channel, double value);

private Q_SLOTS:
void enabledChnCmdFinished(unsigned int i, scopy::Command *cmd);
void configuredDevCmdFinished(unsigned int i, scopy::Command *cmd);
void chnFunctionCmdFinished(unsigned int i, scopy::Command *cmd);

private:
void createChannels();
void initChannelFunction(unsigned int i);
void computeSamplingFrequency();

private:
int m_plotChnlsNo;
QMap<QString, iio_device *> m_iioDevicesMap;
QMap<int, int> m_samplingFrequencies;
double m_samplingFrequency;

QMap<int, ChnlInfo *> m_chnlsInfo;
CommandQueue *m_commandQueue;
};
} // namespace scopy::swiotrefactor

#endif // BUFFERLOGIC_H
Loading
Loading