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