##// END OF EJS Templates
Sync
Jeandet Alexis -
r9:f3bd193d674d default
parent child
Show More
@@ -1,516 +1,521
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22
22
23 #include "stardundeespw_usb.h"
23 #include "stardundeespw_usb.h"
24 #include <socexplorerengine.h>
24 #include <socexplorerengine.h>
25 #include <qhexedit.h>
25 #include <qhexedit.h>
26
26
27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
28 abstractSpwBridge(parent)
28 abstractSpwBridge(parent)
29 {
29 {
30 Q_UNUSED(parent)
30 Q_UNUSED(parent)
31 this->p_GUI = new QWidget(parent);
32 this->mainLayout = new QGridLayout(this->p_GUI);
33 this->p_GUI->setLayout(mainLayout);
34 this->connectBridgeButton = new QPushButton("Connect");
35 this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1);
36 connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
37 this->manager = new stardundeeSPW_USB_Manager(parent,this);
31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
32 makeGUI(socexplorerplugin *parent);
38 this->manager->start();
33 this->manager->start();
39 }
34 }
40
35
41 stardundeeSPW_USB::~stardundeeSPW_USB()
36 stardundeeSPW_USB::~stardundeeSPW_USB()
42 {
37 {
43 this->manager->requestInterruption();
38 this->manager->requestInterruption();
44 delete this->p_GUI;
39 delete this->p_GUI;
45 }
40 }
46
41
47 void stardundeeSPW_USB::toggleBridgeConnection()
42 void stardundeeSPW_USB::toggleBridgeConnection()
48 {
43 {
49 if(this->plugin->isConnected())
44 if(this->plugin->isConnected())
50 {
45 {
51 if(this->disconnectBridge())
46 if(this->disconnectBridge())
52 {
47 {
53 this->connectBridgeButton->setText("Connect");
48 this->connectBridgeButton->setText("Connect");
54 }
49 }
55 }
50 }
56 else
51 else
57 {
52 {
58 if(this->connectBridge())
53 if(this->connectBridge())
59 {
54 {
60 this->connectBridgeButton->setText("Disconnect");
55 this->connectBridgeButton->setText("Disconnect");
61 }
56 }
62 }
57 }
63 }
58 }
64
59
65 bool stardundeeSPW_USB::connectBridge()
60 bool stardundeeSPW_USB::connectBridge()
66 {
61 {
67 return this->manager->connectBridge();
62 return this->manager->connectBridge();
68 }
63 }
69
64
70 bool stardundeeSPW_USB::disconnectBridge()
65 bool stardundeeSPW_USB::disconnectBridge()
71 {
66 {
72 return this->manager->disconnectBridge();
67 return this->manager->disconnectBridge();
73 }
68 }
74
69
75 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
70 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
76 {
71 {
77 return this->manager->sendPacket(packet,size);
72 return this->manager->sendPacket(packet,size);
78 }
73 }
79
74
80 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
75 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
81 {
76 {
82 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
77 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
83 writeBuffer[0]=1;//Link number
78 writeBuffer[0]=1;//Link number
84 int transactionID = 0;
79 int transactionID = 0;
85 int written=0;
80 int written=0;
86 SocExplorerEngine::message(this->plugin,"Enter Write function");
81 SocExplorerEngine::message(this->plugin,"Enter Write function");
87 QProgressBar* progress=NULL;
82 QProgressBar* progress=NULL;
88 if(count>RMAP_MAX_XFER_SIZE)
83 if(count>RMAP_MAX_XFER_SIZE)
89 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
84 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
90 //Quite stupide loop, I guess that I always get the number of byte I asked for!
85 //Quite stupide loop, I guess that I always get the number of byte I asked for!
91 while(count>=RMAP_MAX_XFER_SIZE)
86 while(count>=RMAP_MAX_XFER_SIZE)
92 {
87 {
93 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
88 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
94 {
89 {
95 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
90 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
96 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
91 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
97 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
92 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
98 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
93 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
99 }
94 }
100 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
95 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
101 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
96 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
102 written+=RMAP_MAX_XFER_SIZE;
97 written+=RMAP_MAX_XFER_SIZE;
103 count-=RMAP_MAX_XFER_SIZE;
98 count-=RMAP_MAX_XFER_SIZE;
104 progress->setValue(written);
99 progress->setValue(written);
105 qApp->processEvents();
100 qApp->processEvents();
106 }
101 }
107 if(count>0)
102 if(count>0)
108 {
103 {
109 for(int i=0;i<((int)count);i++)
104 for(int i=0;i<((int)count);i++)
110 {
105 {
111 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
106 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
112 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
107 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
113 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
108 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
114 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
109 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
115 }
110 }
116 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
111 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
117 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
112 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
118 written+=count;
113 written+=count;
119 if(progress!=NULL)
114 if(progress!=NULL)
120 {
115 {
121 progress->setValue(written);
116 progress->setValue(written);
122 qApp->processEvents();
117 qApp->processEvents();
123 }
118 }
124 }
119 }
125 if(progress!=NULL)
120 if(progress!=NULL)
126 {
121 {
127 SocExplorerEngine::deleteProgressBar(progress);
122 SocExplorerEngine::deleteProgressBar(progress);
128 }
123 }
129 return written;
124 return written;
130 }
125 }
131
126
132 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
127 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
133 {
128 {
134 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
129 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
135 char* RMAP_AnswerBuffer;
130 char* RMAP_AnswerBuffer;
136 requestBuffer[0]=1;//Link number
131 requestBuffer[0]=1;//Link number
137 int transactionID = 0;
132 int transactionID = 0;
138 int read=0;
133 int read=0;
139 QProgressBar* progress=NULL;
134 QProgressBar* progress=NULL;
140 if(count>RMAP_MAX_XFER_SIZE)
135 if(count>RMAP_MAX_XFER_SIZE)
141 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
136 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
142 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
137 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
143
138
144 //Quite stupide loop, I guess that I always get the number of byte I asked for!
139 //Quite stupide loop, I guess that I always get the number of byte I asked for!
145 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
140 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
146 {
141 {
147 transactionID = manager->getRMAPtransactionID();
142 transactionID = manager->getRMAPtransactionID();
148 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
143 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
149 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
144 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
150 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
145 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
151 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
146 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
152 for(int i=0;i<((len-13)/4);i++)
147 for(int i=0;i<((len-13)/4);i++)
153 {
148 {
154 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
149 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
155 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
150 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
156 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
151 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
157 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
152 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
158 }
153 }
159 free(RMAP_AnswerBuffer);
154 free(RMAP_AnswerBuffer);
160 read+=RMAP_MAX_XFER_SIZE;
155 read+=RMAP_MAX_XFER_SIZE;
161 count-=RMAP_MAX_XFER_SIZE;
156 count-=RMAP_MAX_XFER_SIZE;
162 progress->setValue(read);
157 progress->setValue(read);
163 qApp->processEvents();
158 qApp->processEvents();
164 }
159 }
165 if((int)count>0)
160 if((int)count>0)
166 {
161 {
167 transactionID = manager->getRMAPtransactionID();
162 transactionID = manager->getRMAPtransactionID();
168 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
163 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
169 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
164 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
170 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
165 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
171 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
166 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
172 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
167 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
173 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
168 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
174 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
169 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
175 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
170 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
176 for(int i=0;i<((len-13)/4);i++)
171 for(int i=0;i<((len-13)/4);i++)
177 {
172 {
178 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
173 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
179 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
174 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
180 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
175 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
181 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
176 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
182 }
177 }
183 free(RMAP_AnswerBuffer);
178 free(RMAP_AnswerBuffer);
184 read+=count;
179 read+=count;
185 if(progress!=NULL)
180 if(progress!=NULL)
186 {
181 {
187 progress->setValue(read);
182 progress->setValue(read);
188 qApp->processEvents();
183 qApp->processEvents();
189 }
184 }
190 }
185 }
191 if(progress!=NULL)
186 if(progress!=NULL)
192 {
187 {
193 SocExplorerEngine::deleteProgressBar(progress);
188 SocExplorerEngine::deleteProgressBar(progress);
194 }
189 }
195 return read;
190 return read;
196 }
191 }
197
192
193 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
194 {
195 this->p_GUI = new QWidget(parent);
196 this->mainLayout = new QGridLayout(this->p_GUI);
197 this->p_GUI->setLayout(mainLayout);
198 this->connectBridgeButton = new QPushButton("Connect");
199 this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1);
200 connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
201 }
202
198 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
203 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
199 :QThread((QObject*)parent)
204 :QThread((QObject*)parent)
200 {
205 {
201 this->handleMutex = new QMutex(QMutex::NonRecursive);
206 this->handleMutex = new QMutex(QMutex::NonRecursive);
202 this->RMAP_AnswersSem = new QSemaphore(0);
207 this->RMAP_AnswersSem = new QSemaphore(0);
203 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
208 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
204 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
209 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
205 this->plugin = plugin;
210 this->plugin = plugin;
206 connected = false;
211 connected = false;
207 }
212 }
208
213
209 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
214 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
210 {
215 {
211 this->terminate();
216 this->terminate();
212 while (!this->isFinished()) {
217 while (!this->isFinished()) {
213 this->usleep(1000);
218 this->usleep(1000);
214 }
219 }
215 }
220 }
216
221
217
222
218 void stardundeeSPW_USB_Manager::run()
223 void stardundeeSPW_USB_Manager::run()
219 {
224 {
220 USB_SPACEWIRE_PACKET_PROPERTIES properties;
225 USB_SPACEWIRE_PACKET_PROPERTIES properties;
221 USB_SPACEWIRE_ID pIdentifier=NULL;
226 USB_SPACEWIRE_ID pIdentifier=NULL;
222 USB_SPACEWIRE_STATUS stat;
227 USB_SPACEWIRE_STATUS stat;
223 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
228 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
224 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
229 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
225 while (!this->isInterruptionRequested())
230 while (!this->isInterruptionRequested())
226 {
231 {
227 if(this->connected)
232 if(this->connected)
228 {
233 {
229 handleMutex->lock();
234 handleMutex->lock();
230 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
235 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
231 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
236 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
232 {
237 {
233 SocExplorerEngine::message(this->plugin,"Got packet");
238 SocExplorerEngine::message(this->plugin,"Got packet");
234 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
239 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
235 if (stat == TRANSFER_SUCCESS)
240 if (stat == TRANSFER_SUCCESS)
236 {
241 {
237 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
242 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
238 {
243 {
239 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
244 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
240 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
245 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
241 {
246 {
242 SocExplorerEngine::message(this->plugin,"Got end of packet");
247 SocExplorerEngine::message(this->plugin,"Got end of packet");
243 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
248 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
244 {
249 {
245 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
250 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
246 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
251 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
247 if(properties.len>8)
252 if(properties.len>8)
248 {
253 {
249 char* packetbuffer = (char*)malloc(properties.len);
254 char* packetbuffer = (char*)malloc(properties.len);
250 memcpy(packetbuffer,buffer,properties.len);
255 memcpy(packetbuffer,buffer,properties.len);
251 USBSpaceWire_FreeRead(hDevice, pIdentifier);
256 USBSpaceWire_FreeRead(hDevice, pIdentifier);
252 pIdentifier = NULL;
257 pIdentifier = NULL;
253 handleMutex->unlock();
258 handleMutex->unlock();
254 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
259 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
255 RMAP_AnswersMtx->lock();
260 RMAP_AnswersMtx->lock();
256 RMAP_Answers.append(packet);
261 RMAP_Answers.append(packet);
257 RMAP_AnswersMtx->unlock();
262 RMAP_AnswersMtx->unlock();
258 RMAP_AnswersSem->release();
263 RMAP_AnswersSem->release();
259
264
260 }
265 }
261 else //it's a RMAP write response
266 else //it's a RMAP write response
262 {
267 {
263 USBSpaceWire_FreeRead(hDevice, pIdentifier);
268 USBSpaceWire_FreeRead(hDevice, pIdentifier);
264 pIdentifier = NULL;
269 pIdentifier = NULL;
265 handleMutex->unlock();
270 handleMutex->unlock();
266 }
271 }
267
272
268 }
273 }
269 else //any non-rmap packet will be pushed to the network
274 else //any non-rmap packet will be pushed to the network
270 {
275 {
271 USBSpaceWire_FreeRead(hDevice, pIdentifier);
276 USBSpaceWire_FreeRead(hDevice, pIdentifier);
272 handleMutex->unlock();
277 handleMutex->unlock();
273 SocExplorerEngine::message(this->plugin,"Got SPW packet");
278 SocExplorerEngine::message(this->plugin,"Got SPW packet");
274 }
279 }
275 }
280 }
276 else
281 else
277 {
282 {
278 SocExplorerEngine::message(this->plugin,"No EOP received");
283 SocExplorerEngine::message(this->plugin,"No EOP received");
279 }
284 }
280 }
285 }
281
286
282 }
287 }
283 else
288 else
284 {
289 {
285 USBSpaceWire_FreeRead(hDevice, pIdentifier);
290 USBSpaceWire_FreeRead(hDevice, pIdentifier);
286 handleMutex->unlock();
291 handleMutex->unlock();
287 }
292 }
288 }
293 }
289 else
294 else
290 {
295 {
291 USBSpaceWire_FreeRead(hDevice, pIdentifier);
296 USBSpaceWire_FreeRead(hDevice, pIdentifier);
292 handleMutex->unlock();
297 handleMutex->unlock();
293 }
298 }
294 }
299 }
295 else
300 else
296 {
301 {
297 sleep(1);
302 sleep(1);
298 SocExplorerEngine::message(this->plugin,"Bridge not connected");
303 SocExplorerEngine::message(this->plugin,"Bridge not connected");
299 }
304 }
300 usleep(1000);
305 usleep(1000);
301 // sleep(2);
306 // sleep(2);
302 }
307 }
303 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
308 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
304 }
309 }
305
310
306 bool stardundeeSPW_USB_Manager::connectBridge()
311 bool stardundeeSPW_USB_Manager::connectBridge()
307 {
312 {
308 this->handleMutex->lock();
313 this->handleMutex->lock();
309 int status;
314 int status;
310 U32 statusControl;
315 U32 statusControl;
311 int brickNumber=0;
316 int brickNumber=0;
312 int linkNumber=1;
317 int linkNumber=1;
313 this->connected = false;
318 this->connected = false;
314 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
319 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
315 {
320 {
316 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
321 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
317 this->handleMutex->unlock();
322 this->handleMutex->unlock();
318 return false;
323 return false;
319 }
324 }
320 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
325 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
321
326
322 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
327 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
323 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
328 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
324 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
329 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
325
330
326 // Set the path and return path to the device
331 // Set the path and return path to the device
327 CFGSpaceWire_StackClear();
332 CFGSpaceWire_StackClear();
328 CFGSpaceWire_AddrStackPush(0);
333 CFGSpaceWire_AddrStackPush(0);
329 CFGSpaceWire_AddrStackPush(254);
334 CFGSpaceWire_AddrStackPush(254);
330 CFGSpaceWire_RetAddrStackPush(254);
335 CFGSpaceWire_RetAddrStackPush(254);
331 // set the base transmit rate to 100 MHz
336 // set the base transmit rate to 100 MHz
332 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
337 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
333 if (status != CFG_TRANSFER_SUCCESS)
338 if (status != CFG_TRANSFER_SUCCESS)
334 {
339 {
335 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
340 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
336 return false;
341 return false;
337 }
342 }
338 else
343 else
339 {
344 {
340 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
345 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
341 }
346 }
342
347
343 // read the link status
348 // read the link status
344 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
349 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
345 {
350 {
346 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
351 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
347 return false;
352 return false;
348 }
353 }
349 else
354 else
350 {
355 {
351 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
356 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
352
357
353 // Set the link status control register properties
358 // Set the link status control register properties
354 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
359 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
355 CFGSpaceWire_LSEnableStart(&statusControl, 1);
360 CFGSpaceWire_LSEnableStart(&statusControl, 1);
356 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
361 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
357 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
362 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
358 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
363 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
359
364
360 // Set the link status control register
365 // Set the link status control register
361 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
366 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
362 {
367 {
363 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
368 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
364 return false;
369 return false;
365 }
370 }
366 else
371 else
367 {
372 {
368 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
373 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
369 }
374 }
370 }
375 }
371
376
372 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
377 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
373 {
378 {
374 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
379 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
375 return false;
380 return false;
376 }
381 }
377 else
382 else
378 {
383 {
379 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
384 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
380 }
385 }
381
386
382 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
387 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
383 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
388 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
384 USBSpaceWire_SetTimeout(hDevice,1.0);
389 USBSpaceWire_SetTimeout(hDevice,1.0);
385 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
390 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
386 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
391 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
387 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
392 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
388 this->connected = true;
393 this->connected = true;
389 this->handleMutex->unlock();
394 this->handleMutex->unlock();
390 return true;
395 return true;
391 }
396 }
392
397
393 bool stardundeeSPW_USB_Manager::disconnectBridge()
398 bool stardundeeSPW_USB_Manager::disconnectBridge()
394 {
399 {
395 this->handleMutex->lock();
400 this->handleMutex->lock();
396 USBSpaceWire_Close(hDevice); // Close the device
401 USBSpaceWire_Close(hDevice); // Close the device
397 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
402 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
398 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
403 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
399 this->handleMutex->unlock();
404 this->handleMutex->unlock();
400 return true;
405 return true;
401 }
406 }
402
407
403 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
408 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
404 {
409 {
405 this->RMAP_pending_transaction_IDsMtx->lock();
410 this->RMAP_pending_transaction_IDsMtx->lock();
406 int ID=0;
411 int ID=0;
407 bool found=true;
412 bool found=true;
408 while(ID<65536)
413 while(ID<65536)
409 {
414 {
410 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
415 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
411 {
416 {
412 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
417 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
413 }
418 }
414 if(found==true)break;
419 if(found==true)break;
415 ID++;
420 ID++;
416 found = true;
421 found = true;
417 }
422 }
418 if(found)
423 if(found)
419 {
424 {
420 RMAP_pending_transaction_IDs.append(ID);
425 RMAP_pending_transaction_IDs.append(ID);
421 }
426 }
422 this->RMAP_pending_transaction_IDsMtx->unlock();
427 this->RMAP_pending_transaction_IDsMtx->unlock();
423 return ID;
428 return ID;
424 }
429 }
425
430
426 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
431 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
427 {
432 {
428 *buffer=NULL;
433 *buffer=NULL;
429 int count=0;
434 int count=0;
430 while (*buffer==NULL)
435 while (*buffer==NULL)
431 {
436 {
432 this->RMAP_AnswersMtx->lock();
437 this->RMAP_AnswersMtx->lock();
433 for(int i=0;i<RMAP_Answers.count();i++)
438 for(int i=0;i<RMAP_Answers.count();i++)
434 {
439 {
435 if(RMAP_Answers[i]->transactionID==transactionID)
440 if(RMAP_Answers[i]->transactionID==transactionID)
436 {
441 {
437 this->RMAP_pending_transaction_IDsMtx->lock();
442 this->RMAP_pending_transaction_IDsMtx->lock();
438 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
443 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
439 {
444 {
440 if(RMAP_pending_transaction_IDs[j]==transactionID)
445 if(RMAP_pending_transaction_IDs[j]==transactionID)
441 {
446 {
442 RMAP_pending_transaction_IDs.removeAt(j);
447 RMAP_pending_transaction_IDs.removeAt(j);
443 }
448 }
444 }
449 }
445 this->RMAP_pending_transaction_IDsMtx->unlock();
450 this->RMAP_pending_transaction_IDsMtx->unlock();
446 *buffer = RMAP_Answers[i]->data;
451 *buffer = RMAP_Answers[i]->data;
447 count = RMAP_Answers[i]->len;
452 count = RMAP_Answers[i]->len;
448 RMAP_Answer* tmp=RMAP_Answers[i];
453 RMAP_Answer* tmp=RMAP_Answers[i];
449 RMAP_Answers.removeAt(i);
454 RMAP_Answers.removeAt(i);
450 delete tmp;
455 delete tmp;
451 }
456 }
452 }
457 }
453 this->RMAP_AnswersMtx->unlock();
458 this->RMAP_AnswersMtx->unlock();
454 //if no answer found in the stack wait until a new packet is pushed
459 //if no answer found in the stack wait until a new packet is pushed
455 if(!buffer)
460 if(!buffer)
456 {
461 {
457 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
462 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
458 this->RMAP_AnswersSem->acquire();
463 this->RMAP_AnswersSem->acquire();
459 }
464 }
460 }
465 }
461 return count;
466 return count;
462 }
467 }
463
468
464 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
469 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
465 {
470 {
466 USB_SPACEWIRE_STATUS result;
471 USB_SPACEWIRE_STATUS result;
467 USB_SPACEWIRE_ID pIdentifier;
472 USB_SPACEWIRE_ID pIdentifier;
468 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
473 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
469 this->handleMutex->lock();
474 this->handleMutex->lock();
470 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
475 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
471 if (result != TRANSFER_SUCCESS)
476 if (result != TRANSFER_SUCCESS)
472 {
477 {
473 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
478 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
474 this->handleMutex->unlock();
479 this->handleMutex->unlock();
475 return false;
480 return false;
476 }
481 }
477 else
482 else
478 {
483 {
479 SocExplorerEngine::message(this->plugin,"Packet sent");
484 SocExplorerEngine::message(this->plugin,"Packet sent");
480 USBSpaceWire_FreeSend(hDevice, pIdentifier);
485 USBSpaceWire_FreeSend(hDevice, pIdentifier);
481 }
486 }
482 this->handleMutex->unlock();
487 this->handleMutex->unlock();
483 return true;
488 return true;
484 }
489 }
485
490
486 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
491 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
487 {
492 {
488 char* packetbuffer = (char*)malloc(len);
493 char* packetbuffer = (char*)malloc(len);
489 memcpy(packetbuffer,packet,len);
494 memcpy(packetbuffer,packet,len);
490 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
495 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
491 RMAP_AnswersMtx->lock();
496 RMAP_AnswersMtx->lock();
492 RMAP_Answers.append(RMPAPpacket);
497 RMAP_Answers.append(RMPAPpacket);
493 RMAP_AnswersMtx->unlock();
498 RMAP_AnswersMtx->unlock();
494 }
499 }
495
500
496
501
497
502
498
503
499
504
500
505
501
506
502
507
503
508
504
509
505
510
506
511
507
512
508
513
509
514
510
515
511
516
512
517
513
518
514
519
515
520
516
521
@@ -1,97 +1,99
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef STARDUNDEESPW_USB_H
22 #ifndef STARDUNDEESPW_USB_H
23 #define STARDUNDEESPW_USB_H
23 #define STARDUNDEESPW_USB_H
24
24
25 #include <QObject>
25 #include <QObject>
26 #include <spw_usb_api.h>
26 #include <spw_usb_api.h>
27 #include <spw_config_library.h>
27 #include <spw_config_library.h>
28 #include <socexplorerplugin.h>
28 #include <socexplorerplugin.h>
29 #include <abstractspwbridge.h>
29 #include <abstractspwbridge.h>
30 #include <QThread>
30 #include <QThread>
31 #include <QMutex>
31 #include <QMutex>
32 #include <QSemaphore>
32 #include <QSemaphore>
33 #include <QGridLayout>
33 #include <QGridLayout>
34 #include <QPushButton>
34 #include <QPushButton>
35
35
36 class RMAP_Answer
36 class RMAP_Answer
37 {
37 {
38 public:
38 public:
39 RMAP_Answer(int ID,char* data,int len)
39 RMAP_Answer(int ID,char* data,int len)
40 {
40 {
41 transactionID = ID;
41 transactionID = ID;
42 this->data = data;
42 this->data = data;
43 this->len = len;
43 this->len = len;
44 }
44 }
45 int transactionID;
45 int transactionID;
46 char* data;
46 char* data;
47 int len;
47 int len;
48 };
48 };
49
49
50 class stardundeeSPW_USB_Manager: public QThread
50 class stardundeeSPW_USB_Manager: public QThread
51 {
51 {
52 Q_OBJECT
52 Q_OBJECT
53 public:
53 public:
54 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
54 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
55 ~stardundeeSPW_USB_Manager();
55 ~stardundeeSPW_USB_Manager();
56 void run();
56 void run();
57 bool connectBridge();
57 bool connectBridge();
58 bool disconnectBridge();
58 bool disconnectBridge();
59 int getRMAPtransactionID();
59 int getRMAPtransactionID();
60 int getRMAPanswer(int transactionID,char** buffer);
60 int getRMAPanswer(int transactionID,char** buffer);
61 bool sendPacket(char* packet,int size);
61 bool sendPacket(char* packet,int size);
62 private:
62 private:
63 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
63 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
64 QSemaphore* RMAP_AnswersSem;
64 QSemaphore* RMAP_AnswersSem;
65 void pushRmapPacket(char* packet,int len);
65 void pushRmapPacket(char* packet,int len);
66 star_device_handle hDevice;
66 star_device_handle hDevice;
67 socexplorerplugin* plugin;
67 socexplorerplugin* plugin;
68 bool connected;
68 bool connected;
69 char* SPWPacketBuff;
69 char* SPWPacketBuff;
70 QList<RMAP_Answer*> RMAP_Answers;
70 QList<RMAP_Answer*> RMAP_Answers;
71 QList<int> RMAP_pending_transaction_IDs;
71 QList<int> RMAP_pending_transaction_IDs;
72 int linkNumber;
72 };
73 };
73
74
74 class stardundeeSPW_USB : public abstractSpwBridge
75 class stardundeeSPW_USB : public abstractSpwBridge
75 {
76 {
76 Q_OBJECT
77 Q_OBJECT
77 public:
78 public:
78 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
79 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
79 ~stardundeeSPW_USB();
80 ~stardundeeSPW_USB();
80
81
81 signals:
82 signals:
82
83
83 public slots:
84 public slots:
84 void toggleBridgeConnection();
85 void toggleBridgeConnection();
85 bool connectBridge();
86 bool connectBridge();
86 bool disconnectBridge();
87 bool disconnectBridge();
87 int pushRMAPPacket(char* packet,int size);
88 int pushRMAPPacket(char* packet,int size);
88 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
89 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
89 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
90 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
90
91
91 private:
92 private:
93 void makeGUI(socexplorerplugin *parent);
92 stardundeeSPW_USB_Manager* manager;
94 stardundeeSPW_USB_Manager* manager;
93 QGridLayout* mainLayout;
95 QGridLayout* mainLayout;
94 QPushButton* connectBridgeButton;
96 QPushButton* connectBridgeButton;
95 };
97 };
96
98
97 #endif // STARDUNDEESPW_USB_H
99 #endif // STARDUNDEESPW_USB_H
General Comments 0
You need to be logged in to leave comments. Login now