##// END OF EJS Templates
Sync
Jeandet Alexis -
r24:f6b7bed80207 default
parent child
Show More
@@ -1,38 +1,94
1 1 #include "gr_esb_bridge.h"
2 2 #include "gr_esb_ui.h"
3 #include <unistd.h>
3 4
4 5 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
5 6 abstractSpwBridge(parent)
6 7 {
7 8 this->p_GUI = new GR_ESB_ui();
8 this->soc = new QTcpSocket(this);
9 this->Read_soc = new QTcpSocket(this);
10 this->Write_soc = new QTcpSocket(this);
11 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
12 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setPort(QString)));
9 13 }
10 14
11 15 GR_ESB_bridge::~GR_ESB_bridge()
12 16 {
13 17 }
14 18
15 19 bool GR_ESB_bridge::connectBridge()
16 20 {
17
21 int timeout=60;
22 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
23 {
24 this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
25 this->Read_soc->waitForConnected(30000);
26 }
27 if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
28 {
29 this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
30 this->Write_soc->waitForConnected(30000);
31 }
32 while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
33 {
34 usleep(100000);
35 if(timeout--==0)return false;
36 }
37 return true;
18 38 }
19 39
20 40 bool GR_ESB_bridge::disconnectBridge()
21 41 {
42 int timeout=60;
43 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
44 {
45 this->Read_soc->disconnectFromHost();
46 this->Read_soc->waitForDisconnected(30000);
47 while(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
48 {
49 usleep(100000);
50 if(timeout--==0)return false;
51 }
52 }
53 return true;
54 }
22 55
56 void GR_ESB_bridge::setIP(QString ip)
57 {
58 this->IP = ip;
23 59 }
24 60
61 void GR_ESB_bridge::setVirtualLink(QString vlink)
62 {
63 vlink = vlink.section("Virtual link",0,0);
64 bool success;
65 int vlinkTmp = vlink.toInt(&success);
66 if(success)
67 {
68 setVirtualLink(vlinkTmp);
69 }
70 }
71
72 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
73 {
74 if(vlink<6 && vlink>=0)
75 {
76 virtualLinkIndex = vlink;
77 }
78 }
79
80
25 81 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
26 82 {
27 83
28 84 }
29 85
30 86 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
31 87 {
32 88
33 89 }
34 90
35 91 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
36 92 {
37 93
38 94 }
@@ -1,27 +1,50
1 1 #ifndef GR_ESB_BRIDGE_H
2 2 #define GR_ESB_BRIDGE_H
3 3 #include "abstractspwbridge.h"
4 4 #include <QTcpSocket>
5 5
6 struct gresb_Conf_str
7 {
8 qint32 Read_port;
9 qint32 Write_port;
10 };
11
12 const struct gresb_Conf_str gresb_Conf[]=
13 {
14 {3000,3001}, //Virtual link 0
15 {3002,3003}, //Virtual link 1
16 {3004,3005}, //Virtual link 2
17 {3006,3007}, //Virtual link 3
18 {3008,3009}, //Virtual link 4
19 {3010,3011} //Virtual link 5
20 };
21
6 22 class GR_ESB_bridge : public abstractSpwBridge
7 23 {
8 24 Q_OBJECT
9 25 public:
10 26 explicit GR_ESB_bridge(socexplorerplugin *parent = 0);
11 27 ~GR_ESB_bridge();
12 28 signals:
13 29
14 30
15 31 public slots:
16 32 bool connectBridge();
17 33 bool disconnectBridge();
34 void setIP(QString ip);
35 void setVirtualLink(QString vlink);
36 void setVirtualLink(qint32 vlink);
18 37 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
19 38 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
20 39 int pushRMAPPacket(char* packet,int size);
21 40 void packetReceived();
22 41
23 QTcpSocket* soc;
42 private:
43 QTcpSocket* Read_soc;
44 QTcpSocket* Write_soc;
45 QString IP;
46 int virtualLinkIndex;
24 47
25 48 };
26 49
27 50 #endif // GR_ESB_BRIDGE_H
@@ -1,14 +1,19
1 1 #include "gr_esb_ui.h"
2 2 #include "ui_gr_esb_ui.h"
3 #include <QWebView>
3 4
4 5 GR_ESB_ui::GR_ESB_ui(QWidget *parent) :
5 6 QWidget(parent),
6 7 ui(new Ui::GR_ESB_ui)
7 8 {
8 9 ui->setupUi(this);
10 connect(this->ui->GRESB_IP_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changeIp(QString)));
11 connect(this->ui->GRESB_Vlink_CmBx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(vlinkchanged(QString)));
9 12 }
10 13
11 GR_ESB_ui::~GR_ESB_ui()
14 void GR_ESB_ui::changeIp(QString ip)
12 15 {
13 delete ui;
16 this->ui->WebView->load(QUrl("http://"+ip));
17 emit this->ipchanged(ip);
14 18 }
19
@@ -1,22 +1,27
1 1 #ifndef GR_ESB_UI_H
2 2 #define GR_ESB_UI_H
3 3
4 4 #include <QWidget>
5 5
6 6 namespace Ui {
7 7 class GR_ESB_ui;
8 8 }
9 9
10 10 class GR_ESB_ui : public QWidget
11 11 {
12 12 Q_OBJECT
13 13
14 14 public:
15 15 explicit GR_ESB_ui(QWidget *parent = 0);
16 ~GR_ESB_ui();
16
17 public slots:
18 void changeIp(QString ip);
17 19
20 signals:
21 void ipchanged(QString ip);
22 void vlinkchanged(QString vlink);
18 23 private:
19 24 Ui::GR_ESB_ui *ui;
20 25 };
21 26
22 27 #endif // GR_ESB_UI_H
@@ -1,67 +1,139
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>GR_ESB_ui</class>
4 4 <widget class="QWidget" name="GR_ESB_ui">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>489</width>
10 10 <height>295</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="1" column="2">
18 <widget class="QLineEdit" name="GRESB_Port_lineEdit"/>
19 </item>
20 <item row="1" column="0">
21 <widget class="QLabel" name="GRESB_Port_Lbl">
22 <property name="text">
23 <string>GR-ESB Port</string>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <item>
18 <widget class="QTabWidget" name="tabWidget">
19 <property name="toolTip">
20 <string/>
24 21 </property>
25 </widget>
26 </item>
27 <item row="0" column="2">
28 <widget class="QLineEdit" name="GRESB_IP_lineEdit"/>
29 </item>
30 <item row="0" column="0">
31 <widget class="QLabel" name="GRESB_IP_Lbl">
32 <property name="text">
33 <string>GR-ESB IP Address</string>
22 <property name="currentIndex">
23 <number>0</number>
34 24 </property>
35 </widget>
36 </item>
37 <item row="2" column="0">
38 <widget class="QLabel" name="GRESB_LinkNum_Lbl">
39 <property name="text">
40 <string>Select link number</string>
41 </property>
42 </widget>
43 </item>
44 <item row="2" column="2">
45 <widget class="QComboBox" name="GRESB_LinkNum_CmBx">
46 <item>
47 <property name="text">
48 <string>SPW0</string>
25 <widget class="QWidget" name="Config">
26 <property name="toolTip">
27 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Config tab allows you to configure the Ethernet conncetion to the GR-ESB and some spacewire parameters.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
49 28 </property>
50 </item>
51 <item>
52 <property name="text">
53 <string>SPW1</string>
29 <attribute name="title">
30 <string>Config</string>
31 </attribute>
32 <layout class="QGridLayout" name="gridLayout_2">
33 <item row="1" column="1">
34 <widget class="QComboBox" name="GRESB_Vlink_CmBx">
35 <item>
36 <property name="text">
37 <string>Virtual link 0</string>
38 </property>
39 </item>
40 <item>
41 <property name="text">
42 <string>Virtual link 1</string>
43 </property>
44 </item>
45 <item>
46 <property name="text">
47 <string>Virtual link 2</string>
48 </property>
49 </item>
50 <item>
51 <property name="text">
52 <string>Virtual link 3</string>
53 </property>
54 </item>
55 <item>
56 <property name="text">
57 <string>Virtual link 4</string>
58 </property>
59 </item>
60 <item>
61 <property name="text">
62 <string>Virtual link 5</string>
63 </property>
64 </item>
65 </widget>
66 </item>
67 <item row="1" column="0">
68 <widget class="QLabel" name="GRESB_Vlink_Lbl">
69 <property name="text">
70 <string>GR-ESB Virtual link</string>
71 </property>
72 </widget>
73 </item>
74 <item row="2" column="1">
75 <widget class="QComboBox" name="GRESB_LinkNum_CmBx">
76 <item>
77 <property name="text">
78 <string>SPW0</string>
79 </property>
80 </item>
81 <item>
82 <property name="text">
83 <string>SPW1</string>
84 </property>
85 </item>
86 <item>
87 <property name="text">
88 <string>SPW2</string>
89 </property>
90 </item>
91 </widget>
92 </item>
93 <item row="0" column="1">
94 <widget class="QLineEdit" name="GRESB_IP_lineEdit"/>
95 </item>
96 <item row="2" column="0">
97 <widget class="QLabel" name="GRESB_LinkNum_Lbl">
98 <property name="text">
99 <string>Select link number</string>
100 </property>
101 </widget>
102 </item>
103 <item row="0" column="0">
104 <widget class="QLabel" name="GRESB_IP_Lbl">
105 <property name="text">
106 <string>GR-ESB IP Address</string>
107 </property>
108 </widget>
109 </item>
110 </layout>
111 </widget>
112 <widget class="QWidget" name="Web">
113 <property name="toolTip">
114 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The Web tab gives access to the GR-ESB web interface.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
54 115 </property>
55 </item>
56 <item>
57 <property name="text">
58 <string>SPW2</string>
59 </property>
60 </item>
116 <attribute name="title">
117 <string>Web</string>
118 </attribute>
119 <layout class="QHBoxLayout" name="horizontalLayout">
120 <item>
121 <widget class="QWebView" name="WebView" native="true"/>
122 </item>
123 </layout>
124 </widget>
61 125 </widget>
62 126 </item>
63 127 </layout>
64 128 </widget>
129 <customwidgets>
130 <customwidget>
131 <class>QWebView</class>
132 <extends>QWidget</extends>
133 <header location="global">QWebView</header>
134 <container>1</container>
135 </customwidget>
136 </customwidgets>
65 137 <resources/>
66 138 <connections/>
67 139 </ui>
@@ -1,79 +1,86
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>SpwTcpPacketServer</class>
4 4 <widget class="QWidget" name="SpwTcpPacketServer">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>671</width>
10 10 <height>409</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 <property name="toolTip">
17 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The spacewire plugin TCP server allows you to forward spacewire packets to any custom application, here you will configure the TCP connection and get some status information.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
18 </property>
16 19 <layout class="QVBoxLayout" name="verticalLayout">
17 20 <item>
18 21 <widget class="QGroupBox" name="configGroupBox">
19 22 <property name="title">
20 23 <string>Configuration</string>
21 24 </property>
22 25 <layout class="QFormLayout" name="formLayout_2">
23 26 <item row="0" column="0">
24 27 <widget class="QLabel" name="IPLbl">
25 28 <property name="text">
26 29 <string>Server IP</string>
27 30 </property>
28 31 </widget>
29 32 </item>
30 33 <item row="0" column="1">
31 34 <widget class="QLineEdit" name="IPLineEdit">
32 35 <property name="maxLength">
33 36 <number>15</number>
34 37 </property>
35 38 <property name="readOnly">
36 39 <bool>true</bool>
37 40 </property>
38 41 </widget>
39 42 </item>
40 43 <item row="1" column="0">
41 44 <widget class="QLabel" name="PortLbl">
42 45 <property name="text">
43 46 <string>Server Port</string>
44 47 </property>
45 48 </widget>
46 49 </item>
47 50 <item row="1" column="1">
48 <widget class="QLineEdit" name="PortLineEdit"/>
51 <widget class="QLineEdit" name="PortLineEdit">
52 <property name="toolTip">
53 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the port on which the server will listen and accept client connections.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
54 </property>
55 </widget>
49 56 </item>
50 57 <item row="2" column="1">
51 58 <widget class="QPushButton" name="startServeQpb">
52 59 <property name="text">
53 60 <string>Start Server</string>
54 61 </property>
55 62 </widget>
56 63 </item>
57 64 </layout>
58 65 </widget>
59 66 </item>
60 67 <item>
61 68 <widget class="QGroupBox" name="clientListGroupBox_2">
62 69 <property name="title">
63 70 <string>Connected clients</string>
64 71 </property>
65 72 <property name="flat">
66 73 <bool>false</bool>
67 74 </property>
68 75 <layout class="QVBoxLayout" name="verticalLayout_2">
69 76 <item>
70 77 <widget class="QListWidget" name="listWidget"/>
71 78 </item>
72 79 </layout>
73 80 </widget>
74 81 </item>
75 82 </layout>
76 83 </widget>
77 84 <resources/>
78 85 <connections/>
79 86 </ui>
@@ -1,647 +1,646
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22
23 23 #include "stardundeespw_usb.h"
24 24 #include <socexplorerengine.h>
25 25 #include <qhexedit.h>
26 26
27 27 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
28 28 abstractSpwBridge(parent)
29 29 {
30 30 Q_UNUSED(parent)
31 31 this->manager = new stardundeeSPW_USB_Manager(parent,this);
32 32 makeGUI(parent);
33 33 this->manager->start();
34 34 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
35 35 }
36 36
37 37 stardundeeSPW_USB::~stardundeeSPW_USB()
38 38 {
39 39 this->manager->requestInterruption();
40 delete this->p_GUI;
41 40 }
42 41
43 42 void stardundeeSPW_USB::toggleBridgeConnection()
44 43 {
45 44 if(this->plugin->isConnected())
46 45 {
47 46 this->disconnectBridge();
48 47 }
49 48 else
50 49 {
51 50 this->connectBridge();
52 51 }
53 52 }
54 53
55 54 bool stardundeeSPW_USB::connectBridge()
56 55 {
57 56 if(this->manager->connectBridge())
58 57 {
59 58 ((StarDundeeGUI*)this->p_GUI)->lock(true);
60 59 emit setConnected(true);
61 60 return true;
62 61 }
63 62 return false;
64 63 }
65 64
66 65 bool stardundeeSPW_USB::disconnectBridge()
67 66 {
68 67 if(this->manager->disconnectBridge())
69 68 {
70 69 ((StarDundeeGUI*)this->p_GUI)->lock(false);
71 70 emit setConnected(false);
72 71 return true;
73 72 }
74 73 return false;
75 74 }
76 75
77 76
78 77 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
79 78 {
80 79 return this->manager->sendPacket(packet,size);
81 80 }
82 81
83 82 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
84 83 {
85 84 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
86 85 char *RMAPAckBuff;
87 86 writeBuffer[0]=this->manager->linkNumber;//Link number
88 87 int transactionID = 0;
89 88 int written=0;
90 89 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
91 90 QProgressBar* progress=NULL;
92 91 SocExplorerAutoProgressBar autopb;
93 92 if(count>RMAP_MAX_XFER_SIZE)
94 93 {
95 94 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
96 95 autopb.setProgressBar(progress);
97 96 }
98 97 //Quite stupide loop, I guess that I always get the number of byte I asked for!
99 98 while(count>=RMAP_MAX_XFER_SIZE)
100 99 {
101 100 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
102 101 {
103 102 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
104 103 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
105 104 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
106 105 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
107 106 }
108 107 transactionID=manager->getRMAPtransactionID();
109 108 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
110 109 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1);
111 110 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
112 111 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
113 112 free(RMAPAckBuff);
114 113 written+=RMAP_MAX_XFER_SIZE;
115 114 count-=RMAP_MAX_XFER_SIZE;
116 115 progress->setValue(written);
117 116 qApp->processEvents();
118 117 }
119 118 if(count>0)
120 119 {
121 120 for(int i=0;i<((int)count);i++)
122 121 {
123 122 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
124 123 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
125 124 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
126 125 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
127 126 }
128 127 transactionID=manager->getRMAPtransactionID();
129 128 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
130 129 RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),count*4,writeBuffer+1);
131 130 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
132 131 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
133 132 free(RMAPAckBuff);
134 133 written+=count;
135 134 if(progress!=NULL)
136 135 {
137 136 progress->setValue(written);
138 137 qApp->processEvents();
139 138 }
140 139 }
141 140 return written;
142 141 }
143 142
144 143 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
145 144 {
146 145 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
147 146 char* RMAP_AnswerBuffer;
148 147 requestBuffer[0]=this->manager->linkNumber;//Link number
149 148 int transactionID = 0;
150 149 int read=0;
151 150 QProgressBar* progress=NULL;
152 151 SocExplorerAutoProgressBar autopb;
153 152 if(count>RMAP_MAX_XFER_SIZE)
154 153 {
155 154 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
156 155 autopb.setProgressBar(progress);
157 156 }
158 157 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
159 158
160 159 //Quite stupide loop, I guess that I always get the number of byte I asked for!
161 160 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
162 161 {
163 162 transactionID = manager->getRMAPtransactionID();
164 163 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
165 164 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1);
166 165 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
167 166 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
168 167 if(len==-1)
169 168 {
170 169 this->toggleBridgeConnection();
171 170 return 0;
172 171 }
173 172 for(int i=0;i<((len-13)/4);i++)
174 173 {
175 174 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
176 175 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
177 176 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
178 177 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
179 178 }
180 179 free(RMAP_AnswerBuffer);
181 180 read+=RMAP_MAX_XFER_SIZE;
182 181 count-=RMAP_MAX_XFER_SIZE;
183 182 progress->setValue(read);
184 183 qApp->processEvents();
185 184 }
186 185 if((int)count>0)
187 186 {
188 187 transactionID = manager->getRMAPtransactionID();
189 188 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
190 189 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
191 190 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
192 191 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
193 192 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
194 193 RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),count*4,requestBuffer+1);
195 194 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
196 195 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
197 196 if(len==-1)
198 197 {
199 198 this->toggleBridgeConnection();
200 199 return 0;
201 200 }
202 201 for(int i=0;i<((len-13)/4);i++)
203 202 {
204 203 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
205 204 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
206 205 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
207 206 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
208 207 }
209 208 free(RMAP_AnswerBuffer);
210 209 read+=count;
211 210 if(progress!=NULL)
212 211 {
213 212 progress->setValue(read);
214 213 qApp->processEvents();
215 214 }
216 215 }
217 216 return read;
218 217 }
219 218
220 219 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
221 220 {
222 221 this->manager->selectedBrick = brickIndex-1;
223 222 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
224 223 }
225 224
226 225 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
227 226 {
228 227 this->manager->linkNumber = linkIndex + 1;
229 228 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
230 229 }
231 230
232 231 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
233 232 {
234 233 this->manager->linkSpeed = linkSpeed.toInt();
235 234
236 235 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
237 236 }
238 237
239 238 void stardundeeSPW_USB::destinationKeyChanged(const QString &destKey)
240 239 {
241 240 this->manager->destinationKey = destKey.toInt();
242 241 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->destinationKey),1);
243 242 }
244 243
245 244 void stardundeeSPW_USB::rmapAddressChanged(const QString &rmapaddress)
246 245 {
247 246 this->manager->rmapAddress = rmapaddress.toInt();
248 247 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->rmapAddress),1);
249 248 }
250 249
251 250 void stardundeeSPW_USB::rmapKeyChanged(const QString &key)
252 251 {
253 252 this->manager->rmapKey = key.toInt();
254 253 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->rmapKey),1);
255 254 }
256 255
257 256 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
258 257 {
259 258 int tim=timeout.toInt();
260 259 if(tim<50)
261 260 {
262 261 tim = 50;
263 262 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
264 263 }
265 264 this->manager->RMAPtimeout = tim;
266 265 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
267 266 }
268 267
269 268
270 269 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
271 270 {
272 271 this->p_GUI = new StarDundeeGUI();
273 272 // this->mainLayout = new QGridLayout(this->p_GUI);
274 273 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
275 274 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
276 275 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
277 276 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
278 277 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
279 278 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
280 279 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(rmapAddressChanged(QString)));
281 280 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapKeyChanged(QString)),this,SLOT(rmapKeyChanged(QString)));
282 281 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
283 282
284 283 this->brickSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
285 284 this->linkNumberSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
286 285 this->linkSpeedSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
287 286 this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
288 287 this->rmapAddressChanged(((StarDundeeGUI*)this->p_GUI)->getRmapAddress());
289 288 this->rmapKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey());
290 289 this->rmapTimeoutChanged(((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
291 290
292 291 connect(this,SIGNAL(SelectBrick(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
293 292 connect(this,SIGNAL(SelectLinkNumber(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
294 293 connect(this,SIGNAL(SelectLinkSpeed(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
295 294 connect(this,SIGNAL(SetDestinationKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
296 295 connect(this,SIGNAL(SetRmapAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapAddress(QString)));
297 296 connect(this,SIGNAL(SetRmapKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapKey(QString)));
298 297 connect(this,SIGNAL(SetRmapTimeout(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
299 298
300 299 }
301 300
302 301 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
303 302 :QThread((QObject*)parent)
304 303 {
305 304 this->RMAPtimeout = 2000;
306 305 this->handleMutex = new QMutex(QMutex::NonRecursive);
307 306 this->RMAP_AnswersSem = new QSemaphore(0);
308 307 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
309 308 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
310 309 this->plugin = plugin;
311 310 connected = false;
312 311 this->moveToThread(this);
313 312 }
314 313
315 314 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
316 315 {
317 316 this->terminate();
318 317 while (!this->isFinished()) {
319 318 this->usleep(1000);
320 319 }
321 320 }
322 321
323 322
324 323 void stardundeeSPW_USB_Manager::run()
325 324 {
326 325 USB_SPACEWIRE_PACKET_PROPERTIES properties;
327 326 USB_SPACEWIRE_ID pIdentifier=NULL;
328 327 USB_SPACEWIRE_STATUS stat;
329 328 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
330 329 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
331 330 while (!this->isInterruptionRequested())
332 331 {
333 332 if(this->connected)
334 333 {
335 334 handleMutex->lock();
336 335 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
337 336 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
338 337 {
339 338 SocExplorerEngine::message(this->plugin,"Got packet",2);
340 339 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
341 340 if (stat == TRANSFER_SUCCESS)
342 341 {
343 342 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
344 343 {
345 344 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
346 345 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
347 346 {
348 347 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
349 348 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
350 349 {
351 350 RMAP_Answer* packet;
352 351 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
353 352 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
354 353 char* packetbuffer = (char*)malloc(properties.len);
355 354 memcpy(packetbuffer,buffer,properties.len);
356 355 USBSpaceWire_FreeRead(hDevice, pIdentifier);
357 356 pIdentifier = NULL;
358 357 handleMutex->unlock();
359 358 if(properties.len==8)
360 359 {
361 360 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
362 361 }
363 362 else
364 363 {
365 364 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
366 365 }
367 366 RMAP_AnswersMtx->lock();
368 367 RMAP_Answers.append(packet);
369 368 RMAP_AnswersMtx->unlock();
370 369 RMAP_AnswersSem->release();
371 370 }
372 371 else //any non-rmap packet will be pushed to the network
373 372 {
374 373 char* packetbuffer = (char*)malloc(properties.len);
375 374 memcpy(packetbuffer,buffer,properties.len);
376 375 emit emitPacket(packetbuffer,properties.len);
377 376 USBSpaceWire_FreeRead(hDevice, pIdentifier);
378 377 handleMutex->unlock();
379 378 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
380 379 }
381 380 }
382 381 else
383 382 {
384 383 SocExplorerEngine::message(this->plugin,"No EOP received",2);
385 384 }
386 385 }
387 386
388 387 }
389 388 else
390 389 {
391 390 USBSpaceWire_FreeRead(hDevice, pIdentifier);
392 391 handleMutex->unlock();
393 392 }
394 393 }
395 394 else
396 395 {
397 396 USBSpaceWire_FreeRead(hDevice, pIdentifier);
398 397 handleMutex->unlock();
399 398 }
400 399 }
401 400 else
402 401 {
403 402 //do some sanity checks!
404 403 int list = USBSpaceWire_ListDevices();
405 404 if(this->brickList!=list)
406 405 {
407 406 this->brickList = list;
408 407 emit updateAvailableBrickCount(this->brickList);
409 408 }
410 409 usleep(RMAPtimeout/2);
411 410 }
412 411 usleep(1000);
413 412 }
414 413 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
415 414 }
416 415
417 416 bool stardundeeSPW_USB_Manager::connectBridge()
418 417 {
419 418 QMutexLocker mlock(this->handleMutex);
420 419 int status;
421 420 U32 statusControl;
422 421 this->connected = false;
423 422 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
424 423 {
425 424 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
426 425 return false;
427 426 }
428 427 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
429 428
430 429 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
431 430 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
432 431 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
433 432
434 433 // Set the path and return path to the device
435 434 CFGSpaceWire_StackClear();
436 435 CFGSpaceWire_AddrStackPush(0);
437 436 CFGSpaceWire_AddrStackPush(254);
438 437 CFGSpaceWire_RetAddrStackPush(254);
439 438 // set the base transmit rate to 100 MHz
440 439 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
441 440 if (status != CFG_TRANSFER_SUCCESS)
442 441 {
443 442 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
444 443 return false;
445 444 }
446 445 else
447 446 {
448 447 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
449 448 }
450 449
451 450 // read the link status
452 451 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
453 452 {
454 453 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
455 454 return false;
456 455 }
457 456 else
458 457 {
459 458 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
460 459
461 460 // Set the link status control register properties
462 461 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
463 462 CFGSpaceWire_LSEnableStart(&statusControl, 1);
464 463 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
465 464 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
466 465 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
467 466
468 467 // Set the link status control register
469 468 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
470 469 {
471 470 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
472 471 return false;
473 472 }
474 473 else
475 474 {
476 475 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
477 476 }
478 477 }
479 478
480 479 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
481 480 {
482 481 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
483 482 return false;
484 483 }
485 484 else
486 485 {
487 486 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
488 487 }
489 488
490 489 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
491 490 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
492 491 USBSpaceWire_SetTimeout(hDevice,1.0);
493 492 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
494 493 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
495 494 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
496 495 this->connected = true;
497 496 return true;
498 497 }
499 498
500 499 bool stardundeeSPW_USB_Manager::disconnectBridge()
501 500 {
502 501 this->handleMutex->lock();
503 502 USBSpaceWire_Close(hDevice); // Close the device
504 503 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
505 504 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
506 505 this->handleMutex->unlock();
507 506 this->RMAP_pending_transaction_IDsMtx->lock();
508 507 this->RMAP_pending_transaction_IDs.clear();
509 508 this->RMAP_pending_transaction_IDsMtx->unlock();
510 509 this->RMAP_AnswersMtx->lock();
511 510 this->RMAP_Answers.clear();
512 511 this->RMAP_AnswersMtx->unlock();
513 512 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
514 513 return true;
515 514 }
516 515
517 516 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
518 517 {
519 518 this->RMAP_pending_transaction_IDsMtx->lock();
520 519 int ID=0;
521 520 bool found=true;
522 521 while(ID<511)
523 522 {
524 523 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
525 524 {
526 525 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
527 526 }
528 527 if(found==true)break;
529 528 ID++;
530 529 found = true;
531 530 }
532 531 if(found)
533 532 {
534 533 RMAP_pending_transaction_IDs.append(ID);
535 534 }
536 535 this->RMAP_pending_transaction_IDsMtx->unlock();
537 536 return ID;
538 537 }
539 538
540 539 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
541 540 {
542 541 QTime timeout;
543 542 *buffer=NULL;
544 543 int count=0;
545 544 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
546 545 timeout.start();
547 546 while (*buffer==NULL)
548 547 {
549 548 this->RMAP_AnswersMtx->lock();
550 549 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
551 550 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
552 551 for(int i=0;i<RMAP_Answers.count();i++)
553 552 {
554 553 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
555 554 if(RMAP_Answers[i]->transactionID==transactionID)
556 555 {
557 556 this->RMAP_pending_transaction_IDsMtx->lock();
558 557 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
559 558 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
560 559 {
561 560 if(RMAP_pending_transaction_IDs[j]==transactionID)
562 561 {
563 562 RMAP_pending_transaction_IDs.removeAt(j);
564 563 }
565 564 }
566 565 this->RMAP_pending_transaction_IDsMtx->unlock();
567 566 *buffer = RMAP_Answers[i]->data;
568 567 count = RMAP_Answers[i]->len;
569 568 RMAP_Answer* tmp=RMAP_Answers[i];
570 569 RMAP_Answers.removeAt(i);
571 570 delete tmp;
572 571 }
573 572 }
574 573 this->RMAP_AnswersMtx->unlock();
575 574 //if no answer found in the stack wait until a new packet is pushed
576 575 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
577 576 if(*buffer==NULL)
578 577 {
579 578 while (0==this->RMAP_AnswersSem->available())
580 579 {
581 580 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
582 581 if(timeout.elapsed()>=RMAPtimeout)
583 582 {
584 583 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
585 584 return -1;
586 585 }
587 586 usleep(1000);
588 587 }
589 588 this->RMAP_AnswersSem->acquire();
590 589 }
591 590 }
592 591 return count;
593 592 }
594 593
595 594 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
596 595 {
597 596 USB_SPACEWIRE_STATUS result;
598 597 USB_SPACEWIRE_ID pIdentifier;
599 598 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
600 599 this->handleMutex->lock();
601 600 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
602 601 if (result != TRANSFER_SUCCESS)
603 602 {
604 603 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
605 604 this->handleMutex->unlock();
606 605 return false;
607 606 }
608 607 else
609 608 {
610 609 SocExplorerEngine::message(this->plugin,"Packet sent",2);
611 610 USBSpaceWire_FreeSend(hDevice, pIdentifier);
612 611 }
613 612 this->handleMutex->unlock();
614 613 return true;
615 614 }
616 615
617 616 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
618 617 {
619 618 char* packetbuffer = (char*)malloc(len);
620 619 memcpy(packetbuffer,packet,len);
621 620 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
622 621 RMAP_AnswersMtx->lock();
623 622 RMAP_Answers.append(RMPAPpacket);
624 623 RMAP_AnswersMtx->unlock();
625 624 }
626 625
627 626
628 627
629 628
630 629
631 630
632 631
633 632
634 633
635 634
636 635
637 636
638 637
639 638
640 639
641 640
642 641
643 642
644 643
645 644
646 645
647 646
@@ -1,51 +1,56
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "abstractspwbridge.h"
23 23
24 24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
25 25 :QObject((QObject*)parent)
26 26 {
27 27 this->plugin = parent;
28 28 this->p_GUI=NULL;
29 29 }
30 30
31 abstractSpwBridge::~abstractSpwBridge()
32 {
33 delete this->p_GUI;
34 }
35
31 36 QWidget *abstractSpwBridge::getGUI()
32 37 {
33 38 return this->p_GUI;
34 39 }
35 40
36 41 bool abstractSpwBridge::connectBridge()
37 42 {
38 43 return false;
39 44 }
40 45
41 46 bool abstractSpwBridge::disconnectBridge()
42 47 {
43 48 return false;
44 49 }
45 50
46 51
47 52
48 53
49 54
50 55
51 56
@@ -1,53 +1,54
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef ABSTRACTSPWBRIDGE_H
23 23 #define ABSTRACTSPWBRIDGE_H
24 24
25 25 #include <QObject>
26 26 #include <socexplorerplugin.h>
27 27 #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes
28 28 #include <spw.h>
29 29
30 30 class abstractSpwBridge : public QObject
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 explicit abstractSpwBridge(socexplorerplugin *parent);
35 ~abstractSpwBridge();
35 36 QWidget *getGUI();
36 37
37 38 public slots:
38 39 virtual bool connectBridge();
39 40 virtual bool disconnectBridge();
40 41 virtual unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
41 42 virtual unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0)=0;
42 43 virtual int pushRMAPPacket(char* packet,int size)=0;
43 44 signals:
44 45 void setConnected(bool connected);
45 46 void pushPacketOverTCP(char* packet,int size);
46 47 protected:
47 48 socexplorerplugin* plugin;
48 49 QWidget* p_GUI;
49 50 private:
50 51
51 52 };
52 53
53 54 #endif // ABSTRACTSPWBRIDGE_H
@@ -1,90 +1,92
1 1 #
2 2 # Project created by QtCreator 2011-09-20T08:15:30
3 3 #
4 4 #-------------------------------------------------
5 5
6 6 CONFIG += socexplorerplugin
7 QT += network
7 QT += network webkit
8 greaterThan(QT_MAJOR_VERSION, 4): QT += webkitwidgets
9
8 10 win32:CONFIG += dll
9 11 win32:CONFIG -= static
10 12 CONFIG(debug, debug|release) {
11 13 DEBUG_EXT = _d
12 14 } else {
13 15 DEBUG_EXT =
14 16 }
15 17 TARGET = spwplugin$${DEBUG_EXT}
16 18 DEFINES += PLUGIN=spwplugin
17 19 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
18 20 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
19 21 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
20 22 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
21 23 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
22 24 DEFINES += driver_can_be_root=1
23 25 DEFINES += driver_can_be_child=0
24 26 DEFINES += driver_VID=0
25 27 DEFINES += driver_PID=0
26 28
27 29 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
28 30
29 31 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
30 32 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
31 33
32 34 INCLUDEPATH += \
33 35 $${PWD} \
34 36 $$STARTDUNDEEPATH/inc \
35 37 StarDundee \
36 38 GR-ESB
37 39
38 40 HEADERS += \
39 41 spwplugin.h \
40 42 StarDundee/stardundeespw_usb.h \
41 43 abstractspwbridge.h \
42 44 spw.h \
43 45 StarDundee/stardundeegui.h \
44 46 SpwTcpPacketServer/spwtcppacketserver.h \
45 47 spwpywrapper.h \
46 48 GR-ESB/gr_esb_bridge.h \
47 49 GR-ESB/gr_esb_ui.h
48 50
49 51
50 52 SOURCES += \
51 53 spwplugin.cpp \
52 54 StarDundee/stardundeespw_usb.cpp \
53 55 abstractspwbridge.cpp \
54 56 StarDundee/stardundeegui.cpp \
55 57 SpwTcpPacketServer/spwtcppacketserver.cpp \
56 58 spwpywrapper.cpp \
57 59 GR-ESB/gr_esb_bridge.cpp \
58 60 GR-ESB/gr_esb_ui.cpp
59 61
60 62 FORMS += \
61 63 StarDundee/stardundeeGUI.ui \
62 64 SpwTcpPacketServer/spwtcppacketserver.ui \
63 65 GR-ESB/gr_esb_ui.ui
64 66
65 67 RESOURCES += \
66 68 spwRessources.qrc
67 69
68 70
69 71
70 72
71 73
72 74
73 75
74 76
75 77
76 78
77 79
78 80
79 81
80 82
81 83
82 84
83 85
84 86
85 87
86 88
87 89
88 90
89 91
90 92
General Comments 0
You need to be logged in to leave comments. Login now