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