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