##// END OF EJS Templates
Sync
Jeandet Alexis -
r20:d09469239955 default
parent child
Show More
@@ -21,6 +21,8
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),
@@ -30,6 +32,8 SpwTcpPacketServer::SpwTcpPacketServer(Q
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()
@@ -49,20 +53,72 void SpwTcpPacketServer::setBridge(abstr
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 }
@@ -25,6 +25,8
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;
@@ -43,10 +45,16 public:
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
@@ -46,6 +46,9 spwplugin::spwplugin(QWidget *parent):so
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
@@ -99,8 +102,8 void spwplugin::bridgeSelectionChanged(c
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 {
@@ -63,8 +63,8 public slots:
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;
@@ -7,7 +7,6 class spwPyWrapper : public genericPySys
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();
@@ -19,6 +18,10 signals:
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 };
General Comments 0
You need to be logged in to leave comments. Login now