##// END OF EJS Templates
Sync
Jeandet Alexis -
r20:d09469239955 default
parent child
Show More
@@ -1,68 +1,124
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "spwtcppacketserver.h"
23 23 #include "ui_spwtcppacketserver.h"
24 #include <QNetworkInterface>
25 #include <QByteArray>
24 26
25 27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
26 28 QWidget(parent),
27 29 ui(new Ui::SpwTcpPacketServer)
28 30 {
29 31 ui->setupUi(this);
30 32 this->p_bridge = NULL;
31 33 this->p_server = new QTcpServer();
32 34 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
35 updateHostIP();
36 this->ui->PortLineEdit->setText("2200");
33 37 }
34 38
35 39 SpwTcpPacketServer::~SpwTcpPacketServer()
36 40 {
37 41 delete ui;
38 42 }
39 43
40 44 void SpwTcpPacketServer::setBridge(abstractSpwBridge *bridge)
41 45 {
42 46 if(this->p_bridge!=NULL)
43 47 {
44 48 disconnect(this,SLOT(pushPacket(char*,int)));
45 49 }
46 50 this->p_bridge = bridge;
47 51 connect(bridge,SIGNAL(pushPacketOverTCP(char*,int)),SLOT(pushPacket(char*,int)));
48 52 }
49 53
50 54 void SpwTcpPacketServer::pushPacket(char *packet, int size)
51 55 {
52
56 QByteArray data;
57 char sizech[3];
58 data.append((char)0);
59 sizech[0]=size & 0x0FF;
60 sizech[1]=(size>>8) & 0x0FF;
61 sizech[2]=(size>>16) & 0x0FF;
62 data.append(sizech,3);
63 data.append(packet,size);
64 for(int i=0;i<connectedClients.count();i++)
65 {
66 QTcpSocket* soc=connectedClients.at(i);
67 if(soc->state()!=QAbstractSocket::ConnectedState)
68 {
69 connectedClients.removeAt(i);
70 delete soc;
71 }
72 else
73 {
74 connectedClients.at(i)->write(data);
75 }
76 }
53 77 }
54 78
55 79 void SpwTcpPacketServer::toggleServer()
56 80 {
57 81 if(this->p_server->isListening())
58 82 {
59 this->ui->startServeQpb->setText("Start Server");
60 this->p_server->close();
83 disconnectServer();
61 84 }
62 85 else
63 86 {
64 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
65
66 this->ui->startServeQpb->setText("Stop Server");
87 connectServer();
67 88 }
68 89 }
90
91 void SpwTcpPacketServer::connectServer()
92 {
93 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
94 this->ui->startServeQpb->setText("Stop Server");
95 }
96
97 void SpwTcpPacketServer::disconnectServer()
98 {
99 this->ui->startServeQpb->setText("Start Server");
100 this->p_server->close();
101 }
102
103 void SpwTcpPacketServer::setServerPort(qint32 port)
104 {
105 this->ui->PortLineEdit->setText(QString("%1").arg(port));
106 }
107
108 void SpwTcpPacketServer::newConnection()
109 {
110 this->connectedClients.append(this->p_server->nextPendingConnection());
111 }
112
113 void SpwTcpPacketServer::updateHostIP()
114 {
115 QList<QHostAddress> list = QNetworkInterface::allAddresses();
116
117 for(int nIter=0; nIter<list.count(); nIter++)
118
119 {
120 if(!list[nIter].isLoopback())
121 if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
122 this->ui->IPLineEdit->setText(list[nIter].toString());
123 }
124 }
@@ -1,52 +1,60
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef SPWTCPPACKETSERVER_H
23 23 #define SPWTCPPACKETSERVER_H
24 24
25 25 #include <QWidget>
26 26 #include <abstractspwbridge.h>
27 27 #include <QTcpServer>
28 #include <QList>
29 #include <QTcpSocket>
28 30
29 31 namespace Ui {
30 32 class SpwTcpPacketServer;
31 33 }
32 34
33 35 class SpwTcpPacketServer : public QWidget
34 36 {
35 37 Q_OBJECT
36 38
37 39 public:
38 40 explicit SpwTcpPacketServer(QWidget *parent = 0);
39 41 ~SpwTcpPacketServer();
40 42
41 43 void setBridge(abstractSpwBridge* bridge);
42 44
43 45 public slots:
44 46 void pushPacket(char* packet,int size);
45 47 void toggleServer();
48 void connectServer();
49 void disconnectServer();
50 void setServerPort(qint32 port);
51 void newConnection();
46 52 private:
53 void updateHostIP();
47 54 Ui::SpwTcpPacketServer *ui;
48 55 abstractSpwBridge* p_bridge;
49 56 QTcpServer* p_server;
57 QList<QTcpSocket*> connectedClients;
50 58 };
51 59
52 60 #endif // SPWTCPPACKETSERVER_H
@@ -1,147 +1,150
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "spwplugin.h"
24 24 #include "stardundeespw_usb.h"
25 25 #include <socexplorerproxy.h>
26 26 #include "spwpywrapper.h"
27 27
28 28 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false)
29 29 {
30 30 Q_UNUSED(parent)
31 31 this->bridge = NULL;
32 32 this->scanDone = false;
33 33 this->pyObject = new spwPyWrapper(this);
34 34 this->tcpServer = new SpwTcpPacketServer(this);
35 35 this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this);
36 36 this->bridgeSelector = new QComboBox(this);
37 37 this->mainTabWidgt = new QTabWidget(this);
38 38 this->mainTabWidgt->addTab(this->mainGroupBox,"Bridge Configuration");
39 39 this->mainTabWidgt->addTab(this->tcpServer,"TCP Server");
40 40 this->mainLayout = new QGridLayout(this->mainGroupBox);
41 41 this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter);
42 42 this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1);
43 43 //this->mainGroupBox->setLayout(this->mainLayout);
44 44 this->setWidget(this->mainTabWidgt);
45 45 this->bridgeSelector->addItem("none");
46 46 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
47 47 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
48 48 connect(((spwPyWrapper*)this->pyObject),SIGNAL(selectBridge(QString)),this,SLOT(selectBridge(QString)));
49 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerConnect()),this->tcpServer,SLOT(connectServer()));
50 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerDisconnect()),this->tcpServer,SLOT(disconnectServer()));
51 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerSetPort(qint32)),this->tcpServer,SLOT(setServerPort(qint32)));
49 52 }
50 53
51 54
52 55 spwplugin::~spwplugin()
53 56 {
54 57
55 58 }
56 59
57 60
58 61
59 62 unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
60 63 {
61 64 if(Connected)
62 65 {
63 66 return bridge->Read(Value,count,address);
64 67 }
65 68 return 0;
66 69 }
67 70
68 71 void spwplugin::bridgeSelectionChanged(const QString &text)
69 72 {
70 73 printf("test");
71 74 if(text=="none")
72 75 {
73 76 if(this->bridge!=NULL)
74 77 {
75 78 this->mainLayout->removeWidget(this->bridge->getGUI());
76 79 this->disconnect(this,SLOT(setConnected(bool)));
77 80 delete this->bridge;
78 81 this->bridge= NULL;
79 82 }
80 83 }
81 84 if(text=="STAR-Dundee Spw USB Brick")
82 85 {
83 86 if(this->bridge!=NULL)
84 87 {
85 88 this->mainLayout->removeWidget(this->bridge->getGUI());
86 89 this->disconnect(this,SLOT(setConnected(bool)));
87 90 delete this->bridge;
88 91 }
89 92 this->bridge = new stardundeeSPW_USB(this);
90 93 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
91 94 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
92 95 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectBrick(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectBrick(int)));
93 96 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkNumber(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkNumber(int)));
94 97 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkSpeed(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkSpeed(int)));
95 98 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetDestinationKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetDestinationKey(QString)));
96 99 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapAddress(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapAddress(QString)));
97 100 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapKey(QString)));
98 101 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString)));
99 102 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
100 103 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
101 104 }
105 }
102 106
103 }
104 107
105 108 void spwplugin::selectBridge(const QString &text)
106 109 {
107 110
108 111 if(text=="none")
109 112 {
110 113 this->bridgeSelector->setCurrentIndex(0);
111 114 }
112 115 if(text=="STAR-Dundee Spw USB Brick")
113 116 {
114 117 this->bridgeSelector->setCurrentIndex(1);
115 118 }
116 119 }
117 120
118 121 void spwplugin::setConnected(bool connected)
119 122 {
120 123 this->bridgeSelector->setDisabled(connected);
121 124 this->Connected = connected;
122 125 emit activateSig(connected);
123 126 if(!this->scanDone)
124 127 {
125 128 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
126 129 this->scanDone=true;
127 130 }
128 131 }
129 132
130 133
131 134
132 135 unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
133 136 {
134 137 if(Connected)
135 138 {
136 139 return bridge->Write(Value,count,address);
137 140 }
138 141 return 0;
139 142 }
140 143
141 144
142 145
143 146
144 147
145 148
146 149
147 150
@@ -1,76 +1,76
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef spwplugin_H
23 23 #define spwplugin_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include <QGroupBox>
29 29 #include <QComboBox>
30 30 #include <QLabel>
31 31 #include <QTabWidget>
32 32
33 33 #include <abstractspwbridge.h>
34 34 #include <socexplorerplugin.h>
35 35
36 36 #include "SpwTcpPacketServer/spwtcppacketserver.h"
37 37
38 38 class spwplugin : public socexplorerplugin
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 explicit spwplugin(QWidget *parent = 0);
43 43 ~spwplugin();
44 44 /* You can implement the folowing function if you want to overwrite
45 45 * their default behavior
46 46 */
47 47 /*
48 48 int registermenu(QMainWindow *menuHolder);
49 49 int isConnected();
50 50 int connect();
51 51 int VID(){return driver_VID;}
52 52 int PID(){return driver_PID;}
53 53 */
54 54
55 55 public slots:
56 56 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
57 57 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
58 58
59 59 void bridgeSelectionChanged( const QString & text );
60 60 void selectBridge( const QString & text );
61 61 void setConnected(bool connected);
62 62
63 63 signals:
64 64
65 65 private:
66 SpwTcpPacketServer* tcpServer;
66 67 abstractSpwBridge* bridge;
67 SpwTcpPacketServer* tcpServer;
68 68 bool scanDone;
69 69 QTabWidget* mainTabWidgt;
70 70 QGroupBox* mainGroupBox;
71 71 QComboBox* bridgeSelector;
72 72 QGridLayout* mainLayout;
73 73 };
74 74
75 75 #endif // spwplugin_H
76 76
@@ -1,26 +1,29
1 1 #ifndef SPWPYWRAPPER_H
2 2 #define SPWPYWRAPPER_H
3 3 #include <genericPySysdriver.h>
4 4
5 5 class spwPyWrapper : public genericPySysdriver
6 6 {
7 7 Q_OBJECT
8 8 public:
9 9 explicit spwPyWrapper(socexplorerplugin *parent = 0);
10
11 10 signals:
12 11 void selectBridge(const QString &bridgeName);
13 12 bool connectBridge();
14 13 bool disconnectBridge();
15 14 void StarDundeeSelectBrick(int brickIndex);
16 15 void StarDundeeSelectLinkNumber(int linkIndex);
17 16 void StarDundeeSelectLinkSpeed(int linkSpeed);
18 17 void StarDundeeSetDestinationKey(const QString & destKey);
19 18 void StarDundeeSetRmapAddress(const QString & address);
20 19 void StarDundeeSetRmapKey(const QString & key);
21 20 void StarDundeeSetRmapTimeout(const QString & timeout);
21
22 void TCPServerConnect();
23 void TCPServerDisconnect();
24 void TCPServerSetPort(qint32 port);
22 25 public slots:
23 26
24 27 };
25 28
26 29 #endif // SPWPYWRAPPER_H
General Comments 0
You need to be logged in to leave comments. Login now