##// END OF EJS Templates
Sync
Jeandet Alexis -
r15:b813b27420b4 default
parent child
Show More
@@ -1,128 +1,142
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "spwplugin.h"
24 24 #include "stardundeespw_usb.h"
25 25 #include <socexplorerproxy.h>
26 26 #include "spwpywrapper.h"
27 27 spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false)
28 28 {
29 29 Q_UNUSED(parent)
30 30 this->bridge = NULL;
31 31 this->scanDone = false;
32 32 this->pyObject = new spwPyWrapper(this);
33 33 this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this);
34 34 this->bridgeSelector = new QComboBox(this);
35 35 this->mainLayout = new QGridLayout(this);
36 36 this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter);
37 37 this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1);
38 38 this->mainGroupBox->setLayout(this->mainLayout);
39 39 this->setWidget(this->mainGroupBox);
40 40 this->bridgeSelector->addItem("none");
41 41 this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick");
42 42 connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString)));
43 connect(((spwPyWrapper*)this->pyObject),SIGNAL(selectBridge(QString)),this,SLOT(selectBridge(QString)));
43 44 }
44 45
45 46
46 47 spwplugin::~spwplugin()
47 48 {
48 49
49 50 }
50 51
51 52
52 53
53 54 unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
54 55 {
55 56 if(Connected)
56 57 {
57 58 return bridge->Read(Value,count,address);
58 59 }
59 60 return 0;
60 61 }
61 62
62 63 void spwplugin::bridgeSelectionChanged(const QString &text)
63 64 {
64 65 printf("test");
65 66 if(text=="none")
66 67 {
67 68 if(this->bridge!=NULL)
68 69 {
69 70 this->mainLayout->removeWidget(this->bridge->getGUI());
70 71 this->disconnect(this,SLOT(setConnected(bool)));
71 72 delete this->bridge;
72 73 this->bridge= NULL;
73 74 }
74 75 }
75 76 if(text=="STAR-Dundee Spw USB Brick")
76 77 {
77 78 if(this->bridge!=NULL)
78 79 {
79 80 this->mainLayout->removeWidget(this->bridge->getGUI());
80 81 this->disconnect(this,SLOT(setConnected(bool)));
81 82 delete this->bridge;
82 83 }
83 84 this->bridge = new stardundeeSPW_USB(this);
84 85 this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2);
85 86 connect(this->bridge,SIGNAL(setConnected(bool)),this,SLOT(setConnected(bool)));
86 87 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectBrick(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectBrick(int)));
87 88 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkNumber(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkNumber(int)));
88 89 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSelectLinkSpeed(int)),((stardundeeSPW_USB*)bridge),SIGNAL(SelectLinkSpeed(int)));
89 90 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetDestinationKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetDestinationKey(QString)));
90 91 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapAddress(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapAddress(QString)));
91 92 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapKey(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapKey(QString)));
92 93 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString)));
93 94 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
94 95 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
95 96 }
96 97
97 98 }
98 99
100 void spwplugin::selectBridge(const QString &text)
101 {
102
103 if(text=="none")
104 {
105 this->bridgeSelector->setCurrentIndex(0);
106 }
107 if(text=="STAR-Dundee Spw USB Brick")
108 {
109 this->bridgeSelector->setCurrentIndex(1);
110 }
111 }
112
99 113 void spwplugin::setConnected(bool connected)
100 114 {
101 115 this->bridgeSelector->setDisabled(connected);
102 116 this->Connected = connected;
103 117 emit activateSig(connected);
104 118 if(!this->scanDone)
105 119 {
106 120 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
107 121 this->scanDone=true;
108 122 }
109 123 }
110 124
111 125
112 126
113 127 unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
114 128 {
115 129 if(Connected)
116 130 {
117 131 return bridge->Write(Value,count,address);
118 132 }
119 133 return 0;
120 134 }
121 135
122 136
123 137
124 138
125 139
126 140
127 141
128 142
@@ -1,71 +1,72
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 spwplugin_H
23 23 #define spwplugin_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28 #include <QGroupBox>
29 29 #include <QComboBox>
30 30 #include <QLabel>
31 31
32 32 #include <abstractspwbridge.h>
33 33 #include <socexplorerplugin.h>
34 34
35 35
36 36 class spwplugin : public socexplorerplugin
37 37 {
38 38 Q_OBJECT
39 39 public:
40 40 explicit spwplugin(QWidget *parent = 0);
41 41 ~spwplugin();
42 42 /* You can implement the folowing function if you want to overwrite
43 43 * their default behavior
44 44 */
45 45 /*
46 46 int registermenu(QMainWindow *menuHolder);
47 47 int isConnected();
48 48 int connect();
49 49 int VID(){return driver_VID;}
50 50 int PID(){return driver_PID;}
51 51 */
52 52
53 53 public slots:
54 54 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
55 55 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
56 56
57 57 void bridgeSelectionChanged( const QString & text );
58 void selectBridge( const QString & text );
58 59 void setConnected(bool connected);
59 60
60 61 signals:
61 62
62 63 private:
63 64 abstractSpwBridge* bridge;
64 65 bool scanDone;
65 66 QGroupBox* mainGroupBox;
66 67 QComboBox* bridgeSelector;
67 68 QGridLayout* mainLayout;
68 69 };
69 70
70 71 #endif // spwplugin_H
71 72
@@ -1,25 +1,26
1 1 #ifndef SPWPYWRAPPER_H
2 2 #define SPWPYWRAPPER_H
3 3 #include <genericPySysdriver.h>
4 4
5 5 class spwPyWrapper : public genericPySysdriver
6 6 {
7 7 Q_OBJECT
8 8 public:
9 9 explicit spwPyWrapper(socexplorerplugin *parent = 0);
10 10
11 11 signals:
12 void selectBridge(const QString &bridgeName);
12 13 bool connectBridge();
13 14 bool disconnectBridge();
14 15 void StarDundeeSelectBrick(int brickIndex);
15 16 void StarDundeeSelectLinkNumber(int linkIndex);
16 17 void StarDundeeSelectLinkSpeed(int linkSpeed);
17 18 void StarDundeeSetDestinationKey(const QString & destKey);
18 19 void StarDundeeSetRmapAddress(const QString & address);
19 20 void StarDundeeSetRmapKey(const QString & key);
20 21 void StarDundeeSetRmapTimeout(const QString & timeout);
21 22 public slots:
22 23
23 24 };
24 25
25 26 #endif // SPWPYWRAPPER_H
@@ -1,644 +1,636
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 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
28 28 abstractSpwBridge(parent)
29 29 {
30 30 Q_UNUSED(parent)
31 31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
32 32 makeGUI(parent);
33 33 this->manager->start();
34 34 }
35 35
36 36 stardundeeSPW_USB::~stardundeeSPW_USB()
37 37 {
38 38 this->manager->requestInterruption();
39 39 delete this->p_GUI;
40 40 }
41 41
42 42 void stardundeeSPW_USB::toggleBridgeConnection()
43 43 {
44 44 if(this->plugin->isConnected())
45 45 {
46 46 this->disconnectBridge();
47 47 }
48 48 else
49 49 {
50 50 this->connectBridge();
51 51 }
52 52 }
53 53
54 54 bool stardundeeSPW_USB::connectBridge()
55 55 {
56 56 if(this->manager->connectBridge())
57 57 {
58 58 ((StarDundeeGUI*)this->p_GUI)->lock(true);
59 59 emit setConnected(true);
60 60 return true;
61 61 }
62 62 return false;
63 63 }
64 64
65 65 bool stardundeeSPW_USB::disconnectBridge()
66 66 {
67 67 if(this->manager->disconnectBridge())
68 68 {
69 69 ((StarDundeeGUI*)this->p_GUI)->lock(false);
70 70 emit setConnected(false);
71 71 return true;
72 72 }
73 73 return false;
74 74 }
75 75
76 76
77 77 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
78 78 {
79 79 return this->manager->sendPacket(packet,size);
80 80 }
81 81
82 82 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
83 83 {
84 84 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
85 85 writeBuffer[0]=this->manager->linkNumber;//Link number
86 86 int transactionID = 0;
87 87 int written=0;
88 88 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
89 89 QProgressBar* progress=NULL;
90 90 SocExplorerAutoProgressBar autopb;
91 91 if(count>RMAP_MAX_XFER_SIZE)
92 92 {
93 93 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
94 94 autopb.setProgressBar(progress);
95 95 }
96 96 //Quite stupide loop, I guess that I always get the number of byte I asked for!
97 97 while(count>=RMAP_MAX_XFER_SIZE)
98 98 {
99 99 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
100 100 {
101 101 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
102 102 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
103 103 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
104 104 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
105 105 }
106 106 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
107 107 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
108 108 written+=RMAP_MAX_XFER_SIZE;
109 109 count-=RMAP_MAX_XFER_SIZE;
110 110 progress->setValue(written);
111 111 qApp->processEvents();
112 112 }
113 113 if(count>0)
114 114 {
115 115 for(int i=0;i<((int)count);i++)
116 116 {
117 117 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
118 118 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
119 119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
120 120 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
121 121 }
122 122 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),count*4,writeBuffer+1);
123 123 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
124 124 written+=count;
125 125 if(progress!=NULL)
126 126 {
127 127 progress->setValue(written);
128 128 qApp->processEvents();
129 129 }
130 130 }
131 // if(progress!=NULL)
132 // {
133 // SocExplorerEngine::deleteProgressBar(progress);
134 // }
135 131 return written;
136 132 }
137 133
138 134 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
139 135 {
140 136 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
141 137 char* RMAP_AnswerBuffer;
142 138 requestBuffer[0]=this->manager->linkNumber;//Link number
143 139 int transactionID = 0;
144 140 int read=0;
145 141 QProgressBar* progress=NULL;
146 142 SocExplorerAutoProgressBar autopb;
147 143 if(count>RMAP_MAX_XFER_SIZE)
148 144 {
149 145 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
150 146 autopb.setProgressBar(progress);
151 147 }
152 148 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
153 149
154 150 //Quite stupide loop, I guess that I always get the number of byte I asked for!
155 151 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
156 152 {
157 153 transactionID = manager->getRMAPtransactionID();
158 154 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
159 155 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
160 156 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
161 157 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
162 158 if(len==-1)
163 159 {
164 160 this->toggleBridgeConnection();
165 161 return 0;
166 162 }
167 163 for(int i=0;i<((len-13)/4);i++)
168 164 {
169 165 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
170 166 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
171 167 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
172 168 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
173 169 }
174 170 free(RMAP_AnswerBuffer);
175 171 read+=RMAP_MAX_XFER_SIZE;
176 172 count-=RMAP_MAX_XFER_SIZE;
177 173 progress->setValue(read);
178 174 qApp->processEvents();
179 175 }
180 176 if((int)count>0)
181 177 {
182 178 transactionID = manager->getRMAPtransactionID();
183 179 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
184 180 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
185 181 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
186 182 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
187 183 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
188 184 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),count*4,requestBuffer+1);
189 185 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
190 186 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
191 187 if(len==-1)
192 188 {
193 189 this->toggleBridgeConnection();
194 190 return 0;
195 191 }
196 192 for(int i=0;i<((len-13)/4);i++)
197 193 {
198 194 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
199 195 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
200 196 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
201 197 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
202 198 }
203 199 free(RMAP_AnswerBuffer);
204 200 read+=count;
205 201 if(progress!=NULL)
206 202 {
207 203 progress->setValue(read);
208 204 qApp->processEvents();
209 205 }
210 206 }
211 // if(progress!=NULL)
212 // {
213 // SocExplorerEngine::deleteProgressBar(progress);
214 // }
215 207 return read;
216 208 }
217 209
218 210 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
219 211 {
220 212 this->manager->selectedBrick = brickIndex-1;
221 213 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
222 214 }
223 215
224 216 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
225 217 {
226 218 this->manager->linkNumber = linkIndex + 1;
227 219 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
228 220 }
229 221
230 222 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
231 223 {
232 224 this->manager->linkSpeed = linkSpeed.toInt();
233 225
234 226 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
235 227 }
236 228
237 229 void stardundeeSPW_USB::destinationKeyChanged(const QString &destKey)
238 230 {
239 231 this->manager->destinationKey = destKey.toInt();
240 232 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->destinationKey),1);
241 233 }
242 234
243 235 void stardundeeSPW_USB::rmapAddressChanged(const QString &rmapaddress)
244 236 {
245 237 this->manager->rmapAddress = rmapaddress.toInt();
246 238 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->rmapAddress),1);
247 239 }
248 240
249 241 void stardundeeSPW_USB::rmapKeyChanged(const QString &key)
250 242 {
251 243 this->manager->rmapKey = key.toInt();
252 244 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->rmapKey),1);
253 245 }
254 246
255 247 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
256 248 {
257 249 int tim=timeout.toInt();
258 250 if(tim<50)
259 251 {
260 252 tim = 50;
261 253 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
262 254 }
263 255 this->manager->RMAPtimeout = tim;
264 256 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
265 257 }
266 258
267 259
268 260 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
269 261 {
270 262 this->p_GUI = new StarDundeeGUI();
271 263 // this->mainLayout = new QGridLayout(this->p_GUI);
272 264 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
273 265 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
274 266 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
275 267 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
276 268 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
277 269 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
278 270 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(rmapAddressChanged(QString)));
279 271 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapKeyChanged(QString)),this,SLOT(rmapKeyChanged(QString)));
280 272 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
281 273
282 274 this->brickSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
283 275 this->linkNumberSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
284 276 this->linkSpeedSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
285 277 this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
286 278 this->rmapAddressChanged(((StarDundeeGUI*)this->p_GUI)->getRmapAddress());
287 279 this->rmapKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey());
288 280 this->rmapTimeoutChanged(((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
289 281
290 282 connect(this,SIGNAL(SelectBrick(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
291 283 connect(this,SIGNAL(SelectLinkNumber(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
292 284 connect(this,SIGNAL(SelectLinkSpeed(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
293 285 connect(this,SIGNAL(SetDestinationKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
294 286 connect(this,SIGNAL(SetRmapAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapAddress(QString)));
295 287 connect(this,SIGNAL(SetRmapKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapKey(QString)));
296 288 connect(this,SIGNAL(SetRmapTimeout(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
297 289
298 290 }
299 291
300 292 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
301 293 :QThread((QObject*)parent)
302 294 {
303 295 this->RMAPtimeout = 2000;
304 296 this->handleMutex = new QMutex(QMutex::NonRecursive);
305 297 this->RMAP_AnswersSem = new QSemaphore(0);
306 298 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
307 299 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
308 300 this->plugin = plugin;
309 301 connected = false;
310 302 this->moveToThread(this);
311 303 }
312 304
313 305 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
314 306 {
315 307 this->terminate();
316 308 while (!this->isFinished()) {
317 309 this->usleep(1000);
318 310 }
319 311 }
320 312
321 313
322 314 void stardundeeSPW_USB_Manager::run()
323 315 {
324 316 USB_SPACEWIRE_PACKET_PROPERTIES properties;
325 317 USB_SPACEWIRE_ID pIdentifier=NULL;
326 318 USB_SPACEWIRE_STATUS stat;
327 319 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
328 320 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
329 321 while (!this->isInterruptionRequested())
330 322 {
331 323 if(this->connected)
332 324 {
333 325 handleMutex->lock();
334 326 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
335 327 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
336 328 {
337 329 SocExplorerEngine::message(this->plugin,"Got packet",2);
338 330 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
339 331 if (stat == TRANSFER_SUCCESS)
340 332 {
341 333 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
342 334 {
343 335 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
344 336 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
345 337 {
346 338 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
347 339 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
348 340 {
349 341 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
350 342 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
351 343 if(properties.len>8)
352 344 {
353 345 char* packetbuffer = (char*)malloc(properties.len);
354 346 memcpy(packetbuffer,buffer,properties.len);
355 347 USBSpaceWire_FreeRead(hDevice, pIdentifier);
356 348 pIdentifier = NULL;
357 349 handleMutex->unlock();
358 350 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
359 351 RMAP_AnswersMtx->lock();
360 352 RMAP_Answers.append(packet);
361 353 RMAP_AnswersMtx->unlock();
362 354 RMAP_AnswersSem->release();
363 355
364 356 }
365 357 else //it's a RMAP write response
366 358 {
367 359 USBSpaceWire_FreeRead(hDevice, pIdentifier);
368 360 pIdentifier = NULL;
369 361 handleMutex->unlock();
370 362 }
371 363
372 364 }
373 365 else //any non-rmap packet will be pushed to the network
374 366 {
375 367 USBSpaceWire_FreeRead(hDevice, pIdentifier);
376 368 handleMutex->unlock();
377 369 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
378 370 }
379 371 }
380 372 else
381 373 {
382 374 SocExplorerEngine::message(this->plugin,"No EOP received",2);
383 375 }
384 376 }
385 377
386 378 }
387 379 else
388 380 {
389 381 USBSpaceWire_FreeRead(hDevice, pIdentifier);
390 382 handleMutex->unlock();
391 383 }
392 384 }
393 385 else
394 386 {
395 387 USBSpaceWire_FreeRead(hDevice, pIdentifier);
396 388 handleMutex->unlock();
397 389 }
398 390 }
399 391 else
400 392 {
401 393 //do some sanity checks!
402 394 int list = USBSpaceWire_ListDevices();
403 395 if(this->brickList!=list)
404 396 {
405 397 this->brickList = list;
406 398 emit updateAvailableBrickCount(this->brickList);
407 399 }
408 400 usleep(RMAPtimeout/2);
409 401 }
410 402 usleep(1000);
411 403 }
412 404 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
413 405 }
414 406
415 407 bool stardundeeSPW_USB_Manager::connectBridge()
416 408 {
417 409 QMutexLocker mlock(this->handleMutex);
418 410 int status;
419 411 U32 statusControl;
420 412 this->connected = false;
421 413 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
422 414 {
423 415 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
424 416 return false;
425 417 }
426 418 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
427 419
428 420 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
429 421 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
430 422 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
431 423
432 424 // Set the path and return path to the device
433 425 CFGSpaceWire_StackClear();
434 426 CFGSpaceWire_AddrStackPush(0);
435 427 CFGSpaceWire_AddrStackPush(254);
436 428 CFGSpaceWire_RetAddrStackPush(254);
437 429 // set the base transmit rate to 100 MHz
438 430 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
439 431 if (status != CFG_TRANSFER_SUCCESS)
440 432 {
441 433 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
442 434 return false;
443 435 }
444 436 else
445 437 {
446 438 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
447 439 }
448 440
449 441 // read the link status
450 442 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
451 443 {
452 444 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
453 445 return false;
454 446 }
455 447 else
456 448 {
457 449 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
458 450
459 451 // Set the link status control register properties
460 452 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
461 453 CFGSpaceWire_LSEnableStart(&statusControl, 1);
462 454 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
463 455 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
464 456 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
465 457
466 458 // Set the link status control register
467 459 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
468 460 {
469 461 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
470 462 return false;
471 463 }
472 464 else
473 465 {
474 466 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
475 467 }
476 468 }
477 469
478 470 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
479 471 {
480 472 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
481 473 return false;
482 474 }
483 475 else
484 476 {
485 477 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
486 478 }
487 479
488 480 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
489 481 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
490 482 USBSpaceWire_SetTimeout(hDevice,1.0);
491 483 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
492 484 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
493 485 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
494 486 this->connected = true;
495 487 return true;
496 488 }
497 489
498 490 bool stardundeeSPW_USB_Manager::disconnectBridge()
499 491 {
500 492 this->handleMutex->lock();
501 493 USBSpaceWire_Close(hDevice); // Close the device
502 494 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
503 495 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
504 496 this->handleMutex->unlock();
505 497 this->RMAP_pending_transaction_IDsMtx->lock();
506 498 this->RMAP_pending_transaction_IDs.clear();
507 499 this->RMAP_pending_transaction_IDsMtx->unlock();
508 500 this->RMAP_AnswersMtx->lock();
509 501 this->RMAP_Answers.clear();
510 502 this->RMAP_AnswersMtx->unlock();
511 503 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
512 504 return true;
513 505 }
514 506
515 507 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
516 508 {
517 509 this->RMAP_pending_transaction_IDsMtx->lock();
518 510 int ID=0;
519 511 bool found=true;
520 512 while(ID<511)
521 513 {
522 514 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
523 515 {
524 516 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
525 517 }
526 518 if(found==true)break;
527 519 ID++;
528 520 found = true;
529 521 }
530 522 if(found)
531 523 {
532 524 RMAP_pending_transaction_IDs.append(ID);
533 525 }
534 526 this->RMAP_pending_transaction_IDsMtx->unlock();
535 527 return ID;
536 528 }
537 529
538 530 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
539 531 {
540 532 QTime timeout;
541 533 *buffer=NULL;
542 534 int count=0;
543 535 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
544 536 timeout.start();
545 537 while (*buffer==NULL)
546 538 {
547 539 this->RMAP_AnswersMtx->lock();
548 540 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
549 541 SocExplorerEngine::message(this->plugin,QString("%2 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
550 542 for(int i=0;i<RMAP_Answers.count();i++)
551 543 {
552 544 if(RMAP_Answers[i]->transactionID==transactionID)
553 545 {
554 546 this->RMAP_pending_transaction_IDsMtx->lock();
555 547 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
556 548 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
557 549 {
558 550 if(RMAP_pending_transaction_IDs[j]==transactionID)
559 551 {
560 552 RMAP_pending_transaction_IDs.removeAt(j);
561 553 }
562 554 }
563 555 this->RMAP_pending_transaction_IDsMtx->unlock();
564 556 *buffer = RMAP_Answers[i]->data;
565 557 count = RMAP_Answers[i]->len;
566 558 RMAP_Answer* tmp=RMAP_Answers[i];
567 559 RMAP_Answers.removeAt(i);
568 560 delete tmp;
569 561 }
570 562 }
571 563 this->RMAP_AnswersMtx->unlock();
572 564 //if no answer found in the stack wait until a new packet is pushed
573 565 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
574 566 if(*buffer==NULL)
575 567 {
576 568 while (0==this->RMAP_AnswersSem->available())
577 569 {
578 570 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
579 571 if(timeout.elapsed()>=RMAPtimeout)
580 572 {
581 573 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
582 574 return -1;
583 575 }
584 576 usleep(1000);
585 577 }
586 578 this->RMAP_AnswersSem->acquire();
587 579 }
588 580 }
589 581 return count;
590 582 }
591 583
592 584 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
593 585 {
594 586 USB_SPACEWIRE_STATUS result;
595 587 USB_SPACEWIRE_ID pIdentifier;
596 588 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
597 589 this->handleMutex->lock();
598 590 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
599 591 if (result != TRANSFER_SUCCESS)
600 592 {
601 593 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
602 594 this->handleMutex->unlock();
603 595 return false;
604 596 }
605 597 else
606 598 {
607 599 SocExplorerEngine::message(this->plugin,"Packet sent",2);
608 600 USBSpaceWire_FreeSend(hDevice, pIdentifier);
609 601 }
610 602 this->handleMutex->unlock();
611 603 return true;
612 604 }
613 605
614 606 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
615 607 {
616 608 char* packetbuffer = (char*)malloc(len);
617 609 memcpy(packetbuffer,packet,len);
618 610 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
619 611 RMAP_AnswersMtx->lock();
620 612 RMAP_Answers.append(RMPAPpacket);
621 613 RMAP_AnswersMtx->unlock();
622 614 }
623 615
624 616
625 617
626 618
627 619
628 620
629 621
630 622
631 623
632 624
633 625
634 626
635 627
636 628
637 629
638 630
639 631
640 632
641 633
642 634
643 635
644 636
General Comments 0
You need to be logged in to leave comments. Login now