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