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