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