##// END OF EJS Templates
Removed crash on spwplugin while closing the manager thread didn't quit correctly.
Alexis Jeandet -
r82:f085b545eb20 socexplorer-plugins-0.7-2 default draft
parent child
Show More
@@ -1,109 +1,115
1 %global upstream_name socexplorer-plugins-0.7-0
1 %global upstream_name socexplorer-plugins-0.7-2
2 2
3 3 Name: socexplorer-plugins
4 4 Version: 0.7
5 Release: 0%{?dist}
5 Release: 2%{?dist}
6 6 Summary: Base plugins for SocExplorer.
7 7 Group: Development/Tools
8 8 License: GPLv2
9 9 URL: https://hephaistos.lpp.polytechnique.fr/redmine/projects/socexplorer
10 10 Source0: https://hephaistos.lpp.polytechnique.fr/redmine/attachments/download/381/%{upstream_name}.zip
11 11
12 12 BuildRequires: python2-devel
13 13 BuildRequires: qt5-qtbase-devel
14 14 BuildRequires: qt5-qtwebkit-devel
15 15 BuildRequires: qt5-qttools-static
16 16 BuildRequires: qt5-qttools-devel
17 17 BuildRequires: qt5-qtsvg-devel
18 18 BuildRequires: qt5-qtxmlpatterns-devel
19 19 BuildRequires: elfutils-libelf-devel
20 20 BuildRequires: qt5-pythonqt-devel
21 21 BuildRequires: socexplorer-devel = 0.7
22 22
23 23 Requires: socexplorer = 0.7
24 24 Requires: qt5-pythonqt
25 25 Requires: python2
26 26 Requires: qt5-qtwebkit
27 27 Requires: qt5-qttools
28 28 Requires: qt5-qtsvg
29 29 Requires: qt5-qtxmlpatterns
30 30 Requires: elfutils-libelf
31 31
32 32 %description
33 33 SocExplorer is an open source generic System On Chip testing software/framework. This package contains the base plugins for SocExplorer such as AHBUARTplugin for connecting to any grlib based design with an AHBUART.
34 34 You will get:
35 35 - AHB UART plugin
36 36 - APB UART plugin
37 37 - AMBA plugin
38 38 - DSU3 plugin
39 39 - Generic rw plugin
40 40 - Memcheck & Memectr plugins
41 41
42 42 %prep
43 43 %setup -q -n %{upstream_name}
44 44
45 45 %build
46 46 %{_qt5_qmake}
47 47
48 48 make %{?_smp_mflags}
49 49
50 50 %install
51 51 make install INSTALL_ROOT=%{buildroot}
52 52
53 53 %post -p /sbin/ldconfig
54 54
55 55 %postun -p /sbin/ldconfig
56 56
57 57 %files
58 58 %{_qt5_libdir}/SocExplorer/plugins/libApbUartPlugin.so*
59 59 %{_qt5_libdir}/SocExplorer/plugins/libahbuartplugin.so*
60 60 %{_qt5_libdir}/SocExplorer/plugins/libambaplugin.so*
61 61 %{_qt5_libdir}/SocExplorer/plugins/libdsu3plugin.so*
62 62 %{_qt5_libdir}/SocExplorer/plugins/libgenericrwplugin.so*
63 63 %{_qt5_libdir}/SocExplorer/plugins/libmemcheckplugin.so*
64 64 %{_qt5_libdir}/SocExplorer/plugins/libmemctrlrplugin.so*
65 65 %{_qt5_libdir}/SocExplorer/plugins/libspwplugin.so*
66 66
67 67 %changelog
68 * Fri May 13 2016 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.7-2
69 - Fixed another segfault on SpwPlugin.
70
71 * Thu Apr 21 2016 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.7-1
72 - Fixed segfault on SpwPlugin.
73
68 74 * Wed Apr 20 2016 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.7-0
69 75 - Updated to SocExplorer 0.7, some work on spwplugin merged.
70 76
71 77 * Mon Oct 12 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.6-4
72 78 - Added DSU3 cache status readout.
73 79
74 80 * Tue Sep 8 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.6-3
75 81 - Added spwplugin, improved AHB plugn'play decoding, fixed GUI bug on spwplugin.
76 82
77 83 * Fri Apr 3 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.6-2
78 84 - Improved ds3plugin.
79 85
80 86 * Fri Apr 3 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.6-1
81 87 - Fix some remaining mistakes.
82 88
83 89 * Thu Apr 2 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.6-0
84 90 -Uses r53 as source.
85 91 -Removed GenericPySysdriver interface, now socexplorer plugins can be subclassed in python.
86 92
87 93 * Thu Mar 26 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.5
88 94 -Uses r51 as source.
89 95
90 96 * Wed Mar 25 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
91 97 -Uses r50 as source.
92 98
93 99 * Fri Mar 20 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
94 100 -Uses r49 as source.
95 101
96 102 * Mon Mar 9 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
97 103 -Uses r48 as source.
98 104
99 105 * Wed Feb 18 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
100 106 -Uses r45 as source.
101 107
102 108 * Tue Feb 10 2015 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
103 109 -Uses r44 as source.
104 110
105 111 * Tue Dec 30 2014 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
106 112 - Uses r42 as source.
107 113
108 114 * Sat Jun 28 2014 Alexis Jeandet <alexis.jeandet@member.fsf.org> - 0.4
109 115 - Initial Fedora packaging
@@ -1,1011 +1,1014
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 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@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "stardundeespw_usb.h"
24 24 #include "fakestardundeespwusb_lib.h"
25 25 #include <socexplorerengine.h>
26 26 #include <qhexedit.h>
27 27
28 28 const QString dwLinkStatusQString[6] = {
29 29 "CFG_SPACEWIRE_ERROR_RESET",
30 30 "CFG_SPACEWIRE_ERROR_WAIT",
31 31 "CFG_SPACEWIRE_READY",
32 32 "CFG_SPACEWIRE_STARTED",
33 33 "CFG_SPACEWIRE_CONNECTING",
34 34 "CFG_SPACEWIRE_RUN"
35 35 };
36 36
37 37 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
38 38 abstractSpwBridge(parent)
39 39 {
40 40 Q_UNUSED(parent)
41 41 this->manager = new stardundeeSPW_USB_Manager(parent,this);
42 42 makeGUI(parent);
43 43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
44 44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
45 45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
46 46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
47 47 this->manager->start();
48 48 }
49 49
50 50 stardundeeSPW_USB::~stardundeeSPW_USB()
51 51 {
52 this->manager->requestInterruption();
53 while(this->manager->isRunning());
52
54 53 }
55 54
56 55 void stardundeeSPW_USB::toggleBridgeConnection()
57 56 {
58 57 if(this->plugin->isConnected())
59 58 {
60 59 this->disconnectBridge();
61 60 }
62 61 else
63 62 {
64 63 this->connectBridge();
65 64 }
66 65 }
67 66
68 67 bool stardundeeSPW_USB::connectBridge()
69 68 {
70 69 if(this->manager->connectBridge())
71 70 {
72 71 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
73 72 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
74 73 ((StarDundeeGUI*)this->p_GUI)->lock(true);
75 74 emit setConnected(true);
76 75 return true;
77 76 }
78 77 return false;
79 78 }
80 79
81 80 bool stardundeeSPW_USB::disconnectBridge()
82 81 {
83 82 if(this->manager->disconnectBridge())
84 83 {
85 84 ((StarDundeeGUI*)this->p_GUI)->lock(false);
86 85 emit setConnected(false);
87 86 return true;
88 87 }
89 88 return false;
90 89 }
91 90
92 91 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
93 92 {
94 93 return this->manager->sendPacket(packet,size);
95 94 }
96 95
97 96 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
98 97 {
99 98 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
100 99 char *RMAPAckBuff;
101 100 writeBuffer[0]=this->manager->linkNumber;//Link number
102 101 int transactionID = 0;
103 102 int written=0;
104 103 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
105 104 QProgressBar* progress=NULL;
106 105 SocExplorerAutoProgressBar autopb;
107 106 if(count>RMAP_MAX_XFER_SIZE)
108 107 {
109 108 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
110 109 autopb.setProgressBar(progress);
111 110 }
112 111 //Quite stupide loop, I guess that I always get the number of byte I asked for!
113 112 while(count>=RMAP_MAX_XFER_SIZE)
114 113 {
115 114 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
116 115 {
117 116 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
118 117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
119 118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
120 119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
121 120 }
122 121 transactionID=manager->getRMAPtransactionID();
123 122 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
124 123 RMAP_build_tx_request_header(
125 124 this->manager->destinationLogicalAddress,
126 125 this->manager->destinationKey,
127 126 this->manager->sourceLogicalAddress,
128 127 transactionID,
129 128 address+(written*4),
130 129 RMAP_MAX_XFER_SIZE*4,
131 130 writeBuffer+1);
132 131 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
133 132 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
134 133 free(RMAPAckBuff);
135 134 written+=RMAP_MAX_XFER_SIZE;
136 135 count-=RMAP_MAX_XFER_SIZE;
137 136 progress->setValue(written);
138 137 qApp->processEvents();
139 138 }
140 139 if(count>0)
141 140 {
142 141 for(int i=0;i<((int)count);i++)
143 142 {
144 143 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
145 144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
146 145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
147 146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
148 147 }
149 148 transactionID=manager->getRMAPtransactionID();
150 149 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
151 150 RMAP_build_tx_request_header(
152 151 this->manager->destinationLogicalAddress,
153 152 this->manager->destinationKey,
154 153 this->manager->sourceLogicalAddress,
155 154 transactionID,
156 155 address+(written*4),
157 156 count*4,
158 157 writeBuffer+1);
159 158 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
160 159 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
161 160 free(RMAPAckBuff);
162 161 written+=count;
163 162 if(progress!=NULL)
164 163 {
165 164 progress->setValue(written);
166 165 qApp->processEvents();
167 166 }
168 167 }
169 168 return written;
170 169 }
171 170
172 171 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
173 172 {
174 173 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
175 174 char* RMAP_AnswerBuffer;
176 175 requestBuffer[0]=this->manager->linkNumber;//Link number
177 176 int transactionID = 0;
178 177 int read=0;
179 178 QProgressBar* progress=NULL;
180 179 SocExplorerAutoProgressBar autopb;
181 180 if(count>RMAP_MAX_XFER_SIZE)
182 181 {
183 182 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
184 183 autopb.setProgressBar(progress);
185 184 }
186 185 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
187 186
188 187 //Quite stupide loop, I guess that I always get the number of byte I asked for!
189 188 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
190 189 {
191 190 transactionID = manager->getRMAPtransactionID();
192 191 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
193 192 RMAP_build_rx_request_header(
194 193 this->manager->destinationLogicalAddress,
195 194 this->manager->destinationKey,
196 195 this->manager->sourceLogicalAddress,
197 196 transactionID,
198 197 address+(read*4),
199 198 RMAP_MAX_XFER_SIZE*4,
200 199 requestBuffer+1);
201 200 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
202 201 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
203 202 if(len==-1)
204 203 {
205 204 this->toggleBridgeConnection();
206 205 return 0;
207 206 }
208 207 for(int i=0;i<((len-13)/4);i++)
209 208 {
210 209 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
211 210 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
212 211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
213 212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
214 213 }
215 214 free(RMAP_AnswerBuffer);
216 215 read+=RMAP_MAX_XFER_SIZE;
217 216 count-=RMAP_MAX_XFER_SIZE;
218 217 if(progress!=NULL)
219 218 {
220 219 progress->setValue(read);
221 220 qApp->processEvents();
222 221 }
223 222 }
224 223 if((int)count>0)
225 224 {
226 225 transactionID = manager->getRMAPtransactionID();
227 226 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
228 227 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
229 228 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
230 229 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
231 230 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
232 231 RMAP_build_rx_request_header(
233 232 this->manager->destinationLogicalAddress,
234 233 this->manager->destinationKey,
235 234 this->manager->sourceLogicalAddress,
236 235 transactionID,
237 236 address+(read*4),
238 237 count*4,
239 238 requestBuffer+1);
240 239 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
241 240 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
242 241 if(len==-1)
243 242 {
244 243 this->toggleBridgeConnection();
245 244 return 0;
246 245 }
247 246 for(int i=0;i<((len-13)/4);i++)
248 247 {
249 248 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
250 249 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
251 250 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
252 251 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
253 252 }
254 253 free(RMAP_AnswerBuffer);
255 254 read+=count;
256 255 if(progress!=NULL)
257 256 {
258 257 progress->setValue(read);
259 258 qApp->processEvents();
260 259 }
261 260 }
262 261 return read;
263 262 }
264 263
265 264 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
266 265 {
267 266 this->manager->selectedBrick = brickIndex-1;
268 267 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
269 268 }
270 269
271 270 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
272 271 {
273 272 this->manager->linkNumber = linkIndex + 1;
274 273 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
275 274 }
276 275
277 276 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
278 277 {
279 278 this->manager->linkSpeed = linkSpeed.toInt();
280 279
281 280 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
282 281 }
283 282
284 283 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
285 284 {
286 285 this->manager->sourceLogicalAddress = sourceAddress.toInt();
287 286 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
288 287 }
289 288
290 289 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
291 290 {
292 291 this->manager->destinationLogicalAddress = rmapaddress.toInt();
293 292 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
294 293 }
295 294
296 295 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
297 296 {
298 297 this->manager->destinationKey = key.toInt();
299 298 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
300 299 }
301 300
302 301 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
303 302 {
304 303 this->manager->interfaceMode = interfaceMode;
305 304 }
306 305
307 306 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
308 307 {
309 308 this->manager->timecodeFrequency = frequency.toDouble();
310 309 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
311 310 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
312 311 }
313 312
314 313 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
315 314 {
316 315 this->manager->sendTimecodePeriodically( onOff );
317 316 }
318 317
319 318 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
320 319 {
321 320 int tim=timeout.toInt();
322 321 if(tim<50)
323 322 {
324 323 tim = 50;
325 324 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
326 325 }
327 326 this->manager->RMAPtimeout = tim;
328 327 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
329 328 }
330 329
331 330 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
332 331 {
333 332 Q_UNUSED(parent)
334 333 this->p_GUI = new StarDundeeGUI();
335 334 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
336 335 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
337 336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
338 337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
339 338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
340 339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
341 340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
342 341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
343 342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
344 343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
345 344 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
346 345 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
347 346
348 347 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
349 348 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
350 349 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
351 350 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
352 351 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
353 352 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
354 353 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
355 354 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
356 355
357 356 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
358 357 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
359 358 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
360 359 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
361 360 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
362 361 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
363 362 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
364 363 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
365 364 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
366 365 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
367 366 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
368 367 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
369 368 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
370 369 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
371 370 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
372 371 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
373 372 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
374 373 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
375 374
376 375 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
377 376 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
378 377 }
379 378
380 379 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
381 380 {
382 381 char* data;
383 382 int i;
384 383
385 384 data = (char *) malloc( size + 5 );
386 385
387 386 data[0] = this->manager->linkNumber;
388 387 data[1] = this->manager->destinationLogicalAddress; // target logical address
389 388 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
390 389 data[3] = 0x00; // reserved
391 390 data[4] = 0x00; // user application
392 391
393 392 for ( i=0; i<size; i++ )
394 393 {
395 394 data[i+5] = packet[i];
396 395 }
397 396
398 397 this->manager->sendPacket( data, size + 5);
399 398
400 399 free(data);
401 400 free(packet);
402 401 }
403 402
404 403 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
405 404 :abstractSpwManager(plugin, parent)
406 405 {
407 406 // TODO remove this crap!
408 407 this->initDialog();
409 408 // this->moveToThread(this);
410 409 }
411 410
412 411 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
413 412 {
413 if(this->connected)disconnectBridge();
414 this->requestInterruption();
415 while(!this->isFinished());
414 416 }
415 417
416 418 void stardundeeSPW_USB_Manager::run()
417 419 {
418 420 USB_SPACEWIRE_PACKET_PROPERTIES properties;
419 421 USB_SPACEWIRE_ID pIdentifier=NULL;
420 422 USB_SPACEWIRE_STATUS stat;
421 423 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
422 424 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
423 while (!this->isInterruptionRequested())
425 while (!QThread::currentThread()->isInterruptionRequested())
424 426 {
425 427 if(this->connected)
426 428 {
427 429 this->handleMutex->lock();
428 430 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
429 431 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
430 432 {
431 433 SocExplorerEngine::message(this->plugin,"Got packet",2);
432 434 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
433 435 if (stat == TRANSFER_SUCCESS)
434 436 {
435 437 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
436 438 {
437 439 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
438 440 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
439 441 {
440 442 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
441 443 emit bytesReceivedFromSpw( properties.len );
442 444 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
443 445 {
444 446 RMAP_Answer* packet;
445 447 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
446 448 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
447 449 char* packetbuffer = (char*)malloc(properties.len);
448 450 memcpy(packetbuffer,buffer,properties.len);
449 451 USBSpaceWire_FreeRead(hDevice, pIdentifier);
450 452 pIdentifier = NULL;
451 453 this->handleMutex->unlock();
452 454 if(properties.len==8)
453 455 {
454 456 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
455 457 }
456 458 else
457 459 {
458 460 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
459 461 }
460 462 RMAP_AnswersMtx->lock();
461 463 RMAP_Answers.append(packet);
462 464 RMAP_AnswersMtx->unlock();
463 465 RMAP_AnswersSem->release();
464 466 }
465 467 else //any non-rmap packet will be pushed to the network
466 468 {
467 469 char* packetbuffer = (char*)malloc(properties.len);
468 470 memcpy(packetbuffer,buffer,properties.len);
469 471 emit emitPacket(packetbuffer,properties.len);
470 472 USBSpaceWire_FreeRead(hDevice, pIdentifier);
471 473 this->handleMutex->unlock();
472 474 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
473 475 }
474 476 }
475 477 else
476 478 {
477 479 SocExplorerEngine::message(this->plugin,"No EOP received",2);
478 480 this->handleMutex->unlock();
479 481 }
480 482 }
481 483
482 484 }
483 485 else
484 486 {
485 487 USBSpaceWire_FreeRead(hDevice, pIdentifier);
486 488 this->handleMutex->unlock();
487 489 }
488 490 }
489 491 else
490 492 {
491 493 USBSpaceWire_FreeRead(hDevice, pIdentifier);
492 494 this->handleMutex->unlock();
493 495 }
494 496 }
495 497 else
496 498 {
497 499 //do some sanity checks!
498 500 int list = USBSpaceWire_ListDevices();
499 501 if(this->brickList!=list)
500 502 {
501 503 this->brickList = list;
502 504 emit updateAvailableBrickCount(this->brickList);
503 505 }
504 506 usleep(RMAPtimeout/2);
505 507 }
506 508 usleep(1000);
507 509 }
508 510 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
509 511 }
510 512
511 513 bool stardundeeSPW_USB_Manager::connectBridge()
512 514 {
513 515 bool ret;
514 516
515 517 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
516 518 {
517 519 ret = connectBridgeAsInterface();
518 520 }
519 521 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
520 522 {
521 523 ret = connectBridgeAsRouter();
522 524 }
523 525 else
524 526 {
525 527 ret = false;
526 528 }
527 529
528 530 return ret;
529 531 }
530 532
531 533 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
532 534 {
533 535 this->handleMutex->lock();
534 536 int status;
535 537 U32 statusControl;
536 538 this->connected = false;
537 539 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
538 540 {
539 541 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
540 542 this->handleMutex->unlock();
541 543 return false;
542 544 }
543 545 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
544 546
545 547 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
546 548 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
547 549 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
548 550
549 551 // Set the path and return path to the device
550 552 CFGSpaceWire_StackClear();
551 553 CFGSpaceWire_AddrStackPush(0);
552 554 CFGSpaceWire_AddrStackPush(254);
553 555 CFGSpaceWire_RetAddrStackPush(254);
554 556 // set the base transmit rate to 100 MHz
555 557 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
556 558 if (status != CFG_TRANSFER_SUCCESS)
557 559 {
558 560 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
559 561 this->handleMutex->unlock();
560 562 return false;
561 563 }
562 564 else
563 565 {
564 566 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
565 567 }
566 568
567 569 // read the link status
568 570 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
569 571 {
570 572 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
571 573 this->handleMutex->unlock();
572 574 return false;
573 575 }
574 576 else
575 577 {
576 578 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
577 579
578 580 // Set the link status control register properties
579 581 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
580 582 CFGSpaceWire_LSEnableStart(&statusControl, 1);
581 583 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
582 584 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
583 585 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
584 586
585 587 // Set the link status control register
586 588 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
587 589 {
588 590 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
589 591 this->handleMutex->unlock();
590 592 return false;
591 593 }
592 594 else
593 595 {
594 596 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
595 597 }
596 598 }
597 599
598 600 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
599 601 {
600 602 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
601 603 this->handleMutex->unlock();
602 604 return false;
603 605 }
604 606 else
605 607 {
606 608 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
607 609 }
608 610
609 611 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
610 612 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
611 613 USBSpaceWire_SetTimeout(hDevice,1.0);
612 614 this->handleMutex->unlock();
613 615 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
614 616 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
615 617 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
616 618 this->connected = true;
617 619 return true;
618 620 }
619 621
620 622 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
621 623 {
622 624 // QMutexLocker mlock(&this->handleMutex);
623 625 this->handleMutex->lock();
624 626 int status;
625 627 U32 statusControl;
626 628 unsigned int linkStatus1;
627 629 unsigned int linkStatus2;
628 630 unsigned char linkNumber;
629 631 unsigned char deviceIsAnInterface;
630 632
631 633 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
632 634 {
633 635 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
634 636 this->handleMutex->unlock();
635 637 return false;
636 638 }
637 639 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
638 640 + QString::number(this->selectedBrick));
639 641
640 642 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
641 643 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
642 644 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
643 645
644 646 // Set the path and return path to the device
645 647 // This affects just the operations performed by the Configuration Library and does not affect the packets
646 648 // sent and received using the driver API.
647 649 CFGSpaceWire_StackClear();
648 650 CFGSpaceWire_AddrStackPush(0);
649 651 CFGSpaceWire_AddrStackPush(254);
650 652 CFGSpaceWire_RetAddrStackPush(254);
651 653
652 654 // set the base transmit rate to 100 MHz
653 655 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
654 656 if (status != CFG_TRANSFER_SUCCESS)
655 657 {
656 658 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
657 659 }
658 660 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
659 661
660 662 //*********************
661 663 // LINK 1 CONFIGURATION
662 664 linkNumber = 1;
663 665 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
664 666 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
665 667 else
666 668 {
667 669 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
668 670
669 671 // Set the link status control register properties
670 672 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
671 673 CFGSpaceWire_LSEnableStart(&statusControl, 1);
672 674 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
673 675 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
674 676 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
675 677
676 678 // Set the link status control register
677 679 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
678 680 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
679 681 else
680 682 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
681 683 }
682 684
683 685 //*********************
684 686 // LINK 2 CONFIGURATION
685 687 linkNumber = 2;
686 688 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
687 689 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
688 690 else
689 691 {
690 692 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
691 693
692 694 // Set the link status control register properties
693 695 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
694 696 CFGSpaceWire_LSEnableStart(&statusControl, 1);
695 697 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
696 698 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
697 699 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
698 700
699 701 // Set the link status control register
700 702 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
701 703 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
702 704 else
703 705 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
704 706 }
705 707
706 708 //***************************
707 709 // SET THE DEVICE AS A ROUTER
708 710 deviceIsAnInterface = 0; // 0 = router, 1 = interface
709 711 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
710 712 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
711 713 else
712 714 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
713 715
714 716 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
715 717 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
716 718
717 719 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
718 720 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
719 721
720 722 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
721 723 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
722 724 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
723 725
724 726 //************
725 727 // test Link 1 and Link 2
726 728 linkStatus1 = getLinkStatus(0x01);
727 729 linkStatus2 = getLinkStatus(0x02);
728 730 this->handleMutex->unlock();
729 731
730 732 if ((linkStatus1==1) || (linkStatus2==1))
731 733 {
732 734 initializeTimecodeGeneration();
733 735 this->connected=true;
734 736 return true;
735 737 }
736 738 else
737 739 {
738 740 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
739 741 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
740 742 starDundeeStatusQueryDialog->exec();
741 743 this->connected = false;
742 744 return false;
743 745 }
744 746 }
745 747
746 748 void stardundeeSPW_USB_Manager::initDialog( void )
747 749 {
748 750 // STAR DUNDEE STATUS QUERY DIALOG
749 751 starDundeeStatusQueryDialog = new QDialog;
750 752 starDundeeStatusQueryDialogLayout = new QGridLayout;
751 753 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
752 754 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
753 755 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
754 756 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
755 757 statusLink1 = new QLabel(tr("Link 1 status code: -"));
756 758 statusLink2 = new QLabel(tr("Link 2 status code: -"));
757 759
758 760 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
759 761 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
760 762 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
761 763 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
762 764 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
763 765 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
764 766 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
765 767 }
766 768
767 769 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
768 770 {
769 771 U32 routingTableEntry;
770 772 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
771 773 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
772 774 {
773 775 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
774 776 }
775 777 // Build the routing table entry
776 778 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
777 779 dwOutputPorts, // route out of port dwOutputPorts
778 780 bDelHead, // header deletion is enabled [1] or disabled [0]
779 781 0); // priority normal
780 782 // Set the routing table entry for logical address tableEntry
781 783 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
782 784 {
783 785 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
784 786 }
785 787 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
786 788 return 1;
787 789 }
788 790
789 791 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
790 792 {
791 793 U32 routingTableEntry, outputPorts;
792 794 char enabled, delHead, priority;
793 795 int portNum;
794 796
795 797 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
796 798 // Read the routing table entry
797 799 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
798 800 {
799 801 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
800 802 }
801 803 else
802 804 {
803 805 // Display the routing table entry properties
804 806 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
805 807 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
806 808 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
807 809 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
808 810 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
809 811 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
810 812 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
811 813 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
812 814 for (portNum = 0; portNum < 32; portNum++)
813 815 {
814 816 if (outputPorts & (1 << portNum))
815 817 {
816 818 SocExplorerEngine::message(this->plugin,QString::number(portNum));
817 819 }
818 820 }
819 821 }
820 822
821 823 return 1;
822 824 }
823 825
824 826 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
825 827 {
826 828 U32 dwTickEnableStatus;
827 829 U32 rtr_clk_freq;
828 830
829 831 // (1) RESET
830 832 if (!USBSpaceWire_TC_Reset(hDevice))
831 833 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
832 834
833 835 // (2) Clear the tick enable register
834 836 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
835 837 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
836 838 else
837 839 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
838 840
839 841 // (3) get the tick status
840 842 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
841 843 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
842 844
843 845 // (4) enable external timecode selection
844 846 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
845 847 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
846 848
847 849 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
848 850
849 851 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
850 852
851 853 //**************************************************
852 854 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
853 855 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
854 856 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
855 857 }
856 858
857 859 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
858 860 {
859 861 U32 statusControl, errorStatus, portType;
860 862 U32 linkStatus=0, operatingSpeed, outputPortConnection;
861 863 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
862 864
863 865 // Read the link status control register
864 866 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
865 867 {
866 868 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
867 869 }
868 870 else
869 871 {
870 872 // Display the link status control register properties
871 873 CFGSpaceWire_LSPortType(statusControl, &portType);
872 874 if (portType == CFG_CONFIGURATION_PORT)
873 875 {
874 876 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
875 877 }
876 878 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
877 879 {
878 880 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
879 881 }
880 882 else
881 883 {
882 884 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
883 885 }
884 886 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
885 887 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
886 888 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
887 889 CFGSpaceWire_LSIsStart(statusControl, &isStart);
888 890 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
889 891 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
890 892 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
891 893 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
892 894 }
893 895 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
894 896 +" is " + dwLinkStatusQString[linkStatus]);
895 897 if (linkStatus == 5)
896 898 {
897 899 return 1;
898 900 }
899 901 else return 0;
900 902 }
901 903
902 904 bool stardundeeSPW_USB_Manager::disconnectBridge()
903 905 {
904 906 this->handleMutex->lock();
905 907 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
906 908 USBSpaceWire_Close(hDevice); // Close the device
907 909 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
908 910 this->handleMutex->unlock();
909 911 this->RMAP_pending_transaction_IDsMtx->lock();
910 912 this->RMAP_pending_transaction_IDs.clear();
911 913 this->RMAP_pending_transaction_IDsMtx->unlock();
912 914 this->RMAP_AnswersMtx->lock();
913 915 this->RMAP_Answers.clear();
914 916 this->RMAP_AnswersMtx->unlock();
915 917 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
918 this->connected=false;
916 919 return true;
917 920 }
918 921
919 922 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
920 923 {
921 924 char protocoleIdentifier;
922 925 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
923 926 USB_SPACEWIRE_ID pIdentifier;
924 927 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
925 928 this->handleMutex->lock();
926 929 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
927 930 USBSpaceWire_FreeSend(hDevice, pIdentifier);
928 931 this->handleMutex->unlock();
929 932 if (result != TRANSFER_SUCCESS)
930 933 {
931 934 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
932 935 return false;
933 936 }
934 937 else
935 938 {
936 939 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
937 940 // read the protocole identifier
938 941 protocoleIdentifier = packet[2];
939 942 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
940 943 emit ccsdsPacketTransmittedToSpw();
941 944
942 945 SocExplorerEngine::message(this->plugin,"Packet sent",2);
943 946 }
944 947 return true;
945 948 }
946 949
947 950
948 951 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
949 952 {
950 953 this->handleMutex->lock();
951 954 if (onOff == true)
952 955 {
953 956 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
954 957 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
955 958 }
956 959 else
957 960 {
958 961 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
959 962 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
960 963 }
961 964 this->handleMutex->unlock();
962 965 }
963 966
964 967 int stardundeeSPW_USB_Manager::getLinkNumber( void )
965 968 {
966 969 return this->linkNumber;
967 970 }
968 971
969 972 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
970 973 {
971 974 U32 rtr_clk_freq=0;
972 975 U32 freqCount=0;
973 976 double freqCountInDouble=0.0;
974 977 double currentFrequency=0.0;
975 978
976 979 this->handleMutex->lock();
977 980 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
978 981 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
979 982 freqCount = (unsigned int) freqCountInDouble;
980 983
981 984 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
982 985
983 986 //**************************************************
984 987 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
985 988 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
986 989 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
987 990 else
988 991 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
989 992 + " (freqCount set to " + QString::number(freqCount) + ")" );
990 993 this->handleMutex->unlock();
991 994 }
992 995
993 996 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
994 997 {
995 998 this->handleMutex->lock();
996 999 // enable external timecode selection
997 1000 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
998 1001 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
999 1002
1000 1003 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1001 1004 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1002 1005 else
1003 1006 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1004 1007
1005 1008 // disable external timecode selection
1006 1009 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1007 1010 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1008 1011 this->handleMutex->unlock();
1009 1012 }
1010 1013
1011 1014
@@ -1,149 +1,149
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 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@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef STARDUNDEESPW_USB_H
23 23 #define STARDUNDEESPW_USB_H
24 24
25 25 #include <QObject>
26 26 //#include <spw_usb_api.h>
27 27 //#include <spw_config_library.h>
28 28
29 29 #include "fakestardundeespwusb_lib.h"
30 30 #include <socexplorerplugin.h>
31 31 #include <abstractspwbridge.h>
32 32 #include <QThread>
33 33 #include <QMutex>
34 34 #include <QSemaphore>
35 35 #include <QGridLayout>
36 36 #include <QPushButton>
37 37 #include <QComboBox>
38 38 #include <QLabel>
39 39 #include "stardundeegui.h"
40 40
41 41 #define BRICK_IS_SET_AS_AN_INTERFACE true
42 42 #define BRICK_IS_SET_AS_A_ROUTER false
43 43
44 44 class stardundeeSPW_USB_Manager: public abstractSpwManager
45 45 {
46 46 Q_OBJECT
47 47 public:
48 48 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
49 49 ~stardundeeSPW_USB_Manager();
50 void run();
51 bool connectBridge();
50 virtual void run();
51 virtual bool connectBridge();
52 52 bool connectBridgeAsInterface();
53 53 bool connectBridgeAsRouter();
54 54 void initDialog( void );
55 55 unsigned char setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead);
56 56 unsigned int getRoutingTableEntry(int tableEntry);
57 57 void initializeTimecodeGeneration();
58 58 void setTimecodeFrequency(double requestedFrequency);
59 59 unsigned int getLinkStatus(unsigned char link);
60 bool disconnectBridge();
61 bool sendPacket(char* packet,int size);
60 virtual bool disconnectBridge();
61 virtual bool sendPacket(char* packet,int size);
62 62
63 63 signals:
64 64 void updateAvailableBrickCount(int count);
65 65 void emitPacket(char* packet,int size);
66 66 void bytesReceivedFromSpw( unsigned int );
67 67 void bytesTransmittedToSpw( unsigned int);
68 68 void ccsdsPacketTransmittedToSpw( void );
69 69
70 70 public slots:
71 71 void sendTimecodePeriodically( bool onOff );
72 72 void sendOneTimecode(unsigned char nTimein);
73 73 int getLinkNumber( void );
74 74
75 75 private:
76 76 //QSemaphore* RMAP_AnswersSem;
77 77 star_device_handle hDevice;
78 78
79 79 QLabel *starDundeeStatusQueryDialogLabel;
80 80 QPushButton *starDundeeStatusQueryRetryButton;
81 81 QPushButton *starDundeeStatusQueryAbortButton;
82 82 QLabel *statusLink1;
83 83 QLabel *statusLink2;
84 84 QPushButton *starDundeeStatusQueryContinueButton;
85 85 QDialog *starDundeeStatusQueryDialog;
86 86 QGridLayout *starDundeeStatusQueryDialogLayout;
87 87
88 88 public:
89 89 int selectedBrick;
90 90 int brickList;
91 91 int linkSpeed;
92 92 double timecodeFrequency;
93 93 bool interfaceMode; // 1 => interface mode, 0 => router mode
94 94 };
95 95
96 96 class stardundeeSPW_USB : public abstractSpwBridge
97 97 {
98 98 Q_OBJECT
99 99 public:
100 100 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
101 101 ~stardundeeSPW_USB();
102 102
103 103 signals:
104 104
105 105 void setRmapTimeout(const QString & timeout);
106 106 void SelectBrick(int brickIndex);
107 107 void SelectLinkNumber(int linkIndex);
108 108 void SelectLinkSpeed(int linkSpeed);
109 109 void SetDestinationKey(const QString & destKey);
110 110 void SetSourceAddress(const QString & address);
111 111 void SetDestinationAddress(const QString & address);
112 112 void SetRmapTimeout(const QString & timeout);
113 113 void SetTimecodeFrequency( double );
114 114 void SetBrickAsAnInterface( bool );
115 115 void SetBrickAsARouter( bool );
116 116 int GetAvailableBrickCount( void );
117 117 unsigned int GetNbPacketsTransmittedToSpw( void );
118 118 unsigned int GetNbCCSDSPacketsTransmittedToSpw( void );
119 119 void BytesReceivedFromSpw( unsigned int );
120 120 void BytesTransmittedToSpw( unsigned int );
121 121 void CCSDSPacketTransmittedToSpw( void );
122 122 void StartSendingTimecodes( bool );
123 123 void SendOneTimecode( unsigned char );
124 124 int GetLinkNumber();
125 125
126 126 public slots:
127 127 void toggleBridgeConnection();
128 128 bool connectBridge();
129 129 bool disconnectBridge();
130 130 int pushRMAPPacket(char* packet,int size);
131 131 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
132 132 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
133 133 void brickSelectionChanged(int brickIndex);
134 134 void linkNumberSelectionChanged(int linkIndex);
135 135 void linkSpeedSelectionChanged(const QString & linkSpeed);
136 136 void sourceLogicalAddressChanged(const QString & destKey);
137 137 void destinationAddressChanged(const QString & rmapaddress);
138 138 void brickModeChanged( bool interfaceMode );
139 139 void destinationKeyChanged(const QString & key);
140 140 void rmapTimeoutChanged(const QString & timeout);
141 141 void sendPacketComingFromTCPServer(char *packet, int size);
142 142 void timecodeFrequencyChanged(const QString &frequency);
143 143 void startSendingTimecodes( bool onOff );
144 144 private:
145 145 void makeGUI(socexplorerplugin *parent);
146 146 stardundeeSPW_USB_Manager* manager;
147 147 };
148 148
149 149 #endif // STARDUNDEESPW_USB_H
@@ -1,179 +1,176
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 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@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "abstractspwbridge.h"
23 23 #include <QTime>
24 24 #include <socexplorerengine.h>
25 25
26 26 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
27 27 :QObject((QObject*)parent)
28 28 {
29 29 this->plugin = parent;
30 30 this->p_GUI=NULL;
31 31 }
32 32
33 33 abstractSpwBridge::~abstractSpwBridge()
34 34 {
35 35 // delete this->p_GUI;
36 36 }
37 37
38 38 QWidget *abstractSpwBridge::getGUI()
39 39 {
40 40 return this->p_GUI;
41 41 }
42 42
43 43 bool abstractSpwBridge::connectBridge()
44 44 {
45 45 return false;
46 46 }
47 47
48 48 bool abstractSpwBridge::disconnectBridge()
49 49 {
50 50 return false;
51 51 }
52 52
53 53
54 54
55 55
56 56
57 57
58 58
59 59
60 60
61 61
62 62 abstractSpwManager::abstractSpwManager(socexplorerplugin *plugin, QObject *parent)
63 63 :QThread((QObject*)parent)
64 64 {
65 65 this->RMAPtimeout = 2000;
66 66 this->handleMutex = new QMutex(QMutex::NonRecursive);
67 67 this->RMAP_AnswersSem = new QSemaphore(0);
68 68 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
69 69 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
70 70 this->plugin = plugin;
71 71 connected = false;
72 72 }
73 73
74 74 abstractSpwManager::~abstractSpwManager()
75 75 {
76 this->terminate();
77 while (!this->isFinished())
78 {
79 this->usleep(1000);
80 }
76 this->requestInterruption();
77 while(!this->isFinished());
81 78 }
82 79
83 80 int abstractSpwManager::getRMAPtransactionID()
84 81 {
85 82 this->RMAP_pending_transaction_IDsMtx->lock();
86 83 int ID=0;
87 84 bool found=true;
88 85 while(ID<511)
89 86 {
90 87 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
91 88 {
92 89 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
93 90 }
94 91 if(found==true)break;
95 92 ID++;
96 93 found = true;
97 94 }
98 95 if(found)
99 96 {
100 97 RMAP_pending_transaction_IDs.append(ID);
101 98 }
102 99 this->RMAP_pending_transaction_IDsMtx->unlock();
103 100 return ID;
104 101 }
105 102
106 103 int abstractSpwManager::getRMAPanswer(int transactionID, char **buffer)
107 104 {
108 105
109 106 QTime timeout;
110 107 *buffer=NULL;
111 108 int count=0;
112 109 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
113 110 qApp->processEvents();
114 111 timeout.start();
115 112 while (*buffer==NULL)
116 113 {
117 114 this->RMAP_AnswersMtx->lock();
118 115 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
119 116 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
120 117 for(int i=0;i<RMAP_Answers.count();i++)
121 118 {
122 119 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
123 120 if(RMAP_Answers[i]->transactionID==transactionID)
124 121 {
125 122 this->RMAP_pending_transaction_IDsMtx->lock();
126 123 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
127 124 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
128 125 {
129 126 if(RMAP_pending_transaction_IDs[j]==transactionID)
130 127 {
131 128 RMAP_pending_transaction_IDs.removeAt(j);
132 129 }
133 130 }
134 131 this->RMAP_pending_transaction_IDsMtx->unlock();
135 132 *buffer = RMAP_Answers[i]->data;
136 133 count = RMAP_Answers[i]->len;
137 134 RMAP_Answer* tmp=RMAP_Answers[i];
138 135 RMAP_Answers.removeAt(i);
139 136 delete tmp;
140 137 }
141 138 }
142 139 this->RMAP_AnswersMtx->unlock();
143 140 //if no answer found in the stack wait until a new packet is pushed
144 141 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
145 142 if(*buffer==NULL)
146 143 {
147 144 while (0==this->RMAP_AnswersSem->available())
148 145 {
149 146 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
150 147 if(timeout.elapsed()>=RMAPtimeout)
151 148 {
152 149 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
153 150 return -1;
154 151 }
155 152 usleep(1000);
156 153 qApp->processEvents();
157 154 }
158 155 this->RMAP_AnswersSem->acquire();
159 156 }
160 157 }
161 158 return count;
162 159 }
163 160
164 161 int abstractSpwManager::getLinkNumber()
165 162 {
166 163 return this->linkNumber;
167 164 }
168 165
169 166 void abstractSpwManager::pushRmapPacket(char *packet, int len)
170 167 {
171 168 char* packetbuffer = (char*)malloc(len);
172 169 memcpy(packetbuffer,packet,len);
173 170 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
174 171 RMAP_AnswersMtx->lock();
175 172 RMAP_Answers.append(RMPAPpacket);
176 173 RMAP_AnswersMtx->unlock();
177 174 }
178 175
179 176
@@ -1,110 +1,110
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 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@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef ABSTRACTSPWBRIDGE_H
23 23 #define ABSTRACTSPWBRIDGE_H
24 24
25 25 #include <QObject>
26 26 #include <QThread>
27 27 #include <QMutex>
28 28 #include <QSemaphore>
29 29 #include <socexplorerplugin.h>
30 30 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
31 31 #include <spw.h>
32 32
33 33 class RMAP_Answer
34 34 {
35 35 public:
36 36 RMAP_Answer(int ID,char* data,int len)
37 37 {
38 38 transactionID = ID;
39 39 this->data = data;
40 40 this->len = len;
41 41 }
42 42 int transactionID;
43 43 char* data;
44 44 int len;
45 45 };
46 46
47 47 class abstractSpwBridge : public QObject
48 48 {
49 49 Q_OBJECT
50 50 public:
51 51 explicit abstractSpwBridge(socexplorerplugin *parent);
52 52 ~abstractSpwBridge();
53 53 QWidget *getGUI();
54 54
55 55 public slots:
56 56 virtual bool connectBridge();
57 57 virtual bool disconnectBridge();
58 58 virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
59 59 virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
60 60 virtual int pushRMAPPacket(char* packet,int size)=0;
61 61 signals:
62 62 void setConnected(bool connected);
63 63 void pushPacketOverTCP(char* packet,int size);
64 64 protected:
65 65 socexplorerplugin* plugin;
66 66 QWidget* p_GUI;
67 67 private:
68 68
69 69 };
70 70
71 71 class abstractSpwManager: public QThread
72 72 {
73 73 Q_OBJECT
74 74 public:
75 75 explicit abstractSpwManager(socexplorerplugin *plugin = 0,QObject* parent=0);
76 76 ~abstractSpwManager();
77 virtual void run(){}
77 virtual void run(){};
78 78 virtual bool connectBridge()=0;
79 79 virtual bool disconnectBridge()=0;
80 80 int getRMAPtransactionID();
81 81 int getRMAPanswer(int transactionID,char** buffer);
82 82 virtual bool sendPacket(char* packet,int size)=0;
83 83 int RMAPtimeout;
84 84 int linkNumber;
85 85 int sourceLogicalAddress;
86 86 int destinationLogicalAddress;
87 87 int destinationKey;
88 88 signals:
89 89 void emitPacket(char* packet,int size);
90 90 void bytesReceivedFromSpw( unsigned int );
91 91 void bytesTransmittedToSpw( unsigned int);
92 92 void ccsdsPacketTransmittedToSpw( void );
93 93
94 94 public slots:
95 95 int getLinkNumber();
96 96
97 97 protected:
98 98 QList<RMAP_Answer*> RMAP_Answers;
99 99 QList<int> RMAP_pending_transaction_IDs;
100 100 QMutex *handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
101 101 QSemaphore* RMAP_AnswersSem;
102 102 socexplorerplugin* plugin;
103 103 bool connected;
104 104 void pushRmapPacket(char* packet,int len);
105 105
106 106 };
107 107
108 108
109 109
110 110 #endif // ABSTRACTSPWBRIDGE_H
@@ -1,186 +1,187
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 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@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "spwplugin.h"
24 24 #include "stardundeespw_usb.h"
25 25 #include "gr_esb_bridge.h"
26 26 #include <socexplorerproxy.h>
27 27 #include "fakestardundeespwusb_lib.h"
28 28
29 29
30 30 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false)
31 31 {
32 32 Q_UNUSED(parent)
33 33 FakeStarDundeeSpwUSB_Lib::resolve();
34 this->bridge = NULL;
34 this->bridge = Q_NULLPTR;
35 35 this->scanDone = false;
36 36 // this->pyObject = new spwPyWrapper(this);
37 37 this->tcpServer = new SpwTcpPacketServer(this);
38 38 this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this);
39 39 this->bridgeSelector = new QComboBox(this);
40 40 this->mainTabWidgt = new QTabWidget(this);
41 41 this->mainTabWidgt->addTab(this->mainGroupBox,"Bridge Configuration");
42 42 this->mainTabWidgt->addTab(this->tcpServer,"TCP Server");
43 43 this->mainLayout = new QGridLayout(this->mainGroupBox);
44 44 this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter);
45 45 this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1);
46 46 this->setWidget(this->mainTabWidgt);
47 47 this->bridgeSelector->addItem("none");
48 48 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
49 49 this->bridgeSelector->addItem("GR-ESB");
50 50 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
51 51 connect(this,SIGNAL(selectBridge(QString)),this,SLOT(selectBridge(QString)));
52 52 connect(this,SIGNAL(TCPServerConnect()),this->tcpServer,SLOT(connectServer()));
53 53 connect(this,SIGNAL(TCPServerDisconnect()),this->tcpServer,SLOT(disconnectServer()));
54 54 connect(this,SIGNAL(TCPServerSetPort(qint32)),this->tcpServer,SLOT(setServerPort(qint32)));
55 55 connect(this,SIGNAL(TCPServerSetIP(QString)),this->tcpServer,SLOT(setServerSetIP(QString)));
56 56 }
57 57
58 58
59 59 spwplugin::~spwplugin()
60 60 {
61
61 if(this->bridge!=Q_NULLPTR)
62 delete this->bridge;
62 63 }
63 64
64 65
65 66
66 67 unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
67 68 {
68 69 if(Connected)
69 70 {
70 71 return bridge->Read(Value,count,address);
71 72 }
72 73 return 0;
73 74 }
74 75
75 76 void spwplugin::bridgeSelectionChanged(const QString &text)
76 77 {
77 78 printf("test");
78 79 if(text=="none")
79 80 {
80 81 if(this->bridge!=NULL)
81 82 {
82 83 this->mainLayout->removeWidget(this->bridge->getGUI());
83 84 this->bridge->getGUI()->hide();
84 85 this->disconnect(this,SLOT(setConnected(bool)));
85 86 delete this->bridge;
86 87 this->bridge= NULL;
87 88 }
88 89 }
89 90 if(text=="STAR-Dundee Spw USB Brick")
90 91 {
91 92 if(this->bridge!=NULL)
92 93 {
93 94 this->mainLayout->removeWidget(this->bridge->getGUI());
94 95 this->bridge->getGUI()->hide();
95 96 this->disconnect(this,SLOT(setConnected(bool)));
96 97 delete this->bridge;
97 98 }
98 99 this->bridge = new stardundeeSPW_USB(this);
99 100 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
100 101 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
101 102 connect(this,SIGNAL(StarDundeeSelectBrick(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectBrick(int)));
102 103 connect(this,SIGNAL(StarDundeeSelectLinkNumber(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkNumber(int)));
103 104 connect(this,SIGNAL(StarDundeeSelectLinkSpeed(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkSpeed(int)));
104 105 connect(this,SIGNAL(StarDundeeSetSourceAddress(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetSourceAddress(QString)));
105 106 connect(this,SIGNAL(StarDundeeSetDestinationAddress(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetDestinationAddress(QString)));
106 107 connect(this,SIGNAL(StarDundeeSetDestinationKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetDestinationKey(QString)));
107 108 connect(this,SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString)));
108 109 connect(this,SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
109 110 connect(this,SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
110 111 connect(this,SIGNAL(StarDundeeGetAvailableBrickCount()),
111 112 ((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount()));
112 113 connect(this,SIGNAL(StarDundeeGetNbPacketsTransmittedToSpw()),
113 114 ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbPacketsTransmittedToSpw()));
114 115 connect(this,SIGNAL(StarDundeeGetNbCCSDSPacketsTransmittedToSpw()),
115 116 ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()));
116 117 connect(this,SIGNAL(StarDundeeGetLinkNumber()),((stardundeeSPW_USB*)bridge),SIGNAL(GetLinkNumber()));
117 118 connect(this,SIGNAL(StarDundeeSetBrickAsAninterface(bool)),
118 119 ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsAnInterface(bool)));
119 120 connect(this,SIGNAL(StarDundeeSetBrickAsARouter(bool)),
120 121 ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsARouter(bool)));
121 122 connect(this,SIGNAL(StarDundeeStartTimecodes(bool)),
122 123 ((stardundeeSPW_USB*)bridge),SIGNAL(StartSendingTimecodes(bool)));
123 124 connect(this,SIGNAL(StarDundeeSetTimecodeFrequency(double)),
124 125 ((stardundeeSPW_USB*)bridge),SIGNAL(SetTimecodeFrequency(double)));
125 126 connect(this,SIGNAL(StarDundeeSendOneTimecode(unsigned char)),
126 127 ((stardundeeSPW_USB*)bridge),SIGNAL(SendOneTimecode(unsigned char)));
127 128 connect(this->bridge,SIGNAL(pushPacketOverTCP(char*,int)),this->tcpServer,SLOT(pushPacket(char*,int)));
128 129 connect(this->tcpServer, SIGNAL(sendSPWPacket(char*,int)), ((stardundeeSPW_USB*)bridge), SLOT(sendPacketComingFromTCPServer(char*,int)));
129 130 }
130 131 if(text=="GR-ESB")
131 132 {
132 133 if(this->bridge!=NULL)
133 134 {
134 135 this->mainLayout->removeWidget(this->bridge->getGUI());
135 136 this->bridge->getGUI()->hide();
136 137 this->disconnect(this,SLOT(setConnected(bool)));
137 138 delete this->bridge;
138 139 }
139 140 this->bridge = new GR_ESB_bridge(this);
140 141 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
141 142 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
142 143 }
143 144 }
144 145
145 146
146 147 void spwplugin::selectBridge(const QString &text)
147 148 {
148 149
149 150 if(text=="none")
150 151 {
151 152 this->bridgeSelector->setCurrentIndex(0);
152 153 }
153 154 if(text=="STAR-Dundee Spw USB Brick")
154 155 {
155 156 this->bridgeSelector->setCurrentIndex(1);
156 157 }
157 158 }
158 159
159 160 void spwplugin::setConnected(bool connected)
160 161 {
161 162 this->bridgeSelector->setDisabled(connected);
162 163 this->Connected = connected;
163 164 emit activateSig(connected);
164 165 if(!this->scanDone)
165 166 {
166 167 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
167 168 this->scanDone=true;
168 169 }
169 170 }
170 171
171 172 unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
172 173 {
173 174 if(Connected)
174 175 {
175 176 return bridge->Write(Value,count,address);
176 177 }
177 178 return 0;
178 179 }
179 180
180 181
181 182
182 183
183 184
184 185
185 186
186 187
General Comments 0
You need to be logged in to leave comments. Login now