@@ -1,23 +1,145 | |||
|
1 | 1 | #include "gr_esb_bridge.h" |
|
2 | 2 | #include "gr_esb_ui.h" |
|
3 | 3 | #include <unistd.h> |
|
4 | #include "spw.h" | |
|
5 | #include <socexplorerengine.h> | |
|
4 | 6 | |
|
5 | 7 | GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) : |
|
6 | 8 | abstractSpwBridge(parent) |
|
7 | 9 | { |
|
8 | 10 | this->p_GUI = new GR_ESB_ui(); |
|
9 | this->Read_soc = new QTcpSocket(this); | |
|
10 | this->Write_soc = new QTcpSocket(this); | |
|
11 | this->manager = new GR_ESB_Manager(parent,this); | |
|
12 | ||
|
11 | 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(set |
|
|
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 | 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 | 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 | 143 | int timeout=60; |
|
22 | 144 | if(this->Read_soc->state()==QTcpSocket::UnconnectedState) |
|
23 | 145 | { |
@@ -35,60 +157,46 bool GR_ESB_bridge::connectBridge() | |||
|
35 | 157 | if(timeout--==0)return false; |
|
36 | 158 | } |
|
37 | 159 | return true; |
|
160 | ||
|
38 | 161 | } |
|
39 | 162 | |
|
40 |
bool GR_ESB_ |
|
|
163 | bool GR_ESB_Manager::disconnectBridge() | |
|
41 | 164 | { |
|
42 | 165 | int timeout=60; |
|
43 | 166 | if(this->Read_soc->state()!=QTcpSocket::UnconnectedState) |
|
44 | 167 | { |
|
45 | 168 | this->Read_soc->disconnectFromHost(); |
|
46 | 169 | this->Read_soc->waitForDisconnected(30000); |
|
47 | while(this->Read_soc->state()!=QTcpSocket::UnconnectedState) | |
|
48 | { | |
|
49 | usleep(100000); | |
|
50 | if(timeout--==0)return false; | |
|
51 | } | |
|
170 | } | |
|
171 | if(this->Write_soc->state()!=QTcpSocket::UnconnectedState) | |
|
172 | { | |
|
173 | this->Write_soc->disconnectFromHost(); | |
|
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 | 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) | |
|
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) | |
|
189 | int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer) | |
|
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 |
|
|
|
199 | void GR_ESB_Manager::pushRmapPacket(char *packet, int len) | |
|
92 | 200 | { |
|
93 | 201 | |
|
94 | 202 | } |
@@ -2,6 +2,9 | |||
|
2 | 2 | #define GR_ESB_BRIDGE_H |
|
3 | 3 | #include "abstractspwbridge.h" |
|
4 | 4 | #include <QTcpSocket> |
|
5 | #include <QThread> | |
|
6 | #include <QMutex> | |
|
7 | #include <QSemaphore> | |
|
5 | 8 | |
|
6 | 9 | struct gresb_Conf_str |
|
7 | 10 | { |
@@ -9,6 +12,7 struct gresb_Conf_str | |||
|
9 | 12 | qint32 Write_port; |
|
10 | 13 | }; |
|
11 | 14 | |
|
15 | ||
|
12 | 16 | const struct gresb_Conf_str gresb_Conf[]= |
|
13 | 17 | { |
|
14 | 18 | {3000,3001}, //Virtual link 0 |
@@ -19,6 +23,41 const struct gresb_Conf_str gresb_Conf[] | |||
|
19 | 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 | 61 | class GR_ESB_bridge : public abstractSpwBridge |
|
23 | 62 | { |
|
24 | 63 | Q_OBJECT |
@@ -29,6 +68,7 signals: | |||
|
29 | 68 | |
|
30 | 69 | |
|
31 | 70 | public slots: |
|
71 | void toggleBridgeConnection(); | |
|
32 | 72 | bool connectBridge(); |
|
33 | 73 | bool disconnectBridge(); |
|
34 | 74 | void setIP(QString ip); |
@@ -40,10 +80,8 public slots: | |||
|
40 | 80 | void packetReceived(); |
|
41 | 81 | |
|
42 | 82 | private: |
|
43 | QTcpSocket* Read_soc; | |
|
44 | QTcpSocket* Write_soc; | |
|
45 | QString IP; | |
|
46 | int virtualLinkIndex; | |
|
83 | ||
|
84 | GR_ESB_Manager* manager; | |
|
47 | 85 | |
|
48 | 86 | }; |
|
49 | 87 |
@@ -9,6 +9,7 GR_ESB_ui::GR_ESB_ui(QWidget *parent) : | |||
|
9 | 9 | ui->setupUi(this); |
|
10 | 10 | connect(this->ui->GRESB_IP_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changeIp(QString))); |
|
11 | 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 | 15 | void GR_ESB_ui::changeIp(QString ip) |
@@ -17,3 +18,14 void GR_ESB_ui::changeIp(QString ip) | |||
|
17 | 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 | 17 | public slots: |
|
18 | 18 | void changeIp(QString ip); |
|
19 | ||
|
19 | void lock(bool lock); | |
|
20 | 20 | signals: |
|
21 | 21 | void ipchanged(QString ip); |
|
22 | 22 | void vlinkchanged(QString vlink); |
|
23 | void connectClicked(); | |
|
23 | 24 | private: |
|
24 | 25 | Ui::GR_ESB_ui *ui; |
|
25 | 26 | }; |
@@ -6,8 +6,8 | |||
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 |
<width> |
|
|
10 |
<height> |
|
|
9 | <width>968</width> | |
|
10 | <height>392</height> | |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
@@ -107,6 +107,13 | |||
|
107 | 107 | </property> |
|
108 | 108 | </widget> |
|
109 | 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 | 117 | </layout> |
|
111 | 118 | </widget> |
|
112 | 119 | <widget class="QWidget" name="Web"> |
@@ -6,8 +6,8 | |||
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 |
<width> |
|
|
10 |
<height> |
|
|
9 | <width>726</width> | |
|
10 | <height>535</height> | |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
@@ -65,16 +65,45 | |||
|
65 | 65 | </widget> |
|
66 | 66 | </item> |
|
67 | 67 | <item> |
|
68 |
<widget class="QGroupBox" name=" |
|
|
68 | <widget class="QGroupBox" name="groupBox"> | |
|
69 | 69 | <property name="title"> |
|
70 |
<string> |
|
|
70 | <string>Server Statistics</string> | |
|
71 | 71 | </property> |
|
72 | <property name="flat"> | |
|
73 | <bool>false</bool> | |
|
74 | </property> | |
|
75 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |
|
76 | <item> | |
|
77 | <widget class="QListWidget" name="listWidget"/> | |
|
72 | <layout class="QGridLayout" name="gridLayout"> | |
|
73 | <item row="2" column="0" colspan="2"> | |
|
74 | <widget class="QGroupBox" name="clientListGroupBox_2"> | |
|
75 | <property name="title"> | |
|
76 | <string>Connected clients</string> | |
|
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 | 107 | </item> |
|
79 | 108 | </layout> |
|
80 | 109 | </widget> |
@@ -36,19 +36,7 | |||
|
36 | 36 | #include <QLabel> |
|
37 | 37 | #include "stardundeegui.h" |
|
38 | 38 | |
|
39 | class RMAP_Answer | |
|
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 | }; | |
|
39 | ||
|
52 | 40 | |
|
53 | 41 | class stardundeeSPW_USB_Manager: public QThread |
|
54 | 42 | { |
@@ -27,6 +27,20 | |||
|
27 | 27 | #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes |
|
28 | 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 | 44 | class abstractSpwBridge : public QObject |
|
31 | 45 | { |
|
32 | 46 | Q_OBJECT |
@@ -26,6 +26,7 | |||
|
26 | 26 | #include <socexplorerproxy.h> |
|
27 | 27 | #include "spwpywrapper.h" |
|
28 | 28 | |
|
29 | ||
|
29 | 30 | spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false) |
|
30 | 31 | { |
|
31 | 32 | Q_UNUSED(parent) |
@@ -35,6 +35,8 | |||
|
35 | 35 | |
|
36 | 36 | #include "SpwTcpPacketServer/spwtcppacketserver.h" |
|
37 | 37 | |
|
38 | // TODO switch to a class factory approach with self registration | |
|
39 | ||
|
38 | 40 | class spwplugin : public socexplorerplugin |
|
39 | 41 | { |
|
40 | 42 | Q_OBJECT |
@@ -70,6 +72,7 private: | |||
|
70 | 72 | QGroupBox* mainGroupBox; |
|
71 | 73 | QComboBox* bridgeSelector; |
|
72 | 74 | QGridLayout* mainLayout; |
|
75 | ||
|
73 | 76 | }; |
|
74 | 77 | |
|
75 | 78 | #endif // spwplugin_H |
General Comments 0
You need to be logged in to leave comments.
Login now