##// END OF EJS Templates
Sync
Jeandet Alexis -
r20:d09469239955 default
parent child
Show More
@@ -21,6 +21,8
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "spwtcppacketserver.h"
22 #include "spwtcppacketserver.h"
23 #include "ui_spwtcppacketserver.h"
23 #include "ui_spwtcppacketserver.h"
24 #include <QNetworkInterface>
25 #include <QByteArray>
24
26
25 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
26 QWidget(parent),
28 QWidget(parent),
@@ -30,6 +32,8 SpwTcpPacketServer::SpwTcpPacketServer(Q
30 this->p_bridge = NULL;
32 this->p_bridge = NULL;
31 this->p_server = new QTcpServer();
33 this->p_server = new QTcpServer();
32 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
34 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
35 updateHostIP();
36 this->ui->PortLineEdit->setText("2200");
33 }
37 }
34
38
35 SpwTcpPacketServer::~SpwTcpPacketServer()
39 SpwTcpPacketServer::~SpwTcpPacketServer()
@@ -49,20 +53,72 void SpwTcpPacketServer::setBridge(abstr
49
53
50 void SpwTcpPacketServer::pushPacket(char *packet, int size)
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 void SpwTcpPacketServer::toggleServer()
79 void SpwTcpPacketServer::toggleServer()
56 {
80 {
57 if(this->p_server->isListening())
81 if(this->p_server->isListening())
58 {
82 {
59 this->ui->startServeQpb->setText("Start Server");
83 disconnectServer();
60 this->p_server->close();
61 }
84 }
62 else
85 else
63 {
86 {
87 connectServer();
88 }
89 }
90
91 void SpwTcpPacketServer::connectServer()
92 {
64 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
93 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
65
66 this->ui->startServeQpb->setText("Stop Server");
94 this->ui->startServeQpb->setText("Stop Server");
67 }
95 }
96
97 void SpwTcpPacketServer::disconnectServer()
98 {
99 this->ui->startServeQpb->setText("Start Server");
100 this->p_server->close();
68 }
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 }
@@ -25,6 +25,8
25 #include <QWidget>
25 #include <QWidget>
26 #include <abstractspwbridge.h>
26 #include <abstractspwbridge.h>
27 #include <QTcpServer>
27 #include <QTcpServer>
28 #include <QList>
29 #include <QTcpSocket>
28
30
29 namespace Ui {
31 namespace Ui {
30 class SpwTcpPacketServer;
32 class SpwTcpPacketServer;
@@ -43,10 +45,16 public:
43 public slots:
45 public slots:
44 void pushPacket(char* packet,int size);
46 void pushPacket(char* packet,int size);
45 void toggleServer();
47 void toggleServer();
48 void connectServer();
49 void disconnectServer();
50 void setServerPort(qint32 port);
51 void newConnection();
46 private:
52 private:
53 void updateHostIP();
47 Ui::SpwTcpPacketServer *ui;
54 Ui::SpwTcpPacketServer *ui;
48 abstractSpwBridge* p_bridge;
55 abstractSpwBridge* p_bridge;
49 QTcpServer* p_server;
56 QTcpServer* p_server;
57 QList<QTcpSocket*> connectedClients;
50 };
58 };
51
59
52 #endif // SPWTCPPACKETSERVER_H
60 #endif // SPWTCPPACKETSERVER_H
@@ -46,6 +46,9 spwplugin::spwplugin(QWidget *parent):so
46 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
46 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
47 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
47 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
48 connect(((spwPyWrapper*)this->pyObject),SIGNAL(selectBridge(QString)),this,SLOT(selectBridge(QString)));
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
@@ -99,8 +102,8 void spwplugin::bridgeSelectionChanged(c
99 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
102 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
100 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
103 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
101 }
104 }
105 }
102
106
103 }
104
107
105 void spwplugin::selectBridge(const QString &text)
108 void spwplugin::selectBridge(const QString &text)
106 {
109 {
@@ -63,8 +63,8 public slots:
63 signals:
63 signals:
64
64
65 private:
65 private:
66 SpwTcpPacketServer* tcpServer;
66 abstractSpwBridge* bridge;
67 abstractSpwBridge* bridge;
67 SpwTcpPacketServer* tcpServer;
68 bool scanDone;
68 bool scanDone;
69 QTabWidget* mainTabWidgt;
69 QTabWidget* mainTabWidgt;
70 QGroupBox* mainGroupBox;
70 QGroupBox* mainGroupBox;
@@ -7,7 +7,6 class spwPyWrapper : public genericPySys
7 Q_OBJECT
7 Q_OBJECT
8 public:
8 public:
9 explicit spwPyWrapper(socexplorerplugin *parent = 0);
9 explicit spwPyWrapper(socexplorerplugin *parent = 0);
10
11 signals:
10 signals:
12 void selectBridge(const QString &bridgeName);
11 void selectBridge(const QString &bridgeName);
13 bool connectBridge();
12 bool connectBridge();
@@ -19,6 +18,10 signals:
19 void StarDundeeSetRmapAddress(const QString & address);
18 void StarDundeeSetRmapAddress(const QString & address);
20 void StarDundeeSetRmapKey(const QString & key);
19 void StarDundeeSetRmapKey(const QString & key);
21 void StarDundeeSetRmapTimeout(const QString & timeout);
20 void StarDundeeSetRmapTimeout(const QString & timeout);
21
22 void TCPServerConnect();
23 void TCPServerDisconnect();
24 void TCPServerSetPort(qint32 port);
22 public slots:
25 public slots:
23
26
24 };
27 };
General Comments 0
You need to be logged in to leave comments. Login now