##// END OF EJS Templates
Sync
jeandet -
r10:c68f11fff944 default
parent child
Show More
@@ -0,0 +1,104
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>StarDundeeUI</class>
4 <widget class="QWidget" name="StarDundeeUI">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>614</width>
10 <height>152</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Form</string>
15 </property>
16 <layout class="QFormLayout" name="formLayout">
17 <property name="fieldGrowthPolicy">
18 <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
19 </property>
20 <item row="0" column="0">
21 <widget class="QLabel" name="selectBrickLbl">
22 <property name="text">
23 <string>Select Brick</string>
24 </property>
25 </widget>
26 </item>
27 <item row="0" column="1">
28 <widget class="QComboBox" name="selectBrickCmbx">
29 <item>
30 <property name="text">
31 <string>None</string>
32 </property>
33 </item>
34 </widget>
35 </item>
36 <item row="1" column="0">
37 <widget class="QLabel" name="selectLinkLbl">
38 <property name="text">
39 <string>Select link number</string>
40 </property>
41 </widget>
42 </item>
43 <item row="1" column="1">
44 <widget class="QComboBox" name="selectLinkCmbx">
45 <item>
46 <property name="text">
47 <string>1</string>
48 </property>
49 </item>
50 <item>
51 <property name="text">
52 <string>2</string>
53 </property>
54 </item>
55 </widget>
56 </item>
57 <item row="2" column="0">
58 <widget class="QLabel" name="selectLinkSpeedLbl">
59 <property name="text">
60 <string>Link Speed</string>
61 </property>
62 </widget>
63 </item>
64 <item row="2" column="1">
65 <widget class="QComboBox" name="setLinkSpeedCmbx">
66 <item>
67 <property name="text">
68 <string>10MHz</string>
69 </property>
70 </item>
71 </widget>
72 </item>
73 <item row="3" column="0">
74 <widget class="QLabel" name="setDestKeyLbl">
75 <property name="text">
76 <string>Destination key</string>
77 </property>
78 </widget>
79 </item>
80 <item row="3" column="1">
81 <widget class="QLineEdit" name="destKeyLineEdit">
82 <property name="inputMask">
83 <string comment="009"/>
84 </property>
85 <property name="text">
86 <string>32</string>
87 </property>
88 <property name="maxLength">
89 <number>3</number>
90 </property>
91 </widget>
92 </item>
93 <item row="4" column="1">
94 <widget class="QPushButton" name="pushButton">
95 <property name="text">
96 <string>Connect</string>
97 </property>
98 </widget>
99 </item>
100 </layout>
101 </widget>
102 <resources/>
103 <connections/>
104 </ui>
@@ -0,0 +1,9
1 #include "stardundeegui.h"
2
3 #include "ui_stardundeeGUI.h"
4
5 StarDundeeGUI::StarDundeeGUI(QWidget *parent) :
6 QWidget(parent),ui(new Ui::StarDundeeUI)
7 {
8 this->ui->setupUi(this);
9 }
@@ -0,0 +1,24
1 #ifndef STARDUNDEEGUI_H
2 #define STARDUNDEEGUI_H
3
4 #include <QWidget>
5
6 namespace Ui {
7 class StarDundeeUI;
8 }
9
10 class StarDundeeGUI : public QWidget
11 {
12 Q_OBJECT
13 public:
14 explicit StarDundeeGUI(QWidget *parent = 0);
15
16 signals:
17
18 public slots:
19
20 private:
21 Ui::StarDundeeUI *ui;
22 };
23
24 #endif // STARDUNDEEGUI_H
@@ -1,69 +1,74
1 #
1 #
2 # Project created by QtCreator 2011-09-20T08:15:30
2 # Project created by QtCreator 2011-09-20T08:15:30
3 #
3 #
4 #-------------------------------------------------
4 #-------------------------------------------------
5
5
6 CONFIG += socexplorerplugin
6 CONFIG += socexplorerplugin
7 win32:CONFIG += dll
7 win32:CONFIG += dll
8 win32:CONFIG -= static
8 win32:CONFIG -= static
9 CONFIG(debug, debug|release) {
9 CONFIG(debug, debug|release) {
10 DEBUG_EXT = _d
10 DEBUG_EXT = _d
11 } else {
11 } else {
12 DEBUG_EXT =
12 DEBUG_EXT =
13 }
13 }
14 TARGET = spwplugin$${DEBUG_EXT}
14 TARGET = spwplugin$${DEBUG_EXT}
15 DEFINES += PLUGIN=spwplugin
15 DEFINES += PLUGIN=spwplugin
16 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
16 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
17 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
17 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
18 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
18 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
19 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
19 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
20 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
20 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
21 DEFINES += driver_can_be_root=1
21 DEFINES += driver_can_be_root=1
22 DEFINES += driver_can_be_child=0
22 DEFINES += driver_can_be_child=0
23 DEFINES += driver_VID=0
23 DEFINES += driver_VID=0
24 DEFINES += driver_PID=0
24 DEFINES += driver_PID=0
25
25
26 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
26 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
27
27
28 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
28 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
29 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
29 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
30
30
31 INCLUDEPATH += \
31 INCLUDEPATH += \
32 $${PWD} \
32 $${PWD} \
33 $$STARTDUNDEEPATH/inc \
33 $$STARTDUNDEEPATH/inc \
34
34
35 HEADERS += \
35 HEADERS += \
36 spwplugin.h \
36 spwplugin.h \
37 stardundeespw_usb.h \
37 stardundeespw_usb.h \
38 abstractspwbridge.h \
38 abstractspwbridge.h \
39 spw.h
39 spw.h \
40 stardundeegui.h
40
41
41
42
42 SOURCES += \
43 SOURCES += \
43 spwplugin.cpp \
44 spwplugin.cpp \
44 stardundeespw_usb.cpp \
45 stardundeespw_usb.cpp \
45 abstractspwbridge.cpp
46 abstractspwbridge.cpp \
47 stardundeegui.cpp
48
49 FORMS += \
50 stardundeeGUI.ui
46
51
47
52
48
53
49
54
50
55
51
56
52
57
53
58
54
59
55
60
56
61
57
62
58
63
59
64
60
65
61
66
62
67
63
68
64
69
65
70
66
71
67
72
68
73
69
74
@@ -1,521 +1,522
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22
22
23 #include "stardundeespw_usb.h"
23 #include "stardundeespw_usb.h"
24 #include <socexplorerengine.h>
24 #include <socexplorerengine.h>
25 #include <qhexedit.h>
25 #include <qhexedit.h>
26
26
27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
28 abstractSpwBridge(parent)
28 abstractSpwBridge(parent)
29 {
29 {
30 Q_UNUSED(parent)
30 Q_UNUSED(parent)
31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
32 makeGUI(socexplorerplugin *parent);
32 makeGUI(parent);
33 this->manager->start();
33 this->manager->start();
34 }
34 }
35
35
36 stardundeeSPW_USB::~stardundeeSPW_USB()
36 stardundeeSPW_USB::~stardundeeSPW_USB()
37 {
37 {
38 this->manager->requestInterruption();
38 this->manager->requestInterruption();
39 delete this->p_GUI;
39 delete this->p_GUI;
40 }
40 }
41
41
42 void stardundeeSPW_USB::toggleBridgeConnection()
42 void stardundeeSPW_USB::toggleBridgeConnection()
43 {
43 {
44 if(this->plugin->isConnected())
44 if(this->plugin->isConnected())
45 {
45 {
46 if(this->disconnectBridge())
46 if(this->disconnectBridge())
47 {
47 {
48 this->connectBridgeButton->setText("Connect");
48 this->connectBridgeButton->setText("Connect");
49 }
49 }
50 }
50 }
51 else
51 else
52 {
52 {
53 if(this->connectBridge())
53 if(this->connectBridge())
54 {
54 {
55 this->connectBridgeButton->setText("Disconnect");
55 this->connectBridgeButton->setText("Disconnect");
56 }
56 }
57 }
57 }
58 }
58 }
59
59
60 bool stardundeeSPW_USB::connectBridge()
60 bool stardundeeSPW_USB::connectBridge()
61 {
61 {
62 return this->manager->connectBridge();
62 return this->manager->connectBridge();
63 }
63 }
64
64
65 bool stardundeeSPW_USB::disconnectBridge()
65 bool stardundeeSPW_USB::disconnectBridge()
66 {
66 {
67 return this->manager->disconnectBridge();
67 return this->manager->disconnectBridge();
68 }
68 }
69
69
70 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
70 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
71 {
71 {
72 return this->manager->sendPacket(packet,size);
72 return this->manager->sendPacket(packet,size);
73 }
73 }
74
74
75 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
75 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
76 {
76 {
77 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
77 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
78 writeBuffer[0]=1;//Link number
78 writeBuffer[0]=1;//Link number
79 int transactionID = 0;
79 int transactionID = 0;
80 int written=0;
80 int written=0;
81 SocExplorerEngine::message(this->plugin,"Enter Write function");
81 SocExplorerEngine::message(this->plugin,"Enter Write function");
82 QProgressBar* progress=NULL;
82 QProgressBar* progress=NULL;
83 if(count>RMAP_MAX_XFER_SIZE)
83 if(count>RMAP_MAX_XFER_SIZE)
84 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
84 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
85 //Quite stupide loop, I guess that I always get the number of byte I asked for!
85 //Quite stupide loop, I guess that I always get the number of byte I asked for!
86 while(count>=RMAP_MAX_XFER_SIZE)
86 while(count>=RMAP_MAX_XFER_SIZE)
87 {
87 {
88 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
88 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
89 {
89 {
90 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
90 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
91 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
91 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
92 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
92 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
93 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
93 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
94 }
94 }
95 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
95 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
96 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
96 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
97 written+=RMAP_MAX_XFER_SIZE;
97 written+=RMAP_MAX_XFER_SIZE;
98 count-=RMAP_MAX_XFER_SIZE;
98 count-=RMAP_MAX_XFER_SIZE;
99 progress->setValue(written);
99 progress->setValue(written);
100 qApp->processEvents();
100 qApp->processEvents();
101 }
101 }
102 if(count>0)
102 if(count>0)
103 {
103 {
104 for(int i=0;i<((int)count);i++)
104 for(int i=0;i<((int)count);i++)
105 {
105 {
106 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
106 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
107 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
107 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
108 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
108 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
109 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
109 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
110 }
110 }
111 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
111 RMAP_build_tx_request_header(254,2,1,transactionID,address+(written*4),count*4,writeBuffer+1);
112 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
112 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
113 written+=count;
113 written+=count;
114 if(progress!=NULL)
114 if(progress!=NULL)
115 {
115 {
116 progress->setValue(written);
116 progress->setValue(written);
117 qApp->processEvents();
117 qApp->processEvents();
118 }
118 }
119 }
119 }
120 if(progress!=NULL)
120 if(progress!=NULL)
121 {
121 {
122 SocExplorerEngine::deleteProgressBar(progress);
122 SocExplorerEngine::deleteProgressBar(progress);
123 }
123 }
124 return written;
124 return written;
125 }
125 }
126
126
127 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
127 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
128 {
128 {
129 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
129 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
130 char* RMAP_AnswerBuffer;
130 char* RMAP_AnswerBuffer;
131 requestBuffer[0]=1;//Link number
131 requestBuffer[0]=1;//Link number
132 int transactionID = 0;
132 int transactionID = 0;
133 int read=0;
133 int read=0;
134 QProgressBar* progress=NULL;
134 QProgressBar* progress=NULL;
135 if(count>RMAP_MAX_XFER_SIZE)
135 if(count>RMAP_MAX_XFER_SIZE)
136 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
136 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
137 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
137 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE));
138
138
139 //Quite stupide loop, I guess that I always get the number of byte I asked for!
139 //Quite stupide loop, I guess that I always get the number of byte I asked for!
140 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
140 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
141 {
141 {
142 transactionID = manager->getRMAPtransactionID();
142 transactionID = manager->getRMAPtransactionID();
143 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
143 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID));
144 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
144 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
145 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
145 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
146 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
146 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
147 for(int i=0;i<((len-13)/4);i++)
147 for(int i=0;i<((len-13)/4);i++)
148 {
148 {
149 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
149 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
150 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
150 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
151 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
151 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
152 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
152 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
153 }
153 }
154 free(RMAP_AnswerBuffer);
154 free(RMAP_AnswerBuffer);
155 read+=RMAP_MAX_XFER_SIZE;
155 read+=RMAP_MAX_XFER_SIZE;
156 count-=RMAP_MAX_XFER_SIZE;
156 count-=RMAP_MAX_XFER_SIZE;
157 progress->setValue(read);
157 progress->setValue(read);
158 qApp->processEvents();
158 qApp->processEvents();
159 }
159 }
160 if((int)count>0)
160 if((int)count>0)
161 {
161 {
162 transactionID = manager->getRMAPtransactionID();
162 transactionID = manager->getRMAPtransactionID();
163 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
163 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID));
164 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
164 SocExplorerEngine::message(this->plugin,QString("Building request with:"));
165 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
165 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16));
166 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
166 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4));
167 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
167 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13));
168 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
168 RMAP_build_rx_request_header(254,2,1,transactionID,address+(read*4),count*4,requestBuffer+1);
169 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
169 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
170 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
170 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
171 for(int i=0;i<((len-13)/4);i++)
171 for(int i=0;i<((len-13)/4);i++)
172 {
172 {
173 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
173 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
174 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
174 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
175 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
175 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
176 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
176 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
177 }
177 }
178 free(RMAP_AnswerBuffer);
178 free(RMAP_AnswerBuffer);
179 read+=count;
179 read+=count;
180 if(progress!=NULL)
180 if(progress!=NULL)
181 {
181 {
182 progress->setValue(read);
182 progress->setValue(read);
183 qApp->processEvents();
183 qApp->processEvents();
184 }
184 }
185 }
185 }
186 if(progress!=NULL)
186 if(progress!=NULL)
187 {
187 {
188 SocExplorerEngine::deleteProgressBar(progress);
188 SocExplorerEngine::deleteProgressBar(progress);
189 }
189 }
190 return read;
190 return read;
191 }
191 }
192
192
193 void stardundeeSPW_USB::updateAvailableBrickCount(int count)
194 {
195
196 }
197
193 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
198 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
194 {
199 {
195 this->p_GUI = new QWidget(parent);
200 this->p_GUI = new StarDundeeGUI(plugin);
196 this->mainLayout = new QGridLayout(this->p_GUI);
201 this->mainLayout = new QGridLayout(this->p_GUI);
197 this->p_GUI->setLayout(mainLayout);
202 // connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
198 this->connectBridgeButton = new QPushButton("Connect");
199 this->mainLayout->addWidget(this->connectBridgeButton,1,0,1,1);
200 connect(this->connectBridgeButton,SIGNAL(clicked()),this,SLOT(toggleBridgeConnection()));
201 }
203 }
202
204
203 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
205 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
204 :QThread((QObject*)parent)
206 :QThread((QObject*)parent)
205 {
207 {
206 this->handleMutex = new QMutex(QMutex::NonRecursive);
208 this->handleMutex = new QMutex(QMutex::NonRecursive);
207 this->RMAP_AnswersSem = new QSemaphore(0);
209 this->RMAP_AnswersSem = new QSemaphore(0);
208 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
210 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
209 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
211 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
210 this->plugin = plugin;
212 this->plugin = plugin;
211 connected = false;
213 connected = false;
212 }
214 }
213
215
214 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
216 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
215 {
217 {
216 this->terminate();
218 this->terminate();
217 while (!this->isFinished()) {
219 while (!this->isFinished()) {
218 this->usleep(1000);
220 this->usleep(1000);
219 }
221 }
220 }
222 }
221
223
222
224
223 void stardundeeSPW_USB_Manager::run()
225 void stardundeeSPW_USB_Manager::run()
224 {
226 {
225 USB_SPACEWIRE_PACKET_PROPERTIES properties;
227 USB_SPACEWIRE_PACKET_PROPERTIES properties;
226 USB_SPACEWIRE_ID pIdentifier=NULL;
228 USB_SPACEWIRE_ID pIdentifier=NULL;
227 USB_SPACEWIRE_STATUS stat;
229 USB_SPACEWIRE_STATUS stat;
228 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
230 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread");
229 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
231 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
230 while (!this->isInterruptionRequested())
232 while (!this->isInterruptionRequested())
231 {
233 {
232 if(this->connected)
234 if(this->connected)
233 {
235 {
234 handleMutex->lock();
236 handleMutex->lock();
235 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
237 //SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets");
236 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
238 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
237 {
239 {
238 SocExplorerEngine::message(this->plugin,"Got packet");
240 SocExplorerEngine::message(this->plugin,"Got packet");
239 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
241 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
240 if (stat == TRANSFER_SUCCESS)
242 if (stat == TRANSFER_SUCCESS)
241 {
243 {
242 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
244 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
243 {
245 {
244 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
246 SocExplorerEngine::message(this->plugin,"It's a SPW packet");
245 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
247 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
246 {
248 {
247 SocExplorerEngine::message(this->plugin,"Got end of packet");
249 SocExplorerEngine::message(this->plugin,"Got end of packet");
248 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
250 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
249 {
251 {
250 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
252 SocExplorerEngine::message(this->plugin,"Got RMAP packet");
251 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
253 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len));
252 if(properties.len>8)
254 if(properties.len>8)
253 {
255 {
254 char* packetbuffer = (char*)malloc(properties.len);
256 char* packetbuffer = (char*)malloc(properties.len);
255 memcpy(packetbuffer,buffer,properties.len);
257 memcpy(packetbuffer,buffer,properties.len);
256 USBSpaceWire_FreeRead(hDevice, pIdentifier);
258 USBSpaceWire_FreeRead(hDevice, pIdentifier);
257 pIdentifier = NULL;
259 pIdentifier = NULL;
258 handleMutex->unlock();
260 handleMutex->unlock();
259 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
261 RMAP_Answer* packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
260 RMAP_AnswersMtx->lock();
262 RMAP_AnswersMtx->lock();
261 RMAP_Answers.append(packet);
263 RMAP_Answers.append(packet);
262 RMAP_AnswersMtx->unlock();
264 RMAP_AnswersMtx->unlock();
263 RMAP_AnswersSem->release();
265 RMAP_AnswersSem->release();
264
266
265 }
267 }
266 else //it's a RMAP write response
268 else //it's a RMAP write response
267 {
269 {
268 USBSpaceWire_FreeRead(hDevice, pIdentifier);
270 USBSpaceWire_FreeRead(hDevice, pIdentifier);
269 pIdentifier = NULL;
271 pIdentifier = NULL;
270 handleMutex->unlock();
272 handleMutex->unlock();
271 }
273 }
272
274
273 }
275 }
274 else //any non-rmap packet will be pushed to the network
276 else //any non-rmap packet will be pushed to the network
275 {
277 {
276 USBSpaceWire_FreeRead(hDevice, pIdentifier);
278 USBSpaceWire_FreeRead(hDevice, pIdentifier);
277 handleMutex->unlock();
279 handleMutex->unlock();
278 SocExplorerEngine::message(this->plugin,"Got SPW packet");
280 SocExplorerEngine::message(this->plugin,"Got SPW packet");
279 }
281 }
280 }
282 }
281 else
283 else
282 {
284 {
283 SocExplorerEngine::message(this->plugin,"No EOP received");
285 SocExplorerEngine::message(this->plugin,"No EOP received");
284 }
286 }
285 }
287 }
286
288
287 }
289 }
288 else
290 else
289 {
291 {
290 USBSpaceWire_FreeRead(hDevice, pIdentifier);
292 USBSpaceWire_FreeRead(hDevice, pIdentifier);
291 handleMutex->unlock();
293 handleMutex->unlock();
292 }
294 }
293 }
295 }
294 else
296 else
295 {
297 {
296 USBSpaceWire_FreeRead(hDevice, pIdentifier);
298 USBSpaceWire_FreeRead(hDevice, pIdentifier);
297 handleMutex->unlock();
299 handleMutex->unlock();
298 }
300 }
299 }
301 }
300 else
302 else
301 {
303 {
302 sleep(1);
304 sleep(1);
303 SocExplorerEngine::message(this->plugin,"Bridge not connected");
305 this->brickList = USBSpaceWire_ListDevices();
304 }
306 }
305 usleep(1000);
307 usleep(1000);
306 // sleep(2);
307 }
308 }
308 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
309 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread");
309 }
310 }
310
311
311 bool stardundeeSPW_USB_Manager::connectBridge()
312 bool stardundeeSPW_USB_Manager::connectBridge()
312 {
313 {
313 this->handleMutex->lock();
314 this->handleMutex->lock();
314 int status;
315 int status;
315 U32 statusControl;
316 U32 statusControl;
316 int brickNumber=0;
317 int brickNumber=0;
317 int linkNumber=1;
318 int linkNumber=1;
318 this->connected = false;
319 this->connected = false;
319 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
320 if (!USBSpaceWire_Open(&hDevice, brickNumber)) // Open the USB device
320 {
321 {
321 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
322 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
322 this->handleMutex->unlock();
323 this->handleMutex->unlock();
323 return false;
324 return false;
324 }
325 }
325 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
326 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful");
326
327
327 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
328 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
328 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
329 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
329 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
330 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
330
331
331 // Set the path and return path to the device
332 // Set the path and return path to the device
332 CFGSpaceWire_StackClear();
333 CFGSpaceWire_StackClear();
333 CFGSpaceWire_AddrStackPush(0);
334 CFGSpaceWire_AddrStackPush(0);
334 CFGSpaceWire_AddrStackPush(254);
335 CFGSpaceWire_AddrStackPush(254);
335 CFGSpaceWire_RetAddrStackPush(254);
336 CFGSpaceWire_RetAddrStackPush(254);
336 // set the base transmit rate to 100 MHz
337 // set the base transmit rate to 100 MHz
337 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
338 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
338 if (status != CFG_TRANSFER_SUCCESS)
339 if (status != CFG_TRANSFER_SUCCESS)
339 {
340 {
340 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
341 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
341 return false;
342 return false;
342 }
343 }
343 else
344 else
344 {
345 {
345 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
346 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
346 }
347 }
347
348
348 // read the link status
349 // read the link status
349 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
350 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
350 {
351 {
351 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
352 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
352 return false;
353 return false;
353 }
354 }
354 else
355 else
355 {
356 {
356 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
357 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
357
358
358 // Set the link status control register properties
359 // Set the link status control register properties
359 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
360 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
360 CFGSpaceWire_LSEnableStart(&statusControl, 1);
361 CFGSpaceWire_LSEnableStart(&statusControl, 1);
361 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
362 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
362 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
363 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
363 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
364 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
364
365
365 // Set the link status control register
366 // Set the link status control register
366 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
367 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
367 {
368 {
368 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
369 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
369 return false;
370 return false;
370 }
371 }
371 else
372 else
372 {
373 {
373 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
374 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(linkNumber));
374 }
375 }
375 }
376 }
376
377
377 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
378 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
378 {
379 {
379 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
380 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
380 return false;
381 return false;
381 }
382 }
382 else
383 else
383 {
384 {
384 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
385 SocExplorerEngine::message(this->plugin,"Device set to be an interface");
385 }
386 }
386
387
387 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
388 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
388 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
389 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
389 USBSpaceWire_SetTimeout(hDevice,1.0);
390 USBSpaceWire_SetTimeout(hDevice,1.0);
390 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
391 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
391 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
392 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
392 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
393 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
393 this->connected = true;
394 this->connected = true;
394 this->handleMutex->unlock();
395 this->handleMutex->unlock();
395 return true;
396 return true;
396 }
397 }
397
398
398 bool stardundeeSPW_USB_Manager::disconnectBridge()
399 bool stardundeeSPW_USB_Manager::disconnectBridge()
399 {
400 {
400 this->handleMutex->lock();
401 this->handleMutex->lock();
401 USBSpaceWire_Close(hDevice); // Close the device
402 USBSpaceWire_Close(hDevice); // Close the device
402 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
403 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0));
403 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
404 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
404 this->handleMutex->unlock();
405 this->handleMutex->unlock();
405 return true;
406 return true;
406 }
407 }
407
408
408 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
409 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
409 {
410 {
410 this->RMAP_pending_transaction_IDsMtx->lock();
411 this->RMAP_pending_transaction_IDsMtx->lock();
411 int ID=0;
412 int ID=0;
412 bool found=true;
413 bool found=true;
413 while(ID<65536)
414 while(ID<65536)
414 {
415 {
415 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
416 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
416 {
417 {
417 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
418 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
418 }
419 }
419 if(found==true)break;
420 if(found==true)break;
420 ID++;
421 ID++;
421 found = true;
422 found = true;
422 }
423 }
423 if(found)
424 if(found)
424 {
425 {
425 RMAP_pending_transaction_IDs.append(ID);
426 RMAP_pending_transaction_IDs.append(ID);
426 }
427 }
427 this->RMAP_pending_transaction_IDsMtx->unlock();
428 this->RMAP_pending_transaction_IDsMtx->unlock();
428 return ID;
429 return ID;
429 }
430 }
430
431
431 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
432 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
432 {
433 {
433 *buffer=NULL;
434 *buffer=NULL;
434 int count=0;
435 int count=0;
435 while (*buffer==NULL)
436 while (*buffer==NULL)
436 {
437 {
437 this->RMAP_AnswersMtx->lock();
438 this->RMAP_AnswersMtx->lock();
438 for(int i=0;i<RMAP_Answers.count();i++)
439 for(int i=0;i<RMAP_Answers.count();i++)
439 {
440 {
440 if(RMAP_Answers[i]->transactionID==transactionID)
441 if(RMAP_Answers[i]->transactionID==transactionID)
441 {
442 {
442 this->RMAP_pending_transaction_IDsMtx->lock();
443 this->RMAP_pending_transaction_IDsMtx->lock();
443 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
444 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
444 {
445 {
445 if(RMAP_pending_transaction_IDs[j]==transactionID)
446 if(RMAP_pending_transaction_IDs[j]==transactionID)
446 {
447 {
447 RMAP_pending_transaction_IDs.removeAt(j);
448 RMAP_pending_transaction_IDs.removeAt(j);
448 }
449 }
449 }
450 }
450 this->RMAP_pending_transaction_IDsMtx->unlock();
451 this->RMAP_pending_transaction_IDsMtx->unlock();
451 *buffer = RMAP_Answers[i]->data;
452 *buffer = RMAP_Answers[i]->data;
452 count = RMAP_Answers[i]->len;
453 count = RMAP_Answers[i]->len;
453 RMAP_Answer* tmp=RMAP_Answers[i];
454 RMAP_Answer* tmp=RMAP_Answers[i];
454 RMAP_Answers.removeAt(i);
455 RMAP_Answers.removeAt(i);
455 delete tmp;
456 delete tmp;
456 }
457 }
457 }
458 }
458 this->RMAP_AnswersMtx->unlock();
459 this->RMAP_AnswersMtx->unlock();
459 //if no answer found in the stack wait until a new packet is pushed
460 //if no answer found in the stack wait until a new packet is pushed
460 if(!buffer)
461 if(!buffer)
461 {
462 {
462 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
463 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed");
463 this->RMAP_AnswersSem->acquire();
464 this->RMAP_AnswersSem->acquire();
464 }
465 }
465 }
466 }
466 return count;
467 return count;
467 }
468 }
468
469
469 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
470 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
470 {
471 {
471 USB_SPACEWIRE_STATUS result;
472 USB_SPACEWIRE_STATUS result;
472 USB_SPACEWIRE_ID pIdentifier;
473 USB_SPACEWIRE_ID pIdentifier;
473 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
474 SocExplorerEngine::message(this->plugin,"Sending SPW packet");
474 this->handleMutex->lock();
475 this->handleMutex->lock();
475 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
476 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
476 if (result != TRANSFER_SUCCESS)
477 if (result != TRANSFER_SUCCESS)
477 {
478 {
478 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
479 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ");
479 this->handleMutex->unlock();
480 this->handleMutex->unlock();
480 return false;
481 return false;
481 }
482 }
482 else
483 else
483 {
484 {
484 SocExplorerEngine::message(this->plugin,"Packet sent");
485 SocExplorerEngine::message(this->plugin,"Packet sent");
485 USBSpaceWire_FreeSend(hDevice, pIdentifier);
486 USBSpaceWire_FreeSend(hDevice, pIdentifier);
486 }
487 }
487 this->handleMutex->unlock();
488 this->handleMutex->unlock();
488 return true;
489 return true;
489 }
490 }
490
491
491 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
492 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
492 {
493 {
493 char* packetbuffer = (char*)malloc(len);
494 char* packetbuffer = (char*)malloc(len);
494 memcpy(packetbuffer,packet,len);
495 memcpy(packetbuffer,packet,len);
495 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
496 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
496 RMAP_AnswersMtx->lock();
497 RMAP_AnswersMtx->lock();
497 RMAP_Answers.append(RMPAPpacket);
498 RMAP_Answers.append(RMPAPpacket);
498 RMAP_AnswersMtx->unlock();
499 RMAP_AnswersMtx->unlock();
499 }
500 }
500
501
501
502
502
503
503
504
504
505
505
506
506
507
507
508
508
509
509
510
510
511
511
512
512
513
513
514
514
515
515
516
516
517
517
518
518
519
519
520
520
521
521
522
@@ -1,99 +1,104
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2014, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef STARDUNDEESPW_USB_H
22 #ifndef STARDUNDEESPW_USB_H
23 #define STARDUNDEESPW_USB_H
23 #define STARDUNDEESPW_USB_H
24
24
25 #include <QObject>
25 #include <QObject>
26 #include <spw_usb_api.h>
26 #include <spw_usb_api.h>
27 #include <spw_config_library.h>
27 #include <spw_config_library.h>
28 #include <socexplorerplugin.h>
28 #include <socexplorerplugin.h>
29 #include <abstractspwbridge.h>
29 #include <abstractspwbridge.h>
30 #include <QThread>
30 #include <QThread>
31 #include <QMutex>
31 #include <QMutex>
32 #include <QSemaphore>
32 #include <QSemaphore>
33 #include <QGridLayout>
33 #include <QGridLayout>
34 #include <QPushButton>
34 #include <QPushButton>
35 #include <QComboBox>
36 #include <QLabel>
37 #include "stardundeegui.h"
35
38
36 class RMAP_Answer
39 class RMAP_Answer
37 {
40 {
38 public:
41 public:
39 RMAP_Answer(int ID,char* data,int len)
42 RMAP_Answer(int ID,char* data,int len)
40 {
43 {
41 transactionID = ID;
44 transactionID = ID;
42 this->data = data;
45 this->data = data;
43 this->len = len;
46 this->len = len;
44 }
47 }
45 int transactionID;
48 int transactionID;
46 char* data;
49 char* data;
47 int len;
50 int len;
48 };
51 };
49
52
50 class stardundeeSPW_USB_Manager: public QThread
53 class stardundeeSPW_USB_Manager: public QThread
51 {
54 {
52 Q_OBJECT
55 Q_OBJECT
53 public:
56 public:
54 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
57 explicit stardundeeSPW_USB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0);
55 ~stardundeeSPW_USB_Manager();
58 ~stardundeeSPW_USB_Manager();
56 void run();
59 void run();
57 bool connectBridge();
60 bool connectBridge();
58 bool disconnectBridge();
61 bool disconnectBridge();
59 int getRMAPtransactionID();
62 int getRMAPtransactionID();
60 int getRMAPanswer(int transactionID,char** buffer);
63 int getRMAPanswer(int transactionID,char** buffer);
61 bool sendPacket(char* packet,int size);
64 bool sendPacket(char* packet,int size);
62 private:
65 private:
63 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
66 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
64 QSemaphore* RMAP_AnswersSem;
67 QSemaphore* RMAP_AnswersSem;
65 void pushRmapPacket(char* packet,int len);
68 void pushRmapPacket(char* packet,int len);
66 star_device_handle hDevice;
69 star_device_handle hDevice;
67 socexplorerplugin* plugin;
70 socexplorerplugin* plugin;
68 bool connected;
71 bool connected;
69 char* SPWPacketBuff;
72 char* SPWPacketBuff;
70 QList<RMAP_Answer*> RMAP_Answers;
73 QList<RMAP_Answer*> RMAP_Answers;
71 QList<int> RMAP_pending_transaction_IDs;
74 QList<int> RMAP_pending_transaction_IDs;
72 int linkNumber;
75 int linkNumber;
76 int brickList;
73 };
77 };
74
78
75 class stardundeeSPW_USB : public abstractSpwBridge
79 class stardundeeSPW_USB : public abstractSpwBridge
76 {
80 {
77 Q_OBJECT
81 Q_OBJECT
78 public:
82 public:
79 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
83 explicit stardundeeSPW_USB(socexplorerplugin *parent = 0);
80 ~stardundeeSPW_USB();
84 ~stardundeeSPW_USB();
81
85
82 signals:
86 signals:
83
87
84 public slots:
88 public slots:
85 void toggleBridgeConnection();
89 void toggleBridgeConnection();
86 bool connectBridge();
90 bool connectBridge();
87 bool disconnectBridge();
91 bool disconnectBridge();
88 int pushRMAPPacket(char* packet,int size);
92 int pushRMAPPacket(char* packet,int size);
89 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
93 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
90 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
94 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
91
95 void updateAvailableBrickCount(int count);
92 private:
96 private:
93 void makeGUI(socexplorerplugin *parent);
97 void makeGUI(socexplorerplugin *parent);
94 stardundeeSPW_USB_Manager* manager;
98 stardundeeSPW_USB_Manager* manager;
95 QGridLayout* mainLayout;
99 QGridLayout* mainLayout;
96 QPushButton* connectBridgeButton;
100 QPushButton* connectBridgeButton;
101 QComboBox* selectBrickQcmbx;
97 };
102 };
98
103
99 #endif // STARDUNDEESPW_USB_H
104 #endif // STARDUNDEESPW_USB_H
General Comments 0
You need to be logged in to leave comments. Login now