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