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