@@ -1,29 +1,51 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #include "abstractspwbridge.h" |
|
22 | #include "abstractspwbridge.h" | |
2 |
|
23 | |||
3 | abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent) |
|
24 | abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent) | |
4 | :QObject((QObject*)parent) |
|
25 | :QObject((QObject*)parent) | |
5 | { |
|
26 | { | |
6 | this->plugin = parent; |
|
27 | this->plugin = parent; | |
|
28 | this->p_GUI=NULL; | |||
7 | } |
|
29 | } | |
8 |
|
30 | |||
9 | QWidget *abstractSpwBridge::getGUI() |
|
31 | QWidget *abstractSpwBridge::getGUI() | |
10 | { |
|
32 | { | |
11 | return this->p_GUI; |
|
33 | return this->p_GUI; | |
12 | } |
|
34 | } | |
13 |
|
35 | |||
14 | bool abstractSpwBridge::connectBridge() |
|
36 | bool abstractSpwBridge::connectBridge() | |
15 | { |
|
37 | { | |
16 | return false; |
|
38 | return false; | |
17 | } |
|
39 | } | |
18 |
|
40 | |||
19 | bool abstractSpwBridge::disconnectBridge() |
|
41 | bool abstractSpwBridge::disconnectBridge() | |
20 | { |
|
42 | { | |
21 | return false; |
|
43 | return false; | |
22 | } |
|
44 | } | |
23 |
|
45 | |||
24 |
|
46 | |||
25 |
|
47 | |||
26 |
|
48 | |||
27 |
|
49 | |||
28 |
|
50 | |||
29 |
|
51 |
@@ -1,29 +1,50 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #ifndef ABSTRACTSPWBRIDGE_H |
|
22 | #ifndef ABSTRACTSPWBRIDGE_H | |
2 | #define ABSTRACTSPWBRIDGE_H |
|
23 | #define ABSTRACTSPWBRIDGE_H | |
3 |
|
24 | |||
4 | #include <QObject> |
|
25 | #include <QObject> | |
5 | #include <socexplorerplugin.h> |
|
26 | #include <socexplorerplugin.h> | |
6 | #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes |
|
27 | #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes | |
7 | #include <spw.h> |
|
28 | #include <spw.h> | |
8 |
|
29 | |||
9 | class abstractSpwBridge : public QObject |
|
30 | class abstractSpwBridge : public QObject | |
10 | { |
|
31 | { | |
11 | Q_OBJECT |
|
32 | Q_OBJECT | |
12 | public: |
|
33 | public: | |
13 | explicit abstractSpwBridge(socexplorerplugin *parent); |
|
34 | explicit abstractSpwBridge(socexplorerplugin *parent); | |
14 | QWidget *getGUI(); |
|
35 | QWidget *getGUI(); | |
15 |
|
36 | |||
16 | public slots: |
|
37 | public slots: | |
17 | virtual bool connectBridge(); |
|
38 | virtual bool connectBridge(); | |
18 | virtual bool disconnectBridge(); |
|
39 | virtual bool disconnectBridge(); | |
19 | virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0; |
|
40 | virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0; | |
20 | virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0; |
|
41 | virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0; | |
21 | virtual int pushRMAPPacket(char* packet,int size)=0; |
|
42 | virtual int pushRMAPPacket(char* packet,int size)=0; | |
22 | protected: |
|
43 | protected: | |
23 | socexplorerplugin* plugin; |
|
44 | socexplorerplugin* plugin; | |
24 | QWidget* p_GUI; |
|
45 | QWidget* p_GUI; | |
25 | private: |
|
46 | private: | |
26 |
|
47 | |||
27 | }; |
|
48 | }; | |
28 |
|
49 | |||
29 | #endif // ABSTRACTSPWBRIDGE_H |
|
50 | #endif // ABSTRACTSPWBRIDGE_H |
@@ -1,192 +1,213 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #ifndef SPW_H |
|
22 | #ifndef SPW_H | |
2 | #define SPW_H |
|
23 | #define SPW_H | |
3 | #include <stdint.h> |
|
24 | #include <stdint.h> | |
4 |
|
25 | |||
5 | /* |
|
26 | /* | |
6 | βββββββββββββββ βββ βββ βββββββ βββββββ ββββ ββββββββ ββββ βββββββ ββββ βββ |
|
27 | βββββββββββββββ βββ βββ βββββββ βββββββ ββββ ββββββββ ββββ βββββββ ββββ βββ | |
7 | βββββββββββββββββββ βββ ββββββββββββββββββββββ ββββββββββ βββββββββββββββββββ βββ |
|
28 | βββββββββββββββββββ βββ ββββββββββββββββββββββ ββββββββββ βββββββββββββββββββ βββ | |
8 | βββββββββββββββββββ ββ βββ βββ βββ ββββββββββββββββββββββββββββ βββββββββ βββ |
|
29 | βββββββββββββββββββ ββ βββ βββ βββ ββββββββββββββββββββββββββββ βββββββββ βββ | |
9 | βββββββββββββββ ββββββββββ βββ βββ ββββββββββββββββββββββββββββ βββββββββββββ |
|
30 | βββββββββββββββ ββββββββββ βββ βββ ββββββββββββββββββββββββββββ βββββββββββββ | |
10 | βββββββββββ ββββββββββ ββββββββββββββββββββ βββ ββββββ βββ βββββββββββββββ ββββββ |
|
31 | βββββββββββ ββββββββββ ββββββββββββββββββββ βββ ββββββ βββ βββββββββββββββ ββββββ | |
11 | βββββββββββ ββββββββ βββββββ βββββββ βββ ββββββ βββ βββββββ βββ βββββ |
|
32 | βββββββββββ ββββββββ βββββββ βββββββ βββ ββββββ βββ βββββββ βββ βββββ | |
12 | */ |
|
33 | */ | |
13 |
|
34 | |||
14 | enum SPW_PROTOCOL_IDs{ |
|
35 | enum SPW_PROTOCOL_IDs{ | |
15 | SPW_PROTO_ID_EXTEND =0, |
|
36 | SPW_PROTO_ID_EXTEND =0, | |
16 | SPW_PROTO_ID_RMAP = 1, |
|
37 | SPW_PROTO_ID_RMAP = 1, | |
17 | SPW_PROTO_ID_CCSDS = 2, |
|
38 | SPW_PROTO_ID_CCSDS = 2, | |
18 | SPW_PROTO_ID_GOES_R = 238, |
|
39 | SPW_PROTO_ID_GOES_R = 238, | |
19 | SPW_PROTO_ID_STUP = 239 |
|
40 | SPW_PROTO_ID_STUP = 239 | |
20 | }; |
|
41 | }; | |
21 |
|
42 | |||
22 | static const unsigned char SPW_CRCTable[] = { |
|
43 | static const unsigned char SPW_CRCTable[] = { | |
23 | 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75, |
|
44 | 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75, | |
24 | 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b, |
|
45 | 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b, | |
25 | 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69, |
|
46 | 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69, | |
26 | 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67, |
|
47 | 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67, | |
27 | 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d, |
|
48 | 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d, | |
28 | 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43, |
|
49 | 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43, | |
29 | 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51, |
|
50 | 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51, | |
30 | 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f, |
|
51 | 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f, | |
31 | 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05, |
|
52 | 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05, | |
32 | 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b, |
|
53 | 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b, | |
33 | 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19, |
|
54 | 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19, | |
34 | 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17, |
|
55 | 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17, | |
35 | 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d, |
|
56 | 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d, | |
36 | 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33, |
|
57 | 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33, | |
37 | 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21, |
|
58 | 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21, | |
38 | 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f, |
|
59 | 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f, | |
39 | 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95, |
|
60 | 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95, | |
40 | 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b, |
|
61 | 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b, | |
41 | 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89, |
|
62 | 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89, | |
42 | 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87, |
|
63 | 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87, | |
43 | 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad, |
|
64 | 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad, | |
44 | 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3, |
|
65 | 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3, | |
45 | 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1, |
|
66 | 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1, | |
46 | 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf, |
|
67 | 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf, | |
47 | 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5, |
|
68 | 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5, | |
48 | 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb, |
|
69 | 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb, | |
49 | 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9, |
|
70 | 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9, | |
50 | 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7, |
|
71 | 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7, | |
51 | 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd, |
|
72 | 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd, | |
52 | 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3, |
|
73 | 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3, | |
53 | 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1, |
|
74 | 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1, | |
54 | 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf |
|
75 | 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf | |
55 | }; |
|
76 | }; | |
56 |
|
77 | |||
57 | inline unsigned char _spw_CRC_(unsigned char INCR, unsigned char INBYTE) |
|
78 | inline unsigned char _spw_CRC_(unsigned char INCR, unsigned char INBYTE) | |
58 | { |
|
79 | { | |
59 | return SPW_CRCTable[INCR ^ INBYTE]; |
|
80 | return SPW_CRCTable[INCR ^ INBYTE]; | |
60 | } |
|
81 | } | |
61 |
|
82 | |||
62 | inline char spw_CRC(char* buffer, int size) |
|
83 | inline char spw_CRC(char* buffer, int size) | |
63 | { |
|
84 | { | |
64 | unsigned char CRC = 0; |
|
85 | unsigned char CRC = 0; | |
65 | for(int i=0;i<size;i++) |
|
86 | for(int i=0;i<size;i++) | |
66 | { |
|
87 | { | |
67 | CRC = _spw_CRC_(CRC,(unsigned char)buffer[i]); |
|
88 | CRC = _spw_CRC_(CRC,(unsigned char)buffer[i]); | |
68 | } |
|
89 | } | |
69 | return CRC; |
|
90 | return CRC; | |
70 | } |
|
91 | } | |
71 |
|
92 | |||
72 | /* |
|
93 | /* | |
73 | βββββββ ββββ ββββ ββββββ βββββββ βββββββ βββββββ βββββββ βββββββββ βββββββ βββββββ βββββββ βββ |
|
94 | βββββββ ββββ ββββ ββββββ βββββββ βββββββ βββββββ βββββββ βββββββββ βββββββ βββββββ βββββββ βββ | |
74 | βββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
|
95 | βββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
75 | βββββββββββββββββββββββββββββββββββ βββββββββββββββββββ βββ βββ βββ ββββββ βββ ββββββ |
|
96 | βββββββββββββββββββββββββββββββββββ βββββββββββββββββββ βββ βββ βββ ββββββ βββ ββββββ | |
76 | ββββββββββββββββββββββββββββββββββ βββββββ βββββββββββ βββ βββ βββ ββββββ βββ ββββββ |
|
97 | ββββββββββββββββββββββββββββββββββ βββββββ βββββββββββ βββ βββ βββ ββββββ βββ ββββββ | |
77 | βββ ββββββ βββ ββββββ ββββββ βββ βββ ββββββββββββ βββ ββββββββββββββββββββββββββββββββββ |
|
98 | βββ ββββββ βββ ββββββ ββββββ βββ βββ ββββββββββββ βββ ββββββββββββββββββββββββββββββββββ | |
78 | βββ ββββββ ββββββ ββββββ βββ βββ βββ βββββββ βββ βββββββ βββββββ βββββββ ββββββββ |
|
99 | βββ ββββββ ββββββ ββββββ βββ βββ βββ βββββββ βββ βββββββ βββββββ βββββββ ββββββββ | |
79 | */ |
|
100 | */ | |
80 |
|
101 | |||
81 | enum RMAP_CMD_CODE{ |
|
102 | enum RMAP_CMD_CODE{ | |
82 | RMAP_CMD_CODE_invalid0, //0000 |
|
103 | RMAP_CMD_CODE_invalid0, //0000 | |
83 | RMAP_CMD_CODE_invalid1, //0001 |
|
104 | RMAP_CMD_CODE_invalid1, //0001 | |
84 | RMAP_CMD_CODE_read_Single, //0010 |
|
105 | RMAP_CMD_CODE_read_Single, //0010 | |
85 | RMAP_CMD_CODE_read_Inc, //0011 |
|
106 | RMAP_CMD_CODE_read_Inc, //0011 | |
86 | RMAP_CMD_CODE_invalid2, //0100 |
|
107 | RMAP_CMD_CODE_invalid2, //0100 | |
87 | RMAP_CMD_CODE_invalid3, //0101 |
|
108 | RMAP_CMD_CODE_invalid3, //0101 | |
88 | RMAP_CMD_CODE_invalid4, //0110 |
|
109 | RMAP_CMD_CODE_invalid4, //0110 | |
89 | RMAP_CMD_CODE_readModWri_Inc, //0111 |
|
110 | RMAP_CMD_CODE_readModWri_Inc, //0111 | |
90 | RMAP_CMD_CODE_writeSingle_noVer_noRep, //1000 |
|
111 | RMAP_CMD_CODE_writeSingle_noVer_noRep, //1000 | |
91 | RMAP_CMD_CODE_writeInc_noVer_noRep, //1001 |
|
112 | RMAP_CMD_CODE_writeInc_noVer_noRep, //1001 | |
92 | RMAP_CMD_CODE_writeSingle_noVer_Rep, //1010 |
|
113 | RMAP_CMD_CODE_writeSingle_noVer_Rep, //1010 | |
93 | RMAP_CMD_CODE_writeInc_noVer_Rep, //1011 |
|
114 | RMAP_CMD_CODE_writeInc_noVer_Rep, //1011 | |
94 | RMAP_CMD_CODE_writeSingle_ver_noRep, //1100 |
|
115 | RMAP_CMD_CODE_writeSingle_ver_noRep, //1100 | |
95 | RMAP_CMD_CODE_writeInc_ver_noRep, //1101 |
|
116 | RMAP_CMD_CODE_writeInc_ver_noRep, //1101 | |
96 | RMAP_CMD_CODE_writeSingle_ver_rep, //1110 |
|
117 | RMAP_CMD_CODE_writeSingle_ver_rep, //1110 | |
97 | RMAP_CMD_CODE_writeInc_ver_rep //1111 |
|
118 | RMAP_CMD_CODE_writeInc_ver_rep //1111 | |
98 | }; |
|
119 | }; | |
99 |
|
120 | |||
100 | /* |
|
121 | /* | |
101 | * Rmap read command header: |
|
122 | * Rmap read command header: | |
102 | * |
|
123 | * | |
103 | * | Destination Logical Address | Protocol identifier | Packet type | Destination key | |
|
124 | * | Destination Logical Address | Protocol identifier | Packet type | Destination key | | |
104 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
125 | * |-----------------------------|------------------------|------------------------|------------------------| | |
105 | * | Source Logical Address | Transaction identifier | Transaction identifier | Extended read address | |
|
126 | * | Source Logical Address | Transaction identifier | Transaction identifier | Extended read address | | |
106 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
127 | * |-----------------------------|------------------------|------------------------|------------------------| | |
107 | * | Read address MSB | Read address | Read address | Read address LSB | |
|
128 | * | Read address MSB | Read address | Read address | Read address LSB | | |
108 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
129 | * |-----------------------------|------------------------|------------------------|------------------------| | |
109 | * | Data length MSB | Data length | Data length LSB | CRC | |
|
130 | * | Data length MSB | Data length | Data length LSB | CRC | | |
110 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
131 | * |-----------------------------|------------------------|------------------------|------------------------| | |
111 | * |
|
132 | * | |
112 | * Packet type field: |
|
133 | * Packet type field: | |
113 | * |
|
134 | * | |
114 | * | msb |
|
135 | * | msb | |
115 | * | reserved = 0 | Comand = 1| Read = 0 | Read = 0 | Read = 1 | Increment/ | Source Path | Source Path | |
|
136 | * | reserved = 0 | Comand = 1| Read = 0 | Read = 0 | Read = 1 | Increment/ | Source Path | Source Path | | |
116 | * | (Ack/NoAck) | No Inc. address | Address Length | Address Length | |
|
137 | * | (Ack/NoAck) | No Inc. address | Address Length | Address Length | | |
117 | * |
|
138 | * | |
118 | */ |
|
139 | */ | |
119 | #define RMAP_READ_HEADER_MIN_SZ 16 |
|
140 | #define RMAP_READ_HEADER_MIN_SZ 16 | |
120 |
|
141 | |||
121 | inline void RMAP_build_rx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer) |
|
142 | inline void RMAP_build_rx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer) | |
122 | { |
|
143 | { | |
123 | buffer[0] = destinationLogicalAddress; |
|
144 | buffer[0] = destinationLogicalAddress; | |
124 | buffer[1] = SPW_PROTO_ID_RMAP; |
|
145 | buffer[1] = SPW_PROTO_ID_RMAP; | |
125 | buffer[2] = 0b01001100; |
|
146 | buffer[2] = 0b01001100; | |
126 | buffer[3] = destKey; |
|
147 | buffer[3] = destKey; | |
127 | buffer[4] = sourceLogicalAddress; |
|
148 | buffer[4] = sourceLogicalAddress; | |
128 | buffer[5] = (char)(transactionID >> 8); |
|
149 | buffer[5] = (char)(transactionID >> 8); | |
129 | buffer[6] = (char)(transactionID); |
|
150 | buffer[6] = (char)(transactionID); | |
130 | buffer[7] = 0; |
|
151 | buffer[7] = 0; | |
131 | buffer[8] = (char)(readAddress >> 24); |
|
152 | buffer[8] = (char)(readAddress >> 24); | |
132 | buffer[9] = (char)(readAddress >> 16); |
|
153 | buffer[9] = (char)(readAddress >> 16); | |
133 | buffer[10] = (char)(readAddress >> 8); |
|
154 | buffer[10] = (char)(readAddress >> 8); | |
134 | buffer[11] = (char)(readAddress); |
|
155 | buffer[11] = (char)(readAddress); | |
135 | buffer[12] = (char)(length >> 16); |
|
156 | buffer[12] = (char)(length >> 16); | |
136 | buffer[13] = (char)(length >> 8); |
|
157 | buffer[13] = (char)(length >> 8); | |
137 | buffer[14] = (char)(length); |
|
158 | buffer[14] = (char)(length); | |
138 | buffer[15] = (char)spw_CRC(buffer,15); |
|
159 | buffer[15] = (char)spw_CRC(buffer,15); | |
139 | } |
|
160 | } | |
140 |
|
161 | |||
141 | inline int RMAP_get_transactionID(char *packet) |
|
162 | inline int RMAP_get_transactionID(char *packet) | |
142 | { |
|
163 | { | |
143 | return ((((unsigned int)packet[5])<<8) + ((unsigned int)packet[6])); |
|
164 | return ((((unsigned int)packet[5])<<8) + ((unsigned int)packet[6])); | |
144 | } |
|
165 | } | |
145 |
|
166 | |||
146 |
|
167 | |||
147 | /* |
|
168 | /* | |
148 | * Rmap Write command header: |
|
169 | * Rmap Write command header: | |
149 | * |
|
170 | * | |
150 | * | Destination Logical Address | Protocol identifier | Packet type | Destination key | |
|
171 | * | Destination Logical Address | Protocol identifier | Packet type | Destination key | | |
151 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
172 | * |-----------------------------|------------------------|------------------------|------------------------| | |
152 | * | Source Logical Address | Transaction identifier | Transaction identifier | Extended write address | |
|
173 | * | Source Logical Address | Transaction identifier | Transaction identifier | Extended write address | | |
153 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
174 | * |-----------------------------|------------------------|------------------------|------------------------| | |
154 | * | Write address MSB | Write address | Write address | Write address LSB | |
|
175 | * | Write address MSB | Write address | Write address | Write address LSB | | |
155 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
176 | * |-----------------------------|------------------------|------------------------|------------------------| | |
156 | * | Data length MSB | Data length | Data length LSB | Header CRC | |
|
177 | * | Data length MSB | Data length | Data length LSB | Header CRC | | |
157 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
178 | * |-----------------------------|------------------------|------------------------|------------------------| | |
158 | * | Data | (...) | Last data byte | Data CRC | |
|
179 | * | Data | (...) | Last data byte | Data CRC | | |
159 | * |-----------------------------|------------------------|------------------------|------------------------| |
|
180 | * |-----------------------------|------------------------|------------------------|------------------------| | |
160 | * |
|
181 | * | |
161 | * Packet type field: |
|
182 | * Packet type field: | |
162 | * |
|
183 | * | |
163 | * | msb |
|
184 | * | msb | |
164 | * | reserved = 0 | Comand = 1| Write = 1 | Verify data = 1 | Ack = 1 | Increment/ | Source Path | Source Path | |
|
185 | * | reserved = 0 | Comand = 1| Write = 1 | Verify data = 1 | Ack = 1 | Increment/ | Source Path | Source Path | | |
165 | * | Don't Verify data = 0 | No Ack = 0 | No Inc. address | Address Length | Address Length | |
|
186 | * | Don't Verify data = 0 | No Ack = 0 | No Inc. address | Address Length | Address Length | | |
166 | * |
|
187 | * | |
167 | */ |
|
188 | */ | |
168 | #define RMAP_WRITE_HEADER_MIN_SZ 16 |
|
189 | #define RMAP_WRITE_HEADER_MIN_SZ 16 | |
169 | #define RMAP_WRITE_PACKET_MIN_SZ(bytesCnt) (RMAP_WRITE_HEADER_MIN_SZ+bytesCnt+1) //header=16 + data + data CRC=1 |
|
190 | #define RMAP_WRITE_PACKET_MIN_SZ(bytesCnt) (RMAP_WRITE_HEADER_MIN_SZ+bytesCnt+1) //header=16 + data + data CRC=1 | |
170 |
|
191 | |||
171 | inline void RMAP_build_tx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer) |
|
192 | inline void RMAP_build_tx_request_header(char destinationLogicalAddress, char destKey,char sourceLogicalAddress,uint16_t transactionID,int readAddress,int length,char *buffer) | |
172 | { |
|
193 | { | |
173 | buffer[0] = destinationLogicalAddress; |
|
194 | buffer[0] = destinationLogicalAddress; | |
174 | buffer[1] = SPW_PROTO_ID_RMAP; |
|
195 | buffer[1] = SPW_PROTO_ID_RMAP; | |
175 | buffer[2] = 0b01101100; |
|
196 | buffer[2] = 0b01101100; | |
176 | buffer[3] = destKey; |
|
197 | buffer[3] = destKey; | |
177 | buffer[4] = sourceLogicalAddress; |
|
198 | buffer[4] = sourceLogicalAddress; | |
178 | buffer[5] = (char)(transactionID >> 8); |
|
199 | buffer[5] = (char)(transactionID >> 8); | |
179 | buffer[6] = (char)(transactionID); |
|
200 | buffer[6] = (char)(transactionID); | |
180 | buffer[7] = 0; |
|
201 | buffer[7] = 0; | |
181 | buffer[8] = (char)(readAddress >> 24); |
|
202 | buffer[8] = (char)(readAddress >> 24); | |
182 | buffer[9] = (char)(readAddress >> 16); |
|
203 | buffer[9] = (char)(readAddress >> 16); | |
183 | buffer[10] = (char)(readAddress >> 8); |
|
204 | buffer[10] = (char)(readAddress >> 8); | |
184 | buffer[11] = (char)(readAddress); |
|
205 | buffer[11] = (char)(readAddress); | |
185 | buffer[12] = (char)(length >> 16); |
|
206 | buffer[12] = (char)(length >> 16); | |
186 | buffer[13] = (char)(length >> 8); |
|
207 | buffer[13] = (char)(length >> 8); | |
187 | buffer[14] = (char)(length); |
|
208 | buffer[14] = (char)(length); | |
188 | buffer[15] = (char)spw_CRC(buffer,15); |
|
209 | buffer[15] = (char)spw_CRC(buffer,15); | |
189 | buffer[16+length] = (char)spw_CRC(buffer+16,length); |
|
210 | buffer[16+length] = (char)spw_CRC(buffer+16,length); | |
190 | } |
|
211 | } | |
191 |
|
212 | |||
192 | #endif // SPW_H |
|
213 | #endif // SPW_H |
@@ -1,56 +1,103 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
2 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
3 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
4 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
5 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
|
22 | ||||
6 | #include "spwplugin.h" |
|
23 | #include "spwplugin.h" | |
7 | #include "stardundeespw_usb.h" |
|
24 | #include "stardundeespw_usb.h" | |
8 | #include <socexplorerproxy.h> |
|
25 | #include <socexplorerproxy.h> | |
9 |
|
26 | |||
10 | spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,true) |
|
27 | spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,true) | |
11 | { |
|
28 | { | |
12 | Q_UNUSED(parent) |
|
29 | Q_UNUSED(parent) | |
13 | this->bridge = new stardundeeSPW_USB(this); |
|
30 | this->bridge = NULL; | |
14 | this->scanDone = false; |
|
31 | this->scanDone = false; | |
15 | if(this->bridge->connectBridge()) |
|
32 | this->mainGroupBox = new QGroupBox("SpaceWire Plugin Configuration",this); | |
16 | { |
|
33 | this->bridgeSelector = new QComboBox(this); | |
17 | this->Connected = true; |
|
34 | this->mainLayout = new QGridLayout(this); | |
18 | emit this->activateSig(true); |
|
35 | this->mainLayout->addWidget(new QLabel("Select SpaceWire bridge",this),0,0,1,1,Qt::AlignCenter); | |
19 | } |
|
36 | this->mainLayout->addWidget(this->bridgeSelector,0,1,1,1); | |
|
37 | this->mainGroupBox->setLayout(this->mainLayout); | |||
|
38 | this->setWidget(this->mainGroupBox); | |||
|
39 | this->bridgeSelector->addItem("none"); | |||
|
40 | this->bridgeSelector->addItem("STAR-Dundee Spw USB Brick"); | |||
|
41 | connect(this->bridgeSelector,SIGNAL(currentIndexChanged(QString)),this,SLOT(bridgeSelectionChanged(QString))); | |||
20 | } |
|
42 | } | |
21 |
|
43 | |||
22 |
|
44 | |||
23 | spwplugin::~spwplugin() |
|
45 | spwplugin::~spwplugin() | |
24 | { |
|
46 | { | |
25 |
|
47 | |||
26 | } |
|
48 | } | |
27 |
|
49 | |||
28 |
|
50 | |||
29 |
|
51 | |||
30 | unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address) |
|
52 | unsigned int spwplugin::Read(unsigned int *Value,unsigned int count,unsigned int address) | |
31 | { |
|
53 | { | |
32 | if(Connected) |
|
54 | if(Connected) | |
33 | { |
|
55 | { | |
34 | return bridge->Read(Value,count,address); |
|
56 | return bridge->Read(Value,count,address); | |
35 | } |
|
57 | } | |
36 | return 0; |
|
58 | return 0; | |
37 | } |
|
59 | } | |
38 |
|
60 | |||
|
61 | void spwplugin::bridgeSelectionChanged(const QString &text) | |||
|
62 | { | |||
|
63 | printf("test"); | |||
|
64 | if(text=="none") | |||
|
65 | { | |||
|
66 | if(this->bridge!=NULL) | |||
|
67 | { | |||
|
68 | this->mainLayout->removeWidget(this->bridge->getGUI()); | |||
|
69 | delete this->bridge; | |||
|
70 | this->bridge= NULL; | |||
|
71 | } | |||
|
72 | } | |||
|
73 | if(text=="STAR-Dundee Spw USB Brick") | |||
|
74 | { | |||
|
75 | if(this->bridge!=NULL) | |||
|
76 | { | |||
|
77 | this->mainLayout->removeWidget(this->bridge->getGUI()); | |||
|
78 | delete this->bridge; | |||
|
79 | } | |||
|
80 | this->bridge = new stardundeeSPW_USB(this); | |||
|
81 | this->mainLayout->addWidget(this->bridge->getGUI(),1,0,1,2); | |||
|
82 | } | |||
|
83 | ||||
|
84 | } | |||
|
85 | ||||
39 |
|
86 | |||
40 |
|
87 | |||
41 | unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) |
|
88 | unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) | |
42 | { |
|
89 | { | |
43 | if(Connected) |
|
90 | if(Connected) | |
44 | { |
|
91 | { | |
45 | return bridge->Write(Value,count,address); |
|
92 | return bridge->Write(Value,count,address); | |
46 | } |
|
93 | } | |
47 | return 0; |
|
94 | return 0; | |
48 | } |
|
95 | } | |
49 |
|
96 | |||
50 |
|
97 | |||
51 |
|
98 | |||
52 |
|
99 | |||
53 |
|
100 | |||
54 |
|
101 | |||
55 |
|
102 | |||
56 |
|
103 |
@@ -1,47 +1,70 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
2 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
3 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
4 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
5 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
6 | #ifndef spwplugin_H |
|
22 | #ifndef spwplugin_H | |
7 | #define spwplugin_H |
|
23 | #define spwplugin_H | |
8 | #include <QMenuBar> |
|
24 | #include <QMenuBar> | |
9 | #include <QMenu> |
|
25 | #include <QMenu> | |
10 | #include <QAction> |
|
26 | #include <QAction> | |
11 | #include <QLayout> |
|
27 | #include <QLayout> | |
|
28 | #include <QGroupBox> | |||
|
29 | #include <QComboBox> | |||
|
30 | #include <QLabel> | |||
12 |
|
31 | |||
13 | #include <abstractspwbridge.h> |
|
32 | #include <abstractspwbridge.h> | |
14 | #include <socexplorerplugin.h> |
|
33 | #include <socexplorerplugin.h> | |
15 |
|
34 | |||
16 |
|
35 | |||
17 | class spwplugin : public socexplorerplugin |
|
36 | class spwplugin : public socexplorerplugin | |
18 | { |
|
37 | { | |
19 | Q_OBJECT |
|
38 | Q_OBJECT | |
20 | public: |
|
39 | public: | |
21 | explicit spwplugin(QWidget *parent = 0); |
|
40 | explicit spwplugin(QWidget *parent = 0); | |
22 | ~spwplugin(); |
|
41 | ~spwplugin(); | |
23 | /* You can implement the folowing function if you want to overwrite |
|
42 | /* You can implement the folowing function if you want to overwrite | |
24 | * their default behavior |
|
43 | * their default behavior | |
25 | */ |
|
44 | */ | |
26 | /* |
|
45 | /* | |
27 | int registermenu(QMainWindow *menuHolder); |
|
46 | int registermenu(QMainWindow *menuHolder); | |
28 | int isConnected(); |
|
47 | int isConnected(); | |
29 | int connect(); |
|
48 | int connect(); | |
30 | int VID(){return driver_VID;} |
|
49 | int VID(){return driver_VID;} | |
31 | int PID(){return driver_PID;} |
|
50 | int PID(){return driver_PID;} | |
32 | */ |
|
51 | */ | |
33 |
|
52 | |||
34 | public slots: |
|
53 | public slots: | |
35 | unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); |
|
54 | unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); | |
36 | unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); |
|
55 | unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); | |
37 |
|
56 | |||
|
57 | void bridgeSelectionChanged( const QString & text ); | |||
|
58 | ||||
38 | signals: |
|
59 | signals: | |
39 |
|
60 | |||
40 | private: |
|
61 | private: | |
41 | abstractSpwBridge* bridge; |
|
62 | abstractSpwBridge* bridge; | |
42 | bool scanDone; |
|
63 | bool scanDone; | |
43 |
|
64 | QGroupBox* mainGroupBox; | ||
|
65 | QComboBox* bridgeSelector; | |||
|
66 | QGridLayout* mainLayout; | |||
44 | }; |
|
67 | }; | |
45 |
|
68 | |||
46 | #endif // spwplugin_H |
|
69 | #endif // spwplugin_H | |
47 |
|
70 |
@@ -1,464 +1,516 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
1 | #include "stardundeespw_usb.h" |
|
23 | #include "stardundeespw_usb.h" | |
2 | #include <socexplorerengine.h> |
|
24 | #include <socexplorerengine.h> | |
3 | #include <qhexedit.h> |
|
25 | #include <qhexedit.h> | |
4 |
|
26 | |||
5 | stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) : |
|
27 | stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) : | |
6 | abstractSpwBridge(parent) |
|
28 | abstractSpwBridge(parent) | |
7 | { |
|
29 | { | |
8 | Q_UNUSED(parent) |
|
30 | Q_UNUSED(parent) | |
9 |
this-> |
|
31 | this->p_GUI = new QWidget(parent); | |
|
32 | this->mainLayout = new QGridLayout(this->p_GUI); | |||
|
33 | this->p_GUI->setLayout(mainLayout); | |||
|
34 | this->connectBridgeButton = new QPushButton("Connect"); | |||
|
35 | this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1); | |||
|
36 | connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection())); | |||
|
37 | this->manager = new stardundeeSPW_USB_Manager(parent,this); | |||
10 | this->manager->start(); |
|
38 | this->manager->start(); | |
11 | } |
|
39 | } | |
12 |
|
40 | |||
|
41 | stardundeeSPW_USB::~stardundeeSPW_USB() | |||
|
42 | { | |||
|
43 | this->manager->requestInterruption(); | |||
|
44 | delete this->p_GUI; | |||
|
45 | } | |||
|
46 | ||||
|
47 | void stardundeeSPW_USB::toggleBridgeConnection() | |||
|
48 | { | |||
|
49 | if(this->plugin->isConnected()) | |||
|
50 | { | |||
|
51 | if(this->disconnectBridge()) | |||
|
52 | { | |||
|
53 | this->connectBridgeButton->setText("Connect"); | |||
|
54 | } | |||
|
55 | } | |||
|
56 | else | |||
|
57 | { | |||
|
58 | if(this->connectBridge()) | |||
|
59 | { | |||
|
60 | this->connectBridgeButton->setText("Disconnect"); | |||
|
61 | } | |||
|
62 | } | |||
|
63 | } | |||
|
64 | ||||
13 | bool stardundeeSPW_USB::connectBridge() |
|
65 | bool stardundeeSPW_USB::connectBridge() | |
14 | { |
|
66 | { | |
15 | return this->manager->connectBridge(); |
|
67 | return this->manager->connectBridge(); | |
16 | } |
|
68 | } | |
17 |
|
69 | |||
18 | bool stardundeeSPW_USB::disconnectBridge() |
|
70 | bool stardundeeSPW_USB::disconnectBridge() | |
19 | { |
|
71 | { | |
20 | return this->manager->disconnectBridge(); |
|
72 | return this->manager->disconnectBridge(); | |
21 | } |
|
73 | } | |
22 |
|
74 | |||
23 | int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size) |
|
75 | int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size) | |
24 | { |
|
76 | { | |
25 | return this->manager->sendPacket(packet,size); |
|
77 | return this->manager->sendPacket(packet,size); | |
26 | } |
|
78 | } | |
27 |
|
79 | |||
28 | unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address) |
|
80 | unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address) | |
29 | { |
|
81 | { | |
30 | char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1]; |
|
82 | char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1]; | |
31 | writeBuffer[0]=1;//Link number |
|
83 | writeBuffer[0]=1;//Link number | |
32 | int transactionID = 0; |
|
84 | int transactionID = 0; | |
33 | int written=0; |
|
85 | int written=0; | |
34 | SocExplorerEngine::message(this->plugin,"Enter Write function"); |
|
86 | SocExplorerEngine::message(this->plugin,"Enter Write function"); | |
35 | QProgressBar* progress=NULL; |
|
87 | QProgressBar* progress=NULL; | |
36 | if(count>RMAP_MAX_XFER_SIZE) |
|
88 | if(count>RMAP_MAX_XFER_SIZE) | |
37 | progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); |
|
89 | progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |
38 | //Quite stupide loop, I guess that I always get the number of byte I asked for! |
|
90 | //Quite stupide loop, I guess that I always get the number of byte I asked for! | |
39 | while(count>=RMAP_MAX_XFER_SIZE) |
|
91 | while(count>=RMAP_MAX_XFER_SIZE) | |
40 | { |
|
92 | { | |
41 | for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++) |
|
93 | for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++) | |
42 | { |
|
94 | { | |
43 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); |
|
95 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); | |
44 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); |
|
96 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); | |
45 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); |
|
97 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); | |
46 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); |
|
98 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); | |
47 | } |
|
99 | } | |
48 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1); |
|
100 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1); | |
49 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1); |
|
101 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1); | |
50 | written+=RMAP_MAX_XFER_SIZE; |
|
102 | written+=RMAP_MAX_XFER_SIZE; | |
51 | count-=RMAP_MAX_XFER_SIZE; |
|
103 | count-=RMAP_MAX_XFER_SIZE; | |
52 | progress->setValue(written); |
|
104 | progress->setValue(written); | |
53 | qApp->processEvents(); |
|
105 | qApp->processEvents(); | |
54 | } |
|
106 | } | |
55 | if(count>0) |
|
107 | if(count>0) | |
56 | { |
|
108 | { | |
57 | for(int i=0;i<((int)count);i++) |
|
109 | for(int i=0;i<((int)count);i++) | |
58 | { |
|
110 | { | |
59 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); |
|
111 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF); | |
60 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); |
|
112 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF); | |
61 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); |
|
113 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF); | |
62 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); |
|
114 | writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF); | |
63 | } |
|
115 | } | |
64 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1); |
|
116 | RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1); | |
65 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1); |
|
117 | manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1); | |
66 | written+=count; |
|
118 | written+=count; | |
67 | if(progress!=NULL) |
|
119 | if(progress!=NULL) | |
68 | { |
|
120 | { | |
69 | progress->setValue(written); |
|
121 | progress->setValue(written); | |
70 | qApp->processEvents(); |
|
122 | qApp->processEvents(); | |
71 | } |
|
123 | } | |
72 | } |
|
124 | } | |
73 | if(progress!=NULL) |
|
125 | if(progress!=NULL) | |
74 | { |
|
126 | { | |
75 | SocExplorerEngine::deleteProgressBar(progress); |
|
127 | SocExplorerEngine::deleteProgressBar(progress); | |
76 | } |
|
128 | } | |
77 | return written; |
|
129 | return written; | |
78 | } |
|
130 | } | |
79 |
|
131 | |||
80 | unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address) |
|
132 | unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address) | |
81 | { |
|
133 | { | |
82 | char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1]; |
|
134 | char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1]; | |
83 | char* RMAP_AnswerBuffer; |
|
135 | char* RMAP_AnswerBuffer; | |
84 | requestBuffer[0]=1;//Link number |
|
136 | requestBuffer[0]=1;//Link number | |
85 | int transactionID = 0; |
|
137 | int transactionID = 0; | |
86 | int read=0; |
|
138 | int read=0; | |
87 | QProgressBar* progress=NULL; |
|
139 | QProgressBar* progress=NULL; | |
88 | if(count>RMAP_MAX_XFER_SIZE) |
|
140 | if(count>RMAP_MAX_XFER_SIZE) | |
89 | progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); |
|
141 | progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |
90 | SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE)); |
|
142 | SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE)); | |
91 |
|
143 | |||
92 | //Quite stupide loop, I guess that I always get the number of byte I asked for! |
|
144 | //Quite stupide loop, I guess that I always get the number of byte I asked for! | |
93 | while((int)count>=(int)RMAP_MAX_XFER_SIZE) |
|
145 | while((int)count>=(int)RMAP_MAX_XFER_SIZE) | |
94 | { |
|
146 | { | |
95 | transactionID = manager->getRMAPtransactionID(); |
|
147 | transactionID = manager->getRMAPtransactionID(); | |
96 | SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID)); |
|
148 | SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID)); | |
97 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1); |
|
149 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1); | |
98 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); |
|
150 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); | |
99 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); |
|
151 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); | |
100 | for(int i=0;i<((len-13)/4);i++) |
|
152 | for(int i=0;i<((len-13)/4);i++) | |
101 | { |
|
153 | { | |
102 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); |
|
154 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); | |
103 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); |
|
155 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); | |
104 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); |
|
156 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); | |
105 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); |
|
157 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); | |
106 | } |
|
158 | } | |
107 | free(RMAP_AnswerBuffer); |
|
159 | free(RMAP_AnswerBuffer); | |
108 | read+=RMAP_MAX_XFER_SIZE; |
|
160 | read+=RMAP_MAX_XFER_SIZE; | |
109 | count-=RMAP_MAX_XFER_SIZE; |
|
161 | count-=RMAP_MAX_XFER_SIZE; | |
110 | progress->setValue(read); |
|
162 | progress->setValue(read); | |
111 | qApp->processEvents(); |
|
163 | qApp->processEvents(); | |
112 | } |
|
164 | } | |
113 | if((int)count>0) |
|
165 | if((int)count>0) | |
114 | { |
|
166 | { | |
115 | transactionID = manager->getRMAPtransactionID(); |
|
167 | transactionID = manager->getRMAPtransactionID(); | |
116 | SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID)); |
|
168 | SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID)); | |
117 | SocExplorerEngine::message(this->plugin,QString("Building request with:")); |
|
169 | SocExplorerEngine::message(this->plugin,QString("Building request with:")); | |
118 | SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16)); |
|
170 | SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16)); | |
119 | SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4)); |
|
171 | SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4)); | |
120 | SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13)); |
|
172 | SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13)); | |
121 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1); |
|
173 | RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1); | |
122 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); |
|
174 | manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); | |
123 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); |
|
175 | int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); | |
124 | for(int i=0;i<((len-13)/4);i++) |
|
176 | for(int i=0;i<((len-13)/4);i++) | |
125 | { |
|
177 | { | |
126 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); |
|
178 | Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]); | |
127 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); |
|
179 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13])); | |
128 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); |
|
180 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14])); | |
129 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); |
|
181 | Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15])); | |
130 | } |
|
182 | } | |
131 | free(RMAP_AnswerBuffer); |
|
183 | free(RMAP_AnswerBuffer); | |
132 | read+=count; |
|
184 | read+=count; | |
133 | if(progress!=NULL) |
|
185 | if(progress!=NULL) | |
134 | { |
|
186 | { | |
135 | progress->setValue(read); |
|
187 | progress->setValue(read); | |
136 | qApp->processEvents(); |
|
188 | qApp->processEvents(); | |
137 | } |
|
189 | } | |
138 | } |
|
190 | } | |
139 | if(progress!=NULL) |
|
191 | if(progress!=NULL) | |
140 | { |
|
192 | { | |
141 | SocExplorerEngine::deleteProgressBar(progress); |
|
193 | SocExplorerEngine::deleteProgressBar(progress); | |
142 | } |
|
194 | } | |
143 | return read; |
|
195 | return read; | |
144 | } |
|
196 | } | |
145 |
|
197 | |||
146 | stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *parent) |
|
198 | stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent) | |
147 | :QThread((QObject*)parent) |
|
199 | :QThread((QObject*)parent) | |
148 | { |
|
200 | { | |
149 | this->handleMutex = new QMutex(QMutex::NonRecursive); |
|
201 | this->handleMutex = new QMutex(QMutex::NonRecursive); | |
150 | this->RMAP_AnswersSem = new QSemaphore(0); |
|
202 | this->RMAP_AnswersSem = new QSemaphore(0); | |
151 | this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive); |
|
203 | this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive); | |
152 | this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive); |
|
204 | this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive); | |
153 |
this->plugin = p |
|
205 | this->plugin = plugin; | |
154 | connected = false; |
|
206 | connected = false; | |
155 | } |
|
207 | } | |
156 |
|
208 | |||
157 | stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager() |
|
209 | stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager() | |
158 | { |
|
210 | { | |
159 | this->terminate(); |
|
211 | this->terminate(); | |
160 | while (!this->isFinished()) { |
|
212 | while (!this->isFinished()) { | |
161 | this->usleep(1000); |
|
213 | this->usleep(1000); | |
162 | } |
|
214 | } | |
163 | } |
|
215 | } | |
164 |
|
216 | |||
165 |
|
217 | |||
166 | void stardundeeSPW_USB_Manager::run() |
|
218 | void stardundeeSPW_USB_Manager::run() | |
167 | { |
|
219 | { | |
168 | USB_SPACEWIRE_PACKET_PROPERTIES properties; |
|
220 | USB_SPACEWIRE_PACKET_PROPERTIES properties; | |
169 | USB_SPACEWIRE_ID pIdentifier=NULL; |
|
221 | USB_SPACEWIRE_ID pIdentifier=NULL; | |
170 | USB_SPACEWIRE_STATUS stat; |
|
222 | USB_SPACEWIRE_STATUS stat; | |
171 | SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread"); |
|
223 | SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread"); | |
172 | char buffer[(RMAP_MAX_XFER_SIZE*4)+50]; |
|
224 | char buffer[(RMAP_MAX_XFER_SIZE*4)+50]; | |
173 | while (!this->isInterruptionRequested()) |
|
225 | while (!this->isInterruptionRequested()) | |
174 | { |
|
226 | { | |
175 | if(this->connected) |
|
227 | if(this->connected) | |
176 | { |
|
228 | { | |
177 | handleMutex->lock(); |
|
229 | handleMutex->lock(); | |
178 | //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets"); |
|
230 | //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets"); | |
179 | if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01)) |
|
231 | if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01)) | |
180 | { |
|
232 | { | |
181 | SocExplorerEngine::message(this->plugin,"Got packet"); |
|
233 | SocExplorerEngine::message(this->plugin,"Got packet"); | |
182 | stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier); |
|
234 | stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier); | |
183 | if (stat == TRANSFER_SUCCESS) |
|
235 | if (stat == TRANSFER_SUCCESS) | |
184 | { |
|
236 | { | |
185 | if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET) |
|
237 | if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET) | |
186 | { |
|
238 | { | |
187 | SocExplorerEngine::message(this->plugin,"It's a SPW packet"); |
|
239 | SocExplorerEngine::message(this->plugin,"It's a SPW packet"); | |
188 | if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP) |
|
240 | if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP) | |
189 | { |
|
241 | { | |
190 | SocExplorerEngine::message(this->plugin,"Got end of packet"); |
|
242 | SocExplorerEngine::message(this->plugin,"Got end of packet"); | |
191 | if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet |
|
243 | if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet | |
192 | { |
|
244 | { | |
193 | SocExplorerEngine::message(this->plugin,"Got RMAP packet"); |
|
245 | SocExplorerEngine::message(this->plugin,"Got RMAP packet"); | |
194 | SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len)); |
|
246 | SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len)); | |
195 | if(properties.len>8) |
|
247 | if(properties.len>8) | |
196 | { |
|
248 | { | |
197 | char* packetbuffer = (char*)malloc(properties.len); |
|
249 | char* packetbuffer = (char*)malloc(properties.len); | |
198 | memcpy(packetbuffer,buffer,properties.len); |
|
250 | memcpy(packetbuffer,buffer,properties.len); | |
199 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
251 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
200 | pIdentifier = NULL; |
|
252 | pIdentifier = NULL; | |
201 | handleMutex->unlock(); |
|
253 | handleMutex->unlock(); | |
202 | RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len); |
|
254 | RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len); | |
203 | RMAP_AnswersMtx->lock(); |
|
255 | RMAP_AnswersMtx->lock(); | |
204 | RMAP_Answers.append(packet); |
|
256 | RMAP_Answers.append(packet); | |
205 | RMAP_AnswersMtx->unlock(); |
|
257 | RMAP_AnswersMtx->unlock(); | |
206 | RMAP_AnswersSem->release(); |
|
258 | RMAP_AnswersSem->release(); | |
207 |
|
259 | |||
208 | } |
|
260 | } | |
209 | else //it's a RMAP write response |
|
261 | else //it's a RMAP write response | |
210 | { |
|
262 | { | |
211 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
263 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
212 | pIdentifier = NULL; |
|
264 | pIdentifier = NULL; | |
213 | handleMutex->unlock(); |
|
265 | handleMutex->unlock(); | |
214 | } |
|
266 | } | |
215 |
|
267 | |||
216 | } |
|
268 | } | |
217 | else //any non-rmap packet will be pushed to the network |
|
269 | else //any non-rmap packet will be pushed to the network | |
218 | { |
|
270 | { | |
219 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
271 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
220 | handleMutex->unlock(); |
|
272 | handleMutex->unlock(); | |
221 | SocExplorerEngine::message(this->plugin,"Got SPW packet"); |
|
273 | SocExplorerEngine::message(this->plugin,"Got SPW packet"); | |
222 | } |
|
274 | } | |
223 | } |
|
275 | } | |
224 | else |
|
276 | else | |
225 | { |
|
277 | { | |
226 | SocExplorerEngine::message(this->plugin,"No EOP received"); |
|
278 | SocExplorerEngine::message(this->plugin,"No EOP received"); | |
227 | } |
|
279 | } | |
228 | } |
|
280 | } | |
229 |
|
281 | |||
230 | } |
|
282 | } | |
231 | else |
|
283 | else | |
232 | { |
|
284 | { | |
233 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
285 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
234 | handleMutex->unlock(); |
|
286 | handleMutex->unlock(); | |
235 | } |
|
287 | } | |
236 | } |
|
288 | } | |
237 | else |
|
289 | else | |
238 | { |
|
290 | { | |
239 | USBSpaceWire_FreeRead(hDevice, pIdentifier); |
|
291 | USBSpaceWire_FreeRead(hDevice, pIdentifier); | |
240 | handleMutex->unlock(); |
|
292 | handleMutex->unlock(); | |
241 | } |
|
293 | } | |
242 | } |
|
294 | } | |
243 | else |
|
295 | else | |
244 | { |
|
296 | { | |
245 | sleep(1); |
|
297 | sleep(1); | |
246 | SocExplorerEngine::message(this->plugin,"Bridge not connected"); |
|
298 | SocExplorerEngine::message(this->plugin,"Bridge not connected"); | |
247 | } |
|
299 | } | |
248 | usleep(1000); |
|
300 | usleep(1000); | |
249 | // sleep(2); |
|
301 | // sleep(2); | |
250 | } |
|
302 | } | |
251 | SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread"); |
|
303 | SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread"); | |
252 | } |
|
304 | } | |
253 |
|
305 | |||
254 | bool stardundeeSPW_USB_Manager::connectBridge() |
|
306 | bool stardundeeSPW_USB_Manager::connectBridge() | |
255 | { |
|
307 | { | |
256 | this->handleMutex->lock(); |
|
308 | this->handleMutex->lock(); | |
257 | int status; |
|
309 | int status; | |
258 | U32 statusControl; |
|
310 | U32 statusControl; | |
259 | int brickNumber=0; |
|
311 | int brickNumber=0; | |
260 | int linkNumber=1; |
|
312 | int linkNumber=1; | |
261 | this->connected = false; |
|
313 | this->connected = false; | |
262 | if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device |
|
314 | if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device | |
263 | { |
|
315 | { | |
264 | SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))"); |
|
316 | SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))"); | |
265 | this->handleMutex->unlock(); |
|
317 | this->handleMutex->unlock(); | |
266 | return false; |
|
318 | return false; | |
267 | } |
|
319 | } | |
268 | SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful"); |
|
320 | SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful"); | |
269 |
|
321 | |||
270 | USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode |
|
322 | USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode | |
271 | CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration |
|
323 | CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration | |
272 | CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices |
|
324 | CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices | |
273 |
|
325 | |||
274 | // Set the path and return path to the device |
|
326 | // Set the path and return path to the device | |
275 | CFGSpaceWire_StackClear(); |
|
327 | CFGSpaceWire_StackClear(); | |
276 | CFGSpaceWire_AddrStackPush(0); |
|
328 | CFGSpaceWire_AddrStackPush(0); | |
277 | CFGSpaceWire_AddrStackPush(254); |
|
329 | CFGSpaceWire_AddrStackPush(254); | |
278 | CFGSpaceWire_RetAddrStackPush(254); |
|
330 | CFGSpaceWire_RetAddrStackPush(254); | |
279 | // set the base transmit rate to 100 MHz |
|
331 | // set the base transmit rate to 100 MHz | |
280 | status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff); |
|
332 | status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff); | |
281 | if (status != CFG_TRANSFER_SUCCESS) |
|
333 | if (status != CFG_TRANSFER_SUCCESS) | |
282 | { |
|
334 | { | |
283 | SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate"); |
|
335 | SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate"); | |
284 | return false; |
|
336 | return false; | |
285 | } |
|
337 | } | |
286 | else |
|
338 | else | |
287 | { |
|
339 | { | |
288 | SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz"); |
|
340 | SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz"); | |
289 | } |
|
341 | } | |
290 |
|
342 | |||
291 | // read the link status |
|
343 | // read the link status | |
292 | if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS) |
|
344 | if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS) | |
293 | { |
|
345 | { | |
294 | SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber)); |
|
346 | SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber)); | |
295 | return false; |
|
347 | return false; | |
296 | } |
|
348 | } | |
297 | else |
|
349 | else | |
298 | { |
|
350 | { | |
299 | SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber)); |
|
351 | SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber)); | |
300 |
|
352 | |||
301 | // Set the link status control register properties |
|
353 | // Set the link status control register properties | |
302 | CFGSpaceWire_LSEnableAutoStart(&statusControl, 1); |
|
354 | CFGSpaceWire_LSEnableAutoStart(&statusControl, 1); | |
303 | CFGSpaceWire_LSEnableStart(&statusControl, 1); |
|
355 | CFGSpaceWire_LSEnableStart(&statusControl, 1); | |
304 | CFGSpaceWire_LSEnableDisabled(&statusControl, 0); |
|
356 | CFGSpaceWire_LSEnableDisabled(&statusControl, 0); | |
305 | CFGSpaceWire_LSEnableTristate(&statusControl, 0); |
|
357 | CFGSpaceWire_LSEnableTristate(&statusControl, 0); | |
306 | CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz |
|
358 | CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz | |
307 |
|
359 | |||
308 | // Set the link status control register |
|
360 | // Set the link status control register | |
309 | if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS) |
|
361 | if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS) | |
310 | { |
|
362 | { | |
311 | SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber)); |
|
363 | SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber)); | |
312 | return false; |
|
364 | return false; | |
313 | } |
|
365 | } | |
314 | else |
|
366 | else | |
315 | { |
|
367 | { | |
316 | SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber)); |
|
368 | SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber)); | |
317 | } |
|
369 | } | |
318 | } |
|
370 | } | |
319 |
|
371 | |||
320 | if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS) |
|
372 | if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS) | |
321 | { |
|
373 | { | |
322 | SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface"); |
|
374 | SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface"); | |
323 | return false; |
|
375 | return false; | |
324 | } |
|
376 | } | |
325 | else |
|
377 | else | |
326 | { |
|
378 | { | |
327 | SocExplorerEngine::message(this->plugin,"Device set to be an interface"); |
|
379 | SocExplorerEngine::message(this->plugin,"Device set to be an interface"); | |
328 | } |
|
380 | } | |
329 |
|
381 | |||
330 | USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports |
|
382 | USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports | |
331 | USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints |
|
383 | USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints | |
332 | USBSpaceWire_SetTimeout(hDevice,1.0); |
|
384 | USBSpaceWire_SetTimeout(hDevice,1.0); | |
333 | SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes"); |
|
385 | SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes"); | |
334 | SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes"); |
|
386 | SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes"); | |
335 | SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice))); |
|
387 | SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice))); | |
336 | this->connected = true; |
|
388 | this->connected = true; | |
337 | this->handleMutex->unlock(); |
|
389 | this->handleMutex->unlock(); | |
338 | return true; |
|
390 | return true; | |
339 | } |
|
391 | } | |
340 |
|
392 | |||
341 | bool stardundeeSPW_USB_Manager::disconnectBridge() |
|
393 | bool stardundeeSPW_USB_Manager::disconnectBridge() | |
342 | { |
|
394 | { | |
343 | this->handleMutex->lock(); |
|
395 | this->handleMutex->lock(); | |
344 | USBSpaceWire_Close(hDevice); // Close the device |
|
396 | USBSpaceWire_Close(hDevice); // Close the device | |
345 | SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0)); |
|
397 | SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0)); | |
346 | USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports |
|
398 | USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports | |
347 | this->handleMutex->unlock(); |
|
399 | this->handleMutex->unlock(); | |
348 | return true; |
|
400 | return true; | |
349 | } |
|
401 | } | |
350 |
|
402 | |||
351 | int stardundeeSPW_USB_Manager::getRMAPtransactionID() |
|
403 | int stardundeeSPW_USB_Manager::getRMAPtransactionID() | |
352 | { |
|
404 | { | |
353 | this->RMAP_pending_transaction_IDsMtx->lock(); |
|
405 | this->RMAP_pending_transaction_IDsMtx->lock(); | |
354 | int ID=0; |
|
406 | int ID=0; | |
355 | bool found=true; |
|
407 | bool found=true; | |
356 | while(ID<65536) |
|
408 | while(ID<65536) | |
357 | { |
|
409 | { | |
358 | for(int i=0;i<RMAP_pending_transaction_IDs.count();i++) |
|
410 | for(int i=0;i<RMAP_pending_transaction_IDs.count();i++) | |
359 | { |
|
411 | { | |
360 | if(RMAP_pending_transaction_IDs[i]==ID)found=false; |
|
412 | if(RMAP_pending_transaction_IDs[i]==ID)found=false; | |
361 | } |
|
413 | } | |
362 | if(found==true)break; |
|
414 | if(found==true)break; | |
363 | ID++; |
|
415 | ID++; | |
364 | found = true; |
|
416 | found = true; | |
365 | } |
|
417 | } | |
366 | if(found) |
|
418 | if(found) | |
367 | { |
|
419 | { | |
368 | RMAP_pending_transaction_IDs.append(ID); |
|
420 | RMAP_pending_transaction_IDs.append(ID); | |
369 | } |
|
421 | } | |
370 | this->RMAP_pending_transaction_IDsMtx->unlock(); |
|
422 | this->RMAP_pending_transaction_IDsMtx->unlock(); | |
371 | return ID; |
|
423 | return ID; | |
372 | } |
|
424 | } | |
373 |
|
425 | |||
374 | int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer) |
|
426 | int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer) | |
375 | { |
|
427 | { | |
376 | *buffer=NULL; |
|
428 | *buffer=NULL; | |
377 | int count=0; |
|
429 | int count=0; | |
378 | while (*buffer==NULL) |
|
430 | while (*buffer==NULL) | |
379 | { |
|
431 | { | |
380 | this->RMAP_AnswersMtx->lock(); |
|
432 | this->RMAP_AnswersMtx->lock(); | |
381 | for(int i=0;i<RMAP_Answers.count();i++) |
|
433 | for(int i=0;i<RMAP_Answers.count();i++) | |
382 | { |
|
434 | { | |
383 | if(RMAP_Answers[i]->transactionID==transactionID) |
|
435 | if(RMAP_Answers[i]->transactionID==transactionID) | |
384 | { |
|
436 | { | |
385 | this->RMAP_pending_transaction_IDsMtx->lock(); |
|
437 | this->RMAP_pending_transaction_IDsMtx->lock(); | |
386 | for(int j=0;j<RMAP_pending_transaction_IDs.count();j++) |
|
438 | for(int j=0;j<RMAP_pending_transaction_IDs.count();j++) | |
387 | { |
|
439 | { | |
388 | if(RMAP_pending_transaction_IDs[j]==transactionID) |
|
440 | if(RMAP_pending_transaction_IDs[j]==transactionID) | |
389 | { |
|
441 | { | |
390 | RMAP_pending_transaction_IDs.removeAt(j); |
|
442 | RMAP_pending_transaction_IDs.removeAt(j); | |
391 | } |
|
443 | } | |
392 | } |
|
444 | } | |
393 | this->RMAP_pending_transaction_IDsMtx->unlock(); |
|
445 | this->RMAP_pending_transaction_IDsMtx->unlock(); | |
394 | *buffer = RMAP_Answers[i]->data; |
|
446 | *buffer = RMAP_Answers[i]->data; | |
395 | count = RMAP_Answers[i]->len; |
|
447 | count = RMAP_Answers[i]->len; | |
396 | RMAP_Answer* tmp=RMAP_Answers[i]; |
|
448 | RMAP_Answer* tmp=RMAP_Answers[i]; | |
397 | RMAP_Answers.removeAt(i); |
|
449 | RMAP_Answers.removeAt(i); | |
398 | delete tmp; |
|
450 | delete tmp; | |
399 | } |
|
451 | } | |
400 | } |
|
452 | } | |
401 | this->RMAP_AnswersMtx->unlock(); |
|
453 | this->RMAP_AnswersMtx->unlock(); | |
402 | //if no answer found in the stack wait until a new packet is pushed |
|
454 | //if no answer found in the stack wait until a new packet is pushed | |
403 | if(!buffer) |
|
455 | if(!buffer) | |
404 | { |
|
456 | { | |
405 | SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed"); |
|
457 | SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed"); | |
406 | this->RMAP_AnswersSem->acquire(); |
|
458 | this->RMAP_AnswersSem->acquire(); | |
407 | } |
|
459 | } | |
408 | } |
|
460 | } | |
409 | return count; |
|
461 | return count; | |
410 | } |
|
462 | } | |
411 |
|
463 | |||
412 | bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size) |
|
464 | bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size) | |
413 | { |
|
465 | { | |
414 | USB_SPACEWIRE_STATUS result; |
|
466 | USB_SPACEWIRE_STATUS result; | |
415 | USB_SPACEWIRE_ID pIdentifier; |
|
467 | USB_SPACEWIRE_ID pIdentifier; | |
416 | SocExplorerEngine::message(this->plugin,"Sending SPW packet"); |
|
468 | SocExplorerEngine::message(this->plugin,"Sending SPW packet"); | |
417 | this->handleMutex->lock(); |
|
469 | this->handleMutex->lock(); | |
418 | result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier); |
|
470 | result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier); | |
419 | if (result != TRANSFER_SUCCESS) |
|
471 | if (result != TRANSFER_SUCCESS) | |
420 | { |
|
472 | { | |
421 | SocExplorerEngine::message(this->plugin,"ERR sending the READ command "); |
|
473 | SocExplorerEngine::message(this->plugin,"ERR sending the READ command "); | |
422 | this->handleMutex->unlock(); |
|
474 | this->handleMutex->unlock(); | |
423 | return false; |
|
475 | return false; | |
424 | } |
|
476 | } | |
425 | else |
|
477 | else | |
426 | { |
|
478 | { | |
427 | SocExplorerEngine::message(this->plugin,"Packet sent"); |
|
479 | SocExplorerEngine::message(this->plugin,"Packet sent"); | |
428 | USBSpaceWire_FreeSend(hDevice, pIdentifier); |
|
480 | USBSpaceWire_FreeSend(hDevice, pIdentifier); | |
429 | } |
|
481 | } | |
430 | this->handleMutex->unlock(); |
|
482 | this->handleMutex->unlock(); | |
431 | return true; |
|
483 | return true; | |
432 | } |
|
484 | } | |
433 |
|
485 | |||
434 | void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len) |
|
486 | void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len) | |
435 | { |
|
487 | { | |
436 | char* packetbuffer = (char*)malloc(len); |
|
488 | char* packetbuffer = (char*)malloc(len); | |
437 | memcpy(packetbuffer,packet,len); |
|
489 | memcpy(packetbuffer,packet,len); | |
438 | RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len); |
|
490 | RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len); | |
439 | RMAP_AnswersMtx->lock(); |
|
491 | RMAP_AnswersMtx->lock(); | |
440 | RMAP_Answers.append(RMPAPpacket); |
|
492 | RMAP_Answers.append(RMPAPpacket); | |
441 | RMAP_AnswersMtx->unlock(); |
|
493 | RMAP_AnswersMtx->unlock(); | |
442 | } |
|
494 | } | |
443 |
|
495 | |||
444 |
|
496 | |||
445 |
|
497 | |||
446 |
|
498 | |||
447 |
|
499 | |||
448 |
|
500 | |||
449 |
|
501 | |||
450 |
|
502 | |||
451 |
|
503 | |||
452 |
|
504 | |||
453 |
|
505 | |||
454 |
|
506 | |||
455 |
|
507 | |||
456 |
|
508 | |||
457 |
|
509 | |||
458 |
|
510 | |||
459 |
|
511 | |||
460 |
|
512 | |||
461 |
|
513 | |||
462 |
|
514 | |||
463 |
|
515 | |||
464 |
|
516 |
@@ -1,71 +1,97 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the SocExplorer Software | |||
|
3 | -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS | |||
|
4 | -- | |||
|
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 | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
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 | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
1 | #ifndef STARDUNDEESPW_USB_H |
|
22 | #ifndef STARDUNDEESPW_USB_H | |
2 | #define STARDUNDEESPW_USB_H |
|
23 | #define STARDUNDEESPW_USB_H | |
3 |
|
24 | |||
4 | #include <QObject> |
|
25 | #include <QObject> | |
5 | #include <spw_usb_api.h> |
|
26 | #include <spw_usb_api.h> | |
6 | #include <spw_config_library.h> |
|
27 | #include <spw_config_library.h> | |
7 | #include <socexplorerplugin.h> |
|
28 | #include <socexplorerplugin.h> | |
8 | #include <abstractspwbridge.h> |
|
29 | #include <abstractspwbridge.h> | |
9 | #include <QThread> |
|
30 | #include <QThread> | |
10 | #include <QMutex> |
|
31 | #include <QMutex> | |
11 | #include <QSemaphore> |
|
32 | #include <QSemaphore> | |
|
33 | #include <QGridLayout> | |||
|
34 | #include <QPushButton> | |||
12 |
|
35 | |||
13 | class RMAP_Answer |
|
36 | class RMAP_Answer | |
14 | { |
|
37 | { | |
15 | public: |
|
38 | public: | |
16 | RMAP_Answer(int ID,char* data,int len) |
|
39 | RMAP_Answer(int ID,char* data,int len) | |
17 | { |
|
40 | { | |
18 | transactionID = ID; |
|
41 | transactionID = ID; | |
19 | this->data = data; |
|
42 | this->data = data; | |
20 | this->len = len; |
|
43 | this->len = len; | |
21 | } |
|
44 | } | |
22 | int transactionID; |
|
45 | int transactionID; | |
23 | char* data; |
|
46 | char* data; | |
24 | int len; |
|
47 | int len; | |
25 | }; |
|
48 | }; | |
26 |
|
49 | |||
27 | class stardundeeSPW_USB_Manager: public QThread |
|
50 | class stardundeeSPW_USB_Manager: public QThread | |
28 | { |
|
51 | { | |
29 | Q_OBJECT |
|
52 | Q_OBJECT | |
30 | public: |
|
53 | public: | |
31 |
explicit stardundeeSPW_USB_Manager(socexplorerplugin *p |
|
54 | explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0); | |
32 | ~stardundeeSPW_USB_Manager(); |
|
55 | ~stardundeeSPW_USB_Manager(); | |
33 | void run(); |
|
56 | void run(); | |
34 | bool connectBridge(); |
|
57 | bool connectBridge(); | |
35 | bool disconnectBridge(); |
|
58 | bool disconnectBridge(); | |
36 | int getRMAPtransactionID(); |
|
59 | int getRMAPtransactionID(); | |
37 | int getRMAPanswer(int transactionID,char** buffer); |
|
60 | int getRMAPanswer(int transactionID,char** buffer); | |
38 | bool sendPacket(char* packet,int size); |
|
61 | bool sendPacket(char* packet,int size); | |
39 | private: |
|
62 | private: | |
40 | QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx; |
|
63 | QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx; | |
41 | QSemaphore* RMAP_AnswersSem; |
|
64 | QSemaphore* RMAP_AnswersSem; | |
42 | void pushRmapPacket(char* packet,int len); |
|
65 | void pushRmapPacket(char* packet,int len); | |
43 | star_device_handle hDevice; |
|
66 | star_device_handle hDevice; | |
44 | socexplorerplugin* plugin; |
|
67 | socexplorerplugin* plugin; | |
45 | bool connected; |
|
68 | bool connected; | |
46 | char* SPWPacketBuff; |
|
69 | char* SPWPacketBuff; | |
47 | QList<RMAP_Answer*> RMAP_Answers; |
|
70 | QList<RMAP_Answer*> RMAP_Answers; | |
48 | QList<int> RMAP_pending_transaction_IDs; |
|
71 | QList<int> RMAP_pending_transaction_IDs; | |
49 | }; |
|
72 | }; | |
50 |
|
73 | |||
51 | class stardundeeSPW_USB : public abstractSpwBridge |
|
74 | class stardundeeSPW_USB : public abstractSpwBridge | |
52 | { |
|
75 | { | |
53 | Q_OBJECT |
|
76 | Q_OBJECT | |
54 | public: |
|
77 | public: | |
55 | explicit stardundeeSPW_USB(socexplorerplugin *parent = 0); |
|
78 | explicit stardundeeSPW_USB(socexplorerplugin *parent = 0); | |
|
79 | ~stardundeeSPW_USB(); | |||
56 |
|
80 | |||
57 | signals: |
|
81 | signals: | |
58 |
|
82 | |||
59 | public slots: |
|
83 | public slots: | |
|
84 | void toggleBridgeConnection(); | |||
60 | bool connectBridge(); |
|
85 | bool connectBridge(); | |
61 | bool disconnectBridge(); |
|
86 | bool disconnectBridge(); | |
62 | int pushRMAPPacket(char* packet,int size); |
|
87 | int pushRMAPPacket(char* packet,int size); | |
63 | unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); |
|
88 | unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); | |
64 | unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); |
|
89 | unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); | |
65 |
|
90 | |||
66 | private: |
|
91 | private: | |
67 | stardundeeSPW_USB_Manager* manager; |
|
92 | stardundeeSPW_USB_Manager* manager; | |
68 |
|
93 | QGridLayout* mainLayout; | ||
|
94 | QPushButton* connectBridgeButton; | |||
69 | }; |
|
95 | }; | |
70 |
|
96 | |||
71 | #endif // STARDUNDEESPW_USB_H |
|
97 | #endif // STARDUNDEESPW_USB_H |
General Comments 0
You need to be logged in to leave comments.
Login now