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