diff --git a/spwplugin/abstractspwbridge.cpp b/spwplugin/abstractspwbridge.cpp --- a/spwplugin/abstractspwbridge.cpp +++ b/spwplugin/abstractspwbridge.cpp @@ -1,9 +1,31 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ #include "abstractspwbridge.h" abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent) :QObject((QObject*)parent) { this->plugin = parent; + this->p_GUI=NULL; } QWidget *abstractSpwBridge::getGUI() diff --git a/spwplugin/abstractspwbridge.h b/spwplugin/abstractspwbridge.h --- a/spwplugin/abstractspwbridge.h +++ b/spwplugin/abstractspwbridge.h @@ -1,3 +1,24 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ #ifndef ABSTRACTSPWBRIDGE_H #define ABSTRACTSPWBRIDGE_H diff --git a/spwplugin/spw.h b/spwplugin/spw.h --- a/spwplugin/spw.h +++ b/spwplugin/spw.h @@ -1,3 +1,24 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ #ifndef SPW_H #define SPW_H #include diff --git a/spwplugin/spwplugin.cpp b/spwplugin/spwplugin.cpp --- a/spwplugin/spwplugin.cpp +++ b/spwplugin/spwplugin.cpp @@ -1,8 +1,25 @@ /*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ + #include "spwplugin.h" #include "stardundeespw_usb.h" #include @@ -10,13 +27,18 @@ spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,true) { Q_UNUSED(parent) - this->bridge = new stardundeeSPW_USB(this); + this->bridge = NULL; this->scanDone = false; - if(this->bridge->connectBridge()) - { - this->Connected = true; - emit this->activateSig(true); - } + this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this); + this->bridgeSelector = new QComboBox(this); + this->mainLayout = new QGridLayout(this); + this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter); + this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1); + this->mainGroupBox->setLayout(this->mainLayout); + this->setWidget(this->mainGroupBox); + this->bridgeSelector->addItem("none"); + this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick"); + connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString))); } @@ -36,6 +58,31 @@ unsigned int spwplugin::Read(unsigned in return 0; } +void spwplugin::bridgeSelectionChanged(const QString &text) +{ + printf("test"); + if(text=="none") + { + if(this->bridge!=NULL) + { + this->mainLayout->removeWidget(this->bridge->getGUI()); + delete this->bridge; + this->bridge= NULL; + } + } + if(text=="STAR-Dundee Spw USB Brick") + { + if(this->bridge!=NULL) + { + this->mainLayout->removeWidget(this->bridge->getGUI()); + delete this->bridge; + } + this->bridge = new stardundeeSPW_USB(this); + this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2); + } + +} + unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) diff --git a/spwplugin/spwplugin.h b/spwplugin/spwplugin.h --- a/spwplugin/spwplugin.h +++ b/spwplugin/spwplugin.h @@ -1,4 +1,20 @@ /*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org @@ -9,6 +25,9 @@ #include #include #include +#include +#include +#include #include #include @@ -35,12 +54,16 @@ public slots: unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); + void bridgeSelectionChanged( const QString & text ); + signals: private: abstractSpwBridge* bridge; bool scanDone; - + QGroupBox* mainGroupBox; + QComboBox* bridgeSelector; + QGridLayout* mainLayout; }; #endif // spwplugin_H diff --git a/spwplugin/stardundeespw_usb.cpp b/spwplugin/stardundeespw_usb.cpp --- a/spwplugin/stardundeespw_usb.cpp +++ b/spwplugin/stardundeespw_usb.cpp @@ -1,3 +1,25 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ + #include "stardundeespw_usb.h" #include #include @@ -6,10 +28,40 @@ stardundeeSPW_USB::stardundeeSPW_USB(soc abstractSpwBridge(parent) { Q_UNUSED(parent) - this->manager = new stardundeeSPW_USB_Manager(parent); + this->p_GUI = new QWidget(parent); + this->mainLayout = new QGridLayout(this->p_GUI); + this->p_GUI->setLayout(mainLayout); + this->connectBridgeButton = new QPushButton("Connect"); + this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1); + connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection())); + this->manager = new stardundeeSPW_USB_Manager(parent,this); this->manager->start(); } +stardundeeSPW_USB::~stardundeeSPW_USB() +{ + this->manager->requestInterruption(); + delete this->p_GUI; +} + +void stardundeeSPW_USB::toggleBridgeConnection() +{ + if(this->plugin->isConnected()) + { + if(this->disconnectBridge()) + { + this->connectBridgeButton->setText("Connect"); + } + } + else + { + if(this->connectBridge()) + { + this->connectBridgeButton->setText("Disconnect"); + } + } +} + bool stardundeeSPW_USB::connectBridge() { return this->manager->connectBridge(); @@ -143,14 +195,14 @@ unsigned int stardundeeSPW_USB::Read(uns return read; } -stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *parent) +stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent) :QThread((QObject*)parent) { this->handleMutex = new QMutex(QMutex::NonRecursive); this->RMAP_AnswersSem = new QSemaphore(0); this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive); this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive); - this->plugin = parent; + this->plugin = plugin; connected = false; } diff --git a/spwplugin/stardundeespw_usb.h b/spwplugin/stardundeespw_usb.h --- a/spwplugin/stardundeespw_usb.h +++ b/spwplugin/stardundeespw_usb.h @@ -1,3 +1,24 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ #ifndef STARDUNDEESPW_USB_H #define STARDUNDEESPW_USB_H @@ -9,6 +30,8 @@ #include #include #include +#include +#include class RMAP_Answer { @@ -28,7 +51,7 @@ class stardundeeSPW_USB_Manager: public { Q_OBJECT public: - explicit stardundeeSPW_USB_Manager(socexplorerplugin *parent = 0); + explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0); ~stardundeeSPW_USB_Manager(); void run(); bool connectBridge(); @@ -53,10 +76,12 @@ class stardundeeSPW_USB : public abstrac Q_OBJECT public: explicit stardundeeSPW_USB(socexplorerplugin *parent = 0); + ~stardundeeSPW_USB(); signals: public slots: + void toggleBridgeConnection(); bool connectBridge(); bool disconnectBridge(); int pushRMAPPacket(char* packet,int size); @@ -65,7 +90,8 @@ public slots: private: stardundeeSPW_USB_Manager* manager; - + QGridLayout* mainLayout; + QPushButton* connectBridgeButton; }; #endif // STARDUNDEESPW_USB_H