##// END OF EJS Templates
Backported SPW work from GRESB branch.
Alexis Jeandet -
r78:61fd409c32ee default
parent child
Show More
@@ -1,15 +1,16
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 CONFIG += ordered
2 CONFIG += ordered
3
3
4
4
5 SUBDIRS = \
5 SUBDIRS = \
6 ahbuartplugin \
6 ahbuartplugin \
7 ambaplugin \
7 ambaplugin \
8 APBUARTPLUGIN \
8 APBUARTPLUGIN \
9 dsu3plugin \
9 dsu3plugin \
10 genericrwplugin \
10 genericrwplugin \
11 memctrlrplugin \
11 memctrlrplugin \
12 memcheckplugin
12 memcheckplugin
13
13 unix:SUBDIRS += spwplugin
14 unix:SUBDIRS += spwplugin
14
15
15 OTHER_FILES += SocExplorer-plugins.spec
16 OTHER_FILES += SocExplorer-plugins.spec
@@ -1,242 +1,514
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - 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 #include "gr_esb_bridge.h"
22 #include "gr_esb_bridge.h"
23 #include "gr_esb_ui.h"
23 #include "gr_esb_ui.h"
24 #include <unistd.h>
24 #include <unistd.h>
25 #include "spw.h"
25 #include "spw.h"
26 #include <socexplorerengine.h>
26 #include <socexplorerengine.h>
27
27
28 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
28 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
29 abstractSpwBridge(parent)
29 abstractSpwBridge(parent)
30 {
30 {
31 this->p_GUI = new GR_ESB_ui();
31 this->p_GUI = new GR_ESB_ui();
32 this->manager = new GR_ESB_Manager(parent,this);
32 this->manager = new GR_ESB_Manager(parent,this);
33
33
34 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
34 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
35 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
35 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
36 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
36 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
37 this->manager->virtualLinkIndex = 0;
37 this->manager->virtualLinkIndex = 0;
38 this->manager->start();
38 this->manager->start();
39 }
39 }
40
40
41 GR_ESB_bridge::~GR_ESB_bridge()
41 GR_ESB_bridge::~GR_ESB_bridge()
42 {
42 {
43 this->manager->requestInterruption();
43 this->manager->requestInterruption();
44 while(this->manager->isRunning());
44 while(this->manager->isRunning());
45 }
45 }
46
46
47 void GR_ESB_bridge::toggleBridgeConnection()
47 void GR_ESB_bridge::toggleBridgeConnection()
48 {
48 {
49 if(this->plugin->isConnected())
49 if(this->plugin->isConnected())
50 {
50 {
51 this->disconnectBridge();
51 this->disconnectBridge();
52 }
52 }
53 else
53 else
54 {
54 {
55 this->connectBridge();
55 this->connectBridge();
56 }
56 }
57 }
57 }
58
58
59 bool GR_ESB_bridge::connectBridge()
59 bool GR_ESB_bridge::connectBridge()
60 {
60 {
61 if(this->manager->connectBridge())
61 if(this->manager->connectBridge())
62 {
62 {
63 ((GR_ESB_ui*)this->p_GUI)->lock(true);
63 ((GR_ESB_ui*)this->p_GUI)->lock(true);
64 emit setConnected(true);
64 emit setConnected(true);
65 return true;
65 return true;
66 }
66 }
67 return false;
67 return false;
68 }
68 }
69
69
70 bool GR_ESB_bridge::disconnectBridge()
70 bool GR_ESB_bridge::disconnectBridge()
71 {
71 {
72 if(this->manager->disconnectBridge())
72 if(this->manager->disconnectBridge())
73 {
73 {
74 ((GR_ESB_ui*)this->p_GUI)->lock(false);
74 ((GR_ESB_ui*)this->p_GUI)->lock(false);
75 emit setConnected(false);
75 emit setConnected(false);
76 return true;
76 return true;
77 }
77 }
78 return false;
78 return false;
79 }
79 }
80
80
81 void GR_ESB_bridge::setIP(QString ip)
81 void GR_ESB_bridge::setIP(QString ip)
82 {
82 {
83 this->manager->IP = ip;
83 this->manager->IP = ip;
84 }
84 }
85
85
86 void GR_ESB_bridge::setVirtualLink(QString vlink)
86 void GR_ESB_bridge::setVirtualLink(QString vlink)
87 {
87 {
88 vlink = vlink.section("Virtual link",0,0);
88 //vlink = vlink.section(,0,0);
89 vlink.remove("Virtual link");
89 bool success;
90 bool success;
90 int vlinkTmp = vlink.toInt(&success);
91 int vlinkTmp = vlink.toInt(&success);
91 if(success)
92 if(success)
92 {
93 {
93 setVirtualLink(vlinkTmp);
94 setVirtualLink(vlinkTmp);
94 }
95 }
95 }
96 }
96
97
97 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
98 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
98 {
99 {
99 if(vlink<6 && vlink>=0)
100 if(vlink<6 && vlink>=0)
100 {
101 {
101 this->manager->virtualLinkIndex = vlink;
102 this->manager->virtualLinkIndex = vlink;
102 }
103 }
103 }
104 }
104
105
105
106
106 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
107 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
107 {
108 {
108 // TODO write ME!
109 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))];
109 Q_UNUSED(count)
110 char *RMAPAckBuff;
110 Q_UNUSED(Value)
111 int transactionID = 0;
111 Q_UNUSED(address)
112 int written=0;
112 return 0;
113 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
114 QProgressBar* progress=NULL;
115 SocExplorerAutoProgressBar autopb;
116 if(count>RMAP_MAX_XFER_SIZE)
117 {
118 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
119 autopb.setProgressBar(progress);
120 }
121 //Quite stupide loop, I guess that I always get the number of byte I asked for!
122 while(count>=RMAP_MAX_XFER_SIZE)
123 {
124 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
125 {
126 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+0] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
127 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
128 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
129 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written])&0xFF);
130 }
131 transactionID=manager->getRMAPtransactionID();
132 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
133 RMAP_build_tx_request_header(
134 this->manager->destinationLogicalAddress,
135 this->manager->destinationKey,
136 this->manager->sourceLogicalAddress,
137 transactionID,
138 address+(written*4),
139 RMAP_MAX_XFER_SIZE*4,
140 writeBuffer);
141 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4));
142 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
143 free(RMAPAckBuff);
144 written+=RMAP_MAX_XFER_SIZE;
145 count-=RMAP_MAX_XFER_SIZE;
146 progress->setValue(written);
147 qApp->processEvents();
148 }
149 if(count>0)
150 {
151 for(int i=0;i<((int)count);i++)
152 {
153 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+0] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
154 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
155 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
156 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written])&0xFF);
157 }
158 transactionID=manager->getRMAPtransactionID();
159 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
160 RMAP_build_tx_request_header(
161 this->manager->destinationLogicalAddress,
162 this->manager->destinationKey,
163 this->manager->sourceLogicalAddress,
164 transactionID,
165 address+(written*4),
166 count*4,
167 writeBuffer);
168 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4));
169 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
170 free(RMAPAckBuff);
171 written+=count;
172 if(progress!=NULL)
173 {
174 progress->setValue(written);
175 qApp->processEvents();
176 }
177 }
178 return written;
113 }
179 }
114
180
115 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
181 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
116 {
182 {
117 // TODO write ME!
183 char requestBuffer[RMAP_READ_HEADER_MIN_SZ];
118 Q_UNUSED(Value)
184 char* RMAP_AnswerBuffer;
119 Q_UNUSED(count)
185 requestBuffer[0]=this->manager->linkNumber;//Link number
120 Q_UNUSED(address)
186 int transactionID = 0;
121 return 0;
187 int read=0;
188 QProgressBar* progress=NULL;
189 SocExplorerAutoProgressBar autopb;
190 if(count>RMAP_MAX_XFER_SIZE)
191 {
192 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
193 autopb.setProgressBar(progress);
194 }
195 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
196
197 //Quite stupide loop, I guess that I always get the number of byte I asked for!
198 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
199 {
200 transactionID = manager->getRMAPtransactionID();
201 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
202 RMAP_build_rx_request_header(
203 this->manager->destinationLogicalAddress,
204 this->manager->destinationKey,
205 this->manager->sourceLogicalAddress,
206 transactionID,
207 address+(read*4),
208 RMAP_MAX_XFER_SIZE*4,
209 requestBuffer);
210 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ);
211 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
212 if(len==-1)
213 {
214 this->toggleBridgeConnection();
215 return 0;
216 }
217 for(int i=0;i<((len-13)/4);i++)
218 {
219 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
220 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
221 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
222 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
223 }
224 free(RMAP_AnswerBuffer);
225 read+=RMAP_MAX_XFER_SIZE;
226 count-=RMAP_MAX_XFER_SIZE;
227 if(progress!=NULL)
228 {
229 progress->setValue(read);
230 qApp->processEvents();
231 }
232 }
233 if((int)count>0)
234 {
235 transactionID = manager->getRMAPtransactionID();
236 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
237 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
238 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
239 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
240 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
241 RMAP_build_rx_request_header(
242 this->manager->destinationLogicalAddress,
243 this->manager->destinationKey,
244 this->manager->sourceLogicalAddress,
245 transactionID,
246 address+(read*4),
247 count*4,
248 requestBuffer);
249 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ);
250 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
251 if(len==-1)
252 {
253 this->toggleBridgeConnection();
254 return 0;
255 }
256 for(int i=0;i<((len-13)/4);i++)
257 {
258 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
259 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
260 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
261 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
262 }
263 free(RMAP_AnswerBuffer);
264 read+=count;
265 if(progress!=NULL)
266 {
267 progress->setValue(read);
268 qApp->processEvents();
269 }
270 }
271 return read;
122 }
272 }
123
273
124 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
274 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
125 {
275 {
126 return this->manager->sendPacket(packet,size);
276 return this->manager->sendPacket(packet,size);
127 }
277 }
128
278
129
279
130 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
280 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
131 :QThread((QObject*)parent)
281 :abstractSpwManager(plugin, parent)
132 {
282 {
133 this->Read_soc = new QTcpSocket(this);
283 this->sourceLogicalAddress=32;
134 this->Write_soc = new QTcpSocket(this);
284 this->destinationLogicalAddress=254;
135 this->RMAPtimeout = 2000;
285 this->destinationKey=2;
136 this->handleMutex = new QMutex(QMutex::NonRecursive);
286 connect(&(this->Read_soc),SIGNAL(readyRead()),this,SLOT(readyRead()));
137 this->RMAP_AnswersSem = new QSemaphore(0);
138 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
139 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
140 this->plugin = plugin;
141 connected = false;
142 this->moveToThread(this);
143 }
287 }
144
288
145 GR_ESB_Manager::~GR_ESB_Manager()
289 GR_ESB_Manager::~GR_ESB_Manager()
146 {
290 {
291 }
147
292
293 void GR_ESB_Manager::__processPacket(packetBuffer_t *packet)
294 {
295 if(packet->complete)
296 {
297 if(packet->buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
298 {
299 RMAP_Answer* RMapPacket;
300 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
301 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(packet->PacketLen),2);
302 char* packetbuffer = (char*)malloc(packet->PacketLen);
303 if(packetbuffer)
304 {
305 memcpy(packetbuffer,packet->buffer,packet->PacketLen);
306 this->handleMutex->unlock();
307 if(packet->PacketLen==8)
308 {
309 RMapPacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer),packetbuffer,packet->PacketLen);
310 }
311 else
312 {
313 RMapPacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer),packetbuffer,packet->PacketLen);
314 }
315 RMAP_AnswersMtx->lock();
316 RMAP_Answers.append(RMapPacket);
317 RMAP_AnswersMtx->unlock();
318 RMAP_AnswersSem->release();
319 }
320 }
321 else //any non-rmap packet will be pushed to the network
322 {
323 char* packetbuffer = (char*)malloc(packet->PacketLen);
324 if(packetbuffer)
325 {
326 memcpy(packetbuffer,packet->buffer,packet->PacketLen);
327 emit emitPacket(packetbuffer,packet->PacketLen);
328 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
329 }
330 }
331 }
332
333 }
334
335 QByteArray GR_ESB_Manager::__processData(const QByteArray &data, packetBuffer_t *buffer)
336 {
337 if(buffer->complete)
338 {
339 if(Q_UNLIKELY(data.size()<=4))
340 return data;
341 buffer->PacketLen= ((int)data.at(3)& 0x0FF) + (((int)data.at(2)& 0x0FF)<<8) + (((int)data.at(1)& 0x0FF)<<16);
342 if(buffer->PacketLen>(data.size()-4))
343 {
344 memcpy(buffer->buffer,data.data()+4,data.size()-4);
345 buffer->complete=false;
346 buffer->index=data.size()-4;
347 }
348 else
349 {
350 memcpy(buffer->buffer,data.data()+4,data.size()-4);
351 buffer->PacketLen = data.size()-4;
352 buffer->index=data.size()-4;
353 buffer->complete=true;
354 __processPacket(buffer);
355 int len = buffer->PacketLen;
356 buffer->PacketLen = 0;
357 buffer->index=0;
358 if((data.size()-4-len))
359 {
360 return __processData(data.right((data.size()-4-len)),buffer);
361 }
362 }
363
364 }
365 else
366 {
367 if(buffer->PacketLen>(data.size()+buffer->index))
368 {
369 memcpy(buffer->buffer+buffer->index,data.data(),data.size());
370 buffer->complete=false;
371 buffer->index+=data.size();
372 }
373 else
374 {
375 memcpy(buffer->buffer+buffer->index,data.data(),buffer->PacketLen-buffer->index);
376 buffer->complete=true;
377 buffer->index+=data.size();
378 __processPacket(buffer);
379 int len = buffer->PacketLen;
380 buffer->PacketLen = 0;
381 buffer->index=0;
382 if((data.size()-len))
383 {
384 return __processData(data.right((data.size()-len)),buffer);
385 }
386 }
387 }
388 return QByteArray();
148 }
389 }
149
390
150 void GR_ESB_Manager::run()
391 void GR_ESB_Manager::run()
151 {
392 {
393 char bufferData[(RMAP_MAX_XFER_SIZE*4)+50];
394 packetBuffer_t buffer={bufferData,0,0,true};
152 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
395 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
396 QByteArray data;
153 while (!this->isInterruptionRequested())
397 while (!this->isInterruptionRequested())
154 {
398 {
155 if(this->connected)
399 if(this->connected)
156 {
400 {
157 handleMutex->lock();
401 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",8);
158 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
402 if(!incomingPackets.isEmpty())
403 {
404 incomingPacketsMutex.lock();
405 data.append(incomingPackets.dequeue());
406 this->incomingPacketsMutex.unlock();
407 data = __processData(data,&buffer);
408 }
159
409
160 }
410 }
161 else
411 else
162 {
412 {
163 //do some sanity checks!
413 //do some sanity checks!
164
165 usleep(RMAPtimeout/2);
414 usleep(RMAPtimeout/2);
166 }
415 }
167 usleep(1000);
416 usleep(1000);
168 }
417 }
169 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
418 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
170 }
419 }
171
420
172 bool GR_ESB_Manager::connectBridge()
421 bool GR_ESB_Manager::connectBridge()
173 {
422 {
174 int timeout=60;
423 int timeout=60;
175 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
424 this->connected = false;
425 if(this->Read_soc.state()==QTcpSocket::UnconnectedState)
176 {
426 {
177 this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
427 this->Read_soc.connectToHost(IP,gresb_Conf[virtualLinkIndex].Receive_port);
178 this->Read_soc->waitForConnected(30000);
428 this->Read_soc.waitForConnected(30000);
179 }
429 }
180 if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
430 if(this->Write_soc.state()==QTcpSocket::UnconnectedState)
181 {
431 {
182 this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
432 this->Write_soc.connectToHost(IP,gresb_Conf[virtualLinkIndex].Transmit_port);
183 this->Write_soc->waitForConnected(30000);
433 this->Write_soc.waitForConnected(30000);
184 }
434 }
185 while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
435 while((this->Read_soc.state()!=QTcpSocket::ConnectedState) && (this->Write_soc.state()!=QTcpSocket::ConnectedState))
186 {
436 {
187 usleep(100000);
437 usleep(100000);
188 if(timeout--==0)return false;
438 if(timeout--==0)return false;
189 }
439 }
440 this->connected = true;
190 return true;
441 return true;
191
442
192 }
443 }
193
444
194 bool GR_ESB_Manager::disconnectBridge()
445 bool GR_ESB_Manager::disconnectBridge()
195 {
446 {
196 int timeout=60;
447 int timeout=60;
197 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
448 if(this->Read_soc.state()!=QTcpSocket::UnconnectedState)
198 {
449 {
199 this->Read_soc->disconnectFromHost();
450 this->Read_soc.disconnectFromHost();
200 this->Read_soc->waitForDisconnected(30000);
451 this->Read_soc.waitForDisconnected(30000);
201 }
452 }
202 if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
453 if(this->Write_soc.state()!=QTcpSocket::UnconnectedState)
203 {
454 {
204 this->Write_soc->disconnectFromHost();
455 this->Write_soc.disconnectFromHost();
205 this->Write_soc->waitForDisconnected(30000);
456 this->Write_soc.waitForDisconnected(30000);
206 }
457 }
207 while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
458 while((this->Read_soc.state()!=QTcpSocket::UnconnectedState) && (this->Write_soc.state()!=QTcpSocket::UnconnectedState))
208 {
459 {
209 usleep(100000);
460 usleep(100000);
210 if(timeout--==0)return false;
461 if(timeout--==0)return false;
211 }
462 }
212 return true;
463 return true;
213 }
464 }
214
465
215 int GR_ESB_Manager::getRMAPtransactionID()
216 {
217 // TODO write ME!
218 return -1;
219 }
220
221 int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
222 {
223 // TODO write ME!
224 Q_UNUSED(transactionID)
225 Q_UNUSED(buffer)
226 return -1;
227 }
228
466
229 bool GR_ESB_Manager::sendPacket(char *packet, int size)
467 bool GR_ESB_Manager::sendPacket(char *packet, int size)
230 {
468 {
231 // TODO write ME!
469 bool result = false;
232 Q_UNUSED(packet)
470 char protocoleIdentifier;
233 Q_UNUSED(size)
471 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
234 return false;
472 if(Q_UNLIKELY(this->Write_soc.state()!=QAbstractSocket::ConnectedState))
473 {
474 SocExplorerEngine::message(this->plugin,"Socket closed",2);
475 //TODO handle disconnection
476 }
477 char* SPWpacket = (char*)malloc(size+4);
478 if(SPWpacket!=NULL)
479 {
480 SPWpacket[0]=0; //Protocol = spw
481 memcpy(SPWpacket+4,packet,size);
482 SPWpacket[1]=(size>>16) & 0x0FF;
483 SPWpacket[2]=(size>>8) & 0x0FF;
484 SPWpacket[3]=size & 0x0FF;
485 this->handleMutex->lock();
486 result = ((size+4) == this->Write_soc.write(SPWpacket,size+4));
487 this->Write_soc.flush();
488 this->handleMutex->unlock();
489 free(SPWpacket);
490 }
491 if (Q_UNLIKELY(!result))
492 {
493 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
494 return false;
495 }
496 else
497 {
498 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
499 // read the protocole identifier
500 protocoleIdentifier = packet[2];
501 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
502 emit ccsdsPacketTransmittedToSpw();
503 SocExplorerEngine::message(this->plugin,"Packet sent",2);
504 }
505 return true;
235 }
506 }
236
507
237 void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
508 void GR_ESB_Manager::readyRead()
238 {
509 {
239 // TODO write ME!
510 incomingPacketsMutex.lock();
240 Q_UNUSED(packet)
511 incomingPackets.append(Read_soc.readAll());
241 Q_UNUSED(len)
512 incomingPacketsMutex.unlock();
242 }
513 }
514
@@ -1,88 +1,96
1 #ifndef GR_ESB_BRIDGE_H
1 #ifndef GR_ESB_BRIDGE_H
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>
5 #include <QThread>
6 #include <QMutex>
6 #include <QMutex>
7 #include <QSemaphore>
7 #include <QSemaphore>
8 #include <QQueue>
8
9
9 struct gresb_Conf_str
10 struct gresb_Conf_str
10 {
11 {
11 qint32 Read_port;
12 qint32 Transmit_port;
12 qint32 Write_port;
13 qint32 Receive_port;
13 };
14 };
14
15
15
16
16 const struct gresb_Conf_str gresb_Conf[]=
17 const struct gresb_Conf_str gresb_Conf[]=
17 {
18 {
18 {3000,3001}, //Virtual link 0
19 {3000,3001}, //Virtual link 0
19 {3002,3003}, //Virtual link 1
20 {3002,3003}, //Virtual link 1
20 {3004,3005}, //Virtual link 2
21 {3004,3005}, //Virtual link 2
21 {3006,3007}, //Virtual link 3
22 {3006,3007}, //Virtual link 3
22 {3008,3009}, //Virtual link 4
23 {3008,3009}, //Virtual link 4
23 {3010,3011} //Virtual link 5
24 {3010,3011} //Virtual link 5
24 };
25 };
25
26
26
27
27 class GR_ESB_Manager: public QThread
28 class GR_ESB_Manager: public abstractSpwManager
28 {
29 {
29 Q_OBJECT
30 Q_OBJECT
31
32 typedef struct packetBuffer_t
33 {
34 char* buffer;
35 int PacketLen;
36 int index;
37 bool complete;
38 }packetBuffer_t;
39
30 public:
40 public:
31 explicit GR_ESB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
41 explicit GR_ESB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
32 ~GR_ESB_Manager();
42 ~GR_ESB_Manager();
33 void run();
43 void run();
34 bool connectBridge();
44 bool connectBridge();
35 bool disconnectBridge();
45 bool disconnectBridge();
36 int getRMAPtransactionID();
37 int getRMAPanswer(int transactionID,char** buffer);
38 bool sendPacket(char* packet,int size);
46 bool sendPacket(char* packet,int size);
39
47
40 signals:
48 signals:
41 void emitPacket(char* packet,int size);
49 void emitPacket(char* packet,int size);
42 private:
50 private:
43 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
44 QSemaphore* RMAP_AnswersSem;
45 void pushRmapPacket(char* packet,int len);
51 void pushRmapPacket(char* packet,int len);
46 socexplorerplugin* plugin;
47 bool connected;
48 char* SPWPacketBuff;
52 char* SPWPacketBuff;
49 QList<RMAP_Answer*> RMAP_Answers;
53
50 QList<int> RMAP_pending_transaction_IDs;
54 void __processPacket(packetBuffer_t *packet);
55 QByteArray __processData(const QByteArray &data, packetBuffer_t* buffer);
56 private slots:
57 void readyRead();
51
58
52 public:
59 public:
53 QTcpSocket* Read_soc;
60 QTcpSocket Read_soc;
54 QTcpSocket* Write_soc;
61 QTcpSocket Write_soc;
62 QMutex incomingPacketsMutex;
63 QQueue<QByteArray> incomingPackets;
55 QString IP;
64 QString IP;
56 int virtualLinkIndex;
65 int virtualLinkIndex;
57 int RMAPtimeout;
58 };
66 };
59
67
60
68
61 class GR_ESB_bridge : public abstractSpwBridge
69 class GR_ESB_bridge : public abstractSpwBridge
62 {
70 {
63 Q_OBJECT
71 Q_OBJECT
64 public:
72 public:
65 explicit GR_ESB_bridge(socexplorerplugin *parent = 0);
73 explicit GR_ESB_bridge(socexplorerplugin *parent = 0);
66 ~GR_ESB_bridge();
74 ~GR_ESB_bridge();
67 signals:
75 signals:
68
76
69
77
70 public slots:
78 public slots:
71 void toggleBridgeConnection();
79 void toggleBridgeConnection();
72 bool connectBridge();
80 bool connectBridge();
73 bool disconnectBridge();
81 bool disconnectBridge();
74 void setIP(QString ip);
82 void setIP(QString ip);
75 void setVirtualLink(QString vlink);
83 void setVirtualLink(QString vlink);
76 void setVirtualLink(qint32 vlink);
84 void setVirtualLink(qint32 vlink);
77 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
85 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
78 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
86 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
79 int pushRMAPPacket(char* packet,int size);
87 int pushRMAPPacket(char* packet,int size);
80 void packetReceived();
88 void packetReceived();
81
89
82 private:
90 private:
83
91
84 GR_ESB_Manager* manager;
92 GR_ESB_Manager* manager;
85
93
86 };
94 };
87
95
88 #endif // GR_ESB_BRIDGE_H
96 #endif // GR_ESB_BRIDGE_H
@@ -1,146 +1,322
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>GR_ESB_ui</class>
3 <class>GR_ESB_ui</class>
4 <widget class="QWidget" name="GR_ESB_ui">
4 <widget class="QWidget" name="GR_ESB_ui">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>968</width>
9 <width>978</width>
10 <height>392</height>
10 <height>518</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Form</string>
14 <string>Form</string>
15 </property>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout">
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <item>
17 <item>
18 <widget class="QTabWidget" name="tabWidget">
18 <widget class="QTabWidget" name="tabWidget">
19 <property name="toolTip">
19 <property name="toolTip">
20 <string/>
20 <string/>
21 </property>
21 </property>
22 <property name="currentIndex">
22 <property name="currentIndex">
23 <number>0</number>
23 <number>0</number>
24 </property>
24 </property>
25 <widget class="QWidget" name="Config">
25 <widget class="QWidget" name="Config">
26 <property name="toolTip">
26 <property name="toolTip">
27 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Config tab allows you to configure the Ethernet conncetion to the GR-ESB and some spacewire parameters.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
27 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Config tab allows you to configure the Ethernet conncetion to the GR-ESB and some spacewire parameters.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
28 </property>
28 </property>
29 <attribute name="title">
29 <attribute name="title">
30 <string>Config</string>
30 <string>Config</string>
31 </attribute>
31 </attribute>
32 <layout class="QGridLayout" name="gridLayout_2">
32 <layout class="QGridLayout" name="gridLayout_2">
33 <item row="1" column="1">
33 <item row="4" column="2">
34 <widget class="QLineEdit" name="destinationAddressLineEdit">
35 <property name="toolTip">
36 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the RMAP target address, this address will be used as destination address for all the RMAP transfers.&lt;/p&gt;&lt;p&gt;This is you SOC spw address.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
37 </property>
38 <property name="inputMask">
39 <string comment="ddD"/>
40 </property>
41 <property name="text">
42 <string>254</string>
43 </property>
44 <property name="maxLength">
45 <number>3</number>
46 </property>
47 </widget>
48 </item>
49 <item row="11" column="0" colspan="3">
50 <widget class="QWidget" name="widget" native="true">
51 <layout class="QGridLayout" name="gridLayout">
52 <item row="0" column="2">
53 <widget class="QLabel" name="label_7">
54 <property name="font">
55 <font>
56 <weight>75</weight>
57 <bold>true</bold>
58 </font>
59 </property>
60 <property name="text">
61 <string>Transmitted</string>
62 </property>
63 </widget>
64 </item>
65 <item row="1" column="1">
66 <widget class="QLabel" name="ReceivedPackets">
67 <property name="text">
68 <string>-</string>
69 </property>
70 </widget>
71 </item>
72 <item row="2" column="2">
73 <widget class="QLabel" name="TransmittedBytes">
74 <property name="text">
75 <string>-</string>
76 </property>
77 </widget>
78 </item>
79 <item row="2" column="0">
80 <widget class="QLabel" name="label_5">
81 <property name="text">
82 <string>Bytes</string>
83 </property>
84 </widget>
85 </item>
86 <item row="2" column="1">
87 <widget class="QLabel" name="ReceivedBytes">
88 <property name="text">
89 <string>-</string>
90 </property>
91 </widget>
92 </item>
93 <item row="1" column="2">
94 <widget class="QLabel" name="TransmittedPackets">
95 <property name="text">
96 <string>-</string>
97 </property>
98 </widget>
99 </item>
100 <item row="0" column="1">
101 <widget class="QLabel" name="label_3">
102 <property name="font">
103 <font>
104 <weight>75</weight>
105 <bold>true</bold>
106 </font>
107 </property>
108 <property name="text">
109 <string>Received</string>
110 </property>
111 </widget>
112 </item>
113 <item row="1" column="0">
114 <widget class="QLabel" name="label_4">
115 <property name="text">
116 <string>Packets</string>
117 </property>
118 </widget>
119 </item>
120 <item row="0" column="0">
121 <widget class="QPushButton" name="resetStatsQpb">
122 <property name="text">
123 <string>Reset stats</string>
124 </property>
125 </widget>
126 </item>
127 </layout>
128 </widget>
129 </item>
130 <item row="3" column="2">
131 <widget class="QLineEdit" name="sourceAddressLineEdit">
132 <property name="toolTip">
133 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the Space Wire Brick destination Key, the default value is 32 (0x20).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
134 </property>
135 <property name="inputMask">
136 <string comment="ddD"/>
137 </property>
138 <property name="text">
139 <string>32</string>
140 </property>
141 <property name="maxLength">
142 <number>3</number>
143 </property>
144 </widget>
145 </item>
146 <item row="8" column="2">
147 <widget class="QLineEdit" name="RMAPTimeoutLineEdit">
148 <property name="toolTip">
149 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the RMAP timeout, when waiting for a RMAP answer the driver will give up after this time if it doesn't get any answer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
150 </property>
151 <property name="inputMethodHints">
152 <set>Qt::ImhDigitsOnly</set>
153 </property>
154 <property name="inputMask">
155 <string comment="DDdd;"/>
156 </property>
157 <property name="text">
158 <string>500</string>
159 </property>
160 <property name="maxLength">
161 <number>5</number>
162 </property>
163 </widget>
164 </item>
165 <item row="2" column="2">
166 <widget class="QComboBox" name="GRESB_LinkNum_CmBx">
167 <item>
168 <property name="text">
169 <string>SPW0</string>
170 </property>
171 </item>
172 <item>
173 <property name="text">
174 <string>SPW1</string>
175 </property>
176 </item>
177 <item>
178 <property name="text">
179 <string>SPW2</string>
180 </property>
181 </item>
182 </widget>
183 </item>
184 <item row="4" column="0">
185 <widget class="QLabel" name="RMAPaddressLbl">
186 <property name="text">
187 <string>Destination address</string>
188 </property>
189 </widget>
190 </item>
191 <item row="6" column="2">
192 <widget class="QLineEdit" name="destinationKeyLineEdit">
193 <property name="toolTip">
194 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the RMAP target key, this key will be used for all the RMAP transfers.&lt;/p&gt;&lt;p&gt;This is you SOC spw key.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
195 </property>
196 <property name="inputMask">
197 <string comment="ddD"/>
198 </property>
199 <property name="text">
200 <string comment="ddD">2</string>
201 </property>
202 <property name="maxLength">
203 <number>3</number>
204 </property>
205 </widget>
206 </item>
207 <item row="1" column="0">
208 <widget class="QLabel" name="GRESB_Vlink_Lbl">
209 <property name="text">
210 <string>GR-ESB Virtual link</string>
211 </property>
212 </widget>
213 </item>
214 <item row="1" column="2">
34 <widget class="QComboBox" name="GRESB_Vlink_CmBx">
215 <widget class="QComboBox" name="GRESB_Vlink_CmBx">
35 <item>
216 <item>
36 <property name="text">
217 <property name="text">
37 <string>Virtual link 0</string>
218 <string>Virtual link 0</string>
38 </property>
219 </property>
39 </item>
220 </item>
40 <item>
221 <item>
41 <property name="text">
222 <property name="text">
42 <string>Virtual link 1</string>
223 <string>Virtual link 1</string>
43 </property>
224 </property>
44 </item>
225 </item>
45 <item>
226 <item>
46 <property name="text">
227 <property name="text">
47 <string>Virtual link 2</string>
228 <string>Virtual link 2</string>
48 </property>
229 </property>
49 </item>
230 </item>
50 <item>
231 <item>
51 <property name="text">
232 <property name="text">
52 <string>Virtual link 3</string>
233 <string>Virtual link 3</string>
53 </property>
234 </property>
54 </item>
235 </item>
55 <item>
236 <item>
56 <property name="text">
237 <property name="text">
57 <string>Virtual link 4</string>
238 <string>Virtual link 4</string>
58 </property>
239 </property>
59 </item>
240 </item>
60 <item>
241 <item>
61 <property name="text">
242 <property name="text">
62 <string>Virtual link 5</string>
243 <string>Virtual link 5</string>
63 </property>
244 </property>
64 </item>
245 </item>
65 </widget>
246 </widget>
66 </item>
247 </item>
67 <item row="1" column="0">
248 <item row="3" column="0">
68 <widget class="QLabel" name="GRESB_Vlink_Lbl">
249 <widget class="QLabel" name="setDestKeyLbl">
69 <property name="text">
250 <property name="text">
70 <string>GR-ESB Virtual link</string>
251 <string>Source address</string>
71 </property>
252 </property>
72 </widget>
253 </widget>
73 </item>
254 </item>
74 <item row="2" column="1">
255 <item row="8" column="0">
75 <widget class="QComboBox" name="GRESB_LinkNum_CmBx">
256 <widget class="QLabel" name="RMAPTimeoutLbl">
76 <item>
257 <property name="text">
77 <property name="text">
258 <string>RMAP timeout(ms)</string>
78 <string>SPW0</string>
259 </property>
79 </property>
80 </item>
81 <item>
82 <property name="text">
83 <string>SPW1</string>
84 </property>
85 </item>
86 <item>
87 <property name="text">
88 <string>SPW2</string>
89 </property>
90 </item>
91 </widget>
260 </widget>
92 </item>
261 </item>
93 <item row="0" column="1">
262 <item row="0" column="2">
94 <widget class="QLineEdit" name="GRESB_IP_lineEdit"/>
263 <widget class="QLineEdit" name="GRESB_IP_lineEdit"/>
95 </item>
264 </item>
96 <item row="2" column="0">
265 <item row="2" column="0">
97 <widget class="QLabel" name="GRESB_LinkNum_Lbl">
266 <widget class="QLabel" name="GRESB_LinkNum_Lbl">
98 <property name="text">
267 <property name="text">
99 <string>Select link number</string>
268 <string>Select link number</string>
100 </property>
269 </property>
101 </widget>
270 </widget>
102 </item>
271 </item>
272 <item row="6" column="0">
273 <widget class="QLabel" name="RMAPKeyLbl">
274 <property name="text">
275 <string>Destination key</string>
276 </property>
277 </widget>
278 </item>
103 <item row="0" column="0">
279 <item row="0" column="0">
104 <widget class="QLabel" name="GRESB_IP_Lbl">
280 <widget class="QLabel" name="GRESB_IP_Lbl">
105 <property name="text">
281 <property name="text">
106 <string>GR-ESB IP Address</string>
282 <string>GR-ESB IP Address</string>
107 </property>
283 </property>
108 </widget>
284 </widget>
109 </item>
285 </item>
110 <item row="3" column="0" colspan="2">
286 <item row="10" column="0" colspan="3">
111 <widget class="QPushButton" name="connectQpb">
287 <widget class="QPushButton" name="connectQpb">
112 <property name="text">
288 <property name="text">
113 <string>Connect</string>
289 <string>Connect</string>
114 </property>
290 </property>
115 </widget>
291 </widget>
116 </item>
292 </item>
117 </layout>
293 </layout>
118 </widget>
294 </widget>
119 <widget class="QWidget" name="Web">
295 <widget class="QWidget" name="Web">
120 <property name="toolTip">
296 <property name="toolTip">
121 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Web tab gives access to the GR-ESB web interface.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
297 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Web tab gives access to the GR-ESB web interface.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
122 </property>
298 </property>
123 <attribute name="title">
299 <attribute name="title">
124 <string>Web</string>
300 <string>Web</string>
125 </attribute>
301 </attribute>
126 <layout class="QHBoxLayout" name="horizontalLayout">
302 <layout class="QHBoxLayout" name="horizontalLayout">
127 <item>
303 <item>
128 <widget class="QWebView" name="WebView" native="true"/>
304 <widget class="QWebView" name="WebView"/>
129 </item>
305 </item>
130 </layout>
306 </layout>
131 </widget>
307 </widget>
132 </widget>
308 </widget>
133 </item>
309 </item>
134 </layout>
310 </layout>
135 </widget>
311 </widget>
136 <customwidgets>
312 <customwidgets>
137 <customwidget>
313 <customwidget>
138 <class>QWebView</class>
314 <class>QWebView</class>
139 <extends>QWidget</extends>
315 <extends>QWidget</extends>
140 <header location="global">QWebView</header>
316 <header>QtWebKitWidgets/QWebView</header>
141 <container>1</container>
317 <container>1</container>
142 </customwidget>
318 </customwidget>
143 </customwidgets>
319 </customwidgets>
144 <resources/>
320 <resources/>
145 <connections/>
321 <connections/>
146 </ui>
322 </ui>
@@ -1,1108 +1,1011
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - 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 "fakestardundeespwusb_lib.h"
24 #include "fakestardundeespwusb_lib.h"
25 #include <socexplorerengine.h>
25 #include <socexplorerengine.h>
26 #include <qhexedit.h>
26 #include <qhexedit.h>
27
27
28 const QString dwLinkStatusQString[6] = {
28 const QString dwLinkStatusQString[6] = {
29 "CFG_SPACEWIRE_ERROR_RESET",
29 "CFG_SPACEWIRE_ERROR_RESET",
30 "CFG_SPACEWIRE_ERROR_WAIT",
30 "CFG_SPACEWIRE_ERROR_WAIT",
31 "CFG_SPACEWIRE_READY",
31 "CFG_SPACEWIRE_READY",
32 "CFG_SPACEWIRE_STARTED",
32 "CFG_SPACEWIRE_STARTED",
33 "CFG_SPACEWIRE_CONNECTING",
33 "CFG_SPACEWIRE_CONNECTING",
34 "CFG_SPACEWIRE_RUN"
34 "CFG_SPACEWIRE_RUN"
35 };
35 };
36
36
37 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
37 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
38 abstractSpwBridge(parent)
38 abstractSpwBridge(parent)
39 {
39 {
40 Q_UNUSED(parent)
40 Q_UNUSED(parent)
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
42 makeGUI(parent);
42 makeGUI(parent);
43 this->manager->start();
44 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
45 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
46 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
47 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
47 this->manager->start();
48 }
48 }
49
49
50 stardundeeSPW_USB::~stardundeeSPW_USB()
50 stardundeeSPW_USB::~stardundeeSPW_USB()
51 {
51 {
52 this->manager->requestInterruption();
52 this->manager->requestInterruption();
53 while(this->manager->isRunning());
53 while(this->manager->isRunning());
54 }
54 }
55
55
56 void stardundeeSPW_USB::toggleBridgeConnection()
56 void stardundeeSPW_USB::toggleBridgeConnection()
57 {
57 {
58 if(this->plugin->isConnected())
58 if(this->plugin->isConnected())
59 {
59 {
60 this->disconnectBridge();
60 this->disconnectBridge();
61 }
61 }
62 else
62 else
63 {
63 {
64 this->connectBridge();
64 this->connectBridge();
65 }
65 }
66 }
66 }
67
67
68 bool stardundeeSPW_USB::connectBridge()
68 bool stardundeeSPW_USB::connectBridge()
69 {
69 {
70 if(this->manager->connectBridge())
70 if(this->manager->connectBridge())
71 {
71 {
72 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
72 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
73 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
73 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
74 ((StarDundeeGUI*)this->p_GUI)->lock(true);
74 ((StarDundeeGUI*)this->p_GUI)->lock(true);
75 emit setConnected(true);
75 emit setConnected(true);
76 return true;
76 return true;
77 }
77 }
78 return false;
78 return false;
79 }
79 }
80
80
81 bool stardundeeSPW_USB::disconnectBridge()
81 bool stardundeeSPW_USB::disconnectBridge()
82 {
82 {
83 if(this->manager->disconnectBridge())
83 if(this->manager->disconnectBridge())
84 {
84 {
85 ((StarDundeeGUI*)this->p_GUI)->lock(false);
85 ((StarDundeeGUI*)this->p_GUI)->lock(false);
86 emit setConnected(false);
86 emit setConnected(false);
87 return true;
87 return true;
88 }
88 }
89 return false;
89 return false;
90 }
90 }
91
91
92 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
92 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
93 {
93 {
94 return this->manager->sendPacket(packet,size);
94 return this->manager->sendPacket(packet,size);
95 }
95 }
96
96
97 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
97 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
98 {
98 {
99 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
99 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
100 char *RMAPAckBuff;
100 char *RMAPAckBuff;
101 writeBuffer[0]=this->manager->linkNumber;//Link number
101 writeBuffer[0]=this->manager->linkNumber;//Link number
102 int transactionID = 0;
102 int transactionID = 0;
103 int written=0;
103 int written=0;
104 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
104 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
105 QProgressBar* progress=NULL;
105 QProgressBar* progress=NULL;
106 SocExplorerAutoProgressBar autopb;
106 SocExplorerAutoProgressBar autopb;
107 if(count>RMAP_MAX_XFER_SIZE)
107 if(count>RMAP_MAX_XFER_SIZE)
108 {
108 {
109 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
109 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
110 autopb.setProgressBar(progress);
110 autopb.setProgressBar(progress);
111 }
111 }
112 //Quite stupide loop, I guess that I always get the number of byte I asked for!
112 //Quite stupide loop, I guess that I always get the number of byte I asked for!
113 while(count>=RMAP_MAX_XFER_SIZE)
113 while(count>=RMAP_MAX_XFER_SIZE)
114 {
114 {
115 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
115 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
116 {
116 {
117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
120 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
120 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
121 }
121 }
122 transactionID=manager->getRMAPtransactionID();
122 transactionID=manager->getRMAPtransactionID();
123 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
123 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
124 RMAP_build_tx_request_header(
124 RMAP_build_tx_request_header(
125 this->manager->destinationLogicalAddress,
125 this->manager->destinationLogicalAddress,
126 this->manager->destinationKey,
126 this->manager->destinationKey,
127 this->manager->sourceLogicalAddress,
127 this->manager->sourceLogicalAddress,
128 transactionID,
128 transactionID,
129 address+(written*4),
129 address+(written*4),
130 RMAP_MAX_XFER_SIZE*4,
130 RMAP_MAX_XFER_SIZE*4,
131 writeBuffer+1);
131 writeBuffer+1);
132 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
132 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
133 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
133 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
134 free(RMAPAckBuff);
134 free(RMAPAckBuff);
135 written+=RMAP_MAX_XFER_SIZE;
135 written+=RMAP_MAX_XFER_SIZE;
136 count-=RMAP_MAX_XFER_SIZE;
136 count-=RMAP_MAX_XFER_SIZE;
137 progress->setValue(written);
137 progress->setValue(written);
138 qApp->processEvents();
138 qApp->processEvents();
139 }
139 }
140 if(count>0)
140 if(count>0)
141 {
141 {
142 for(int i=0;i<((int)count);i++)
142 for(int i=0;i<((int)count);i++)
143 {
143 {
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
147 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
147 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
148 }
148 }
149 transactionID=manager->getRMAPtransactionID();
149 transactionID=manager->getRMAPtransactionID();
150 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
150 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
151 RMAP_build_tx_request_header(
151 RMAP_build_tx_request_header(
152 this->manager->destinationLogicalAddress,
152 this->manager->destinationLogicalAddress,
153 this->manager->destinationKey,
153 this->manager->destinationKey,
154 this->manager->sourceLogicalAddress,
154 this->manager->sourceLogicalAddress,
155 transactionID,
155 transactionID,
156 address+(written*4),
156 address+(written*4),
157 count*4,
157 count*4,
158 writeBuffer+1);
158 writeBuffer+1);
159 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
159 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
160 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
160 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
161 free(RMAPAckBuff);
161 free(RMAPAckBuff);
162 written+=count;
162 written+=count;
163 if(progress!=NULL)
163 if(progress!=NULL)
164 {
164 {
165 progress->setValue(written);
165 progress->setValue(written);
166 qApp->processEvents();
166 qApp->processEvents();
167 }
167 }
168 }
168 }
169 return written;
169 return written;
170 }
170 }
171
171
172 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
172 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
173 {
173 {
174 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
174 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
175 char* RMAP_AnswerBuffer;
175 char* RMAP_AnswerBuffer;
176 requestBuffer[0]=this->manager->linkNumber;//Link number
176 requestBuffer[0]=this->manager->linkNumber;//Link number
177 int transactionID = 0;
177 int transactionID = 0;
178 int read=0;
178 int read=0;
179 QProgressBar* progress=NULL;
179 QProgressBar* progress=NULL;
180 SocExplorerAutoProgressBar autopb;
180 SocExplorerAutoProgressBar autopb;
181 if(count>RMAP_MAX_XFER_SIZE)
181 if(count>RMAP_MAX_XFER_SIZE)
182 {
182 {
183 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
183 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
184 autopb.setProgressBar(progress);
184 autopb.setProgressBar(progress);
185 }
185 }
186 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
186 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
187
187
188 //Quite stupide loop, I guess that I always get the number of byte I asked for!
188 //Quite stupide loop, I guess that I always get the number of byte I asked for!
189 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
189 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
190 {
190 {
191 transactionID = manager->getRMAPtransactionID();
191 transactionID = manager->getRMAPtransactionID();
192 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
192 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
193 RMAP_build_rx_request_header(
193 RMAP_build_rx_request_header(
194 this->manager->destinationLogicalAddress,
194 this->manager->destinationLogicalAddress,
195 this->manager->destinationKey,
195 this->manager->destinationKey,
196 this->manager->sourceLogicalAddress,
196 this->manager->sourceLogicalAddress,
197 transactionID,
197 transactionID,
198 address+(read*4),
198 address+(read*4),
199 RMAP_MAX_XFER_SIZE*4,
199 RMAP_MAX_XFER_SIZE*4,
200 requestBuffer+1);
200 requestBuffer+1);
201 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
201 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
202 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
202 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
203 if(len==-1)
203 if(len==-1)
204 {
204 {
205 this->toggleBridgeConnection();
205 this->toggleBridgeConnection();
206 return 0;
206 return 0;
207 }
207 }
208 for(int i=0;i<((len-13)/4);i++)
208 for(int i=0;i<((len-13)/4);i++)
209 {
209 {
210 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
210 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
213 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
213 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
214 }
214 }
215 free(RMAP_AnswerBuffer);
215 free(RMAP_AnswerBuffer);
216 read+=RMAP_MAX_XFER_SIZE;
216 read+=RMAP_MAX_XFER_SIZE;
217 count-=RMAP_MAX_XFER_SIZE;
217 count-=RMAP_MAX_XFER_SIZE;
218 progress->setValue(read);
218 if(progress!=NULL)
219 qApp->processEvents();
219 {
220 progress->setValue(read);
221 qApp->processEvents();
222 }
220 }
223 }
221 if((int)count>0)
224 if((int)count>0)
222 {
225 {
223 transactionID = manager->getRMAPtransactionID();
226 transactionID = manager->getRMAPtransactionID();
224 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
227 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
225 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
228 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
226 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
229 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
227 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
230 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
228 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
231 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
229 RMAP_build_rx_request_header(
232 RMAP_build_rx_request_header(
230 this->manager->destinationLogicalAddress,
233 this->manager->destinationLogicalAddress,
231 this->manager->destinationKey,
234 this->manager->destinationKey,
232 this->manager->sourceLogicalAddress,
235 this->manager->sourceLogicalAddress,
233 transactionID,
236 transactionID,
234 address+(read*4),
237 address+(read*4),
235 count*4,
238 count*4,
236 requestBuffer+1);
239 requestBuffer+1);
237 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
240 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
238 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
241 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
239 if(len==-1)
242 if(len==-1)
240 {
243 {
241 this->toggleBridgeConnection();
244 this->toggleBridgeConnection();
242 return 0;
245 return 0;
243 }
246 }
244 for(int i=0;i<((len-13)/4);i++)
247 for(int i=0;i<((len-13)/4);i++)
245 {
248 {
246 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
249 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
247 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
250 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
248 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
251 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
249 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
252 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
250 }
253 }
251 free(RMAP_AnswerBuffer);
254 free(RMAP_AnswerBuffer);
252 read+=count;
255 read+=count;
253 if(progress!=NULL)
256 if(progress!=NULL)
254 {
257 {
255 progress->setValue(read);
258 progress->setValue(read);
256 qApp->processEvents();
259 qApp->processEvents();
257 }
260 }
258 }
261 }
259 return read;
262 return read;
260 }
263 }
261
264
262 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
265 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
263 {
266 {
264 this->manager->selectedBrick = brickIndex-1;
267 this->manager->selectedBrick = brickIndex-1;
265 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
268 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
266 }
269 }
267
270
268 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
271 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
269 {
272 {
270 this->manager->linkNumber = linkIndex + 1;
273 this->manager->linkNumber = linkIndex + 1;
271 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
274 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
272 }
275 }
273
276
274 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
277 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
275 {
278 {
276 this->manager->linkSpeed = linkSpeed.toInt();
279 this->manager->linkSpeed = linkSpeed.toInt();
277
280
278 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
281 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
279 }
282 }
280
283
281 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
284 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
282 {
285 {
283 this->manager->sourceLogicalAddress = sourceAddress.toInt();
286 this->manager->sourceLogicalAddress = sourceAddress.toInt();
284 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
287 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
285 }
288 }
286
289
287 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
290 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
288 {
291 {
289 this->manager->destinationLogicalAddress = rmapaddress.toInt();
292 this->manager->destinationLogicalAddress = rmapaddress.toInt();
290 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
293 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
291 }
294 }
292
295
293 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
296 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
294 {
297 {
295 this->manager->destinationKey = key.toInt();
298 this->manager->destinationKey = key.toInt();
296 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
299 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
297 }
300 }
298
301
299 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
302 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
300 {
303 {
301 this->manager->interfaceMode = interfaceMode;
304 this->manager->interfaceMode = interfaceMode;
302 }
305 }
303
306
304 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
307 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
305 {
308 {
306 this->manager->timecodeFrequency = frequency.toDouble();
309 this->manager->timecodeFrequency = frequency.toDouble();
307 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
310 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
308 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
311 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
309 }
312 }
310
313
311 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
314 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
312 {
315 {
313 this->manager->sendTimecodePeriodically( onOff );
316 this->manager->sendTimecodePeriodically( onOff );
314 }
317 }
315
318
316 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
319 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
317 {
320 {
318 int tim=timeout.toInt();
321 int tim=timeout.toInt();
319 if(tim<50)
322 if(tim<50)
320 {
323 {
321 tim = 50;
324 tim = 50;
322 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
325 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
323 }
326 }
324 this->manager->RMAPtimeout = tim;
327 this->manager->RMAPtimeout = tim;
325 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
328 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
326 }
329 }
327
330
328 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
331 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
329 {
332 {
330 Q_UNUSED(parent)
333 Q_UNUSED(parent)
331 this->p_GUI = new StarDundeeGUI();
334 this->p_GUI = new StarDundeeGUI();
332 // this->mainLayout = new QGridLayout(this->p_GUI);
333 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
334 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
336 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
344 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
345 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
344 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
346 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
345
347
346 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
348 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
347 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
349 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
348 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
350 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
349 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
351 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
350 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
352 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
351 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
353 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
352 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
354 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
353 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
355 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
354
356
355 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
357 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
356 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
358 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
357 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
359 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
358 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
360 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
359 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
361 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
360 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
362 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
361 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
363 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
362 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
364 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
363 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
365 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
364 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
366 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
365 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
367 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
366 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
368 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
367 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
369 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
368 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
370 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
369 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
371 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
370 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
372 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
371 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
373 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
372 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
374 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
373
375
374 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
376 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
375 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
377 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
376 }
378 }
377
379
378 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
380 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
379 {
381 {
380 char* data;
382 char* data;
381 int i;
383 int i;
382
384
383 data = (char *) malloc( size + 5 );
385 data = (char *) malloc( size + 5 );
384
386
385 data[0] = this->manager->linkNumber;
387 data[0] = this->manager->linkNumber;
386 data[1] = this->manager->destinationLogicalAddress; // target logical address
388 data[1] = this->manager->destinationLogicalAddress; // target logical address
387 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
389 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
388 data[3] = 0x00; // reserved
390 data[3] = 0x00; // reserved
389 data[4] = 0x00; // user application
391 data[4] = 0x00; // user application
390
392
391 for ( i=0; i<size; i++ )
393 for ( i=0; i<size; i++ )
392 {
394 {
393 data[i+5] = packet[i];
395 data[i+5] = packet[i];
394 }
396 }
395
397
396 this->manager->sendPacket( data, size + 5);
398 this->manager->sendPacket( data, size + 5);
397
399
398 free(data);
400 free(data);
399 free(packet);
401 free(packet);
400 }
402 }
401
403
402 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
404 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
403 :QThread((QObject*)parent)
405 :abstractSpwManager(plugin, parent)
404 {
406 {
405 this->RMAPtimeout = 2000;
406 this->handleMutex = new QMutex(QMutex::NonRecursive);
407 // this->handleMutex = new QMutex(QMutex::Recursive);
408 this->RMAP_AnswersSem = new QSemaphore(0);
409 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
410 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
411 this->plugin = plugin;
412 connected = false;
413 // TODO remove this crap!
407 // TODO remove this crap!
414 this->initDialog();
408 this->initDialog();
415 // this->moveToThread(this);
409 // this->moveToThread(this);
416 }
410 }
417
411
418 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
412 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
419 {
413 {
420 this->terminate();
421 while (!this->isFinished()) {
422 this->usleep(1000);
423 }
424 }
414 }
425
415
426 void stardundeeSPW_USB_Manager::run()
416 void stardundeeSPW_USB_Manager::run()
427 {
417 {
428 USB_SPACEWIRE_PACKET_PROPERTIES properties;
418 USB_SPACEWIRE_PACKET_PROPERTIES properties;
429 USB_SPACEWIRE_ID pIdentifier=NULL;
419 USB_SPACEWIRE_ID pIdentifier=NULL;
430 USB_SPACEWIRE_STATUS stat;
420 USB_SPACEWIRE_STATUS stat;
431 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
421 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
432 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
422 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
433 while (!this->isInterruptionRequested())
423 while (!this->isInterruptionRequested())
434 {
424 {
435 if(this->connected)
425 if(this->connected)
436 {
426 {
437 this->handleMutex->lock();
427 this->handleMutex->lock();
438 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
428 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
439 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
429 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
440 {
430 {
441 SocExplorerEngine::message(this->plugin,"Got packet",2);
431 SocExplorerEngine::message(this->plugin,"Got packet",2);
442 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
432 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
443 if (stat == TRANSFER_SUCCESS)
433 if (stat == TRANSFER_SUCCESS)
444 {
434 {
445 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
435 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
446 {
436 {
447 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
437 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
448 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
438 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
449 {
439 {
450 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
440 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
451 emit bytesReceivedFromSpw( properties.len );
441 emit bytesReceivedFromSpw( properties.len );
452 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
442 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
453 {
443 {
454 RMAP_Answer* packet;
444 RMAP_Answer* packet;
455 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
445 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
456 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
446 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
457 char* packetbuffer = (char*)malloc(properties.len);
447 char* packetbuffer = (char*)malloc(properties.len);
458 memcpy(packetbuffer,buffer,properties.len);
448 memcpy(packetbuffer,buffer,properties.len);
459 USBSpaceWire_FreeRead(hDevice, pIdentifier);
449 USBSpaceWire_FreeRead(hDevice, pIdentifier);
460 pIdentifier = NULL;
450 pIdentifier = NULL;
461 this->handleMutex->unlock();
451 this->handleMutex->unlock();
462 if(properties.len==8)
452 if(properties.len==8)
463 {
453 {
464 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
454 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
465 }
455 }
466 else
456 else
467 {
457 {
468 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
458 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
469 }
459 }
470 RMAP_AnswersMtx->lock();
460 RMAP_AnswersMtx->lock();
471 RMAP_Answers.append(packet);
461 RMAP_Answers.append(packet);
472 RMAP_AnswersMtx->unlock();
462 RMAP_AnswersMtx->unlock();
473 RMAP_AnswersSem->release();
463 RMAP_AnswersSem->release();
474 }
464 }
475 else //any non-rmap packet will be pushed to the network
465 else //any non-rmap packet will be pushed to the network
476 {
466 {
477 char* packetbuffer = (char*)malloc(properties.len);
467 char* packetbuffer = (char*)malloc(properties.len);
478 memcpy(packetbuffer,buffer,properties.len);
468 memcpy(packetbuffer,buffer,properties.len);
479 emit emitPacket(packetbuffer,properties.len);
469 emit emitPacket(packetbuffer,properties.len);
480 USBSpaceWire_FreeRead(hDevice, pIdentifier);
470 USBSpaceWire_FreeRead(hDevice, pIdentifier);
481 this->handleMutex->unlock();
471 this->handleMutex->unlock();
482 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
472 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
483 }
473 }
484 }
474 }
485 else
475 else
486 {
476 {
487 SocExplorerEngine::message(this->plugin,"No EOP received",2);
477 SocExplorerEngine::message(this->plugin,"No EOP received",2);
488 this->handleMutex->unlock();
478 this->handleMutex->unlock();
489 }
479 }
490 }
480 }
491
481
492 }
482 }
493 else
483 else
494 {
484 {
495 USBSpaceWire_FreeRead(hDevice, pIdentifier);
485 USBSpaceWire_FreeRead(hDevice, pIdentifier);
496 this->handleMutex->unlock();
486 this->handleMutex->unlock();
497 }
487 }
498 }
488 }
499 else
489 else
500 {
490 {
501 USBSpaceWire_FreeRead(hDevice, pIdentifier);
491 USBSpaceWire_FreeRead(hDevice, pIdentifier);
502 this->handleMutex->unlock();
492 this->handleMutex->unlock();
503 }
493 }
504 }
494 }
505 else
495 else
506 {
496 {
507 //do some sanity checks!
497 //do some sanity checks!
508 int list = USBSpaceWire_ListDevices();
498 int list = USBSpaceWire_ListDevices();
509 if(this->brickList!=list)
499 if(this->brickList!=list)
510 {
500 {
511 this->brickList = list;
501 this->brickList = list;
512 emit updateAvailableBrickCount(this->brickList);
502 emit updateAvailableBrickCount(this->brickList);
513 }
503 }
514 usleep(RMAPtimeout/2);
504 usleep(RMAPtimeout/2);
515 }
505 }
516 usleep(1000);
506 usleep(1000);
517 }
507 }
518 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
508 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
519 }
509 }
520
510
521 bool stardundeeSPW_USB_Manager::connectBridge()
511 bool stardundeeSPW_USB_Manager::connectBridge()
522 {
512 {
523 bool ret;
513 bool ret;
524
514
525 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
515 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
526 {
516 {
527 ret = connectBridgeAsInterface();
517 ret = connectBridgeAsInterface();
528 }
518 }
529 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
519 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
530 {
520 {
531 ret = connectBridgeAsRouter();
521 ret = connectBridgeAsRouter();
532 }
522 }
533 else
523 else
534 {
524 {
535 ret = false;
525 ret = false;
536 }
526 }
537
527
538 return ret;
528 return ret;
539 }
529 }
540
530
541 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
531 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
542 {
532 {
543 this->handleMutex->lock();
533 this->handleMutex->lock();
544 int status;
534 int status;
545 U32 statusControl;
535 U32 statusControl;
546 this->connected = false;
536 this->connected = false;
547 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
537 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
548 {
538 {
549 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
539 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
550 this->handleMutex->unlock();
540 this->handleMutex->unlock();
551 return false;
541 return false;
552 }
542 }
553 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
543 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
554
544
555 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
545 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
556 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
546 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
557 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
547 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
558
548
559 // Set the path and return path to the device
549 // Set the path and return path to the device
560 CFGSpaceWire_StackClear();
550 CFGSpaceWire_StackClear();
561 CFGSpaceWire_AddrStackPush(0);
551 CFGSpaceWire_AddrStackPush(0);
562 CFGSpaceWire_AddrStackPush(254);
552 CFGSpaceWire_AddrStackPush(254);
563 CFGSpaceWire_RetAddrStackPush(254);
553 CFGSpaceWire_RetAddrStackPush(254);
564 // set the base transmit rate to 100 MHz
554 // set the base transmit rate to 100 MHz
565 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
555 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
566 if (status != CFG_TRANSFER_SUCCESS)
556 if (status != CFG_TRANSFER_SUCCESS)
567 {
557 {
568 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
558 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
569 this->handleMutex->unlock();
559 this->handleMutex->unlock();
570 return false;
560 return false;
571 }
561 }
572 else
562 else
573 {
563 {
574 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
564 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
575 }
565 }
576
566
577 // read the link status
567 // read the link status
578 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
568 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
579 {
569 {
580 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
570 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
581 this->handleMutex->unlock();
571 this->handleMutex->unlock();
582 return false;
572 return false;
583 }
573 }
584 else
574 else
585 {
575 {
586 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
576 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
587
577
588 // Set the link status control register properties
578 // Set the link status control register properties
589 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
579 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
590 CFGSpaceWire_LSEnableStart(&statusControl, 1);
580 CFGSpaceWire_LSEnableStart(&statusControl, 1);
591 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
581 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
592 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
582 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
593 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
583 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
594
584
595 // Set the link status control register
585 // Set the link status control register
596 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
586 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
597 {
587 {
598 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
588 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
599 this->handleMutex->unlock();
589 this->handleMutex->unlock();
600 return false;
590 return false;
601 }
591 }
602 else
592 else
603 {
593 {
604 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
594 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
605 }
595 }
606 }
596 }
607
597
608 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
598 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
609 {
599 {
610 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
600 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
611 this->handleMutex->unlock();
601 this->handleMutex->unlock();
612 return false;
602 return false;
613 }
603 }
614 else
604 else
615 {
605 {
616 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
606 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
617 }
607 }
618
608
619 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
609 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
620 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
610 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
621 USBSpaceWire_SetTimeout(hDevice,1.0);
611 USBSpaceWire_SetTimeout(hDevice,1.0);
622 this->handleMutex->unlock();
612 this->handleMutex->unlock();
623 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
613 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
624 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
614 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
625 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
615 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
626 this->connected = true;
616 this->connected = true;
627 return true;
617 return true;
628 }
618 }
629
619
630 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
620 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
631 {
621 {
632 // QMutexLocker mlock(&this->handleMutex);
622 // QMutexLocker mlock(&this->handleMutex);
633 this->handleMutex->lock();
623 this->handleMutex->lock();
634 int status;
624 int status;
635 U32 statusControl;
625 U32 statusControl;
636 unsigned int linkStatus1;
626 unsigned int linkStatus1;
637 unsigned int linkStatus2;
627 unsigned int linkStatus2;
638 unsigned char linkNumber;
628 unsigned char linkNumber;
639 unsigned char deviceIsAnInterface;
629 unsigned char deviceIsAnInterface;
640
630
641 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
631 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
642 {
632 {
643 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
633 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
644 this->handleMutex->unlock();
634 this->handleMutex->unlock();
645 return false;
635 return false;
646 }
636 }
647 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
637 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
648 + QString::number(this->selectedBrick));
638 + QString::number(this->selectedBrick));
649
639
650 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
640 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
651 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
641 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
652 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
642 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
653
643
654 // Set the path and return path to the device
644 // Set the path and return path to the device
655 // This affects just the operations performed by the Configuration Library and does not affect the packets
645 // This affects just the operations performed by the Configuration Library and does not affect the packets
656 // sent and received using the driver API.
646 // sent and received using the driver API.
657 CFGSpaceWire_StackClear();
647 CFGSpaceWire_StackClear();
658 CFGSpaceWire_AddrStackPush(0);
648 CFGSpaceWire_AddrStackPush(0);
659 CFGSpaceWire_AddrStackPush(254);
649 CFGSpaceWire_AddrStackPush(254);
660 CFGSpaceWire_RetAddrStackPush(254);
650 CFGSpaceWire_RetAddrStackPush(254);
661
651
662 // set the base transmit rate to 100 MHz
652 // set the base transmit rate to 100 MHz
663 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
653 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
664 if (status != CFG_TRANSFER_SUCCESS)
654 if (status != CFG_TRANSFER_SUCCESS)
665 {
655 {
666 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
656 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
667 }
657 }
668 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
658 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
669
659
670 //*********************
660 //*********************
671 // LINK 1 CONFIGURATION
661 // LINK 1 CONFIGURATION
672 linkNumber = 1;
662 linkNumber = 1;
673 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
663 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
674 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
664 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
675 else
665 else
676 {
666 {
677 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
667 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
678
668
679 // Set the link status control register properties
669 // Set the link status control register properties
680 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
670 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
681 CFGSpaceWire_LSEnableStart(&statusControl, 1);
671 CFGSpaceWire_LSEnableStart(&statusControl, 1);
682 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
672 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
683 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
673 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
684 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
674 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
685
675
686 // Set the link status control register
676 // Set the link status control register
687 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
677 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
688 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
678 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
689 else
679 else
690 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
680 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
691 }
681 }
692
682
693 //*********************
683 //*********************
694 // LINK 2 CONFIGURATION
684 // LINK 2 CONFIGURATION
695 linkNumber = 2;
685 linkNumber = 2;
696 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
686 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
697 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
687 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
698 else
688 else
699 {
689 {
700 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
690 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
701
691
702 // Set the link status control register properties
692 // Set the link status control register properties
703 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
693 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
704 CFGSpaceWire_LSEnableStart(&statusControl, 1);
694 CFGSpaceWire_LSEnableStart(&statusControl, 1);
705 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
695 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
706 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
696 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
707 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
697 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
708
698
709 // Set the link status control register
699 // Set the link status control register
710 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
700 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
711 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
701 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
712 else
702 else
713 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
703 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
714 }
704 }
715
705
716 //***************************
706 //***************************
717 // SET THE DEVICE AS A ROUTER
707 // SET THE DEVICE AS A ROUTER
718 deviceIsAnInterface = 0; // 0 = router, 1 = interface
708 deviceIsAnInterface = 0; // 0 = router, 1 = interface
719 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
709 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
720 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
710 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
721 else
711 else
722 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
712 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
723
713
724 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
714 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
725 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
715 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
726
716
727 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
717 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
728 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
718 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
729
719
730 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
720 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
731 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
721 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
732 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
722 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
733
723
734 //************
724 //************
735 // test Link 1 and Link 2
725 // test Link 1 and Link 2
736 linkStatus1 = getLinkStatus(0x01);
726 linkStatus1 = getLinkStatus(0x01);
737 linkStatus2 = getLinkStatus(0x02);
727 linkStatus2 = getLinkStatus(0x02);
738 this->handleMutex->unlock();
728 this->handleMutex->unlock();
739
729
740 if ((linkStatus1==1) || (linkStatus2==1))
730 if ((linkStatus1==1) || (linkStatus2==1))
741 {
731 {
742 initializeTimecodeGeneration();
732 initializeTimecodeGeneration();
743 this->connected=true;
733 this->connected=true;
744 return true;
734 return true;
745 }
735 }
746 else
736 else
747 {
737 {
748 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
738 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
749 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
739 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
750 starDundeeStatusQueryDialog->exec();
740 starDundeeStatusQueryDialog->exec();
751 this->connected = false;
741 this->connected = false;
752 return false;
742 return false;
753 }
743 }
754 }
744 }
755
745
756 void stardundeeSPW_USB_Manager::initDialog( void )
746 void stardundeeSPW_USB_Manager::initDialog( void )
757 {
747 {
758 // STAR DUNDEE STATUS QUERY DIALOG
748 // STAR DUNDEE STATUS QUERY DIALOG
759 starDundeeStatusQueryDialog = new QDialog;
749 starDundeeStatusQueryDialog = new QDialog;
760 starDundeeStatusQueryDialogLayout = new QGridLayout;
750 starDundeeStatusQueryDialogLayout = new QGridLayout;
761 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
751 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
762 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
752 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
763 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
753 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
764 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
754 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
765 statusLink1 = new QLabel(tr("Link 1 status code: -"));
755 statusLink1 = new QLabel(tr("Link 1 status code: -"));
766 statusLink2 = new QLabel(tr("Link 2 status code: -"));
756 statusLink2 = new QLabel(tr("Link 2 status code: -"));
767
757
768 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
758 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
769 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
759 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
770 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
760 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
771 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
761 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
772 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
762 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
773 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
763 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
774 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
764 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
775 }
765 }
776
766
777 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
767 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
778 {
768 {
779 U32 routingTableEntry;
769 U32 routingTableEntry;
780 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
770 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
781 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
771 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
782 {
772 {
783 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
773 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
784 }
774 }
785 // Build the routing table entry
775 // Build the routing table entry
786 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
776 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
787 dwOutputPorts, // route out of port dwOutputPorts
777 dwOutputPorts, // route out of port dwOutputPorts
788 bDelHead, // header deletion is enabled [1] or disabled [0]
778 bDelHead, // header deletion is enabled [1] or disabled [0]
789 0); // priority normal
779 0); // priority normal
790 // Set the routing table entry for logical address tableEntry
780 // Set the routing table entry for logical address tableEntry
791 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
781 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
792 {
782 {
793 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
783 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
794 }
784 }
795 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
785 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
796 return 1;
786 return 1;
797 }
787 }
798
788
799 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
789 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
800 {
790 {
801 U32 routingTableEntry, outputPorts;
791 U32 routingTableEntry, outputPorts;
802 char enabled, delHead, priority;
792 char enabled, delHead, priority;
803 int portNum;
793 int portNum;
804
794
805 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
795 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
806 // Read the routing table entry
796 // Read the routing table entry
807 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
797 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
808 {
798 {
809 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
799 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
810 }
800 }
811 else
801 else
812 {
802 {
813 // Display the routing table entry properties
803 // Display the routing table entry properties
814 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
804 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
815 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
805 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
816 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
806 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
817 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
807 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
818 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
808 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
819 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
809 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
820 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
810 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
821 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
811 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
822 for (portNum = 0; portNum < 32; portNum++)
812 for (portNum = 0; portNum < 32; portNum++)
823 {
813 {
824 if (outputPorts & (1 << portNum))
814 if (outputPorts & (1 << portNum))
825 {
815 {
826 SocExplorerEngine::message(this->plugin,QString::number(portNum));
816 SocExplorerEngine::message(this->plugin,QString::number(portNum));
827 }
817 }
828 }
818 }
829 }
819 }
830
820
831 return 1;
821 return 1;
832 }
822 }
833
823
834 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
824 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
835 {
825 {
836 U32 dwTickEnableStatus;
826 U32 dwTickEnableStatus;
837 U32 rtr_clk_freq;
827 U32 rtr_clk_freq;
838
828
839 // (1) RESET
829 // (1) RESET
840 if (!USBSpaceWire_TC_Reset(hDevice))
830 if (!USBSpaceWire_TC_Reset(hDevice))
841 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
831 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
842
832
843 // (2) Clear the tick enable register
833 // (2) Clear the tick enable register
844 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
834 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
845 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
835 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
846 else
836 else
847 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
837 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
848
838
849 // (3) get the tick status
839 // (3) get the tick status
850 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
840 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
851 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
841 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
852
842
853 // (4) enable external timecode selection
843 // (4) enable external timecode selection
854 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
844 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
855 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
845 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
856
846
857 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
847 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
858
848
859 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
849 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
860
850
861 //**************************************************
851 //**************************************************
862 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
852 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
863 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
853 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
864 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
854 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
865 }
855 }
866
856
867 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
857 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
868 {
858 {
869 U32 statusControl, errorStatus, portType;
859 U32 statusControl, errorStatus, portType;
870 U32 linkStatus, operatingSpeed, outputPortConnection;
860 U32 linkStatus=0, operatingSpeed, outputPortConnection;
871 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
861 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
872
862
873 // Read the link status control register
863 // Read the link status control register
874 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
864 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
875 {
865 {
876 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
866 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
877 }
867 }
878 else
868 else
879 {
869 {
880 // Display the link status control register properties
870 // Display the link status control register properties
881 CFGSpaceWire_LSPortType(statusControl, &portType);
871 CFGSpaceWire_LSPortType(statusControl, &portType);
882 if (portType == CFG_CONFIGURATION_PORT)
872 if (portType == CFG_CONFIGURATION_PORT)
883 {
873 {
884 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
874 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
885 }
875 }
886 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
876 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
887 {
877 {
888 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
878 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
889 }
879 }
890 else
880 else
891 {
881 {
892 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
882 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
893 }
883 }
894 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
884 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
895 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
885 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
896 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
886 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
897 CFGSpaceWire_LSIsStart(statusControl, &isStart);
887 CFGSpaceWire_LSIsStart(statusControl, &isStart);
898 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
888 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
899 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
889 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
900 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
890 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
901 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
891 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
902 }
892 }
903 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
893 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
904 +" is " + dwLinkStatusQString[linkStatus]);
894 +" is " + dwLinkStatusQString[linkStatus]);
905 if (linkStatus == 5)
895 if (linkStatus == 5)
906 {
896 {
907 return 1;
897 return 1;
908 }
898 }
909 else return 0;
899 else return 0;
910 }
900 }
911
901
912 bool stardundeeSPW_USB_Manager::disconnectBridge()
902 bool stardundeeSPW_USB_Manager::disconnectBridge()
913 {
903 {
914 this->handleMutex->lock();
904 this->handleMutex->lock();
905 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
915 USBSpaceWire_Close(hDevice); // Close the device
906 USBSpaceWire_Close(hDevice); // Close the device
916 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
907 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
917 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
918 this->handleMutex->unlock();
908 this->handleMutex->unlock();
919 this->RMAP_pending_transaction_IDsMtx->lock();
909 this->RMAP_pending_transaction_IDsMtx->lock();
920 this->RMAP_pending_transaction_IDs.clear();
910 this->RMAP_pending_transaction_IDs.clear();
921 this->RMAP_pending_transaction_IDsMtx->unlock();
911 this->RMAP_pending_transaction_IDsMtx->unlock();
922 this->RMAP_AnswersMtx->lock();
912 this->RMAP_AnswersMtx->lock();
923 this->RMAP_Answers.clear();
913 this->RMAP_Answers.clear();
924 this->RMAP_AnswersMtx->unlock();
914 this->RMAP_AnswersMtx->unlock();
925 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
915 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
926 return true;
916 return true;
927 }
917 }
928
918
929 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
930 {
931 this->RMAP_pending_transaction_IDsMtx->lock();
932 int ID=0;
933 bool found=true;
934 while(ID<511)
935 {
936 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
937 {
938 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
939 }
940 if(found==true)break;
941 ID++;
942 found = true;
943 }
944 if(found)
945 {
946 RMAP_pending_transaction_IDs.append(ID);
947 }
948 this->RMAP_pending_transaction_IDsMtx->unlock();
949 return ID;
950 }
951
952 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
953 {
954 QTime timeout;
955 *buffer=NULL;
956 int count=0;
957 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
958 timeout.start();
959 while (*buffer==NULL)
960 {
961 this->RMAP_AnswersMtx->lock();
962 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
963 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
964 for(int i=0;i<RMAP_Answers.count();i++)
965 {
966 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
967 if(RMAP_Answers[i]->transactionID==transactionID)
968 {
969 this->RMAP_pending_transaction_IDsMtx->lock();
970 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
971 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
972 {
973 if(RMAP_pending_transaction_IDs[j]==transactionID)
974 {
975 RMAP_pending_transaction_IDs.removeAt(j);
976 }
977 }
978 this->RMAP_pending_transaction_IDsMtx->unlock();
979 *buffer = RMAP_Answers[i]->data;
980 count = RMAP_Answers[i]->len;
981 RMAP_Answer* tmp=RMAP_Answers[i];
982 RMAP_Answers.removeAt(i);
983 delete tmp;
984 }
985 }
986 this->RMAP_AnswersMtx->unlock();
987 //if no answer found in the stack wait until a new packet is pushed
988 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
989 if(*buffer==NULL)
990 {
991 while (0==this->RMAP_AnswersSem->available())
992 {
993 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
994 if(timeout.elapsed()>=RMAPtimeout)
995 {
996 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
997 return -1;
998 }
999 usleep(1000);
1000 }
1001 this->RMAP_AnswersSem->acquire();
1002 }
1003 }
1004 return count;
1005 }
1006
1007 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
919 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
1008 {
920 {
1009 char protocoleIdentifier;
921 char protocoleIdentifier;
1010 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
922 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
1011 USB_SPACEWIRE_ID pIdentifier;
923 USB_SPACEWIRE_ID pIdentifier;
1012 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
924 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
1013 this->handleMutex->lock();
925 this->handleMutex->lock();
1014 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
926 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
1015 USBSpaceWire_FreeSend(hDevice, pIdentifier);
927 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1016 this->handleMutex->unlock();
928 this->handleMutex->unlock();
1017 if (result != TRANSFER_SUCCESS)
929 if (result != TRANSFER_SUCCESS)
1018 {
930 {
1019 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
931 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
1020 return false;
932 return false;
1021 }
933 }
1022 else
934 else
1023 {
935 {
1024 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
936 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1025 // read the protocole identifier
937 // read the protocole identifier
1026 protocoleIdentifier = packet[2];
938 protocoleIdentifier = packet[2];
1027 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
939 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1028 emit ccsdsPacketTransmittedToSpw();
940 emit ccsdsPacketTransmittedToSpw();
1029
941
1030 SocExplorerEngine::message(this->plugin,"Packet sent",2);
942 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1031 }
943 }
1032 return true;
944 return true;
1033 }
945 }
1034
946
1035 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1036 {
1037 char* packetbuffer = (char*)malloc(len);
1038 memcpy(packetbuffer,packet,len);
1039 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1040 RMAP_AnswersMtx->lock();
1041 RMAP_Answers.append(RMPAPpacket);
1042 RMAP_AnswersMtx->unlock();
1043 }
1044
947
1045 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
948 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1046 {
949 {
1047 this->handleMutex->lock();
950 this->handleMutex->lock();
1048 if (onOff == true)
951 if (onOff == true)
1049 {
952 {
1050 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
953 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
1051 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
954 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
1052 }
955 }
1053 else
956 else
1054 {
957 {
1055 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
958 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
1056 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
959 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
1057 }
960 }
1058 this->handleMutex->unlock();
961 this->handleMutex->unlock();
1059 }
962 }
1060
963
1061 int stardundeeSPW_USB_Manager::getLinkNumber( void )
964 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1062 {
965 {
1063 return this->linkNumber;
966 return this->linkNumber;
1064 }
967 }
1065
968
1066 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
969 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1067 {
970 {
1068 U32 rtr_clk_freq=0;
971 U32 rtr_clk_freq=0;
1069 U32 freqCount=0;
972 U32 freqCount=0;
1070 double freqCountInDouble=0.0;
973 double freqCountInDouble=0.0;
1071 double currentFrequency=0.0;
974 double currentFrequency=0.0;
1072
975
1073 this->handleMutex->lock();
976 this->handleMutex->lock();
1074 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
977 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
1075 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
978 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
1076 freqCount = (unsigned int) freqCountInDouble;
979 freqCount = (unsigned int) freqCountInDouble;
1077
980
1078 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
981 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
1079
982
1080 //**************************************************
983 //**************************************************
1081 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
984 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
1082 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
985 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
1083 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
986 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
1084 else
987 else
1085 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
988 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
1086 + " (freqCount set to " + QString::number(freqCount) + ")" );
989 + " (freqCount set to " + QString::number(freqCount) + ")" );
1087 this->handleMutex->unlock();
990 this->handleMutex->unlock();
1088 }
991 }
1089
992
1090 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
993 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
1091 {
994 {
1092 this->handleMutex->lock();
995 this->handleMutex->lock();
1093 // enable external timecode selection
996 // enable external timecode selection
1094 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
997 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
1095 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
998 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
1096
999
1097 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1000 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1098 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1001 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1099 else
1002 else
1100 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1003 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1101
1004
1102 // disable external timecode selection
1005 // disable external timecode selection
1103 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1006 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1104 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1007 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1105 this->handleMutex->unlock();
1008 this->handleMutex->unlock();
1106 }
1009 }
1107
1010
1108
1011
@@ -1,163 +1,149
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - 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
28
29 #include "fakestardundeespwusb_lib.h"
29 #include "fakestardundeespwusb_lib.h"
30 #include <socexplorerplugin.h>
30 #include <socexplorerplugin.h>
31 #include <abstractspwbridge.h>
31 #include <abstractspwbridge.h>
32 #include <QThread>
32 #include <QThread>
33 #include <QMutex>
33 #include <QMutex>
34 #include <QSemaphore>
34 #include <QSemaphore>
35 #include <QGridLayout>
35 #include <QGridLayout>
36 #include <QPushButton>
36 #include <QPushButton>
37 #include <QComboBox>
37 #include <QComboBox>
38 #include <QLabel>
38 #include <QLabel>
39 #include "stardundeegui.h"
39 #include "stardundeegui.h"
40
40
41 #define BRICK_IS_SET_AS_AN_INTERFACE true
41 #define BRICK_IS_SET_AS_AN_INTERFACE true
42 #define BRICK_IS_SET_AS_A_ROUTER false
42 #define BRICK_IS_SET_AS_A_ROUTER false
43
43
44 class stardundeeSPW_USB_Manager: public QThread
44 class stardundeeSPW_USB_Manager: public abstractSpwManager
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
48 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
49 ~stardundeeSPW_USB_Manager();
49 ~stardundeeSPW_USB_Manager();
50 void run();
50 void run();
51 bool connectBridge();
51 bool connectBridge();
52 bool connectBridgeAsInterface();
52 bool connectBridgeAsInterface();
53 bool connectBridgeAsRouter();
53 bool connectBridgeAsRouter();
54 void initDialog( void );
54 void initDialog( void );
55 unsigned char setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead);
55 unsigned char setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead);
56 unsigned int getRoutingTableEntry(int tableEntry);
56 unsigned int getRoutingTableEntry(int tableEntry);
57 void initializeTimecodeGeneration();
57 void initializeTimecodeGeneration();
58 void setTimecodeFrequency(double requestedFrequency);
58 void setTimecodeFrequency(double requestedFrequency);
59 unsigned int getLinkStatus(unsigned char link);
59 unsigned int getLinkStatus(unsigned char link);
60 bool disconnectBridge();
60 bool disconnectBridge();
61 int getRMAPtransactionID();
62 int getRMAPanswer(int transactionID,char** buffer);
63 bool sendPacket(char* packet,int size);
61 bool sendPacket(char* packet,int size);
64
62
65 signals:
63 signals:
66 void updateAvailableBrickCount(int count);
64 void updateAvailableBrickCount(int count);
67 void emitPacket(char* packet,int size);
65 void emitPacket(char* packet,int size);
68 void bytesReceivedFromSpw( unsigned int );
66 void bytesReceivedFromSpw( unsigned int );
69 void bytesTransmittedToSpw( unsigned int);
67 void bytesTransmittedToSpw( unsigned int);
70 void ccsdsPacketTransmittedToSpw( void );
68 void ccsdsPacketTransmittedToSpw( void );
71
69
72 public slots:
70 public slots:
73 void sendTimecodePeriodically( bool onOff );
71 void sendTimecodePeriodically( bool onOff );
74 void sendOneTimecode(unsigned char nTimein);
72 void sendOneTimecode(unsigned char nTimein);
75 int getLinkNumber( void );
73 int getLinkNumber( void );
76
74
77 private:
75 private:
78 QMutex *handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
76 //QSemaphore* RMAP_AnswersSem;
79 QSemaphore* RMAP_AnswersSem;
80 void pushRmapPacket(char* packet,int len);
81 star_device_handle hDevice;
77 star_device_handle hDevice;
82 socexplorerplugin* plugin;
83 bool connected;
84 char* SPWPacketBuff;
85 QList<RMAP_Answer*> RMAP_Answers;
86 QList<int> RMAP_pending_transaction_IDs;
87
78
88 QLabel *starDundeeStatusQueryDialogLabel;
79 QLabel *starDundeeStatusQueryDialogLabel;
89 QPushButton *starDundeeStatusQueryRetryButton;
80 QPushButton *starDundeeStatusQueryRetryButton;
90 QPushButton *starDundeeStatusQueryAbortButton;
81 QPushButton *starDundeeStatusQueryAbortButton;
91 QLabel *statusLink1;
82 QLabel *statusLink1;
92 QLabel *statusLink2;
83 QLabel *statusLink2;
93 QPushButton *starDundeeStatusQueryContinueButton;
84 QPushButton *starDundeeStatusQueryContinueButton;
94 QDialog *starDundeeStatusQueryDialog;
85 QDialog *starDundeeStatusQueryDialog;
95 QGridLayout *starDundeeStatusQueryDialogLayout;
86 QGridLayout *starDundeeStatusQueryDialogLayout;
96
87
97 public:
88 public:
98 int selectedBrick;
89 int selectedBrick;
99 int linkNumber;
100 int brickList;
90 int brickList;
101 int linkSpeed;
91 int linkSpeed;
102 int sourceLogicalAddress;
103 int destinationLogicalAddress;
104 int destinationKey;
105 int RMAPtimeout;
106 double timecodeFrequency;
92 double timecodeFrequency;
107 bool interfaceMode; // 1 => interface mode, 0 => router mode
93 bool interfaceMode; // 1 => interface mode, 0 => router mode
108 };
94 };
109
95
110 class stardundeeSPW_USB : public abstractSpwBridge
96 class stardundeeSPW_USB : public abstractSpwBridge
111 {
97 {
112 Q_OBJECT
98 Q_OBJECT
113 public:
99 public:
114 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
100 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
115 ~stardundeeSPW_USB();
101 ~stardundeeSPW_USB();
116
102
117 signals:
103 signals:
118
104
119 void setRmapTimeout(const QString & timeout);
105 void setRmapTimeout(const QString & timeout);
120 void SelectBrick(int brickIndex);
106 void SelectBrick(int brickIndex);
121 void SelectLinkNumber(int linkIndex);
107 void SelectLinkNumber(int linkIndex);
122 void SelectLinkSpeed(int linkSpeed);
108 void SelectLinkSpeed(int linkSpeed);
123 void SetDestinationKey(const QString & destKey);
109 void SetDestinationKey(const QString & destKey);
124 void SetSourceAddress(const QString & address);
110 void SetSourceAddress(const QString & address);
125 void SetDestinationAddress(const QString & address);
111 void SetDestinationAddress(const QString & address);
126 void SetRmapTimeout(const QString & timeout);
112 void SetRmapTimeout(const QString & timeout);
127 void SetTimecodeFrequency( double );
113 void SetTimecodeFrequency( double );
128 void SetBrickAsAnInterface( bool );
114 void SetBrickAsAnInterface( bool );
129 void SetBrickAsARouter( bool );
115 void SetBrickAsARouter( bool );
130 int GetAvailableBrickCount( void );
116 int GetAvailableBrickCount( void );
131 unsigned int GetNbPacketsTransmittedToSpw( void );
117 unsigned int GetNbPacketsTransmittedToSpw( void );
132 unsigned int GetNbCCSDSPacketsTransmittedToSpw( void );
118 unsigned int GetNbCCSDSPacketsTransmittedToSpw( void );
133 void BytesReceivedFromSpw( unsigned int );
119 void BytesReceivedFromSpw( unsigned int );
134 void BytesTransmittedToSpw( unsigned int );
120 void BytesTransmittedToSpw( unsigned int );
135 void CCSDSPacketTransmittedToSpw( void );
121 void CCSDSPacketTransmittedToSpw( void );
136 void StartSendingTimecodes( bool );
122 void StartSendingTimecodes( bool );
137 void SendOneTimecode( unsigned char );
123 void SendOneTimecode( unsigned char );
138 int GetLinkNumber();
124 int GetLinkNumber();
139
125
140 public slots:
126 public slots:
141 void toggleBridgeConnection();
127 void toggleBridgeConnection();
142 bool connectBridge();
128 bool connectBridge();
143 bool disconnectBridge();
129 bool disconnectBridge();
144 int pushRMAPPacket(char* packet,int size);
130 int pushRMAPPacket(char* packet,int size);
145 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
131 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
146 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
132 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
147 void brickSelectionChanged(int brickIndex);
133 void brickSelectionChanged(int brickIndex);
148 void linkNumberSelectionChanged(int linkIndex);
134 void linkNumberSelectionChanged(int linkIndex);
149 void linkSpeedSelectionChanged(const QString & linkSpeed);
135 void linkSpeedSelectionChanged(const QString & linkSpeed);
150 void sourceLogicalAddressChanged(const QString & destKey);
136 void sourceLogicalAddressChanged(const QString & destKey);
151 void destinationAddressChanged(const QString & rmapaddress);
137 void destinationAddressChanged(const QString & rmapaddress);
152 void brickModeChanged( bool interfaceMode );
138 void brickModeChanged( bool interfaceMode );
153 void destinationKeyChanged(const QString & key);
139 void destinationKeyChanged(const QString & key);
154 void rmapTimeoutChanged(const QString & timeout);
140 void rmapTimeoutChanged(const QString & timeout);
155 void sendPacketComingFromTCPServer(char *packet, int size);
141 void sendPacketComingFromTCPServer(char *packet, int size);
156 void timecodeFrequencyChanged(const QString &frequency);
142 void timecodeFrequencyChanged(const QString &frequency);
157 void startSendingTimecodes( bool onOff );
143 void startSendingTimecodes( bool onOff );
158 private:
144 private:
159 void makeGUI(socexplorerplugin *parent);
145 void makeGUI(socexplorerplugin *parent);
160 stardundeeSPW_USB_Manager* manager;
146 stardundeeSPW_USB_Manager* manager;
161 };
147 };
162
148
163 #endif // STARDUNDEESPW_USB_H
149 #endif // STARDUNDEESPW_USB_H
@@ -1,56 +1,179
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - 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 #include "abstractspwbridge.h"
22 #include "abstractspwbridge.h"
23 #include <QTime>
24 #include <socexplorerengine.h>
23
25
24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
26 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
25 :QObject((QObject*)parent)
27 :QObject((QObject*)parent)
26 {
28 {
27 this->plugin = parent;
29 this->plugin = parent;
28 this->p_GUI=NULL;
30 this->p_GUI=NULL;
29 }
31 }
30
32
31 abstractSpwBridge::~abstractSpwBridge()
33 abstractSpwBridge::~abstractSpwBridge()
32 {
34 {
33 // delete this->p_GUI;
35 // delete this->p_GUI;
34 }
36 }
35
37
36 QWidget *abstractSpwBridge::getGUI()
38 QWidget *abstractSpwBridge::getGUI()
37 {
39 {
38 return this->p_GUI;
40 return this->p_GUI;
39 }
41 }
40
42
41 bool abstractSpwBridge::connectBridge()
43 bool abstractSpwBridge::connectBridge()
42 {
44 {
43 return false;
45 return false;
44 }
46 }
45
47
46 bool abstractSpwBridge::disconnectBridge()
48 bool abstractSpwBridge::disconnectBridge()
47 {
49 {
48 return false;
50 return false;
49 }
51 }
50
52
51
53
52
54
53
55
54
56
55
57
56
58
59
60
61
62 abstractSpwManager::abstractSpwManager(socexplorerplugin *plugin, QObject *parent)
63 :QThread((QObject*)parent)
64 {
65 this->RMAPtimeout = 2000;
66 this->handleMutex = new QMutex(QMutex::NonRecursive);
67 this->RMAP_AnswersSem = new QSemaphore(0);
68 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
69 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
70 this->plugin = plugin;
71 connected = false;
72 }
73
74 abstractSpwManager::~abstractSpwManager()
75 {
76 this->terminate();
77 while (!this->isFinished())
78 {
79 this->usleep(1000);
80 }
81 }
82
83 int abstractSpwManager::getRMAPtransactionID()
84 {
85 this->RMAP_pending_transaction_IDsMtx->lock();
86 int ID=0;
87 bool found=true;
88 while(ID<511)
89 {
90 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
91 {
92 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
93 }
94 if(found==true)break;
95 ID++;
96 found = true;
97 }
98 if(found)
99 {
100 RMAP_pending_transaction_IDs.append(ID);
101 }
102 this->RMAP_pending_transaction_IDsMtx->unlock();
103 return ID;
104 }
105
106 int abstractSpwManager::getRMAPanswer(int transactionID, char **buffer)
107 {
108
109 QTime timeout;
110 *buffer=NULL;
111 int count=0;
112 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
113 qApp->processEvents();
114 timeout.start();
115 while (*buffer==NULL)
116 {
117 this->RMAP_AnswersMtx->lock();
118 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
119 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
120 for(int i=0;i<RMAP_Answers.count();i++)
121 {
122 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
123 if(RMAP_Answers[i]->transactionID==transactionID)
124 {
125 this->RMAP_pending_transaction_IDsMtx->lock();
126 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
127 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
128 {
129 if(RMAP_pending_transaction_IDs[j]==transactionID)
130 {
131 RMAP_pending_transaction_IDs.removeAt(j);
132 }
133 }
134 this->RMAP_pending_transaction_IDsMtx->unlock();
135 *buffer = RMAP_Answers[i]->data;
136 count = RMAP_Answers[i]->len;
137 RMAP_Answer* tmp=RMAP_Answers[i];
138 RMAP_Answers.removeAt(i);
139 delete tmp;
140 }
141 }
142 this->RMAP_AnswersMtx->unlock();
143 //if no answer found in the stack wait until a new packet is pushed
144 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
145 if(*buffer==NULL)
146 {
147 while (0==this->RMAP_AnswersSem->available())
148 {
149 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
150 if(timeout.elapsed()>=RMAPtimeout)
151 {
152 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
153 return -1;
154 }
155 usleep(1000);
156 qApp->processEvents();
157 }
158 this->RMAP_AnswersSem->acquire();
159 }
160 }
161 return count;
162 }
163
164 int abstractSpwManager::getLinkNumber()
165 {
166 return this->linkNumber;
167 }
168
169 void abstractSpwManager::pushRmapPacket(char *packet, int len)
170 {
171 char* packetbuffer = (char*)malloc(len);
172 memcpy(packetbuffer,packet,len);
173 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
174 RMAP_AnswersMtx->lock();
175 RMAP_Answers.append(RMPAPpacket);
176 RMAP_AnswersMtx->unlock();
177 }
178
179
@@ -1,68 +1,110
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, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - 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 ABSTRACTSPWBRIDGE_H
22 #ifndef ABSTRACTSPWBRIDGE_H
23 #define ABSTRACTSPWBRIDGE_H
23 #define ABSTRACTSPWBRIDGE_H
24
24
25 #include <QObject>
25 #include <QObject>
26 #include <QThread>
27 #include <QMutex>
28 #include <QSemaphore>
26 #include <socexplorerplugin.h>
29 #include <socexplorerplugin.h>
27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
30 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
28 #include <spw.h>
31 #include <spw.h>
29
32
30 class RMAP_Answer
33 class RMAP_Answer
31 {
34 {
32 public:
35 public:
33 RMAP_Answer(int ID,char* data,int len)
36 RMAP_Answer(int ID,char* data,int len)
34 {
37 {
35 transactionID = ID;
38 transactionID = ID;
36 this->data = data;
39 this->data = data;
37 this->len = len;
40 this->len = len;
38 }
41 }
39 int transactionID;
42 int transactionID;
40 char* data;
43 char* data;
41 int len;
44 int len;
42 };
45 };
43
46
44 class abstractSpwBridge : public QObject
47 class abstractSpwBridge : public QObject
45 {
48 {
46 Q_OBJECT
49 Q_OBJECT
47 public:
50 public:
48 explicit abstractSpwBridge(socexplorerplugin *parent);
51 explicit abstractSpwBridge(socexplorerplugin *parent);
49 ~abstractSpwBridge();
52 ~abstractSpwBridge();
50 QWidget *getGUI();
53 QWidget *getGUI();
51
54
52 public slots:
55 public slots:
53 virtual bool connectBridge();
56 virtual bool connectBridge();
54 virtual bool disconnectBridge();
57 virtual bool disconnectBridge();
55 virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
58 virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
56 virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
59 virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
57 virtual int pushRMAPPacket(char* packet,int size)=0;
60 virtual int pushRMAPPacket(char* packet,int size)=0;
58 signals:
61 signals:
59 void setConnected(bool connected);
62 void setConnected(bool connected);
60 void pushPacketOverTCP(char* packet,int size);
63 void pushPacketOverTCP(char* packet,int size);
61 protected:
64 protected:
62 socexplorerplugin* plugin;
65 socexplorerplugin* plugin;
63 QWidget* p_GUI;
66 QWidget* p_GUI;
64 private:
67 private:
65
68
66 };
69 };
67
70
71 class abstractSpwManager: public QThread
72 {
73 Q_OBJECT
74 public:
75 explicit abstractSpwManager(socexplorerplugin *plugin = 0,QObject* parent=0);
76 ~abstractSpwManager();
77 virtual void run(){}
78 virtual bool connectBridge()=0;
79 virtual bool disconnectBridge()=0;
80 int getRMAPtransactionID();
81 int getRMAPanswer(int transactionID,char** buffer);
82 virtual bool sendPacket(char* packet,int size)=0;
83 int RMAPtimeout;
84 int linkNumber;
85 int sourceLogicalAddress;
86 int destinationLogicalAddress;
87 int destinationKey;
88 signals:
89 void emitPacket(char* packet,int size);
90 void bytesReceivedFromSpw( unsigned int );
91 void bytesTransmittedToSpw( unsigned int);
92 void ccsdsPacketTransmittedToSpw( void );
93
94 public slots:
95 int getLinkNumber();
96
97 protected:
98 QList<RMAP_Answer*> RMAP_Answers;
99 QList<int> RMAP_pending_transaction_IDs;
100 QMutex *handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
101 QSemaphore* RMAP_AnswersSem;
102 socexplorerplugin* plugin;
103 bool connected;
104 void pushRmapPacket(char* packet,int len);
105
106 };
107
108
109
68 #endif // ABSTRACTSPWBRIDGE_H
110 #endif // ABSTRACTSPWBRIDGE_H
@@ -1,96 +1,92
1 #
1 #
2 # Project created by QtCreator 2011-09-20T08:15:30
2 # Project created by QtCreator 2011-09-20T08:15:30
3 #
3 #
4 #-------------------------------------------------
4 #-------------------------------------------------
5
5
6 CONFIG += socexplorerplugin
6 CONFIG += socexplorerplugin
7 QT += network webkit
7 QT += network webkit
8 greaterThan(QT_MAJOR_VERSION, 4): QT += webkitwidgets
8 greaterThan(QT_MAJOR_VERSION, 4): QT += webkitwidgets
9
9
10 QMAKE_CXXFLAGS += -std=c++11
10 QMAKE_CXXFLAGS += -std=c++11
11 QMAKE_CFLAGS += -std=c++11
11 QMAKE_CFLAGS += -std=c++11
12
12
13 win32:CONFIG += dll
13 win32:CONFIG += dll
14 win32:CONFIG -= static
14 win32:CONFIG -= static
15 VERSION=0.6.1
15 VERSION=0.6.2
16 TARGET = spwplugin
16 TARGET = spwplugin
17 DEFINES += PLUGIN=spwplugin
17 DEFINES += PLUGIN=spwplugin
18 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
18 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
19 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
19 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
20 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org; Paul Leroy paul.leroy@lpp.polytechnique.fr"\\\"\"
20 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org; Paul Leroy paul.leroy@lpp.polytechnique.fr"\\\"\"
21 DEFINES += driver_Description="\"\\\"This plugin allows you to use spacewire's RMAP protocol with Stardundee USB brick v1"\\\"\"
21 DEFINES += driver_Description="\"\\\"This plugin allows you to use spacewire's RMAP protocol with Stardundee USB brick v1"\\\"\"
22 DEFINES += driver_can_be_root=1
22 DEFINES += driver_can_be_root=1
23 DEFINES += driver_can_be_child=0
23 DEFINES += driver_can_be_child=0
24 DEFINES += driver_VID=0
24 DEFINES += driver_VID=0
25 DEFINES += driver_PID=0
25 DEFINES += driver_PID=0
26
26
27 #STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
28
29 #LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
30 # $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
31
27
32 INCLUDEPATH += \
28 INCLUDEPATH += \
33 $${PWD} \
29 $${PWD} \
34 $$STARTDUNDEEPATH/inc \
30 $$STARTDUNDEEPATH/inc \
35 StarDundee \
31 StarDundee \
36 SpwTcpPacketServer \
32 SpwTcpPacketServer \
37 GR-ESB
33 GR-ESB
38
34
39 HEADERS += \
35 HEADERS += \
40 spwplugin.h \
36 spwplugin.h \
41 StarDundee/stardundeespw_usb.h \
37 StarDundee/stardundeespw_usb.h \
42 abstractspwbridge.h \
38 abstractspwbridge.h \
43 spw.h \
39 spw.h \
44 StarDundee/stardundeegui.h \
40 StarDundee/stardundeegui.h \
45 SpwTcpPacketServer/spwtcppacketserver.h \
41 SpwTcpPacketServer/spwtcppacketserver.h \
46 GR-ESB/gr_esb_bridge.h \
42 GR-ESB/gr_esb_bridge.h \
47 GR-ESB/gr_esb_ui.h \
43 GR-ESB/gr_esb_ui.h \
48 SpwTcpPacketServer/incomingpacketparser.h \
44 SpwTcpPacketServer/incomingpacketparser.h \
49 StarDundee/fakestardundeespwusb_lib.h \
45 StarDundee/fakestardundeespwusb_lib.h \
50 StarDundee/fakestardundeespwusbgui.h
46 StarDundee/fakestardundeespwusbgui.h
51
47
52
48
53 SOURCES += \
49 SOURCES += \
54 spwplugin.cpp \
50 spwplugin.cpp \
55 StarDundee/stardundeespw_usb.cpp \
51 StarDundee/stardundeespw_usb.cpp \
56 abstractspwbridge.cpp \
52 abstractspwbridge.cpp \
57 StarDundee/stardundeegui.cpp \
53 StarDundee/stardundeegui.cpp \
58 SpwTcpPacketServer/spwtcppacketserver.cpp \
54 SpwTcpPacketServer/spwtcppacketserver.cpp \
59 GR-ESB/gr_esb_bridge.cpp \
55 GR-ESB/gr_esb_bridge.cpp \
60 GR-ESB/gr_esb_ui.cpp \
56 GR-ESB/gr_esb_ui.cpp \
61 SpwTcpPacketServer/incomingpacketparser.cpp \
57 SpwTcpPacketServer/incomingpacketparser.cpp \
62 StarDundee/fakestardundeespwusb_lib.cpp \
58 StarDundee/fakestardundeespwusb_lib.cpp \
63 StarDundee/fakestardundeespwusbgui.cpp
59 StarDundee/fakestardundeespwusbgui.cpp
64
60
65 FORMS += \
61 FORMS += \
66 StarDundee/stardundeeGUI.ui \
62 StarDundee/stardundeeGUI.ui \
67 SpwTcpPacketServer/spwtcppacketserver.ui \
63 SpwTcpPacketServer/spwtcppacketserver.ui \
68 GR-ESB/gr_esb_ui.ui \
64 GR-ESB/gr_esb_ui.ui \
69 StarDundee/fakestardundeespwusbgui.ui
65 StarDundee/fakestardundeespwusbgui.ui
70
66
71 RESOURCES += \
67 RESOURCES += \
72 spwRessources.qrc
68 spwRessources.qrc
73
69
74
70
75
71
76
72
77
73
78
74
79
75
80
76
81
77
82
78
83
79
84
80
85
81
86
82
87
83
88
84
89
85
90
86
91
87
92
88
93
89
94
90
95
91
96
92
General Comments 0
You need to be logged in to leave comments. Login now