##// END OF EJS Templates
Sync
jeandet -
r21:4db1f259222a default
parent child
Show More
@@ -1,124 +1,131
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 24 #include <QNetworkInterface>
25 25 #include <QByteArray>
26 26
27 27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
28 28 QWidget(parent),
29 29 ui(new Ui::SpwTcpPacketServer)
30 30 {
31 31 ui->setupUi(this);
32 32 this->p_bridge = NULL;
33 33 this->p_server = new QTcpServer();
34 34 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
35 35 updateHostIP();
36 36 this->ui->PortLineEdit->setText("2200");
37 connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
37 38 }
38 39
39 40 SpwTcpPacketServer::~SpwTcpPacketServer()
40 41 {
41 42 delete ui;
42 43 }
43 44
44 45 void SpwTcpPacketServer::setBridge(abstractSpwBridge *bridge)
45 46 {
46 47 if(this->p_bridge!=NULL)
47 48 {
48 49 disconnect(this,SLOT(pushPacket(char*,int)));
49 50 }
50 51 this->p_bridge = bridge;
51 52 connect(bridge,SIGNAL(pushPacketOverTCP(char*,int)),SLOT(pushPacket(char*,int)));
52 53 }
53 54
54 55 void SpwTcpPacketServer::pushPacket(char *packet, int size)
55 56 {
56 57 QByteArray data;
57 58 char sizech[3];
58 59 data.append((char)0);
59 60 sizech[0]=size & 0x0FF;
60 61 sizech[1]=(size>>8) & 0x0FF;
61 62 sizech[2]=(size>>16) & 0x0FF;
62 63 data.append(sizech,3);
63 64 data.append(packet,size);
64 65 for(int i=0;i<connectedClients.count();i++)
65 66 {
66 67 QTcpSocket* soc=connectedClients.at(i);
67 68 if(soc->state()!=QAbstractSocket::ConnectedState)
68 69 {
69 70 connectedClients.removeAt(i);
70 71 delete soc;
71 72 }
72 73 else
73 74 {
74 75 connectedClients.at(i)->write(data);
75 76 }
76 77 }
77 78 }
78 79
79 80 void SpwTcpPacketServer::toggleServer()
80 81 {
81 82 if(this->p_server->isListening())
82 83 {
83 84 disconnectServer();
84 85 }
85 86 else
86 87 {
87 88 connectServer();
88 89 }
89 90 }
90 91
91 92 void SpwTcpPacketServer::connectServer()
92 93 {
93 94 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
94 95 this->ui->startServeQpb->setText("Stop Server");
95 96 }
96 97
97 98 void SpwTcpPacketServer::disconnectServer()
98 99 {
99 100 this->ui->startServeQpb->setText("Start Server");
100 101 this->p_server->close();
101 102 }
102 103
103 104 void SpwTcpPacketServer::setServerPort(qint32 port)
104 105 {
105 106 this->ui->PortLineEdit->setText(QString("%1").arg(port));
106 107 }
107 108
109 void SpwTcpPacketServer::setServerSetIP(QString ip)
110 {
111 this->ui->IPLineEdit->setText(ip);
112 }
113
108 114 void SpwTcpPacketServer::newConnection()
109 115 {
110 116 this->connectedClients.append(this->p_server->nextPendingConnection());
117 this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString());
111 118 }
112 119
113 120 void SpwTcpPacketServer::updateHostIP()
114 121 {
115 122 QList<QHostAddress> list = QNetworkInterface::allAddresses();
116 123
117 124 for(int nIter=0; nIter<list.count(); nIter++)
118 125
119 126 {
120 127 if(!list[nIter].isLoopback())
121 128 if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
122 129 this->ui->IPLineEdit->setText(list[nIter].toString());
123 130 }
124 131 }
@@ -1,60 +1,61
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 28 #include <QList>
29 29 #include <QTcpSocket>
30 30
31 31 namespace Ui {
32 32 class SpwTcpPacketServer;
33 33 }
34 34
35 35 class SpwTcpPacketServer : public QWidget
36 36 {
37 37 Q_OBJECT
38 38
39 39 public:
40 40 explicit SpwTcpPacketServer(QWidget *parent = 0);
41 41 ~SpwTcpPacketServer();
42 42
43 43 void setBridge(abstractSpwBridge* bridge);
44 44
45 45 public slots:
46 46 void pushPacket(char* packet,int size);
47 47 void toggleServer();
48 48 void connectServer();
49 49 void disconnectServer();
50 50 void setServerPort(qint32 port);
51 void setServerSetIP(QString ip);
51 52 void newConnection();
52 53 private:
53 54 void updateHostIP();
54 55 Ui::SpwTcpPacketServer *ui;
55 56 abstractSpwBridge* p_bridge;
56 57 QTcpServer* p_server;
57 58 QList<QTcpSocket*> connectedClients;
58 59 };
59 60
60 61 #endif // SPWTCPPACKETSERVER_H
@@ -1,150 +1,151
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 49 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerConnect()),this->tcpServer,SLOT(connectServer()));
50 50 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerDisconnect()),this->tcpServer,SLOT(disconnectServer()));
51 51 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerSetPort(qint32)),this->tcpServer,SLOT(setServerPort(qint32)));
52 connect(((spwPyWrapper*)this->pyObject),SIGNAL(TCPServerSetIP(QString)),this->tcpServer,SLOT(setServerSetIP(QString)));
52 53 }
53 54
54 55
55 56 spwplugin::~spwplugin()
56 57 {
57 58
58 59 }
59 60
60 61
61 62
62 63 unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
63 64 {
64 65 if(Connected)
65 66 {
66 67 return bridge->Read(Value,count,address);
67 68 }
68 69 return 0;
69 70 }
70 71
71 72 void spwplugin::bridgeSelectionChanged(const QString &text)
72 73 {
73 74 printf("test");
74 75 if(text=="none")
75 76 {
76 77 if(this->bridge!=NULL)
77 78 {
78 79 this->mainLayout->removeWidget(this->bridge->getGUI());
79 80 this->disconnect(this,SLOT(setConnected(bool)));
80 81 delete this->bridge;
81 82 this->bridge= NULL;
82 83 }
83 84 }
84 85 if(text=="STAR-Dundee Spw USB Brick")
85 86 {
86 87 if(this->bridge!=NULL)
87 88 {
88 89 this->mainLayout->removeWidget(this->bridge->getGUI());
89 90 this->disconnect(this,SLOT(setConnected(bool)));
90 91 delete this->bridge;
91 92 }
92 93 this->bridge = new stardundeeSPW_USB(this);
93 94 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
94 95 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
95 96 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectBrick(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectBrick(int)));
96 97 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkNumber(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkNumber(int)));
97 98 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkSpeed(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkSpeed(int)));
98 99 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetDestinationKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetDestinationKey(QString)));
99 100 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapAddress(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapAddress(QString)));
100 101 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapKey(QString)));
101 102 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString)));
102 103 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
103 104 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
104 105 }
105 106 }
106 107
107 108
108 109 void spwplugin::selectBridge(const QString &text)
109 110 {
110 111
111 112 if(text=="none")
112 113 {
113 114 this->bridgeSelector->setCurrentIndex(0);
114 115 }
115 116 if(text=="STAR-Dundee Spw USB Brick")
116 117 {
117 118 this->bridgeSelector->setCurrentIndex(1);
118 119 }
119 120 }
120 121
121 122 void spwplugin::setConnected(bool connected)
122 123 {
123 124 this->bridgeSelector->setDisabled(connected);
124 125 this->Connected = connected;
125 126 emit activateSig(connected);
126 127 if(!this->scanDone)
127 128 {
128 129 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
129 130 this->scanDone=true;
130 131 }
131 132 }
132 133
133 134
134 135
135 136 unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
136 137 {
137 138 if(Connected)
138 139 {
139 140 return bridge->Write(Value,count,address);
140 141 }
141 142 return 0;
142 143 }
143 144
144 145
145 146
146 147
147 148
148 149
149 150
150 151
@@ -1,29 +1,30
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 10 signals:
11 11 void selectBridge(const QString &bridgeName);
12 12 bool connectBridge();
13 13 bool disconnectBridge();
14 14 void StarDundeeSelectBrick(int brickIndex);
15 15 void StarDundeeSelectLinkNumber(int linkIndex);
16 16 void StarDundeeSelectLinkSpeed(int linkSpeed);
17 17 void StarDundeeSetDestinationKey(const QString & destKey);
18 18 void StarDundeeSetRmapAddress(const QString & address);
19 19 void StarDundeeSetRmapKey(const QString & key);
20 20 void StarDundeeSetRmapTimeout(const QString & timeout);
21 21
22 22 void TCPServerConnect();
23 23 void TCPServerDisconnect();
24 24 void TCPServerSetPort(qint32 port);
25 void TCPServerSetIP(QString ip);
25 26 public slots:
26 27
27 28 };
28 29
29 30 #endif // SPWPYWRAPPER_H
General Comments 0
You need to be logged in to leave comments. Login now