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