|
@@
-1,521
+1,522
|
|
1
|
/*------------------------------------------------------------------------------
|
|
1
|
/*------------------------------------------------------------------------------
|
|
2
|
-- This file is a part of the SocExplorer Software
|
|
2
|
-- This file is a part of the SocExplorer Software
|
|
3
|
-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
|
|
3
|
-- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
|
|
4
|
--
|
|
4
|
--
|
|
5
|
-- This program is free software; you can redistribute it and/or modify
|
|
5
|
-- This program is free software; you can redistribute it and/or modify
|
|
6
|
-- it under the terms of the GNU General Public License as published by
|
|
6
|
-- it under the terms of the GNU General Public License as published by
|
|
7
|
-- the Free Software Foundation; either version 3 of the License, or
|
|
7
|
-- the Free Software Foundation; either version 3 of the License, or
|
|
8
|
-- (at your option) any later version.
|
|
8
|
-- (at your option) any later version.
|
|
9
|
--
|
|
9
|
--
|
|
10
|
-- This program is distributed in the hope that it will be useful,
|
|
10
|
-- This program is distributed in the hope that it will be useful,
|
|
11
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-- GNU General Public License for more details.
|
|
13
|
-- GNU General Public License for more details.
|
|
14
|
--
|
|
14
|
--
|
|
15
|
-- You should have received a copy of the GNU General Public License
|
|
15
|
-- You should have received a copy of the GNU General Public License
|
|
16
|
-- along with this program; if not, write to the Free Software
|
|
16
|
-- along with this program; if not, write to the Free Software
|
|
17
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
-------------------------------------------------------------------------------*/
|
|
18
|
-------------------------------------------------------------------------------*/
|
|
19
|
/*-- Author : Alexis Jeandet
|
|
19
|
/*-- Author : Alexis Jeandet
|
|
20
|
-- Mail : alexis.jeandet@member.fsf.org
|
|
20
|
-- Mail : alexis.jeandet@member.fsf.org
|
|
21
|
----------------------------------------------------------------------------*/
|
|
21
|
----------------------------------------------------------------------------*/
|
|
22
|
|
|
22
|
|
|
23
|
#include "stardundeespw_usb.h"
|
|
23
|
#include "stardundeespw_usb.h"
|
|
24
|
#include <socexplorerengine.h>
|
|
24
|
#include <socexplorerengine.h>
|
|
25
|
#include <qhexedit.h>
|
|
25
|
#include <qhexedit.h>
|
|
26
|
|
|
26
|
|
|
27
|
stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
|
|
27
|
stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
|
|
28
|
abstractSpwBridge(parent)
|
|
28
|
abstractSpwBridge(parent)
|
|
29
|
{
|
|
29
|
{
|
|
30
|
Q_UNUSED(parent)
|
|
30
|
Q_UNUSED(parent)
|
|
31
|
this->manager = new stardundeeSPW_USB_Manager(parent,this);
|
|
31
|
this->manager = new stardundeeSPW_USB_Manager(parent,this);
|
|
32
|
makeGUI(socexplorerplugin *parent);
|
|
32
|
makeGUI(parent);
|
|
33
|
this->manager->start();
|
|
33
|
this->manager->start();
|
|
34
|
}
|
|
34
|
}
|
|
35
|
|
|
35
|
|
|
36
|
stardundeeSPW_USB::~stardundeeSPW_USB()
|
|
36
|
stardundeeSPW_USB::~stardundeeSPW_USB()
|
|
37
|
{
|
|
37
|
{
|
|
38
|
this->manager->requestInterruption();
|
|
38
|
this->manager->requestInterruption();
|
|
39
|
delete this->p_GUI;
|
|
39
|
delete this->p_GUI;
|
|
40
|
}
|
|
40
|
}
|
|
41
|
|
|
41
|
|
|
42
|
void stardundeeSPW_USB::toggleBridgeConnection()
|
|
42
|
void stardundeeSPW_USB::toggleBridgeConnection()
|
|
43
|
{
|
|
43
|
{
|
|
44
|
if(this->plugin->isConnected())
|
|
44
|
if(this->plugin->isConnected())
|
|
45
|
{
|
|
45
|
{
|
|
46
|
if(this->disconnectBridge())
|
|
46
|
if(this->disconnectBridge())
|
|
47
|
{
|
|
47
|
{
|
|
48
|
this->connectBridgeButton->setText("Connect");
|
|
48
|
this->connectBridgeButton->setText("Connect");
|
|
49
|
}
|
|
49
|
}
|
|
50
|
}
|
|
50
|
}
|
|
51
|
else
|
|
51
|
else
|
|
52
|
{
|
|
52
|
{
|
|
53
|
if(this->connectBridge())
|
|
53
|
if(this->connectBridge())
|
|
54
|
{
|
|
54
|
{
|
|
55
|
this->connectBridgeButton->setText("Disconnect");
|
|
55
|
this->connectBridgeButton->setText("Disconnect");
|
|
56
|
}
|
|
56
|
}
|
|
57
|
}
|
|
57
|
}
|
|
58
|
}
|
|
58
|
}
|
|
59
|
|
|
59
|
|
|
60
|
bool stardundeeSPW_USB::connectBridge()
|
|
60
|
bool stardundeeSPW_USB::connectBridge()
|
|
61
|
{
|
|
61
|
{
|
|
62
|
return this->manager->connectBridge();
|
|
62
|
return this->manager->connectBridge();
|
|
63
|
}
|
|
63
|
}
|
|
64
|
|
|
64
|
|
|
65
|
bool stardundeeSPW_USB::disconnectBridge()
|
|
65
|
bool stardundeeSPW_USB::disconnectBridge()
|
|
66
|
{
|
|
66
|
{
|
|
67
|
return this->manager->disconnectBridge();
|
|
67
|
return this->manager->disconnectBridge();
|
|
68
|
}
|
|
68
|
}
|
|
69
|
|
|
69
|
|
|
70
|
int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
|
|
70
|
int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
|
|
71
|
{
|
|
71
|
{
|
|
72
|
return this->manager->sendPacket(packet,size);
|
|
72
|
return this->manager->sendPacket(packet,size);
|
|
73
|
}
|
|
73
|
}
|
|
74
|
|
|
74
|
|
|
75
|
unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
|
|
75
|
unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
|
|
76
|
{
|
|
76
|
{
|
|
77
|
char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
|
|
77
|
char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
|
|
78
|
writeBuffer[0]=1;//Link number
|
|
78
|
writeBuffer[0]=1;//Link number
|
|
79
|
int transactionID = 0;
|
|
79
|
int transactionID = 0;
|
|
80
|
int written=0;
|
|
80
|
int written=0;
|
|
81
|
SocExplorerEngine::message(this->plugin,"Enter Write function");
|
|
81
|
SocExplorerEngine::message(this->plugin,"Enter Write function");
|
|
82
|
QProgressBar* progress=NULL;
|
|
82
|
QProgressBar* progress=NULL;
|
|
83
|
if(count>RMAP_MAX_XFER_SIZE)
|
|
83
|
if(count>RMAP_MAX_XFER_SIZE)
|
|
84
|
progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
|
|
84
|
progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
|
|
85
|
//Quite stupide loop, I guess that I always get the number of byte I asked for!
|
|
85
|
//Quite stupide loop, I guess that I always get the number of byte I asked for!
|
|
86
|
while(count>=RMAP_MAX_XFER_SIZE)
|
|
86
|
while(count>=RMAP_MAX_XFER_SIZE)
|
|
87
|
{
|
|
87
|
{
|
|
88
|
for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
|
|
88
|
for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
|
|
89
|
{
|
|
89
|
{
|
|
90
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
|
|
90
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
|
|
91
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
|
|
91
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
|
|
92
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
|
|
92
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
|
|
93
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
|
|
93
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
|
|
94
|
}
|
|
94
|
}
|
|
95
|
RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
|
|
95
|
RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
|
|
96
|
manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
|
|
96
|
manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
|
|
97
|
written+=RMAP_MAX_XFER_SIZE;
|
|
97
|
written+=RMAP_MAX_XFER_SIZE;
|
|
98
|
count-=RMAP_MAX_XFER_SIZE;
|
|
98
|
count-=RMAP_MAX_XFER_SIZE;
|
|
99
|
progress->setValue(written);
|
|
99
|
progress->setValue(written);
|
|
100
|
qApp->processEvents();
|
|
100
|
qApp->processEvents();
|
|
101
|
}
|
|
101
|
}
|
|
102
|
if(count>0)
|
|
102
|
if(count>0)
|
|
103
|
{
|
|
103
|
{
|
|
104
|
for(int i=0;i<((int)count);i++)
|
|
104
|
for(int i=0;i<((int)count);i++)
|
|
105
|
{
|
|
105
|
{
|
|
106
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
|
|
106
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
|
|
107
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
|
|
107
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
|
|
108
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
|
|
108
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
|
|
109
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
|
|
109
|
writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
|
|
110
|
}
|
|
110
|
}
|
|
111
|
RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
|
|
111
|
RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
|
|
112
|
manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
|
|
112
|
manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
|
|
113
|
written+=count;
|
|
113
|
written+=count;
|
|
114
|
if(progress!=NULL)
|
|
114
|
if(progress!=NULL)
|
|
115
|
{
|
|
115
|
{
|
|
116
|
progress->setValue(written);
|
|
116
|
progress->setValue(written);
|
|
117
|
qApp->processEvents();
|
|
117
|
qApp->processEvents();
|
|
118
|
}
|
|
118
|
}
|
|
119
|
}
|
|
119
|
}
|
|
120
|
if(progress!=NULL)
|
|
120
|
if(progress!=NULL)
|
|
121
|
{
|
|
121
|
{
|
|
122
|
SocExplorerEngine::deleteProgressBar(progress);
|
|
122
|
SocExplorerEngine::deleteProgressBar(progress);
|
|
123
|
}
|
|
123
|
}
|
|
124
|
return written;
|
|
124
|
return written;
|
|
125
|
}
|
|
125
|
}
|
|
126
|
|
|
126
|
|
|
127
|
unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
|
|
127
|
unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
|
|
128
|
{
|
|
128
|
{
|
|
129
|
char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
|
|
129
|
char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
|
|
130
|
char* RMAP_AnswerBuffer;
|
|
130
|
char* RMAP_AnswerBuffer;
|
|
131
|
requestBuffer[0]=1;//Link number
|
|
131
|
requestBuffer[0]=1;//Link number
|
|
132
|
int transactionID = 0;
|
|
132
|
int transactionID = 0;
|
|
133
|
int read=0;
|
|
133
|
int read=0;
|
|
134
|
QProgressBar* progress=NULL;
|
|
134
|
QProgressBar* progress=NULL;
|
|
135
|
if(count>RMAP_MAX_XFER_SIZE)
|
|
135
|
if(count>RMAP_MAX_XFER_SIZE)
|
|
136
|
progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
|
|
136
|
progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
|
|
137
|
SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
|
|
137
|
SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
|
|
138
|
|
|
138
|
|
|
139
|
//Quite stupide loop, I guess that I always get the number of byte I asked for!
|
|
139
|
//Quite stupide loop, I guess that I always get the number of byte I asked for!
|
|
140
|
while((int)count>=(int)RMAP_MAX_XFER_SIZE)
|
|
140
|
while((int)count>=(int)RMAP_MAX_XFER_SIZE)
|
|
141
|
{
|
|
141
|
{
|
|
142
|
transactionID = manager->getRMAPtransactionID();
|
|
142
|
transactionID = manager->getRMAPtransactionID();
|
|
143
|
SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
|
|
143
|
SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
|
|
144
|
RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
|
|
144
|
RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
|
|
145
|
manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
|
|
145
|
manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
|
|
146
|
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
|
|
146
|
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
|
|
147
|
for(int i=0;i<((len-13)/4);i++)
|
|
147
|
for(int i=0;i<((len-13)/4);i++)
|
|
148
|
{
|
|
148
|
{
|
|
149
|
Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
|
|
149
|
Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
|
|
150
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
|
|
150
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
|
|
151
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
|
|
151
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
|
|
152
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
|
|
152
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
|
|
153
|
}
|
|
153
|
}
|
|
154
|
free(RMAP_AnswerBuffer);
|
|
154
|
free(RMAP_AnswerBuffer);
|
|
155
|
read+=RMAP_MAX_XFER_SIZE;
|
|
155
|
read+=RMAP_MAX_XFER_SIZE;
|
|
156
|
count-=RMAP_MAX_XFER_SIZE;
|
|
156
|
count-=RMAP_MAX_XFER_SIZE;
|
|
157
|
progress->setValue(read);
|
|
157
|
progress->setValue(read);
|
|
158
|
qApp->processEvents();
|
|
158
|
qApp->processEvents();
|
|
159
|
}
|
|
159
|
}
|
|
160
|
if((int)count>0)
|
|
160
|
if((int)count>0)
|
|
161
|
{
|
|
161
|
{
|
|
162
|
transactionID = manager->getRMAPtransactionID();
|
|
162
|
transactionID = manager->getRMAPtransactionID();
|
|
163
|
SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
|
|
163
|
SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
|
|
164
|
SocExplorerEngine::message(this->plugin,QString("Building request with:"));
|
|
164
|
SocExplorerEngine::message(this->plugin,QString("Building request with:"));
|
|
165
|
SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
|
|
165
|
SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
|
|
166
|
SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
|
|
166
|
SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
|
|
167
|
SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
|
|
167
|
SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
|
|
168
|
RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
|
|
168
|
RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
|
|
169
|
manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
|
|
169
|
manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
|
|
170
|
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
|
|
170
|
int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
|
|
171
|
for(int i=0;i<((len-13)/4);i++)
|
|
171
|
for(int i=0;i<((len-13)/4);i++)
|
|
172
|
{
|
|
172
|
{
|
|
173
|
Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
|
|
173
|
Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
|
|
174
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
|
|
174
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
|
|
175
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
|
|
175
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
|
|
176
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
|
|
176
|
Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
|
|
177
|
}
|
|
177
|
}
|
|
178
|
free(RMAP_AnswerBuffer);
|
|
178
|
free(RMAP_AnswerBuffer);
|
|
179
|
read+=count;
|
|
179
|
read+=count;
|
|
180
|
if(progress!=NULL)
|
|
180
|
if(progress!=NULL)
|
|
181
|
{
|
|
181
|
{
|
|
182
|
progress->setValue(read);
|
|
182
|
progress->setValue(read);
|
|
183
|
qApp->processEvents();
|
|
183
|
qApp->processEvents();
|
|
184
|
}
|
|
184
|
}
|
|
185
|
}
|
|
185
|
}
|
|
186
|
if(progress!=NULL)
|
|
186
|
if(progress!=NULL)
|
|
187
|
{
|
|
187
|
{
|
|
188
|
SocExplorerEngine::deleteProgressBar(progress);
|
|
188
|
SocExplorerEngine::deleteProgressBar(progress);
|
|
189
|
}
|
|
189
|
}
|
|
190
|
return read;
|
|
190
|
return read;
|
|
191
|
}
|
|
191
|
}
|
|
192
|
|
|
192
|
|
|
|
|
|
193
|
void stardundeeSPW_USB::updateAvailableBrickCount(int count)
|
|
|
|
|
194
|
{
|
|
|
|
|
195
|
|
|
|
|
|
196
|
}
|
|
|
|
|
197
|
|
|
193
|
void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
|
|
198
|
void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
|
|
194
|
{
|
|
199
|
{
|
|
195
|
this->p_GUI = new QWidget(parent);
|
|
200
|
this->p_GUI = new StarDundeeGUI(plugin);
|
|
196
|
this->mainLayout = new QGridLayout(this->p_GUI);
|
|
201
|
this->mainLayout = new QGridLayout(this->p_GUI);
|
|
197
|
this->p_GUI->setLayout(mainLayout);
|
|
202
|
// connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
|
|
198
|
this->connectBridgeButton = new QPushButton("Connect");
|
|
|
|
|
199
|
this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1);
|
|
|
|
|
200
|
connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
|
|
|
|
|
201
|
}
|
|
203
|
}
|
|
202
|
|
|
204
|
|
|
203
|
stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
|
|
205
|
stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
|
|
204
|
:QThread((QObject*)parent)
|
|
206
|
:QThread((QObject*)parent)
|
|
205
|
{
|
|
207
|
{
|
|
206
|
this->handleMutex = new QMutex(QMutex::NonRecursive);
|
|
208
|
this->handleMutex = new QMutex(QMutex::NonRecursive);
|
|
207
|
this->RMAP_AnswersSem = new QSemaphore(0);
|
|
209
|
this->RMAP_AnswersSem = new QSemaphore(0);
|
|
208
|
this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
|
|
210
|
this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
|
|
209
|
this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
|
|
211
|
this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
|
|
210
|
this->plugin = plugin;
|
|
212
|
this->plugin = plugin;
|
|
211
|
connected = false;
|
|
213
|
connected = false;
|
|
212
|
}
|
|
214
|
}
|
|
213
|
|
|
215
|
|
|
214
|
stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
|
|
216
|
stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
|
|
215
|
{
|
|
217
|
{
|
|
216
|
this->terminate();
|
|
218
|
this->terminate();
|
|
217
|
while (!this->isFinished()) {
|
|
219
|
while (!this->isFinished()) {
|
|
218
|
this->usleep(1000);
|
|
220
|
this->usleep(1000);
|
|
219
|
}
|
|
221
|
}
|
|
220
|
}
|
|
222
|
}
|
|
221
|
|
|
223
|
|
|
222
|
|
|
224
|
|
|
223
|
void stardundeeSPW_USB_Manager::run()
|
|
225
|
void stardundeeSPW_USB_Manager::run()
|
|
224
|
{
|
|
226
|
{
|
|
225
|
USB_SPACEWIRE_PACKET_PROPERTIES properties;
|
|
227
|
USB_SPACEWIRE_PACKET_PROPERTIES properties;
|
|
226
|
USB_SPACEWIRE_ID pIdentifier=NULL;
|
|
228
|
USB_SPACEWIRE_ID pIdentifier=NULL;
|
|
227
|
USB_SPACEWIRE_STATUS stat;
|
|
229
|
USB_SPACEWIRE_STATUS stat;
|
|
228
|
SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
|
|
230
|
SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
|
|
229
|
char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
|
|
231
|
char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
|
|
230
|
while (!this->isInterruptionRequested())
|
|
232
|
while (!this->isInterruptionRequested())
|
|
231
|
{
|
|
233
|
{
|
|
232
|
if(this->connected)
|
|
234
|
if(this->connected)
|
|
233
|
{
|
|
235
|
{
|
|
234
|
handleMutex->lock();
|
|
236
|
handleMutex->lock();
|
|
235
|
//SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
|
|
237
|
//SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
|
|
236
|
if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
|
|
238
|
if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
|
|
237
|
{
|
|
239
|
{
|
|
238
|
SocExplorerEngine::message(this->plugin,"Got packet");
|
|
240
|
SocExplorerEngine::message(this->plugin,"Got packet");
|
|
239
|
stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
|
|
241
|
stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
|
|
240
|
if (stat == TRANSFER_SUCCESS)
|
|
242
|
if (stat == TRANSFER_SUCCESS)
|
|
241
|
{
|
|
243
|
{
|
|
242
|
if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
|
|
244
|
if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
|
|
243
|
{
|
|
245
|
{
|
|
244
|
SocExplorerEngine::message(this->plugin,"It's a SPW packet");
|
|
246
|
SocExplorerEngine::message(this->plugin,"It's a SPW packet");
|
|
245
|
if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
|
|
247
|
if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
|
|
246
|
{
|
|
248
|
{
|
|
247
|
SocExplorerEngine::message(this->plugin,"Got end of packet");
|
|
249
|
SocExplorerEngine::message(this->plugin,"Got end of packet");
|
|
248
|
if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
|
|
250
|
if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
|
|
249
|
{
|
|
251
|
{
|
|
250
|
SocExplorerEngine::message(this->plugin,"Got RMAP packet");
|
|
252
|
SocExplorerEngine::message(this->plugin,"Got RMAP packet");
|
|
251
|
SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
|
|
253
|
SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
|
|
252
|
if(properties.len>8)
|
|
254
|
if(properties.len>8)
|
|
253
|
{
|
|
255
|
{
|
|
254
|
char* packetbuffer = (char*)malloc(properties.len);
|
|
256
|
char* packetbuffer = (char*)malloc(properties.len);
|
|
255
|
memcpy(packetbuffer,buffer,properties.len);
|
|
257
|
memcpy(packetbuffer,buffer,properties.len);
|
|
256
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
258
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
257
|
pIdentifier = NULL;
|
|
259
|
pIdentifier = NULL;
|
|
258
|
handleMutex->unlock();
|
|
260
|
handleMutex->unlock();
|
|
259
|
RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
|
|
261
|
RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
|
|
260
|
RMAP_AnswersMtx->lock();
|
|
262
|
RMAP_AnswersMtx->lock();
|
|
261
|
RMAP_Answers.append(packet);
|
|
263
|
RMAP_Answers.append(packet);
|
|
262
|
RMAP_AnswersMtx->unlock();
|
|
264
|
RMAP_AnswersMtx->unlock();
|
|
263
|
RMAP_AnswersSem->release();
|
|
265
|
RMAP_AnswersSem->release();
|
|
264
|
|
|
266
|
|
|
265
|
}
|
|
267
|
}
|
|
266
|
else //it's a RMAP write response
|
|
268
|
else //it's a RMAP write response
|
|
267
|
{
|
|
269
|
{
|
|
268
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
270
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
269
|
pIdentifier = NULL;
|
|
271
|
pIdentifier = NULL;
|
|
270
|
handleMutex->unlock();
|
|
272
|
handleMutex->unlock();
|
|
271
|
}
|
|
273
|
}
|
|
272
|
|
|
274
|
|
|
273
|
}
|
|
275
|
}
|
|
274
|
else //any non-rmap packet will be pushed to the network
|
|
276
|
else //any non-rmap packet will be pushed to the network
|
|
275
|
{
|
|
277
|
{
|
|
276
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
278
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
277
|
handleMutex->unlock();
|
|
279
|
handleMutex->unlock();
|
|
278
|
SocExplorerEngine::message(this->plugin,"Got SPW packet");
|
|
280
|
SocExplorerEngine::message(this->plugin,"Got SPW packet");
|
|
279
|
}
|
|
281
|
}
|
|
280
|
}
|
|
282
|
}
|
|
281
|
else
|
|
283
|
else
|
|
282
|
{
|
|
284
|
{
|
|
283
|
SocExplorerEngine::message(this->plugin,"No EOP received");
|
|
285
|
SocExplorerEngine::message(this->plugin,"No EOP received");
|
|
284
|
}
|
|
286
|
}
|
|
285
|
}
|
|
287
|
}
|
|
286
|
|
|
288
|
|
|
287
|
}
|
|
289
|
}
|
|
288
|
else
|
|
290
|
else
|
|
289
|
{
|
|
291
|
{
|
|
290
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
292
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
291
|
handleMutex->unlock();
|
|
293
|
handleMutex->unlock();
|
|
292
|
}
|
|
294
|
}
|
|
293
|
}
|
|
295
|
}
|
|
294
|
else
|
|
296
|
else
|
|
295
|
{
|
|
297
|
{
|
|
296
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
298
|
USBSpaceWire_FreeRead(hDevice, pIdentifier);
|
|
297
|
handleMutex->unlock();
|
|
299
|
handleMutex->unlock();
|
|
298
|
}
|
|
300
|
}
|
|
299
|
}
|
|
301
|
}
|
|
300
|
else
|
|
302
|
else
|
|
301
|
{
|
|
303
|
{
|
|
302
|
sleep(1);
|
|
304
|
sleep(1);
|
|
303
|
SocExplorerEngine::message(this->plugin,"Bridge not connected");
|
|
305
|
this->brickList = USBSpaceWire_ListDevices();
|
|
304
|
}
|
|
306
|
}
|
|
305
|
usleep(1000);
|
|
307
|
usleep(1000);
|
|
306
|
// sleep(2);
|
|
|
|
|
307
|
}
|
|
308
|
}
|
|
308
|
SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
|
|
309
|
SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
|
|
309
|
}
|
|
310
|
}
|
|
310
|
|
|
311
|
|
|
311
|
bool stardundeeSPW_USB_Manager::connectBridge()
|
|
312
|
bool stardundeeSPW_USB_Manager::connectBridge()
|
|
312
|
{
|
|
313
|
{
|
|
313
|
this->handleMutex->lock();
|
|
314
|
this->handleMutex->lock();
|
|
314
|
int status;
|
|
315
|
int status;
|
|
315
|
U32 statusControl;
|
|
316
|
U32 statusControl;
|
|
316
|
int brickNumber=0;
|
|
317
|
int brickNumber=0;
|
|
317
|
int linkNumber=1;
|
|
318
|
int linkNumber=1;
|
|
318
|
this->connected = false;
|
|
319
|
this->connected = false;
|
|
319
|
if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
|
|
320
|
if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
|
|
320
|
{
|
|
321
|
{
|
|
321
|
SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
|
|
322
|
SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
|
|
322
|
this->handleMutex->unlock();
|
|
323
|
this->handleMutex->unlock();
|
|
323
|
return false;
|
|
324
|
return false;
|
|
324
|
}
|
|
325
|
}
|
|
325
|
SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
|
|
326
|
SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
|
|
326
|
|
|
327
|
|
|
327
|
USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
|
|
328
|
USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
|
|
328
|
CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
|
|
329
|
CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
|
|
329
|
CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
|
|
330
|
CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
|
|
330
|
|
|
331
|
|
|
331
|
// Set the path and return path to the device
|
|
332
|
// Set the path and return path to the device
|
|
332
|
CFGSpaceWire_StackClear();
|
|
333
|
CFGSpaceWire_StackClear();
|
|
333
|
CFGSpaceWire_AddrStackPush(0);
|
|
334
|
CFGSpaceWire_AddrStackPush(0);
|
|
334
|
CFGSpaceWire_AddrStackPush(254);
|
|
335
|
CFGSpaceWire_AddrStackPush(254);
|
|
335
|
CFGSpaceWire_RetAddrStackPush(254);
|
|
336
|
CFGSpaceWire_RetAddrStackPush(254);
|
|
336
|
// set the base transmit rate to 100 MHz
|
|
337
|
// set the base transmit rate to 100 MHz
|
|
337
|
status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
|
|
338
|
status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
|
|
338
|
if (status != CFG_TRANSFER_SUCCESS)
|
|
339
|
if (status != CFG_TRANSFER_SUCCESS)
|
|
339
|
{
|
|
340
|
{
|
|
340
|
SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
|
|
341
|
SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
|
|
341
|
return false;
|
|
342
|
return false;
|
|
342
|
}
|
|
343
|
}
|
|
343
|
else
|
|
344
|
else
|
|
344
|
{
|
|
345
|
{
|
|
345
|
SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
|
|
346
|
SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
|
|
346
|
}
|
|
347
|
}
|
|
347
|
|
|
348
|
|
|
348
|
// read the link status
|
|
349
|
// read the link status
|
|
349
|
if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
|
|
350
|
if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
|
|
350
|
{
|
|
351
|
{
|
|
351
|
SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
|
|
352
|
SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
|
|
352
|
return false;
|
|
353
|
return false;
|
|
353
|
}
|
|
354
|
}
|
|
354
|
else
|
|
355
|
else
|
|
355
|
{
|
|
356
|
{
|
|
356
|
SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
|
|
357
|
SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
|
|
357
|
|
|
358
|
|
|
358
|
// Set the link status control register properties
|
|
359
|
// Set the link status control register properties
|
|
359
|
CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
|
|
360
|
CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
|
|
360
|
CFGSpaceWire_LSEnableStart(&statusControl, 1);
|
|
361
|
CFGSpaceWire_LSEnableStart(&statusControl, 1);
|
|
361
|
CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
|
|
362
|
CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
|
|
362
|
CFGSpaceWire_LSEnableTristate(&statusControl, 0);
|
|
363
|
CFGSpaceWire_LSEnableTristate(&statusControl, 0);
|
|
363
|
CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
|
|
364
|
CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
|
|
364
|
|
|
365
|
|
|
365
|
// Set the link status control register
|
|
366
|
// Set the link status control register
|
|
366
|
if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
|
|
367
|
if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
|
|
367
|
{
|
|
368
|
{
|
|
368
|
SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
|
|
369
|
SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
|
|
369
|
return false;
|
|
370
|
return false;
|
|
370
|
}
|
|
371
|
}
|
|
371
|
else
|
|
372
|
else
|
|
372
|
{
|
|
373
|
{
|
|
373
|
SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
|
|
374
|
SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
|
|
374
|
}
|
|
375
|
}
|
|
375
|
}
|
|
376
|
}
|
|
376
|
|
|
377
|
|
|
377
|
if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
|
|
378
|
if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
|
|
378
|
{
|
|
379
|
{
|
|
379
|
SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
|
|
380
|
SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
|
|
380
|
return false;
|
|
381
|
return false;
|
|
381
|
}
|
|
382
|
}
|
|
382
|
else
|
|
383
|
else
|
|
383
|
{
|
|
384
|
{
|
|
384
|
SocExplorerEngine::message(this->plugin,"Device set to be an interface");
|
|
385
|
SocExplorerEngine::message(this->plugin,"Device set to be an interface");
|
|
385
|
}
|
|
386
|
}
|
|
386
|
|
|
387
|
|
|
387
|
USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
|
|
388
|
USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
|
|
388
|
USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
|
|
389
|
USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
|
|
389
|
USBSpaceWire_SetTimeout(hDevice,1.0);
|
|
390
|
USBSpaceWire_SetTimeout(hDevice,1.0);
|
|
390
|
SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
|
|
391
|
SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
|
|
391
|
SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
|
|
392
|
SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
|
|
392
|
SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
|
|
393
|
SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
|
|
393
|
this->connected = true;
|
|
394
|
this->connected = true;
|
|
394
|
this->handleMutex->unlock();
|
|
395
|
this->handleMutex->unlock();
|
|
395
|
return true;
|
|
396
|
return true;
|
|
396
|
}
|
|
397
|
}
|
|
397
|
|
|
398
|
|
|
398
|
bool stardundeeSPW_USB_Manager::disconnectBridge()
|
|
399
|
bool stardundeeSPW_USB_Manager::disconnectBridge()
|
|
399
|
{
|
|
400
|
{
|
|
400
|
this->handleMutex->lock();
|
|
401
|
this->handleMutex->lock();
|
|
401
|
USBSpaceWire_Close(hDevice); // Close the device
|
|
402
|
USBSpaceWire_Close(hDevice); // Close the device
|
|
402
|
SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
|
|
403
|
SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
|
|
403
|
USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
|
|
404
|
USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
|
|
404
|
this->handleMutex->unlock();
|
|
405
|
this->handleMutex->unlock();
|
|
405
|
return true;
|
|
406
|
return true;
|
|
406
|
}
|
|
407
|
}
|
|
407
|
|
|
408
|
|
|
408
|
int stardundeeSPW_USB_Manager::getRMAPtransactionID()
|
|
409
|
int stardundeeSPW_USB_Manager::getRMAPtransactionID()
|
|
409
|
{
|
|
410
|
{
|
|
410
|
this->RMAP_pending_transaction_IDsMtx->lock();
|
|
411
|
this->RMAP_pending_transaction_IDsMtx->lock();
|
|
411
|
int ID=0;
|
|
412
|
int ID=0;
|
|
412
|
bool found=true;
|
|
413
|
bool found=true;
|
|
413
|
while(ID<65536)
|
|
414
|
while(ID<65536)
|
|
414
|
{
|
|
415
|
{
|
|
415
|
for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
|
|
416
|
for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
|
|
416
|
{
|
|
417
|
{
|
|
417
|
if(RMAP_pending_transaction_IDs[i]==ID)found=false;
|
|
418
|
if(RMAP_pending_transaction_IDs[i]==ID)found=false;
|
|
418
|
}
|
|
419
|
}
|
|
419
|
if(found==true)break;
|
|
420
|
if(found==true)break;
|
|
420
|
ID++;
|
|
421
|
ID++;
|
|
421
|
found = true;
|
|
422
|
found = true;
|
|
422
|
}
|
|
423
|
}
|
|
423
|
if(found)
|
|
424
|
if(found)
|
|
424
|
{
|
|
425
|
{
|
|
425
|
RMAP_pending_transaction_IDs.append(ID);
|
|
426
|
RMAP_pending_transaction_IDs.append(ID);
|
|
426
|
}
|
|
427
|
}
|
|
427
|
this->RMAP_pending_transaction_IDsMtx->unlock();
|
|
428
|
this->RMAP_pending_transaction_IDsMtx->unlock();
|
|
428
|
return ID;
|
|
429
|
return ID;
|
|
429
|
}
|
|
430
|
}
|
|
430
|
|
|
431
|
|
|
431
|
int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
|
|
432
|
int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
|
|
432
|
{
|
|
433
|
{
|
|
433
|
*buffer=NULL;
|
|
434
|
*buffer=NULL;
|
|
434
|
int count=0;
|
|
435
|
int count=0;
|
|
435
|
while (*buffer==NULL)
|
|
436
|
while (*buffer==NULL)
|
|
436
|
{
|
|
437
|
{
|
|
437
|
this->RMAP_AnswersMtx->lock();
|
|
438
|
this->RMAP_AnswersMtx->lock();
|
|
438
|
for(int i=0;i<RMAP_Answers.count();i++)
|
|
439
|
for(int i=0;i<RMAP_Answers.count();i++)
|
|
439
|
{
|
|
440
|
{
|
|
440
|
if(RMAP_Answers[i]->transactionID==transactionID)
|
|
441
|
if(RMAP_Answers[i]->transactionID==transactionID)
|
|
441
|
{
|
|
442
|
{
|
|
442
|
this->RMAP_pending_transaction_IDsMtx->lock();
|
|
443
|
this->RMAP_pending_transaction_IDsMtx->lock();
|
|
443
|
for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
|
|
444
|
for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
|
|
444
|
{
|
|
445
|
{
|
|
445
|
if(RMAP_pending_transaction_IDs[j]==transactionID)
|
|
446
|
if(RMAP_pending_transaction_IDs[j]==transactionID)
|
|
446
|
{
|
|
447
|
{
|
|
447
|
RMAP_pending_transaction_IDs.removeAt(j);
|
|
448
|
RMAP_pending_transaction_IDs.removeAt(j);
|
|
448
|
}
|
|
449
|
}
|
|
449
|
}
|
|
450
|
}
|
|
450
|
this->RMAP_pending_transaction_IDsMtx->unlock();
|
|
451
|
this->RMAP_pending_transaction_IDsMtx->unlock();
|
|
451
|
*buffer = RMAP_Answers[i]->data;
|
|
452
|
*buffer = RMAP_Answers[i]->data;
|
|
452
|
count = RMAP_Answers[i]->len;
|
|
453
|
count = RMAP_Answers[i]->len;
|
|
453
|
RMAP_Answer* tmp=RMAP_Answers[i];
|
|
454
|
RMAP_Answer* tmp=RMAP_Answers[i];
|
|
454
|
RMAP_Answers.removeAt(i);
|
|
455
|
RMAP_Answers.removeAt(i);
|
|
455
|
delete tmp;
|
|
456
|
delete tmp;
|
|
456
|
}
|
|
457
|
}
|
|
457
|
}
|
|
458
|
}
|
|
458
|
this->RMAP_AnswersMtx->unlock();
|
|
459
|
this->RMAP_AnswersMtx->unlock();
|
|
459
|
//if no answer found in the stack wait until a new packet is pushed
|
|
460
|
//if no answer found in the stack wait until a new packet is pushed
|
|
460
|
if(!buffer)
|
|
461
|
if(!buffer)
|
|
461
|
{
|
|
462
|
{
|
|
462
|
SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
|
|
463
|
SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
|
|
463
|
this->RMAP_AnswersSem->acquire();
|
|
464
|
this->RMAP_AnswersSem->acquire();
|
|
464
|
}
|
|
465
|
}
|
|
465
|
}
|
|
466
|
}
|
|
466
|
return count;
|
|
467
|
return count;
|
|
467
|
}
|
|
468
|
}
|
|
468
|
|
|
469
|
|
|
469
|
bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
|
|
470
|
bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
|
|
470
|
{
|
|
471
|
{
|
|
471
|
USB_SPACEWIRE_STATUS result;
|
|
472
|
USB_SPACEWIRE_STATUS result;
|
|
472
|
USB_SPACEWIRE_ID pIdentifier;
|
|
473
|
USB_SPACEWIRE_ID pIdentifier;
|
|
473
|
SocExplorerEngine::message(this->plugin,"Sending SPW packet");
|
|
474
|
SocExplorerEngine::message(this->plugin,"Sending SPW packet");
|
|
474
|
this->handleMutex->lock();
|
|
475
|
this->handleMutex->lock();
|
|
475
|
result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
|
|
476
|
result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
|
|
476
|
if (result != TRANSFER_SUCCESS)
|
|
477
|
if (result != TRANSFER_SUCCESS)
|
|
477
|
{
|
|
478
|
{
|
|
478
|
SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
|
|
479
|
SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
|
|
479
|
this->handleMutex->unlock();
|
|
480
|
this->handleMutex->unlock();
|
|
480
|
return false;
|
|
481
|
return false;
|
|
481
|
}
|
|
482
|
}
|
|
482
|
else
|
|
483
|
else
|
|
483
|
{
|
|
484
|
{
|
|
484
|
SocExplorerEngine::message(this->plugin,"Packet sent");
|
|
485
|
SocExplorerEngine::message(this->plugin,"Packet sent");
|
|
485
|
USBSpaceWire_FreeSend(hDevice, pIdentifier);
|
|
486
|
USBSpaceWire_FreeSend(hDevice, pIdentifier);
|
|
486
|
}
|
|
487
|
}
|
|
487
|
this->handleMutex->unlock();
|
|
488
|
this->handleMutex->unlock();
|
|
488
|
return true;
|
|
489
|
return true;
|
|
489
|
}
|
|
490
|
}
|
|
490
|
|
|
491
|
|
|
491
|
void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
|
|
492
|
void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
|
|
492
|
{
|
|
493
|
{
|
|
493
|
char* packetbuffer = (char*)malloc(len);
|
|
494
|
char* packetbuffer = (char*)malloc(len);
|
|
494
|
memcpy(packetbuffer,packet,len);
|
|
495
|
memcpy(packetbuffer,packet,len);
|
|
495
|
RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
|
|
496
|
RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
|
|
496
|
RMAP_AnswersMtx->lock();
|
|
497
|
RMAP_AnswersMtx->lock();
|
|
497
|
RMAP_Answers.append(RMPAPpacket);
|
|
498
|
RMAP_Answers.append(RMPAPpacket);
|
|
498
|
RMAP_AnswersMtx->unlock();
|
|
499
|
RMAP_AnswersMtx->unlock();
|
|
499
|
}
|
|
500
|
}
|
|
500
|
|
|
501
|
|
|
501
|
|
|
502
|
|
|
502
|
|
|
503
|
|
|
503
|
|
|
504
|
|
|
504
|
|
|
505
|
|
|
505
|
|
|
506
|
|
|
506
|
|
|
507
|
|
|
507
|
|
|
508
|
|
|
508
|
|
|
509
|
|
|
509
|
|
|
510
|
|
|
510
|
|
|
511
|
|
|
511
|
|
|
512
|
|
|
512
|
|
|
513
|
|
|
513
|
|
|
514
|
|
|
514
|
|
|
515
|
|
|
515
|
|
|
516
|
|
|
516
|
|
|
517
|
|
|
517
|
|
|
518
|
|
|
518
|
|
|
519
|
|
|
519
|
|
|
520
|
|
|
520
|
|
|
521
|
|
|
521
|
|
|
522
|
|