##// END OF EJS Templates
An other Win32 dirty fix tentative.
Jeandet Alexis -
r5:15c638a85130 default
parent child
Show More
@@ -1,188 +1,199
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - 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 2 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 #include "APBUARTPLUGIN.h"
23 23 #include <socexplorerengine.h>
24 24
25 25
26 26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
27 27 {
28 28 this->UI = new ApbUartPluginUi();
29 29 this->setWindowTitle(tr("APBUART"));
30 30 this->setWidget((QWidget*)this->UI);
31 31 this->useLoopBack = false;
32 32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
33 33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
34 34 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
35 35 }
36 36
37 37
38 38 ApbUartPlugin::~ApbUartPlugin()
39 39 {
40 40
41 41 }
42 42
43 43 void ApbUartPlugin::closeMe()
44 44 {
45 45 emit this->closePlugin(this);
46 46 }
47 47
48 48 void ApbUartPlugin::postInstantiationTrigger()
49 49 {
50 50 if(this->isEnabled())
51 51 {
52 52 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
53 53 loopbackChangeState(Qt::Checked);
54 54 }
55 55 }
56 56
57 57 void ApbUartPlugin::loopbackChangeState(int state)
58 58 {
59 59 if(state==Qt::Checked)
60 60 {
61 61 enableLoopback();
62 62 }
63 63 else
64 64 {
65 65 disableLoopback();
66 66 }
67 67 }
68 68
69 69 void ApbUartPlugin::uartReadout()
70 70 {
71 #ifdef WIN32
72 int readcnt=0;
73 #endif
71 74 if(this->isEnabled() && parent!=NULL)
72 75 {
73 76 if(this->useLoopBack)
74 77 {
75 78 if(this->baseAddress()!=-1)
76 79 {
77 80 this->loopBackTimer.stop();
78 81 unsigned int status_reg,data;
79 82 char ch;
80 83 QString printdata="";
81 84 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
82 85 while ((status_reg&4)==0) {
83 86 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
84 87 ch = (char)(0xff & data);
85 88 printdata+=ch;
89 #ifdef WIN32
90 readcnt++;
91 if(readcnt>=32)
92 {
93 qApp->processEvents();
94 break;
95 }
96 #endif
86 97 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
87 98 }
88 99 if(printdata!="")
89 100 emit apbUartTextReceived(printdata);
90 this->loopBackTimer.start();
101 this->loopBackTimer.start(200);
91 102 }
92 103 else
93 104 {
94 105 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
95 106 this->enableLoopback();
96 107 }
97 108 }
98 109 }
99 110 }
100 111
101 112 void ApbUartPlugin::activate(bool flag)
102 113 {
103 114 this->setEnabled(flag);
104 115 emit this->activateSig(flag);
105 116 if(this->isEnabled())
106 117 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
107 118
108 119 loopbackChangeState(Qt::Checked);
109 120 }
110 121 }
111 122
112 123 void ApbUartPlugin::activateScan(bool flag)
113 124 {
114 125 if(flag)
115 126 this->loopBackTimer.start(200);
116 127 else
117 128 this->loopBackTimer.stop();
118 129 }
119 130
120 131 int ApbUartPlugin::enableLoopback()
121 132 {
122 133
123 134 this->useLoopBack = true;
124 135 this->loopBackTimer.start(200);
125 136 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
126 137 if(parent==NULL)
127 138 {
128 139 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
129 140 return -1;
130 141 }
131 142 if(this->baseAddress()==-1)
132 143 {
133 144 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
134 145 if(this->baseAddress()==-1)
135 146 return -1;
136 147 }
137 148 unsigned int ctrl_reg= 0x843;
138 149 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
139 150 return 0;
140 151 }
141 152
142 153 int ApbUartPlugin::disableLoopback()
143 154 {
144 155 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
145 156 if(parent==NULL)
146 157 {
147 158 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
148 159 return -1;
149 160 }
150 161 if(this->baseAddress()==-1)
151 162 {
152 163 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
153 164 if(this->baseAddress()==-1)
154 165 return -1;
155 166 }
156 167 unsigned int ctrl_reg;
157 168 this->loopBackTimer.stop();
158 169 /* Firts get Control reg value*/
159 170 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
160 171 ctrl_reg = ctrl_reg & (~(1<<11));
161 172 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
162 173 this->useLoopBack = false;
163 174 return 0;
164 175 }
165 176
166 177
167 178 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
168 179 {
169 180 if(parent!=NULL)
170 181 return parent->Read(Value,count,address);
171 182 return 0;
172 183 }
173 184
174 185
175 186 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
176 187 {
177 188 if(parent!=NULL)
178 189 return parent->Write(Value,count,address);
179 190 return 0;
180 191 }
181 192
182 193
183 194
184 195
185 196
186 197
187 198
188 199
@@ -1,459 +1,468
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 "ahbuartpywrapper.h"
31 31 #include <QCompleter>
32 32 #include <QStringList>
33 33 #include <QLineEdit>
34 34 #include <socexplorerproxy.h>
35 35
36 36 ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false)
37 37 {
38 38 this->port =(rs232port_t)NULL;
39 39 this->portMutex = new QMutex(QMutex::Recursive);
40 40 this->UI = new ahbUartPluginUI();
41 41 this->setWidget((QWidget*)this->UI);
42 42 this->setWindowTitle(tr("AHB UART"));
43 43 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
44 44 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
45 45 this->pyObject = new ahbuartPywrapper(this);
46 46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
47 47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
48 48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
49 49 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
50 50 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
51 51 this->portListcompleter = NULL;
52 52 this->scanDone = false;
53 53 updatePortList();
54 54 }
55 55
56 56
57 57 ahbuartplugin::~ahbuartplugin()
58 58 {
59 59 if(this->port!=(rs232port_t)NULL)
60 60 {
61 61 rs232close(this->port);
62 62 this->port = (rs232port_t)NULL;
63 63 }
64 64 this->UI->close();
65 65 this->UI->~ahbUartPluginUI();
66 66 }
67 67
68 68
69 69 void ahbuartplugin::closeMe()
70 70 {
71 71 if(this->port!=(rs232port_t)NULL)
72 72 {
73 73 rs232close(this->port);
74 74 this->port = (rs232port_t)NULL;
75 75 }
76 76 emit this->closePlugin(this);
77 77 }
78 78
79 79 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
80 80 {
81 81 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
82 82 this->closeAction = this->menu->addAction(tr("Close plugin"));
83 83 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
84 84 return 1;
85 85 }
86 86
87 87
88 88
89 89
90 90 bool ahbuartplugin::checkConnection()
91 91 {
92 92 QTime timeout;
93 93 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
94 94 char test2[1024];
95 95 int writen =0;
96 96 int read = 0;
97 97 timeout.start();
98 98 SocExplorerEngine::message(this,"Check connection",2);
99 99 while(writen!=5)
100 100 {
101 101 writen+=rs232write(this->port,test+writen,5-writen);
102 102 if(timeout.elapsed()>1000)
103 103 {
104 104 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
105 105 return false;
106 106 }
107 107 }
108 #ifdef WIN32
109 usleep(1000);
110 #endif
108 111 timeout.restart();
109 112 while(read!=4)
110 113 {
111 114 read += rs232read(this->port,test2,4-read);
112 115 if(timeout.elapsed()>1000) break;
113 116 }
114 117 if(read>0)
115 118 {
116 119 SocExplorerEngine::message(this,"Connection Ok",2);
117 120 return true;
118 121 }
119 122 else
120 123 {
121 124 SocExplorerEngine::message(this,"Connection Error",2);
122 125 return false;
123 126 }
124 127
125 128 }
126 129
127 130 void ahbuartplugin::connectPort(QString PortName, int baudrate)
128 131 {
129 132 QTime timeout;
130 133 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
131 134 timeout.start();
132 135 if(this->port==(rs232port_t)NULL)
133 136 {
134 137 SocExplorerEngine::message(this,"Open port "+PortName,2);
135 138 this->port=rs232open((char*)PortName.toStdString().c_str());
136 139 }
137 140 if(this->port!=badPortValue)
138 141 {
139 142 SocExplorerEngine::message(this,"Port opened "+PortName,2);
140 143 SocExplorerEngine::message(this,"Configure port "+PortName,2);
141 144 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
142 145 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
143 146 char test2[1024];
144 147 SAFEWRITE(test,1,timeout,2000,return);
145 148 SAFEWRITE((test+1),1,timeout,2000,return);
146 149 APPENDTOLOG(QString("Flush port "));
147 150 rs232read(this->port,test2,512);
148 151 int read = 0;
149 152 for(int i=0;i<10;i++)
150 153 {
151 154 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
152 155 SAFEWRITE(test+2,5,timeout,2000,return);
153 156 SocExplorerEngine::message(this,"Read Result",2);
154 157 read=rs232read(this->port,test2+read,16);
155 158 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
156 159 if(read>0)
157 160 {
158 161 SocExplorerEngine::message(this,"Flush port ",2);
159 162 while(rs232read(this->port,test2,1)>0);
160 163 this->Connected = true;
161 164 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
162 165 emit this->activate(true);
163 166 if(this->scanDone==false)
164 167 {
165 168 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
166 169 this->scanDone=true;
167 170 }
168 171 break;
169 172 }
170 173 }
171 174 }
172 175 else
173 176 {
174 177 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
175 178 this->port = (rs232port_t)NULL;
176 179 this->Connected = false;
177 180 emit this->activateSig(false);
178 181 return;
179 182 }
180 183 if(this->Connected == false)
181 184 {
182 185 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
183 186 rs232close(this->port);
184 187 this->port = (rs232port_t)NULL;
185 188 emit this->activateSig(false);
186 189 }
187 190
188 191 }
189 192
190 193 bool ahbuartplugin::open(QString PortName,int baudrate)
191 194 {
192 195 if(this->port!=(rs232port_t)NULL)
193 196 this->close();
194 197 this->UI->setconfig(PortName,baudrate);
195 198 this->connectPort(PortName,baudrate);
196 199 return (this->port!=(rs232port_t)NULL);
197 200 }
198 201
199 202 void ahbuartplugin::close()
200 203 {
201 204 if(this->port!=(rs232port_t)NULL)
202 205 {
203 206 rs232close(this->port);
204 207 this->port = (rs232port_t)NULL;
205 208 this->Connected = false;
206 209 emit this->activateSig(false);
207 210 }
208 211 }
209 212
210 213 void ahbuartplugin::togglePort(QString PortName,int baudrate)
211 214 {
212 215 if(this->port!=(rs232port_t)NULL)
213 216 {
214 217 this->close();
215 218 }
216 219 else
217 220 {
218 221 this->connectPort(PortName,baudrate);
219 222 }
220 223 }
221 224
222 225
223 226 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
224 227 {
225 228 QTime timeout;
226 229 timeout.start();
227 230 unsigned int read=0;
228 231 unsigned int cnt=count;
229 232 unsigned int nextUpdateTrig=0,updateStep=512;
230 233 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
231 234 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
232 235 {
233 236 if(!this->portMutex->tryLock())
234 237 return 0;
235 238 if(!this->checkConnection())
236 239 {
237 240 this->Connected = false;
238 241 emit this->activateSig(false);
239 242 this->portMutex->unlock();
240 243 return 0;
241 244 }
242 245 QProgressBar* progress=NULL;
243 246 if(cnt>128)
244 247 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
245 248 char CMD[5];
246 249 char* result = (char*)malloc(count*4);
247 250 while(count>32)
248 251 {
249 252 CMD[0] = 0x80 | (32-1);
250 253 CMD[1] = (char)((address>>24)&0xFF);
251 254 CMD[2] = (char)((address>>16)&0xFF);
252 255 CMD[3] = (char)((address>>8)&0xFF);
253 256 CMD[4] = (char)((address)&0xFF);
254 257 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
255 258 SAFEWRITE(CMD,5,timeout,1000,return 0);
259 #ifdef WIN32
260 usleep(1000);
261 #endif
256 262 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
257 263 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
258 264 count-=32;
259 265 address+=32*4;
260 266 if(cnt>128)
261 267 {
262 268
263 269 if((cnt-count)>=nextUpdateTrig)
264 270 {
265 271 progress->setValue(cnt-count);
266 272 qApp->processEvents();
267 273 nextUpdateTrig+=updateStep;
268 274 }
269 275 }
270 276 }
271 277 if(count>0)
272 278 {
273 279 CMD[0] = 0x80 | (count-1);
274 280 CMD[1] = (char)((address>>24)&0xFF);
275 281 CMD[2] = (char)((address>>16)&0xFF);
276 282 CMD[3] = (char)((address>>8)&0xFF);
277 283 CMD[4] = (char)((address)&0xFF);
278 284 SAFEWRITE(CMD,5,timeout,1000,return 0);
285 #ifdef WIN32
286 usleep(1000);
287 #endif
279 288 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
280 289 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
281 290 }
282 291 if(cnt>128)
283 292 {
284 293 progress->setValue(cnt-count);
285 294 qApp->processEvents();
286 295 }
287 296 for(int i=0;(unsigned int)i<cnt;i++)
288 297 {
289 298 for(int j =0;j<4;j++)
290 299 {
291 300 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
292 301 }
293 302 read = cnt*4;
294 303
295 304 }
296 305 if(cnt>128)
297 306 SocExplorerEngine::deleteProgressBar(progress);
298 307 free(result);
299 308 this->portMutex->unlock();
300 309 }
301 310 return read/4;
302 311 }
303 312
304 313 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
305 314 {
306 315 QTime timeout;
307 316 timeout.start();
308 317 unsigned int writen=0;
309 318 unsigned int nextUpdateTrig=0,updateStep=512;
310 319 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
311 320 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
312 321 {
313 322 if(!this->portMutex->tryLock())
314 323 return 0;
315 324 if(!this->checkConnection())
316 325 {
317 326 emit this->activateSig(false);
318 327 this->Connected = false;
319 328 this->portMutex->unlock();
320 329 return 0;
321 330 }
322 331 QProgressBar* progress = NULL;
323 332 if(count>128)
324 333 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
325 334 int offset = 0;
326 335 char* CMD= (char*)malloc((32*4)+5);
327 336 while(count>32)
328 337 {
329 338 writen=0;
330 339 CMD[0] = 0xC0 | (32-1);
331 340 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
332 341 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
333 342 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
334 343 CMD[4] = (char)(((unsigned int)address)&0xFF);
335 344 for(int i=0;i<32;i++)
336 345 {
337 346 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
338 347 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
339 348 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
340 349 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
341 350 }
342 351 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
343 352 writen+=32;
344 353 count-=32;
345 354 offset+=32;
346 355 address+=32*4;
347 356 if(offset>=nextUpdateTrig && progress!=NULL)
348 357 {
349 358 progress->setValue(offset);
350 359 qApp->processEvents();
351 360 nextUpdateTrig +=updateStep;
352 361 }
353 362
354 363 }
355 364 if(count>0)
356 365 {
357 366 CMD[0] = 0xC0 | (count-1);
358 367 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
359 368 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
360 369 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
361 370 CMD[4] = (char)(((unsigned int)address)&0xFF);
362 371 for(int i=0;(unsigned int) i<(count);i++)
363 372 {
364 373 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
365 374 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
366 375 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
367 376 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
368 377 }
369 378 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
370 379 writen+=count;
371 380 }
372 381 if(progress!=NULL)
373 382 {
374 383 progress->setValue(writen);
375 384 qApp->processEvents();
376 385 SocExplorerEngine::deleteProgressBar(progress);
377 386 }
378 387 free(CMD);
379 388 this->portMutex->unlock();
380 389 return writen;
381 390 }
382 391 return 0;
383 392 }
384 393
385 394
386 395
387 396
388 397 void ahbuartplugin::updatePortList()
389 398 {
390 399 if(this->portListcompleter==(QCompleter*)NULL)
391 400 {
392 401 this->portListcompleter=new QCompleter(this);
393 402 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
394 403 this->portListcompleterModel = new QStringListModel(this);
395 404 this->portListcompleter->setModel(this->portListcompleterModel);
396 405 this->UI->setCompleter(this->portListcompleter);
397 406 }
398 407 rs232portslist_t* portlist = rs232getportlist();
399 408 rs232portslist_t* portlistenum = portlist;
400 409 QStringList wordList;
401 410 while(portlistenum!=NULL)
402 411 {
403 412 wordList << portlistenum->name;
404 413 portlistenum = portlistenum->next;
405 414 }
406 415 rs232deleteportlist(portlist);
407 416 this->portListcompleterModel->setStringList(wordList);
408 417 }
409 418
410 419 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
411 420 {
412 421 unsigned int data[(count/4)+1];
413 422 QVariantList result;
414 423 this->Read(data,(count/4)+1,address);
415 424 for(unsigned int i = 0;i<count/4;i++)
416 425 {
417 426 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
418 427 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
419 428 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
420 429 result.append(QVariant((int)(0x0FF&(data[i]))));
421 430 }
422 431
423 432 for(int i=0;i<(count%4);i++)
424 433 {
425 434 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
426 435 }
427 436
428 437 return result;
429 438 }
430 439
431 440 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
432 441 {
433 442 unsigned int data[dataList.count()/4];
434 443 for(int i = 0;i<(dataList.count()/4);i++)
435 444 {
436 445 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
437 446 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
438 447 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
439 448 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
440 449 }
441 450 this->Write(data,dataList.count()/4,address);
442 451 }
443 452
444 453
445 454
446 455
447 456
448 457
449 458
450 459
451 460
452 461
453 462
454 463
455 464
456 465
457 466
458 467
459 468
General Comments 0
You need to be logged in to leave comments. Login now