##// END OF EJS Templates
A lot of cleaning,...
paul -
r50:9c702d65566a default
parent child
Show More
@@ -1,90 +1,90
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 "ahbpluginui.h"
22 #include "ahbpluginui.h"
23 #include <socexplorerengine.h>
23 #include <socexplorerengine.h>
24
24
25 ahbPluginUi::ahbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
25 ahbPluginUi::ahbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
26 QWidget(parent)
26 QWidget(parent)
27 {
27 {
28 this->mainlayout = new QHBoxLayout;
28 this->mainlayout = new QHBoxLayout;
29 this->scanBp = new QPushButton(tr("Scan AHB"));
29 this->scanBp = new QPushButton(tr("Scan AHB"));
30 this->deviceslst = new ahbdevicelist;
30 this->deviceslst = new ahbdevicelist;
31 this->mainlayout->addWidget(this->deviceslst);
31 this->mainlayout->addWidget(this->deviceslst);
32 this->mainlayout->addWidget(this->scanBp);
32 this->mainlayout->addWidget(this->scanBp);
33 this->setLayout(this->mainlayout);
33 this->setLayout(this->mainlayout);
34 this->_plugin = plugin;
34 this->_plugin = plugin;
35 connect(this,SIGNAL(addAHBdevice(ahbdeviceInfo*)),this->deviceslst,SLOT(addAHBdevice(ahbdeviceInfo*)));
35 connect(this,SIGNAL(addAHBdevice(ahbdeviceInfo*)),this->deviceslst,SLOT(addAHBdevice(ahbdeviceInfo*)));
36 connect(this,SIGNAL(clearAHBdevicesList()),this->deviceslst,SLOT(clearAHBdevicesList()));
36 connect(this,SIGNAL(clearAHBdevicesList()),this->deviceslst,SLOT(clearAHBdevicesList()));
37 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAHB()));
37 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAHB()));
38 }
38 }
39
39
40
40
41
41
42 ahbdeviceInfo* ahbPluginUi::extractInfos(int *pnpregs)
42 ahbdeviceInfo* ahbPluginUi::extractInfos(int *pnpregs)
43 {
43 {
44 AHBbarreg BAR[4];
44 AHBbarreg BAR[4];
45
45
46 int VID;
46 int VID;
47 int PID;
47 int PID;
48 for(int i=0;i<4;i++)
48 for(int i=0;i<4;i++)
49 {
49 {
50 BAR[i].address = pnpregs[i+4] & 0xfff00000;
50 BAR[i].address = pnpregs[i+4] & 0xfff00000;
51 BAR[i].size = (pnpregs[i+4] & 0x0000fff0)<<16;
51 BAR[i].size = (pnpregs[i+4] & 0x0000fff0)<<16;
52 if(BAR[i].size!=0)
52 if(BAR[i].size!=0)
53 BAR[i].size = (((-1^BAR[i].size)|BAR[i].address)-BAR[i].address)+1;
53 BAR[i].size = (((-1^BAR[i].size)|BAR[i].address)-BAR[i].address)+1;
54 BAR[i].cacheable = (bool)((pnpregs[i+4]&0x00010000)>>16);
54 BAR[i].cacheable = (bool)((pnpregs[i+4]&0x00010000)>>16);
55 BAR[i].prefectchable = (bool)((pnpregs[i+4]&0x00020000)>>17);
55 BAR[i].prefectchable = (bool)((pnpregs[i+4]&0x00020000)>>17);
56 BAR[i].type = (unsigned char)(pnpregs[i+4]&0xf);
56 BAR[i].type = (unsigned char)(pnpregs[i+4]&0xf);
57 }
57 }
58
58
59 VID = (pnpregs[0]>>24)&0xff;
59 VID = (pnpregs[0]>>24)&0xff;
60 PID = (pnpregs[0]>>12)&0xfff;
60 PID = (pnpregs[0]>>12)&0xfff;
61 QString devname = SocExplorerEngine::getDevName(VID,PID);
61 QString devname = SocExplorerEngine::getDevName(VID,PID);
62 return new ahbdeviceInfo(devname,BAR[0],BAR[1],BAR[2],BAR[3],VID,PID);
62 return new ahbdeviceInfo(devname,BAR[0],BAR[1],BAR[2],BAR[3],VID,PID);
63 }
63 }
64
64
65
65
66 void ahbPluginUi::scanAHB()
66 void ahbPluginUi::scanAHB()
67 {
67 {
68 unsigned int size = AHB_PLUGNPLAY_SLAVE_STOP- AHB_PLUGNPLAY_MASTER_START;
68 unsigned int size = (AHB_PLUGNPLAY_SLAVE_STOP - AHB_PLUGNPLAY_MASTER_START)/4;
69 int j=0;
69 int j=0;
70 unsigned long long i = AHB_PLUGNPLAY_MASTER_START;
70 unsigned long long i = AHB_PLUGNPLAY_MASTER_START;
71 int pnpregs[AHB_PLUGNPLAY_SLAVE_STOP- AHB_PLUGNPLAY_MASTER_START];
71 int pnpregs[size];
72 emit this->clearAHBdevicesList();
72 emit this->clearAHBdevicesList();
73 if( this->_plugin->Read((unsigned int*)pnpregs,size,(unsigned int)AHB_PLUGNPLAY_MASTER_START)==size)
73 if( this->_plugin->Read((unsigned int*)pnpregs,size,(unsigned int)AHB_PLUGNPLAY_MASTER_START)==size)
74 {
74 {
75 while(i<AHB_PLUGNPLAY_SLAVE_STOP)
75 while(i<AHB_PLUGNPLAY_SLAVE_STOP)
76 {
76 {
77 if(pnpregs[j]!=0)
77 if(pnpregs[j]!=0)
78 {
78 {
79 ahbdeviceInfo* devinfo=this->extractInfos(pnpregs+j);
79 ahbdeviceInfo* devinfo=this->extractInfos(pnpregs+j);
80 if(!devinfo->deviceName->compare("DSU3"))
80 if(!devinfo->deviceName->compare("DSU3"))
81 SocExplorerEngine::addEnumDevice(this->_plugin,devinfo->VID,devinfo->PID,devinfo->BAR[0].address,*devinfo->deviceName);
81 SocExplorerEngine::addEnumDevice(this->_plugin,devinfo->VID,devinfo->PID,devinfo->BAR[0].address,*devinfo->deviceName);
82 emit this->addAHBdevice(devinfo);
82 emit this->addAHBdevice(devinfo);
83 }
83 }
84 i+=32;
84 i+=32;
85 j+=8;
85 j+=8;
86 }
86 }
87 }
87 }
88 }
88 }
89
89
90
90
@@ -1,59 +1,58
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 #ifndef AHBPLUGINUI_H
22 #ifndef AHBPLUGINUI_H
23 #define AHBPLUGINUI_H
23 #define AHBPLUGINUI_H
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include <QHBoxLayout>
26 #include <QHBoxLayout>
27 #include <QPushButton>
27 #include <QPushButton>
28 #include "ahbdevicelist.h"
28 #include "ahbdevicelist.h"
29 #include <socexplorerplugin.h>
29 #include <socexplorerplugin.h>
30 #define AHB_PLUGNPLAY_MASTER_START ((unsigned int)(0xFFFFF000))
30 #define AHB_PLUGNPLAY_MASTER_START ((unsigned int)(0xFFFFF000))
31 #define AHB_PLUGNPLAY_MASTER_STOP ((unsigned int)(0xFFFFF800))
31 #define AHB_PLUGNPLAY_MASTER_STOP ((unsigned int)(0xFFFFF800))
32 #define AHB_PLUGNPLAY_SLAVE_START ((unsigned int)(0xFFFFF800))
32 #define AHB_PLUGNPLAY_SLAVE_START ((unsigned int)(0xFFFFF800))
33
34 #define AHB_PLUGNPLAY_SLAVE_STOP ((unsigned int)(0xFFFFFFFC))
33 #define AHB_PLUGNPLAY_SLAVE_STOP ((unsigned int)(0xFFFFFFFC))
35
34
36
35
37 class ahbPluginUi : public QWidget
36 class ahbPluginUi : public QWidget
38 {
37 {
39 Q_OBJECT
38 Q_OBJECT
40 public:
39 public:
41 explicit ahbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
40 explicit ahbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
42 ahbdeviceInfo* extractInfos(int* pnpregs);
41 ahbdeviceInfo* extractInfos(int* pnpregs);
43 public slots:
42 public slots:
44 void scanAHB();
43 void scanAHB();
45 signals:
44 signals:
46 void addAHBdevice(ahbdeviceInfo* device);
45 void addAHBdevice(ahbdeviceInfo* device);
47 void clearAHBdevicesList();
46 void clearAHBdevicesList();
48 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
47 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
49 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
48 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
50 private:
49 private:
51 QHBoxLayout* mainlayout;
50 QHBoxLayout* mainlayout;
52 QPushButton* scanBp;
51 QPushButton* scanBp;
53 ahbdevicelist* deviceslst;
52 ahbdevicelist* deviceslst;
54 socexplorerplugin* _plugin;
53 socexplorerplugin* _plugin;
55
54
56
55
57 };
56 };
58
57
59 #endif // AHBPLUGINUI_H
58 #endif // AHBPLUGINUI_H
@@ -1,99 +1,99
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 "apbpluginui.h"
22 #include "apbpluginui.h"
23 #include <stdint.h>
23 #include <stdint.h>
24 #include <socexplorerengine.h>
24 #include <socexplorerengine.h>
25
25
26 apbPluginUi::apbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
26 apbPluginUi::apbPluginUi(socexplorerplugin *plugin, QWidget *parent) :
27 QWidget(parent)
27 QWidget(parent)
28 {
28 {
29 this->setWindowTitle(tr("APB Driver"));
29 this->setWindowTitle(tr("APB Driver"));
30 this->mainlayout = new QHBoxLayout;
30 this->mainlayout = new QHBoxLayout;
31 this->scanBp = new QPushButton(tr("Scan APB"));
31 this->scanBp = new QPushButton(tr("Scan APB"));
32 this->deviceslst = new apbdevicelist;
32 this->deviceslst = new apbdevicelist;
33 this->mainlayout->addWidget(this->deviceslst);
33 this->mainlayout->addWidget(this->deviceslst);
34 this->mainlayout->addWidget(this->scanBp);
34 this->mainlayout->addWidget(this->scanBp);
35 this->setLayout(this->mainlayout);
35 this->setLayout(this->mainlayout);
36 this->_plugin = plugin;
36 this->_plugin = plugin;
37 connect(this,SIGNAL(addAPBdevice(apbdeviceInfo*)),this->deviceslst,SLOT(addAPBdevice(apbdeviceInfo*)));
37 connect(this,SIGNAL(addAPBdevice(apbdeviceInfo*)),this->deviceslst,SLOT(addAPBdevice(apbdeviceInfo*)));
38 connect(this,SIGNAL(clearAPBdevicesList()),this->deviceslst,SLOT(clearAPBdevicesList()));
38 connect(this,SIGNAL(clearAPBdevicesList()),this->deviceslst,SLOT(clearAPBdevicesList()));
39 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAPB()));
39 connect(this->scanBp,SIGNAL(clicked()),this,SLOT(scanAPB()));
40 }
40 }
41
41
42 void apbPluginUi::lockScanBp()
42 void apbPluginUi::lockScanBp()
43 {
43 {
44 this->scanBp->setEnabled(false);
44 this->scanBp->setEnabled(false);
45 }
45 }
46
46
47
47
48 void apbPluginUi::unlockScanBp()
48 void apbPluginUi::unlockScanBp()
49 {
49 {
50 this->scanBp->setEnabled(true);
50 this->scanBp->setEnabled(true);
51 }
51 }
52
52
53
53
54
54
55 apbdeviceInfo* apbPluginUi::extractInfos(int *pnpregs)
55 apbdeviceInfo* apbPluginUi::extractInfos(int *pnpregs)
56 {
56 {
57 APBbarreg BAR[1];
57 APBbarreg BAR[1];
58
58
59 int VID;
59 int VID;
60 int PID;
60 int PID;
61 for(int i=0;i<1;i++)
61 for(int i=0;i<1;i++)
62 {
62 {
63 BAR[i].address = ((uint32_t)(pnpregs[i+1] & 0xfff00000)>>12)+ APB_BUS_START;
63 BAR[i].address = ((uint32_t)(pnpregs[i+1] & 0xfff00000)>>12)+ APB_BUS_START;
64 BAR[i].size = ((pnpregs[i+1] & 0x00000ff0)>>4 )+1;
64 BAR[i].size = ((pnpregs[i+1] & 0x00000ff0)>>4 )+1;
65 BAR[i].type = (unsigned char)(pnpregs[i+1]&0xf);
65 BAR[i].type = (unsigned char)(pnpregs[i+1]&0xf);
66 }
66 }
67
67
68 VID = (pnpregs[0]>>24)&0xff;
68 VID = (pnpregs[0]>>24)&0xff;
69 PID = (pnpregs[0]>>12)&0xfff;
69 PID = (pnpregs[0]>>12)&0xfff;
70 QString devname = SocExplorerEngine::getDevName(VID,PID);
70 QString devname = SocExplorerEngine::getDevName(VID,PID);
71 return new apbdeviceInfo(devname,BAR[0],VID,PID);
71 return new apbdeviceInfo(devname,BAR[0],VID,PID);
72 }
72 }
73
73
74 void apbPluginUi::scanAPB()
74 void apbPluginUi::scanAPB()
75 {
75 {
76 this->lockScanBp();
76 this->lockScanBp();
77 unsigned int size = APB_PLUGNPLAY_STOP - APB_PLUGNPLAY_START;
77 unsigned int size = (APB_PLUGNPLAY_STOP - APB_PLUGNPLAY_START)/4;
78 int j=0;
78 int j=0;
79 unsigned long long i = APB_PLUGNPLAY_START;
79 unsigned long long i = APB_PLUGNPLAY_START;
80 int pnpregs[APB_PLUGNPLAY_STOP - APB_PLUGNPLAY_START];
80 int pnpregs[size];
81 emit this->clearAPBdevicesList();
81 emit this->clearAPBdevicesList();
82 if(this->_plugin->Read((unsigned int*)pnpregs,size/4,(unsigned int)APB_PLUGNPLAY_START)==(size/4))
82 if(this->_plugin->Read((unsigned int*)pnpregs,size,(unsigned int)APB_PLUGNPLAY_START)==size)
83 {
83 {
84 while(i<APB_PLUGNPLAY_STOP)
84 while(i<APB_PLUGNPLAY_STOP)
85 {
85 {
86 if(pnpregs[j]!=0)
86 if(pnpregs[j]!=0)
87 {
87 {
88 apbdeviceInfo* devinfos=this->extractInfos(pnpregs+j);
88 apbdeviceInfo* devinfos=this->extractInfos(pnpregs+j);
89 SocExplorerEngine::addEnumDevice(this->_plugin,devinfos->VID,devinfos->PID,devinfos->BAR[0].address,devinfos->deviceName);
89 SocExplorerEngine::addEnumDevice(this->_plugin,devinfos->VID,devinfos->PID,devinfos->BAR[0].address,devinfos->deviceName);
90 emit this->addAPBdevice(devinfos);
90 emit this->addAPBdevice(devinfos);
91 }
91 }
92 i+=8;
92 i+=8;
93 j+=2;
93 j+=2;
94 if(pnpregs[0]==pnpregs[j]&&pnpregs[1]==pnpregs[j+1])break;
94 if(pnpregs[0]==pnpregs[j]&&pnpregs[1]==pnpregs[j+1])break;
95 }
95 }
96 }
96 }
97 this->unlockScanBp();
97 this->unlockScanBp();
98 }
98 }
99
99
@@ -1,60 +1,59
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 #ifndef APBPLUGINUI_H
22 #ifndef APBPLUGINUI_H
23 #define APBPLUGINUI_H
23 #define APBPLUGINUI_H
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include <QHBoxLayout>
26 #include <QHBoxLayout>
27 #include <QPushButton>
27 #include <QPushButton>
28 #include "apbdevicelist.h"
28 #include "apbdevicelist.h"
29 #include <socexplorerplugin.h>
29 #include <socexplorerplugin.h>
30
30
31 #define APB_BUS_START ((unsigned int)(0x80000000))
31 #define APB_BUS_START ((unsigned int)(0x80000000))
32 #define APB_PLUGNPLAY_START ((unsigned int)(0x800FF000))
32 #define APB_PLUGNPLAY_START ((unsigned int)(0x800FF000))
33
33 #define APB_PLUGNPLAY_STOP ((unsigned int)(0x800FFFFF))
34 #define APB_PLUGNPLAY_STOP ((unsigned int)(0x800FF000+(512*8)))
35
34
36
35
37 class apbPluginUi : public QWidget
36 class apbPluginUi : public QWidget
38 {
37 {
39 Q_OBJECT
38 Q_OBJECT
40 public:
39 public:
41 explicit apbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
40 explicit apbPluginUi(socexplorerplugin* plugin,QWidget *parent = 0);
42 void lockScanBp();
41 void lockScanBp();
43 void unlockScanBp();
42 void unlockScanBp();
44 apbdeviceInfo* extractInfos(int* pnpregs);
43 apbdeviceInfo* extractInfos(int* pnpregs);
45
44
46 signals:
45 signals:
47 void addAPBdevice(apbdeviceInfo* device);
46 void addAPBdevice(apbdeviceInfo* device);
48 void clearAPBdevicesList();
47 void clearAPBdevicesList();
49 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
48 unsigned int WriteSig(unsigned int* Value,unsigned int count,unsigned int address);
50 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
49 unsigned int ReadSig(unsigned int* Value,unsigned int count,unsigned int address);
51 public slots:
50 public slots:
52 void scanAPB();
51 void scanAPB();
53 private:
52 private:
54 QHBoxLayout* mainlayout;
53 QHBoxLayout* mainlayout;
55 QPushButton* scanBp;
54 QPushButton* scanBp;
56 apbdevicelist* deviceslst;
55 apbdevicelist* deviceslst;
57 socexplorerplugin* _plugin;
56 socexplorerplugin* _plugin;
58 };
57 };
59
58
60 #endif // APBPLUGINUI_H
59 #endif // APBPLUGINUI_H
@@ -1,225 +1,242
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 "gr_esb_bridge.h"
22 #include "gr_esb_bridge.h"
23 #include "gr_esb_ui.h"
23 #include "gr_esb_ui.h"
24 #include <unistd.h>
24 #include <unistd.h>
25 #include "spw.h"
25 #include "spw.h"
26 #include <socexplorerengine.h>
26 #include <socexplorerengine.h>
27
27
28 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
28 GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
29 abstractSpwBridge(parent)
29 abstractSpwBridge(parent)
30 {
30 {
31 this->p_GUI = new GR_ESB_ui();
31 this->p_GUI = new GR_ESB_ui();
32 this->manager = new GR_ESB_Manager(parent,this);
32 this->manager = new GR_ESB_Manager(parent,this);
33
33
34 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
34 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
35 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
35 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
36 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
36 connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
37 this->manager->virtualLinkIndex = 0;
37 this->manager->virtualLinkIndex = 0;
38 this->manager->start();
38 this->manager->start();
39 }
39 }
40
40
41 GR_ESB_bridge::~GR_ESB_bridge()
41 GR_ESB_bridge::~GR_ESB_bridge()
42 {
42 {
43 this->manager->requestInterruption();
43 this->manager->requestInterruption();
44 while(this->manager->isRunning());
44 while(this->manager->isRunning());
45 }
45 }
46
46
47 void GR_ESB_bridge::toggleBridgeConnection()
47 void GR_ESB_bridge::toggleBridgeConnection()
48 {
48 {
49 if(this->plugin->isConnected())
49 if(this->plugin->isConnected())
50 {
50 {
51 this->disconnectBridge();
51 this->disconnectBridge();
52 }
52 }
53 else
53 else
54 {
54 {
55 this->connectBridge();
55 this->connectBridge();
56 }
56 }
57 }
57 }
58
58
59 bool GR_ESB_bridge::connectBridge()
59 bool GR_ESB_bridge::connectBridge()
60 {
60 {
61 if(this->manager->connectBridge())
61 if(this->manager->connectBridge())
62 {
62 {
63 ((GR_ESB_ui*)this->p_GUI)->lock(true);
63 ((GR_ESB_ui*)this->p_GUI)->lock(true);
64 emit setConnected(true);
64 emit setConnected(true);
65 return true;
65 return true;
66 }
66 }
67 return false;
67 return false;
68 }
68 }
69
69
70 bool GR_ESB_bridge::disconnectBridge()
70 bool GR_ESB_bridge::disconnectBridge()
71 {
71 {
72 if(this->manager->disconnectBridge())
72 if(this->manager->disconnectBridge())
73 {
73 {
74 ((GR_ESB_ui*)this->p_GUI)->lock(false);
74 ((GR_ESB_ui*)this->p_GUI)->lock(false);
75 emit setConnected(false);
75 emit setConnected(false);
76 return true;
76 return true;
77 }
77 }
78 return false;
78 return false;
79 }
79 }
80
80
81 void GR_ESB_bridge::setIP(QString ip)
81 void GR_ESB_bridge::setIP(QString ip)
82 {
82 {
83 this->manager->IP = ip;
83 this->manager->IP = ip;
84 }
84 }
85
85
86 void GR_ESB_bridge::setVirtualLink(QString vlink)
86 void GR_ESB_bridge::setVirtualLink(QString vlink)
87 {
87 {
88 vlink = vlink.section("Virtual link",0,0);
88 vlink = vlink.section("Virtual link",0,0);
89 bool success;
89 bool success;
90 int vlinkTmp = vlink.toInt(&success);
90 int vlinkTmp = vlink.toInt(&success);
91 if(success)
91 if(success)
92 {
92 {
93 setVirtualLink(vlinkTmp);
93 setVirtualLink(vlinkTmp);
94 }
94 }
95 }
95 }
96
96
97 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
97 void GR_ESB_bridge::setVirtualLink(qint32 vlink)
98 {
98 {
99 if(vlink<6 && vlink>=0)
99 if(vlink<6 && vlink>=0)
100 {
100 {
101 this->manager->virtualLinkIndex = vlink;
101 this->manager->virtualLinkIndex = vlink;
102 }
102 }
103 }
103 }
104
104
105
105
106 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
106 unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
107 {
107 {
108
108 // TODO write ME!
109 Q_UNUSED(count)
110 Q_UNUSED(Value)
111 Q_UNUSED(address)
112 return 0;
109 }
113 }
110
114
111 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
115 unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
112 {
116 {
113
117 // TODO write ME!
118 Q_UNUSED(Value)
119 Q_UNUSED(count)
120 Q_UNUSED(address)
121 return 0;
114 }
122 }
115
123
116 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
124 int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
117 {
125 {
118 return this->manager->sendPacket(packet,size);
126 return this->manager->sendPacket(packet,size);
119 }
127 }
120
128
121
129
122 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
130 GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
123 :QThread((QObject*)parent)
131 :QThread((QObject*)parent)
124 {
132 {
125 this->Read_soc = new QTcpSocket(this);
133 this->Read_soc = new QTcpSocket(this);
126 this->Write_soc = new QTcpSocket(this);
134 this->Write_soc = new QTcpSocket(this);
127 this->RMAPtimeout = 2000;
135 this->RMAPtimeout = 2000;
128 this->handleMutex = new QMutex(QMutex::NonRecursive);
136 this->handleMutex = new QMutex(QMutex::NonRecursive);
129 this->RMAP_AnswersSem = new QSemaphore(0);
137 this->RMAP_AnswersSem = new QSemaphore(0);
130 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
138 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
131 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
139 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
132 this->plugin = plugin;
140 this->plugin = plugin;
133 connected = false;
141 connected = false;
134 this->moveToThread(this);
142 this->moveToThread(this);
135 }
143 }
136
144
137 GR_ESB_Manager::~GR_ESB_Manager()
145 GR_ESB_Manager::~GR_ESB_Manager()
138 {
146 {
139
147
140 }
148 }
141
149
142 void GR_ESB_Manager::run()
150 void GR_ESB_Manager::run()
143 {
151 {
144 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
152 SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
145 while (!this->isInterruptionRequested())
153 while (!this->isInterruptionRequested())
146 {
154 {
147 if(this->connected)
155 if(this->connected)
148 {
156 {
149 handleMutex->lock();
157 handleMutex->lock();
150 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
158 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
151
159
152 }
160 }
153 else
161 else
154 {
162 {
155 //do some sanity checks!
163 //do some sanity checks!
156
164
157 usleep(RMAPtimeout/2);
165 usleep(RMAPtimeout/2);
158 }
166 }
159 usleep(1000);
167 usleep(1000);
160 }
168 }
161 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
169 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
162 }
170 }
163
171
164 bool GR_ESB_Manager::connectBridge()
172 bool GR_ESB_Manager::connectBridge()
165 {
173 {
166 int timeout=60;
174 int timeout=60;
167 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
175 if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
168 {
176 {
169 this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
177 this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
170 this->Read_soc->waitForConnected(30000);
178 this->Read_soc->waitForConnected(30000);
171 }
179 }
172 if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
180 if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
173 {
181 {
174 this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
182 this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
175 this->Write_soc->waitForConnected(30000);
183 this->Write_soc->waitForConnected(30000);
176 }
184 }
177 while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
185 while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
178 {
186 {
179 usleep(100000);
187 usleep(100000);
180 if(timeout--==0)return false;
188 if(timeout--==0)return false;
181 }
189 }
182 return true;
190 return true;
183
191
184 }
192 }
185
193
186 bool GR_ESB_Manager::disconnectBridge()
194 bool GR_ESB_Manager::disconnectBridge()
187 {
195 {
188 int timeout=60;
196 int timeout=60;
189 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
197 if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
190 {
198 {
191 this->Read_soc->disconnectFromHost();
199 this->Read_soc->disconnectFromHost();
192 this->Read_soc->waitForDisconnected(30000);
200 this->Read_soc->waitForDisconnected(30000);
193 }
201 }
194 if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
202 if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
195 {
203 {
196 this->Write_soc->disconnectFromHost();
204 this->Write_soc->disconnectFromHost();
197 this->Write_soc->waitForDisconnected(30000);
205 this->Write_soc->waitForDisconnected(30000);
198 }
206 }
199 while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
207 while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
200 {
208 {
201 usleep(100000);
209 usleep(100000);
202 if(timeout--==0)return false;
210 if(timeout--==0)return false;
203 }
211 }
204 return true;
212 return true;
205 }
213 }
206
214
207 int GR_ESB_Manager::getRMAPtransactionID()
215 int GR_ESB_Manager::getRMAPtransactionID()
208 {
216 {
209
217 // TODO write ME!
218 return -1;
210 }
219 }
211
220
212 int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
221 int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
213 {
222 {
214
223 // TODO write ME!
224 Q_UNUSED(transactionID)
225 Q_UNUSED(buffer)
226 return -1;
215 }
227 }
216
228
217 bool GR_ESB_Manager::sendPacket(char *packet, int size)
229 bool GR_ESB_Manager::sendPacket(char *packet, int size)
218 {
230 {
219
231 // TODO write ME!
232 Q_UNUSED(packet)
233 Q_UNUSED(size)
234 return false;
220 }
235 }
221
236
222 void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
237 void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
223 {
238 {
224
239 // TODO write ME!
240 Q_UNUSED(packet)
241 Q_UNUSED(len)
225 }
242 }
@@ -1,231 +1,231
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "spwtcppacketserver.h"
22 #include "spwtcppacketserver.h"
23 #include "ui_spwtcppacketserver.h"
23 #include "ui_spwtcppacketserver.h"
24 #include <QNetworkInterface>
24 #include <QNetworkInterface>
25 #include <QByteArray>
25 #include <QByteArray>
26
26
27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
27 SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
28 QWidget(parent),
28 QWidget(parent),
29 ui(new Ui::SpwTcpPacketServer)
29 ui(new Ui::SpwTcpPacketServer)
30 {
30 {
31 ui->setupUi(this);
31 ui->setupUi(this);
32 this->p_bridge = NULL;
32 this->p_bridge = NULL;
33 this->p_server = new QTcpServer();
33 this->p_server = new QTcpServer();
34 this->incomingTCParser = new IncomingTCParser();
34 this->incomingTCParser = new IncomingTCParser();
35
35
36 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
36 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
37 updateHostIP();
37 updateHostIP();
38 this->ui->PortLineEdit->setText("2200");
38 this->ui->PortLineEdit->setText("2200");
39 connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
39 connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
40 resetStatististics();
40 resetStatististics();
41
41
42 connect( this->incomingTCParser, SIGNAL(sendPacketUsingSpaceWire(QByteArray)),
42 connect( this->incomingTCParser, SIGNAL(sendPacketUsingSpaceWire(QByteArray)),
43 this, SLOT(sendTCUsingSpaceWire(QByteArray)));
43 this, SLOT(sendTCUsingSpaceWire(QByteArray)));
44 }
44 }
45
45
46 SpwTcpPacketServer::~SpwTcpPacketServer()
46 SpwTcpPacketServer::~SpwTcpPacketServer()
47 {
47 {
48 delete ui;
48 delete ui;
49 }
49 }
50
50
51 void SpwTcpPacketServer::setBridge(abstractSpwBridge *bridge)
51 void SpwTcpPacketServer::setBridge(abstractSpwBridge *bridge)
52 {
52 {
53 if(this->p_bridge!=NULL)
53 if(this->p_bridge!=NULL)
54 {
54 {
55 disconnect(this,SLOT(pushPacket(char*,int)));
55 disconnect(this,SLOT(pushPacket(char*,int)));
56 }
56 }
57 this->p_bridge = bridge;
57 this->p_bridge = bridge;
58 connect(bridge,SIGNAL(pushPacketOverTCP(char*,int)),SLOT(pushPacket(char*,int)));
58 connect(bridge,SIGNAL(pushPacketOverTCP(char*,int)),SLOT(pushPacket(char*,int)));
59 }
59 }
60
60
61 void SpwTcpPacketServer::pushPacket(char *packet, int size)
61 void SpwTcpPacketServer::pushPacket(char *packet, int size)
62 {
62 {
63 QByteArray data;
63 QByteArray data;
64 char sizech[3];
64 char sizech[3];
65 data.append((char)0);
65 data.append((char)0);
66 sizech[0]=size & 0x0FF;
66 sizech[0]=size & 0x0FF;
67 sizech[1]=(size>>8) & 0x0FF;
67 sizech[1]=(size>>8) & 0x0FF;
68 sizech[2]=(size>>16) & 0x0FF;
68 sizech[2]=(size>>16) & 0x0FF;
69 data.append(sizech,3);
69 data.append(sizech,3);
70 data.append(packet,size);
70 data.append(packet,size);
71 for(int i=0;i<connectedClients.count();i++)
71 for(int i=0;i<connectedClients.count();i++)
72 {
72 {
73 QTcpSocket* soc=connectedClients.at(i);
73 QTcpSocket* soc=connectedClients.at(i);
74 if(soc->state()!=QAbstractSocket::ConnectedState)
74 if(soc->state()!=QAbstractSocket::ConnectedState)
75 {
75 {
76 connectedClients.removeAt(i);
76 connectedClients.removeAt(i);
77 delete soc;
77 delete soc;
78 }
78 }
79 else
79 else
80 {
80 {
81 connectedClients.at(i)->write(data);
81 connectedClients.at(i)->write(data);
82 onePacketTransmitted();
82 onePacketTransmitted();
83 }
83 }
84 }
84 }
85 free(packet);
85 free(packet);
86 }
86 }
87
87
88 void SpwTcpPacketServer::toggleServer()
88 void SpwTcpPacketServer::toggleServer()
89 {
89 {
90 if(this->p_server->isListening())
90 if(this->p_server->isListening())
91 {
91 {
92 disconnectServer();
92 disconnectServer();
93 }
93 }
94 else
94 else
95 {
95 {
96 connectServer();
96 connectServer();
97 }
97 }
98 }
98 }
99
99
100 void SpwTcpPacketServer::connectServer()
100 void SpwTcpPacketServer::connectServer()
101 {
101 {
102 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
102 this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
103 this->ui->startServeQpb->setText("Stop Server");
103 this->ui->startServeQpb->setText("Stop Server");
104 resetStatististics();
104 resetStatististics();
105 }
105 }
106
106
107 void SpwTcpPacketServer::disconnectServer()
107 void SpwTcpPacketServer::disconnectServer()
108 {
108 {
109 this->ui->startServeQpb->setText("Start Server");
109 this->ui->startServeQpb->setText("Start Server");
110 this->p_server->close();
110 this->p_server->close();
111 }
111 }
112
112
113 void SpwTcpPacketServer::setServerPort(qint32 port)
113 void SpwTcpPacketServer::setServerPort(qint32 port)
114 {
114 {
115 this->ui->PortLineEdit->setText(QString("%1").arg(port));
115 this->ui->PortLineEdit->setText(QString("%1").arg(port));
116 }
116 }
117
117
118 void SpwTcpPacketServer::setServerSetIP(QString ip)
118 void SpwTcpPacketServer::setServerSetIP(QString ip)
119 {
119 {
120 this->ui->IPLineEdit->setText(ip);
120 this->ui->IPLineEdit->setText(ip);
121 }
121 }
122
122
123 void SpwTcpPacketServer::newConnection()
123 void SpwTcpPacketServer::newConnection()
124 {
124 {
125 QTcpSocket* soc=this->p_server->nextPendingConnection();
125 QTcpSocket* soc=this->p_server->nextPendingConnection();
126 this->connectedClients.append(soc);
126 this->connectedClients.append(soc);
127 this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString());
127 this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString());
128 connect(soc,SIGNAL(readyRead()),this,SLOT(parseIncomingTC()));
128 connect(soc,SIGNAL(readyRead()),this,SLOT(parseIncomingTC()));
129 }
129 }
130
130
131 void SpwTcpPacketServer::parseIncomingTC()
131 void SpwTcpPacketServer::parseIncomingTC()
132 {
132 {
133 for(int i=0;i<connectedClients.count();i++)
133 for(int i=0;i<connectedClients.count();i++)
134 {
134 {
135 QTcpSocket* soc=connectedClients.at(i);
135 QTcpSocket* soc=connectedClients.at(i);
136 if(soc->state()!=QAbstractSocket::ConnectedState)
136 if(soc->state()!=QAbstractSocket::ConnectedState)
137 {
137 {
138 connectedClients.removeAt(i);
138 connectedClients.removeAt(i);
139 delete soc;
139 delete soc;
140 }
140 }
141 else
141 else
142 {
142 {
143 if(soc->bytesAvailable()!=0)
143 if(soc->bytesAvailable()!=0)
144 {
144 {
145 do
145 do
146 {
146 {
147 QByteArray data = soc->readAll();
147 QByteArray data = soc->readAll();
148 incomingTCParser->processIncomingQByteArray( data );
148 incomingTCParser->processIncomingQByteArray( data );
149 }while(soc->bytesAvailable()!=0);
149 }while(soc->bytesAvailable()!=0);
150 }
150 }
151 }
151 }
152 }
152 }
153 }
153 }
154
154
155 void SpwTcpPacketServer::sendTCUsingSpaceWire(QByteArray data)
155 void SpwTcpPacketServer::sendTCUsingSpaceWire(QByteArray data)
156 {
156 {
157 onePacketReceived();
157 onePacketReceived();
158 if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission
158 if(data[0]==(char)0) // Protocole = 0 => Host to SpaceWire packet transmission
159 {
159 {
160 int size = (data[1]*256*256) + (data[2]*256) + data[3];
160 int size = (data[1]*256*256) + (data[2]*256) + data[3];
161 char* SPWpacket = (char*)malloc(size);
161 char* SPWpacket = (char*)malloc(size);
162 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
162 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
163 emit sendSPWPacket(SPWpacket,size);
163 emit sendSPWPacket(SPWpacket,size);
164 }
164 }
165 }
165 }
166
166
167 void SpwTcpPacketServer::readReady()
167 void SpwTcpPacketServer::readReady()
168 {
168 {
169 for(int i=0;i<connectedClients.count();i++)
169 for(int i=0;i<connectedClients.count();i++)
170 {
170 {
171 QTcpSocket* soc=connectedClients.at(i);
171 QTcpSocket* soc=connectedClients.at(i);
172 if(soc->state()!=QAbstractSocket::ConnectedState)
172 if(soc->state()!=QAbstractSocket::ConnectedState)
173 {
173 {
174 connectedClients.removeAt(i);
174 connectedClients.removeAt(i);
175 delete soc;
175 delete soc;
176 }
176 }
177 else
177 else
178 {
178 {
179 if(soc->bytesAvailable()!=0)
179 if(soc->bytesAvailable()!=0)
180 {
180 {
181 do
181 do
182 {
182 {
183 QByteArray data = soc->readAll();
183 QByteArray data = soc->readAll();
184 onePacketReceived();
184 onePacketReceived();
185 if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission
185 if(data[0]==(char)0) // Protocole = 0 => Host to SpaceWire packet transmission
186 {
186 {
187 int size = (data[1]*256*256) + (data[2]*256) + data[3];
187 int size = (data[1]*256*256) + (data[2]*256) + data[3];
188 char* SPWpacket = (char*)malloc(size);
188 char* SPWpacket = (char*)malloc(size);
189 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
189 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
190 emit sendSPWPacket(SPWpacket,size);
190 emit sendSPWPacket(SPWpacket,size);
191 }
191 }
192 }while(soc->bytesAvailable()!=0);
192 }while(soc->bytesAvailable()!=0);
193 }
193 }
194 }
194 }
195 }
195 }
196 }
196 }
197
197
198 void SpwTcpPacketServer::resetStatististics()
198 void SpwTcpPacketServer::resetStatististics()
199 {
199 {
200 receivedPackets = 0;
200 receivedPackets = 0;
201 transmittedPackets = 0;
201 transmittedPackets = 0;
202
202
203 this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
203 this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
204 this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
204 this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
205 }
205 }
206
206
207 void SpwTcpPacketServer::updateHostIP()
207 void SpwTcpPacketServer::updateHostIP()
208 {
208 {
209 QList<QHostAddress> list = QNetworkInterface::allAddresses();
209 QList<QHostAddress> list = QNetworkInterface::allAddresses();
210
210
211 for(int nIter=0; nIter<list.count(); nIter++)
211 for(int nIter=0; nIter<list.count(); nIter++)
212 {
212 {
213 if(!list[nIter].isLoopback())
213 if(!list[nIter].isLoopback())
214 if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
214 if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
215 this->ui->IPLineEdit->setText(list[nIter].toString());
215 this->ui->IPLineEdit->setText(list[nIter].toString());
216 }
216 }
217 }
217 }
218
218
219 void SpwTcpPacketServer::onePacketReceived()
219 void SpwTcpPacketServer::onePacketReceived()
220 {
220 {
221 receivedPackets = receivedPackets + 1;
221 receivedPackets = receivedPackets + 1;
222
222
223 this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
223 this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
224 }
224 }
225
225
226 void SpwTcpPacketServer::onePacketTransmitted()
226 void SpwTcpPacketServer::onePacketTransmitted()
227 {
227 {
228 transmittedPackets = transmittedPackets + 1;
228 transmittedPackets = transmittedPackets + 1;
229
229
230 this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
230 this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
231 }
231 }
@@ -1,1089 +1,1103
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 QString dwLinkStatusQString[6] = {
27 QString dwLinkStatusQString[6] = {
28 "CFG_SPACEWIRE_ERROR_RESET",
28 "CFG_SPACEWIRE_ERROR_RESET",
29 "CFG_SPACEWIRE_ERROR_WAIT",
29 "CFG_SPACEWIRE_ERROR_WAIT",
30 "CFG_SPACEWIRE_READY",
30 "CFG_SPACEWIRE_READY",
31 "CFG_SPACEWIRE_STARTED",
31 "CFG_SPACEWIRE_STARTED",
32 "CFG_SPACEWIRE_CONNECTING",
32 "CFG_SPACEWIRE_CONNECTING",
33 "CFG_SPACEWIRE_RUN"
33 "CFG_SPACEWIRE_RUN"
34 };
34 };
35
35
36 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
36 stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) :
37 abstractSpwBridge(parent)
37 abstractSpwBridge(parent)
38 {
38 {
39 Q_UNUSED(parent)
39 Q_UNUSED(parent)
40 this->manager = new stardundeeSPW_USB_Manager(parent,this);
40 this->manager = new stardundeeSPW_USB_Manager(parent,this);
41 makeGUI(parent);
41 makeGUI(parent);
42 this->manager->start();
42 this->manager->start();
43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
47 }
47 }
48
48
49 stardundeeSPW_USB::~stardundeeSPW_USB()
49 stardundeeSPW_USB::~stardundeeSPW_USB()
50 {
50 {
51 this->manager->requestInterruption();
51 this->manager->requestInterruption();
52 while(this->manager->isRunning());
52 while(this->manager->isRunning());
53 }
53 }
54
54
55 void stardundeeSPW_USB::toggleBridgeConnection()
55 void stardundeeSPW_USB::toggleBridgeConnection()
56 {
56 {
57 if(this->plugin->isConnected())
57 if(this->plugin->isConnected())
58 {
58 {
59 this->disconnectBridge();
59 this->disconnectBridge();
60 }
60 }
61 else
61 else
62 {
62 {
63 this->connectBridge();
63 this->connectBridge();
64 }
64 }
65 }
65 }
66
66
67 bool stardundeeSPW_USB::connectBridge()
67 bool stardundeeSPW_USB::connectBridge()
68 {
68 {
69 if(this->manager->connectBridge())
69 if(this->manager->connectBridge())
70 {
70 {
71 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
71 this->timecodeFrequencyChanged( ((StarDundeeGUI*)this->p_GUI)->getTimecodeFrequency());
72 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
72 this->startSendingTimecodes( ((StarDundeeGUI*)this->p_GUI)->getStartSendingTimecodes());
73 ((StarDundeeGUI*)this->p_GUI)->lock(true);
73 ((StarDundeeGUI*)this->p_GUI)->lock(true);
74 emit setConnected(true);
74 emit setConnected(true);
75 return true;
75 return true;
76 }
76 }
77 return false;
77 return false;
78 }
78 }
79
79
80 bool stardundeeSPW_USB::disconnectBridge()
80 bool stardundeeSPW_USB::disconnectBridge()
81 {
81 {
82 if(this->manager->disconnectBridge())
82 if(this->manager->disconnectBridge())
83 {
83 {
84 ((StarDundeeGUI*)this->p_GUI)->lock(false);
84 ((StarDundeeGUI*)this->p_GUI)->lock(false);
85 emit setConnected(false);
85 emit setConnected(false);
86 return true;
86 return true;
87 }
87 }
88 return false;
88 return false;
89 }
89 }
90
90
91 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
91 int stardundeeSPW_USB::pushRMAPPacket(char *packet, int size)
92 {
92 {
93 return this->manager->sendPacket(packet,size);
93 return this->manager->sendPacket(packet,size);
94 }
94 }
95
95
96 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
96 unsigned int stardundeeSPW_USB::Write(unsigned int *Value, unsigned int count, unsigned int address)
97 {
97 {
98 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
98 char writeBuffer[RMAP_WRITE_PACKET_MIN_SZ((RMAP_MAX_XFER_SIZE*4))+1];
99 char *RMAPAckBuff;
99 char *RMAPAckBuff;
100 writeBuffer[0]=this->manager->linkNumber;//Link number
100 writeBuffer[0]=this->manager->linkNumber;//Link number
101 int transactionID = 0;
101 int transactionID = 0;
102 int written=0;
102 int written=0;
103 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
103 SocExplorerEngine::message(this->plugin,"Enter Write function",2);
104 QProgressBar* progress=NULL;
104 QProgressBar* progress=NULL;
105 SocExplorerAutoProgressBar autopb;
105 SocExplorerAutoProgressBar autopb;
106 if(count>RMAP_MAX_XFER_SIZE)
106 if(count>RMAP_MAX_XFER_SIZE)
107 {
107 {
108 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
108 progress= SocExplorerEngine::getProgressBar("Writing on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
109 autopb.setProgressBar(progress);
109 autopb.setProgressBar(progress);
110 }
110 }
111 //Quite stupide loop, I guess that I always get the number of byte I asked for!
111 //Quite stupide loop, I guess that I always get the number of byte I asked for!
112 while(count>=RMAP_MAX_XFER_SIZE)
112 while(count>=RMAP_MAX_XFER_SIZE)
113 {
113 {
114 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
114 for(int i=0;i<(RMAP_MAX_XFER_SIZE);i++)
115 {
115 {
116 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
116 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)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
117 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)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
118 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)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
119 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
120 }
120 }
121 transactionID=manager->getRMAPtransactionID();
121 transactionID=manager->getRMAPtransactionID();
122 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
122 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
123 RMAP_build_tx_request_header(
123 RMAP_build_tx_request_header(
124 this->manager->destinationLogicalAddress,
124 this->manager->destinationLogicalAddress,
125 this->manager->destinationKey,
125 this->manager->destinationKey,
126 this->manager->sourceLogicalAddress,
126 this->manager->sourceLogicalAddress,
127 transactionID,
127 transactionID,
128 address+(written*4),
128 address+(written*4),
129 RMAP_MAX_XFER_SIZE*4,
129 RMAP_MAX_XFER_SIZE*4,
130 writeBuffer+1);
130 writeBuffer+1);
131 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
131 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1);
132 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
132 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
133 free(RMAPAckBuff);
133 free(RMAPAckBuff);
134 written+=RMAP_MAX_XFER_SIZE;
134 written+=RMAP_MAX_XFER_SIZE;
135 count-=RMAP_MAX_XFER_SIZE;
135 count-=RMAP_MAX_XFER_SIZE;
136 progress->setValue(written);
136 progress->setValue(written);
137 qApp->processEvents();
137 qApp->processEvents();
138 }
138 }
139 if(count>0)
139 if(count>0)
140 {
140 {
141 for(int i=0;i<((int)count);i++)
141 for(int i=0;i<((int)count);i++)
142 {
142 {
143 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
143 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+1] = (char)(((unsigned int)Value[i+written]>>24)&0xFF);
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
144 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+2] = (char)(((unsigned int)Value[i+written]>>16)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
145 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+3] = (char)(((unsigned int)Value[i+written]>>8)&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
146 writeBuffer[RMAP_WRITE_HEADER_MIN_SZ+(i*4)+4] = (char)(((unsigned int)Value[i+written])&0xFF);
147 }
147 }
148 transactionID=manager->getRMAPtransactionID();
148 transactionID=manager->getRMAPtransactionID();
149 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
149 SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2);
150 RMAP_build_tx_request_header(
150 RMAP_build_tx_request_header(
151 this->manager->destinationLogicalAddress,
151 this->manager->destinationLogicalAddress,
152 this->manager->destinationKey,
152 this->manager->destinationKey,
153 this->manager->sourceLogicalAddress,
153 this->manager->sourceLogicalAddress,
154 transactionID,
154 transactionID,
155 address+(written*4),
155 address+(written*4),
156 count*4,
156 count*4,
157 writeBuffer+1);
157 writeBuffer+1);
158 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
158 manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1);
159 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
159 manager->getRMAPanswer(transactionID,&RMAPAckBuff);
160 free(RMAPAckBuff);
160 free(RMAPAckBuff);
161 written+=count;
161 written+=count;
162 if(progress!=NULL)
162 if(progress!=NULL)
163 {
163 {
164 progress->setValue(written);
164 progress->setValue(written);
165 qApp->processEvents();
165 qApp->processEvents();
166 }
166 }
167 }
167 }
168 return written;
168 return written;
169 }
169 }
170
170
171 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
171 unsigned int stardundeeSPW_USB::Read(unsigned int *Value, unsigned int count, unsigned int address)
172 {
172 {
173 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
173 char requestBuffer[RMAP_READ_HEADER_MIN_SZ+1];
174 char* RMAP_AnswerBuffer;
174 char* RMAP_AnswerBuffer;
175 requestBuffer[0]=this->manager->linkNumber;//Link number
175 requestBuffer[0]=this->manager->linkNumber;//Link number
176 int transactionID = 0;
176 int transactionID = 0;
177 int read=0;
177 int read=0;
178 QProgressBar* progress=NULL;
178 QProgressBar* progress=NULL;
179 SocExplorerAutoProgressBar autopb;
179 SocExplorerAutoProgressBar autopb;
180 if(count>RMAP_MAX_XFER_SIZE)
180 if(count>RMAP_MAX_XFER_SIZE)
181 {
181 {
182 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
182 progress= SocExplorerEngine::getProgressBar("Reading on SPW @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
183 autopb.setProgressBar(progress);
183 autopb.setProgressBar(progress);
184 }
184 }
185 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
185 SocExplorerEngine::message(this->plugin,QString("Enter read function, count=%1, RMAP_MAX_XFER_SIZE=%2").arg(count).arg(RMAP_MAX_XFER_SIZE),2);
186
186
187 //Quite stupide loop, I guess that I always get the number of byte I asked for!
187 //Quite stupide loop, I guess that I always get the number of byte I asked for!
188 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
188 while((int)count>=(int)RMAP_MAX_XFER_SIZE)
189 {
189 {
190 transactionID = manager->getRMAPtransactionID();
190 transactionID = manager->getRMAPtransactionID();
191 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
191 SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2);
192 RMAP_build_rx_request_header(
192 RMAP_build_rx_request_header(
193 this->manager->destinationLogicalAddress,
193 this->manager->destinationLogicalAddress,
194 this->manager->destinationKey,
194 this->manager->destinationKey,
195 this->manager->sourceLogicalAddress,
195 this->manager->sourceLogicalAddress,
196 transactionID,
196 transactionID,
197 address+(read*4),
197 address+(read*4),
198 RMAP_MAX_XFER_SIZE*4,
198 RMAP_MAX_XFER_SIZE*4,
199 requestBuffer+1);
199 requestBuffer+1);
200 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
200 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
201 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
201 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
202 if(len==-1)
202 if(len==-1)
203 {
203 {
204 this->toggleBridgeConnection();
204 this->toggleBridgeConnection();
205 return 0;
205 return 0;
206 }
206 }
207 for(int i=0;i<((len-13)/4);i++)
207 for(int i=0;i<((len-13)/4);i++)
208 {
208 {
209 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
209 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
210 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
210 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
211 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
212 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
213 }
213 }
214 free(RMAP_AnswerBuffer);
214 free(RMAP_AnswerBuffer);
215 read+=RMAP_MAX_XFER_SIZE;
215 read+=RMAP_MAX_XFER_SIZE;
216 count-=RMAP_MAX_XFER_SIZE;
216 count-=RMAP_MAX_XFER_SIZE;
217 progress->setValue(read);
217 progress->setValue(read);
218 qApp->processEvents();
218 qApp->processEvents();
219 }
219 }
220 if((int)count>0)
220 if((int)count>0)
221 {
221 {
222 transactionID = manager->getRMAPtransactionID();
222 transactionID = manager->getRMAPtransactionID();
223 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
223 SocExplorerEngine::message(this->plugin,QString("New transactionID: %1").arg(transactionID),2);
224 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
224 SocExplorerEngine::message(this->plugin,QString("Building request with:"),2);
225 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
225 SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2);
226 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
226 SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2);
227 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
227 SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2);
228 RMAP_build_rx_request_header(
228 RMAP_build_rx_request_header(
229 this->manager->destinationLogicalAddress,
229 this->manager->destinationLogicalAddress,
230 this->manager->destinationKey,
230 this->manager->destinationKey,
231 this->manager->sourceLogicalAddress,
231 this->manager->sourceLogicalAddress,
232 transactionID,
232 transactionID,
233 address+(read*4),
233 address+(read*4),
234 count*4,
234 count*4,
235 requestBuffer+1);
235 requestBuffer+1);
236 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
236 manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1);
237 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
237 int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer);
238 if(len==-1)
238 if(len==-1)
239 {
239 {
240 this->toggleBridgeConnection();
240 this->toggleBridgeConnection();
241 return 0;
241 return 0;
242 }
242 }
243 for(int i=0;i<((len-13)/4);i++)
243 for(int i=0;i<((len-13)/4);i++)
244 {
244 {
245 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
245 Value[read+i] = 0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+12]);
246 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
246 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+13]));
247 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
247 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+14]));
248 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
248 Value[read+i] = (Value[read+i]<<8) + (0x0FF & ((unsigned int)RMAP_AnswerBuffer[(4*i)+15]));
249 }
249 }
250 free(RMAP_AnswerBuffer);
250 free(RMAP_AnswerBuffer);
251 read+=count;
251 read+=count;
252 if(progress!=NULL)
252 if(progress!=NULL)
253 {
253 {
254 progress->setValue(read);
254 progress->setValue(read);
255 qApp->processEvents();
255 qApp->processEvents();
256 }
256 }
257 }
257 }
258 return read;
258 return read;
259 }
259 }
260
260
261 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
261 void stardundeeSPW_USB::brickSelectionChanged(int brickIndex)
262 {
262 {
263 this->manager->selectedBrick = brickIndex-1;
263 this->manager->selectedBrick = brickIndex-1;
264 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
264 SocExplorerEngine::message(plugin,QString("Changing brick index: %1").arg(manager->selectedBrick),1);
265 }
265 }
266
266
267 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
267 void stardundeeSPW_USB::linkNumberSelectionChanged(int linkIndex)
268 {
268 {
269 this->manager->linkNumber = linkIndex + 1;
269 this->manager->linkNumber = linkIndex + 1;
270 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
270 SocExplorerEngine::message(plugin,QString("Changing Link Number: %1").arg(manager->linkNumber),1);
271 }
271 }
272
272
273 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
273 void stardundeeSPW_USB::linkSpeedSelectionChanged(const QString &linkSpeed)
274 {
274 {
275 this->manager->linkSpeed = linkSpeed.toInt();
275 this->manager->linkSpeed = linkSpeed.toInt();
276
276
277 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
277 SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1);
278 }
278 }
279
279
280 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
280 void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress)
281 {
281 {
282 this->manager->sourceLogicalAddress = sourceAddress.toInt();
282 this->manager->sourceLogicalAddress = sourceAddress.toInt();
283 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
283 SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1);
284 }
284 }
285
285
286 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
286 void stardundeeSPW_USB::destinationAddressChanged(const QString &rmapaddress)
287 {
287 {
288 this->manager->destinationLogicalAddress = rmapaddress.toInt();
288 this->manager->destinationLogicalAddress = rmapaddress.toInt();
289 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
289 SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1);
290 }
290 }
291
291
292 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
292 void stardundeeSPW_USB::destinationKeyChanged(const QString &key)
293 {
293 {
294 this->manager->destinationKey = key.toInt();
294 this->manager->destinationKey = key.toInt();
295 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
295 SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1);
296 }
296 }
297
297
298 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
298 void stardundeeSPW_USB::brickModeChanged( bool interfaceMode )
299 {
299 {
300 this->manager->interfaceMode = interfaceMode;
300 this->manager->interfaceMode = interfaceMode;
301 }
301 }
302
302
303 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
303 void stardundeeSPW_USB::timecodeFrequencyChanged(const QString &frequency)
304 {
304 {
305 this->manager->timecodeFrequency = frequency.toDouble();
305 this->manager->timecodeFrequency = frequency.toDouble();
306 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
306 this->manager->setTimecodeFrequency( this->manager->timecodeFrequency);
307 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
307 SocExplorerEngine::message(plugin,QString("Changing timecode frequency: %1").arg(manager->timecodeFrequency),1);
308 }
308 }
309
309
310 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
310 void stardundeeSPW_USB::startSendingTimecodes(bool onOff )
311 {
311 {
312 this->manager->sendTimecodePeriodically( onOff );
312 this->manager->sendTimecodePeriodically( onOff );
313 }
313 }
314
314
315 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
315 void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout)
316 {
316 {
317 int tim=timeout.toInt();
317 int tim=timeout.toInt();
318 if(tim<50)
318 if(tim<50)
319 {
319 {
320 tim = 50;
320 tim = 50;
321 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
321 ((StarDundeeGUI*)this->p_GUI)->setRmapTimeout(QString("%1").arg(tim));
322 }
322 }
323 this->manager->RMAPtimeout = tim;
323 this->manager->RMAPtimeout = tim;
324 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
324 SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1);
325 }
325 }
326
326
327 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
327 void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent)
328 {
328 {
329 Q_UNUSED(parent)
329 this->p_GUI = new StarDundeeGUI();
330 this->p_GUI = new StarDundeeGUI();
330 // this->mainLayout = new QGridLayout(this->p_GUI);
331 // this->mainLayout = new QGridLayout(this->p_GUI);
331 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
332 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
332 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
333 connect(this->manager,SIGNAL(updateAvailableBrickCount(int)),((StarDundeeGUI*)this->p_GUI),SLOT(updateAvailableBrickCount(int)));
333 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
334 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int)));
334 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int)));
335 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString)));
336 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString)));
337 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(destinationAddressChanged(QString)));
338 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString)));
339 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString)));
340 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool)));
341 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(timecodeFrequencyChange(QString)), this, SLOT(timecodeFrequencyChanged(QString)));
342 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
343 connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(startSendingTimecode(bool)), this, SLOT(startSendingTimecodes(bool)));
343
344
344 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
345 this->brickSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getBrickSelection());
345 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
346 this->linkNumberSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection());
346 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
347 this->linkSpeedSelectionChanged( ((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection());
347 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
348 this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getSourceAddress());
348 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
349 this->destinationAddressChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationAddress());
349 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
350 this->destinationKeyChanged( ((StarDundeeGUI*)this->p_GUI)->getDestinationKey());
350 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
351 this->rmapTimeoutChanged( ((StarDundeeGUI*)this->p_GUI)->getRmapTimeout());
351 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
352 this->brickModeChanged( ((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface());
352
353
353 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
354 connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int)));
354 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
355 connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int)));
355 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
356 connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int)));
356 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
357 connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString)));
357 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
358 connect(this,SIGNAL(SetDestinationAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationAddress(QString)));
358 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
359 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
359 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
360 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
360 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
361 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
361 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
362 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
362 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
363 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
363 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
364 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
364 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
365 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
365 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
366 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
366 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
367 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
367 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
368 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
368 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
369 connect(this,SIGNAL(CCSDSPacketTransmittedToSpw()), ((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
369 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
370 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(double)));
370 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
371 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
371
372
372 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
373 connect(this,SIGNAL(SendOneTimecode(unsigned char)),this->manager, SLOT(sendOneTimecode(unsigned char)));
373 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
374 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
374 }
375 }
375
376
376 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
377 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
377 {
378 {
378 char* data;
379 char* data;
379 int i;
380 int i;
380
381
381 data = (char *) malloc( size + 5 );
382 data = (char *) malloc( size + 5 );
382
383
383 data[0] = this->manager->linkNumber;
384 data[0] = this->manager->linkNumber;
384 data[1] = this->manager->destinationLogicalAddress; // target logical address
385 data[1] = this->manager->destinationLogicalAddress; // target logical address
385 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
386 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
386 data[3] = 0x00; // reserved
387 data[3] = 0x00; // reserved
387 data[4] = 0x00; // user application
388 data[4] = 0x00; // user application
388
389
389 for ( i=0; i<size; i++ )
390 for ( i=0; i<size; i++ )
390 {
391 {
391 data[i+5] = packet[i];
392 data[i+5] = packet[i];
392 }
393 }
393
394
394 this->manager->sendPacket( data, size + 5);
395 this->manager->sendPacket( data, size + 5);
395
396
396 free(data);
397 free(data);
397 free(packet);
398 free(packet);
398 }
399 }
399
400
400 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
401 stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent)
401 :QThread((QObject*)parent)
402 :QThread((QObject*)parent)
402 {
403 {
403 this->RMAPtimeout = 2000;
404 this->RMAPtimeout = 2000;
404 this->handleMutex = new QMutex(QMutex::NonRecursive);
405 this->handleMutex = new QMutex(QMutex::NonRecursive);
406 // this->handleMutex = new QMutex(QMutex::Recursive);
405 this->RMAP_AnswersSem = new QSemaphore(0);
407 this->RMAP_AnswersSem = new QSemaphore(0);
406 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
408 this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
407 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
409 this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
408 this->plugin = plugin;
410 this->plugin = plugin;
409 connected = false;
411 connected = false;
410 this->moveToThread(this);
412 // TODO remove this crap!
413 this->initDialog();
414 // this->moveToThread(this);
411 }
415 }
412
416
413 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
417 stardundeeSPW_USB_Manager::~stardundeeSPW_USB_Manager()
414 {
418 {
415 this->terminate();
419 this->terminate();
416 while (!this->isFinished()) {
420 while (!this->isFinished()) {
417 this->usleep(1000);
421 this->usleep(1000);
418 }
422 }
419 }
423 }
420
424
421 void stardundeeSPW_USB_Manager::run()
425 void stardundeeSPW_USB_Manager::run()
422 {
426 {
423 USB_SPACEWIRE_PACKET_PROPERTIES properties;
427 USB_SPACEWIRE_PACKET_PROPERTIES properties;
424 USB_SPACEWIRE_ID pIdentifier=NULL;
428 USB_SPACEWIRE_ID pIdentifier=NULL;
425 USB_SPACEWIRE_STATUS stat;
429 USB_SPACEWIRE_STATUS stat;
426 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
430 SocExplorerEngine::message(this->plugin,"Starting Startdundee USB pooling thread",1);
427 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
431 char buffer[(RMAP_MAX_XFER_SIZE*4)+50];
428 while (!this->isInterruptionRequested())
432 while (!this->isInterruptionRequested())
429 {
433 {
430 if(this->connected)
434 if(this->connected)
431 {
435 {
432 handleMutex->lock();
436 this->handleMutex->lock();
433 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
437 SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
434 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
438 if(USBSpaceWire_WaitOnReadPacketAvailable(hDevice,0.01))
435 {
439 {
436 SocExplorerEngine::message(this->plugin,"Got packet",2);
440 SocExplorerEngine::message(this->plugin,"Got packet",2);
437 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
441 stat = USBSpaceWire_ReadPackets(hDevice, buffer, (RMAP_MAX_XFER_SIZE*4)+50,1, 1, &properties, &pIdentifier);
438 if (stat == TRANSFER_SUCCESS)
442 if (stat == TRANSFER_SUCCESS)
439 {
443 {
440 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
444 if(USBSpaceWire_GetReadTrafficType(&properties, 0) ==SPACEWIRE_TRAFFIC_PACKET)
441 {
445 {
442 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
446 SocExplorerEngine::message(this->plugin,"It's a SPW packet",2);
443 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
447 if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP)
444 {
448 {
445 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
449 SocExplorerEngine::message(this->plugin,"Got end of packet",2);
446 emit bytesReceivedFromSpw( properties.len );
450 emit bytesReceivedFromSpw( properties.len );
447 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
451 if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet
448 {
452 {
449 RMAP_Answer* packet;
453 RMAP_Answer* packet;
450 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
454 SocExplorerEngine::message(this->plugin,"Got RMAP packet",2);
451 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
455 SocExplorerEngine::message(this->plugin,QString("Rmap packet size %1").arg(properties.len),2);
452 char* packetbuffer = (char*)malloc(properties.len);
456 char* packetbuffer = (char*)malloc(properties.len);
453 memcpy(packetbuffer,buffer,properties.len);
457 memcpy(packetbuffer,buffer,properties.len);
454 USBSpaceWire_FreeRead(hDevice, pIdentifier);
458 USBSpaceWire_FreeRead(hDevice, pIdentifier);
455 pIdentifier = NULL;
459 pIdentifier = NULL;
456 handleMutex->unlock();
460 this->handleMutex->unlock();
457 if(properties.len==8)
461 if(properties.len==8)
458 {
462 {
459 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
463 packet=new RMAP_Answer(RMAP_get_transactionID(buffer),packetbuffer,properties.len);
460 }
464 }
461 else
465 else
462 {
466 {
463 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
467 packet=new RMAP_Answer(RMAP_get_transactionID(buffer+1),packetbuffer,properties.len);
464 }
468 }
465 RMAP_AnswersMtx->lock();
469 RMAP_AnswersMtx->lock();
466 RMAP_Answers.append(packet);
470 RMAP_Answers.append(packet);
467 RMAP_AnswersMtx->unlock();
471 RMAP_AnswersMtx->unlock();
468 RMAP_AnswersSem->release();
472 RMAP_AnswersSem->release();
469 }
473 }
470 else //any non-rmap packet will be pushed to the network
474 else //any non-rmap packet will be pushed to the network
471 {
475 {
472 char* packetbuffer = (char*)malloc(properties.len);
476 char* packetbuffer = (char*)malloc(properties.len);
473 memcpy(packetbuffer,buffer,properties.len);
477 memcpy(packetbuffer,buffer,properties.len);
474 emit emitPacket(packetbuffer,properties.len);
478 emit emitPacket(packetbuffer,properties.len);
475 USBSpaceWire_FreeRead(hDevice, pIdentifier);
479 USBSpaceWire_FreeRead(hDevice, pIdentifier);
476 handleMutex->unlock();
480 this->handleMutex->unlock();
477 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
481 SocExplorerEngine::message(this->plugin,"Got SPW packet",2);
478 }
482 }
479 }
483 }
480 else
484 else
481 {
485 {
482 SocExplorerEngine::message(this->plugin,"No EOP received",2);
486 SocExplorerEngine::message(this->plugin,"No EOP received",2);
487 this->handleMutex->unlock();
483 }
488 }
484 }
489 }
485
490
486 }
491 }
487 else
492 else
488 {
493 {
489 USBSpaceWire_FreeRead(hDevice, pIdentifier);
494 USBSpaceWire_FreeRead(hDevice, pIdentifier);
490 handleMutex->unlock();
495 this->handleMutex->unlock();
491 }
496 }
492 }
497 }
493 else
498 else
494 {
499 {
495 USBSpaceWire_FreeRead(hDevice, pIdentifier);
500 USBSpaceWire_FreeRead(hDevice, pIdentifier);
496 handleMutex->unlock();
501 this->handleMutex->unlock();
497 }
502 }
498 }
503 }
499 else
504 else
500 {
505 {
501 //do some sanity checks!
506 //do some sanity checks!
502 int list = USBSpaceWire_ListDevices();
507 int list = USBSpaceWire_ListDevices();
503 if(this->brickList!=list)
508 if(this->brickList!=list)
504 {
509 {
505 this->brickList = list;
510 this->brickList = list;
506 emit updateAvailableBrickCount(this->brickList);
511 emit updateAvailableBrickCount(this->brickList);
507 }
512 }
508 usleep(RMAPtimeout/2);
513 usleep(RMAPtimeout/2);
509 }
514 }
510 usleep(1000);
515 usleep(1000);
511 }
516 }
512 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
517 SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
513 }
518 }
514
519
515 bool stardundeeSPW_USB_Manager::connectBridge()
520 bool stardundeeSPW_USB_Manager::connectBridge()
516 {
521 {
517 bool ret;
522 bool ret;
518
523
519 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
524 if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE)
520 {
525 {
521 ret = connectBridgeAsInterface();
526 ret = connectBridgeAsInterface();
522 }
527 }
523 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
528 else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER)
524 {
529 {
525 ret = connectBridgeAsRouter();
530 ret = connectBridgeAsRouter();
526 }
531 }
527 else
532 else
528 {
533 {
529 ret = false;
534 ret = false;
530 }
535 }
531
536
532 return ret;
537 return ret;
533 }
538 }
534
539
535 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
540 bool stardundeeSPW_USB_Manager::connectBridgeAsInterface()
536 {
541 {
537 QMutexLocker mlock(this->handleMutex);
542 // QMutexLocker mlock(&this->handleMutex);
543 this->handleMutex->lock();
538 int status;
544 int status;
539 U32 statusControl;
545 U32 statusControl;
540 this->connected = false;
546 this->connected = false;
541 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
547 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
542 {
548 {
543 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
549 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))",0);
550 this->handleMutex->unlock();
544 return false;
551 return false;
545 }
552 }
546 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
553 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful",0);
547
554
548 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
555 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
549 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
556 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
550 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
557 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
551
558
552 // Set the path and return path to the device
559 // Set the path and return path to the device
553 CFGSpaceWire_StackClear();
560 CFGSpaceWire_StackClear();
554 CFGSpaceWire_AddrStackPush(0);
561 CFGSpaceWire_AddrStackPush(0);
555 CFGSpaceWire_AddrStackPush(254);
562 CFGSpaceWire_AddrStackPush(254);
556 CFGSpaceWire_RetAddrStackPush(254);
563 CFGSpaceWire_RetAddrStackPush(254);
557 // set the base transmit rate to 100 MHz
564 // set the base transmit rate to 100 MHz
558 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
565 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
559 if (status != CFG_TRANSFER_SUCCESS)
566 if (status != CFG_TRANSFER_SUCCESS)
560 {
567 {
561 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
568 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate",1);
569 this->handleMutex->unlock();
562 return false;
570 return false;
563 }
571 }
564 else
572 else
565 {
573 {
566 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
574 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz",1);
567 }
575 }
568
576
569 // read the link status
577 // read the link status
570 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
578 if (CFGSpaceWire_GetLinkStatusControl(hDevice, this->linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
571 {
579 {
572 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
580 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(this->linkNumber),1);
581 this->handleMutex->unlock();
573 return false;
582 return false;
574 }
583 }
575 else
584 else
576 {
585 {
577 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
586 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(this->linkNumber),1);
578
587
579 // Set the link status control register properties
588 // Set the link status control register properties
580 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
589 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
581 CFGSpaceWire_LSEnableStart(&statusControl, 1);
590 CFGSpaceWire_LSEnableStart(&statusControl, 1);
582 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
591 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
583 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
592 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
584 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
593 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
585
594
586 // Set the link status control register
595 // Set the link status control register
587 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
596 if (CFGSpaceWire_SetLinkStatusControl(hDevice, this->linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
588 {
597 {
589 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
598 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(this->linkNumber),1);
599 this->handleMutex->unlock();
590 return false;
600 return false;
591 }
601 }
592 else
602 else
593 {
603 {
594 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
604 SocExplorerEngine::message(this->plugin,"Set the link status control for link " + QString::number(this->linkNumber),1);
595 }
605 }
596 }
606 }
597
607
598 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
608 if (CFGSpaceWire_SetAsInterface(hDevice, 1, 0) != CFG_TRANSFER_SUCCESS)
599 {
609 {
600 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
610 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface",1);
611 this->handleMutex->unlock();
601 return false;
612 return false;
602 }
613 }
603 else
614 else
604 {
615 {
605 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
616 SocExplorerEngine::message(this->plugin,"Device set to be an interface",1);
606 }
617 }
607
618
608 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
619 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on all ports
609 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
620 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
610 USBSpaceWire_SetTimeout(hDevice,1.0);
621 USBSpaceWire_SetTimeout(hDevice,1.0);
622 this->handleMutex->unlock();
611 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
623 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes",1);
612 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
624 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes",1);
613 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
625 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)),1);
614 this->connected = true;
626 this->connected = true;
615 return true;
627 return true;
616 }
628 }
617
629
618 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
630 bool stardundeeSPW_USB_Manager::connectBridgeAsRouter()
619 {
631 {
620 QMutexLocker mlock(this->handleMutex);
632 // QMutexLocker mlock(&this->handleMutex);
633 this->handleMutex->lock();
621 int status;
634 int status;
622 U32 statusControl;
635 U32 statusControl;
623 unsigned int linkStatus1;
636 unsigned int linkStatus1;
624 unsigned int linkStatus2;
637 unsigned int linkStatus2;
625 unsigned char linkNumber;
638 unsigned char linkNumber;
626 unsigned char deviceIsAnInterface;
639 unsigned char deviceIsAnInterface;
627
640
628 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
641 if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device
629 {
642 {
630 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
643 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))");
644 this->handleMutex->unlock();
631 return false;
645 return false;
632 }
646 }
633 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
647 SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: "
634 + QString::number(this->selectedBrick));
648 + QString::number(this->selectedBrick));
635
649
636 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
650 USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode
637 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
651 CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration
638 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
652 CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices
639
653
640 // Set the path and return path to the device
654 // Set the path and return path to the device
641 // This affects just the operations performed by the Configuration Library and does not affect the packets
655 // This affects just the operations performed by the Configuration Library and does not affect the packets
642 // sent and received using the driver API.
656 // sent and received using the driver API.
643 CFGSpaceWire_StackClear();
657 CFGSpaceWire_StackClear();
644 CFGSpaceWire_AddrStackPush(0);
658 CFGSpaceWire_AddrStackPush(0);
645 CFGSpaceWire_AddrStackPush(254);
659 CFGSpaceWire_AddrStackPush(254);
646 CFGSpaceWire_RetAddrStackPush(254);
660 CFGSpaceWire_RetAddrStackPush(254);
647
661
648 // set the base transmit rate to 100 MHz
662 // set the base transmit rate to 100 MHz
649 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
663 status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff);
650 if (status != CFG_TRANSFER_SUCCESS)
664 if (status != CFG_TRANSFER_SUCCESS)
651 {
665 {
652 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
666 SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate");
653 }
667 }
654 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
668 else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz");
655
669
656 //*********************
670 //*********************
657 // LINK 1 CONFIGURATION
671 // LINK 1 CONFIGURATION
658 linkNumber = 1;
672 linkNumber = 1;
659 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
673 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
660 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
674 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
661 else
675 else
662 {
676 {
663 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
677 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
664
678
665 // Set the link status control register properties
679 // Set the link status control register properties
666 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
680 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
667 CFGSpaceWire_LSEnableStart(&statusControl, 1);
681 CFGSpaceWire_LSEnableStart(&statusControl, 1);
668 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
682 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
669 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
683 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
670 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
684 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
671
685
672 // Set the link status control register
686 // Set the link status control register
673 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
687 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
674 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
688 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
675 else
689 else
676 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
690 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set");
677 }
691 }
678
692
679 //*********************
693 //*********************
680 // LINK 2 CONFIGURATION
694 // LINK 2 CONFIGURATION
681 linkNumber = 2;
695 linkNumber = 2;
682 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
696 if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS)
683 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
697 SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber));
684 else
698 else
685 {
699 {
686 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
700 SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber));
687
701
688 // Set the link status control register properties
702 // Set the link status control register properties
689 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
703 CFGSpaceWire_LSEnableAutoStart(&statusControl, 1);
690 CFGSpaceWire_LSEnableStart(&statusControl, 1);
704 CFGSpaceWire_LSEnableStart(&statusControl, 1);
691 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
705 CFGSpaceWire_LSEnableDisabled(&statusControl, 0);
692 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
706 CFGSpaceWire_LSEnableTristate(&statusControl, 0);
693 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
707 CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz
694
708
695 // Set the link status control register
709 // Set the link status control register
696 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
710 if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS)
697 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
711 SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber));
698 else
712 else
699 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
713 SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set");
700 }
714 }
701
715
702 //***************************
716 //***************************
703 // SET THE DEVICE AS A ROUTER
717 // SET THE DEVICE AS A ROUTER
704 deviceIsAnInterface = 0; // 0 = router, 1 = interface
718 deviceIsAnInterface = 0; // 0 = router, 1 = interface
705 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
719 if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS)
706 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
720 SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface");
707 else
721 else
708 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
722 SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)");
709
723
710 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
724 setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1
711 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
725 setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3
712
726
713 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
727 USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only
714 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
728 USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints
715
729
716 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
730 SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes");
717 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
731 SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes");
718 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
732 SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice)));
719
733
720 //************
734 //************
721 // test Link 1 and Link 2
735 // test Link 1 and Link 2
722 linkStatus1 = getLinkStatus(0x01);
736 linkStatus1 = getLinkStatus(0x01);
723 linkStatus2 = getLinkStatus(0x02);
737 linkStatus2 = getLinkStatus(0x02);
738 this->handleMutex->unlock();
724
739
725 if ((linkStatus1==1) || (linkStatus2==1))
740 if ((linkStatus1==1) || (linkStatus2==1))
726 {
741 {
727 initializeTimecodeGeneration();
742 initializeTimecodeGeneration();
728 this->connected=true;
743 this->connected=true;
729 return true;
744 return true;
730 }
745 }
731 else
746 else
732 {
747 {
733 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
748 statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1));
734 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
749 statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2));
735 starDundeeStatusQueryDialog->exec();
750 starDundeeStatusQueryDialog->exec();
736 this->connected = false;
751 this->connected = false;
737 return false;
752 return false;
738 }
753 }
739 }
754 }
740
755
741 void stardundeeSPW_USB_Manager::initDialog( void )
756 void stardundeeSPW_USB_Manager::initDialog( void )
742 {
757 {
743 // STAR DUNDEE STATUS QUERY DIALOG
758 // STAR DUNDEE STATUS QUERY DIALOG
744 starDundeeStatusQueryDialog = new QDialog;
759 starDundeeStatusQueryDialog = new QDialog;
745 starDundeeStatusQueryDialogLayout = new QGridLayout;
760 starDundeeStatusQueryDialogLayout = new QGridLayout;
746 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
761 starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state"));
747 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
762 starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue"));
748 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
763 starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry"));
749 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
764 starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort"));
750 statusLink1 = new QLabel(tr("Link 1 status code: -"));
765 statusLink1 = new QLabel(tr("Link 1 status code: -"));
751 statusLink2 = new QLabel(tr("Link 2 status code: -"));
766 statusLink2 = new QLabel(tr("Link 2 status code: -"));
752
767
753 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
768 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2);
754 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
769 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0);
755 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
770 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0);
756 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
771 starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0);
757 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
772 starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0);
758 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
773 starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0);
759 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
774 starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout);
760 }
775 }
761
776
762 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
777 unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead)
763 {
778 {
764 U32 routingTableEntry;
779 U32 routingTableEntry;
765 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
780 // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber
766 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
781 if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS)
767 {
782 {
768 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
783 SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry));
769 }
784 }
770 // Build the routing table entry
785 // Build the routing table entry
771 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
786 CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry,
772 dwOutputPorts, // route out of port dwOutputPorts
787 dwOutputPorts, // route out of port dwOutputPorts
773 bDelHead, // header deletion is enabled [1] or disabled [0]
788 bDelHead, // header deletion is enabled [1] or disabled [0]
774 0); // priority normal
789 0); // priority normal
775 // Set the routing table entry for logical address tableEntry
790 // Set the routing table entry for logical address tableEntry
776 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
791 if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS)
777 {
792 {
778 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
793 SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]");
779 }
794 }
780 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
795 else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" );
781 return 1;
796 return 1;
782 }
797 }
783
798
784 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
799 unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry)
785 {
800 {
786 U32 routingTableEntry, outputPorts;
801 U32 routingTableEntry, outputPorts;
787 char enabled, delHead, priority;
802 char enabled, delHead, priority;
788 int portNum;
803 int portNum;
789
804
790 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
805 SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]");
791 // Read the routing table entry
806 // Read the routing table entry
792 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
807 if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS)
793 {
808 {
794 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
809 SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]");
795 }
810 }
796 else
811 else
797 {
812 {
798 // Display the routing table entry properties
813 // Display the routing table entry properties
799 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
814 CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled);
800 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
815 CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead);
801 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
816 CFGSpaceWire_RTIsPriority(routingTableEntry, &priority);
802 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
817 CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts);
803 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
818 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled));
804 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
819 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead));
805 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
820 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority));
806 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
821 SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : ");
807 for (portNum = 0; portNum < 32; portNum++)
822 for (portNum = 0; portNum < 32; portNum++)
808 {
823 {
809 if (outputPorts & (1 << portNum))
824 if (outputPorts & (1 << portNum))
810 {
825 {
811 SocExplorerEngine::message(this->plugin,QString::number(portNum));
826 SocExplorerEngine::message(this->plugin,QString::number(portNum));
812 }
827 }
813 }
828 }
814 }
829 }
815
830
816 return 1;
831 return 1;
817 }
832 }
818
833
819 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
834 void stardundeeSPW_USB_Manager::initializeTimecodeGeneration()
820 {
835 {
821 U32 dwTickEnableStatus;
836 U32 dwTickEnableStatus;
822 U32 rtr_clk_freq;
837 U32 rtr_clk_freq;
823
838
824 // (1) RESET
839 // (1) RESET
825 if (!USBSpaceWire_TC_Reset(hDevice))
840 if (!USBSpaceWire_TC_Reset(hDevice))
826 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
841 SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n");
827
842
828 // (2) Clear the tick enable register
843 // (2) Clear the tick enable register
829 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
844 if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
830 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
845 SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register");
831 else
846 else
832 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
847 SocExplorerEngine::message(this->plugin,"Cleared the tick enable register");
833
848
834 // (3) get the tick status
849 // (3) get the tick status
835 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
850 CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
836 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
851 SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
837
852
838 // (4) enable external timecode selection
853 // (4) enable external timecode selection
839 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
854 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
840 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
855 SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection");
841
856
842 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
857 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
843
858
844 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
859 SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) );
845
860
846 //**************************************************
861 //**************************************************
847 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
862 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
848 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
863 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) )
849 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
864 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
850 }
865 }
851
866
852 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
867 unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link)
853 {
868 {
854 U32 statusControl, errorStatus, portType;
869 U32 statusControl, errorStatus, portType;
855 U32 linkStatus, operatingSpeed, outputPortConnection;
870 U32 linkStatus, operatingSpeed, outputPortConnection;
856 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
871 char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate;
857
872
858 // Read the link status control register
873 // Read the link status control register
859 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
874 if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS)
860 {
875 {
861 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
876 SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link));
862 }
877 }
863 else
878 else
864 {
879 {
865 // Display the link status control register properties
880 // Display the link status control register properties
866 CFGSpaceWire_LSPortType(statusControl, &portType);
881 CFGSpaceWire_LSPortType(statusControl, &portType);
867 if (portType == CFG_CONFIGURATION_PORT)
882 if (portType == CFG_CONFIGURATION_PORT)
868 {
883 {
869 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
884 CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus);
870 }
885 }
871 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
886 else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
872 {
887 {
873 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
888 CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
874 }
889 }
875 else
890 else
876 {
891 {
877 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
892 CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
878 }
893 }
879 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
894 CFGSpaceWire_LSLinkState(statusControl, &linkStatus);
880 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
895 CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning);
881 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
896 CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart);
882 CFGSpaceWire_LSIsStart(statusControl, &isStart);
897 CFGSpaceWire_LSIsStart(statusControl, &isStart);
883 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
898 CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled);
884 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
899 CFGSpaceWire_LSIsTristate(statusControl, &isTristate);
885 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
900 CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed);
886 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
901 CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection);
887 }
902 }
888 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
903 SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link)
889 +" is " + dwLinkStatusQString[linkStatus]);
904 +" is " + dwLinkStatusQString[linkStatus]);
890 if (linkStatus == 5)
905 if (linkStatus == 5)
891 {
906 {
892 return 1;
907 return 1;
893 }
908 }
894 else return 0;
909 else return 0;
895 }
910 }
896
911
897 bool stardundeeSPW_USB_Manager::disconnectBridge()
912 bool stardundeeSPW_USB_Manager::disconnectBridge()
898 {
913 {
899 this->handleMutex->lock();
914 this->handleMutex->lock();
900 USBSpaceWire_Close(hDevice); // Close the device
915 USBSpaceWire_Close(hDevice); // Close the device
901 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
916 SocExplorerEngine::message(this->plugin,"stardundee *** Close *** USBSpaceWire_Close, device: " + QString::number(0),0);
902 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
917 USBSpaceWire_UnregisterReceiveOnAllPorts(hDevice); // Stop receiving on all ports
903 this->handleMutex->unlock();
918 this->handleMutex->unlock();
904 this->RMAP_pending_transaction_IDsMtx->lock();
919 this->RMAP_pending_transaction_IDsMtx->lock();
905 this->RMAP_pending_transaction_IDs.clear();
920 this->RMAP_pending_transaction_IDs.clear();
906 this->RMAP_pending_transaction_IDsMtx->unlock();
921 this->RMAP_pending_transaction_IDsMtx->unlock();
907 this->RMAP_AnswersMtx->lock();
922 this->RMAP_AnswersMtx->lock();
908 this->RMAP_Answers.clear();
923 this->RMAP_Answers.clear();
909 this->RMAP_AnswersMtx->unlock();
924 this->RMAP_AnswersMtx->unlock();
910 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
925 this->RMAP_AnswersSem->acquire(this->RMAP_AnswersSem->available());
911 return true;
926 return true;
912 }
927 }
913
928
914 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
929 int stardundeeSPW_USB_Manager::getRMAPtransactionID()
915 {
930 {
916 this->RMAP_pending_transaction_IDsMtx->lock();
931 this->RMAP_pending_transaction_IDsMtx->lock();
917 int ID=0;
932 int ID=0;
918 bool found=true;
933 bool found=true;
919 while(ID<511)
934 while(ID<511)
920 {
935 {
921 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
936 for(int i=0;i<RMAP_pending_transaction_IDs.count();i++)
922 {
937 {
923 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
938 if(RMAP_pending_transaction_IDs[i]==ID)found=false;
924 }
939 }
925 if(found==true)break;
940 if(found==true)break;
926 ID++;
941 ID++;
927 found = true;
942 found = true;
928 }
943 }
929 if(found)
944 if(found)
930 {
945 {
931 RMAP_pending_transaction_IDs.append(ID);
946 RMAP_pending_transaction_IDs.append(ID);
932 }
947 }
933 this->RMAP_pending_transaction_IDsMtx->unlock();
948 this->RMAP_pending_transaction_IDsMtx->unlock();
934 return ID;
949 return ID;
935 }
950 }
936
951
937 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
952 int stardundeeSPW_USB_Manager::getRMAPanswer(int transactionID, char **buffer)
938 {
953 {
939 QTime timeout;
954 QTime timeout;
940 *buffer=NULL;
955 *buffer=NULL;
941 int count=0;
956 int count=0;
942 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
957 SocExplorerEngine::message(this->plugin,"Looking for RMAP answer",2);
943 timeout.start();
958 timeout.start();
944 while (*buffer==NULL)
959 while (*buffer==NULL)
945 {
960 {
946 this->RMAP_AnswersMtx->lock();
961 this->RMAP_AnswersMtx->lock();
947 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
962 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_Answers stack",2);
948 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
963 SocExplorerEngine::message(this->plugin,QString("%1 packet(s) available in RMAP_Answers stack").arg(RMAP_Answers.count()),2);
949 for(int i=0;i<RMAP_Answers.count();i++)
964 for(int i=0;i<RMAP_Answers.count();i++)
950 {
965 {
951 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
966 SocExplorerEngine::message(this->plugin,QString("Packet %1 ID=%2").arg(i).arg(RMAP_Answers[i]->transactionID),2);
952 if(RMAP_Answers[i]->transactionID==transactionID)
967 if(RMAP_Answers[i]->transactionID==transactionID)
953 {
968 {
954 this->RMAP_pending_transaction_IDsMtx->lock();
969 this->RMAP_pending_transaction_IDsMtx->lock();
955 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
970 SocExplorerEngine::message(this->plugin,"Got exclusive access on RMAP_pending_transaction_ID stack",2);
956 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
971 for(int j=0;j<RMAP_pending_transaction_IDs.count();j++)
957 {
972 {
958 if(RMAP_pending_transaction_IDs[j]==transactionID)
973 if(RMAP_pending_transaction_IDs[j]==transactionID)
959 {
974 {
960 RMAP_pending_transaction_IDs.removeAt(j);
975 RMAP_pending_transaction_IDs.removeAt(j);
961 }
976 }
962 }
977 }
963 this->RMAP_pending_transaction_IDsMtx->unlock();
978 this->RMAP_pending_transaction_IDsMtx->unlock();
964 *buffer = RMAP_Answers[i]->data;
979 *buffer = RMAP_Answers[i]->data;
965 count = RMAP_Answers[i]->len;
980 count = RMAP_Answers[i]->len;
966 RMAP_Answer* tmp=RMAP_Answers[i];
981 RMAP_Answer* tmp=RMAP_Answers[i];
967 RMAP_Answers.removeAt(i);
982 RMAP_Answers.removeAt(i);
968 delete tmp;
983 delete tmp;
969 }
984 }
970 }
985 }
971 this->RMAP_AnswersMtx->unlock();
986 this->RMAP_AnswersMtx->unlock();
972 //if no answer found in the stack wait until a new packet is pushed
987 //if no answer found in the stack wait until a new packet is pushed
973 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
988 SocExplorerEngine::message(this->plugin,"waiting until a new packet is pushed",2);
974 if(*buffer==NULL)
989 if(*buffer==NULL)
975 {
990 {
976 while (0==this->RMAP_AnswersSem->available())
991 while (0==this->RMAP_AnswersSem->available())
977 {
992 {
978 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
993 SocExplorerEngine::message(this->plugin,QString("this->RMAP_AnswersSem->available() = %1").arg(this->RMAP_AnswersSem->available()),2);
979 if(timeout.elapsed()>=RMAPtimeout)
994 if(timeout.elapsed()>=RMAPtimeout)
980 {
995 {
981 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
996 SocExplorerEngine::message(this->plugin,"Timeout reached giving up!",2);
982 return -1;
997 return -1;
983 }
998 }
984 usleep(1000);
999 usleep(1000);
985 }
1000 }
986 this->RMAP_AnswersSem->acquire();
1001 this->RMAP_AnswersSem->acquire();
987 }
1002 }
988 }
1003 }
989 return count;
1004 return count;
990 }
1005 }
991
1006
992 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
1007 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
993 {
1008 {
994 char protocoleIdentifier;
1009 char protocoleIdentifier;
995 USB_SPACEWIRE_STATUS result;
1010 USB_SPACEWIRE_STATUS result=TRANSFER_ERROR_NOT_FOUND;
996 USB_SPACEWIRE_ID pIdentifier;
1011 USB_SPACEWIRE_ID pIdentifier;
997 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
1012 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
998 this->handleMutex->lock();
1013 this->handleMutex->lock();
999 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
1014 result = USBSpaceWire_SendPacket(hDevice,packet,size,1, &pIdentifier);
1015 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1016 this->handleMutex->unlock();
1000 if (result != TRANSFER_SUCCESS)
1017 if (result != TRANSFER_SUCCESS)
1001 {
1018 {
1002 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
1019 SocExplorerEngine::message(this->plugin,"ERR sending the READ command ",2);
1003 this->handleMutex->unlock();
1004 return false;
1020 return false;
1005 }
1021 }
1006 else
1022 else
1007 {
1023 {
1008 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1024 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1009
1010 // read the protocole identifier
1025 // read the protocole identifier
1011 protocoleIdentifier = packet[2];
1026 protocoleIdentifier = packet[2];
1012 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1027 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1013 emit ccsdsPacketTransmittedToSpw();
1028 emit ccsdsPacketTransmittedToSpw();
1014
1029
1015 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1030 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1016 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1017 }
1031 }
1018 this->handleMutex->unlock();
1032 // this->handleMutex->unlock();
1019 return true;
1033 return true;
1020 }
1034 }
1021
1035
1022 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1036 void stardundeeSPW_USB_Manager::pushRmapPacket(char *packet, int len)
1023 {
1037 {
1024 char* packetbuffer = (char*)malloc(len);
1038 char* packetbuffer = (char*)malloc(len);
1025 memcpy(packetbuffer,packet,len);
1039 memcpy(packetbuffer,packet,len);
1026 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1040 RMAP_Answer* RMPAPpacket=new RMAP_Answer(RMAP_get_transactionID(packetbuffer+1),packetbuffer,len);
1027 RMAP_AnswersMtx->lock();
1041 RMAP_AnswersMtx->lock();
1028 RMAP_Answers.append(RMPAPpacket);
1042 RMAP_Answers.append(RMPAPpacket);
1029 RMAP_AnswersMtx->unlock();
1043 RMAP_AnswersMtx->unlock();
1030 }
1044 }
1031
1045
1032 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1046 void stardundeeSPW_USB_Manager::sendTimecodePeriodically( bool onOff )
1033 {
1047 {
1034 if (onOff == true)
1048 if (onOff == true)
1035 {
1049 {
1036 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
1050 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 1, 1))
1037 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
1051 SocExplorerEngine::message(this->plugin,"Could not enable auto tick-in");
1038 }
1052 }
1039 else
1053 else
1040 {
1054 {
1041 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
1055 if (!USBSpaceWire_TC_EnableAutoTickIn(hDevice, 0, 0))
1042 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
1056 SocExplorerEngine::message(this->plugin,"Could not disable auto tick-in");
1043 }
1057 }
1044 }
1058 }
1045
1059
1046 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1060 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1047 {
1061 {
1048 return this->linkNumber;
1062 return this->linkNumber;
1049 }
1063 }
1050
1064
1051 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1065 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1052 {
1066 {
1053 U32 rtr_clk_freq;
1067 U32 rtr_clk_freq=0;
1054 U32 freqCount;
1068 U32 freqCount=0;
1055 double freqCountInDouble;
1069 double freqCountInDouble=0.0;
1056 double currentFrequency;
1070 double currentFrequency=0.0;
1057
1071
1058 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
1072 rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice);
1059 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
1073 freqCountInDouble = ((double) rtr_clk_freq) / requestedFrequency;
1060 freqCount = (unsigned int) freqCountInDouble;
1074 freqCount = (unsigned int) freqCountInDouble;
1061
1075
1062 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
1076 currentFrequency = ((double) rtr_clk_freq) / ((double) freqCount);
1063
1077
1064 //**************************************************
1078 //**************************************************
1065 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
1079 // auto _ tick _ freq = rtr _ clk _ freq / freqCount
1066 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
1080 if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, freqCount) )
1067 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
1081 SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency");
1068 else
1082 else
1069 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
1083 SocExplorerEngine::message(this->plugin,"tick frequency set to " + QString::number(currentFrequency) +" Hz"
1070 + " (freqCount set to " + QString::number(freqCount) + ")" );
1084 + " (freqCount set to " + QString::number(freqCount) + ")" );
1071 }
1085 }
1072
1086
1073 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
1087 void stardundeeSPW_USB_Manager::sendOneTimecode( unsigned char nTimein )
1074 {
1088 {
1075 // enable external timecode selection
1089 // enable external timecode selection
1076 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
1090 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,1))
1077 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
1091 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** enable external timecode selection");
1078
1092
1079 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1093 if (!USBSpaceWire_TC_PerformTickIn( hDevice, nTimein) )
1080 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1094 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** ERR *** Could not send the requested timecode: " + QString::number(nTimein) );
1081 else
1095 else
1082 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1096 SocExplorerEngine::message( this->plugin,"sendOneTimecode *** OK *** timecode sent " + QString::number(nTimein) );
1083
1097
1084 // disable external timecode selection
1098 // disable external timecode selection
1085 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1099 if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
1086 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1100 SocExplorerEngine::message(this->plugin,"sendOneTimecode *** ERR *** disable external timecode selection");
1087 }
1101 }
1088
1102
1089
1103
@@ -1,56 +1,56
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 "abstractspwbridge.h"
22 #include "abstractspwbridge.h"
23
23
24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
24 abstractSpwBridge::abstractSpwBridge(socexplorerplugin *parent)
25 :QObject((QObject*)parent)
25 :QObject((QObject*)parent)
26 {
26 {
27 this->plugin = parent;
27 this->plugin = parent;
28 this->p_GUI=NULL;
28 this->p_GUI=NULL;
29 }
29 }
30
30
31 abstractSpwBridge::~abstractSpwBridge()
31 abstractSpwBridge::~abstractSpwBridge()
32 {
32 {
33 delete this->p_GUI;
33 // delete this->p_GUI;
34 }
34 }
35
35
36 QWidget *abstractSpwBridge::getGUI()
36 QWidget *abstractSpwBridge::getGUI()
37 {
37 {
38 return this->p_GUI;
38 return this->p_GUI;
39 }
39 }
40
40
41 bool abstractSpwBridge::connectBridge()
41 bool abstractSpwBridge::connectBridge()
42 {
42 {
43 return false;
43 return false;
44 }
44 }
45
45
46 bool abstractSpwBridge::disconnectBridge()
46 bool abstractSpwBridge::disconnectBridge()
47 {
47 {
48 return false;
48 return false;
49 }
49 }
50
50
51
51
52
52
53
53
54
54
55
55
56
56
@@ -1,94 +1,89
1 #
1 #
2 # Project created by QtCreator 2011-09-20T08:15:30
2 # Project created by QtCreator 2011-09-20T08:15:30
3 #
3 #
4 #-------------------------------------------------
4 #-------------------------------------------------
5
5
6 CONFIG += socexplorerplugin
6 CONFIG += socexplorerplugin
7 QT += network webkit
7 QT += network webkit
8 greaterThan(QT_MAJOR_VERSION, 4): QT += webkitwidgets
8 greaterThan(QT_MAJOR_VERSION, 4): QT += webkitwidgets
9
9
10 win32:CONFIG += dll
10 win32:CONFIG += dll
11 win32:CONFIG -= static
11 win32:CONFIG -= static
12 CONFIG(debug, debug|release) {
12 TARGET = spwplugin
13 DEBUG_EXT = _d
14 } else {
15 DEBUG_EXT =
16 }
17 TARGET = spwplugin$${DEBUG_EXT}
18 DEFINES += PLUGIN=spwplugin
13 DEFINES += PLUGIN=spwplugin
19 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
14 DEFINES += PLUGINHEADER="\"\\\"spwplugin.h"\\\"\"
20 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
15 DEFINES += driver_Name="\"\\\"SpwPlugin"\\\"\"
21 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
16 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
22 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
17 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
23 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
18 DEFINES += driver_Description="\"\\\"Driver description"\\\"\"
24 DEFINES += driver_can_be_root=1
19 DEFINES += driver_can_be_root=1
25 DEFINES += driver_can_be_child=0
20 DEFINES += driver_can_be_child=0
26 DEFINES += driver_VID=0
21 DEFINES += driver_VID=0
27 DEFINES += driver_PID=0
22 DEFINES += driver_PID=0
28
23
29 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
24 STARTDUNDEEPATH=/home/spacewire/usb/spw_usb_driver_v2.68/
30
25
31 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
26 LIBS += $$STARTDUNDEEPATH/lib/x86_64/libSpaceWireUSBAPI.so \
32 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
27 $$STARTDUNDEEPATH/lib/x86_64/libConfigLibraryUSB.so
33
28
34 INCLUDEPATH += \
29 INCLUDEPATH += \
35 $${PWD} \
30 $${PWD} \
36 $$STARTDUNDEEPATH/inc \
31 $$STARTDUNDEEPATH/inc \
37 StarDundee \
32 StarDundee \
38 GR-ESB
33 GR-ESB
39
34
40 HEADERS += \
35 HEADERS += \
41 spwplugin.h \
36 spwplugin.h \
42 StarDundee/stardundeespw_usb.h \
37 StarDundee/stardundeespw_usb.h \
43 abstractspwbridge.h \
38 abstractspwbridge.h \
44 spw.h \
39 spw.h \
45 StarDundee/stardundeegui.h \
40 StarDundee/stardundeegui.h \
46 SpwTcpPacketServer/spwtcppacketserver.h \
41 SpwTcpPacketServer/spwtcppacketserver.h \
47 spwpywrapper.h \
42 spwpywrapper.h \
48 GR-ESB/gr_esb_bridge.h \
43 GR-ESB/gr_esb_bridge.h \
49 GR-ESB/gr_esb_ui.h \
44 GR-ESB/gr_esb_ui.h \
50 incomingtcparser.h
45 incomingtcparser.h
51
46
52
47
53 SOURCES += \
48 SOURCES += \
54 spwplugin.cpp \
49 spwplugin.cpp \
55 StarDundee/stardundeespw_usb.cpp \
50 StarDundee/stardundeespw_usb.cpp \
56 abstractspwbridge.cpp \
51 abstractspwbridge.cpp \
57 StarDundee/stardundeegui.cpp \
52 StarDundee/stardundeegui.cpp \
58 SpwTcpPacketServer/spwtcppacketserver.cpp \
53 SpwTcpPacketServer/spwtcppacketserver.cpp \
59 spwpywrapper.cpp \
54 spwpywrapper.cpp \
60 GR-ESB/gr_esb_bridge.cpp \
55 GR-ESB/gr_esb_bridge.cpp \
61 GR-ESB/gr_esb_ui.cpp \
56 GR-ESB/gr_esb_ui.cpp \
62 incomingtcparser.cpp
57 incomingtcparser.cpp
63
58
64 FORMS += \
59 FORMS += \
65 StarDundee/stardundeeGUI.ui \
60 StarDundee/stardundeeGUI.ui \
66 SpwTcpPacketServer/spwtcppacketserver.ui \
61 SpwTcpPacketServer/spwtcppacketserver.ui \
67 GR-ESB/gr_esb_ui.ui
62 GR-ESB/gr_esb_ui.ui
68
63
69 RESOURCES += \
64 RESOURCES += \
70 spwRessources.qrc
65 spwRessources.qrc
71
66
72
67
73
68
74
69
75
70
76
71
77
72
78
73
79
74
80
75
81
76
82
77
83
78
84
79
85
80
86
81
87
82
88
83
89
84
90
85
91
86
92
87
93
88
94
89
General Comments 0
You need to be logged in to leave comments. Login now