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