##// END OF EJS Templates
Some work on GRESB driver for spwplugin.
Jeandet Alexis -
r25:8fdbbdd7a3a4 default
parent child
Show More
@@ -1,23 +1,145
1 #include "gr_esb_bridge.h"
1 #include "gr_esb_bridge.h"
2 #include "gr_esb_ui.h"
2 #include "gr_esb_ui.h"
3 #include <unistd.h>
3 #include <unistd.h>
4 #include "spw.h"
5 #include <socexplorerengine.h>
4
6
5 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
7 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
6 abstractSpwBridge(parent)
8 abstractSpwBridge(parent)
7 {
9 {
8 this->p_GUI = new GR_ESB_ui();
10 this->p_GUI = new GR_ESB_ui();
9 this->Read_soc = new QTcpSocket(this);
11 this->manager = new GR_ESB_Manager(parent,this);
10 this->Write_soc = new QTcpSocket(this);
12
11 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
13 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
12 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setPort(QString)));
14 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
15 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
16 this->manager->virtualLinkIndex = 0;
17 this->manager->start();
13 }
18 }
14
19
15 GR_ESB_bridge::~GR_ESB_bridge()
20 GR_ESB_bridge::~GR_ESB_bridge()
16 {
21 {
17 }
22 }
18
23
24 void GR_ESB_bridge::toggleBridgeConnection()
25 {
26 if(this->plugin->isConnected())
27 {
28 this->disconnectBridge();
29 }
30 else
31 {
32 this->connectBridge();
33 }
34 }
35
19 bool GR_ESB_bridge::connectBridge()
36 bool GR_ESB_bridge::connectBridge()
20 {
37 {
38 if(this->manager->connectBridge())
39 {
40 ((GR_ESB_ui*)this->p_GUI)->lock(true);
41 emit setConnected(true);
42 return true;
43 }
44 return false;
45 }
46
47 bool GR_ESB_bridge::disconnectBridge()
48 {
49 if(this->manager->disconnectBridge())
50 {
51 ((GR_ESB_ui*)this->p_GUI)->lock(false);
52 emit setConnected(false);
53 return true;
54 }
55 return false;
56 }
57
58 void GR_ESB_bridge::setIP(QString ip)
59 {
60 this->manager->IP = ip;
61 }
62
63 void GR_ESB_bridge::setVirtualLink(QString vlink)
64 {
65 vlink = vlink.section("Virtual link",0,0);
66 bool success;
67 int vlinkTmp = vlink.toInt(&success);
68 if(success)
69 {
70 setVirtualLink(vlinkTmp);
71 }
72 }
73
74 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
75 {
76 if(vlink<6 && vlink>=0)
77 {
78 this->manager->virtualLinkIndex = vlink;
79 }
80 }
81
82
83 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
84 {
85
86 }
87
88 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
89 {
90
91 }
92
93 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
94 {
95 return this->manager->sendPacket(packet,size);
96 }
97
98
99 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
100 :QThread((QObject*)parent)
101 {
102 this->Read_soc = new QTcpSocket(this);
103 this->Write_soc = new QTcpSocket(this);
104 this->RMAPtimeout = 2000;
105 this->handleMutex = new QMutex(QMutex::NonRecursive);
106 this->RMAP_AnswersSem = new QSemaphore(0);
107 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
108 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
109 this->plugin = plugin;
110 connected = false;
111 this->moveToThread(this);
112 }
113
114 GR_ESB_Manager::~GR_ESB_Manager()
115 {
116
117 }
118
119 void GR_ESB_Manager::run()
120 {
121 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
122 while (!this->isInterruptionRequested())
123 {
124 if(this->connected)
125 {
126 handleMutex->lock();
127 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
128
129 }
130 else
131 {
132 //do some sanity checks!
133
134 usleep(RMAPtimeout/2);
135 }
136 usleep(1000);
137 }
138 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
139 }
140
141 bool GR_ESB_Manager::connectBridge()
142 {
21 int timeout=60;
143 int timeout=60;
22 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
144 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
23 {
145 {
@@ -35,60 +157,46 bool GR_ESB_bridge::connectBridge()
35 if(timeout--==0)return false;
157 if(timeout--==0)return false;
36 }
158 }
37 return true;
159 return true;
160
38 }
161 }
39
162
40 bool GR_ESB_bridge::disconnectBridge()
163 bool GR_ESB_Manager::disconnectBridge()
41 {
164 {
42 int timeout=60;
165 int timeout=60;
43 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
166 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
44 {
167 {
45 this->Read_soc->disconnectFromHost();
168 this->Read_soc->disconnectFromHost();
46 this->Read_soc->waitForDisconnected(30000);
169 this->Read_soc->waitForDisconnected(30000);
47 while(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
170 }
48 {
171 if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
49 usleep(100000);
172 {
50 if(timeout--==0)return false;
173 this->Write_soc->disconnectFromHost();
51 }
174 this->Write_soc->waitForDisconnected(30000);
175 }
176 while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
177 {
178 usleep(100000);
179 if(timeout--==0)return false;
52 }
180 }
53 return true;
181 return true;
54 }
182 }
55
183
56 void GR_ESB_bridge::setIP(QString ip)
184 int GR_ESB_Manager::getRMAPtransactionID()
57 {
185 {
58 this->IP = ip;
186
59 }
187 }
60
188
61 void GR_ESB_bridge::setVirtualLink(QString vlink)
189 int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
62 {
63 vlink = vlink.section("Virtual link",0,0);
64 bool success;
65 int vlinkTmp = vlink.toInt(&success);
66 if(success)
67 {
68 setVirtualLink(vlinkTmp);
69 }
70 }
71
72 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
73 {
74 if(vlink<6 && vlink>=0)
75 {
76 virtualLinkIndex = vlink;
77 }
78 }
79
80
81 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
82 {
190 {
83
191
84 }
192 }
85
193
86 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
194 bool GR_ESB_Manager::sendPacket(char *packet, int size)
87 {
195 {
88
196
89 }
197 }
90
198
91 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
199 void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
92 {
200 {
93
201
94 }
202 }
@@ -2,6 +2,9
2 #define GR_ESB_BRIDGE_H
2 #define GR_ESB_BRIDGE_H
3 #include "abstractspwbridge.h"
3 #include "abstractspwbridge.h"
4 #include <QTcpSocket>
4 #include <QTcpSocket>
5 #include <QThread>
6 #include <QMutex>
7 #include <QSemaphore>
5
8
6 struct gresb_Conf_str
9 struct gresb_Conf_str
7 {
10 {
@@ -9,6 +12,7 struct gresb_Conf_str
9 qint32 Write_port;
12 qint32 Write_port;
10 };
13 };
11
14
15
12 const struct gresb_Conf_str gresb_Conf[]=
16 const struct gresb_Conf_str gresb_Conf[]=
13 {
17 {
14 {3000,3001}, //Virtual link 0
18 {3000,3001}, //Virtual link 0
@@ -19,6 +23,41 const struct gresb_Conf_str gresb_Conf[]
19 {3010,3011} //Virtual link 5
23 {3010,3011} //Virtual link 5
20 };
24 };
21
25
26
27 class GR_ESB_Manager: public QThread
28 {
29 Q_OBJECT
30 public:
31 explicit GR_ESB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
32 ~GR_ESB_Manager();
33 void run();
34 bool connectBridge();
35 bool disconnectBridge();
36 int getRMAPtransactionID();
37 int getRMAPanswer(int transactionID,char** buffer);
38 bool sendPacket(char* packet,int size);
39
40 signals:
41 void emitPacket(char* packet,int size);
42 private:
43 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
44 QSemaphore* RMAP_AnswersSem;
45 void pushRmapPacket(char* packet,int len);
46 socexplorerplugin* plugin;
47 bool connected;
48 char* SPWPacketBuff;
49 QList<RMAP_Answer*> RMAP_Answers;
50 QList<int> RMAP_pending_transaction_IDs;
51
52 public:
53 QTcpSocket* Read_soc;
54 QTcpSocket* Write_soc;
55 QString IP;
56 int virtualLinkIndex;
57 int RMAPtimeout;
58 };
59
60
22 class GR_ESB_bridge : public abstractSpwBridge
61 class GR_ESB_bridge : public abstractSpwBridge
23 {
62 {
24 Q_OBJECT
63 Q_OBJECT
@@ -29,6 +68,7 signals:
29
68
30
69
31 public slots:
70 public slots:
71 void toggleBridgeConnection();
32 bool connectBridge();
72 bool connectBridge();
33 bool disconnectBridge();
73 bool disconnectBridge();
34 void setIP(QString ip);
74 void setIP(QString ip);
@@ -40,10 +80,8 public slots:
40 void packetReceived();
80 void packetReceived();
41
81
42 private:
82 private:
43 QTcpSocket* Read_soc;
83
44 QTcpSocket* Write_soc;
84 GR_ESB_Manager* manager;
45 QString IP;
46 int virtualLinkIndex;
47
85
48 };
86 };
49
87
@@ -9,6 +9,7 GR_ESB_ui::GR_ESB_ui(QWidget *parent) :
9 ui->setupUi(this);
9 ui->setupUi(this);
10 connect(this->ui->GRESB_IP_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changeIp(QString)));
10 connect(this->ui->GRESB_IP_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changeIp(QString)));
11 connect(this->ui->GRESB_Vlink_CmBx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(vlinkchanged(QString)));
11 connect(this->ui->GRESB_Vlink_CmBx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(vlinkchanged(QString)));
12 connect(this->ui->connectQpb,SIGNAL(clicked()),this,SIGNAL(connectClicked()));
12 }
13 }
13
14
14 void GR_ESB_ui::changeIp(QString ip)
15 void GR_ESB_ui::changeIp(QString ip)
@@ -17,3 +18,14 void GR_ESB_ui::changeIp(QString ip)
17 emit this->ipchanged(ip);
18 emit this->ipchanged(ip);
18 }
19 }
19
20
21 void GR_ESB_ui::lock(bool lock)
22 {
23 this->ui->GRESB_IP_lineEdit->setDisabled(lock);
24 this->ui->GRESB_LinkNum_CmBx->setDisabled(lock);
25 this->ui->GRESB_Vlink_CmBx->setDisabled(lock);
26 if(lock)
27 this->ui->connectQpb->setText("Disconnect");
28 else
29 this->ui->connectQpb->setText("Connect");
30 }
31
@@ -16,10 +16,11 public:
16
16
17 public slots:
17 public slots:
18 void changeIp(QString ip);
18 void changeIp(QString ip);
19
19 void lock(bool lock);
20 signals:
20 signals:
21 void ipchanged(QString ip);
21 void ipchanged(QString ip);
22 void vlinkchanged(QString vlink);
22 void vlinkchanged(QString vlink);
23 void connectClicked();
23 private:
24 private:
24 Ui::GR_ESB_ui *ui;
25 Ui::GR_ESB_ui *ui;
25 };
26 };
@@ -6,8 +6,8
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>489</width>
9 <width>968</width>
10 <height>295</height>
10 <height>392</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
@@ -107,6 +107,13
107 </property>
107 </property>
108 </widget>
108 </widget>
109 </item>
109 </item>
110 <item row="3" column="0" colspan="2">
111 <widget class="QPushButton" name="connectQpb">
112 <property name="text">
113 <string>Connect</string>
114 </property>
115 </widget>
116 </item>
110 </layout>
117 </layout>
111 </widget>
118 </widget>
112 <widget class="QWidget" name="Web">
119 <widget class="QWidget" name="Web">
@@ -6,8 +6,8
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>671</width>
9 <width>726</width>
10 <height>409</height>
10 <height>535</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
@@ -65,16 +65,45
65 </widget>
65 </widget>
66 </item>
66 </item>
67 <item>
67 <item>
68 <widget class="QGroupBox" name="clientListGroupBox_2">
68 <widget class="QGroupBox" name="groupBox">
69 <property name="title">
69 <property name="title">
70 <string>Connected clients</string>
70 <string>Server Statistics</string>
71 </property>
71 </property>
72 <property name="flat">
72 <layout class="QGridLayout" name="gridLayout">
73 <bool>false</bool>
73 <item row="2" column="0" colspan="2">
74 </property>
74 <widget class="QGroupBox" name="clientListGroupBox_2">
75 <layout class="QVBoxLayout" name="verticalLayout_2">
75 <property name="title">
76 <item>
76 <string>Connected clients</string>
77 <widget class="QListWidget" name="listWidget"/>
77 </property>
78 <property name="flat">
79 <bool>false</bool>
80 </property>
81 <layout class="QVBoxLayout" name="verticalLayout_2">
82 <item>
83 <widget class="QListWidget" name="listWidget"/>
84 </item>
85 </layout>
86 </widget>
87 </item>
88 <item row="0" column="1">
89 <widget class="QLCDNumber" name="lcdNumber"/>
90 </item>
91 <item row="0" column="0">
92 <widget class="QLabel" name="label">
93 <property name="text">
94 <string>Sended Packets</string>
95 </property>
96 </widget>
97 </item>
98 <item row="1" column="0">
99 <widget class="QLabel" name="label_2">
100 <property name="text">
101 <string>Received Packets</string>
102 </property>
103 </widget>
104 </item>
105 <item row="1" column="1">
106 <widget class="QLCDNumber" name="lcdNumber_2"/>
78 </item>
107 </item>
79 </layout>
108 </layout>
80 </widget>
109 </widget>
@@ -36,19 +36,7
36 #include <QLabel>
36 #include <QLabel>
37 #include "stardundeegui.h"
37 #include "stardundeegui.h"
38
38
39 class RMAP_Answer
39
40 {
41 public:
42 RMAP_Answer(int ID,char* data,int len)
43 {
44 transactionID = ID;
45 this->data = data;
46 this->len = len;
47 }
48 int transactionID;
49 char* data;
50 int len;
51 };
52
40
53 class stardundeeSPW_USB_Manager: public QThread
41 class stardundeeSPW_USB_Manager: public QThread
54 {
42 {
@@ -27,6 +27,20
27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
28 #include <spw.h>
28 #include <spw.h>
29
29
30 class RMAP_Answer
31 {
32 public:
33 RMAP_Answer(int ID,char* data,int len)
34 {
35 transactionID = ID;
36 this->data = data;
37 this->len = len;
38 }
39 int transactionID;
40 char* data;
41 int len;
42 };
43
30 class abstractSpwBridge : public QObject
44 class abstractSpwBridge : public QObject
31 {
45 {
32 Q_OBJECT
46 Q_OBJECT
@@ -26,6 +26,7
26 #include <socexplorerproxy.h>
26 #include <socexplorerproxy.h>
27 #include "spwpywrapper.h"
27 #include "spwpywrapper.h"
28
28
29
29 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false)
30 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false)
30 {
31 {
31 Q_UNUSED(parent)
32 Q_UNUSED(parent)
@@ -35,6 +35,8
35
35
36 #include "SpwTcpPacketServer/spwtcppacketserver.h"
36 #include "SpwTcpPacketServer/spwtcppacketserver.h"
37
37
38 // TODO switch to a class factory approach with self registration
39
38 class spwplugin : public socexplorerplugin
40 class spwplugin : public socexplorerplugin
39 {
41 {
40 Q_OBJECT
42 Q_OBJECT
@@ -70,6 +72,7 private:
70 QGroupBox* mainGroupBox;
72 QGroupBox* mainGroupBox;
71 QComboBox* bridgeSelector;
73 QComboBox* bridgeSelector;
72 QGridLayout* mainLayout;
74 QGridLayout* mainLayout;
75
73 };
76 };
74
77
75 #endif // spwplugin_H
78 #endif // spwplugin_H
General Comments 0
You need to be logged in to leave comments. Login now