From e8fb5fd5a7437888f0cb0cf7cb72d160022eddaa Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 11:34:10 -0500 Subject: [PATCH 001/147] add fieldline plugin folder to cmake in mne_scan --- src/applications/mne_scan/plugins/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 775c74dbf69..428ec8d8392 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,6 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) +add_subdirectory(fieldline) # Algorithm Plugin add_subdirectory(rtcmne) From 76920a07fd33896f1ab58f112eb9abfb818ebbc8 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 11:49:52 -0500 Subject: [PATCH 002/147] add initial structure plugin Fieldline --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 77 ++++++++++++++++++ .../plugins/fieldline/fieldline_global.cpp | 54 +++++++++++++ .../plugins/fieldline/fieldline_global.h | 81 +++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 src/applications/mne_scan/plugins/fieldline/CMakeLists.txt create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_global.h diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt new file mode 100644 index 00000000000..e1ca2afd007 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 3.14) +project(scan_fieldline LANGUAGES CXX) + +#Handle qt uic, moc, rrc automatically +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) + +set(SOURCES + # natus.cpp + fieldline_global.cpp + # natusproducer.cpp + # FormFiles/natussetup.cpp +) + +set(HEADERS + # natus.h + fieldline_global.h + # natusproducer.h + # FormFiles/natussetup.h +) + +set(FILE_TO_UPDATE fieldline_global.cpp) + +set(SOURCE_PATHS ${SOURCES}) +list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +set(FFTW_LIBS "") + +if(USE_FFTW) + if (WIN32) + set(FFTW_LIBS + ${FFTW_DIR_LIBS}/libfftw3-3.dll + ${FFTW_DIR_LIBS}/libfftw3f-3.dll + ${FFTW_DIR_LIBS}/libfftwf3l-3.dll + ) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) + elseif(UNIX AND NOT APPLE) + set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) + endif() +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC ../) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + mne_fs + mne_mne + mne_fwd + mne_inverse + mne_rtprocessing + mne_connectivity + mne_events + scDisp + scShared + scMeas + ${FFTW_LIBS}) + +target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}") + +if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) +endif() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp new file mode 100644 index 00000000000..2e691274c01 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp @@ -0,0 +1,54 @@ +//============================================================================================================= +/** + * @file fieldline_global.cpp + * @author Juan G Prieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Fieldline plugin global definitions. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "fieldline_global.h" + +//============================================================================================================= +// DEFINE METHODS +//============================================================================================================= + +const char* FIELDLINEPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} + +//============================================================================================================= + +const char* FIELDLINEPLUGIN::buildHash(){ return UTILSLIB::gitHash();} + +//============================================================================================================= + +const char* FIELDLINEPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.h b/src/applications/mne_scan/plugins/fieldline/fieldline_global.h new file mode 100644 index 00000000000..095072664a8 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.h @@ -0,0 +1,81 @@ +//============================================================================================================= +/** + * @file fieldlilne_global.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the Fieldline plugin library export/import macros. + * + */ + +#ifndef FIELDLINE_GLOBAL_H +#define FIELDLINE_GLOBAL_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// PREPROCESSOR DEFINES +//============================================================================================================= + +#if defined(SCAN_FIELDLINE_PLUGIN) +# define FIELDLINESHARED_EXPORT Q_DECL_EXPORT /**< Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library. */ +#else +# define FIELDLINESHARED_EXPORT Q_DECL_IMPORT /**< Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library. */ +#endif + +namespace FIELDLINEPLUGIN{ + +//============================================================================================================= +/** + * Returns build date and time. + */ +FIELDLINESHARED_EXPORT const char* buildDateTime(); + +//============================================================================================================= +/** + * Returns abbreviated build git hash. + */ +FIELDLINESHARED_EXPORT const char* buildHash(); + +//============================================================================================================= +/** + * Returns full build git hash. + */ +FIELDLINESHARED_EXPORT const char* buildHashLong(); } // namespace FIELDLINEPLUGIN + +#endif // FIELDLINE_GLOBAL_H From 3dd2832bf13b783384cbde6d66f131a9256daa76 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 13:15:29 -0500 Subject: [PATCH 003/147] add fieldline header file for the plugin --- .../mne_scan/plugins/CMakeLists.txt | 2 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 0 .../mne_scan/plugins/fieldline/fieldline.h | 185 ++++++++++++++++++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline.h diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 428ec8d8392..00959801da3 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -add_subdirectory(fieldline) +# add_subdirectory(fieldline) # Algorithm Plugin add_subdirectory(rtcmne) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h new file mode 100644 index 00000000000..93b9fb66232 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -0,0 +1,185 @@ +//============================================================================================================= +/** + * @file fieldline.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline plugin class. + * + */ + +#ifndef FIELDLINE_H +#define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= + +#include "fieldline_global.h" + +// #include +// #include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +// #include +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +// #include + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +namespace SCMEASLIB { + class RealTimeMultiSampleArray; +} + +namespace FIFFLIB { + class FiffInfo; +} + +//============================================================================================================= +// DEFINE NAMESPACE FIELDLINEPLUGIN +//============================================================================================================= + +namespace FIELDLINEPLUGIN +{ + +//============================================================================================================= +// FIELDLINEPLUGIN FORWARD DECLARATIONS +//============================================================================================================= + +// class FieldlineProducer; +// class FieldlineSetup; + +//============================================================================================================= +/** + * The Fieldline class provides a EEG connector for receiving data from Fieldline box through its Python API. + * + * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. + */ +class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces + Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + + // friend class FieldlineSetup; + +public: + //========================================================================================================= + /** + * Constructs a Fieldline. + */ + Fieldline(); + + //========================================================================================================= + /** + * Destroys the Fieldline. + */ + virtual ~Fieldline(); + + //========================================================================================================= + /** + * Clone the plugin + */ + virtual QSharedPointer clone() const; + + //========================================================================================================= + /** + * Initialise input and output connectors. + */ + virtual void init(); + + //========================================================================================================= + /** + * Is called when plugin is detached of the stage. Can be used to safe settings. + */ + virtual void unload(); + + //========================================================================================================= + /** + * Sets up the fiff info with the current data chosen by the user. + */ + void setUpFiffInfo(); + + //========================================================================================================= + /** + * Starts the Fieldline by starting the tmsi's thread. + */ + virtual bool start(); + + //========================================================================================================= + /** + * Stops the Fieldline by stopping the tmsi's thread. + */ + virtual bool stop(); + + virtual AbstractPlugin::PluginType getType() const; + virtual QString getName() const; + virtual QWidget* setupWidget(); + virtual QString getBuildInfo(); + +protected: + //========================================================================================================= + /** + * Call this function whenenver you received new data. + * + * @param[in] matData The new data. + */ + void onNewDataAvailable(const Eigen::MatrixXd &matData); + + //========================================================================================================= + /** + * The starting point for the thread. After calling start(), the newly created thread calls this function. + * Returning from this method will end the execution of the thread. + * Pure virtual method inherited by QThread. + */ + virtual void run(); + + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the GUI (in Hertz).*/ + int m_iNumberChannels; /**< The number of channels to be received.*/ + int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + + QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + + QThread m_pProducerThread; /**< The thread used to host the producer.*/ + QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + + QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ +}; + +} // namespace FIELDLINEPLUGIN + +#endif // FIELDLINE_H From f8cfe073d9276fc2f717675423ba7cfa60b0dbcc Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 22:42:02 -0500 Subject: [PATCH 004/147] activate fieldline plugin --- src/applications/mne_scan/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 00959801da3..428ec8d8392 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -# add_subdirectory(fieldline) +add_subdirectory(fieldline) # Algorithm Plugin add_subdirectory(rtcmne) From ee60b525bb06cf8c2398ef7d05dc9116cd57972f Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 16 Feb 2023 13:20:58 -0500 Subject: [PATCH 005/147] fieldline plugin adapting --- .../mne_scan/mne_scan/mainwindow.cpp | 61 ---- .../mne_scan/plugins/fieldline/CMakeLists.txt | 4 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 318 ++++++++++++++++++ .../mne_scan/plugins/fieldline/fieldline.h | 38 +-- 4 files changed, 338 insertions(+), 83 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index ec6f3a67a09..0f5f53a84a8 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -594,67 +594,6 @@ void MainWindow::createMenus() if(!m_pMenuFile) { m_pMenuFile = menuBar()->addMenu(tr("&File")); m_pMenuFile->addAction(m_pActionNewConfig); - m_pMenuFile->addAction(m_pActionOpenConfig); - m_pMenuFile->addAction(m_pActionSaveConfig); - m_pMenuFile->addSeparator(); - m_pMenuFile->addAction(m_pActionExit); - } - - // View menu - if(!m_pMenuView) { - m_pMenuView = menuBar()->addMenu(tr("&View")); - } - - m_pMenuView->clear(); - - if(m_pDockWidget_Log) { - m_pMenuView->addAction(m_pDockWidget_Log->toggleViewAction()); - } - m_pMenuLgLv = m_pMenuView->addMenu(tr("&Log Level")); - m_pMenuLgLv->addAction(m_pActionMinLgLv); - m_pMenuLgLv->addAction(m_pActionNormLgLv); - m_pMenuLgLv->addAction(m_pActionMaxLgLv); - m_pMenuView->addSeparator(); - - if(m_pPluginGuiDockWidget) { - m_pMenuView->addAction(m_pPluginGuiDockWidget->toggleViewAction()); - } - - for(int i = 0; i < m_qListDynamicDisplayMenuActions.size(); ++i) { - m_pMenuView->addAction(m_qListDynamicDisplayMenuActions.at(i)); - } - - menuBar()->addSeparator(); - - // Help Appearance - if(!m_pMenuAppearance) { - m_pMenuAppearance = menuBar()->addMenu(tr("&Appearance")); - m_pMenuAppearance->addMenu("Styles")->addActions(m_pActionStyleGroup->actions()); - m_pMenuAppearance->addMenu("Modes")->addActions(m_pActionModeGroup->actions()); - } - - // Help menu - if(!m_pMenuHelp) { - m_pMenuHelp = menuBar()->addMenu(tr("&Help")); - m_pMenuHelp->addAction(m_pActionHelpContents); - m_pMenuHelp->addSeparator(); - m_pMenuHelp->addAction(m_pActionAbout); - } -} - -//============================================================================================================= - -void MainWindow::createToolBars() -{ - //Control - if(!m_pToolBar) { - m_pToolBar = addToolBar(tr("Control")); - m_pToolBar->addAction(m_pActionRun); - m_pToolBar->addAction(m_pActionStop); - m_pActionStop->setEnabled(false); - - m_pToolBar->addSeparator(); - m_pLabelTime = new QLabel(this); m_pToolBar->addWidget(m_pLabelTime); m_pLabelTime->setText(QTime(0, 0).toString()); diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index e1ca2afd007..f534ceed23f 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,15 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurren find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) set(SOURCES - # natus.cpp fieldline_global.cpp + fieldline.cpp # natusproducer.cpp # FormFiles/natussetup.cpp ) set(HEADERS - # natus.h fieldline_global.h + fieldline.h # natusproducer.h # FormFiles/natussetup.h ) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index e69de29bb2d..8694084190e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -0,0 +1,318 @@ +//============================================================================================================= +/** + * @file fieldline.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline class. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "fieldline.h" +// #include "fieldlineproducer.h" +// #include "FormFiles/fieldlinesetup.h" + +// #include +// #include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +using namespace FIELDLINEPLUGIN; +// using namespace SCSHAREDLIB; +// using namespace SCMEASLIB; +// using namespace FIFFLIB; +// using namespace Eigen; +// using namespace UTILSLIB; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +Fieldline::Fieldline() +: m_iSamplingFreq(2048) +, m_iNumberChannels(46) +, m_iSamplesPerBlock(256) +, m_qStringResourcePath(qApp->applicationDirPath()+"/resources/mne_scan/plugins/fieldline/") +, m_pRMTSA_Fieldline(PluginOutputData::create(this, "Fieldline", "EEG output data")) +, m_pFiffInfo(QSharedPointer::create()) +{ + m_pRMTSA_Fieldline->measurementData()->setName(this->getName());//Provide name to auto store widget settings +} + +//============================================================================================================= + +Fieldline::~Fieldline() { + // If the program is closed while the sampling is in process + if(this->isRunning()) { + this->stop(); + } +} + +//============================================================================================================= + +QSharedPointer Fieldline::clone() const +{ + QSharedPointer pFieldline(new Fieldline()); + return pFieldlineClone; +} + +//============================================================================================================= + +void Fieldline::init() +{ + m_outputConnectors.append(m_pRMTSA_Natus); +} + +//============================================================================================================= + +void Fieldline::unload() +{ +} + +//============================================================================================================= + +void Fieldline::setUpFiffInfo() +{ + //Clear old fiff info data + m_pFiffInfo->clear(); + + //Set number of channels, sampling frequency and high/-lowpass + m_pFiffInfo->nchan = m_iNumberChannels; + m_pFiffInfo->sfreq = m_iSamplingFreq; + m_pFiffInfo->highpass = 0.001f; + m_pFiffInfo->lowpass = m_iSamplingFreq/2; + + //Set up the channel info + QStringList QSLChNames; + m_pFiffInfo->chs.clear(); + + for(int i = 0; i < m_pFiffInfo->nchan; ++i) + { + //Create information for each channel + QString sChType; + FiffChInfo fChInfo; + +// //EEG Channels +// if(i <= m_pFiffInfo->nchan-2) +// { + //Set channel name + sChType = QString("EEG "); + if(i<10) { + sChType.append("00"); + } + + if(i>=10 && i<100) { + sChType.append("0"); + } + + fChInfo.ch_name = sChType.append(sChType.number(i)); + + //Set channel type + fChInfo.kind = FIFFV_EEG_CH; + + //Set logno + fChInfo.logNo = i; + + //Set coord frame + fChInfo.coord_frame = FIFFV_COORD_HEAD; + + //Set unit + fChInfo.unit = FIFF_UNIT_V; + + //Set EEG electrode location - Convert from mm to m + fChInfo.eeg_loc(0,0) = 0; + fChInfo.eeg_loc(1,0) = 0; + fChInfo.eeg_loc(2,0) = 0; + + //Set EEG electrode direction - Convert from mm to m + fChInfo.eeg_loc(0,1) = 0; + fChInfo.eeg_loc(1,1) = 0; + fChInfo.eeg_loc(2,1) = 0; + + //Also write the eeg electrode locations into the meg loc variable (mne_ex_read_raw() matlab function wants this) + fChInfo.chpos.r0(0) = 0; + fChInfo.chpos.r0(1) = 0; + fChInfo.chpos.r0(2) = 0; + + fChInfo.chpos.ex(0) = 1; + fChInfo.chpos.ex(1) = 0; + fChInfo.chpos.ex(2) = 0; + + fChInfo.chpos.ey(0) = 0; + fChInfo.chpos.ey(1) = 1; + fChInfo.chpos.ey(2) = 0; + + fChInfo.chpos.ez(0) = 0; + fChInfo.chpos.ez(1) = 0; + fChInfo.chpos.ez(2) = 1; +// } + +// //Digital input channel +// if(i == m_pFiffInfo->nchan-1) +// { +// //Set channel type +// fChInfo.kind = FIFFV_STIM_CH; + +// sChType = QString("STIM"); +// fChInfo.ch_name = sChType; +// } + + QSLChNames << sChType; + + m_pFiffInfo->chs.append(fChInfo); + } + + //Set channel names in fiff_info_base + m_pFiffInfo->ch_names = QSLChNames; + + //Set head projection + m_pFiffInfo->dev_head_t.from = FIFFV_COORD_DEVICE; + m_pFiffInfo->dev_head_t.to = FIFFV_COORD_HEAD; + m_pFiffInfo->ctf_head_t.from = FIFFV_COORD_DEVICE; + m_pFiffInfo->ctf_head_t.to = FIFFV_COORD_HEAD; +} + +//============================================================================================================= + +bool Fieldline::start() +{ + // Init circular buffer to transmit data from the producer to this thread + if(!m_pCircularBuffer) { + m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); + } + + //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA + setUpFiffInfo(); + + //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime + m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + + QThread::start(); + + // Start the producer + m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); + m_pNatusProducer->moveToThread(&m_pProducerThread); + connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + m_pProducerThread.start(); + + return true; +} + +//============================================================================================================= + +bool Fieldline::stop() +{ + requestInterruption(); + wait(500); + + // Clear all data in the buffer connected to displays and other plugins + m_pRMTSA_Natus->measurementData()->clear(); + m_pCircularBuffer->clear(); + + m_pProducerThread.quit(); + m_pProducerThread.wait(); + + return true; +} + +//============================================================================================================= + +AbstractPlugin::PluginType Fieldline::getType() const +{ + return _ISensor; +} + +//============================================================================================================= + +QString Fieldline::getName() const +{ + return "Natus EEG"; +} + +//============================================================================================================= + +QWidget* Fieldline::setupWidget() +{ + NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new + + //init properties dialog + widget->initGui(); + + return widget; +} + +//============================================================================================================= + +void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) +{ + while(!m_pCircularBuffer->push(matData)) { + //Do nothing until the circular buffer is ready to accept new data again + } +} + +//============================================================================================================= + +void Fieldline::run() +{ + MatrixXd matData; + + while(!isInterruptionRequested()) { + if(m_pCircularBuffer->pop(matData)) { + //emit values + if(!isInterruptionRequested()) { + m_pRMTSA_Natus->measurementData()->setValue(matData); + } + } + } +} + +//============================================================================================================= + +QString Fieldline::getBuildInfo() +{ + return QString(NATUSPLUGIN::buildDateTime()) + QString(" - ") + QString(NATUSPLUGIN::buildHash()); +} + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 93b9fb66232..cdba732a587 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -38,8 +38,8 @@ #include "fieldline_global.h" -// #include -// #include +#include +#include //============================================================================================================= // QT INCLUDES @@ -52,26 +52,24 @@ // EIGEN INCLUDES //============================================================================================================= -// #include +#include //============================================================================================================= // FORWARD DECLARATIONS //============================================================================================================= namespace SCMEASLIB { - class RealTimeMultiSampleArray; +class RealTimeMultiSampleArray; } - namespace FIFFLIB { - class FiffInfo; +class FiffInfo; } //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN //============================================================================================================= -namespace FIELDLINEPLUGIN -{ +namespace FIELDLINEPLUGIN { //============================================================================================================= // FIELDLINEPLUGIN FORWARD DECLARATIONS @@ -89,9 +87,9 @@ namespace FIELDLINEPLUGIN class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { Q_OBJECT - Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + // Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces - Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + // Q_INTERFACES(SCSHAREDLIB::AbstractSensor) // friend class FieldlineSetup; @@ -160,24 +158,24 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor //========================================================================================================= /** - * The starting point for the thread. After calling start(), the newly created thread calls this function. - * Returning from this method will end the execution of the thread. - * Pure virtual method inherited by QThread. + * the starting point for the thread. after calling start(), the newly created thread calls this function. + * returning from this method will end the execution of the thread. + * pure virtual method inherited by qthread. */ virtual void run(); - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the GUI (in Hertz).*/ - int m_iNumberChannels; /**< The number of channels to be received.*/ - int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + int m_iNumberChannels; /**< The number of channels to be received.*/ + int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - QThread m_pProducerThread; /**< The thread used to host the producer.*/ - QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From fc7817b6e26b4f7ea98394a68ecad4cfea6e2bb7 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 15:20:55 -0500 Subject: [PATCH 006/147] improve indentation cmakelists --- src/applications/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/applications/CMakeLists.txt b/src/applications/CMakeLists.txt index 950bcc5060c..025af9078bd 100644 --- a/src/applications/CMakeLists.txt +++ b/src/applications/CMakeLists.txt @@ -5,12 +5,12 @@ if(WIN32) endif() if(APPLE) - set(CMAKE_INSTALL_RPATH "@executable_path/../lib") + set(CMAKE_INSTALL_RPATH "@executable_path/../lib") if(NOT BUILD_MAC_APP_BUNDLE) set(CMAKE_MACOSX_RPATH TRUE) endif() else() - set(CMAKE_INSTALL_RPATH "\${ORIGIN}/../lib") + set(CMAKE_INSTALL_RPATH "\${ORIGIN}/../lib") endif() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) From 9bc494a94aa06d3554008524ada54b2d26c50708 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 16:48:57 -0500 Subject: [PATCH 007/147] add .sessions to gitignore --- .gitignore | 1 + .../mne_scan/mne_scan/mainwindow.cpp | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/.gitignore b/.gitignore index bcfb6110f26..554fc837ada 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ *.so.debug *.debug +.session # Compiled Static libraries *.lai *.la diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index 0f5f53a84a8..ec6f3a67a09 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -594,6 +594,67 @@ void MainWindow::createMenus() if(!m_pMenuFile) { m_pMenuFile = menuBar()->addMenu(tr("&File")); m_pMenuFile->addAction(m_pActionNewConfig); + m_pMenuFile->addAction(m_pActionOpenConfig); + m_pMenuFile->addAction(m_pActionSaveConfig); + m_pMenuFile->addSeparator(); + m_pMenuFile->addAction(m_pActionExit); + } + + // View menu + if(!m_pMenuView) { + m_pMenuView = menuBar()->addMenu(tr("&View")); + } + + m_pMenuView->clear(); + + if(m_pDockWidget_Log) { + m_pMenuView->addAction(m_pDockWidget_Log->toggleViewAction()); + } + m_pMenuLgLv = m_pMenuView->addMenu(tr("&Log Level")); + m_pMenuLgLv->addAction(m_pActionMinLgLv); + m_pMenuLgLv->addAction(m_pActionNormLgLv); + m_pMenuLgLv->addAction(m_pActionMaxLgLv); + m_pMenuView->addSeparator(); + + if(m_pPluginGuiDockWidget) { + m_pMenuView->addAction(m_pPluginGuiDockWidget->toggleViewAction()); + } + + for(int i = 0; i < m_qListDynamicDisplayMenuActions.size(); ++i) { + m_pMenuView->addAction(m_qListDynamicDisplayMenuActions.at(i)); + } + + menuBar()->addSeparator(); + + // Help Appearance + if(!m_pMenuAppearance) { + m_pMenuAppearance = menuBar()->addMenu(tr("&Appearance")); + m_pMenuAppearance->addMenu("Styles")->addActions(m_pActionStyleGroup->actions()); + m_pMenuAppearance->addMenu("Modes")->addActions(m_pActionModeGroup->actions()); + } + + // Help menu + if(!m_pMenuHelp) { + m_pMenuHelp = menuBar()->addMenu(tr("&Help")); + m_pMenuHelp->addAction(m_pActionHelpContents); + m_pMenuHelp->addSeparator(); + m_pMenuHelp->addAction(m_pActionAbout); + } +} + +//============================================================================================================= + +void MainWindow::createToolBars() +{ + //Control + if(!m_pToolBar) { + m_pToolBar = addToolBar(tr("Control")); + m_pToolBar->addAction(m_pActionRun); + m_pToolBar->addAction(m_pActionStop); + m_pActionStop->setEnabled(false); + + m_pToolBar->addSeparator(); + m_pLabelTime = new QLabel(this); m_pToolBar->addWidget(m_pLabelTime); m_pLabelTime->setText(QTime(0, 0).toString()); From e8f4104d1b232cd7fc26f97f497f36c75a0fbb88 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 20:50:20 -0500 Subject: [PATCH 008/147] create fieldline plugin --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 46 +-- .../mne_scan/plugins/fieldline/fieldline.cpp | 269 +++++------------- .../mne_scan/plugins/fieldline/fieldline.h | 62 ++-- .../mne_scan/plugins/fieldline/fieldline.json | 1 + src/libraries/CMakeLists.txt | 4 +- 5 files changed, 142 insertions(+), 240 deletions(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline.json diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f534ceed23f..f7c6772cbda 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -6,28 +6,35 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(QT NAMES Qt6 Qt5 REQUIRED + COMPONENTS Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED + COMPONENTS Core Widgets Network Concurrent) set(SOURCES fieldline_global.cpp fieldline.cpp - # natusproducer.cpp - # FormFiles/natussetup.cpp ) set(HEADERS fieldline_global.h fieldline.h - # natusproducer.h - # FormFiles/natussetup.h ) set(FILE_TO_UPDATE fieldline_global.cpp) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) + message("File fieldline.json exists.") +else() + message("File fieldline.json does not exist.") + message("Creating a new fieldline.json file.") + execute_process(COMMAND "echo ") +endif() + set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") -set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES + OBJECT_DEPENDS "${SOURCE_PATHS}") add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) @@ -57,21 +64,26 @@ target_link_libraries(${PROJECT_NAME} PRIVATE eigen mne_disp mne_utils - mne_fiff - mne_fs - mne_mne - mne_fwd - mne_inverse - mne_rtprocessing - mne_connectivity - mne_events + # mne_fiff + # mne_fs + # mne_mne + # mne_fwd + # mne_inverse + # mne_rtprocessing + # mne_connectivity + # mne_events scDisp scShared scMeas ${FFTW_LIBS}) -target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}") +target_compile_definitions(${PROJECT_NAME} PRIVATE + SCAN_FIELDLINE_PLUGIN + MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" +) if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) + target_compile_definitions(${PROJECT_NAME} PRIVATE + STATICBUILD QT_STATICPLUGIN) endif() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 8694084190e..36b6f2e1e79 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -38,6 +38,7 @@ //============================================================================================================= #include "fieldline.h" + // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -49,6 +50,7 @@ //============================================================================================================= // #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -58,261 +60,146 @@ // USED NAMESPACES //============================================================================================================= -using namespace FIELDLINEPLUGIN; -// using namespace SCSHAREDLIB; -// using namespace SCMEASLIB; -// using namespace FIFFLIB; -// using namespace Eigen; -// using namespace UTILSLIB; +namespace FIELDLINEPLUGIN { //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() -: m_iSamplingFreq(2048) -, m_iNumberChannels(46) -, m_iSamplesPerBlock(256) -, m_qStringResourcePath(qApp->applicationDirPath()+"/resources/mne_scan/plugins/fieldline/") -, m_pRMTSA_Fieldline(PluginOutputData::create(this, "Fieldline", "EEG output data")) -, m_pFiffInfo(QSharedPointer::create()) -{ - m_pRMTSA_Fieldline->measurementData()->setName(this->getName());//Provide name to auto store widget settings +Fieldline::Fieldline() { + } //============================================================================================================= Fieldline::~Fieldline() { // If the program is closed while the sampling is in process - if(this->isRunning()) { - this->stop(); - } + // if(this->isRunning()) { + // this->stop(); + // } } //============================================================================================================= -QSharedPointer Fieldline::clone() const -{ - QSharedPointer pFieldline(new Fieldline()); +QSharedPointer Fieldline::clone() const { + QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } //============================================================================================================= -void Fieldline::init() -{ - m_outputConnectors.append(m_pRMTSA_Natus); -} - -//============================================================================================================= +void Fieldline::init() { -void Fieldline::unload() -{ + // m_outputConnectors.append(m_pRMTSA_Natus); } //============================================================================================================= -void Fieldline::setUpFiffInfo() -{ - //Clear old fiff info data - m_pFiffInfo->clear(); - - //Set number of channels, sampling frequency and high/-lowpass - m_pFiffInfo->nchan = m_iNumberChannels; - m_pFiffInfo->sfreq = m_iSamplingFreq; - m_pFiffInfo->highpass = 0.001f; - m_pFiffInfo->lowpass = m_iSamplingFreq/2; - - //Set up the channel info - QStringList QSLChNames; - m_pFiffInfo->chs.clear(); - - for(int i = 0; i < m_pFiffInfo->nchan; ++i) - { - //Create information for each channel - QString sChType; - FiffChInfo fChInfo; - -// //EEG Channels -// if(i <= m_pFiffInfo->nchan-2) -// { - //Set channel name - sChType = QString("EEG "); - if(i<10) { - sChType.append("00"); - } - - if(i>=10 && i<100) { - sChType.append("0"); - } - - fChInfo.ch_name = sChType.append(sChType.number(i)); - - //Set channel type - fChInfo.kind = FIFFV_EEG_CH; - - //Set logno - fChInfo.logNo = i; - - //Set coord frame - fChInfo.coord_frame = FIFFV_COORD_HEAD; - - //Set unit - fChInfo.unit = FIFF_UNIT_V; - - //Set EEG electrode location - Convert from mm to m - fChInfo.eeg_loc(0,0) = 0; - fChInfo.eeg_loc(1,0) = 0; - fChInfo.eeg_loc(2,0) = 0; - - //Set EEG electrode direction - Convert from mm to m - fChInfo.eeg_loc(0,1) = 0; - fChInfo.eeg_loc(1,1) = 0; - fChInfo.eeg_loc(2,1) = 0; - - //Also write the eeg electrode locations into the meg loc variable (mne_ex_read_raw() matlab function wants this) - fChInfo.chpos.r0(0) = 0; - fChInfo.chpos.r0(1) = 0; - fChInfo.chpos.r0(2) = 0; - - fChInfo.chpos.ex(0) = 1; - fChInfo.chpos.ex(1) = 0; - fChInfo.chpos.ex(2) = 0; - - fChInfo.chpos.ey(0) = 0; - fChInfo.chpos.ey(1) = 1; - fChInfo.chpos.ey(2) = 0; - - fChInfo.chpos.ez(0) = 0; - fChInfo.chpos.ez(1) = 0; - fChInfo.chpos.ez(2) = 1; -// } - -// //Digital input channel -// if(i == m_pFiffInfo->nchan-1) -// { -// //Set channel type -// fChInfo.kind = FIFFV_STIM_CH; - -// sChType = QString("STIM"); -// fChInfo.ch_name = sChType; -// } - - QSLChNames << sChType; - - m_pFiffInfo->chs.append(fChInfo); - } - - //Set channel names in fiff_info_base - m_pFiffInfo->ch_names = QSLChNames; - - //Set head projection - m_pFiffInfo->dev_head_t.from = FIFFV_COORD_DEVICE; - m_pFiffInfo->dev_head_t.to = FIFFV_COORD_HEAD; - m_pFiffInfo->ctf_head_t.from = FIFFV_COORD_DEVICE; - m_pFiffInfo->ctf_head_t.to = FIFFV_COORD_HEAD; +void Fieldline::unload() { + } //============================================================================================================= -bool Fieldline::start() -{ - // Init circular buffer to transmit data from the producer to this thread - if(!m_pCircularBuffer) { - m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); - } - - //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA - setUpFiffInfo(); - - //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime - m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); +bool Fieldline::start() { - QThread::start(); - - // Start the producer - m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); - m_pNatusProducer->moveToThread(&m_pProducerThread); - connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - m_pProducerThread.start(); + // Init circular buffer to transmit data from the producer to this thread + // if(!m_pCircularBuffer) { + // m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); + // } + // + // //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA + // setUpFiffInfo(); + // + // //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime + // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + // + // QThread::start(); + // + // // Start the producer + // m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); + // m_pNatusProducer->moveToThread(&m_pProducerThread); + // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + // m_pProducerThread.start(); return true; } //============================================================================================================= -bool Fieldline::stop() -{ - requestInterruption(); - wait(500); - - // Clear all data in the buffer connected to displays and other plugins - m_pRMTSA_Natus->measurementData()->clear(); - m_pCircularBuffer->clear(); +bool Fieldline::stop() { - m_pProducerThread.quit(); - m_pProducerThread.wait(); + // requestInterruption(); + // wait(500); + // + // // Clear all data in the buffer connected to displays and other plugins + // m_pRMTSA_Natus->measurementData()->clear(); + // m_pCircularBuffer->clear(); + // + // m_pProducerThread.quit(); + // m_pProducerThread.wait(); return true; } //============================================================================================================= -AbstractPlugin::PluginType Fieldline::getType() const -{ - return _ISensor; +SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { + return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } //============================================================================================================= -QString Fieldline::getName() const -{ - return "Natus EEG"; +QString Fieldline::getName() const { + return QString("Fieldline OPM"); } //============================================================================================================= -QWidget* Fieldline::setupWidget() -{ - NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new +QWidget* Fieldline::setupWidget() { + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new //init properties dialog - widget->initGui(); + // widget->initGui(); - return widget; + return new QLabel("Fieldline"); } //============================================================================================================= -void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) -{ - while(!m_pCircularBuffer->push(matData)) { - //Do nothing until the circular buffer is ready to accept new data again - } -} +// void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { +// +// while(!m_pCircularBuffer->push(matData)) { +// //Do nothing until the circular buffer is ready to accept new data again +// } +// } //============================================================================================================= -void Fieldline::run() -{ - MatrixXd matData; - - while(!isInterruptionRequested()) { - if(m_pCircularBuffer->pop(matData)) { - //emit values - if(!isInterruptionRequested()) { - m_pRMTSA_Natus->measurementData()->setValue(matData); - } - } - } +void Fieldline::run() { + // MatrixXd matData; + // + // while(!isInterruptionRequested()) { + // if(m_pCircularBuffer->pop(matData)) { + // //emit values + // if(!isInterruptionRequested()) { + // m_pRMTSA_Natus->measurementData()->setValue(matData); + // } + // } + // } } //============================================================================================================= -QString Fieldline::getBuildInfo() -{ - return QString(NATUSPLUGIN::buildDateTime()) + QString(" - ") + QString(NATUSPLUGIN::buildHash()); +QString Fieldline::getBuildInfo() { + + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } + +} // namespace FIELDLINEPLUGIN + + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index cdba732a587..f7e1f6923e4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -35,35 +35,34 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= - #include "fieldline_global.h" #include -#include +// #include //============================================================================================================= // QT INCLUDES //============================================================================================================= -// #include +#include // #include //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= -#include +// #include //============================================================================================================= // FORWARD DECLARATIONS //============================================================================================================= -namespace SCMEASLIB { -class RealTimeMultiSampleArray; -} -namespace FIFFLIB { -class FiffInfo; -} +// namespace SCMEASLIB { +// class RealTimeMultiSampleArray; +// } +// namespace FIFFLIB { +// class FiffInfo; +// } //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN @@ -84,16 +83,16 @@ namespace FIELDLINEPLUGIN { * * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. */ -class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor -{ +class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { + Q_OBJECT - // Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces - // Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + Q_INTERFACES(SCSHAREDLIB::AbstractSensor) // friend class FieldlineSetup; -public: + public: //========================================================================================================= /** * Constructs a Fieldline. @@ -128,7 +127,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor /** * Sets up the fiff info with the current data chosen by the user. */ - void setUpFiffInfo(); + // void setUpFiffInfo(); //========================================================================================================= /** @@ -143,18 +142,21 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor virtual bool stop(); virtual AbstractPlugin::PluginType getType() const; + virtual QString getName() const; + virtual QWidget* setupWidget(); + virtual QString getBuildInfo(); -protected: + protected: //========================================================================================================= /** * Call this function whenenver you received new data. * * @param[in] matData The new data. */ - void onNewDataAvailable(const Eigen::MatrixXd &matData); + // void onNewDataAvailable(const Eigen::MatrixXd &matData); //========================================================================================================= /** @@ -164,18 +166,18 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor */ virtual void run(); - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - int m_iNumberChannels; /**< The number of channels to be received.*/ - int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - - QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - - QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - - QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + // int m_iNumberChannels; /**< The number of channels to be received.*/ + // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + // + // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + // + // QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + // + // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.json b/src/applications/mne_scan/plugins/fieldline/fieldline.json new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.json @@ -0,0 +1 @@ + diff --git a/src/libraries/CMakeLists.txt b/src/libraries/CMakeLists.txt index 0e4ff82a7d4..f73569a53fc 100644 --- a/src/libraries/CMakeLists.txt +++ b/src/libraries/CMakeLists.txt @@ -32,12 +32,12 @@ message(STATUS CMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) message(STATUS CMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) if(APPLE) - set(CMAKE_INSTALL_RPATH "@executable_path/../lib") + set(CMAKE_INSTALL_RPATH "@executable_path/../lib") if(NOT BUILD_MAC_APP_BUNDLE) set(CMAKE_MACOSX_RPATH TRUE) endif() else() - set(CMAKE_INSTALL_RPATH "\${ORIGIN}/") + set(CMAKE_INSTALL_RPATH "\${ORIGIN}/") endif() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) From 96b769f74b3bc30f954bab976943f4e6528625a9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 20:53:30 -0500 Subject: [PATCH 009/147] fix typo no_tests --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5985bf93823..da79c4f7190 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,7 +125,7 @@ endif() if(BUILD_TESTS) add_subdirectory(testframes) endif() - + ##============================================================================== ## Add symbolic links to project resources folder From 29bf3e9370fa4dce6c3e5a0e43fda22f3c633912 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 21 Feb 2023 14:54:23 -0500 Subject: [PATCH 010/147] fieldline barebones plugin working --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 13 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 186 ++++++++++-------- .../mne_scan/plugins/fieldline/fieldline.h | 10 +- .../mne_scan/plugins/fieldline/fieldline.json | 1 - .../plugins/fieldline/fieldline_global.cpp | 6 +- 5 files changed, 115 insertions(+), 101 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f7c6772cbda..bd980a8b645 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -24,11 +24,13 @@ set(HEADERS set(FILE_TO_UPDATE fieldline_global.cpp) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) - message("File fieldline.json exists.") + # message("File fieldline.json exists.") else() - message("File fieldline.json does not exist.") - message("Creating a new fieldline.json file.") - execute_process(COMMAND "echo ") + # message("File fieldline.json does not exist.") + # message("Creating a new fieldline.json file.") + execute_process(COMMAND "echo \"\"" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_FILE fieldline.json) endif() set(SOURCE_PATHS ${SOURCES}) @@ -78,8 +80,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${FFTW_LIBS}) target_compile_definitions(${PROJECT_NAME} PRIVATE - SCAN_FIELDLINE_PLUGIN - MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" ) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 36b6f2e1e79..2c77a024160 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -10,22 +10,27 @@ * * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @@ -50,6 +55,7 @@ //============================================================================================================= // #include +#include #include //============================================================================================================= @@ -66,105 +72,115 @@ namespace FIELDLINEPLUGIN { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { - +Fieldline::Fieldline() : m_iSamplingFreq(1000) { + qDebug() << "Creating Fieldline object"; } //============================================================================================================= Fieldline::~Fieldline() { - // If the program is closed while the sampling is in process - // if(this->isRunning()) { - // this->stop(); - // } + // If the program is closed while the sampling is in process + // if(this->isRunning()) { + // this->stop(); + // } + qDebug() << "Destroying Fieldline object"; } //============================================================================================================= QSharedPointer Fieldline::clone() const { - QSharedPointer pFieldlineClone(new Fieldline()); - return pFieldlineClone; + QSharedPointer pFieldlineClone(new Fieldline()); + return pFieldlineClone; } //============================================================================================================= void Fieldline::init() { - // m_outputConnectors.append(m_pRMTSA_Natus); + // m_outputConnectors.append(m_pRMTSA_Natus); + qDebug() << "Init Fieldline"; } //============================================================================================================= -void Fieldline::unload() { - -} +void Fieldline::unload() { qDebug() << "unload Fieldline"; } //============================================================================================================= bool Fieldline::start() { - - // Init circular buffer to transmit data from the producer to this thread - // if(!m_pCircularBuffer) { - // m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); - // } - // - // //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA - // setUpFiffInfo(); - // - // //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime - // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); - // - // QThread::start(); - // - // // Start the producer - // m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); - // m_pNatusProducer->moveToThread(&m_pProducerThread); - // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - // m_pProducerThread.start(); - - return true; + qDebug() << "start Fieldline"; + + // Init circular buffer to transmit data from the producer to this thread + // if(!m_pCircularBuffer) { + // m_pCircularBuffer = QSharedPointer(new + // CircularBuffer_Matrix_double(10)); + // } + // + // //Setup fiff info before setting up the RMTSA because we need it to init + // the RTMSA setUpFiffInfo(); + // + // //Set the channel size of the RMTSA - this needs to be done here and NOT in + // the init() function because the user can change the number of channels + // during runtime + // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + // + // QThread::start(); + // + // // Start the producer + // m_pNatusProducer = + // QSharedPointer::create(m_iSamplesPerBlock, + // m_iNumberChannels); m_pNatusProducer->moveToThread(&m_pProducerThread); + // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + // m_pProducerThread.start(); + + return true; } //============================================================================================================= bool Fieldline::stop() { - // requestInterruption(); - // wait(500); - // - // // Clear all data in the buffer connected to displays and other plugins - // m_pRMTSA_Natus->measurementData()->clear(); - // m_pCircularBuffer->clear(); - // - // m_pProducerThread.quit(); - // m_pProducerThread.wait(); - - return true; + // requestInterruption(); + // wait(500); + // + // // Clear all data in the buffer connected to displays and other plugins + // m_pRMTSA_Natus->measurementData()->clear(); + // m_pCircularBuffer->clear(); + // + // m_pProducerThread.quit(); + // m_pProducerThread.wait(); + qDebug() << "Stop Fieldline"; + + return true; } //============================================================================================================= SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { - return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; + qDebug() << "getType Fieldline"; + return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } //============================================================================================================= QString Fieldline::getName() const { - return QString("Fieldline OPM"); + qDebug() << "getName Fieldline"; + return QString("Fieldline OPM"); } //============================================================================================================= -QWidget* Fieldline::setupWidget() { - // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new +QWidget *Fieldline::setupWidget() { + qDebug() << "setupWidget Fieldline"; + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by + // CentralWidget - so it has to be created everytime new - //init properties dialog - // widget->initGui(); + // init properties dialog + // widget->initGui(); - return new QLabel("Fieldline"); + return new QLabel("Fieldline \n OPM"); } //============================================================================================================= @@ -172,34 +188,32 @@ QWidget* Fieldline::setupWidget() { // void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { // // while(!m_pCircularBuffer->push(matData)) { -// //Do nothing until the circular buffer is ready to accept new data again +// //Do nothing until the circular buffer is ready to accept new data +// again // } // } //============================================================================================================= void Fieldline::run() { - // MatrixXd matData; - // - // while(!isInterruptionRequested()) { - // if(m_pCircularBuffer->pop(matData)) { - // //emit values - // if(!isInterruptionRequested()) { - // m_pRMTSA_Natus->measurementData()->setValue(matData); - // } - // } - // } + qDebug() << "run Fieldline"; + // MatrixXd matData; + // + // while(!isInterruptionRequested()) { + // if(m_pCircularBuffer->pop(matData)) { + // //emit values + // if(!isInterruptionRequested()) { + // m_pRMTSA_Natus->measurementData()->setValue(matData); + // } + // } + // } } //============================================================================================================= QString Fieldline::getBuildInfo() { - - return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); + qDebug() << "getBuildInfo Fieldline"; + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } - -} // namespace FIELDLINEPLUGIN - - - +} // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index f7e1f6923e4..06c9d7d1bd3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -35,6 +35,7 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= + #include "fieldline_global.h" #include @@ -45,7 +46,6 @@ //============================================================================================================= #include -// #include //============================================================================================================= // EIGEN INCLUDES @@ -54,12 +54,13 @@ // #include //============================================================================================================= -// FORWARD DECLARATIONS +// FORWARD DECLARATION //============================================================================================================= // namespace SCMEASLIB { // class RealTimeMultiSampleArray; // } +// u // namespace FIFFLIB { // class FiffInfo; // } @@ -84,7 +85,6 @@ namespace FIELDLINEPLUGIN { * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. */ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { - Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces @@ -166,7 +166,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { */ virtual void run(); - // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ // int m_iNumberChannels; /**< The number of channels to be received.*/ // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ // @@ -177,7 +177,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ // // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.json b/src/applications/mne_scan/plugins/fieldline/fieldline.json index 8b137891791..e69de29bb2d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.json +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.json @@ -1 +0,0 @@ - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp index 2e691274c01..13809aec2de 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp @@ -43,12 +43,12 @@ // DEFINE METHODS //============================================================================================================= -const char* FIELDLINEPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} +const char* FIELDLINEPLUGIN::buildDateTime() { return UTILSLIB::dateTimeNow();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHash(){ return UTILSLIB::gitHash();} +const char* FIELDLINEPLUGIN::buildHash() { return UTILSLIB::gitHash();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} +const char* FIELDLINEPLUGIN::buildHashLong() { return UTILSLIB::gitHashLong();} From 0a5a2a29a19c1cfe84562d46034259eae0d5d375 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:42:09 -0500 Subject: [PATCH 011/147] add python bindings to fieldline plugin --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 24 +++++++-- .../fieldline/fieldline_plugin_gui.cpp | 53 +++++++++++++++++++ .../plugins/fieldline/fieldline_plugin_gui.h | 52 ++++++++++++++++++ .../fieldline/fieldline_system_controller.cpp | 53 +++++++++++++++++++ .../fieldline/fieldline_system_controller.h | 51 ++++++++++++++++++ 5 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index bd980a8b645..d237475fe7b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,29 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(Python COMPONENTS Interpreter Development) +cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) + +set(PYTHON_COMPILE_FLAGS "--cflags") +execute_process(COMMAND + ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} + OUTPUT_VARIABLE Python_FLAGS +) + + set(SOURCES fieldline_global.cpp fieldline.cpp + fieldline_acq_system_controller.cpp + fieldline_plugin_gui.cpp ) set(HEADERS fieldline_global.h fieldline.h + fieldline_acq_system_controller.h + fieldline_plugin_gui.h ) set(FILE_TO_UPDATE fieldline_global.cpp) @@ -58,8 +72,7 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC ../) -target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent @@ -77,8 +90,13 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scDisp scShared scMeas - ${FFTW_LIBS}) + ${FFTW_LIBS} + PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) +target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) +separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") +target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) + target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp new file mode 100644 index 00000000000..5e7e879932c --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp @@ -0,0 +1,53 @@ +//============================================================================================================= +/** + * @file fieldline_plugin_gui.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline plugin GUI class. + * +*/ + +#include "fieldline_plugin_gui.h" + + +namespace FIELDLINEPLUGIN { + +FieldlinePluginGUI::FieldlinePluginGUI() noexcept { + +} + + +} // namespace FIELDLINEPLUGIN + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h new file mode 100644 index 00000000000..1e434db8b5e --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h @@ -0,0 +1,52 @@ +//============================================================================================================= +/** + * @file fieldline_plugin_gui.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline plugin GUI class. + */ + + + +namespace FIELDLINEPLUGIN { + + +class FieldlinePluginGUI { + public: + FieldlinePluginGUI() noexcept; + + + private: + +}; + + +} // namespace FIELDLINEPLUGIN + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp new file mode 100644 index 00000000000..1a37ab804ff --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp @@ -0,0 +1,53 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline class. + * + */ + + + +#include "fieldline_system_controller.h" + + +namespace FIELDLINEPLUGIN { + +FieldlineSystemController::FieldlineSystemController() noexcept { + +} + + +} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h new file mode 100644 index 00000000000..1cfe93570df --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h @@ -0,0 +1,51 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline Acquisition System Controller class. + * + */ + + +namespace FIELDLINEPLUGIN { + + +class FieldlineSystemController { + public: + FieldlineSystemController() noexcept; + + + private: + +}; + + +} // namespace FIELDLINEPLUGIN + From 07804e24e13b709e013d5c7e8b6843fb6c0c118a Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:45:50 -0500 Subject: [PATCH 012/147] add python to fieldline plugin --- .../mne_scan/plugins/fieldline/fieldline.cpp | 10 ++++-- .../mne_scan/plugins/fieldline/fieldline.h | 33 +++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 2c77a024160..10538a7139a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -72,7 +72,7 @@ namespace FIELDLINEPLUGIN { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() : m_iSamplingFreq(1000) { +Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } @@ -89,6 +89,7 @@ Fieldline::~Fieldline() { //============================================================================================================= QSharedPointer Fieldline::clone() const { + qDebug() << "Cloning Fieldline."; QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } @@ -99,11 +100,14 @@ void Fieldline::init() { // m_outputConnectors.append(m_pRMTSA_Natus); qDebug() << "Init Fieldline"; + acqSystem = std::make_unique(); } //============================================================================================================= -void Fieldline::unload() { qDebug() << "unload Fieldline"; } +void Fieldline::unload() { + qDebug() << "unload Fieldline"; +} //============================================================================================================= @@ -174,6 +178,8 @@ QString Fieldline::getName() const { QWidget *Fieldline::setupWidget() { qDebug() << "setupWidget Fieldline"; + guiWidget = std::make_unique(); + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by // CentralWidget - so it has to be created everytime new diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 06c9d7d1bd3..eb77827d089 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -37,9 +37,12 @@ #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= #include "fieldline_global.h" +#include "fieldline_acq_system_controller.h" +#include "fieldline_plugin_gui.h" #include // #include +#include //============================================================================================================= // QT INCLUDES @@ -164,20 +167,22 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { * returning from this method will end the execution of the thread. * pure virtual method inherited by qthread. */ - virtual void run(); - - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - // int m_iNumberChannels; /**< The number of channels to be received.*/ - // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - // - // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - // - // QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - // - // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + virtual void run(); + + + std::unique_ptr acqSystem; + std::unique_ptr guiWidget; + + // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + // int m_iNumberChannels; /**< The number of channels to be received.*/ + // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + // QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + // + // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From 13c3afe685b85c6ffe62fa8af73e408e69b42ae1 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:48:23 -0500 Subject: [PATCH 013/147] add fieldline acq system class --- ...pp => fieldline_acq_system_controller.cpp} | 42 +++++++++++++++++-- ...er.h => fieldline_acq_system_controller.h} | 6 ++- 2 files changed, 43 insertions(+), 5 deletions(-) rename src/applications/mne_scan/plugins/fieldline/{fieldline_system_controller.cpp => fieldline_acq_system_controller.cpp} (66%) rename src/applications/mne_scan/plugins/fieldline/{fieldline_system_controller.h => fieldline_acq_system_controller.h} (94%) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp similarity index 66% rename from src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp rename to src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index 1a37ab804ff..62a700a18b6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -40,14 +40,50 @@ -#include "fieldline_system_controller.h" +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "fieldline_acq_system_controller.h" namespace FIELDLINEPLUGIN { -FieldlineSystemController::FieldlineSystemController() noexcept { - +FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { + + // pythonInterpreter initiate + // + // run script + // + // find ip + // + // start connection + // + // initialize channels + // + // + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + FILE* py_file = fopen("main.py", "r"); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, + "main.py", + Py_file_input, + global_dict, + local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); + } +FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { + Py_Finalize(); +} + } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h similarity index 94% rename from src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h rename to src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h index 1cfe93570df..84bdc40a3e3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h @@ -37,9 +37,11 @@ namespace FIELDLINEPLUGIN { -class FieldlineSystemController { +class FieldlineAcqSystemController { public: - FieldlineSystemController() noexcept; + FieldlineAcqSystemController() noexcept; + + ~FieldlineAcqSystemController() noexcept; private: From 52fd119e291df8d1ddd6f6340ae8a88983bee7b3 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:48:37 -0500 Subject: [PATCH 014/147] add example python script --- main.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 00000000000..b727a0ebb90 --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +print("hello pepe!!") From 5614571c9333029c9342543eab0aa79d4904cc09 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Wed, 22 Feb 2023 15:25:58 -0500 Subject: [PATCH 015/147] Add sensor, chassis, and rack ui elements. Sensors can blink --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 5 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 16 +++- .../fieldline_acq_system_controller.cpp | 40 +++++----- src/libraries/disp/CMakeLists.txt | 6 ++ src/libraries/disp/viewers/fl_chassis.cpp | 22 ++++++ src/libraries/disp/viewers/fl_chassis.h | 26 +++++++ src/libraries/disp/viewers/fl_rack.cpp | 18 +++++ src/libraries/disp/viewers/fl_rack.h | 22 ++++++ src/libraries/disp/viewers/fl_sensor.cpp | 78 +++++++++++++++++++ src/libraries/disp/viewers/fl_sensor.h | 45 +++++++++++ .../disp/viewers/formfiles/fl_chassis.ui | 75 ++++++++++++++++++ .../disp/viewers/formfiles/fl_rack.ui | 45 +++++++++++ .../disp/viewers/formfiles/fl_sensor.ui | 59 ++++++++++++++ 13 files changed, 434 insertions(+), 23 deletions(-) create mode 100644 src/libraries/disp/viewers/fl_chassis.cpp create mode 100644 src/libraries/disp/viewers/fl_chassis.h create mode 100644 src/libraries/disp/viewers/fl_rack.cpp create mode 100644 src/libraries/disp/viewers/fl_rack.h create mode 100644 src/libraries/disp/viewers/fl_sensor.cpp create mode 100644 src/libraries/disp/viewers/fl_sensor.h create mode 100644 src/libraries/disp/viewers/formfiles/fl_chassis.ui create mode 100644 src/libraries/disp/viewers/formfiles/fl_rack.ui create mode 100644 src/libraries/disp/viewers/formfiles/fl_sensor.ui diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index d237475fe7b..5e758c7c5da 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,7 +10,7 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Python COMPONENTS Interpreter Development) +find_package(Python REQUIRED COMPONENTS Interpreter Development) cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) set(PYTHON_COMPILE_FLAGS "--cflags") @@ -91,7 +91,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core scShared scMeas ${FFTW_LIBS} - PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) +# PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + ) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 10538a7139a..37e780bbeee 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,6 +44,7 @@ #include "fieldline.h" +#include // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -57,6 +58,9 @@ // #include #include #include +#include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -186,7 +190,17 @@ QWidget *Fieldline::setupWidget() { // init properties dialog // widget->initGui(); - return new QLabel("Fieldline \n OPM"); + + + + auto* frame = new QWidget(); + frame->setLayout(new QHBoxLayout()); + + frame->layout()->addWidget(new fl_rack()); + + return frame; + + // return new QLabel("Fieldline \n OPM"); } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index 62a700a18b6..df78a5179a0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" +//#include "Python.h" #include "fieldline_acq_system_controller.h" @@ -60,30 +60,30 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // - Py_Initialize(); - PyConfig config; - PyConfig_InitPythonConfig(&config); - config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, L"."); - Py_InitializeFromConfig(&config); - FILE* py_file = fopen("main.py", "r"); - PyObject* global_dict = PyDict_New(); - PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, - "main.py", - Py_file_input, - global_dict, - local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); +// Py_Initialize(); +// PyConfig config; +// PyConfig_InitPythonConfig(&config); +// config.module_search_paths_set = 1; +// PyWideStringList_Append(&config.module_search_paths, L"."); +// Py_InitializeFromConfig(&config); +// FILE* py_file = fopen("main.py", "r"); +// PyObject* global_dict = PyDict_New(); +// PyObject* local_dict = PyDict_New(); +// PyObject* result = PyRun_File(py_file, +// "main.py", +// Py_file_input, +// global_dict, +// local_dict); +// Py_DECREF(global_dict); +// Py_DECREF(local_dict); +// Py_DECREF(result); +// fclose(py_file); } FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { - Py_Finalize(); +// Py_Finalize(); } } diff --git a/src/libraries/disp/CMakeLists.txt b/src/libraries/disp/CMakeLists.txt index e75f51feb10..177cdc0ad0b 100644 --- a/src/libraries/disp/CMakeLists.txt +++ b/src/libraries/disp/CMakeLists.txt @@ -56,6 +56,9 @@ set(SOURCES viewers/hpisettingsview.cpp viewers/covariancesettingsview.cpp viewers/bidsview.cpp + viewers/fl_sensor.cpp + viewers/fl_chassis.cpp + viewers/fl_rack.cpp viewers/helpers/rtfiffrawviewmodel.cpp viewers/helpers/rtfiffrawviewdelegate.cpp viewers/helpers/evokedsetmodel.cpp @@ -119,6 +122,9 @@ set(HEADERS viewers/hpisettingsview.h viewers/covariancesettingsview.h viewers/bidsview.h + viewers/fl_sensor.h + viewers/fl_chassis.h + viewers/fl_rack.h viewers/helpers/rtfiffrawviewdelegate.h viewers/helpers/rtfiffrawviewmodel.h viewers/helpers/evokedsetmodel.h diff --git a/src/libraries/disp/viewers/fl_chassis.cpp b/src/libraries/disp/viewers/fl_chassis.cpp new file mode 100644 index 00000000000..d8e735e0aba --- /dev/null +++ b/src/libraries/disp/viewers/fl_chassis.cpp @@ -0,0 +1,22 @@ +#include "fl_chassis.h" +#include "ui_fl_chassis.h" + + +fl_chassis::fl_chassis(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_chassis) +{ + ui->setupUi(this); + + for(int i = 0; i < 16; ++i){ + sensors.push_back(std::make_unique()); + sensors.back()->setLabel(QString::number(i+1)); + ui->sensor_frame->layout()->addWidget(sensors.back().get()); + } + sensors.back()->setBlink(true); +} + +fl_chassis::~fl_chassis() +{ + delete ui; +} diff --git a/src/libraries/disp/viewers/fl_chassis.h b/src/libraries/disp/viewers/fl_chassis.h new file mode 100644 index 00000000000..904b880e748 --- /dev/null +++ b/src/libraries/disp/viewers/fl_chassis.h @@ -0,0 +1,26 @@ +#ifndef FL_CHASSIS_H +#define FL_CHASSIS_H + +#include +#include +#include +#include "fl_sensor.h" + +namespace Ui { +class fl_chassis; +} + +class fl_chassis : public QWidget +{ + Q_OBJECT + +public: + explicit fl_chassis(QWidget *parent = nullptr); + ~fl_chassis(); + +private: + Ui::fl_chassis *ui; + std::vector> sensors; +}; + +#endif // FL_CHASSIS_H diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fl_rack.cpp new file mode 100644 index 00000000000..add240e76c5 --- /dev/null +++ b/src/libraries/disp/viewers/fl_rack.cpp @@ -0,0 +1,18 @@ +#include "fl_rack.h" +#include "ui_fl_rack.h" + +#include "fl_chassis.h" + +fl_rack::fl_rack(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_rack) +{ + ui->setupUi(this); + + ui->frame->layout()->addWidget(new fl_chassis()); +} + +fl_rack::~fl_rack() +{ + delete ui; +} diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fl_rack.h new file mode 100644 index 00000000000..0e8939bd569 --- /dev/null +++ b/src/libraries/disp/viewers/fl_rack.h @@ -0,0 +1,22 @@ +#ifndef FL_RACK_H +#define FL_RACK_H + +#include + +namespace Ui { +class fl_rack; +} + +class fl_rack : public QWidget +{ + Q_OBJECT + +public: + explicit fl_rack(QWidget *parent = nullptr); + ~fl_rack(); + +private: + Ui::fl_rack *ui; +}; + +#endif // FL_RACK_H diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/fl_sensor.cpp new file mode 100644 index 00000000000..3e214e16bf9 --- /dev/null +++ b/src/libraries/disp/viewers/fl_sensor.cpp @@ -0,0 +1,78 @@ +#include "fl_sensor.h" +#include "ui_fl_sensor.h" +# + +fl_sensor::fl_sensor(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_sensor) +{ + color = Qt::red; + + blink_brush = QBrush(Qt::transparent); + on_brush = QBrush(color); + + ui->setupUi(this); + ui->graphicsView->setStyleSheet("background:transparent"); + ui->label->setText("Hello"); + m_pScene = std::make_unique(); + ui->graphicsView->setScene(m_pScene.get()); + + circle = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); + blinkstate = false; + + blinktime = 200; +} + +fl_sensor::~fl_sensor() +{ + delete ui; +} + +void fl_sensor::setLabel(const QString& label) +{ + ui->label->setText(label); +} + + +void fl_sensor::resizeEvent(QResizeEvent *event) +{ + auto bounds = m_pScene->itemsBoundingRect(); + bounds.setWidth(bounds.width() * 1.2); + bounds.setHeight(bounds.height() * 1.2); + ui->graphicsView->fitInView(bounds, Qt::KeepAspectRatio); + + QWidget::resizeEvent(event); +} + +void fl_sensor::setBlink(bool state) +{ + if(state){ + turnOnBlink(); + } else { + turnOffBlink(); + } +} + + +void fl_sensor::turnOnBlink() +{ + connect(&t, &QTimer::timeout, this, &fl_sensor::handleBlink, Qt::UniqueConnection); + t.start(blinktime); +} + +void fl_sensor::turnOffBlink() +{ + t.stop(); + circle->setBrush(on_brush); +} + +void fl_sensor::handleBlink() +{ + if(blinkstate){ + circle->setBrush(blink_brush); + blinkstate = false; + } else { + circle->setBrush(on_brush); + blinkstate = true; + } +} diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/fl_sensor.h new file mode 100644 index 00000000000..3d7ed16b57f --- /dev/null +++ b/src/libraries/disp/viewers/fl_sensor.h @@ -0,0 +1,45 @@ +#ifndef FL_SENSOR_H +#define FL_SENSOR_H + +#include +#include +#include +#include +#include + +namespace Ui { +class fl_sensor; +} + +class fl_sensor : public QWidget +{ + Q_OBJECT + +public: + explicit fl_sensor(QWidget *parent = nullptr); + ~fl_sensor(); + + void setLabel(const QString& label); + + void setBlink(bool state); + +protected: + virtual void resizeEvent(QResizeEvent *event); +private: + void turnOnBlink(); + void turnOffBlink(); + void handleBlink(); + + + int blinktime; + Ui::fl_sensor *ui; + std::unique_ptr m_pScene; + QGraphicsEllipseItem* circle; + QTimer t; + QColor color; + QBrush blink_brush; + QBrush on_brush; + bool blinkstate; +}; + +#endif // FL_SENSOR_H diff --git a/src/libraries/disp/viewers/formfiles/fl_chassis.ui b/src/libraries/disp/viewers/formfiles/fl_chassis.ui new file mode 100644 index 00000000000..2de422ee7d6 --- /dev/null +++ b/src/libraries/disp/viewers/formfiles/fl_chassis.ui @@ -0,0 +1,75 @@ + + + fl_chassis + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + Form + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + FieldLine + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + + + + + + + diff --git a/src/libraries/disp/viewers/formfiles/fl_rack.ui b/src/libraries/disp/viewers/formfiles/fl_rack.ui new file mode 100644 index 00000000000..22cd98411b2 --- /dev/null +++ b/src/libraries/disp/viewers/formfiles/fl_rack.ui @@ -0,0 +1,45 @@ + + + fl_rack + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Qt::Vertical + + + + 20 + 262 + + + + + + + + + diff --git a/src/libraries/disp/viewers/formfiles/fl_sensor.ui b/src/libraries/disp/viewers/formfiles/fl_sensor.ui new file mode 100644 index 00000000000..eebb7d10dbd --- /dev/null +++ b/src/libraries/disp/viewers/formfiles/fl_sensor.ui @@ -0,0 +1,59 @@ + + + fl_sensor + + + + 0 + 0 + 400 + 225 + + + + + 0 + 0 + + + + Form + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + + From 6a101ff310030dd27472b5b31f9444c9a091eaa4 Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 12:20:39 -0500 Subject: [PATCH 016/147] Reorganize and refactor fl_rack --- src/libraries/disp/viewers/fl_rack.cpp | 176 ++++++++++++++++++++++++- src/libraries/disp/viewers/fl_rack.h | 98 +++++++++++++- 2 files changed, 264 insertions(+), 10 deletions(-) diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fl_rack.cpp index add240e76c5..0cc76cadb2c 100644 --- a/src/libraries/disp/viewers/fl_rack.cpp +++ b/src/libraries/disp/viewers/fl_rack.cpp @@ -1,18 +1,182 @@ +//============================================================================================================= +/** + * @file fl_rack.cpp + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + #include "fl_rack.h" +#include "fl_chassis.h" + #include "ui_fl_rack.h" -#include "fl_chassis.h" +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +using DISPLIB::FieldlineView; +using DISPLIB::fl_chassis; + +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +int FieldlineView::default_num_sensors = 16; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + + +FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) +: FieldlineView(parent) +{ + configure(num_chassis, sensors_per_chassis); +} + +//============================================================================================================= + +FieldlineView::FieldlineView(int num_chassis, QWidget *parent) +: FieldlineView(num_chassis, default_num_sensors, parent) +{ +} + +//============================================================================================================= -fl_rack::fl_rack(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_rack) +FieldlineView::FieldlineView(QWidget *parent) +: QWidget(parent) +, ui(std::make_unique()) { ui->setupUi(this); +} + +//============================================================================================================= + +FieldlineView::~FieldlineView() +{ +} + +//============================================================================================================= + +void FieldlineView::configure(int num_chassis) +{ + configure(num_chassis, default_num_sensors); +} + +//============================================================================================================= + +void FieldlineView::configure(int num_chassis, int num_sensors) +{ ui->frame->layout()->addWidget(new fl_chassis()); } -fl_rack::~fl_rack() +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) { - delete ui; + +} + +//============================================================================================================= + +void FieldlineView::setChassisColor(int chassis_id, QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllColor(QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllColor(QColor color, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllBlinkState(bool blinking) +{ + +} + +//============================================================================================================= + +static void setDefaultNumSensors(int num_sensors) +{ + } diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fl_rack.h index 0e8939bd569..6f31be7c623 100644 --- a/src/libraries/disp/viewers/fl_rack.h +++ b/src/libraries/disp/viewers/fl_rack.h @@ -1,22 +1,112 @@ +//============================================================================================================= +/** + * @file fl_rack.h + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + #ifndef FL_RACK_H #define FL_RACK_H +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "../disp_global.h" +#include "fl_chassis.h" + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + #include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= namespace Ui { class fl_rack; } -class fl_rack : public QWidget +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace DISPLIB +{ + +class FieldlineView : public QWidget { Q_OBJECT public: - explicit fl_rack(QWidget *parent = nullptr); - ~fl_rack(); + FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); + FieldlineView(int num_chassis, QWidget *parent = nullptr); + explicit FieldlineView(QWidget *parent = nullptr); + ~FieldlineView(); + + void configure(int num_chassis); + void configure(int num_chassis, int num_sensors); + + void setColor(int chassis_id, int sensnor_num, QColor color); + void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); + + void setChassisColor(int chassis_id, QColor color); + void setChassisColor(int chassis_id, QColor color, bool blinking); + + void setAllColor(QColor color); + void setAllColor(QColor color, bool blinking); + + void setBlinkState(int chassis_id, int sensnor_num, bool blinking); + void setChassisBlinkState(int chassis_id, bool blinking); + void setAllBlinkState(bool blinking); + + static void setDefaultNumSensors(int num_sensors); private: - Ui::fl_rack *ui; + static int default_num_sensors; + + std::unique_ptr ui; + + std::vector> chassis; }; +}//namespace DISPLIB + #endif // FL_RACK_H From 6102e5bd4b2680616c9ba7ab03f1f477a76d3a9d Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 12:21:17 -0500 Subject: [PATCH 017/147] Reorganize and refactor fl_sensor --- src/libraries/disp/viewers/fl_sensor.cpp | 155 +++++++++++++++++------ src/libraries/disp/viewers/fl_sensor.h | 91 +++++++++++-- 2 files changed, 197 insertions(+), 49 deletions(-) diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/fl_sensor.cpp index 3e214e16bf9..ca393dece09 100644 --- a/src/libraries/disp/viewers/fl_sensor.cpp +++ b/src/libraries/disp/viewers/fl_sensor.cpp @@ -1,40 +1,118 @@ +//============================================================================================================= +/** + * @file fl_sensor.cpp + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineSensor class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + #include "fl_sensor.h" #include "ui_fl_sensor.h" -# -fl_sensor::fl_sensor(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_sensor) -{ - color = Qt::red; +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +using DISPLIB::FieldlineSensor; - blink_brush = QBrush(Qt::transparent); - on_brush = QBrush(color); +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +QColor FieldlineSensor::default_color = Qt::red; +QString FieldlineSensor::default_label = "XX"; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +FieldlineSensor::FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent) +: QWidget(parent) +, ui(std::make_unique()) +, blink_brush(QBrush(Qt::transparent)) +, on_brush(QBrush(led_color)) +, blink_time_ms(200) +{ + m_pScene = std::make_unique(); ui->setupUi(this); ui->graphicsView->setStyleSheet("background:transparent"); - ui->label->setText("Hello"); - m_pScene = std::make_unique(); + ui->label->setText(label); ui->graphicsView->setScene(m_pScene.get()); - circle = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); - blinkstate = false; + circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); +} + +//============================================================================================================= - blinktime = 200; +FieldlineSensor::FieldlineSensor(const QString& label, QWidget *parent) +: FieldlineSensor(label, default_color, parent) +{ +} + +//============================================================================================================= + +FieldlineSensor::FieldlineSensor(QWidget *parent) +: FieldlineSensor(default_label, default_color, parent) +{ } -fl_sensor::~fl_sensor() +//============================================================================================================= + +FieldlineSensor::~FieldlineSensor() { - delete ui; } -void fl_sensor::setLabel(const QString& label) +//============================================================================================================= + +void FieldlineSensor::setLabel(const QString& label) { ui->label->setText(label); } +//============================================================================================================= -void fl_sensor::resizeEvent(QResizeEvent *event) +void FieldlineSensor::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); bounds.setWidth(bounds.width() * 1.2); @@ -44,35 +122,38 @@ void fl_sensor::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } -void fl_sensor::setBlink(bool state) +//============================================================================================================= + +void FieldlineSensor::setBlink(bool state) { - if(state){ - turnOnBlink(); - } else { - turnOffBlink(); - } + state ? turnOnBlink() : turnOffBlink(); } +//============================================================================================================= -void fl_sensor::turnOnBlink() +void FieldlineSensor::turnOnBlink() { - connect(&t, &QTimer::timeout, this, &fl_sensor::handleBlink, Qt::UniqueConnection); - t.start(blinktime); + connect(&blink_timer, &QTimer::timeout, + this, &FieldlineSensor::handleBlink, Qt::UniqueConnection); + blink_timer.start(blink_time_ms); } -void fl_sensor::turnOffBlink() +//============================================================================================================= + +void FieldlineSensor::turnOffBlink() { - t.stop(); - circle->setBrush(on_brush); + blink_timer.stop(); + circle_led->setBrush(on_brush); } -void fl_sensor::handleBlink() +//============================================================================================================= + +void FieldlineSensor::handleBlink() { - if(blinkstate){ - circle->setBrush(blink_brush); - blinkstate = false; - } else { - circle->setBrush(on_brush); - blinkstate = true; - } + static bool blink_state = false; + + blink_state ? circle_led->setBrush(blink_brush) + : circle_led->setBrush(on_brush); + + blink_state = !blink_state; } diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/fl_sensor.h index 3d7ed16b57f..a048eab0f35 100644 --- a/src/libraries/disp/viewers/fl_sensor.h +++ b/src/libraries/disp/viewers/fl_sensor.h @@ -1,45 +1,112 @@ +//============================================================================================================= +/** + * @file fl_sensor.h + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineSensor class declaration. + * + */ + #ifndef FL_SENSOR_H #define FL_SENSOR_H +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "../disp_global.h" + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + #include #include -#include #include #include +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + namespace Ui { class fl_sensor; } -class fl_sensor : public QWidget +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace DISPLIB +{ + +class FieldlineSensor : public QWidget { Q_OBJECT public: - explicit fl_sensor(QWidget *parent = nullptr); - ~fl_sensor(); + FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent = nullptr); + FieldlineSensor(const QString& label, QWidget *parent = nullptr); + explicit FieldlineSensor(QWidget *parent = nullptr); + ~FieldlineSensor(); void setLabel(const QString& label); - void setBlink(bool state); + void setColor(const QColor& color); protected: virtual void resizeEvent(QResizeEvent *event); + private: void turnOnBlink(); void turnOffBlink(); void handleBlink(); - - int blinktime; - Ui::fl_sensor *ui; + std::unique_ptr ui; std::unique_ptr m_pScene; - QGraphicsEllipseItem* circle; - QTimer t; - QColor color; + + int blink_time_ms; + QTimer blink_timer; + + static QColor default_color; + static QString default_label; + + QGraphicsEllipseItem* circle_led; QBrush blink_brush; QBrush on_brush; - bool blinkstate; }; +}//namespace DISPLIB #endif // FL_SENSOR_H From f3ce786f61f25f0069a83fe402e8947fd8d13a9a Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 14:00:24 -0500 Subject: [PATCH 018/147] Reorganiz files and names --- src/libraries/disp/CMakeLists.txt | 10 ++--- .../{fl_rack.cpp => fieldlineview.cpp} | 30 +++++++++++-- .../viewers/{fl_rack.h => fieldlineview.h} | 29 +++++++++++-- src/libraries/disp/viewers/fl_chassis.cpp | 22 ---------- src/libraries/disp/viewers/fl_chassis.h | 26 ----------- .../{fl_sensor.ui => led_indicator.ui} | 6 +-- .../{fl_sensor.cpp => led_indicator.cpp} | 43 +++++++++---------- .../viewers/{fl_sensor.h => led_indicator.h} | 22 +++++----- 8 files changed, 91 insertions(+), 97 deletions(-) rename src/libraries/disp/viewers/{fl_rack.cpp => fieldlineview.cpp} (89%) rename src/libraries/disp/viewers/{fl_rack.h => fieldlineview.h} (87%) delete mode 100644 src/libraries/disp/viewers/fl_chassis.cpp delete mode 100644 src/libraries/disp/viewers/fl_chassis.h rename src/libraries/disp/viewers/formfiles/{fl_sensor.ui => led_indicator.ui} (93%) rename src/libraries/disp/viewers/{fl_sensor.cpp => led_indicator.cpp} (84%) rename src/libraries/disp/viewers/{fl_sensor.h => led_indicator.h} (90%) diff --git a/src/libraries/disp/CMakeLists.txt b/src/libraries/disp/CMakeLists.txt index 177cdc0ad0b..78792d03770 100644 --- a/src/libraries/disp/CMakeLists.txt +++ b/src/libraries/disp/CMakeLists.txt @@ -56,9 +56,8 @@ set(SOURCES viewers/hpisettingsview.cpp viewers/covariancesettingsview.cpp viewers/bidsview.cpp - viewers/fl_sensor.cpp - viewers/fl_chassis.cpp - viewers/fl_rack.cpp + viewers/led_indicator.cpp + viewers/fieldlineview.cpp viewers/helpers/rtfiffrawviewmodel.cpp viewers/helpers/rtfiffrawviewdelegate.cpp viewers/helpers/evokedsetmodel.cpp @@ -122,9 +121,8 @@ set(HEADERS viewers/hpisettingsview.h viewers/covariancesettingsview.h viewers/bidsview.h - viewers/fl_sensor.h - viewers/fl_chassis.h - viewers/fl_rack.h + viewers/led_indicator.h + viewers/fieldlineview.h viewers/helpers/rtfiffrawviewdelegate.h viewers/helpers/rtfiffrawviewmodel.h viewers/helpers/evokedsetmodel.h diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fieldlineview.cpp similarity index 89% rename from src/libraries/disp/viewers/fl_rack.cpp rename to src/libraries/disp/viewers/fieldlineview.cpp index 0cc76cadb2c..8fcd9976d0e 100644 --- a/src/libraries/disp/viewers/fl_rack.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -37,10 +37,11 @@ // INCLUDES //============================================================================================================= -#include "fl_rack.h" -#include "fl_chassis.h" +#include "fieldlineview.h" #include "ui_fl_rack.h" +#include "ui_fl_chassis.h" + //============================================================================================================= // QT INCLUDES @@ -176,7 +177,30 @@ void FieldlineView::setAllBlinkState(bool blinking) //============================================================================================================= -static void setDefaultNumSensors(int num_sensors) +void FieldlineView::setDefaultNumSensors(int num_sensors) { } + +//============================================================================================================= + +fl_chassis::fl_chassis(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_chassis) +{ + ui->setupUi(this); + + for(int i = 0; i < 16; ++i){ + sensors.push_back(std::make_unique()); + sensors.back()->setLabel(QString::number(i+1)); + ui->sensor_frame->layout()->addWidget(sensors.back().get()); + } + sensors.back()->setBlink(true); +} + +//============================================================================================================= + +fl_chassis::~fl_chassis() +{ + delete ui; +} diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fieldlineview.h similarity index 87% rename from src/libraries/disp/viewers/fl_rack.h rename to src/libraries/disp/viewers/fieldlineview.h index 6f31be7c623..feb2ad5d1cd 100644 --- a/src/libraries/disp/viewers/fl_rack.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -33,17 +33,19 @@ * */ -#ifndef FL_RACK_H -#define FL_RACK_H +#ifndef FIELDLINE_UI_VIEW_H +#define FIELDLINE_UI_VIEW_H //============================================================================================================= // INCLUDES //============================================================================================================= #include "../disp_global.h" -#include "fl_chassis.h" + +#include "led_indicator.h" #include +#include //============================================================================================================= // QT INCLUDES @@ -62,6 +64,7 @@ namespace Ui { class fl_rack; +class fl_chassis; } //============================================================================================================= @@ -71,6 +74,9 @@ class fl_rack; namespace DISPLIB { +class fl_chassis; + +//============================================================================================================= class FieldlineView : public QWidget { Q_OBJECT @@ -107,6 +113,21 @@ class FieldlineView : public QWidget std::vector> chassis; }; +//============================================================================================================= +class fl_chassis : public QWidget +{ + Q_OBJECT + +public: + explicit fl_chassis(QWidget *parent = nullptr); + ~fl_chassis(); + +private: + Ui::fl_chassis *ui; + std::vector> sensors; +}; + + }//namespace DISPLIB -#endif // FL_RACK_H +#endif // FIELDLINE_UI_VIEW_H diff --git a/src/libraries/disp/viewers/fl_chassis.cpp b/src/libraries/disp/viewers/fl_chassis.cpp deleted file mode 100644 index d8e735e0aba..00000000000 --- a/src/libraries/disp/viewers/fl_chassis.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "fl_chassis.h" -#include "ui_fl_chassis.h" - - -fl_chassis::fl_chassis(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_chassis) -{ - ui->setupUi(this); - - for(int i = 0; i < 16; ++i){ - sensors.push_back(std::make_unique()); - sensors.back()->setLabel(QString::number(i+1)); - ui->sensor_frame->layout()->addWidget(sensors.back().get()); - } - sensors.back()->setBlink(true); -} - -fl_chassis::~fl_chassis() -{ - delete ui; -} diff --git a/src/libraries/disp/viewers/fl_chassis.h b/src/libraries/disp/viewers/fl_chassis.h deleted file mode 100644 index 904b880e748..00000000000 --- a/src/libraries/disp/viewers/fl_chassis.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef FL_CHASSIS_H -#define FL_CHASSIS_H - -#include -#include -#include -#include "fl_sensor.h" - -namespace Ui { -class fl_chassis; -} - -class fl_chassis : public QWidget -{ - Q_OBJECT - -public: - explicit fl_chassis(QWidget *parent = nullptr); - ~fl_chassis(); - -private: - Ui::fl_chassis *ui; - std::vector> sensors; -}; - -#endif // FL_CHASSIS_H diff --git a/src/libraries/disp/viewers/formfiles/fl_sensor.ui b/src/libraries/disp/viewers/formfiles/led_indicator.ui similarity index 93% rename from src/libraries/disp/viewers/formfiles/fl_sensor.ui rename to src/libraries/disp/viewers/formfiles/led_indicator.ui index eebb7d10dbd..ab1c713991a 100644 --- a/src/libraries/disp/viewers/formfiles/fl_sensor.ui +++ b/src/libraries/disp/viewers/formfiles/led_indicator.ui @@ -1,13 +1,13 @@ - fl_sensor - + led_ind + 0 0 400 - 225 + 242 diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/led_indicator.cpp similarity index 84% rename from src/libraries/disp/viewers/fl_sensor.cpp rename to src/libraries/disp/viewers/led_indicator.cpp index ca393dece09..39f27501e31 100644 --- a/src/libraries/disp/viewers/fl_sensor.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -1,6 +1,6 @@ //============================================================================================================= /** - * @file fl_sensor.cpp + * @file led_indicator.cpp * @author Gabriel Motta * Juan Garcia-Prieto * @since 0.1.9 @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * - * @brief FieldlineSensor class definition. + * @brief LEDIndicator class definition. * */ @@ -37,9 +37,8 @@ // INCLUDES //============================================================================================================= - -#include "fl_sensor.h" -#include "ui_fl_sensor.h" +#include "led_indicator.h" +#include "ui_led_indicator.h" //============================================================================================================= // QT INCLUDES @@ -53,22 +52,22 @@ // USED NAMESPACES //============================================================================================================= -using DISPLIB::FieldlineSensor; +using DISPLIB::LEDIndicator; //============================================================================================================= // DEFINE STATIC METHODS //============================================================================================================= -QColor FieldlineSensor::default_color = Qt::red; -QString FieldlineSensor::default_label = "XX"; +QColor LEDIndicator::default_color = Qt::red; +QString LEDIndicator::default_label = "XX"; //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -FieldlineSensor::FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent) +LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) +, ui(std::make_unique()) , blink_brush(QBrush(Qt::transparent)) , on_brush(QBrush(led_color)) , blink_time_ms(200) @@ -85,34 +84,34 @@ FieldlineSensor::FieldlineSensor(const QString& label, const QColor& led_color, //============================================================================================================= -FieldlineSensor::FieldlineSensor(const QString& label, QWidget *parent) -: FieldlineSensor(label, default_color, parent) +LEDIndicator::LEDIndicator(const QString& label, QWidget *parent) +: LEDIndicator(label, default_color, parent) { } //============================================================================================================= -FieldlineSensor::FieldlineSensor(QWidget *parent) -: FieldlineSensor(default_label, default_color, parent) +LEDIndicator::LEDIndicator(QWidget *parent) +: LEDIndicator(default_label, default_color, parent) { } //============================================================================================================= -FieldlineSensor::~FieldlineSensor() +LEDIndicator::~LEDIndicator() { } //============================================================================================================= -void FieldlineSensor::setLabel(const QString& label) +void LEDIndicator::setLabel(const QString& label) { ui->label->setText(label); } //============================================================================================================= -void FieldlineSensor::resizeEvent(QResizeEvent *event) +void LEDIndicator::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); bounds.setWidth(bounds.width() * 1.2); @@ -124,23 +123,23 @@ void FieldlineSensor::resizeEvent(QResizeEvent *event) //============================================================================================================= -void FieldlineSensor::setBlink(bool state) +void LEDIndicator::setBlink(bool state) { state ? turnOnBlink() : turnOffBlink(); } //============================================================================================================= -void FieldlineSensor::turnOnBlink() +void LEDIndicator::turnOnBlink() { connect(&blink_timer, &QTimer::timeout, - this, &FieldlineSensor::handleBlink, Qt::UniqueConnection); + this, &LEDIndicator::handleBlink, Qt::UniqueConnection); blink_timer.start(blink_time_ms); } //============================================================================================================= -void FieldlineSensor::turnOffBlink() +void LEDIndicator::turnOffBlink() { blink_timer.stop(); circle_led->setBrush(on_brush); @@ -148,7 +147,7 @@ void FieldlineSensor::turnOffBlink() //============================================================================================================= -void FieldlineSensor::handleBlink() +void LEDIndicator::handleBlink() { static bool blink_state = false; diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/led_indicator.h similarity index 90% rename from src/libraries/disp/viewers/fl_sensor.h rename to src/libraries/disp/viewers/led_indicator.h index a048eab0f35..dfabfe1c2bc 100644 --- a/src/libraries/disp/viewers/fl_sensor.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -1,6 +1,6 @@ //============================================================================================================= /** - * @file fl_sensor.h + * @file led_indicator.h * @author Gabriel Motta * Juan Garcia-Prieto * @since 0.1.9 @@ -33,8 +33,8 @@ * */ -#ifndef FL_SENSOR_H -#define FL_SENSOR_H +#ifndef LED_INDICATOR_H +#define LED_INDICATOR_H //============================================================================================================= // INCLUDES @@ -62,7 +62,7 @@ //============================================================================================================= namespace Ui { -class fl_sensor; +class led_ind; } //============================================================================================================= @@ -72,15 +72,15 @@ class fl_sensor; namespace DISPLIB { -class FieldlineSensor : public QWidget +class LEDIndicator : public QWidget { Q_OBJECT public: - FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent = nullptr); - FieldlineSensor(const QString& label, QWidget *parent = nullptr); - explicit FieldlineSensor(QWidget *parent = nullptr); - ~FieldlineSensor(); + LEDIndicator(const QString& label, const QColor& led_color, QWidget *parent = nullptr); + LEDIndicator(const QString& label, QWidget *parent = nullptr); + explicit LEDIndicator(QWidget *parent = nullptr); + ~LEDIndicator(); void setLabel(const QString& label); void setBlink(bool state); @@ -94,7 +94,7 @@ class FieldlineSensor : public QWidget void turnOffBlink(); void handleBlink(); - std::unique_ptr ui; + std::unique_ptr ui; std::unique_ptr m_pScene; int blink_time_ms; @@ -109,4 +109,4 @@ class FieldlineSensor : public QWidget }; }//namespace DISPLIB -#endif // FL_SENSOR_H +#endif // LED_INDICATOR_H From 3d464925ccee6b6472c56c34cae6786193fb63ea Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 15:40:47 -0500 Subject: [PATCH 019/147] clean up led indicator --- .../disp/viewers/formfiles/led_indicator.ui | 4 +-- src/libraries/disp/viewers/led_indicator.cpp | 34 ++++++++++++------- src/libraries/disp/viewers/led_indicator.h | 8 +++-- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/libraries/disp/viewers/formfiles/led_indicator.ui b/src/libraries/disp/viewers/formfiles/led_indicator.ui index ab1c713991a..28af9347b34 100644 --- a/src/libraries/disp/viewers/formfiles/led_indicator.ui +++ b/src/libraries/disp/viewers/formfiles/led_indicator.ui @@ -1,7 +1,7 @@ - led_ind - + led_indicator + 0 diff --git a/src/libraries/disp/viewers/led_indicator.cpp b/src/libraries/disp/viewers/led_indicator.cpp index 39f27501e31..c9b235fdf0f 100644 --- a/src/libraries/disp/viewers/led_indicator.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -44,6 +44,8 @@ // QT INCLUDES //============================================================================================================= +#include + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -67,15 +69,18 @@ QString LEDIndicator::default_label = "XX"; LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) -, blink_brush(QBrush(Qt::transparent)) +, ui(std::make_unique()) +, off_brush(QBrush(Qt::transparent)) , on_brush(QBrush(led_color)) , blink_time_ms(200) +, blink_state(false) { m_pScene = std::make_unique(); ui->setupUi(this); ui->graphicsView->setStyleSheet("background:transparent"); + ui->graphicsView->horizontalScrollBar()->hide(); + ui->graphicsView->verticalScrollBar()->hide(); ui->label->setText(label); ui->graphicsView->setScene(m_pScene.get()); @@ -111,6 +116,20 @@ void LEDIndicator::setLabel(const QString& label) //============================================================================================================= +void LEDIndicator::setBlink(bool state) +{ + state ? turnOnBlink() : turnOffBlink(); +} + +//============================================================================================================= + +void LEDIndicator::setColor(const QColor& color) +{ + on_brush.setColor(color); +} + +//============================================================================================================= + void LEDIndicator::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); @@ -123,13 +142,6 @@ void LEDIndicator::resizeEvent(QResizeEvent *event) //============================================================================================================= -void LEDIndicator::setBlink(bool state) -{ - state ? turnOnBlink() : turnOffBlink(); -} - -//============================================================================================================= - void LEDIndicator::turnOnBlink() { connect(&blink_timer, &QTimer::timeout, @@ -149,9 +161,7 @@ void LEDIndicator::turnOffBlink() void LEDIndicator::handleBlink() { - static bool blink_state = false; - - blink_state ? circle_led->setBrush(blink_brush) + blink_state ? circle_led->setBrush(off_brush) : circle_led->setBrush(on_brush); blink_state = !blink_state; diff --git a/src/libraries/disp/viewers/led_indicator.h b/src/libraries/disp/viewers/led_indicator.h index dfabfe1c2bc..59fc4d9de0f 100644 --- a/src/libraries/disp/viewers/led_indicator.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -62,7 +62,7 @@ //============================================================================================================= namespace Ui { -class led_ind; + class led_indicator; } //============================================================================================================= @@ -94,17 +94,19 @@ class LEDIndicator : public QWidget void turnOffBlink(); void handleBlink(); - std::unique_ptr ui; + std::unique_ptr ui; std::unique_ptr m_pScene; int blink_time_ms; QTimer blink_timer; + bool blink_state; + static QColor default_color; static QString default_label; QGraphicsEllipseItem* circle_led; - QBrush blink_brush; + QBrush off_brush; QBrush on_brush; }; }//namespace DISPLIB From bc7122acf3bc6bc6107be3a70bf9b0bd90c74d5a Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 16:35:04 -0500 Subject: [PATCH 020/147] Implement rest of Fielline view and chassis logic --- .../mne_scan/plugins/fieldline/fieldline.cpp | 8 +- .../fieldline_acq_system_controller.cpp | 38 ++--- src/libraries/disp/viewers/fieldlineview.cpp | 150 ++++++++++++++---- src/libraries/disp/viewers/fieldlineview.h | 42 +++-- 4 files changed, 170 insertions(+), 68 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 37e780bbeee..fa115f113d0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,7 +44,7 @@ #include "fieldline.h" -#include +#include // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -196,7 +196,11 @@ QWidget *Fieldline::setupWidget() { auto* frame = new QWidget(); frame->setLayout(new QHBoxLayout()); - frame->layout()->addWidget(new fl_rack()); + auto* flWidget = new DISPLIB::FieldlineView(2, 16); + + frame->layout()->addWidget(flWidget); + flWidget->setBlinkState(0, 2, true); + flWidget->setBlinkState(1, 5, true); return frame; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index df78a5179a0..dbebe2ca44d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -//#include "Python.h" +#include "Python.h" #include "fieldline_acq_system_controller.h" @@ -60,24 +60,24 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // -// Py_Initialize(); -// PyConfig config; -// PyConfig_InitPythonConfig(&config); -// config.module_search_paths_set = 1; -// PyWideStringList_Append(&config.module_search_paths, L"."); -// Py_InitializeFromConfig(&config); -// FILE* py_file = fopen("main.py", "r"); -// PyObject* global_dict = PyDict_New(); -// PyObject* local_dict = PyDict_New(); -// PyObject* result = PyRun_File(py_file, -// "main.py", -// Py_file_input, -// global_dict, -// local_dict); -// Py_DECREF(global_dict); -// Py_DECREF(local_dict); -// Py_DECREF(result); -// fclose(py_file); + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + FILE* py_file = fopen("main.py", "r"); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, + "main.py", + Py_file_input, + global_dict, + local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); } diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 8fcd9976d0e..4de1397226c 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -37,11 +37,10 @@ // INCLUDES //============================================================================================================= -#include "fieldlineview.h" - #include "ui_fl_rack.h" #include "ui_fl_chassis.h" +#include "fieldlineview.h" //============================================================================================================= // QT INCLUDES @@ -86,15 +85,15 @@ FieldlineView::FieldlineView(int num_chassis, QWidget *parent) FieldlineView::FieldlineView(QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) +, ui(new Ui::fl_rack()) { ui->setupUi(this); } - //============================================================================================================= FieldlineView::~FieldlineView() { + delete ui; } //============================================================================================================= @@ -108,94 +107,129 @@ void FieldlineView::configure(int num_chassis) void FieldlineView::configure(int num_chassis, int num_sensors) { - - ui->frame->layout()->addWidget(new fl_chassis()); + clear(); + for(int i = 0; i < num_chassis; ++i){ + chassis.push_back(new fl_chassis(num_sensors)); + ui->frame->layout()->addWidget(chassis.back()); + } } //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) +void FieldlineView::clear() { + for(auto* c : chassis){ + ui->frame->layout()->removeWidget(c); + } +}; +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color) +{ + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(sensor_num, color); } //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) +void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(sensor_num, color, blinking); } //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, QColor color) +void FieldlineView::setChassisColor(int chassis_id, const QColor& color) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(color); } //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) +void FieldlineView::setChassisColor(int chassis_id, const QColor& color, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(color, blinking); } //============================================================================================================= -void FieldlineView::setAllColor(QColor color) +void FieldlineView::setAllColor(const QColor& color) { - + for(auto* c : chassis){ + c->setColor(color); + } } //============================================================================================================= -void FieldlineView::setAllColor(QColor color, bool blinking) +void FieldlineView::setAllColor(const QColor& color, bool blinking) { - + for(auto* c : chassis){ + c->setColor(color, blinking); + } } //============================================================================================================= -void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) +void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); } //============================================================================================================= void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setBlinkState(blinking); } //============================================================================================================= void FieldlineView::setAllBlinkState(bool blinking) { - + for(auto* c : chassis){ + c->setBlinkState(blinking); + } } //============================================================================================================= void FieldlineView::setDefaultNumSensors(int num_sensors) { - + default_num_sensors = num_sensors; } //============================================================================================================= -fl_chassis::fl_chassis(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_chassis) +fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) +: QWidget(parent) +, ui(new Ui::fl_chassis()) { ui->setupUi(this); - for(int i = 0; i < 16; ++i){ - sensors.push_back(std::make_unique()); - sensors.back()->setLabel(QString::number(i+1)); - ui->sensor_frame->layout()->addWidget(sensors.back().get()); + for(int i = 0; i < num_sensors; ++i){ + sensors.push_back(new LEDIndicator()); + sensors.back()->setLabel(QString::number(i + 1)); + ui->sensor_frame->layout()->addWidget(sensors.back()); } - sensors.back()->setBlink(true); } //============================================================================================================= @@ -204,3 +238,59 @@ fl_chassis::~fl_chassis() { delete ui; } + +//============================================================================================================= + +void fl_chassis::setColor(int sensor_num, const QColor& color) +{ + if(sensor_num > sensors.size() || sensor_num < 1){ + return; + } + sensors.at(sensor_num - 1)->setColor(color); +} + +//============================================================================================================= + +void fl_chassis::setColor(int sensor_num, const QColor& color, bool blinking) +{ + setColor(sensor_num, color); + setBlinkState(sensor_num, blinking); +} + +//============================================================================================================= + +void fl_chassis::setColor(const QColor& color) +{ + for(auto* sensor : sensors){ + sensor->setColor(color); + } +} + +//============================================================================================================= + +void fl_chassis::setColor(const QColor& color, bool blinking) +{ + for(auto* sensor : sensors){ + sensor->setColor(color); + sensor->setBlink(blinking); + } +} + +//============================================================================================================= + +void fl_chassis::setBlinkState(int sensor_num, bool blinking) +{ + if(sensor_num > sensors.size() || sensor_num < 1){ + return; + } + sensors.at(sensor_num - 1)->setBlink(blinking); +} + +//============================================================================================================= + +void fl_chassis::setBlinkState(bool blinking) +{ + for(auto* sensor : sensors){ + sensor->setBlink(blinking); + } +} diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index feb2ad5d1cd..99b368ceb02 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -63,8 +63,8 @@ //============================================================================================================= namespace Ui { -class fl_rack; -class fl_chassis; + class fl_rack; + class fl_chassis; } //============================================================================================================= @@ -82,25 +82,26 @@ class FieldlineView : public QWidget Q_OBJECT public: + explicit FieldlineView(QWidget *parent = nullptr); FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); FieldlineView(int num_chassis, QWidget *parent = nullptr); - explicit FieldlineView(QWidget *parent = nullptr); - ~FieldlineView(); void configure(int num_chassis); void configure(int num_chassis, int num_sensors); - void setColor(int chassis_id, int sensnor_num, QColor color); - void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); + void clear(); - void setChassisColor(int chassis_id, QColor color); - void setChassisColor(int chassis_id, QColor color, bool blinking); + void setColor(int chassis_id, int sensor_num, const QColor& color); + void setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking); - void setAllColor(QColor color); - void setAllColor(QColor color, bool blinking); + void setChassisColor(int chassis_id, const QColor& color); + void setChassisColor(int chassis_id, const QColor& color, bool blinking); - void setBlinkState(int chassis_id, int sensnor_num, bool blinking); + void setAllColor(const QColor& color); + void setAllColor(const QColor &color, bool blinking); + + void setBlinkState(int chassis_id, int sensor_num, bool blinking); void setChassisBlinkState(int chassis_id, bool blinking); void setAllBlinkState(bool blinking); @@ -108,23 +109,30 @@ class FieldlineView : public QWidget private: static int default_num_sensors; - std::unique_ptr ui; - - std::vector> chassis; + Ui::fl_rack* ui; + std::vector chassis; }; //============================================================================================================= + class fl_chassis : public QWidget { Q_OBJECT public: - explicit fl_chassis(QWidget *parent = nullptr); + fl_chassis(int num_sensors, QWidget *parent = nullptr); ~fl_chassis(); + void setColor(int sensor_num, const QColor& color); + void setColor(int sensor_num, const QColor& color, bool blinking); + void setColor(const QColor& color); + void setColor(const QColor& color, bool blinking); + + void setBlinkState(int sensor_num, bool blinking); + void setBlinkState(bool blinking); private: - Ui::fl_chassis *ui; - std::vector> sensors; + Ui::fl_chassis* ui; + std::vector sensors; }; From f0ddaf5cf49f90adc052df1f597f92fa2dcc62a3 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 24 Feb 2023 09:53:43 -0500 Subject: [PATCH 021/147] Change indexing type to unsigned size_t --- src/libraries/disp/viewers/fieldlineview.cpp | 30 ++++++++++---------- src/libraries/disp/viewers/fieldlineview.h | 18 ++++++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 4de1397226c..e3be5510d8e 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -125,9 +125,9 @@ void FieldlineView::clear() //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color) +void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(sensor_num, color); @@ -135,9 +135,9 @@ void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking) +void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(sensor_num, color, blinking); @@ -145,9 +145,9 @@ void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, const QColor& color) +void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(color); @@ -155,9 +155,9 @@ void FieldlineView::setChassisColor(int chassis_id, const QColor& color) //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, const QColor& color, bool blinking) +void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(color, blinking); @@ -183,9 +183,9 @@ void FieldlineView::setAllColor(const QColor& color, bool blinking) //============================================================================================================= -void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) +void FieldlineView::setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); @@ -193,9 +193,9 @@ void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) //============================================================================================================= -void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) +void FieldlineView::setChassisBlinkState(size_t chassis_id, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setBlinkState(blinking); @@ -241,7 +241,7 @@ fl_chassis::~fl_chassis() //============================================================================================================= -void fl_chassis::setColor(int sensor_num, const QColor& color) +void fl_chassis::setColor(size_t sensor_num, const QColor& color) { if(sensor_num > sensors.size() || sensor_num < 1){ return; @@ -251,7 +251,7 @@ void fl_chassis::setColor(int sensor_num, const QColor& color) //============================================================================================================= -void fl_chassis::setColor(int sensor_num, const QColor& color, bool blinking) +void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) { setColor(sensor_num, color); setBlinkState(sensor_num, blinking); @@ -278,7 +278,7 @@ void fl_chassis::setColor(const QColor& color, bool blinking) //============================================================================================================= -void fl_chassis::setBlinkState(int sensor_num, bool blinking) +void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) { if(sensor_num > sensors.size() || sensor_num < 1){ return; diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index 99b368ceb02..e268dbfc4d9 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -92,17 +92,17 @@ class FieldlineView : public QWidget void clear(); - void setColor(int chassis_id, int sensor_num, const QColor& color); - void setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking); + void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); + void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); - void setChassisColor(int chassis_id, const QColor& color); - void setChassisColor(int chassis_id, const QColor& color, bool blinking); + void setChassisColor(size_t chassis_id, const QColor& color); + void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); void setAllColor(const QColor& color); void setAllColor(const QColor &color, bool blinking); - void setBlinkState(int chassis_id, int sensor_num, bool blinking); - void setChassisBlinkState(int chassis_id, bool blinking); + void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); + void setChassisBlinkState(size_t chassis_id, bool blinking); void setAllBlinkState(bool blinking); static void setDefaultNumSensors(int num_sensors); @@ -123,12 +123,12 @@ class fl_chassis : public QWidget fl_chassis(int num_sensors, QWidget *parent = nullptr); ~fl_chassis(); - void setColor(int sensor_num, const QColor& color); - void setColor(int sensor_num, const QColor& color, bool blinking); + void setColor(size_t sensor_num, const QColor& color); + void setColor(size_t sensor_num, const QColor& color, bool blinking); void setColor(const QColor& color); void setColor(const QColor& color, bool blinking); - void setBlinkState(int sensor_num, bool blinking); + void setBlinkState(size_t sensor_num, bool blinking); void setBlinkState(bool blinking); private: Ui::fl_chassis* ui; From 4402f383f574190eae073e91efbf5312e3831bd0 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 10:37:57 -0500 Subject: [PATCH 022/147] remove unnecessary PRIVATE in cmakelists file --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 5e758c7c5da..f3e0e567d33 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -72,7 +72,8 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC ../) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent @@ -91,13 +92,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core scShared scMeas ${FFTW_LIBS} -# PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - ) + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) - + target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" From eaeab9cb07a7dc0ced7634221f423ce1e5133017 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 15:34:33 -0500 Subject: [PATCH 023/147] add folder for dependencies --- src/applications/mne_scan/plugins/fieldline/fieldline.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index eb77827d089..9f3cb022cc4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -36,9 +36,9 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= -#include "fieldline_global.h" -#include "fieldline_acq_system_controller.h" -#include "fieldline_plugin_gui.h" +#include "fieldline/fieldline_global.h" +#include "fieldline/fieldline_acq_system_controller.h" +#include "fieldline/fieldline_plugin_gui.h" #include // #include From 5c32d812fca81b86dd256cbf000068db2845eb13 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 15:34:57 -0500 Subject: [PATCH 024/147] minor edit cmakelists.txt --- src/applications/mne_scan/plugins/fieldline/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f3e0e567d33..563e6bc354b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -19,8 +19,6 @@ execute_process(COMMAND OUTPUT_VARIABLE Python_FLAGS ) - - set(SOURCES fieldline_global.cpp fieldline.cpp From 3796cb4c096d59532313e5eed11b30a6d55a1827 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Mon, 27 Feb 2023 14:06:30 -0500 Subject: [PATCH 025/147] Trigger deletion of removed widgets --- src/libraries/disp/viewers/fieldlineview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index e3be5510d8e..e8966924537 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -120,6 +120,7 @@ void FieldlineView::clear() { for(auto* c : chassis){ ui->frame->layout()->removeWidget(c); + c->deleteLater(); } }; From b553c47799554ba3bc2a0c90f6bbadfaf3efb0ee Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Tue, 28 Feb 2023 10:41:07 -0500 Subject: [PATCH 026/147] Trying out gui interaction --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 27 +++++++++--------- .../fieldline_acq_system_controller.cpp | 2 +- src/libraries/disp/viewers/fieldlineview.cpp | 28 +++++++++++++++++++ src/libraries/disp/viewers/fieldlineview.h | 7 +++++ src/libraries/disp/viewers/led_indicator.cpp | 4 +++ src/libraries/disp/viewers/led_indicator.h | 1 - 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 563e6bc354b..1630ea0f1ea 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,15 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Python REQUIRED COMPONENTS Interpreter Development) -cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) - -set(PYTHON_COMPILE_FLAGS "--cflags") -execute_process(COMMAND - ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} - OUTPUT_VARIABLE Python_FLAGS -) - +# find_package(Python REQUIRED COMPONENTS Interpreter Development) +# cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) +# +# set(PYTHON_COMPILE_FLAGS "--cflags") +# execute_process(COMMAND +# ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} +# OUTPUT_VARIABLE Python_FLAGS +# ) +# set(SOURCES fieldline_global.cpp fieldline.cpp @@ -90,11 +90,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) + # python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) + ) -target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) -separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") -target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) +# target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) +# separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") +# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index dbebe2ca44d..328fad1ca84 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" +// #include "Python.h" #include "fieldline_acq_system_controller.h" diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index e8966924537..1964bb7e578 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -46,6 +46,10 @@ // QT INCLUDES //============================================================================================================= +#include +#include +#include + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -228,8 +232,11 @@ fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) for(int i = 0; i < num_sensors; ++i){ sensors.push_back(new LEDIndicator()); + auto& last_item = sensors.back(); sensors.back()->setLabel(QString::number(i + 1)); ui->sensor_frame->layout()->addWidget(sensors.back()); + connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); + connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); } } @@ -295,3 +302,24 @@ void fl_chassis::setBlinkState(bool blinking) sensor->setBlink(blinking); } } + +//============================================================================================================= + +void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) +{ +// auto* menu = new QMenu(); + +// auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); +// auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); + +// auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); +// auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); + +// connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); +// connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); + +// connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); +// connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); + +// menu->exec(pos); +} diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index e268dbfc4d9..2f9034f1941 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -130,6 +130,13 @@ class fl_chassis : public QWidget void setBlinkState(size_t sensor_num, bool blinking); void setBlinkState(bool blinking); + +signals: + void clicked(int sensor, const QPoint& pos); + +private slots: + void rightClickMenu(int sensor, const QPoint& pos); + private: Ui::fl_chassis* ui; std::vector sensors; diff --git a/src/libraries/disp/viewers/led_indicator.cpp b/src/libraries/disp/viewers/led_indicator.cpp index c9b235fdf0f..6228349a9d9 100644 --- a/src/libraries/disp/viewers/led_indicator.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -45,6 +45,8 @@ //============================================================================================================= #include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -85,6 +87,8 @@ LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidge ui->graphicsView->setScene(m_pScene.get()); circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); + + this->setContextMenuPolicy(Qt::CustomContextMenu); } //============================================================================================================= diff --git a/src/libraries/disp/viewers/led_indicator.h b/src/libraries/disp/viewers/led_indicator.h index 59fc4d9de0f..391da06ad69 100644 --- a/src/libraries/disp/viewers/led_indicator.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -101,7 +101,6 @@ class LEDIndicator : public QWidget QTimer blink_timer; bool blink_state; - static QColor default_color; static QString default_label; From e1a7984d399ac80e5c961826ee673eda819c0261 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 1 Mar 2023 15:01:27 -0500 Subject: [PATCH 027/147] create random data from fieldline --- .gitignore | 7 +- .../mne_scan/plugins/fieldline/CMakeLists.txt | 2 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 70 +++++++++++++++---- .../mne_scan/plugins/fieldline/fieldline.h | 23 +++--- 4 files changed, 74 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 554fc837ada..f6fb124c5f0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ # Bin folder with exceptions /lib/ +/bin/ +/out*/ # External device SDKs (if installed) /applications/mne_scan/plugins/eegosports/eemagine/ @@ -71,9 +73,8 @@ compile_commands.json # Generated docu Docker files /_site -/build* -/out* -/resources/data* +build-*/* + .cache/* codecov diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 1630ea0f1ea..0b267c16646 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -78,7 +78,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE eigen mne_disp mne_utils - # mne_fiff + mne_fiff # mne_fs # mne_mne # mne_fwd diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index fa115f113d0..d2a75ddc9f4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -48,8 +48,7 @@ // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" -// #include -// #include +#include //============================================================================================================= // QT INCLUDES @@ -102,8 +101,15 @@ QSharedPointer Fieldline::clone() const { void Fieldline::init() { - // m_outputConnectors.append(m_pRMTSA_Natus); - qDebug() << "Init Fieldline"; + // we instantiante + m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData::create( + this, + "Fieldline Plugin", + "FieldlinePlguin output"); + + m_outputConnectors.append(m_pRTMSA_Fieldline); + + qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; acqSystem = std::make_unique(); } @@ -133,7 +139,7 @@ bool Fieldline::start() { // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); // - // QThread::start(); + QThread::start(); // // // Start the producer // m_pNatusProducer = @@ -149,12 +155,12 @@ bool Fieldline::start() { //============================================================================================================= bool Fieldline::stop() { - - // requestInterruption(); - // wait(500); + requestInterruption(); + wait(500); + // m_pRMTSA_Natus->measurementData()->clear(); + // // // // Clear all data in the buffer connected to displays and other plugins - // m_pRMTSA_Natus->measurementData()->clear(); // m_pCircularBuffer->clear(); // // m_pProducerThread.quit(); @@ -174,7 +180,7 @@ SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { //============================================================================================================= QString Fieldline::getName() const { - qDebug() << "getName Fieldline"; + // qDebug() << "getName Fieldline"; return QString("Fieldline OPM"); } @@ -221,16 +227,52 @@ QWidget *Fieldline::setupWidget() { void Fieldline::run() { qDebug() << "run Fieldline"; - // MatrixXd matData; - // - // while(!isInterruptionRequested()) { - // if(m_pCircularBuffer->pop(matData)) { + + m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); + + m_pFiffInfo->sfreq = 1000.0f; + m_pFiffInfo->nchan = 32; + m_pFiffInfo->chs.clear(); + + for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { + FIFFLIB::FiffChInfo channel; + channel.ch_name = "Ch. " + QString::number(chan_i); + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + m_pFiffInfo->chs.append(channel); + m_pFiffInfo->ch_names.append(channel.ch_name); + } + + m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo(m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); + m_pRTMSA_Fieldline->measurementData()->setVisibility(true); + + Eigen::MatrixXd matData; + matData.resize(m_pFiffInfo->nchan, 200); + // matData.setZero(); + + for(;;) { + //gather the data + + matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + matData *= 4e-12; + + msleep(200); + + if (isInterruptionRequested()) + break; + m_pRTMSA_Fieldline->measurementData()->setValue(matData); + } + // //emit values // if(!isInterruptionRequested()) { // m_pRMTSA_Natus->measurementData()->setValue(matData); // } // } // } + qDebug() << "run Fieldline finished"; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 9f3cb022cc4..b076e2ce980 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -40,6 +40,9 @@ #include "fieldline/fieldline_acq_system_controller.h" #include "fieldline/fieldline_plugin_gui.h" +#include +#include + #include // #include #include @@ -49,6 +52,7 @@ //============================================================================================================= #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -60,13 +64,13 @@ // FORWARD DECLARATION //============================================================================================================= -// namespace SCMEASLIB { -// class RealTimeMultiSampleArray; -// } -// u -// namespace FIFFLIB { -// class FiffInfo; -// } +namespace SCMEASLIB { +class RealTimeMultiSampleArray; +} + +namespace FIFFLIB { +class FiffInfo; +} //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN @@ -181,9 +185,8 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ // - // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ -}; + QSharedPointer > m_pRTMSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From 2910ea317ac8625435a5ef071bb5aa7d19693395 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 2 Mar 2023 18:46:36 -0500 Subject: [PATCH 028/147] [FIX] Seg fault when calling qDebug in destructor --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 1 - src/applications/mne_scan/plugins/fieldline/fieldline.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index d2a75ddc9f4..6f3c8194f4a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -86,7 +86,6 @@ Fieldline::~Fieldline() { // if(this->isRunning()) { // this->stop(); // } - qDebug() << "Destroying Fieldline object"; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index b076e2ce980..12012882d48 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -110,7 +110,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { /** * Destroys the Fieldline. */ - virtual ~Fieldline(); + ~Fieldline(); //========================================================================================================= /** From b0c87615b149145fcc684c47340b120b2664d20f Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 3 Mar 2023 13:24:00 -0500 Subject: [PATCH 029/147] set minimum size for control slider --- .../disp/viewers/formfiles/scalecontrol.ui | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libraries/disp/viewers/formfiles/scalecontrol.ui b/src/libraries/disp/viewers/formfiles/scalecontrol.ui index 6d0e5609438..4c5a1ac2bf3 100644 --- a/src/libraries/disp/viewers/formfiles/scalecontrol.ui +++ b/src/libraries/disp/viewers/formfiles/scalecontrol.ui @@ -35,11 +35,17 @@ - + 0 0 + + + 0 + 20 + + @@ -57,6 +63,12 @@ 0 + + + 0 + 20 + + Qt::Horizontal From b7b6021443bcf040733f7959aa403194fd35e55f Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 2 Mar 2023 11:17:40 -0500 Subject: [PATCH 030/147] Add functions for creating fiffinfo based on filedline chassis parameters --- .../mne_scan/plugins/fieldline/fieldline.cpp | 101 +++++++++++++----- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 6f3c8194f4a..42dd0dd8bbd 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -56,10 +56,12 @@ // #include #include -#include -#include #include +#include #include +#include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -71,13 +73,69 @@ namespace FIELDLINEPLUGIN { +//============================================================================================================= + +// QSharedPointer createFiffInfo(int numChassis, +// int numChannels) { +// QSharedPointer pFiffInfo; +// pFiffInfo->sfreq = 1000.0f; +// pFiffInfo->nchan = numChassis * numChannels; +// pFiffInfo->chs.clear(); +// +// for (int chan_i = 0; chan_i < pFiffInfo->nchan; ++chan_i) { +// FIFFLIB::FiffChInfo channel; +// channel.ch_name = QString("%1:%2").arg(numChannels, 2).arg(chan_i, 2); +// channel.kind = FIFFV_MEG_CH; +// channel.unit = FIFF_UNIT_T; +// channel.unit_mul = FIFF_UNITM_NONE; +// channel.chpos.coil_type = FIFFV_COIL_NONE; +// pFiffInfo->chs.append(channel); +// pFiffInfo->ch_names.append(channel.ch_name); +// } +// } + +QSharedPointer +createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { + QSharedPointer pFiffInfo; + pFiffInfo->sfreq = sfreq; + pFiffInfo->chs.clear(); + + int total_channels = 0; + int chassis_num = 0; + for (auto &chassis : fl_chassis) { + for (auto &sensor : chassis) { + FIFFLIB::FiffChInfo channel; + channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + pFiffInfo->chs.append(channel); + pFiffInfo->ch_names.append(channel.ch_name); + ++total_channels; + } + } + pFiffInfo->nchan = total_channels; + + return pFiffInfo; +} + +QSharedPointer +createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { + std::vector> fl; + for (int i = 0; i < numChassis; ++i) { + std::vector ch(numChannels); + std::iota(ch.begin(), ch.end(), 1); + fl.push_back(std::move(ch)); + } + return createFiffInfo(fl, sfreq); +} + //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { - qDebug() << "Creating Fieldline object"; -} +Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } //============================================================================================================= @@ -100,12 +158,11 @@ QSharedPointer Fieldline::clone() const { void Fieldline::init() { - // we instantiante - m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData::create( - this, - "Fieldline Plugin", - "FieldlinePlguin output"); - + // we instantiante + m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< + SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Plugin", + "FieldlinePlguin output"); + m_outputConnectors.append(m_pRTMSA_Fieldline); qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; @@ -114,9 +171,7 @@ void Fieldline::init() { //============================================================================================================= -void Fieldline::unload() { - qDebug() << "unload Fieldline"; -} +void Fieldline::unload() { qDebug() << "unload Fieldline"; } //============================================================================================================= @@ -195,13 +250,10 @@ QWidget *Fieldline::setupWidget() { // init properties dialog // widget->initGui(); - - - - auto* frame = new QWidget(); + auto *frame = new QWidget(); frame->setLayout(new QHBoxLayout()); - auto* flWidget = new DISPLIB::FieldlineView(2, 16); + auto *flWidget = new DISPLIB::FieldlineView(2, 16); frame->layout()->addWidget(flWidget); flWidget->setBlinkState(0, 2, true); @@ -244,7 +296,8 @@ void Fieldline::run() { m_pFiffInfo->ch_names.append(channel.ch_name); } - m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo(m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( + m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); m_pRTMSA_Fieldline->measurementData()->setVisibility(true); @@ -252,19 +305,19 @@ void Fieldline::run() { matData.resize(m_pFiffInfo->nchan, 200); // matData.setZero(); - for(;;) { - //gather the data + for (;;) { + // gather the data matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); matData *= 4e-12; msleep(200); - if (isInterruptionRequested()) + if (isInterruptionRequested()) break; m_pRTMSA_Fieldline->measurementData()->setValue(matData); } - + // //emit values // if(!isInterruptionRequested()) { // m_pRMTSA_Natus->measurementData()->setValue(matData); From 67ca4fb46401f874173b25457963dcffd8b65072 Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Fri, 3 Mar 2023 11:31:37 -0500 Subject: [PATCH 031/147] Add callback functions to be called by python --- .../fieldline_acq_system_controller.cpp | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index 328fad1ca84..a3afed3fa7c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -45,8 +45,68 @@ #include "fieldline_acq_system_controller.h" -namespace FIELDLINEPLUGIN { +#include +#include + +extern "C" { + +PyObject *restartFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - restart finished;\n"; + } else { + std::cout << "A sensor has finished restarting!\n"; + } + + return NULL; +} +PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - coarse zero finished;\n"; + } else { + std::cout << "A sensor has finished coarse zeroing!\n"; + } + + return NULL; +} +PyObject *fineZeroFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - fine zero finished;\n"; + } else { + std::cout << "A sensor has finished fine zeroing!\n"; + } + return NULL; +} +} + +static PyMethodDef my_module_methods[] = { + {"restartFinished", restartFinished, METH_VARARGS, " "}, + {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, + {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, + {NULL, NULL, 0, NULL}}; + +static PyModuleDef my_module_def = { + PyModuleDef_HEAD_INIT, + "mne_cpp_callbacks", + "A module of callback functions for mne-cpp.", + -1, + my_module_methods, + NULL, + NULL, + NULL, + NULL}; + +PyMODINIT_FUNC PyInit_my_module(void) { + return PyModule_Create(&my_module_def); +} + +namespace FIELDLINEPLUGIN { FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // pythonInterpreter initiate From a76880e3bcfdc2538fa9465573daa3fafd7290fb Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 3 Mar 2023 14:09:46 -0500 Subject: [PATCH 032/147] uncomment cmakelists to include python paths and vars --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 0b267c16646..4df07cb05d2 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,15 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -# find_package(Python REQUIRED COMPONENTS Interpreter Development) -# cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) -# -# set(PYTHON_COMPILE_FLAGS "--cflags") -# execute_process(COMMAND -# ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} -# OUTPUT_VARIABLE Python_FLAGS -# ) -# + find_package(Python REQUIRED COMPONENTS Interpreter Development) + cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) + + set(PYTHON_COMPILE_FLAGS "--cflags") + execute_process(COMMAND + ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} + OUTPUT_VARIABLE Python_FLAGS + ) + set(SOURCES fieldline_global.cpp fieldline.cpp @@ -90,12 +90,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - # python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) -# target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) -# separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") -# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) + target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) + separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") + target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" From f992e55cb06fe17382b25a99df63b2cec18983d2 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 3 Mar 2023 14:10:19 -0500 Subject: [PATCH 033/147] add callback functions to event of right click on channels --- .../fieldline_acq_system_controller.cpp | 2 +- src/libraries/disp/viewers/fieldlineview.cpp | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index a3afed3fa7c..a515a0591fb 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -// #include "Python.h" +#include "Python.h" #include "fieldline_acq_system_controller.h" diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 1964bb7e578..e7f7de7e8f2 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -235,7 +235,12 @@ fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) auto& last_item = sensors.back(); sensors.back()->setLabel(QString::number(i + 1)); ui->sensor_frame->layout()->addWidget(sensors.back()); - connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); + connect(sensors.back(), &QWidget::customContextMenuRequested, + [this, i, &last_item](const QPoint& pos) { + qDebug() << "clicked " << i+1; + qDebug() << "global pos: " << last_item->mapToGlobal(pos); + this->emit clicked(i, last_item->mapToGlobal(pos)); + }); connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); } } @@ -307,19 +312,19 @@ void fl_chassis::setBlinkState(bool blinking) void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) { -// auto* menu = new QMenu(); + auto* menu = new QMenu(); -// auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); -// auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); + auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); + auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); -// auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); -// auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); + auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); + auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); -// connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); -// connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); + connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); + connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); -// connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); -// connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); + connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); + connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); -// menu->exec(pos); + menu->exec(pos); } From 556d5e0b391259932ae9068a9572256ef7f9c006 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 3 Mar 2023 19:00:47 -0500 Subject: [PATCH 034/147] normalize height of graphs and styling, typos --- .../libs/scShared/Plugins/abstractplugin.h | 6 ++--- src/applications/mne_scan/mne_scan/main.cpp | 2 ++ .../mne_scan/plugins/fieldline/fieldline.cpp | 6 ++--- .../eigen-3.4.0/demos/opengl/CMakeLists.txt | 3 ++- src/libraries/disp/viewers/fieldlineview.cpp | 14 ++++++----- .../viewers/helpers/rtfiffrawviewdelegate.cpp | 25 +++++++++++++------ 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h b/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h index 03d4f387d88..2d21486eb67 100644 --- a/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h +++ b/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h @@ -231,10 +231,10 @@ class SCSHAREDSHARED_EXPORT AbstractPlugin : public QThread */ inline void addPluginAction(QAction* pAction); - InputConnectorList m_inputConnectors; /**< Set of input connectors associated with this plug-in. */ - OutputConnectorList m_outputConnectors; /**< Set of output connectors associated with this plug-in. */ + InputConnectorList m_inputConnectors; /**< Set of input connectors associated with this plug-in. */ + OutputConnectorList m_outputConnectors; /**< Set of output connectors associated with this plug-in. */ - bool m_bPluginControlWidgetsInit = false; /**< Flag to indicate if the plugin control widgets were initialized already. */ + bool m_bPluginControlWidgetsInit = false; /**< Flag to indicate if the plugin control widgets were initialized already. */ private: QList< QAction* > m_qListPluginActions; /**< List of plugin actions. */ diff --git a/src/applications/mne_scan/mne_scan/main.cpp b/src/applications/mne_scan/mne_scan/main.cpp index 7f09d4fd354..b6ccfd2b646 100644 --- a/src/applications/mne_scan/mne_scan/main.cpp +++ b/src/applications/mne_scan/mne_scan/main.cpp @@ -92,6 +92,7 @@ Q_IMPORT_PLUGIN(NeuronalConnectivity) Q_IMPORT_PLUGIN(FtBuffer) Q_IMPORT_PLUGIN(WriteToFile) Q_IMPORT_PLUGIN(Hpi) +Q_IMPORT_PLUGIN(Fieldline) //Q_IMPORT_PLUGIN(DummyToolbox) #ifdef WITHGUSBAMP Q_IMPORT_PLUGIN(GUSBAmp) @@ -134,6 +135,7 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(averaging); Q_INIT_RESOURCE(writetofile); Q_INIT_RESOURCE(hpi); + Q_INIT_RESOURCE(fieldline); #ifdef WITHBRAINAMP Q_INIT_RESOURCE(brainamp); #endif diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 42dd0dd8bbd..b93b8d8cc3b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -157,7 +157,6 @@ QSharedPointer Fieldline::clone() const { //============================================================================================================= void Fieldline::init() { - // we instantiante m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Plugin", @@ -297,13 +296,12 @@ void Fieldline::run() { } m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( - m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); m_pRTMSA_Fieldline->measurementData()->setVisibility(true); Eigen::MatrixXd matData; matData.resize(m_pFiffInfo->nchan, 200); - // matData.setZero(); for (;;) { // gather the data @@ -311,7 +309,7 @@ void Fieldline::run() { matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); matData *= 4e-12; - msleep(200); + msleep(2000); if (isInterruptionRequested()) break; diff --git a/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt b/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt index cf29962d943..6700cf58afa 100644 --- a/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt +++ b/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt @@ -3,7 +3,7 @@ find_package(OpenGL) if(QT4_FOUND AND OPENGL_FOUND) - set(QT_USE_QTOPENGL TRUE) + set(QT_USE_QTOPENGL FALSE) include(${QT_USE_FILE}) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -27,3 +27,4 @@ else() endif() + diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index e7f7de7e8f2..144cc99a4fe 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -236,11 +236,12 @@ fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) sensors.back()->setLabel(QString::number(i + 1)); ui->sensor_frame->layout()->addWidget(sensors.back()); connect(sensors.back(), &QWidget::customContextMenuRequested, - [this, i, &last_item](const QPoint& pos) { - qDebug() << "clicked " << i+1; - qDebug() << "global pos: " << last_item->mapToGlobal(pos); - this->emit clicked(i, last_item->mapToGlobal(pos)); - }); + [this, i, &last_item](const QPoint& pos) + { + qDebug() << "clicked " << i+1; + qDebug() << "global pos: " << last_item->mapToGlobal(pos); + this->emit clicked(i, last_item->mapToGlobal(pos)); + }); connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); } } @@ -256,7 +257,8 @@ fl_chassis::~fl_chassis() void fl_chassis::setColor(size_t sensor_num, const QColor& color) { - if(sensor_num > sensors.size() || sensor_num < 1){ + if(sensor_num > sensors.size() || sensor_num < 1) + { return; } sensors.at(sensor_num - 1)->setColor(color); diff --git a/src/libraries/disp/viewers/helpers/rtfiffrawviewdelegate.cpp b/src/libraries/disp/viewers/helpers/rtfiffrawviewdelegate.cpp index c5c9becb99b..f4c82296c0b 100644 --- a/src/libraries/disp/viewers/helpers/rtfiffrawviewdelegate.cpp +++ b/src/libraries/disp/viewers/helpers/rtfiffrawviewdelegate.cpp @@ -460,15 +460,24 @@ void RtFiffRawViewDelegate::createPlotPath(const QModelIndex &index, // The plot works as a rolling time-cursor, ploting data on top of previous // runs. You always plot one whole window of data, between first sample and - // numSamplesToPlot (or data.second) Even if the only change is a new block - // of samples to the left of the time-cursor. At any time, to the left of - // the time-cursor you have the most recent data (A part) corresponding to - // the current roll. To the right of the time-cursor, you have data - // corresponding to the previous roll. + // numSamplesToPlot (or data.second). Even if the only change is a new + // block of samples to the left of the time-cursor. At any time, to the + // left of the time-cursor you have the most recent data (A part) + // corresponding to the current roll. To the right of the time-cursor, you + // have data corresponding to the previous roll. for (int j = 0; j < data.second; ++j) { - dY = data.first[j]; - path.lineTo(calcPoint(path, dPixelsPerSample, dY, - dChannelOffset, dScaleY)); + if (j < iTimeCursorSample) { + // A part + dY = data.first[j]; // - data.first[0]; + } else { + // B part + dY = data.first[j]; // - firstValuePreviousPlot; + } + path.lineTo(calcPoint(path, + dPixelsPerSample, + dY, + dChannelOffset, + dScaleY)); } } From d8b00131559ac4745cc178f321283fe1b2a575c6 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 3 Mar 2023 21:44:50 -0500 Subject: [PATCH 035/147] fix quick control settings --- .../mne_scan/images/icons/quickControl.png | Bin 0 -> 16076 bytes .../mne_scan/mne_scan/mainwindow.cpp | 22 ++--- .../mne_scan/mne_scan/mne_scan.qrc | 1 + .../mne_scan/plugins/fieldline/fieldline.cpp | 75 +++++++----------- .../plugins/noisereduction/noisereduction.cpp | 2 +- 5 files changed, 45 insertions(+), 55 deletions(-) create mode 100644 src/applications/mne_scan/mne_scan/images/icons/quickControl.png diff --git a/src/applications/mne_scan/mne_scan/images/icons/quickControl.png b/src/applications/mne_scan/mne_scan/images/icons/quickControl.png new file mode 100644 index 0000000000000000000000000000000000000000..a9ddae68d08bdd783f581eb6b9ef5a0ea5782c8e GIT binary patch literal 16076 zcmZvDbyQVb)GvsHG}4{Yf`o*W(%mVgfJt|EgLFx!lF~|t(jd|xh=g<>N*dnue&dbz z{qfEiT)Cbjd$ZSEbN*_DtE#n?8Twz#OMkSwgG>Gg`hz(}jg9q_lrWNS=uCh8xy{$Ry_6Bio4~oY4 zp4zQ`PvvX-o+<1|g2`a(fa4WJk>eHQn5sFk6XQ5`XxRYi;9YrKWGv!-e3gem{rvq)8W^SzOEHGm59jWXHV+) z^W~?ALX(P=W?1M7^(DfTx$P~(5SJGpe;1M0)=~NiUP+1{zO*fVdYnJvmlB_xO!BF+ z5`XdVY|37FEuT3Fg|_D)hDMCS+0jwz;NZaSC|SN9!8=e0&M)S0m!@2$tJ> zs-jDEKS^$FZrUBK3u`(%J3C$c-Emkj*KVLXB_l?)XmZ(+baZg|?_EktN~f*};{Ww- zczF09%c=6df*;H(X-t0+i1m8GUc(cL*glzUlkK@&c~w;s<7PJvW>=k8uU-*^c4(|q z4<5B>tiXj|Vv%wYX|fWf&cZV%W@cjYBbJ|g@cJ>X7q+5@5(Bz8?u$O5VyaUilGlsh zf*CM_84~2EiDYE%+_`g*kK28mh(ep6_g;B*c)I45M5p{5rNw$UAxl|$S{lu9_ky>z zvM_?D{AcZ(vD>n;vIusLnw^PKy?{tkZe9!B$K-dFalPI}?swoxgbfS~ym)GQet!N( zC0(Fzd4)1R&GVh|N7Cw^TEFKxznfg^B-{{>KMoBu%0*k9oSdX=RNO_=Il%~rCp6); z(C)uVDQHvljA@U!dVi@$(9_+W$MXe3T%ZWvCsCG@TU(8$7U?!_@gPPyzLEcF<x}W)ofA8Iz>F@8)sChLM-7d1)BO7B}N}K+2E_E*ihqAh~q{J#n z(ypav^3T%Jy~+ERNX;!RT|Z@|@ljDxrRC&UJeRto7_0uC>2ENZWZ>!BQ-5Vz>WPt9 z+1=eu%gl_bt&_sW_#)u6uAa2lcGF5sd3;g)clUQ`d}`|SyCn2XRXN#rWXM093T@_^ zg}1Enu_mu+2{Wlq_sRqUzdq2>&>-MVRW98aD>SXHs(La$J|6q4&bFfpm6YpUR8(+o zZf=nGt7mmFVPUU1*x0^WD~yheJVC>uxQ)!Wp33(sV{2)aSV3cs`7rxRi zhadFyneyn^Sbk%Dy%CR~pj={NB2z^5==iv@_x_)*WvxP00vB7Pg`u>EO0Sc0n7w@) zA?n52pm!@{Z|z4WrRVlf9@@Oe$O}X1g0^a!n(^FOjy|uJa3}?^**G`?eP3&6jQmOA zHl5seYfg|}+1k1iS6r~Pv{a)KaoNs@W0d^ zWo2bLR_ffb4QF9t;T~RI-snTO<`^#dtNdHy34P|mu}gE(5G$#svU1Ldij zppK4Cf$z~9?sD%y%Ir*FUR_`WM84VdC8GDJh1WD-8;Upv^y;bHt z!=-u^GhgcJPA<7)ix9>~7tj18oYsfA#l*yhR@c^)o~YcsoUSl!E8N-HxjH&Jx~Af_ z=ykvi9a~*owBH%vZgcu$Clrg4Q0sEMsS_;b`M2Qme5)b>Uc}j=?$u4r&9lL(g@W+v z2-e;l?C-}^QC7}~OGr3u8b{yqM?M!tz(Wv*yWvMi56y=wC71L&IXfq$r>6_U|B>8d zW@hi~?w%ncB9bO2C%>w7Sm__oq`t&C`~)>{pMwL7ivRU++6SeS)gRdsZN^$!2_MVK zE-iI*ChA5LpC~C|si>)CpIn|fK8L@m7^PC0Y4*H*O318?c=>>A8+N2TFN=k>HT9qM zb+Yo};&Awz*uHaa6ErlmaDIwU>&IJDlzI92#Z^^Ri$+|e;qTrhhV$9l+1b_m`y*F7 zZH!hXap*qn=o1#0Q>kPibkX$bp);`$4BleBWS(FyEWe0tFkp@T6|{tS+

lYQ)kh^Y(~L_i zZuPOGC;X6F8$7+MJvBctZr8Xh8I zVst}8!<)0|SJ@*_B{CHWC@}=p-aKl+aE677IJvF+L@w<=oGo`iHG|pik_MOih`}{#9ZQ z+V)3Dfwu4C>De?qHg?#uq-04@FnBVYEA`ark?|r-^p$5>os^Q(nO-w9GYjW_G@@?9 zbwx$%rXtQa*H@o^&(4~V!AA5aq-!P&>&onz@~e3Uzo4h2WWdtaRE4dRpm%Z;0^`^lcYe7P!UGh6?AL0wjtQpBZGM90L*k}+Zy+f!3(R@h|!_wP*BPUhz3%aflBuSvO0-nn-q z{@K`ItE{UlEGjM48XXbYmn$>A{!BGp z0Eg}VeVK**mw-2@wHTJ}TE2bT$R{Ku)ZWpt)IVOV)p9YTfwnZ`qL>^T`^@KfbK(lX znQB~I+=z^f%)CNB;dw{Q9U7caJlg2?dqVf_1wSwpLWT*OBXM(i=y!hZF&dMmiQL-I zaF)~F-hO#;vPYP8+C=?z1B*tJMl7CFgodgVHW>ctlhF;QY@JfwoqICv;{6r?7sa8F z+r}p+zZtX)ETJc};Zi>$^3RmGe;?<~n>SxaKPXX%h=@3CO@0bAZS^vsAmm;(6sK11HH}?4SGpM$o=cPgk3iPBZzOVPUg9Fw6%p2sssvVD$Oz#PjMi-*=Z^Y<_PV7#e!w(~xs;aCqvVdU$wz z8%!4@{GoGHjwnF#{r;XOm_x6eKdIA(qgeJUbwHnmlsuBtdHOob9H$jQjqV_{;REAb_NZVLZqkT|qPd$ANF z!Q|kxWs?zeyl3jQ-=%>T$V1A@ccdH0I0dMp-g2_+Yi8I~A0_K~xexmp>XD z*Tmz3Dhk^5u<`KPbWBWarY0vtl%jpE&grwg4itJCc(}RMlylW*y3DHXaxr7v+PG%N z#=$vO%@)t}IoUNvZ@yYN`pJ*9`UAQ{VMAl1svFE*R04!nu{Lr0ky6hQJ2n_{(Kt9m=7SQ`72B$q<9r;u)io)6Y z{AeQqc$)OHCtI7}E6U4#>OOt4CaR~TBqO{0;(oZA>Irx5e0A>Z3!AkyDQRLMAmG+) z`O35QqVn?Vo#nm+d@Cu|C@hVIQb59%g~i3iEOE*fxVX6Tva;QA04gpy6kktQzX*j6 zQeJ5_&0DwgtF8%#Ar+uey|=L2nvMB;(Xf54@My(FUH1RToTZxFsUGIqw{r zYgArdo)n8()@^i=*(c;dezs<2ywe>WjKrFVMU`wE5i#j!)Dk|;zp5A+7$mW=v1f|3 zH-pQ{%FuJD>>hX$+7mar?wK?kqj8(b7nnA?*<%FIE#k+aHa(iHDuX9ftX(ny=xbf# z5+Rk68;<0orlz(ZOD`4sYA9er*EhHqQsXLmw30F-LnEQk1w6vK!3|VyxC0W_oz8u2B?z)bSeC1xe_5KxrNuK>~ zbRMFQLZ7Q?X=%A4V@_Z@LLlgtzq)LWvwec*t;5aD?e34l7C_Fug@TUzUbA@Ig_=5Z zb4cRG$gj@V%q-6uP?#7W-yv>RtKB3_JL&xV{QHWEiY9+HBC$?6Ng_YH?f;2yY4erRC@4@s34WHgxH%eA`&uENn3{TL)lRvu*$!Fa z(W9sDQ&Qxl1$r5*Ha0dCJeY9kpBIex_4O6^PEJlTv9p(SL?U1&qKVQ}B(~eJrVk2S z10rr%TwEk73Wkea{h9Z@`JISVAwG7GhiBwq=CftcEmbIp5kEg9#1cLA=_cHPGu%NC zk?^y2q}JfzVBFA-jWgx)Ag0~svBi$ii*RX%xRewotgm418(CRxn~|Ng`=ek}M9HR0_=>moJ27nqV!OoRUiBrgBn@SWF(#_CkBksx z3fg9&>5eh4Qv2@Ad}fWSr2*(`ASIRG1*|5kV^N;vH#vD)PrEq)u0Xn^?$yEcLt(1_ zMtmd8nmIdfSzs({x;i@6!Yi1qjXss;s4NmtB17v4*8)frBBbNMHd z+lWpOC)zVnyAT;q82{4o`tnQypsRSw<}%&k#olpP{ZY_c zEp2R~yFX!UxIRu*e%T&?isd3BE6at6i<|7RtMEpJjg76ZIWN!5$=Z77l_<@gZAFWI zcWqr=sQf3t>gsA^;}KV^OIS>v$gaG{K9tQkUJkIlDems>3J>uZOd1fwJ)NDmbpfS< zHXy=EgqgCi@oTIW6BF|SCZE{n+SN6D*>lmo*^56~Vl~ zBMO&RRA;E+=0^+EP|hDQa&U0y-rCq`fh%wRt>IQWggr^|duGO?y1xD={`W@dw1fo0 zYS+EFF#uDhu9Iy_3$}C3XEN^Y4ZPW)~py3nDd8P zy)R@%y-pu^|EzqjY!|XMh(yV7n5)iu91#)G4{)AD-@rha)1X>hN$y2qHv zv$F37YKe&8lDAXl?kPZxHQjO};j5K_6l!PnzSl?v@Ka05WEK5o==u1x5R)`&-5H+g z=s$00Mcw>ne*NOJn5agJGX_w`5S#Q4O~Hy!?Po3#^N{ae`&mPpx>8ZqvabXx3|II zc$6|=%>&nNv0n=5yr*ewWJFgVPD@T+JWI{o_<6JWMWx;1H{N^q?g`A{cbwc=SYOA; z&Ykl2_fK1JnEkbOE!aazv-~1OHea0;-=UC|B$Ca}C765Na7g!O=0Xj&D?NKsgygX_ zC<39+%;K5~3U0exU$=N~`#-$-`^)xBLqp>s+}c8Zpv)!L8#*Qprn^Z{c0)*5eBayA zU;fi(>B%|C*_ey8-}0poW}Tewn*-~d5{9Kruvz({T8m6N9S{)ELS3ypUcamO+lHm_ZbJdtV*9VBsw}8bU6FVKV6Y^ z+p`UPDT*JSj%^%a=c)^ZaHcM>+V9PY<$n0EQZ(0y2;iFm2`<{ez~JiJ(tdoW8P6{1 zjPEAOH+A}k?FeFy2lF^~$iC~txe8;2YObD!KjcPH{Y}~Gk!rtuVFo^Z-q6sXqts8R zb^|J`H_+S!QL|1AW^z&k)~EFN82Cj4#3UrLKn8}YHa9n`V`F1=+?FH4!hU|t&mZ%J z?dRC>?VCEr=OBCuUgZ+IMQ_By6GrVwY-kvl+Y#nwaxpX$Kl=M4G<0=W{UTAx3q$K( z1YMsl#S{RbX*4HBCq?)dM@Os1!dyJ7eBROg#7)7~7wEOLo}OURz{(sMXmhyS+!ZvA zhJQ~^hH9#+$kCo9)%xGT5!JJ{vhqP94FJq$o1DmUG~eug=wWC1qpxooRE;Q+@k4Lk z_K<|k%*?ufxWb}0EEs+J2y_U%2M?f87#M6|9M>?tsT}C|c!pT)s0Ug`x=8h!5J9UKMXtL>lv0v(LFya#Q8ZXiiH>>)YGPFjh>WVv;1*&iWGUVK43yqFqk_k|7gRzcQ?ZZa}5zkBFvQ*9#wgeF>AgxO!8 zacXO7Hm>aK7%RUg4~e$7w`acP|BNboNbMPKDz<_XZcnvdg~?}-!{>*GhiUeA{QK9T zTZumf!Q<2j?-4DJ*=+|9ZnX;4vO_qjgA^;|Z+YpnqXNeK1;z0tw1_iLgeBv6dwY8o zpyZK0_4Lo5KU?BY=hTbGU%`MZ1(BP1cdq5a6TALilto|syepph{sQ&4o4{ zq^{A?c;FYOZ6!oz6WHSg6arTIoiMiwOxUO{H+-*-r!uifIO`ve58M@1Jv=zrgnH%o zxS+>1(}C|yKvF3sM7~?5(dKh?3ztT8{a~kV-e-#N`Z5%kI-+-A04pTT(Crrx%G+mW zXV3Cegmjn;+V|df{1XrdQn;7WhSKHF!a#O6*=+xJA35>y@m{RhDh0^vd$SFUGmXxr zx8klxHwnqeSV3pzjAA_neNTgsFyX7?>i0Mgx`8j&zZhT)1?<0Ew{vii1nuNOI!Du( zbHy!F9i4}vU1rv0MMag@D=DT0m|hs9vyIM{V*oPj3(Gu9I|0a@$Hw9teI@vPAIZQM zm~Qdd#Kb-A7ODUP!0^NE?T>Zdgz|71H}V^Skx)@w{6-42D4fYNHPB}>MO@3RZuySn z$<&KKftpnNC&ryf-?I->`&3lq_RWI#j@XbUYvQZc*4E?}@8%6`R=aJGwM-AX%y@G7 ze5ItM=+g&j4g{jfIOxKM{l#wn?)=)gfB$}<{ZZ(82_DL+ofJ$BM6jQq-;f=v--8Vh zbzc&O$Ds;080~%!3k#daz?(y%?&#=f8=abxkZPX^EGaD=+D9PTGk!;}J1wAt_VD9S zEnD3AE8AKq%H{Rd#U2MIC%>4(G6tJ-RHNZLaEg}B8IUC^$Np(MASsKYsl97adtdVsmd#Z61Be0l~34S63vpt}B~Y7S^sF&_Ob6n`nk%j*!4nQ44ptW}t%PSj<^DzBmv z1;0k;q4|ck@+eoGiHV6B45d`sBt`4#HeZRwQ0(Ri)0&q!nEUVDDC+4gUcMBEU7yar z)59j};4Fg`V+1XqEnhZ@B23T$Y)uScDy8GD-m$dNqDsk}Z@~I|uVTdzC+`IfSrZf6 z4DGEe)**=27<<2)LX}v1+Yw`G5-OX~bp^hz_V#Q~E1&t_$!dO#s6IQ|(2`$XCLtmk zXK}fx^Ee;!z2>WHY&)36}sB+{7g(3)~%A4j)ECMa_jVTW^xQm=xP* zalHVXBBF+zpyA$zBMhu#utd@k%^%x}UquSD5o(+vohC4=G`7L$=N=myi_{?Ms(lU+ z_6rClF^T%9nl4_9jEuXmo6do85+rafc+rxQhHl6Ogg+OQ&RKu|o{UG=1U8!MQ$xcO z7=ILTD=)&Gt*Y1COKX6W5^nzyqS#zpliOlTxL-B^bwrOq8xx)fam(QITVmjDwI`)C z0h(=KneYOe7tlrRi2iqlH`V&?F0$wbkrEf%H3Av!Lx}x-a*mCk)x#130)KI%pC#ii z+?=gtM~KCJIKx5ws@grxQ7dY6+np6w*3dQH$WEm81rtOEwvF2tk}B|+{j;;P#~E)} zR5MtgR+$Cg$tvrz6U`ZU-Q(@;z1DxrExaEAD@jF&8SJ=#5m=QA?hv!*-)%N!HMNxU z?!@=+ds{*L;Se<-PE1NFb=jNy6lpJ>8UK7zUJnJ}{3Izcaq%L-N7FW+K>#yme>S9o z1nB6Hg2OyTRal9{VG4bp2faqn?Yxg-r$33~W~j5XQ}fA_=VUa~@BoL6n_Lto8c~|A zc7HcfLRs1y{8d&_*$RA}mTHZJMC0)<3lJE1&xMj6^^}K)=d!Gf(YdrmM)LPqlm9oL%sDPnQ8wwC`p9znY@Cka-&y|N~%*+xu{4)Un4 zwvLWi%)56?%iF;+Sy=_(mb-t1qC(zKdhmtD(OAFU?m0)2Vi)Qk@P`G4vL#IaF!Hjs zOV}+u-hujki1_&q!T=O%S)$=vCVuvd*D@jKrwc6Cr~6CI-WPw5_2~pg+@Ei(EiEO8 z!0xjQ^KAd=fqe?bfptq`V>M0RNvt(NF(vL||@r z)sP}b5lFP({=gje1k}2eUxi3^rf_vV`3~-9biff4nPChvRD8osZ?8OIz7ci%&2oZT zKk5CaLDNoi1U8iE723##rJA!qZ8 z%$GB@Z|X8LGP(oi3A!iE+W|yK2Ll|#)pg{cn(BT>uC=5a+xNN`Mc>?`)4d+}3ei|H50qc0cw@)=zX9>-=m7(g;1AqOHGQ;}_8 zG%Qb~;H023sJ>;CefQd=)vKX1yKGlLqah(}`%!UMXD7e78v>~&lX&u}l2WNSJG-Jl z#&}r$Jpe{??E?c!n>KwQp^<(vYS7$Gp8buxKi@XcY{;9bS`iTym2`R)O62%a6d#qc z#3OK13QHQ6fDO!}xF~c^_x0ztj~lmm>a3=#vxe4u)pJ9~KB^FY&k{=~>XC(3rhm)5 zvcbwf`*o$ey*&>FF>&y8QbKQ8I9j?|8h`O%M~9SIByO)V1>%KpOD||HktFw@GO2No z;waKT5EB<~1*<`3b3+DLNV%jnvZzD`0i!Gic;C?jm`pm3%nwqIgEWCKvCcVUE&Ox_ zY2($GFJBIVG~Mtc{FCJ+i^0X-uV}lD;INa~Y!~F=nU;9bPn4=cUk`GX5Ln&rm|wXb zr)FkSlai9kDMqxGSE}&`F91(i0!kwv7gL*$t4w5@X6HVtk8Q|^d)L?ZW(UO9gMunD zr^(XxJ*79_AOP|T`hWjekU5f$9@7E;qPjp89&w1Dne9OG{RGmGSp3uBO!?;+=;-J` zjS~1R35!L<=P2|KG#@kNtm8!DwGa*e^QhsfzGUs854Se{*miYwoe6zIT!(ze`+RB$ z&{x0NqVe=sfkJ{h9v)sQN^A2hi+j4@OI2FKh9QW;VALCxD<@tglDh2%-x>lr?H7b` z#=to|H}YQtnntUq&6NCjPbC?38TN~-mZql1r}mnN($Xygh}KMPZ(H4dMPJdj^A>jD zpi~I9{UHJ&6zSfS;P-%m;hP~RNe}p7><4FF-!j_SCuV2A1MPcSR8ZigG^3-HGZX%p zj*JB#<1QF}J+abj>ZgCeTeBv@>;h+xKdbVtofAY4GWP#%)ug1PdZV~`>RV3YUZ-}; z--59Ue`JYm`P0c`;SyXk-1BI7;UJVj4bt(P`on_HpOboj`X2KEyzt9w28^QTaH z$6^?hSxD6(sFPGb!C;PpQKRT~fP9r8MiiQ_S?mc-*nHZ`rKq-~@NrVYKab4Q)04JJ ze_JW1{?`pjrX+G?S`H9TbP0(zYcd^X0s{vJ-cJPu7Pqs9vJLe0>z~|x8H+VBI(iq3 z{}?4zRg-W!c|sE(5L5H>376N`UyED)d|=D^X>2^m^Ltw#M#AvKgvyFTgWx|&wqszR z6nBp)Y!o2dY7~{Q0~u3XeC^lZGm!l%DX-d>_G6v5CgU^}P@6fYtpvcbYI*}A3nDm9 zTl;o21>hlfFsj9p?{l%SDJ;PgMFt;x31lVed%rnTm6>mUpo3^uM3dLqL1bDQg;9g5 z{r_XefofLJ`Ps0LqBY>D^ucEEv9Yn4xXah|mF}O81k1Y&J(3qFiQSQx1RE9Yf*kbx z;Gp2(Ctp|0f#AHLr>8Hif%}I?N=T+(K=tqJq=l zd*hS;<%k^P&q3!W-e!-@Mv+0U$IK0NrXde-Vat`cHKL zTtmOlh4)RPc>JY6y4W7%o?1cibp%QBgraoVViZ&gTWKGkYhzfqVE7$J^*LBsEkK`( zA&Bg9pZ7lbZHIBr#l>Z!4KCDEJ-wcava)TV(T&Z`QGHGlDIi1Bot;drpFZ8!pu;x; z#L=3o{x--{C+U=y?@*5kvv{7Lj}m&H09*vf_j!(aIvw+l|iy!wG)arzRP5k^H0Zm z_YONNH8nLTV-9Nkrv{M@QDhg9d=2Z}aC~`HEF2dONaj%@UrMnNVU7nebgf-xkNQ!7ZMz}~=(Ysk=ph6E?@fwO%?C+7p9a>zBlGI{EgyjLzA(lW zNx9^&Ut~PABv}H&G6;gpI}n9$T#sMm++$%03=W+e9;TcAAcMAgKtrGoDGeR8z>yz| zc1#kcvHU&o97Y?AY$D-qH-Q*3&0QK987**i!u;PBz>+F#p8{>O4#FB65MtW?ncMr? zE*j!8AOC9Wh&A(~obvJV-iD+BMrsdDvqP)`UQapzq@Nq))wj=G*T_I_8T|2s#J|jf z|1<)u8vJRXntMiECj%$@+eD{)FTV>FR#Zr2G7U$91@&TQY3cC&yKseso^*4y;;5*o zTjZoBZ~AAbZR<~0mX|Sl-jSP+|LRHKwFqw8gYtL{u{^FUGrP?F;3dYG9uZflGV*#q zyv}q1YY$Mqo^yrY!TC`R`h}yY_xaIF0P{U_;zQ;}egvT6Zh+9QT=`7FY^{fvW||-I z?ar$?2q_4HOdxzTDMK>U49a3*H8@`b^InI8ctG4#y3!o3z0KQS=$V?{biuY1`E)+D zLhcJTZz15>S0)V(s6$lOc{^aY@;+<#)5Atv+7fnLoxRstkn+gCxTd*T^euQDD3HXw zOa8Gl>pkXs?Kk{sNRrHu2iwdNFi?EdQ&3Pa0{fN)%wQbQAu+1Jl#?_wH&+9Ud$sk0 z%*nF>2Ll7YMxRsh%^Nlw`tgYgED)et-M$8(cKQg{%Q3Y{L8pBNIT>be@2fz`T)R7G zjIli$0D2{2dJf_9#`9X-)yoPu5~=|1v;g(gSG2a$)TII%!YD2+C4|~`B~Sl#A8~wi zq#G0xvfJ!?BfcwKJ-yulV!JO`b+5idN(WyMg?t04RSdd?JvuJcX?a6~@Kf1N4?XO} zJ_|HX{mN&0Zf>V}SqCj~AvB;ReCJ?imj$cTr+aCCb&0y;#}8Z_m}C%S{W+mCZ{v@b z30%Y&rvK3^U0o6`VekSrL8hw1rV_FXEqh9YP=5WVGu-!|Ud3e>#JIFVG4wNY1V}a` zBzn&N%>rd5rHc>d>3$PD?v`*>MFCojS{VxLb(8a5t<`yg}USUI&Fo%llwiVFi>cj1L$YqVBw#ySwH7 zbQsJmyrS)eGIDZQAQfQ@e*gOQD;O0uYJ2j(Rc1#MOyuq=f+tn7`RCpP6fX845RyDqZtSUOkpYfDF8KICoR;rR z3}O2GFAMK(98RjZcVkFtsbx$9HR0X(g8w|cnPzv#Na)8C!^8L^bJ`gc%SQZ~+8dONLYInc?@Zsm=Ub1YTbGEyLgp7?)ji*9! zxL!fvuaj__7-{P16@uN6`_FMq?_FN@7B|9qyj>X+qm~4Vzf*&RR{*Pq1I5k^km$Xj zj;M%F=qh}RUS{0%*Zs+puckC1`YD}rb3WJ!eMBB^ZVP;PE#wOTMxTOFQv#BPjDAnz zn1U%dqf`$*Xcq4PTc40_Rfh-i1<39ZI2R&r1*q8>PXf`NxV(x4ha|=A{12KB?Aaq> zsvinUN(1&_)OGObqVGT)fevBeqOY&dJNaXwduDdl3c^?of56{-%s6 zsG)%0nDybq2Sj~n<@B~Ov=hnKuh+Bn<*>1^mWqmtGu@8X2`0IGNBkLQ0KVI1in=@e zbA7q=EN9z8HE^)8nYr~V={{Fg5xBBu1P7xEsXi(2sx!BpuD%yE__8j%>kk&hK<(|C zM~8k_i4 zN<*7=w19_!fA6M_gpAD1Z8+x%CMZ4jflRfa%(F(xHfb6fimcqHXQjyK`DaUQ$4Fe; zb%?wXZn2<1YKI&y6An4A1(#4q%SCH`aj`qO%t#0r&r{$jkKMg{H~!%8Fc=1auV*kS z4W!c_S%JUqbIfit%Yd*uIanExdi5jY47c>o;co*%RB?nll!D6m$jBLH#TG9Hj)<>~ z&F&b)MY}<;cCFB_GW!L+eh35zZ&d$ISXx(z3ClTuk$#La8FO>dc9S1XBlc(q6a?J( z`-RP}t`ta>(G(9iXO1?;Sk{)8!=Q;ZVN2=g>9zfun-j;pdlwdSUch!v)NyaFrL^3% zZMWjnr@^}FY6@&undXXx1qUM?o#S7SVt&44wXM2)a%FsX0Y#z{2GwfTcVM2neznFeHW2lrAxaoH^uo~aR~2-t{-H}ZqR==O;LdUoEnNG?^SO?q-UfDs z-P9+;SFFX@1xWKhew2g3F?vq5AJ)M5JLLS6A&+hROdvVWQhXmzX-uRWb9oE3k%K3o8(@P4Iyq?qVS!R-aBEFGBR8zB0lKXN)(?eD z9s#EM#yjqf_E7)tgM;X(XlSd1ecuskPat;oi01x+gG^`Op0N*-4-O6v2IiA>r^cZY zozlO5Nfs=g&jL%hfFE%M{UWm2=jy51a9|DjY{ddk&4*z1-1xTQ7m%l0_q{&M{%XXP za?~qUjARNmZUu)>xRIZ!bNb6)TpkXII1C0(&4FY`5cVn<9hk@80G0H77zX7m0#aQgu;#fv(bN~Eithn|gCe-(BK7e> z^~}#I^RFL{K?{Allp*Y>uav@N%@SG1dEh@z4Q5gRU{dF1R}j+UnVFd!8oe*R+;l~f z&YL`Dt9dzi7Xo1ZdBw#FFmpPNyUky|41uBYXk~3}$@O>V1CC;3Q#rX;-yp$TQK`=f zIC%|O%kC0MFBJTYfb=&VFoFj`6`428{W>=07}MH%&0EcFn!uvA+pA)3VNozYH^&8{ z0#k+L?GTw*fj;?EC)SX(Cxwv7 zTRWp*ZdW}YV>_dgqN3Ll9!Ew0#c1WFBs5XPF)VFuC8oZ9r7v%7H9@_`BSAT(3NTfH zlM-Km19r^KWr6!DE8=_I%ql22h597+@&|MO%NoJPhK9jKhlWp_B$i|uH~WpXE+3@b z0(*OVi*7bcD`cf)!@x7Hp`fIEcs`@C4i4!{00b5Em9)I18RFiL%(s75ZJwQFmXHX3 zX@7+te`ji9Ld>FOx*z6y59DMY-QWCJR3!8h94a+XiPEyNvi{AKqe~=n@wu*!7NT{sU&js9)#>8+ zrr{u10<&7yHrnyWoSzh_DgXm4dSmHZVIXAz;~J+0j#P&cp!^gvu6KBQ=+pK7Z%o|6 z;_~gwm)%-=dTL(hM{ks2ck!f}KM8jIxuT_|6>|+S&_kvLm488T3NSno`K;{hKY%(9 z!aDim(TJW-rAP(XUr*?4wucfx0A*qD*@K^;>KTXREoQ!tic$$nNYD}zDpc5V9%*l< zi<8YKo|v4p`Ptye;taEU@xdg_WU>f7lQ+W^#!UiL(P*G_VPOF?fpbYVkWu*vJkNB* z+TtDFt20M;g@klpg7K@u zb^pGKu7<|h=f*~gR%K0CzPIaesWma*Ya=*Da#1>twu#*BO>=7N%mYiiP_ND(foPIF34ee+s+VO(yO= zO_`m#&K1~w1R(e(hl@mYCU|uC)uJ*e(N&+id3w&fIyh7Z^U8{m-`&{WE|YZ0tN>}C z1X|2reOV}BDd9|LLcc-e_Y*U)WKi-F*Ix*XhqDh6^v?Xtiw#a2cV!e5!tY4jdUK5r z53AOIQ}>siske;cJDP$ake_rL9aa>R`2A7v!f*NKya6?xm5LCL`q9xNZtfxJH1ogA zdw3M5H|m^>fUL7s3n|xDS6#+;lP2+yd|tzNjMJ~P`+f%#^KOS>Fh9liww*1KF*XH% zksCO6fdscVde3fh1;a@Tx!J<{EH;6!3%&x^yJTu~)C>(*N1FGmv*0UA%5*Fa-Llg% zk;dI?-1dJ)))2t6_DF$ZoH_A@?CNTV=WwfCU~RsHa#dI(l`UCbesEFbccc3P+-brd zkVtwaCtXxMJw>pn<{J-KzLjpCp1O@5VJ@7&L|RJ9<@2Zw}pxKzw+1 zX(@f?&3Xm4#jAU8?6eqAt~w0L&8>>I*4yQyvEzxoE2D6{0wiF}hp8A3k$j}3r41Dn z?(FukpL&2`Ne`1v4m6S-BVFCUfEH!^ht>wL-ZmTH2qQ#7@2#U{3Rusu;f5}G0OpMz zU)KKx)u_{YbA6#(cC?q@VcCX0WfG<>V*jVJI5Ck3qh#-WAQP`wkvE+5tgHs|It^G? zK>ZlSl5r^@^27{FLkB8l8V*iUh3ou?Nm7Mlj2wIa_ZVZ$Z`#*}PoLIB;hvcO6cOyW1N=GUTzd-cQ4{ho7YSeLl37Z zC@yAWy?>whWN$tjWV9UVTy-KgB1JiD_VG%Y|IZ;yz~(7QNsIkY@aPjE6WrRjwBPO9 zIS~A2(_z6}lQ4iv)U8rjOss`5NK^M0G=nr!PW|>ooihssu75{OWkI&_1m(j93rqHI zLG1L*%oj)yUL~al5PhU&C4`S~Z3F)66s1x7c--}}rVD=g&ZKUXr6UO;-c%ELgV8U5 z@8Imk6Ry z6?u8OZ3cfS9NOFe4%#Mb;CfN@$J=Yd=Q!1&rG#zYLKO-QbhrDFu*@&7uy zZ1E_Na~xJeyY7EZCWHTr3xqz%>MH~A0sL@jFZLu%)pH^cfAs)Uf7C2SH2xw$Vjzk9 zg?j4=N0hAPMFk_XBG?Pqr*eVKG#Iyv#r#NVuOVqfa6}v~9RcL49qW67t^4PHFU?}@ zun^=qOnwR+H#V5MBRLlF>a3UR0p0eT^Yij6?JOn2?rq|qkcAN!M+beuEG6(=_*>Pv f3N_1x8)OFLZtdJFwG23(j-()?DqSx5Ea3kDaUQO+ literal 0 HcmV?d00001 diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index ec6f3a67a09..e98c916e0fa 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -578,12 +578,14 @@ void MainWindow::createActions() connect(m_pActionStop.data(), &QAction::triggered, this, &MainWindow::stopMeasurement); - //Display Toolbar - m_pActionQuickControl = new QAction(QIcon(":/images/quickControl.png"), tr("Show quick control widget"),this); + // Display Toolbar + m_pActionQuickControl = new QAction( + QIcon(":/images/quickControl.png"), + tr("Show quick control widget"),this); m_pActionQuickControl->setStatusTip(tr("Show quick control widget")); connect(m_pActionQuickControl.data(), &QAction::triggered, m_pQuickControlView.data(), &QuickControlView::show); - m_pActionQuickControl->setVisible(false); + m_pActionQuickControl->setVisible(true); } //============================================================================================================= @@ -646,8 +648,8 @@ void MainWindow::createMenus() void MainWindow::createToolBars() { - //Control - if(!m_pToolBar) { + // Control + if (!m_pToolBar) { m_pToolBar = addToolBar(tr("Control")); m_pToolBar->addAction(m_pActionRun); m_pToolBar->addAction(m_pActionStop); @@ -656,12 +658,13 @@ void MainWindow::createToolBars() m_pToolBar->addSeparator(); m_pLabelTime = new QLabel(this); - m_pToolBar->addWidget(m_pLabelTime); + m_pLabelTime->setStatusTip("Measurement time duration."); m_pLabelTime->setText(QTime(0, 0).toString()); + m_pToolBar->addWidget(m_pLabelTime); } - //Plugin - if(!m_pDynamicPluginToolBar) { + // Plugin + if (!m_pDynamicPluginToolBar) { m_pDynamicPluginToolBar = addToolBar(tr("Plugin Control")); } @@ -811,7 +814,8 @@ void MainWindow::initMultiViewWidget(QListgetName() == "GUSBAmp"|| lPlugins.at(i)->getName() == "LSL Adapter"|| lPlugins.at(i)->getName() == "TMSI"|| - lPlugins.at(i)->getName() == "BrainAMP") { + lPlugins.at(i)->getName() == "BrainAMP" || + lPlugins.at(i)->getName() == "Fieldline OPM") { pMultiViewWinow = m_pMultiView->addWidgetBottom(pWidget, sCurPluginName); } else { pMultiViewWinow = m_pMultiView->addWidgetTop(pWidget, sCurPluginName); diff --git a/src/applications/mne_scan/mne_scan/mne_scan.qrc b/src/applications/mne_scan/mne_scan/mne_scan.qrc index 219b18e23df..8c2b20f8b25 100644 --- a/src/applications/mne_scan/mne_scan/mne_scan.qrc +++ b/src/applications/mne_scan/mne_scan/mne_scan.qrc @@ -4,6 +4,7 @@ images/icons/new.png images/icons/save.png images/icons/stop.png + images/icons/quickControl.png images/icons/sensor.png images/icons/io.png images/icons/algorithm.png diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index b93b8d8cc3b..98bb39a1e18 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -135,33 +135,36 @@ createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } +Fieldline::Fieldline() +{ +} //============================================================================================================= -Fieldline::~Fieldline() { - // If the program is closed while the sampling is in process - // if(this->isRunning()) { - // this->stop(); - // } +Fieldline::~Fieldline() +{ + if(this->isRunning()) { + Fieldline::stop(); + } } //============================================================================================================= -QSharedPointer Fieldline::clone() const { - qDebug() << "Cloning Fieldline."; +QSharedPointer Fieldline::clone() const +{ QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } //============================================================================================================= -void Fieldline::init() { +void Fieldline::init() +{ // we instantiante m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< - SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Plugin", + SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Out", "FieldlinePlguin output"); - + m_pRTMSA_Fieldline->measurementData()->setName(this->getName()); m_outputConnectors.append(m_pRTMSA_Fieldline); qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; @@ -170,13 +173,14 @@ void Fieldline::init() { //============================================================================================================= -void Fieldline::unload() { qDebug() << "unload Fieldline"; } +void Fieldline::unload() +{ +} //============================================================================================================= -bool Fieldline::start() { - qDebug() << "start Fieldline"; - +bool Fieldline::start() +{ // Init circular buffer to transmit data from the producer to this thread // if(!m_pCircularBuffer) { // m_pCircularBuffer = QSharedPointer(new @@ -207,40 +211,34 @@ bool Fieldline::start() { //============================================================================================================= -bool Fieldline::stop() { +bool Fieldline::stop() +{ requestInterruption(); wait(500); - // m_pRMTSA_Natus->measurementData()->clear(); - // - // - // // Clear all data in the buffer connected to displays and other plugins - // m_pCircularBuffer->clear(); - // - // m_pProducerThread.quit(); - // m_pProducerThread.wait(); - qDebug() << "Stop Fieldline"; + m_pRTMSA_Fieldline->measurementData()->clear(); return true; } //============================================================================================================= -SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { - qDebug() << "getType Fieldline"; +SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const +{ return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } //============================================================================================================= -QString Fieldline::getName() const { - // qDebug() << "getName Fieldline"; - return QString("Fieldline OPM"); +QString Fieldline::getName() const +{ + return "Fieldline OPM"; } //============================================================================================================= -QWidget *Fieldline::setupWidget() { - qDebug() << "setupWidget Fieldline"; +QWidget *Fieldline::setupWidget() +{ + guiWidget = std::make_unique(); // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by @@ -259,8 +257,6 @@ QWidget *Fieldline::setupWidget() { flWidget->setBlinkState(1, 5, true); return frame; - - // return new QLabel("Fieldline \n OPM"); } //============================================================================================================= @@ -276,8 +272,6 @@ QWidget *Fieldline::setupWidget() { //============================================================================================================= void Fieldline::run() { - qDebug() << "run Fieldline"; - m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); m_pFiffInfo->sfreq = 1000.0f; @@ -315,20 +309,11 @@ void Fieldline::run() { break; m_pRTMSA_Fieldline->measurementData()->setValue(matData); } - - // //emit values - // if(!isInterruptionRequested()) { - // m_pRMTSA_Natus->measurementData()->setValue(matData); - // } - // } - // } - qDebug() << "run Fieldline finished"; } //============================================================================================================= QString Fieldline::getBuildInfo() { - qDebug() << "getBuildInfo Fieldline"; return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } diff --git a/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp b/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp index 92882f69f60..9775001dccf 100644 --- a/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp +++ b/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp @@ -112,7 +112,7 @@ NoiseReduction::NoiseReduction() NoiseReduction::~NoiseReduction() { if(this->isRunning()) { - stop(); + NoiseReduction::stop(); } } From ac0f1a764ca4499bbe28b6a2069397ca02ae2aef Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 11:49:52 -0500 Subject: [PATCH 036/147] add initial structure plugin Fieldline --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 69 +++++-------------- .../plugins/fieldline/fieldline_global.cpp | 6 +- 2 files changed, 22 insertions(+), 53 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 4df07cb05d2..e1ca2afd007 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -6,49 +6,28 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -find_package(QT NAMES Qt6 Qt5 REQUIRED - COMPONENTS Core Widgets Network Concurrent) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED - COMPONENTS Core Widgets Network Concurrent) - find_package(Python REQUIRED COMPONENTS Interpreter Development) - cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) - - set(PYTHON_COMPILE_FLAGS "--cflags") - execute_process(COMMAND - ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} - OUTPUT_VARIABLE Python_FLAGS - ) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) set(SOURCES + # natus.cpp fieldline_global.cpp - fieldline.cpp - fieldline_acq_system_controller.cpp - fieldline_plugin_gui.cpp + # natusproducer.cpp + # FormFiles/natussetup.cpp ) set(HEADERS + # natus.h fieldline_global.h - fieldline.h - fieldline_acq_system_controller.h - fieldline_plugin_gui.h + # natusproducer.h + # FormFiles/natussetup.h ) set(FILE_TO_UPDATE fieldline_global.cpp) -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) - # message("File fieldline.json exists.") -else() - # message("File fieldline.json does not exist.") - # message("Creating a new fieldline.json file.") - execute_process(COMMAND "echo \"\"" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_FILE fieldline.json) -endif() - set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") -set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES - OBJECT_DEPENDS "${SOURCE_PATHS}") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) @@ -79,30 +58,20 @@ target_link_libraries(${PROJECT_NAME} PRIVATE mne_disp mne_utils mne_fiff - # mne_fs - # mne_mne - # mne_fwd - # mne_inverse - # mne_rtprocessing - # mne_connectivity - # mne_events + mne_fs + mne_mne + mne_fwd + mne_inverse + mne_rtprocessing + mne_connectivity + mne_events scDisp scShared scMeas - ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - ) + ${FFTW_LIBS}) - target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) - separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") - target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) - -target_compile_definitions(${PROJECT_NAME} PRIVATE - SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" - MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" -) +target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}") if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${PROJECT_NAME} PRIVATE - STATICBUILD QT_STATICPLUGIN) + target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) endif() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp index 13809aec2de..2e691274c01 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp @@ -43,12 +43,12 @@ // DEFINE METHODS //============================================================================================================= -const char* FIELDLINEPLUGIN::buildDateTime() { return UTILSLIB::dateTimeNow();} +const char* FIELDLINEPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHash() { return UTILSLIB::gitHash();} +const char* FIELDLINEPLUGIN::buildHash(){ return UTILSLIB::gitHash();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHashLong() { return UTILSLIB::gitHashLong();} +const char* FIELDLINEPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} From 64cec782462dbe35db61cfcb64b4582902193ed2 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 13:15:29 -0500 Subject: [PATCH 037/147] add fieldline header file for the plugin --- .../mne_scan/plugins/CMakeLists.txt | 2 +- .../mne_scan/plugins/fieldline/fieldline.h | 76 +++++++++---------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 428ec8d8392..00959801da3 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -add_subdirectory(fieldline) +# add_subdirectory(fieldline) # Algorithm Plugin add_subdirectory(rtcmne) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 12012882d48..93b9fb66232 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -36,23 +36,17 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= -#include "fieldline/fieldline_global.h" -#include "fieldline/fieldline_acq_system_controller.h" -#include "fieldline/fieldline_plugin_gui.h" +#include "fieldline_global.h" -#include -#include - -#include +// #include // #include -#include //============================================================================================================= // QT INCLUDES //============================================================================================================= -#include -#include +// #include +// #include //============================================================================================================= // EIGEN INCLUDES @@ -61,22 +55,23 @@ // #include //============================================================================================================= -// FORWARD DECLARATION +// FORWARD DECLARATIONS //============================================================================================================= namespace SCMEASLIB { -class RealTimeMultiSampleArray; + class RealTimeMultiSampleArray; } namespace FIFFLIB { -class FiffInfo; + class FiffInfo; } //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN //============================================================================================================= -namespace FIELDLINEPLUGIN { +namespace FIELDLINEPLUGIN +{ //============================================================================================================= // FIELDLINEPLUGIN FORWARD DECLARATIONS @@ -91,7 +86,8 @@ namespace FIELDLINEPLUGIN { * * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. */ -class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { +class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor +{ Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces @@ -99,7 +95,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // friend class FieldlineSetup; - public: +public: //========================================================================================================= /** * Constructs a Fieldline. @@ -110,7 +106,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { /** * Destroys the Fieldline. */ - ~Fieldline(); + virtual ~Fieldline(); //========================================================================================================= /** @@ -134,7 +130,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { /** * Sets up the fiff info with the current data chosen by the user. */ - // void setUpFiffInfo(); + void setUpFiffInfo(); //========================================================================================================= /** @@ -149,44 +145,40 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { virtual bool stop(); virtual AbstractPlugin::PluginType getType() const; - virtual QString getName() const; - virtual QWidget* setupWidget(); - virtual QString getBuildInfo(); - protected: +protected: //========================================================================================================= /** * Call this function whenenver you received new data. * * @param[in] matData The new data. */ - // void onNewDataAvailable(const Eigen::MatrixXd &matData); + void onNewDataAvailable(const Eigen::MatrixXd &matData); //========================================================================================================= /** - * the starting point for the thread. after calling start(), the newly created thread calls this function. - * returning from this method will end the execution of the thread. - * pure virtual method inherited by qthread. + * The starting point for the thread. After calling start(), the newly created thread calls this function. + * Returning from this method will end the execution of the thread. + * Pure virtual method inherited by QThread. */ - virtual void run(); - - - std::unique_ptr acqSystem; - std::unique_ptr guiWidget; - - // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - // int m_iNumberChannels; /**< The number of channels to be received.*/ - // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - // QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - // - QSharedPointer > m_pRTMSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; + virtual void run(); + + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the GUI (in Hertz).*/ + int m_iNumberChannels; /**< The number of channels to be received.*/ + int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + + QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + + QThread m_pProducerThread; /**< The thread used to host the producer.*/ + QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + + QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ +}; } // namespace FIELDLINEPLUGIN From 066df63a08f26682c91115bd31568e655556493b Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 14 Feb 2023 22:42:02 -0500 Subject: [PATCH 038/147] activate fieldline plugin --- src/applications/mne_scan/plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 00959801da3..428ec8d8392 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -# add_subdirectory(fieldline) +add_subdirectory(fieldline) # Algorithm Plugin add_subdirectory(rtcmne) From b960499ca4826e819686f64973a2659ad5ce19f9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 16 Feb 2023 13:20:58 -0500 Subject: [PATCH 039/147] fieldline plugin adapting --- .../mne_scan/mne_scan/mainwindow.cpp | 61 --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 4 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 408 +++++++++--------- .../mne_scan/plugins/fieldline/fieldline.h | 38 +- 4 files changed, 223 insertions(+), 288 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index e98c916e0fa..a00999f23f5 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -596,67 +596,6 @@ void MainWindow::createMenus() if(!m_pMenuFile) { m_pMenuFile = menuBar()->addMenu(tr("&File")); m_pMenuFile->addAction(m_pActionNewConfig); - m_pMenuFile->addAction(m_pActionOpenConfig); - m_pMenuFile->addAction(m_pActionSaveConfig); - m_pMenuFile->addSeparator(); - m_pMenuFile->addAction(m_pActionExit); - } - - // View menu - if(!m_pMenuView) { - m_pMenuView = menuBar()->addMenu(tr("&View")); - } - - m_pMenuView->clear(); - - if(m_pDockWidget_Log) { - m_pMenuView->addAction(m_pDockWidget_Log->toggleViewAction()); - } - m_pMenuLgLv = m_pMenuView->addMenu(tr("&Log Level")); - m_pMenuLgLv->addAction(m_pActionMinLgLv); - m_pMenuLgLv->addAction(m_pActionNormLgLv); - m_pMenuLgLv->addAction(m_pActionMaxLgLv); - m_pMenuView->addSeparator(); - - if(m_pPluginGuiDockWidget) { - m_pMenuView->addAction(m_pPluginGuiDockWidget->toggleViewAction()); - } - - for(int i = 0; i < m_qListDynamicDisplayMenuActions.size(); ++i) { - m_pMenuView->addAction(m_qListDynamicDisplayMenuActions.at(i)); - } - - menuBar()->addSeparator(); - - // Help Appearance - if(!m_pMenuAppearance) { - m_pMenuAppearance = menuBar()->addMenu(tr("&Appearance")); - m_pMenuAppearance->addMenu("Styles")->addActions(m_pActionStyleGroup->actions()); - m_pMenuAppearance->addMenu("Modes")->addActions(m_pActionModeGroup->actions()); - } - - // Help menu - if(!m_pMenuHelp) { - m_pMenuHelp = menuBar()->addMenu(tr("&Help")); - m_pMenuHelp->addAction(m_pActionHelpContents); - m_pMenuHelp->addSeparator(); - m_pMenuHelp->addAction(m_pActionAbout); - } -} - -//============================================================================================================= - -void MainWindow::createToolBars() -{ - // Control - if (!m_pToolBar) { - m_pToolBar = addToolBar(tr("Control")); - m_pToolBar->addAction(m_pActionRun); - m_pToolBar->addAction(m_pActionStop); - m_pActionStop->setEnabled(false); - - m_pToolBar->addSeparator(); - m_pLabelTime = new QLabel(this); m_pLabelTime->setStatusTip("Measurement time duration."); m_pLabelTime->setText(QTime(0, 0).toString()); diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index e1ca2afd007..f534ceed23f 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,15 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurren find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) set(SOURCES - # natus.cpp fieldline_global.cpp + fieldline.cpp # natusproducer.cpp # FormFiles/natussetup.cpp ) set(HEADERS - # natus.h fieldline_global.h + fieldline.h # natusproducer.h # FormFiles/natussetup.h ) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 98bb39a1e18..8694084190e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -10,27 +10,22 @@ * * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @@ -43,25 +38,17 @@ //============================================================================================================= #include "fieldline.h" - -#include // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" -#include +// #include +// #include //============================================================================================================= // QT INCLUDES //============================================================================================================= // #include -#include -#include -#include -#include -#include -#include -#include //============================================================================================================= // EIGEN INCLUDES @@ -71,104 +58,50 @@ // USED NAMESPACES //============================================================================================================= -namespace FIELDLINEPLUGIN { - -//============================================================================================================= - -// QSharedPointer createFiffInfo(int numChassis, -// int numChannels) { -// QSharedPointer pFiffInfo; -// pFiffInfo->sfreq = 1000.0f; -// pFiffInfo->nchan = numChassis * numChannels; -// pFiffInfo->chs.clear(); -// -// for (int chan_i = 0; chan_i < pFiffInfo->nchan; ++chan_i) { -// FIFFLIB::FiffChInfo channel; -// channel.ch_name = QString("%1:%2").arg(numChannels, 2).arg(chan_i, 2); -// channel.kind = FIFFV_MEG_CH; -// channel.unit = FIFF_UNIT_T; -// channel.unit_mul = FIFF_UNITM_NONE; -// channel.chpos.coil_type = FIFFV_COIL_NONE; -// pFiffInfo->chs.append(channel); -// pFiffInfo->ch_names.append(channel.ch_name); -// } -// } - -QSharedPointer -createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { - QSharedPointer pFiffInfo; - pFiffInfo->sfreq = sfreq; - pFiffInfo->chs.clear(); - - int total_channels = 0; - int chassis_num = 0; - for (auto &chassis : fl_chassis) { - for (auto &sensor : chassis) { - FIFFLIB::FiffChInfo channel; - channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); - channel.kind = FIFFV_MEG_CH; - channel.unit = FIFF_UNIT_T; - channel.unit_mul = FIFF_UNITM_NONE; - channel.chpos.coil_type = FIFFV_COIL_NONE; - pFiffInfo->chs.append(channel); - pFiffInfo->ch_names.append(channel.ch_name); - ++total_channels; - } - } - pFiffInfo->nchan = total_channels; - - return pFiffInfo; -} - -QSharedPointer -createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { - std::vector> fl; - for (int i = 0; i < numChassis; ++i) { - std::vector ch(numChannels); - std::iota(ch.begin(), ch.end(), 1); - fl.push_back(std::move(ch)); - } - return createFiffInfo(fl, sfreq); -} +using namespace FIELDLINEPLUGIN; +// using namespace SCSHAREDLIB; +// using namespace SCMEASLIB; +// using namespace FIFFLIB; +// using namespace Eigen; +// using namespace UTILSLIB; //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= Fieldline::Fieldline() +: m_iSamplingFreq(2048) +, m_iNumberChannels(46) +, m_iSamplesPerBlock(256) +, m_qStringResourcePath(qApp->applicationDirPath()+"/resources/mne_scan/plugins/fieldline/") +, m_pRMTSA_Fieldline(PluginOutputData::create(this, "Fieldline", "EEG output data")) +, m_pFiffInfo(QSharedPointer::create()) { + m_pRMTSA_Fieldline->measurementData()->setName(this->getName());//Provide name to auto store widget settings } //============================================================================================================= -Fieldline::~Fieldline() -{ - if(this->isRunning()) { - Fieldline::stop(); - } +Fieldline::~Fieldline() { + // If the program is closed while the sampling is in process + if(this->isRunning()) { + this->stop(); + } } //============================================================================================================= -QSharedPointer Fieldline::clone() const +QSharedPointer Fieldline::clone() const { - QSharedPointer pFieldlineClone(new Fieldline()); - return pFieldlineClone; + QSharedPointer pFieldline(new Fieldline()); + return pFieldlineClone; } //============================================================================================================= void Fieldline::init() { - // we instantiante - m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< - SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Out", - "FieldlinePlguin output"); - m_pRTMSA_Fieldline->measurementData()->setName(this->getName()); - m_outputConnectors.append(m_pRTMSA_Fieldline); - - qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; - acqSystem = std::make_unique(); + m_outputConnectors.append(m_pRMTSA_Natus); } //============================================================================================================= @@ -179,142 +112,207 @@ void Fieldline::unload() //============================================================================================================= -bool Fieldline::start() +void Fieldline::setUpFiffInfo() { - // Init circular buffer to transmit data from the producer to this thread - // if(!m_pCircularBuffer) { - // m_pCircularBuffer = QSharedPointer(new - // CircularBuffer_Matrix_double(10)); - // } - // - // //Setup fiff info before setting up the RMTSA because we need it to init - // the RTMSA setUpFiffInfo(); - // - // //Set the channel size of the RMTSA - this needs to be done here and NOT in - // the init() function because the user can change the number of channels - // during runtime - // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); - // - QThread::start(); - // - // // Start the producer - // m_pNatusProducer = - // QSharedPointer::create(m_iSamplesPerBlock, - // m_iNumberChannels); m_pNatusProducer->moveToThread(&m_pProducerThread); - // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - // m_pProducerThread.start(); - - return true; + //Clear old fiff info data + m_pFiffInfo->clear(); + + //Set number of channels, sampling frequency and high/-lowpass + m_pFiffInfo->nchan = m_iNumberChannels; + m_pFiffInfo->sfreq = m_iSamplingFreq; + m_pFiffInfo->highpass = 0.001f; + m_pFiffInfo->lowpass = m_iSamplingFreq/2; + + //Set up the channel info + QStringList QSLChNames; + m_pFiffInfo->chs.clear(); + + for(int i = 0; i < m_pFiffInfo->nchan; ++i) + { + //Create information for each channel + QString sChType; + FiffChInfo fChInfo; + +// //EEG Channels +// if(i <= m_pFiffInfo->nchan-2) +// { + //Set channel name + sChType = QString("EEG "); + if(i<10) { + sChType.append("00"); + } + + if(i>=10 && i<100) { + sChType.append("0"); + } + + fChInfo.ch_name = sChType.append(sChType.number(i)); + + //Set channel type + fChInfo.kind = FIFFV_EEG_CH; + + //Set logno + fChInfo.logNo = i; + + //Set coord frame + fChInfo.coord_frame = FIFFV_COORD_HEAD; + + //Set unit + fChInfo.unit = FIFF_UNIT_V; + + //Set EEG electrode location - Convert from mm to m + fChInfo.eeg_loc(0,0) = 0; + fChInfo.eeg_loc(1,0) = 0; + fChInfo.eeg_loc(2,0) = 0; + + //Set EEG electrode direction - Convert from mm to m + fChInfo.eeg_loc(0,1) = 0; + fChInfo.eeg_loc(1,1) = 0; + fChInfo.eeg_loc(2,1) = 0; + + //Also write the eeg electrode locations into the meg loc variable (mne_ex_read_raw() matlab function wants this) + fChInfo.chpos.r0(0) = 0; + fChInfo.chpos.r0(1) = 0; + fChInfo.chpos.r0(2) = 0; + + fChInfo.chpos.ex(0) = 1; + fChInfo.chpos.ex(1) = 0; + fChInfo.chpos.ex(2) = 0; + + fChInfo.chpos.ey(0) = 0; + fChInfo.chpos.ey(1) = 1; + fChInfo.chpos.ey(2) = 0; + + fChInfo.chpos.ez(0) = 0; + fChInfo.chpos.ez(1) = 0; + fChInfo.chpos.ez(2) = 1; +// } + +// //Digital input channel +// if(i == m_pFiffInfo->nchan-1) +// { +// //Set channel type +// fChInfo.kind = FIFFV_STIM_CH; + +// sChType = QString("STIM"); +// fChInfo.ch_name = sChType; +// } + + QSLChNames << sChType; + + m_pFiffInfo->chs.append(fChInfo); + } + + //Set channel names in fiff_info_base + m_pFiffInfo->ch_names = QSLChNames; + + //Set head projection + m_pFiffInfo->dev_head_t.from = FIFFV_COORD_DEVICE; + m_pFiffInfo->dev_head_t.to = FIFFV_COORD_HEAD; + m_pFiffInfo->ctf_head_t.from = FIFFV_COORD_DEVICE; + m_pFiffInfo->ctf_head_t.to = FIFFV_COORD_HEAD; } //============================================================================================================= -bool Fieldline::stop() +bool Fieldline::start() { - requestInterruption(); - wait(500); - m_pRTMSA_Fieldline->measurementData()->clear(); + // Init circular buffer to transmit data from the producer to this thread + if(!m_pCircularBuffer) { + m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); + } - return true; -} + //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA + setUpFiffInfo(); -//============================================================================================================= + //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime + m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); -SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const -{ - return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; -} + QThread::start(); -//============================================================================================================= + // Start the producer + m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); + m_pNatusProducer->moveToThread(&m_pProducerThread); + connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + m_pProducerThread.start(); -QString Fieldline::getName() const -{ - return "Fieldline OPM"; + return true; } //============================================================================================================= -QWidget *Fieldline::setupWidget() +bool Fieldline::stop() { + requestInterruption(); + wait(500); - guiWidget = std::make_unique(); - - // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by - // CentralWidget - so it has to be created everytime new - - // init properties dialog - // widget->initGui(); - - auto *frame = new QWidget(); - frame->setLayout(new QHBoxLayout()); + // Clear all data in the buffer connected to displays and other plugins + m_pRMTSA_Natus->measurementData()->clear(); + m_pCircularBuffer->clear(); - auto *flWidget = new DISPLIB::FieldlineView(2, 16); + m_pProducerThread.quit(); + m_pProducerThread.wait(); - frame->layout()->addWidget(flWidget); - flWidget->setBlinkState(0, 2, true); - flWidget->setBlinkState(1, 5, true); - - return frame; + return true; } //============================================================================================================= -// void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { -// -// while(!m_pCircularBuffer->push(matData)) { -// //Do nothing until the circular buffer is ready to accept new data -// again -// } -// } +AbstractPlugin::PluginType Fieldline::getType() const +{ + return _ISensor; +} //============================================================================================================= -void Fieldline::run() { - m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); +QString Fieldline::getName() const +{ + return "Natus EEG"; +} - m_pFiffInfo->sfreq = 1000.0f; - m_pFiffInfo->nchan = 32; - m_pFiffInfo->chs.clear(); +//============================================================================================================= - for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { - FIFFLIB::FiffChInfo channel; - channel.ch_name = "Ch. " + QString::number(chan_i); - channel.kind = FIFFV_MEG_CH; - channel.unit = FIFF_UNIT_T; - channel.unit_mul = FIFF_UNITM_NONE; - channel.chpos.coil_type = FIFFV_COIL_NONE; - m_pFiffInfo->chs.append(channel); - m_pFiffInfo->ch_names.append(channel.ch_name); - } +QWidget* Fieldline::setupWidget() +{ + NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new - m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( - m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { - m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); - m_pRTMSA_Fieldline->measurementData()->setVisibility(true); + //init properties dialog + widget->initGui(); - Eigen::MatrixXd matData; - matData.resize(m_pFiffInfo->nchan, 200); + return widget; +} - for (;;) { - // gather the data +//============================================================================================================= - matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); - matData *= 4e-12; +void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) +{ + while(!m_pCircularBuffer->push(matData)) { + //Do nothing until the circular buffer is ready to accept new data again + } +} - msleep(2000); +//============================================================================================================= - if (isInterruptionRequested()) - break; - m_pRTMSA_Fieldline->measurementData()->setValue(matData); - } +void Fieldline::run() +{ + MatrixXd matData; + + while(!isInterruptionRequested()) { + if(m_pCircularBuffer->pop(matData)) { + //emit values + if(!isInterruptionRequested()) { + m_pRMTSA_Natus->measurementData()->setValue(matData); + } + } + } } //============================================================================================================= -QString Fieldline::getBuildInfo() { - return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); +QString Fieldline::getBuildInfo() +{ + return QString(NATUSPLUGIN::buildDateTime()) + QString(" - ") + QString(NATUSPLUGIN::buildHash()); } -} // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 93b9fb66232..cdba732a587 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -38,8 +38,8 @@ #include "fieldline_global.h" -// #include -// #include +#include +#include //============================================================================================================= // QT INCLUDES @@ -52,26 +52,24 @@ // EIGEN INCLUDES //============================================================================================================= -// #include +#include //============================================================================================================= // FORWARD DECLARATIONS //============================================================================================================= namespace SCMEASLIB { - class RealTimeMultiSampleArray; +class RealTimeMultiSampleArray; } - namespace FIFFLIB { - class FiffInfo; +class FiffInfo; } //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN //============================================================================================================= -namespace FIELDLINEPLUGIN -{ +namespace FIELDLINEPLUGIN { //============================================================================================================= // FIELDLINEPLUGIN FORWARD DECLARATIONS @@ -89,9 +87,9 @@ namespace FIELDLINEPLUGIN class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { Q_OBJECT - Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + // Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces - Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + // Q_INTERFACES(SCSHAREDLIB::AbstractSensor) // friend class FieldlineSetup; @@ -160,24 +158,24 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor //========================================================================================================= /** - * The starting point for the thread. After calling start(), the newly created thread calls this function. - * Returning from this method will end the execution of the thread. - * Pure virtual method inherited by QThread. + * the starting point for the thread. after calling start(), the newly created thread calls this function. + * returning from this method will end the execution of the thread. + * pure virtual method inherited by qthread. */ virtual void run(); - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the GUI (in Hertz).*/ - int m_iNumberChannels; /**< The number of channels to be received.*/ - int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + int m_iNumberChannels; /**< The number of channels to be received.*/ + int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - QThread m_pProducerThread; /**< The thread used to host the producer.*/ - QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From a3cdef4e5973a30e988fbcd7d801cf4ccb8428c5 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 16:48:57 -0500 Subject: [PATCH 040/147] add .sessions to gitignore --- .../mne_scan/mne_scan/mainwindow.cpp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index a00999f23f5..3fe04af1761 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -596,6 +596,67 @@ void MainWindow::createMenus() if(!m_pMenuFile) { m_pMenuFile = menuBar()->addMenu(tr("&File")); m_pMenuFile->addAction(m_pActionNewConfig); + m_pMenuFile->addAction(m_pActionOpenConfig); + m_pMenuFile->addAction(m_pActionSaveConfig); + m_pMenuFile->addSeparator(); + m_pMenuFile->addAction(m_pActionExit); + } + + // View menu + if(!m_pMenuView) { + m_pMenuView = menuBar()->addMenu(tr("&View")); + } + + m_pMenuView->clear(); + + if(m_pDockWidget_Log) { + m_pMenuView->addAction(m_pDockWidget_Log->toggleViewAction()); + } + m_pMenuLgLv = m_pMenuView->addMenu(tr("&Log Level")); + m_pMenuLgLv->addAction(m_pActionMinLgLv); + m_pMenuLgLv->addAction(m_pActionNormLgLv); + m_pMenuLgLv->addAction(m_pActionMaxLgLv); + m_pMenuView->addSeparator(); + + if(m_pPluginGuiDockWidget) { + m_pMenuView->addAction(m_pPluginGuiDockWidget->toggleViewAction()); + } + + for(int i = 0; i < m_qListDynamicDisplayMenuActions.size(); ++i) { + m_pMenuView->addAction(m_qListDynamicDisplayMenuActions.at(i)); + } + + menuBar()->addSeparator(); + + // Help Appearance + if(!m_pMenuAppearance) { + m_pMenuAppearance = menuBar()->addMenu(tr("&Appearance")); + m_pMenuAppearance->addMenu("Styles")->addActions(m_pActionStyleGroup->actions()); + m_pMenuAppearance->addMenu("Modes")->addActions(m_pActionModeGroup->actions()); + } + + // Help menu + if(!m_pMenuHelp) { + m_pMenuHelp = menuBar()->addMenu(tr("&Help")); + m_pMenuHelp->addAction(m_pActionHelpContents); + m_pMenuHelp->addSeparator(); + m_pMenuHelp->addAction(m_pActionAbout); + } +} + +//============================================================================================================= + +void MainWindow::createToolBars() +{ + //Control + if(!m_pToolBar) { + m_pToolBar = addToolBar(tr("Control")); + m_pToolBar->addAction(m_pActionRun); + m_pToolBar->addAction(m_pActionStop); + m_pActionStop->setEnabled(false); + + m_pToolBar->addSeparator(); + m_pLabelTime = new QLabel(this); m_pLabelTime->setStatusTip("Measurement time duration."); m_pLabelTime->setText(QTime(0, 0).toString()); From 6797439599f098b65cee370050dad1962d176a22 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 17 Feb 2023 20:50:20 -0500 Subject: [PATCH 041/147] create fieldline plugin --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 46 +-- .../mne_scan/plugins/fieldline/fieldline.cpp | 269 +++++------------- .../mne_scan/plugins/fieldline/fieldline.h | 62 ++-- .../mne_scan/plugins/fieldline/fieldline.json | 1 + 4 files changed, 140 insertions(+), 238 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f534ceed23f..f7c6772cbda 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -6,28 +6,35 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(QT NAMES Qt6 Qt5 REQUIRED + COMPONENTS Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED + COMPONENTS Core Widgets Network Concurrent) set(SOURCES fieldline_global.cpp fieldline.cpp - # natusproducer.cpp - # FormFiles/natussetup.cpp ) set(HEADERS fieldline_global.h fieldline.h - # natusproducer.h - # FormFiles/natussetup.h ) set(FILE_TO_UPDATE fieldline_global.cpp) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) + message("File fieldline.json exists.") +else() + message("File fieldline.json does not exist.") + message("Creating a new fieldline.json file.") + execute_process(COMMAND "echo ") +endif() + set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") -set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES + OBJECT_DEPENDS "${SOURCE_PATHS}") add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) @@ -57,21 +64,26 @@ target_link_libraries(${PROJECT_NAME} PRIVATE eigen mne_disp mne_utils - mne_fiff - mne_fs - mne_mne - mne_fwd - mne_inverse - mne_rtprocessing - mne_connectivity - mne_events + # mne_fiff + # mne_fs + # mne_mne + # mne_fwd + # mne_inverse + # mne_rtprocessing + # mne_connectivity + # mne_events scDisp scShared scMeas ${FFTW_LIBS}) -target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}") +target_compile_definitions(${PROJECT_NAME} PRIVATE + SCAN_FIELDLINE_PLUGIN + MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" +) if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) + target_compile_definitions(${PROJECT_NAME} PRIVATE + STATICBUILD QT_STATICPLUGIN) endif() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 8694084190e..36b6f2e1e79 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -38,6 +38,7 @@ //============================================================================================================= #include "fieldline.h" + // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -49,6 +50,7 @@ //============================================================================================================= // #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -58,261 +60,146 @@ // USED NAMESPACES //============================================================================================================= -using namespace FIELDLINEPLUGIN; -// using namespace SCSHAREDLIB; -// using namespace SCMEASLIB; -// using namespace FIFFLIB; -// using namespace Eigen; -// using namespace UTILSLIB; +namespace FIELDLINEPLUGIN { //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() -: m_iSamplingFreq(2048) -, m_iNumberChannels(46) -, m_iSamplesPerBlock(256) -, m_qStringResourcePath(qApp->applicationDirPath()+"/resources/mne_scan/plugins/fieldline/") -, m_pRMTSA_Fieldline(PluginOutputData::create(this, "Fieldline", "EEG output data")) -, m_pFiffInfo(QSharedPointer::create()) -{ - m_pRMTSA_Fieldline->measurementData()->setName(this->getName());//Provide name to auto store widget settings +Fieldline::Fieldline() { + } //============================================================================================================= Fieldline::~Fieldline() { // If the program is closed while the sampling is in process - if(this->isRunning()) { - this->stop(); - } + // if(this->isRunning()) { + // this->stop(); + // } } //============================================================================================================= -QSharedPointer Fieldline::clone() const -{ - QSharedPointer pFieldline(new Fieldline()); +QSharedPointer Fieldline::clone() const { + QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } //============================================================================================================= -void Fieldline::init() -{ - m_outputConnectors.append(m_pRMTSA_Natus); -} - -//============================================================================================================= +void Fieldline::init() { -void Fieldline::unload() -{ + // m_outputConnectors.append(m_pRMTSA_Natus); } //============================================================================================================= -void Fieldline::setUpFiffInfo() -{ - //Clear old fiff info data - m_pFiffInfo->clear(); - - //Set number of channels, sampling frequency and high/-lowpass - m_pFiffInfo->nchan = m_iNumberChannels; - m_pFiffInfo->sfreq = m_iSamplingFreq; - m_pFiffInfo->highpass = 0.001f; - m_pFiffInfo->lowpass = m_iSamplingFreq/2; - - //Set up the channel info - QStringList QSLChNames; - m_pFiffInfo->chs.clear(); - - for(int i = 0; i < m_pFiffInfo->nchan; ++i) - { - //Create information for each channel - QString sChType; - FiffChInfo fChInfo; - -// //EEG Channels -// if(i <= m_pFiffInfo->nchan-2) -// { - //Set channel name - sChType = QString("EEG "); - if(i<10) { - sChType.append("00"); - } - - if(i>=10 && i<100) { - sChType.append("0"); - } - - fChInfo.ch_name = sChType.append(sChType.number(i)); - - //Set channel type - fChInfo.kind = FIFFV_EEG_CH; - - //Set logno - fChInfo.logNo = i; - - //Set coord frame - fChInfo.coord_frame = FIFFV_COORD_HEAD; - - //Set unit - fChInfo.unit = FIFF_UNIT_V; - - //Set EEG electrode location - Convert from mm to m - fChInfo.eeg_loc(0,0) = 0; - fChInfo.eeg_loc(1,0) = 0; - fChInfo.eeg_loc(2,0) = 0; - - //Set EEG electrode direction - Convert from mm to m - fChInfo.eeg_loc(0,1) = 0; - fChInfo.eeg_loc(1,1) = 0; - fChInfo.eeg_loc(2,1) = 0; - - //Also write the eeg electrode locations into the meg loc variable (mne_ex_read_raw() matlab function wants this) - fChInfo.chpos.r0(0) = 0; - fChInfo.chpos.r0(1) = 0; - fChInfo.chpos.r0(2) = 0; - - fChInfo.chpos.ex(0) = 1; - fChInfo.chpos.ex(1) = 0; - fChInfo.chpos.ex(2) = 0; - - fChInfo.chpos.ey(0) = 0; - fChInfo.chpos.ey(1) = 1; - fChInfo.chpos.ey(2) = 0; - - fChInfo.chpos.ez(0) = 0; - fChInfo.chpos.ez(1) = 0; - fChInfo.chpos.ez(2) = 1; -// } - -// //Digital input channel -// if(i == m_pFiffInfo->nchan-1) -// { -// //Set channel type -// fChInfo.kind = FIFFV_STIM_CH; - -// sChType = QString("STIM"); -// fChInfo.ch_name = sChType; -// } - - QSLChNames << sChType; - - m_pFiffInfo->chs.append(fChInfo); - } - - //Set channel names in fiff_info_base - m_pFiffInfo->ch_names = QSLChNames; - - //Set head projection - m_pFiffInfo->dev_head_t.from = FIFFV_COORD_DEVICE; - m_pFiffInfo->dev_head_t.to = FIFFV_COORD_HEAD; - m_pFiffInfo->ctf_head_t.from = FIFFV_COORD_DEVICE; - m_pFiffInfo->ctf_head_t.to = FIFFV_COORD_HEAD; +void Fieldline::unload() { + } //============================================================================================================= -bool Fieldline::start() -{ - // Init circular buffer to transmit data from the producer to this thread - if(!m_pCircularBuffer) { - m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); - } - - //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA - setUpFiffInfo(); - - //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime - m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); +bool Fieldline::start() { - QThread::start(); - - // Start the producer - m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); - m_pNatusProducer->moveToThread(&m_pProducerThread); - connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - m_pProducerThread.start(); + // Init circular buffer to transmit data from the producer to this thread + // if(!m_pCircularBuffer) { + // m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); + // } + // + // //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA + // setUpFiffInfo(); + // + // //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime + // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + // + // QThread::start(); + // + // // Start the producer + // m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); + // m_pNatusProducer->moveToThread(&m_pProducerThread); + // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + // m_pProducerThread.start(); return true; } //============================================================================================================= -bool Fieldline::stop() -{ - requestInterruption(); - wait(500); - - // Clear all data in the buffer connected to displays and other plugins - m_pRMTSA_Natus->measurementData()->clear(); - m_pCircularBuffer->clear(); +bool Fieldline::stop() { - m_pProducerThread.quit(); - m_pProducerThread.wait(); + // requestInterruption(); + // wait(500); + // + // // Clear all data in the buffer connected to displays and other plugins + // m_pRMTSA_Natus->measurementData()->clear(); + // m_pCircularBuffer->clear(); + // + // m_pProducerThread.quit(); + // m_pProducerThread.wait(); return true; } //============================================================================================================= -AbstractPlugin::PluginType Fieldline::getType() const -{ - return _ISensor; +SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { + return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } //============================================================================================================= -QString Fieldline::getName() const -{ - return "Natus EEG"; +QString Fieldline::getName() const { + return QString("Fieldline OPM"); } //============================================================================================================= -QWidget* Fieldline::setupWidget() -{ - NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new +QWidget* Fieldline::setupWidget() { + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new //init properties dialog - widget->initGui(); + // widget->initGui(); - return widget; + return new QLabel("Fieldline"); } //============================================================================================================= -void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) -{ - while(!m_pCircularBuffer->push(matData)) { - //Do nothing until the circular buffer is ready to accept new data again - } -} +// void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { +// +// while(!m_pCircularBuffer->push(matData)) { +// //Do nothing until the circular buffer is ready to accept new data again +// } +// } //============================================================================================================= -void Fieldline::run() -{ - MatrixXd matData; - - while(!isInterruptionRequested()) { - if(m_pCircularBuffer->pop(matData)) { - //emit values - if(!isInterruptionRequested()) { - m_pRMTSA_Natus->measurementData()->setValue(matData); - } - } - } +void Fieldline::run() { + // MatrixXd matData; + // + // while(!isInterruptionRequested()) { + // if(m_pCircularBuffer->pop(matData)) { + // //emit values + // if(!isInterruptionRequested()) { + // m_pRMTSA_Natus->measurementData()->setValue(matData); + // } + // } + // } } //============================================================================================================= -QString Fieldline::getBuildInfo() -{ - return QString(NATUSPLUGIN::buildDateTime()) + QString(" - ") + QString(NATUSPLUGIN::buildHash()); +QString Fieldline::getBuildInfo() { + + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } + +} // namespace FIELDLINEPLUGIN + + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index cdba732a587..f7e1f6923e4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -35,35 +35,34 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= - #include "fieldline_global.h" #include -#include +// #include //============================================================================================================= // QT INCLUDES //============================================================================================================= -// #include +#include // #include //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= -#include +// #include //============================================================================================================= // FORWARD DECLARATIONS //============================================================================================================= -namespace SCMEASLIB { -class RealTimeMultiSampleArray; -} -namespace FIFFLIB { -class FiffInfo; -} +// namespace SCMEASLIB { +// class RealTimeMultiSampleArray; +// } +// namespace FIFFLIB { +// class FiffInfo; +// } //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN @@ -84,16 +83,16 @@ namespace FIELDLINEPLUGIN { * * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. */ -class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor -{ +class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { + Q_OBJECT - // Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces - // Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + Q_INTERFACES(SCSHAREDLIB::AbstractSensor) // friend class FieldlineSetup; -public: + public: //========================================================================================================= /** * Constructs a Fieldline. @@ -128,7 +127,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor /** * Sets up the fiff info with the current data chosen by the user. */ - void setUpFiffInfo(); + // void setUpFiffInfo(); //========================================================================================================= /** @@ -143,18 +142,21 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor virtual bool stop(); virtual AbstractPlugin::PluginType getType() const; + virtual QString getName() const; + virtual QWidget* setupWidget(); + virtual QString getBuildInfo(); -protected: + protected: //========================================================================================================= /** * Call this function whenenver you received new data. * * @param[in] matData The new data. */ - void onNewDataAvailable(const Eigen::MatrixXd &matData); + // void onNewDataAvailable(const Eigen::MatrixXd &matData); //========================================================================================================= /** @@ -164,18 +166,18 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor */ virtual void run(); - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - int m_iNumberChannels; /**< The number of channels to be received.*/ - int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - - QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - - QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - - QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + // int m_iNumberChannels; /**< The number of channels to be received.*/ + // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + // + // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + // + // QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + // + // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.json b/src/applications/mne_scan/plugins/fieldline/fieldline.json index e69de29bb2d..8b137891791 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.json +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.json @@ -0,0 +1 @@ + From a66fb6802c69a60427c2159878e6c7b08d37229e Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 21 Feb 2023 14:54:23 -0500 Subject: [PATCH 042/147] fieldline barebones plugin working --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 13 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 186 ++++++++++-------- .../mne_scan/plugins/fieldline/fieldline.h | 10 +- .../mne_scan/plugins/fieldline/fieldline.json | 1 - .../plugins/fieldline/fieldline_global.cpp | 6 +- 5 files changed, 115 insertions(+), 101 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f7c6772cbda..bd980a8b645 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -24,11 +24,13 @@ set(HEADERS set(FILE_TO_UPDATE fieldline_global.cpp) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) - message("File fieldline.json exists.") + # message("File fieldline.json exists.") else() - message("File fieldline.json does not exist.") - message("Creating a new fieldline.json file.") - execute_process(COMMAND "echo ") + # message("File fieldline.json does not exist.") + # message("Creating a new fieldline.json file.") + execute_process(COMMAND "echo \"\"" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_FILE fieldline.json) endif() set(SOURCE_PATHS ${SOURCES}) @@ -78,8 +80,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${FFTW_LIBS}) target_compile_definitions(${PROJECT_NAME} PRIVATE - SCAN_FIELDLINE_PLUGIN - MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" ) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 36b6f2e1e79..2c77a024160 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -10,22 +10,27 @@ * * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @@ -50,6 +55,7 @@ //============================================================================================================= // #include +#include #include //============================================================================================================= @@ -66,105 +72,115 @@ namespace FIELDLINEPLUGIN { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { - +Fieldline::Fieldline() : m_iSamplingFreq(1000) { + qDebug() << "Creating Fieldline object"; } //============================================================================================================= Fieldline::~Fieldline() { - // If the program is closed while the sampling is in process - // if(this->isRunning()) { - // this->stop(); - // } + // If the program is closed while the sampling is in process + // if(this->isRunning()) { + // this->stop(); + // } + qDebug() << "Destroying Fieldline object"; } //============================================================================================================= QSharedPointer Fieldline::clone() const { - QSharedPointer pFieldlineClone(new Fieldline()); - return pFieldlineClone; + QSharedPointer pFieldlineClone(new Fieldline()); + return pFieldlineClone; } //============================================================================================================= void Fieldline::init() { - // m_outputConnectors.append(m_pRMTSA_Natus); + // m_outputConnectors.append(m_pRMTSA_Natus); + qDebug() << "Init Fieldline"; } //============================================================================================================= -void Fieldline::unload() { - -} +void Fieldline::unload() { qDebug() << "unload Fieldline"; } //============================================================================================================= bool Fieldline::start() { - - // Init circular buffer to transmit data from the producer to this thread - // if(!m_pCircularBuffer) { - // m_pCircularBuffer = QSharedPointer(new CircularBuffer_Matrix_double(10)); - // } - // - // //Setup fiff info before setting up the RMTSA because we need it to init the RTMSA - // setUpFiffInfo(); - // - // //Set the channel size of the RMTSA - this needs to be done here and NOT in the init() function because the user can change the number of channels during runtime - // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); - // - // QThread::start(); - // - // // Start the producer - // m_pNatusProducer = QSharedPointer::create(m_iSamplesPerBlock, m_iNumberChannels); - // m_pNatusProducer->moveToThread(&m_pProducerThread); - // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - // m_pProducerThread.start(); - - return true; + qDebug() << "start Fieldline"; + + // Init circular buffer to transmit data from the producer to this thread + // if(!m_pCircularBuffer) { + // m_pCircularBuffer = QSharedPointer(new + // CircularBuffer_Matrix_double(10)); + // } + // + // //Setup fiff info before setting up the RMTSA because we need it to init + // the RTMSA setUpFiffInfo(); + // + // //Set the channel size of the RMTSA - this needs to be done here and NOT in + // the init() function because the user can change the number of channels + // during runtime + // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + // + // QThread::start(); + // + // // Start the producer + // m_pNatusProducer = + // QSharedPointer::create(m_iSamplesPerBlock, + // m_iNumberChannels); m_pNatusProducer->moveToThread(&m_pProducerThread); + // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); + // m_pProducerThread.start(); + + return true; } //============================================================================================================= bool Fieldline::stop() { - // requestInterruption(); - // wait(500); - // - // // Clear all data in the buffer connected to displays and other plugins - // m_pRMTSA_Natus->measurementData()->clear(); - // m_pCircularBuffer->clear(); - // - // m_pProducerThread.quit(); - // m_pProducerThread.wait(); - - return true; + // requestInterruption(); + // wait(500); + // + // // Clear all data in the buffer connected to displays and other plugins + // m_pRMTSA_Natus->measurementData()->clear(); + // m_pCircularBuffer->clear(); + // + // m_pProducerThread.quit(); + // m_pProducerThread.wait(); + qDebug() << "Stop Fieldline"; + + return true; } //============================================================================================================= SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { - return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; + qDebug() << "getType Fieldline"; + return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } //============================================================================================================= QString Fieldline::getName() const { - return QString("Fieldline OPM"); + qDebug() << "getName Fieldline"; + return QString("Fieldline OPM"); } //============================================================================================================= -QWidget* Fieldline::setupWidget() { - // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by CentralWidget - so it has to be created everytime new +QWidget *Fieldline::setupWidget() { + qDebug() << "setupWidget Fieldline"; + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by + // CentralWidget - so it has to be created everytime new - //init properties dialog - // widget->initGui(); + // init properties dialog + // widget->initGui(); - return new QLabel("Fieldline"); + return new QLabel("Fieldline \n OPM"); } //============================================================================================================= @@ -172,34 +188,32 @@ QWidget* Fieldline::setupWidget() { // void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { // // while(!m_pCircularBuffer->push(matData)) { -// //Do nothing until the circular buffer is ready to accept new data again +// //Do nothing until the circular buffer is ready to accept new data +// again // } // } //============================================================================================================= void Fieldline::run() { - // MatrixXd matData; - // - // while(!isInterruptionRequested()) { - // if(m_pCircularBuffer->pop(matData)) { - // //emit values - // if(!isInterruptionRequested()) { - // m_pRMTSA_Natus->measurementData()->setValue(matData); - // } - // } - // } + qDebug() << "run Fieldline"; + // MatrixXd matData; + // + // while(!isInterruptionRequested()) { + // if(m_pCircularBuffer->pop(matData)) { + // //emit values + // if(!isInterruptionRequested()) { + // m_pRMTSA_Natus->measurementData()->setValue(matData); + // } + // } + // } } //============================================================================================================= QString Fieldline::getBuildInfo() { - - return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); + qDebug() << "getBuildInfo Fieldline"; + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } - -} // namespace FIELDLINEPLUGIN - - - +} // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index f7e1f6923e4..06c9d7d1bd3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -35,6 +35,7 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= + #include "fieldline_global.h" #include @@ -45,7 +46,6 @@ //============================================================================================================= #include -// #include //============================================================================================================= // EIGEN INCLUDES @@ -54,12 +54,13 @@ // #include //============================================================================================================= -// FORWARD DECLARATIONS +// FORWARD DECLARATION //============================================================================================================= // namespace SCMEASLIB { // class RealTimeMultiSampleArray; // } +// u // namespace FIFFLIB { // class FiffInfo; // } @@ -84,7 +85,6 @@ namespace FIELDLINEPLUGIN { * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. */ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { - Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces @@ -166,7 +166,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { */ virtual void run(); - // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ // int m_iNumberChannels; /**< The number of channels to be received.*/ // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ // @@ -177,7 +177,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ // // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.json b/src/applications/mne_scan/plugins/fieldline/fieldline.json index 8b137891791..e69de29bb2d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.json +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.json @@ -1 +0,0 @@ - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp index 2e691274c01..13809aec2de 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp @@ -43,12 +43,12 @@ // DEFINE METHODS //============================================================================================================= -const char* FIELDLINEPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} +const char* FIELDLINEPLUGIN::buildDateTime() { return UTILSLIB::dateTimeNow();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHash(){ return UTILSLIB::gitHash();} +const char* FIELDLINEPLUGIN::buildHash() { return UTILSLIB::gitHash();} //============================================================================================================= -const char* FIELDLINEPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} +const char* FIELDLINEPLUGIN::buildHashLong() { return UTILSLIB::gitHashLong();} From c34ee99560b9756c3ec1fbb729ee182a946316c9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:42:09 -0500 Subject: [PATCH 043/147] add python bindings to fieldline plugin --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 24 +++++++-- .../fieldline/fieldline_system_controller.cpp | 53 +++++++++++++++++++ .../fieldline/fieldline_system_controller.h | 51 ++++++++++++++++++ 3 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index bd980a8b645..d237475fe7b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,29 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(Python COMPONENTS Interpreter Development) +cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) + +set(PYTHON_COMPILE_FLAGS "--cflags") +execute_process(COMMAND + ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} + OUTPUT_VARIABLE Python_FLAGS +) + + set(SOURCES fieldline_global.cpp fieldline.cpp + fieldline_acq_system_controller.cpp + fieldline_plugin_gui.cpp ) set(HEADERS fieldline_global.h fieldline.h + fieldline_acq_system_controller.h + fieldline_plugin_gui.h ) set(FILE_TO_UPDATE fieldline_global.cpp) @@ -58,8 +72,7 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC ../) -target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent @@ -77,8 +90,13 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scDisp scShared scMeas - ${FFTW_LIBS}) + ${FFTW_LIBS} + PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) +target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) +separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") +target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) + target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp new file mode 100644 index 00000000000..1a37ab804ff --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp @@ -0,0 +1,53 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline class. + * + */ + + + +#include "fieldline_system_controller.h" + + +namespace FIELDLINEPLUGIN { + +FieldlineSystemController::FieldlineSystemController() noexcept { + +} + + +} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h new file mode 100644 index 00000000000..1cfe93570df --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h @@ -0,0 +1,51 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline Acquisition System Controller class. + * + */ + + +namespace FIELDLINEPLUGIN { + + +class FieldlineSystemController { + public: + FieldlineSystemController() noexcept; + + + private: + +}; + + +} // namespace FIELDLINEPLUGIN + From 09dbd13ab9d994d27fee0bfb2b13c8db0d188709 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:45:50 -0500 Subject: [PATCH 044/147] add python to fieldline plugin --- .../mne_scan/plugins/fieldline/fieldline.cpp | 10 ++++-- .../mne_scan/plugins/fieldline/fieldline.h | 33 +++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 2c77a024160..10538a7139a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -72,7 +72,7 @@ namespace FIELDLINEPLUGIN { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() : m_iSamplingFreq(1000) { +Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } @@ -89,6 +89,7 @@ Fieldline::~Fieldline() { //============================================================================================================= QSharedPointer Fieldline::clone() const { + qDebug() << "Cloning Fieldline."; QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } @@ -99,11 +100,14 @@ void Fieldline::init() { // m_outputConnectors.append(m_pRMTSA_Natus); qDebug() << "Init Fieldline"; + acqSystem = std::make_unique(); } //============================================================================================================= -void Fieldline::unload() { qDebug() << "unload Fieldline"; } +void Fieldline::unload() { + qDebug() << "unload Fieldline"; +} //============================================================================================================= @@ -174,6 +178,8 @@ QString Fieldline::getName() const { QWidget *Fieldline::setupWidget() { qDebug() << "setupWidget Fieldline"; + guiWidget = std::make_unique(); + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by // CentralWidget - so it has to be created everytime new diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 06c9d7d1bd3..eb77827d089 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -37,9 +37,12 @@ #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= #include "fieldline_global.h" +#include "fieldline_acq_system_controller.h" +#include "fieldline_plugin_gui.h" #include // #include +#include //============================================================================================================= // QT INCLUDES @@ -164,20 +167,22 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { * returning from this method will end the execution of the thread. * pure virtual method inherited by qthread. */ - virtual void run(); - - int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - // int m_iNumberChannels; /**< The number of channels to be received.*/ - // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - // - // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ - // - // QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - // - // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + virtual void run(); + + + std::unique_ptr acqSystem; + std::unique_ptr guiWidget; + + // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ + // int m_iNumberChannels; /**< The number of channels to be received.*/ + // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ + // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + // QThread m_pProducerThread; /**< The thread used to host the producer.*/ + // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ + // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + // + // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From d566076d936d4f91d2c4f567076e65f970e85966 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 22 Feb 2023 09:48:23 -0500 Subject: [PATCH 045/147] add fieldline acq system class --- .../fieldline_acq_system_controller.cpp | 64 +------------------ .../fieldline/fieldline_system_controller.cpp | 53 --------------- .../fieldline/fieldline_system_controller.h | 51 --------------- 3 files changed, 2 insertions(+), 166 deletions(-) delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index a515a0591fb..62a700a18b6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -45,68 +45,8 @@ #include "fieldline_acq_system_controller.h" -#include -#include - -extern "C" { - -PyObject *restartFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - restart finished;\n"; - } else { - std::cout << "A sensor has finished restarting!\n"; - } - - return NULL; -} -PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - coarse zero finished;\n"; - } else { - std::cout << "A sensor has finished coarse zeroing!\n"; - } - - return NULL; -} -PyObject *fineZeroFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - fine zero finished;\n"; - } else { - std::cout << "A sensor has finished fine zeroing!\n"; - } - - return NULL; -} -} - -static PyMethodDef my_module_methods[] = { - {"restartFinished", restartFinished, METH_VARARGS, " "}, - {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, - {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, - {NULL, NULL, 0, NULL}}; - -static PyModuleDef my_module_def = { - PyModuleDef_HEAD_INIT, - "mne_cpp_callbacks", - "A module of callback functions for mne-cpp.", - -1, - my_module_methods, - NULL, - NULL, - NULL, - NULL}; - -PyMODINIT_FUNC PyInit_my_module(void) { - return PyModule_Create(&my_module_def); -} - namespace FIELDLINEPLUGIN { + FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // pythonInterpreter initiate @@ -143,7 +83,7 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { -// Py_Finalize(); + Py_Finalize(); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp deleted file mode 100644 index 1a37ab804ff..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.cpp +++ /dev/null @@ -1,53 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_system_controller.cpp - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the definition of the Fieldline class. - * - */ - - - -#include "fieldline_system_controller.h" - - -namespace FIELDLINEPLUGIN { - -FieldlineSystemController::FieldlineSystemController() noexcept { - -} - - -} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h b/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h deleted file mode 100644 index 1cfe93570df..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_system_controller.h +++ /dev/null @@ -1,51 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_system_controller.h - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the declaration of the Fieldline Acquisition System Controller class. - * - */ - - -namespace FIELDLINEPLUGIN { - - -class FieldlineSystemController { - public: - FieldlineSystemController() noexcept; - - - private: - -}; - - -} // namespace FIELDLINEPLUGIN - From 6ada8b156ddddd353485c1e5d9a4916cc8e59250 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Wed, 22 Feb 2023 15:25:58 -0500 Subject: [PATCH 046/147] Add sensor, chassis, and rack ui elements. Sensors can blink --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 5 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 16 +++- .../fieldline_acq_system_controller.cpp | 40 +++++----- src/libraries/disp/CMakeLists.txt | 10 ++- src/libraries/disp/viewers/fl_chassis.cpp | 22 ++++++ src/libraries/disp/viewers/fl_chassis.h | 26 +++++++ src/libraries/disp/viewers/fl_rack.cpp | 18 +++++ src/libraries/disp/viewers/fl_rack.h | 22 ++++++ src/libraries/disp/viewers/fl_sensor.cpp | 78 +++++++++++++++++++ src/libraries/disp/viewers/fl_sensor.h | 45 +++++++++++ .../disp/viewers/formfiles/fl_sensor.ui | 59 ++++++++++++++ 11 files changed, 314 insertions(+), 27 deletions(-) create mode 100644 src/libraries/disp/viewers/fl_chassis.cpp create mode 100644 src/libraries/disp/viewers/fl_chassis.h create mode 100644 src/libraries/disp/viewers/fl_rack.cpp create mode 100644 src/libraries/disp/viewers/fl_rack.h create mode 100644 src/libraries/disp/viewers/fl_sensor.cpp create mode 100644 src/libraries/disp/viewers/fl_sensor.h create mode 100644 src/libraries/disp/viewers/formfiles/fl_sensor.ui diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index d237475fe7b..5e758c7c5da 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,7 +10,7 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Python COMPONENTS Interpreter Development) +find_package(Python REQUIRED COMPONENTS Interpreter Development) cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) set(PYTHON_COMPILE_FLAGS "--cflags") @@ -91,7 +91,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core scShared scMeas ${FFTW_LIBS} - PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) +# PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + ) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 10538a7139a..37e780bbeee 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,6 +44,7 @@ #include "fieldline.h" +#include // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -57,6 +58,9 @@ // #include #include #include +#include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -186,7 +190,17 @@ QWidget *Fieldline::setupWidget() { // init properties dialog // widget->initGui(); - return new QLabel("Fieldline \n OPM"); + + + + auto* frame = new QWidget(); + frame->setLayout(new QHBoxLayout()); + + frame->layout()->addWidget(new fl_rack()); + + return frame; + + // return new QLabel("Fieldline \n OPM"); } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index 62a700a18b6..df78a5179a0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" +//#include "Python.h" #include "fieldline_acq_system_controller.h" @@ -60,30 +60,30 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // - Py_Initialize(); - PyConfig config; - PyConfig_InitPythonConfig(&config); - config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, L"."); - Py_InitializeFromConfig(&config); - FILE* py_file = fopen("main.py", "r"); - PyObject* global_dict = PyDict_New(); - PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, - "main.py", - Py_file_input, - global_dict, - local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); +// Py_Initialize(); +// PyConfig config; +// PyConfig_InitPythonConfig(&config); +// config.module_search_paths_set = 1; +// PyWideStringList_Append(&config.module_search_paths, L"."); +// Py_InitializeFromConfig(&config); +// FILE* py_file = fopen("main.py", "r"); +// PyObject* global_dict = PyDict_New(); +// PyObject* local_dict = PyDict_New(); +// PyObject* result = PyRun_File(py_file, +// "main.py", +// Py_file_input, +// global_dict, +// local_dict); +// Py_DECREF(global_dict); +// Py_DECREF(local_dict); +// Py_DECREF(result); +// fclose(py_file); } FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { - Py_Finalize(); +// Py_Finalize(); } } diff --git a/src/libraries/disp/CMakeLists.txt b/src/libraries/disp/CMakeLists.txt index 78792d03770..177cdc0ad0b 100644 --- a/src/libraries/disp/CMakeLists.txt +++ b/src/libraries/disp/CMakeLists.txt @@ -56,8 +56,9 @@ set(SOURCES viewers/hpisettingsview.cpp viewers/covariancesettingsview.cpp viewers/bidsview.cpp - viewers/led_indicator.cpp - viewers/fieldlineview.cpp + viewers/fl_sensor.cpp + viewers/fl_chassis.cpp + viewers/fl_rack.cpp viewers/helpers/rtfiffrawviewmodel.cpp viewers/helpers/rtfiffrawviewdelegate.cpp viewers/helpers/evokedsetmodel.cpp @@ -121,8 +122,9 @@ set(HEADERS viewers/hpisettingsview.h viewers/covariancesettingsview.h viewers/bidsview.h - viewers/led_indicator.h - viewers/fieldlineview.h + viewers/fl_sensor.h + viewers/fl_chassis.h + viewers/fl_rack.h viewers/helpers/rtfiffrawviewdelegate.h viewers/helpers/rtfiffrawviewmodel.h viewers/helpers/evokedsetmodel.h diff --git a/src/libraries/disp/viewers/fl_chassis.cpp b/src/libraries/disp/viewers/fl_chassis.cpp new file mode 100644 index 00000000000..d8e735e0aba --- /dev/null +++ b/src/libraries/disp/viewers/fl_chassis.cpp @@ -0,0 +1,22 @@ +#include "fl_chassis.h" +#include "ui_fl_chassis.h" + + +fl_chassis::fl_chassis(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_chassis) +{ + ui->setupUi(this); + + for(int i = 0; i < 16; ++i){ + sensors.push_back(std::make_unique()); + sensors.back()->setLabel(QString::number(i+1)); + ui->sensor_frame->layout()->addWidget(sensors.back().get()); + } + sensors.back()->setBlink(true); +} + +fl_chassis::~fl_chassis() +{ + delete ui; +} diff --git a/src/libraries/disp/viewers/fl_chassis.h b/src/libraries/disp/viewers/fl_chassis.h new file mode 100644 index 00000000000..904b880e748 --- /dev/null +++ b/src/libraries/disp/viewers/fl_chassis.h @@ -0,0 +1,26 @@ +#ifndef FL_CHASSIS_H +#define FL_CHASSIS_H + +#include +#include +#include +#include "fl_sensor.h" + +namespace Ui { +class fl_chassis; +} + +class fl_chassis : public QWidget +{ + Q_OBJECT + +public: + explicit fl_chassis(QWidget *parent = nullptr); + ~fl_chassis(); + +private: + Ui::fl_chassis *ui; + std::vector> sensors; +}; + +#endif // FL_CHASSIS_H diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fl_rack.cpp new file mode 100644 index 00000000000..add240e76c5 --- /dev/null +++ b/src/libraries/disp/viewers/fl_rack.cpp @@ -0,0 +1,18 @@ +#include "fl_rack.h" +#include "ui_fl_rack.h" + +#include "fl_chassis.h" + +fl_rack::fl_rack(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_rack) +{ + ui->setupUi(this); + + ui->frame->layout()->addWidget(new fl_chassis()); +} + +fl_rack::~fl_rack() +{ + delete ui; +} diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fl_rack.h new file mode 100644 index 00000000000..0e8939bd569 --- /dev/null +++ b/src/libraries/disp/viewers/fl_rack.h @@ -0,0 +1,22 @@ +#ifndef FL_RACK_H +#define FL_RACK_H + +#include + +namespace Ui { +class fl_rack; +} + +class fl_rack : public QWidget +{ + Q_OBJECT + +public: + explicit fl_rack(QWidget *parent = nullptr); + ~fl_rack(); + +private: + Ui::fl_rack *ui; +}; + +#endif // FL_RACK_H diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/fl_sensor.cpp new file mode 100644 index 00000000000..3e214e16bf9 --- /dev/null +++ b/src/libraries/disp/viewers/fl_sensor.cpp @@ -0,0 +1,78 @@ +#include "fl_sensor.h" +#include "ui_fl_sensor.h" +# + +fl_sensor::fl_sensor(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_sensor) +{ + color = Qt::red; + + blink_brush = QBrush(Qt::transparent); + on_brush = QBrush(color); + + ui->setupUi(this); + ui->graphicsView->setStyleSheet("background:transparent"); + ui->label->setText("Hello"); + m_pScene = std::make_unique(); + ui->graphicsView->setScene(m_pScene.get()); + + circle = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); + blinkstate = false; + + blinktime = 200; +} + +fl_sensor::~fl_sensor() +{ + delete ui; +} + +void fl_sensor::setLabel(const QString& label) +{ + ui->label->setText(label); +} + + +void fl_sensor::resizeEvent(QResizeEvent *event) +{ + auto bounds = m_pScene->itemsBoundingRect(); + bounds.setWidth(bounds.width() * 1.2); + bounds.setHeight(bounds.height() * 1.2); + ui->graphicsView->fitInView(bounds, Qt::KeepAspectRatio); + + QWidget::resizeEvent(event); +} + +void fl_sensor::setBlink(bool state) +{ + if(state){ + turnOnBlink(); + } else { + turnOffBlink(); + } +} + + +void fl_sensor::turnOnBlink() +{ + connect(&t, &QTimer::timeout, this, &fl_sensor::handleBlink, Qt::UniqueConnection); + t.start(blinktime); +} + +void fl_sensor::turnOffBlink() +{ + t.stop(); + circle->setBrush(on_brush); +} + +void fl_sensor::handleBlink() +{ + if(blinkstate){ + circle->setBrush(blink_brush); + blinkstate = false; + } else { + circle->setBrush(on_brush); + blinkstate = true; + } +} diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/fl_sensor.h new file mode 100644 index 00000000000..3d7ed16b57f --- /dev/null +++ b/src/libraries/disp/viewers/fl_sensor.h @@ -0,0 +1,45 @@ +#ifndef FL_SENSOR_H +#define FL_SENSOR_H + +#include +#include +#include +#include +#include + +namespace Ui { +class fl_sensor; +} + +class fl_sensor : public QWidget +{ + Q_OBJECT + +public: + explicit fl_sensor(QWidget *parent = nullptr); + ~fl_sensor(); + + void setLabel(const QString& label); + + void setBlink(bool state); + +protected: + virtual void resizeEvent(QResizeEvent *event); +private: + void turnOnBlink(); + void turnOffBlink(); + void handleBlink(); + + + int blinktime; + Ui::fl_sensor *ui; + std::unique_ptr m_pScene; + QGraphicsEllipseItem* circle; + QTimer t; + QColor color; + QBrush blink_brush; + QBrush on_brush; + bool blinkstate; +}; + +#endif // FL_SENSOR_H diff --git a/src/libraries/disp/viewers/formfiles/fl_sensor.ui b/src/libraries/disp/viewers/formfiles/fl_sensor.ui new file mode 100644 index 00000000000..eebb7d10dbd --- /dev/null +++ b/src/libraries/disp/viewers/formfiles/fl_sensor.ui @@ -0,0 +1,59 @@ + + + fl_sensor + + + + 0 + 0 + 400 + 225 + + + + + 0 + 0 + + + + Form + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + + From 22f7f01597f20a4d26893a2d4f4389948eb702d4 Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 12:20:39 -0500 Subject: [PATCH 047/147] Reorganize and refactor fl_rack --- src/libraries/disp/viewers/fl_rack.cpp | 176 ++++++++++++++++++++++++- src/libraries/disp/viewers/fl_rack.h | 98 +++++++++++++- 2 files changed, 264 insertions(+), 10 deletions(-) diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fl_rack.cpp index add240e76c5..0cc76cadb2c 100644 --- a/src/libraries/disp/viewers/fl_rack.cpp +++ b/src/libraries/disp/viewers/fl_rack.cpp @@ -1,18 +1,182 @@ +//============================================================================================================= +/** + * @file fl_rack.cpp + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + #include "fl_rack.h" +#include "fl_chassis.h" + #include "ui_fl_rack.h" -#include "fl_chassis.h" +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +using DISPLIB::FieldlineView; +using DISPLIB::fl_chassis; + +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +int FieldlineView::default_num_sensors = 16; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + + +FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) +: FieldlineView(parent) +{ + configure(num_chassis, sensors_per_chassis); +} + +//============================================================================================================= + +FieldlineView::FieldlineView(int num_chassis, QWidget *parent) +: FieldlineView(num_chassis, default_num_sensors, parent) +{ +} + +//============================================================================================================= -fl_rack::fl_rack(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_rack) +FieldlineView::FieldlineView(QWidget *parent) +: QWidget(parent) +, ui(std::make_unique()) { ui->setupUi(this); +} + +//============================================================================================================= + +FieldlineView::~FieldlineView() +{ +} + +//============================================================================================================= + +void FieldlineView::configure(int num_chassis) +{ + configure(num_chassis, default_num_sensors); +} + +//============================================================================================================= + +void FieldlineView::configure(int num_chassis, int num_sensors) +{ ui->frame->layout()->addWidget(new fl_chassis()); } -fl_rack::~fl_rack() +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) { - delete ui; + +} + +//============================================================================================================= + +void FieldlineView::setChassisColor(int chassis_id, QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllColor(QColor color) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllColor(QColor color, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) +{ + +} + +//============================================================================================================= + +void FieldlineView::setAllBlinkState(bool blinking) +{ + +} + +//============================================================================================================= + +static void setDefaultNumSensors(int num_sensors) +{ + } diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fl_rack.h index 0e8939bd569..6f31be7c623 100644 --- a/src/libraries/disp/viewers/fl_rack.h +++ b/src/libraries/disp/viewers/fl_rack.h @@ -1,22 +1,112 @@ +//============================================================================================================= +/** + * @file fl_rack.h + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + #ifndef FL_RACK_H #define FL_RACK_H +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "../disp_global.h" +#include "fl_chassis.h" + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + #include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= namespace Ui { class fl_rack; } -class fl_rack : public QWidget +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace DISPLIB +{ + +class FieldlineView : public QWidget { Q_OBJECT public: - explicit fl_rack(QWidget *parent = nullptr); - ~fl_rack(); + FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); + FieldlineView(int num_chassis, QWidget *parent = nullptr); + explicit FieldlineView(QWidget *parent = nullptr); + ~FieldlineView(); + + void configure(int num_chassis); + void configure(int num_chassis, int num_sensors); + + void setColor(int chassis_id, int sensnor_num, QColor color); + void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); + + void setChassisColor(int chassis_id, QColor color); + void setChassisColor(int chassis_id, QColor color, bool blinking); + + void setAllColor(QColor color); + void setAllColor(QColor color, bool blinking); + + void setBlinkState(int chassis_id, int sensnor_num, bool blinking); + void setChassisBlinkState(int chassis_id, bool blinking); + void setAllBlinkState(bool blinking); + + static void setDefaultNumSensors(int num_sensors); private: - Ui::fl_rack *ui; + static int default_num_sensors; + + std::unique_ptr ui; + + std::vector> chassis; }; +}//namespace DISPLIB + #endif // FL_RACK_H From 1b0a387e0100c78cbac8cd8ee2b2ae41c7f7339c Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 12:21:17 -0500 Subject: [PATCH 048/147] Reorganize and refactor fl_sensor --- src/libraries/disp/viewers/fl_sensor.cpp | 155 +++++++++++++++++------ src/libraries/disp/viewers/fl_sensor.h | 91 +++++++++++-- 2 files changed, 197 insertions(+), 49 deletions(-) diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/fl_sensor.cpp index 3e214e16bf9..ca393dece09 100644 --- a/src/libraries/disp/viewers/fl_sensor.cpp +++ b/src/libraries/disp/viewers/fl_sensor.cpp @@ -1,40 +1,118 @@ +//============================================================================================================= +/** + * @file fl_sensor.cpp + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineSensor class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + #include "fl_sensor.h" #include "ui_fl_sensor.h" -# -fl_sensor::fl_sensor(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_sensor) -{ - color = Qt::red; +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +using DISPLIB::FieldlineSensor; - blink_brush = QBrush(Qt::transparent); - on_brush = QBrush(color); +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +QColor FieldlineSensor::default_color = Qt::red; +QString FieldlineSensor::default_label = "XX"; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +FieldlineSensor::FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent) +: QWidget(parent) +, ui(std::make_unique()) +, blink_brush(QBrush(Qt::transparent)) +, on_brush(QBrush(led_color)) +, blink_time_ms(200) +{ + m_pScene = std::make_unique(); ui->setupUi(this); ui->graphicsView->setStyleSheet("background:transparent"); - ui->label->setText("Hello"); - m_pScene = std::make_unique(); + ui->label->setText(label); ui->graphicsView->setScene(m_pScene.get()); - circle = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); - blinkstate = false; + circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); +} + +//============================================================================================================= - blinktime = 200; +FieldlineSensor::FieldlineSensor(const QString& label, QWidget *parent) +: FieldlineSensor(label, default_color, parent) +{ +} + +//============================================================================================================= + +FieldlineSensor::FieldlineSensor(QWidget *parent) +: FieldlineSensor(default_label, default_color, parent) +{ } -fl_sensor::~fl_sensor() +//============================================================================================================= + +FieldlineSensor::~FieldlineSensor() { - delete ui; } -void fl_sensor::setLabel(const QString& label) +//============================================================================================================= + +void FieldlineSensor::setLabel(const QString& label) { ui->label->setText(label); } +//============================================================================================================= -void fl_sensor::resizeEvent(QResizeEvent *event) +void FieldlineSensor::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); bounds.setWidth(bounds.width() * 1.2); @@ -44,35 +122,38 @@ void fl_sensor::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } -void fl_sensor::setBlink(bool state) +//============================================================================================================= + +void FieldlineSensor::setBlink(bool state) { - if(state){ - turnOnBlink(); - } else { - turnOffBlink(); - } + state ? turnOnBlink() : turnOffBlink(); } +//============================================================================================================= -void fl_sensor::turnOnBlink() +void FieldlineSensor::turnOnBlink() { - connect(&t, &QTimer::timeout, this, &fl_sensor::handleBlink, Qt::UniqueConnection); - t.start(blinktime); + connect(&blink_timer, &QTimer::timeout, + this, &FieldlineSensor::handleBlink, Qt::UniqueConnection); + blink_timer.start(blink_time_ms); } -void fl_sensor::turnOffBlink() +//============================================================================================================= + +void FieldlineSensor::turnOffBlink() { - t.stop(); - circle->setBrush(on_brush); + blink_timer.stop(); + circle_led->setBrush(on_brush); } -void fl_sensor::handleBlink() +//============================================================================================================= + +void FieldlineSensor::handleBlink() { - if(blinkstate){ - circle->setBrush(blink_brush); - blinkstate = false; - } else { - circle->setBrush(on_brush); - blinkstate = true; - } + static bool blink_state = false; + + blink_state ? circle_led->setBrush(blink_brush) + : circle_led->setBrush(on_brush); + + blink_state = !blink_state; } diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/fl_sensor.h index 3d7ed16b57f..a048eab0f35 100644 --- a/src/libraries/disp/viewers/fl_sensor.h +++ b/src/libraries/disp/viewers/fl_sensor.h @@ -1,45 +1,112 @@ +//============================================================================================================= +/** + * @file fl_sensor.h + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineSensor class declaration. + * + */ + #ifndef FL_SENSOR_H #define FL_SENSOR_H +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "../disp_global.h" + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + #include #include -#include #include #include +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + namespace Ui { class fl_sensor; } -class fl_sensor : public QWidget +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace DISPLIB +{ + +class FieldlineSensor : public QWidget { Q_OBJECT public: - explicit fl_sensor(QWidget *parent = nullptr); - ~fl_sensor(); + FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent = nullptr); + FieldlineSensor(const QString& label, QWidget *parent = nullptr); + explicit FieldlineSensor(QWidget *parent = nullptr); + ~FieldlineSensor(); void setLabel(const QString& label); - void setBlink(bool state); + void setColor(const QColor& color); protected: virtual void resizeEvent(QResizeEvent *event); + private: void turnOnBlink(); void turnOffBlink(); void handleBlink(); - - int blinktime; - Ui::fl_sensor *ui; + std::unique_ptr ui; std::unique_ptr m_pScene; - QGraphicsEllipseItem* circle; - QTimer t; - QColor color; + + int blink_time_ms; + QTimer blink_timer; + + static QColor default_color; + static QString default_label; + + QGraphicsEllipseItem* circle_led; QBrush blink_brush; QBrush on_brush; - bool blinkstate; }; +}//namespace DISPLIB #endif // FL_SENSOR_H From 7c87aaf44e8cdc624b5c1f068c00d4f8d589bdaa Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 14:00:24 -0500 Subject: [PATCH 049/147] Reorganiz files and names --- src/libraries/disp/CMakeLists.txt | 10 +- src/libraries/disp/viewers/fieldlineview.cpp | 184 +++--------------- src/libraries/disp/viewers/fieldlineview.h | 51 ++--- src/libraries/disp/viewers/fl_chassis.cpp | 22 --- src/libraries/disp/viewers/fl_chassis.h | 26 --- src/libraries/disp/viewers/fl_rack.cpp | 182 ----------------- src/libraries/disp/viewers/fl_rack.h | 112 ----------- src/libraries/disp/viewers/fl_sensor.cpp | 159 --------------- src/libraries/disp/viewers/fl_sensor.h | 112 ----------- .../disp/viewers/formfiles/fl_sensor.ui | 59 ------ .../disp/viewers/formfiles/led_indicator.ui | 4 +- src/libraries/disp/viewers/led_indicator.cpp | 38 ++-- src/libraries/disp/viewers/led_indicator.h | 7 +- 13 files changed, 68 insertions(+), 898 deletions(-) delete mode 100644 src/libraries/disp/viewers/fl_chassis.cpp delete mode 100644 src/libraries/disp/viewers/fl_chassis.h delete mode 100644 src/libraries/disp/viewers/fl_rack.cpp delete mode 100644 src/libraries/disp/viewers/fl_rack.h delete mode 100644 src/libraries/disp/viewers/fl_sensor.cpp delete mode 100644 src/libraries/disp/viewers/fl_sensor.h delete mode 100644 src/libraries/disp/viewers/formfiles/fl_sensor.ui diff --git a/src/libraries/disp/CMakeLists.txt b/src/libraries/disp/CMakeLists.txt index 177cdc0ad0b..78792d03770 100644 --- a/src/libraries/disp/CMakeLists.txt +++ b/src/libraries/disp/CMakeLists.txt @@ -56,9 +56,8 @@ set(SOURCES viewers/hpisettingsview.cpp viewers/covariancesettingsview.cpp viewers/bidsview.cpp - viewers/fl_sensor.cpp - viewers/fl_chassis.cpp - viewers/fl_rack.cpp + viewers/led_indicator.cpp + viewers/fieldlineview.cpp viewers/helpers/rtfiffrawviewmodel.cpp viewers/helpers/rtfiffrawviewdelegate.cpp viewers/helpers/evokedsetmodel.cpp @@ -122,9 +121,8 @@ set(HEADERS viewers/hpisettingsview.h viewers/covariancesettingsview.h viewers/bidsview.h - viewers/fl_sensor.h - viewers/fl_chassis.h - viewers/fl_rack.h + viewers/led_indicator.h + viewers/fieldlineview.h viewers/helpers/rtfiffrawviewdelegate.h viewers/helpers/rtfiffrawviewmodel.h viewers/helpers/evokedsetmodel.h diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 144cc99a4fe..8fcd9976d0e 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -37,19 +37,16 @@ // INCLUDES //============================================================================================================= +#include "fieldlineview.h" + #include "ui_fl_rack.h" #include "ui_fl_chassis.h" -#include "fieldlineview.h" //============================================================================================================= // QT INCLUDES //============================================================================================================= -#include -#include -#include - //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -89,15 +86,15 @@ FieldlineView::FieldlineView(int num_chassis, QWidget *parent) FieldlineView::FieldlineView(QWidget *parent) : QWidget(parent) -, ui(new Ui::fl_rack()) +, ui(std::make_unique()) { ui->setupUi(this); } + //============================================================================================================= FieldlineView::~FieldlineView() { - delete ui; } //============================================================================================================= @@ -111,222 +108,99 @@ void FieldlineView::configure(int num_chassis) void FieldlineView::configure(int num_chassis, int num_sensors) { - clear(); - for(int i = 0; i < num_chassis; ++i){ - chassis.push_back(new fl_chassis(num_sensors)); - ui->frame->layout()->addWidget(chassis.back()); - } + + ui->frame->layout()->addWidget(new fl_chassis()); } //============================================================================================================= -void FieldlineView::clear() +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) { - for(auto* c : chassis){ - ui->frame->layout()->removeWidget(c); - c->deleteLater(); - } -}; -//============================================================================================================= - -void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(sensor_num, color); } //============================================================================================================= -void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) +void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) { - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(sensor_num, color, blinking); -} - -//============================================================================================================= -void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(color); } //============================================================================================================= -void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color, bool blinking) +void FieldlineView::setChassisColor(int chassis_id, QColor color) { - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(color, blinking); -} - -//============================================================================================================= -void FieldlineView::setAllColor(const QColor& color) -{ - for(auto* c : chassis){ - c->setColor(color); - } } //============================================================================================================= -void FieldlineView::setAllColor(const QColor& color, bool blinking) +void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) { - for(auto* c : chassis){ - c->setColor(color, blinking); - } -} -//============================================================================================================= - -void FieldlineView::setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); } //============================================================================================================= -void FieldlineView::setChassisBlinkState(size_t chassis_id, bool blinking) +void FieldlineView::setAllColor(QColor color) { - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setBlinkState(blinking); -} - -//============================================================================================================= -void FieldlineView::setAllBlinkState(bool blinking) -{ - for(auto* c : chassis){ - c->setBlinkState(blinking); - } } //============================================================================================================= -void FieldlineView::setDefaultNumSensors(int num_sensors) +void FieldlineView::setAllColor(QColor color, bool blinking) { - default_num_sensors = num_sensors; + } //============================================================================================================= -fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) -: QWidget(parent) -, ui(new Ui::fl_chassis()) +void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) { - ui->setupUi(this); - for(int i = 0; i < num_sensors; ++i){ - sensors.push_back(new LEDIndicator()); - auto& last_item = sensors.back(); - sensors.back()->setLabel(QString::number(i + 1)); - ui->sensor_frame->layout()->addWidget(sensors.back()); - connect(sensors.back(), &QWidget::customContextMenuRequested, - [this, i, &last_item](const QPoint& pos) - { - qDebug() << "clicked " << i+1; - qDebug() << "global pos: " << last_item->mapToGlobal(pos); - this->emit clicked(i, last_item->mapToGlobal(pos)); - }); - connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); - } } //============================================================================================================= -fl_chassis::~fl_chassis() +void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) { - delete ui; -} - -//============================================================================================================= -void fl_chassis::setColor(size_t sensor_num, const QColor& color) -{ - if(sensor_num > sensors.size() || sensor_num < 1) - { - return; - } - sensors.at(sensor_num - 1)->setColor(color); } //============================================================================================================= -void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) +void FieldlineView::setAllBlinkState(bool blinking) { - setColor(sensor_num, color); - setBlinkState(sensor_num, blinking); -} - -//============================================================================================================= -void fl_chassis::setColor(const QColor& color) -{ - for(auto* sensor : sensors){ - sensor->setColor(color); - } } //============================================================================================================= -void fl_chassis::setColor(const QColor& color, bool blinking) +void FieldlineView::setDefaultNumSensors(int num_sensors) { - for(auto* sensor : sensors){ - sensor->setColor(color); - sensor->setBlink(blinking); - } -} -//============================================================================================================= - -void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) -{ - if(sensor_num > sensors.size() || sensor_num < 1){ - return; - } - sensors.at(sensor_num - 1)->setBlink(blinking); } //============================================================================================================= -void fl_chassis::setBlinkState(bool blinking) +fl_chassis::fl_chassis(QWidget *parent) : + QWidget(parent), + ui(new Ui::fl_chassis) { - for(auto* sensor : sensors){ - sensor->setBlink(blinking); + ui->setupUi(this); + + for(int i = 0; i < 16; ++i){ + sensors.push_back(std::make_unique()); + sensors.back()->setLabel(QString::number(i+1)); + ui->sensor_frame->layout()->addWidget(sensors.back().get()); } + sensors.back()->setBlink(true); } //============================================================================================================= -void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) +fl_chassis::~fl_chassis() { - auto* menu = new QMenu(); - - auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); - auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); - - auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); - auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); - - connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); - connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); - - connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); - connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); - - menu->exec(pos); + delete ui; } diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index 2f9034f1941..feb2ad5d1cd 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -63,8 +63,8 @@ //============================================================================================================= namespace Ui { - class fl_rack; - class fl_chassis; +class fl_rack; +class fl_chassis; } //============================================================================================================= @@ -82,64 +82,49 @@ class FieldlineView : public QWidget Q_OBJECT public: - explicit FieldlineView(QWidget *parent = nullptr); FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); FieldlineView(int num_chassis, QWidget *parent = nullptr); + explicit FieldlineView(QWidget *parent = nullptr); + ~FieldlineView(); void configure(int num_chassis); void configure(int num_chassis, int num_sensors); - void clear(); - - void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); - void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); + void setColor(int chassis_id, int sensnor_num, QColor color); + void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); - void setChassisColor(size_t chassis_id, const QColor& color); - void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); + void setChassisColor(int chassis_id, QColor color); + void setChassisColor(int chassis_id, QColor color, bool blinking); - void setAllColor(const QColor& color); - void setAllColor(const QColor &color, bool blinking); + void setAllColor(QColor color); + void setAllColor(QColor color, bool blinking); - void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); - void setChassisBlinkState(size_t chassis_id, bool blinking); + void setBlinkState(int chassis_id, int sensnor_num, bool blinking); + void setChassisBlinkState(int chassis_id, bool blinking); void setAllBlinkState(bool blinking); static void setDefaultNumSensors(int num_sensors); private: static int default_num_sensors; - Ui::fl_rack* ui; - std::vector chassis; + std::unique_ptr ui; + + std::vector> chassis; }; //============================================================================================================= - class fl_chassis : public QWidget { Q_OBJECT public: - fl_chassis(int num_sensors, QWidget *parent = nullptr); + explicit fl_chassis(QWidget *parent = nullptr); ~fl_chassis(); - void setColor(size_t sensor_num, const QColor& color); - void setColor(size_t sensor_num, const QColor& color, bool blinking); - void setColor(const QColor& color); - void setColor(const QColor& color, bool blinking); - - void setBlinkState(size_t sensor_num, bool blinking); - void setBlinkState(bool blinking); - -signals: - void clicked(int sensor, const QPoint& pos); - -private slots: - void rightClickMenu(int sensor, const QPoint& pos); - private: - Ui::fl_chassis* ui; - std::vector sensors; + Ui::fl_chassis *ui; + std::vector> sensors; }; diff --git a/src/libraries/disp/viewers/fl_chassis.cpp b/src/libraries/disp/viewers/fl_chassis.cpp deleted file mode 100644 index d8e735e0aba..00000000000 --- a/src/libraries/disp/viewers/fl_chassis.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "fl_chassis.h" -#include "ui_fl_chassis.h" - - -fl_chassis::fl_chassis(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_chassis) -{ - ui->setupUi(this); - - for(int i = 0; i < 16; ++i){ - sensors.push_back(std::make_unique()); - sensors.back()->setLabel(QString::number(i+1)); - ui->sensor_frame->layout()->addWidget(sensors.back().get()); - } - sensors.back()->setBlink(true); -} - -fl_chassis::~fl_chassis() -{ - delete ui; -} diff --git a/src/libraries/disp/viewers/fl_chassis.h b/src/libraries/disp/viewers/fl_chassis.h deleted file mode 100644 index 904b880e748..00000000000 --- a/src/libraries/disp/viewers/fl_chassis.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef FL_CHASSIS_H -#define FL_CHASSIS_H - -#include -#include -#include -#include "fl_sensor.h" - -namespace Ui { -class fl_chassis; -} - -class fl_chassis : public QWidget -{ - Q_OBJECT - -public: - explicit fl_chassis(QWidget *parent = nullptr); - ~fl_chassis(); - -private: - Ui::fl_chassis *ui; - std::vector> sensors; -}; - -#endif // FL_CHASSIS_H diff --git a/src/libraries/disp/viewers/fl_rack.cpp b/src/libraries/disp/viewers/fl_rack.cpp deleted file mode 100644 index 0cc76cadb2c..00000000000 --- a/src/libraries/disp/viewers/fl_rack.cpp +++ /dev/null @@ -1,182 +0,0 @@ -//============================================================================================================= -/** - * @file fl_rack.cpp - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineView class definition. - * - */ - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "fl_rack.h" -#include "fl_chassis.h" - -#include "ui_fl_rack.h" - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// USED NAMESPACES -//============================================================================================================= - -using DISPLIB::FieldlineView; -using DISPLIB::fl_chassis; - -//============================================================================================================= -// DEFINE STATIC METHODS -//============================================================================================================= - -int FieldlineView::default_num_sensors = 16; - -//============================================================================================================= -// DEFINE MEMBER METHODS -//============================================================================================================= - - -FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) -: FieldlineView(parent) -{ - configure(num_chassis, sensors_per_chassis); -} - -//============================================================================================================= - -FieldlineView::FieldlineView(int num_chassis, QWidget *parent) -: FieldlineView(num_chassis, default_num_sensors, parent) -{ -} - -//============================================================================================================= - -FieldlineView::FieldlineView(QWidget *parent) -: QWidget(parent) -, ui(std::make_unique()) -{ - ui->setupUi(this); -} - -//============================================================================================================= - -FieldlineView::~FieldlineView() -{ -} - -//============================================================================================================= - -void FieldlineView::configure(int num_chassis) -{ - configure(num_chassis, default_num_sensors); -} - -//============================================================================================================= - -void FieldlineView::configure(int num_chassis, int num_sensors) -{ - - ui->frame->layout()->addWidget(new fl_chassis()); -} - -//============================================================================================================= - -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) -{ - -} - -//============================================================================================================= - -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) -{ - -} - -//============================================================================================================= - -void FieldlineView::setChassisColor(int chassis_id, QColor color) -{ - -} - -//============================================================================================================= - -void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) -{ - -} - -//============================================================================================================= - -void FieldlineView::setAllColor(QColor color) -{ - -} - -//============================================================================================================= - -void FieldlineView::setAllColor(QColor color, bool blinking) -{ - -} - -//============================================================================================================= - -void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) -{ - -} - -//============================================================================================================= - -void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) -{ - -} - -//============================================================================================================= - -void FieldlineView::setAllBlinkState(bool blinking) -{ - -} - -//============================================================================================================= - -static void setDefaultNumSensors(int num_sensors) -{ - -} diff --git a/src/libraries/disp/viewers/fl_rack.h b/src/libraries/disp/viewers/fl_rack.h deleted file mode 100644 index 6f31be7c623..00000000000 --- a/src/libraries/disp/viewers/fl_rack.h +++ /dev/null @@ -1,112 +0,0 @@ -//============================================================================================================= -/** - * @file fl_rack.h - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineView class declaration. - * - */ - -#ifndef FL_RACK_H -#define FL_RACK_H - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "../disp_global.h" -#include "fl_chassis.h" - -#include - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -#include -#include - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// FORWARD DECLARATIONS -//============================================================================================================= - -namespace Ui { -class fl_rack; -} - -//============================================================================================================= -// DEFINE NAMESPACE DISPLIB -//============================================================================================================= - -namespace DISPLIB -{ - -class FieldlineView : public QWidget -{ - Q_OBJECT - -public: - FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); - FieldlineView(int num_chassis, QWidget *parent = nullptr); - explicit FieldlineView(QWidget *parent = nullptr); - - ~FieldlineView(); - - void configure(int num_chassis); - void configure(int num_chassis, int num_sensors); - - void setColor(int chassis_id, int sensnor_num, QColor color); - void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); - - void setChassisColor(int chassis_id, QColor color); - void setChassisColor(int chassis_id, QColor color, bool blinking); - - void setAllColor(QColor color); - void setAllColor(QColor color, bool blinking); - - void setBlinkState(int chassis_id, int sensnor_num, bool blinking); - void setChassisBlinkState(int chassis_id, bool blinking); - void setAllBlinkState(bool blinking); - - static void setDefaultNumSensors(int num_sensors); -private: - static int default_num_sensors; - - std::unique_ptr ui; - - std::vector> chassis; -}; - -}//namespace DISPLIB - -#endif // FL_RACK_H diff --git a/src/libraries/disp/viewers/fl_sensor.cpp b/src/libraries/disp/viewers/fl_sensor.cpp deleted file mode 100644 index ca393dece09..00000000000 --- a/src/libraries/disp/viewers/fl_sensor.cpp +++ /dev/null @@ -1,159 +0,0 @@ -//============================================================================================================= -/** - * @file fl_sensor.cpp - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineSensor class definition. - * - */ - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - - -#include "fl_sensor.h" -#include "ui_fl_sensor.h" - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// USED NAMESPACES -//============================================================================================================= - -using DISPLIB::FieldlineSensor; - -//============================================================================================================= -// DEFINE STATIC METHODS -//============================================================================================================= - -QColor FieldlineSensor::default_color = Qt::red; -QString FieldlineSensor::default_label = "XX"; - -//============================================================================================================= -// DEFINE MEMBER METHODS -//============================================================================================================= - -FieldlineSensor::FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent) -: QWidget(parent) -, ui(std::make_unique()) -, blink_brush(QBrush(Qt::transparent)) -, on_brush(QBrush(led_color)) -, blink_time_ms(200) -{ - m_pScene = std::make_unique(); - - ui->setupUi(this); - ui->graphicsView->setStyleSheet("background:transparent"); - ui->label->setText(label); - ui->graphicsView->setScene(m_pScene.get()); - - circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); -} - -//============================================================================================================= - -FieldlineSensor::FieldlineSensor(const QString& label, QWidget *parent) -: FieldlineSensor(label, default_color, parent) -{ -} - -//============================================================================================================= - -FieldlineSensor::FieldlineSensor(QWidget *parent) -: FieldlineSensor(default_label, default_color, parent) -{ -} - -//============================================================================================================= - -FieldlineSensor::~FieldlineSensor() -{ -} - -//============================================================================================================= - -void FieldlineSensor::setLabel(const QString& label) -{ - ui->label->setText(label); -} - -//============================================================================================================= - -void FieldlineSensor::resizeEvent(QResizeEvent *event) -{ - auto bounds = m_pScene->itemsBoundingRect(); - bounds.setWidth(bounds.width() * 1.2); - bounds.setHeight(bounds.height() * 1.2); - ui->graphicsView->fitInView(bounds, Qt::KeepAspectRatio); - - QWidget::resizeEvent(event); -} - -//============================================================================================================= - -void FieldlineSensor::setBlink(bool state) -{ - state ? turnOnBlink() : turnOffBlink(); -} - -//============================================================================================================= - -void FieldlineSensor::turnOnBlink() -{ - connect(&blink_timer, &QTimer::timeout, - this, &FieldlineSensor::handleBlink, Qt::UniqueConnection); - blink_timer.start(blink_time_ms); -} - -//============================================================================================================= - -void FieldlineSensor::turnOffBlink() -{ - blink_timer.stop(); - circle_led->setBrush(on_brush); -} - -//============================================================================================================= - -void FieldlineSensor::handleBlink() -{ - static bool blink_state = false; - - blink_state ? circle_led->setBrush(blink_brush) - : circle_led->setBrush(on_brush); - - blink_state = !blink_state; -} diff --git a/src/libraries/disp/viewers/fl_sensor.h b/src/libraries/disp/viewers/fl_sensor.h deleted file mode 100644 index a048eab0f35..00000000000 --- a/src/libraries/disp/viewers/fl_sensor.h +++ /dev/null @@ -1,112 +0,0 @@ -//============================================================================================================= -/** - * @file fl_sensor.h - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineSensor class declaration. - * - */ - -#ifndef FL_SENSOR_H -#define FL_SENSOR_H - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "../disp_global.h" - -#include - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -#include -#include -#include -#include - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// FORWARD DECLARATIONS -//============================================================================================================= - -namespace Ui { -class fl_sensor; -} - -//============================================================================================================= -// DEFINE NAMESPACE DISPLIB -//============================================================================================================= - -namespace DISPLIB -{ - -class FieldlineSensor : public QWidget -{ - Q_OBJECT - -public: - FieldlineSensor(const QString& label, const QColor& led_color, QWidget *parent = nullptr); - FieldlineSensor(const QString& label, QWidget *parent = nullptr); - explicit FieldlineSensor(QWidget *parent = nullptr); - ~FieldlineSensor(); - - void setLabel(const QString& label); - void setBlink(bool state); - void setColor(const QColor& color); - -protected: - virtual void resizeEvent(QResizeEvent *event); - -private: - void turnOnBlink(); - void turnOffBlink(); - void handleBlink(); - - std::unique_ptr ui; - std::unique_ptr m_pScene; - - int blink_time_ms; - QTimer blink_timer; - - static QColor default_color; - static QString default_label; - - QGraphicsEllipseItem* circle_led; - QBrush blink_brush; - QBrush on_brush; -}; -}//namespace DISPLIB - -#endif // FL_SENSOR_H diff --git a/src/libraries/disp/viewers/formfiles/fl_sensor.ui b/src/libraries/disp/viewers/formfiles/fl_sensor.ui deleted file mode 100644 index eebb7d10dbd..00000000000 --- a/src/libraries/disp/viewers/formfiles/fl_sensor.ui +++ /dev/null @@ -1,59 +0,0 @@ - - - fl_sensor - - - - 0 - 0 - 400 - 225 - - - - - 0 - 0 - - - - Form - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - - - - - 0 - 0 - - - - TextLabel - - - Qt::AlignBottom|Qt::AlignHCenter - - - - - - - - diff --git a/src/libraries/disp/viewers/formfiles/led_indicator.ui b/src/libraries/disp/viewers/formfiles/led_indicator.ui index 28af9347b34..ab1c713991a 100644 --- a/src/libraries/disp/viewers/formfiles/led_indicator.ui +++ b/src/libraries/disp/viewers/formfiles/led_indicator.ui @@ -1,7 +1,7 @@ - led_indicator - + led_ind + 0 diff --git a/src/libraries/disp/viewers/led_indicator.cpp b/src/libraries/disp/viewers/led_indicator.cpp index 6228349a9d9..39f27501e31 100644 --- a/src/libraries/disp/viewers/led_indicator.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -44,10 +44,6 @@ // QT INCLUDES //============================================================================================================= -#include -#include -#include - //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -71,24 +67,19 @@ QString LEDIndicator::default_label = "XX"; LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) -, off_brush(QBrush(Qt::transparent)) +, ui(std::make_unique()) +, blink_brush(QBrush(Qt::transparent)) , on_brush(QBrush(led_color)) , blink_time_ms(200) -, blink_state(false) { m_pScene = std::make_unique(); ui->setupUi(this); ui->graphicsView->setStyleSheet("background:transparent"); - ui->graphicsView->horizontalScrollBar()->hide(); - ui->graphicsView->verticalScrollBar()->hide(); ui->label->setText(label); ui->graphicsView->setScene(m_pScene.get()); circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); - - this->setContextMenuPolicy(Qt::CustomContextMenu); } //============================================================================================================= @@ -120,20 +111,6 @@ void LEDIndicator::setLabel(const QString& label) //============================================================================================================= -void LEDIndicator::setBlink(bool state) -{ - state ? turnOnBlink() : turnOffBlink(); -} - -//============================================================================================================= - -void LEDIndicator::setColor(const QColor& color) -{ - on_brush.setColor(color); -} - -//============================================================================================================= - void LEDIndicator::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); @@ -146,6 +123,13 @@ void LEDIndicator::resizeEvent(QResizeEvent *event) //============================================================================================================= +void LEDIndicator::setBlink(bool state) +{ + state ? turnOnBlink() : turnOffBlink(); +} + +//============================================================================================================= + void LEDIndicator::turnOnBlink() { connect(&blink_timer, &QTimer::timeout, @@ -165,7 +149,9 @@ void LEDIndicator::turnOffBlink() void LEDIndicator::handleBlink() { - blink_state ? circle_led->setBrush(off_brush) + static bool blink_state = false; + + blink_state ? circle_led->setBrush(blink_brush) : circle_led->setBrush(on_brush); blink_state = !blink_state; diff --git a/src/libraries/disp/viewers/led_indicator.h b/src/libraries/disp/viewers/led_indicator.h index 391da06ad69..dfabfe1c2bc 100644 --- a/src/libraries/disp/viewers/led_indicator.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -62,7 +62,7 @@ //============================================================================================================= namespace Ui { - class led_indicator; +class led_ind; } //============================================================================================================= @@ -94,18 +94,17 @@ class LEDIndicator : public QWidget void turnOffBlink(); void handleBlink(); - std::unique_ptr ui; + std::unique_ptr ui; std::unique_ptr m_pScene; int blink_time_ms; QTimer blink_timer; - bool blink_state; static QColor default_color; static QString default_label; QGraphicsEllipseItem* circle_led; - QBrush off_brush; + QBrush blink_brush; QBrush on_brush; }; }//namespace DISPLIB From 5fc07880ca062d842b6a77d16e32132fc565d49a Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 15:40:47 -0500 Subject: [PATCH 050/147] clean up led indicator --- .../disp/viewers/formfiles/led_indicator.ui | 4 +-- src/libraries/disp/viewers/led_indicator.cpp | 34 ++++++++++++------- src/libraries/disp/viewers/led_indicator.h | 8 +++-- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/libraries/disp/viewers/formfiles/led_indicator.ui b/src/libraries/disp/viewers/formfiles/led_indicator.ui index ab1c713991a..28af9347b34 100644 --- a/src/libraries/disp/viewers/formfiles/led_indicator.ui +++ b/src/libraries/disp/viewers/formfiles/led_indicator.ui @@ -1,7 +1,7 @@ - led_ind - + led_indicator + 0 diff --git a/src/libraries/disp/viewers/led_indicator.cpp b/src/libraries/disp/viewers/led_indicator.cpp index 39f27501e31..c9b235fdf0f 100644 --- a/src/libraries/disp/viewers/led_indicator.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -44,6 +44,8 @@ // QT INCLUDES //============================================================================================================= +#include + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -67,15 +69,18 @@ QString LEDIndicator::default_label = "XX"; LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) -, blink_brush(QBrush(Qt::transparent)) +, ui(std::make_unique()) +, off_brush(QBrush(Qt::transparent)) , on_brush(QBrush(led_color)) , blink_time_ms(200) +, blink_state(false) { m_pScene = std::make_unique(); ui->setupUi(this); ui->graphicsView->setStyleSheet("background:transparent"); + ui->graphicsView->horizontalScrollBar()->hide(); + ui->graphicsView->verticalScrollBar()->hide(); ui->label->setText(label); ui->graphicsView->setScene(m_pScene.get()); @@ -111,6 +116,20 @@ void LEDIndicator::setLabel(const QString& label) //============================================================================================================= +void LEDIndicator::setBlink(bool state) +{ + state ? turnOnBlink() : turnOffBlink(); +} + +//============================================================================================================= + +void LEDIndicator::setColor(const QColor& color) +{ + on_brush.setColor(color); +} + +//============================================================================================================= + void LEDIndicator::resizeEvent(QResizeEvent *event) { auto bounds = m_pScene->itemsBoundingRect(); @@ -123,13 +142,6 @@ void LEDIndicator::resizeEvent(QResizeEvent *event) //============================================================================================================= -void LEDIndicator::setBlink(bool state) -{ - state ? turnOnBlink() : turnOffBlink(); -} - -//============================================================================================================= - void LEDIndicator::turnOnBlink() { connect(&blink_timer, &QTimer::timeout, @@ -149,9 +161,7 @@ void LEDIndicator::turnOffBlink() void LEDIndicator::handleBlink() { - static bool blink_state = false; - - blink_state ? circle_led->setBrush(blink_brush) + blink_state ? circle_led->setBrush(off_brush) : circle_led->setBrush(on_brush); blink_state = !blink_state; diff --git a/src/libraries/disp/viewers/led_indicator.h b/src/libraries/disp/viewers/led_indicator.h index dfabfe1c2bc..59fc4d9de0f 100644 --- a/src/libraries/disp/viewers/led_indicator.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -62,7 +62,7 @@ //============================================================================================================= namespace Ui { -class led_ind; + class led_indicator; } //============================================================================================================= @@ -94,17 +94,19 @@ class LEDIndicator : public QWidget void turnOffBlink(); void handleBlink(); - std::unique_ptr ui; + std::unique_ptr ui; std::unique_ptr m_pScene; int blink_time_ms; QTimer blink_timer; + bool blink_state; + static QColor default_color; static QString default_label; QGraphicsEllipseItem* circle_led; - QBrush blink_brush; + QBrush off_brush; QBrush on_brush; }; }//namespace DISPLIB From 11564175012bc0127645c062360a1ca430bb659e Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 23 Feb 2023 16:35:04 -0500 Subject: [PATCH 051/147] Implement rest of Fielline view and chassis logic --- .../mne_scan/plugins/fieldline/fieldline.cpp | 8 +- .../fieldline_acq_system_controller.cpp | 38 ++--- src/libraries/disp/viewers/fieldlineview.cpp | 150 ++++++++++++++---- src/libraries/disp/viewers/fieldlineview.h | 42 +++-- 4 files changed, 170 insertions(+), 68 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 37e780bbeee..fa115f113d0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,7 +44,7 @@ #include "fieldline.h" -#include +#include // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" @@ -196,7 +196,11 @@ QWidget *Fieldline::setupWidget() { auto* frame = new QWidget(); frame->setLayout(new QHBoxLayout()); - frame->layout()->addWidget(new fl_rack()); + auto* flWidget = new DISPLIB::FieldlineView(2, 16); + + frame->layout()->addWidget(flWidget); + flWidget->setBlinkState(0, 2, true); + flWidget->setBlinkState(1, 5, true); return frame; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index df78a5179a0..dbebe2ca44d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -//#include "Python.h" +#include "Python.h" #include "fieldline_acq_system_controller.h" @@ -60,24 +60,24 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // -// Py_Initialize(); -// PyConfig config; -// PyConfig_InitPythonConfig(&config); -// config.module_search_paths_set = 1; -// PyWideStringList_Append(&config.module_search_paths, L"."); -// Py_InitializeFromConfig(&config); -// FILE* py_file = fopen("main.py", "r"); -// PyObject* global_dict = PyDict_New(); -// PyObject* local_dict = PyDict_New(); -// PyObject* result = PyRun_File(py_file, -// "main.py", -// Py_file_input, -// global_dict, -// local_dict); -// Py_DECREF(global_dict); -// Py_DECREF(local_dict); -// Py_DECREF(result); -// fclose(py_file); + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + FILE* py_file = fopen("main.py", "r"); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, + "main.py", + Py_file_input, + global_dict, + local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); } diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 8fcd9976d0e..4de1397226c 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -37,11 +37,10 @@ // INCLUDES //============================================================================================================= -#include "fieldlineview.h" - #include "ui_fl_rack.h" #include "ui_fl_chassis.h" +#include "fieldlineview.h" //============================================================================================================= // QT INCLUDES @@ -86,15 +85,15 @@ FieldlineView::FieldlineView(int num_chassis, QWidget *parent) FieldlineView::FieldlineView(QWidget *parent) : QWidget(parent) -, ui(std::make_unique()) +, ui(new Ui::fl_rack()) { ui->setupUi(this); } - //============================================================================================================= FieldlineView::~FieldlineView() { + delete ui; } //============================================================================================================= @@ -108,94 +107,129 @@ void FieldlineView::configure(int num_chassis) void FieldlineView::configure(int num_chassis, int num_sensors) { - - ui->frame->layout()->addWidget(new fl_chassis()); + clear(); + for(int i = 0; i < num_chassis; ++i){ + chassis.push_back(new fl_chassis(num_sensors)); + ui->frame->layout()->addWidget(chassis.back()); + } } //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color) +void FieldlineView::clear() { + for(auto* c : chassis){ + ui->frame->layout()->removeWidget(c); + } +}; +//============================================================================================================= + +void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color) +{ + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(sensor_num, color); } //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensnor_num, QColor color, bool blinking) +void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(sensor_num, color, blinking); } //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, QColor color) +void FieldlineView::setChassisColor(int chassis_id, const QColor& color) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(color); } //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, QColor color, bool blinking) +void FieldlineView::setChassisColor(int chassis_id, const QColor& color, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setColor(color, blinking); } //============================================================================================================= -void FieldlineView::setAllColor(QColor color) +void FieldlineView::setAllColor(const QColor& color) { - + for(auto* c : chassis){ + c->setColor(color); + } } //============================================================================================================= -void FieldlineView::setAllColor(QColor color, bool blinking) +void FieldlineView::setAllColor(const QColor& color, bool blinking) { - + for(auto* c : chassis){ + c->setColor(color, blinking); + } } //============================================================================================================= -void FieldlineView::setBlinkState(int chassis_id, int sensnor_num, bool blinking) +void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); } //============================================================================================================= void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) { - + if(chassis_id >= chassis.size() || chassis_id < 0){ + return; + } + chassis.at(chassis_id)->setBlinkState(blinking); } //============================================================================================================= void FieldlineView::setAllBlinkState(bool blinking) { - + for(auto* c : chassis){ + c->setBlinkState(blinking); + } } //============================================================================================================= void FieldlineView::setDefaultNumSensors(int num_sensors) { - + default_num_sensors = num_sensors; } //============================================================================================================= -fl_chassis::fl_chassis(QWidget *parent) : - QWidget(parent), - ui(new Ui::fl_chassis) +fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) +: QWidget(parent) +, ui(new Ui::fl_chassis()) { ui->setupUi(this); - for(int i = 0; i < 16; ++i){ - sensors.push_back(std::make_unique()); - sensors.back()->setLabel(QString::number(i+1)); - ui->sensor_frame->layout()->addWidget(sensors.back().get()); + for(int i = 0; i < num_sensors; ++i){ + sensors.push_back(new LEDIndicator()); + sensors.back()->setLabel(QString::number(i + 1)); + ui->sensor_frame->layout()->addWidget(sensors.back()); } - sensors.back()->setBlink(true); } //============================================================================================================= @@ -204,3 +238,59 @@ fl_chassis::~fl_chassis() { delete ui; } + +//============================================================================================================= + +void fl_chassis::setColor(int sensor_num, const QColor& color) +{ + if(sensor_num > sensors.size() || sensor_num < 1){ + return; + } + sensors.at(sensor_num - 1)->setColor(color); +} + +//============================================================================================================= + +void fl_chassis::setColor(int sensor_num, const QColor& color, bool blinking) +{ + setColor(sensor_num, color); + setBlinkState(sensor_num, blinking); +} + +//============================================================================================================= + +void fl_chassis::setColor(const QColor& color) +{ + for(auto* sensor : sensors){ + sensor->setColor(color); + } +} + +//============================================================================================================= + +void fl_chassis::setColor(const QColor& color, bool blinking) +{ + for(auto* sensor : sensors){ + sensor->setColor(color); + sensor->setBlink(blinking); + } +} + +//============================================================================================================= + +void fl_chassis::setBlinkState(int sensor_num, bool blinking) +{ + if(sensor_num > sensors.size() || sensor_num < 1){ + return; + } + sensors.at(sensor_num - 1)->setBlink(blinking); +} + +//============================================================================================================= + +void fl_chassis::setBlinkState(bool blinking) +{ + for(auto* sensor : sensors){ + sensor->setBlink(blinking); + } +} diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index feb2ad5d1cd..99b368ceb02 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -63,8 +63,8 @@ //============================================================================================================= namespace Ui { -class fl_rack; -class fl_chassis; + class fl_rack; + class fl_chassis; } //============================================================================================================= @@ -82,25 +82,26 @@ class FieldlineView : public QWidget Q_OBJECT public: + explicit FieldlineView(QWidget *parent = nullptr); FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); FieldlineView(int num_chassis, QWidget *parent = nullptr); - explicit FieldlineView(QWidget *parent = nullptr); - ~FieldlineView(); void configure(int num_chassis); void configure(int num_chassis, int num_sensors); - void setColor(int chassis_id, int sensnor_num, QColor color); - void setColor(int chassis_id, int sensnor_num, QColor color, bool blinking); + void clear(); - void setChassisColor(int chassis_id, QColor color); - void setChassisColor(int chassis_id, QColor color, bool blinking); + void setColor(int chassis_id, int sensor_num, const QColor& color); + void setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking); - void setAllColor(QColor color); - void setAllColor(QColor color, bool blinking); + void setChassisColor(int chassis_id, const QColor& color); + void setChassisColor(int chassis_id, const QColor& color, bool blinking); - void setBlinkState(int chassis_id, int sensnor_num, bool blinking); + void setAllColor(const QColor& color); + void setAllColor(const QColor &color, bool blinking); + + void setBlinkState(int chassis_id, int sensor_num, bool blinking); void setChassisBlinkState(int chassis_id, bool blinking); void setAllBlinkState(bool blinking); @@ -108,23 +109,30 @@ class FieldlineView : public QWidget private: static int default_num_sensors; - std::unique_ptr ui; - - std::vector> chassis; + Ui::fl_rack* ui; + std::vector chassis; }; //============================================================================================================= + class fl_chassis : public QWidget { Q_OBJECT public: - explicit fl_chassis(QWidget *parent = nullptr); + fl_chassis(int num_sensors, QWidget *parent = nullptr); ~fl_chassis(); + void setColor(int sensor_num, const QColor& color); + void setColor(int sensor_num, const QColor& color, bool blinking); + void setColor(const QColor& color); + void setColor(const QColor& color, bool blinking); + + void setBlinkState(int sensor_num, bool blinking); + void setBlinkState(bool blinking); private: - Ui::fl_chassis *ui; - std::vector> sensors; + Ui::fl_chassis* ui; + std::vector sensors; }; From 6cf74bd9c340e31b734c86416a2cfd8e29c6cb44 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 24 Feb 2023 09:53:43 -0500 Subject: [PATCH 052/147] Change indexing type to unsigned size_t --- src/libraries/disp/viewers/fieldlineview.cpp | 30 ++++++++++---------- src/libraries/disp/viewers/fieldlineview.h | 18 ++++++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index 4de1397226c..e3be5510d8e 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -125,9 +125,9 @@ void FieldlineView::clear() //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color) +void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(sensor_num, color); @@ -135,9 +135,9 @@ void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color //============================================================================================================= -void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking) +void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(sensor_num, color, blinking); @@ -145,9 +145,9 @@ void FieldlineView::setColor(int chassis_id, int sensor_num, const QColor& color //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, const QColor& color) +void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(color); @@ -155,9 +155,9 @@ void FieldlineView::setChassisColor(int chassis_id, const QColor& color) //============================================================================================================= -void FieldlineView::setChassisColor(int chassis_id, const QColor& color, bool blinking) +void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setColor(color, blinking); @@ -183,9 +183,9 @@ void FieldlineView::setAllColor(const QColor& color, bool blinking) //============================================================================================================= -void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) +void FieldlineView::setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); @@ -193,9 +193,9 @@ void FieldlineView::setBlinkState(int chassis_id, int sensor_num, bool blinking) //============================================================================================================= -void FieldlineView::setChassisBlinkState(int chassis_id, bool blinking) +void FieldlineView::setChassisBlinkState(size_t chassis_id, bool blinking) { - if(chassis_id >= chassis.size() || chassis_id < 0){ + if(chassis_id >= chassis.size()){ return; } chassis.at(chassis_id)->setBlinkState(blinking); @@ -241,7 +241,7 @@ fl_chassis::~fl_chassis() //============================================================================================================= -void fl_chassis::setColor(int sensor_num, const QColor& color) +void fl_chassis::setColor(size_t sensor_num, const QColor& color) { if(sensor_num > sensors.size() || sensor_num < 1){ return; @@ -251,7 +251,7 @@ void fl_chassis::setColor(int sensor_num, const QColor& color) //============================================================================================================= -void fl_chassis::setColor(int sensor_num, const QColor& color, bool blinking) +void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) { setColor(sensor_num, color); setBlinkState(sensor_num, blinking); @@ -278,7 +278,7 @@ void fl_chassis::setColor(const QColor& color, bool blinking) //============================================================================================================= -void fl_chassis::setBlinkState(int sensor_num, bool blinking) +void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) { if(sensor_num > sensors.size() || sensor_num < 1){ return; diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index 99b368ceb02..e268dbfc4d9 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -92,17 +92,17 @@ class FieldlineView : public QWidget void clear(); - void setColor(int chassis_id, int sensor_num, const QColor& color); - void setColor(int chassis_id, int sensor_num, const QColor& color, bool blinking); + void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); + void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); - void setChassisColor(int chassis_id, const QColor& color); - void setChassisColor(int chassis_id, const QColor& color, bool blinking); + void setChassisColor(size_t chassis_id, const QColor& color); + void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); void setAllColor(const QColor& color); void setAllColor(const QColor &color, bool blinking); - void setBlinkState(int chassis_id, int sensor_num, bool blinking); - void setChassisBlinkState(int chassis_id, bool blinking); + void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); + void setChassisBlinkState(size_t chassis_id, bool blinking); void setAllBlinkState(bool blinking); static void setDefaultNumSensors(int num_sensors); @@ -123,12 +123,12 @@ class fl_chassis : public QWidget fl_chassis(int num_sensors, QWidget *parent = nullptr); ~fl_chassis(); - void setColor(int sensor_num, const QColor& color); - void setColor(int sensor_num, const QColor& color, bool blinking); + void setColor(size_t sensor_num, const QColor& color); + void setColor(size_t sensor_num, const QColor& color, bool blinking); void setColor(const QColor& color); void setColor(const QColor& color, bool blinking); - void setBlinkState(int sensor_num, bool blinking); + void setBlinkState(size_t sensor_num, bool blinking); void setBlinkState(bool blinking); private: Ui::fl_chassis* ui; From 7a2dd619cea5b0e6cc56e7d1b7e55456724d7962 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 10:37:57 -0500 Subject: [PATCH 053/147] remove unnecessary PRIVATE in cmakelists file --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 5e758c7c5da..f3e0e567d33 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -72,7 +72,8 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC ../) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent @@ -91,13 +92,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core scShared scMeas ${FFTW_LIBS} -# PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - ) + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) - + target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" From 6176f36b127ae9b2025755b3704cab26030968be Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 15:34:33 -0500 Subject: [PATCH 054/147] add folder for dependencies --- src/applications/mne_scan/plugins/fieldline/fieldline.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index eb77827d089..9f3cb022cc4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -36,9 +36,9 @@ #ifndef FIELDLINE_H #define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= -#include "fieldline_global.h" -#include "fieldline_acq_system_controller.h" -#include "fieldline_plugin_gui.h" +#include "fieldline/fieldline_global.h" +#include "fieldline/fieldline_acq_system_controller.h" +#include "fieldline/fieldline_plugin_gui.h" #include // #include From 5fd86a373bd24b4fa13ca0cda80897d45fdeea5a Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 23 Feb 2023 15:34:57 -0500 Subject: [PATCH 055/147] minor edit cmakelists.txt --- src/applications/mne_scan/plugins/fieldline/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index f3e0e567d33..563e6bc354b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -19,8 +19,6 @@ execute_process(COMMAND OUTPUT_VARIABLE Python_FLAGS ) - - set(SOURCES fieldline_global.cpp fieldline.cpp From 7d4791697469898f45b6a2ef034119316f1c0daf Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Mon, 27 Feb 2023 14:06:30 -0500 Subject: [PATCH 056/147] Trigger deletion of removed widgets --- src/libraries/disp/viewers/fieldlineview.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index e3be5510d8e..e8966924537 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -120,6 +120,7 @@ void FieldlineView::clear() { for(auto* c : chassis){ ui->frame->layout()->removeWidget(c); + c->deleteLater(); } }; From 154b9f3681ce7f3e9a20439fc869ca28ec25c1d9 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Tue, 28 Feb 2023 10:41:07 -0500 Subject: [PATCH 057/147] Trying out gui interaction --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 27 ++++++------- .../fieldline_acq_system_controller.cpp | 38 +++++++++---------- src/libraries/disp/viewers/fieldlineview.cpp | 28 ++++++++++++++ src/libraries/disp/viewers/fieldlineview.h | 7 ++++ src/libraries/disp/viewers/led_indicator.cpp | 4 ++ src/libraries/disp/viewers/led_indicator.h | 1 - 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 563e6bc354b..1630ea0f1ea 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,15 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -find_package(Python REQUIRED COMPONENTS Interpreter Development) -cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) - -set(PYTHON_COMPILE_FLAGS "--cflags") -execute_process(COMMAND - ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} - OUTPUT_VARIABLE Python_FLAGS -) - +# find_package(Python REQUIRED COMPONENTS Interpreter Development) +# cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) +# +# set(PYTHON_COMPILE_FLAGS "--cflags") +# execute_process(COMMAND +# ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} +# OUTPUT_VARIABLE Python_FLAGS +# ) +# set(SOURCES fieldline_global.cpp fieldline.cpp @@ -90,11 +90,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) + # python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) + ) -target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) -separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") -target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) +# target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) +# separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") +# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index dbebe2ca44d..276532a4d8c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" +// #include "Python.h" #include "fieldline_acq_system_controller.h" @@ -60,30 +60,26 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // - Py_Initialize(); - PyConfig config; - PyConfig_InitPythonConfig(&config); - config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, L"."); - Py_InitializeFromConfig(&config); - FILE* py_file = fopen("main.py", "r"); - PyObject* global_dict = PyDict_New(); - PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, - "main.py", - Py_file_input, - global_dict, - local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); - + // Py_Initialize(); + // PyConfig config; + // PyConfig_InitPythonConfig(&config); + // config.module_search_paths_set = 1; + // PyWideStringList_Append(&config.module_search_paths, L"."); + // Py_InitializeFromConfig(&config); + // FILE *py_file = fopen("main.py", "r"); + // PyObject *global_dict = PyDict_New(); + // PyObject *local_dict = PyDict_New(); + // PyObject *result = + // PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); + // Py_DECREF(global_dict); + // Py_DECREF(local_dict); + // Py_DECREF(result); + // fclose(py_file); } FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { -// Py_Finalize(); + // Py_Finalize(); } } diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/libraries/disp/viewers/fieldlineview.cpp index e8966924537..1964bb7e578 100644 --- a/src/libraries/disp/viewers/fieldlineview.cpp +++ b/src/libraries/disp/viewers/fieldlineview.cpp @@ -46,6 +46,10 @@ // QT INCLUDES //============================================================================================================= +#include +#include +#include + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -228,8 +232,11 @@ fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) for(int i = 0; i < num_sensors; ++i){ sensors.push_back(new LEDIndicator()); + auto& last_item = sensors.back(); sensors.back()->setLabel(QString::number(i + 1)); ui->sensor_frame->layout()->addWidget(sensors.back()); + connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); + connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); } } @@ -295,3 +302,24 @@ void fl_chassis::setBlinkState(bool blinking) sensor->setBlink(blinking); } } + +//============================================================================================================= + +void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) +{ +// auto* menu = new QMenu(); + +// auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); +// auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); + +// auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); +// auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); + +// connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); +// connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); + +// connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); +// connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); + +// menu->exec(pos); +} diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/libraries/disp/viewers/fieldlineview.h index e268dbfc4d9..2f9034f1941 100644 --- a/src/libraries/disp/viewers/fieldlineview.h +++ b/src/libraries/disp/viewers/fieldlineview.h @@ -130,6 +130,13 @@ class fl_chassis : public QWidget void setBlinkState(size_t sensor_num, bool blinking); void setBlinkState(bool blinking); + +signals: + void clicked(int sensor, const QPoint& pos); + +private slots: + void rightClickMenu(int sensor, const QPoint& pos); + private: Ui::fl_chassis* ui; std::vector sensors; diff --git a/src/libraries/disp/viewers/led_indicator.cpp b/src/libraries/disp/viewers/led_indicator.cpp index c9b235fdf0f..6228349a9d9 100644 --- a/src/libraries/disp/viewers/led_indicator.cpp +++ b/src/libraries/disp/viewers/led_indicator.cpp @@ -45,6 +45,8 @@ //============================================================================================================= #include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -85,6 +87,8 @@ LEDIndicator::LEDIndicator(const QString& label, const QColor& led_color, QWidge ui->graphicsView->setScene(m_pScene.get()); circle_led = m_pScene->addEllipse(0,0,this->width()/3,this->width()/3, QPen(Qt::black), on_brush); + + this->setContextMenuPolicy(Qt::CustomContextMenu); } //============================================================================================================= diff --git a/src/libraries/disp/viewers/led_indicator.h b/src/libraries/disp/viewers/led_indicator.h index 59fc4d9de0f..391da06ad69 100644 --- a/src/libraries/disp/viewers/led_indicator.h +++ b/src/libraries/disp/viewers/led_indicator.h @@ -101,7 +101,6 @@ class LEDIndicator : public QWidget QTimer blink_timer; bool blink_state; - static QColor default_color; static QString default_label; From d68293a2f5d91f052d01032b64179ad3603c59ee Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 1 Mar 2023 15:01:27 -0500 Subject: [PATCH 058/147] create random data from fieldline --- .gitignore | 2 +- .../mne_scan/plugins/fieldline/CMakeLists.txt | 2 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 70 +++++++++++++++---- .../mne_scan/plugins/fieldline/fieldline.h | 23 +++--- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index f6fb124c5f0..a6c5b7ea068 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ compile_commands.json # Generated docu Docker files /_site -build-*/* +build*/* .cache/* diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 1630ea0f1ea..0b267c16646 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -78,7 +78,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE eigen mne_disp mne_utils - # mne_fiff + mne_fiff # mne_fs # mne_mne # mne_fwd diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index fa115f113d0..d2a75ddc9f4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -48,8 +48,7 @@ // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" -// #include -// #include +#include //============================================================================================================= // QT INCLUDES @@ -102,8 +101,15 @@ QSharedPointer Fieldline::clone() const { void Fieldline::init() { - // m_outputConnectors.append(m_pRMTSA_Natus); - qDebug() << "Init Fieldline"; + // we instantiante + m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData::create( + this, + "Fieldline Plugin", + "FieldlinePlguin output"); + + m_outputConnectors.append(m_pRTMSA_Fieldline); + + qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; acqSystem = std::make_unique(); } @@ -133,7 +139,7 @@ bool Fieldline::start() { // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); // - // QThread::start(); + QThread::start(); // // // Start the producer // m_pNatusProducer = @@ -149,12 +155,12 @@ bool Fieldline::start() { //============================================================================================================= bool Fieldline::stop() { - - // requestInterruption(); - // wait(500); + requestInterruption(); + wait(500); + // m_pRMTSA_Natus->measurementData()->clear(); + // // // // Clear all data in the buffer connected to displays and other plugins - // m_pRMTSA_Natus->measurementData()->clear(); // m_pCircularBuffer->clear(); // // m_pProducerThread.quit(); @@ -174,7 +180,7 @@ SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { //============================================================================================================= QString Fieldline::getName() const { - qDebug() << "getName Fieldline"; + // qDebug() << "getName Fieldline"; return QString("Fieldline OPM"); } @@ -221,16 +227,52 @@ QWidget *Fieldline::setupWidget() { void Fieldline::run() { qDebug() << "run Fieldline"; - // MatrixXd matData; - // - // while(!isInterruptionRequested()) { - // if(m_pCircularBuffer->pop(matData)) { + + m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); + + m_pFiffInfo->sfreq = 1000.0f; + m_pFiffInfo->nchan = 32; + m_pFiffInfo->chs.clear(); + + for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { + FIFFLIB::FiffChInfo channel; + channel.ch_name = "Ch. " + QString::number(chan_i); + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + m_pFiffInfo->chs.append(channel); + m_pFiffInfo->ch_names.append(channel.ch_name); + } + + m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo(m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); + m_pRTMSA_Fieldline->measurementData()->setVisibility(true); + + Eigen::MatrixXd matData; + matData.resize(m_pFiffInfo->nchan, 200); + // matData.setZero(); + + for(;;) { + //gather the data + + matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + matData *= 4e-12; + + msleep(200); + + if (isInterruptionRequested()) + break; + m_pRTMSA_Fieldline->measurementData()->setValue(matData); + } + // //emit values // if(!isInterruptionRequested()) { // m_pRMTSA_Natus->measurementData()->setValue(matData); // } // } // } + qDebug() << "run Fieldline finished"; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 9f3cb022cc4..b076e2ce980 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -40,6 +40,9 @@ #include "fieldline/fieldline_acq_system_controller.h" #include "fieldline/fieldline_plugin_gui.h" +#include +#include + #include // #include #include @@ -49,6 +52,7 @@ //============================================================================================================= #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -60,13 +64,13 @@ // FORWARD DECLARATION //============================================================================================================= -// namespace SCMEASLIB { -// class RealTimeMultiSampleArray; -// } -// u -// namespace FIFFLIB { -// class FiffInfo; -// } +namespace SCMEASLIB { +class RealTimeMultiSampleArray; +} + +namespace FIFFLIB { +class FiffInfo; +} //============================================================================================================= // DEFINE NAMESPACE FIELDLINEPLUGIN @@ -181,9 +185,8 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ // - // QSharedPointer > m_pRMTSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ - // QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ -}; + QSharedPointer > m_pRTMSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN From f0479c1c9272118aa366ee6a23a8752d26e2ae06 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 2 Mar 2023 18:46:36 -0500 Subject: [PATCH 059/147] [FIX] Seg fault when calling qDebug in destructor --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 1 - src/applications/mne_scan/plugins/fieldline/fieldline.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index d2a75ddc9f4..6f3c8194f4a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -86,7 +86,6 @@ Fieldline::~Fieldline() { // if(this->isRunning()) { // this->stop(); // } - qDebug() << "Destroying Fieldline object"; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index b076e2ce980..12012882d48 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -110,7 +110,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { /** * Destroys the Fieldline. */ - virtual ~Fieldline(); + ~Fieldline(); //========================================================================================================= /** From c1c5ba3563fb413fe7aab57f161121c0afb7394e Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Thu, 2 Mar 2023 11:17:40 -0500 Subject: [PATCH 060/147] Add functions for creating fiffinfo based on filedline chassis parameters --- .../mne_scan/plugins/fieldline/fieldline.cpp | 101 +++++++++++++----- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 6f3c8194f4a..42dd0dd8bbd 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -56,10 +56,12 @@ // #include #include -#include -#include #include +#include #include +#include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -71,13 +73,69 @@ namespace FIELDLINEPLUGIN { +//============================================================================================================= + +// QSharedPointer createFiffInfo(int numChassis, +// int numChannels) { +// QSharedPointer pFiffInfo; +// pFiffInfo->sfreq = 1000.0f; +// pFiffInfo->nchan = numChassis * numChannels; +// pFiffInfo->chs.clear(); +// +// for (int chan_i = 0; chan_i < pFiffInfo->nchan; ++chan_i) { +// FIFFLIB::FiffChInfo channel; +// channel.ch_name = QString("%1:%2").arg(numChannels, 2).arg(chan_i, 2); +// channel.kind = FIFFV_MEG_CH; +// channel.unit = FIFF_UNIT_T; +// channel.unit_mul = FIFF_UNITM_NONE; +// channel.chpos.coil_type = FIFFV_COIL_NONE; +// pFiffInfo->chs.append(channel); +// pFiffInfo->ch_names.append(channel.ch_name); +// } +// } + +QSharedPointer +createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { + QSharedPointer pFiffInfo; + pFiffInfo->sfreq = sfreq; + pFiffInfo->chs.clear(); + + int total_channels = 0; + int chassis_num = 0; + for (auto &chassis : fl_chassis) { + for (auto &sensor : chassis) { + FIFFLIB::FiffChInfo channel; + channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + pFiffInfo->chs.append(channel); + pFiffInfo->ch_names.append(channel.ch_name); + ++total_channels; + } + } + pFiffInfo->nchan = total_channels; + + return pFiffInfo; +} + +QSharedPointer +createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { + std::vector> fl; + for (int i = 0; i < numChassis; ++i) { + std::vector ch(numChannels); + std::iota(ch.begin(), ch.end(), 1); + fl.push_back(std::move(ch)); + } + return createFiffInfo(fl, sfreq); +} + //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { - qDebug() << "Creating Fieldline object"; -} +Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } //============================================================================================================= @@ -100,12 +158,11 @@ QSharedPointer Fieldline::clone() const { void Fieldline::init() { - // we instantiante - m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData::create( - this, - "Fieldline Plugin", - "FieldlinePlguin output"); - + // we instantiante + m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< + SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Plugin", + "FieldlinePlguin output"); + m_outputConnectors.append(m_pRTMSA_Fieldline); qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; @@ -114,9 +171,7 @@ void Fieldline::init() { //============================================================================================================= -void Fieldline::unload() { - qDebug() << "unload Fieldline"; -} +void Fieldline::unload() { qDebug() << "unload Fieldline"; } //============================================================================================================= @@ -195,13 +250,10 @@ QWidget *Fieldline::setupWidget() { // init properties dialog // widget->initGui(); - - - - auto* frame = new QWidget(); + auto *frame = new QWidget(); frame->setLayout(new QHBoxLayout()); - auto* flWidget = new DISPLIB::FieldlineView(2, 16); + auto *flWidget = new DISPLIB::FieldlineView(2, 16); frame->layout()->addWidget(flWidget); flWidget->setBlinkState(0, 2, true); @@ -244,7 +296,8 @@ void Fieldline::run() { m_pFiffInfo->ch_names.append(channel.ch_name); } - m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo(m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( + m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); m_pRTMSA_Fieldline->measurementData()->setVisibility(true); @@ -252,19 +305,19 @@ void Fieldline::run() { matData.resize(m_pFiffInfo->nchan, 200); // matData.setZero(); - for(;;) { - //gather the data + for (;;) { + // gather the data matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); matData *= 4e-12; msleep(200); - if (isInterruptionRequested()) + if (isInterruptionRequested()) break; m_pRTMSA_Fieldline->measurementData()->setValue(matData); } - + // //emit values // if(!isInterruptionRequested()) { // m_pRMTSA_Natus->measurementData()->setValue(matData); From 0745963867eac899712f98feb83c4a8ad2ab9dc5 Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Fri, 3 Mar 2023 11:31:37 -0500 Subject: [PATCH 061/147] Add callback functions to be called by python --- .../fieldline_acq_system_controller.cpp | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index 276532a4d8c..a6c6467a801 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -45,8 +45,68 @@ #include "fieldline_acq_system_controller.h" -namespace FIELDLINEPLUGIN { +#include +#include + +extern "C" { + +PyObject *restartFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - restart finished;\n"; + } else { + std::cout << "A sensor has finished restarting!\n"; + } + + return NULL; +} +PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - coarse zero finished;\n"; + } else { + std::cout << "A sensor has finished coarse zeroing!\n"; + } + + return NULL; +} +PyObject *fineZeroFinished(PyObject *self, PyObject *args) { + long chassis, sensor; + if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor + << " - fine zero finished;\n"; + } else { + std::cout << "A sensor has finished fine zeroing!\n"; + } + return NULL; +} +} + +static PyMethodDef my_module_methods[] = { + {"restartFinished", restartFinished, METH_VARARGS, " "}, + {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, + {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, + {NULL, NULL, 0, NULL}}; + +static PyModuleDef my_module_def = { + PyModuleDef_HEAD_INIT, + "mne_cpp_callbacks", + "A module of callback functions for mne-cpp.", + -1, + my_module_methods, + NULL, + NULL, + NULL, + NULL}; + +PyMODINIT_FUNC PyInit_my_module(void) { + return PyModule_Create(&my_module_def); +} + +namespace FIELDLINEPLUGIN { FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // pythonInterpreter initiate From 32934ac2bd969802326da93c72e3d901ed45dc39 Mon Sep 17 00:00:00 2001 From: juangpc Date: Wed, 8 Mar 2023 00:09:49 -0500 Subject: [PATCH 062/147] adapting cmakelists to martinos setup --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 141 +++++++++++++----- .../fieldline_acq_system_controller.cpp | 2 +- 2 files changed, 108 insertions(+), 35 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 0b267c16646..dcdfdf3150e 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -10,15 +10,84 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) -# find_package(Python REQUIRED COMPONENTS Interpreter Development) -# cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) +find_package(Python REQUIRED COMPONENTS Interpreter Development) +cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) + +#if(AWK MATCHES ".+-NOTFOUND") +# message(FATAL_ERROR "FATAL: awk (and mawk and gawk) could not be found (${AWK}).") +#else() +# execute_process( +# COMMAND /bin/sh -c "\"${AWK}\" '$1 ~ /^#define/ && $2 ~ /^LIB_(MAJVER|MINVER|PATCH|BUILD)$/\ { print \"set(\${PRJNAME}_\" $2 \" \" $3 \")\" }' \"${CMAKE_SOURCE_DIR}/version.h\"" +# RESULT_VARIABLE AWK_EXITCODE +# OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/version.cmake" +# ) +# message(STATUS "Exit code from awk: ${AWK_EXITCODE}") +# include(${CMAKE_CURRENT_BINARY_DIR}/version.cmake) +#endif() + +#set(Python_EXECUTABLE /autofs/cluster/fusion/juan/anaconda3/bin/python) +#cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) +#if (WIN32) +# execute_process(COMMAND CMD /c echo bar OUTPUT_VARIABLE FOO) +#else() +# message("holaaaaaaa") +# execute_process( +# COMMAND "python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor)'" +# OUTPUT_VARIABLE Python_version) +#endif (WIN32) +#message("Python executable: " ${Python_EXECUTABLE}) +#message("Python_version: " ${Python_version}) +# +# execute_process( +# COMMAND /bin/sh -c "\"${AWK}\" '$1 ~ /^#define/ && $2 ~ /^LIB_(MAJVER|MINVER|PATCH|BUILD)$/\ { print \"set(\${PRJNAME}_\" $2 \" \" $3 \")\" }' \"${CMAKE_SOURCE_DIR}/version.h\"" +# RESULT_VARIABLE AWK_EXITCODE +# OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/version.cmake" +# ) # -# set(PYTHON_COMPILE_FLAGS "--cflags") -# execute_process(COMMAND -# ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${PYTHON_COMPILE_FLAGS} -# OUTPUT_VARIABLE Python_FLAGS -# ) + +#execute_process( +# "echo $(dirname $(which python))" +# WORKING_DIRECTORY . +# OUTPUT_VARIABLE Python_BIN_DIR +#) + +#execute_process(COMMAND +# /usr/bin/zsh -c " python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major)'" +# OUTPUT_VARIABLE Python_VERSION_MAJOR +#) +#execute_process(COMMAND +# /usr/bin/zsh -c "python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor)'" +# OUTPUT_VARIABLE Python_VERSION_MINOR +#) # +#set(Python_EXECUTABLE ${Python_BIN_DIR}/python) +#execute_process(COMMAND +# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes" +# OUTPUT_VARIABLE Python_INCLUDE_DIRS +#) +#execute_process(COMMAND +# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags" +# OUTPUT_VARIABLE Python_CFLAGS +#) +#execute_process(COMMAND +# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs" +# OUTPUT_VARIABLE Python_LIBS +#) +#execute_process(COMMAND +# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --ldflags" +# OUTPUT_VARIABLE Python_LDFLAGS +#) + +message("python bin dir: " ${Python_BIN_DIR}) +message("python executable: " ${Python_EXECUTABLE}) +message("python version major: " ${Python_VERSION_MAJOR}) +message("python version minor: " ${Python_VERSION_MINOR}) +message("python include dirs: " ${Python_INCLUDE_DIRS}) +message("python cflags: " ${Python_CFLAGS}) +message("python cflags norm: " ${Python_CFLAGS_NORM}) +message("python libraries: " ${Python_LIBS}) +message("python lib flags: " ${Python_LDFLAGS}) + set(SOURCES fieldline_global.cpp fieldline.cpp @@ -41,7 +110,7 @@ else() # message("File fieldline.json does not exist.") # message("Creating a new fieldline.json file.") execute_process(COMMAND "echo \"\"" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_C OUTPUT_FILE fieldline.json) endif() @@ -68,41 +137,45 @@ if(USE_FFTW) endif() endif() -target_include_directories(${PROJECT_NAME} PUBLIC ../) +target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Network - Qt${QT_VERSION_MAJOR}::Concurrent - eigen - mne_disp - mne_utils - mne_fiff - # mne_fs - # mne_mne - # mne_fwd - # mne_inverse - # mne_rtprocessing - # mne_connectivity - # mne_events - scDisp - scShared - scMeas - ${FFTW_LIBS} - # python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}) - ) - -# target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIBRARY_DIRS}) -# separate_arguments(Python_FLAGS_NORM UNIX_COMMAND "${Python_FLAGS}") -# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_FLAGS_NORM}) + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + # mne_fs + # mne_mne + # mne_fwd + # mne_inverse + # mne_rtprocessing + # mne_connectivity + # mne_events + scDisp + scShared + scMeas + ${FFTW_LIBS} + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + ${Python_LIBS} +) + +target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS}) +separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") +target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) + target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" ) + if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) endif() + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index a6c6467a801..a086708927d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -41,7 +41,7 @@ #define PY_SSIZE_T_CLEAN -// #include "Python.h" +#include "Python.h" #include "fieldline_acq_system_controller.h" From 9ef573fbc7f1af31729fb5ef8dd6f644752ce315 Mon Sep 17 00:00:00 2001 From: juangpc Date: Wed, 8 Mar 2023 01:33:38 -0500 Subject: [PATCH 063/147] fieldline python setup within cmake working --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 98 +++++++----- .../fieldline_acq_system_controller.cpp | 144 +++++++++--------- 2 files changed, 129 insertions(+), 113 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index dcdfdf3150e..5e4d75542e4 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -11,7 +11,7 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Python REQUIRED COMPONENTS Interpreter Development) -cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) +#cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) #if(AWK MATCHES ".+-NOTFOUND") # message(FATAL_ERROR "FATAL: awk (and mawk and gawk) could not be found (${AWK}).") @@ -45,48 +45,65 @@ cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) # ) # +set(ANACONDA_DIR /autofs/cluster/fusion/juan/anaconda3) +set(Python_BIN_DIR ${ANACONDA_DIR}/bin) +set(Python_LIB_DIR ${ANACONDA_DIR}/lib) +set(Python_EXECUTABLE ${Python_BIN_DIR}/python) + #execute_process( -# "echo $(dirname $(which python))" +# COMMAND "echo $(dirname $(which ${ANACONDA_DIR}/bin/python))" # WORKING_DIRECTORY . # OUTPUT_VARIABLE Python_BIN_DIR #) -#execute_process(COMMAND -# /usr/bin/zsh -c " python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major)'" -# OUTPUT_VARIABLE Python_VERSION_MAJOR -#) -#execute_process(COMMAND -# /usr/bin/zsh -c "python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor)'" -# OUTPUT_VARIABLE Python_VERSION_MINOR -#) -# -#set(Python_EXECUTABLE ${Python_BIN_DIR}/python) -#execute_process(COMMAND -# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes" -# OUTPUT_VARIABLE Python_INCLUDE_DIRS -#) -#execute_process(COMMAND -# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags" -# OUTPUT_VARIABLE Python_CFLAGS -#) -#execute_process(COMMAND -# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs" -# OUTPUT_VARIABLE Python_LIBS -#) -#execute_process(COMMAND -# bash -c "${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --ldflags" -# OUTPUT_VARIABLE Python_LDFLAGS -#) +execute_process( + COMMAND ${Python_BIN_DIR}/python -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" + OUTPUT_VARIABLE Python_VERSION_MAJOR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(minor)" + OUTPUT_VARIABLE Python_VERSION_MINOR + OUTPUT_STRIP_TRAILING_WHITESPACE +) -message("python bin dir: " ${Python_BIN_DIR}) -message("python executable: " ${Python_EXECUTABLE}) -message("python version major: " ${Python_VERSION_MAJOR}) -message("python version minor: " ${Python_VERSION_MINOR}) -message("python include dirs: " ${Python_INCLUDE_DIRS}) -message("python cflags: " ${Python_CFLAGS}) -message("python cflags norm: " ${Python_CFLAGS_NORM}) -message("python libraries: " ${Python_LIBS}) -message("python lib flags: " ${Python_LDFLAGS}) +execute_process( + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes + OUTPUT_VARIABLE Python_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags + OUTPUT_VARIABLE Python_CFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") + +execute_process( + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs + OUTPUT_VARIABLE Python_LIBS + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --ldflags + OUTPUT_VARIABLE Python_LDFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") + +message( "python bin dir: " ${Python_BIN_DIR}) +message( "python lib dir: " ${Python_LIB_DIR}) +message( "python executable: " ${Python_EXECUTABLE}) +message( "python version major: " ${Python_VERSION_MAJOR}) +message( "python version minor: " ${Python_VERSION_MINOR}) +message( "python include dirs: " ${Python_INCLUDE_DIRS}) +message( "python cflags: " ${Python_CFLAGS}) +message( "python cflags norm: " ${Python_CFLAGS_NORM}) +message( "python libraries: " ${Python_LIBS}) +message( "python lib flags: " ${Python_LDFLAGS}) +message("python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp @@ -118,7 +135,7 @@ set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") - +link_directories(${Python_LDFLAGS_NORM}) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) set(FFTW_LIBS "") @@ -159,11 +176,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - ${Python_LIBS} + ${Python_LIB_DIR}/libpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}.so + ${Python_LDFlags_NORM} ) -target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS}) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp index a086708927d..1c537d25f72 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp @@ -48,63 +48,63 @@ #include #include -extern "C" { - -PyObject *restartFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - restart finished;\n"; - } else { - std::cout << "A sensor has finished restarting!\n"; - } - - return NULL; -} -PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - coarse zero finished;\n"; - } else { - std::cout << "A sensor has finished coarse zeroing!\n"; - } - - return NULL; -} -PyObject *fineZeroFinished(PyObject *self, PyObject *args) { - long chassis, sensor; - if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { - std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor - << " - fine zero finished;\n"; - } else { - std::cout << "A sensor has finished fine zeroing!\n"; - } - - return NULL; -} -} - -static PyMethodDef my_module_methods[] = { - {"restartFinished", restartFinished, METH_VARARGS, " "}, - {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, - {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, - {NULL, NULL, 0, NULL}}; - -static PyModuleDef my_module_def = { - PyModuleDef_HEAD_INIT, - "mne_cpp_callbacks", - "A module of callback functions for mne-cpp.", - -1, - my_module_methods, - NULL, - NULL, - NULL, - NULL}; - -PyMODINIT_FUNC PyInit_my_module(void) { - return PyModule_Create(&my_module_def); -} +//extern "C" { +// +//PyObject *restartFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - restart finished;\n"; +// } else { +// std::cout << "A sensor has finished restarting!\n"; +// } +// +// return NULL; +//} +//PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - coarse zero finished;\n"; +// } else { +// std::cout << "A sensor has finished coarse zeroing!\n"; +// } +// +// return NULL; +//} +//PyObject *fineZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - fine zero finished;\n"; +// } else { +// std::cout << "A sensor has finished fine zeroing!\n"; +// } +// +// return NULL; +//} +//} +// +//static PyMethodDef my_module_methods[] = { +// {"restartFinished", restartFinished, METH_VARARGS, " "}, +// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, +// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, +// {NULL, NULL, 0, NULL}}; +// +//static PyModuleDef my_module_def = { +// PyModuleDef_HEAD_INIT, +// "mne_cpp_callbacks", +// "A module of callback functions for mne-cpp.", +// -1, +// my_module_methods, +// NULL, +// NULL, +// NULL, +// NULL}; +// +//PyMODINIT_FUNC PyInit_my_module(void) { +// return PyModule_Create(&my_module_def); +//} namespace FIELDLINEPLUGIN { FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { @@ -120,21 +120,21 @@ FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { // initialize channels // // - // Py_Initialize(); - // PyConfig config; - // PyConfig_InitPythonConfig(&config); - // config.module_search_paths_set = 1; - // PyWideStringList_Append(&config.module_search_paths, L"."); - // Py_InitializeFromConfig(&config); - // FILE *py_file = fopen("main.py", "r"); - // PyObject *global_dict = PyDict_New(); - // PyObject *local_dict = PyDict_New(); - // PyObject *result = - // PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); - // Py_DECREF(global_dict); - // Py_DECREF(local_dict); - // Py_DECREF(result); - // fclose(py_file); + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + FILE *py_file = fopen("main.py", "r"); + PyObject *global_dict = PyDict_New(); + PyObject *local_dict = PyDict_New(); + PyObject *result = + PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); } From 33b2cb59a329b43a7f267a273e5d5196098fa9ef Mon Sep 17 00:00:00 2001 From: juangpc Date: Wed, 8 Mar 2023 16:17:05 -0500 Subject: [PATCH 064/147] fine tune dependencies regarding python --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 5e4d75542e4..9d520e67fe2 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -134,8 +134,9 @@ endif() set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES - OBJECT_DEPENDS "${SOURCE_PATHS}") -link_directories(${Python_LDFLAGS_NORM}) + OBJECT_DEPENDS "${SOURCE_PATHS}" +) + add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) set(FFTW_LIBS "") @@ -156,6 +157,8 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) +target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) + target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets @@ -176,13 +179,12 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - ${Python_LIB_DIR}/libpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}.so - ${Python_LDFlags_NORM} + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) - +add_link_options(${Python_LDFLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" From 1ee62561eb388a809868d284e85ceec47e547205 Mon Sep 17 00:00:00 2001 From: juangpc Date: Thu, 9 Mar 2023 11:05:24 -0500 Subject: [PATCH 065/147] plugin destructor checks for thread running --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 42dd0dd8bbd..e24a96a52ec 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -140,10 +140,10 @@ Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } //============================================================================================================= Fieldline::~Fieldline() { - // If the program is closed while the sampling is in process - // if(this->isRunning()) { - // this->stop(); - // } + //If the program is closed while the sampling is in process + if(this->isRunning()) { + this->stop(); + } } //============================================================================================================= From a8ef9c0ca1f4a7a5580c7545766105673ea48876 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 28 Mar 2023 17:29:10 -0400 Subject: [PATCH 066/147] move fieldline_view to fieldline folder --- .gitignore | 1 + .../mne_scan/plugins/fieldline/CMakeLists.txt | 12 ++---------- .../mne_scan/plugins/fieldline/fieldline.h | 6 +++++- .../mne_scan/plugins/fieldline}/fieldlineview.cpp | 0 .../mne_scan/plugins/fieldline}/fieldlineview.h | 0 5 files changed, 8 insertions(+), 11 deletions(-) rename src/{libraries/disp/viewers => applications/mne_scan/plugins/fieldline}/fieldlineview.cpp (100%) rename src/{libraries/disp/viewers => applications/mne_scan/plugins/fieldline}/fieldlineview.h (100%) diff --git a/.gitignore b/.gitignore index a6c5b7ea068..5cdd62c477a 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ compile_commands.json /_site build*/* +/resources/data* .cache/* diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 9d520e67fe2..2e184e91c01 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -44,8 +44,8 @@ find_package(Python REQUIRED COMPONENTS Interpreter Development) # OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/version.cmake" # ) # - -set(ANACONDA_DIR /autofs/cluster/fusion/juan/anaconda3) +set(ANACONDA_DIR /opt/anaconda3) +# set(ANACONDA_DIR /autofs/cluster/fusion/juan/anaconda3) set(Python_BIN_DIR ${ANACONDA_DIR}/bin) set(Python_LIB_DIR ${ANACONDA_DIR}/lib) set(Python_EXECUTABLE ${Python_BIN_DIR}/python) @@ -168,13 +168,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE mne_disp mne_utils mne_fiff - # mne_fs - # mne_mne - # mne_fwd - # mne_inverse - # mne_rtprocessing - # mne_connectivity - # mne_events scDisp scShared scMeas @@ -191,7 +184,6 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" ) - if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 12012882d48..f8ed44b4b77 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -34,7 +34,11 @@ */ #ifndef FIELDLINE_H -#define FIELDLINE_H //============================================================================================================= INCLUDES ============================================================================================================= +#define FIELDLINE_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= #include "fieldline/fieldline_global.h" #include "fieldline/fieldline_acq_system_controller.h" diff --git a/src/libraries/disp/viewers/fieldlineview.cpp b/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp similarity index 100% rename from src/libraries/disp/viewers/fieldlineview.cpp rename to src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp diff --git a/src/libraries/disp/viewers/fieldlineview.h b/src/applications/mne_scan/plugins/fieldline/fieldlineview.h similarity index 100% rename from src/libraries/disp/viewers/fieldlineview.h rename to src/applications/mne_scan/plugins/fieldline/fieldlineview.h From 71a21ef4d4ccb06285932a088d11339d11650cf2 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 28 Mar 2023 17:32:17 -0400 Subject: [PATCH 067/147] update gitignore --- .gitignore | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5cdd62c477a..0f9952f4e7e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,11 +18,6 @@ *.pdb *.qm -# Bin folder with exceptions -/lib/ -/bin/ -/out*/ - # External device SDKs (if installed) /applications/mne_scan/plugins/eegosports/eemagine/ /applications/mne_scan/plugins/gusbamp/gtec_gUSBamp.h @@ -47,7 +42,6 @@ *.so.debug *.debug -.session # Compiled Static libraries *.lai *.la @@ -67,13 +61,15 @@ Makefile mne-cpp.pro.user* compile_commands.json -# FFTW -/src/external/fftw - # Generated docu Docker files /_site -build*/* +# Binary data folders +/build* +/out* + +# Resources folders +/src/external/fftw /resources/data* .cache/* From 367000ad79585a611e66f4faad0e7fd7353e8997 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 28 Mar 2023 17:36:53 -0400 Subject: [PATCH 068/147] delete quickcontrol transitory png used --- .../mne_scan/images/icons/quickControl.png | Bin 16076 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/applications/mne_scan/mne_scan/images/icons/quickControl.png diff --git a/src/applications/mne_scan/mne_scan/images/icons/quickControl.png b/src/applications/mne_scan/mne_scan/images/icons/quickControl.png deleted file mode 100644 index a9ddae68d08bdd783f581eb6b9ef5a0ea5782c8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16076 zcmZvDbyQVb)GvsHG}4{Yf`o*W(%mVgfJt|EgLFx!lF~|t(jd|xh=g<>N*dnue&dbz z{qfEiT)Cbjd$ZSEbN*_DtE#n?8Twz#OMkSwgG>Gg`hz(}jg9q_lrWNS=uCh8xy{$Ry_6Bio4~oY4 zp4zQ`PvvX-o+<1|g2`a(fa4WJk>eHQn5sFk6XQ5`XxRYi;9YrKWGv!-e3gem{rvq)8W^SzOEHGm59jWXHV+) z^W~?ALX(P=W?1M7^(DfTx$P~(5SJGpe;1M0)=~NiUP+1{zO*fVdYnJvmlB_xO!BF+ z5`XdVY|37FEuT3Fg|_D)hDMCS+0jwz;NZaSC|SN9!8=e0&M)S0m!@2$tJ> zs-jDEKS^$FZrUBK3u`(%J3C$c-Emkj*KVLXB_l?)XmZ(+baZg|?_EktN~f*};{Ww- zczF09%c=6df*;H(X-t0+i1m8GUc(cL*glzUlkK@&c~w;s<7PJvW>=k8uU-*^c4(|q z4<5B>tiXj|Vv%wYX|fWf&cZV%W@cjYBbJ|g@cJ>X7q+5@5(Bz8?u$O5VyaUilGlsh zf*CM_84~2EiDYE%+_`g*kK28mh(ep6_g;B*c)I45M5p{5rNw$UAxl|$S{lu9_ky>z zvM_?D{AcZ(vD>n;vIusLnw^PKy?{tkZe9!B$K-dFalPI}?swoxgbfS~ym)GQet!N( zC0(Fzd4)1R&GVh|N7Cw^TEFKxznfg^B-{{>KMoBu%0*k9oSdX=RNO_=Il%~rCp6); z(C)uVDQHvljA@U!dVi@$(9_+W$MXe3T%ZWvCsCG@TU(8$7U?!_@gPPyzLEcF<x}W)ofA8Iz>F@8)sChLM-7d1)BO7B}N}K+2E_E*ihqAh~q{J#n z(ypav^3T%Jy~+ERNX;!RT|Z@|@ljDxrRC&UJeRto7_0uC>2ENZWZ>!BQ-5Vz>WPt9 z+1=eu%gl_bt&_sW_#)u6uAa2lcGF5sd3;g)clUQ`d}`|SyCn2XRXN#rWXM093T@_^ zg}1Enu_mu+2{Wlq_sRqUzdq2>&>-MVRW98aD>SXHs(La$J|6q4&bFfpm6YpUR8(+o zZf=nGt7mmFVPUU1*x0^WD~yheJVC>uxQ)!Wp33(sV{2)aSV3cs`7rxRi zhadFyneyn^Sbk%Dy%CR~pj={NB2z^5==iv@_x_)*WvxP00vB7Pg`u>EO0Sc0n7w@) zA?n52pm!@{Z|z4WrRVlf9@@Oe$O}X1g0^a!n(^FOjy|uJa3}?^**G`?eP3&6jQmOA zHl5seYfg|}+1k1iS6r~Pv{a)KaoNs@W0d^ zWo2bLR_ffb4QF9t;T~RI-snTO<`^#dtNdHy34P|mu}gE(5G$#svU1Ldij zppK4Cf$z~9?sD%y%Ir*FUR_`WM84VdC8GDJh1WD-8;Upv^y;bHt z!=-u^GhgcJPA<7)ix9>~7tj18oYsfA#l*yhR@c^)o~YcsoUSl!E8N-HxjH&Jx~Af_ z=ykvi9a~*owBH%vZgcu$Clrg4Q0sEMsS_;b`M2Qme5)b>Uc}j=?$u4r&9lL(g@W+v z2-e;l?C-}^QC7}~OGr3u8b{yqM?M!tz(Wv*yWvMi56y=wC71L&IXfq$r>6_U|B>8d zW@hi~?w%ncB9bO2C%>w7Sm__oq`t&C`~)>{pMwL7ivRU++6SeS)gRdsZN^$!2_MVK zE-iI*ChA5LpC~C|si>)CpIn|fK8L@m7^PC0Y4*H*O318?c=>>A8+N2TFN=k>HT9qM zb+Yo};&Awz*uHaa6ErlmaDIwU>&IJDlzI92#Z^^Ri$+|e;qTrhhV$9l+1b_m`y*F7 zZH!hXap*qn=o1#0Q>kPibkX$bp);`$4BleBWS(FyEWe0tFkp@T6|{tS+

lYQ)kh^Y(~L_i zZuPOGC;X6F8$7+MJvBctZr8Xh8I zVst}8!<)0|SJ@*_B{CHWC@}=p-aKl+aE677IJvF+L@w<=oGo`iHG|pik_MOih`}{#9ZQ z+V)3Dfwu4C>De?qHg?#uq-04@FnBVYEA`ark?|r-^p$5>os^Q(nO-w9GYjW_G@@?9 zbwx$%rXtQa*H@o^&(4~V!AA5aq-!P&>&onz@~e3Uzo4h2WWdtaRE4dRpm%Z;0^`^lcYe7P!UGh6?AL0wjtQpBZGM90L*k}+Zy+f!3(R@h|!_wP*BPUhz3%aflBuSvO0-nn-q z{@K`ItE{UlEGjM48XXbYmn$>A{!BGp z0Eg}VeVK**mw-2@wHTJ}TE2bT$R{Ku)ZWpt)IVOV)p9YTfwnZ`qL>^T`^@KfbK(lX znQB~I+=z^f%)CNB;dw{Q9U7caJlg2?dqVf_1wSwpLWT*OBXM(i=y!hZF&dMmiQL-I zaF)~F-hO#;vPYP8+C=?z1B*tJMl7CFgodgVHW>ctlhF;QY@JfwoqICv;{6r?7sa8F z+r}p+zZtX)ETJc};Zi>$^3RmGe;?<~n>SxaKPXX%h=@3CO@0bAZS^vsAmm;(6sK11HH}?4SGpM$o=cPgk3iPBZzOVPUg9Fw6%p2sssvVD$Oz#PjMi-*=Z^Y<_PV7#e!w(~xs;aCqvVdU$wz z8%!4@{GoGHjwnF#{r;XOm_x6eKdIA(qgeJUbwHnmlsuBtdHOob9H$jQjqV_{;REAb_NZVLZqkT|qPd$ANF z!Q|kxWs?zeyl3jQ-=%>T$V1A@ccdH0I0dMp-g2_+Yi8I~A0_K~xexmp>XD z*Tmz3Dhk^5u<`KPbWBWarY0vtl%jpE&grwg4itJCc(}RMlylW*y3DHXaxr7v+PG%N z#=$vO%@)t}IoUNvZ@yYN`pJ*9`UAQ{VMAl1svFE*R04!nu{Lr0ky6hQJ2n_{(Kt9m=7SQ`72B$q<9r;u)io)6Y z{AeQqc$)OHCtI7}E6U4#>OOt4CaR~TBqO{0;(oZA>Irx5e0A>Z3!AkyDQRLMAmG+) z`O35QqVn?Vo#nm+d@Cu|C@hVIQb59%g~i3iEOE*fxVX6Tva;QA04gpy6kktQzX*j6 zQeJ5_&0DwgtF8%#Ar+uey|=L2nvMB;(Xf54@My(FUH1RToTZxFsUGIqw{r zYgArdo)n8()@^i=*(c;dezs<2ywe>WjKrFVMU`wE5i#j!)Dk|;zp5A+7$mW=v1f|3 zH-pQ{%FuJD>>hX$+7mar?wK?kqj8(b7nnA?*<%FIE#k+aHa(iHDuX9ftX(ny=xbf# z5+Rk68;<0orlz(ZOD`4sYA9er*EhHqQsXLmw30F-LnEQk1w6vK!3|VyxC0W_oz8u2B?z)bSeC1xe_5KxrNuK>~ zbRMFQLZ7Q?X=%A4V@_Z@LLlgtzq)LWvwec*t;5aD?e34l7C_Fug@TUzUbA@Ig_=5Z zb4cRG$gj@V%q-6uP?#7W-yv>RtKB3_JL&xV{QHWEiY9+HBC$?6Ng_YH?f;2yY4erRC@4@s34WHgxH%eA`&uENn3{TL)lRvu*$!Fa z(W9sDQ&Qxl1$r5*Ha0dCJeY9kpBIex_4O6^PEJlTv9p(SL?U1&qKVQ}B(~eJrVk2S z10rr%TwEk73Wkea{h9Z@`JISVAwG7GhiBwq=CftcEmbIp5kEg9#1cLA=_cHPGu%NC zk?^y2q}JfzVBFA-jWgx)Ag0~svBi$ii*RX%xRewotgm418(CRxn~|Ng`=ek}M9HR0_=>moJ27nqV!OoRUiBrgBn@SWF(#_CkBksx z3fg9&>5eh4Qv2@Ad}fWSr2*(`ASIRG1*|5kV^N;vH#vD)PrEq)u0Xn^?$yEcLt(1_ zMtmd8nmIdfSzs({x;i@6!Yi1qjXss;s4NmtB17v4*8)frBBbNMHd z+lWpOC)zVnyAT;q82{4o`tnQypsRSw<}%&k#olpP{ZY_c zEp2R~yFX!UxIRu*e%T&?isd3BE6at6i<|7RtMEpJjg76ZIWN!5$=Z77l_<@gZAFWI zcWqr=sQf3t>gsA^;}KV^OIS>v$gaG{K9tQkUJkIlDems>3J>uZOd1fwJ)NDmbpfS< zHXy=EgqgCi@oTIW6BF|SCZE{n+SN6D*>lmo*^56~Vl~ zBMO&RRA;E+=0^+EP|hDQa&U0y-rCq`fh%wRt>IQWggr^|duGO?y1xD={`W@dw1fo0 zYS+EFF#uDhu9Iy_3$}C3XEN^Y4ZPW)~py3nDd8P zy)R@%y-pu^|EzqjY!|XMh(yV7n5)iu91#)G4{)AD-@rha)1X>hN$y2qHv zv$F37YKe&8lDAXl?kPZxHQjO};j5K_6l!PnzSl?v@Ka05WEK5o==u1x5R)`&-5H+g z=s$00Mcw>ne*NOJn5agJGX_w`5S#Q4O~Hy!?Po3#^N{ae`&mPpx>8ZqvabXx3|II zc$6|=%>&nNv0n=5yr*ewWJFgVPD@T+JWI{o_<6JWMWx;1H{N^q?g`A{cbwc=SYOA; z&Ykl2_fK1JnEkbOE!aazv-~1OHea0;-=UC|B$Ca}C765Na7g!O=0Xj&D?NKsgygX_ zC<39+%;K5~3U0exU$=N~`#-$-`^)xBLqp>s+}c8Zpv)!L8#*Qprn^Z{c0)*5eBayA zU;fi(>B%|C*_ey8-}0poW}Tewn*-~d5{9Kruvz({T8m6N9S{)ELS3ypUcamO+lHm_ZbJdtV*9VBsw}8bU6FVKV6Y^ z+p`UPDT*JSj%^%a=c)^ZaHcM>+V9PY<$n0EQZ(0y2;iFm2`<{ez~JiJ(tdoW8P6{1 zjPEAOH+A}k?FeFy2lF^~$iC~txe8;2YObD!KjcPH{Y}~Gk!rtuVFo^Z-q6sXqts8R zb^|J`H_+S!QL|1AW^z&k)~EFN82Cj4#3UrLKn8}YHa9n`V`F1=+?FH4!hU|t&mZ%J z?dRC>?VCEr=OBCuUgZ+IMQ_By6GrVwY-kvl+Y#nwaxpX$Kl=M4G<0=W{UTAx3q$K( z1YMsl#S{RbX*4HBCq?)dM@Os1!dyJ7eBROg#7)7~7wEOLo}OURz{(sMXmhyS+!ZvA zhJQ~^hH9#+$kCo9)%xGT5!JJ{vhqP94FJq$o1DmUG~eug=wWC1qpxooRE;Q+@k4Lk z_K<|k%*?ufxWb}0EEs+J2y_U%2M?f87#M6|9M>?tsT}C|c!pT)s0Ug`x=8h!5J9UKMXtL>lv0v(LFya#Q8ZXiiH>>)YGPFjh>WVv;1*&iWGUVK43yqFqk_k|7gRzcQ?ZZa}5zkBFvQ*9#wgeF>AgxO!8 zacXO7Hm>aK7%RUg4~e$7w`acP|BNboNbMPKDz<_XZcnvdg~?}-!{>*GhiUeA{QK9T zTZumf!Q<2j?-4DJ*=+|9ZnX;4vO_qjgA^;|Z+YpnqXNeK1;z0tw1_iLgeBv6dwY8o zpyZK0_4Lo5KU?BY=hTbGU%`MZ1(BP1cdq5a6TALilto|syepph{sQ&4o4{ zq^{A?c;FYOZ6!oz6WHSg6arTIoiMiwOxUO{H+-*-r!uifIO`ve58M@1Jv=zrgnH%o zxS+>1(}C|yKvF3sM7~?5(dKh?3ztT8{a~kV-e-#N`Z5%kI-+-A04pTT(Crrx%G+mW zXV3Cegmjn;+V|df{1XrdQn;7WhSKHF!a#O6*=+xJA35>y@m{RhDh0^vd$SFUGmXxr zx8klxHwnqeSV3pzjAA_neNTgsFyX7?>i0Mgx`8j&zZhT)1?<0Ew{vii1nuNOI!Du( zbHy!F9i4}vU1rv0MMag@D=DT0m|hs9vyIM{V*oPj3(Gu9I|0a@$Hw9teI@vPAIZQM zm~Qdd#Kb-A7ODUP!0^NE?T>Zdgz|71H}V^Skx)@w{6-42D4fYNHPB}>MO@3RZuySn z$<&KKftpnNC&ryf-?I->`&3lq_RWI#j@XbUYvQZc*4E?}@8%6`R=aJGwM-AX%y@G7 ze5ItM=+g&j4g{jfIOxKM{l#wn?)=)gfB$}<{ZZ(82_DL+ofJ$BM6jQq-;f=v--8Vh zbzc&O$Ds;080~%!3k#daz?(y%?&#=f8=abxkZPX^EGaD=+D9PTGk!;}J1wAt_VD9S zEnD3AE8AKq%H{Rd#U2MIC%>4(G6tJ-RHNZLaEg}B8IUC^$Np(MASsKYsl97adtdVsmd#Z61Be0l~34S63vpt}B~Y7S^sF&_Ob6n`nk%j*!4nQ44ptW}t%PSj<^DzBmv z1;0k;q4|ck@+eoGiHV6B45d`sBt`4#HeZRwQ0(Ri)0&q!nEUVDDC+4gUcMBEU7yar z)59j};4Fg`V+1XqEnhZ@B23T$Y)uScDy8GD-m$dNqDsk}Z@~I|uVTdzC+`IfSrZf6 z4DGEe)**=27<<2)LX}v1+Yw`G5-OX~bp^hz_V#Q~E1&t_$!dO#s6IQ|(2`$XCLtmk zXK}fx^Ee;!z2>WHY&)36}sB+{7g(3)~%A4j)ECMa_jVTW^xQm=xP* zalHVXBBF+zpyA$zBMhu#utd@k%^%x}UquSD5o(+vohC4=G`7L$=N=myi_{?Ms(lU+ z_6rClF^T%9nl4_9jEuXmo6do85+rafc+rxQhHl6Ogg+OQ&RKu|o{UG=1U8!MQ$xcO z7=ILTD=)&Gt*Y1COKX6W5^nzyqS#zpliOlTxL-B^bwrOq8xx)fam(QITVmjDwI`)C z0h(=KneYOe7tlrRi2iqlH`V&?F0$wbkrEf%H3Av!Lx}x-a*mCk)x#130)KI%pC#ii z+?=gtM~KCJIKx5ws@grxQ7dY6+np6w*3dQH$WEm81rtOEwvF2tk}B|+{j;;P#~E)} zR5MtgR+$Cg$tvrz6U`ZU-Q(@;z1DxrExaEAD@jF&8SJ=#5m=QA?hv!*-)%N!HMNxU z?!@=+ds{*L;Se<-PE1NFb=jNy6lpJ>8UK7zUJnJ}{3Izcaq%L-N7FW+K>#yme>S9o z1nB6Hg2OyTRal9{VG4bp2faqn?Yxg-r$33~W~j5XQ}fA_=VUa~@BoL6n_Lto8c~|A zc7HcfLRs1y{8d&_*$RA}mTHZJMC0)<3lJE1&xMj6^^}K)=d!Gf(YdrmM)LPqlm9oL%sDPnQ8wwC`p9znY@Cka-&y|N~%*+xu{4)Un4 zwvLWi%)56?%iF;+Sy=_(mb-t1qC(zKdhmtD(OAFU?m0)2Vi)Qk@P`G4vL#IaF!Hjs zOV}+u-hujki1_&q!T=O%S)$=vCVuvd*D@jKrwc6Cr~6CI-WPw5_2~pg+@Ei(EiEO8 z!0xjQ^KAd=fqe?bfptq`V>M0RNvt(NF(vL||@r z)sP}b5lFP({=gje1k}2eUxi3^rf_vV`3~-9biff4nPChvRD8osZ?8OIz7ci%&2oZT zKk5CaLDNoi1U8iE723##rJA!qZ8 z%$GB@Z|X8LGP(oi3A!iE+W|yK2Ll|#)pg{cn(BT>uC=5a+xNN`Mc>?`)4d+}3ei|H50qc0cw@)=zX9>-=m7(g;1AqOHGQ;}_8 zG%Qb~;H023sJ>;CefQd=)vKX1yKGlLqah(}`%!UMXD7e78v>~&lX&u}l2WNSJG-Jl z#&}r$Jpe{??E?c!n>KwQp^<(vYS7$Gp8buxKi@XcY{;9bS`iTym2`R)O62%a6d#qc z#3OK13QHQ6fDO!}xF~c^_x0ztj~lmm>a3=#vxe4u)pJ9~KB^FY&k{=~>XC(3rhm)5 zvcbwf`*o$ey*&>FF>&y8QbKQ8I9j?|8h`O%M~9SIByO)V1>%KpOD||HktFw@GO2No z;waKT5EB<~1*<`3b3+DLNV%jnvZzD`0i!Gic;C?jm`pm3%nwqIgEWCKvCcVUE&Ox_ zY2($GFJBIVG~Mtc{FCJ+i^0X-uV}lD;INa~Y!~F=nU;9bPn4=cUk`GX5Ln&rm|wXb zr)FkSlai9kDMqxGSE}&`F91(i0!kwv7gL*$t4w5@X6HVtk8Q|^d)L?ZW(UO9gMunD zr^(XxJ*79_AOP|T`hWjekU5f$9@7E;qPjp89&w1Dne9OG{RGmGSp3uBO!?;+=;-J` zjS~1R35!L<=P2|KG#@kNtm8!DwGa*e^QhsfzGUs854Se{*miYwoe6zIT!(ze`+RB$ z&{x0NqVe=sfkJ{h9v)sQN^A2hi+j4@OI2FKh9QW;VALCxD<@tglDh2%-x>lr?H7b` z#=to|H}YQtnntUq&6NCjPbC?38TN~-mZql1r}mnN($Xygh}KMPZ(H4dMPJdj^A>jD zpi~I9{UHJ&6zSfS;P-%m;hP~RNe}p7><4FF-!j_SCuV2A1MPcSR8ZigG^3-HGZX%p zj*JB#<1QF}J+abj>ZgCeTeBv@>;h+xKdbVtofAY4GWP#%)ug1PdZV~`>RV3YUZ-}; z--59Ue`JYm`P0c`;SyXk-1BI7;UJVj4bt(P`on_HpOboj`X2KEyzt9w28^QTaH z$6^?hSxD6(sFPGb!C;PpQKRT~fP9r8MiiQ_S?mc-*nHZ`rKq-~@NrVYKab4Q)04JJ ze_JW1{?`pjrX+G?S`H9TbP0(zYcd^X0s{vJ-cJPu7Pqs9vJLe0>z~|x8H+VBI(iq3 z{}?4zRg-W!c|sE(5L5H>376N`UyED)d|=D^X>2^m^Ltw#M#AvKgvyFTgWx|&wqszR z6nBp)Y!o2dY7~{Q0~u3XeC^lZGm!l%DX-d>_G6v5CgU^}P@6fYtpvcbYI*}A3nDm9 zTl;o21>hlfFsj9p?{l%SDJ;PgMFt;x31lVed%rnTm6>mUpo3^uM3dLqL1bDQg;9g5 z{r_XefofLJ`Ps0LqBY>D^ucEEv9Yn4xXah|mF}O81k1Y&J(3qFiQSQx1RE9Yf*kbx z;Gp2(Ctp|0f#AHLr>8Hif%}I?N=T+(K=tqJq=l zd*hS;<%k^P&q3!W-e!-@Mv+0U$IK0NrXde-Vat`cHKL zTtmOlh4)RPc>JY6y4W7%o?1cibp%QBgraoVViZ&gTWKGkYhzfqVE7$J^*LBsEkK`( zA&Bg9pZ7lbZHIBr#l>Z!4KCDEJ-wcava)TV(T&Z`QGHGlDIi1Bot;drpFZ8!pu;x; z#L=3o{x--{C+U=y?@*5kvv{7Lj}m&H09*vf_j!(aIvw+l|iy!wG)arzRP5k^H0Zm z_YONNH8nLTV-9Nkrv{M@QDhg9d=2Z}aC~`HEF2dONaj%@UrMnNVU7nebgf-xkNQ!7ZMz}~=(Ysk=ph6E?@fwO%?C+7p9a>zBlGI{EgyjLzA(lW zNx9^&Ut~PABv}H&G6;gpI}n9$T#sMm++$%03=W+e9;TcAAcMAgKtrGoDGeR8z>yz| zc1#kcvHU&o97Y?AY$D-qH-Q*3&0QK987**i!u;PBz>+F#p8{>O4#FB65MtW?ncMr? zE*j!8AOC9Wh&A(~obvJV-iD+BMrsdDvqP)`UQapzq@Nq))wj=G*T_I_8T|2s#J|jf z|1<)u8vJRXntMiECj%$@+eD{)FTV>FR#Zr2G7U$91@&TQY3cC&yKseso^*4y;;5*o zTjZoBZ~AAbZR<~0mX|Sl-jSP+|LRHKwFqw8gYtL{u{^FUGrP?F;3dYG9uZflGV*#q zyv}q1YY$Mqo^yrY!TC`R`h}yY_xaIF0P{U_;zQ;}egvT6Zh+9QT=`7FY^{fvW||-I z?ar$?2q_4HOdxzTDMK>U49a3*H8@`b^InI8ctG4#y3!o3z0KQS=$V?{biuY1`E)+D zLhcJTZz15>S0)V(s6$lOc{^aY@;+<#)5Atv+7fnLoxRstkn+gCxTd*T^euQDD3HXw zOa8Gl>pkXs?Kk{sNRrHu2iwdNFi?EdQ&3Pa0{fN)%wQbQAu+1Jl#?_wH&+9Ud$sk0 z%*nF>2Ll7YMxRsh%^Nlw`tgYgED)et-M$8(cKQg{%Q3Y{L8pBNIT>be@2fz`T)R7G zjIli$0D2{2dJf_9#`9X-)yoPu5~=|1v;g(gSG2a$)TII%!YD2+C4|~`B~Sl#A8~wi zq#G0xvfJ!?BfcwKJ-yulV!JO`b+5idN(WyMg?t04RSdd?JvuJcX?a6~@Kf1N4?XO} zJ_|HX{mN&0Zf>V}SqCj~AvB;ReCJ?imj$cTr+aCCb&0y;#}8Z_m}C%S{W+mCZ{v@b z30%Y&rvK3^U0o6`VekSrL8hw1rV_FXEqh9YP=5WVGu-!|Ud3e>#JIFVG4wNY1V}a` zBzn&N%>rd5rHc>d>3$PD?v`*>MFCojS{VxLb(8a5t<`yg}USUI&Fo%llwiVFi>cj1L$YqVBw#ySwH7 zbQsJmyrS)eGIDZQAQfQ@e*gOQD;O0uYJ2j(Rc1#MOyuq=f+tn7`RCpP6fX845RyDqZtSUOkpYfDF8KICoR;rR z3}O2GFAMK(98RjZcVkFtsbx$9HR0X(g8w|cnPzv#Na)8C!^8L^bJ`gc%SQZ~+8dONLYInc?@Zsm=Ub1YTbGEyLgp7?)ji*9! zxL!fvuaj__7-{P16@uN6`_FMq?_FN@7B|9qyj>X+qm~4Vzf*&RR{*Pq1I5k^km$Xj zj;M%F=qh}RUS{0%*Zs+puckC1`YD}rb3WJ!eMBB^ZVP;PE#wOTMxTOFQv#BPjDAnz zn1U%dqf`$*Xcq4PTc40_Rfh-i1<39ZI2R&r1*q8>PXf`NxV(x4ha|=A{12KB?Aaq> zsvinUN(1&_)OGObqVGT)fevBeqOY&dJNaXwduDdl3c^?of56{-%s6 zsG)%0nDybq2Sj~n<@B~Ov=hnKuh+Bn<*>1^mWqmtGu@8X2`0IGNBkLQ0KVI1in=@e zbA7q=EN9z8HE^)8nYr~V={{Fg5xBBu1P7xEsXi(2sx!BpuD%yE__8j%>kk&hK<(|C zM~8k_i4 zN<*7=w19_!fA6M_gpAD1Z8+x%CMZ4jflRfa%(F(xHfb6fimcqHXQjyK`DaUQ$4Fe; zb%?wXZn2<1YKI&y6An4A1(#4q%SCH`aj`qO%t#0r&r{$jkKMg{H~!%8Fc=1auV*kS z4W!c_S%JUqbIfit%Yd*uIanExdi5jY47c>o;co*%RB?nll!D6m$jBLH#TG9Hj)<>~ z&F&b)MY}<;cCFB_GW!L+eh35zZ&d$ISXx(z3ClTuk$#La8FO>dc9S1XBlc(q6a?J( z`-RP}t`ta>(G(9iXO1?;Sk{)8!=Q;ZVN2=g>9zfun-j;pdlwdSUch!v)NyaFrL^3% zZMWjnr@^}FY6@&undXXx1qUM?o#S7SVt&44wXM2)a%FsX0Y#z{2GwfTcVM2neznFeHW2lrAxaoH^uo~aR~2-t{-H}ZqR==O;LdUoEnNG?^SO?q-UfDs z-P9+;SFFX@1xWKhew2g3F?vq5AJ)M5JLLS6A&+hROdvVWQhXmzX-uRWb9oE3k%K3o8(@P4Iyq?qVS!R-aBEFGBR8zB0lKXN)(?eD z9s#EM#yjqf_E7)tgM;X(XlSd1ecuskPat;oi01x+gG^`Op0N*-4-O6v2IiA>r^cZY zozlO5Nfs=g&jL%hfFE%M{UWm2=jy51a9|DjY{ddk&4*z1-1xTQ7m%l0_q{&M{%XXP za?~qUjARNmZUu)>xRIZ!bNb6)TpkXII1C0(&4FY`5cVn<9hk@80G0H77zX7m0#aQgu;#fv(bN~Eithn|gCe-(BK7e> z^~}#I^RFL{K?{Allp*Y>uav@N%@SG1dEh@z4Q5gRU{dF1R}j+UnVFd!8oe*R+;l~f z&YL`Dt9dzi7Xo1ZdBw#FFmpPNyUky|41uBYXk~3}$@O>V1CC;3Q#rX;-yp$TQK`=f zIC%|O%kC0MFBJTYfb=&VFoFj`6`428{W>=07}MH%&0EcFn!uvA+pA)3VNozYH^&8{ z0#k+L?GTw*fj;?EC)SX(Cxwv7 zTRWp*ZdW}YV>_dgqN3Ll9!Ew0#c1WFBs5XPF)VFuC8oZ9r7v%7H9@_`BSAT(3NTfH zlM-Km19r^KWr6!DE8=_I%ql22h597+@&|MO%NoJPhK9jKhlWp_B$i|uH~WpXE+3@b z0(*OVi*7bcD`cf)!@x7Hp`fIEcs`@C4i4!{00b5Em9)I18RFiL%(s75ZJwQFmXHX3 zX@7+te`ji9Ld>FOx*z6y59DMY-QWCJR3!8h94a+XiPEyNvi{AKqe~=n@wu*!7NT{sU&js9)#>8+ zrr{u10<&7yHrnyWoSzh_DgXm4dSmHZVIXAz;~J+0j#P&cp!^gvu6KBQ=+pK7Z%o|6 z;_~gwm)%-=dTL(hM{ks2ck!f}KM8jIxuT_|6>|+S&_kvLm488T3NSno`K;{hKY%(9 z!aDim(TJW-rAP(XUr*?4wucfx0A*qD*@K^;>KTXREoQ!tic$$nNYD}zDpc5V9%*l< zi<8YKo|v4p`Ptye;taEU@xdg_WU>f7lQ+W^#!UiL(P*G_VPOF?fpbYVkWu*vJkNB* z+TtDFt20M;g@klpg7K@u zb^pGKu7<|h=f*~gR%K0CzPIaesWma*Ya=*Da#1>twu#*BO>=7N%mYiiP_ND(foPIF34ee+s+VO(yO= zO_`m#&K1~w1R(e(hl@mYCU|uC)uJ*e(N&+id3w&fIyh7Z^U8{m-`&{WE|YZ0tN>}C z1X|2reOV}BDd9|LLcc-e_Y*U)WKi-F*Ix*XhqDh6^v?Xtiw#a2cV!e5!tY4jdUK5r z53AOIQ}>siske;cJDP$ake_rL9aa>R`2A7v!f*NKya6?xm5LCL`q9xNZtfxJH1ogA zdw3M5H|m^>fUL7s3n|xDS6#+;lP2+yd|tzNjMJ~P`+f%#^KOS>Fh9liww*1KF*XH% zksCO6fdscVde3fh1;a@Tx!J<{EH;6!3%&x^yJTu~)C>(*N1FGmv*0UA%5*Fa-Llg% zk;dI?-1dJ)))2t6_DF$ZoH_A@?CNTV=WwfCU~RsHa#dI(l`UCbesEFbccc3P+-brd zkVtwaCtXxMJw>pn<{J-KzLjpCp1O@5VJ@7&L|RJ9<@2Zw}pxKzw+1 zX(@f?&3Xm4#jAU8?6eqAt~w0L&8>>I*4yQyvEzxoE2D6{0wiF}hp8A3k$j}3r41Dn z?(FukpL&2`Ne`1v4m6S-BVFCUfEH!^ht>wL-ZmTH2qQ#7@2#U{3Rusu;f5}G0OpMz zU)KKx)u_{YbA6#(cC?q@VcCX0WfG<>V*jVJI5Ck3qh#-WAQP`wkvE+5tgHs|It^G? zK>ZlSl5r^@^27{FLkB8l8V*iUh3ou?Nm7Mlj2wIa_ZVZ$Z`#*}PoLIB;hvcO6cOyW1N=GUTzd-cQ4{ho7YSeLl37Z zC@yAWy?>whWN$tjWV9UVTy-KgB1JiD_VG%Y|IZ;yz~(7QNsIkY@aPjE6WrRjwBPO9 zIS~A2(_z6}lQ4iv)U8rjOss`5NK^M0G=nr!PW|>ooihssu75{OWkI&_1m(j93rqHI zLG1L*%oj)yUL~al5PhU&C4`S~Z3F)66s1x7c--}}rVD=g&ZKUXr6UO;-c%ELgV8U5 z@8Imk6Ry z6?u8OZ3cfS9NOFe4%#Mb;CfN@$J=Yd=Q!1&rG#zYLKO-QbhrDFu*@&7uy zZ1E_Na~xJeyY7EZCWHTr3xqz%>MH~A0sL@jFZLu%)pH^cfAs)Uf7C2SH2xw$Vjzk9 zg?j4=N0hAPMFk_XBG?Pqr*eVKG#Iyv#r#NVuOVqfa6}v~9RcL49qW67t^4PHFU?}@ zun^=qOnwR+H#V5MBRLlF>a3UR0p0eT^Yij6?JOn2?rq|qkcAN!M+beuEG6(=_*>Pv f3N_1x8)OFLZtdJFwG23(j-()?DqSx5Ea3kDaUQO+ From 6c8792246f68fbfd708a83b7e129bcdb3c501db6 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 28 Mar 2023 23:54:05 -0400 Subject: [PATCH 069/147] fieldline working in directory --- src/applications/mne_scan/mne_scan/mne_scan.qrc | 1 - src/applications/mne_scan/plugins/fieldline/CMakeLists.txt | 2 ++ src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 2 +- .../fieldline/{fieldlineview.cpp => fieldline_view.cpp} | 2 +- .../plugins/fieldline/{fieldlineview.h => fieldline_view.h} | 4 ++-- .../mne_scan/plugins/fieldline}/fl_chassis.ui | 0 .../mne_scan/plugins/fieldline}/fl_rack.ui | 0 src/libraries/disp/CMakeLists.txt | 2 -- 8 files changed, 6 insertions(+), 7 deletions(-) rename src/applications/mne_scan/plugins/fieldline/{fieldlineview.cpp => fieldline_view.cpp} (99%) rename src/applications/mne_scan/plugins/fieldline/{fieldlineview.h => fieldline_view.h} (98%) rename src/{libraries/disp/viewers/formfiles => applications/mne_scan/plugins/fieldline}/fl_chassis.ui (100%) rename src/{libraries/disp/viewers/formfiles => applications/mne_scan/plugins/fieldline}/fl_rack.ui (100%) diff --git a/src/applications/mne_scan/mne_scan/mne_scan.qrc b/src/applications/mne_scan/mne_scan/mne_scan.qrc index 8c2b20f8b25..219b18e23df 100644 --- a/src/applications/mne_scan/mne_scan/mne_scan.qrc +++ b/src/applications/mne_scan/mne_scan/mne_scan.qrc @@ -4,7 +4,6 @@ images/icons/new.png images/icons/save.png images/icons/stop.png - images/icons/quickControl.png images/icons/sensor.png images/icons/io.png images/icons/algorithm.png diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 2e184e91c01..2473052fd39 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -110,6 +110,7 @@ set(SOURCES fieldline.cpp fieldline_acq_system_controller.cpp fieldline_plugin_gui.cpp + fieldline_view.cpp ) set(HEADERS @@ -117,6 +118,7 @@ set(HEADERS fieldline.h fieldline_acq_system_controller.h fieldline_plugin_gui.h + fieldline_view.h ) set(FILE_TO_UPDATE fieldline_global.cpp) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index e24a96a52ec..99c50cca355 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,7 +44,7 @@ #include "fieldline.h" -#include +#include "fieldline/fieldline_view.h" // #include "fieldlineproducer.h" // #include "FormFiles/fieldlinesetup.h" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp similarity index 99% rename from src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp rename to src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 1964bb7e578..e9ef86a0ae8 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -40,7 +40,7 @@ #include "ui_fl_rack.h" #include "ui_fl_chassis.h" -#include "fieldlineview.h" +#include "fieldline/fieldline_view.h" //============================================================================================================= // QT INCLUDES diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h similarity index 98% rename from src/applications/mne_scan/plugins/fieldline/fieldlineview.h rename to src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 2f9034f1941..139aa16573a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -40,9 +40,9 @@ // INCLUDES //============================================================================================================= -#include "../disp_global.h" +#include "fieldline/fieldline_global.h" -#include "led_indicator.h" +#include "disp/viewers/led_indicator.h" #include #include diff --git a/src/libraries/disp/viewers/formfiles/fl_chassis.ui b/src/applications/mne_scan/plugins/fieldline/fl_chassis.ui similarity index 100% rename from src/libraries/disp/viewers/formfiles/fl_chassis.ui rename to src/applications/mne_scan/plugins/fieldline/fl_chassis.ui diff --git a/src/libraries/disp/viewers/formfiles/fl_rack.ui b/src/applications/mne_scan/plugins/fieldline/fl_rack.ui similarity index 100% rename from src/libraries/disp/viewers/formfiles/fl_rack.ui rename to src/applications/mne_scan/plugins/fieldline/fl_rack.ui diff --git a/src/libraries/disp/CMakeLists.txt b/src/libraries/disp/CMakeLists.txt index 78792d03770..513959302fc 100644 --- a/src/libraries/disp/CMakeLists.txt +++ b/src/libraries/disp/CMakeLists.txt @@ -57,7 +57,6 @@ set(SOURCES viewers/covariancesettingsview.cpp viewers/bidsview.cpp viewers/led_indicator.cpp - viewers/fieldlineview.cpp viewers/helpers/rtfiffrawviewmodel.cpp viewers/helpers/rtfiffrawviewdelegate.cpp viewers/helpers/evokedsetmodel.cpp @@ -122,7 +121,6 @@ set(HEADERS viewers/covariancesettingsview.h viewers/bidsview.h viewers/led_indicator.h - viewers/fieldlineview.h viewers/helpers/rtfiffrawviewdelegate.h viewers/helpers/rtfiffrawviewmodel.h viewers/helpers/evokedsetmodel.h From ffc08f48d88966acd07e642dedbdf220968f398b Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 29 Mar 2023 16:09:08 -0400 Subject: [PATCH 070/147] put view files in plugin folder --- src/applications/mne_scan/mne_scan/plugingui.cpp | 2 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 10 ++++++---- .../mne_scan/plugins/fieldline/fieldline.h | 1 - .../fieldline/{fl_chassis.ui => fieldline_chassis.ui} | 0 .../fieldline/{fl_rack.ui => fieldline_rack.ui} | 0 .../mne_scan/plugins/fieldline/fieldline_view.cpp | 4 ++-- 6 files changed, 9 insertions(+), 8 deletions(-) rename src/applications/mne_scan/plugins/fieldline/{fl_chassis.ui => fieldline_chassis.ui} (100%) rename src/applications/mne_scan/plugins/fieldline/{fl_rack.ui => fieldline_rack.ui} (100%) diff --git a/src/applications/mne_scan/mne_scan/plugingui.cpp b/src/applications/mne_scan/mne_scan/plugingui.cpp index dda3b866cf9..4422a64bc93 100644 --- a/src/applications/mne_scan/mne_scan/plugingui.cpp +++ b/src/applications/mne_scan/mne_scan/plugingui.cpp @@ -286,7 +286,7 @@ void PluginGui::loadConfig(const QString& sPath, const QString& sFileName) void PluginGui::saveConfig(const QString& sPath, const QString& sFileName) { - qDebug() << "Save Config" << sPath+"/"+sFileName; + //qDebug() << "Save Config" << sPath+"/"+sFileName; QDomDocument doc("PluginConfig"); QDomElement root = doc.createElement("PluginTree"); doc.appendChild(root); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 99c50cca355..9dbf17c7e09 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -62,6 +62,7 @@ #include #include #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -140,10 +141,11 @@ Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } //============================================================================================================= Fieldline::~Fieldline() { - //If the program is closed while the sampling is in process - if(this->isRunning()) { - this->stop(); - } + //If the program is closed while the sampling is in process + qDebug() << "Destroying Fieldline plugin."; + if(this->isRunning()) { + this->stop(); + } } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index f8ed44b4b77..65cb7e61b66 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -176,7 +176,6 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { * pure virtual method inherited by qthread. */ virtual void run(); - std::unique_ptr acqSystem; std::unique_ptr guiWidget; diff --git a/src/applications/mne_scan/plugins/fieldline/fl_chassis.ui b/src/applications/mne_scan/plugins/fieldline/fieldline_chassis.ui similarity index 100% rename from src/applications/mne_scan/plugins/fieldline/fl_chassis.ui rename to src/applications/mne_scan/plugins/fieldline/fieldline_chassis.ui diff --git a/src/applications/mne_scan/plugins/fieldline/fl_rack.ui b/src/applications/mne_scan/plugins/fieldline/fieldline_rack.ui similarity index 100% rename from src/applications/mne_scan/plugins/fieldline/fl_rack.ui rename to src/applications/mne_scan/plugins/fieldline/fieldline_rack.ui diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index e9ef86a0ae8..f08020d28a6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -37,8 +37,8 @@ // INCLUDES //============================================================================================================= -#include "ui_fl_rack.h" -#include "ui_fl_chassis.h" +#include "ui_fieldline_rack.h" +#include "ui_fieldline_chassis.h" #include "fieldline/fieldline_view.h" From 4d5a385caeed42a0f29d6bdc2726c6b0a93906ff Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 29 Mar 2023 19:08:00 -0400 Subject: [PATCH 071/147] major reorganization fieldline plugin --- .../libs/scMeas/realtimemultisamplearray.cpp | 2 +- .../mne_scan/plugins/fieldline/CMakeLists.txt | 10 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 273 +++++++-------- .../mne_scan/plugins/fieldline/fieldline.h | 64 +--- .../fieldline_acq_system_controller.cpp | 145 -------- .../fieldline_acq_system_controller.h | 53 --- .../fieldline/fieldline_plugin_gui.cpp | 53 --- .../plugins/fieldline/fieldline_plugin_gui.h | 52 --- .../plugins/fieldline/fieldline_view.cpp | 325 ------------------ .../plugins/fieldline/fieldline_view.h | 148 -------- 10 files changed, 135 insertions(+), 990 deletions(-) delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view.h diff --git a/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp b/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp index 8284ae1e66e..9fbde90490b 100644 --- a/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp +++ b/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp @@ -158,7 +158,7 @@ void RealTimeMultiSampleArray::setValue(const MatrixXd& mat) // else if(v[i] > m_qListChInfo[i].getMaxValue()) v[i] = m_qListChInfo[i].getMaxValue(); // } - //Store + // Store m_matSamples.push_back(mat); m_qMutex.unlock(); diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 2473052fd39..ff679aa5ac1 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -108,17 +108,15 @@ message("python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp fieldline.cpp - fieldline_acq_system_controller.cpp - fieldline_plugin_gui.cpp - fieldline_view.cpp + fieldline_acqsystem.cpp + fieldlineview.cpp ) set(HEADERS fieldline_global.h fieldline.h - fieldline_acq_system_controller.h - fieldline_plugin_gui.h - fieldline_view.h + fieldline_acqsystem.h + fieldlineview.h ) set(FILE_TO_UPDATE fieldline_global.cpp) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 9dbf17c7e09..8091ad6ec89 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -42,27 +42,26 @@ // INCLUDES //============================================================================================================= -#include "fieldline.h" - -#include "fieldline/fieldline_view.h" -// #include "fieldlineproducer.h" -// #include "FormFiles/fieldlinesetup.h" +#include "fieldline/fieldline.h" +#include "fieldline/fieldline_acqsystem.h" +#include "fieldline/fieldlineview.h" #include +// #include //============================================================================================================= // QT INCLUDES //============================================================================================================= // #include -#include -#include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include //============================================================================================================= // EIGEN INCLUDES @@ -95,55 +94,55 @@ namespace FIELDLINEPLUGIN { // } // } -QSharedPointer -createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { - QSharedPointer pFiffInfo; - pFiffInfo->sfreq = sfreq; - pFiffInfo->chs.clear(); - - int total_channels = 0; - int chassis_num = 0; - for (auto &chassis : fl_chassis) { - for (auto &sensor : chassis) { - FIFFLIB::FiffChInfo channel; - channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); - channel.kind = FIFFV_MEG_CH; - channel.unit = FIFF_UNIT_T; - channel.unit_mul = FIFF_UNITM_NONE; - channel.chpos.coil_type = FIFFV_COIL_NONE; - pFiffInfo->chs.append(channel); - pFiffInfo->ch_names.append(channel.ch_name); - ++total_channels; - } - } - pFiffInfo->nchan = total_channels; - - return pFiffInfo; -} - -QSharedPointer -createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { - std::vector> fl; - for (int i = 0; i < numChassis; ++i) { - std::vector ch(numChannels); - std::iota(ch.begin(), ch.end(), 1); - fl.push_back(std::move(ch)); - } - return createFiffInfo(fl, sfreq); -} +// QSharedPointer +// createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { +// QSharedPointer pFiffInfo; +// pFiffInfo->sfreq = sfreq; +// pFiffInfo->chs.clear(); +// +// int total_channels = 0; +// int chassis_num = 0; +// for (auto &chassis : fl_chassis) { +// for (auto &sensor : chassis) { +// FIFFLIB::FiffChInfo channel; +// channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); +// channel.kind = FIFFV_MEG_CH; +// channel.unit = FIFF_UNIT_T; +// channel.unit_mul = FIFF_UNITM_NONE; +// channel.chpos.coil_type = FIFFV_COIL_NONE; +// pFiffInfo->chs.append(channel); +// pFiffInfo->ch_names.append(channel.ch_name); +// ++total_channels; +// } +// } +// pFiffInfo->nchan = total_channels; +// +// return pFiffInfo; +// } +// +// QSharedPointer +// createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { +// std::vector> fl; +// for (int i = 0; i < numChassis; ++i) { +// std::vector ch(numChannels); +// std::iota(ch.begin(), ch.end(), 1); +// fl.push_back(std::move(ch)); +// } +// return createFiffInfo(fl, sfreq); +// } //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { qDebug() << "Creating Fieldline object"; } +Fieldline::Fieldline() { +} //============================================================================================================= Fieldline::~Fieldline() { - //If the program is closed while the sampling is in process qDebug() << "Destroying Fieldline plugin."; - if(this->isRunning()) { + if (this->isRunning()) { this->stop(); } } @@ -151,7 +150,6 @@ Fieldline::~Fieldline() { //============================================================================================================= QSharedPointer Fieldline::clone() const { - qDebug() << "Cloning Fieldline."; QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } @@ -160,50 +158,28 @@ QSharedPointer Fieldline::clone() const { void Fieldline::init() { - // we instantiante - m_pRTMSA_Fieldline = SCSHAREDLIB::PluginOutputData< - SCMEASLIB::RealTimeMultiSampleArray>::create(this, "Fieldline Plugin", - "FieldlinePlguin output"); + // data infrastructure + m_pRTMSA = SCSHAREDLIB::PluginOutputData + ::create(this, "Fieldline Plugin", + "FieldlinePlguin output"); + m_outputConnectors.append(m_pRTMSA); - m_outputConnectors.append(m_pRTMSA_Fieldline); - - qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Fieldline (....again)"; - acqSystem = std::make_unique(); + acqSystem = std::make_unique(this); + guiWidget = std::make_unique(this); } //============================================================================================================= -void Fieldline::unload() { qDebug() << "unload Fieldline"; } +void Fieldline::unload() { + qDebug() << "unload Fieldline"; +} //============================================================================================================= bool Fieldline::start() { qDebug() << "start Fieldline"; - // Init circular buffer to transmit data from the producer to this thread - // if(!m_pCircularBuffer) { - // m_pCircularBuffer = QSharedPointer(new - // CircularBuffer_Matrix_double(10)); - // } - // - // //Setup fiff info before setting up the RMTSA because we need it to init - // the RTMSA setUpFiffInfo(); - // - // //Set the channel size of the RMTSA - this needs to be done here and NOT in - // the init() function because the user can change the number of channels - // during runtime - // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); - // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); - // QThread::start(); - // - // // Start the producer - // m_pNatusProducer = - // QSharedPointer::create(m_iSamplesPerBlock, - // m_iNumberChannels); m_pNatusProducer->moveToThread(&m_pProducerThread); - // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, - // this, &Fieldline::onNewDataAvailable, Qt::DirectConnection); - // m_pProducerThread.start(); return true; } @@ -213,15 +189,6 @@ bool Fieldline::start() { bool Fieldline::stop() { requestInterruption(); wait(500); - // m_pRMTSA_Natus->measurementData()->clear(); - // - // - // // Clear all data in the buffer connected to displays and other plugins - // m_pCircularBuffer->clear(); - // - // m_pProducerThread.quit(); - // m_pProducerThread.wait(); - qDebug() << "Stop Fieldline"; return true; } @@ -236,7 +203,6 @@ SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { //============================================================================================================= QString Fieldline::getName() const { - // qDebug() << "getName Fieldline"; return QString("Fieldline OPM"); } @@ -244,7 +210,6 @@ QString Fieldline::getName() const { QWidget *Fieldline::setupWidget() { qDebug() << "setupWidget Fieldline"; - guiWidget = std::make_unique(); // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by // CentralWidget - so it has to be created everytime new @@ -252,17 +217,18 @@ QWidget *Fieldline::setupWidget() { // init properties dialog // widget->initGui(); - auto *frame = new QWidget(); - frame->setLayout(new QHBoxLayout()); - - auto *flWidget = new DISPLIB::FieldlineView(2, 16); - - frame->layout()->addWidget(flWidget); - flWidget->setBlinkState(0, 2, true); - flWidget->setBlinkState(1, 5, true); - - return frame; + // auto *frame = new QWidget(); + // frame->setLayout(new QHBoxLayout()); + // + // auto *flWidget = new DISPLIB::FieldlineView(2, 16); + // + // frame->layout()->addWidget(flWidget); + // flWidget->setBlinkState(0, 2, true); + // flWidget->setBlinkState(1, 5, true); + // + // return frame; + return guiWidget->getWidget(); // return new QLabel("Fieldline \n OPM"); } @@ -281,52 +247,57 @@ QWidget *Fieldline::setupWidget() { void Fieldline::run() { qDebug() << "run Fieldline"; - m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); - - m_pFiffInfo->sfreq = 1000.0f; - m_pFiffInfo->nchan = 32; - m_pFiffInfo->chs.clear(); - - for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { - FIFFLIB::FiffChInfo channel; - channel.ch_name = "Ch. " + QString::number(chan_i); - channel.kind = FIFFV_MEG_CH; - channel.unit = FIFF_UNIT_T; - channel.unit_mul = FIFF_UNITM_NONE; - channel.chpos.coil_type = FIFFV_COIL_NONE; - m_pFiffInfo->chs.append(channel); - m_pFiffInfo->ch_names.append(channel.ch_name); - } - - m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( - m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { - m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); - m_pRTMSA_Fieldline->measurementData()->setVisibility(true); - - Eigen::MatrixXd matData; - matData.resize(m_pFiffInfo->nchan, 200); - // matData.setZero(); - - for (;;) { - // gather the data - - matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); - matData *= 4e-12; - - msleep(200); - - if (isInterruptionRequested()) - break; - m_pRTMSA_Fieldline->measurementData()->setValue(matData); - } - - // //emit values - // if(!isInterruptionRequested()) { - // m_pRMTSA_Natus->measurementData()->setValue(matData); - // } - // } + // while (true) { + // if (QThread::isInterruptionRequested()) + // break; + // msleep(200); // } - qDebug() << "run Fieldline finished"; + // m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); + // + // m_pFiffInfo->sfreq = 1000.0f; + // m_pFiffInfo->nchan = 32; + // m_pFiffInfo->chs.clear(); + // + // for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { + // FIFFLIB::FiffChInfo channel; + // channel.ch_name = "Ch. " + QString::number(chan_i); + // channel.kind = FIFFV_MEG_CH; + // channel.unit = FIFF_UNIT_T; + // channel.unit_mul = FIFF_UNITM_NONE; + // channel.chpos.coil_type = FIFFV_COIL_NONE; + // m_pFiffInfo->chs.append(channel); + // m_pFiffInfo->ch_names.append(channel.ch_name); + // } + // + // m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( + // m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + // m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); + // m_pRTMSA_Fieldline->measurementData()->setVisibility(true); + // + // Eigen::MatrixXd matData; + // matData.resize(m_pFiffInfo->nchan, 200); + // // matData.setZero(); + // + // for (;;) { + // // gather the data + // + // matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + // matData *= 4e-12; + // + // msleep(200); + // + // if (isInterruptionRequested()) + // break; + // m_pRTMSA_Fieldline->measurementData()->setValue(matData); + // } + // + // // //emit values + // // if(!isInterruptionRequested()) { + // // m_pRMTSA_Natus->measurementData()->setValue(matData); + // // } + // // } + // // } + // qDebug() << "run Fieldline finished"; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 65cb7e61b66..cf3d9ab0a3c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -33,37 +33,25 @@ * */ -#ifndef FIELDLINE_H -#define FIELDLINE_H +#ifndef FIELDLINEPLUGIN_FIELDLINE_H +#define FIELDLINEPLUGIN_FIELDLINE_H //============================================================================================================= // INCLUDES //============================================================================================================= #include "fieldline/fieldline_global.h" -#include "fieldline/fieldline_acq_system_controller.h" -#include "fieldline/fieldline_plugin_gui.h" #include #include #include -// #include -#include -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= +#include #include #include -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -// #include - //============================================================================================================= // FORWARD DECLARATION //============================================================================================================= @@ -82,12 +70,8 @@ class FiffInfo; namespace FIELDLINEPLUGIN { -//============================================================================================================= -// FIELDLINEPLUGIN FORWARD DECLARATIONS -//============================================================================================================= - -// class FieldlineProducer; -// class FieldlineSetup; +class FieldlineAcqSystemController; +class FieldlineView; //============================================================================================================= /** @@ -105,51 +89,19 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { public: //========================================================================================================= - /** - * Constructs a Fieldline. - */ + // The plugin interface Fieldline(); - //========================================================================================================= - /** - * Destroys the Fieldline. - */ ~Fieldline(); - //========================================================================================================= - /** - * Clone the plugin - */ virtual QSharedPointer clone() const; - //========================================================================================================= - /** - * Initialise input and output connectors. - */ virtual void init(); - //========================================================================================================= - /** - * Is called when plugin is detached of the stage. Can be used to safe settings. - */ virtual void unload(); - //========================================================================================================= - /** - * Sets up the fiff info with the current data chosen by the user. - */ - // void setUpFiffInfo(); - - //========================================================================================================= - /** - * Starts the Fieldline by starting the tmsi's thread. - */ virtual bool start(); - //========================================================================================================= - /** - * Stops the Fieldline by stopping the tmsi's thread. - */ virtual bool stop(); virtual AbstractPlugin::PluginType getType() const; @@ -178,7 +130,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { virtual void run(); std::unique_ptr acqSystem; - std::unique_ptr guiWidget; + std::unique_ptr guiWidget; // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ // int m_iNumberChannels; /**< The number of channels to be received.*/ @@ -188,7 +140,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ // - QSharedPointer > m_pRTMSA_Fieldline; /**< The RealTimeSampleArray to provide the EEG data.*/ + QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp deleted file mode 100644 index 1c537d25f72..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_system_controller.cpp - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the definition of the Fieldline class. - * - */ - - - -#define PY_SSIZE_T_CLEAN -#include "Python.h" - -#include "fieldline_acq_system_controller.h" - -#include -#include - -//extern "C" { -// -//PyObject *restartFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - restart finished;\n"; -// } else { -// std::cout << "A sensor has finished restarting!\n"; -// } -// -// return NULL; -//} -//PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - coarse zero finished;\n"; -// } else { -// std::cout << "A sensor has finished coarse zeroing!\n"; -// } -// -// return NULL; -//} -//PyObject *fineZeroFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - fine zero finished;\n"; -// } else { -// std::cout << "A sensor has finished fine zeroing!\n"; -// } -// -// return NULL; -//} -//} -// -//static PyMethodDef my_module_methods[] = { -// {"restartFinished", restartFinished, METH_VARARGS, " "}, -// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, -// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, -// {NULL, NULL, 0, NULL}}; -// -//static PyModuleDef my_module_def = { -// PyModuleDef_HEAD_INIT, -// "mne_cpp_callbacks", -// "A module of callback functions for mne-cpp.", -// -1, -// my_module_methods, -// NULL, -// NULL, -// NULL, -// NULL}; -// -//PyMODINIT_FUNC PyInit_my_module(void) { -// return PyModule_Create(&my_module_def); -//} - -namespace FIELDLINEPLUGIN { -FieldlineAcqSystemController::FieldlineAcqSystemController() noexcept { - - // pythonInterpreter initiate - // - // run script - // - // find ip - // - // start connection - // - // initialize channels - // - // - Py_Initialize(); - PyConfig config; - PyConfig_InitPythonConfig(&config); - config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, L"."); - Py_InitializeFromConfig(&config); - FILE *py_file = fopen("main.py", "r"); - PyObject *global_dict = PyDict_New(); - PyObject *local_dict = PyDict_New(); - PyObject *result = - PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); -} - - -FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { - // Py_Finalize(); -} - -} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h deleted file mode 100644 index 84bdc40a3e3..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system_controller.h +++ /dev/null @@ -1,53 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_system_controller.h - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the declaration of the Fieldline Acquisition System Controller class. - * - */ - - -namespace FIELDLINEPLUGIN { - - -class FieldlineAcqSystemController { - public: - FieldlineAcqSystemController() noexcept; - - ~FieldlineAcqSystemController() noexcept; - - - private: - -}; - - -} // namespace FIELDLINEPLUGIN - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp deleted file mode 100644 index 5e7e879932c..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.cpp +++ /dev/null @@ -1,53 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_plugin_gui.cpp - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the definition of the Fieldline plugin GUI class. - * -*/ - -#include "fieldline_plugin_gui.h" - - -namespace FIELDLINEPLUGIN { - -FieldlinePluginGUI::FieldlinePluginGUI() noexcept { - -} - - -} // namespace FIELDLINEPLUGIN - - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h b/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h deleted file mode 100644 index 1e434db8b5e..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_plugin_gui.h +++ /dev/null @@ -1,52 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_plugin_gui.h - * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief Contains the declaration of the Fieldline plugin GUI class. - */ - - - -namespace FIELDLINEPLUGIN { - - -class FieldlinePluginGUI { - public: - FieldlinePluginGUI() noexcept; - - - private: - -}; - - -} // namespace FIELDLINEPLUGIN - - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp deleted file mode 100644 index f08020d28a6..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ /dev/null @@ -1,325 +0,0 @@ -//============================================================================================================= -/** - * @file fl_rack.cpp - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineView class definition. - * - */ - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "ui_fieldline_rack.h" -#include "ui_fieldline_chassis.h" - -#include "fieldline/fieldline_view.h" - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -#include -#include -#include - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// USED NAMESPACES -//============================================================================================================= - -using DISPLIB::FieldlineView; -using DISPLIB::fl_chassis; - -//============================================================================================================= -// DEFINE STATIC METHODS -//============================================================================================================= - -int FieldlineView::default_num_sensors = 16; - -//============================================================================================================= -// DEFINE MEMBER METHODS -//============================================================================================================= - - -FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) -: FieldlineView(parent) -{ - configure(num_chassis, sensors_per_chassis); -} - -//============================================================================================================= - -FieldlineView::FieldlineView(int num_chassis, QWidget *parent) -: FieldlineView(num_chassis, default_num_sensors, parent) -{ -} - -//============================================================================================================= - -FieldlineView::FieldlineView(QWidget *parent) -: QWidget(parent) -, ui(new Ui::fl_rack()) -{ - ui->setupUi(this); -} -//============================================================================================================= - -FieldlineView::~FieldlineView() -{ - delete ui; -} - -//============================================================================================================= - -void FieldlineView::configure(int num_chassis) -{ - configure(num_chassis, default_num_sensors); -} - -//============================================================================================================= - -void FieldlineView::configure(int num_chassis, int num_sensors) -{ - clear(); - for(int i = 0; i < num_chassis; ++i){ - chassis.push_back(new fl_chassis(num_sensors)); - ui->frame->layout()->addWidget(chassis.back()); - } -} - -//============================================================================================================= - -void FieldlineView::clear() -{ - for(auto* c : chassis){ - ui->frame->layout()->removeWidget(c); - c->deleteLater(); - } -}; - -//============================================================================================================= - -void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(sensor_num, color); -} - -//============================================================================================================= - -void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(sensor_num, color, blinking); -} - -//============================================================================================================= - -void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(color); -} - -//============================================================================================================= - -void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color, bool blinking) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setColor(color, blinking); -} - -//============================================================================================================= - -void FieldlineView::setAllColor(const QColor& color) -{ - for(auto* c : chassis){ - c->setColor(color); - } -} - -//============================================================================================================= - -void FieldlineView::setAllColor(const QColor& color, bool blinking) -{ - for(auto* c : chassis){ - c->setColor(color, blinking); - } -} - -//============================================================================================================= - -void FieldlineView::setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); -} - -//============================================================================================================= - -void FieldlineView::setChassisBlinkState(size_t chassis_id, bool blinking) -{ - if(chassis_id >= chassis.size()){ - return; - } - chassis.at(chassis_id)->setBlinkState(blinking); -} - -//============================================================================================================= - -void FieldlineView::setAllBlinkState(bool blinking) -{ - for(auto* c : chassis){ - c->setBlinkState(blinking); - } -} - -//============================================================================================================= - -void FieldlineView::setDefaultNumSensors(int num_sensors) -{ - default_num_sensors = num_sensors; -} - -//============================================================================================================= - -fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) -: QWidget(parent) -, ui(new Ui::fl_chassis()) -{ - ui->setupUi(this); - - for(int i = 0; i < num_sensors; ++i){ - sensors.push_back(new LEDIndicator()); - auto& last_item = sensors.back(); - sensors.back()->setLabel(QString::number(i + 1)); - ui->sensor_frame->layout()->addWidget(sensors.back()); - connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); - connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); - } -} - -//============================================================================================================= - -fl_chassis::~fl_chassis() -{ - delete ui; -} - -//============================================================================================================= - -void fl_chassis::setColor(size_t sensor_num, const QColor& color) -{ - if(sensor_num > sensors.size() || sensor_num < 1){ - return; - } - sensors.at(sensor_num - 1)->setColor(color); -} - -//============================================================================================================= - -void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) -{ - setColor(sensor_num, color); - setBlinkState(sensor_num, blinking); -} - -//============================================================================================================= - -void fl_chassis::setColor(const QColor& color) -{ - for(auto* sensor : sensors){ - sensor->setColor(color); - } -} - -//============================================================================================================= - -void fl_chassis::setColor(const QColor& color, bool blinking) -{ - for(auto* sensor : sensors){ - sensor->setColor(color); - sensor->setBlink(blinking); - } -} - -//============================================================================================================= - -void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) -{ - if(sensor_num > sensors.size() || sensor_num < 1){ - return; - } - sensors.at(sensor_num - 1)->setBlink(blinking); -} - -//============================================================================================================= - -void fl_chassis::setBlinkState(bool blinking) -{ - for(auto* sensor : sensors){ - sensor->setBlink(blinking); - } -} - -//============================================================================================================= - -void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) -{ -// auto* menu = new QMenu(); - -// auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); -// auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); - -// auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); -// auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); - -// connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); -// connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); - -// connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); -// connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); - -// menu->exec(pos); -} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h deleted file mode 100644 index 139aa16573a..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ /dev/null @@ -1,148 +0,0 @@ -//============================================================================================================= -/** - * @file fl_rack.h - * @author Gabriel Motta - * Juan Garcia-Prieto - * @since 0.1.9 - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineView class declaration. - * - */ - -#ifndef FIELDLINE_UI_VIEW_H -#define FIELDLINE_UI_VIEW_H - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "fieldline/fieldline_global.h" - -#include "disp/viewers/led_indicator.h" - -#include -#include - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -#include -#include - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// FORWARD DECLARATIONS -//============================================================================================================= - -namespace Ui { - class fl_rack; - class fl_chassis; -} - -//============================================================================================================= -// DEFINE NAMESPACE DISPLIB -//============================================================================================================= - -namespace DISPLIB -{ - -class fl_chassis; - -//============================================================================================================= -class FieldlineView : public QWidget -{ - Q_OBJECT - -public: - explicit FieldlineView(QWidget *parent = nullptr); - FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); - FieldlineView(int num_chassis, QWidget *parent = nullptr); - ~FieldlineView(); - - void configure(int num_chassis); - void configure(int num_chassis, int num_sensors); - - void clear(); - - void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); - void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); - - void setChassisColor(size_t chassis_id, const QColor& color); - void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); - - void setAllColor(const QColor& color); - void setAllColor(const QColor &color, bool blinking); - - void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); - void setChassisBlinkState(size_t chassis_id, bool blinking); - void setAllBlinkState(bool blinking); - - static void setDefaultNumSensors(int num_sensors); -private: - static int default_num_sensors; - - Ui::fl_rack* ui; - std::vector chassis; -}; - -//============================================================================================================= - -class fl_chassis : public QWidget -{ - Q_OBJECT - -public: - fl_chassis(int num_sensors, QWidget *parent = nullptr); - ~fl_chassis(); - - void setColor(size_t sensor_num, const QColor& color); - void setColor(size_t sensor_num, const QColor& color, bool blinking); - void setColor(const QColor& color); - void setColor(const QColor& color, bool blinking); - - void setBlinkState(size_t sensor_num, bool blinking); - void setBlinkState(bool blinking); - -signals: - void clicked(int sensor, const QPoint& pos); - -private slots: - void rightClickMenu(int sensor, const QPoint& pos); - -private: - Ui::fl_chassis* ui; - std::vector sensors; -}; - - -}//namespace DISPLIB - -#endif // FIELDLINE_UI_VIEW_H From 5a1191fd8e63ec8f22cde15557efcfeb0673ac43 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 29 Mar 2023 19:33:49 -0400 Subject: [PATCH 072/147] minor edit style --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 8091ad6ec89..94c9b37881d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -307,4 +307,4 @@ QString Fieldline::getBuildInfo() { return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } -} // namespace FIELDLINEPLUGIN +} // namespace FIELDLINEPLUGIN From 5bf91a20e22e19e5fe5806a58b9cfe6878dd6b96 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 29 Mar 2023 19:37:19 -0400 Subject: [PATCH 073/147] minor update style clang-format --- .clang-format | 216 +++++++++++ .../plugins/fieldline/fieldline_acqsystem.cpp | 145 ++++++++ .../plugins/fieldline/fieldline_acqsystem.h | 57 +++ .../plugins/fieldline/fieldlineview.cpp | 350 ++++++++++++++++++ .../plugins/fieldline/fieldlineview.h | 148 ++++++++ 5 files changed, 916 insertions(+) create mode 100644 .clang-format create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldlineview.h diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000000..3a2e0d14d7f --- /dev/null +++ b/.clang-format @@ -0,0 +1,216 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 101 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RequiresClausePosition: OwnLine +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp new file mode 100644 index 00000000000..484f1aee160 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -0,0 +1,145 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline class. + * + */ +#define PY_SSIZE_T_CLEAN +#include "Python.h" + +#include "fieldline/fieldline.h" +#include "fieldline/fieldline_acqsystem.h" + +#include +#include + +//extern "C" { +// +//PyObject *restartFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - restart finished;\n"; +// } else { +// std::cout << "A sensor has finished restarting!\n"; +// } +// +// return NULL; +//} +//PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - coarse zero finished;\n"; +// } else { +// std::cout << "A sensor has finished coarse zeroing!\n"; +// } +// +// return NULL; +//} +//PyObject *fineZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - fine zero finished;\n"; +// } else { +// std::cout << "A sensor has finished fine zeroing!\n"; +// } +// +// return NULL; +//} +//} +// +//static PyMethodDef my_module_methods[] = { +// {"restartFinished", restartFinished, METH_VARARGS, " "}, +// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, +// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, +// {NULL, NULL, 0, NULL}}; +// +//static PyModuleDef my_module_def = { +// PyModuleDef_HEAD_INIT, +// "mne_cpp_callbacks", +// "A module of callback functions for mne-cpp.", +// -1, +// my_module_methods, +// NULL, +// NULL, +// NULL, +// NULL}; +// +//PyMODINIT_FUNC PyInit_my_module(void) { +// return PyModule_Create(&my_module_def); +//} + +namespace FIELDLINEPLUGIN { + + +FieldlineAcqSystemController::FieldlineAcqSystemController(Fieldline* parent) noexcept +: m_pFieldlinePlugin(parent) { + // pythonInterpreter initiate + // + // run script + // + // find ip + // + // start connection + // + // initialize channels + // + // + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + FILE *py_file = fopen("main.py", "r"); + PyObject *global_dict = PyDict_New(); + PyObject *local_dict = PyDict_New(); + PyObject *result = + PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); +} + + +FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { + // Py_Finalize(); +} + +} // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h new file mode 100644 index 00000000000..6778761ba70 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -0,0 +1,57 @@ +//============================================================================================================= +/** + * @file fieldline_system_controller.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline Acquisition System Controller class. + * + */ +#ifndef FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H +#define FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H + +namespace FIELDLINEPLUGIN { + +class Fieldline; + +class FieldlineAcqSystemController { + public: + FieldlineAcqSystemController(Fieldline* parent) noexcept; + + ~FieldlineAcqSystemController() noexcept; + + + private: + Fieldline* m_pFieldlinePlugin; +}; + + +} // namespace FIELDLINEPLUGIN + +#endif // FIELDLINEPLUGIN_FIELDLINEACQSYSTEMCONTROLLER_H + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp b/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp new file mode 100644 index 00000000000..92ee055db2b --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp @@ -0,0 +1,350 @@ +//============================================================================================================= +/** + * @file fl_rack.cpp + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "fieldline/fieldlineview.h" +#include "fieldline/fieldline.h" +// #include "ui_fieldline_rack.h" +// #include "ui_fieldline_chassis.h" + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include +#include +// #include +// #include +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +// using DISPLIB::FieldlineView; +// using DISPLIB::fl_chassis; +// +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +// int FieldlineView::default_num_sensors = 16; + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + + +namespace FIELDLINEPLUGIN { + + +FieldlineView::FieldlineView(Fieldline* parent) +: m_pFieldlinePlugin(parent) +{ + + +} + +QWidget* FieldlineView::getWidget() const { + + QLabel* label = new QLabel("FieldlineView testing..."); + return label; +} + + +} // namespace FIELDLINEPLUGIN + +// +// FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) +// : FieldlineView(parent) +// { +// configure(num_chassis, sensors_per_chassis); +// } +// +// //============================================================================================================= +// +// FieldlineView::FieldlineView(int num_chassis, QWidget *parent) +// : FieldlineView(num_chassis, default_num_sensors, parent) +// { +// } +// +// //============================================================================================================= +// +// FieldlineView::FieldlineView(QWidget *parent) +// : QWidget(parent) +// , ui(new Ui::fl_rack()) +// { +// ui->setupUi(this); +// } +// //============================================================================================================= +// +// FieldlineView::~FieldlineView() +// { +// delete ui; +// } +// +// //============================================================================================================= +// +// void FieldlineView::configure(int num_chassis) +// { +// configure(num_chassis, default_num_sensors); +// } +// +// //============================================================================================================= +// +// void FieldlineView::configure(int num_chassis, int num_sensors) +// { +// clear(); +// for(int i = 0; i < num_chassis; ++i){ +// chassis.push_back(new fl_chassis(num_sensors)); +// ui->frame->layout()->addWidget(chassis.back()); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineView::clear() +// { +// for(auto* c : chassis){ +// ui->frame->layout()->removeWidget(c); +// c->deleteLater(); +// } +// }; +// +// //============================================================================================================= +// +// void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setColor(sensor_num, color); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setColor(sensor_num, color, blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setColor(color); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setChassisColor(size_t chassis_id, const QColor& color, bool blinking) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setColor(color, blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setAllColor(const QColor& color) +// { +// for(auto* c : chassis){ +// c->setColor(color); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineView::setAllColor(const QColor& color, bool blinking) +// { +// for(auto* c : chassis){ +// c->setColor(color, blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineView::setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setChassisBlinkState(size_t chassis_id, bool blinking) +// { +// if(chassis_id >= chassis.size()){ +// return; +// } +// chassis.at(chassis_id)->setBlinkState(blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineView::setAllBlinkState(bool blinking) +// { +// for(auto* c : chassis){ +// c->setBlinkState(blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineView::setDefaultNumSensors(int num_sensors) +// { +// default_num_sensors = num_sensors; +// } +// +// //============================================================================================================= +// +// fl_chassis::fl_chassis(int num_sensors, QWidget *parent ) +// : QWidget(parent) +// , ui(new Ui::fl_chassis()) +// { +// ui->setupUi(this); +// +// for(int i = 0; i < num_sensors; ++i){ +// sensors.push_back(new LEDIndicator()); +// auto& last_item = sensors.back(); +// sensors.back()->setLabel(QString::number(i + 1)); +// ui->sensor_frame->layout()->addWidget(sensors.back()); +// connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); +// connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); +// } +// } +// +// //============================================================================================================= +// +// fl_chassis::~fl_chassis() +// { +// delete ui; +// } +// +// //============================================================================================================= +// +// void fl_chassis::setColor(size_t sensor_num, const QColor& color) +// { +// if(sensor_num > sensors.size() || sensor_num < 1){ +// return; +// } +// sensors.at(sensor_num - 1)->setColor(color); +// } +// +// //============================================================================================================= +// +// void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) +// { +// setColor(sensor_num, color); +// setBlinkState(sensor_num, blinking); +// } +// +// //============================================================================================================= +// +// void fl_chassis::setColor(const QColor& color) +// { +// for(auto* sensor : sensors){ +// sensor->setColor(color); +// } +// } +// +// //============================================================================================================= +// +// void fl_chassis::setColor(const QColor& color, bool blinking) +// { +// for(auto* sensor : sensors){ +// sensor->setColor(color); +// sensor->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) +// { +// if(sensor_num > sensors.size() || sensor_num < 1){ +// return; +// } +// sensors.at(sensor_num - 1)->setBlink(blinking); +// } +// +// //============================================================================================================= +// +// void fl_chassis::setBlinkState(bool blinking) +// { +// for(auto* sensor : sensors){ +// sensor->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) +// { +// // auto* menu = new QMenu(); +// +// // auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); +// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); +// +// // auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); +// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); +// +// // connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); +// // connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); +// +// // connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); +// // connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); +// +// // menu->exec(pos); +// } +// +// +// diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h b/src/applications/mne_scan/plugins/fieldline/fieldlineview.h new file mode 100644 index 00000000000..799bd89a6fa --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldlineview.h @@ -0,0 +1,148 @@ +//============================================================================================================= +/** + * @file fl_rack.h + * @author Gabriel Motta + * Juan Garcia-Prieto + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + +#ifndef FIELDLINE_FIELDLINEVIEW_H +#define FIELDLINE_FIELDLINEVIEW_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +// #include "disp/viewers/led_indicator.h" + +// #include +// #include +// +// //============================================================================================================= +// // QT INCLUDES +// //============================================================================================================= +// +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +class QWidget; +// namespace Ui { +// class fieldline_rack; +// class fieldline_chassis; +// } + +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace FIELDLINEPLUGIN { + +class Fieldline; +// class fieldline_chassis; + +//============================================================================================================= +class FieldlineView /*: public QWidget */ { + // Q_OBJECT + +public: + FieldlineView(Fieldline* parent); + + QWidget* getWidget() const; + // FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); + // FieldlineView(int num_chassis, QWidget *parent = nullptr); + // ~FieldlineView(); + // + // void configure(int num_chassis); + // void configure(int num_chassis, int num_sensors); + // + // void clear(); + // + // void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); + // void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); + // + // void setChassisColor(size_t chassis_id, const QColor& color); + // void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); + // + // void setAllColor(const QColor& color); + // void setAllColor(const QColor &color, bool blinking); + // + // void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); + // void setChassisBlinkState(size_t chassis_id, bool blinking); + // void setAllBlinkState(bool blinking); + // + // static void setDefaultNumSensors(int num_sensors); +private: + // static int default_num_sensors; + // + // Ui::fieldline_rack* ui; + // std::vector chassis; + Fieldline* m_pFieldlinePlugin; +}; + +//============================================================================================================= + +// class fieldline_chassis : public QWidget +// { +// Q_OBJECT +// +// public: +// fl_chassis(int num_sensors, QWidget *parent = nullptr); +// ~fl_chassis(); +// +// void setColor(size_t sensor_num, const QColor& color); +// void setColor(size_t sensor_num, const QColor& color, bool blinking); +// void setColor(const QColor& color); +// void setColor(const QColor& color, bool blinking); +// +// void setBlinkState(size_t sensor_num, bool blinking); +// void setBlinkState(bool blinking); +// +// signals: +// void clicked(int sensor, const QPoint& pos); +// +// private slots: +// void rightClickMenu(int sensor, const QPoint& pos); +// +// private: +// Ui::fl_chassis* ui; +// std::vector sensors; +// }; + + +} // namespace FIELDLINEPLUGIN + +#endif // FIELDLINE_UI_VIEW_H From 2197899fdb224878dcbccd9f9f8c7e20896f9ebc Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 30 Mar 2023 13:12:13 -0400 Subject: [PATCH 074/147] add clang-format file to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0f9952f4e7e..aa1b63746bf 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ Makefile .settings .vscode .session +.clang-format mne-cpp.pro.user* compile_commands.json From 3e9046e33eaa52d1deae903e10cb415329e4a21e Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 30 Mar 2023 13:13:16 -0400 Subject: [PATCH 075/147] minr edits --- .clang-format | 216 ------------------ .../mne_scan/plugins/fieldline/fieldline.h | 1 + .../plugins/fieldline/fieldline_acqsystem.h | 1 - .../plugins/fieldline/fieldlineview.cpp | 2 - 4 files changed, 1 insertion(+), 219 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 3a2e0d14d7f..00000000000 --- a/.clang-format +++ /dev/null @@ -1,216 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: true -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -AttributeMacros: - - __capability -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 101 -CommentPragmas: '^ IWYU pragma:' -QualifierAlignment: Leave -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DeriveLineEnding: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -PackConstructorInitializers: BinPack -BasedOnStyle: '' -ConstructorInitializerAllOnOneLineOrOnePerLine: false -AllowAllConstructorInitializersOnNextLine: true -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseLabels: false -IndentCaseBlocks: false -IndentGotoLabels: true -IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertTrailingCommas: None -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -LambdaBodyIndentation: Signature -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PenaltyIndentedWhitespace: 0 -PointerAlignment: Right -PPIndentWidth: -1 -ReferenceAlignment: Pointer -ReflowComments: true -RemoveBracesLLVM: false -RequiresClausePosition: OwnLine -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceAroundPointerQualifiers: Default -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParentheses: false -SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -BitFieldColonSpacing: Both -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseCRLF: false -UseTab: Never -WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - - BOOST_PP_STRINGIZE - - NS_SWIFT_NAME - - CF_SWIFT_NAME -... - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index cf3d9ab0a3c..10c9aa403aa 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -146,3 +146,4 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { } // namespace FIELDLINEPLUGIN #endif // FIELDLINE_H + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 6778761ba70..a3d2e0d19ea 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -45,7 +45,6 @@ class FieldlineAcqSystemController { ~FieldlineAcqSystemController() noexcept; - private: Fieldline* m_pFieldlinePlugin; }; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp b/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp index 92ee055db2b..37ad0d42fbc 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp @@ -80,8 +80,6 @@ namespace FIELDLINEPLUGIN { FieldlineView::FieldlineView(Fieldline* parent) : m_pFieldlinePlugin(parent) { - - } QWidget* FieldlineView::getWidget() const { From 980c16e3b83b16fd38aed4566eb263389c9473c2 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Mon, 3 Apr 2023 13:36:50 -0400 Subject: [PATCH 076/147] add differentiation of component classes and resources --- resources/mne_scan/plugins/fieldline/main.py | 1 + .../mne_scan/plugins/fieldline/fieldline.h | 24 ++++--------------- .../plugins/fieldline/fieldline_acqsystem.cpp | 15 +++++++++--- .../plugins/fieldline/fieldline_acqsystem.h | 8 ++++++- .../mne_scan/plugins/fieldline/python/main.py | 1 + .../mne_scan/plugins/fieldline/python/test.py | 0 6 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 resources/mne_scan/plugins/fieldline/main.py create mode 100644 src/applications/mne_scan/plugins/fieldline/python/main.py create mode 100644 src/applications/mne_scan/plugins/fieldline/python/test.py diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py new file mode 100644 index 00000000000..b727a0ebb90 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -0,0 +1 @@ +print("hello pepe!!") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 10c9aa403aa..d41e3825e75 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -75,9 +75,9 @@ class FieldlineView; //============================================================================================================= /** - * The Fieldline class provides a EEG connector for receiving data from Fieldline box through its Python API. + * The Fieldline class provides a MEG connector for receiving data from Fieldline box through its Python API. * - * @brief The Fieldline class provides a EEG connector for receiving data from Fieldline API. + * @brief The Fieldline class provides a MEG connector for receiving data from Fieldline API. */ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { Q_OBJECT @@ -89,7 +89,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { public: //========================================================================================================= - // The plugin interface + // The plugin interface Fieldline(); ~Fieldline(); @@ -113,20 +113,6 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { virtual QString getBuildInfo(); protected: - //========================================================================================================= - /** - * Call this function whenenver you received new data. - * - * @param[in] matData The new data. - */ - // void onNewDataAvailable(const Eigen::MatrixXd &matData); - - //========================================================================================================= - /** - * the starting point for the thread. after calling start(), the newly created thread calls this function. - * returning from this method will end the execution of the thread. - * pure virtual method inherited by qthread. - */ virtual void run(); std::unique_ptr acqSystem; @@ -135,11 +121,11 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ // int m_iNumberChannels; /**< The number of channels to be received.*/ // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - // QString m_qStringResourcePath; /**< The path to the EEG resource directory.*/ + // QString m_qStringResourcePath; /**< The path to the MEG resource directory.*/ // QThread m_pProducerThread; /**< The thread used to host the producer.*/ // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ - // + QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 484f1aee160..79aa95755ee 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -105,10 +105,13 @@ //} namespace FIELDLINEPLUGIN { +namespace FeildlineAcqSystemController { -FieldlineAcqSystemController::FieldlineAcqSystemController(Fieldline* parent) noexcept -: m_pFieldlinePlugin(parent) { +FieldlineAcqSystemController(Fieldline* parent, + const std::string& resourcesPath) noexcept +: m_pFieldlinePlugin(parent), m_resourcesDir(resourcesPath) +{ // pythonInterpreter initiate // // run script @@ -138,8 +141,14 @@ FieldlineAcqSystemController::FieldlineAcqSystemController(Fieldline* parent) no } -FieldlineAcqSystemController::~FieldlineAcqSystemController() noexcept { +~FieldlineAcqSystemController() noexcept { // Py_Finalize(); } +void setResourcesDir(const std::string& path) { + m_resourcesDir = path; +} + +} // namespace FieldlineAcqSystemController + } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index a3d2e0d19ea..f90a476fb98 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -35,18 +35,24 @@ #ifndef FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H #define FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H +#include + namespace FIELDLINEPLUGIN { class Fieldline; class FieldlineAcqSystemController { public: - FieldlineAcqSystemController(Fieldline* parent) noexcept; + FieldlineAcqSystemController(Fieldline* parent, + const std::string& resourcesPath) noexcept; ~FieldlineAcqSystemController() noexcept; + void setResourcesDir(const std::string& path); + private: Fieldline* m_pFieldlinePlugin; + std::string m_resourcesDir; }; diff --git a/src/applications/mne_scan/plugins/fieldline/python/main.py b/src/applications/mne_scan/plugins/fieldline/python/main.py new file mode 100644 index 00000000000..b727a0ebb90 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/python/main.py @@ -0,0 +1 @@ +print("hello pepe!!") diff --git a/src/applications/mne_scan/plugins/fieldline/python/test.py b/src/applications/mne_scan/plugins/fieldline/python/test.py new file mode 100644 index 00000000000..e69de29bb2d From 5678bd292d54fbe842741b6ba51fb34f9eeb2df3 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Mon, 3 Apr 2023 15:48:38 -0400 Subject: [PATCH 077/147] make path to resources work correctly --- main.py | 1 - .../mne_scan/plugins/fieldline/fieldline.cpp | 2 +- .../mne_scan/plugins/fieldline/fieldline.h | 4 +-- .../plugins/fieldline/fieldline_acqsystem.cpp | 36 ++++++++++--------- .../plugins/fieldline/fieldline_acqsystem.h | 14 +++----- 5 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index b727a0ebb90..00000000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -print("hello pepe!!") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 94c9b37881d..eeb23eb7c57 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -164,7 +164,7 @@ void Fieldline::init() { "FieldlinePlguin output"); m_outputConnectors.append(m_pRTMSA); - acqSystem = std::make_unique(this); + acqSystem = std::make_unique(this); guiWidget = std::make_unique(this); } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index d41e3825e75..b40eb02139c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -70,7 +70,7 @@ class FiffInfo; namespace FIELDLINEPLUGIN { -class FieldlineAcqSystemController; +class FieldlineAcqSystem; class FieldlineView; //============================================================================================================= @@ -115,7 +115,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { protected: virtual void run(); - std::unique_ptr acqSystem; + std::unique_ptr acqSystem; std::unique_ptr guiWidget; // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 79aa95755ee..2442c35c8af 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -40,12 +40,15 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "fieldline/fieldline.h" -#include "fieldline/fieldline_acqsystem.h" - #include +#include #include +#include + +#include "fieldline/fieldline.h" +#include "fieldline/fieldline_acqsystem.h" + //extern "C" { // //PyObject *restartFinished(PyObject *self, PyObject *args) { @@ -105,12 +108,10 @@ //} namespace FIELDLINEPLUGIN { -namespace FeildlineAcqSystemController { -FieldlineAcqSystemController(Fieldline* parent, - const std::string& resourcesPath) noexcept -: m_pFieldlinePlugin(parent), m_resourcesDir(resourcesPath) +FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) +: m_pControllerParent(parent) { // pythonInterpreter initiate // @@ -123,13 +124,19 @@ FieldlineAcqSystemController(Fieldline* parent, // initialize channels // // + + const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline"); + const std::wstring resourcesPath_w(resourcesPath.begin(), resourcesPath.end()); + const std::string entryFile(resourcesPath + "/main.py"); + Py_Initialize(); PyConfig config; PyConfig_InitPythonConfig(&config); config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, L"."); + PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str()); + // PyWideStringList_Append(&config.module_search_paths,L"."); Py_InitializeFromConfig(&config); - FILE *py_file = fopen("main.py", "r"); + FILE *py_file = fopen(entryFile.c_str(), "r"); PyObject *global_dict = PyDict_New(); PyObject *local_dict = PyDict_New(); PyObject *result = @@ -140,15 +147,10 @@ FieldlineAcqSystemController(Fieldline* parent, fclose(py_file); } - -~FieldlineAcqSystemController() noexcept { +FieldlineAcqSystem::~FieldlineAcqSystem() +{ + qDebug() << "About to finalize python"; // Py_Finalize(); } -void setResourcesDir(const std::string& path) { - m_resourcesDir = path; -} - -} // namespace FieldlineAcqSystemController - } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index f90a476fb98..83383adbe2d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -35,24 +35,18 @@ #ifndef FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H #define FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H -#include - namespace FIELDLINEPLUGIN { class Fieldline; -class FieldlineAcqSystemController { +class FieldlineAcqSystem { public: - FieldlineAcqSystemController(Fieldline* parent, - const std::string& resourcesPath) noexcept; - - ~FieldlineAcqSystemController() noexcept; + FieldlineAcqSystem(Fieldline* parent); - void setResourcesDir(const std::string& path); + ~FieldlineAcqSystem(); private: - Fieldline* m_pFieldlinePlugin; - std::string m_resourcesDir; + Fieldline* m_pControllerParent; }; From 8834af5640968da1b58cb0c4e3fa4ff475cad673 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 18:08:50 -0400 Subject: [PATCH 078/147] python initialization almost ready --- .../plugins/fieldline/fieldline_acqsystem.cpp | 86 +++++++++++++------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 2442c35c8af..b49d61ad1ce 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -109,42 +109,78 @@ namespace FIELDLINEPLUGIN { - FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { - // pythonInterpreter initiate - // - // run script - // - // find ip - // - // start connection - // - // initialize channels - // - // - - const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline"); + const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); + const std::string base_exec_prefix(resourcesPath + "venv/"); + const std::string base_executable(base_exec_prefix + "bin/python"); + const std::string base_prefix(base_exec_prefix); + const std::string exec_prefix(base_exec_prefix); + const std::string executable(base_executable); + const std::string homePath(resourcesPath + "venv/lib/python3.9"); + const std::string path_venv_modules(resourcesPath + "venv/lib/python3.9/site-packages"); + const std::string path_env(resourcesPath + ":" + path_venv_modules); + const std::string entryFile(resourcesPath + "main.py"); + const std::wstring resourcesPath_w(resourcesPath.begin(), resourcesPath.end()); - const std::string entryFile(resourcesPath + "/main.py"); +// PyStatus status; +// PyConfig config; +// PyConfig_InitPythonConfig(&config); +// +// // status = PyConfig_SetBytesString(&config, &config.home, homePath.c_str()); +// // status = PyConfig_SetBytesString(&config, &config.platlibdir, "lib"); +// // status = PyConfig_SetBytesString(&config, &config.program_name, "mne_scan - fieldline opm"); +// // config.pathconfig_warnings = 1; +// // status = PyConfig_SetBytesString(&config, &config.pythonpath_env, path_env.c_str()); +// // +// // status = PyConfig_SetBytesString(&config, &config.base_exec_prefix, base_exec_prefix.c_str()); +// status = PyConfig_SetBytesString(&config, &config.base_executable, base_executable.c_str()); +// // status = PyConfig_SetBytesString(&config, &config.base_prefix, base_prefix.c_str()); +// // status = PyConfig_SetBytesString(&config, &config.exec_prefix, exec_prefix.c_str()); +// status = PyConfig_SetBytesString(&config, &config.executable, executable.c_str()); +// config.module_search_paths_set = 1; +// status = PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str()); +// // status = PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str() + ); +// // +// status = Py_InitializeFromConfig(&config); +// PyConfig_Clear(&config); Py_Initialize(); - PyConfig config; - PyConfig_InitPythonConfig(&config); - config.module_search_paths_set = 1; - PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str()); - // PyWideStringList_Append(&config.module_search_paths,L"."); - Py_InitializeFromConfig(&config); + + PyObject* sys = PyImport_ImportModule("sys"); + + PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); + PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); + PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); + + int versionMajor = PyLong_AsLong(versionInfoMajor); + int versionMinor = PyLong_AsLong(versionInfoMinor); + // if (PyLong_Check(versionMajor)) { + std::cout << "version major is " << versionMajor << "\n"; + std::cout << "version minor is " << versionMinor << "\n"; + // } + Py_DECREF(versionInfoMajor); + Py_DECREF(versionInfoMinor); + Py_DECREF(versionInfo); + + PyObject* path = PyObject_GetAttrString(sys, "path"); + + PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); + PyList_Insert(path, 1, PyUnicode_FromString(path_venv_modules.c_str())); + Py_DECREF(sys); + Py_DECREF(path); + + FILE *py_file = fopen(entryFile.c_str(), "r"); - PyObject *global_dict = PyDict_New(); - PyObject *local_dict = PyDict_New(); - PyObject *result = - PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); Py_DECREF(global_dict); Py_DECREF(local_dict); Py_DECREF(result); fclose(py_file); + Py_Finalize(); } FieldlineAcqSystem::~FieldlineAcqSystem() From cb1e4df5ebbcc7bb6d6d89cc00e14d6aae402f95 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 19:42:25 -0400 Subject: [PATCH 079/147] plugin fieldline functions refactoring --- .../plugins/fieldline/fieldline_acqsystem.cpp | 71 ++++++------------- .../plugins/fieldline/fieldline_acqsystem.h | 11 +-- 2 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index b49d61ad1ce..898f49ca647 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -109,84 +109,55 @@ namespace FIELDLINEPLUGIN { +const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); +const std::string entryFile(resourcesPath + "main.py"); + FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { - const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); - const std::string base_exec_prefix(resourcesPath + "venv/"); - const std::string base_executable(base_exec_prefix + "bin/python"); - const std::string base_prefix(base_exec_prefix); - const std::string exec_prefix(base_exec_prefix); - const std::string executable(base_executable); - const std::string homePath(resourcesPath + "venv/lib/python3.9"); - const std::string path_venv_modules(resourcesPath + "venv/lib/python3.9/site-packages"); - const std::string path_env(resourcesPath + ":" + path_venv_modules); - const std::string entryFile(resourcesPath + "main.py"); + preConfigurePython(); + runPythonFile(entryFile.c_str(), "main.py"); +} - const std::wstring resourcesPath_w(resourcesPath.begin(), resourcesPath.end()); +FieldlineAcqSystem::~FieldlineAcqSystem() +{ + qDebug() << "About to finalize python"; + Py_Finalize(); +} -// PyStatus status; -// PyConfig config; -// PyConfig_InitPythonConfig(&config); -// -// // status = PyConfig_SetBytesString(&config, &config.home, homePath.c_str()); -// // status = PyConfig_SetBytesString(&config, &config.platlibdir, "lib"); -// // status = PyConfig_SetBytesString(&config, &config.program_name, "mne_scan - fieldline opm"); -// // config.pathconfig_warnings = 1; -// // status = PyConfig_SetBytesString(&config, &config.pythonpath_env, path_env.c_str()); -// // -// // status = PyConfig_SetBytesString(&config, &config.base_exec_prefix, base_exec_prefix.c_str()); -// status = PyConfig_SetBytesString(&config, &config.base_executable, base_executable.c_str()); -// // status = PyConfig_SetBytesString(&config, &config.base_prefix, base_prefix.c_str()); -// // status = PyConfig_SetBytesString(&config, &config.exec_prefix, exec_prefix.c_str()); -// status = PyConfig_SetBytesString(&config, &config.executable, executable.c_str()); -// config.module_search_paths_set = 1; -// status = PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str()); -// // status = PyWideStringList_Append(&config.module_search_paths, resourcesPath_w.c_str() + ); -// // -// status = Py_InitializeFromConfig(&config); -// PyConfig_Clear(&config); +void FieldlineAcqSystem::preConfigurePython() const { Py_Initialize(); - PyObject* sys = PyImport_ImportModule("sys"); - PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); - int versionMajor = PyLong_AsLong(versionInfoMajor); - int versionMinor = PyLong_AsLong(versionInfoMinor); - // if (PyLong_Check(versionMajor)) { - std::cout << "version major is " << versionMajor << "\n"; - std::cout << "version minor is " << versionMinor << "\n"; - // } + std::string pythonVerStr("pythonx.x/"); + pythonVerStr.at(6) = '0' + PyLong_AsLong(versionInfoMajor); + pythonVerStr.at(8) = '0' + PyLong_AsLong(versionInfoMinor); + Py_DECREF(versionInfoMajor); Py_DECREF(versionInfoMinor); Py_DECREF(versionInfo); PyObject* path = PyObject_GetAttrString(sys, "path"); + const std::string path_venv_modules(resourcesPath + "venv/lib/" + pythonVerStr + "site-packages/"); PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); PyList_Insert(path, 1, PyUnicode_FromString(path_venv_modules.c_str())); Py_DECREF(sys); Py_DECREF(path); +} - - FILE *py_file = fopen(entryFile.c_str(), "r"); +void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { + FILE *py_file = fopen(file, "r"); PyObject* global_dict = PyDict_New(); PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, "main.py", Py_file_input, global_dict, local_dict); + PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); Py_DECREF(global_dict); Py_DECREF(local_dict); Py_DECREF(result); fclose(py_file); - Py_Finalize(); -} - -FieldlineAcqSystem::~FieldlineAcqSystem() -{ - qDebug() << "About to finalize python"; - // Py_Finalize(); } } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 83383adbe2d..fef01a32109 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -40,12 +40,15 @@ namespace FIELDLINEPLUGIN { class Fieldline; class FieldlineAcqSystem { - public: - FieldlineAcqSystem(Fieldline* parent); +public: + FieldlineAcqSystem(Fieldline* parent); - ~FieldlineAcqSystem(); + ~FieldlineAcqSystem(); + +private: + void preConfigurePython() const; + void runPythonFile(const char* file, const char* comment) const; - private: Fieldline* m_pControllerParent; }; From f5cdce4a69215205496f206705a51c963df2f3ef Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 19:43:46 -0400 Subject: [PATCH 080/147] update main plugin to show import resolution --- resources/mne_scan/plugins/fieldline/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index b727a0ebb90..7ac14325e4c 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1 +1,12 @@ -print("hello pepe!!") +"""This is my super module""" +import sys + +for path in sys.path: + print(path) + +print("sys.executable: " + str(sys.executable)) + +print("hello pepe vamos vamos!!!") + +from test import core +core.sayHi("Antonio") From e4a9a98c5c930bb8a4b87a3c8c6c5ba7b8d16f1d Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 19:47:06 -0400 Subject: [PATCH 081/147] add example and debug python scripts to resources fieldline --- .../mne_scan/plugins/fieldline/readme.md | 21 +++++++++++++++++++ .../plugins/fieldline/test/__init__.py | 0 .../mne_scan/plugins/fieldline/test/core.py | 10 +++++++++ 3 files changed, 31 insertions(+) create mode 100644 resources/mne_scan/plugins/fieldline/readme.md create mode 100644 resources/mne_scan/plugins/fieldline/test/__init__.py create mode 100644 resources/mne_scan/plugins/fieldline/test/core.py diff --git a/resources/mne_scan/plugins/fieldline/readme.md b/resources/mne_scan/plugins/fieldline/readme.md new file mode 100644 index 00000000000..97f7d89bc1f --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/readme.md @@ -0,0 +1,21 @@ +FieldLine API README + +Prerequisits: +- Python 3.8 needs to be installed - due to an issue in the shared memory library that was fixed +- Download api-example.zip and fieldline_api_XXX.whl + +1) Download and extract api-example.zip +2) cd api-example +3) python3.8 -m venv venv +4) . venv/bin/activate +5) pip install -r requirements-api.txt +6) pip install +7) python main.py + +Release Notes: +0.0.13 - add SENSOR_READY state +0.0.12 - fix wrong file include +0.0.11 - Add sensor status call +0.0.10 - Few API cleanup items +0.0.2 - add start_adc and stop_adc calls +0.0.1 - initial release diff --git a/resources/mne_scan/plugins/fieldline/test/__init__.py b/resources/mne_scan/plugins/fieldline/test/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/resources/mne_scan/plugins/fieldline/test/core.py b/resources/mne_scan/plugins/fieldline/test/core.py new file mode 100644 index 00000000000..c28a3607ce6 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/test/core.py @@ -0,0 +1,10 @@ + +def sayHi(name): + print("Hey " + name + ", hello from secondary!") + +class Person: + def __init__(self, name, age): + self.name = name + self.age = age + + From 2e264fbea316a8cfe03965b8de0f4611a8b64201 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 19:49:29 -0400 Subject: [PATCH 082/147] update gitignore to avoid pushing python cache files and wheels --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aa1b63746bf..a1cc1d862a9 100644 --- a/.gitignore +++ b/.gitignore @@ -72,7 +72,8 @@ compile_commands.json # Resources folders /src/external/fftw /resources/data* - +__pycache__/ +*.whl .cache/* codecov From 8a6389a9d75d04c135680fbecad9b52d7de75a9e Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 20:15:49 -0400 Subject: [PATCH 083/147] update cmakelists to check for linux and automate python finding --- src/applications/mne_scan/plugins/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 428ec8d8392..6ed4201c835 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,7 +17,9 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -add_subdirectory(fieldline) +if (UNIX) + add_subdirectory(fieldline) +endif() # Algorithm Plugin add_subdirectory(rtcmne) From b7807ade560589a1237a9c7c4a5189688e109702 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 20:16:32 -0400 Subject: [PATCH 084/147] update cmakelists work generic python installation --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index ff679aa5ac1..9d86d5e54bd 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -11,50 +11,16 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) find_package(Python REQUIRED COMPONENTS Interpreter Development) -#cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) - -#if(AWK MATCHES ".+-NOTFOUND") -# message(FATAL_ERROR "FATAL: awk (and mawk and gawk) could not be found (${AWK}).") -#else() -# execute_process( -# COMMAND /bin/sh -c "\"${AWK}\" '$1 ~ /^#define/ && $2 ~ /^LIB_(MAJVER|MINVER|PATCH|BUILD)$/\ { print \"set(\${PRJNAME}_\" $2 \" \" $3 \")\" }' \"${CMAKE_SOURCE_DIR}/version.h\"" -# RESULT_VARIABLE AWK_EXITCODE -# OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/version.cmake" -# ) -# message(STATUS "Exit code from awk: ${AWK_EXITCODE}") -# include(${CMAKE_CURRENT_BINARY_DIR}/version.cmake) -#endif() - -#set(Python_EXECUTABLE /autofs/cluster/fusion/juan/anaconda3/bin/python) -#cmake_path(GET Python_EXECUTABLE PARENT_PATH Python_BIN_DIR) -#if (WIN32) -# execute_process(COMMAND CMD /c echo bar OUTPUT_VARIABLE FOO) -#else() -# message("holaaaaaaa") -# execute_process( -# COMMAND "python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(minor)'" -# OUTPUT_VARIABLE Python_version) -#endif (WIN32) -#message("Python executable: " ${Python_EXECUTABLE}) -#message("Python_version: " ${Python_version}) -# -# execute_process( -# COMMAND /bin/sh -c "\"${AWK}\" '$1 ~ /^#define/ && $2 ~ /^LIB_(MAJVER|MINVER|PATCH|BUILD)$/\ { print \"set(\${PRJNAME}_\" $2 \" \" $3 \")\" }' \"${CMAKE_SOURCE_DIR}/version.h\"" -# RESULT_VARIABLE AWK_EXITCODE -# OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/version.cmake" -# ) -# -set(ANACONDA_DIR /opt/anaconda3) -# set(ANACONDA_DIR /autofs/cluster/fusion/juan/anaconda3) -set(Python_BIN_DIR ${ANACONDA_DIR}/bin) -set(Python_LIB_DIR ${ANACONDA_DIR}/lib) -set(Python_EXECUTABLE ${Python_BIN_DIR}/python) -#execute_process( -# COMMAND "echo $(dirname $(which ${ANACONDA_DIR}/bin/python))" -# WORKING_DIRECTORY . -# OUTPUT_VARIABLE Python_BIN_DIR -#) +execute_process( + COMMAND echo $(cd $(dirname $(dirname $(which python))/../..); pwd -P) + OUTPUT_VARIABLE Python_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(Python_BIN_DIR ${Python_PREFIX}/bin) +set(Python_LIB_DIR ${Python_PREFIX}/lib) +set(Python_EXECUTABLE ${Python_BIN_DIR}/python) execute_process( COMMAND ${Python_BIN_DIR}/python -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" From d3b8ce3446b6605797d24865f9270bac2b51159e Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 20:17:57 -0400 Subject: [PATCH 085/147] minr edits formatting --- .../mne_scan/plugins/fieldline/fieldline_acqsystem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 898f49ca647..6279b18550d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -109,7 +109,8 @@ namespace FIELDLINEPLUGIN { -const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); +const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + \ + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) @@ -142,7 +143,8 @@ void FieldlineAcqSystem::preConfigurePython() const { PyObject* path = PyObject_GetAttrString(sys, "path"); - const std::string path_venv_modules(resourcesPath + "venv/lib/" + pythonVerStr + "site-packages/"); + const std::string path_venv_modules(resourcesPath + "venv/lib/" + \ + pythonVerStr + "site-packages/"); PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); PyList_Insert(path, 1, PyUnicode_FromString(path_venv_modules.c_str())); Py_DECREF(sys); From 9e3ad81101628ad56a29a0c0edf8b83cbe4ce855 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 20:19:47 -0400 Subject: [PATCH 086/147] add venv folders to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a1cc1d862a9..2269466801d 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ compile_commands.json /src/external/fftw /resources/data* __pycache__/ +venv/ *.whl .cache/* From 8557107fe62844e0ea7b280210d56722e046d2be Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 4 Apr 2023 20:21:50 -0400 Subject: [PATCH 087/147] udpate python testing scripts --- resources/mne_scan/plugins/fieldline/main.py | 3 ++- resources/mne_scan/plugins/fieldline/test/core.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index 7ac14325e4c..69467085f34 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,5 +1,6 @@ """This is my super module""" import sys +from test import core for path in sys.path: print(path) @@ -8,5 +9,5 @@ print("hello pepe vamos vamos!!!") -from test import core core.sayHi("Antonio") + diff --git a/resources/mne_scan/plugins/fieldline/test/core.py b/resources/mne_scan/plugins/fieldline/test/core.py index c28a3607ce6..610d29da31d 100644 --- a/resources/mne_scan/plugins/fieldline/test/core.py +++ b/resources/mne_scan/plugins/fieldline/test/core.py @@ -7,4 +7,3 @@ def __init__(self, name, age): self.name = name self.age = age - From 9324ffb69c0367dfc33c5f39a5d2ec18d160ad87 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 5 Apr 2023 12:58:12 -0400 Subject: [PATCH 088/147] opm fieldline python working --- resources/mne_scan/plugins/fieldline/main.py | 3 -- .../plugins/fieldline/test/__init__.py | 0 .../mne_scan/plugins/fieldline/test/core.py | 9 ----- .../mne_scan/plugins/fieldline/CMakeLists.txt | 34 ++++++++++++++----- .../mne_scan/plugins/fieldline/fieldline.cpp | 9 ++--- .../plugins/fieldline/fieldline_acqsystem.cpp | 22 ++++++------ .../plugins/fieldline/fieldlineview.h | 5 +-- 7 files changed, 44 insertions(+), 38 deletions(-) delete mode 100644 resources/mne_scan/plugins/fieldline/test/__init__.py delete mode 100644 resources/mne_scan/plugins/fieldline/test/core.py diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index 69467085f34..d97d0fe27e3 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,6 +1,5 @@ """This is my super module""" import sys -from test import core for path in sys.path: print(path) @@ -9,5 +8,3 @@ print("hello pepe vamos vamos!!!") -core.sayHi("Antonio") - diff --git a/resources/mne_scan/plugins/fieldline/test/__init__.py b/resources/mne_scan/plugins/fieldline/test/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/resources/mne_scan/plugins/fieldline/test/core.py b/resources/mne_scan/plugins/fieldline/test/core.py deleted file mode 100644 index 610d29da31d..00000000000 --- a/resources/mne_scan/plugins/fieldline/test/core.py +++ /dev/null @@ -1,9 +0,0 @@ - -def sayHi(name): - print("Hey " + name + ", hello from secondary!") - -class Person: - def __init__(self, name, age): - self.name = name - self.age = age - diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 9d86d5e54bd..e4e5121e911 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -7,23 +7,40 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(QT NAMES Qt6 Qt5 REQUIRED - COMPONENTS Core Widgets Network Concurrent) + COMPONENTS Core Widgets Network Concurrent +) find_package(Qt${QT_VERSION_MAJOR} REQUIRED - COMPONENTS Core Widgets Network Concurrent) -find_package(Python REQUIRED COMPONENTS Interpreter Development) + COMPONENTS Core Widgets Network Concurrent +) execute_process( - COMMAND echo $(cd $(dirname $(dirname $(which python))/../..); pwd -P) + COMMAND which python + OUTPUT_VARIABLE Python_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND dirname ${Python_EXECUTABLE} + OUTPUT_VARIABLE Python_BIN_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND pwd -P + WORKING_DIRECTORY ${Python_BIN_DIR}/.. OUTPUT_VARIABLE Python_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE ) -set(Python_BIN_DIR ${Python_PREFIX}/bin) -set(Python_LIB_DIR ${Python_PREFIX}/lib) -set(Python_EXECUTABLE ${Python_BIN_DIR}/python) +execute_process( + COMMAND pwd -P + WORKING_DIRECTORY ${Python_PREFIX}/lib + OUTPUT_VARIABLE Python_LIB_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) execute_process( - COMMAND ${Python_BIN_DIR}/python -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" + COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" OUTPUT_VARIABLE Python_VERSION_MAJOR OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -59,6 +76,7 @@ execute_process( separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") +message( "python prefix dir: " ${Python_PREFIX}) message( "python bin dir: " ${Python_BIN_DIR}) message( "python lib dir: " ${Python_LIB_DIR}) message( "python executable: " ${Python_EXECUTABLE}) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index eeb23eb7c57..3e66b2ce44c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,7 +44,7 @@ #include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" -#include "fieldline/fieldlineview.h" +#include "fieldline/fieldlineview.h" #include // #include @@ -149,15 +149,16 @@ Fieldline::~Fieldline() { //============================================================================================================= -QSharedPointer Fieldline::clone() const { +QSharedPointer Fieldline::clone() const +{ QSharedPointer pFieldlineClone(new Fieldline()); return pFieldlineClone; } //============================================================================================================= -void Fieldline::init() { - +void Fieldline::init() +{ // data infrastructure m_pRTMSA = SCSHAREDLIB::PluginOutputData ::create(this, "Fieldline Plugin", diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 6279b18550d..7db292937e9 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -120,38 +120,36 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) runPythonFile(entryFile.c_str(), "main.py"); } -FieldlineAcqSystem::~FieldlineAcqSystem() +FieldlineAcqSystem::~FieldlineAcqSystem() { qDebug() << "About to finalize python"; Py_Finalize(); } -void FieldlineAcqSystem::preConfigurePython() const { +void FieldlineAcqSystem::preConfigurePython() const +{ Py_Initialize(); PyObject* sys = PyImport_ImportModule("sys"); PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); - - std::string pythonVerStr("pythonx.x/"); - pythonVerStr.at(6) = '0' + PyLong_AsLong(versionInfoMajor); - pythonVerStr.at(8) = '0' + PyLong_AsLong(versionInfoMinor); - + const std::string pythonVer(std::to_string(PyLong_AsLong(versionInfoMajor)) + \ + "." + std::to_string(PyLong_AsLong(versionInfoMinor))); Py_DECREF(versionInfoMajor); Py_DECREF(versionInfoMinor); Py_DECREF(versionInfo); PyObject* path = PyObject_GetAttrString(sys, "path"); - const std::string path_venv_modules(resourcesPath + "venv/lib/" + \ - pythonVerStr + "site-packages/"); + const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); - PyList_Insert(path, 1, PyUnicode_FromString(path_venv_modules.c_str())); + PyList_Insert(path, 1, PyUnicode_FromString(pathVenvMods.c_str())); Py_DECREF(sys); Py_DECREF(path); } -void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { +void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const +{ FILE *py_file = fopen(file, "r"); PyObject* global_dict = PyDict_New(); PyObject* local_dict = PyDict_New(); @@ -162,4 +160,4 @@ void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) co fclose(py_file); } -} // namespace FIELDLINEPLUGIN +} // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h b/src/applications/mne_scan/plugins/fieldline/fieldlineview.h index 799bd89a6fa..b42214a2cf3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldlineview.h @@ -60,10 +60,11 @@ //============================================================================================================= class QWidget; -// namespace Ui { + namespace Ui { + class fieldline_view_ui // class fieldline_rack; // class fieldline_chassis; -// } +} //============================================================================================================= // DEFINE NAMESPACE DISPLIB From 090cdf5f44b5d52d2d169135e1e77eb39030d959 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 5 Apr 2023 14:29:56 -0400 Subject: [PATCH 089/147] add formfiles for the plugin --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 6 +- .../plugins/fieldline/fieldlineview.ui | 193 ++++++++++++++++++ .../fieldline/mac_address_ip_text_box.ui | 47 +++++ 3 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldlineview.ui create mode 100644 src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index e4e5121e911..b9bf90ec84b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -103,6 +103,10 @@ set(HEADERS fieldlineview.h ) +set(UI_FILES + fieldlineview.ui +) + set(FILE_TO_UPDATE fieldline_global.cpp) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) @@ -121,7 +125,7 @@ set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}" ) -add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) set(FFTW_LIBS "") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.ui b/src/applications/mne_scan/plugins/fieldline/fieldlineview.ui new file mode 100644 index 00000000000..f1b3bcd7097 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldlineview.ui @@ -0,0 +1,193 @@ + + + generalFrame + + + + 0 + 0 + 652 + 665 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 100 + 100 + + + + + 16777215 + 200 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + 0 + 100 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + -1 + + + 10 + + + 0 + + + 10 + + + 0 + + + + + IP Address + + + + + + + MAC Address + + + + + + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + Find Acq System + + + + + + + Connect + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui b/src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui new file mode 100644 index 00000000000..aeb4f605400 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui @@ -0,0 +1,47 @@ + + + IpMacPair + + + + 0 + 0 + 402 + 50 + + + + + 400 + 50 + + + + Form + + + + + + + 100 + 25 + + + + + + + + + 100 + 25 + + + + + + + + + From ca509aa7676d6f099efc665b524719f86d24915d Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 5 Apr 2023 14:30:48 -0400 Subject: [PATCH 090/147] delete unused python scripts --- src/applications/mne_scan/plugins/fieldline/python/main.py | 1 - src/applications/mne_scan/plugins/fieldline/python/test.py | 0 2 files changed, 1 deletion(-) delete mode 100644 src/applications/mne_scan/plugins/fieldline/python/main.py delete mode 100644 src/applications/mne_scan/plugins/fieldline/python/test.py diff --git a/src/applications/mne_scan/plugins/fieldline/python/main.py b/src/applications/mne_scan/plugins/fieldline/python/main.py deleted file mode 100644 index b727a0ebb90..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/python/main.py +++ /dev/null @@ -1 +0,0 @@ -print("hello pepe!!") diff --git a/src/applications/mne_scan/plugins/fieldline/python/test.py b/src/applications/mne_scan/plugins/fieldline/python/test.py deleted file mode 100644 index e69de29bb2d..00000000000 From dcacb40a0d98e6da11c9a5bdb2dd7199ec1bea62 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 5 Apr 2023 14:32:26 -0400 Subject: [PATCH 091/147] add fieldline mocking script --- .../fieldline/fieldline_api_mock/__init__.py | 0 .../fieldline_service_mock.py | 199 ++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 resources/mne_scan/plugins/fieldline/fieldline_api_mock/__init__.py create mode 100644 resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/__init__.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py new file mode 100644 index 00000000000..b4c2820044c --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py @@ -0,0 +1,199 @@ + +class FieldLineService: + def __init(self, ip_list, prefix=""): + """ + callback - required callback class + should be of type FieldLineCallback + """ + self.counter_lock = 0 + self.hardware_state = 0 + print("Initializing FieldLine Service") + self.prefix = "prefix" + self.data_source = None + interfaces = netifaces.interfaces() + self.network_interfaces = [] + for i in interfaces: + print("interface %s" % i) + if i.startswith('lo'): + continue + iface = netifaces.ifaddresses(i).get(netifaces.AF_INET) + if iface is not None: + for j in iface: + ip_addr = j['addr'] + print("address %s" % ip_addr) + self.network_interfaces.append(ip_addr) + print("network interfaces: %s" % self.network_interfaces) + + def __enter__(self): + self.open() + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.close() + + def open(self): + try: + print("connecting to devices") + print("connecting to devices in ip_list: " + str(ip_list)) + print("start monitor") + print("start data source") + + def close(self): + self.data_source.shutdown(block=True) + self.data_source = None + + def load_sensors(self): + return self.data_source.load_sensors() + + def get_chassis_list(self): + return self.data_source.get_chassis_list() + + def read_data(self, data_callback=None): + self.data_source.read_data(data_callback=data_callback) + + def start_adc(self, chassis_id): + """ + Start ADC from chassis + + chassis_id - unique ID of chassis + """ + self.data_source.start_adc(chassis_id) + + def stop_adc(self, chassis_id): + """ + Stop ADC from chassis + + chassis_id - unique ID of chassis + """ + self.data_source.stop_adc(chassis_id) + + def turn_off_sensors(self, sensor_dict): + """ + Turn off sensors + Note: can be performed anytime + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + """ + self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_OFF) + + def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Restart the sensors + Note: can be performed anytime + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_RESTART) + + def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Coarse zero sensor + Note: can only be performed after restart is complete + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_COARSE_ZERO) + + def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Fine zero sensor + Note: can only be performed after coarse zero is complete + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_FINE_ZERO) + + def set_bz_wave(self, chassis_id, sensor_id, wave_type, freq=None, amplitude=None): + """ + Apply a known magnetic field to the BZ coil (e.g. sine wave) + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + wave_type - FieldLineWaveType (WAVE_OFF, WAVE_RAMP, WAVE_SINE) + freq - frequency of wave + amplitude - amplitude of wave (nT) + """ + if wave_type == FieldLineWaveType.WAVE_OFF: + self.data_source.set_wave_off(chassis_id, sensor_id) + elif wave_type == FieldLineWaveType.WAVE_RAMP: + self.data_source.set_wave_ramp(chassis_id, sensor_id, freq, amplitude) + elif wave_type == FieldLineWaveType.WAVE_SINE: + self.data_source.set_wave_sine(chassis_id, sensor_id, freq, amplitude) + + def set_closed_loop(self, enable): + """ + Turn closed loop on or off + + enable - True or False for on or off + """ + self.data_source.set_closed_loop(enable) + + def get_fields(self, chassis_id, sensor_id): + """ + Get the fields for a sensor + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + """ + for s in self.data_source.get_sensors(): + if s.chassis_id == chassis_id and s.sensor_id == sensor_id: + return s.fields + return None + + def get_serial_numbers(self, chassis_id, sensor_id): + """ + Get the card and sensor serial number for a sensor + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + """ + for s in self.data_source.get_sensors(): + if s.chassis_id == chassis_id and s.sensor_id == sensor_id: + return (s.card_serial,s.sensor_serial) + + def get_chassis_serial_number(self, chassis_id): + """ + Get the chassis serial number + + chassis_id - unique ID of chassis + """ + return self.data_source.get_chassis_serial(chassis_id) + + def get_version(self, chassis_id): + """ + Get the build version + + chassis_id - unique ID of chassis + """ + return self.data_source.get_chassis_version(chassis_id) + + def get_sensor_state(self, chassis_id, sensor_id): + """ + Get the current state of the sensor + + chassis_id - unique ID of chassis + sensor_id - ID of sensor + """ + return self.data_source.get_sensor_state(chassis_id, sensor_id) + + def get_calibration_value(self, ch_name): + """ + Get the calibration value for a channel + + ch_name - channel name in chassis:sensor:datatype format + """ + channel_dict = self.hardware_state.get_channel_dict() + return channel_dict[ch_name] if ch_name in channel_dict else 1.0 + From 847e724f4c609ebb373a66a3e43643fb6e7f1c5a Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 5 Apr 2023 14:34:15 -0400 Subject: [PATCH 092/147] update gitignore to not include fieldline api files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2269466801d..cca0064d56a 100644 --- a/.gitignore +++ b/.gitignore @@ -74,7 +74,8 @@ compile_commands.json /resources/data* __pycache__/ venv/ -*.whl +/resources/**/fieldline/*.whl +/resources/**/fieldline/sample_restart.py .cache/* codecov From 9c625b6211e328141b60ccadd84754bed89cd946 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 6 Apr 2023 10:08:09 -0400 Subject: [PATCH 093/147] update main fieldline plugin class --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 9 +++-- .../mne_scan/plugins/fieldline/fieldline.cpp | 40 +++---------------- .../mne_scan/plugins/fieldline/fieldline.h | 24 +++-------- 3 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index b9bf90ec84b..2b4f074af83 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -93,18 +93,21 @@ set(SOURCES fieldline_global.cpp fieldline.cpp fieldline_acqsystem.cpp - fieldlineview.cpp + fieldline_view.cpp ) set(HEADERS fieldline_global.h fieldline.h fieldline_acqsystem.h - fieldlineview.h + fieldline_view.h ) set(UI_FILES - fieldlineview.ui + formfiles/fieldline_view.ui + formfiles/fieldline_rack.ui + formfiles/fieldline_chassis.ui + formfiles/macaddress_ip_box.ui ) set(FILE_TO_UPDATE fieldline_global.cpp) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 3e66b2ce44c..f7d315164c5 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -44,7 +44,7 @@ #include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" -#include "fieldline/fieldlineview.h" +#include "fieldline/fieldline_view.h" #include // #include @@ -53,16 +53,6 @@ // QT INCLUDES //============================================================================================================= -// #include -// #include -// #include -// #include -// #include -// #include -// #include -// #include -// #include - //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -165,14 +155,16 @@ void Fieldline::init() "FieldlinePlguin output"); m_outputConnectors.append(m_pRTMSA); - acqSystem = std::make_unique(this); - guiWidget = std::make_unique(this); + acqSystem = new FieldlineAcqSystem(this); + guiWidget = new FieldlineView(this); } //============================================================================================================= void Fieldline::unload() { qDebug() << "unload Fieldline"; + delete acqSystem; + // delete guiWidget; // deleted by Qt } //============================================================================================================= @@ -210,27 +202,7 @@ QString Fieldline::getName() const { //============================================================================================================= QWidget *Fieldline::setupWidget() { - qDebug() << "setupWidget Fieldline"; - - // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by - // CentralWidget - so it has to be created everytime new - - // init properties dialog - // widget->initGui(); - - // auto *frame = new QWidget(); - // frame->setLayout(new QHBoxLayout()); - // - // auto *flWidget = new DISPLIB::FieldlineView(2, 16); - // - // frame->layout()->addWidget(flWidget); - // flWidget->setBlinkState(0, 2, true); - // flWidget->setBlinkState(1, 5, true); - // - // return frame; - - return guiWidget->getWidget(); - // return new QLabel("Fieldline \n OPM"); + return guiWidget; } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index b40eb02139c..9fdb88da087 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -47,8 +47,6 @@ #include -#include - #include #include @@ -81,12 +79,9 @@ class FieldlineView; */ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { Q_OBJECT - Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro - // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") Q_INTERFACES(SCSHAREDLIB::AbstractSensor) - // friend class FieldlineSetup; - public: //========================================================================================================= // The plugin interface @@ -115,21 +110,14 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { protected: virtual void run(); - std::unique_ptr acqSystem; - std::unique_ptr guiWidget; - - // int m_iSamplingFreq; /**< The sampling frequency defined by the user via the gui (in hertz).*/ - // int m_iNumberChannels; /**< The number of channels to be received.*/ - // int m_iSamplesPerBlock; /**< The number of samples per block to be received.*/ - // QString m_qStringResourcePath; /**< The path to the MEG resource directory.*/ - // QThread m_pProducerThread; /**< The thread used to host the producer.*/ - // // QSharedPointer m_pFieldlineProducer; /**< The producer object.*/ - // QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ + FieldlineAcqSystem* acqSystem; + FieldlineView* guiWidget; QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ - QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ }; + QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ +}; } // namespace FIELDLINEPLUGIN -#endif // FIELDLINE_H +#endif // FIELDLINEPLUGIN_FIELDLINE_H From 937cf061449f11002794977940cb677d60cda3fd Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 6 Apr 2023 10:11:25 -0400 Subject: [PATCH 094/147] refactor main fieldline widget --- .../plugins/fieldline/fieldline_acqsystem.cpp | 2 +- .../plugins/fieldline/fieldline_acqsystem.h | 2 +- .../{fieldlineview.cpp => fieldline_view.cpp} | 50 ++++++++-- .../{fieldlineview.h => fieldline_view.h} | 76 +++++---------- .../fieldline/fieldline_view_chassis.h | 96 +++++++++++++++++++ .../_delete_macaddress_ip_box.ui} | 0 .../{ => formfiles}/fieldline_chassis.ui | 0 .../{ => formfiles}/fieldline_rack.ui | 0 .../fieldline_view.ui} | 77 +++++++++++++-- 9 files changed, 230 insertions(+), 73 deletions(-) rename src/applications/mne_scan/plugins/fieldline/{fieldlineview.cpp => fieldline_view.cpp} (89%) rename src/applications/mne_scan/plugins/fieldline/{fieldlineview.h => fieldline_view.h} (74%) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h rename src/applications/mne_scan/plugins/fieldline/{mac_address_ip_text_box.ui => formfiles/_delete_macaddress_ip_box.ui} (100%) rename src/applications/mne_scan/plugins/fieldline/{ => formfiles}/fieldline_chassis.ui (100%) rename src/applications/mne_scan/plugins/fieldline/{ => formfiles}/fieldline_rack.ui (100%) rename src/applications/mne_scan/plugins/fieldline/{fieldlineview.ui => formfiles/fieldline_view.ui} (66%) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 7db292937e9..d50288ab2e6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -126,7 +126,7 @@ FieldlineAcqSystem::~FieldlineAcqSystem() Py_Finalize(); } -void FieldlineAcqSystem::preConfigurePython() const +void FieldlineAcqSystem::preConfigurePython() const { Py_Initialize(); PyObject* sys = PyImport_ImportModule("sys"); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index fef01a32109..2a79d2dbf6f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -41,7 +41,7 @@ class Fieldline; class FieldlineAcqSystem { public: - FieldlineAcqSystem(Fieldline* parent); + explicit FieldlineAcqSystem(Fieldline* parent); ~FieldlineAcqSystem(); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp similarity index 89% rename from src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp rename to src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 37ad0d42fbc..87832c064eb 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -37,10 +37,12 @@ // INCLUDES //============================================================================================================= -#include "fieldline/fieldlineview.h" +#include "fieldline/fieldline_view.h" #include "fieldline/fieldline.h" -// #include "ui_fieldline_rack.h" -// #include "ui_fieldline_chassis.h" +#include "formfiles/ui_fieldline_view.h" +#include "formfiles/ui_fieldline_rack.h" +#include "formfiles/ui_fieldline_chassis.h" +#include "formfiles/ui_macaddress_ip_box.h" //============================================================================================================= // QT INCLUDES @@ -48,6 +50,7 @@ #include #include +#include // #include // #include // #include @@ -76,18 +79,51 @@ namespace FIELDLINEPLUGIN { +int numChassis(2); FieldlineView::FieldlineView(Fieldline* parent) -: m_pFieldlinePlugin(parent) +: m_pFieldlinePlugin(parent), + m_pUi(new Ui::FieldlineSetupUi) { + m_pUi->setupUi(this); + QVBoxLayout* frameLayout = qobject_cast(m_pUi->ipMacFrame->layout()); + + QHBoxLayout* ipMacLayout1 = new QHBoxLayout(m_pUi->ipMacFrame); + QLineEdit* ip1 = new QLineEdit("ip1"); + ip1->setEnabled(false); + QLineEdit* macAddr1 = new QLineEdit("macaddr1"); + ipMacLayout1->addWidget(macAddr1); + ipMacLayout1->addWidget(ip1); + + QHBoxLayout* ipMacLayout2 = new QHBoxLayout(m_pUi->ipMacFrame); + QLineEdit* ip2 = new QLineEdit("ip2"); + ip2->setEnabled(false); + QLineEdit* macAddr2 = new QLineEdit("macaddr2"); + ipMacLayout2->addWidget(macAddr2); + ipMacLayout2->addWidget(ip2); + + frameLayout->insertLayout(1, ipMacLayout1); + frameLayout->insertLayout(1, ipMacLayout2); } -QWidget* FieldlineView::getWidget() const { +void FieldlineView::initAcqRack(int numChassis, const std::vector>& sensors) +{ + QVBoxLayout* rackLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); + for (int i = 0; i < numChassis; i++) + { + FieldlineChassis* chassis = new FieldlineChassis(sensors[i]); - QLabel* label = new QLabel("FieldlineView testing..."); - return label; + rackLayout->addWidget(chassis); + } + } +// QWidget* FieldlineView::getWidget() const { +// +// // QLabel* label = new QLabel("FieldlineView testing..."); +// return this; +// } + } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h similarity index 74% rename from src/applications/mne_scan/plugins/fieldline/fieldlineview.h rename to src/applications/mne_scan/plugins/fieldline/fieldline_view.h index b42214a2cf3..47e40c85f4a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -1,8 +1,8 @@ //============================================================================================================= /** - * @file fl_rack.h - * @author Gabriel Motta - * Juan Garcia-Prieto + * @file fieldline_view.h + * @author Juan Garcia-Prieto + * Gabriel Motta * @since 0.1.9 * @date February, 2023 * @@ -42,14 +42,11 @@ // #include "disp/viewers/led_indicator.h" -// #include -// #include -// -// //============================================================================================================= -// // QT INCLUDES -// //============================================================================================================= -// -// #include +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include //============================================================================================================= // EIGEN INCLUDES @@ -59,11 +56,9 @@ // FORWARD DECLARATIONS //============================================================================================================= -class QWidget; - namespace Ui { - class fieldline_view_ui -// class fieldline_rack; -// class fieldline_chassis; +namespace Ui { + class FieldlineSetupUi; + class Fieldline_view_chassisUi; } //============================================================================================================= @@ -76,13 +71,16 @@ class Fieldline; // class fieldline_chassis; //============================================================================================================= -class FieldlineView /*: public QWidget */ { - // Q_OBJECT -public: - FieldlineView(Fieldline* parent); +class FieldlineView : public QWidget +{ + Q_OBJECT - QWidget* getWidget() const; + public: + explicit FieldlineView(Fieldline* parent); + + void initAcqRack(int numChassis, const std::vector>& sensors); + // QWidget* getWidget() const; // FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); // FieldlineView(int num_chassis, QWidget *parent = nullptr); // ~FieldlineView(); @@ -106,44 +104,14 @@ class FieldlineView /*: public QWidget */ { // void setAllBlinkState(bool blinking); // // static void setDefaultNumSensors(int num_sensors); -private: + private: // static int default_num_sensors; // - // Ui::fieldline_rack* ui; - // std::vector chassis; Fieldline* m_pFieldlinePlugin; + Ui::FieldlineSetupUi* m_pUi; + // std::vector chassis; }; -//============================================================================================================= - -// class fieldline_chassis : public QWidget -// { -// Q_OBJECT -// -// public: -// fl_chassis(int num_sensors, QWidget *parent = nullptr); -// ~fl_chassis(); -// -// void setColor(size_t sensor_num, const QColor& color); -// void setColor(size_t sensor_num, const QColor& color, bool blinking); -// void setColor(const QColor& color); -// void setColor(const QColor& color, bool blinking); -// -// void setBlinkState(size_t sensor_num, bool blinking); -// void setBlinkState(bool blinking); -// -// signals: -// void clicked(int sensor, const QPoint& pos); -// -// private slots: -// void rightClickMenu(int sensor, const QPoint& pos); -// -// private: -// Ui::fl_chassis* ui; -// std::vector sensors; -// }; - - } // namespace FIELDLINEPLUGIN #endif // FIELDLINE_UI_VIEW_H diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h new file mode 100644 index 00000000000..7b73533b390 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -0,0 +1,96 @@ +//============================================================================================================= +/** + * @file fl_rack.h + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + #include "disp/viewers/led_indicator.h" + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +// namespace Ui { +// class FieldlineSetupUi; +// // class fieldline_chassis; +// } + +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace FIELDLINEPLUGIN { + + +//============================================================================================================= + +class fieldline_chassis : public QWidget +{ + Q_OBJECT + + public: + fl_chassis(int num_sensors, QWidget *parent = nullptr); + ~fl_chassis(); + + void setColor(size_t sensor_num, const QColor& color); + void setColor(size_t sensor_num, const QColor& color, bool blinking); + void setColor(const QColor& color); + void setColor(const QColor& color, bool blinking); + + void setBlinkState(size_t sensor_num, bool blinking); + void setBlinkState(bool blinking); + + signals: + void clicked(int sensor, const QPoint& pos); + + private slots: + void rightClickMenu(int sensor, const QPoint& pos); + + private: + Ui::fl_chassis* ui; + std::vector sensors; +}; + +} // namespace FIELDLINEPLUGIN + diff --git a/src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui similarity index 100% rename from src/applications/mne_scan/plugins/fieldline/mac_address_ip_text_box.ui rename to src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui similarity index 100% rename from src/applications/mne_scan/plugins/fieldline/fieldline_chassis.ui rename to src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_rack.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui similarity index 100% rename from src/applications/mne_scan/plugins/fieldline/fieldline_rack.ui rename to src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui diff --git a/src/applications/mne_scan/plugins/fieldline/fieldlineview.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui similarity index 66% rename from src/applications/mne_scan/plugins/fieldline/fieldlineview.ui rename to src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index f1b3bcd7097..330c00abc6d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldlineview.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -1,7 +1,7 @@ - generalFrame - + FieldlineSetupUi + 0 @@ -10,6 +10,12 @@ 665 + + + 0 + 0 + + Form @@ -30,17 +36,17 @@ 0 - + - + 0 0 - 100 - 100 + 0 + 0 @@ -57,7 +63,16 @@ - + + + true + + + + 0 + 0 + + QFrame::StyledPanel @@ -85,10 +100,16 @@ true + + + 0 + 0 + + 0 - 100 + 0 @@ -115,16 +136,40 @@ + + + 0 + 0 + + IP Address + + Qt::AlignCenter + + + + 0 + 0 + + + + + 0 + 0 + + MAC Address + + Qt::AlignCenter + @@ -134,7 +179,13 @@ - + + + + 0 + 0 + + QFrame::NoFrame @@ -163,7 +214,13 @@ - + + + + 0 + 0 + + QFrame::StyledPanel From 6864888815b2b914cfa11da884a30f0d74fb9ae9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 11 Apr 2023 10:30:58 -0400 Subject: [PATCH 095/147] biuld pythod mock and improve widget --- .clangd | 5 + resources/mne_scan/plugins/fieldline/.flake8 | 4 + .../fieldline_api_mock/fieldline_service.py | 214 ++++++++++++++++ .../fieldline_service_mock.py | 199 --------------- resources/mne_scan/plugins/fieldline/main.py | 3 + .../mne_scan/plugins/fieldline/random_data.py | 30 +++ resources/mne_scan/plugins/fieldline/test.py | 30 +++ resources/mne_scan/plugins/fieldline/test2.py | 32 +++ .../plugins/fieldline/fieldline_acqsystem.h | 14 +- .../plugins/fieldline/fieldline_view.cpp | 241 ++++-------------- .../plugins/fieldline/fieldline_view.h | 85 +++--- .../fieldline/fieldline_view_chassis.cpp | 180 +++++++++++++ .../fieldline/fieldline_view_chassis.h | 55 ++-- .../plugins/fieldline/fieldline_view_led.cpp | 0 .../plugins/fieldline/fieldline_view_led.h | 96 +++++++ .../fieldline/formfiles/fieldline_chassis.ui | 4 +- .../fieldline/formfiles/fieldline_view.ui | 4 +- 17 files changed, 737 insertions(+), 459 deletions(-) create mode 100644 .clangd create mode 100644 resources/mne_scan/plugins/fieldline/.flake8 create mode 100644 resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py delete mode 100644 resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py create mode 100644 resources/mne_scan/plugins/fieldline/random_data.py create mode 100644 resources/mne_scan/plugins/fieldline/test.py create mode 100644 resources/mne_scan/plugins/fieldline/test2.py create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h diff --git a/.clangd b/.clangd new file mode 100644 index 00000000000..2df5e3d6d83 --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +Diagnostics: + UnusedIncludes: Strict + InlayHints: + Enabled: No + diff --git a/resources/mne_scan/plugins/fieldline/.flake8 b/resources/mne_scan/plugins/fieldline/.flake8 new file mode 100644 index 00000000000..9a79ff74f60 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 125 +extend-ignore = E251 + diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py new file mode 100644 index 00000000000..6023f430740 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -0,0 +1,214 @@ +class FieldLineService: + def __init__(self, ip_list, prefix=""): + """ + callback - required callback class + should be of type FieldLineCallback + """ + self.counter_lock = 0 + self.hardware_state = 0 + print("Initializing FieldLine Service") + self.prefix = "prefix" + self.data_source = None + # interfaces = netifaces.interfaces() + self.network_interfaces = [] + self.ip_list = ip_list + # for i in interfaces: + # print("interface %s" % i) + # if i.startswith('lo'): + # continue + # iface = netifaces.ifaddresses(i).get(netifaces.AF_INET) + # if iface is not None: + # for j in iface: + # ip_addr = j['addr'] + # print("address %s" % ip_addr) + # self.network_interfaces.append(ip_addr) + # print("network interfaces: %s" % self.network_interfaces) + + def __enter__(self): + self.open() + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.close() + + def open(self): + print("connecting to devices in ip_list: " + str(self.ip_list)) + print("connecting to devices") + print("start monitor") + print("start data source") + + def close(self): + print("data source shut down") + + def load_sensors(self): + print("loading sensors") + # return self.data_source.load_sensors() + + def get_chassis_list(self): + print("get chassis list") + # return self.data_source.get_chassis_list() + + def read_data(self, data_callback=None): + print("read_data defined. Callback set to : " + data_callback.__name__) + # self.data_source.read_data(data_callback=data_callback) + + def start_adc(self, chassis_id): + """ + Start ADC from chassis + + chassis_id - unique ID of chassis + """ + print("start adc") + # self.data_source.start_adc(chassis_id) + + def stop_adc(self, chassis_id): + """ + Stop ADC from chassis + + chassis_id - unique ID of chassis + """ + print("stop adc") + # self.data_source.stop_adc(chassis_id) + + def turn_off_sensors(self, sensor_dict): + """ + Turn off sensors + Note: can be performed anytime + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + """ + print("turn off sensors") + # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_OFF) + + def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Restart the sensors + Note: can be performed anytime + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + print("restart sensors") + # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_RESTART) + + def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Coarse zero sensor + Note: can only be performed after restart is complete + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + print("coarse zero sensor") + # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_COARSE_ZERO) + + def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + """ + Fine zero sensor + Note: can only be performed after coarse zero is complete + + sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} + on_next - callback when sensor succeeds a step + on_error - callback when sensor fails a step + on_completed - callback when all sensors have either succeeded or failed + """ + print("fine zero sensors") + # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) + # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_FINE_ZERO) + + # def set_bz_wave(self, chassis_id, sensor_id, wave_type, freq=None, amplitude=None): + # """ + # Apply a known magnetic field to the BZ coil (e.g. sine wave) + # + # chassis_id - unique ID of chassis + # sensor_id - unique ID of sensor + # wave_type - FieldLineWaveType (WAVE_OFF, WAVE_RAMP, WAVE_SINE) + # freq - frequency of wave + # amplitude - amplitude of wave (nT) + # """ + # + # if wave_type == FieldLineWaveType.WAVE_OFF: + # self.data_source.set_wave_off(chassis_id, sensor_id) + # elif wave_type == FieldLineWaveType.WAVE_RAMP: + # self.data_source.set_wave_ramp(chassis_id, sensor_id, freq, amplitude) + # elif wave_type == FieldLineWaveType.WAVE_SINE: + # self.data_source.set_wave_sine(chassis_id, sensor_id, freq, amplitude) + + def set_closed_loop(self, enable): + """ + Turn closed loop on or off + + enable - True or False for on or off + """ + print("set closed loop") + # self.data_source.set_closed_loop(enable) + + def get_fields(self, chassis_id, sensor_id): + """ + Get the fields for a sensor + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + """ + print("get fields") + # for s in self.data_source.get_sensors(): + # if s.chassis_id == chassis_id and s.sensor_id == sensor_id: + # return s.fields + # return None + + def get_serial_numbers(self, chassis_id, sensor_id): + """ + Get the card and sensor serial number for a sensor + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + """ + print("get serial numbers") + # for s in self.data_source.get_sensors(): + # if s.chassis_id == chassis_id and s.sensor_id == sensor_id: + # return (s.card_serial,s.sensor_serial) + + def get_chassis_serial_number(self, chassis_id): + """ + Get the chassis serial number + + chassis_id - unique ID of chassis + """ + print("get chassis serial number") + # return self.data_source.get_chassis_serial(chassis_id) + + def get_version(self, chassis_id): + """ + Get the build version + + chassis_id - unique ID of chassis + """ + print("get version") + # return self.data_source.get_chassis_version(chassis_id) + + def get_sensor_state(self, chassis_id, sensor_id): + """ + Get the current state of the sensor + + chassis_id - unique ID of chassis + sensor_id - ID of sensor + """ + print("get sensor state") + # return self.data_source.get_sensor_state(chassis_id, sensor_id) + + def get_calibration_value(self, ch_name): + """ + Get the calibration value for a channel + + ch_name - channel name in chassis:sensor:datatype format + """ + print("get calibration value") + # channel_dict = self.hardware_state.get_channel_dict() + # return channel_dict[ch_name] if ch_name in channel_dict else 1.0 + diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py deleted file mode 100644 index b4c2820044c..00000000000 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service_mock.py +++ /dev/null @@ -1,199 +0,0 @@ - -class FieldLineService: - def __init(self, ip_list, prefix=""): - """ - callback - required callback class - should be of type FieldLineCallback - """ - self.counter_lock = 0 - self.hardware_state = 0 - print("Initializing FieldLine Service") - self.prefix = "prefix" - self.data_source = None - interfaces = netifaces.interfaces() - self.network_interfaces = [] - for i in interfaces: - print("interface %s" % i) - if i.startswith('lo'): - continue - iface = netifaces.ifaddresses(i).get(netifaces.AF_INET) - if iface is not None: - for j in iface: - ip_addr = j['addr'] - print("address %s" % ip_addr) - self.network_interfaces.append(ip_addr) - print("network interfaces: %s" % self.network_interfaces) - - def __enter__(self): - self.open() - return self - - def __exit__(self, exc_type, exc_value, traceback): - self.close() - - def open(self): - try: - print("connecting to devices") - print("connecting to devices in ip_list: " + str(ip_list)) - print("start monitor") - print("start data source") - - def close(self): - self.data_source.shutdown(block=True) - self.data_source = None - - def load_sensors(self): - return self.data_source.load_sensors() - - def get_chassis_list(self): - return self.data_source.get_chassis_list() - - def read_data(self, data_callback=None): - self.data_source.read_data(data_callback=data_callback) - - def start_adc(self, chassis_id): - """ - Start ADC from chassis - - chassis_id - unique ID of chassis - """ - self.data_source.start_adc(chassis_id) - - def stop_adc(self, chassis_id): - """ - Stop ADC from chassis - - chassis_id - unique ID of chassis - """ - self.data_source.stop_adc(chassis_id) - - def turn_off_sensors(self, sensor_dict): - """ - Turn off sensors - Note: can be performed anytime - - sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} - """ - self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_OFF) - - def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): - """ - Restart the sensors - Note: can be performed anytime - - sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} - on_next - callback when sensor succeeds a step - on_error - callback when sensor fails a step - on_completed - callback when all sensors have either succeeded or failed - """ - self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_RESTART) - - def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): - """ - Coarse zero sensor - Note: can only be performed after restart is complete - - sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} - on_next - callback when sensor succeeds a step - on_error - callback when sensor fails a step - on_completed - callback when all sensors have either succeeded or failed - """ - self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_COARSE_ZERO) - - def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): - """ - Fine zero sensor - Note: can only be performed after coarse zero is complete - - sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} - on_next - callback when sensor succeeds a step - on_error - callback when sensor fails a step - on_completed - callback when all sensors have either succeeded or failed - """ - self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_FINE_ZERO) - - def set_bz_wave(self, chassis_id, sensor_id, wave_type, freq=None, amplitude=None): - """ - Apply a known magnetic field to the BZ coil (e.g. sine wave) - - chassis_id - unique ID of chassis - sensor_id - unique ID of sensor - wave_type - FieldLineWaveType (WAVE_OFF, WAVE_RAMP, WAVE_SINE) - freq - frequency of wave - amplitude - amplitude of wave (nT) - """ - if wave_type == FieldLineWaveType.WAVE_OFF: - self.data_source.set_wave_off(chassis_id, sensor_id) - elif wave_type == FieldLineWaveType.WAVE_RAMP: - self.data_source.set_wave_ramp(chassis_id, sensor_id, freq, amplitude) - elif wave_type == FieldLineWaveType.WAVE_SINE: - self.data_source.set_wave_sine(chassis_id, sensor_id, freq, amplitude) - - def set_closed_loop(self, enable): - """ - Turn closed loop on or off - - enable - True or False for on or off - """ - self.data_source.set_closed_loop(enable) - - def get_fields(self, chassis_id, sensor_id): - """ - Get the fields for a sensor - - chassis_id - unique ID of chassis - sensor_id - unique ID of sensor - """ - for s in self.data_source.get_sensors(): - if s.chassis_id == chassis_id and s.sensor_id == sensor_id: - return s.fields - return None - - def get_serial_numbers(self, chassis_id, sensor_id): - """ - Get the card and sensor serial number for a sensor - - chassis_id - unique ID of chassis - sensor_id - unique ID of sensor - """ - for s in self.data_source.get_sensors(): - if s.chassis_id == chassis_id and s.sensor_id == sensor_id: - return (s.card_serial,s.sensor_serial) - - def get_chassis_serial_number(self, chassis_id): - """ - Get the chassis serial number - - chassis_id - unique ID of chassis - """ - return self.data_source.get_chassis_serial(chassis_id) - - def get_version(self, chassis_id): - """ - Get the build version - - chassis_id - unique ID of chassis - """ - return self.data_source.get_chassis_version(chassis_id) - - def get_sensor_state(self, chassis_id, sensor_id): - """ - Get the current state of the sensor - - chassis_id - unique ID of chassis - sensor_id - ID of sensor - """ - return self.data_source.get_sensor_state(chassis_id, sensor_id) - - def get_calibration_value(self, ch_name): - """ - Get the calibration value for a channel - - ch_name - channel name in chassis:sensor:datatype format - """ - channel_dict = self.hardware_state.get_channel_dict() - return channel_dict[ch_name] if ch_name in channel_dict else 1.0 - diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index d97d0fe27e3..dafd7fd9efc 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,5 +1,6 @@ """This is my super module""" import sys +from fieldline_api_mock.fieldline_service import FieldlineService for path in sys.path: print(path) @@ -8,3 +9,5 @@ print("hello pepe vamos vamos!!!") +fl = FieldlineService(["8.8.8.8", "9.9.9.9"]) + diff --git a/resources/mne_scan/plugins/fieldline/random_data.py b/resources/mne_scan/plugins/fieldline/random_data.py new file mode 100644 index 00000000000..2618ad357ff --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/random_data.py @@ -0,0 +1,30 @@ +import random + + +def generate_data(): + timestamp = 179331926 + num_sensors_per_chassis = 16 + num_chassis = 2 + + data_frames = {} + + data_values = [91599] + \ + [round(random.normalvariate(0, 1000)) + for _ in range(1, num_sensors_per_chassis * num_chassis - 1)] + + chassis_labels = [0] + [num for num in range(0, num_chassis) for _ in range(num_sensors_per_chassis)] + sensor_labels = [0] + (list(range(1, num_sensors_per_chassis + 1))) * num_chassis + data_type_labels = [0] + ([50] * num_sensors_per_chassis * num_chassis) + global_labels = [f'{chassis_label:02}:{sensor_label:02}:{data_type:02}' + for chassis_label, sensor_label, data_type in zip(chassis_labels, sensor_labels, data_type_labels)] + + for global_l, data_i, sensor_l, chassis_l, data_type_l in \ + zip(global_labels, data_values, sensor_labels, chassis_labels, data_type_labels): + data_frames[global_l] = \ + {'data': data_i, 'sensor': f'{chassis_l:02}:{sensor_l:02}', 'sensor_id': sensor_l, 'data_type': data_type_l} + + return {'timestamp': timestamp, 'data_frames': data_frames} + + +data = generate_data() +print(data) diff --git a/resources/mne_scan/plugins/fieldline/test.py b/resources/mne_scan/plugins/fieldline/test.py new file mode 100644 index 00000000000..810ab282292 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/test.py @@ -0,0 +1,30 @@ +data = {'timestamp': 179331926, 'data_frames': + {'00:00:0': {'data': 91599, 'sensor': '00:00', 'sensor_id': 0, 'data_type': 0}, + '00:01:50': {'data': 3440, 'sensor': '00:01', 'sensor_id': 1, 'data_type': 50}, + '00:02:50': {'data': 1434, 'sensor': '00:02', 'sensor_id': 2, 'data_type': 50}, + '00:03:50': {'data': 1073, 'sensor': '00:03', 'sensor_id': 3, 'data_type': 50}, + '00:04:50': {'data': -2361, 'sensor': '00:04', 'sensor_id': 4, 'data_type': 50}, + '00:05:50': {'data': 1936, 'sensor': '00:05', 'sensor_id': 5, 'data_type': 50}, + '00:06:50': {'data': 1385, 'sensor': '00:06', 'sensor_id': 6, 'data_type': 50}, + '00:08:50': {'data': 564, 'sensor': '00:08', 'sensor_id': 8, 'data_type': 50}, + '00:09:50': {'data': 3224, 'sensor': '00:09', 'sensor_id': 9, 'data_type': 50}, + '00:10:50': {'data': 2654, 'sensor': '00:10', 'sensor_id': 10, 'data_type': 50}, + '00:11:50': {'data': 1168, 'sensor': '00:11', 'sensor_id': 11, 'data_type': 50}, + '00:12:50': {'data': 6068, 'sensor': '00:12', 'sensor_id': 12, 'data_type': 50}, + '00:13:50': {'data': 1012, 'sensor': '00:13', 'sensor_id': 13, 'data_type': 50}, + '00:14:50': {'data': 1244, 'sensor': '00:14', 'sensor_id': 14, 'data_type': 50}, + '00:15:50': {'data': 749, 'sensor': '00:15', 'sensor_id': 15, 'data_type': 50}, + '00:16:50': {'data': 720, 'sensor': '00:16', 'sensor_id': 16, 'data_type': 50}, + '01:01:50': {'data': 1148, 'sensor': '01:02', 'sensor_id': 2, 'data_type': 50}, + '01:02:50': {'data': 1148, 'sensor': '01:02', 'sensor_id': 2, 'data_type': 50}, + '01:03:50': {'data': 1823, 'sensor': '01:03', 'sensor_id': 3, 'data_type': 50}, + '01:06:50': {'data': 1179, 'sensor': '01:06', 'sensor_id': 6, 'data_type': 50}, + '01:07:50': {'data': 2701, 'sensor': '01:07', 'sensor_id': 7, 'data_type': 50}, + '01:08:50': {'data': 4647, 'sensor': '01:08', 'sensor_id': 8, 'data_type': 50}, + '01:09:50': {'data': 3595, 'sensor': '01:09', 'sensor_id': 9, 'data_type': 50}, + '01:10:50': {'data': 936, 'sensor': '01:10', 'sensor_id': 10, 'data_type': 50}, + '01:12:50': {'data': -4956, 'sensor': '01:12', 'sensor_id': 12, 'data_type': 50}, + '01:13:50': {'data': 2274, 'sensor': '01:13', 'sensor_id': 13, 'data_type': 50}, + '01:14:50': {'data': 1698, 'sensor': '01:14', 'sensor_id': 14, 'data_type': 50}, + '01:15:50': {'data': 3942, 'sensor': '01:15', 'sensor_id': 15, 'data_type': 50}, + '01:16:50': {'data': 4695, 'sensor': '01:16', 'sensor_id': 16, 'data_type': 50}}} diff --git a/resources/mne_scan/plugins/fieldline/test2.py b/resources/mne_scan/plugins/fieldline/test2.py new file mode 100644 index 00000000000..ad5380693f3 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/test2.py @@ -0,0 +1,32 @@ +data = {'timestamp': 179331926, 'data_frames': + {'00:00:00': {'data': 91599, 'sensor': '00:00', 'sensor_id': 0, 'data_type': 0}, + '00:01:50': {'data': -187, 'sensor': '00:01', 'sensor_id': 1, 'data_type': 50}, + '00:02:50': {'data': -606, 'sensor': '00:02', 'sensor_id': 2, 'data_type': 50}, + '00:03:50': {'data': -261, 'sensor': '00:03', 'sensor_id': 3, 'data_type': 50}, + '00:04:50': {'data': 2100, 'sensor': '00:04', 'sensor_id': 4, 'data_type': 50}, + '00:05:50': {'data': -880, 'sensor': '00:05', 'sensor_id': 5, 'data_type': 50}, + '00:06:50': {'data': -2066, 'sensor': '00:06', 'sensor_id': 6, 'data_type': 50}, + '00:07:50': {'data': -657, 'sensor': '00:07', 'sensor_id': 7, 'data_type': 50}, + '00:08:50': {'data': 443, 'sensor': '00:08', 'sensor_id': 8, 'data_type': 50}, + '00:09:50': {'data': -228, 'sensor': '00:09', 'sensor_id': 9, 'data_type': 50}, + '00:10:50': {'data': 922, 'sensor': '00:10', 'sensor_id': 10, 'data_type': 50}, + '00:11:50': {'data': 2129, 'sensor': '00:11', 'sensor_id': 11, 'data_type': 50}, + '00:12:50': {'data': -1235, 'sensor': '00:12', 'sensor_id': 12, 'data_type': 50}, + '00:13:50': {'data': -15, 'sensor': '00:13', 'sensor_id': 13, 'data_type': 50}, + '00:14:50': {'data': 1214, 'sensor': '00:14', 'sensor_id': 14, 'data_type': 50}, + '00:15:50': {'data': -535, 'sensor': '00:15', 'sensor_id': 15, 'data_type': 50}, + '00:16:50': {'data': -1326, 'sensor': '00:16', 'sensor_id': 16, 'data_type': 50}, + '01:01:50': {'data': -663, 'sensor': '01:01', 'sensor_id': 1, 'data_type': 50}, + '01:02:50': {'data': 740, 'sensor': '01:02', 'sensor_id': 2, 'data_type': 50}, + '01:03:50': {'data': -1406, 'sensor': '01:03', 'sensor_id': 3, 'data_type': 50}, + '01:04:50': {'data': 210, 'sensor': '01:04', 'sensor_id': 4, 'data_type': 50}, + '01:05:50': {'data': -811, 'sensor': '01:05', 'sensor_id': 5, 'data_type': 50}, + '01:06:50': {'data': -534, 'sensor': '01:06', 'sensor_id': 6, 'data_type': 50}, + '01:07:50': {'data': 1300, 'sensor': '01:07', 'sensor_id': 7, 'data_type': 50}, + '01:08:50': {'data': 1321, 'sensor': '01:08', 'sensor_id': 8, 'data_type': 50}, + '01:09:50': {'data': 75, 'sensor': '01:09', 'sensor_id': 9, 'data_type': 50}, + '01:10:50': {'data': -689, 'sensor': '01:10', 'sensor_id': 10, 'data_type': 50}, + '01:11:50': {'data': -233, 'sensor': '01:11', 'sensor_id': 11, 'data_type': 50}, + '01:12:50': {'data': 649, 'sensor': '01:12', 'sensor_id': 12, 'data_type': 50}, + '01:13:50': {'data': -319, 'sensor': '01:13', 'sensor_id': 13, 'data_type': 50}, + '01:14:50': {'data': -91, 'sensor': '01:14', 'sensor_id': 14, 'data_type': 50}}} diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 2a79d2dbf6f..69b877c2cb5 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -40,16 +40,16 @@ namespace FIELDLINEPLUGIN { class Fieldline; class FieldlineAcqSystem { -public: - explicit FieldlineAcqSystem(Fieldline* parent); + public: + explicit FieldlineAcqSystem(Fieldline* parent); - ~FieldlineAcqSystem(); + ~FieldlineAcqSystem(); -private: - void preConfigurePython() const; - void runPythonFile(const char* file, const char* comment) const; + private: + void preConfigurePython() const; + void runPythonFile(const char* file, const char* comment) const; - Fieldline* m_pControllerParent; + Fieldline* m_pControllerParent; }; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 87832c064eb..026db6ec355 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -1,8 +1,8 @@ //============================================================================================================= /** - * @file fl_rack.cpp - * @author Gabriel Motta - * Juan Garcia-Prieto + * @file fieldline_view.cpp + * @author Juan Garcia-Prieto + * Gabriel Motta * @since 0.1.9 * @date February, 2023 * @@ -40,20 +40,12 @@ #include "fieldline/fieldline_view.h" #include "fieldline/fieldline.h" #include "formfiles/ui_fieldline_view.h" -#include "formfiles/ui_fieldline_rack.h" -#include "formfiles/ui_fieldline_chassis.h" -#include "formfiles/ui_macaddress_ip_box.h" //============================================================================================================= // QT INCLUDES //============================================================================================================= -#include -#include #include -// #include -// #include -// #include //============================================================================================================= // EIGEN INCLUDES @@ -63,15 +55,10 @@ // USED NAMESPACES //============================================================================================================= -// using DISPLIB::FieldlineView; -// using DISPLIB::fl_chassis; -// //============================================================================================================= // DEFINE STATIC METHODS //============================================================================================================= -// int FieldlineView::default_num_sensors = 16; - //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= @@ -79,13 +66,23 @@ namespace FIELDLINEPLUGIN { -int numChassis(2); - FieldlineView::FieldlineView(Fieldline* parent) : m_pFieldlinePlugin(parent), - m_pUi(new Ui::FieldlineSetupUi) + m_pUi(new Ui::uiFieldlineView), + m_pAcqSystem(nullptr) { m_pUi->setupUi(this); + initTopMenu(); + initTopMenuCallbacks(); +} + +FieldlineView::~FieldlineView() +{ + delete m_pUi; +} + +void FieldlineView::initTopMenu() +{ QVBoxLayout* frameLayout = qobject_cast(m_pUi->ipMacFrame->layout()); QHBoxLayout* ipMacLayout1 = new QHBoxLayout(m_pUi->ipMacFrame); @@ -94,87 +91,56 @@ FieldlineView::FieldlineView(Fieldline* parent) QLineEdit* macAddr1 = new QLineEdit("macaddr1"); ipMacLayout1->addWidget(macAddr1); ipMacLayout1->addWidget(ip1); - + QHBoxLayout* ipMacLayout2 = new QHBoxLayout(m_pUi->ipMacFrame); QLineEdit* ip2 = new QLineEdit("ip2"); ip2->setEnabled(false); QLineEdit* macAddr2 = new QLineEdit("macaddr2"); ipMacLayout2->addWidget(macAddr2); ipMacLayout2->addWidget(ip2); - + frameLayout->insertLayout(1, ipMacLayout1); frameLayout->insertLayout(1, ipMacLayout2); } -void FieldlineView::initAcqRack(int numChassis, const std::vector>& sensors) +void FieldlineView::initCallbacks() { - QVBoxLayout* rackLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); +} + +void FieldlineView::initAcqSystem(int numChassis, const std::vector>& chans) +{ + displayAcqSystem(); + initAcqSystemCallbacks(); +} + +void FieldlineView::displayAcqSystem() +{ + QVBoxLayout* rackFrameLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); for (int i = 0; i < numChassis; i++) { - FieldlineChassis* chassis = new FieldlineChassis(sensors[i]); + FieldlineChassis* chassis = new FieldlineViewChassis(chans[i]); - rackLayout->addWidget(chassis); + rackFrameLayout->addWidget(chassis); } - } -// QWidget* FieldlineView::getWidget() const { -// -// // QLabel* label = new QLabel("FieldlineView testing..."); -// return this; -// } +void FieldlineView::setChannelState(size_t chassis_i, size_t chan_i) +{ +} +statish FieldlineView::getChannelState(size_t chassis_i, size_t chan_i) +{ +} -} // namespace FIELDLINEPLUGIN +statish FieldlineView::setAllChannelState(size_t chassis_i, statish) +{ +} + +} // namespace FIELDLINEPLUGIN -// -// FieldlineView::FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent) -// : FieldlineView(parent) -// { -// configure(num_chassis, sensors_per_chassis); -// } -// -// //============================================================================================================= -// -// FieldlineView::FieldlineView(int num_chassis, QWidget *parent) -// : FieldlineView(num_chassis, default_num_sensors, parent) -// { -// } -// -// //============================================================================================================= -// -// FieldlineView::FieldlineView(QWidget *parent) -// : QWidget(parent) -// , ui(new Ui::fl_rack()) -// { -// ui->setupUi(this); -// } -// //============================================================================================================= -// -// FieldlineView::~FieldlineView() -// { -// delete ui; -// } -// -// //============================================================================================================= -// -// void FieldlineView::configure(int num_chassis) -// { -// configure(num_chassis, default_num_sensors); -// } // // //============================================================================================================= // -// void FieldlineView::configure(int num_chassis, int num_sensors) -// { -// clear(); -// for(int i = 0; i < num_chassis; ++i){ -// chassis.push_back(new fl_chassis(num_sensors)); -// ui->frame->layout()->addWidget(chassis.back()); -// } -// } -// -// //============================================================================================================= // // void FieldlineView::clear() // { @@ -186,22 +152,22 @@ void FieldlineView::initAcqRack(int numChassis, const std::vector= chassis.size()){ // return; // } -// chassis.at(chassis_id)->setColor(sensor_num, color); +// chassis.at(chassis_id)->setColor(chan_num, color); // } // // //============================================================================================================= // -// void FieldlineView::setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking) +// void FieldlineView::setColor(size_t chassis_id, size_t chan_num, const QColor& color, bool blinking) // { // if(chassis_id >= chassis.size()){ // return; // } -// chassis.at(chassis_id)->setColor(sensor_num, color, blinking); +// chassis.at(chassis_id)->setColor(chan_num, color, blinking); // } // // //============================================================================================================= @@ -244,12 +210,12 @@ void FieldlineView::initAcqRack(int numChassis, const std::vector= chassis.size()){ // return; // } -// chassis.at(chassis_id)->setBlinkState(sensor_num, blinking); +// chassis.at(chassis_id)->setBlinkState(chan_num, blinking); // } // // //============================================================================================================= @@ -273,112 +239,7 @@ void FieldlineView::initAcqRack(int numChassis, const std::vectorsetupUi(this); -// -// for(int i = 0; i < num_sensors; ++i){ -// sensors.push_back(new LEDIndicator()); -// auto& last_item = sensors.back(); -// sensors.back()->setLabel(QString::number(i + 1)); -// ui->sensor_frame->layout()->addWidget(sensors.back()); -// connect(sensors.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); -// connect(this, &fl_chassis::clicked, this, &fl_chassis::rightClickMenu, Qt::UniqueConnection); -// } -// } -// -// //============================================================================================================= -// -// fl_chassis::~fl_chassis() -// { -// delete ui; -// } -// -// //============================================================================================================= -// -// void fl_chassis::setColor(size_t sensor_num, const QColor& color) -// { -// if(sensor_num > sensors.size() || sensor_num < 1){ -// return; -// } -// sensors.at(sensor_num - 1)->setColor(color); -// } -// -// //============================================================================================================= -// -// void fl_chassis::setColor(size_t sensor_num, const QColor& color, bool blinking) -// { -// setColor(sensor_num, color); -// setBlinkState(sensor_num, blinking); -// } -// -// //============================================================================================================= -// -// void fl_chassis::setColor(const QColor& color) -// { -// for(auto* sensor : sensors){ -// sensor->setColor(color); -// } -// } -// -// //============================================================================================================= -// -// void fl_chassis::setColor(const QColor& color, bool blinking) -// { -// for(auto* sensor : sensors){ -// sensor->setColor(color); -// sensor->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void fl_chassis::setBlinkState(size_t sensor_num, bool blinking) -// { -// if(sensor_num > sensors.size() || sensor_num < 1){ -// return; -// } -// sensors.at(sensor_num - 1)->setBlink(blinking); -// } -// -// //============================================================================================================= -// -// void fl_chassis::setBlinkState(bool blinking) -// { -// for(auto* sensor : sensors){ -// sensor->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void fl_chassis::rightClickMenu(int sensor, const QPoint& pos) -// { -// // auto* menu = new QMenu(); -// -// // auto blink_on_sensor = menu->addAction("Blink ON - " + QString::number(sensor)); -// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); -// -// // auto blink_off_sensor = menu->addAction("Blink OFF - " + QString::number(sensor)); -// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); -// -// // connect(blink_on_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, true);}); -// // connect(blink_off_sensor, &QAction::triggered,[this, sensor](){this->setBlinkState(sensor, false);}); -// -// // connect(blink_on_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(true);}); -// // connect(blink_off_chassis, &QAction::triggered,[this, sensor](){this->setBlinkState(false);}); -// -// // menu->exec(pos); -// } -// -// -// diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 47e40c85f4a..af1aa9a2afa 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -40,7 +40,7 @@ // INCLUDES //============================================================================================================= -// #include "disp/viewers/led_indicator.h" +#include //============================================================================================================= // QT INCLUDES @@ -57,8 +57,7 @@ //============================================================================================================= namespace Ui { - class FieldlineSetupUi; - class Fieldline_view_chassisUi; +class uiFieldlineView; } //============================================================================================================= @@ -68,7 +67,37 @@ namespace Ui { namespace FIELDLINEPLUGIN { class Fieldline; -// class fieldline_chassis; +class FieldlineViewChassis; + +enum class FieldlineDataType { + DATA_BZ = 0, + DATA_BY = 1, + DATA_BX = 2 +}; + +enum class FieldLineWaveType { + WAVE_OFF = 0, + WAVE_RAMP = 1, + WAVE_SINE = 2, +}; + +enum class FieldLineSensorStatusType { + SENSOR_OFF = 0, + SENSOR_RESTARTING = 1, + SENSOR_RESTARTED = 2, + SENSOR_COARSE_ZEROING = 3, + SENSOR_COARSE_ZEROED = 4, + SENSOR_FINE_ZEROING = 5, + SENSOR_FINE_ZEROED = 6, + SENSOR_ERROR = 7, + SENSOR_READY = 8, +}; + +enum class FieldLineConnectStatusType { + CONNECT_OK = 0, + CONNECT_NOT_READY = 1, + CONNECT_CHASSIS_MISSING = 2, +}; //============================================================================================================= @@ -78,38 +107,28 @@ class FieldlineView : public QWidget public: explicit FieldlineView(Fieldline* parent); + ~FieldlineView(); + + // void setLedColor(size_t chassis_id, size_t chan_num, const QColor& color); + // void getLedColor()// + // void setLedAllColor(const QColor& color); + // void setLedAllColor(const QColor &color, bool blinking); + void setChannelState(size_t chassis_i, size_t chan_i); + statish getChannelState(size_t chassis_i, size_t chan_i); + void setAllChannelsState(size_t chassis_i, statish); - void initAcqRack(int numChassis, const std::vector>& sensors); - // QWidget* getWidget() const; - // FieldlineView(int num_chassis, int sensors_per_chassis, QWidget *parent = nullptr); - // FieldlineView(int num_chassis, QWidget *parent = nullptr); - // ~FieldlineView(); - // - // void configure(int num_chassis); - // void configure(int num_chassis, int num_sensors); - // - // void clear(); - // - // void setColor(size_t chassis_id, size_t sensor_num, const QColor& color); - // void setColor(size_t chassis_id, size_t sensor_num, const QColor& color, bool blinking); - // - // void setChassisColor(size_t chassis_id, const QColor& color); - // void setChassisColor(size_t chassis_id, const QColor& color, bool blinking); - // - // void setAllColor(const QColor& color); - // void setAllColor(const QColor &color, bool blinking); - // - // void setBlinkState(size_t chassis_id, size_t sensor_num, bool blinking); - // void setChassisBlinkState(size_t chassis_id, bool blinking); - // void setAllBlinkState(bool blinking); - // - // static void setDefaultNumSensors(int num_sensors); private: - // static int default_num_sensors; - // + void initAcqSystem(int numChassis, const std::vector>& channels); + + void initTopMenu(); + void initTopMenuCallbacks(); + + void initAcqSystem(); + void initAcqSystemCallbacks(); + Fieldline* m_pFieldlinePlugin; - Ui::FieldlineSetupUi* m_pUi; - // std::vector chassis; + Ui::uiFieldlineView* m_pUi; + std::vector* m_pAcqSystem; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp new file mode 100644 index 00000000000..8f195f2db7f --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp @@ -0,0 +1,180 @@ +//============================================================================================================= +/** + * @file fieldline_view_chassis.cpp + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +// #include "fieldline/fieldline_view.h" +// #include "fieldline/fieldline.h" +#include "formfiles/ui_fieldline_view.h" +#include "formfiles/ui_fieldline_rack.h" +#include "formfiles/ui_fieldline_chassis.h" + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= +// +// #include +// #include +// #include +// #include +// #include +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + + +namespace FIELDLINEPLUGIN { + +//============================================================================================================= + +FieldlineViewChassis::FieldlineViewChassis(int num_chans, QWidget *parent ) +: QWidget(parent) +, m_pUi(new Ui::uiFieldlineViewChassis) +{ + ui->setupUi(this); +} + +FieldlineViewChassis::~FieldlineViewChassis() +{ + delete ui; +} + +FieldlineViewChassis::initChannels(size_t numChans) +{ + // for(int i = 0; i < num_chans; ++i){ + // chans.push_back(new LEDIndicator()); + // auto& last_item = chans.back(); + // chans.back()->setLabel(QString::number(i + 1)); + // ui->chan_frame->layout()->addWidget(chans.back()); + // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); + // connect(this, &FieldlineViewChassis::clicked, this, &FieldlineViewChassis::rightClickMenu, Qt::UniqueConnection); + // } +} + +//============================================================================================================= +// +// void FieldlineViewChassis::setColor(size_t chan_num, const QColor& color) +// { +// if(chan_num > chans.size() || chan_num < 1){ +// return; +// } +// chans.at(chan_num - 1)->setColor(color); +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::setColor(size_t chan_num, const QColor& color, bool blinking) +// { +// setColor(chan_num, color); +// setBlinkState(chan_num, blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::setColor(const QColor& color) +// { +// for(auto* chan : chans){ +// chan->setColor(color); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::setColor(const QColor& color, bool blinking) +// { +// for(auto* chan : chans){ +// chan->setColor(color); +// chan->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::setBlinkState(size_t chan_num, bool blinking) +// { +// if(chan_num > chans.size() || chan_num < 1){ +// return; +// } +// chans.at(chan_num - 1)->setBlink(blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::setBlinkState(bool blinking) +// { +// for(auto* chan : chans){ +// chan->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewChassis::rightClickMenu(int chan, const QPoint& pos) +// { +// // auto* menu = new QMenu(); +// +// // auto blink_on_chan = menu->addAction("Blink ON - " + QString::number(chan)); +// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); +// +// // auto blink_off_chan = menu->addAction("Blink OFF - " + QString::number(chan)); +// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); +// +// // connect(blink_on_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, true);}); +// // connect(blink_off_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, false);}); +// +// // connect(blink_on_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(true);}); +// // connect(blink_off_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(false);}); +// +// // menu->exec(pos); +// } + +} // namespace FIELDLINEPLUGIN + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index 7b73533b390..f74cf1b6b8e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -1,6 +1,6 @@ //============================================================================================================= /** - * @file fl_rack.h + * @file fieldline_view_chassis.h * @author Juan Garcia-Prieto * Gabriel Motta * @since 0.1.9 @@ -37,12 +37,14 @@ // INCLUDES //============================================================================================================= - #include "disp/viewers/led_indicator.h" +// #include "disp/viewers/led_indicator.h" //============================================================================================================= // QT INCLUDES //============================================================================================================= +#include +int aalakjdflaskjdflkajsdlfkasjfdlksdjfsldkfjasldkjfasmssmkjlkjdfisldkfjasldkfjalskdjflaskdjfasldkfjasldkfjlkkkkkkkkkkkkkkk = 44; //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -51,45 +53,46 @@ // FORWARD DECLARATIONS //============================================================================================================= -// namespace Ui { -// class FieldlineSetupUi; -// // class fieldline_chassis; -// } - +namespace Ui { +// class uiFieldlineViewChassis; +} //============================================================================================================= // DEFINE NAMESPACE DISPLIB //============================================================================================================= namespace FIELDLINEPLUGIN { +class FieldlineViewChannel; //============================================================================================================= -class fieldline_chassis : public QWidget +class FieldlineViewChassis : public QWidget { Q_OBJECT public: - fl_chassis(int num_sensors, QWidget *parent = nullptr); - ~fl_chassis(); - - void setColor(size_t sensor_num, const QColor& color); - void setColor(size_t sensor_num, const QColor& color, bool blinking); - void setColor(const QColor& color); - void setColor(const QColor& color, bool blinking); - - void setBlinkState(size_t sensor_num, bool blinking); - void setBlinkState(bool blinking); - - signals: - void clicked(int sensor, const QPoint& pos); - - private slots: - void rightClickMenu(int sensor, const QPoint& pos); + FieldlineViewChassis(int num_chans, QWidget *parent = nullptr); + ~FieldlineViewChassis(); + void setChannelState(size_t chan_i, statish); + statish getChannelState(size_t chan_i); +// void setColor(size_t chan_num, const QColor& color); +// void setColor(size_t chan_num, const QColor& color, bool blinking); +// void setColor(const QColor& color); +// void setColor(const QColor& color, bool blinking); +// +// void setBlinkState(size_t chan_num, bool blinking); +// void setBlinkState(bool blinking); +// +// signals: +// void clicked(int chan, const QPoint& pos); +// +// private slots: + // void rightClickMenu(int chan, const QPoint& pos); private: - Ui::fl_chassis* ui; - std::vector sensors; + QWidget* m_pParent; + // Ui::uiFieldlineViewChassis* m_pUi; + // std::vector* m_pChannels; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h new file mode 100644 index 00000000000..3fe23133644 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h @@ -0,0 +1,96 @@ +//============================================================================================================= +/** + * @file fieldline_view_led.h + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @file fieldline_view_chassis.h + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + // #include "disp/viewers/led_indicator.h" + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +namespace Ui { +class uiFieldlineViewChassis; +} +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace FIELDLINEPLUGIN { + +//============================================================================================================= + +class FieldlineViewChassis : public QWidget +{ + Q_OBJECT + + public: + FieldlineViewChassis(int num_sensors, QWidget *parent = nullptr); + ~FieldlineViewChassis(); + // void setColor(size_t sensor_num, const QColor& color); + // void setColor(size_t sensor_num, const QColor& color, bool blinking); + // void setColor(const QColor& color); + // void setColor(const QColor& color, bool blinking); + // + // void setBlinkState(size_t sensor_num, bool blinking); + // void setBlinkState(bool blinking); + // + // signals: + // void clicked(int sensor, const QPoint& pos); + // + // private slots: + // void rightClickMenu(int sensor, const QPoint& pos); + + private: + QWidget* m_pParent; + Ui::uiFieldlineViewChassis* m_pUi; + std::vector* m_pSensors; +}; + +} // namespace FIELDLINEPLUGIN + diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui index 2de422ee7d6..6f225cf5f65 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui @@ -1,7 +1,7 @@ - fl_chassis - + uiFieldlineViewChassis + 0 diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 330c00abc6d..d01f120d85f 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -1,7 +1,7 @@ - FieldlineSetupUi - + uiFieldlineView + 0 From b3e89a662d25a1dd558f24823860104f4bdeb5ac Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Tue, 11 Apr 2023 11:53:24 -0400 Subject: [PATCH 096/147] Debugging python symlinks --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 2b4f074af83..a0c2880df59 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -50,6 +50,47 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) +execute_process( + COMMAND which ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + OUTPUT_VARIABLE Python_Config_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND dirname ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + OUTPUT_VARIABLE Python_Config_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND dirname ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + OUTPUT_VARIABLE Python_Config_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND readlink -f ${Python_EXECUTABLE} + OUTPUT_VARIABLE Python_EXECUTABLE_TRUE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process( + COMMAND dirname ${Python_EXECUTABLE_TRUE_PATH} + OUTPUT_VARIABLE Python_BIN_TRUE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +#get_filename_component(Python_BIN_DIR_CLEAN ${Python_BIN_DIR} ABSOLUTE) + +#get_filename_component(Python_Config_DIR_CLEAN ${Python_Config_DIR} ABSOLUTE) + +if(${Python_BIN_DIR} NOT STREQUAL ${Python_BIN_TRUE_DIR}) + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + ) +endif() + execute_process( COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes OUTPUT_VARIABLE Python_INCLUDE_DIRS @@ -107,7 +148,6 @@ set(UI_FILES formfiles/fieldline_view.ui formfiles/fieldline_rack.ui formfiles/fieldline_chassis.ui - formfiles/macaddress_ip_box.ui ) set(FILE_TO_UPDATE fieldline_global.cpp) From 77582a0f54c96cc8039d0e66211c4a803a7025ec Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Tue, 11 Apr 2023 13:33:44 -0400 Subject: [PATCH 097/147] set symlink for python-config when it is missing --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 84 ++++++++----------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index a0c2880df59..c8bc5c9ee31 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -50,52 +50,40 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -execute_process( - COMMAND which ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config - OUTPUT_VARIABLE Python_Config_EXECUTABLE - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -execute_process( - COMMAND dirname ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config - OUTPUT_VARIABLE Python_Config_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -execute_process( - COMMAND dirname ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config - OUTPUT_VARIABLE Python_Config_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -execute_process( - COMMAND readlink -f ${Python_EXECUTABLE} - OUTPUT_VARIABLE Python_EXECUTABLE_TRUE_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -execute_process( - COMMAND dirname ${Python_EXECUTABLE_TRUE_PATH} - OUTPUT_VARIABLE Python_BIN_TRUE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -#get_filename_component(Python_BIN_DIR_CLEAN ${Python_BIN_DIR} ABSOLUTE) - -#get_filename_component(Python_Config_DIR_CLEAN ${Python_Config_DIR} ABSOLUTE) +if(EXISTS ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config) + message(STATUS "python config found") +else() + message(STATUS "python config not found") + execute_process( + COMMAND readlink -f ${Python_EXECUTABLE} + OUTPUT_VARIABLE Python_EXECUTABLE_TRUE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) -if(${Python_BIN_DIR} NOT STREQUAL ${Python_BIN_TRUE_DIR}) execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink - ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + COMMAND dirname ${Python_EXECUTABLE_TRUE_PATH} + OUTPUT_VARIABLE Python_BIN_TRUE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + + if(NOT EXISTS ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config) + message(FATAL python-config not found. Python installation missing python-config.) + else() + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + ) + message(STATUS "Creating sym link to python config") + endif() endif() + execute_process( COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes OUTPUT_VARIABLE Python_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags OUTPUT_VARIABLE Python_CFLAGS @@ -117,18 +105,18 @@ execute_process( separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") -message( "python prefix dir: " ${Python_PREFIX}) -message( "python bin dir: " ${Python_BIN_DIR}) -message( "python lib dir: " ${Python_LIB_DIR}) -message( "python executable: " ${Python_EXECUTABLE}) -message( "python version major: " ${Python_VERSION_MAJOR}) -message( "python version minor: " ${Python_VERSION_MINOR}) -message( "python include dirs: " ${Python_INCLUDE_DIRS}) -message( "python cflags: " ${Python_CFLAGS}) -message( "python cflags norm: " ${Python_CFLAGS_NORM}) -message( "python libraries: " ${Python_LIBS}) -message( "python lib flags: " ${Python_LDFLAGS}) -message("python lib flags norm: " ${Python_LDFLAGS_NORM}) +message( "python prefix dir: " ${Python_PREFIX}) +message( "python bin dir: " ${Python_BIN_DIR}) +message( "python lib dir: " ${Python_LIB_DIR}) +message( "python executable: " ${Python_EXECUTABLE}) +message( "python version major: " ${Python_VERSION_MAJOR}) +message( "python version minor: " ${Python_VERSION_MINOR}) +message( "python include dirs: " ${Python_INCLUDE_DIRS}) +message( "python cflags: " ${Python_CFLAGS}) +message( "python cflags norm: " ${Python_CFLAGS_NORM}) +message( "python libraries: " ${Python_LIBS}) +message( "python lib flags: " ${Python_LDFLAGS}) +message(" python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp From 5db4d1a996b54fddcb0bfac1c166eb48c0bd39dc Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Tue, 11 Apr 2023 14:20:25 -0400 Subject: [PATCH 098/147] extend data generation channel bounds --- resources/mne_scan/plugins/fieldline/random_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/mne_scan/plugins/fieldline/random_data.py b/resources/mne_scan/plugins/fieldline/random_data.py index 2618ad357ff..a058c57dfb5 100644 --- a/resources/mne_scan/plugins/fieldline/random_data.py +++ b/resources/mne_scan/plugins/fieldline/random_data.py @@ -10,7 +10,7 @@ def generate_data(): data_values = [91599] + \ [round(random.normalvariate(0, 1000)) - for _ in range(1, num_sensors_per_chassis * num_chassis - 1)] + for _ in range(1, num_sensors_per_chassis * num_chassis + 1)] chassis_labels = [0] + [num for num in range(0, num_chassis) for _ in range(num_sensors_per_chassis)] sensor_labels = [0] + (list(range(1, num_sensors_per_chassis + 1))) * num_chassis @@ -23,6 +23,8 @@ def generate_data(): data_frames[global_l] = \ {'data': data_i, 'sensor': f'{chassis_l:02}:{sensor_l:02}', 'sensor_id': sensor_l, 'data_type': data_type_l} + + # data_frames = [] return {'timestamp': timestamp, 'data_frames': data_frames} From b3af3464491d830f7af0b61da2866db9f68b2e7c Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Tue, 11 Apr 2023 15:51:46 -0400 Subject: [PATCH 099/147] Make mock ork with fieldline example. Set data generation interval --- .../fieldline_api_mock/fieldline_service.py | 48 ++++++++++++++++++- .../mne_scan/plugins/fieldline/random_data.py | 6 +-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index 6023f430740..701fa1c509d 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -1,3 +1,7 @@ +import threading +import random_data +import time + class FieldLineService: def __init__(self, ip_list, prefix=""): """ @@ -12,6 +16,8 @@ def __init__(self, ip_list, prefix=""): # interfaces = netifaces.interfaces() self.network_interfaces = [] self.ip_list = ip_list + self.continue_data_acquisition = False + self.data_acquisition_thread = None # for i in interfaces: # print("interface %s" % i) # if i.startswith('lo'): @@ -43,15 +49,44 @@ def close(self): def load_sensors(self): print("loading sensors") # return self.data_source.load_sensors() + self.list_of_sensors = {i: list(range(1, 16 + 1)) for i in range(0, 1 + 1)} + + return self.list_of_sensors def get_chassis_list(self): print("get chassis list") # return self.data_source.get_chassis_list() + def data_acquisition(self): + + start_time = time.time() + data = random_data.generate_data() + end_time = time.time() + elapsed_time = end_time - start_time + time.sleep(0.001 - elapsed_time) + end_time = time.time() + + elapsed_time = end_time - start_time + elapsed_time_diff = (0.001 - elapsed_time) + + + while(self.continue_data_acquisition): + start_time = time.time() + data = random_data.generate_data() + self.callback_function(data) + end_time = time.time() + elapsed_time = end_time - start_time + # time_to_sleep = max(0, .001 - elapsed_time) + time.sleep(0.001 + elapsed_time_diff - elapsed_time) + # print(f"elapsed_time: {elapsed_time:04}") + def read_data(self, data_callback=None): - print("read_data defined. Callback set to : " + data_callback.__name__) + if(data_callback is not None): + print(f"read_data defined. Callback set to : {data_callback.__name__}") + self.callback_function = data_callback # self.data_source.read_data(data_callback=data_callback) + def start_adc(self, chassis_id): """ Start ADC from chassis @@ -59,6 +94,9 @@ def start_adc(self, chassis_id): chassis_id - unique ID of chassis """ print("start adc") + self.continue_data_acquisition = True + self.data_acquisition_thread = threading.Thread(target=self.data_acquisition) + self.data_acquisition_thread.start() # self.data_source.start_adc(chassis_id) def stop_adc(self, chassis_id): @@ -68,6 +106,8 @@ def stop_adc(self, chassis_id): chassis_id - unique ID of chassis """ print("stop adc") + self.continue_data_acquisition = False + self.data_acquisition_thread.join(timeout=5) # self.data_source.stop_adc(chassis_id) def turn_off_sensors(self, sensor_dict): @@ -91,6 +131,8 @@ def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed on_completed - callback when all sensors have either succeeded or failed """ print("restart sensors") + time.sleep(.3) + on_completed() # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_RESTART) @@ -105,6 +147,8 @@ def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_compl on_completed - callback when all sensors have either succeeded or failed """ print("coarse zero sensor") + time.sleep(.3) + on_completed() # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_COARSE_ZERO) @@ -119,6 +163,8 @@ def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_complet on_completed - callback when all sensors have either succeeded or failed """ print("fine zero sensors") + time.sleep(.3) + on_completed() # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_FINE_ZERO) diff --git a/resources/mne_scan/plugins/fieldline/random_data.py b/resources/mne_scan/plugins/fieldline/random_data.py index a058c57dfb5..59753c3bf6c 100644 --- a/resources/mne_scan/plugins/fieldline/random_data.py +++ b/resources/mne_scan/plugins/fieldline/random_data.py @@ -27,6 +27,6 @@ def generate_data(): # data_frames = [] return {'timestamp': timestamp, 'data_frames': data_frames} - -data = generate_data() -print(data) +if __name__ == "__main__": + data = generate_data() + print(data) From 8e9d9b24b8e6cdae552efa0307562e1227443830 Mon Sep 17 00:00:00 2001 From: gabrielbmotta Date: Tue, 11 Apr 2023 15:56:34 -0400 Subject: [PATCH 100/147] Fine tune sleep time in mock file --- .../fieldline/fieldline_api_mock/fieldline_service.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index 701fa1c509d..33f75f2fc9f 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -65,11 +65,10 @@ def data_acquisition(self): elapsed_time = end_time - start_time time.sleep(0.001 - elapsed_time) end_time = time.time() - + elapsed_time = end_time - start_time elapsed_time_diff = (0.001 - elapsed_time) - - + while(self.continue_data_acquisition): start_time = time.time() data = random_data.generate_data() @@ -77,7 +76,7 @@ def data_acquisition(self): end_time = time.time() elapsed_time = end_time - start_time # time_to_sleep = max(0, .001 - elapsed_time) - time.sleep(0.001 + elapsed_time_diff - elapsed_time) + time.sleep(0.001 + elapsed_time_diff - 0.5 * elapsed_time) # print(f"elapsed_time: {elapsed_time:04}") def read_data(self, data_callback=None): From 798ced303db50f5ffb2bab46970724a3dd7dea55 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 12 Apr 2023 19:31:49 -0400 Subject: [PATCH 101/147] add venv folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cca0064d56a..dcae112071d 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ __pycache__/ venv/ /resources/**/fieldline/*.whl /resources/**/fieldline/sample_restart.py +/resources/**/fieldline/venv/ .cache/* codecov From 0e62baf4f75265141c64bfede35b821550ad2753 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 12 Apr 2023 20:52:18 -0400 Subject: [PATCH 102/147] add fieldline definitions header file --- .../plugins/fieldline/fieldline_definitions.h | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h new file mode 100644 index 00000000000..ed2be7f815a --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h @@ -0,0 +1,73 @@ +//============================================================================================================= +/** + * @file fieldline_view.h + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + +#ifndef FIELDLINE_FIELDLINEDEFINITIONS_H +#define FIELDLINE_FIELDLINEDEFINITIONS_H + +namespace FIELDLINEPLUGIN { + +enum class FieldlineDataType { + DATA_BZ = 0, + DATA_BY = 1, + DATA_BX = 2 +}; + +enum class FieldLineWaveType { + WAVE_OFF = 0, + WAVE_RAMP = 1, + WAVE_SINE = 2, +}; + +enum class FieldLineSensorStatusType { + SENSOR_OFF = 0, + SENSOR_RESTARTING = 1, + SENSOR_RESTARTED = 2, + SENSOR_COARSE_ZEROING = 3, + SENSOR_COARSE_ZEROED = 4, + SENSOR_FINE_ZEROING = 5, + SENSOR_FINE_ZEROED = 6, + SENSOR_ERROR = 7, + SENSOR_READY = 8, +}; + +enum class FieldLineConnectStatusType { + CONNECT_OK = 0, + CONNECT_NOT_READY = 1, + CONNECT_CHASSIS_MISSING = 2, +}; + + + +} // namespace FIELDLINEPLUGIN From a38b8a07a3c5d94e1f18c89e6984f2fa416cef4b Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 12 Apr 2023 20:52:38 -0400 Subject: [PATCH 103/147] modify cmakelists fieldline --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 152 +++++++++--------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index c8bc5c9ee31..2a1993d9309 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -7,47 +7,47 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(QT NAMES Qt6 Qt5 REQUIRED - COMPONENTS Core Widgets Network Concurrent + COMPONENTS Core Widgets Network Concurrent ) find_package(Qt${QT_VERSION_MAJOR} REQUIRED - COMPONENTS Core Widgets Network Concurrent + COMPONENTS Core Widgets Network Concurrent ) execute_process( - COMMAND which python - OUTPUT_VARIABLE Python_EXECUTABLE - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND which python + OUTPUT_VARIABLE Python_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND dirname ${Python_EXECUTABLE} - OUTPUT_VARIABLE Python_BIN_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND dirname ${Python_EXECUTABLE} + OUTPUT_VARIABLE Python_BIN_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND pwd -P - WORKING_DIRECTORY ${Python_BIN_DIR}/.. - OUTPUT_VARIABLE Python_PREFIX - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND pwd -P + WORKING_DIRECTORY ${Python_BIN_DIR}/.. + OUTPUT_VARIABLE Python_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND pwd -P - WORKING_DIRECTORY ${Python_PREFIX}/lib - OUTPUT_VARIABLE Python_LIB_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND pwd -P + WORKING_DIRECTORY ${Python_PREFIX}/lib + OUTPUT_VARIABLE Python_LIB_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" - OUTPUT_VARIABLE Python_VERSION_MAJOR - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(major)" + OUTPUT_VARIABLE Python_VERSION_MAJOR + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(minor)" - OUTPUT_VARIABLE Python_VERSION_MINOR - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_EXECUTABLE} -c "import platform; major, minor, patch = platform.python_version_tuple(); print(minor)" + OUTPUT_VARIABLE Python_VERSION_MINOR + OUTPUT_STRIP_TRAILING_WHITESPACE ) if(EXISTS ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config) @@ -55,52 +55,52 @@ if(EXISTS ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR else() message(STATUS "python config not found") execute_process( - COMMAND readlink -f ${Python_EXECUTABLE} - OUTPUT_VARIABLE Python_EXECUTABLE_TRUE_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND readlink -f ${Python_EXECUTABLE} + OUTPUT_VARIABLE Python_EXECUTABLE_TRUE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND dirname ${Python_EXECUTABLE_TRUE_PATH} - OUTPUT_VARIABLE Python_BIN_TRUE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND dirname ${Python_EXECUTABLE_TRUE_PATH} + OUTPUT_VARIABLE Python_BIN_TRUE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ) if(NOT EXISTS ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config) message(FATAL python-config not found. Python installation missing python-config.) else() execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink - ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config - ) + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${Python_BIN_TRUE_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config + ) message(STATUS "Creating sym link to python config") endif() endif() execute_process( - COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes - OUTPUT_VARIABLE Python_INCLUDE_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes + OUTPUT_VARIABLE Python_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags - OUTPUT_VARIABLE Python_CFLAGS - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --cflags + OUTPUT_VARIABLE Python_CFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE ) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") execute_process( - COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs - OUTPUT_VARIABLE Python_LIBS - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs + OUTPUT_VARIABLE Python_LIBS + OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --ldflags - OUTPUT_VARIABLE Python_LDFLAGS - OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --ldflags + OUTPUT_VARIABLE Python_LDFLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE ) separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") @@ -133,27 +133,28 @@ set(HEADERS ) set(UI_FILES - formfiles/fieldline_view.ui - formfiles/fieldline_rack.ui - formfiles/fieldline_chassis.ui + formfiles/fieldline_view.ui + formfiles/fieldline_rack.ui + formfiles/fieldline_chassis.ui ) set(FILE_TO_UPDATE fieldline_global.cpp) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) - # message("File fieldline.json exists.") + # message("File fieldline.json exists.") else() - # message("File fieldline.json does not exist.") - # message("Creating a new fieldline.json file.") - execute_process(COMMAND "echo \"\"" + # message("File fieldline.json does not exist.") + # message("Creating a new fieldline.json file.") +execute_process(COMMAND "echo \"\"" WORKING_DIRECTORY ${CMAKE_C - OUTPUT_FILE fieldline.json) + OUTPUT_FILE fieldline.json +) endif() set(SOURCE_PATHS ${SOURCES}) list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES - OBJECT_DEPENDS "${SOURCE_PATHS}" + OBJECT_DEPENDS "${SOURCE_PATHS}" ) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) @@ -161,17 +162,17 @@ add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) set(FFTW_LIBS "") if(USE_FFTW) - if (WIN32) +if (WIN32) set(FFTW_LIBS - ${FFTW_DIR_LIBS}/libfftw3-3.dll - ${FFTW_DIR_LIBS}/libfftw3f-3.dll - ${FFTW_DIR_LIBS}/libfftwf3l-3.dll + ${FFTW_DIR_LIBS}/libfftw3-3.dll + ${FFTW_DIR_LIBS}/libfftw3f-3.dll + ${FFTW_DIR_LIBS}/libfftwf3l-3.dll ) target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) - elseif(UNIX AND NOT APPLE) +elseif(UNIX AND NOT APPLE) set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) - endif() +endif() endif() target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) @@ -179,19 +180,19 @@ target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Network - Qt${QT_VERSION_MAJOR}::Concurrent - eigen - mne_disp - mne_utils - mne_fiff - scDisp - scShared - scMeas - ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + scDisp + scShared + scMeas + ${FFTW_LIBS} + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") @@ -199,12 +200,13 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) add_link_options(${Python_LDFLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE - SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" - MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" + SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" ) if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${PROJECT_NAME} PRIVATE - STATICBUILD QT_STATICPLUGIN) + target_compile_definitions(${PROJECT_NAME} PRIVATE + STATICBUILD QT_STATICPLUGIN +) endif() From efa86dbf34f81d94d610fd5cf6e26c165a030860 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 13 Apr 2023 10:24:54 -0400 Subject: [PATCH 104/147] comment python to work with qt creator --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 8 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 12 ++- .../mne_scan/plugins/fieldline/fieldline.h | 4 +- .../plugins/fieldline/fieldline_definitions.h | 4 +- .../plugins/fieldline/fieldline_view.cpp | 95 ++++++++++++------- .../plugins/fieldline/fieldline_view.h | 24 +++-- .../fieldline/formfiles/fieldline_view.ui | 82 ++++++++++++---- 7 files changed, 155 insertions(+), 74 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 2a1993d9309..176efcc82df 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -121,21 +121,21 @@ message(" python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp fieldline.cpp - fieldline_acqsystem.cpp +# fieldline_acqsystem.cpp fieldline_view.cpp ) set(HEADERS fieldline_global.h fieldline.h - fieldline_acqsystem.h +# fieldline_acqsystem.h fieldline_view.h ) set(UI_FILES formfiles/fieldline_view.ui formfiles/fieldline_rack.ui - formfiles/fieldline_chassis.ui +# formfiles/fieldline_chassis.ui ) set(FILE_TO_UPDATE fieldline_global.cpp) @@ -192,7 +192,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + #python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index f7d315164c5..040413ddf83 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -43,7 +43,7 @@ //============================================================================================================= #include "fieldline/fieldline.h" -#include "fieldline/fieldline_acqsystem.h" +//#include "fieldline/fieldline_acqsystem.h" #include "fieldline/fieldline_view.h" #include @@ -125,7 +125,11 @@ namespace FIELDLINEPLUGIN { // DEFINE MEMBER METHODS //============================================================================================================= -Fieldline::Fieldline() { +Fieldline::Fieldline() + : + //acqSystem(nullptr), + guiWidget(nullptr) +{ } //============================================================================================================= @@ -155,7 +159,7 @@ void Fieldline::init() "FieldlinePlguin output"); m_outputConnectors.append(m_pRTMSA); - acqSystem = new FieldlineAcqSystem(this); +// acqSystem = new FieldlineAcqSystem(this); guiWidget = new FieldlineView(this); } @@ -163,7 +167,7 @@ void Fieldline::init() void Fieldline::unload() { qDebug() << "unload Fieldline"; - delete acqSystem; +// delete acqSystem; // delete guiWidget; // deleted by Qt } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 9fdb88da087..1057084d57b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -68,7 +68,7 @@ class FiffInfo; namespace FIELDLINEPLUGIN { -class FieldlineAcqSystem; +//class FieldlineAcqSystem; class FieldlineView; //============================================================================================================= @@ -110,7 +110,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { protected: virtual void run(); - FieldlineAcqSystem* acqSystem; +// FieldlineAcqSystem* acqSystem; FieldlineView* guiWidget; QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h index ed2be7f815a..8a788c55155 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h @@ -68,6 +68,6 @@ enum class FieldLineConnectStatusType { CONNECT_CHASSIS_MISSING = 2, }; - - } // namespace FIELDLINEPLUGIN + +#endif // FIELDLINE_FIELDLINEDEFINITIONS_H diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 026db6ec355..c0ef6cc35f3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -46,6 +46,7 @@ //============================================================================================================= #include +#include //============================================================================================================= // EIGEN INCLUDES @@ -68,12 +69,12 @@ namespace FIELDLINEPLUGIN { FieldlineView::FieldlineView(Fieldline* parent) : m_pFieldlinePlugin(parent), - m_pUi(new Ui::uiFieldlineView), - m_pAcqSystem(nullptr) + m_pUi(new Ui::uiFieldlineView) +// m_pAcqSystem(nullptr) { m_pUi->setupUi(this); initTopMenu(); - initTopMenuCallbacks(); +// initTopMenuCallbacks(); } FieldlineView::~FieldlineView() @@ -83,26 +84,43 @@ FieldlineView::~FieldlineView() void FieldlineView::initTopMenu() { - QVBoxLayout* frameLayout = qobject_cast(m_pUi->ipMacFrame->layout()); + m_pUi->topMenuFrame->setEnabled(true); + m_pUi->numChassisSpinBox->setMinimum(0); + m_pUi->numChassisSpinBox->setMaximum(6); + m_pUi->numChassisSpinBox->setValue(0); + QObject::connect(m_pUi->numChassisSpinBox,QOverload::of(&QSpinBox::valueChanged), + this, &FieldlineView::setNumRowsIpMacFrame); + QObject::connect(m_pUi->findBtn, &QPushButton::clicked, + this, &FieldlineView::findChassis); +} - QHBoxLayout* ipMacLayout1 = new QHBoxLayout(m_pUi->ipMacFrame); - QLineEdit* ip1 = new QLineEdit("ip1"); - ip1->setEnabled(false); - QLineEdit* macAddr1 = new QLineEdit("macaddr1"); - ipMacLayout1->addWidget(macAddr1); - ipMacLayout1->addWidget(ip1); - - QHBoxLayout* ipMacLayout2 = new QHBoxLayout(m_pUi->ipMacFrame); - QLineEdit* ip2 = new QLineEdit("ip2"); - ip2->setEnabled(false); - QLineEdit* macAddr2 = new QLineEdit("macaddr2"); - ipMacLayout2->addWidget(macAddr2); - ipMacLayout2->addWidget(ip2); - - frameLayout->insertLayout(1, ipMacLayout1); - frameLayout->insertLayout(1, ipMacLayout2); +void FieldlineView::setNumRowsIpMacFrame(int i) +{ + QVBoxLayout* frameLayout = qobject_cast(m_pUi->ipMacFrame->layout()); + if ( i < m_ipMacList.size()) + { + frameLayout->removeWidget(qobject_cast(m_ipMacList.back())); + m_ipMacList.pop_back(); + } + if ( i > m_ipMacList.size()) + { + QHBoxLayout* ipMacLayout = new QHBoxLayout(m_pUi->ipMacFrame); + QLineEdit* ip = new QLineEdit("0.0.0.0"); + ip->setEnabled(false); + QLineEdit* macAddr = new QLineEdit("AF-70-04-21-2D-28"); + ipMacLayout->addWidget(macAddr); + ipMacLayout->addWidget(ip); + frameLayout->insertLayout(m_ipMacList.size() + 1, ipMacLayout); + m_ipMacList.push_back(ipMacLayout); + } } +void FieldlineView::findChassis() +{ + //generate list of mac addresses + //call class finder. + // retrieve list of ips and set variable with it. +} void FieldlineView::initCallbacks() { } @@ -110,31 +128,36 @@ void FieldlineView::initCallbacks() void FieldlineView::initAcqSystem(int numChassis, const std::vector>& chans) { displayAcqSystem(); - initAcqSystemCallbacks(); } void FieldlineView::displayAcqSystem() { - QVBoxLayout* rackFrameLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); - for (int i = 0; i < numChassis; i++) - { - FieldlineChassis* chassis = new FieldlineViewChassis(chans[i]); +// QVBoxLayout* rackFrameLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); +// for (int i = 0; i < numChassis; i++) +// { +// FieldlineChassis* chassis = new FieldlineViewChassis(chans[i]); - rackFrameLayout->addWidget(chassis); - } +// rackFrameLayout->addWidget(chassis); +// } } -void FieldlineView::setChannelState(size_t chassis_i, size_t chan_i) -{ -} -statish FieldlineView::getChannelState(size_t chassis_i, size_t chan_i) -{ -} +//void FieldlineView::on_numChassisSpinBox_valueChanged(int arg1) +//{ -statish FieldlineView::setAllChannelState(size_t chassis_i, statish) -{ -} +//} + +//void FieldlineView::setChannelState(size_t chassis_i, size_t chan_i) +//{ +//} + +//statish FieldlineView::getChannelState(size_t chassis_i, size_t chan_i) +//{ +//} + +//statish FieldlineView::setAllChannelState(size_t chassis_i, statish) +//{ +//} } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index af1aa9a2afa..71f28a21e16 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -63,11 +63,12 @@ class uiFieldlineView; //============================================================================================================= // DEFINE NAMESPACE DISPLIB //============================================================================================================= +class QHBoxLayout; namespace FIELDLINEPLUGIN { class Fieldline; -class FieldlineViewChassis; +//class FieldlineViewChassis; enum class FieldlineDataType { DATA_BZ = 0, @@ -113,22 +114,27 @@ class FieldlineView : public QWidget // void getLedColor()// // void setLedAllColor(const QColor& color); // void setLedAllColor(const QColor &color, bool blinking); - void setChannelState(size_t chassis_i, size_t chan_i); - statish getChannelState(size_t chassis_i, size_t chan_i); - void setAllChannelsState(size_t chassis_i, statish); - - private: +// void setChannelState(size_t chassis_i, size_t chan_i); +// statish getChannelState(size_t chassis_i, size_t chan_i); +// void setAllChannelsState(size_t chassis_i, statish); + +private slots: +// void on_numChassisSpinBox_valueChanged(int arg1); + void setNumRowsIpMacFrame(int i); +private: + void displayAcqSystem(); void initAcqSystem(int numChassis, const std::vector>& channels); - + void initCallbacks(); void initTopMenu(); - void initTopMenuCallbacks(); + void initAcqSystem(); void initAcqSystemCallbacks(); Fieldline* m_pFieldlinePlugin; Ui::uiFieldlineView* m_pUi; - std::vector* m_pAcqSystem; + std::vector m_ipMacList; +// std::vector* m_pAcqSystem; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index d01f120d85f..02a115ac056 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -62,6 +62,16 @@ QFrame::Raised + + + + + 50 + 16777215 + + + + @@ -135,7 +145,7 @@ 0 - + 0 @@ -151,7 +161,7 @@ - + 0 @@ -214,7 +224,7 @@ - + 0 @@ -227,22 +237,60 @@ QFrame::Raised - + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::Horizontal + + + + 597 + 20 + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::Vertical + + + + 20 + 215 + + + + + + + + - - - - Qt::Vertical - - - - 20 - 40 - - - - From 02123d78e74312e0a7708934b215291509d5b5da Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 14 Apr 2023 01:20:25 -0400 Subject: [PATCH 105/147] add table for ip mac addresses --- .clang-format_old | 250 ++++++++++++++++++ .clangd | 5 - .../mne_scan/plugins/fieldline/CMakeLists.txt | 1 + .../plugins/fieldline/fieldline_view.cpp | 70 +++-- .../plugins/fieldline/fieldline_view.h | 39 +-- .../fieldline/formfiles/fieldline_view.ui | 164 +++++------- 6 files changed, 374 insertions(+), 155 deletions(-) create mode 100644 .clang-format_old delete mode 100644 .clangd diff --git a/.clang-format_old b/.clang-format_old new file mode 100644 index 00000000000..1da44674a81 --- /dev/null +++ b/.clang-format_old @@ -0,0 +1,250 @@ +--- +Language: Cpp +BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +reakBeforeBraces: Allman +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +olumnLimit: 110 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +pp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: NextLine +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: true +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RequiresClausePosition: OwnLine +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/.clangd b/.clangd deleted file mode 100644 index 2df5e3d6d83..00000000000 --- a/.clangd +++ /dev/null @@ -1,5 +0,0 @@ -Diagnostics: - UnusedIncludes: Strict - InlayHints: - Enabled: No - diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 176efcc82df..bbbc4475a3a 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -127,6 +127,7 @@ set(SOURCES set(HEADERS fieldline_global.h + fieldline_definitions.h fieldline.h # fieldline_acqsystem.h fieldline_view.h diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index c0ef6cc35f3..0df1d40e23d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -46,7 +46,12 @@ //============================================================================================================= #include +#include +#include +#include #include +#include +#include //============================================================================================================= // EIGEN INCLUDES @@ -75,6 +80,7 @@ FieldlineView::FieldlineView(Fieldline* parent) m_pUi->setupUi(this); initTopMenu(); // initTopMenuCallbacks(); +// m_ipMacList.reserve(6); } FieldlineView::~FieldlineView() @@ -88,39 +94,67 @@ void FieldlineView::initTopMenu() m_pUi->numChassisSpinBox->setMinimum(0); m_pUi->numChassisSpinBox->setMaximum(6); m_pUi->numChassisSpinBox->setValue(0); + + m_pMacIpTable = new QTableWidget(this); + m_pMacIpTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_pMacIpTable->verticalHeader()->setSectionHidden(0,true); + + m_pMacIpTable->setColumnCount(2); + m_pMacIpTable->setHorizontalHeaderLabels(QStringList({"Mac","IP"})); + + QVBoxLayout* macIpTableLayout = qobject_cast(m_pUi->ipMacFrame->layout()); + macIpTableLayout->insertWidget(0, m_pMacIpTable); + + connect( m_pMacIpTable, SIGNAL(cellDoubleClicked(int,int)), + this, SLOT( cellSelected(int,int))); QObject::connect(m_pUi->numChassisSpinBox,QOverload::of(&QSpinBox::valueChanged), - this, &FieldlineView::setNumRowsIpMacFrame); + this, &FieldlineView::setNumRowsIpMacFrame); QObject::connect(m_pUi->findBtn, &QPushButton::clicked, this, &FieldlineView::findChassis); + +} + +void FieldlineView::cellSelected(int row, int col) { + std::cout << "row: " << row << " col " << col << "\n"; + std::cout.flush(); } void FieldlineView::setNumRowsIpMacFrame(int i) { - QVBoxLayout* frameLayout = qobject_cast(m_pUi->ipMacFrame->layout()); - if ( i < m_ipMacList.size()) - { - frameLayout->removeWidget(qobject_cast(m_ipMacList.back())); - m_ipMacList.pop_back(); - } - if ( i > m_ipMacList.size()) - { - QHBoxLayout* ipMacLayout = new QHBoxLayout(m_pUi->ipMacFrame); - QLineEdit* ip = new QLineEdit("0.0.0.0"); - ip->setEnabled(false); - QLineEdit* macAddr = new QLineEdit("AF-70-04-21-2D-28"); - ipMacLayout->addWidget(macAddr); - ipMacLayout->addWidget(ip); - frameLayout->insertLayout(m_ipMacList.size() + 1, ipMacLayout); - m_ipMacList.push_back(ipMacLayout); - } + m_pMacIpTable->setRowCount(i); + m_pMacIpTable->setSortingEnabled(false); + m_pMacIpTable->setItem(i-1, 0, new QTableWidgetItem("Hello")); + m_pMacIpTable->setItem(i-1, 1, new QTableWidgetItem("Baby")); + m_pMacIpTable->setSortingEnabled(true);// QVBoxLayout* vertIpMacLayout = qobject_cast(m_pUi->ipMacFrame->layout()); +// if ( i < m_ipMacList.size()) +// { +// vertIpMacLayout->removeItem(m_ipMacList.back()); +// delete m_ipMacList.back(); +// m_ipMacList.pop_back(); +// } +// if ( i > m_ipMacList.size()) +// { +// QHBoxLayout* ipMacLayout = new QHBoxLayout(m_pUi->ipMacFrame); +// QLineEdit* ip = new QLineEdit("0.0.0.0"); +// ip->setEnabled(false); +// QLineEdit* macAddr = new QLineEdit("AF-70-04-21-2D-28"); +// ipMacLayout->addWidget(macAddr); +// ipMacLayout->addWidget(ip); +// vertIpMacLayout->insertLayout(m_ipMacList.size() + 1, ipMacLayout); +// m_ipMacList.push_back(ipMacLayout); +// } } void FieldlineView::findChassis() { + qDebug() << "Find chasssis!\n"; + std::cout.flush(); + //generate list of mac addresses //call class finder. // retrieve list of ips and set variable with it. } + void FieldlineView::initCallbacks() { } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 71f28a21e16..d434a6c4567 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -64,41 +64,12 @@ class uiFieldlineView; // DEFINE NAMESPACE DISPLIB //============================================================================================================= class QHBoxLayout; +class QTableWidget; namespace FIELDLINEPLUGIN { class Fieldline; -//class FieldlineViewChassis; - -enum class FieldlineDataType { - DATA_BZ = 0, - DATA_BY = 1, - DATA_BX = 2 -}; - -enum class FieldLineWaveType { - WAVE_OFF = 0, - WAVE_RAMP = 1, - WAVE_SINE = 2, -}; - -enum class FieldLineSensorStatusType { - SENSOR_OFF = 0, - SENSOR_RESTARTING = 1, - SENSOR_RESTARTED = 2, - SENSOR_COARSE_ZEROING = 3, - SENSOR_COARSE_ZEROED = 4, - SENSOR_FINE_ZEROING = 5, - SENSOR_FINE_ZEROED = 6, - SENSOR_ERROR = 7, - SENSOR_READY = 8, -}; - -enum class FieldLineConnectStatusType { - CONNECT_OK = 0, - CONNECT_NOT_READY = 1, - CONNECT_CHASSIS_MISSING = 2, -}; +// class FieldlineViewChassis; //============================================================================================================= @@ -126,14 +97,16 @@ private slots: void initAcqSystem(int numChassis, const std::vector>& channels); void initCallbacks(); void initTopMenu(); - + void findChassis(); + void cellSelected(int, int); void initAcqSystem(); void initAcqSystemCallbacks(); Fieldline* m_pFieldlinePlugin; Ui::uiFieldlineView* m_pUi; - std::vector m_ipMacList; + QTableWidget* m_pMacIpTable; +// std::vector m_ipMacList; // std::vector* m_pAcqSystem; }; diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 02a115ac056..6f710d2938d 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -45,14 +45,14 @@ - 0 - 0 + 600 + 100 - 16777215 - 200 + 800 + 115 @@ -62,27 +62,29 @@ QFrame::Raised - - - - - 50 - 16777215 - - - - true - + 0 0 + + + 0 + 0 + + + + + 300 + 110 + + QFrame::StyledPanel @@ -105,86 +107,6 @@ 0 - - - - true - - - - 0 - 0 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - -1 - - - 10 - - - 0 - - - 10 - - - 0 - - - - - - 0 - 0 - - - - IP Address - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - MAC Address - - - Qt::AlignCenter - - - - - - @@ -196,27 +118,71 @@ 0 + + + 330 + 100 + + QFrame::NoFrame QFrame::Plain - - + + + + + 0 + 0 + + + + + 140 + 16777215 + + - Find Acq System + Find Acq System - + + + + 140 + 0 + + Connect + + + + Number of Chassis + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + 16777215 + + + + From 831ac05967bd5216f37d610101288f41c20dfa6e Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 14 Apr 2023 18:48:20 -0400 Subject: [PATCH 106/147] prepare chassis without form file --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 5 +- .../plugins/fieldline/fieldline_view.cpp | 109 ++++++++++++++---- .../plugins/fieldline/fieldline_view.h | 33 +++--- .../fieldline/fieldline_view_chassis.cpp | 13 ++- .../fieldline/fieldline_view_chassis.h | 14 +-- .../fieldline/formfiles/fieldline_chassis.ui | 4 +- .../fieldline/formfiles/fieldline_view.ui | 20 ++-- 7 files changed, 136 insertions(+), 62 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index bbbc4475a3a..d863e861dfc 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -123,6 +123,7 @@ set(SOURCES fieldline.cpp # fieldline_acqsystem.cpp fieldline_view.cpp + fieldline_view_chassis.cpp ) set(HEADERS @@ -131,12 +132,12 @@ set(HEADERS fieldline.h # fieldline_acqsystem.h fieldline_view.h + fieldline_view_chassis.h ) set(UI_FILES formfiles/fieldline_view.ui - formfiles/fieldline_rack.ui -# formfiles/fieldline_chassis.ui + formfiles/fieldline_chassis.ui ) set(FILE_TO_UPDATE fieldline_global.cpp) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 0df1d40e23d..8a1a0ee921c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -79,8 +79,7 @@ FieldlineView::FieldlineView(Fieldline* parent) { m_pUi->setupUi(this); initTopMenu(); -// initTopMenuCallbacks(); -// m_ipMacList.reserve(6); + initAcqSystem(2); } FieldlineView::~FieldlineView() @@ -94,7 +93,6 @@ void FieldlineView::initTopMenu() m_pUi->numChassisSpinBox->setMinimum(0); m_pUi->numChassisSpinBox->setMaximum(6); m_pUi->numChassisSpinBox->setValue(0); - m_pMacIpTable = new QTableWidget(this); m_pMacIpTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); m_pMacIpTable->verticalHeader()->setSectionHidden(0,true); @@ -105,17 +103,32 @@ void FieldlineView::initTopMenu() QVBoxLayout* macIpTableLayout = qobject_cast(m_pUi->ipMacFrame->layout()); macIpTableLayout->insertWidget(0, m_pMacIpTable); - connect( m_pMacIpTable, SIGNAL(cellDoubleClicked(int,int)), - this, SLOT( cellSelected(int,int))); + QObject::connect(m_pMacIpTable, QOverload::of(&QTableWidget::cellDoubleClicked), + this, &FieldlineView::macIpTableDoubleClicked); + QObject::connect(m_pMacIpTable, &QTableWidget::itemChanged, + this, &FieldlineView::macIpTableValueChanged); QObject::connect(m_pUi->numChassisSpinBox,QOverload::of(&QSpinBox::valueChanged), this, &FieldlineView::setNumRowsIpMacFrame); - QObject::connect(m_pUi->findBtn, &QPushButton::clicked, - this, &FieldlineView::findChassis); + QObject::connect(m_pUi->disconnectBtn, &QPushButton::clicked, + this, &FieldlineView::disconnect); +} +void FieldlineView::macIpTableDoubleClicked(int row, int col) { + std::cout << "row: " << row << " col: " << col << "\n"; + std::cout.flush(); + if ( col == 0 ) { +// std::string macAddr = findIP(m_pMacIpTable->item(row, col)->text.toStdString()); + std::string macAddr("0.0.0.0"); + m_pMacIpTable->item(row, col + 1)->setText(QString::fromStdString(macAddr)); + } + if ( col == 1 ) { + // perhaps send ping? + } } -void FieldlineView::cellSelected(int row, int col) { - std::cout << "row: " << row << " col " << col << "\n"; +void FieldlineView::macIpTableValueChanged(QTableWidgetItem* item) +{ + std::cout << "cell (" << item->row() << "," << item->column() << " changed to: " << item->text().toStdString() << "\n"; std::cout.flush(); } @@ -123,9 +136,11 @@ void FieldlineView::setNumRowsIpMacFrame(int i) { m_pMacIpTable->setRowCount(i); m_pMacIpTable->setSortingEnabled(false); - m_pMacIpTable->setItem(i-1, 0, new QTableWidgetItem("Hello")); - m_pMacIpTable->setItem(i-1, 1, new QTableWidgetItem("Baby")); - m_pMacIpTable->setSortingEnabled(true);// QVBoxLayout* vertIpMacLayout = qobject_cast(m_pUi->ipMacFrame->layout()); + m_pMacIpTable->setItem(i-1, 0, new QTableWidgetItem("AF-70-04-21-2D-28")); + m_pMacIpTable->setItem(i-1, 1, new QTableWidgetItem("0.0.0.0")); + m_pMacIpTable->item(i-1, 0)->setToolTip((QString("Doubleclick to find the IP."))); + m_pMacIpTable->setSortingEnabled(true); + // QVBoxLayout* vertIpMacLayout = qobject_cast(m_pUi->ipMacFrame->layout()); // if ( i < m_ipMacList.size()) // { // vertIpMacLayout->removeItem(m_ipMacList.back()); @@ -145,7 +160,7 @@ void FieldlineView::setNumRowsIpMacFrame(int i) // } } -void FieldlineView::findChassis() +void FieldlineView::disconnect() { qDebug() << "Find chasssis!\n"; std::cout.flush(); @@ -155,31 +170,83 @@ void FieldlineView::findChassis() // retrieve list of ips and set variable with it. } -void FieldlineView::initCallbacks() +void FieldlineView::initAcqSystemTopButtons() { + QPushButton* button = new QPushButton(QString("Start"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::startAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(0, button); + + button = new QPushButton(QString("Stop"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::stopAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(1, button); + + button = new QPushButton(QString("Auto-Tune"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::autoTuneAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(3, button); + + button = new QPushButton(QString("Restart Sensors"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::restartAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(4, button); + + button = new QPushButton(QString("Coarse Zero"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::coarseZeroAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(5, button); + + button = new QPushButton(QString("Fine Zero"), m_pUi->acqSystemTopButtonsFrame); + QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::fineZeroAllSensors); + acqSystemTopBtnMenuLayout->insertWidget(6, button); } -void FieldlineView::initAcqSystem(int numChassis, const std::vector>& chans) +void FieldlineView::initAcqSystem(int numChassis) { - displayAcqSystem(); + QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); + initAcqSystemTopButtons(); + for( int i = 0; i < numChassis; i++ ) { + m_pAcqSystem.emplace_back(); + } } -void FieldlineView::displayAcqSystem() + +void FieldlineView::initAcqSystem() { // QVBoxLayout* rackFrameLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); // for (int i = 0; i < numChassis; i++) // { // FieldlineChassis* chassis = new FieldlineViewChassis(chans[i]); - // rackFrameLayout->addWidget(chassis); // } } +void FieldlineView::startAllSensors() { + std::cout << "startAllSensors" << "\n"; + std::cout.flush(); +} -//void FieldlineView::on_numChassisSpinBox_valueChanged(int arg1) -//{ +void FieldlineView::stopAllSensors() { + std::cout << "stopAllSensors" << "\n"; + std::cout.flush(); +} + +void FieldlineView::autoTuneAllSensors() { + std::cout << "autoTuneAllSensors" << "\n"; + std::cout.flush(); +} + +void FieldlineView::restartAllSensors() { + std::cout << "restartAllSensors" << "\n"; + std::cout.flush(); +} + +void FieldlineView::coarseZeroAllSensors() { + std::cout << "coarseZeroAllSensors" << "\n"; + std::cout.flush(); +} + +void FieldlineView::fineZeroAllSensors() { + std::cout << "fineZeroAllSensors" << "\n"; + std::cout.flush(); +} -//} //void FieldlineView::setChannelState(size_t chassis_i, size_t chan_i) //{ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index d434a6c4567..97524f9251d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -65,6 +65,7 @@ class uiFieldlineView; //============================================================================================================= class QHBoxLayout; class QTableWidget; +class QTableWidgetItem; namespace FIELDLINEPLUGIN { @@ -81,33 +82,29 @@ class FieldlineView : public QWidget explicit FieldlineView(Fieldline* parent); ~FieldlineView(); - // void setLedColor(size_t chassis_id, size_t chan_num, const QColor& color); - // void getLedColor()// - // void setLedAllColor(const QColor& color); - // void setLedAllColor(const QColor &color, bool blinking); -// void setChannelState(size_t chassis_i, size_t chan_i); -// statish getChannelState(size_t chassis_i, size_t chan_i); -// void setAllChannelsState(size_t chassis_i, statish); - -private slots: -// void on_numChassisSpinBox_valueChanged(int arg1); - void setNumRowsIpMacFrame(int i); private: - void displayAcqSystem(); - void initAcqSystem(int numChassis, const std::vector>& channels); - void initCallbacks(); + void initAcqSystem(int numChassis); void initTopMenu(); - void findChassis(); - void cellSelected(int, int); + void disconnect(); + void macIpTableDoubleClicked(int, int); + void macIpTableValueChanged(QTableWidgetItem* item); void initAcqSystem(); void initAcqSystemCallbacks(); + void initAcqSystemTopButtons(); + void setNumRowsIpMacFrame(int i); + + void startAllSensors(); + void stopAllSensors(); + void autoTuneAllSensors(); + void restartAllSensors(); + void coarseZeroAllSensors(); + void fineZeroAllSensors(); Fieldline* m_pFieldlinePlugin; Ui::uiFieldlineView* m_pUi; QTableWidget* m_pMacIpTable; -// std::vector m_ipMacList; -// std::vector* m_pAcqSystem; + std::vector m_pAcqSystem; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp index 8f195f2db7f..79ab1f22963 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp @@ -39,8 +39,8 @@ // #include "fieldline/fieldline_view.h" // #include "fieldline/fieldline.h" -#include "formfiles/ui_fieldline_view.h" -#include "formfiles/ui_fieldline_rack.h" +//#include "formfiles/ui_fieldline_view.h" +//#include "formfiles/ui_fieldline_rack.h" #include "formfiles/ui_fieldline_chassis.h" //============================================================================================================= @@ -75,11 +75,14 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= -FieldlineViewChassis::FieldlineViewChassis(int num_chans, QWidget *parent ) +FieldlineViewChassis::FieldlineViewChassis(QWidget *parent ) : QWidget(parent) -, m_pUi(new Ui::uiFieldlineViewChassis) { - ui->setupUi(this); + QVBoxLayout* layout = new QVBoxLayout; + QFrame* frame = new QFrame; + + layout->addWidget(frame); + QWidget::setLayout(layout); } FieldlineViewChassis::~FieldlineViewChassis() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index f74cf1b6b8e..a17fe6d6572 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -44,7 +44,7 @@ //============================================================================================================= #include -int aalakjdflaskjdflkajsdlfkasjfdlksdjfsldkfjasldkjfasmssmkjlkjdfisldkfjasldkfjalskdjflaskdjfasldkfjasldkfjlkkkkkkkkkkkkkkk = 44; + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -53,9 +53,9 @@ int aalakjdflaskjdflkajsdlfkasjfdlksdjfsldkfjasldkjfasmssmkjlkjdfisldkfjasldkfja // FORWARD DECLARATIONS //============================================================================================================= -namespace Ui { +//namespace Ui { // class uiFieldlineViewChassis; -} +//} //============================================================================================================= // DEFINE NAMESPACE DISPLIB //============================================================================================================= @@ -71,7 +71,7 @@ class FieldlineViewChassis : public QWidget Q_OBJECT public: - FieldlineViewChassis(int num_chans, QWidget *parent = nullptr); + FieldlineViewChassis(QWidget *parent = nullptr); ~FieldlineViewChassis(); void setChannelState(size_t chan_i, statish); statish getChannelState(size_t chan_i); @@ -90,9 +90,9 @@ class FieldlineViewChassis : public QWidget // void rightClickMenu(int chan, const QPoint& pos); private: - QWidget* m_pParent; - // Ui::uiFieldlineViewChassis* m_pUi; - // std::vector* m_pChannels; + +// Ui::uiFieldlineViewChassis* m_pUi; + std::vector m_pChannels; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui index 6f225cf5f65..410a4dc4beb 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui @@ -36,7 +36,7 @@ - + 0 @@ -49,7 +49,7 @@ - + 0 diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 6f710d2938d..6dcb4720686 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -75,13 +75,13 @@ - 0 + 350 0 - 300 + 400 110 @@ -132,7 +132,7 @@ - + 0 @@ -146,11 +146,11 @@ - Find Acq System + Disconnect - + @@ -163,7 +163,7 @@ - + Number of Chassis @@ -173,7 +173,7 @@ - + @@ -197,6 +197,12 @@ 0 + + + 800 + 16777215 + + QFrame::StyledPanel From 9153ee11a17be8ff6045c8afc1701f1d9afb151b Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 20 Apr 2023 19:27:24 -0400 Subject: [PATCH 107/147] find ip given mac --- .clangd | 3 + .../mne_scan/plugins/fieldline/CMakeLists.txt | 10 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 25 +-- .../mne_scan/plugins/fieldline/fieldline.h | 32 ++-- .../plugins/fieldline/fieldline_view.cpp | 10 +- .../plugins/fieldline/fieldline_view.h | 2 +- .../fieldline/fieldline_view_chassis.h | 12 +- .../mne_scan/plugins/fieldline/ipfinder.cpp | 158 ++++++++++++++++++ .../mne_scan/plugins/fieldline/ipfinder.h | 84 ++++++++++ .../plugins/fieldline/ipfinder_network.cpp | 87 ++++++++++ .../plugins/fieldline/ipfinder_network.h | 21 +++ 11 files changed, 406 insertions(+), 38 deletions(-) create mode 100644 .clangd create mode 100644 src/applications/mne_scan/plugins/fieldline/ipfinder.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/ipfinder.h create mode 100644 src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/ipfinder_network.h diff --git a/.clangd b/.clangd new file mode 100644 index 00000000000..3af4d40d4e3 --- /dev/null +++ b/.clangd @@ -0,0 +1,3 @@ +InlayHints: + Enabled: No + diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index d863e861dfc..6338bd7404d 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -116,14 +116,16 @@ message( "python cflags: " ${Python_CFLAGS}) message( "python cflags norm: " ${Python_CFLAGS_NORM}) message( "python libraries: " ${Python_LIBS}) message( "python lib flags: " ${Python_LDFLAGS}) -message(" python lib flags norm: " ${Python_LDFLAGS_NORM}) +message( "python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp fieldline.cpp # fieldline_acqsystem.cpp fieldline_view.cpp - fieldline_view_chassis.cpp + # fieldline_view_chassis.cpp + ipfinder.cpp + ipfinder_network.cpp ) set(HEADERS @@ -132,7 +134,9 @@ set(HEADERS fieldline.h # fieldline_acqsystem.h fieldline_view.h - fieldline_view_chassis.h + # fieldline_view_chassis.h + ipfinder.h + ipfinder_network.h ) set(UI_FILES diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 040413ddf83..45ecad61865 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -45,6 +45,7 @@ #include "fieldline/fieldline.h" //#include "fieldline/fieldline_acqsystem.h" #include "fieldline/fieldline_view.h" +#include "fieldline/ipfinder.h" #include // #include @@ -126,9 +127,9 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= Fieldline::Fieldline() - : - //acqSystem(nullptr), - guiWidget(nullptr) + : + //acqSystem(nullptr), + guiWidget(nullptr) { } @@ -167,7 +168,7 @@ void Fieldline::init() void Fieldline::unload() { qDebug() << "unload Fieldline"; -// delete acqSystem; + // delete acqSystem; // delete guiWidget; // deleted by Qt } @@ -211,13 +212,15 @@ QWidget *Fieldline::setupWidget() { //============================================================================================================= -// void Fieldline::onNewDataAvailable(const Eigen::MatrixXd &matData) { -// -// while(!m_pCircularBuffer->push(matData)) { -// //Do nothing until the circular buffer is ready to accept new data -// again -// } -// } +std::string Fieldline::findIp(const std::string& neti, const std::string& mac) { + + IPFINDER::IpFinder ipFinder; + ipFinder.addMacAddress(mac); + ipFinder.findIps(); + // ipFinder.macIpList. + return ipFinder.macIpList[0].ip; + +} //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 1057084d57b..feead38edbb 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -68,7 +68,7 @@ class FiffInfo; namespace FIELDLINEPLUGIN { -//class FieldlineAcqSystem; +// class FieldlineAcqSystem; class FieldlineView; //============================================================================================================= @@ -77,38 +77,40 @@ class FieldlineView; * * @brief The Fieldline class provides a MEG connector for receiving data from Fieldline API. */ -class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor { +class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor +{ Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") Q_INTERFACES(SCSHAREDLIB::AbstractSensor) public: - //========================================================================================================= - // The plugin interface - Fieldline(); + //========================================================================================================= + // The plugin interface + Fieldline(); - ~Fieldline(); + ~Fieldline(); - virtual QSharedPointer clone() const; + virtual QSharedPointer clone() const; - virtual void init(); + virtual void init(); - virtual void unload(); + virtual void unload(); - virtual bool start(); + virtual bool start(); - virtual bool stop(); + virtual bool stop(); - virtual AbstractPlugin::PluginType getType() const; + virtual AbstractPlugin::PluginType getType() const; - virtual QString getName() const; + virtual QString getName() const; - virtual QWidget* setupWidget(); + virtual QWidget* setupWidget(); - virtual QString getBuildInfo(); + virtual QString getBuildInfo(); protected: virtual void run(); + std::string findIp(const std::string& neti, const std::string& mac); // FieldlineAcqSystem* acqSystem; FieldlineView* guiWidget; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 8a1a0ee921c..b7e58ab3000 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -172,6 +172,8 @@ void FieldlineView::disconnect() void FieldlineView::initAcqSystemTopButtons() { + QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); + QPushButton* button = new QPushButton(QString("Start"), m_pUi->acqSystemTopButtonsFrame); QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::startAllSensors); acqSystemTopBtnMenuLayout->insertWidget(0, button); @@ -199,11 +201,11 @@ void FieldlineView::initAcqSystemTopButtons() void FieldlineView::initAcqSystem(int numChassis) { - QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); + // QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); initAcqSystemTopButtons(); - for( int i = 0; i < numChassis; i++ ) { - m_pAcqSystem.emplace_back(); - } + // for( int i = 0; i < numChassis; i++ ) { + // m_pAcqSystem.emplace_back(); + // } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 97524f9251d..9370a9d595c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -104,7 +104,7 @@ class FieldlineView : public QWidget Fieldline* m_pFieldlinePlugin; Ui::uiFieldlineView* m_pUi; QTableWidget* m_pMacIpTable; - std::vector m_pAcqSystem; + // std::vector m_pAcqSystem; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index a17fe6d6572..4e5ffb2c96f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -33,11 +33,14 @@ * */ +#ifndef FIELDLINEPLUGIN_FIELDLINEVIEW_H + //============================================================================================================= // INCLUDES //============================================================================================================= // #include "disp/viewers/led_indicator.h" +#include "fieldline/fieldline_definitions.h" //============================================================================================================= // QT INCLUDES @@ -71,10 +74,10 @@ class FieldlineViewChassis : public QWidget Q_OBJECT public: - FieldlineViewChassis(QWidget *parent = nullptr); + explicit FieldlineViewChassis(QWidget *parent = nullptr); ~FieldlineViewChassis(); - void setChannelState(size_t chan_i, statish); - statish getChannelState(size_t chan_i); + void setChannelState(size_t chan_i, FieldLineSensorStatusType status); + FieldLineSensorStatusType getChannelState(size_t chan_i); // void setColor(size_t chan_num, const QColor& color); // void setColor(size_t chan_num, const QColor& color, bool blinking); // void setColor(const QColor& color); @@ -87,7 +90,7 @@ class FieldlineViewChassis : public QWidget // void clicked(int chan, const QPoint& pos); // // private slots: - // void rightClickMenu(int chan, const QPoint& pos); +// void rightClickMenu(int chan, const QPoint& pos); private: @@ -97,3 +100,4 @@ class FieldlineViewChassis : public QWidget } // namespace FIELDLINEPLUGIN +#endif // FIELDLINEPLUGIN_FIELDLINEVIEW_H diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp new file mode 100644 index 00000000000..852ec9b4c76 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp @@ -0,0 +1,158 @@ +//============================================================================================================= +/** + * @file ipfinder.cpp + * @author Juan GarciaPrieto + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the definition of the Fieldline class. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ipfinder.h" +#include "ipfinder_network.h" + +namespace IPFINDER { + +const std::regex MAC_REGEX("[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}"); +const std::regex IP_REGEX("[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}"); +const char* default_table_file = "~/.ipfinder_171921"; +const int defaultNumRetriesMax = 3; + +void printMacIpList(const std::vector& macIpList) { + for (const MacIp& macip_i : macIpList) { + std::cout << "mac: " << macip_i.mac << " - ip: " + << (macip_i.ip.empty() ? "not found" : macip_i.ip) + << "\n"; + } +} + +void sendPingsAroundNetwork() { + std::string appStr("ping"); + std::string appFlags("-c 1 -w 0.002"); + std::vector threads; + std::vector networks = getNetworksClassC(); + + for (auto& netw_i : networks) { + for (auto& hostIp : netw_i.hostIPs) { + std::string commandStr = appStr + " " + appFlags + " " + hostIp + " &>/dev/null"; + threads.emplace_back([=]{std::system(commandStr.c_str());}); + } + } + for (auto& thread : threads) { + thread.join(); + } +} + +void systemCalltoFile(const std::string& call, const std::string& filename) { + std::string callStr(call); + callStr.append(" > ").append(filename); + std::system(callStr.c_str()); +} + +void delete_file(const std::string& filename) { + std::string command("rm -f"); + std::system(command.append(" ").append(filename).c_str()); +} + +IpFinder::IpFinder() + : arp_table_filename(default_table_file), + numRetriesMax(defaultNumRetriesMax), + numRetries(0) +{ +} + +void IpFinder::addMacAddress(const std::string& mac) { + std::smatch macParsed; + if (std::regex_search(mac, macParsed, MAC_REGEX)) { + macIpList.emplace_back(MacIp(macParsed[0],"")); + } +} + +void IpFinder::findIps() { + numRetries += 1; + findIpsInARPTable(); + if (!allIpsFound() && (numRetries < numRetriesMax)) { + sendPingsAroundNetwork(); + findIps(); + } +} + +void IpFinder::findIpsInARPTable() { + systemCalltoFile("arp -a", arp_table_filename); + std::ifstream fp(arp_table_filename); + if (!fp.is_open()) { + std::cout << "Error: Unable to open arp file table.\n"; + return; + } + std::string line; + for (MacIp& macip_i : macIpList) { + while (std::getline(fp, line)) { + std::smatch mac_found; + std::regex mac_i(macip_i.mac); + if (std::regex_search(line, mac_found, mac_i)) { + std::smatch ip_found; + if (std::regex_search(line, ip_found, IP_REGEX)) { + macip_i.ip = ip_found[0]; + } + } + } + } + fp.close(); + delete_file(arp_table_filename); +} + +bool IpFinder::allIpsFound() const { + for (const MacIp& macip_i: macIpList) { + if (macip_i.ip.empty()) { + return false; + } + } + return true; +} + +} // namepsace IPFINDER + diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.h b/src/applications/mne_scan/plugins/fieldline/ipfinder.h new file mode 100644 index 00000000000..d8725714d81 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.h @@ -0,0 +1,84 @@ +//============================================================================================================= +/** + * @file ipfinder.h + * @author Juan GarciaPrieto + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Contains the declaration of the Fieldline plugin class. + * + */ + +#ifndef IPFINDER_H +#define IPFINDER_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include +#include + +namespace IPFINDER { + +struct MacIp { + MacIp(const std::string& mac_, + const std::string& ip_) + : mac(mac_), ip(ip_) + {}; + std::string mac; + std::string ip; +}; + +void printMacIpList(const std::vector& macIpList); + +void sendPingsAroundNetwork(); + +void systemCalltoFile(const std::string& call, + const std::string& filename); + +void delete_file(const std::string& filename); + +class IpFinder { +public: + IpFinder(); + void findIps(); + void addMacAddress(const std::string& mac); + bool allIpsFound() const; + + std::vector macIpList; +private: + const char* arp_table_filename; + void findIpsInARPTable(); + int numRetriesMax; + int numRetries; +}; + +} // namespace IpFinder + + + +#endif // IPFINDER_H diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp new file mode 100644 index 00000000000..1053e01ddd4 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace IPFINDER { + +struct Network { + std::string baseAddress; + int numOfHosts; + std::vector hostIPs; +}; + +void printNetworks(const std::vector& networks) { + std::cout << "Networks:" << std::endl; + for (const auto& network : networks) { + std::cout << "Base Address: " << network.baseAddress << "\n"; + std::cout << "Number of Hosts: " << network.numOfHosts << "\n"; + std::cout << "Host IPs: "; + for (int i = 0; i < 10; i++) { + std::cout << " " << i << " " << network.hostIPs[i] << "\n"; + if (i == 10) break; + } + } +} + +std::vector getNetworksClassC() { + std::vector networks; + struct ifaddrs* ifAddrStruct = nullptr; + struct ifaddrs* ifa = nullptr; + void* tmpAddrPtr = nullptr; + + getifaddrs(&ifAddrStruct); + for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) continue; + if (ifa->ifa_addr->sa_family == AF_INET) { + tmpAddrPtr = &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr; + char addressBuffer[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); + std::string ip_address(addressBuffer); + + tmpAddrPtr = &((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr; + inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); + std::string subnet_mask(addressBuffer); + + // Calculate the network base address + struct in_addr network_addr; + inet_aton(ip_address.c_str(), &network_addr); + struct in_addr mask_addr; + inet_aton(subnet_mask.c_str(), &mask_addr); + network_addr.s_addr &= mask_addr.s_addr; + std::string network_address(inet_ntoa(network_addr)); + + // Calculate the number of possible hosts in the network + // int num_of_bits = 32 - __builtin_popcount(mask_addr.s_addr); + std::bitset<32> mask(mask_addr.s_addr); + int num_of_bits = 32 - mask.count(); + int num_of_hosts = (1 << num_of_bits) - 2; // Calculate the IP addresses of all possible hosts in the network + + if (num_of_hosts > 255) + continue; + + std::vector host_ips; + for (int i = 1; i < num_of_hosts; ++i) { + struct in_addr host_addr; + host_addr.s_addr = network_addr.s_addr + htonl(i); + std::string host_ip(inet_ntoa(host_addr)); + host_ips.push_back(host_ip); + } + + Network network = { network_address, num_of_hosts, host_ips }; + networks.push_back(network); + } + } + if (ifAddrStruct != nullptr) freeifaddrs(ifAddrStruct); + return networks; +} + +} // namespace IPFINDER diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.h b/src/applications/mne_scan/plugins/fieldline/ipfinder_network.h new file mode 100644 index 00000000000..44145bd430a --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder_network.h @@ -0,0 +1,21 @@ +#include +#include + +#ifndef IPFINDER_GETNETWORKS_H +#define IPFINDER_GETNETWORKS_H + +namespace IPFINDER { + +struct Network { + std::string baseAddress; + int numOfHosts; + std::vector hostIPs; +}; + +void printNetworks(const std::vector& networks); + +std::vector getNetworksClassC(); + +} // namespace IPFINDER + +#endif // IPFINDER_GETNETWORKS_H From c865e402ed201815e3902baba6b9e1094c63bc5c Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 21 Apr 2023 13:29:29 -0400 Subject: [PATCH 108/147] update cmake for python controller --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 6338bd7404d..8c54dbdb6f7 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -77,7 +77,6 @@ else() endif() endif() - execute_process( COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --includes OUTPUT_VARIABLE Python_INCLUDE_DIRS @@ -121,7 +120,7 @@ message( "python lib flags norm: " ${Python_LDFLAGS_NORM}) set(SOURCES fieldline_global.cpp fieldline.cpp -# fieldline_acqsystem.cpp + fieldline_acqsystem.cpp fieldline_view.cpp # fieldline_view_chassis.cpp ipfinder.cpp @@ -132,7 +131,7 @@ set(HEADERS fieldline_global.h fieldline_definitions.h fieldline.h -# fieldline_acqsystem.h + fieldline_acqsystem.h fieldline_view.h # fieldline_view_chassis.h ipfinder.h @@ -158,11 +157,14 @@ execute_process(COMMAND "echo \"\"" endif() set(SOURCE_PATHS ${SOURCES}) + list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}" ) +add_link_options(${Python_LDFLAGS}) + add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) set(FFTW_LIBS "") @@ -181,7 +183,8 @@ elseif(UNIX AND NOT APPLE) endif() endif() -target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) +# target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) +target_include_directories(${PROJECT_NAME} PUBLIC ../) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) @@ -198,12 +201,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE scShared scMeas ${FFTW_LIBS} - #python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} + python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") -target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) -add_link_options(${Python_LDFLAGS_NORM}) +separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") + +target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS}) + +message( "python cflags2: " ${Python_CFLAGS}) +message( "python cflags norm2: " ${Python_CFLAGS_NORM}) +message( "python lib flags2: " ${Python_LDFLAGS}) +message( "python lib flags norm2: " ${Python_LDFLAGS_NORM}) target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" From 675205c0908be7d40859790d4796faac6a780dbe Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 21 Apr 2023 14:21:15 -0400 Subject: [PATCH 109/147] working so happy --- resources/mne_scan/plugins/fieldline/main.py | 4 +-- .../mne_scan/plugins/fieldline/CMakeLists.txt | 24 ++++++-------- .../mne_scan/plugins/fieldline/fieldline.cpp | 30 +++++++++-------- .../mne_scan/plugins/fieldline/fieldline.h | 8 +++-- .../plugins/fieldline/fieldline_acqsystem.cpp | 32 +++++++++++++------ .../plugins/fieldline/fieldline_acqsystem.h | 5 +-- 6 files changed, 58 insertions(+), 45 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index dafd7fd9efc..0df61cb211d 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,6 +1,6 @@ """This is my super module""" import sys -from fieldline_api_mock.fieldline_service import FieldlineService +# from fieldline_api_mock.fieldline_service import FieldlineService for path in sys.path: print(path) @@ -9,5 +9,5 @@ print("hello pepe vamos vamos!!!") -fl = FieldlineService(["8.8.8.8", "9.9.9.9"]) +# fl = FieldlineService(["8.8.8.8", "9.9.9.9"]) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 8c54dbdb6f7..aa58224fb97 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -103,6 +103,7 @@ execute_process( ) separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") +separate_arguments(Python_INCLUDE_DIRS_NORM UNIX_COMMAND "${Python_INCLUDE_DIRS}") message( "python prefix dir: " ${Python_PREFIX}) message( "python bin dir: " ${Python_BIN_DIR}) @@ -111,6 +112,7 @@ message( "python executable: " ${Python_EXECUTABLE}) message( "python version major: " ${Python_VERSION_MAJOR}) message( "python version minor: " ${Python_VERSION_MINOR}) message( "python include dirs: " ${Python_INCLUDE_DIRS}) +message("python include dirs norm: " ${Python_INCLUDE_DIRS_NORM}) message( "python cflags: " ${Python_CFLAGS}) message( "python cflags norm: " ${Python_CFLAGS_NORM}) message( "python libraries: " ${Python_LIBS}) @@ -163,14 +165,14 @@ set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}" ) -add_link_options(${Python_LDFLAGS}) +# add_link_options(${Python_LDFLAGS_NORM}) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) set(FFTW_LIBS "") if(USE_FFTW) -if (WIN32) +if(WIN32) set(FFTW_LIBS ${FFTW_DIR_LIBS}/libfftw3-3.dll ${FFTW_DIR_LIBS}/libfftw3f-3.dll @@ -183,11 +185,15 @@ elseif(UNIX AND NOT APPLE) endif() endif() -# target_include_directories(${PROJECT_NAME} PUBLIC ../ ${Python_INCLUDE_DIRS}) +separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") +separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") + target_include_directories(${PROJECT_NAME} PUBLIC ../) +target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS_NORM}) +# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) - +# target_link_options(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS}) target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets @@ -204,16 +210,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) -separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") -separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") - -target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS}) - -message( "python cflags2: " ${Python_CFLAGS}) -message( "python cflags norm2: " ${Python_CFLAGS_NORM}) -message( "python lib flags2: " ${Python_LDFLAGS}) -message( "python lib flags norm2: " ${Python_LDFLAGS_NORM}) - target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 45ecad61865..5767941d0e8 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -43,7 +43,7 @@ //============================================================================================================= #include "fieldline/fieldline.h" -//#include "fieldline/fieldline_acqsystem.h" +#include "fieldline/fieldline_acqsystem.h" #include "fieldline/fieldline_view.h" #include "fieldline/ipfinder.h" @@ -53,6 +53,7 @@ //============================================================================================================= // QT INCLUDES //============================================================================================================= +#include //============================================================================================================= // EIGEN INCLUDES @@ -128,7 +129,7 @@ namespace FIELDLINEPLUGIN { Fieldline::Fieldline() : - //acqSystem(nullptr), + acqSystem(nullptr), guiWidget(nullptr) { } @@ -160,7 +161,7 @@ void Fieldline::init() "FieldlinePlguin output"); m_outputConnectors.append(m_pRTMSA); -// acqSystem = new FieldlineAcqSystem(this); + acqSystem = new FieldlineAcqSystem(this); guiWidget = new FieldlineView(this); } @@ -168,7 +169,7 @@ void Fieldline::init() void Fieldline::unload() { qDebug() << "unload Fieldline"; - // delete acqSystem; + delete acqSystem; // delete guiWidget; // deleted by Qt } @@ -208,25 +209,26 @@ QString Fieldline::getName() const { QWidget *Fieldline::setupWidget() { return guiWidget; + // return new QLabel("hola!"); } //============================================================================================================= -std::string Fieldline::findIp(const std::string& neti, const std::string& mac) { - - IPFINDER::IpFinder ipFinder; - ipFinder.addMacAddress(mac); - ipFinder.findIps(); - // ipFinder.macIpList. - return ipFinder.macIpList[0].ip; - +void Fieldline::findIpAsync(const std::string& mac, + std::function callback) { + std::thread ipFinder([&mac, &callback]{ + IPFINDER::IpFinder ipFinder; + ipFinder.addMacAddress(mac); + ipFinder.findIps(); + callback(ipFinder.macIpList[0].ip); + }); } //============================================================================================================= void Fieldline::run() { qDebug() << "run Fieldline"; - +} // while (true) { // if (QThread::isInterruptionRequested()) // break; @@ -278,7 +280,7 @@ void Fieldline::run() { // // } // // } // qDebug() << "run Fieldline finished"; -} +// } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index feead38edbb..2569b34969b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -68,7 +68,7 @@ class FiffInfo; namespace FIELDLINEPLUGIN { -// class FieldlineAcqSystem; +class FieldlineAcqSystem; class FieldlineView; //============================================================================================================= @@ -110,9 +110,11 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor protected: virtual void run(); - std::string findIp(const std::string& neti, const std::string& mac); -// FieldlineAcqSystem* acqSystem; + void findIpAsync(const std::string& mac, + std::function callback); + + FieldlineAcqSystem* acqSystem; FieldlineView* guiWidget; QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index d50288ab2e6..6bf59638d9f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -46,7 +46,6 @@ #include -#include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" //extern "C" { @@ -107,10 +106,12 @@ // return PyModule_Create(&my_module_def); //} +// using FIELDLINEPLUGIN; +// using FIELDLINEPLUGIN::FieldlineAcqSystem; namespace FIELDLINEPLUGIN { +// using FIELDLINEPLUGIN::Fieldline; -const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + \ - "/../resources/mne_scan/plugins/fieldline/"); +const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) @@ -118,6 +119,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) { preConfigurePython(); runPythonFile(entryFile.c_str(), "main.py"); + // std::cout << "addr: " << m_pControllerParent << "\n"; } FieldlineAcqSystem::~FieldlineAcqSystem() @@ -150,14 +152,24 @@ void FieldlineAcqSystem::preConfigurePython() const void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { + std::cout << "we're up here!\n"; + std::cout.flush(); FILE *py_file = fopen(file, "r"); - PyObject* global_dict = PyDict_New(); - PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); + if (py_file) + { + std::cout << "we're here!\n"; + std::cout.flush(); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); + std::cout << "we're down here!\n"; + std::cout.flush(); + Py_XDECREF(global_dict); + Py_XDECREF(local_dict); + Py_XDECREF(result); + fclose(py_file); + } } } // namespace FIELDLINEPLUGIN + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 69b877c2cb5..8c91ec5331f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -35,9 +35,11 @@ #ifndef FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H #define FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H +#include "fieldline/fieldline.h" + namespace FIELDLINEPLUGIN { -class Fieldline; +// class Fieldline; class FieldlineAcqSystem { public: @@ -52,7 +54,6 @@ class FieldlineAcqSystem { Fieldline* m_pControllerParent; }; - } // namespace FIELDLINEPLUGIN #endif // FIELDLINEPLUGIN_FIELDLINEACQSYSTEMCONTROLLER_H From e67dc54e4d82df8483d3d7adad86b6a594c02e2d Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 21 Apr 2023 16:11:43 -0400 Subject: [PATCH 110/147] fieldline view working, python api --- .../mne_scan/plugins/fieldline/CMakeLists.txt | 65 +++++++++---------- .../mne_scan/plugins/fieldline/ipfinder.cpp | 2 +- .../mne_scan/plugins/fieldline/ipfinder.h | 7 +- ..._network.cpp => ipfinder_network_unix.cpp} | 13 ++-- ...nder_network.h => ipfinder_network_unix.h} | 3 +- 5 files changed, 43 insertions(+), 47 deletions(-) rename src/applications/mne_scan/plugins/fieldline/{ipfinder_network.cpp => ipfinder_network_unix.cpp} (88%) rename src/applications/mne_scan/plugins/fieldline/{ipfinder_network.h => ipfinder_network_unix.h} (89%) diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index aa58224fb97..2188a18da79 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -105,29 +105,19 @@ execute_process( separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") separate_arguments(Python_INCLUDE_DIRS_NORM UNIX_COMMAND "${Python_INCLUDE_DIRS}") -message( "python prefix dir: " ${Python_PREFIX}) -message( "python bin dir: " ${Python_BIN_DIR}) -message( "python lib dir: " ${Python_LIB_DIR}) -message( "python executable: " ${Python_EXECUTABLE}) -message( "python version major: " ${Python_VERSION_MAJOR}) -message( "python version minor: " ${Python_VERSION_MINOR}) -message( "python include dirs: " ${Python_INCLUDE_DIRS}) -message("python include dirs norm: " ${Python_INCLUDE_DIRS_NORM}) -message( "python cflags: " ${Python_CFLAGS}) -message( "python cflags norm: " ${Python_CFLAGS_NORM}) -message( "python libraries: " ${Python_LIBS}) -message( "python lib flags: " ${Python_LDFLAGS}) -message( "python lib flags norm: " ${Python_LDFLAGS_NORM}) - -set(SOURCES - fieldline_global.cpp - fieldline.cpp - fieldline_acqsystem.cpp - fieldline_view.cpp - # fieldline_view_chassis.cpp - ipfinder.cpp - ipfinder_network.cpp -) +message(" python prefix dir: " ${Python_PREFIX}) +message(" python bin dir: " ${Python_BIN_DIR}) +message(" python lib dir: " ${Python_LIB_DIR}) +message(" python executable: " ${Python_EXECUTABLE}) +message(" python version major: " ${Python_VERSION_MAJOR}) +message(" python version minor: " ${Python_VERSION_MINOR}) +message(" python include dirs: " ${Python_INCLUDE_DIRS}) +message(" python include dirs norm: " ${Python_INCLUDE_DIRS_NORM}) +message(" python cflags: " ${Python_CFLAGS}) +message(" python cflags norm: " ${Python_CFLAGS_NORM}) +message(" python libraries: " ${Python_LIBS}) +message(" python lib flags: " ${Python_LDFLAGS}) +message(" python lib flags norm: " ${Python_LDFLAGS_NORM}) set(HEADERS fieldline_global.h @@ -137,7 +127,17 @@ set(HEADERS fieldline_view.h # fieldline_view_chassis.h ipfinder.h - ipfinder_network.h + ipfinder_network_unix.h +) + +set(SOURCES + fieldline_global.cpp + fieldline.cpp + fieldline_acqsystem.cpp + fieldline_view.cpp + # fieldline_view_chassis.cpp + ipfinder.cpp + ipfinder_network_unix.cpp ) set(UI_FILES @@ -148,10 +148,10 @@ set(UI_FILES set(FILE_TO_UPDATE fieldline_global.cpp) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) - # message("File fieldline.json exists.") +# message("File fieldline.json exists.") else() - # message("File fieldline.json does not exist.") - # message("Creating a new fieldline.json file.") +# message("File fieldline.json does not exist.") +# message("Creating a new fieldline.json file.") execute_process(COMMAND "echo \"\"" WORKING_DIRECTORY ${CMAKE_C OUTPUT_FILE fieldline.json @@ -189,11 +189,12 @@ separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") target_include_directories(${PROJECT_NAME} PUBLIC ../) -target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS_NORM}) -# target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM}) +target_compile_options(${PROJECT_NAME} PRIVATE + ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS_NORM} +) target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) -# target_link_options(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS}) + target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets @@ -216,8 +217,6 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE ) if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${PROJECT_NAME} PRIVATE - STATICBUILD QT_STATICPLUGIN -) +target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) endif() diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp index 852ec9b4c76..8c2ee11221a 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp @@ -53,7 +53,7 @@ #include #include "ipfinder.h" -#include "ipfinder_network.h" +#include "ipfinder_network_unix.h" namespace IPFINDER { diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.h b/src/applications/mne_scan/plugins/fieldline/ipfinder.h index d8725714d81..7015a110bcc 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.h +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.h @@ -45,7 +45,7 @@ namespace IPFINDER { struct MacIp { - MacIp(const std::string& mac_, + MacIp(const std::string& mac_, const std::string& ip_) : mac(mac_), ip(ip_) {}; @@ -63,14 +63,14 @@ void systemCalltoFile(const std::string& call, void delete_file(const std::string& filename); class IpFinder { -public: + public: IpFinder(); void findIps(); void addMacAddress(const std::string& mac); bool allIpsFound() const; std::vector macIpList; -private: + private: const char* arp_table_filename; void findIpsInARPTable(); int numRetriesMax; @@ -82,3 +82,4 @@ class IpFinder { #endif // IPFINDER_H + diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.cpp similarity index 88% rename from src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp rename to src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.cpp index 1053e01ddd4..b2988f35304 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.cpp +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.cpp @@ -11,13 +11,9 @@ #include #include -namespace IPFINDER { +#include "fieldline/ipfinder_network_unix.h" -struct Network { - std::string baseAddress; - int numOfHosts; - std::vector hostIPs; -}; +namespace IPFINDER { void printNetworks(const std::vector& networks) { std::cout << "Networks:" << std::endl; @@ -60,12 +56,11 @@ std::vector getNetworksClassC() { std::string network_address(inet_ntoa(network_addr)); // Calculate the number of possible hosts in the network - // int num_of_bits = 32 - __builtin_popcount(mask_addr.s_addr); std::bitset<32> mask(mask_addr.s_addr); int num_of_bits = 32 - mask.count(); - int num_of_hosts = (1 << num_of_bits) - 2; // Calculate the IP addresses of all possible hosts in the network + int num_of_hosts = (1 << num_of_bits) - 2; - if (num_of_hosts > 255) + if (num_of_hosts > 255) continue; std::vector host_ips; diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.h b/src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.h similarity index 89% rename from src/applications/mne_scan/plugins/fieldline/ipfinder_network.h rename to src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.h index 44145bd430a..c57775dcc3e 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder_network.h +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder_network_unix.h @@ -14,8 +14,9 @@ struct Network { void printNetworks(const std::vector& networks); -std::vector getNetworksClassC(); +std::vector getNetworksClassC(); } // namespace IPFINDER #endif // IPFINDER_GETNETWORKS_H + From 5a6235be1e4df31e2491af2ee5d4f60b90bb22e5 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Mon, 24 Apr 2023 23:37:20 -0400 Subject: [PATCH 111/147] sensor and chassis working --- .ipfinder_hu56thzl | 11 + .../mne_scan/plugins/fieldline/CMakeLists.txt | 220 ++++++++++-------- .../mne_scan/plugins/fieldline/fieldline.cpp | 21 +- .../mne_scan/plugins/fieldline/fieldline.h | 6 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 6 +- .../plugins/fieldline/fieldline_view.cpp | 76 +++--- .../plugins/fieldline/fieldline_view.h | 6 +- .../fieldline/fieldline_view_chassis.cpp | 60 +++-- .../fieldline/fieldline_view_chassis.h | 43 ++-- .../fieldline/fieldline_view_sensor.cpp | 191 +++++++++++++++ .../plugins/fieldline/fieldline_view_sensor.h | 89 +++++++ .../formfiles/_delete_macaddress_ip_box.ui | 47 ---- .../fieldline/formfiles/fieldline_rack.ui | 45 ---- .../fieldline/formfiles/fieldline_view.ui | 50 ++-- ...e_chassis.ui => fieldline_view_chassis.ui} | 16 +- .../formfiles/fieldline_view_sensor.ui | 85 +++++++ .../mne_scan/plugins/fieldline/ipfinder.cpp | 41 +++- .../mne_scan/plugins/fieldline/ipfinder.h | 3 +- 18 files changed, 688 insertions(+), 328 deletions(-) create mode 100644 .ipfinder_hu56thzl create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h delete mode 100644 src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui delete mode 100644 src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui rename src/applications/mne_scan/plugins/fieldline/formfiles/{fieldline_chassis.ui => fieldline_view_chassis.ui} (83%) create mode 100644 src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui diff --git a/.ipfinder_hu56thzl b/.ipfinder_hu56thzl new file mode 100644 index 00000000000..efa40fbff10 --- /dev/null +++ b/.ipfinder_hu56thzl @@ -0,0 +1,11 @@ +? (10.0.0.1) at ac:db:48:84:ee:9e on en0 ifscope [ethernet] +? (10.0.0.10) at 78:4f:43:4:dd:c1 on en0 ifscope [ethernet] +? (10.0.0.61) at 8:97:98:1a:7a:e4 on en0 ifscope [ethernet] +? (10.0.0.69) at 56:eb:af:1d:28:d8 on en0 ifscope [ethernet] +? (10.0.0.117) at 7c:d9:5c:41:59:e6 on en0 ifscope [ethernet] +? (10.0.0.147) at 42:f1:ce:4d:96:5d on en0 ifscope [ethernet] +? (10.0.0.165) at c2:50:67:9:a7:9e on en0 ifscope [ethernet] +? (10.0.0.236) at 10:2c:6b:f0:41:e on en0 ifscope [ethernet] +? (10.0.0.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet] +? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet] +? (239.255.255.250) at 1:0:5e:7f:ff:fa on en0 ifscope permanent [ethernet] diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index 2188a18da79..cc3ff61385b 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -13,6 +13,103 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent ) +set(HEADERS + fieldline_global.h + fieldline_definitions.h + fieldline.h + fieldline_acqsystem.h + fieldline_view.h + fieldline_view_chassis.h + fieldline_view_sensor.h + ipfinder.h + ipfinder_network_unix.h +) + +set(SOURCES + fieldline_global.cpp + fieldline.cpp + fieldline_acqsystem.cpp + fieldline_view.cpp + fieldline_view_chassis.cpp + fieldline_view_sensor.cpp + ipfinder.cpp + ipfinder_network_unix.cpp +) + +set(UI_FILES + formfiles/fieldline_view.ui + formfiles/fieldline_view_chassis.ui + formfiles/fieldline_view_sensor.ui +) + +set(FILE_TO_UPDATE fieldline_global.cpp) + +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) +# message("File fieldline.json exists.") +else() +# message("File fieldline.json does not exist.") +# message("Creating a new fieldline.json file.") +execute_process(COMMAND "echo \"\"" + WORKING_DIRECTORY ${CMAKE_C + OUTPUT_FILE fieldline.json +) +endif() + +set(SOURCE_PATHS ${SOURCES}) + +list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES + OBJECT_DEPENDS "${SOURCE_PATHS}" +) + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) + +set(FFTW_LIBS "") + +if(USE_FFTW) +if(WIN32) + set(FFTW_LIBS + ${FFTW_DIR_LIBS}/libfftw3-3.dll + ${FFTW_DIR_LIBS}/libfftw3f-3.dll + ${FFTW_DIR_LIBS}/libfftwf3l-3.dll + ) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) +elseif(UNIX AND NOT APPLE) + set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) +endif() +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC ../) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + scDisp + scShared + scMeas + ${FFTW_LIBS} +) + +target_compile_definitions(${PROJECT_NAME} PRIVATE + SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" +) + +if(NOT BUILD_SHARED_LIBS) +target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) +endif() + +# ################################################################### +# ######### Python Dependencies ##################################### +# ################################################################### + execute_process( COMMAND which python OUTPUT_VARIABLE Python_EXECUTABLE @@ -89,8 +186,6 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") - execute_process( COMMAND ${Python_BIN_DIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}-config --libs OUTPUT_VARIABLE Python_LIBS @@ -102,9 +197,18 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") +set(Python_VERSION_MAJOR "3") +set(Python_VERSION_MINOR "9") +set(Python_LIB_DIR "/opt/anaconda3/lib") +set(Python_INCLUDE_DIRS "-I/opt/anacnda3/include/python3.9") +set(Python_CFLAGS "-I/opt/anaconda3/include/python3.9 -I/opt/anaconda2/include/python3.9 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64") +set(Python_LDFLAGS "-L/opt/anaconda3/lib/python3.9/config-3.9-darwin -ldl -framework CoreFoundation") + separate_arguments(Python_INCLUDE_DIRS_NORM UNIX_COMMAND "${Python_INCLUDE_DIRS}") +separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") +separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") +message(" ") message(" python prefix dir: " ${Python_PREFIX}) message(" python bin dir: " ${Python_BIN_DIR}) message(" python lib dir: " ${Python_LIB_DIR}) @@ -112,111 +216,25 @@ message(" python executable: " ${Python_EXECUTABLE}) message(" python version major: " ${Python_VERSION_MAJOR}) message(" python version minor: " ${Python_VERSION_MINOR}) message(" python include dirs: " ${Python_INCLUDE_DIRS}) -message(" python include dirs norm: " ${Python_INCLUDE_DIRS_NORM}) +message("*python include dirs norm: " ${Python_INCLUDE_DIRS_NORM}) message(" python cflags: " ${Python_CFLAGS}) -message(" python cflags norm: " ${Python_CFLAGS_NORM}) -message(" python libraries: " ${Python_LIBS}) -message(" python lib flags: " ${Python_LDFLAGS}) -message(" python lib flags norm: " ${Python_LDFLAGS_NORM}) - -set(HEADERS - fieldline_global.h - fieldline_definitions.h - fieldline.h - fieldline_acqsystem.h - fieldline_view.h - # fieldline_view_chassis.h - ipfinder.h - ipfinder_network_unix.h -) - -set(SOURCES - fieldline_global.cpp - fieldline.cpp - fieldline_acqsystem.cpp - fieldline_view.cpp - # fieldline_view_chassis.cpp - ipfinder.cpp - ipfinder_network_unix.cpp -) - -set(UI_FILES - formfiles/fieldline_view.ui - formfiles/fieldline_chassis.ui -) - -set(FILE_TO_UPDATE fieldline_global.cpp) - -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fieldline.json) -# message("File fieldline.json exists.") -else() -# message("File fieldline.json does not exist.") -# message("Creating a new fieldline.json file.") -execute_process(COMMAND "echo \"\"" - WORKING_DIRECTORY ${CMAKE_C - OUTPUT_FILE fieldline.json -) -endif() - -set(SOURCE_PATHS ${SOURCES}) - -list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") -set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES - OBJECT_DEPENDS "${SOURCE_PATHS}" -) - -# add_link_options(${Python_LDFLAGS_NORM}) +message(" *python cflags norm: " ${Python_CFLAGS_NORM}) +message(" python libs: " ${Python_LIBS}) +message(" python ldflags: " ${Python_LDFLAGS}) +message(" *python ldflags norm: " ${Python_LDFLAGS_NORM}) +message(" (*)Message missrepresents content of lists.") +message(" ") -add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UI_FILES}) - -set(FFTW_LIBS "") - -if(USE_FFTW) -if(WIN32) - set(FFTW_LIBS - ${FFTW_DIR_LIBS}/libfftw3-3.dll - ${FFTW_DIR_LIBS}/libfftw3f-3.dll - ${FFTW_DIR_LIBS}/libfftwf3l-3.dll - ) - target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) -elseif(UNIX AND NOT APPLE) - set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) - target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) -endif() -endif() - -separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") -separate_arguments(Python_LDFLAGS_NORM UNIX_COMMAND "${Python_LDFLAGS}") - -target_include_directories(${PROJECT_NAME} PUBLIC ../) target_compile_options(${PROJECT_NAME} PRIVATE ${Python_CFLAGS_NORM} ${Python_INCLUDE_DIRS_NORM} ) - -target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Network - Qt${QT_VERSION_MAJOR}::Concurrent - eigen - mne_disp - mne_utils - mne_fiff - scDisp - scShared - scMeas - ${FFTW_LIBS} python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} ) +target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) +target_link_options(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS_NORM}) -target_compile_definitions(${PROJECT_NAME} PRIVATE - SCAN_FIELDLINE_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" - MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" -) - -if(NOT BUILD_SHARED_LIBS) -target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) -endif() +# ################################################################### +# ################################################################### +# ################################################################### diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 5767941d0e8..f200f453739 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -41,6 +41,7 @@ //============================================================================================================= // INCLUDES //============================================================================================================= +#include #include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" @@ -214,14 +215,26 @@ QWidget *Fieldline::setupWidget() { //============================================================================================================= -void Fieldline::findIpAsync(const std::string& mac, - std::function callback) { - std::thread ipFinder([&mac, &callback]{ +void Fieldline::findIpAsync(const std::string mac, + std::function callback) { + std::cout << "outside here!\n"; + std::cout << "mac: " << mac << "\n"; + std::thread ipFinder([=]{ IPFINDER::IpFinder ipFinder; ipFinder.addMacAddress(mac); + std::cout << "here inside!\n"; + std::cout << "mac: " << mac << "\n"; + std::cout.flush(); ipFinder.findIps(); - callback(ipFinder.macIpList[0].ip); + if (ipFinder.macIpList.size() == 0) { + + std::cout.flush(); + callback(ipFinder.macIpList[0].ip); + } else { + callback(std::string("Mac address not valid.")); + } }); + ipFinder.detach(); } //============================================================================================================= diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 2569b34969b..79e07a2abef 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -50,6 +50,8 @@ #include #include +#include + //============================================================================================================= // FORWARD DECLARATION //============================================================================================================= @@ -108,11 +110,11 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor virtual QString getBuildInfo(); + void findIpAsync(const std::string mac, + std::function callback); protected: virtual void run(); - void findIpAsync(const std::string& mac, - std::function callback); FieldlineAcqSystem* acqSystem; FieldlineView* guiWidget; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 6bf59638d9f..02103c1792f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -164,9 +164,9 @@ void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) co PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); std::cout << "we're down here!\n"; std::cout.flush(); - Py_XDECREF(global_dict); - Py_XDECREF(local_dict); - Py_XDECREF(result); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); fclose(py_file); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index b7e58ab3000..6c3f965f3d3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -37,8 +37,9 @@ // INCLUDES //============================================================================================================= -#include "fieldline/fieldline_view.h" #include "fieldline/fieldline.h" +#include "fieldline/fieldline_view.h" +#include "fieldline/fieldline_view_chassis.h" #include "formfiles/ui_fieldline_view.h" //============================================================================================================= @@ -53,6 +54,9 @@ #include #include +#include +#include + //============================================================================================================= // EIGEN INCLUDES //============================================================================================================= @@ -72,10 +76,9 @@ namespace FIELDLINEPLUGIN { -FieldlineView::FieldlineView(Fieldline* parent) +FieldlineView::FieldlineView(Fieldline *parent) : m_pFieldlinePlugin(parent), m_pUi(new Ui::uiFieldlineView) -// m_pAcqSystem(nullptr) { m_pUi->setupUi(this); initTopMenu(); @@ -95,51 +98,46 @@ void FieldlineView::initTopMenu() m_pUi->numChassisSpinBox->setValue(0); m_pMacIpTable = new QTableWidget(this); m_pMacIpTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - m_pMacIpTable->verticalHeader()->setSectionHidden(0,true); + m_pMacIpTable->verticalHeader()->setSectionHidden(0, true); m_pMacIpTable->setColumnCount(2); - m_pMacIpTable->setHorizontalHeaderLabels(QStringList({"Mac","IP"})); + m_pMacIpTable->setHorizontalHeaderLabels(QStringList({"Mac", "IP"})); QVBoxLayout* macIpTableLayout = qobject_cast(m_pUi->ipMacFrame->layout()); macIpTableLayout->insertWidget(0, m_pMacIpTable); QObject::connect(m_pMacIpTable, QOverload::of(&QTableWidget::cellDoubleClicked), this, &FieldlineView::macIpTableDoubleClicked); - QObject::connect(m_pMacIpTable, &QTableWidget::itemChanged, - this, &FieldlineView::macIpTableValueChanged); - QObject::connect(m_pUi->numChassisSpinBox,QOverload::of(&QSpinBox::valueChanged), + QObject::connect(m_pUi->numChassisSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &FieldlineView::setNumRowsIpMacFrame); QObject::connect(m_pUi->disconnectBtn, &QPushButton::clicked, this, &FieldlineView::disconnect); } void FieldlineView::macIpTableDoubleClicked(int row, int col) { - std::cout << "row: " << row << " col: " << col << "\n"; - std::cout.flush(); if ( col == 0 ) { -// std::string macAddr = findIP(m_pMacIpTable->item(row, col)->text.toStdString()); - std::string macAddr("0.0.0.0"); - m_pMacIpTable->item(row, col + 1)->setText(QString::fromStdString(macAddr)); - } - if ( col == 1 ) { - // perhaps send ping? + std::cout << "cell (" << row << "," << col << ") " + << " doubleclicked : " << m_pMacIpTable->item(row, col)->text().toStdString() << "\n"; + std::cout.flush(); + auto callback = [this, row, col](const std::string str) { + std::cout << "inside callback! :" << str << " \n"; + m_pMacIpTable->item(row, col+1)->setText(str.c_str()); + m_pMacIpTable->repaint(); + }; + m_pFieldlinePlugin->findIpAsync(m_pMacIpTable->item(row, col)->text().toStdString(), callback); } } -void FieldlineView::macIpTableValueChanged(QTableWidgetItem* item) +void FieldlineView::setNumRowsIpMacFrame(int numRows) { - std::cout << "cell (" << item->row() << "," << item->column() << " changed to: " << item->text().toStdString() << "\n"; - std::cout.flush(); -} - -void FieldlineView::setNumRowsIpMacFrame(int i) -{ - m_pMacIpTable->setRowCount(i); - m_pMacIpTable->setSortingEnabled(false); - m_pMacIpTable->setItem(i-1, 0, new QTableWidgetItem("AF-70-04-21-2D-28")); - m_pMacIpTable->setItem(i-1, 1, new QTableWidgetItem("0.0.0.0")); - m_pMacIpTable->item(i-1, 0)->setToolTip((QString("Doubleclick to find the IP."))); - m_pMacIpTable->setSortingEnabled(true); + m_pMacIpTable->setRowCount(numRows); + if (numRows > 0) { + m_pMacIpTable->setSortingEnabled(false); + m_pMacIpTable->setItem(numRows-1, 0, new QTableWidgetItem("AF:70:04:21:2D:28")); + m_pMacIpTable->setItem(numRows-1, 1, new QTableWidgetItem("0.0.0.0")); + m_pMacIpTable->item(numRows-1, 0)->setToolTip((QString("Doubleclick to find the IP."))); + m_pMacIpTable->setSortingEnabled(true); + } // QVBoxLayout* vertIpMacLayout = qobject_cast(m_pUi->ipMacFrame->layout()); // if ( i < m_ipMacList.size()) // { @@ -152,7 +150,7 @@ void FieldlineView::setNumRowsIpMacFrame(int i) // QHBoxLayout* ipMacLayout = new QHBoxLayout(m_pUi->ipMacFrame); // QLineEdit* ip = new QLineEdit("0.0.0.0"); // ip->setEnabled(false); -// QLineEdit* macAddr = new QLineEdit("AF-70-04-21-2D-28"); +// QLineEdit* macAddr = new QLineEdit("AF:70:04:21:2D:28"); // ipMacLayout->addWidget(macAddr); // ipMacLayout->addWidget(ip); // vertIpMacLayout->insertLayout(m_ipMacList.size() + 1, ipMacLayout); @@ -203,21 +201,27 @@ void FieldlineView::initAcqSystem(int numChassis) { // QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); initAcqSystemTopButtons(); - // for( int i = 0; i < numChassis; i++ ) { - // m_pAcqSystem.emplace_back(); - // } + + QVBoxLayout* acqSystemRackLayout = qobject_cast(m_pUi->chassisRackFrame->layout()); + + for( int i = 0; i < numChassis; i++ ) { + FieldlineViewChassis* pChassis = new FieldlineViewChassis(this, i); + acqSystemRackLayout->insertWidget(i, pChassis); + //lkajdsflkasjdf + m_pAcqSystem.push_back(pChassis); + } } -void FieldlineView::initAcqSystem() -{ +// void FieldlineView::initAcqSystem() +// { // QVBoxLayout* rackFrameLayout = qobject_cast(m_pUi->fieldlineRackFrame->layout()); // for (int i = 0; i < numChassis; i++) // { // FieldlineChassis* chassis = new FieldlineViewChassis(chans[i]); // rackFrameLayout->addWidget(chassis); // } -} +// } void FieldlineView::startAllSensors() { std::cout << "startAllSensors" << "\n"; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 9370a9d595c..8b2676a5b77 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -70,7 +70,7 @@ class QTableWidgetItem; namespace FIELDLINEPLUGIN { class Fieldline; -// class FieldlineViewChassis; +class FieldlineViewChassis; //============================================================================================================= @@ -87,9 +87,7 @@ class FieldlineView : public QWidget void initTopMenu(); void disconnect(); void macIpTableDoubleClicked(int, int); - void macIpTableValueChanged(QTableWidgetItem* item); - void initAcqSystem(); void initAcqSystemCallbacks(); void initAcqSystemTopButtons(); void setNumRowsIpMacFrame(int i); @@ -104,7 +102,7 @@ class FieldlineView : public QWidget Fieldline* m_pFieldlinePlugin; Ui::uiFieldlineView* m_pUi; QTableWidget* m_pMacIpTable; - // std::vector m_pAcqSystem; + std::vector m_pAcqSystem; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp index 79ab1f22963..5327d7f5b7a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp @@ -37,11 +37,12 @@ // INCLUDES //============================================================================================================= -// #include "fieldline/fieldline_view.h" +#include // #include "fieldline/fieldline.h" -//#include "formfiles/ui_fieldline_view.h" -//#include "formfiles/ui_fieldline_rack.h" -#include "formfiles/ui_fieldline_chassis.h" +#include "fieldline/fieldline_view.h" +#include "fieldline/fieldline_view_chassis.h" +#include "fieldline/fieldline_view_sensor.h" +#include "formfiles/ui_fieldline_view_chassis.h" //============================================================================================================= // QT INCLUDES @@ -75,32 +76,43 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= -FieldlineViewChassis::FieldlineViewChassis(QWidget *parent ) -: QWidget(parent) -{ - QVBoxLayout* layout = new QVBoxLayout; - QFrame* frame = new QFrame; - - layout->addWidget(frame); - QWidget::setLayout(layout); +FieldlineViewChassis::FieldlineViewChassis(FieldlineView *parent, int num ) +: QWidget(parent), + m_pFieldlineView(parent), + m_pUi(new Ui::uiFieldlineViewChassis), + chassisNum(num), + numSensors(16) + { + m_pUi->setupUi(this); + + std::string chassisName("Fieldline Chassis "); + chassisName += std::to_string(chassisNum); + m_pUi->chassisName->setText(QString::fromStdString(chassisName)); + QHBoxLayout* sensorLayout = qobject_cast(m_pUi->sensorFrame->layout()); + + for (int i = 0; i < numSensors; i++) { + FieldlineViewSensor* pSensor = new FieldlineViewSensor(this, i); + sensorLayout->insertWidget(i, pSensor); + m_pSensors.push_back(pSensor); + } } FieldlineViewChassis::~FieldlineViewChassis() { - delete ui; + delete m_pUi; } -FieldlineViewChassis::initChannels(size_t numChans) -{ - // for(int i = 0; i < num_chans; ++i){ - // chans.push_back(new LEDIndicator()); - // auto& last_item = chans.back(); - // chans.back()->setLabel(QString::number(i + 1)); - // ui->chan_frame->layout()->addWidget(chans.back()); - // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); - // connect(this, &FieldlineViewChassis::clicked, this, &FieldlineViewChassis::rightClickMenu, Qt::UniqueConnection); - // } -} +// FieldlineViewChassis::initChannels(size_t numChans) +// { +// // for(int i = 0; i < num_chans; ++i){ +// // chans.push_back(new LEDIndicator()); +// // auto& last_item = chans.back(); +// // chans.back()->setLabel(QString::number(i + 1)); +// // ui->chan_frame->layout()->addWidget(chans.back()); +// // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); +// // connect(this, &FieldlineViewChassis::clicked, this, &FieldlineViewChassis::rightClickMenu, Qt::UniqueConnection); +// // } +// } //============================================================================================================= // diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index 4e5ffb2c96f..7c4c5a16c00 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -33,14 +33,14 @@ * */ -#ifndef FIELDLINEPLUGIN_FIELDLINEVIEW_H +#ifndef FIELDLINEPLUGIN_FIELDLINEVIEWCHASSIS_H +#define FIELDLINEPLUGIN_FIELDLINEVIEWCHASSIS_H //============================================================================================================= // INCLUDES //============================================================================================================= -// #include "disp/viewers/led_indicator.h" -#include "fieldline/fieldline_definitions.h" +#include //============================================================================================================= // QT INCLUDES @@ -56,16 +56,18 @@ // FORWARD DECLARATIONS //============================================================================================================= -//namespace Ui { -// class uiFieldlineViewChassis; -//} +namespace Ui { +class uiFieldlineViewChassis; +} + //============================================================================================================= // DEFINE NAMESPACE DISPLIB //============================================================================================================= namespace FIELDLINEPLUGIN { -class FieldlineViewChannel; +class FieldlineView; +class FieldlineViewSensor; //============================================================================================================= @@ -74,30 +76,17 @@ class FieldlineViewChassis : public QWidget Q_OBJECT public: - explicit FieldlineViewChassis(QWidget *parent = nullptr); + explicit FieldlineViewChassis(FieldlineView *parent, int num); ~FieldlineViewChassis(); - void setChannelState(size_t chan_i, FieldLineSensorStatusType status); - FieldLineSensorStatusType getChannelState(size_t chan_i); -// void setColor(size_t chan_num, const QColor& color); -// void setColor(size_t chan_num, const QColor& color, bool blinking); -// void setColor(const QColor& color); -// void setColor(const QColor& color, bool blinking); -// -// void setBlinkState(size_t chan_num, bool blinking); -// void setBlinkState(bool blinking); -// -// signals: -// void clicked(int chan, const QPoint& pos); -// -// private slots: -// void rightClickMenu(int chan, const QPoint& pos); private: - -// Ui::uiFieldlineViewChassis* m_pUi; - std::vector m_pChannels; + FieldlineView *m_pFieldlineView; + Ui::uiFieldlineViewChassis* m_pUi; + std::vector m_pSensors; + int chassisNum; + int numSensors; }; } // namespace FIELDLINEPLUGIN -#endif // FIELDLINEPLUGIN_FIELDLINEVIEW_H +#endif // FIELDLINEPLUGIN_FIELDLINEVIEWCHASSIS_H diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp new file mode 100644 index 00000000000..c0779ae37b0 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp @@ -0,0 +1,191 @@ +//============================================================================================================= +/** + * @file fieldline_view_chassis.cpp + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class definition. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + + +#include + +// #include "fieldline/fieldline.h" +// #include "fieldline/fieldline_view.h" +#include "fieldline/fieldline_view_sensor.h" +// #include "fieldline/fieldline_view_chassis.h" +#include "formfiles/ui_fieldline_view_sensor.h" + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= +// +#include +// #include +// #include +// #include +// #include +// #include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +//============================================================================================================= +// DEFINE STATIC METHODS +//============================================================================================================= + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + + +namespace FIELDLINEPLUGIN { + +//============================================================================================================= + +FieldlineViewSensor::FieldlineViewSensor(FieldlineViewChassis *parent, int index) +: m_pFieldlineViewChassis(parent), + m_pUi(new Ui::uiFieldlineViewSensor), + m_sensorIndex(index) +{ + m_pUi->setupUi(this); + + // QVBoxLayout* layout = new QVBoxLayout; + // QFrame* frame = new QFrame; + // + // layout->addWidget(frame); + // QWidget::setLayout(layout); +} + +FieldlineViewSensor::~FieldlineViewSensor() +{ + delete m_pUi; +} + +// FieldlineViewSensor::initChannels(size_t numChans) +// { +// // for(int i = 0; i < num_chans; ++i){ +// // chans.push_back(new LEDIndicator()); +// // auto& last_item = chans.back(); +// // chans.back()->setLabel(QString::number(i + 1)); +// // ui->chan_frame->layout()->addWidget(chans.back()); +// // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); +// // connect(this, &FieldlineViewSensor::clicked, this, &FieldlineViewSensor::rightClickMenu, Qt::UniqueConnection); +// // } +// } + +//============================================================================================================= +// +// void FieldlineViewSensor::setColor(size_t chan_num, const QColor& color) +// { +// if(chan_num > chans.size() || chan_num < 1){ +// return; +// } +// chans.at(chan_num - 1)->setColor(color); +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::setColor(size_t chan_num, const QColor& color, bool blinking) +// { +// setColor(chan_num, color); +// setBlinkState(chan_num, blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::setColor(const QColor& color) +// { +// for(auto* chan : chans){ +// chan->setColor(color); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::setColor(const QColor& color, bool blinking) +// { +// for(auto* chan : chans){ +// chan->setColor(color); +// chan->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::setBlinkState(size_t chan_num, bool blinking) +// { +// if(chan_num > chans.size() || chan_num < 1){ +// return; +// } +// chans.at(chan_num - 1)->setBlink(blinking); +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::setBlinkState(bool blinking) +// { +// for(auto* chan : chans){ +// chan->setBlink(blinking); +// } +// } +// +// //============================================================================================================= +// +// void FieldlineViewSensor::rightClickMenu(int chan, const QPoint& pos) +// { +// // auto* menu = new QMenu(); +// +// // auto blink_on_chan = menu->addAction("Blink ON - " + QString::number(chan)); +// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); +// +// // auto blink_off_chan = menu->addAction("Blink OFF - " + QString::number(chan)); +// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); +// +// // connect(blink_on_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, true);}); +// // connect(blink_off_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, false);}); +// +// // connect(blink_on_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(true);}); +// // connect(blink_off_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(false);}); +// +// // menu->exec(pos); +// } + +} // namespace FIELDLINEPLUGIN + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h new file mode 100644 index 00000000000..be0fc9d327d --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h @@ -0,0 +1,89 @@ +//============================================================================================================= +/** + * @file fieldline_view_chassis.h + * @author Juan Garcia-Prieto + * Gabriel Motta + * @since 0.1.9 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief FieldlineView class declaration. + * + */ + +#ifndef FIELDLINEPLUGIN_FIELDLINEVIEWSENSOR +#define FIELDLINEPLUGIN_FIELDLINEVIEWSENSOR + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +namespace Ui { +class uiFieldlineViewSensor; +} + + +//============================================================================================================= +// DEFINE NAMESPACE DISPLIB +//============================================================================================================= + +namespace FIELDLINEPLUGIN { + +class FieldlineViewChassis; + +//============================================================================================================= + +class FieldlineViewSensor: public QWidget +{ + Q_OBJECT + + public: + explicit FieldlineViewSensor(FieldlineViewChassis *parent, int index); + ~FieldlineViewSensor(); + + private: + FieldlineViewChassis *m_pFieldlineViewChassis; + Ui::uiFieldlineViewSensor* m_pUi; + int m_sensorIndex; +}; + +} // namespace FIELDLINEPLUGIN + +#endif // FIELDLINEPLUGIN_FIELDLINEVIEWSENSOR_H + diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui deleted file mode 100644 index aeb4f605400..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/_delete_macaddress_ip_box.ui +++ /dev/null @@ -1,47 +0,0 @@ - - - IpMacPair - - - - 0 - 0 - 402 - 50 - - - - - 400 - 50 - - - - Form - - - - - - - 100 - 25 - - - - - - - - - 100 - 25 - - - - - - - - - diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui deleted file mode 100644 index 22cd98411b2..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_rack.ui +++ /dev/null @@ -1,45 +0,0 @@ - - - fl_rack - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - Qt::Vertical - - - - 20 - 262 - - - - - - - - - diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 6dcb4720686..9e35e337a4b 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -131,7 +131,30 @@ QFrame::Plain - + + + + + 140 + 0 + + + + Connect + + + + + + + + 50 + 16777215 + + + + + @@ -150,20 +173,7 @@ - - - - - 140 - 0 - - - - Connect - - - - + Number of Chassis @@ -173,16 +183,6 @@ - - - - - 50 - 16777215 - - - - diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui similarity index 83% rename from src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui rename to src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui index 410a4dc4beb..7e0ebb83d77 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_chassis.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui @@ -21,7 +21,7 @@ - + 0 @@ -36,13 +36,25 @@ - + 0 0 + + + 0 + 40 + + + + + 16777215 + 40 + + FieldLine diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui new file mode 100644 index 00000000000..ee09138a599 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui @@ -0,0 +1,85 @@ + + + uiFieldlineViewSensor + + + + 0 + 0 + 137 + 320 + + + + + 140 + 320 + + + + Form + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 16777215 + 15 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + PushButton 1 + + + + + + + PushButton 2 + + + + + + + PushButton 3 + + + + + + + PushButton 4 + + + + + + + + + + diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp index 8c2ee11221a..5d37c107ca2 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp @@ -57,7 +57,6 @@ namespace IPFINDER { -const std::regex MAC_REGEX("[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}"); const std::regex IP_REGEX("[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}"); const char* default_table_file = "~/.ipfinder_171921"; const int defaultNumRetriesMax = 3; @@ -99,16 +98,43 @@ void delete_file(const std::string& filename) { } IpFinder::IpFinder() - : arp_table_filename(default_table_file), - numRetriesMax(defaultNumRetriesMax), + : numRetriesMax(defaultNumRetriesMax), numRetries(0) { + arp_table_filename = generateRandomArpTableFileName(); +} + +//void IpFinder::addMacAddress(const std::string& mac) { +// std::smatch macParsed; +// if (std::regex_search(mac, macParsed, MAC_REGEX)) { +// macIpList.emplace_back(MacIp(macParsed[0],"")); +// } +//} + +std::string IpFinder::generateRandomArpTableFileName() { + std::string newFileName(".ipfinder_"); + const std::string charset = "abcdefghijklmpqrstuvwxyz0123456789"; + const int strLen(8); + + for(int i =0; i < strLen; i++) { + int index = rand() % charset.length(); + newFileName += charset[index]; + } + return newFileName; } void IpFinder::addMacAddress(const std::string& mac) { + std::regex MAC_REGEX("[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}"); std::smatch macParsed; - if (std::regex_search(mac, macParsed, MAC_REGEX)) { - macIpList.emplace_back(MacIp(macParsed[0],"")); + auto bla = std::regex_search(mac, macParsed, MAC_REGEX); + if (bla) { + if (macParsed.size() > 0) { + macIpList.emplace_back(MacIp(macParsed[0],"0.0.0.0")); + } else { + std::cerr << "Error: no matches found for MAC address " << mac << std::endl; + } + } else { + std::cerr << "Error: failed to match MAC address " << mac << " with regular expression." << std::endl; } } @@ -116,8 +142,8 @@ void IpFinder::findIps() { numRetries += 1; findIpsInARPTable(); if (!allIpsFound() && (numRetries < numRetriesMax)) { - sendPingsAroundNetwork(); - findIps(); + sendPingsAroundNetwork(); + findIps(); } } @@ -126,6 +152,7 @@ void IpFinder::findIpsInARPTable() { std::ifstream fp(arp_table_filename); if (!fp.is_open()) { std::cout << "Error: Unable to open arp file table.\n"; + std::cout.flush(); return; } std::string line; diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.h b/src/applications/mne_scan/plugins/fieldline/ipfinder.h index 7015a110bcc..31a885039a6 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.h +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.h @@ -71,7 +71,8 @@ class IpFinder { std::vector macIpList; private: - const char* arp_table_filename; + std::string generateRandomArpTableFileName(); + std::string arp_table_filename; void findIpsInARPTable(); int numRetriesMax; int numRetries; From 98aa491c5ef9ff477e7c42fb45f7250ff3104c4a Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 25 Apr 2023 10:37:50 -0400 Subject: [PATCH 112/147] update gitignore to avoid linter config files --- .clang-format_old | 250 --------------------------------------------- .clangd | 3 - .gitignore | 23 +++-- .ipfinder_hu56thzl | 11 -- 4 files changed, 13 insertions(+), 274 deletions(-) delete mode 100644 .clang-format_old delete mode 100644 .clangd delete mode 100644 .ipfinder_hu56thzl diff --git a/.clang-format_old b/.clang-format_old deleted file mode 100644 index 1da44674a81..00000000000 --- a/.clang-format_old +++ /dev/null @@ -1,250 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: Google -AccessModifierOffset: -1 -AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignEscapedNewlines: Left -AlignOperands: Align -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortEnumsOnASingleLine: true -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: Yes -AttributeMacros: - - __capability -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always -reakBeforeBraces: Allman -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -olumnLimit: 110 -CommentPragmas: '^ IWYU pragma:' -QualifierAlignment: Leave -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -pp11BracedListStyle: true -DeriveLineEnding: true -DerivePointerAlignment: true -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -PackConstructorInitializers: NextLine -BasedOnStyle: '' -ConstructorInitializerAllOnOneLineOrOnePerLine: false -AllowAllConstructorInitializersOnNextLine: true -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*\.h>' - Priority: 1 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 3 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '([-_](test|unittest))?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseLabels: true -IndentCaseBlocks: false -IndentGotoLabels: true -IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertTrailingCommas: None -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false -LambdaBodyIndentation: Signature -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Never -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 200 -PenaltyIndentedWhitespace: 0 -PointerAlignment: Left -PPIndentWidth: -1 -RawStringFormats: - - Language: Cpp - Delimiters: - - cc - - CC - - cpp - - Cpp - - CPP - - 'c++' - - 'C++' - CanonicalDelimiter: '' - BasedOnStyle: google - - Language: TextProto - Delimiters: - - pb - - PB - - proto - - PROTO - EnclosingFunctions: - - EqualsProto - - EquivToProto - - PARSE_PARTIAL_TEXT_PROTO - - PARSE_TEST_PROTO - - PARSE_TEXT_PROTO - - ParseTextOrDie - - ParseTextProtoOrDie - - ParseTestProto - - ParsePartialTestProto - CanonicalDelimiter: pb - BasedOnStyle: google -ReferenceAlignment: Pointer -ReflowComments: true -RemoveBracesLLVM: false -RequiresClausePosition: OwnLine -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceAroundPointerQualifiers: Default -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: Never -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParentheses: false -SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -BitFieldColonSpacing: Both -Standard: Auto -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseCRLF: false -UseTab: Never -WhitespaceSensitiveMacros: - - STRINGIZE - - PP_STRINGIZE - - BOOST_PP_STRINGIZE - - NS_SWIFT_NAME - - CF_SWIFT_NAME -... - diff --git a/.clangd b/.clangd deleted file mode 100644 index 3af4d40d4e3..00000000000 --- a/.clangd +++ /dev/null @@ -1,3 +0,0 @@ -InlayHints: - Enabled: No - diff --git a/.gitignore b/.gitignore index dcae112071d..758a76cd798 100644 --- a/.gitignore +++ b/.gitignore @@ -52,16 +52,6 @@ ui_*.h *.user Makefile -# IDE settings -.cproject -.project -.settings -.vscode -.session -.clang-format -mne-cpp.pro.user* -compile_commands.json - # Generated docu Docker files /_site @@ -80,3 +70,16 @@ venv/ .cache/* codecov + +# IDE settings +.cproject +.project +.settings +.vscode +.session +.clang-format +mne-cpp.pro.user* +compile_commands.json +CPPLINT.cfg + + diff --git a/.ipfinder_hu56thzl b/.ipfinder_hu56thzl deleted file mode 100644 index efa40fbff10..00000000000 --- a/.ipfinder_hu56thzl +++ /dev/null @@ -1,11 +0,0 @@ -? (10.0.0.1) at ac:db:48:84:ee:9e on en0 ifscope [ethernet] -? (10.0.0.10) at 78:4f:43:4:dd:c1 on en0 ifscope [ethernet] -? (10.0.0.61) at 8:97:98:1a:7a:e4 on en0 ifscope [ethernet] -? (10.0.0.69) at 56:eb:af:1d:28:d8 on en0 ifscope [ethernet] -? (10.0.0.117) at 7c:d9:5c:41:59:e6 on en0 ifscope [ethernet] -? (10.0.0.147) at 42:f1:ce:4d:96:5d on en0 ifscope [ethernet] -? (10.0.0.165) at c2:50:67:9:a7:9e on en0 ifscope [ethernet] -? (10.0.0.236) at 10:2c:6b:f0:41:e on en0 ifscope [ethernet] -? (10.0.0.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet] -? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet] -? (239.255.255.250) at 1:0:5e:7f:ff:fa on en0 ifscope permanent [ethernet] From 564f021bc55d90f08f94d782bb57e539a2dc71f6 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 25 Apr 2023 16:15:51 -0400 Subject: [PATCH 113/147] make led indicator for channel work --- .../mne_scan/plugins/fieldline/fieldline.cpp | 7 +- .../plugins/fieldline/fieldline_definitions.h | 2 +- .../fieldline/fieldline_view_chassis.cpp | 95 +----------- .../fieldline/fieldline_view_chassis.h | 3 +- .../plugins/fieldline/fieldline_view_led.cpp | 0 .../plugins/fieldline/fieldline_view_led.h | 96 ------------ .../fieldline/fieldline_view_sensor.cpp | 139 +++++------------- .../plugins/fieldline/fieldline_view_sensor.h | 20 ++- .../fieldline/formfiles/fieldline_view.ui | 6 +- .../formfiles/fieldline_view_chassis.ui | 15 +- .../formfiles/fieldline_view_sensor.ui | 53 ++++++- 11 files changed, 130 insertions(+), 306 deletions(-) delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp delete mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index f200f453739..efaf869fa8e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -176,7 +176,8 @@ void Fieldline::unload() { //============================================================================================================= -bool Fieldline::start() { +bool Fieldline::start() +{ qDebug() << "start Fieldline"; QThread::start(); @@ -217,8 +218,7 @@ QWidget *Fieldline::setupWidget() { void Fieldline::findIpAsync(const std::string mac, std::function callback) { - std::cout << "outside here!\n"; - std::cout << "mac: " << mac << "\n"; + std::cout << "outside here! mac: " << mac << " \n"; std::thread ipFinder([=]{ IPFINDER::IpFinder ipFinder; ipFinder.addMacAddress(mac); @@ -227,7 +227,6 @@ void Fieldline::findIpAsync(const std::string mac, std::cout.flush(); ipFinder.findIps(); if (ipFinder.macIpList.size() == 0) { - std::cout.flush(); callback(ipFinder.macIpList[0].ip); } else { diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h index 8a788c55155..022917d74a6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_definitions.h @@ -50,7 +50,7 @@ enum class FieldLineWaveType { WAVE_SINE = 2, }; -enum class FieldLineSensorStatusType { +enum class FieldlineSensorStatusType { SENSOR_OFF = 0, SENSOR_RESTARTING = 1, SENSOR_RESTARTED = 2, diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp index 5327d7f5b7a..d6b3dbb0f4e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp @@ -37,8 +37,9 @@ // INCLUDES //============================================================================================================= -#include -// #include "fieldline/fieldline.h" +#include + +// #include "fieldlin/fieldline.h" #include "fieldline/fieldline_view.h" #include "fieldline/fieldline_view_chassis.h" #include "fieldline/fieldline_view_sensor.h" @@ -71,7 +72,6 @@ // DEFINE MEMBER METHODS //============================================================================================================= - namespace FIELDLINEPLUGIN { //============================================================================================================= @@ -102,94 +102,5 @@ FieldlineViewChassis::~FieldlineViewChassis() delete m_pUi; } -// FieldlineViewChassis::initChannels(size_t numChans) -// { -// // for(int i = 0; i < num_chans; ++i){ -// // chans.push_back(new LEDIndicator()); -// // auto& last_item = chans.back(); -// // chans.back()->setLabel(QString::number(i + 1)); -// // ui->chan_frame->layout()->addWidget(chans.back()); -// // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); -// // connect(this, &FieldlineViewChassis::clicked, this, &FieldlineViewChassis::rightClickMenu, Qt::UniqueConnection); -// // } -// } - -//============================================================================================================= -// -// void FieldlineViewChassis::setColor(size_t chan_num, const QColor& color) -// { -// if(chan_num > chans.size() || chan_num < 1){ -// return; -// } -// chans.at(chan_num - 1)->setColor(color); -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::setColor(size_t chan_num, const QColor& color, bool blinking) -// { -// setColor(chan_num, color); -// setBlinkState(chan_num, blinking); -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::setColor(const QColor& color) -// { -// for(auto* chan : chans){ -// chan->setColor(color); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::setColor(const QColor& color, bool blinking) -// { -// for(auto* chan : chans){ -// chan->setColor(color); -// chan->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::setBlinkState(size_t chan_num, bool blinking) -// { -// if(chan_num > chans.size() || chan_num < 1){ -// return; -// } -// chans.at(chan_num - 1)->setBlink(blinking); -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::setBlinkState(bool blinking) -// { -// for(auto* chan : chans){ -// chan->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewChassis::rightClickMenu(int chan, const QPoint& pos) -// { -// // auto* menu = new QMenu(); -// -// // auto blink_on_chan = menu->addAction("Blink ON - " + QString::number(chan)); -// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); -// -// // auto blink_off_chan = menu->addAction("Blink OFF - " + QString::number(chan)); -// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); -// -// // connect(blink_on_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, true);}); -// // connect(blink_off_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, false);}); -// -// // connect(blink_on_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(true);}); -// // connect(blink_off_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(false);}); -// -// // menu->exec(pos); -// } - } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index 7c4c5a16c00..6faab73737d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -76,9 +76,10 @@ class FieldlineViewChassis : public QWidget Q_OBJECT public: - explicit FieldlineViewChassis(FieldlineView *parent, int num); + explicit FieldlineViewChassis(FieldlineView *parent, int num); ~FieldlineViewChassis(); + private: FieldlineView *m_pFieldlineView; Ui::uiFieldlineViewChassis* m_pUi; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h deleted file mode 100644 index 3fe23133644..00000000000 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_led.h +++ /dev/null @@ -1,96 +0,0 @@ -//============================================================================================================= -/** - * @file fieldline_view_led.h - * @author Juan Garcia-Prieto - * Gabriel Motta - * @since 0.1.9 - * @file fieldline_view_chassis.h - * @date February, 2023 - * - * @section LICENSE - * - * Copyright (C) 2023, Gabriel Motta, Juan Garcia-Prieto. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * @brief FieldlineView class declaration. - * - */ - -//============================================================================================================= -// INCLUDES -//============================================================================================================= - - // #include "disp/viewers/led_indicator.h" - -//============================================================================================================= -// QT INCLUDES -//============================================================================================================= - -#include - -//============================================================================================================= -// EIGEN INCLUDES -//============================================================================================================= - -//============================================================================================================= -// FORWARD DECLARATIONS -//============================================================================================================= - -namespace Ui { -class uiFieldlineViewChassis; -} -//============================================================================================================= -// DEFINE NAMESPACE DISPLIB -//============================================================================================================= - -namespace FIELDLINEPLUGIN { - -//============================================================================================================= - -class FieldlineViewChassis : public QWidget -{ - Q_OBJECT - - public: - FieldlineViewChassis(int num_sensors, QWidget *parent = nullptr); - ~FieldlineViewChassis(); - // void setColor(size_t sensor_num, const QColor& color); - // void setColor(size_t sensor_num, const QColor& color, bool blinking); - // void setColor(const QColor& color); - // void setColor(const QColor& color, bool blinking); - // - // void setBlinkState(size_t sensor_num, bool blinking); - // void setBlinkState(bool blinking); - // - // signals: - // void clicked(int sensor, const QPoint& pos); - // - // private slots: - // void rightClickMenu(int sensor, const QPoint& pos); - - private: - QWidget* m_pParent; - Ui::uiFieldlineViewChassis* m_pUi; - std::vector* m_pSensors; -}; - -} // namespace FIELDLINEPLUGIN - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp index c0779ae37b0..3d674ad95ec 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp @@ -1,6 +1,6 @@ //============================================================================================================= /** - * @file fieldline_view_chassis.cpp + * @file fieldline_view_sensor.cpp * @author Juan Garcia-Prieto * Gabriel Motta * @since 0.1.9 @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * - * @brief FieldlineView class definition. + * @brief FieldlineView Sensor class declaration. * */ @@ -43,7 +43,7 @@ // #include "fieldline/fieldline.h" // #include "fieldline/fieldline_view.h" #include "fieldline/fieldline_view_sensor.h" -// #include "fieldline/fieldline_view_chassis.h" +#include "fieldline/fieldline_view_chassis.h" #include "formfiles/ui_fieldline_view_sensor.h" //============================================================================================================= @@ -51,6 +51,8 @@ //============================================================================================================= // #include +#include +#include // #include // #include // #include @@ -79,17 +81,24 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= FieldlineViewSensor::FieldlineViewSensor(FieldlineViewChassis *parent, int index) -: m_pFieldlineViewChassis(parent), - m_pUi(new Ui::uiFieldlineViewSensor), - m_sensorIndex(index) +: QWidget(parent), + m_pFieldlineViewChassis(parent), + m_pUi(new Ui::uiFieldlineViewSensor), + m_sensorIndex(index) { m_pUi->setupUi(this); - - // QVBoxLayout* layout = new QVBoxLayout; - // QFrame* frame = new QFrame; - // - // layout->addWidget(frame); - // QWidget::setLayout(layout); + + + m_pScene = new QGraphicsScene(); + m_pUi->ledQGraphView->setStyleSheet("background:transparent"); + m_pUi->ledQGraphView->horizontalScrollBar()->hide(); + m_pUi->ledQGraphView->verticalScrollBar()->hide(); + m_pUi->label->setText(QString::number(index)); + m_pUi->ledQGraphView->setScene(m_pScene); + // m_pUi->ledQGraphView->fitInView(m_pScene, Qt::KeepAspectRatio); + + m_pCircleLed = m_pScene->addEllipse(0, 0, this->width()/3., this->width()/3., + QPen(Qt::black), QBrush(QColor(200, 1, 1))); } FieldlineViewSensor::~FieldlineViewSensor() @@ -97,94 +106,26 @@ FieldlineViewSensor::~FieldlineViewSensor() delete m_pUi; } -// FieldlineViewSensor::initChannels(size_t numChans) -// { -// // for(int i = 0; i < num_chans; ++i){ -// // chans.push_back(new LEDIndicator()); -// // auto& last_item = chans.back(); -// // chans.back()->setLabel(QString::number(i + 1)); -// // ui->chan_frame->layout()->addWidget(chans.back()); -// // connect(chans.back(), &QWidget::customContextMenuRequested, [this, i, &last_item](const QPoint& pos){this->emit clicked(i, last_item->mapToGlobal(pos)); qDebug() << "clicked " << i+1;}); -// // connect(this, &FieldlineViewSensor::clicked, this, &FieldlineViewSensor::rightClickMenu, Qt::UniqueConnection); -// // } -// } +void FieldlineViewSensor::resizeEvent(QResizeEvent *event) +{ + // m_pUi->ledQGraphView->fitInView(, Qt::KeepAspectRatio); + auto bounds = m_pScene->itemsBoundingRect(); + bounds.setWidth(bounds.width() * 1.2); + bounds.setHeight(bounds.height() * 1.2); + std::cout << "Resize: " << bounds.width() << " , " << bounds.height() << "\n"; std::cout.flush(); + m_pUi->ledQGraphView->fitInView(bounds, Qt::KeepAspectRatio); + + QWidget::resizeEvent(event); +} -//============================================================================================================= -// -// void FieldlineViewSensor::setColor(size_t chan_num, const QColor& color) -// { -// if(chan_num > chans.size() || chan_num < 1){ -// return; -// } -// chans.at(chan_num - 1)->setColor(color); -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::setColor(size_t chan_num, const QColor& color, bool blinking) -// { -// setColor(chan_num, color); -// setBlinkState(chan_num, blinking); -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::setColor(const QColor& color) -// { -// for(auto* chan : chans){ -// chan->setColor(color); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::setColor(const QColor& color, bool blinking) -// { -// for(auto* chan : chans){ -// chan->setColor(color); -// chan->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::setBlinkState(size_t chan_num, bool blinking) -// { -// if(chan_num > chans.size() || chan_num < 1){ -// return; -// } -// chans.at(chan_num - 1)->setBlink(blinking); -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::setBlinkState(bool blinking) -// { -// for(auto* chan : chans){ -// chan->setBlink(blinking); -// } -// } -// -// //============================================================================================================= -// -// void FieldlineViewSensor::rightClickMenu(int chan, const QPoint& pos) -// { -// // auto* menu = new QMenu(); -// -// // auto blink_on_chan = menu->addAction("Blink ON - " + QString::number(chan)); -// // auto blink_on_chassis = menu->addAction("Blink ON - Whole Chassis"); -// -// // auto blink_off_chan = menu->addAction("Blink OFF - " + QString::number(chan)); -// // auto blink_off_chassis = menu->addAction("Blink OFF - Whole Chassis"); -// -// // connect(blink_on_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, true);}); -// // connect(blink_off_chan, &QAction::triggered,[this, chan](){this->setBlinkState(chan, false);}); -// -// // connect(blink_on_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(true);}); -// // connect(blink_off_chassis, &QAction::triggered,[this, chan](){this->setBlinkState(false);}); -// -// // menu->exec(pos); -// } + +void FieldlineViewSensor::setState(FieldlineSensorStatusType state) { + m_state = state; +} + +FieldlineSensorStatusType FieldlineViewSensor::getState() const { + return m_state; +} } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h index be0fc9d327d..8cf93176e58 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h @@ -1,6 +1,6 @@ //============================================================================================================= /** - * @file fieldline_view_chassis.h + * @file fieldline_view_sensor.h * @author Juan Garcia-Prieto * Gabriel Motta * @since 0.1.9 @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * - * @brief FieldlineView class declaration. + * @brief FieldlineView Sensor class declaration. * */ @@ -39,6 +39,7 @@ //============================================================================================================= // INCLUDES //============================================================================================================= +#include "fieldline/fieldline_definitions.h" //============================================================================================================= // QT INCLUDES @@ -58,11 +59,13 @@ namespace Ui { class uiFieldlineViewSensor; } - //============================================================================================================= // DEFINE NAMESPACE DISPLIB //============================================================================================================= +class QGraphicsScene; +class QGraphicsEllipseItem; + namespace FIELDLINEPLUGIN { class FieldlineViewChassis; @@ -76,13 +79,20 @@ class FieldlineViewSensor: public QWidget public: explicit FieldlineViewSensor(FieldlineViewChassis *parent, int index); ~FieldlineViewSensor(); + void setState(FieldlineSensorStatusType state); + FieldlineSensorStatusType getState() const; + + protected: + virtual void resizeEvent(QResizeEvent *event); private: FieldlineViewChassis *m_pFieldlineViewChassis; - Ui::uiFieldlineViewSensor* m_pUi; + Ui::uiFieldlineViewSensor* m_pUi; + QGraphicsScene *m_pScene; + QGraphicsEllipseItem* m_pCircleLed; + FieldlineSensorStatusType m_state; int m_sensorIndex; }; - } // namespace FIELDLINEPLUGIN #endif // FIELDLINEPLUGIN_FIELDLINEVIEWSENSOR_H diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 9e35e337a4b..9ec29b965e8 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -6,7 +6,7 @@ 0 0 - 652 + 948 665 @@ -51,7 +51,7 @@ - 800 + 1000 115 @@ -199,7 +199,7 @@ - 800 + 1000 16777215 diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui index 7e0ebb83d77..756003b21f7 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui @@ -74,7 +74,20 @@ QFrame::Plain - + + + 0 + + + 0 + + + 0 + + + 0 + + diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui index ee09138a599..99a0bc2797b 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui @@ -6,8 +6,8 @@ 0 0 - 137 - 320 + 113 + 206 @@ -20,16 +20,61 @@ Form + + 0 + + + 0 + + + 0 + + + 0 + - QFrame::StyledPanel + QFrame::NoFrame - QFrame::Raised + QFrame::Plain + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 30 + + + + QFrame::NoFrame + + + QFrame::Plain + + + QAbstractScrollArea::AdjustToContents + + + + From 44aa352be22b2ec37116a5aae4e755d8bf02133b Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 26 Apr 2023 01:35:36 -0400 Subject: [PATCH 114/147] add blinking structure for leds --- .../fieldline_api_mock/fieldline_service.py | 34 ++++++++++++-- resources/mne_scan/plugins/fieldline/main.py | 19 +++++++- .../plugins/fieldline/fieldline_view.cpp | 8 +++- .../fieldline/fieldline_view_chassis.cpp | 46 ++++++++++++++++--- .../fieldline/fieldline_view_chassis.h | 11 ++++- .../fieldline/fieldline_view_sensor.cpp | 42 +++++++++++++---- .../plugins/fieldline/fieldline_view_sensor.h | 20 ++++++-- .../fieldline/formfiles/fieldline_view.ui | 4 +- .../formfiles/fieldline_view_chassis.ui | 19 +++++++- .../formfiles/fieldline_view_sensor.ui | 3 ++ 10 files changed, 175 insertions(+), 31 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index 33f75f2fc9f..d2261fa144a 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -1,6 +1,34 @@ import threading -import random_data import time +import random + + +def generate_data(): + timestamp = 179331926 + num_sensors_per_chassis = 16 + num_chassis = 2 + + data_frames = {} + + data_values = [91599] + \ + [round(random.normalvariate(0, 1000)) + for _ in range(1, num_sensors_per_chassis * num_chassis + 1)] + + chassis_labels = [0] + [num for num in range(0, num_chassis) for _ in range(num_sensors_per_chassis)] + sensor_labels = [0] + (list(range(1, num_sensors_per_chassis + 1))) * num_chassis + data_type_labels = [0] + ([50] * num_sensors_per_chassis * num_chassis) + global_labels = [f'{chassis_label:02}:{sensor_label:02}:{data_type:02}' + for chassis_label, sensor_label, data_type in zip(chassis_labels, sensor_labels, data_type_labels)] + + for global_l, data_i, sensor_l, chassis_l, data_type_l in \ + zip(global_labels, data_values, sensor_labels, chassis_labels, data_type_labels): + data_frames[global_l] = \ + {'data': data_i, 'sensor': f'{chassis_l:02}:{sensor_l:02}', 'sensor_id': sensor_l, 'data_type': data_type_l} + + + # data_frames = [] + return {'timestamp': timestamp, 'data_frames': data_frames} + class FieldLineService: def __init__(self, ip_list, prefix=""): @@ -60,7 +88,7 @@ def get_chassis_list(self): def data_acquisition(self): start_time = time.time() - data = random_data.generate_data() + data = generate_data() end_time = time.time() elapsed_time = end_time - start_time time.sleep(0.001 - elapsed_time) @@ -71,7 +99,7 @@ def data_acquisition(self): while(self.continue_data_acquisition): start_time = time.time() - data = random_data.generate_data() + data = generate_data() self.callback_function(data) end_time = time.time() elapsed_time = end_time - start_time diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index 0df61cb211d..28af104446c 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,6 +1,7 @@ """This is my super module""" import sys -# from fieldline_api_mock.fieldline_service import FieldlineService +from fieldline_api_mock.fieldline_service import FieldLineService +import time for path in sys.path: print(path) @@ -9,5 +10,19 @@ print("hello pepe vamos vamos!!!") -# fl = FieldlineService(["8.8.8.8", "9.9.9.9"]) +ip_list = ["8.8.8.8", "9.9.9.9"] + +# fl = FieldLineService(["8.8.8.8", "9.9.9.9"]) +# with FieldLineService(ip_list) as service: +# done = False +# # Get dict of all the sensors +# sensors = service.load_sensors() +# print(f"Got sensors: {sensors}") +# # Make sure closed loop is set +# service.set_closed_loop(True) +# print("Doing sensor restart") +# # Do the restart +# service.restart_sensors(sensors, on_next=lambda c_id, s_id: print(f'sensor {c_id}:{s_id} finished restart'), on_error=lambda c_id, s_id, err: print(f'sensor {c_id}:{s_id} failed with {hex(err)}'), on_completed=lambda: call_done()) +# while not done: +# time.sleep(0.5) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 6c3f965f3d3..c0dbedc22ba 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -119,7 +119,7 @@ void FieldlineView::macIpTableDoubleClicked(int row, int col) { std::cout << "cell (" << row << "," << col << ") " << " doubleclicked : " << m_pMacIpTable->item(row, col)->text().toStdString() << "\n"; std::cout.flush(); - auto callback = [this, row, col](const std::string str) { + auto callback = [this, row, col](const std::string& str) { std::cout << "inside callback! :" << str << " \n"; m_pMacIpTable->item(row, col+1)->setText(str.c_str()); m_pMacIpTable->repaint(); @@ -131,6 +131,12 @@ void FieldlineView::macIpTableDoubleClicked(int row, int col) { void FieldlineView::setNumRowsIpMacFrame(int numRows) { m_pMacIpTable->setRowCount(numRows); + QStringList vertLabels; + for ( int i = 0; i < numRows; i++ ) { + vertLabels.push_back(QString::number(i)); + } + m_pMacIpTable->setVerticalHeaderLabels(vertLabels); + if (numRows > 0) { m_pMacIpTable->setSortingEnabled(false); m_pMacIpTable->setItem(numRows-1, 0, new QTableWidgetItem("AF:70:04:21:2D:28")); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp index d6b3dbb0f4e..b53d785467b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.cpp @@ -81,26 +81,58 @@ FieldlineViewChassis::FieldlineViewChassis(FieldlineView *parent, int num ) m_pFieldlineView(parent), m_pUi(new Ui::uiFieldlineViewChassis), chassisNum(num), - numSensors(16) + numSensors(16), + sensorLedUpdateFreq(150) { m_pUi->setupUi(this); std::string chassisName("Fieldline Chassis "); chassisName += std::to_string(chassisNum); m_pUi->chassisName->setText(QString::fromStdString(chassisName)); - QHBoxLayout* sensorLayout = qobject_cast(m_pUi->sensorFrame->layout()); + createSensors(); + chassisActive.store(true); + chassisRunning.store(true); + updateSensorLedThread = std::thread(&FieldlineViewChassis::updateSensorLeds, this); +} - for (int i = 0; i < numSensors; i++) { - FieldlineViewSensor* pSensor = new FieldlineViewSensor(this, i); - sensorLayout->insertWidget(i, pSensor); - m_pSensors.push_back(pSensor); +void FieldlineViewChassis::updateSensorLeds() +{ + while (chassisRunning.load()) { + while (chassisActive.load()) { + for (auto pSensor : m_pSensors) { + pSensor->updateLedState(); + } + std::this_thread::sleep_for(sensorLedUpdateFreq); } + } +} + +void FieldlineViewChassis::createSensors() +{ + QHBoxLayout* sensorLayout = qobject_cast(m_pUi->sensorFrame->layout()); + for (int i = 0; i < numSensors; i++) { + FieldlineViewSensor* pSensor = new FieldlineViewSensor(this, i); + sensorLayout->insertWidget(i, pSensor); + m_pSensors.push_back(pSensor); + } } FieldlineViewChassis::~FieldlineViewChassis() { - delete m_pUi; + // delete m_pUi; + chassisActive.store(false); + chassisRunning.store(false); + if (updateSensorLedThread.joinable()) { + updateSensorLedThread.join(); + } } +void FieldlineViewChassis::setActive() +{ + chassisActive.store(true); +} + + + } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h index 6faab73737d..0fe524c2336 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_chassis.h @@ -41,6 +41,9 @@ //============================================================================================================= #include +#include +#include +#include //============================================================================================================= // QT INCLUDES @@ -78,14 +81,20 @@ class FieldlineViewChassis : public QWidget public: explicit FieldlineViewChassis(FieldlineView *parent, int num); ~FieldlineViewChassis(); - + void setActive(); private: + void createSensors(); + void updateSensorLeds(); FieldlineView *m_pFieldlineView; Ui::uiFieldlineViewChassis* m_pUi; std::vector m_pSensors; int chassisNum; int numSensors; + std::chrono::milliseconds sensorLedUpdateFreq; + std::thread updateSensorLedThread; + std::atomic chassisActive; + std::atomic chassisRunning; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp index 3d674ad95ec..40a0dbfd485 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp @@ -83,19 +83,21 @@ namespace FIELDLINEPLUGIN { FieldlineViewSensor::FieldlineViewSensor(FieldlineViewChassis *parent, int index) : QWidget(parent), m_pFieldlineViewChassis(parent), + m_sensorIndex(index), + m_sensorState(FieldlineSensorStatusType::SENSOR_OFF), + ledChangePeriod(600), + ledState(LedState::A), m_pUi(new Ui::uiFieldlineViewSensor), - m_sensorIndex(index) + m_pScene(new QGraphicsScene) { + updateTimeStamp(); m_pUi->setupUi(this); - - m_pScene = new QGraphicsScene(); m_pUi->ledQGraphView->setStyleSheet("background:transparent"); m_pUi->ledQGraphView->horizontalScrollBar()->hide(); m_pUi->ledQGraphView->verticalScrollBar()->hide(); m_pUi->label->setText(QString::number(index)); m_pUi->ledQGraphView->setScene(m_pScene); - // m_pUi->ledQGraphView->fitInView(m_pScene, Qt::KeepAspectRatio); m_pCircleLed = m_pScene->addEllipse(0, 0, this->width()/3., this->width()/3., QPen(Qt::black), QBrush(QColor(200, 1, 1))); @@ -103,12 +105,11 @@ FieldlineViewSensor::FieldlineViewSensor(FieldlineViewChassis *parent, int index FieldlineViewSensor::~FieldlineViewSensor() { - delete m_pUi; + // delete m_pUi; } void FieldlineViewSensor::resizeEvent(QResizeEvent *event) { - // m_pUi->ledQGraphView->fitInView(, Qt::KeepAspectRatio); auto bounds = m_pScene->itemsBoundingRect(); bounds.setWidth(bounds.width() * 1.2); bounds.setHeight(bounds.height() * 1.2); @@ -118,13 +119,36 @@ void FieldlineViewSensor::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } - void FieldlineViewSensor::setState(FieldlineSensorStatusType state) { - m_state = state; + m_sensorState = state; + updateTimeStamp(); } FieldlineSensorStatusType FieldlineViewSensor::getState() const { - return m_state; + return m_sensorState; +} + +void FieldlineViewSensor::updateTimeStamp() +{ + timeStamp = std::chrono::steady_clock::now(); +} + +void FieldlineViewSensor::updateLedState() +{ + std::chrono::time_point now = std::chrono::steady_clock::now(); + std::chrono::milliseconds duration = std::chrono::duration_cast(now - timeStamp); + if (duration >= ledChangePeriod) { + switchLedState(); + } +} + +void FieldlineViewSensor::switchLedState() { + if (ledState == LedState::A) { + ledState = LedState::B; + } else { + ledState = LedState::B; + } + updateTimeStamp(); } } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h index 8cf93176e58..d46d9820b3c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.h @@ -39,6 +39,8 @@ //============================================================================================================= // INCLUDES //============================================================================================================= + +#include #include "fieldline/fieldline_definitions.h" //============================================================================================================= @@ -81,17 +83,27 @@ class FieldlineViewSensor: public QWidget ~FieldlineViewSensor(); void setState(FieldlineSensorStatusType state); FieldlineSensorStatusType getState() const; + void updateLedState(); protected: virtual void resizeEvent(QResizeEvent *event); private: + void updateTimeStamp(); + void switchLedState(); + FieldlineViewChassis *m_pFieldlineViewChassis; - Ui::uiFieldlineViewSensor* m_pUi; - QGraphicsScene *m_pScene; - QGraphicsEllipseItem* m_pCircleLed; - FieldlineSensorStatusType m_state; int m_sensorIndex; + FieldlineSensorStatusType m_sensorState; + std::chrono::time_point timeStamp; + std::chrono::milliseconds ledChangePeriod; + + enum class LedState { A, B }; + LedState ledState; + + Ui::uiFieldlineViewSensor *m_pUi; + QGraphicsScene *m_pScene; + QGraphicsEllipseItem *m_pCircleLed; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 9ec29b965e8..219bef14883 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -38,7 +38,7 @@ - + 0 0 @@ -46,7 +46,7 @@ 600 - 100 + 120 diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui index 756003b21f7..0bbfaaa5f55 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_chassis.ui @@ -35,6 +35,18 @@ QFrame::Raised + + 2 + + + 2 + + + 0 + + + 0 + @@ -46,13 +58,13 @@ 0 - 40 + 10 16777215 - 40 + 20 @@ -75,6 +87,9 @@ QFrame::Plain + + 2 + 0 diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui index 99a0bc2797b..688cf361a3f 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view_sensor.ui @@ -34,6 +34,9 @@ + + 0 + From e5fa21c1aa444c43d1cf8898544d01c1202f39b6 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:29:59 -0400 Subject: [PATCH 115/147] minor edits --- .../mne_scan/libs/scShared/Plugins/abstractplugin.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h b/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h index 2d21486eb67..03d4f387d88 100644 --- a/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h +++ b/src/applications/mne_scan/libs/scShared/Plugins/abstractplugin.h @@ -231,10 +231,10 @@ class SCSHAREDSHARED_EXPORT AbstractPlugin : public QThread */ inline void addPluginAction(QAction* pAction); - InputConnectorList m_inputConnectors; /**< Set of input connectors associated with this plug-in. */ - OutputConnectorList m_outputConnectors; /**< Set of output connectors associated with this plug-in. */ + InputConnectorList m_inputConnectors; /**< Set of input connectors associated with this plug-in. */ + OutputConnectorList m_outputConnectors; /**< Set of output connectors associated with this plug-in. */ - bool m_bPluginControlWidgetsInit = false; /**< Flag to indicate if the plugin control widgets were initialized already. */ + bool m_bPluginControlWidgetsInit = false; /**< Flag to indicate if the plugin control widgets were initialized already. */ private: QList< QAction* > m_qListPluginActions; /**< List of plugin actions. */ From 6f45304fb201d5e65cc6cfc4ed42826c84be24ec Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:34:14 -0400 Subject: [PATCH 116/147] minor edits multisamplearray --- .../mne_scan/libs/scMeas/realtimemultisamplearray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp b/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp index 9fbde90490b..8284ae1e66e 100644 --- a/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp +++ b/src/applications/mne_scan/libs/scMeas/realtimemultisamplearray.cpp @@ -158,7 +158,7 @@ void RealTimeMultiSampleArray::setValue(const MatrixXd& mat) // else if(v[i] > m_qListChInfo[i].getMaxValue()) v[i] = m_qListChInfo[i].getMaxValue(); // } - // Store + //Store m_matSamples.push_back(mat); m_qMutex.unlock(); From 527211f618495760ad22cf4954b53634b0a17c8c Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:35:48 -0400 Subject: [PATCH 117/147] minor edits mainwindow --- src/applications/mne_scan/mne_scan/mainwindow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index 3fe04af1761..77f572b8fe4 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -578,10 +578,8 @@ void MainWindow::createActions() connect(m_pActionStop.data(), &QAction::triggered, this, &MainWindow::stopMeasurement); - // Display Toolbar - m_pActionQuickControl = new QAction( - QIcon(":/images/quickControl.png"), - tr("Show quick control widget"),this); + //Display Toolbar + m_pActionQuickControl = new QAction(QIcon(":/images/quickControl.png"),tr("Show quick control widget"),this); m_pActionQuickControl->setStatusTip(tr("Show quick control widget")); connect(m_pActionQuickControl.data(), &QAction::triggered, m_pQuickControlView.data(), &QuickControlView::show); From 0f1b2c1388ae5630d706607446ba360f93551eac Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:36:34 -0400 Subject: [PATCH 118/147] minor edits mainwindow mne_scan --- src/applications/mne_scan/mne_scan/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index 77f572b8fe4..412869da53b 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -583,7 +583,7 @@ void MainWindow::createActions() m_pActionQuickControl->setStatusTip(tr("Show quick control widget")); connect(m_pActionQuickControl.data(), &QAction::triggered, m_pQuickControlView.data(), &QuickControlView::show); - m_pActionQuickControl->setVisible(true); + m_pActionQuickControl->setVisible(false); } //============================================================================================================= From 123e768b143274d9db7e30de58b19e34295fe8c9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:43:09 -0400 Subject: [PATCH 119/147] minor edit --- src/applications/mne_scan/mne_scan/plugingui.cpp | 2 +- .../plugins/noisereduction/noisereduction.cpp | 2 +- .../disp/viewers/formfiles/scalecontrol.ui | 14 +------------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/plugingui.cpp b/src/applications/mne_scan/mne_scan/plugingui.cpp index 4422a64bc93..dda3b866cf9 100644 --- a/src/applications/mne_scan/mne_scan/plugingui.cpp +++ b/src/applications/mne_scan/mne_scan/plugingui.cpp @@ -286,7 +286,7 @@ void PluginGui::loadConfig(const QString& sPath, const QString& sFileName) void PluginGui::saveConfig(const QString& sPath, const QString& sFileName) { - //qDebug() << "Save Config" << sPath+"/"+sFileName; + qDebug() << "Save Config" << sPath+"/"+sFileName; QDomDocument doc("PluginConfig"); QDomElement root = doc.createElement("PluginTree"); doc.appendChild(root); diff --git a/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp b/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp index 9775001dccf..92882f69f60 100644 --- a/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp +++ b/src/applications/mne_scan/plugins/noisereduction/noisereduction.cpp @@ -112,7 +112,7 @@ NoiseReduction::NoiseReduction() NoiseReduction::~NoiseReduction() { if(this->isRunning()) { - NoiseReduction::stop(); + stop(); } } diff --git a/src/libraries/disp/viewers/formfiles/scalecontrol.ui b/src/libraries/disp/viewers/formfiles/scalecontrol.ui index 4c5a1ac2bf3..6d0e5609438 100644 --- a/src/libraries/disp/viewers/formfiles/scalecontrol.ui +++ b/src/libraries/disp/viewers/formfiles/scalecontrol.ui @@ -35,17 +35,11 @@ - + 0 0 - - - 0 - 20 - - @@ -63,12 +57,6 @@ 0 - - - 0 - 20 - - Qt::Horizontal From 6efbcd42c9d9fcad5818c2cf5afa2eb8d07d1d56 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:47:52 -0400 Subject: [PATCH 120/147] solve crash on shut down --- .../mne_scan/plugins/fieldline/fieldline.cpp | 39 +++++++++++-------- .../mne_scan/plugins/fieldline/fieldline.h | 3 +- .../plugins/fieldline/fieldline_global.cpp | 6 +++ .../plugins/fieldline/fieldline_global.h | 15 +++++-- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index efaf869fa8e..c66de9a6d78 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -129,16 +129,15 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= Fieldline::Fieldline() - : - acqSystem(nullptr), +: acqSystem(nullptr), guiWidget(nullptr) { + printLog("constructor fieldline plugin"); } //============================================================================================================= Fieldline::~Fieldline() { - qDebug() << "Destroying Fieldline plugin."; if (this->isRunning()) { this->stop(); } @@ -156,21 +155,23 @@ QSharedPointer Fieldline::clone() const void Fieldline::init() { + printLog("Fieldline init"); // data infrastructure - m_pRTMSA = SCSHAREDLIB::PluginOutputData - ::create(this, "Fieldline Plugin", - "FieldlinePlguin output"); - m_outputConnectors.append(m_pRTMSA); + // m_pRTMSA = SCSHAREDLIB::PluginOutputData + // ::create(this, "Fieldline Plugin", + // "FieldlinePlguin output"); + // m_outputConnectors.append(m_pRTMSA); - acqSystem = new FieldlineAcqSystem(this); - guiWidget = new FieldlineView(this); + // acqSystem = new FieldlineAcqSystem(this); + // guiWidget = new FieldlineView(this); } //============================================================================================================= void Fieldline::unload() { qDebug() << "unload Fieldline"; - delete acqSystem; + printLog("unload"); + // delete acqSystem; // delete guiWidget; // deleted by Qt } @@ -179,6 +180,7 @@ void Fieldline::unload() { bool Fieldline::start() { qDebug() << "start Fieldline"; + std::cout.flush(); QThread::start(); @@ -190,7 +192,7 @@ bool Fieldline::start() bool Fieldline::stop() { requestInterruption(); wait(500); - + printLog("stop"); return true; } @@ -210,21 +212,22 @@ QString Fieldline::getName() const { //============================================================================================================= QWidget *Fieldline::setupWidget() { - return guiWidget; - // return new QLabel("hola!"); + printLog("setupWidget"); + // return guiWidget; + return new QLabel("hola!"); } //============================================================================================================= void Fieldline::findIpAsync(const std::string mac, std::function callback) { - std::cout << "outside here! mac: " << mac << " \n"; + // std::cout << "outside here! mac: " << mac << "\n"; std::thread ipFinder([=]{ IPFINDER::IpFinder ipFinder; ipFinder.addMacAddress(mac); - std::cout << "here inside!\n"; - std::cout << "mac: " << mac << "\n"; - std::cout.flush(); + // std::cout << "here inside!\n"; + // std::cout << "mac: " << mac << "\n"; + // std::cout.flush(); ipFinder.findIps(); if (ipFinder.macIpList.size() == 0) { std::cout.flush(); @@ -240,6 +243,7 @@ void Fieldline::findIpAsync(const std::string mac, void Fieldline::run() { qDebug() << "run Fieldline"; + std::cout.flush(); } // while (true) { // if (QThread::isInterruptionRequested()) @@ -298,6 +302,7 @@ void Fieldline::run() { QString Fieldline::getBuildInfo() { qDebug() << "getBuildInfo Fieldline"; + std::cout.flush(); return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 79e07a2abef..4e8f717a185 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -73,7 +73,7 @@ namespace FIELDLINEPLUGIN { class FieldlineAcqSystem; class FieldlineView; -//============================================================================================================= +//============================================================================================================ /** * The Fieldline class provides a MEG connector for receiving data from Fieldline box through its Python API. * @@ -84,7 +84,6 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") Q_INTERFACES(SCSHAREDLIB::AbstractSensor) - public: //========================================================================================================= // The plugin interface diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp index 13809aec2de..aaf03c2cb6e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.cpp @@ -52,3 +52,9 @@ const char* FIELDLINEPLUGIN::buildHash() { return UTILSLIB::gitHash();} //============================================================================================================= const char* FIELDLINEPLUGIN::buildHashLong() { return UTILSLIB::gitHashLong();} + +void FIELDLINEPLUGIN::printLog(const std::string& str) { + std::cout << str << "\n"; + std::cout.flush(); +} + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_global.h b/src/applications/mne_scan/plugins/fieldline/fieldline_global.h index 095072664a8..0807588cc56 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_global.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_global.h @@ -40,6 +40,9 @@ // INCLUDES //============================================================================================================= +#include +#include + #include //============================================================================================================= @@ -53,9 +56,9 @@ //============================================================================================================= #if defined(SCAN_FIELDLINE_PLUGIN) -# define FIELDLINESHARED_EXPORT Q_DECL_EXPORT /**< Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library. */ +# define FIELDLINESHARED_EXPORT Q_DECL_EXPORT #else -# define FIELDLINESHARED_EXPORT Q_DECL_IMPORT /**< Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library. */ +# define FIELDLINESHARED_EXPORT Q_DECL_IMPORT #endif namespace FIELDLINEPLUGIN{ @@ -76,6 +79,12 @@ FIELDLINESHARED_EXPORT const char* buildHash(); /** * Returns full build git hash. */ -FIELDLINESHARED_EXPORT const char* buildHashLong(); } // namespace FIELDLINEPLUGIN +FIELDLINESHARED_EXPORT const char* buildHashLong(); + +void printLog(const std::string& str); + +} // namespace FIELDLINEPLUGIN + + #endif // FIELDLINE_GLOBAL_H From 3b04e7900283ab3f430561325f84a93cd6ed0704 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 00:58:25 -0400 Subject: [PATCH 121/147] minior edits --- src/CMakeLists.txt | 2 +- src/applications/CMakeLists.txt | 4 ++-- src/applications/mne_scan/mne_scan/mainwindow.cpp | 9 ++++----- src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt | 3 +-- src/libraries/CMakeLists.txt | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index da79c4f7190..5985bf93823 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,7 +125,7 @@ endif() if(BUILD_TESTS) add_subdirectory(testframes) endif() - + ##============================================================================== ## Add symbolic links to project resources folder diff --git a/src/applications/CMakeLists.txt b/src/applications/CMakeLists.txt index 025af9078bd..950bcc5060c 100644 --- a/src/applications/CMakeLists.txt +++ b/src/applications/CMakeLists.txt @@ -5,12 +5,12 @@ if(WIN32) endif() if(APPLE) - set(CMAKE_INSTALL_RPATH "@executable_path/../lib") + set(CMAKE_INSTALL_RPATH "@executable_path/../lib") if(NOT BUILD_MAC_APP_BUNDLE) set(CMAKE_MACOSX_RPATH TRUE) endif() else() - set(CMAKE_INSTALL_RPATH "\${ORIGIN}/../lib") + set(CMAKE_INSTALL_RPATH "\${ORIGIN}/../lib") endif() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index 412869da53b..f33b889e2bf 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -579,7 +579,7 @@ void MainWindow::createActions() this, &MainWindow::stopMeasurement); //Display Toolbar - m_pActionQuickControl = new QAction(QIcon(":/images/quickControl.png"),tr("Show quick control widget"),this); + m_pActionQuickControl = new QAction(QIcon(":/images/quickControl.png"), tr("Show quick control widget"),this); m_pActionQuickControl->setStatusTip(tr("Show quick control widget")); connect(m_pActionQuickControl.data(), &QAction::triggered, m_pQuickControlView.data(), &QuickControlView::show); @@ -656,13 +656,12 @@ void MainWindow::createToolBars() m_pToolBar->addSeparator(); m_pLabelTime = new QLabel(this); - m_pLabelTime->setStatusTip("Measurement time duration."); - m_pLabelTime->setText(QTime(0, 0).toString()); m_pToolBar->addWidget(m_pLabelTime); + m_pLabelTime->setText(QTime(0, 0).toString()); } - // Plugin - if (!m_pDynamicPluginToolBar) { + //Plugin + if(!m_pDynamicPluginToolBar) { m_pDynamicPluginToolBar = addToolBar(tr("Plugin Control")); } diff --git a/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt b/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt index 6700cf58afa..cf29962d943 100644 --- a/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt +++ b/src/external/eigen-3.4.0/demos/opengl/CMakeLists.txt @@ -3,7 +3,7 @@ find_package(OpenGL) if(QT4_FOUND AND OPENGL_FOUND) - set(QT_USE_QTOPENGL FALSE) + set(QT_USE_QTOPENGL TRUE) include(${QT_USE_FILE}) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -27,4 +27,3 @@ else() endif() - diff --git a/src/libraries/CMakeLists.txt b/src/libraries/CMakeLists.txt index f73569a53fc..0e4ff82a7d4 100644 --- a/src/libraries/CMakeLists.txt +++ b/src/libraries/CMakeLists.txt @@ -32,12 +32,12 @@ message(STATUS CMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) message(STATUS CMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) if(APPLE) - set(CMAKE_INSTALL_RPATH "@executable_path/../lib") + set(CMAKE_INSTALL_RPATH "@executable_path/../lib") if(NOT BUILD_MAC_APP_BUNDLE) set(CMAKE_MACOSX_RPATH TRUE) endif() else() - set(CMAKE_INSTALL_RPATH "\${ORIGIN}/") + set(CMAKE_INSTALL_RPATH "\${ORIGIN}/") endif() set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) From 8677ec7cb0c7a995dbb484ff0f4b790ecdc24f18 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 01:35:38 -0400 Subject: [PATCH 122/147] remove unnecessary debug prints --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 2 +- src/applications/mne_scan/plugins/fieldline/fieldline.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index c66de9a6d78..46c2309669d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -199,7 +199,7 @@ bool Fieldline::stop() { //============================================================================================================= SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { - qDebug() << "getType Fieldline"; + // qDebug() << "getType Fieldline"; return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 4e8f717a185..b38fff67192 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -84,6 +84,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor Q_OBJECT Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "fieldline.json") Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + public: //========================================================================================================= // The plugin interface From 18643cc4e337ce17cdc44572e98fade5442b8a57 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 27 Apr 2023 10:30:27 -0400 Subject: [PATCH 123/147] debug crit error. set fieldline plugin offline --- src/applications/mne_scan/mne_scan/main.cpp | 4 ++-- src/applications/mne_scan/mne_scan/mainwindow.cpp | 6 ++++-- src/applications/mne_scan/plugins/CMakeLists.txt | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/main.cpp b/src/applications/mne_scan/mne_scan/main.cpp index b6ccfd2b646..15a30ae7862 100644 --- a/src/applications/mne_scan/mne_scan/main.cpp +++ b/src/applications/mne_scan/mne_scan/main.cpp @@ -92,7 +92,7 @@ Q_IMPORT_PLUGIN(NeuronalConnectivity) Q_IMPORT_PLUGIN(FtBuffer) Q_IMPORT_PLUGIN(WriteToFile) Q_IMPORT_PLUGIN(Hpi) -Q_IMPORT_PLUGIN(Fieldline) +// Q_IMPORT_PLUGIN(Fieldline) //Q_IMPORT_PLUGIN(DummyToolbox) #ifdef WITHGUSBAMP Q_IMPORT_PLUGIN(GUSBAmp) @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(averaging); Q_INIT_RESOURCE(writetofile); Q_INIT_RESOURCE(hpi); - Q_INIT_RESOURCE(fieldline); + // Q_INIT_RESOURCE(fieldline); #ifdef WITHBRAINAMP Q_INIT_RESOURCE(brainamp); #endif diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index f33b889e2bf..fcc98e12a09 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -811,8 +811,10 @@ void MainWindow::initMultiViewWidget(QListgetName() == "GUSBAmp"|| lPlugins.at(i)->getName() == "LSL Adapter"|| lPlugins.at(i)->getName() == "TMSI"|| - lPlugins.at(i)->getName() == "BrainAMP" || - lPlugins.at(i)->getName() == "Fieldline OPM") { + lPlugins.at(i)->getName() == "BrainAMP") { + // lPlugins.at(i)->getName() == "Fieldline OPM") { + // lPlugins.at(i)->getName() == "BrainAMP" || + // lPlugins.at(i)->getName() == "Fieldline OPM") { pMultiViewWinow = m_pMultiView->addWidgetBottom(pWidget, sCurPluginName); } else { pMultiViewWinow = m_pMultiView->addWidgetTop(pWidget, sCurPluginName); diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 6ed4201c835..5d9d490e866 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -18,7 +18,7 @@ add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) if (UNIX) - add_subdirectory(fieldline) +# add_subdirectory(fieldline) endif() # Algorithm Plugin From bd4d19d3f4413eb5e661c24960b7fc17691b5490 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 28 Apr 2023 10:06:09 -0400 Subject: [PATCH 124/147] fix findIp problems --- .../mne_scan/mne_scan/CMakeLists.txt | 32 ++++----- src/applications/mne_scan/mne_scan/main.cpp | 6 +- .../mne_scan/mne_scan/mainwindow.cpp | 26 ++++--- .../mne_scan/plugins/CMakeLists.txt | 4 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 63 +++++++---------- .../mne_scan/plugins/fieldline/fieldline.h | 9 ++- .../plugins/fieldline/fieldline_view.cpp | 57 +++++++++------- .../plugins/fieldline/fieldline_view.h | 14 ++-- .../fieldline/formfiles/fieldline_view.ui | 55 +++++++++------ .../mne_scan/plugins/fieldline/ipfinder.cpp | 68 ++++++++++--------- .../mne_scan/plugins/fieldline/ipfinder.h | 32 +++++++-- 11 files changed, 202 insertions(+), 164 deletions(-) diff --git a/src/applications/mne_scan/mne_scan/CMakeLists.txt b/src/applications/mne_scan/mne_scan/CMakeLists.txt index 959bc7cd5b6..03af1eaa54b 100644 --- a/src/applications/mne_scan/mne_scan/CMakeLists.txt +++ b/src/applications/mne_scan/mne_scan/CMakeLists.txt @@ -11,26 +11,26 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS}) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS}) set(SOURCES - main.cpp - mainsplashscreencloser.cpp - startupwidget.cpp - mainsplashscreen.cpp - pluginscene.cpp - pluginitem.cpp - plugingui.cpp - arrow.cpp + main.cpp + mainsplashscreencloser.cpp + startupwidget.cpp + mainsplashscreen.cpp + pluginscene.cpp + pluginitem.cpp + plugingui.cpp + arrow.cpp mainwindow.cpp ) set(HEADERS - info.h - mainsplashscreencloser.h - startupwidget.h - mainsplashscreen.h - pluginscene.h - pluginitem.h - plugingui.h - arrow.h + info.h + mainsplashscreencloser.h + startupwidget.h + mainsplashscreen.h + pluginscene.h + pluginitem.h + plugingui.h + arrow.h mainwindow.h ) diff --git a/src/applications/mne_scan/mne_scan/main.cpp b/src/applications/mne_scan/mne_scan/main.cpp index 15a30ae7862..930637301bf 100644 --- a/src/applications/mne_scan/mne_scan/main.cpp +++ b/src/applications/mne_scan/mne_scan/main.cpp @@ -92,8 +92,8 @@ Q_IMPORT_PLUGIN(NeuronalConnectivity) Q_IMPORT_PLUGIN(FtBuffer) Q_IMPORT_PLUGIN(WriteToFile) Q_IMPORT_PLUGIN(Hpi) -// Q_IMPORT_PLUGIN(Fieldline) -//Q_IMPORT_PLUGIN(DummyToolbox) +Q_IMPORT_PLUGIN(Fieldline) +// Q_IMPORT_PLUGIN(DummyToolbox) #ifdef WITHGUSBAMP Q_IMPORT_PLUGIN(GUSBAmp) #endif @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(averaging); Q_INIT_RESOURCE(writetofile); Q_INIT_RESOURCE(hpi); - // Q_INIT_RESOURCE(fieldline); + Q_INIT_RESOURCE(fieldline); #ifdef WITHBRAINAMP Q_INIT_RESOURCE(brainamp); #endif diff --git a/src/applications/mne_scan/mne_scan/mainwindow.cpp b/src/applications/mne_scan/mne_scan/mainwindow.cpp index fcc98e12a09..73afe8621ff 100644 --- a/src/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/src/applications/mne_scan/mne_scan/mainwindow.cpp @@ -801,20 +801,18 @@ void MainWindow::initMultiViewWidget(QListgetName() == "Filter" || - lPlugins.at(i)->getName() == "Fiff Simulator" || - lPlugins.at(i)->getName() == "FtBuffer" || - lPlugins.at(i)->getName() == "Natus" || - lPlugins.at(i)->getName() == "BabyMEG"|| - lPlugins.at(i)->getName() == "BrainFlow"|| - lPlugins.at(i)->getName() == "EEGoSports"|| - lPlugins.at(i)->getName() == "GUSBAmp"|| - lPlugins.at(i)->getName() == "LSL Adapter"|| - lPlugins.at(i)->getName() == "TMSI"|| - lPlugins.at(i)->getName() == "BrainAMP") { - // lPlugins.at(i)->getName() == "Fieldline OPM") { - // lPlugins.at(i)->getName() == "BrainAMP" || - // lPlugins.at(i)->getName() == "Fieldline OPM") { + if (lPlugins.at(i)->getName() == "Filter" || + lPlugins.at(i)->getName() == "Fiff Simulator" || + lPlugins.at(i)->getName() == "FtBuffer" || + lPlugins.at(i)->getName() == "Natus" || + lPlugins.at(i)->getName() == "BabyMEG" || + lPlugins.at(i)->getName() == "BrainFlow" || + lPlugins.at(i)->getName() == "EEGoSports" || + lPlugins.at(i)->getName() == "GUSBAmp" || + lPlugins.at(i)->getName() == "LSL Adapter" || + lPlugins.at(i)->getName() == "TMSI" || + lPlugins.at(i)->getName() == "BrainAMP" || + lPlugins.at(i)->getName() == "Fieldline OPM") { pMultiViewWinow = m_pMultiView->addWidgetBottom(pWidget, sCurPluginName); } else { pMultiViewWinow = m_pMultiView->addWidgetTop(pWidget, sCurPluginName); diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 5d9d490e866..d2e5556de28 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,8 +17,8 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) -if (UNIX) -# add_subdirectory(fieldline) +if(UNIX) + add_subdirectory(fieldline) endif() # Algorithm Plugin diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 46c2309669d..6ed78f0e682 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -129,8 +129,7 @@ namespace FIELDLINEPLUGIN { //============================================================================================================= Fieldline::Fieldline() -: acqSystem(nullptr), - guiWidget(nullptr) +: m_pAcqSystem(nullptr) { printLog("constructor fieldline plugin"); } @@ -162,44 +161,38 @@ void Fieldline::init() // "FieldlinePlguin output"); // m_outputConnectors.append(m_pRTMSA); - // acqSystem = new FieldlineAcqSystem(this); - // guiWidget = new FieldlineView(this); + m_pAcqSystem = new FieldlineAcqSystem(this); } //============================================================================================================= void Fieldline::unload() { - qDebug() << "unload Fieldline"; printLog("unload"); - // delete acqSystem; - // delete guiWidget; // deleted by Qt + delete m_pAcqSystem; } //============================================================================================================= bool Fieldline::start() { - qDebug() << "start Fieldline"; - std::cout.flush(); - + printLog("start Fieldline"); QThread::start(); - return true; } //============================================================================================================= bool Fieldline::stop() { + printLog("stop"); requestInterruption(); wait(500); - printLog("stop"); return true; } //============================================================================================================= SCSHAREDLIB::AbstractPlugin::PluginType Fieldline::getType() const { - // qDebug() << "getType Fieldline"; + printLog("getType Fieldline"); return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; } @@ -212,38 +205,33 @@ QString Fieldline::getName() const { //============================================================================================================= QWidget *Fieldline::setupWidget() { - printLog("setupWidget"); - // return guiWidget; - return new QLabel("hola!"); + return new FieldlineView(this); } //============================================================================================================= -void Fieldline::findIpAsync(const std::string mac, - std::function callback) { - // std::cout << "outside here! mac: " << mac << "\n"; - std::thread ipFinder([=]{ - IPFINDER::IpFinder ipFinder; - ipFinder.addMacAddress(mac); - // std::cout << "here inside!\n"; - // std::cout << "mac: " << mac << "\n"; - // std::cout.flush(); - ipFinder.findIps(); - if (ipFinder.macIpList.size() == 0) { - std::cout.flush(); - callback(ipFinder.macIpList[0].ip); - } else { - callback(std::string("Mac address not valid.")); - } - }); +void Fieldline::findIpAsync(std::vector& macList, + std::function&)> callback) { + std::thread ipFinder([macList, callback] { + IPFINDER::IpFinder ipFinder; + for (auto& mac : macList) { + ipFinder.addMacAddress(mac); + } + ipFinder.findIps(); + std::vector ipList; + ipList.reserve(ipFinder.macIpList.size()); + for (int i = 0; i < ipFinder.macIpList.size(); i++ ) { + ipList.emplace_back(ipFinder.macIpList[i].ip); + } + callback(ipList); + }); ipFinder.detach(); } //============================================================================================================= void Fieldline::run() { - qDebug() << "run Fieldline"; - std::cout.flush(); + printLog("run Fieldline"); } // while (true) { // if (QThread::isInterruptionRequested()) @@ -295,14 +283,13 @@ void Fieldline::run() { // // } // // } // // } - // qDebug() << "run Fieldline finished"; + // printLog("run Fieldline finished"); // } //============================================================================================================= QString Fieldline::getBuildInfo() { - qDebug() << "getBuildInfo Fieldline"; - std::cout.flush(); + printLog("getBuildInfo Fieldline"); return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index b38fff67192..1aa707e0660 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -72,6 +72,7 @@ namespace FIELDLINEPLUGIN { class FieldlineAcqSystem; class FieldlineView; +class IpFinder; //============================================================================================================ /** @@ -110,14 +111,12 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor virtual QString getBuildInfo(); - void findIpAsync(const std::string mac, - std::function callback); + void findIpAsync(std::vector& macList, + std::function&)> callback); protected: virtual void run(); - - FieldlineAcqSystem* acqSystem; - FieldlineView* guiWidget; + FieldlineAcqSystem* m_pAcqSystem; QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index c0dbedc22ba..afbaff2bd49 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -50,8 +50,6 @@ #include #include #include -#include -#include #include #include @@ -83,6 +81,8 @@ FieldlineView::FieldlineView(Fieldline *parent) m_pUi->setupUi(this); initTopMenu(); initAcqSystem(2); + connect(this, &FieldlineView::updateMacIpTable, + this, &FieldlineView::updateMacIpTableItem); } FieldlineView::~FieldlineView() @@ -102,30 +102,39 @@ void FieldlineView::initTopMenu() m_pMacIpTable->setColumnCount(2); m_pMacIpTable->setHorizontalHeaderLabels(QStringList({"Mac", "IP"})); + m_pMacIpTable->horizontalHeader()->setSortIndicatorShown(false); QVBoxLayout* macIpTableLayout = qobject_cast(m_pUi->ipMacFrame->layout()); macIpTableLayout->insertWidget(0, m_pMacIpTable); - QObject::connect(m_pMacIpTable, QOverload::of(&QTableWidget::cellDoubleClicked), - this, &FieldlineView::macIpTableDoubleClicked); + // QObject::connect(m_pMacIpTable, QOverload::of(&QTableWidget::cellDoubleClicked), + // this, &FieldlineView::macIpTableDoubleClicked); QObject::connect(m_pUi->numChassisSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &FieldlineView::setNumRowsIpMacFrame); + QObject::connect(m_pUi->findIPsBtn, &QPushButton::clicked, + this, &FieldlineView::findIps); + QObject::connect(m_pUi->connectBtn, &QPushButton::clicked, + this, &FieldlineView::connectToAcqSys); QObject::connect(m_pUi->disconnectBtn, &QPushButton::clicked, - this, &FieldlineView::disconnect); + this, &FieldlineView::disconnectFromAcqSys); } -void FieldlineView::macIpTableDoubleClicked(int row, int col) { - if ( col == 0 ) { - std::cout << "cell (" << row << "," << col << ") " - << " doubleclicked : " << m_pMacIpTable->item(row, col)->text().toStdString() << "\n"; - std::cout.flush(); - auto callback = [this, row, col](const std::string& str) { - std::cout << "inside callback! :" << str << " \n"; - m_pMacIpTable->item(row, col+1)->setText(str.c_str()); - m_pMacIpTable->repaint(); - }; - m_pFieldlinePlugin->findIpAsync(m_pMacIpTable->item(row, col)->text().toStdString(), callback); +void FieldlineView::findIps() { + std::vector macList; + macList.reserve(m_pMacIpTable->rowCount()); + for (int i = 0; i < m_pMacIpTable->rowCount(); i++) { + macList.emplace_back(m_pMacIpTable->item(i, 0)->text().toStdString()); } + auto callback = [this](std::vector& ipList) { + for (size_t i = 0; i < ipList.size(); i++ ) { + emit this->updateMacIpTable(i, 1, QString::fromStdString(ipList[i])); + } + }; + m_pFieldlinePlugin->findIpAsync(macList, callback); +} + +void FieldlineView::updateMacIpTableItem(int row, int col, const QString& str) { + m_pMacIpTable->item(row, col)->setText(str); } void FieldlineView::setNumRowsIpMacFrame(int numRows) @@ -139,7 +148,7 @@ void FieldlineView::setNumRowsIpMacFrame(int numRows) if (numRows > 0) { m_pMacIpTable->setSortingEnabled(false); - m_pMacIpTable->setItem(numRows-1, 0, new QTableWidgetItem("AF:70:04:21:2D:28")); + m_pMacIpTable->setItem(numRows-1, 0, new QTableWidgetItem("a0:b1:c2:d3:e4:f5")); m_pMacIpTable->setItem(numRows-1, 1, new QTableWidgetItem("0.0.0.0")); m_pMacIpTable->item(numRows-1, 0)->setToolTip((QString("Doubleclick to find the IP."))); m_pMacIpTable->setSortingEnabled(true); @@ -164,11 +173,12 @@ void FieldlineView::setNumRowsIpMacFrame(int numRows) // } } -void FieldlineView::disconnect() -{ - qDebug() << "Find chasssis!\n"; - std::cout.flush(); +void FieldlineView::connectToAcqSys() { + printLog("connect!\n"); +} +void FieldlineView::disconnectFromAcqSys() { + printLog("disconnect!\n"); //generate list of mac addresses //call class finder. // retrieve list of ips and set variable with it. @@ -207,13 +217,10 @@ void FieldlineView::initAcqSystem(int numChassis) { // QHBoxLayout* acqSystemTopBtnMenuLayout = qobject_cast(m_pUi->acqSystemTopButtonsFrame->layout()); initAcqSystemTopButtons(); - QVBoxLayout* acqSystemRackLayout = qobject_cast(m_pUi->chassisRackFrame->layout()); - - for( int i = 0; i < numChassis; i++ ) { + for (int i = 0; i < numChassis; i++) { FieldlineViewChassis* pChassis = new FieldlineViewChassis(this, i); acqSystemRackLayout->insertWidget(i, pChassis); - //lkajdsflkasjdf m_pAcqSystem.push_back(pChassis); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h index 8b2676a5b77..38b07476f77 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.h @@ -41,6 +41,7 @@ //============================================================================================================= #include +#include //============================================================================================================= // QT INCLUDES @@ -78,20 +79,25 @@ class FieldlineView : public QWidget { Q_OBJECT - public: +public: explicit FieldlineView(Fieldline* parent); ~FieldlineView(); + signals: + void updateMacIpTable(int row, int col, const QString& str); -private: + private: void initAcqSystem(int numChassis); void initTopMenu(); - void disconnect(); - void macIpTableDoubleClicked(int, int); + + void updateMacIpTableItem(int row, int col, const QString& str); void initAcqSystemCallbacks(); void initAcqSystemTopButtons(); void setNumRowsIpMacFrame(int i); + void findIps(); + void connectToAcqSys(); + void disconnectFromAcqSys(); void startAllSensors(); void stopAllSensors(); void autoTuneAllSensors(); diff --git a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui index 219bef14883..ac80fd1000f 100644 --- a/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui +++ b/src/applications/mne_scan/plugins/fieldline/formfiles/fieldline_view.ui @@ -131,6 +131,25 @@ QFrame::Plain + + + + + 0 + 0 + + + + + 140 + 16777215 + + + + Disconnect + + + @@ -144,18 +163,8 @@ - + - - - 50 - 16777215 - - - - - - 0 @@ -164,22 +173,28 @@ - 140 + 50 16777215 - - Disconnect + + false + + + Qt::AlignCenter + + + false + + + 12 - - + + - Number of Chassis - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Find IPs diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp index 5d37c107ca2..937c13876d3 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.cpp @@ -57,9 +57,17 @@ namespace IPFINDER { -const std::regex IP_REGEX("[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}"); -const char* default_table_file = "~/.ipfinder_171921"; -const int defaultNumRetriesMax = 3; +const char Defaults::regexIpStr[] = "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}"; +const char Defaults::regexMacStr[] = "[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}"; +const char Defaults::tableFile[] = ".ipfinder_171921"; +const char Defaults::pingCommand[] = "ping"; +const char Defaults::pingCommandOpts[] = " -c 1 -w 0.002"; +const char Defaults::deleteFileCommand[] = "rm -f"; +const int Defaults::numRetriesMax = 3; +const char Defaults::arpTableFilePrefix[] = ".ipfinder_"; +const char Defaults::randomCharset[] = "abcdefghijklmpqrstuvwxyz0123456789"; +const int Defaults::randomStringLength = 8; +const char Defaults::defaultIpStr[] = "0.0.0.0"; void printMacIpList(const std::vector& macIpList) { for (const MacIp& macip_i : macIpList) { @@ -70,14 +78,14 @@ void printMacIpList(const std::vector& macIpList) { } void sendPingsAroundNetwork() { - std::string appStr("ping"); - std::string appFlags("-c 1 -w 0.002"); + std::string appStr(Defaults::pingCommand); + std::string appFlags(Defaults::pingCommandOpts); std::vector threads; std::vector networks = getNetworksClassC(); for (auto& netw_i : networks) { for (auto& hostIp : netw_i.hostIPs) { - std::string commandStr = appStr + " " + appFlags + " " + hostIp + " &>/dev/null"; + std::string commandStr = appStr + appFlags + " " + hostIp + " &>/dev/null"; threads.emplace_back([=]{std::system(commandStr.c_str());}); } } @@ -86,37 +94,30 @@ void sendPingsAroundNetwork() { } } -void systemCalltoFile(const std::string& call, const std::string& filename) { +void systemCalltoFile(const std::string& call, const std::string& filename) { std::string callStr(call); callStr.append(" > ").append(filename); std::system(callStr.c_str()); } -void delete_file(const std::string& filename) { - std::string command("rm -f"); +void deleteFile(const std::string& filename) { + std::string command(Defaults::deleteFileCommand); std::system(command.append(" ").append(filename).c_str()); } IpFinder::IpFinder() - : numRetriesMax(defaultNumRetriesMax), + : numRetriesMax(Defaults::numRetriesMax), numRetries(0) -{ +{ arp_table_filename = generateRandomArpTableFileName(); } -//void IpFinder::addMacAddress(const std::string& mac) { -// std::smatch macParsed; -// if (std::regex_search(mac, macParsed, MAC_REGEX)) { -// macIpList.emplace_back(MacIp(macParsed[0],"")); -// } -//} - std::string IpFinder::generateRandomArpTableFileName() { - std::string newFileName(".ipfinder_"); - const std::string charset = "abcdefghijklmpqrstuvwxyz0123456789"; - const int strLen(8); + std::string newFileName(Defaults::arpTableFilePrefix); + const std::string charset(Defaults::randomCharset); + const int strLen(Defaults::randomStringLength); - for(int i =0; i < strLen; i++) { + for (int i = 0; i < strLen; i++) { int index = rand() % charset.length(); newFileName += charset[index]; } @@ -124,12 +125,12 @@ std::string IpFinder::generateRandomArpTableFileName() { } void IpFinder::addMacAddress(const std::string& mac) { - std::regex MAC_REGEX("[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}"); + std::regex macRegex(Defaults::regexMacStr); std::smatch macParsed; - auto bla = std::regex_search(mac, macParsed, MAC_REGEX); - if (bla) { + auto validMac = std::regex_search(mac, macParsed, macRegex); + if (validMac) { if (macParsed.size() > 0) { - macIpList.emplace_back(MacIp(macParsed[0],"0.0.0.0")); + macIpList.emplace_back(MacIp(macParsed[0], "0.0.0.0", false)); } else { std::cerr << "Error: no matches found for MAC address " << mac << std::endl; } @@ -154,7 +155,8 @@ void IpFinder::findIpsInARPTable() { std::cout << "Error: Unable to open arp file table.\n"; std::cout.flush(); return; - } + } + std::string line; for (MacIp& macip_i : macIpList) { while (std::getline(fp, line)) { @@ -162,24 +164,26 @@ void IpFinder::findIpsInARPTable() { std::regex mac_i(macip_i.mac); if (std::regex_search(line, mac_found, mac_i)) { std::smatch ip_found; - if (std::regex_search(line, ip_found, IP_REGEX)) { + std::regex regexIP(Defaults::regexIpStr); + if (std::regex_search(line, ip_found, regexIP)) { macip_i.ip = ip_found[0]; + macip_i.valid = true; } } } } fp.close(); - delete_file(arp_table_filename); + deleteFile(arp_table_filename); } bool IpFinder::allIpsFound() const { - for (const MacIp& macip_i: macIpList) { - if (macip_i.ip.empty()) { + for (const MacIp& macip_i : macIpList) { + if (macip_i.valid) { return false; } } return true; } -} // namepsace IPFINDER +} // namespace IPFINDER diff --git a/src/applications/mne_scan/plugins/fieldline/ipfinder.h b/src/applications/mne_scan/plugins/fieldline/ipfinder.h index 31a885039a6..d32aa14835f 100644 --- a/src/applications/mne_scan/plugins/fieldline/ipfinder.h +++ b/src/applications/mne_scan/plugins/fieldline/ipfinder.h @@ -41,16 +41,37 @@ #include #include +#include namespace IPFINDER { -struct MacIp { +struct MacIp +{ MacIp(const std::string& mac_, - const std::string& ip_) - : mac(mac_), ip(ip_) + const std::string& ip_, + bool value) + : mac(mac_), ip(ip_), valid(value) + {}; + MacIp() + : mac(""), ip(""), valid(false) {}; std::string mac; std::string ip; + bool valid; +}; + +struct Defaults { + static const char regexIpStr[]; + static const char regexMacStr[]; + static const char tableFile[]; + static const char pingCommand[]; + static const char pingCommandOpts[]; + static const char deleteFileCommand[]; + static const int numRetriesMax; + static const char arpTableFilePrefix[]; + static const char randomCharset[]; + static const int randomStringLength; + static const char defaultIpStr[]; }; void printMacIpList(const std::vector& macIpList); @@ -60,7 +81,7 @@ void sendPingsAroundNetwork(); void systemCalltoFile(const std::string& call, const std::string& filename); -void delete_file(const std::string& filename); +void deleteFile(const std::string& filename); class IpFinder { public: @@ -70,6 +91,7 @@ class IpFinder { bool allIpsFound() const; std::vector macIpList; + private: std::string generateRandomArpTableFileName(); std::string arp_table_filename; @@ -78,7 +100,7 @@ class IpFinder { int numRetries; }; -} // namespace IpFinder +} // namespace IPFINDER From 81724126c066cba65a69fea115f31196a15242a9 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Sat, 29 Apr 2023 00:17:09 -0400 Subject: [PATCH 125/147] finish fieldline mock api --- .../fieldline_api_mock/fieldline_service.py | 275 +++++++++++------- resources/mne_scan/plugins/fieldline/main.py | 15 +- .../plugins/fieldline/fieldline_view.cpp | 20 +- 3 files changed, 177 insertions(+), 133 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index d2261fa144a..382f43e8cb2 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -2,61 +2,40 @@ import time import random - -def generate_data(): - timestamp = 179331926 - num_sensors_per_chassis = 16 - num_chassis = 2 - - data_frames = {} - - data_values = [91599] + \ - [round(random.normalvariate(0, 1000)) - for _ in range(1, num_sensors_per_chassis * num_chassis + 1)] - - chassis_labels = [0] + [num for num in range(0, num_chassis) for _ in range(num_sensors_per_chassis)] - sensor_labels = [0] + (list(range(1, num_sensors_per_chassis + 1))) * num_chassis - data_type_labels = [0] + ([50] * num_sensors_per_chassis * num_chassis) - global_labels = [f'{chassis_label:02}:{sensor_label:02}:{data_type:02}' - for chassis_label, sensor_label, data_type in zip(chassis_labels, sensor_labels, data_type_labels)] - - for global_l, data_i, sensor_l, chassis_l, data_type_l in \ - zip(global_labels, data_values, sensor_labels, chassis_labels, data_type_labels): - data_frames[global_l] = \ - {'data': data_i, 'sensor': f'{chassis_l:02}:{sensor_l:02}', 'sensor_id': sensor_l, 'data_type': data_type_l} - - - # data_frames = [] - return {'timestamp': timestamp, 'data_frames': data_frames} - - class FieldLineService: + class SensorApi: + def __init__(self): + self.sleep_mean = 1 + self.sleep_var = .2 + self.prob_success = 0.9 + def __init__(self, ip_list, prefix=""): """ callback - required callback class should be of type FieldLineCallback """ - self.counter_lock = 0 - self.hardware_state = 0 print("Initializing FieldLine Service") - self.prefix = "prefix" - self.data_source = None - # interfaces = netifaces.interfaces() - self.network_interfaces = [] + self.is_open = False + + self.num_sensors_per_chassis = 16 + self.num_chassis = 2 + self.ip_list = ip_list + self.num_chassis = len(self.ip_list) + # print("IP list: " + str(self.ip_list)) + + self.sensors = {i: list(range(1, self.num_sensors_per_chassis + 1)) for i in range(0, self.num_chassis) } + self.sensor_api = self.SensorApi() + + self.data_random_mean = 0 + self.data_random_var = 1000 + self.sampling_frequency = 1000 + self.callback_function = self.callback_function_default self.continue_data_acquisition = False - self.data_acquisition_thread = None - # for i in interfaces: - # print("interface %s" % i) - # if i.startswith('lo'): - # continue - # iface = netifaces.ifaddresses(i).get(netifaces.AF_INET) - # if iface is not None: - # for j in iface: - # ip_addr = j['addr'] - # print("address %s" % ip_addr) - # self.network_interfaces.append(ip_addr) - # print("network interfaces: %s" % self.network_interfaces) + self.data_acquisition_thread = threading.Thread(target=self.data_acquisition) + + def callback_function_default(self, _): + pass def __enter__(self): self.open() @@ -66,65 +45,121 @@ def __exit__(self, exc_type, exc_value, traceback): self.close() def open(self): - print("connecting to devices in ip_list: " + str(self.ip_list)) - print("connecting to devices") - print("start monitor") - print("start data source") + self.is_open = True + print("FieldLineService Open") + print("Connecting to devices in ip_list: " + str(self.ip_list)) def close(self): - print("data source shut down") + self.is_open = False + print("FieldLineService Close.") + print("Disconnecting.") def load_sensors(self): - print("loading sensors") - # return self.data_source.load_sensors() - self.list_of_sensors = {i: list(range(1, 16 + 1)) for i in range(0, 1 + 1)} - - return self.list_of_sensors + if self.is_open: + print("Loading sensors.") + return self.sensors + else: + print("Fieldline service closed.") def get_chassis_list(self): - print("get chassis list") - # return self.data_source.get_chassis_list() + if self.is_open: + print("Get chassis list") + return list(range(0, len(self.ip_list))) + else: + print("Fieldline service closed.") + return None + + def generate_data(self): + timestamp = int(time.time()) + + data_frames = {} + + num_sensors = sum(len(sensor_list) for sensor_list in self.sensors.values()) + + data_values = [91599] + [round(random.normalvariate(self.data_random_mean, self.data_random_var)) + for _ in range(1, num_sensors + 1)] + + chassis_labels = [0] + [chassis for chassis, sensors in self.sensors.items() for _ in sensors] + sensor_labels = [0] + [sensor for sensor_list in self.sensors.values() for sensor in sensor_list] + + data_type_labels = [0] + ([50] * num_sensors) + global_labels = [f'{chassis_label:02}:{sensor_label:02}:{data_type:02}' + for chassis_label, sensor_label, data_type in zip(chassis_labels, sensor_labels, data_type_labels)] + + for global_l, data_i, sensor_l, chassis_l, data_type_l in \ + zip(global_labels, data_values, sensor_labels, chassis_labels, data_type_labels): + data_frames[global_l] = \ + {'data': data_i, 'sensor': f'{chassis_l:02}:{sensor_l:02}', 'sensor_id': sensor_l, 'data_type': data_type_l} + + return {'timestamp': timestamp, 'data_frames': data_frames} def data_acquisition(self): - + sampling_period = 1/self.sampling_frequency + start_time = time.time() - data = generate_data() + data = self.generate_data() end_time = time.time() elapsed_time = end_time - start_time - time.sleep(0.001 - elapsed_time) + time.sleep(sampling_period - elapsed_time) end_time = time.time() elapsed_time = end_time - start_time - elapsed_time_diff = (0.001 - elapsed_time) + elapsed_time_diff = (sampling_period - elapsed_time) while(self.continue_data_acquisition): start_time = time.time() - data = generate_data() + data = self.generate_data() self.callback_function(data) end_time = time.time() elapsed_time = end_time - start_time # time_to_sleep = max(0, .001 - elapsed_time) - time.sleep(0.001 + elapsed_time_diff - 0.5 * elapsed_time) + time.sleep(sampling_period + elapsed_time_diff - 0.6 * elapsed_time) # print(f"elapsed_time: {elapsed_time:04}") + # start_time = time.time() + # end_time = time.time() + # time_meas = end_time - start_time + # + # start_time = time.time() + # data = self.generate_data() + # self.callback_function(data) + # time.sleep(sampling_period) + # end_time = time.time() + # + # time_diff = end_time - start_time - sampling_period - time_meas + # time_to_sleep_adjusted = sampling_period - 1.5 * time_diff + # time_to_sleep_final = 0 if time_to_sleep_adjusted < 0 else time_to_sleep_adjusted + # print(time_to_sleep_final) + # + # while(self.continue_data_acquisition): + # data = self.generate_data() + # self.callback_function(data) + # time.sleep(time_to_sleep_final) def read_data(self, data_callback=None): - if(data_callback is not None): - print(f"read_data defined. Callback set to : {data_callback.__name__}") - self.callback_function = data_callback - # self.data_source.read_data(data_callback=data_callback) - - - def start_adc(self, chassis_id): + if self.is_open: + if(data_callback is not None): + self.callback_function = data_callback + print(f"Data callback set to: {data_callback.__name__}.") + else: + self.callback_function = self.callback_function_default + print(f'Data callback disabled.') + else: + print("Fieldline service closed.") + return None + + def start_adc(self, _): """ Start ADC from chassis chassis_id - unique ID of chassis """ - print("start adc") - self.continue_data_acquisition = True - self.data_acquisition_thread = threading.Thread(target=self.data_acquisition) - self.data_acquisition_thread.start() - # self.data_source.start_adc(chassis_id) + if self.is_open: + self.continue_data_acquisition = True + self.data_acquisition_thread.start() + print("Starting data acquisition.") + else: + print("Fieldline service closed.") + return None def stop_adc(self, chassis_id): """ @@ -132,10 +167,17 @@ def stop_adc(self, chassis_id): chassis_id - unique ID of chassis """ - print("stop adc") - self.continue_data_acquisition = False - self.data_acquisition_thread.join(timeout=5) - # self.data_source.stop_adc(chassis_id) + if self.is_open: + self.continue_data_acquisition = False + if self.data_acquisition_thread.is_alive(): + self.data_acquisition_thread.join(timeout=5) + print("Stopping data acquisition.") + else: + print("Data acquisition running.") + else: + print("Fieldline service closed.") + return None + def turn_off_sensors(self, sensor_dict): """ @@ -144,8 +186,35 @@ def turn_off_sensors(self, sensor_dict): sensor_dict - dictionary of chassis id to list of sensors ex. {0: [0,1], 1:[0,1]} """ - print("turn off sensors") - # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_OFF) + print("Turning off sensors.") + + def sensors_api(self, sensor_dict, on_next=None, on_error=None, on_completed=None): + def sensor_thread(chassis_id: int, sensor_id: int): + sleep_time = random.normalvariate(self.sensor_api.sleep_mean, self.sensor_api.sleep_var) + if sleep_time <= 0: + sleep_time = 0.1 + time.sleep(sleep_time) + result = random.random() + if result <= self.sensor_api.prob_success: + if on_next: + on_next(chassis_id, sensor_id) + else: + codes = [117, 31337, 2626] + if on_error: + on_error(chassis_id, sensor_id, random.choice(codes)) + + threads = [] + for chassis_id, sensor_ids in sensor_dict.items(): + for sensor_id in sensor_ids: + t = threading.Thread(target=sensor_thread, args=(chassis_id, sensor_id)) + t.start() + threads.append(t) + + for t in threads: + t.join() + + if on_completed: + on_completed() def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): """ @@ -157,11 +226,9 @@ def restart_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed on_error - callback when sensor fails a step on_completed - callback when all sensors have either succeeded or failed """ - print("restart sensors") - time.sleep(.3) - on_completed() - # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_RESTART) + print("Restarting sensors.") + self.sensors_api(sensor_dict, on_next, on_error, on_completed) + def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): """ @@ -174,10 +241,7 @@ def coarse_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_compl on_completed - callback when all sensors have either succeeded or failed """ print("coarse zero sensor") - time.sleep(.3) - on_completed() - # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_COARSE_ZERO) + self.sensors_api(sensor_dict, on_next, on_error, on_completed) def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_completed=None): """ @@ -190,21 +254,20 @@ def fine_zero_sensors(self, sensor_dict, on_next=None, on_error=None, on_complet on_completed - callback when all sensors have either succeeded or failed """ print("fine zero sensors") - time.sleep(.3) - on_completed() - # self.data_source.set_callbacks(on_next=on_next, on_error=on_error, on_completed=on_completed) - # self.data_source.send_logic_command(sensor_dict, proto.LogicMessage.LOGIC_SENSOR_FINE_ZERO) - - # def set_bz_wave(self, chassis_id, sensor_id, wave_type, freq=None, amplitude=None): - # """ - # Apply a known magnetic field to the BZ coil (e.g. sine wave) - # - # chassis_id - unique ID of chassis - # sensor_id - unique ID of sensor - # wave_type - FieldLineWaveType (WAVE_OFF, WAVE_RAMP, WAVE_SINE) - # freq - frequency of wave - # amplitude - amplitude of wave (nT) - # """ + self.sensors_api(sensor_dict, on_next, on_error, on_completed) + + def set_bz_wave(self, chassis_id, sensor_id, wave_type, freq=None, amplitude=None): + """ + Apply a known magnetic field to the BZ coil (e.g. sine wave) + + chassis_id - unique ID of chassis + sensor_id - unique ID of sensor + wave_type - FieldLineWaveType (WAVE_OFF, WAVE_RAMP, WAVE_SINE) + freq - frequency of wave + amplitude - amplitude of wave (nT) + """ + print('Setting bz wave') + print('UuuUUUuuuuu...') # # if wave_type == FieldLineWaveType.WAVE_OFF: # self.data_source.set_wave_off(chassis_id, sensor_id) diff --git a/resources/mne_scan/plugins/fieldline/main.py b/resources/mne_scan/plugins/fieldline/main.py index 28af104446c..cef2a2ea39a 100644 --- a/resources/mne_scan/plugins/fieldline/main.py +++ b/resources/mne_scan/plugins/fieldline/main.py @@ -1,6 +1,6 @@ """This is my super module""" import sys -from fieldline_api_mock.fieldline_service import FieldLineService +from fieldline_api_mock.fieldline_service import FieldLineService import time for path in sys.path: @@ -12,17 +12,4 @@ ip_list = ["8.8.8.8", "9.9.9.9"] -# fl = FieldLineService(["8.8.8.8", "9.9.9.9"]) -# with FieldLineService(ip_list) as service: -# done = False -# # Get dict of all the sensors -# sensors = service.load_sensors() -# print(f"Got sensors: {sensors}") -# # Make sure closed loop is set -# service.set_closed_loop(True) -# print("Doing sensor restart") -# # Do the restart -# service.restart_sensors(sensors, on_next=lambda c_id, s_id: print(f'sensor {c_id}:{s_id} finished restart'), on_error=lambda c_id, s_id, err: print(f'sensor {c_id}:{s_id} failed with {hex(err)}'), on_completed=lambda: call_done()) -# while not done: -# time.sleep(0.5) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index afbaff2bd49..c41c929a9bf 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -33,15 +33,6 @@ * */ -//============================================================================================================= -// INCLUDES -//============================================================================================================= - -#include "fieldline/fieldline.h" -#include "fieldline/fieldline_view.h" -#include "fieldline/fieldline_view_chassis.h" -#include "formfiles/ui_fieldline_view.h" - //============================================================================================================= // QT INCLUDES //============================================================================================================= @@ -60,9 +51,14 @@ //============================================================================================================= //============================================================================================================= -// USED NAMESPACES +// INCLUDES //============================================================================================================= +#include "fieldline/fieldline.h" +#include "fieldline/fieldline_view.h" +#include "fieldline/fieldline_view_chassis.h" +#include "formfiles/ui_fieldline_view.h" + //============================================================================================================= // DEFINE STATIC METHODS //============================================================================================================= @@ -107,8 +103,6 @@ void FieldlineView::initTopMenu() QVBoxLayout* macIpTableLayout = qobject_cast(m_pUi->ipMacFrame->layout()); macIpTableLayout->insertWidget(0, m_pMacIpTable); - // QObject::connect(m_pMacIpTable, QOverload::of(&QTableWidget::cellDoubleClicked), - // this, &FieldlineView::macIpTableDoubleClicked); QObject::connect(m_pUi->numChassisSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &FieldlineView::setNumRowsIpMacFrame); QObject::connect(m_pUi->findIPsBtn, &QPushButton::clicked, @@ -126,7 +120,7 @@ void FieldlineView::findIps() { macList.emplace_back(m_pMacIpTable->item(i, 0)->text().toStdString()); } auto callback = [this](std::vector& ipList) { - for (size_t i = 0; i < ipList.size(); i++ ) { + for (size_t i = 0; i < ipList.size(); i++) { emit this->updateMacIpTable(i, 1, QString::fromStdString(ipList[i])); } }; From 76af775908ffb4b70f1f4acec173ae88e1bac954 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Mon, 1 May 2023 09:58:19 -0400 Subject: [PATCH 126/147] delete debugs prints from acq system class --- .../plugins/fieldline/fieldline_acqsystem.cpp | 14 ++------------ .../plugins/fieldline/fieldline_view_sensor.cpp | 1 - 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 02103c1792f..2984688ebcb 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -106,10 +106,7 @@ // return PyModule_Create(&my_module_def); //} -// using FIELDLINEPLUGIN; -// using FIELDLINEPLUGIN::FieldlineAcqSystem; namespace FIELDLINEPLUGIN { -// using FIELDLINEPLUGIN::Fieldline; const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); @@ -117,20 +114,19 @@ const std::string entryFile(resourcesPath + "main.py"); FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { + Py_Initialize(); preConfigurePython(); runPythonFile(entryFile.c_str(), "main.py"); - // std::cout << "addr: " << m_pControllerParent << "\n"; } FieldlineAcqSystem::~FieldlineAcqSystem() { - qDebug() << "About to finalize python"; + printLog("About to finalize python"); Py_Finalize(); } void FieldlineAcqSystem::preConfigurePython() const { - Py_Initialize(); PyObject* sys = PyImport_ImportModule("sys"); PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); @@ -152,18 +148,12 @@ void FieldlineAcqSystem::preConfigurePython() const void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { - std::cout << "we're up here!\n"; - std::cout.flush(); FILE *py_file = fopen(file, "r"); if (py_file) { - std::cout << "we're here!\n"; - std::cout.flush(); PyObject* global_dict = PyDict_New(); PyObject* local_dict = PyDict_New(); PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); - std::cout << "we're down here!\n"; - std::cout.flush(); Py_DECREF(global_dict); Py_DECREF(local_dict); Py_DECREF(result); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp index 40a0dbfd485..fc7f9d5b01f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view_sensor.cpp @@ -113,7 +113,6 @@ void FieldlineViewSensor::resizeEvent(QResizeEvent *event) auto bounds = m_pScene->itemsBoundingRect(); bounds.setWidth(bounds.width() * 1.2); bounds.setHeight(bounds.height() * 1.2); - std::cout << "Resize: " << bounds.width() << " , " << bounds.height() << "\n"; std::cout.flush(); m_pUi->ledQGraphView->fitInView(bounds, Qt::KeepAspectRatio); QWidget::resizeEvent(event); From e0f16b0722d0d2c2a49193cb6d11819435a70a8c Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Mon, 1 May 2023 20:42:48 -0400 Subject: [PATCH 127/147] add simple python interaction --- .../mne_scan/plugins/fieldline/callback.py | 55 ++++++++++++++ .../mne_scan/plugins/fieldline/fieldline.cpp | 3 +- .../mne_scan/plugins/fieldline/fieldline.h | 3 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 71 +++++++++++++++++-- .../plugins/fieldline/fieldline_acqsystem.h | 9 ++- .../plugins/fieldline/fieldline_view.cpp | 21 +++--- 6 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 resources/mne_scan/plugins/fieldline/callback.py diff --git a/resources/mne_scan/plugins/fieldline/callback.py b/resources/mne_scan/plugins/fieldline/callback.py new file mode 100644 index 00000000000..78ae0282440 --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/callback.py @@ -0,0 +1,55 @@ +import sys +import time +import threading + +time_to_sleep = 0.5 +keep_running = True + + +# default callback function that prints its name +def default_callback1(): + print("... default_callback") + sys.stdout.flush() + +def default_callback2(): + with open("output.txt", "a") as f: + f.write("default_callback2\n") + + +callback = default_callback1 + + +# function to set the callback +def set_callback(new_callback=None): + global callback + if new_callback is None: + callback = default_callback2 + else: + callback = new_callback + + +# function to call the callback every second +def run(): + global keep_running + global time_to_sleep + keep_running = True + while keep_running: + callback() + time.sleep(time_to_sleep) + + +# function to stop the callback loop +def stop(): + global keep_running + keep_running = False + + +def start(): + t = threading.Thread(target=run) + t.start() + + + +# if __name__ == '__main__': +# pass +# diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 6ed78f0e682..e8c4fb589a5 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -42,6 +42,7 @@ // INCLUDES //============================================================================================================= #include +#include #include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" @@ -220,7 +221,7 @@ void Fieldline::findIpAsync(std::vector& macList, ipFinder.findIps(); std::vector ipList; ipList.reserve(ipFinder.macIpList.size()); - for (int i = 0; i < ipFinder.macIpList.size(); i++ ) { + for (size_t i = 0; i < ipFinder.macIpList.size(); i++) { ipList.emplace_back(ipFinder.macIpList[i].ip); } callback(ipList); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 1aa707e0660..2ac135a0b77 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -113,10 +113,11 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor void findIpAsync(std::vector& macList, std::function&)> callback); + FieldlineAcqSystem* m_pAcqSystem; + protected: virtual void run(); - FieldlineAcqSystem* m_pAcqSystem; QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 2984688ebcb..b870de8827d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -108,15 +108,19 @@ namespace FIELDLINEPLUGIN { -const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); +const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { - Py_Initialize(); + Py_InitializeEx(0); + PyEval_InitThreads(); + preConfigurePython(); - runPythonFile(entryFile.c_str(), "main.py"); + // runPythonFile(entryFile.c_str(), "main.py"); + // loadPythonModule("callback"); } FieldlineAcqSystem::~FieldlineAcqSystem() @@ -125,6 +129,59 @@ FieldlineAcqSystem::~FieldlineAcqSystem() Py_Finalize(); } +void FieldlineAcqSystem::loadPythonModule(const char* moduleName) +{ + // Import the callback_module Python module + PyObject* pModule = PyImport_ImportModule(moduleName); + if (pModule == NULL) { + printLog(std::string("Error importing: ").append(moduleName).c_str()); + PyErr_Print(); + } +} + +void FieldlineAcqSystem::callFunction(const char* moduleName, const char* funcName) +{ + if (!Py_IsInitialized()) { + Py_Initialize(); + } + // Py_BEGIN_ALLOW_THREADS + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject* pModule = PyImport_ImportModule(moduleName); + if (pModule == NULL) { + printLog(std::string("Error importing module: ").append(funcName)); + PyErr_Print(); + } + + // Get a reference to the start function + PyObject* pStartFunc = PyObject_GetAttrString(pModule, funcName); + if (pStartFunc == NULL) { + printLog(std::string("Error finding function: ").append(funcName).c_str()); + PyErr_Print(); + Py_DECREF(pModule); + } + + // Call the start function + PyObject* pResult = PyObject_CallObject(pStartFunc, NULL); + if (pResult == NULL) { + printLog(std::string("Error calling function: ").append(funcName).c_str()); + PyErr_Print(); + Py_DECREF(pModule); + Py_DECREF(pStartFunc); + } + + Py_DECREF(pModule); + Py_DECREF(pStartFunc); + Py_DECREF(pResult); + + PyGILState_Release(gstate); + if (Py_IsInitialized()) { + Py_Finalize(); // Py_END_ALLOW_THREADS + } +} + + void FieldlineAcqSystem::preConfigurePython() const { PyObject* sys = PyImport_ImportModule("sys"); @@ -138,18 +195,18 @@ void FieldlineAcqSystem::preConfigurePython() const Py_DECREF(versionInfo); PyObject* path = PyObject_GetAttrString(sys, "path"); + PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); + Py_DECREF(sys); const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); - PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); PyList_Insert(path, 1, PyUnicode_FromString(pathVenvMods.c_str())); - Py_DECREF(sys); Py_DECREF(path); } -void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const +void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { FILE *py_file = fopen(file, "r"); - if (py_file) + if (py_file) { PyObject* global_dict = PyDict_New(); PyObject* local_dict = PyDict_New(); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 8c91ec5331f..4927efe8bb8 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -47,11 +47,14 @@ class FieldlineAcqSystem { ~FieldlineAcqSystem(); + void callFunction(const char* moduleName, const char* funcName); + private: - void preConfigurePython() const; - void runPythonFile(const char* file, const char* comment) const; + void preConfigurePython() const; + void runPythonFile(const char* file, const char* comment) const; + void loadPythonModule(const char* moduleName); - Fieldline* m_pControllerParent; + Fieldline* m_pControllerParent; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index c41c929a9bf..add2f14913f 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -57,6 +57,7 @@ #include "fieldline/fieldline.h" #include "fieldline/fieldline_view.h" #include "fieldline/fieldline_view_chassis.h" +#include "fieldline/fieldline_acqsystem.h" #include "formfiles/ui_fieldline_view.h" //============================================================================================================= @@ -231,33 +232,29 @@ void FieldlineView::initAcqSystem(int numChassis) // } void FieldlineView::startAllSensors() { - std::cout << "startAllSensors" << "\n"; - std::cout.flush(); + printLog("startAllSensors"); + m_pFieldlinePlugin->m_pAcqSystem->callFunction("callback", "start"); } void FieldlineView::stopAllSensors() { - std::cout << "stopAllSensors" << "\n"; - std::cout.flush(); + printLog("stopAllSensors"); + m_pFieldlinePlugin->m_pAcqSystem->callFunction("callback", "stop"); } void FieldlineView::autoTuneAllSensors() { - std::cout << "autoTuneAllSensors" << "\n"; - std::cout.flush(); + printLog("autoTuneAllSensors"); } void FieldlineView::restartAllSensors() { - std::cout << "restartAllSensors" << "\n"; - std::cout.flush(); + printLog("restartAllSensors"); } void FieldlineView::coarseZeroAllSensors() { - std::cout << "coarseZeroAllSensors" << "\n"; - std::cout.flush(); + printLog("coarseZeroAllSensors"); } void FieldlineView::fineZeroAllSensors() { - std::cout << "fineZeroAllSensors" << "\n"; - std::cout.flush(); + printLog("fineZeroAllSensors"); } From 50220526d27708062ab210648829927897920948 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Tue, 2 May 2023 16:27:07 -0400 Subject: [PATCH 128/147] python cpp interaction cranking up --- .../mne_scan/plugins/fieldline/callback.py | 15 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 1 + .../plugins/fieldline/fieldline_acqsystem.cpp | 145 +++++++++++++++--- .../plugins/fieldline/fieldline_acqsystem.h | 15 +- .../plugins/fieldline/fieldline_view.cpp | 7 +- 5 files changed, 150 insertions(+), 33 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/callback.py b/resources/mne_scan/plugins/fieldline/callback.py index 78ae0282440..512bcc71d07 100644 --- a/resources/mne_scan/plugins/fieldline/callback.py +++ b/resources/mne_scan/plugins/fieldline/callback.py @@ -1,15 +1,17 @@ -import sys import time import threading time_to_sleep = 0.5 keep_running = True +counter = 0 # default callback function that prints its name def default_callback1(): - print("... default_callback") - sys.stdout.flush() + # print("... default_callback") + global counter + print(f'Counter: {counter}') + counter += 1 def default_callback2(): with open("output.txt", "a") as f: @@ -23,8 +25,10 @@ def default_callback2(): def set_callback(new_callback=None): global callback if new_callback is None: + print('Setting the default callback.') callback = default_callback2 else: + print('Setting new callback.') callback = new_callback @@ -32,6 +36,7 @@ def set_callback(new_callback=None): def run(): global keep_running global time_to_sleep + global counter keep_running = True while keep_running: callback() @@ -41,7 +46,9 @@ def run(): # function to stop the callback loop def stop(): global keep_running + global counter keep_running = False + print(f'Global counter: {counter}') def start(): @@ -49,7 +56,7 @@ def start(): t.start() - # if __name__ == '__main__': # pass # + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index e8c4fb589a5..ffca27ddfe5 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -43,6 +43,7 @@ //============================================================================================================= #include #include +#include #include "fieldline/fieldline.h" #include "fieldline/fieldline_acqsystem.h" diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index b870de8827d..bddeb06d904 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include @@ -112,24 +114,115 @@ const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdStri "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); + +void callback1() { + printLog("This is callback1."); + +} + +static PyObject* callback1_py(PyObject* self, PyObject* args) { + callback1(); + return Py_None; +} + +static struct PyMethodDef callbacksMethods[] = { + {"callback1", callback1_py, METH_VARARGS, "Call to callback1"}, + {NULL, NULL, 0, NULL} +}; + +static PyModuleDef CallModule = { + PyModuleDef_HEAD_INIT, "calls", NULL, -1, callbacksMethods, + NULL, NULL, NULL, NULL +}; + +static PyObject* PyInit_calls(void) { + return PyModule_Create(&CallModule); +} + + + + + + + + + + FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { - Py_InitializeEx(0); - PyEval_InitThreads(); + Py_Initialize(); preConfigurePython(); // runPythonFile(entryFile.c_str(), "main.py"); - // loadPythonModule("callback"); + m_pCallbackModule = (void*)loadPythonModule("callback"); + + if (Py_IsInitialized()) { + PyImport_AddModule("calls"); + PyObject* pyModule = PyInit_calls(); + PyObject* sys_modules = PyImport_GetModuleDict(); + PyDict_SetItemString(sys_modules, "calls", pyModule); + Py_DECREF(pyModule); + } + + m_pCallsModule = (void*)loadPythonModule("calls"); + + m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() { + PyEval_RestoreThread((PyThreadState*)m_pThreadState); printLog("About to finalize python"); + Py_DECREF(m_pCallbackModule); + Py_DECREF(m_pCallsModule); Py_Finalize(); } -void FieldlineAcqSystem::loadPythonModule(const char* moduleName) +void FieldlineAcqSystem::setCallback() +{ + + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject *pSetCallbackFunc = NULL; + PyObject *pCallback1 = NULL; + PyObject *pArgs = NULL; + PyObject *pResult = NULL; + + // Get a reference to the function + pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); + if (pSetCallbackFunc == NULL) { + printLog(std::string("Error finding function: ").append("set_callback").c_str()); + PyErr_Print(); + } + + printLog("I'm here!!!!!"); + pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); + if (pCallback1 && PyCallable_Check(pCallback1)) { + pArgs = PyTuple_New(1); + PyTuple_SetItem(pArgs, 0, pCallback1); + } + else { + if (PyErr_Occurred()) + PyErr_Print(); + printLog(std::string("Cannot find function callback1 in calls module.")); + } + // Call the set_callback function + pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); + if (pResult == NULL) { + printLog(std::string("Error calling function: ").append("set_callback").c_str()); + PyErr_Print(); + } + Py_XDECREF(pSetCallbackFunc); + Py_XDECREF(pCallback1); + Py_XDECREF(pArgs); + Py_XDECREF(pResult); + + PyGILState_Release(gstate); +} + +void* FieldlineAcqSystem::loadPythonModule(const char* moduleName) { // Import the callback_module Python module PyObject* pModule = PyImport_ImportModule(moduleName); @@ -137,29 +230,41 @@ void FieldlineAcqSystem::loadPythonModule(const char* moduleName) printLog(std::string("Error importing: ").append(moduleName).c_str()); PyErr_Print(); } + return (void*)pModule; } -void FieldlineAcqSystem::callFunction(const char* moduleName, const char* funcName) + +void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* funcName) +{ + printLog("Right before spawning threads!"); + auto lambda = [this, moduleName, funcName]() { + printLog("in the thread!"); + printLog(std::string("Module name: ").append(moduleName)); + printLog(std::string("Func name: ").append(funcName)); + this->callFunction(moduleName, funcName); + }; + std::thread t(lambda); + t.detach(); +} + +void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::string funcName) { - if (!Py_IsInitialized()) { - Py_Initialize(); - } - // Py_BEGIN_ALLOW_THREADS PyGILState_STATE gstate; gstate = PyGILState_Ensure(); - PyObject* pModule = PyImport_ImportModule(moduleName); - if (pModule == NULL) { - printLog(std::string("Error importing module: ").append(funcName)); - PyErr_Print(); - } + // PyObject* pModule = PyImport_ImportModule(moduleName.c_str()); + // PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); + // if (pModule == NULL) { + // printLog(std::string("Error importing module: ").append(moduleName).c_str()); + // PyErr_Print(); + // } // Get a reference to the start function - PyObject* pStartFunc = PyObject_GetAttrString(pModule, funcName); + PyObject* pStartFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, funcName.c_str()); if (pStartFunc == NULL) { printLog(std::string("Error finding function: ").append(funcName).c_str()); PyErr_Print(); - Py_DECREF(pModule); + // Py_DECREF(pModule); } // Call the start function @@ -167,21 +272,17 @@ void FieldlineAcqSystem::callFunction(const char* moduleName, const char* funcNa if (pResult == NULL) { printLog(std::string("Error calling function: ").append(funcName).c_str()); PyErr_Print(); - Py_DECREF(pModule); + // Py_DECREF(pModule); Py_DECREF(pStartFunc); } - Py_DECREF(pModule); + // Py_DECREF(pModule); Py_DECREF(pStartFunc); Py_DECREF(pResult); PyGILState_Release(gstate); - if (Py_IsInitialized()) { - Py_Finalize(); // Py_END_ALLOW_THREADS - } } - void FieldlineAcqSystem::preConfigurePython() const { PyObject* sys = PyImport_ImportModule("sys"); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 4927efe8bb8..4b68f122b8c 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -35,26 +35,33 @@ #ifndef FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H #define FIELDLINEPLUGIN_FIELDLINEACQSYSTEM_H +#include + #include "fieldline/fieldline.h" namespace FIELDLINEPLUGIN { -// class Fieldline; - class FieldlineAcqSystem { public: explicit FieldlineAcqSystem(Fieldline* parent); ~FieldlineAcqSystem(); - void callFunction(const char* moduleName, const char* funcName); + void callFunctionAsync(const char* moduleName, const char* funcName); + + void callFunction(const std::string moduleName, const std::string funcName); + + void setCallback(); private: void preConfigurePython() const; void runPythonFile(const char* file, const char* comment) const; - void loadPythonModule(const char* moduleName); + void* loadPythonModule(const char* moduleName); Fieldline* m_pControllerParent; + void* m_pThreadState; + void* m_pCallbackModule; + void* m_pCallsModule; }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index add2f14913f..8a3e55a91a6 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -193,7 +193,7 @@ void FieldlineView::initAcqSystemTopButtons() button = new QPushButton(QString("Auto-Tune"), m_pUi->acqSystemTopButtonsFrame); QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::autoTuneAllSensors); - acqSystemTopBtnMenuLayout->insertWidget(3, button); + acqSystemTopBtnMenuLayout->insertWidget(3, button); // after the spacer button = new QPushButton(QString("Restart Sensors"), m_pUi->acqSystemTopButtonsFrame); QObject::connect(button, &QPushButton::clicked, this, &FieldlineView::restartAllSensors); @@ -233,16 +233,17 @@ void FieldlineView::initAcqSystem(int numChassis) void FieldlineView::startAllSensors() { printLog("startAllSensors"); - m_pFieldlinePlugin->m_pAcqSystem->callFunction("callback", "start"); + m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "start"); } void FieldlineView::stopAllSensors() { printLog("stopAllSensors"); - m_pFieldlinePlugin->m_pAcqSystem->callFunction("callback", "stop"); + m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "stop"); } void FieldlineView::autoTuneAllSensors() { printLog("autoTuneAllSensors"); + m_pFieldlinePlugin->m_pAcqSystem->setCallback(); } void FieldlineView::restartAllSensors() { From 048e03f9ff19ce9455b09dbeb8dce8ef936e6ee6 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 3 May 2023 19:48:27 -0400 Subject: [PATCH 129/147] refactor python api code --- .../mne_scan/plugins/fieldline/fieldline.cpp | 117 +++++++++--------- .../mne_scan/plugins/fieldline/fieldline.h | 7 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 106 ++++++++-------- .../plugins/fieldline/fieldline_acqsystem.h | 3 +- 4 files changed, 118 insertions(+), 115 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index ffca27ddfe5..79633508c0a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -51,7 +51,7 @@ #include "fieldline/ipfinder.h" #include -// #include +#include //============================================================================================================= // QT INCLUDES @@ -132,8 +132,9 @@ namespace FIELDLINEPLUGIN { Fieldline::Fieldline() : m_pAcqSystem(nullptr) +, m_pCircularBuffer(QSharedPointer(new UTILSLIB::CircularBuffer_Matrix_double(10))) { - printLog("constructor fieldline plugin"); + // printLog("constructor fieldline plugin"); } //============================================================================================================= @@ -157,11 +158,13 @@ QSharedPointer Fieldline::clone() const void Fieldline::init() { printLog("Fieldline init"); + m_pCircularBuffer = QSharedPointer::create(10); // data infrastructure - // m_pRTMSA = SCSHAREDLIB::PluginOutputData - // ::create(this, "Fieldline Plugin", - // "FieldlinePlguin output"); - // m_outputConnectors.append(m_pRTMSA); + m_pRTMSA = SCSHAREDLIB::PluginOutputData + ::create(this, "Fieldline Plugin", + "FieldlinePlguin output"); + m_pRTMSA->measurementData()->setName(this->getName()); // Provide name to auto store widget settings + m_outputConnectors.append(m_pRTMSA); m_pAcqSystem = new FieldlineAcqSystem(this); } @@ -178,16 +181,46 @@ void Fieldline::unload() { bool Fieldline::start() { printLog("start Fieldline"); + + initFiffInfo(); + QThread::start(); return true; } +void Fieldline::initFiffInfo() +{ + QSharedPointer info; + info->sfreq = 1000.0f; + info->nchan = 32; + info->chs.clear(); + for (int chan_i = 0; chan_i < info->nchan; chan_i++) { + FIFFLIB::FiffChInfo channel; + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + std::string channel_name(std::string("Ch. ") + std::to_string(chan_i)); + channel.ch_name = QString::fromStdString(channel_name); + info->chs.append(channel); + info->ch_names.append(QString::fromStdString(channel_name)); + } + + m_pRTMSA->measurementData()->initFromFiffInfo(info); + m_pRTMSA->measurementData()->setMultiArraySize(1); + m_pRTMSA->measurementData()->setVisibility(true); +} + //============================================================================================================= bool Fieldline::stop() { printLog("stop"); requestInterruption(); wait(500); + + m_pRTMSA->measurementData()->clear(); + m_pCircularBuffer->clear(); + return true; } @@ -232,61 +265,18 @@ void Fieldline::findIpAsync(std::vector& macList, //============================================================================================================= -void Fieldline::run() { - printLog("run Fieldline"); +void Fieldline::run() +{ + Eigen::MatrixXd matData; + + while (!isInterruptionRequested()) { + if (m_pCircularBuffer->pop(matData)) { + if (!isInterruptionRequested()) { + m_pRTMSA->measurementData()->setValue(matData); + } + } + } } - // while (true) { - // if (QThread::isInterruptionRequested()) - // break; - // msleep(200); - // } - // m_pFiffInfo = QSharedPointer(new FIFFLIB::FiffInfo()); - // - // m_pFiffInfo->sfreq = 1000.0f; - // m_pFiffInfo->nchan = 32; - // m_pFiffInfo->chs.clear(); - // - // for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { - // FIFFLIB::FiffChInfo channel; - // channel.ch_name = "Ch. " + QString::number(chan_i); - // channel.kind = FIFFV_MEG_CH; - // channel.unit = FIFF_UNIT_T; - // channel.unit_mul = FIFF_UNITM_NONE; - // channel.chpos.coil_type = FIFFV_COIL_NONE; - // m_pFiffInfo->chs.append(channel); - // m_pFiffInfo->ch_names.append(channel.ch_name); - // } - // - // m_pRTMSA_Fieldline->measurementData()->initFromFiffInfo( - // m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { - // m_pRTMSA_Fieldline->measurementData()->setMultiArraySize(1); - // m_pRTMSA_Fieldline->measurementData()->setVisibility(true); - // - // Eigen::MatrixXd matData; - // matData.resize(m_pFiffInfo->nchan, 200); - // // matData.setZero(); - // - // for (;;) { - // // gather the data - // - // matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); - // matData *= 4e-12; - // - // msleep(200); - // - // if (isInterruptionRequested()) - // break; - // m_pRTMSA_Fieldline->measurementData()->setValue(matData); - // } - // - // // //emit values - // // if(!isInterruptionRequested()) { - // // m_pRMTSA_Natus->measurementData()->setValue(matData); - // // } - // // } - // // } - // printLog("run Fieldline finished"); -// } //============================================================================================================= @@ -295,4 +285,11 @@ QString Fieldline::getBuildInfo() { return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } +void Fieldline::newData(double* mat, size_t numSamples, size_t numChannels) +{ + while(!m_pCircularBuffer->push(Eigen::Map(mat, numSamples, numChannels))) { + printLog("Fieldline Plugin: Pushing data to circular buffer failed... Trying again."); + } +} + } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 2ac135a0b77..5d1722eb3c3 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -44,6 +44,7 @@ #include #include +#include #include @@ -115,12 +116,16 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor std::function&)> callback); FieldlineAcqSystem* m_pAcqSystem; + void newData(double* mat, size_t numSamples, size_t numChannels); + protected: virtual void run(); - + private: + void initFiffInfo(); QSharedPointer > m_pRTMSA; /**< The RealTimeSampleArray to provide the EEG data.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ + QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ }; } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index bddeb06d904..ddea0ce57c8 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -117,7 +117,6 @@ const std::string entryFile(resourcesPath + "main.py"); void callback1() { printLog("This is callback1."); - } static PyObject* callback1_py(PyObject* self, PyObject* args) { @@ -139,41 +138,23 @@ static PyObject* PyInit_calls(void) { return PyModule_Create(&CallModule); } - - - - - - - - - FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { Py_Initialize(); preConfigurePython(); - // runPythonFile(entryFile.c_str(), "main.py"); - m_pCallbackModule = (void*)loadPythonModule("callback"); - if (Py_IsInitialized()) { - PyImport_AddModule("calls"); - PyObject* pyModule = PyInit_calls(); - PyObject* sys_modules = PyImport_GetModuleDict(); - PyDict_SetItemString(sys_modules, "calls", pyModule); - Py_DECREF(pyModule); - } + m_pCallbackModule = loadModule("callback"); - m_pCallsModule = (void*)loadPythonModule("calls"); + m_pCallsModule = loadCModule("calls", *(void*(*)(void))&PyInit_calls); m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() { - PyEval_RestoreThread((PyThreadState*)m_pThreadState); - printLog("About to finalize python"); + PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); Py_DECREF(m_pCallbackModule); Py_DECREF(m_pCallsModule); Py_Finalize(); @@ -181,14 +162,13 @@ FieldlineAcqSystem::~FieldlineAcqSystem() void FieldlineAcqSystem::setCallback() { - PyGILState_STATE gstate; gstate = PyGILState_Ensure(); PyObject *pSetCallbackFunc = NULL; PyObject *pCallback1 = NULL; PyObject *pArgs = NULL; - PyObject *pResult = NULL; + PyObject *pResult = NULL; // Get a reference to the function pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); @@ -197,13 +177,11 @@ void FieldlineAcqSystem::setCallback() PyErr_Print(); } - printLog("I'm here!!!!!"); pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); if (pCallback1 && PyCallable_Check(pCallback1)) { pArgs = PyTuple_New(1); PyTuple_SetItem(pArgs, 0, pCallback1); - } - else { + } else { if (PyErr_Occurred()) PyErr_Print(); printLog(std::string("Cannot find function callback1 in calls module.")); @@ -222,28 +200,48 @@ void FieldlineAcqSystem::setCallback() PyGILState_Release(gstate); } -void* FieldlineAcqSystem::loadPythonModule(const char* moduleName) +void* FieldlineAcqSystem::loadModule(const char* moduleName) { - // Import the callback_module Python module + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + PyObject* pModule = PyImport_ImportModule(moduleName); if (pModule == NULL) { - printLog(std::string("Error importing: ").append(moduleName).c_str()); + printLog(std::string("Error loading module ").append(moduleName).append(".").c_str()); PyErr_Print(); } + + PyGILState_Release(gstate); + return (void*)pModule; } +void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitFunc)(void)) +{ + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + if (Py_IsInitialized()) + { + PyImport_AddModule(moduleName); + PyObject* pyModule = (PyObject*)moduleInitFunc(); + PyObject* sys_modules = PyImport_GetModuleDict(); + PyDict_SetItemString(sys_modules, moduleName, pyModule); + Py_DECREF(pyModule); + } else { + PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); + } + + PyGILState_Release(gstate); + + return loadModule(moduleName); +} void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* funcName) { - printLog("Right before spawning threads!"); - auto lambda = [this, moduleName, funcName]() { - printLog("in the thread!"); - printLog(std::string("Module name: ").append(moduleName)); - printLog(std::string("Func name: ").append(funcName)); + std::thread t([this, moduleName, funcName]() { this->callFunction(moduleName, funcName); - }; - std::thread t(lambda); + }); t.detach(); } @@ -252,32 +250,34 @@ void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::s PyGILState_STATE gstate; gstate = PyGILState_Ensure(); - // PyObject* pModule = PyImport_ImportModule(moduleName.c_str()); - // PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); - // if (pModule == NULL) { - // printLog(std::string("Error importing module: ").append(moduleName).c_str()); - // PyErr_Print(); - // } + PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); + if (pModule == NULL) { + printLog(std::string("Module ").append(moduleName).append(" has not been imported yet.").c_str()); + printLog(std::string("Attempting to import the module ").append(moduleName).append(".").c_str()); + pModule = PyImport_ImportModule(moduleName.c_str()); + if (pModule == NULL) { + PyErr_Print(); + printLog(std::string("Import failed. Can't find ").append(moduleName).append(".").c_str()); + } + } - // Get a reference to the start function - PyObject* pStartFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, funcName.c_str()); - if (pStartFunc == NULL) { + PyObject* pFunc = PyObject_GetAttrString(pModule, funcName.c_str()); + if (pFunc == NULL) { printLog(std::string("Error finding function: ").append(funcName).c_str()); PyErr_Print(); - // Py_DECREF(pModule); + Py_DECREF(pModule); } - // Call the start function - PyObject* pResult = PyObject_CallObject(pStartFunc, NULL); + PyObject* pResult = PyObject_CallObject(pFunc, NULL); if (pResult == NULL) { printLog(std::string("Error calling function: ").append(funcName).c_str()); PyErr_Print(); - // Py_DECREF(pModule); - Py_DECREF(pStartFunc); + Py_DECREF(pModule); + Py_DECREF(pFunc); } - // Py_DECREF(pModule); - Py_DECREF(pStartFunc); + Py_DECREF(pModule); + Py_DECREF(pFunc); Py_DECREF(pResult); PyGILState_Release(gstate); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 4b68f122b8c..12bd531e41e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -56,7 +56,8 @@ class FieldlineAcqSystem { private: void preConfigurePython() const; void runPythonFile(const char* file, const char* comment) const; - void* loadPythonModule(const char* moduleName); + void* loadModule(const char* moduleName); + void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); Fieldline* m_pControllerParent; void* m_pThreadState; From 5479693e3d3f6726776ffec9c2d7483800c95851 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 4 May 2023 21:58:22 -0400 Subject: [PATCH 130/147] prepare for new callbacks interacting with fieldline box --- .../fieldline_acq_system/CMakeLists.txt | 0 .../plugins/fieldline/fieldline_acqsystem.cpp | 5 + testing.cpp | 208 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 src/applications/mne_scan/plugins/fieldline/fieldline_acq_system/CMakeLists.txt create mode 100644 testing.cpp diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/fieldline_acq_system/CMakeLists.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index ddea0ce57c8..0039efeabbf 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -237,6 +237,11 @@ void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitF return loadModule(moduleName); } + +PyObject* var1, var2; + +int (*var)(void); + void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* funcName) { std::thread t([this, moduleName, funcName]() { diff --git a/testing.cpp b/testing.cpp new file mode 100644 index 00000000000..ca647ca0663 --- /dev/null +++ b/testing.cpp @@ -0,0 +1,208 @@ +#define PY_SSIZE_T_CLEAN +#include +#include +#include +// #include "defaults.hpp" + +void dictParser() { + std::cout << "Hello from dictParser\n"; +} + +static PyObject* dict_parser_py_fastcall(PyObject* self, PyObject*const* args, Py_ssize_t argc) { + PyObject* dict = args[1]; + std::cout << "fastcall started.\n"; + std::cout << "num of args = " << argc << "\n"; + + if (!PyLong_Check(args[0])) { + std::cout << "Not int.\n"; + return NULL; + } else { + std::cout << "integer: " << PyLong_AsLong(args[0]) << "\n"; + } + if (!PyDict_Check(dict)) { + std::cout << "Not a dict.!\n"; + return NULL; + } else { + int typeDict = PyDict_Check(dict); + if (typeDict) + std::cout << "It is a boy!\n"; + + int s = PyDict_Size(dict); + std::cout << "Number of elements: " << s << "\n"; + + PyObject *key = PyUnicode_FromString("keyA"); + if (PyDict_Contains(dict, key) == 1) { + PyObject *value = PyDict_GetItem(dict, key); + long my_value = PyLong_AsLong(value); + std::cout + << "The value :" << PyUnicode_AsUTF8(key) + << " is " << my_value << "\n"; + } + } + return Py_None; +} + +static PyObject* dict_parser_py_varargs(PyObject* self, PyObject* args) { + // parse input args + int numArgs = 0; + int s = 0; + int var; + PyObject* dict; + + + if (!PyTuple_Check(args)) { + return NULL; + } + + numArgs = PyTuple_Size(args); + std::cout << "Num args: " << numArgs << "\n"; + // if (PyTuple_Size(args) != 1) + // std::cout << "Num args not correct.\n"; + // + if (!PyArg_ParseTuple(args, "iO", &var, &dict)) { + std::cout << "Error parsing arguments.\n"; + return NULL; + } + std::cout << "var = " << var << "\n"; + int typeDict = PyDict_Check(dict); + if (typeDict) + std::cout << "It is a boy!\n"; + + s = PyDict_Size(dict); + std::cout << "Number of elements: " << s << "\n"; + + PyObject *key = PyUnicode_FromString("keyA"); + if (PyDict_Contains(dict, key) == 1) { + PyObject *value = PyDict_GetItem(dict, key); + long my_value = PyLong_AsLong(value); + std::cout + << "The value :" << PyUnicode_AsUTF8(key) + << " is " << my_value << "\n"; + } + + return Py_None; +} + + +void get_item_from_dict(PyObject* item, PyObject* dict, const char* key) { + PyObject* key_obj = PyUnicode_FromString(key); + item = PyDict_GetItem(dict, key_obj); +} + + +static PyObject* dict_parser(PyObject* self, PyObject*const* args, Py_ssize_t argc) { + if (argc != 1) { + return NULL; + } + + if (!PyDict_Check(args[0])) { + return NULL; + } + + PyObject* dict = args[0]; + PyObject* data_frames; + PyObject* dataKeyObj = PyUnicode_FromString("data"); + PyObject* sensorNameKeyObj = PyUnicode_FromString("sensor"); + + PyObject* key_obj = PyUnicode_FromString("data_frames"); + + data_frames = PyDict_GetItem(dict, key_obj); + Py_DECREF(dict); + Py_DECREF(); + + int num_channels = PyDict_Size(data_frames); + + // std::cout << "Num channels: " << num_channels << "\n"; + // int* data = new int() + PyObject* key, *value; + Py_ssize_t pos = 0; + struct dataValue { + int value; + char label[5+1]; + }; + dataValue* dataValues = new dataValue[num_channels]; + + while (PyDict_Next(data_frames, &pos, &key, &value)) { + // int num_values = PyDict_Size(value); + // std::cout << "Num values: " << num_values << "\n"; + PyObject* data; + PyObject* sensorName; + sensorName = PyDict_GetItem(value, sensorNameKeyObj); + data = PyDict_GetItem(value, dataKeyObj); + // std::cout << "Sensor " << PyUnicode_AsUTF8(sensorName) + // << ": " << PyLong_AsLong(data) + // << " - pos: " << pos << "\n"; + memcpy((void*)dataValues[pos-1].label,(void*)PyUnicode_AsUTF8(sensorName), 5); + + dataValues[pos-1].label[5] = static_cast(0); + dataValues[pos-1].value = PyLong_AsLong(data); + } + + // for (int i = 0; i < num_channels; i++) { + // std::cout << "(" << dataValues[i].label << ") - " << dataValues[i].value << "\n"; + // } + + delete[] dataValues; + + + // important !!!!! + // we need to Py_DECREF a few PyObjects!!!! + + return Py_None; +} + +static struct PyMethodDef callbacksMethods[] = { + {"dict_parser_fastcall", _PyCFunction_CAST(dict_parser_py_fastcall), + METH_FASTCALL, "Parse dictionary fastcall"}, + {"dict_parser", _PyCFunction_CAST(dict_parser), + METH_FASTCALL, "Parse dictionary"}, + {"dict_parser_varargs", dict_parser_py_varargs, + METH_VARARGS, "Parse dictionary with varargs"}, + {NULL, NULL, 0, NULL} +}; + +static PyModuleDef CallModule = { + PyModuleDef_HEAD_INIT, "parsing", NULL, -1, callbacksMethods, + NULL, NULL, NULL, NULL +}; + + +static PyObject* PyInit_parsing(void) { + return PyModule_Create(&CallModule); +} + + + +int main(int argc, char* argv[]) { + // std::cout << "Starting execution\n"; + + PyImport_AppendInittab("parsing", &PyInit_parsing); + Py_Initialize(); + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.module_search_paths_set = 1; + PyWideStringList_Append(&config.module_search_paths, L"."); + Py_InitializeFromConfig(&config); + + FILE* py_file; + if (argc != 2) { + std::cout << "Usage: " << argv[0] << ": main.py\n"; + exit(1); + } + py_file = fopen(argv[1], "r"); + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, + argv[1], + Py_file_input, + global_dict, + local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); + + Py_Finalize(); + + return 0; +} From 0a89e7e67c7041b09f610e248c66ec3be530a8e0 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Fri, 5 May 2023 19:33:13 -0400 Subject: [PATCH 131/147] instantiate objects in c python --- .../plugins/fieldline/fieldline_acqsystem.cpp | 392 ++++++++++-------- 1 file changed, 218 insertions(+), 174 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 0039efeabbf..7e2c055516d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -1,10 +1,10 @@ //============================================================================================================= /** - * @file fieldline_system_controller.cpp + * @file fieldline_system_controller.cpp * @author Juan GarciaPrieto ; - * Gabriel B Motta ; - * @since 0.1.0 - * @date February, 2023 + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 * * @section LICENSE * @@ -12,12 +12,12 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, + * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright + * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of MNE-CPP authors nor the names of its contributors + * * Neither the name of MNE-CPP authors nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * @@ -34,7 +34,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * - * @brief Contains the definition of the Fieldline class. + * @brief Contains the definition of the Fieldline class. * */ #define PY_SSIZE_T_CLEAN @@ -55,10 +55,10 @@ //PyObject *restartFinished(PyObject *self, PyObject *args) { // long chassis, sensor; // if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - restart finished;\n"; +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - restart finished;\n"; // } else { -// std::cout << "A sensor has finished restarting!\n"; +// std::cout << "A sensor has finished restarting!\n"; // } // // return NULL; @@ -66,10 +66,10 @@ //PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { // long chassis, sensor; // if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - coarse zero finished;\n"; +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - coarse zero finished;\n"; // } else { -// std::cout << "A sensor has finished coarse zeroing!\n"; +// std::cout << "A sensor has finished coarse zeroing!\n"; // } // // return NULL; @@ -77,10 +77,10 @@ //PyObject *fineZeroFinished(PyObject *self, PyObject *args) { // long chassis, sensor; // if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - fine zero finished;\n"; +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - fine zero finished;\n"; // } else { -// std::cout << "A sensor has finished fine zeroing!\n"; +// std::cout << "A sensor has finished fine zeroing!\n"; // } // // return NULL; @@ -88,21 +88,21 @@ //} // //static PyMethodDef my_module_methods[] = { -// {"restartFinished", restartFinished, METH_VARARGS, " "}, -// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, -// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, -// {NULL, NULL, 0, NULL}}; +// {"restartFinished", restartFinished, METH_VARARGS, " "}, +// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, +// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, +// {NULL, NULL, 0, NULL}}; // //static PyModuleDef my_module_def = { -// PyModuleDef_HEAD_INIT, -// "mne_cpp_callbacks", -// "A module of callback functions for mne-cpp.", -// -1, -// my_module_methods, -// NULL, -// NULL, -// NULL, -// NULL}; +// PyModuleDef_HEAD_INIT, +// "mne_cpp_callbacks", +// "A module of callback functions for mne-cpp.", +// -1, +// my_module_methods, +// NULL, +// NULL, +// NULL, +// NULL}; // //PyMODINIT_FUNC PyInit_my_module(void) { // return PyModule_Create(&my_module_def); @@ -111,217 +111,261 @@ namespace FIELDLINEPLUGIN { const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + - "/../resources/mne_scan/plugins/fieldline/"); + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); void callback1() { - printLog("This is callback1."); + printLog("This is callback1."); } static PyObject* callback1_py(PyObject* self, PyObject* args) { - callback1(); - return Py_None; + callback1(); + return Py_None; } static struct PyMethodDef callbacksMethods[] = { - {"callback1", callback1_py, METH_VARARGS, "Call to callback1"}, - {NULL, NULL, 0, NULL} + {"callback1", callback1_py, METH_VARARGS, "Call to callback1"}, + {NULL, NULL, 0, NULL} }; static PyModuleDef CallModule = { - PyModuleDef_HEAD_INIT, "calls", NULL, -1, callbacksMethods, - NULL, NULL, NULL, NULL + PyModuleDef_HEAD_INIT, "calls", NULL, -1, callbacksMethods, + NULL, NULL, NULL, NULL }; static PyObject* PyInit_calls(void) { - return PyModule_Create(&CallModule); + return PyModule_Create(&CallModule); } FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent) { - Py_Initialize(); + Py_Initialize(); - preConfigurePython(); + preConfigurePython(); - m_pCallbackModule = loadModule("callback"); + m_pCallbackModule = loadModule("callback"); - m_pCallsModule = loadCModule("calls", *(void*(*)(void))&PyInit_calls); - m_pThreadState = (void*)PyEval_SaveThread(); + m_pCallsModule = loadCModule("calls", *(void*(*)(void))&PyInit_calls); + + PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + + PyObject* fService = PyObject_GetAttrString(FieldlineModule, "FieldLineService"); + if (fService == NULL) + { + printLog("fservice wrong!"); + } else{ + printLog("fservice ok!"); + } + PyObject* ipList = Py_BuildValue("([ss])", "8.8.8.8", "1.1.1.1"); + PyObject* fServiceInstance = PyObject_CallObject(fService, ipList); + printLog("here!!!"); + if (fServiceInstance == NULL) + { + printLog("fServiceInstance wrong!"); + } else{ + printLog("fServiceInstance ok!"); + } + PyObject* openMethod = PyObject_GetAttrString(fServiceInstance, "open"); + if (openMethod == NULL) + { + printLog("openMethod wrong!"); + } else{ + printLog("openMethod ok!"); + } + PyObject* pResult = PyObject_CallMethodNoArgs(fServiceInstance, PyUnicode_FromString("open")); + if (pResult == NULL) + { + printLog("pResult wrong!"); + } else{ + printLog("pResult ok!"); + } + PyObject* pResult2 = PyObject_CallNoArgs(openMethod); + if (pResult2 == NULL) + { + printLog("pResult2 wrong!"); + } else{ + printLog("pResult2 ok!"); + } + + Py_DECREF(FieldlineModule); + Py_DECREF(fService); + Py_DECREF(ipList); + Py_DECREF(fServiceInstance); + Py_DECREF(openMethod); + Py_DECREF(pResult); + + m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() { - PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); - Py_DECREF(m_pCallbackModule); - Py_DECREF(m_pCallsModule); - Py_Finalize(); + PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); + Py_DECREF(m_pCallbackModule); + Py_DECREF(m_pCallsModule); + Py_Finalize(); } -void FieldlineAcqSystem::setCallback() +void FieldlineAcqSystem::setCallback() { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - PyObject *pSetCallbackFunc = NULL; - PyObject *pCallback1 = NULL; - PyObject *pArgs = NULL; - PyObject *pResult = NULL; - - // Get a reference to the function - pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); - if (pSetCallbackFunc == NULL) { - printLog(std::string("Error finding function: ").append("set_callback").c_str()); - PyErr_Print(); - } - - pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); - if (pCallback1 && PyCallable_Check(pCallback1)) { - pArgs = PyTuple_New(1); - PyTuple_SetItem(pArgs, 0, pCallback1); - } else { - if (PyErr_Occurred()) - PyErr_Print(); - printLog(std::string("Cannot find function callback1 in calls module.")); - } - // Call the set_callback function - pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); - if (pResult == NULL) { - printLog(std::string("Error calling function: ").append("set_callback").c_str()); - PyErr_Print(); - } - Py_XDECREF(pSetCallbackFunc); - Py_XDECREF(pCallback1); - Py_XDECREF(pArgs); - Py_XDECREF(pResult); - - PyGILState_Release(gstate); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject *pSetCallbackFunc = NULL; + PyObject *pCallback1 = NULL; + PyObject *pArgs = NULL; + PyObject *pResult = NULL; + + // Get a reference to the function + pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); + if (pSetCallbackFunc == NULL) { + printLog(std::string("Error finding function: ").append("set_callback").c_str()); + PyErr_Print(); + } + + pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); + if (pCallback1 && PyCallable_Check(pCallback1)) { + pArgs = PyTuple_New(1); + PyTuple_SetItem(pArgs, 0, pCallback1); + } else { + if (PyErr_Occurred()) + PyErr_Print(); + printLog(std::string("Cannot find function callback1 in calls module.")); + } + // Call the set_callback function + pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); + if (pResult == NULL) { + printLog(std::string("Error calling function: ").append("set_callback").c_str()); + PyErr_Print(); + } + Py_XDECREF(pSetCallbackFunc); + Py_XDECREF(pCallback1); + Py_XDECREF(pArgs); + Py_XDECREF(pResult); + + PyGILState_Release(gstate); } void* FieldlineAcqSystem::loadModule(const char* moduleName) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); - PyObject* pModule = PyImport_ImportModule(moduleName); - if (pModule == NULL) { - printLog(std::string("Error loading module ").append(moduleName).append(".").c_str()); - PyErr_Print(); - } + PyObject* pModule = PyImport_ImportModule(moduleName); + if (pModule == NULL) { + printLog(std::string("Error loading module ").append(moduleName).append(".").c_str()); + PyErr_Print(); + } - PyGILState_Release(gstate); + PyGILState_Release(gstate); - return (void*)pModule; + return (void*)pModule; } void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitFunc)(void)) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - if (Py_IsInitialized()) - { - PyImport_AddModule(moduleName); - PyObject* pyModule = (PyObject*)moduleInitFunc(); - PyObject* sys_modules = PyImport_GetModuleDict(); - PyDict_SetItemString(sys_modules, moduleName, pyModule); - Py_DECREF(pyModule); - } else { - PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); - } - - PyGILState_Release(gstate); - - return loadModule(moduleName); -} - + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + if (Py_IsInitialized()) + { + PyImport_AddModule(moduleName); + PyObject* pyModule = (PyObject*)moduleInitFunc(); + PyObject* sys_modules = PyImport_GetModuleDict(); + PyDict_SetItemString(sys_modules, moduleName, pyModule); + Py_DECREF(pyModule); + } else { + PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); + } -PyObject* var1, var2; + PyGILState_Release(gstate); -int (*var)(void); + return loadModule(moduleName); +} void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* funcName) { - std::thread t([this, moduleName, funcName]() { - this->callFunction(moduleName, funcName); - }); - t.detach(); + std::thread t([this, moduleName, funcName]() { + this->callFunction(moduleName, funcName); + }); + t.detach(); } void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::string funcName) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); - if (pModule == NULL) { - printLog(std::string("Module ").append(moduleName).append(" has not been imported yet.").c_str()); - printLog(std::string("Attempting to import the module ").append(moduleName).append(".").c_str()); - pModule = PyImport_ImportModule(moduleName.c_str()); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); if (pModule == NULL) { - PyErr_Print(); - printLog(std::string("Import failed. Can't find ").append(moduleName).append(".").c_str()); + printLog(std::string("Module ").append(moduleName).append(" has not been imported yet.").c_str()); + printLog(std::string("Attempting to import the module ").append(moduleName).append(".").c_str()); + pModule = PyImport_ImportModule(moduleName.c_str()); + if (pModule == NULL) { + PyErr_Print(); + printLog(std::string("Import failed. Can't find ").append(moduleName).append(".").c_str()); + } } - } - PyObject* pFunc = PyObject_GetAttrString(pModule, funcName.c_str()); - if (pFunc == NULL) { - printLog(std::string("Error finding function: ").append(funcName).c_str()); - PyErr_Print(); - Py_DECREF(pModule); - } + PyObject* pFunc = PyObject_GetAttrString(pModule, funcName.c_str()); + if (pFunc == NULL) { + printLog(std::string("Error finding function: ").append(funcName).c_str()); + PyErr_Print(); + Py_DECREF(pModule); + } + + PyObject* pResult = PyObject_CallObject(pFunc, NULL); + if (pResult == NULL) { + printLog(std::string("Error calling function: ").append(funcName).c_str()); + PyErr_Print(); + Py_DECREF(pModule); + Py_DECREF(pFunc); + } - PyObject* pResult = PyObject_CallObject(pFunc, NULL); - if (pResult == NULL) { - printLog(std::string("Error calling function: ").append(funcName).c_str()); - PyErr_Print(); Py_DECREF(pModule); Py_DECREF(pFunc); - } - - Py_DECREF(pModule); - Py_DECREF(pFunc); - Py_DECREF(pResult); + Py_DECREF(pResult); - PyGILState_Release(gstate); + PyGILState_Release(gstate); } void FieldlineAcqSystem::preConfigurePython() const { - PyObject* sys = PyImport_ImportModule("sys"); - PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); - PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); - PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); - const std::string pythonVer(std::to_string(PyLong_AsLong(versionInfoMajor)) + \ - "." + std::to_string(PyLong_AsLong(versionInfoMinor))); - Py_DECREF(versionInfoMajor); - Py_DECREF(versionInfoMinor); - Py_DECREF(versionInfo); - - PyObject* path = PyObject_GetAttrString(sys, "path"); - PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); - Py_DECREF(sys); - - const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); - PyList_Insert(path, 1, PyUnicode_FromString(pathVenvMods.c_str())); - Py_DECREF(path); + PyObject* sys = PyImport_ImportModule("sys"); + PyObject* versionInfo = PyObject_GetAttrString(sys, "version_info"); + PyObject* versionInfoMajor = PyObject_GetAttrString(versionInfo, "major"); + PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); + const std::string pythonVer(std::to_string(PyLong_AsLong(versionInfoMajor)) + \ + "." + std::to_string(PyLong_AsLong(versionInfoMinor))); + Py_DECREF(versionInfoMajor); + Py_DECREF(versionInfoMinor); + Py_DECREF(versionInfo); + + PyObject* path = PyObject_GetAttrString(sys, "path"); + PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); + Py_DECREF(sys); + + const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); + printLog(pathVenvMods); + PyList_Insert(path, 1, PyUnicode_FromString(pathVenvMods.c_str())); + Py_DECREF(path); } void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const { - FILE *py_file = fopen(file, "r"); - if (py_file) - { - PyObject* global_dict = PyDict_New(); - PyObject* local_dict = PyDict_New(); - PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); - fclose(py_file); - } + FILE *py_file = fopen(file, "r"); + if (py_file) + { + PyObject* global_dict = PyDict_New(); + PyObject* local_dict = PyDict_New(); + PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); + Py_DECREF(global_dict); + Py_DECREF(local_dict); + Py_DECREF(result); + fclose(py_file); + } } } // namespace FIELDLINEPLUGIN From b1d2320259956d736c4f6d940af1b95ed5005c8c Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Wed, 10 May 2023 13:00:22 -0400 Subject: [PATCH 132/147] connect new data to circular buffer --- .../mne_scan/plugins/fieldline/callback.py | 1 + .../fieldline_api_mock/fieldline_service.py | 6 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 8 +- .../mne_scan/plugins/fieldline/fieldline.h | 2 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 497 ++++++++++++++---- .../plugins/fieldline/fieldline_acqsystem.h | 6 +- .../plugins/fieldline/fieldline_view.cpp | 6 +- .../mne_scan/plugins/fieldline/notes.cpp | 58 ++ 8 files changed, 465 insertions(+), 119 deletions(-) create mode 100644 src/applications/mne_scan/plugins/fieldline/notes.cpp diff --git a/resources/mne_scan/plugins/fieldline/callback.py b/resources/mne_scan/plugins/fieldline/callback.py index 512bcc71d07..f654b33cb8b 100644 --- a/resources/mne_scan/plugins/fieldline/callback.py +++ b/resources/mne_scan/plugins/fieldline/callback.py @@ -13,6 +13,7 @@ def default_callback1(): print(f'Counter: {counter}') counter += 1 + def default_callback2(): with open("output.txt", "a") as f: f.write("default_callback2\n") diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index 382f43e8cb2..bc99bd8206b 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -59,6 +59,7 @@ def load_sensors(self): print("Loading sensors.") return self.sensors else: + print("Cannot load sensors.") print("Fieldline service closed.") def get_chassis_list(self): @@ -113,7 +114,7 @@ def data_acquisition(self): end_time = time.time() elapsed_time = end_time - start_time # time_to_sleep = max(0, .001 - elapsed_time) - time.sleep(sampling_period + elapsed_time_diff - 0.6 * elapsed_time) + time.sleep(abs(sampling_period + elapsed_time_diff - 0.7 * elapsed_time)) # print(f"elapsed_time: {elapsed_time:04}") # start_time = time.time() # end_time = time.time() @@ -136,6 +137,7 @@ def data_acquisition(self): # time.sleep(time_to_sleep_final) def read_data(self, data_callback=None): + print("Setting the data callback fcn.") if self.is_open: if(data_callback is not None): self.callback_function = data_callback @@ -161,7 +163,7 @@ def start_adc(self, _): print("Fieldline service closed.") return None - def stop_adc(self, chassis_id): + def stop_adc(self, _): """ Stop ADC from chassis diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 79633508c0a..f4c9f8ccf95 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -158,7 +158,7 @@ QSharedPointer Fieldline::clone() const void Fieldline::init() { printLog("Fieldline init"); - m_pCircularBuffer = QSharedPointer::create(10); + m_pCircularBuffer = QSharedPointer::create(40); // data infrastructure m_pRTMSA = SCSHAREDLIB::PluginOutputData ::create(this, "Fieldline Plugin", @@ -188,7 +188,7 @@ bool Fieldline::start() return true; } -void Fieldline::initFiffInfo() +void Fieldline::initFiffInfo() { QSharedPointer info; info->sfreq = 1000.0f; @@ -285,9 +285,9 @@ QString Fieldline::getBuildInfo() { return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } -void Fieldline::newData(double* mat, size_t numSamples, size_t numChannels) +void Fieldline::newData(double* data, size_t numChannels) { - while(!m_pCircularBuffer->push(Eigen::Map(mat, numSamples, numChannels))) { + while(!m_pCircularBuffer->push(Eigen::Map(data, 1, numChannels))) { printLog("Fieldline Plugin: Pushing data to circular buffer failed... Trying again."); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 5d1722eb3c3..55b9ddc76ec 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -116,7 +116,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor std::function&)> callback); FieldlineAcqSystem* m_pAcqSystem; - void newData(double* mat, size_t numSamples, size_t numChannels); + void newData(double* data, size_t numChannels); protected: virtual void run(); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 7e2c055516d..051bcbafa2d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -50,92 +50,239 @@ #include "fieldline/fieldline_acqsystem.h" -//extern "C" { -// -//PyObject *restartFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - restart finished;\n"; -// } else { -// std::cout << "A sensor has finished restarting!\n"; -// } -// -// return NULL; -//} -//PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - coarse zero finished;\n"; -// } else { -// std::cout << "A sensor has finished coarse zeroing!\n"; -// } -// -// return NULL; -//} -//PyObject *fineZeroFinished(PyObject *self, PyObject *args) { -// long chassis, sensor; -// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { -// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor -// << " - fine zero finished;\n"; -// } else { -// std::cout << "A sensor has finished fine zeroing!\n"; -// } -// -// return NULL; -//} -//} -// -//static PyMethodDef my_module_methods[] = { -// {"restartFinished", restartFinished, METH_VARARGS, " "}, -// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, -// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, -// {NULL, NULL, 0, NULL}}; -// -//static PyModuleDef my_module_def = { -// PyModuleDef_HEAD_INIT, -// "mne_cpp_callbacks", -// "A module of callback functions for mne-cpp.", -// -1, -// my_module_methods, -// NULL, -// NULL, -// NULL, -// NULL}; -// -//PyMODINIT_FUNC PyInit_my_module(void) { -// return PyModule_Create(&my_module_def); -//} - namespace FIELDLINEPLUGIN { const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdString() + "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); +bool restartFinished = false; + +void callbackOnFinishedWhileRestart(int chassisId, int sensorId) { + std::cout << "Sensor: (" << chassisId << ", " << sensorId << ") Finished restart.\n"; +} + +void callbackOnFinishedWhileCoarseZero(int chassisId, int sensorId) { + std::cout << "Sensor: (" << chassisId << ", " << sensorId << ") Finished coarse zero.\n"; +} + +void callbackOnFinishedWhileFineZero(int chassisId, int sensorId) { + std::cout << "Sensor: (" << chassisId << ", " << sensorId << ") Finished fine zero.\n"; +} + +void callbackOnErrorWhileRestart(int chassisId, int sensorId, int errorId) { + std::cout << "Error while restarting sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; +} + +void callbackOnErrorWhileCoarseZero(int chassisId, int sensorId, int errorId) { + std::cout << "Error while restarting sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; +} + +void callbackOnErrorWhileFineZero(int chassisId, int sensorId, int errorId) { + std::cout << "Error while restarting sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; +} + +void callbackOnCompletionRestart() { + std::cout << "About to change restartFinished\n"; + restartFinished = true; + std::cout << "Restart of sensors, finished.\n"; +} + +void callbackOnCompletionCoarseZero() { + std::cout << "Coarse zero of sensors, finished.\n"; +} -void callback1() { - printLog("This is callback1."); +void callbackOnCompletionFineZero() { + std::cout << "Fine zero of sensors, finished.\n"; } -static PyObject* callback1_py(PyObject* self, PyObject* args) { - callback1(); +static PyObject* callbackOnFinishedWhileRestart_py(PyObject* self, PyObject* args) { + int chassis, sensor; + if (!PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + return NULL; + } + callbackOnFinishedWhileRestart(chassis, sensor); + return Py_None; +} + +static PyObject* callbackOnFinishedWhileCoarseZero_py(PyObject* self, PyObject* args) { + int chassis, sensor; + if (!PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + return NULL; + } + callbackOnFinishedWhileCoarseZero(chassis, sensor); + return Py_None; +} + +static PyObject* callbackOnFinishedWhileFineZero_py(PyObject* self, PyObject* args) { + int chassis, sensor; + if (!PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { + return NULL; + } + callbackOnFinishedWhileFineZero(chassis, sensor); + return Py_None; +} + +static PyObject* callbackOnErrorWhileRestart_py(PyObject* self, PyObject* args) { + int chassis, sensor, error; + if (!PyArg_ParseTuple(args, "iii", &chassis, &sensor, &error)) { + return NULL; + } + callbackOnErrorWhileRestart(chassis, sensor, error); return Py_None; } -static struct PyMethodDef callbacksMethods[] = { - {"callback1", callback1_py, METH_VARARGS, "Call to callback1"}, +static PyObject* callbackOnErrorWhileCoarseZero_py(PyObject* self, PyObject* args) { + int chassis, sensor, error; + if (!PyArg_ParseTuple(args, "iii", &chassis, &sensor, &error)) { + return NULL; + } + callbackOnErrorWhileCoarseZero(chassis, sensor, error); + return Py_None; +} + +static PyObject* callbackOnErrorWhileFinzeZero_py(PyObject* self, PyObject* args) { + int chassis, sensor, error; + if (!PyArg_ParseTuple(args, "iii", &chassis, &sensor, &error)) { + return NULL; + } + callbackOnErrorWhileFineZero(chassis, sensor, error); + return Py_None; +} + +static PyObject* callbackOnCompletionRestart_py(PyObject* self, PyObject* args) { + Py_ssize_t arg_count = PyTuple_Size(args); + if (arg_count != 0) { + PyErr_SetString(PyExc_ValueError, "This function should be called with no arguments."); + return nullptr; + } + callbackOnCompletionRestart(); + return Py_None; +} + +static PyObject* callbackOnCompletionCoarseZero_py(PyObject* self, PyObject* args) { + Py_ssize_t arg_count = PyTuple_Size(args); + if (arg_count != 0) { + PyErr_SetString(PyExc_ValueError, "This function should be called with no arguments."); + return nullptr; + } + callbackOnCompletionCoarseZero(); + return Py_None; +} + +static PyObject* callbackOnCompletionFineZero_py(PyObject* self, PyObject* args) { + Py_ssize_t arg_count = PyTuple_Size(args); + if (arg_count != 0) { + PyErr_SetString(PyExc_ValueError, "This function should be called with no arguments."); + return nullptr; + } + callbackOnCompletionFineZero(); + return Py_None; +} + +static struct PyMethodDef fieldlineCallbacksMethods[] = { + {"callbackOnFinishedWhileRestart", callbackOnFinishedWhileRestart_py, + METH_VARARGS, "Function to be called when a sensor has finished its restart."}, + {"callbackOnFinishedWhileCoarseZero", callbackOnFinishedWhileCoarseZero_py, + METH_VARARGS, "Function to be called when a sensor has finished its coarse zeroing."}, + {"callbackOnFinishedWhileFineZero", callbackOnFinishedWhileFineZero_py, + METH_VARARGS, "Function to be called when a sensor has finished its fine zeroing."}, + {"callbackOnErrorWhileRestart", callbackOnErrorWhileRestart_py, + METH_VARARGS, "Function to be called when a sensor has an error while restarting."}, + {"callbackOnErrorWhileCoarseZero", callbackOnErrorWhileCoarseZero_py, + METH_VARARGS, "Function to be called when a sensor has an error while coarse zeroing."}, + {"callbackOnErrorWhileFinzeZero", callbackOnErrorWhileFinzeZero_py, + METH_VARARGS, "Function to be called when a sensor has an error while fine zeroing"}, + {"callbackOnCompletionRestart", callbackOnCompletionRestart_py, + METH_VARARGS, "Function to be called when restarting has finished for all sensors."}, + {"callbackOnCompletionCoarseZero", callbackOnCompletionCoarseZero_py, + METH_VARARGS, "Function to be called when coarse zeroing has finished for all sensors."}, + {"callbackOnCompletionFineZero", callbackOnCompletionFineZero_py, + METH_VARARGS, "Function to be called when fine zeroing has finished for all sensors."}, {NULL, NULL, 0, NULL} }; -static PyModuleDef CallModule = { - PyModuleDef_HEAD_INIT, "calls", NULL, -1, callbacksMethods, +static PyModuleDef FieldlineCallbacksModule = { + PyModuleDef_HEAD_INIT, "fieldline_callbacks", NULL, -1, fieldlineCallbacksMethods, NULL, NULL, NULL, NULL }; -static PyObject* PyInit_calls(void) { - return PyModule_Create(&CallModule); +static PyObject* PyInit_fieldline_callbacks(void) { + return PyModule_Create(&FieldlineCallbacksModule); +} + +static FieldlineAcqSystem* acq_system(nullptr); + +struct dataValue { + double value; + char label[5+1]; +}; + +void dataParser(const dataValue* data, int size) { + double* samplesArray = new double[size]; + for (int i = 0; i < size; i++) { + samplesArray[i] = data[i].value; + // std::cout << "(" << data[i].label << ") - " << data[i].value << "\n"; + } + if (acq_system != nullptr) { + acq_system->m_pControllerParent->newData(samplesArray, size); + } +} + +static PyObject* dict_parser(PyObject* self, PyObject* args) { + PyObject* dataDict; + if (!PyArg_ParseTuple(args, "O", &dataDict)) { + PyErr_SetString(PyExc_TypeError, "data is not valid."); + return NULL; + } + + PyObject* data_frames = PyDict_GetItemString(dataDict, "data_frames"); + if (!data_frames || !PyDict_Check(data_frames)) { + PyErr_SetString(PyExc_TypeError, "data_frames is not a dictionary."); + return NULL; + } + + int num_channels = PyDict_Size(data_frames); + // std::cout << "Num channels: " << num_channels << "\n"; + // int* data = new int() + dataValue* dataValues = new dataValue[num_channels]; + PyObject* key; + PyObject* value; + PyObject* data; + PyObject* sensorName; + Py_ssize_t pos = 0; + + while (PyDict_Next(data_frames, &pos, &key, &value)) { + // int num_values = PyDict_Size(value); + // std::cout << "Num values: " << num_values << "\n"; + data = PyDict_GetItemString(value, "data"); + sensorName = PyDict_GetItemString(value, "sensor"); + // std::cout << "Sensor " << PyUnicode_AsUTF8(sensorName) + // << ": " << PyLong_AsLong(data) + // << " - pos: " << pos << "\n"; + dataValues[pos-1].value = (double) PyLong_AsLong(data); + memcpy((void*)dataValues[pos-1].label,(void*)PyUnicode_AsUTF8(sensorName), 5); + dataValues[pos-1].label[5] = static_cast(0); + } + + dataParser(dataValues, num_channels); + + delete[] dataValues; + return Py_None; +} + +static struct PyMethodDef callbacksParseMethods[] = { + {"dict_parser", dict_parser, METH_VARARGS, "Parse dictionary"}, + {NULL, NULL, 0, NULL} +}; + +static PyModuleDef CallbacksParseModule = { + PyModuleDef_HEAD_INIT, "callbacks_parsing", NULL, -1, callbacksParseMethods, + NULL, NULL, NULL, NULL +}; + +static PyObject* PyInit_callbacks_parsing(void) { + return PyModule_Create(&CallbacksParseModule); } FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) @@ -148,9 +295,22 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) m_pCallbackModule = loadModule("callback"); - m_pCallsModule = loadCModule("calls", *(void*(*)(void))&PyInit_calls); + m_pCallsModule = loadCModule("fieldline_callbacks", *(void*(*)(void))&PyInit_fieldline_callbacks); + PyObject* parseCallbacksModule = (PyObject*)loadCModule("callbacks_parsing", *(void*(*)(void))&PyInit_callbacks_parsing); + if (parseCallbacksModule == NULL) + { + printLog("callbacks module wrong!"); + } else{ + printLog("callbacks module ok!"); + } PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + if (FieldlineModule == NULL) + { + printLog("fieldline module wrong!"); + } else{ + printLog("fieldline module ok!"); + } PyObject* fService = PyObject_GetAttrString(FieldlineModule, "FieldLineService"); if (fService == NULL) @@ -161,7 +321,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } PyObject* ipList = Py_BuildValue("([ss])", "8.8.8.8", "1.1.1.1"); PyObject* fServiceInstance = PyObject_CallObject(fService, ipList); - printLog("here!!!"); + m_fServiceInstance = (void*) fServiceInstance; if (fServiceInstance == NULL) { printLog("fServiceInstance wrong!"); @@ -175,28 +335,107 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("openMethod ok!"); } - PyObject* pResult = PyObject_CallMethodNoArgs(fServiceInstance, PyUnicode_FromString("open")); + PyObject* pResult = PyObject_CallNoArgs(openMethod); if (pResult == NULL) { printLog("pResult wrong!"); } else{ printLog("pResult ok!"); } - PyObject* pResult2 = PyObject_CallNoArgs(openMethod); - if (pResult2 == NULL) + + PyObject* setCloseLoop = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); + PyObject* trueTuple = PyTuple_New(1); + PyTuple_SetItem(trueTuple, 0, Py_True); + PyObject* pResult2 = PyObject_CallObject(setCloseLoop, trueTuple); + + PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); + PyObject* sensors = PyObject_CallNoArgs(loadSensors); + PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); + + if (restartAllSensors == NULL) + { + printLog("restart sensors broken"); + } else { + printLog("restartAllSensors ok!"); + } + + PyObject* callback_on_finished = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileRestart"); + if (callback_on_finished == NULL) { - printLog("pResult2 wrong!"); - } else{ - printLog("pResult2 ok!"); + printLog("callback on finished broken"); + } else { + printLog("callback restart ok!"); + } + PyObject* callback_on_error = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileRestart"); + if (callback_on_error == NULL) + { + printLog("callback on error broken"); + } else { + printLog("callback error ok!"); + } + PyObject* callback_on_completion = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionRestart"); + if (callback_on_completion == NULL) + { + printLog("callback on completion broken"); + } else { + printLog("callback completion ok!"); } - Py_DECREF(FieldlineModule); - Py_DECREF(fService); - Py_DECREF(ipList); - Py_DECREF(fServiceInstance); - Py_DECREF(openMethod); - Py_DECREF(pResult); + PyObject* argsRestart = PyTuple_New(4); + PyTuple_SetItem(argsRestart, 0, sensors); + PyTuple_SetItem(argsRestart, 1, callback_on_finished); + PyTuple_SetItem(argsRestart, 2, callback_on_error); + PyTuple_SetItem(argsRestart, 3, callback_on_completion); + + restartFinished = false; + + PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); + while (restartFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + printLog("waiting..."); + } + + PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); + if (readDataFcn == NULL) { + printLog("problem readDataFcn"); + } else { + printLog("readDataFcn ok"); + } + + PyObject* parserCallback = PyObject_GetAttrString(parseCallbacksModule, "dict_parser"); + if (parserCallback == NULL) { + printLog("problem parserCallback"); + } else { + printLog("parserCallback ok"); + } + PyObject* argsSetDataParser = PyTuple_New(1); + PyTuple_SetItem(argsSetDataParser, 0, parserCallback); + + PyObject* result33 = PyObject_CallObject(readDataFcn, argsSetDataParser); + if (result33 == NULL) + { + printLog("result33 bad"); + } else { + printLog("result33 ok"); + } + + + // register "this" into somewhere findable by python's execution flow. + acq_system = this; + + // Py_DECREF(argsSetDataParser); + // Py_DECREF(setCloseLoop); + // Py_DECREF(trueTuple); + // Py_DECREF(pResult2); + // + // Py_DECREF(FieldlineModule); + // Py_DECREF(fService); + // Py_DECREF(ipList); + // Py_DECREF(fServiceInstance); + // Py_DECREF(openMethod); + // Py_DECREF(pResult); + // m_pThreadState = (void*)PyEval_SaveThread(); } @@ -213,37 +452,75 @@ void FieldlineAcqSystem::setCallback() PyGILState_STATE gstate; gstate = PyGILState_Ensure(); - PyObject *pSetCallbackFunc = NULL; - PyObject *pCallback1 = NULL; - PyObject *pArgs = NULL; - PyObject *pResult = NULL; + // PyObject *pSetCallbackFunc = NULL; + // PyObject *pCallback1 = NULL; + // PyObject *pArgs = NULL; + // PyObject *pResult = NULL; + // + // // Get a reference to the function + // pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); + // if (pSetCallbackFunc == NULL) { + // printLog(std::string("Error finding function: ").append("set_callback").c_str()); + // PyErr_Print(); + // } + // + // pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); + // if (pCallback1 && PyCallable_Check(pCallback1)) { + // pArgs = PyTuple_New(1); + // PyTuple_SetItem(pArgs, 0, pCallback1); + // } else { + // if (PyErr_Occurred()) + // PyErr_Print(); + // printLog(std::string("Cannot find function callback1 in calls module.")); + // } + // // Call the set_callback function + // pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); + // if (pResult == NULL) { + // printLog(std::string("Error calling function: ").append("set_callback").c_str()); + // PyErr_Print(); + // } + // Py_XDECREF(pSetCallbackFunc); + // Py_XDECREF(pCallback1); + // Py_XDECREF(pArgs); + // Py_XDECREF(pResult); + // + PyGILState_Release(gstate); +} - // Get a reference to the function - pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); - if (pSetCallbackFunc == NULL) { - printLog(std::string("Error finding function: ").append("set_callback").c_str()); - PyErr_Print(); - } +void FieldlineAcqSystem::startADC() { + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); - pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); - if (pCallback1 && PyCallable_Check(pCallback1)) { - pArgs = PyTuple_New(1); - PyTuple_SetItem(pArgs, 0, pCallback1); + PyObject* start_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "start_adc"); + PyObject* argsStartData = PyTuple_New(1); + PyObject* zeroArg = PyLong_FromLong(0); + PyTuple_SetItem(argsStartData, 0, zeroArg); + PyObject* startResult = PyObject_CallObject(start_data, argsStartData); + if (startResult == NULL) + { + printLog("startResult bad"); } else { - if (PyErr_Occurred()) - PyErr_Print(); - printLog(std::string("Cannot find function callback1 in calls module.")); + printLog("startResult ok"); } - // Call the set_callback function - pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); - if (pResult == NULL) { - printLog(std::string("Error calling function: ").append("set_callback").c_str()); - PyErr_Print(); + + PyGILState_Release(gstate); +} + +void FieldlineAcqSystem::stopADC() { + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject* stop_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "stop_adc"); + PyObject* argsstopData = PyTuple_New(1); + PyObject* stopArg = PyLong_FromLong(0); + PyTuple_SetItem(argsstopData, 0, stopArg); + PyObject* stopResult = PyObject_CallObject(stop_data, argsstopData); + if (stopResult == NULL) + { + printLog("stopResult bad"); + } else { + printLog("stopResult ok"); } - Py_XDECREF(pSetCallbackFunc); - Py_XDECREF(pCallback1); - Py_XDECREF(pArgs); - Py_XDECREF(pResult); PyGILState_Release(gstate); } @@ -344,8 +621,10 @@ void FieldlineAcqSystem::preConfigurePython() const Py_DECREF(versionInfo); PyObject* path = PyObject_GetAttrString(sys, "path"); - PyList_Insert(path, 0, PyUnicode_FromString(resourcesPath.c_str())); + PyObject* resourcesObj = PyUnicode_FromString(resourcesPath.c_str()); + PyList_Insert(path, 0, resourcesObj); Py_DECREF(sys); + Py_DECREF(resourcesObj); const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); printLog(pathVenvMods); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 12bd531e41e..b79de552c70 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -52,6 +52,9 @@ class FieldlineAcqSystem { void callFunction(const std::string moduleName, const std::string funcName); void setCallback(); + void startADC(); + void stopADC(); + Fieldline* m_pControllerParent; private: void preConfigurePython() const; @@ -59,7 +62,8 @@ class FieldlineAcqSystem { void* loadModule(const char* moduleName); void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); - Fieldline* m_pControllerParent; + // bool m_restartFinished; + void* m_fServiceInstance; void* m_pThreadState; void* m_pCallbackModule; void* m_pCallsModule; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 8a3e55a91a6..77a324412c0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -233,12 +233,14 @@ void FieldlineView::initAcqSystem(int numChassis) void FieldlineView::startAllSensors() { printLog("startAllSensors"); - m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "start"); + // m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "start"); + m_pFieldlinePlugin->m_pAcqSystem->startADC(); } void FieldlineView::stopAllSensors() { printLog("stopAllSensors"); - m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "stop"); + // m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "stop"); + m_pFieldlinePlugin->m_pAcqSystem->stopADC(); } void FieldlineView::autoTuneAllSensors() { diff --git a/src/applications/mne_scan/plugins/fieldline/notes.cpp b/src/applications/mne_scan/plugins/fieldline/notes.cpp new file mode 100644 index 00000000000..b90590ac452 --- /dev/null +++ b/src/applications/mne_scan/plugins/fieldline/notes.cpp @@ -0,0 +1,58 @@ + +//extern "C" { +// +//PyObject *restartFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - restart finished;\n"; +// } else { +// std::cout << "A sensor has finished restarting!\n"; +// } +// +// return NULL; +//} +//PyObject *coarseZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - coarse zero finished;\n"; +// } else { +// std::cout << "A sensor has finished coarse zeroing!\n"; +// } +// +// return NULL; +//} +//PyObject *fineZeroFinished(PyObject *self, PyObject *args) { +// long chassis, sensor; +// if (PyArg_ParseTuple(args, "ii", &chassis, &sensor)) { +// std::cout << std::setfill('0') << std::setw(2) << chassis << ":" << sensor +// << " - fine zero finished;\n"; +// } else { +// std::cout << "A sensor has finished fine zeroing!\n"; +// } +// +// return NULL; +//} +//} +// +//static PyMethodDef my_module_methods[] = { +// {"restartFinished", restartFinished, METH_VARARGS, " "}, +// {"coarseZeroFinished", coarseZeroFinished, METH_VARARGS, " "}, +// {"fineZeroFinished", fineZeroFinished, METH_VARARGS, " "}, +// {NULL, NULL, 0, NULL}}; +// +//static PyModuleDef my_module_def = { +// PyModuleDef_HEAD_INIT, +// "mne_cpp_callbacks", +// "A module of callback functions for mne-cpp.", +// -1, +// my_module_methods, +// NULL, +// NULL, +// NULL, +// NULL}; +// +//PyMODINIT_FUNC PyInit_my_module(void) { +// return PyModule_Create(&my_module_def); +//} From 41fa5af21ab5d313d9e2020cbe669c3be5530f09 Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 11 May 2023 00:35:52 -0400 Subject: [PATCH 133/147] troubleshooting connection --- .../fieldline_api_mock/fieldline_service.py | 3 +- .../mne_scan/plugins/fieldline/fieldline.cpp | 40 ++++++---- .../mne_scan/plugins/fieldline/fieldline.h | 3 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 73 +++++++++---------- .../plugins/fieldline/fieldline_acqsystem.h | 7 +- 5 files changed, 70 insertions(+), 56 deletions(-) diff --git a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py index bc99bd8206b..caa79c85fe9 100644 --- a/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py +++ b/resources/mne_scan/plugins/fieldline/fieldline_api_mock/fieldline_service.py @@ -114,7 +114,8 @@ def data_acquisition(self): end_time = time.time() elapsed_time = end_time - start_time # time_to_sleep = max(0, .001 - elapsed_time) - time.sleep(abs(sampling_period + elapsed_time_diff - 0.7 * elapsed_time)) + # time.sleep(abs(sampling_period + elapsed_time_diff - 0.7 * elapsed_time)) + time.sleep(sampling_period) # print(f"elapsed_time: {elapsed_time:04}") # start_time = time.time() # end_time = time.time() diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index f4c9f8ccf95..60dad087f82 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -132,9 +132,8 @@ namespace FIELDLINEPLUGIN { Fieldline::Fieldline() : m_pAcqSystem(nullptr) -, m_pCircularBuffer(QSharedPointer(new UTILSLIB::CircularBuffer_Matrix_double(10))) +, m_pFiffInfo(QSharedPointer(new FIFFLIB::FiffInfo())) { - // printLog("constructor fieldline plugin"); } //============================================================================================================= @@ -159,11 +158,10 @@ void Fieldline::init() { printLog("Fieldline init"); m_pCircularBuffer = QSharedPointer::create(40); - // data infrastructure m_pRTMSA = SCSHAREDLIB::PluginOutputData ::create(this, "Fieldline Plugin", "FieldlinePlguin output"); - m_pRTMSA->measurementData()->setName(this->getName()); // Provide name to auto store widget settings + m_pRTMSA->measurementData()->setName(this->getName()); m_outputConnectors.append(m_pRTMSA); m_pAcqSystem = new FieldlineAcqSystem(this); @@ -190,11 +188,10 @@ bool Fieldline::start() void Fieldline::initFiffInfo() { - QSharedPointer info; - info->sfreq = 1000.0f; - info->nchan = 32; - info->chs.clear(); - for (int chan_i = 0; chan_i < info->nchan; chan_i++) { + m_pFiffInfo->sfreq = 1000.0f; + m_pFiffInfo->nchan = 33; + m_pFiffInfo->chs.clear(); + for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; chan_i++) { FIFFLIB::FiffChInfo channel; channel.kind = FIFFV_MEG_CH; channel.unit = FIFF_UNIT_T; @@ -202,11 +199,11 @@ void Fieldline::initFiffInfo() channel.chpos.coil_type = FIFFV_COIL_NONE; std::string channel_name(std::string("Ch. ") + std::to_string(chan_i)); channel.ch_name = QString::fromStdString(channel_name); - info->chs.append(channel); - info->ch_names.append(QString::fromStdString(channel_name)); + m_pFiffInfo->chs.append(channel); + m_pFiffInfo->ch_names.append(QString::fromStdString(channel_name)); } - m_pRTMSA->measurementData()->initFromFiffInfo(info); + m_pRTMSA->measurementData()->initFromFiffInfo(m_pFiffInfo); m_pRTMSA->measurementData()->setMultiArraySize(1); m_pRTMSA->measurementData()->setVisibility(true); } @@ -265,13 +262,17 @@ void Fieldline::findIpAsync(std::vector& macList, //============================================================================================================= -void Fieldline::run() +void Fieldline::run() { Eigen::MatrixXd matData; + matData.resize(m_pFiffInfo->nchan, 200); while (!isInterruptionRequested()) { if (m_pCircularBuffer->pop(matData)) { if (!isInterruptionRequested()) { + // matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + matData *= 4e-12; + // msleep(200); m_pRTMSA->measurementData()->setValue(matData); } } @@ -285,9 +286,18 @@ QString Fieldline::getBuildInfo() { return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); } -void Fieldline::newData(double* data, size_t numChannels) +//============================================================================================================= + +void Fieldline::newData(double* data, size_t numChannels, size_t numSamples) { - while(!m_pCircularBuffer->push(Eigen::Map(data, 1, numChannels))) { + Eigen::MatrixXd matData; + matData.resize(numChannels, numSamples); + for (size_t i = 0; i < numChannels; i++) { + for (size_t j = 0; j < numSamples; j++) { + matData(i, j) = data[i * numSamples + j]; + } + } + while (!m_pCircularBuffer->push(matData)) { printLog("Fieldline Plugin: Pushing data to circular buffer failed... Trying again."); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.h b/src/applications/mne_scan/plugins/fieldline/fieldline.h index 55b9ddc76ec..35310c06e7a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.h @@ -52,6 +52,7 @@ #include #include +#include //============================================================================================================= // FORWARD DECLARATION @@ -116,7 +117,7 @@ class FIELDLINESHARED_EXPORT Fieldline : public SCSHAREDLIB::AbstractSensor std::function&)> callback); FieldlineAcqSystem* m_pAcqSystem; - void newData(double* data, size_t numChannels); + void newData(double* data, size_t numChannels, size_t numSamples); protected: virtual void run(); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 051bcbafa2d..8b3cf9456ed 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -213,22 +213,6 @@ static PyObject* PyInit_fieldline_callbacks(void) { static FieldlineAcqSystem* acq_system(nullptr); -struct dataValue { - double value; - char label[5+1]; -}; - -void dataParser(const dataValue* data, int size) { - double* samplesArray = new double[size]; - for (int i = 0; i < size; i++) { - samplesArray[i] = data[i].value; - // std::cout << "(" << data[i].label << ") - " << data[i].value << "\n"; - } - if (acq_system != nullptr) { - acq_system->m_pControllerParent->newData(samplesArray, size); - } -} - static PyObject* dict_parser(PyObject* self, PyObject* args) { PyObject* dataDict; if (!PyArg_ParseTuple(args, "O", &dataDict)) { @@ -242,32 +226,16 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { return NULL; } - int num_channels = PyDict_Size(data_frames); - // std::cout << "Num channels: " << num_channels << "\n"; - // int* data = new int() - dataValue* dataValues = new dataValue[num_channels]; PyObject* key; PyObject* value; - PyObject* data; - PyObject* sensorName; Py_ssize_t pos = 0; while (PyDict_Next(data_frames, &pos, &key, &value)) { - // int num_values = PyDict_Size(value); - // std::cout << "Num values: " << num_values << "\n"; - data = PyDict_GetItemString(value, "data"); - sensorName = PyDict_GetItemString(value, "sensor"); - // std::cout << "Sensor " << PyUnicode_AsUTF8(sensorName) - // << ": " << PyLong_AsLong(data) - // << " - pos: " << pos << "\n"; - dataValues[pos-1].value = (double) PyLong_AsLong(data); - memcpy((void*)dataValues[pos-1].label,(void*)PyUnicode_AsUTF8(sensorName), 5); - dataValues[pos-1].label[5] = static_cast(0); + PyObject* data = PyDict_GetItemString(value, "data"); + // printLog(std::string("pos: ") + std::to_string(pos)); + // printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); + acq_system->addSampleToSamplesColumn((int) pos-1, (double) PyLong_AsLong(data)); } - - dataParser(dataValues, num_channels); - - delete[] dataValues; return Py_None; } @@ -286,7 +254,9 @@ static PyObject* PyInit_callbacks_parsing(void) { } FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) -: m_pControllerParent(parent) +: m_pControllerParent(parent), + m_numSamplesPerBlock(200), + m_numSensors(33) { Py_Initialize(); @@ -423,7 +393,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // register "this" into somewhere findable by python's execution flow. acq_system = this; - + initSampleArrays(); // Py_DECREF(argsSetDataParser); // Py_DECREF(setCloseLoop); // Py_DECREF(trueTuple); @@ -647,5 +617,32 @@ void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) co } } +void FieldlineAcqSystem::initSampleArrays() +{ + m_samplesBlock = new double[m_numSensors * m_numSamplesPerBlock]; + m_samplesBlock2 = new double[m_numSensors * m_numSamplesPerBlock]; +} + +void FieldlineAcqSystem::addSampleToSamplesColumn(int sensorIdx, double value) +{ + static int sampleIdx = 0; + // printLog(std::string("sensorIdx: ") + std::to_string(sensorIdx)); + // printLog(std::string("sampleIdx: ") + std::to_string(sampleIdx)); + // printLog(std::string("m_numSensors = ") + std::to_string(m_numSensors)); + // printLog(std::string("m_numSamplesPerBlock = ") + std::to_string(m_numSamplesPerBlock)); + // printLog(std::string("m_samplesBlock[").append(std::to_string(sensorIdx * m_numSamplesPerBlock + sampleIdx)).append("] = ").append(std::to_string(value))); + m_samplesBlock[sensorIdx * m_numSamplesPerBlock + sampleIdx] = value; + if (sensorIdx == m_numSensors -1) { + sampleIdx++; + if (sampleIdx == m_numSamplesPerBlock) { + sampleIdx = 0; + memcpy((void*)m_samplesBlock2, (void*)m_samplesBlock, m_numSamplesPerBlock * m_numSensors); + std::thread([this](){ + m_pControllerParent->newData(m_samplesBlock2, m_numSensors, m_numSamplesPerBlock); + }); + } + } +} + } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index b79de552c70..5c5e619d543 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -55,6 +55,8 @@ class FieldlineAcqSystem { void startADC(); void stopADC(); Fieldline* m_pControllerParent; + void initSampleArrays(); + void addSampleToSamplesColumn(int sensorIdx, double value); private: void preConfigurePython() const; @@ -62,11 +64,14 @@ class FieldlineAcqSystem { void* loadModule(const char* moduleName); void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); - // bool m_restartFinished; + int m_numSamplesPerBlock; + int m_numSensors; void* m_fServiceInstance; void* m_pThreadState; void* m_pCallbackModule; void* m_pCallsModule; + double* m_samplesBlock; + double* m_samplesBlock2; }; } // namespace FIELDLINEPLUGIN From 93ed6f916423237e5dba98ca4fbd1c85cb8369af Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 11 May 2023 00:44:13 -0400 Subject: [PATCH 134/147] something wrong with circularbuffer --- .../mne_scan/plugins/fieldline/fieldline.cpp | 34 ++++++++++--------- .../plugins/fieldline/fieldline_acqsystem.cpp | 9 ++--- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 60dad087f82..1520542591b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -264,19 +264,19 @@ void Fieldline::findIpAsync(std::vector& macList, void Fieldline::run() { - Eigen::MatrixXd matData; - matData.resize(m_pFiffInfo->nchan, 200); - - while (!isInterruptionRequested()) { - if (m_pCircularBuffer->pop(matData)) { - if (!isInterruptionRequested()) { - // matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); - matData *= 4e-12; - // msleep(200); - m_pRTMSA->measurementData()->setValue(matData); - } - } - } + // Eigen::MatrixXd matData; + // matData.resize(m_pFiffInfo->nchan, 200); + // + // while (!isInterruptionRequested()) { + // if (m_pCircularBuffer->pop(matData)) { + // if (!isInterruptionRequested()) { + // // matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + // matData *= 4e-12; + // // msleep(200); + // m_pRTMSA->measurementData()->setValue(matData); + // } + // } + // } } //============================================================================================================= @@ -297,9 +297,11 @@ void Fieldline::newData(double* data, size_t numChannels, size_t numSamples) matData(i, j) = data[i * numSamples + j]; } } - while (!m_pCircularBuffer->push(matData)) { - printLog("Fieldline Plugin: Pushing data to circular buffer failed... Trying again."); - } + m_pRTMSA->measurementData()->setValue(matData); + // + // while (!m_pCircularBuffer->push(matData)) { + // printLog("Fieldline Plugin: Pushing data to circular buffer failed... Trying again."); + // } } } // namespace FIELDLINEPLUGIN diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 8b3cf9456ed..ed5c6b566fc 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -636,10 +636,11 @@ void FieldlineAcqSystem::addSampleToSamplesColumn(int sensorIdx, double value) sampleIdx++; if (sampleIdx == m_numSamplesPerBlock) { sampleIdx = 0; - memcpy((void*)m_samplesBlock2, (void*)m_samplesBlock, m_numSamplesPerBlock * m_numSensors); - std::thread([this](){ - m_pControllerParent->newData(m_samplesBlock2, m_numSensors, m_numSamplesPerBlock); - }); + m_pControllerParent->newData(m_samplesBlock, m_numSensors, m_numSamplesPerBlock); + // memcpy((void*)m_samplesBlock2, (void*)m_samplesBlock, m_numSamplesPerBlock * m_numSensors); + // std::thread([this](){ + // m_pControllerParent->newData(m_samplesBlock2, m_numSensors, m_numSamplesPerBlock); + // }); } } } From fecc80d30cabc067d772a4a8313c82342dd46f2d Mon Sep 17 00:00:00 2001 From: JuanGPC Date: Thu, 11 May 2023 10:48:08 -0400 Subject: [PATCH 135/147] review decref for pyobjects --- .../plugins/fieldline/fieldline_acqsystem.cpp | 78 ++++++++++++------- .../plugins/fieldline/fieldline_acqsystem.h | 2 +- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index ed5c6b566fc..3f69e5b1a8e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -394,26 +394,46 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // register "this" into somewhere findable by python's execution flow. acq_system = this; initSampleArrays(); - // Py_DECREF(argsSetDataParser); - // Py_DECREF(setCloseLoop); - // Py_DECREF(trueTuple); - // Py_DECREF(pResult2); - // - // Py_DECREF(FieldlineModule); - // Py_DECREF(fService); - // Py_DECREF(ipList); - // Py_DECREF(fServiceInstance); - // Py_DECREF(openMethod); - // Py_DECREF(pResult); - // + + Py_DECREF(parseCallbacksModule); + Py_DECREF(FieldlineModule); + Py_DECREF(fService); + Py_DECREF(ipList); + Py_DECREF(fServiceInstance); + Py_DECREF(openMethod); + Py_DECREF(pResult); + Py_DECREF(setCloseLoop); + Py_DECREF(trueTuple); + Py_DECREF(pResult2); + Py_DECREF(loadSensors); + Py_DECREF(restartAllSensors); + Py_DECREF(callback_on_finished); + Py_DECREF(callback_on_error); + Py_DECREF(callback_on_completion); + Py_DECREF(argsRestart); + Py_DECREF(resultRestart); + Py_DECREF(readDataFcn); + Py_DECREF(parserCallback); + Py_DECREF(argsSetDataParser); + Py_DECREF(result33); + m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() { PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); - Py_DECREF(m_pCallbackModule); - Py_DECREF(m_pCallsModule); + + Py_XDECREF(m_pCallbackModule); + Py_XDECREF(m_pCallsModule); + + if (m_samplesBlock) { + delete[] m_samplesBlock; + } + if (m_samplesBlock2) { + delete[] m_samplesBlock2; + } + Py_Finalize(); } @@ -473,6 +493,10 @@ void FieldlineAcqSystem::startADC() { printLog("startResult ok"); } + Py_DECREF(argsStartData); + Py_DECREF(zeroArg); + Py_DECREF(startResult); + PyGILState_Release(gstate); } @@ -492,6 +516,10 @@ void FieldlineAcqSystem::stopADC() { printLog("stopResult ok"); } + Py_DECREF(argsstopData); + Py_DECREF(stopArg); + Py_DECREF(stopResult); + PyGILState_Release(gstate); } @@ -506,6 +534,8 @@ void* FieldlineAcqSystem::loadModule(const char* moduleName) PyErr_Print(); } + Py_DECREF(pModule); + PyGILState_Release(gstate); return (void*)pModule; @@ -519,16 +549,14 @@ void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitF if (Py_IsInitialized()) { PyImport_AddModule(moduleName); - PyObject* pyModule = (PyObject*)moduleInitFunc(); + PyObject* PyModule = (PyObject*)moduleInitFunc(); PyObject* sys_modules = PyImport_GetModuleDict(); - PyDict_SetItemString(sys_modules, moduleName, pyModule); - Py_DECREF(pyModule); + PyDict_SetItemString(sys_modules, moduleName, PyModule); + Py_DECREF(PyModule); } else { PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); } - PyGILState_Release(gstate); - return loadModule(moduleName); } @@ -540,7 +568,7 @@ void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* f t.detach(); } -void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::string funcName) +void FieldlineAcqSystem::callFunction(const std::string& moduleName, const std::string& funcName) { PyGILState_STATE gstate; gstate = PyGILState_Ensure(); @@ -553,6 +581,7 @@ void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::s if (pModule == NULL) { PyErr_Print(); printLog(std::string("Import failed. Can't find ").append(moduleName).append(".").c_str()); + printLog("Check the Path."); } } @@ -560,20 +589,17 @@ void FieldlineAcqSystem::callFunction(const std::string moduleName, const std::s if (pFunc == NULL) { printLog(std::string("Error finding function: ").append(funcName).c_str()); PyErr_Print(); - Py_DECREF(pModule); } PyObject* pResult = PyObject_CallObject(pFunc, NULL); if (pResult == NULL) { printLog(std::string("Error calling function: ").append(funcName).c_str()); PyErr_Print(); - Py_DECREF(pModule); - Py_DECREF(pFunc); } - Py_DECREF(pModule); - Py_DECREF(pFunc); - Py_DECREF(pResult); + Py_XDECREF(pModule); + Py_XDECREF(pFunc); + Py_XDECREF(pResult); PyGILState_Release(gstate); } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 5c5e619d543..fc1f2eaba0d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -49,7 +49,7 @@ class FieldlineAcqSystem { void callFunctionAsync(const char* moduleName, const char* funcName); - void callFunction(const std::string moduleName, const std::string funcName); + void callFunction(const std::string& moduleName, const std::string& funcName); void setCallback(); void startADC(); From 6fdeaafb57d7caad8411679f43b3664788250758 Mon Sep 17 00:00:00 2001 From: juangpc Date: Tue, 16 May 2023 17:47:33 -0400 Subject: [PATCH 136/147] fix undefined PyExc_ValueError when linking python as shared lib --- .../mne_scan/plugins/fieldline/README.md | 21 +++++++++++++++++++ .../mne_scan/plugins/fieldline/CMakeLists.txt | 17 +++++++++------ .../plugins/fieldline/fieldline_acqsystem.cpp | 17 ++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 resources/mne_scan/plugins/fieldline/README.md diff --git a/resources/mne_scan/plugins/fieldline/README.md b/resources/mne_scan/plugins/fieldline/README.md new file mode 100644 index 00000000000..97f7d89bc1f --- /dev/null +++ b/resources/mne_scan/plugins/fieldline/README.md @@ -0,0 +1,21 @@ +FieldLine API README + +Prerequisits: +- Python 3.8 needs to be installed - due to an issue in the shared memory library that was fixed +- Download api-example.zip and fieldline_api_XXX.whl + +1) Download and extract api-example.zip +2) cd api-example +3) python3.8 -m venv venv +4) . venv/bin/activate +5) pip install -r requirements-api.txt +6) pip install +7) python main.py + +Release Notes: +0.0.13 - add SENSOR_READY state +0.0.12 - fix wrong file include +0.0.11 - Add sensor status call +0.0.10 - Few API cleanup items +0.0.2 - add start_adc and stop_adc calls +0.0.1 - initial release diff --git a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt index cc3ff61385b..84330b3ea74 100644 --- a/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/fieldline/CMakeLists.txt @@ -197,12 +197,12 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -set(Python_VERSION_MAJOR "3") -set(Python_VERSION_MINOR "9") -set(Python_LIB_DIR "/opt/anaconda3/lib") -set(Python_INCLUDE_DIRS "-I/opt/anacnda3/include/python3.9") -set(Python_CFLAGS "-I/opt/anaconda3/include/python3.9 -I/opt/anaconda2/include/python3.9 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64") -set(Python_LDFLAGS "-L/opt/anaconda3/lib/python3.9/config-3.9-darwin -ldl -framework CoreFoundation") +# set(Python_VERSION_MAJOR "3") +# set(Python_VERSION_MINOR "9") +# set(Python_LIB_DIR "/opt/anaconda3/lib") +# set(Python_INCLUDE_DIRS "-I/opt/anacnda3/include/python3.9") +# set(Python_CFLAGS "-I/opt/anaconda3/include/python3.9 -I/opt/anaconda2/include/python3.9 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -fPIC -O2 -isystem /opt/anaconda3/include -arch x86_64") +# set(Python_LDFLAGS "-L/opt/anaconda3/lib/python3.9/config-3.9-darwin -ldl -framework CoreFoundation") separate_arguments(Python_INCLUDE_DIRS_NORM UNIX_COMMAND "${Python_INCLUDE_DIRS}") separate_arguments(Python_CFLAGS_NORM UNIX_COMMAND "${Python_CFLAGS}") @@ -234,6 +234,11 @@ target_link_libraries(${PROJECT_NAME} PRIVATE target_link_directories(${PROJECT_NAME} PRIVATE ${Python_LIB_DIR}) target_link_options(${PROJECT_NAME} PRIVATE ${Python_LDFLAGS_NORM}) +target_compile_definitions(${PROJECT_NAME} PRIVATE + PYTHON_VERSION_MAJOR=${Python_VERSION_MAJOR} + PYTHON_VERSION_MINOR=${Python_VERSION_MINOR} +) + # ################################################################### # ################################################################### # ################################################################### diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 3f69e5b1a8e..e06939f2840 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -40,6 +40,16 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#define QUOTE(str) #str +#define EXPAND_AND_QUOTE(str) QUOTE(str) + +const char libPythonBugFix[] = "libpython" + EXPAND_AND_QUOTE(PYTHON_VERSION_MAJOR) + "." + EXPAND_AND_QUOTE(PYTHON_VERSION_MINOR) + ".so"; + +#include #include #include #include @@ -258,6 +268,10 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) m_numSamplesPerBlock(200), m_numSensors(33) { + printLog("Initializing Python"); + printLog(libPythonBugFix); + void*const libBugFix = dlopen(libPythonBugFix, RTLD_LAZY | RTLD_GLOBAL); + Py_Initialize(); preConfigurePython(); @@ -274,7 +288,8 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) printLog("callbacks module ok!"); } - PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + // PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api.fieldline_service"); if (FieldlineModule == NULL) { printLog("fieldline module wrong!"); From 68b2cd8eaacdc65d4ea89103a92ad000da6c0088 Mon Sep 17 00:00:00 2001 From: juangpc Date: Tue, 16 May 2023 21:31:02 -0400 Subject: [PATCH 137/147] have client communicate with fieldline box --- .../plugins/fieldline/fieldline_acqsystem.cpp | 149 +++++++++++------- 1 file changed, 95 insertions(+), 54 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index e06939f2840..2912a7da73e 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -304,7 +304,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("fservice ok!"); } - PyObject* ipList = Py_BuildValue("([ss])", "8.8.8.8", "1.1.1.1"); + PyObject* ipList = Py_BuildValue("([ss])", "172.21.16.181", "172.21.16.139"); PyObject* fServiceInstance = PyObject_CallObject(fService, ipList); m_fServiceInstance = (void*) fServiceInstance; if (fServiceInstance == NULL) @@ -320,66 +320,101 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("openMethod ok!"); } - PyObject* pResult = PyObject_CallNoArgs(openMethod); - if (pResult == NULL) - { - printLog("pResult wrong!"); - } else{ - printLog("pResult ok!"); - } - PyObject* setCloseLoop = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); - PyObject* trueTuple = PyTuple_New(1); - PyTuple_SetItem(trueTuple, 0, Py_True); - PyObject* pResult2 = PyObject_CallObject(setCloseLoop, trueTuple); - PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); - PyObject* sensors = PyObject_CallNoArgs(loadSensors); - PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); + m_pThreadState = (void*)PyEval_SaveThread(); - if (restartAllSensors == NULL) - { - printLog("restart sensors broken"); - } else { - printLog("restartAllSensors ok!"); - } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - PyObject* callback_on_finished = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileRestart"); - if (callback_on_finished == NULL) - { - printLog("callback on finished broken"); - } else { - printLog("callback restart ok!"); - } - PyObject* callback_on_error = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileRestart"); - if (callback_on_error == NULL) - { - printLog("callback on error broken"); - } else { - printLog("callback error ok!"); - } - PyObject* callback_on_completion = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionRestart"); - if (callback_on_completion == NULL) - { - printLog("callback on completion broken"); - } else { - printLog("callback completion ok!"); - } + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); - PyObject* argsRestart = PyTuple_New(4); - PyTuple_SetItem(argsRestart, 0, sensors); - PyTuple_SetItem(argsRestart, 1, callback_on_finished); - PyTuple_SetItem(argsRestart, 2, callback_on_error); - PyTuple_SetItem(argsRestart, 3, callback_on_completion); + PyObject* pResult = PyObject_CallNoArgs(openMethod); + if (pResult == NULL) + { + printLog("pResult wrong!"); + } else{ + printLog("pResult ok!"); + } + + PyGILState_Release(gstate); - restartFinished = false; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); - PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); - while (restartFinished == false) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - printLog("waiting..."); - } + PyObject* setCloseLoop = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); + PyObject* trueTuple = PyTuple_New(1); + PyTuple_SetItem(trueTuple, 0, Py_True); + PyObject* pResult2 = PyObject_CallObject(setCloseLoop, trueTuple); + + PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); + PyObject* sensors = PyObject_CallNoArgs(loadSensors); + PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); + + if (restartAllSensors == NULL) + { + printLog("restart sensors broken"); + } else { + printLog("restartAllSensors ok!"); + } + + PyObject* callback_on_finished = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileRestart"); + if (callback_on_finished == NULL) + { + printLog("callback on finished broken"); + } else { + printLog("callback restart ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_error = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileRestart"); + if (callback_on_error == NULL) + { + printLog("callback on error broken"); + } else { + printLog("callback error ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_completion = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionRestart"); + if (callback_on_completion == NULL) + { + printLog("callback on completion broken"); + } else { + printLog("callback completion ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* argsRestart = PyTuple_New(4); + PyTuple_SetItem(argsRestart, 0, sensors); + PyTuple_SetItem(argsRestart, 1, callback_on_finished); + PyTuple_SetItem(argsRestart, 2, callback_on_error); + PyTuple_SetItem(argsRestart, 3, callback_on_completion); + + restartFinished = false; + + PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); + if (resultRestart == NULL) + { + printLog("restart call broken"); + } else { + printLog("restart call ok!"); + } + + PyGILState_Release(gstate); + // while (restartFinished == false) { + // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // printLog("waiting..."); + // } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); if (readDataFcn == NULL) { @@ -405,6 +440,11 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) printLog("result33 ok"); } + PyGILState_Release(gstate); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); // register "this" into somewhere findable by python's execution flow. acq_system = this; @@ -432,7 +472,8 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(argsSetDataParser); Py_DECREF(result33); - m_pThreadState = (void*)PyEval_SaveThread(); + PyGILState_Release(gstate); + // m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() From f997a4f9de08dfb6e86c2a84f9994016f72f4b5f Mon Sep 17 00:00:00 2001 From: juangpc Date: Tue, 16 May 2023 22:20:05 -0400 Subject: [PATCH 138/147] fix incref of Py_None obj --- .../mne_scan/plugins/fieldline/fieldline_acqsystem.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 2912a7da73e..63b9bbfcb05 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -112,6 +112,7 @@ static PyObject* callbackOnFinishedWhileRestart_py(PyObject* self, PyObject* arg return NULL; } callbackOnFinishedWhileRestart(chassis, sensor); + Py_INCREF(Py_None); return Py_None; } @@ -121,6 +122,7 @@ static PyObject* callbackOnFinishedWhileCoarseZero_py(PyObject* self, PyObject* return NULL; } callbackOnFinishedWhileCoarseZero(chassis, sensor); + Py_INCREF(Py_None); return Py_None; } @@ -130,6 +132,7 @@ static PyObject* callbackOnFinishedWhileFineZero_py(PyObject* self, PyObject* ar return NULL; } callbackOnFinishedWhileFineZero(chassis, sensor); + Py_INCREF(Py_None); return Py_None; } @@ -139,6 +142,7 @@ static PyObject* callbackOnErrorWhileRestart_py(PyObject* self, PyObject* args) return NULL; } callbackOnErrorWhileRestart(chassis, sensor, error); + Py_INCREF(Py_None); return Py_None; } @@ -148,6 +152,7 @@ static PyObject* callbackOnErrorWhileCoarseZero_py(PyObject* self, PyObject* arg return NULL; } callbackOnErrorWhileCoarseZero(chassis, sensor, error); + Py_INCREF(Py_None); return Py_None; } @@ -157,6 +162,7 @@ static PyObject* callbackOnErrorWhileFinzeZero_py(PyObject* self, PyObject* args return NULL; } callbackOnErrorWhileFineZero(chassis, sensor, error); + Py_INCREF(Py_None); return Py_None; } @@ -167,6 +173,7 @@ static PyObject* callbackOnCompletionRestart_py(PyObject* self, PyObject* args) return nullptr; } callbackOnCompletionRestart(); + Py_INCREF(Py_None); return Py_None; } @@ -177,6 +184,7 @@ static PyObject* callbackOnCompletionCoarseZero_py(PyObject* self, PyObject* arg return nullptr; } callbackOnCompletionCoarseZero(); + Py_INCREF(Py_None); return Py_None; } @@ -187,6 +195,7 @@ static PyObject* callbackOnCompletionFineZero_py(PyObject* self, PyObject* args) return nullptr; } callbackOnCompletionFineZero(); + Py_INCREF(Py_None); return Py_None; } @@ -246,6 +255,7 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { // printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); acq_system->addSampleToSamplesColumn((int) pos-1, (double) PyLong_AsLong(data)); } + Py_INCREF(Py_None); return Py_None; } From d2cabbfeb96b4de17aa3568dcb5b52fe748b1c5d Mon Sep 17 00:00:00 2001 From: juangpc Date: Tue, 16 May 2023 23:31:15 -0400 Subject: [PATCH 139/147] add coarse and fine zero interactions --- .../plugins/fieldline/fieldline_acqsystem.cpp | 191 ++++++++++++++++-- 1 file changed, 177 insertions(+), 14 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 63b9bbfcb05..bdaed42cf40 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -67,6 +67,8 @@ const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdStri const std::string entryFile(resourcesPath + "main.py"); bool restartFinished = false; +bool coarseZeroFinished = false; +bool fineZeroFinished = false; void callbackOnFinishedWhileRestart(int chassisId, int sensorId) { std::cout << "Sensor: (" << chassisId << ", " << sensorId << ") Finished restart.\n"; @@ -95,15 +97,17 @@ void callbackOnErrorWhileFineZero(int chassisId, int sensorId, int errorId) { void callbackOnCompletionRestart() { std::cout << "About to change restartFinished\n"; restartFinished = true; - std::cout << "Restart of sensors, finished.\n"; + std::cout << "Restarting sensors, finished.\n"; } void callbackOnCompletionCoarseZero() { - std::cout << "Coarse zero of sensors, finished.\n"; + coarseZeroFinished = true; + std::cout << "Coarse zero sensors, finished.\n"; } void callbackOnCompletionFineZero() { - std::cout << "Fine zero of sensors, finished.\n"; + fineZeroFinished = true; + std::cout << "Fine zero sensors, finished.\n"; } static PyObject* callbackOnFinishedWhileRestart_py(PyObject* self, PyObject* args) { @@ -361,6 +365,8 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); PyObject* sensors = PyObject_CallNoArgs(loadSensors); + // ========================================================================= + // ========================================================================= PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); if (restartAllSensors == NULL) @@ -416,16 +422,179 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) printLog("restart call ok!"); } + Py_DECREF(restartAllSensors); + Py_DECREF(callback_on_finished); + Py_DECREF(callback_on_error); + Py_DECREF(callback_on_completion); + Py_DECREF(argsRestart); + Py_DECREF(resultRestart); + PyGILState_Release(gstate); - // while (restartFinished == false) { - // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - // printLog("waiting..."); - // } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + while (restartFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + + // ========================================================================= + // =========== coarse zero ================================================= + // ========================================================================= + gstate = PyGILState_Ensure(); + + + PyObject* coarseZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "coarse_zero_sensors"); + + if (coarseZeroAllSensors == NULL) + { + printLog("coarse zero sensors broken"); + } else { + printLog("coarseZeroAllSensors ok!"); + } + + PyObject* callback_on_finished_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileCoarseZero"); + if (callback_on_finished_coarse_zero == NULL) + { + printLog("callback on finished coarse zero broken"); + } else { + printLog("callback on finished coarse zero ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_error_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileCoarseZero"); + if (callback_on_error_coarse_zero == NULL) + { + printLog("callback on error coarse zero broken"); + } else { + printLog("callback coarse zero error ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_completion_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionCoarseZero"); + if (callback_on_completion_coarse_zero == NULL) + { + printLog("callback on completion coarse zero broken"); + } else { + printLog("callback coarse zero completion ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* argsCoarseZero = PyTuple_New(4); + PyTuple_SetItem(argsCoarseZero, 0, sensors); + PyTuple_SetItem(argsCoarseZero, 1, callback_on_finished_coarse_zero); + PyTuple_SetItem(argsCoarseZero, 2, callback_on_error_coarse_zero); + PyTuple_SetItem(argsCoarseZero, 3, callback_on_completion_coarse_zero); + + coarseZeroFinished = false; + + PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensors, argsCoarseZero); + if (resultCoarseZero == NULL) + { + printLog("call coarsezero call broken"); + } else { + printLog("coarse zero call call ok!"); + } + + Py_DECREF(coarseZeroAllSensors); + Py_DECREF(callback_on_finished_coarse_zero); + Py_DECREF(callback_on_error_coarse_zero); + Py_DECREF(callback_on_completion_coarse_zero); + Py_DECREF(argsCoarseZero); + Py_DECREF(resultCoarseZero); + + PyGILState_Release(gstate); + + while (coarseZeroFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + // ========================================================================= + // ========================================================================= + + + // ========================================================================= + // ============ fine zero ================================================== + // ========================================================================= + gstate = PyGILState_Ensure(); + + + PyObject* fineZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "fine_zero_sensors"); + + if (fineZeroAllSensors == NULL) + { + printLog("fine zero sensors broken"); + } else { + printLog("fineZeroAllSensors ok!"); + } + + PyObject* callback_on_finished_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileFineZero"); + if (callback_on_finished_fine_zero == NULL) + { + printLog("callback on finished fine zero broken"); + } else { + printLog("callback on finished fine zero ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_error_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileFineZero"); + if (callback_on_error_fine_zero == NULL) + { + printLog("callback on error fine zero broken"); + } else { + printLog("callback fine zero error ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_completion_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionFineZero"); + if (callback_on_completion_fine_zero == NULL) + { + printLog("callback on completion fine zero broken"); + } else { + printLog("callback fine zero completion ok!"); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* argsFineZero = PyTuple_New(4); + PyTuple_SetItem(argsFineZero, 0, sensors); + PyTuple_SetItem(argsFineZero, 1, callback_on_finished_fine_zero); + PyTuple_SetItem(argsFineZero, 2, callback_on_error_fine_zero); + PyTuple_SetItem(argsFineZero, 3, callback_on_completion_fine_zero); + + fineZeroFinished = false; + + PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensors, argsFineZero); + if (resultFineZero == NULL) + { + printLog("call finezero call broken"); + } else { + printLog("fine zero call call ok!"); + } + + Py_DECREF(fineZeroAllSensors); + Py_DECREF(callback_on_finished_fine_zero); + Py_DECREF(callback_on_error_fine_zero); + Py_DECREF(callback_on_completion_fine_zero); + Py_DECREF(argsFineZero); + Py_DECREF(resultFineZero); + + PyGILState_Release(gstate); + + while (fineZeroFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + // ========================================================================= + // ========================================================================= + + // // PyGILState_STATE gstate; gstate = PyGILState_Ensure(); + PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); if (readDataFcn == NULL) { printLog("problem readDataFcn"); @@ -471,12 +640,6 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(trueTuple); Py_DECREF(pResult2); Py_DECREF(loadSensors); - Py_DECREF(restartAllSensors); - Py_DECREF(callback_on_finished); - Py_DECREF(callback_on_error); - Py_DECREF(callback_on_completion); - Py_DECREF(argsRestart); - Py_DECREF(resultRestart); Py_DECREF(readDataFcn); Py_DECREF(parserCallback); Py_DECREF(argsSetDataParser); From 0c2eca08d9c1c891d7a1303ccafce656e1aa28dc Mon Sep 17 00:00:00 2001 From: juangpc Date: Wed, 17 May 2023 12:16:42 -0400 Subject: [PATCH 140/147] improve reference counting --- .../plugins/fieldline/fieldline_acqsystem.cpp | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index bdaed42cf40..237b336c951 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -284,6 +284,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) { printLog("Initializing Python"); printLog(libPythonBugFix); + void*const libBugFix = dlopen(libPythonBugFix, RTLD_LAZY | RTLD_GLOBAL); Py_Initialize(); @@ -327,13 +328,9 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("fServiceInstance ok!"); } - PyObject* openMethod = PyObject_GetAttrString(fServiceInstance, "open"); - if (openMethod == NULL) - { - printLog("openMethod wrong!"); - } else{ - printLog("openMethod ok!"); - } + + Py_DECREF(ipList); + m_pThreadState = (void*)PyEval_SaveThread(); @@ -343,13 +340,22 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) PyGILState_STATE gstate; gstate = PyGILState_Ensure(); - PyObject* pResult = PyObject_CallNoArgs(openMethod); - if (pResult == NULL) + PyObject* openMethod = PyObject_GetAttrString(fServiceInstance, "open"); + if (openMethod == NULL) { - printLog("pResult wrong!"); + printLog("openMethod wrong!"); } else{ - printLog("pResult ok!"); - } + printLog("openMethod ok!"); + } + + PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); + if (openMethodCall == NULL) + { + printLog("openMethodCall wrong!"); + } else{ + printLog("openMethodCall ok!"); + } + Py_DECREF(openMethodCall); PyGILState_Release(gstate); @@ -357,16 +363,22 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // PyGILState_STATE gstate; gstate = PyGILState_Ensure(); + // ========================================================================= + // ========================================================================= PyObject* setCloseLoop = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); PyObject* trueTuple = PyTuple_New(1); PyTuple_SetItem(trueTuple, 0, Py_True); PyObject* pResult2 = PyObject_CallObject(setCloseLoop, trueTuple); + Py_DECREF(setCloseLoop); + Py_DECREF(trueTuple); + Py_DECREF(pResult2); PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); PyObject* sensors = PyObject_CallNoArgs(loadSensors); - // ========================================================================= - // ========================================================================= + Py_INCREF(loadSensors); + Py_INCREF(sensors); + PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); if (restartAllSensors == NULL) @@ -441,9 +453,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // ========================================================================= gstate = PyGILState_Ensure(); - PyObject* coarseZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "coarse_zero_sensors"); - if (coarseZeroAllSensors == NULL) { printLog("coarse zero sensors broken"); @@ -589,10 +599,13 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // ========================================================================= // ========================================================================= - // // PyGILState_STATE gstate; gstate = PyGILState_Ensure(); + Py_DECREF(loadSensors); + Py_XDECREF(loadSensors); + Py_DECREF(sensors); + Py_XDECREF(sensors); PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); @@ -632,14 +645,8 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(parseCallbacksModule); Py_DECREF(FieldlineModule); Py_DECREF(fService); - Py_DECREF(ipList); Py_DECREF(fServiceInstance); Py_DECREF(openMethod); - Py_DECREF(pResult); - Py_DECREF(setCloseLoop); - Py_DECREF(trueTuple); - Py_DECREF(pResult2); - Py_DECREF(loadSensors); Py_DECREF(readDataFcn); Py_DECREF(parserCallback); Py_DECREF(argsSetDataParser); From 26eed8ce2d8b34435962c0e1ffba3faa391b1b24 Mon Sep 17 00:00:00 2001 From: juangpc Date: Wed, 17 May 2023 15:26:09 -0400 Subject: [PATCH 141/147] fix typo in method name for fine zero callback --- .../plugins/fieldline/fieldline_acqsystem.cpp | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 237b336c951..67fb0e0b93b 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -87,11 +87,11 @@ void callbackOnErrorWhileRestart(int chassisId, int sensorId, int errorId) { } void callbackOnErrorWhileCoarseZero(int chassisId, int sensorId, int errorId) { - std::cout << "Error while restarting sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; + std::cout << "Error while coarse zeroing sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; } void callbackOnErrorWhileFineZero(int chassisId, int sensorId, int errorId) { - std::cout << "Error while restarting sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; + std::cout << "Error while fine zeroing sensor: (" << chassisId << ", " << sensorId << ") Code: " << errorId << ".\n"; } void callbackOnCompletionRestart() { @@ -214,7 +214,7 @@ static struct PyMethodDef fieldlineCallbacksMethods[] = { METH_VARARGS, "Function to be called when a sensor has an error while restarting."}, {"callbackOnErrorWhileCoarseZero", callbackOnErrorWhileCoarseZero_py, METH_VARARGS, "Function to be called when a sensor has an error while coarse zeroing."}, - {"callbackOnErrorWhileFinzeZero", callbackOnErrorWhileFinzeZero_py, + {"callbackOnErrorWhileFineZero", callbackOnErrorWhileFinzeZero_py, METH_VARARGS, "Function to be called when a sensor has an error while fine zeroing"}, {"callbackOnCompletionRestart", callbackOnCompletionRestart_py, METH_VARARGS, "Function to be called when restarting has finished for all sensors."}, @@ -328,11 +328,10 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("fServiceInstance ok!"); } + Py_DECREF(fService); Py_DECREF(ipList); - - m_pThreadState = (void*)PyEval_SaveThread(); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); @@ -355,11 +354,13 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("openMethodCall ok!"); } + Py_DECREF(openMethod); Py_DECREF(openMethodCall); PyGILState_Release(gstate); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // PyGILState_STATE gstate; gstate = PyGILState_Ensure(); @@ -528,7 +529,6 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) // ========================================================================= gstate = PyGILState_Ensure(); - PyObject* fineZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "fine_zero_sensors"); if (fineZeroAllSensors == NULL) @@ -568,8 +568,11 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + PyObject* loadSensors3 = PyObject_GetAttrString(fServiceInstance, "load_sensors"); + PyObject* sensors3 = PyObject_CallNoArgs(loadSensors); + PyObject* argsFineZero = PyTuple_New(4); - PyTuple_SetItem(argsFineZero, 0, sensors); + PyTuple_SetItem(argsFineZero, 0, sensors3); PyTuple_SetItem(argsFineZero, 1, callback_on_finished_fine_zero); PyTuple_SetItem(argsFineZero, 2, callback_on_error_fine_zero); PyTuple_SetItem(argsFineZero, 3, callback_on_completion_fine_zero); @@ -583,6 +586,10 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else { printLog("fine zero call call ok!"); } + Py_DECREF(sensors); + + Py_DECREF(sensors3); + Py_DECREF(loadSensors3); Py_DECREF(fineZeroAllSensors); Py_DECREF(callback_on_finished_fine_zero); @@ -624,13 +631,17 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) PyObject* argsSetDataParser = PyTuple_New(1); PyTuple_SetItem(argsSetDataParser, 0, parserCallback); - PyObject* result33 = PyObject_CallObject(readDataFcn, argsSetDataParser); - if (result33 == NULL) + PyObject* readDataReturn = PyObject_CallObject(readDataFcn, argsSetDataParser); + if (readDataReturn == NULL) { - printLog("result33 bad"); + printLog("readDataReturn bad"); } else { - printLog("result33 ok"); + printLog("readDataReturn ok"); } + Py_DECREF(readDataReturn); + Py_DECREF(readDataFcn); + Py_DECREF(parserCallback); + Py_DECREF(argsSetDataParser); PyGILState_Release(gstate); @@ -644,13 +655,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(parseCallbacksModule); Py_DECREF(FieldlineModule); - Py_DECREF(fService); Py_DECREF(fServiceInstance); - Py_DECREF(openMethod); - Py_DECREF(readDataFcn); - Py_DECREF(parserCallback); - Py_DECREF(argsSetDataParser); - Py_DECREF(result33); PyGILState_Release(gstate); // m_pThreadState = (void*)PyEval_SaveThread(); From 70b316dee175534b012f05b59b316bd6eedab45f Mon Sep 17 00:00:00 2001 From: juangpc Date: Fri, 19 May 2023 11:06:02 -0400 Subject: [PATCH 142/147] refactor for real time data. not working --- .../plugins/fieldline/fieldline_acqsystem.cpp | 91 +++++++++---------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 67fb0e0b93b..b552db6ef56 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -255,8 +255,8 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { while (PyDict_Next(data_frames, &pos, &key, &value)) { PyObject* data = PyDict_GetItemString(value, "data"); - // printLog(std::string("pos: ") + std::to_string(pos)); - // printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); + printLog(std::string("pos: ") + std::to_string(pos)); + printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); acq_system->addSampleToSamplesColumn((int) pos-1, (double) PyLong_AsLong(data)); } Py_INCREF(Py_None); @@ -280,7 +280,7 @@ static PyObject* PyInit_callbacks_parsing(void) { FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent), m_numSamplesPerBlock(200), - m_numSensors(33) + m_numSensors(19) { printLog("Initializing Python"); printLog(libPythonBugFix); @@ -360,7 +360,7 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) PyGILState_Release(gstate); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - + // PyGILState_STATE gstate; gstate = PyGILState_Ensure(); @@ -427,26 +427,26 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) restartFinished = false; - PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); - if (resultRestart == NULL) - { - printLog("restart call broken"); - } else { - printLog("restart call ok!"); - } - - Py_DECREF(restartAllSensors); + //PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); + //if (resultRestart == NULL) + //{ + //printLog("restart call broken"); + //} else { + //printLog("restart call ok!"); + //} + // + //Py_DECREF(restartAllSensors); Py_DECREF(callback_on_finished); Py_DECREF(callback_on_error); Py_DECREF(callback_on_completion); Py_DECREF(argsRestart); - Py_DECREF(resultRestart); + //Py_DECREF(resultRestart); PyGILState_Release(gstate); - while (restartFinished == false) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - } + //while (restartFinished == false) { + //std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + //} std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // ========================================================================= @@ -500,26 +500,26 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) coarseZeroFinished = false; - PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensors, argsCoarseZero); - if (resultCoarseZero == NULL) - { - printLog("call coarsezero call broken"); - } else { - printLog("coarse zero call call ok!"); - } + //PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensors, argsCoarseZero); + //if (resultCoarseZero == NULL) + //{ + // printLog("call coarsezero call broken"); + //} else { + // printLog("coarse zero call call ok!"); + //} Py_DECREF(coarseZeroAllSensors); Py_DECREF(callback_on_finished_coarse_zero); Py_DECREF(callback_on_error_coarse_zero); Py_DECREF(callback_on_completion_coarse_zero); Py_DECREF(argsCoarseZero); - Py_DECREF(resultCoarseZero); + //Py_DECREF(resultCoarseZero); PyGILState_Release(gstate); - while (coarseZeroFinished == false) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - } + //while (coarseZeroFinished == false) { + // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + //} // ========================================================================= // ========================================================================= @@ -579,13 +579,13 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) fineZeroFinished = false; - PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensors, argsFineZero); - if (resultFineZero == NULL) - { - printLog("call finezero call broken"); - } else { - printLog("fine zero call call ok!"); - } + //PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensors, argsFineZero); + //if (resultFineZero == NULL) + //{ + // printLog("call finezero call broken"); + //} else { + // printLog("fine zero call call ok!"); + //} Py_DECREF(sensors); Py_DECREF(sensors3); @@ -596,23 +596,22 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(callback_on_error_fine_zero); Py_DECREF(callback_on_completion_fine_zero); Py_DECREF(argsFineZero); - Py_DECREF(resultFineZero); + //Py_DECREF(resultFineZero); - PyGILState_Release(gstate); + //PyGILState_Release(gstate); - while (fineZeroFinished == false) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - } + // while (fineZeroFinished == false) { + // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // } // ========================================================================= // ========================================================================= - // PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + //gstate = PyGILState_Ensure(); - Py_DECREF(loadSensors); - Py_XDECREF(loadSensors); - Py_DECREF(sensors); - Py_XDECREF(sensors); + //Py_DECREF(loadSensors); + //Py_XDECREF(loadSensors); + //Py_DECREF(sensors); + //Py_XDECREF(sensors); PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); From 814ef2c8d7a16ff613ca9539a1507a98e8af340e Mon Sep 17 00:00:00 2001 From: juangpc Date: Fri, 19 May 2023 18:00:32 -0400 Subject: [PATCH 143/147] debug interaction with python --- .../mne_scan/plugins/fieldline/callback.py | 63 -- .../mne_scan/plugins/fieldline/fieldline.cpp | 7 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 641 ++++++++++-------- .../plugins/fieldline/fieldline_acqsystem.h | 7 +- .../plugins/fieldline/fieldline_view.cpp | 17 +- 5 files changed, 369 insertions(+), 366 deletions(-) delete mode 100644 resources/mne_scan/plugins/fieldline/callback.py diff --git a/resources/mne_scan/plugins/fieldline/callback.py b/resources/mne_scan/plugins/fieldline/callback.py deleted file mode 100644 index f654b33cb8b..00000000000 --- a/resources/mne_scan/plugins/fieldline/callback.py +++ /dev/null @@ -1,63 +0,0 @@ -import time -import threading - -time_to_sleep = 0.5 -keep_running = True -counter = 0 - - -# default callback function that prints its name -def default_callback1(): - # print("... default_callback") - global counter - print(f'Counter: {counter}') - counter += 1 - - -def default_callback2(): - with open("output.txt", "a") as f: - f.write("default_callback2\n") - - -callback = default_callback1 - - -# function to set the callback -def set_callback(new_callback=None): - global callback - if new_callback is None: - print('Setting the default callback.') - callback = default_callback2 - else: - print('Setting new callback.') - callback = new_callback - - -# function to call the callback every second -def run(): - global keep_running - global time_to_sleep - global counter - keep_running = True - while keep_running: - callback() - time.sleep(time_to_sleep) - - -# function to stop the callback loop -def stop(): - global keep_running - global counter - keep_running = False - print(f'Global counter: {counter}') - - -def start(): - t = threading.Thread(target=run) - t.start() - - -# if __name__ == '__main__': -# pass -# - diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 1520542591b..e3f0d95a14d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -182,6 +182,11 @@ bool Fieldline::start() initFiffInfo(); + std::thread t([this]{ + m_pAcqSystem->startADC(); + }); + t.detach(); + QThread::start(); return true; } @@ -189,7 +194,7 @@ bool Fieldline::start() void Fieldline::initFiffInfo() { m_pFiffInfo->sfreq = 1000.0f; - m_pFiffInfo->nchan = 33; + m_pFiffInfo->nchan = 2; m_pFiffInfo->chs.clear(); for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; chan_i++) { FIFFLIB::FiffChInfo channel; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index b552db6ef56..52e776d521a 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -66,6 +66,85 @@ const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdStri "/../resources/mne_scan/plugins/fieldline/"); const std::string entryFile(resourcesPath + "main.py"); +struct GILHandler { + GILHandler():isAcquired(false) { + acquireGIL(); + } + + ~GILHandler() { + releaseGIL(); + } + + void acquireGIL() { + if (!isAcquired) { + m_gstate = PyGILState_Ensure(); + isAcquired = true; + } + } + void releaseGIL() { + if (isAcquired) { + PyGILState_Release(m_gstate); + isAcquired = false; + } + } + + bool isAcquired; + PyGILState_STATE m_gstate; +}; + +struct AcqOpener { + AcqOpener(PyObject* s): m_serviceInstance(s) { + openAcq(); + } + ~AcqOpener() { + closeAcq(); + } + + void openAcq() { + PyObject* openMethod = PyObject_GetAttrString(m_serviceInstance, "open"); + if (openMethod == NULL) + { + printLog("openMethod wrong!"); + } else{ + printLog("openMethod ok!"); + } + + PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); + if (openMethodCall == NULL) + { + printLog("openMethodCall wrong!"); + } else{ + printLog("openMethodCall ok!"); + } + Py_DECREF(openMethod); + Py_DECREF(openMethodCall); + } + + void closeAcq() { + PyObject* closeMethod = PyObject_GetAttrString(m_serviceInstance, "close"); + if (closeMethod == NULL) + { + printLog("closeMethod wrong!"); + } else{ + printLog("closeMethod ok!"); + } + + PyObject* closeMethodCall = PyObject_CallNoArgs(closeMethod); + if (closeMethodCall == NULL) + { + printLog("closeMethodCall wrong!"); + } else{ + printLog("closeMethodCall ok!"); + } + + Py_DECREF(closeMethod); + Py_DECREF(closeMethodCall); + } + + PyObject* m_serviceInstance; + +}; + bool restartFinished = false; bool coarseZeroFinished = false; bool fineZeroFinished = false; @@ -239,12 +318,14 @@ static FieldlineAcqSystem* acq_system(nullptr); static PyObject* dict_parser(PyObject* self, PyObject* args) { PyObject* dataDict; if (!PyArg_ParseTuple(args, "O", &dataDict)) { + printLog("problem with dataDict."); PyErr_SetString(PyExc_TypeError, "data is not valid."); return NULL; } PyObject* data_frames = PyDict_GetItemString(dataDict, "data_frames"); if (!data_frames || !PyDict_Check(data_frames)) { + printLog("Problem with data frames."); PyErr_SetString(PyExc_TypeError, "data_frames is not a dictionary."); return NULL; } @@ -258,6 +339,8 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { printLog(std::string("pos: ") + std::to_string(pos)); printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); acq_system->addSampleToSamplesColumn((int) pos-1, (double) PyLong_AsLong(data)); + if (pos == 2) + break; } Py_INCREF(Py_None); return Py_None; @@ -280,31 +363,23 @@ static PyObject* PyInit_callbacks_parsing(void) { FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent), m_numSamplesPerBlock(200), - m_numSensors(19) + m_numSensors(2) { printLog("Initializing Python"); printLog(libPythonBugFix); void*const libBugFix = dlopen(libPythonBugFix, RTLD_LAZY | RTLD_GLOBAL); + + acq_system = this; Py_Initialize(); preConfigurePython(); - m_pCallbackModule = loadModule("callback"); - - m_pCallsModule = loadCModule("fieldline_callbacks", *(void*(*)(void))&PyInit_fieldline_callbacks); - PyObject* parseCallbacksModule = (PyObject*)loadCModule("callbacks_parsing", *(void*(*)(void))&PyInit_callbacks_parsing); - if (parseCallbacksModule == NULL) - { - printLog("callbacks module wrong!"); - } else{ - printLog("callbacks module ok!"); - } - // PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); - PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api.fieldline_service"); + PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + //PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api.fieldline_service"); if (FieldlineModule == NULL) { printLog("fieldline module wrong!"); @@ -328,299 +403,310 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) } else{ printLog("fServiceInstance ok!"); } - Py_DECREF(fService); + Py_DECREF(FieldlineModule); + Py_DECREF(fService); Py_DECREF(ipList); - m_pThreadState = (void*)PyEval_SaveThread(); - - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + setDataCallback(); - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + { + AcqOpener o((PyObject*)m_fServiceInstance); - PyObject* openMethod = PyObject_GetAttrString(fServiceInstance, "open"); - if (openMethod == NULL) + PyObject* setCloseLoopCall = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); + PyObject* trueTuple = PyTuple_New(1); + PyTuple_SetItem(trueTuple, 0, Py_True); + PyObject* setCloseLoopCallResult = PyObject_CallObject(setCloseLoopCall, trueTuple); + if (setCloseLoopCallResult == NULL) { - printLog("openMethod wrong!"); + printLog("setCloseLoopCallResult wrong!"); } else{ - printLog("openMethod ok!"); + printLog("setCloseLoopCallResult ok!"); + } + + Py_DECREF(setCloseLoopCall); + Py_DECREF(trueTuple); + Py_DECREF(setCloseLoopCallResult); } - PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); - if (openMethodCall == NULL) + initSampleArrays(); + + m_pThreadState = (void*)PyEval_SaveThread(); +} + +FieldlineAcqSystem::~FieldlineAcqSystem() +{ + PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); + + Py_XDECREF(m_fServiceInstance); + Py_XDECREF(m_pCallsModule); + + if (m_samplesBlock) { + delete[] m_samplesBlock; + } + if (m_samplesBlock2) { + delete[] m_samplesBlock2; + } + + Py_Finalize(); +} + +void* FieldlineAcqSystem::loadSensors() { + PyObject* loadSensors = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "load_sensors"); + PyObject* sensors = PyObject_CallNoArgs(loadSensors); + Py_DECREF(loadSensors); + return (void*)sensors; +} + +void FieldlineAcqSystem::restartAllSensors() { + + restartFinished = false; + + GILHandler g; + + AcqOpener opener((PyObject*)m_fServiceInstance); + + PyObject* sensors = (PyObject*) loadSensors(); + + PyObject* restartAllSensorsCall = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "restart_sensors"); + if (restartAllSensorsCall == NULL) { - printLog("openMethodCall wrong!"); - } else{ - printLog("openMethodCall ok!"); + printLog("restart sensors broken"); + } else { + printLog("restartAllSensors ok!"); } - Py_DECREF(openMethod); - Py_DECREF(openMethodCall); - PyGILState_Release(gstate); + PyObject* callback_on_finished = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileRestart"); + if (callback_on_finished == NULL) + { + printLog("callback on finished broken"); + } else { + printLog("callback restart ok!"); + } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - // PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + PyObject* callback_on_error = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileRestart"); + if (callback_on_error == NULL) + { + printLog("callback on error broken"); + } else { + printLog("callback error ok!"); + } - // ========================================================================= - // ========================================================================= + PyObject* callback_on_completion = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionRestart"); + if (callback_on_completion == NULL) + { + printLog("callback on completion broken"); + } else { + printLog("callback completion ok!"); + } - PyObject* setCloseLoop = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); - PyObject* trueTuple = PyTuple_New(1); - PyTuple_SetItem(trueTuple, 0, Py_True); - PyObject* pResult2 = PyObject_CallObject(setCloseLoop, trueTuple); - Py_DECREF(setCloseLoop); - Py_DECREF(trueTuple); - Py_DECREF(pResult2); + PyObject* argsRestart = PyTuple_New(4); + PyTuple_SetItem(argsRestart, 0, sensors); + PyTuple_SetItem(argsRestart, 1, callback_on_finished); + PyTuple_SetItem(argsRestart, 2, callback_on_error); + PyTuple_SetItem(argsRestart, 3, callback_on_completion); + + PyObject* resultRestart = PyObject_CallObject(restartAllSensorsCall, argsRestart); + if (resultRestart == NULL) + { + printLog("restart call broken"); + } else { + printLog("restart call ok!"); + } - PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors"); - PyObject* sensors = PyObject_CallNoArgs(loadSensors); - Py_INCREF(loadSensors); - Py_INCREF(sensors); + g.releaseGIL(); - PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors"); + while (restartFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(600)); + } - if (restartAllSensors == NULL) - { - printLog("restart sensors broken"); - } else { - printLog("restartAllSensors ok!"); - } + g.acquireGIL(); - PyObject* callback_on_finished = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileRestart"); - if (callback_on_finished == NULL) - { - printLog("callback on finished broken"); - } else { - printLog("callback restart ok!"); - } + Py_DECREF(sensors); + Py_DECREF(restartAllSensorsCall); + Py_DECREF(callback_on_finished); + Py_DECREF(callback_on_error); + Py_DECREF(callback_on_completion); + Py_DECREF(argsRestart); + Py_DECREF(resultRestart); +} - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); +void FieldlineAcqSystem::coarseZeroAllSensors() { - PyObject* callback_on_error = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileRestart"); - if (callback_on_error == NULL) - { - printLog("callback on error broken"); - } else { - printLog("callback error ok!"); - } + coarseZeroFinished = false; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - PyObject* callback_on_completion = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionRestart"); - if (callback_on_completion == NULL) - { - printLog("callback on completion broken"); - } else { - printLog("callback completion ok!"); - } + GILHandler g; - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - PyObject* argsRestart = PyTuple_New(4); - PyTuple_SetItem(argsRestart, 0, sensors); - PyTuple_SetItem(argsRestart, 1, callback_on_finished); - PyTuple_SetItem(argsRestart, 2, callback_on_error); - PyTuple_SetItem(argsRestart, 3, callback_on_completion); - - restartFinished = false; - - //PyObject* resultRestart = PyObject_CallObject(restartAllSensors, argsRestart); - //if (resultRestart == NULL) - //{ - //printLog("restart call broken"); - //} else { - //printLog("restart call ok!"); - //} - // - //Py_DECREF(restartAllSensors); - Py_DECREF(callback_on_finished); - Py_DECREF(callback_on_error); - Py_DECREF(callback_on_completion); - Py_DECREF(argsRestart); - //Py_DECREF(resultRestart); - - PyGILState_Release(gstate); - - //while (restartFinished == false) { - //std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - //} - std::this_thread::sleep_for(std::chrono::milliseconds(3000)); - - // ========================================================================= - // =========== coarse zero ================================================= - // ========================================================================= - gstate = PyGILState_Ensure(); - - PyObject* coarseZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "coarse_zero_sensors"); - if (coarseZeroAllSensors == NULL) - { - printLog("coarse zero sensors broken"); - } else { - printLog("coarseZeroAllSensors ok!"); - } + AcqOpener opener((PyObject*)m_fServiceInstance); - PyObject* callback_on_finished_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileCoarseZero"); - if (callback_on_finished_coarse_zero == NULL) - { - printLog("callback on finished coarse zero broken"); - } else { - printLog("callback on finished coarse zero ok!"); - } + PyObject* sensors = (PyObject*) loadSensors(); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + PyObject* coarseZeroAllSensorsCall = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "coarse_zero_sensors"); + if (coarseZeroAllSensorsCall == NULL) + { + printLog("coarse zero sensors broken"); + } else { + printLog("coarseZeroAllSensors ok!"); + } - PyObject* callback_on_error_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileCoarseZero"); - if (callback_on_error_coarse_zero == NULL) - { - printLog("callback on error coarse zero broken"); - } else { - printLog("callback coarse zero error ok!"); - } + PyObject* callback_on_finished_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileCoarseZero"); + if (callback_on_finished_coarse_zero == NULL) + { + printLog("callback on finished coarse zero broken"); + } else { + printLog("callback on finished coarse zero ok!"); + } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - PyObject* callback_on_completion_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionCoarseZero"); - if (callback_on_completion_coarse_zero == NULL) - { - printLog("callback on completion coarse zero broken"); - } else { - printLog("callback coarse zero completion ok!"); - } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + PyObject* callback_on_error_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileCoarseZero"); + if (callback_on_error_coarse_zero == NULL) + { + printLog("callback on error coarse zero broken"); + } else { + printLog("callback coarse zero error ok!"); + } - PyObject* argsCoarseZero = PyTuple_New(4); - PyTuple_SetItem(argsCoarseZero, 0, sensors); - PyTuple_SetItem(argsCoarseZero, 1, callback_on_finished_coarse_zero); - PyTuple_SetItem(argsCoarseZero, 2, callback_on_error_coarse_zero); - PyTuple_SetItem(argsCoarseZero, 3, callback_on_completion_coarse_zero); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* callback_on_completion_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionCoarseZero"); + if (callback_on_completion_coarse_zero == NULL) + { + printLog("callback on completion coarse zero broken"); + } else { + printLog("callback coarse zero completion ok!"); + } - coarseZeroFinished = false; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + PyObject* argsCoarseZero = PyTuple_New(4); + PyTuple_SetItem(argsCoarseZero, 0, sensors); + PyTuple_SetItem(argsCoarseZero, 1, callback_on_finished_coarse_zero); + PyTuple_SetItem(argsCoarseZero, 2, callback_on_error_coarse_zero); + PyTuple_SetItem(argsCoarseZero, 3, callback_on_completion_coarse_zero); - //PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensors, argsCoarseZero); - //if (resultCoarseZero == NULL) - //{ - // printLog("call coarsezero call broken"); - //} else { - // printLog("coarse zero call call ok!"); - //} + PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensorsCall, argsCoarseZero); + if (resultCoarseZero == NULL) + { + printLog("call coarsezero call broken"); + } else { + printLog("coarse zero call call ok!"); + } + + g.releaseGIL(); - Py_DECREF(coarseZeroAllSensors); - Py_DECREF(callback_on_finished_coarse_zero); - Py_DECREF(callback_on_error_coarse_zero); - Py_DECREF(callback_on_completion_coarse_zero); - Py_DECREF(argsCoarseZero); - //Py_DECREF(resultCoarseZero); + while (coarseZeroFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(600)); + } - PyGILState_Release(gstate); + g.acquireGIL(); - //while (coarseZeroFinished == false) { - // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - //} - // ========================================================================= - // ========================================================================= + Py_DECREF(sensors); + Py_DECREF(coarseZeroAllSensorsCall); + Py_DECREF(callback_on_finished_coarse_zero); + Py_DECREF(callback_on_error_coarse_zero); + Py_DECREF(callback_on_completion_coarse_zero); + Py_DECREF(argsCoarseZero); + Py_DECREF(resultCoarseZero); +} - // ========================================================================= - // ============ fine zero ================================================== - // ========================================================================= - gstate = PyGILState_Ensure(); +void FieldlineAcqSystem::fineZeroAllSensors() { - PyObject* fineZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "fine_zero_sensors"); + fineZeroFinished = false; - if (fineZeroAllSensors == NULL) - { - printLog("fine zero sensors broken"); - } else { - printLog("fineZeroAllSensors ok!"); - } + GILHandler g; - PyObject* callback_on_finished_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileFineZero"); - if (callback_on_finished_fine_zero == NULL) - { - printLog("callback on finished fine zero broken"); - } else { - printLog("callback on finished fine zero ok!"); - } + AcqOpener opener((PyObject*)m_fServiceInstance); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + PyObject* sensors = (PyObject*) loadSensors(); - PyObject* callback_on_error_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileFineZero"); - if (callback_on_error_fine_zero == NULL) - { - printLog("callback on error fine zero broken"); - } else { - printLog("callback fine zero error ok!"); - } + PyObject* fineZeroAllSensorsCall = PyObject_GetAttrString((PyObject*) m_fServiceInstance, "fine_zero_sensors"); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - - PyObject* callback_on_completion_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionFineZero"); - if (callback_on_completion_fine_zero == NULL) - { - printLog("callback on completion fine zero broken"); - } else { - printLog("callback fine zero completion ok!"); - } + if (fineZeroAllSensorsCall == NULL) + { + printLog("fine zero sensors broken"); + } else { + printLog("fineZeroAllSensors ok!"); + } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + PyObject* callback_on_finished_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileFineZero"); + if (callback_on_finished_fine_zero == NULL) + { + printLog("callback on finished fine zero broken"); + } else { + printLog("callback on finished fine zero ok!"); + } - PyObject* loadSensors3 = PyObject_GetAttrString(fServiceInstance, "load_sensors"); - PyObject* sensors3 = PyObject_CallNoArgs(loadSensors); + PyObject* callback_on_error_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileFineZero"); + if (callback_on_error_fine_zero == NULL) + { + printLog("callback on error fine zero broken"); + } else { + printLog("callback fine zero error ok!"); + } - PyObject* argsFineZero = PyTuple_New(4); - PyTuple_SetItem(argsFineZero, 0, sensors3); - PyTuple_SetItem(argsFineZero, 1, callback_on_finished_fine_zero); - PyTuple_SetItem(argsFineZero, 2, callback_on_error_fine_zero); - PyTuple_SetItem(argsFineZero, 3, callback_on_completion_fine_zero); + PyObject* callback_on_completion_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionFineZero"); + if (callback_on_completion_fine_zero == NULL) + { + printLog("callback on completion fine zero broken"); + } else { + printLog("callback fine zero completion ok!"); + } - fineZeroFinished = false; + PyObject* argsFineZero = PyTuple_New(4); + PyTuple_SetItem(argsFineZero, 0, sensors); + PyTuple_SetItem(argsFineZero, 1, callback_on_finished_fine_zero); + PyTuple_SetItem(argsFineZero, 2, callback_on_error_fine_zero); + PyTuple_SetItem(argsFineZero, 3, callback_on_completion_fine_zero); - //PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensors, argsFineZero); - //if (resultFineZero == NULL) - //{ - // printLog("call finezero call broken"); - //} else { - // printLog("fine zero call call ok!"); - //} - Py_DECREF(sensors); + PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensorsCall, argsFineZero); + if (resultFineZero == NULL) + { + printLog("call finezero call broken"); + } else { + printLog("fine zero call call ok!"); + } - Py_DECREF(sensors3); - Py_DECREF(loadSensors3); + g.releaseGIL(); - Py_DECREF(fineZeroAllSensors); - Py_DECREF(callback_on_finished_fine_zero); - Py_DECREF(callback_on_error_fine_zero); - Py_DECREF(callback_on_completion_fine_zero); - Py_DECREF(argsFineZero); - //Py_DECREF(resultFineZero); + while (fineZeroFinished == false) { + std::this_thread::sleep_for(std::chrono::milliseconds(600)); + } - //PyGILState_Release(gstate); + g.acquireGIL(); - // while (fineZeroFinished == false) { - // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - // } - // ========================================================================= - // ========================================================================= - // PyGILState_STATE gstate; - //gstate = PyGILState_Ensure(); + Py_DECREF(sensors); - //Py_DECREF(loadSensors); - //Py_XDECREF(loadSensors); - //Py_DECREF(sensors); - //Py_XDECREF(sensors); + Py_DECREF(fineZeroAllSensorsCall); + Py_DECREF(callback_on_finished_fine_zero); + Py_DECREF(callback_on_error_fine_zero); + Py_DECREF(callback_on_completion_fine_zero); + Py_DECREF(argsFineZero); + Py_DECREF(resultFineZero); +} +void FieldlineAcqSystem::setDataCallback() { - PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data"); + GILHandler g; + + AcqOpener opener((PyObject*)m_fServiceInstance); + + PyObject* readDataFcn = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "read_data"); if (readDataFcn == NULL) { printLog("problem readDataFcn"); } else { printLog("readDataFcn ok"); } + PyObject* parseCallbacksModule = (PyObject*)loadCModule("callbacks_parsing", *(void*(*)(void))&PyInit_callbacks_parsing); + if (parseCallbacksModule == NULL) + { + printLog("callbacks module wrong!"); + } else{ + printLog("callbacks module ok!"); + } + PyObject* parserCallback = PyObject_GetAttrString(parseCallbacksModule, "dict_parser"); if (parserCallback == NULL) { printLog("problem parserCallback"); @@ -642,45 +728,13 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_DECREF(parserCallback); Py_DECREF(argsSetDataParser); - PyGILState_Release(gstate); - - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - // PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - // register "this" into somewhere findable by python's execution flow. - acq_system = this; - initSampleArrays(); - Py_DECREF(parseCallbacksModule); - Py_DECREF(FieldlineModule); - Py_DECREF(fServiceInstance); - - PyGILState_Release(gstate); - // m_pThreadState = (void*)PyEval_SaveThread(); -} - -FieldlineAcqSystem::~FieldlineAcqSystem() -{ - PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); - - Py_XDECREF(m_pCallbackModule); - Py_XDECREF(m_pCallsModule); - - if (m_samplesBlock) { - delete[] m_samplesBlock; - } - if (m_samplesBlock2) { - delete[] m_samplesBlock2; - } - Py_Finalize(); } void FieldlineAcqSystem::setCallback() { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; // PyObject *pSetCallbackFunc = NULL; // PyObject *pCallback1 = NULL; @@ -714,12 +768,12 @@ void FieldlineAcqSystem::setCallback() // Py_XDECREF(pArgs); // Py_XDECREF(pResult); // - PyGILState_Release(gstate); } void FieldlineAcqSystem::startADC() { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; + + AcqOpener o((PyObject*)m_fServiceInstance); PyObject* start_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "start_adc"); PyObject* argsStartData = PyTuple_New(1); @@ -736,13 +790,11 @@ void FieldlineAcqSystem::startADC() { Py_DECREF(argsStartData); Py_DECREF(zeroArg); Py_DECREF(startResult); - - PyGILState_Release(gstate); } void FieldlineAcqSystem::stopADC() { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; + AcqOpener o((PyObject*)m_fServiceInstance); PyObject* stop_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "stop_adc"); PyObject* argsstopData = PyTuple_New(1); @@ -759,14 +811,11 @@ void FieldlineAcqSystem::stopADC() { Py_DECREF(argsstopData); Py_DECREF(stopArg); Py_DECREF(stopResult); - - PyGILState_Release(gstate); } void* FieldlineAcqSystem::loadModule(const char* moduleName) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; PyObject* pModule = PyImport_ImportModule(moduleName); if (pModule == NULL) { @@ -776,15 +825,12 @@ void* FieldlineAcqSystem::loadModule(const char* moduleName) Py_DECREF(pModule); - PyGILState_Release(gstate); - return (void*)pModule; } void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitFunc)(void)) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; if (Py_IsInitialized()) { @@ -796,7 +842,7 @@ void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitF } else { PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); } - PyGILState_Release(gstate); + return loadModule(moduleName); } @@ -810,8 +856,7 @@ void FieldlineAcqSystem::callFunctionAsync(const char* moduleName, const char* f void FieldlineAcqSystem::callFunction(const std::string& moduleName, const std::string& funcName) { - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); + GILHandler g; PyObject* pModule = PyImport_GetModule(PyUnicode_FromString(moduleName.c_str())); if (pModule == NULL) { @@ -840,8 +885,6 @@ void FieldlineAcqSystem::callFunction(const std::string& moduleName, const std:: Py_XDECREF(pModule); Py_XDECREF(pFunc); Py_XDECREF(pResult); - - PyGILState_Release(gstate); } void FieldlineAcqSystem::preConfigurePython() const diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index fc1f2eaba0d..7d2b8a456e4 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -57,19 +57,24 @@ class FieldlineAcqSystem { Fieldline* m_pControllerParent; void initSampleArrays(); void addSampleToSamplesColumn(int sensorIdx, double value); + void restartAllSensors(); + void coarseZeroAllSensors(); + void fineZeroAllSensors(); private: void preConfigurePython() const; void runPythonFile(const char* file, const char* comment) const; void* loadModule(const char* moduleName); void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); + void* loadSensors(); + void setDataCallback(); int m_numSamplesPerBlock; int m_numSensors; void* m_fServiceInstance; void* m_pThreadState; - void* m_pCallbackModule; void* m_pCallsModule; + void* m_pOpenMethod; double* m_samplesBlock; double* m_samplesBlock2; }; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp index 77a324412c0..81a6235da9d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_view.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -234,7 +235,7 @@ void FieldlineView::initAcqSystem(int numChassis) void FieldlineView::startAllSensors() { printLog("startAllSensors"); // m_pFieldlinePlugin->m_pAcqSystem->callFunctionAsync("callback", "start"); - m_pFieldlinePlugin->m_pAcqSystem->startADC(); +// m_pFieldlinePlugin->m_pAcqSystem->startADC(); } void FieldlineView::stopAllSensors() { @@ -245,19 +246,31 @@ void FieldlineView::stopAllSensors() { void FieldlineView::autoTuneAllSensors() { printLog("autoTuneAllSensors"); - m_pFieldlinePlugin->m_pAcqSystem->setCallback(); + //m_pFieldlinePlugin->m_pAcqSystem->setCallback(); } void FieldlineView::restartAllSensors() { printLog("restartAllSensors"); + std::thread t([this]{ + m_pFieldlinePlugin->m_pAcqSystem->restartAllSensors(); + }); + t.detach(); } void FieldlineView::coarseZeroAllSensors() { printLog("coarseZeroAllSensors"); + std::thread t([this]{ + m_pFieldlinePlugin->m_pAcqSystem->coarseZeroAllSensors(); + }); + t.detach(); } void FieldlineView::fineZeroAllSensors() { printLog("fineZeroAllSensors"); + std::thread t([this]{ + m_pFieldlinePlugin->m_pAcqSystem->fineZeroAllSensors(); + }); + t.detach(); } From 3146cf1369d0c5a16ae4c20a333ea2c4d4d1ba39 Mon Sep 17 00:00:00 2001 From: juangpc Date: Mon, 22 May 2023 11:50:16 -0400 Subject: [PATCH 144/147] getting data_parser callback to work --- config2.py | 14 ++ .../mne_scan/plugins/fieldline/fieldline.cpp | 5 + .../plugins/fieldline/fieldline_acqsystem.cpp | 179 +++++++++++------- .../plugins/fieldline/fieldline_acqsystem.h | 2 +- 4 files changed, 134 insertions(+), 66 deletions(-) create mode 100644 config2.py diff --git a/config2.py b/config2.py new file mode 100644 index 00000000000..7e4cca46f34 --- /dev/null +++ b/config2.py @@ -0,0 +1,14 @@ +import sys + +def dump(obj): + for attr in dir(obj): + print("obj.%s = %r" % (attr, getattr(obj, attr))) + + +print("hello there!!!") + +sys.argv = '/autofs/cluster/fusion/juan/anaconda3/bin/anaconda' + +dump(sys) + + diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index e3f0d95a14d..81e20d6da84 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -183,6 +183,8 @@ bool Fieldline::start() initFiffInfo(); std::thread t([this]{ + m_pAcqSystem->setDataCallback(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); m_pAcqSystem->startADC(); }); t.detach(); @@ -217,6 +219,9 @@ void Fieldline::initFiffInfo() bool Fieldline::stop() { printLog("stop"); + + m_pAcqSystem->stopADC(); + requestInterruption(); wait(500); diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 52e776d521a..bf6ad6f82c7 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -116,8 +116,8 @@ struct AcqOpener { } else{ printLog("openMethodCall ok!"); } - Py_DECREF(openMethod); - Py_DECREF(openMethodCall); + Py_XDECREF(openMethod); + Py_XDECREF(openMethodCall); } void closeAcq() { @@ -137,8 +137,8 @@ struct AcqOpener { printLog("closeMethodCall ok!"); } - Py_DECREF(closeMethod); - Py_DECREF(closeMethodCall); + Py_XDECREF(closeMethod); + Py_XDECREF(closeMethodCall); } PyObject* m_serviceInstance; @@ -338,7 +338,11 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { PyObject* data = PyDict_GetItemString(value, "data"); printLog(std::string("pos: ") + std::to_string(pos)); printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); - acq_system->addSampleToSamplesColumn((int) pos-1, (double) PyLong_AsLong(data)); + float sample = (double) PyLong_AsLong(data); + Py_BEGIN_ALLOW_THREADS + acq_system->addSampleToSamplesColumn((int) pos-1, sample); + Py_END_ALLOW_THREADS + if (pos == 2) break; } @@ -376,10 +380,12 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) preConfigurePython(); + //runPythonFile("./config2.py","bla"); + m_pCallsModule = loadCModule("fieldline_callbacks", *(void*(*)(void))&PyInit_fieldline_callbacks); - PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); - //PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api.fieldline_service"); + //PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api_mock.fieldline_service"); + PyObject* FieldlineModule = (PyObject*)loadModule("fieldline_api.fieldline_service"); if (FieldlineModule == NULL) { printLog("fieldline module wrong!"); @@ -404,11 +410,11 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) printLog("fServiceInstance ok!"); } - Py_DECREF(FieldlineModule); - Py_DECREF(fService); - Py_DECREF(ipList); + Py_XDECREF(FieldlineModule); + Py_XDECREF(fService); + Py_XDECREF(ipList); - setDataCallback(); + //setDataCallback(); { AcqOpener o((PyObject*)m_fServiceInstance); @@ -424,9 +430,9 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) printLog("setCloseLoopCallResult ok!"); } - Py_DECREF(setCloseLoopCall); - Py_DECREF(trueTuple); - Py_DECREF(setCloseLoopCallResult); + Py_XDECREF(setCloseLoopCall); + Py_XDECREF(trueTuple); + Py_XDECREF(setCloseLoopCallResult); } initSampleArrays(); @@ -454,10 +460,16 @@ FieldlineAcqSystem::~FieldlineAcqSystem() void* FieldlineAcqSystem::loadSensors() { PyObject* loadSensors = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "load_sensors"); PyObject* sensors = PyObject_CallNoArgs(loadSensors); - Py_DECREF(loadSensors); + Py_XDECREF(loadSensors); return (void*)sensors; } + +// for activating trigger sensor: service.restart_sensors({0:[0]}) +// for deactivating trigger sensors: service.turn_off_sensors({0:[0]}) +// typical calibration value: 2.27e-15 T +// + void FieldlineAcqSystem::restartAllSensors() { restartFinished = false; @@ -522,13 +534,13 @@ void FieldlineAcqSystem::restartAllSensors() { g.acquireGIL(); - Py_DECREF(sensors); - Py_DECREF(restartAllSensorsCall); - Py_DECREF(callback_on_finished); - Py_DECREF(callback_on_error); - Py_DECREF(callback_on_completion); - Py_DECREF(argsRestart); - Py_DECREF(resultRestart); + Py_XDECREF(sensors); + Py_XDECREF(restartAllSensorsCall); + Py_XDECREF(callback_on_finished); + Py_XDECREF(callback_on_error); + Py_XDECREF(callback_on_completion); + Py_XDECREF(argsRestart); + Py_XDECREF(resultRestart); } void FieldlineAcqSystem::coarseZeroAllSensors() { @@ -601,14 +613,14 @@ void FieldlineAcqSystem::coarseZeroAllSensors() { g.acquireGIL(); - Py_DECREF(sensors); + Py_XDECREF(sensors); - Py_DECREF(coarseZeroAllSensorsCall); - Py_DECREF(callback_on_finished_coarse_zero); - Py_DECREF(callback_on_error_coarse_zero); - Py_DECREF(callback_on_completion_coarse_zero); - Py_DECREF(argsCoarseZero); - Py_DECREF(resultCoarseZero); + Py_XDECREF(coarseZeroAllSensorsCall); + Py_XDECREF(callback_on_finished_coarse_zero); + Py_XDECREF(callback_on_error_coarse_zero); + Py_XDECREF(callback_on_completion_coarse_zero); + Py_XDECREF(argsCoarseZero); + Py_XDECREF(resultCoarseZero); } void FieldlineAcqSystem::fineZeroAllSensors() { @@ -676,14 +688,14 @@ void FieldlineAcqSystem::fineZeroAllSensors() { g.acquireGIL(); - Py_DECREF(sensors); + Py_XDECREF(sensors); - Py_DECREF(fineZeroAllSensorsCall); - Py_DECREF(callback_on_finished_fine_zero); - Py_DECREF(callback_on_error_fine_zero); - Py_DECREF(callback_on_completion_fine_zero); - Py_DECREF(argsFineZero); - Py_DECREF(resultFineZero); + Py_XDECREF(fineZeroAllSensorsCall); + Py_XDECREF(callback_on_finished_fine_zero); + Py_XDECREF(callback_on_error_fine_zero); + Py_XDECREF(callback_on_completion_fine_zero); + Py_XDECREF(argsFineZero); + Py_XDECREF(resultFineZero); } void FieldlineAcqSystem::setDataCallback() { @@ -692,11 +704,11 @@ void FieldlineAcqSystem::setDataCallback() { AcqOpener opener((PyObject*)m_fServiceInstance); - PyObject* readDataFcn = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "read_data"); - if (readDataFcn == NULL) { - printLog("problem readDataFcn"); + PyObject* readDataCall = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "read_data"); + if (readDataCall == NULL) { + printLog("problem readDataCall"); } else { - printLog("readDataFcn ok"); + printLog("readDataCall ok"); } PyObject* parseCallbacksModule = (PyObject*)loadCModule("callbacks_parsing", *(void*(*)(void))&PyInit_callbacks_parsing); @@ -716,19 +728,18 @@ void FieldlineAcqSystem::setDataCallback() { PyObject* argsSetDataParser = PyTuple_New(1); PyTuple_SetItem(argsSetDataParser, 0, parserCallback); - PyObject* readDataReturn = PyObject_CallObject(readDataFcn, argsSetDataParser); + PyObject* readDataReturn = PyObject_CallObject(readDataCall, argsSetDataParser); if (readDataReturn == NULL) { printLog("readDataReturn bad"); } else { printLog("readDataReturn ok"); } - Py_DECREF(readDataReturn); - Py_DECREF(readDataFcn); - Py_DECREF(parserCallback); - Py_DECREF(argsSetDataParser); - - Py_DECREF(parseCallbacksModule); + Py_XDECREF(readDataCall); + Py_XDECREF(parseCallbacksModule); + Py_XDECREF(parserCallback); + Py_XDECREF(argsSetDataParser); + Py_XDECREF(readDataReturn); } @@ -773,7 +784,24 @@ void FieldlineAcqSystem::setCallback() void FieldlineAcqSystem::startADC() { GILHandler g; - AcqOpener o((PyObject*)m_fServiceInstance); + //AcqOpener o((PyObject*)m_fServiceInstance); + PyObject* openMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "open"); + if (openMethod == NULL) + { + printLog("openMethod wrong!"); + } else{ + printLog("openMethod ok!"); + } + + PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); + if (openMethodCall == NULL) + { + printLog("openMethodCall wrong!"); + } else{ + printLog("openMethodCall ok!"); + } + Py_XDECREF(openMethod); + Py_XDECREF(openMethodCall); PyObject* start_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "start_adc"); PyObject* argsStartData = PyTuple_New(1); @@ -787,9 +815,9 @@ void FieldlineAcqSystem::startADC() { printLog("startResult ok"); } - Py_DECREF(argsStartData); - Py_DECREF(zeroArg); - Py_DECREF(startResult); + Py_XDECREF(argsStartData); + Py_XDECREF(zeroArg); + Py_XDECREF(startResult); } void FieldlineAcqSystem::stopADC() { @@ -799,6 +827,7 @@ void FieldlineAcqSystem::stopADC() { PyObject* stop_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "stop_adc"); PyObject* argsstopData = PyTuple_New(1); PyObject* stopArg = PyLong_FromLong(0); + PyTuple_SetItem(argsstopData, 0, stopArg); PyObject* stopResult = PyObject_CallObject(stop_data, argsstopData); if (stopResult == NULL) @@ -808,9 +837,28 @@ void FieldlineAcqSystem::stopADC() { printLog("stopResult ok"); } - Py_DECREF(argsstopData); - Py_DECREF(stopArg); - Py_DECREF(stopResult); + PyObject* closeMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "close"); + if (closeMethod == NULL) + { + printLog("closeMethod wrong!"); + } else{ + printLog("closeMethod ok!"); + } + + PyObject* closeMethodCall = PyObject_CallNoArgs(closeMethod); + if (closeMethodCall == NULL) + { + printLog("closeMethodCall wrong!"); + } else{ + printLog("closeMethodCall ok!"); + } + + Py_XDECREF(closeMethod); + Py_XDECREF(closeMethodCall); + + Py_XDECREF(argsstopData); + Py_XDECREF(stopArg); + Py_XDECREF(stopResult); } void* FieldlineAcqSystem::loadModule(const char* moduleName) @@ -823,7 +871,7 @@ void* FieldlineAcqSystem::loadModule(const char* moduleName) PyErr_Print(); } - Py_DECREF(pModule); + Py_XDECREF(pModule); return (void*)pModule; } @@ -838,7 +886,7 @@ void* FieldlineAcqSystem::loadCModule(const char* moduleName, void*(*moduleInitF PyObject* PyModule = (PyObject*)moduleInitFunc(); PyObject* sys_modules = PyImport_GetModuleDict(); PyDict_SetItemString(sys_modules, moduleName, PyModule); - Py_DECREF(PyModule); + Py_XDECREF(PyModule); } else { PyImport_AppendInittab(moduleName, (PyObject*(*)(void)) moduleInitFunc); } @@ -895,20 +943,21 @@ void FieldlineAcqSystem::preConfigurePython() const PyObject* versionInfoMinor = PyObject_GetAttrString(versionInfo, "minor"); const std::string pythonVer(std::to_string(PyLong_AsLong(versionInfoMajor)) + \ "." + std::to_string(PyLong_AsLong(versionInfoMinor))); - Py_DECREF(versionInfoMajor); - Py_DECREF(versionInfoMinor); - Py_DECREF(versionInfo); + Py_XDECREF(versionInfoMajor); + Py_XDECREF(versionInfoMinor); + Py_XDECREF(versionInfo); PyObject* path = PyObject_GetAttrString(sys, "path"); PyObject* resourcesObj = PyUnicode_FromString(resourcesPath.c_str()); PyList_Insert(path, 0, resourcesObj); - Py_DECREF(sys); - Py_DECREF(resourcesObj); + Py_XDECREF(resourcesObj); const std::string pathVenvMods(resourcesPath + "venv/lib/python" + pythonVer + "/site-packages/"); printLog(pathVenvMods); PyList_Insert(path, 1, PyUnicode_FromString(pathVenvMods.c_str())); - Py_DECREF(path); + Py_XDECREF(path); + + Py_XDECREF(sys); } void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) const @@ -919,9 +968,9 @@ void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) co PyObject* global_dict = PyDict_New(); PyObject* local_dict = PyDict_New(); PyObject* result = PyRun_File(py_file, comment, Py_file_input, global_dict, local_dict); - Py_DECREF(global_dict); - Py_DECREF(local_dict); - Py_DECREF(result); + Py_XDECREF(global_dict); + Py_XDECREF(local_dict); + Py_XDECREF(result); fclose(py_file); } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 7d2b8a456e4..01b1e2851cd 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -60,6 +60,7 @@ class FieldlineAcqSystem { void restartAllSensors(); void coarseZeroAllSensors(); void fineZeroAllSensors(); + void setDataCallback(); private: void preConfigurePython() const; @@ -67,7 +68,6 @@ class FieldlineAcqSystem { void* loadModule(const char* moduleName); void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); void* loadSensors(); - void setDataCallback(); int m_numSamplesPerBlock; int m_numSensors; From 8ea8963ca059d81c30d806311a4c6c17a714a5ae Mon Sep 17 00:00:00 2001 From: juangpc Date: Mon, 22 May 2023 19:11:14 -0400 Subject: [PATCH 145/147] fix data parser callback --- config2.py | 26 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 233 ++++++++---------- .../plugins/fieldline/fieldline_acqsystem.h | 2 +- 3 files changed, 132 insertions(+), 129 deletions(-) diff --git a/config2.py b/config2.py index 7e4cca46f34..75ef296a7c8 100644 --- a/config2.py +++ b/config2.py @@ -1,14 +1,32 @@ import sys - def dump(obj): for attr in dir(obj): print("obj.%s = %r" % (attr, getattr(obj, attr))) +#sys.argv = '/autofs/cluster/fusion/juan/anaconda3/bin/anaconda' +print(' === configuration script =======================================================') +dump(sys) +print(' ==================================================================================') -print("hello there!!!") +print(' === system path ===============================================================') +for p in sys.path: + print(p) +print(' ==================================================================================') -sys.argv = '/autofs/cluster/fusion/juan/anaconda3/bin/anaconda' +print(' === system argv ===============================================================') +print(sys.argv) +print(' ==================================================================================') +sys.argv = '/autofs/cluster/fusion/juan/anaconda3/bin/python' +print(' === system argv ===============================================================') +print(sys.argv) +print(' ==================================================================================') -dump(sys) +import logging +import argparse +import queue +import sys +import time +import multiprocessing +multiprocessing.set_executable('autofs/cluster/fusion/juan/anaconda3/bin/python') diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index bf6ad6f82c7..1489fd62009 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -316,6 +316,7 @@ static PyObject* PyInit_fieldline_callbacks(void) { static FieldlineAcqSystem* acq_system(nullptr); static PyObject* dict_parser(PyObject* self, PyObject* args) { + printLog("heeeelo!!!!!"); PyObject* dataDict; if (!PyArg_ParseTuple(args, "O", &dataDict)) { printLog("problem with dataDict."); @@ -378,9 +379,13 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_Initialize(); + m_pThreadState = (void*)PyEval_SaveThread(); + + GILHandler g; + preConfigurePython(); - //runPythonFile("./config2.py","bla"); + runPythonFile("./config2.py","bla"); m_pCallsModule = loadCModule("fieldline_callbacks", *(void*(*)(void))&PyInit_fieldline_callbacks); @@ -414,46 +419,19 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) Py_XDECREF(fService); Py_XDECREF(ipList); - //setDataCallback(); - - { - AcqOpener o((PyObject*)m_fServiceInstance); - - PyObject* setCloseLoopCall = PyObject_GetAttrString(fServiceInstance, "set_closed_loop"); - PyObject* trueTuple = PyTuple_New(1); - PyTuple_SetItem(trueTuple, 0, Py_True); - PyObject* setCloseLoopCallResult = PyObject_CallObject(setCloseLoopCall, trueTuple); - if (setCloseLoopCallResult == NULL) - { - printLog("setCloseLoopCallResult wrong!"); - } else{ - printLog("setCloseLoopCallResult ok!"); - } - - Py_XDECREF(setCloseLoopCall); - Py_XDECREF(trueTuple); - Py_XDECREF(setCloseLoopCallResult); - } - initSampleArrays(); - - m_pThreadState = (void*)PyEval_SaveThread(); } FieldlineAcqSystem::~FieldlineAcqSystem() { - PyEval_RestoreThread(reinterpret_cast(m_pThreadState)); - + GILHandler g; + Py_XDECREF(m_fServiceInstance); Py_XDECREF(m_pCallsModule); if (m_samplesBlock) { delete[] m_samplesBlock; } - if (m_samplesBlock2) { - delete[] m_samplesBlock2; - } - Py_Finalize(); } @@ -464,6 +442,27 @@ void* FieldlineAcqSystem::loadSensors() { return (void*)sensors; } +void FieldlineAcqSystem::setCloseLoop() { + + GILHandler g; + + AcqOpener o((PyObject*)m_fServiceInstance); + + PyObject* setCloseLoopCall = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "set_closed_loop"); + PyObject* trueTuple = PyTuple_New(1); + PyTuple_SetItem(trueTuple, 0, Py_True); + PyObject* setCloseLoopCallResult = PyObject_CallObject(setCloseLoopCall, trueTuple); + if (setCloseLoopCallResult == NULL) + { + printLog("setCloseLoopCallResult wrong!"); + } else{ + printLog("setCloseLoopCallResult ok!"); + } + + Py_XDECREF(setCloseLoopCall); + Py_XDECREF(trueTuple); + Py_XDECREF(setCloseLoopCallResult); +} // for activating trigger sensor: service.restart_sensors({0:[0]}) // for deactivating trigger sensors: service.turn_off_sensors({0:[0]}) @@ -476,7 +475,7 @@ void FieldlineAcqSystem::restartAllSensors() { GILHandler g; - AcqOpener opener((PyObject*)m_fServiceInstance); + AcqOpener o((PyObject*)m_fServiceInstance); PyObject* sensors = (PyObject*) loadSensors(); @@ -526,13 +525,11 @@ void FieldlineAcqSystem::restartAllSensors() { printLog("restart call ok!"); } - g.releaseGIL(); - + Py_BEGIN_ALLOW_THREADS while (restartFinished == false) { std::this_thread::sleep_for(std::chrono::milliseconds(600)); } - - g.acquireGIL(); + Py_END_ALLOW_THREADS Py_XDECREF(sensors); Py_XDECREF(restartAllSensorsCall); @@ -549,7 +546,7 @@ void FieldlineAcqSystem::coarseZeroAllSensors() { GILHandler g; - AcqOpener opener((PyObject*)m_fServiceInstance); + AcqOpener o((PyObject*)m_fServiceInstance); PyObject* sensors = (PyObject*) loadSensors(); @@ -605,16 +602,13 @@ void FieldlineAcqSystem::coarseZeroAllSensors() { printLog("coarse zero call call ok!"); } - g.releaseGIL(); - + Py_BEGIN_ALLOW_THREADS while (coarseZeroFinished == false) { std::this_thread::sleep_for(std::chrono::milliseconds(600)); } - - g.acquireGIL(); + Py_END_ALLOW_THREADS Py_XDECREF(sensors); - Py_XDECREF(coarseZeroAllSensorsCall); Py_XDECREF(callback_on_finished_coarse_zero); Py_XDECREF(callback_on_error_coarse_zero); @@ -629,7 +623,7 @@ void FieldlineAcqSystem::fineZeroAllSensors() { GILHandler g; - AcqOpener opener((PyObject*)m_fServiceInstance); + AcqOpener o((PyObject*)m_fServiceInstance); PyObject* sensors = (PyObject*) loadSensors(); @@ -680,16 +674,13 @@ void FieldlineAcqSystem::fineZeroAllSensors() { printLog("fine zero call call ok!"); } - g.releaseGIL(); - + Py_BEGIN_ALLOW_THREADS while (fineZeroFinished == false) { std::this_thread::sleep_for(std::chrono::milliseconds(600)); } - - g.acquireGIL(); + Py_END_ALLOW_THREADS Py_XDECREF(sensors); - Py_XDECREF(fineZeroAllSensorsCall); Py_XDECREF(callback_on_finished_fine_zero); Py_XDECREF(callback_on_error_fine_zero); @@ -740,68 +731,68 @@ void FieldlineAcqSystem::setDataCallback() { Py_XDECREF(parserCallback); Py_XDECREF(argsSetDataParser); Py_XDECREF(readDataReturn); - } -void FieldlineAcqSystem::setCallback() -{ +void FieldlineAcqSystem::startADC() { + GILHandler g; - // PyObject *pSetCallbackFunc = NULL; - // PyObject *pCallback1 = NULL; - // PyObject *pArgs = NULL; - // PyObject *pResult = NULL; - // - // // Get a reference to the function - // pSetCallbackFunc = PyObject_GetAttrString((PyObject*)m_pCallbackModule, "set_callback"); - // if (pSetCallbackFunc == NULL) { - // printLog(std::string("Error finding function: ").append("set_callback").c_str()); - // PyErr_Print(); - // } - // - // pCallback1 = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callback1"); - // if (pCallback1 && PyCallable_Check(pCallback1)) { - // pArgs = PyTuple_New(1); - // PyTuple_SetItem(pArgs, 0, pCallback1); - // } else { - // if (PyErr_Occurred()) - // PyErr_Print(); - // printLog(std::string("Cannot find function callback1 in calls module.")); - // } - // // Call the set_callback function - // pResult = PyObject_CallObject(pSetCallbackFunc, pArgs); - // if (pResult == NULL) { - // printLog(std::string("Error calling function: ").append("set_callback").c_str()); - // PyErr_Print(); - // } - // Py_XDECREF(pSetCallbackFunc); - // Py_XDECREF(pCallback1); - // Py_XDECREF(pArgs); - // Py_XDECREF(pResult); - // -} + PyObject* openMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "open"); + if (openMethod == NULL) + { + printLog("openMethod wrong!"); + } else{ + printLog("openMethod ok!"); + } -void FieldlineAcqSystem::startADC() { - GILHandler g; + PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); + if (openMethodCall == NULL) + { + printLog("openMethodCall wrong!"); + } else{ + printLog("openMethodCall ok!"); + } + Py_XDECREF(openMethod); + Py_XDECREF(openMethodCall); - //AcqOpener o((PyObject*)m_fServiceInstance); - PyObject* openMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "open"); - if (openMethod == NULL) - { - printLog("openMethod wrong!"); - } else{ - printLog("openMethod ok!"); - } + PyObject* readDataCall = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "read_data"); + if (readDataCall == NULL) { + printLog("problem readDataCall"); + } else { + printLog("readDataCall ok"); + } + + PyObject* parseCallbacksModule = (PyObject*)loadCModule("callbacks_parsing", *(void*(*)(void))&PyInit_callbacks_parsing); + if (parseCallbacksModule == NULL) + { + printLog("callbacks module wrong!"); + } else{ + printLog("callbacks module ok!"); + } + + PyObject* parserCallback = PyObject_GetAttrString(parseCallbacksModule, "dict_parser"); + if (parserCallback == NULL) { + printLog("problem parserCallback"); + } else { + printLog("parserCallback ok"); + } + PyObject* argsSetDataParser = PyTuple_New(1); + PyTuple_SetItem(argsSetDataParser, 0, parserCallback); + + PyObject* readDataReturn = PyObject_CallObject(readDataCall, argsSetDataParser); + if (readDataReturn == NULL) + { + printLog("readDataReturn bad"); + } else { + printLog("readDataReturn ok"); + } + + Py_XDECREF(readDataCall); + Py_XDECREF(parseCallbacksModule); + //Py_XDECREF(parserCallback); + Py_XDECREF(argsSetDataParser); + Py_XDECREF(readDataReturn); - PyObject* openMethodCall = PyObject_CallNoArgs(openMethod); - if (openMethodCall == NULL) - { - printLog("openMethodCall wrong!"); - } else{ - printLog("openMethodCall ok!"); - } - Py_XDECREF(openMethod); - Py_XDECREF(openMethodCall); PyObject* start_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "start_adc"); PyObject* argsStartData = PyTuple_New(1); @@ -822,7 +813,6 @@ void FieldlineAcqSystem::startADC() { void FieldlineAcqSystem::stopADC() { GILHandler g; - AcqOpener o((PyObject*)m_fServiceInstance); PyObject* stop_data = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "stop_adc"); PyObject* argsstopData = PyTuple_New(1); @@ -837,24 +827,24 @@ void FieldlineAcqSystem::stopADC() { printLog("stopResult ok"); } - PyObject* closeMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "close"); - if (closeMethod == NULL) - { - printLog("closeMethod wrong!"); - } else{ - printLog("closeMethod ok!"); - } + PyObject* closeMethod = PyObject_GetAttrString((PyObject*)m_fServiceInstance, "close"); + if (closeMethod == NULL) + { + printLog("closeMethod wrong!"); + } else{ + printLog("closeMethod ok!"); + } - PyObject* closeMethodCall = PyObject_CallNoArgs(closeMethod); - if (closeMethodCall == NULL) - { - printLog("closeMethodCall wrong!"); - } else{ - printLog("closeMethodCall ok!"); - } + PyObject* closeMethodCall = PyObject_CallNoArgs(closeMethod); + if (closeMethodCall == NULL) + { + printLog("closeMethodCall wrong!"); + } else{ + printLog("closeMethodCall ok!"); + } - Py_XDECREF(closeMethod); - Py_XDECREF(closeMethodCall); + Py_XDECREF(closeMethod); + Py_XDECREF(closeMethodCall); Py_XDECREF(argsstopData); Py_XDECREF(stopArg); @@ -978,7 +968,6 @@ void FieldlineAcqSystem::runPythonFile(const char* file, const char* comment) co void FieldlineAcqSystem::initSampleArrays() { m_samplesBlock = new double[m_numSensors * m_numSamplesPerBlock]; - m_samplesBlock2 = new double[m_numSensors * m_numSamplesPerBlock]; } void FieldlineAcqSystem::addSampleToSamplesColumn(int sensorIdx, double value) @@ -995,10 +984,6 @@ void FieldlineAcqSystem::addSampleToSamplesColumn(int sensorIdx, double value) if (sampleIdx == m_numSamplesPerBlock) { sampleIdx = 0; m_pControllerParent->newData(m_samplesBlock, m_numSensors, m_numSamplesPerBlock); - // memcpy((void*)m_samplesBlock2, (void*)m_samplesBlock, m_numSamplesPerBlock * m_numSensors); - // std::thread([this](){ - // m_pControllerParent->newData(m_samplesBlock2, m_numSensors, m_numSamplesPerBlock); - // }); } } } diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 01b1e2851cd..49528938c6d 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -51,7 +51,6 @@ class FieldlineAcqSystem { void callFunction(const std::string& moduleName, const std::string& funcName); - void setCallback(); void startADC(); void stopADC(); Fieldline* m_pControllerParent; @@ -61,6 +60,7 @@ class FieldlineAcqSystem { void coarseZeroAllSensors(); void fineZeroAllSensors(); void setDataCallback(); + void setCloseLoop(); private: void preConfigurePython() const; From 95791bfa3121239dc30dd33181f6b2a6ffebd306 Mon Sep 17 00:00:00 2001 From: juangpc Date: Mon, 22 May 2023 19:12:32 -0400 Subject: [PATCH 146/147] only startADC after data_parser callback in place --- src/applications/mne_scan/plugins/fieldline/fieldline.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index 81e20d6da84..bee317ffcab 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -183,7 +183,6 @@ bool Fieldline::start() initFiffInfo(); std::thread t([this]{ - m_pAcqSystem->setDataCallback(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); m_pAcqSystem->startADC(); }); From bc450cac73f32c5bec6e17d3c129194a6ef64605 Mon Sep 17 00:00:00 2001 From: juangpc Date: Mon, 22 May 2023 19:51:13 -0400 Subject: [PATCH 147/147] fix calib value --- .../mne_scan/plugins/fieldline/fieldline.cpp | 2 +- .../plugins/fieldline/fieldline_acqsystem.cpp | 27 +++++++++---------- .../plugins/fieldline/fieldline_acqsystem.h | 8 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp index bee317ffcab..be166101ef0 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline.cpp @@ -195,7 +195,7 @@ bool Fieldline::start() void Fieldline::initFiffInfo() { m_pFiffInfo->sfreq = 1000.0f; - m_pFiffInfo->nchan = 2; + m_pFiffInfo->nchan = 3; m_pFiffInfo->chs.clear(); for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; chan_i++) { FIFFLIB::FiffChInfo channel; diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp index 1489fd62009..46dc4b721eb 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp @@ -316,7 +316,6 @@ static PyObject* PyInit_fieldline_callbacks(void) { static FieldlineAcqSystem* acq_system(nullptr); static PyObject* dict_parser(PyObject* self, PyObject* args) { - printLog("heeeelo!!!!!"); PyObject* dataDict; if (!PyArg_ParseTuple(args, "O", &dataDict)) { printLog("problem with dataDict."); @@ -337,14 +336,15 @@ static PyObject* dict_parser(PyObject* self, PyObject* args) { while (PyDict_Next(data_frames, &pos, &key, &value)) { PyObject* data = PyDict_GetItemString(value, "data"); - printLog(std::string("pos: ") + std::to_string(pos)); - printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); - float sample = (double) PyLong_AsLong(data); + //printLog(std::string("pos: ") + std::to_string(pos)); + //printLog(std::string("value: ") + std::to_string((double) PyLong_AsLong(data))); + double sample = PyLong_AsDouble(data); + Py_BEGIN_ALLOW_THREADS - acq_system->addSampleToSamplesColumn((int) pos-1, sample); + acq_system->addSampleToSamplesColumn(pos-1, sample); Py_END_ALLOW_THREADS - if (pos == 2) + if (pos == 3) break; } Py_INCREF(Py_None); @@ -368,7 +368,7 @@ static PyObject* PyInit_callbacks_parsing(void) { FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent) : m_pControllerParent(parent), m_numSamplesPerBlock(200), - m_numSensors(2) + m_numSensors(3) { printLog("Initializing Python"); printLog(libPythonBugFix); @@ -970,15 +970,12 @@ void FieldlineAcqSystem::initSampleArrays() m_samplesBlock = new double[m_numSensors * m_numSamplesPerBlock]; } -void FieldlineAcqSystem::addSampleToSamplesColumn(int sensorIdx, double value) +void FieldlineAcqSystem::addSampleToSamplesColumn(size_t sensorIdx, double value) { - static int sampleIdx = 0; - // printLog(std::string("sensorIdx: ") + std::to_string(sensorIdx)); - // printLog(std::string("sampleIdx: ") + std::to_string(sampleIdx)); - // printLog(std::string("m_numSensors = ") + std::to_string(m_numSensors)); - // printLog(std::string("m_numSamplesPerBlock = ") + std::to_string(m_numSamplesPerBlock)); - // printLog(std::string("m_samplesBlock[").append(std::to_string(sensorIdx * m_numSamplesPerBlock + sampleIdx)).append("] = ").append(std::to_string(value))); - m_samplesBlock[sensorIdx * m_numSamplesPerBlock + sampleIdx] = value; + static size_t sampleIdx = 0; + std::cout << "Value: " << 2.27e-15 * value << "\n"; + std::cout.flush(); + m_samplesBlock[sensorIdx * m_numSamplesPerBlock + sampleIdx] = 2.27e-15 * value; if (sensorIdx == m_numSensors -1) { sampleIdx++; if (sampleIdx == m_numSamplesPerBlock) { diff --git a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h index 49528938c6d..04c9c92f051 100644 --- a/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h +++ b/src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.h @@ -55,12 +55,12 @@ class FieldlineAcqSystem { void stopADC(); Fieldline* m_pControllerParent; void initSampleArrays(); - void addSampleToSamplesColumn(int sensorIdx, double value); + void addSampleToSamplesColumn(size_t sensorIdx, double value); void restartAllSensors(); void coarseZeroAllSensors(); void fineZeroAllSensors(); void setDataCallback(); - void setCloseLoop(); + void setCloseLoop(); private: void preConfigurePython() const; @@ -69,8 +69,8 @@ class FieldlineAcqSystem { void* loadCModule(const char* moduleName, void* (*moduleInitFunc)(void)); void* loadSensors(); - int m_numSamplesPerBlock; - int m_numSensors; + size_t m_numSamplesPerBlock; + size_t m_numSensors; void* m_fServiceInstance; void* m_pThreadState; void* m_pCallsModule;