##// END OF EJS Templates
AHBUART plugin now saves data.
jeandet -
r66:a69da3403983 default
parent child
Show More
@@ -1,549 +1,550
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, 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@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include <socexplorerengine.h>
23 23 #include "ahbuartplugin.h"
24 24 #include <unistd.h>
25 25 #include <errno.h>
26 26 #include <QApplication>
27 27 #include <QProgressBar>
28 28 #include <stdio.h>
29 29 #include <QThread>
30 30 #include <QCompleter>
31 31 #include <QStringList>
32 32 #include <QLineEdit>
33 33 #include <socexplorerproxy.h>
34 #include <socexplorersettings.h>
34 35
35 36 ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false)
36 37 {
37 38 this->port =(rs232port_t)NULL;
38 39 this->portMutex = new QMutex(QMutex::Recursive);
39 40 this->UI = new ahbUartPluginUI();
40 41 this->setWidget((QWidget*)this->UI);
41 42 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
42 43 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
43 // this->pyObject = new ahbuartPywrapper(this);
44 // QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
45 // QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
46 // QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
47 // QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
48 44 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
49 45 QObject::connect(this,SIGNAL(addReadBytes(int)),this->UI,SLOT(addReadBytes(int)));
50 46 QObject::connect(this,SIGNAL(addWritenBytes(int)),this->UI,SLOT(addWritenBytes(int)));
51 47 this->portListcompleter = NULL;
52 this->scanDone = false;
48 // this->scanDone = false;
53 49 updatePortList();
54 50 }
55 51
56 52
57 53 ahbuartplugin::~ahbuartplugin()
58 54 {
59 55 if(this->port!=(rs232port_t)NULL)
60 56 {
61 57 rs232close(this->port);
62 58 this->port = (rs232port_t)NULL;
63 59 }
60 SocExplorerSettings::setValue(this->instance(),"PORT",this->UI->portName(),SocExplorerSettings::Session);
61 SocExplorerSettings::setValue(this->instance(),"SPEED",this->UI->baudRate(),SocExplorerSettings::Session);
64 62 this->UI->close();
65 63 this->UI->~ahbUartPluginUI();
66 64 }
67 65
68 66
69 67 void ahbuartplugin::closeMe()
70 68 {
71 69 if(this->port!=(rs232port_t)NULL)
72 70 {
73 71 rs232close(this->port);
74 72 this->port = (rs232port_t)NULL;
75 73 }
76 74 emit this->closePlugin(this);
77 75 }
78 76
79 77 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
80 78 {
81 79 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
82 80 this->closeAction = this->menu->addAction(tr("Close plugin"));
83 81 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
84 82 return 1;
85 83 }
86 84
87 85
88 86 bool ahbuartplugin::checkConnection()
89 87 {
90 88 QTime timeout;
91 89 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
92 90 char test2[1024];
93 91 int writen =0;
94 92 int read = 0;
95 93 timeout.start();
96 94 SocExplorerEngine::message(this,"Check connection",2);
97 95 QMutexLocker lock(portMutex);
98 96 while(writen!=5)
99 97 {
100 98 writen+=rs232write(this->port,test+writen,5-writen);
101 99 if(timeout.elapsed()>1000)
102 100 {
103 101 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
104 102 return false;
105 103 }
106 104 }
107 105 #ifdef WIN32
108 106 usleep(1000);
109 107 #endif
110 108 timeout.restart();
111 109 int avail = 0;
112 110 do
113 111 {
114 112 avail = rs232availablebytes(this->port);
115 113 if(timeout.elapsed()>1000)
116 114 {
117 115 if(avail)
118 116 rs232read(this->port,test2,avail);
119 117 SocExplorerEngine::message(this,"Connection Error",2);
120 118 return false;
121 119 }
122 120 }while(avail<4);
123 121 read = rs232read(this->port,test2,avail);
124 122 if(read>0)
125 123 {
126 124 SocExplorerEngine::message(this,"Connection Ok",2);
127 125 return true;
128 126 }
129 127 else
130 128 {
131 129 SocExplorerEngine::message(this,"Connection Error",2);
132 130 return false;
133 131 }
134 132 }
135 133
136 134 void ahbuartplugin::connectPort(QString PortName, int baudrate)
137 135 {
138 136 QTime timeout;
139 137 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
140 138 timeout.start();
141 139 QMutexLocker lock(portMutex);
142 140 if(this->port==(rs232port_t)NULL)
143 141 {
144 142 SocExplorerEngine::message(this,"Open port "+PortName,2);
145 143 this->port=rs232open((char*)PortName.toStdString().c_str());
146 144 }
147 145 if(this->port!=badPortValue)
148 146 {
149 147 SocExplorerEngine::message(this,"Port opened "+PortName,2);
150 148 SocExplorerEngine::message(this,"Configure port "+PortName,2);
151 149 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
152 150 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
153 151 char test2[1024];
154 152 SAFEWRITE(test,1,timeout,2000,return);
155 153 SAFEWRITE((test+1),1,timeout,2000,return);
156 154 rs232read(this->port,test2,512);
157 155 int read = 0;
158 156 for(int i=0;i<10;i++)
159 157 {
160 158 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
161 159 SAFEWRITE(test+2,5,timeout,2000,return);
162 160 SocExplorerEngine::message(this,"Read Result",2);
163 161 read=rs232read(this->port,test2+read,16);
164 162 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
165 163 if(read>0)
166 164 {
167 165 SocExplorerEngine::message(this,"Flush port ",2);
168 166 while(rs232read(this->port,test2,1)>0);
169 167 this->Connected = true;
170 168 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
171 169 emit this->activate(true);
172 if(this->scanDone==false)
170 if(!socexplorerproxy::haveChild(this,"AMBA_PLUGIN"))
173 171 {
174 172 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
175 this->scanDone=true;
173 // this->scanDone=true;
176 174 }
177 175 this->UI->setSystemSpeed(this->detectSpeed());
178 176 break;
179 177 }
180 178 }
181 179 }
182 180 else
183 181 {
184 182 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
185 183 this->port = (rs232port_t)NULL;
186 184 this->Connected = false;
187 185 emit this->activateSig(false);
188 186 return;
189 187 }
190 188 if(this->Connected == false)
191 189 {
192 190 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
193 191 rs232close(this->port);
194 192 this->port = (rs232port_t)NULL;
195 193 emit this->activateSig(false);
196 194 }
197 195
198 196 }
199 197
200 198 bool ahbuartplugin::open(QString PortName,int baudrate)
201 199 {
202 200 if(this->port!=(rs232port_t)NULL)
203 201 this->close();
204 202 this->UI->setconfig(PortName,baudrate);
205 203 this->connectPort(PortName,baudrate);
206 204 return (this->port!=(rs232port_t)NULL);
207 205 }
208 206
209 207 void ahbuartplugin::close()
210 208 {
211 209 if(this->port!=(rs232port_t)NULL)
212 210 {
213 211 rs232close(this->port);
214 212 this->port = (rs232port_t)NULL;
215 213 this->Connected = false;
216 214 emit this->activateSig(false);
217 215 }
218 216 }
219 217
220 218 void ahbuartplugin::togglePort(QString PortName,int baudrate)
221 219 {
222 220 if(this->port!=(rs232port_t)NULL)
223 221 {
224 222 this->close();
225 223 }
226 224 else
227 225 {
228 226 this->connectPort(PortName,baudrate);
229 227 }
230 228 }
231 229
232 230
233 231 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
234 232 {
235 233 QTime timeout;
236 234 timeout.start();
237 235 unsigned int read=0;
238 236 unsigned int cnt=count;
239 237 unsigned int nextUpdateTrig=0,updateStep=1024;
240 238 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
241 239 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
242 240 {
243 241 QMutexLocker lock(portMutex);
244 242 if(!this->checkConnection())
245 243 {
246 244 this->Connected = false;
247 245 emit this->activateSig(false);
248 246 this->portMutex->unlock();
249 247 return 0;
250 248 }
251 249 QProgressBar* progress=NULL;
252 250 if(cnt>128)
253 251 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
254 252 char CMD[5];
255 253 char* result = (char*)malloc(count*4);
256 254 while(count>32)
257 255 {
258 256 CMD[0] = 0x80 | (32-1);
259 257 CMD[1] = (char)((address>>24)&0xFF);
260 258 CMD[2] = (char)((address>>16)&0xFF);
261 259 CMD[3] = (char)((address>>8)&0xFF);
262 260 CMD[4] = (char)((address)&0xFF);
263 261 SAFEWRITE(CMD,5,timeout,1000,return 0);
264 262 timeout.restart();
265 263 int avail=0;
266 264 do{
267 265 avail=rs232availablebytes(this->port);
268 266 if(timeout.elapsed()>1000)
269 267 {
270 268 rs232close(this->port);
271 269 this->port = (rs232port_t)NULL;
272 270 this->Connected = false;
273 271 emit this->activateSig(false);
274 272 return 0;
275 273 }
276 274 }while(avail<(32*4));
277 275 rs232read(this->port,result+((cnt-count)*4),32*4);
278 276 count-=32;
279 277 address+=32*4;
280 278 if(cnt>128)
281 279 {
282 280
283 281 if((cnt-count)>=nextUpdateTrig)
284 282 {
285 283 progress->setValue(cnt-count);
286 284 qApp->processEvents();
287 285 nextUpdateTrig+=updateStep;
288 286 }
289 287 }
290 288 }
291 289 if(count>0)
292 290 {
293 291 CMD[0] = 0x80 | (count-1);
294 292 CMD[1] = (char)((address>>24)&0xFF);
295 293 CMD[2] = (char)((address>>16)&0xFF);
296 294 CMD[3] = (char)((address>>8)&0xFF);
297 295 CMD[4] = (char)((address)&0xFF);
298 296 SAFEWRITE(CMD,5,timeout,1000,return 0);
299 297 timeout.restart();
300 int avail=0;
298 unsigned int avail=0;
301 299 do{
302 300 avail=rs232availablebytes(this->port);
303 301 if(timeout.elapsed()>1000)
304 302 {
305 303 rs232close(this->port);
306 304 this->port = (rs232port_t)NULL;
307 305 this->Connected = false;
308 306 emit this->activateSig(false);
309 307 return 0;
310 308 }
311 309 }while(avail<(count*4));
312 310 rs232read(this->port,result+((cnt-count)*4),count*4);
313 311 }
314 312 if(cnt>128)
315 313 {
316 314 progress->setValue(cnt-count);
317 315 qApp->processEvents();
318 316 }
319 317 for(int i=0;(unsigned int)i<cnt;i++)
320 318 {
321 319 #if __BYTE_ORDER == __LITTLE_ENDIAN
322 320 // for(int j =0;j<4;j++)
323 321 // {
324 322 // Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
325 323 // }
326 324 Value[i]= socexplorerBswap32(((uint32_t*)result)[i]);
327 325 #elif __BYTE_ORDER == __BIG_ENDIAN
328 326 Value[i]= ((uint32_t*)result)[i];
329 327 #endif
330 328 }
331 329 read = cnt*4;
332 330 if(cnt>128)
333 331 SocExplorerEngine::deleteProgressBar(progress);
334 332 free(result);
335 333 }
336 334 emit this->addReadBytes(read);
337 335 return read/4;
338 336 }
339 337
340 338 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
341 339 {
342 340 QTime timeout;
343 341 timeout.start();
344 342 unsigned int writen=0;
345 343 unsigned int nextUpdateTrig=0,updateStep=1024;
346 344 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
347 345 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
348 346 {
349 347 QMutexLocker lock(portMutex);
350 348 if(!this->checkConnection())
351 349 {
352 350 emit this->activateSig(false);
353 351 this->Connected = false;
354 352 this->portMutex->unlock();
355 353 return 0;
356 354 }
357 355 QProgressBar* progress = NULL;
358 356 if(count>128)
359 357 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
360 int offset = 0;
358 unsigned int offset = 0;
361 359 char* CMD= (char*)malloc((32*4)+5);
362 360 writen=0;
363 361 while(count>32)
364 362 {
365 363 CMD[0] = 0xC0 | (32-1);
366 364 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
367 365 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
368 366 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
369 367 CMD[4] = (char)(((unsigned int)address)&0xFF);
370 368 for(int i=0;i<32;i++)
371 369 {
372 370 #if __BYTE_ORDER == __LITTLE_ENDIAN
373 371 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
374 372 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
375 373 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
376 374 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
377 375 #elif __BYTE_ORDER == __BIG_ENDIAN
378 376 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset])&0xFF);
379 377 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
380 378 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
381 379 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
382 380 #endif
383 381 }
384 382 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
385 383 writen+=32;
386 384 count-=32;
387 385 offset+=32;
388 386 address+=32*4;
389 387 if(offset>=nextUpdateTrig && progress!=NULL)
390 388 {
391 389 progress->setValue(offset);
392 390 qApp->processEvents();
393 391 nextUpdateTrig +=updateStep;
394 392 }
395 393
396 394 }
397 395 if(count>0)
398 396 {
399 397 CMD[0] = 0xC0 | (count-1);
400 398 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
401 399 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
402 400 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
403 401 CMD[4] = (char)(((unsigned int)address)&0xFF);
404 402 for(int i=0;(unsigned int) i<(count);i++)
405 403 {
406 404 #if __BYTE_ORDER == __LITTLE_ENDIAN
407 405 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
408 406 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
409 407 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
410 408 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
411 409 #elif __BYTE_ORDER == __BIG_ENDIAN
412 410 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset])&0xFF);
413 411 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
414 412 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
415 413 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
416 414 #endif
417 415 }
418 416 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
419 417 writen+=count;
420 418 }
421 419 if(progress!=NULL)
422 420 {
423 421 progress->setValue(writen);
424 422 qApp->processEvents();
425 423 SocExplorerEngine::deleteProgressBar(progress);
426 424 }
427 425 free(CMD);
428 426 emit this->addWritenBytes(writen*4);
429 427 return writen;
430 428 }
431 429 return 0;
432 430 }
433 431
434 432
435 433
436 434
437 435 void ahbuartplugin::updatePortList()
438 436 {
439 437 if(this->portListcompleter==(QCompleter*)NULL)
440 438 {
441 439 this->portListcompleter=new QCompleter(this);
442 440 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
443 441 this->portListcompleterModel = new QStringListModel(this);
444 442 this->portListcompleter->setModel(this->portListcompleterModel);
445 443 this->UI->setCompleter(this->portListcompleter);
446 444 }
447 445 rs232portslist_t* portlist = rs232getportlist();
448 446 rs232portslist_t* portlistenum = portlist;
449 447 QStringList wordList;
450 448 while(portlistenum!=NULL)
451 449 {
452 450 wordList << portlistenum->name;
453 451 portlistenum = portlistenum->next;
454 452 }
455 453 rs232deleteportlist(portlist);
456 454 this->portListcompleterModel->setStringList(wordList);
457 455 }
458 456
459 457 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
460 458 {
461 459 unsigned int data[(count/4)+1];
462 460 QVariantList result;
463 461 this->Read(data,(count/4)+1,address);
464 462 for(unsigned int i = 0;i<count/4;i++)
465 463 {
466 464 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
467 465 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
468 466 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
469 467 result.append(QVariant((int)(0x0FF&(data[i]))));
470 468 }
471 469
472 for(int i=0;i<(count%4);i++)
470 for(unsigned int i=0;i<(count%4);i++)
473 471 {
474 472 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
475 473 }
476 474
477 475 return result;
478 476 }
479 477
480 478 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
481 479 {
482 480 unsigned int data[dataList.count()/4];
483 481 for(int i = 0;i<(dataList.count()/4);i++)
484 482 {
485 483 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
486 484 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
487 485 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
488 486 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
489 487 }
490 488 this->Write(data,dataList.count()/4,address);
491 489 }
492 490
493 491 int ahbuartplugin::detectSpeed()
494 492 {
495 493 //scaler = (((system_clk*10)/(baudrate*8))-5)/10
496 494 unsigned int ahbUartBaseAddress = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01,0x007,0);
497 495 // unsigned int dsuBaseAddress = SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,0x01,0x0017,0);
498 496 unsigned int dsuBaseAddress = 0x90000000;
499 497 unsigned int scaler = 0,dsuVal1=0,dsuVal2=0;
500 498 int speed=0;
501 499 QElapsedTimer time;
502 if(dsuBaseAddress!=-1)
500 if((int)dsuBaseAddress!=-1)
503 501 {
504 502 time.start();
505 503 if( this->Read(&dsuVal1,1,dsuBaseAddress+0x08)==1)
506 504 {
507 505 usleep(1000*1000);
508 506 qint64 el = time.elapsed();
509 507 this->Read(&dsuVal2,1,dsuBaseAddress+0x08);
510 508 if(dsuVal1!=dsuVal2)
511 509 return ((dsuVal2-dsuVal1)/el)*1000;
512 510 }
513 511 }
514 if(ahbUartBaseAddress!=-1)
512 if((int)ahbUartBaseAddress!=-1)
515 513 {
516 514 if( this->Read(&scaler,1,ahbUartBaseAddress+0x0C)==1)
517 515 {
518 516 scaler&=0x3FFFF;
519 517 speed = (int)(((double)scaler*10.0)+5.0)*((double)this->UI->baudRate()/10.0)*8.0;
520 518 // speed = (int)((double)(scaler+1)*8.0*(double)this->UI->baudRate());
521 519 }
522 520 }
523 521 return speed;
524 522 }
525 523
526 524 void ahbuartplugin::postInstantiationTrigger()
527 525 {
528 if(this->scanDone && this->Connected)
526 if(this->Connected)
529 527 {
530 528 this->UI->setSystemSpeed(this->detectSpeed());
531 529 }
530 QString portName = SocExplorerSettings::value(this->instance(),"PORT",this->UI->portName(),SocExplorerSettings::Session).toString();
531 int baudRate = SocExplorerSettings::value(this->instance(),"SPEED",this->UI->baudRate(),SocExplorerSettings::Session).toInt();
532 this->UI->setconfig(portName,baudRate);
532 533 }
533 534
534 535
535 536
536 537
537 538
538 539
539 540
540 541
541 542
542 543
543 544
544 545
545 546
546 547
547 548
548 549
549 550
@@ -1,101 +1,101
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, 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@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBUARTPLUGIN_H
23 23 #define AHBUARTPLUGIN_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include <QMutex>
29 29 #include <QProgressDialog>
30 30 #include <QStringListModel>
31 31 #include <QTime>
32 32 #include <socexplorerplugin.h>
33 33 #include "ahbuartpluginui.h"
34 34 #include <RS232.h>
35 35 #include <unistd.h>
36 36
37 37
38 38 #define SAFEWRITE(data,count,timer,timeout,error) \
39 39 while(1)\
40 40 {\
41 41 unsigned int __writen__=0; \
42 42 (timer).restart(); \
43 43 while(__writen__!=(count)) \
44 44 {\
45 45 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
46 46 if((timer).elapsed()>(timeout)) \
47 47 {\
48 48 this->port = (rs232port_t)NULL; \
49 49 this->Connected = false; \
50 50 emit this->activateSig(false); \
51 51 error; \
52 52 } \
53 53 } \
54 54 break;\
55 55 }
56 56
57 57
58 58
59 59
60 60
61 61 class ahbuartplugin : public socexplorerplugin
62 62 {
63 63 Q_OBJECT
64 64 public:
65 65 ahbuartplugin(QWidget *parent = 0);
66 66 ~ahbuartplugin();
67 67 int registermenu(QMainWindow *menuHolder);
68 68 int VID(){return driver_VID;}
69 69 int PID(){return driver_PID;}
70 70
71 71 public slots:
72 72 void togglePort(QString PortName,int baudrate);
73 73 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
74 74 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
75 75 void closeMe();
76 76 void close();
77 77 bool open(QString PortName,int baudrate);
78 78 void updatePortList();
79 79 QVariantList ReadBytes(unsigned int address,unsigned int count);
80 80 void WriteBytes(unsigned int address,QList<QVariant> dataList);
81 81 int detectSpeed();
82 82 void postInstantiationTrigger();
83 83 signals:
84 84 void setProgressValue(int progress);
85 85 void addWritenBytes(int count);
86 86 void addReadBytes(int count);
87 87 private:
88 bool scanDone;
88 // bool scanDone;
89 89 QProgressDialog* progress;
90 90 QLayout * mainLayout;
91 91 ahbUartPluginUI* UI;
92 92 QMutex* portMutex;
93 93 rs232port_t port;
94 94 QCompleter *portListcompleter;
95 95 QStringListModel *portListcompleterModel;
96 96 void connectPort(QString PortName,int baudrate);
97 97 bool checkConnection();
98 98
99 99 };
100 100
101 101 #endif // AHBUARTPLUGIN_H
@@ -1,121 +1,127
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, 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@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "ahbuartpluginui.h"
23 23 #include "ui_ahbuartpluginui.h"
24 24
25 25 ahbUartPluginUI::ahbUartPluginUI(QWidget *parent) :
26 26 QWidget(parent),
27 27 ui(new Ui::ahbUartPluginUI)
28 28 {
29 29 ui->setupUi(this);
30 30 connect(ui->OpenPort,SIGNAL(clicked()),this,SLOT(connectPort()));
31 31 // connect(ui->PortspeedSlider,SIGNAL(valueChanged(int)),ui->baurateLCD,SLOT(display(int)));
32 32 connect(ui->rescanPorts,SIGNAL(clicked()),this,SIGNAL(rescanPorts()));
33 33 QStringList allowedSpeeds;
34 34 allowedSpeeds<<"0"<<"50"<<"75"<<"110"<<"134"<<"150"<<
35 35 "200"<<"300"<<"600"<<"1200"<<"1800"<<"2400"<<
36 36 "4800"<<"9600"<<"19200"<<"38400"<<"57600"<<
37 37 "115200"<<"230400"<<"460800"<<"500000"<<"576000"<<
38 38 "921600"<<"1000000"<<"1152000"<<"1500000"<<"2000000"<<
39 39 "2500000"<<"3000000"<<"3500000"<<"4000000";
40 40
41 41 portSpeedCompleter = new QCompleter(allowedSpeeds);
42 42 this->ui->portSpeed->setCompleter(portSpeedCompleter);
43 43 this->writtenBytes = 0;
44 44 this->readBytes = 0;
45 45 }
46 46
47 47 void ahbUartPluginUI::connectPort()
48 48 {
49 49 int baudrate = ui->portSpeed->text().toInt();
50 50 emit this->connectPortsig(ui->PortName->text(),baudrate);
51 51 }
52 52
53 53 void ahbUartPluginUI::setConnected(bool connected)
54 54 {
55 55 if(connected == true)
56 56 {
57 57 ui->OpenPort->setText(tr("Close port"));
58 58 }
59 59 else
60 60 ui->OpenPort->setText(tr("Open port"));
61 61 }
62 62
63 63
64 64 ahbUartPluginUI::~ahbUartPluginUI()
65 65 {
66 66 delete ui;
67 67 }
68 68
69 69
70 70 void ahbUartPluginUI::setconfig(QString PortName, int baudrate)
71 71 {
72 72 this->ui->PortName->setText(PortName);
73 73 this->ui->portSpeed->setText(QString::number(baudrate));
74 74 }
75 75
76 76 void ahbUartPluginUI::addWritenBytes(int count)
77 77 {
78 78 this->writtenBytes+=count;
79 79 this->ui->WrBytesLCD->display(this->writtenBytes);
80 80 }
81 81
82 82 void ahbUartPluginUI::addReadBytes(int count)
83 83 {
84 84 this->readBytes+=count;
85 85 this->ui->RdBytesLCD->display(this->readBytes);
86 86 }
87 87
88 88 void ahbUartPluginUI::setSystemSpeed(int speed)
89 89 {
90 90 QStringList frLst = QStringList()<<"Hz"<<"kHz"<<"MHz"<<"GHz";
91 91 int ind=0;
92 92 double speedD = speed;
93 93 while(speedD>1000.0)
94 94 {
95 95 speedD/=1000.0;
96 96 ind++;
97 97 }
98 98 this->ui->detectedSpeedLbl->setText(QString::number(speedD)+frLst[ind]);
99 99 }
100 100
101 101
102 102 void ahbUartPluginUI::setCompleter(QCompleter *completer)
103 103 {
104 104 this->ui->PortName->setCompleter(completer);
105 105 }
106 106
107 107 int ahbUartPluginUI::baudRate()
108 108 {
109 109 return ui->portSpeed->text().toInt();
110 110 }
111 111
112 QString ahbUartPluginUI::portName()
113 {
114 return this->ui->PortName->text();
115 }
116
117
112 118 void ahbUartPluginUI::closeEvent(QCloseEvent *event)
113 119 {
114 120 event->accept();
115 121 }
116 122
117 123
118 124
119 125
120 126
121 127
@@ -1,71 +1,72
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, 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@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef AHBUARTPLUGINUI_H
23 23 #define AHBUARTPLUGINUI_H
24 24
25 25 #include <QWidget>
26 26 #include <QFile>
27 27 #include <QTextStream>
28 28 #include <QFileDialog>
29 29 #include <QDir>
30 30 #include <QCloseEvent>
31 31 #include <QCompleter>
32 32
33 33 namespace Ui {
34 34 class ahbUartPluginUI;
35 35 }
36 36
37 37 class ahbUartPluginUI : public QWidget
38 38 {
39 39 Q_OBJECT
40 40
41 41 public:
42 42 explicit ahbUartPluginUI(QWidget *parent = 0);
43 43 ~ahbUartPluginUI();
44 44 void closeEvent(QCloseEvent *event);
45 45 void setCompleter(QCompleter* completer);
46 46 int baudRate();
47 QString portName();
47 48 public slots:
48 49 void setConnected(bool connected);
49 50 void connectPort();
50 51 void setconfig(QString PortName,int baudrate);
51 52 void addWritenBytes(int count);
52 53 void addReadBytes(int count);
53 54 void setSystemSpeed(int speed);
54 55
55 56 signals:
56 57 void connectPortsig(QString PortName,int baudrate);
57 58 void setLogFileName(QString FileName);
58 59 void rescanPorts();
59 60 private:
60 61 int writtenBytes;
61 62 int readBytes;
62 63 Ui::ahbUartPluginUI *ui;
63 64 QCompleter* portSpeedCompleter;
64 65 };
65 66
66 67 #endif // AHBUARTPLUGINUI_H
67 68
68 69
69 70
70 71
71 72
General Comments 0
You need to be logged in to leave comments. Login now