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