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