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