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