##// END OF EJS Templates
Removed APBUartPlugin bug (when switching between debug and non debug link)....
jeandet -
r34:ccd56e93ef09 default
parent child
Show More
@@ -0,0 +1,27
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 #include "apbuartpywrapper.h"
23
24 APBUartPyWrapper::APBUartPyWrapper(socexplorerplugin *parent) :
25 genericPySysdriver(parent)
26 {
27 }
@@ -0,0 +1,46
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 #ifndef APBUARTPYWRAPPER_H
23 #define APBUARTPYWRAPPER_H
24 #include <QString>
25 #include <socexplorerplugin.h>
26 #include <genericPySysdriver.h>
27
28 class APBUartPyWrapper : public genericPySysdriver
29 {
30 Q_OBJECT
31 public:
32 explicit APBUartPyWrapper(socexplorerplugin *parent = 0);
33
34 signals:
35 void setFifoDebugEnabled(bool enable);
36 void setAPBUartIndex(int index);
37 void setUARTPortNane(QString name);
38 void setUARTPortSpeed(int speed);
39 void updateAPBUartsList();
40 void openUart();
41 void closeUart();
42 public slots:
43
44 };
45
46 #endif // APBUARTPYWRAPPER_H
@@ -1,102 +1,177
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "APBUARTPLUGIN.h"
23 23 #include <socexplorerengine.h>
24 #include <apbuartpywrapper.h>
24 25
25 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent,false)
26 27 {
27 28 this->setBaseAddress(-1);
29 this->p_curentAPBUart = 0;
28 30 this->UI = new APBUART_Plugin_ui();
29 31 this->setWidget((QWidget*)this->UI);
30 32 this->uartConnected = false;
31 33 this->UartThread = new UARTPollingThread(this);
32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
34 this->pyObject = new APBUartPyWrapper(this);
35 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(fifoDebugChangeState(int)));
33 36 connect(this->UartThread,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
34 37 connect(this->UI,SIGNAL(connectPort()),this,SLOT(toggleUartState()));
35 38 connect(this->UI,SIGNAL(sendChar(char)),this->UartThread,SLOT(sendChar(char)));
36 39 connect(this->UI,SIGNAL(PortNameChanged(QString)),this->UartThread,SLOT(setPortName(QString)));
37 40 connect(this->UI,SIGNAL(UartSpeedChanged(QString)),this->UartThread,SLOT(setPortSpeedStr(QString)));
41 connect(this->UI,SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList()));
42 connect(this->UI,SIGNAL(curentAPBUartChanged(int)),this,SLOT(setCurentAPBUart(int)));
43 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(openUart()),this,SLOT(openUart()));
44 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(closeUart()),this,SLOT(closeUart()));
45 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setFifoDebugEnabled(bool)),this,SLOT(setFifoDebugEnabled(bool)));
46 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortNane(QString)),this,SLOT(setUARTPortNane(QString)));
47 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortSpeed(int)),this,SLOT(setUARTPortSpeed(int)));
48 connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList()));
38 49 this->UartThread->start();
39 50 }
40 51
41 52
42 53 ApbUartPlugin::~ApbUartPlugin()
43 54 {
44 55
45 56 }
46 57
58 int ApbUartPlugin::curentAPBUart()
59 {
60 return p_curentAPBUart;
61 }
62
47 63 void ApbUartPlugin::closeMe()
48 64 {
49 65 emit this->closePlugin(this);
50 66 }
51 67
52 68 void ApbUartPlugin::toggleUartState()
53 69 {
54 70 if(!uartConnected)
55 71 {
56 uartConnected = this->UartThread->openUart();
72 this->openUart();
57 73 }
58 74 else
59 75 {
60 this->UartThread->closeUart();
61 this->uartConnected = false;
76 this->closeUart();
77 }
78 }
79
80 void ApbUartPlugin::activate(bool flag)
81 {
82 socexplorerplugin::activate(flag);
83 this->updateAPBUartsList();
62 84 }
85
86 void ApbUartPlugin::updateAPBUartsList()
87 {
88 QList<unsigned int> addresses;
89 int count = SocExplorerEngine::self()->getEnumDeviceCount(this,this->VID(),this->PID());
90 for(int i=0;i<count;i++)
91 {
92 addresses.append(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),i));
93 }
94 this->UI->updateAPBUartList(addresses);
95 }
96
97 void ApbUartPlugin::setCurentAPBUart(int index)
98 {
99 this->p_curentAPBUart = index;
100 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),index));
101 }
102
103 void ApbUartPlugin::openUart()
104 {
105 if(this->UartThread->fifoDebugEnabled())
106 setFifoDebugEnabled(false);
107 if(!uartConnected)
108 uartConnected = this->UartThread->openUart();
63 109 this->UI->setUartConnected(uartConnected);
64 110 }
65 111
66 void ApbUartPlugin::loopbackChangeState(int state)
112 void ApbUartPlugin::closeUart()
113 {
114 if(uartConnected)
115 this->UartThread->closeUart();
116 this->uartConnected = false;
117 this->UI->setUartConnected(uartConnected);
118 }
119
120 void ApbUartPlugin::setFifoDebugEnabled(bool enable)
121 {
122 if(uartConnected)
123 closeUart();
124 this->UI->setEnableForLoopBack(!enable);
125 this->UartThread->setFifoDebugEable(enable);
126 }
127
128 void ApbUartPlugin::setAPBUartIndex(int index)
129 {
130 this->UI->setAPBUartIndex(index);
131 }
132
133 void ApbUartPlugin::setUARTPortNane(QString name)
134 {
135 this->UI->setUartPortName(name);
136 }
137
138 void ApbUartPlugin::setUARTPortSpeed(int speed)
139 {
140 this->UI->setUartSpeed(speed);
141 }
142
143 void ApbUartPlugin::fifoDebugChangeState(int state)
67 144 {
68 145 if(state==Qt::Checked)
69 146 {
70 this->UI->setEnableForLoopBack(false);
71 this->UartThread->setFifoDebugEable(true);
147 this->setFifoDebugEnabled(true);
72 148 }
73 149 else
74 150 {
75 this->UI->setEnableForLoopBack(true);
76 this->UartThread->setFifoDebugEable(false);
151 this->setFifoDebugEnabled(false);
77 152 }
78 153 }
79 154
80 155
81 156 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
82 157 {
83 158 if(parent!=NULL)
84 159 return parent->Read(Value,count,address);
85 160 return 0;
86 161 }
87 162
88 163
89 164 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
90 165 {
91 166 if(parent!=NULL)
92 167 return parent->Write(Value,count,address);
93 168 return 0;
94 169 }
95 170
96 171
97 172
98 173
99 174
100 175
101 176
102 177
@@ -1,65 +1,76
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTPLUGIN_H
23 23 #define APBUARTPLUGIN_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28
29 29 #include <socexplorerplugin.h>
30 30 #include <QTimer>
31 31 #include "apbuart_plugin_ui.h"
32 32 #include "uartpollingthread.h"
33 33 #define APB_UART_DATA_REG 0x0
34 34 #define APB_UART_STATUS_REG 0x4
35 35 #define APB_UART_CONTROL_REG 0x8
36 36 #define APB_UART_SCALE_REG 0xC
37 37 #define APB_UART_FIFO_DEBUG_REG 0x10
38 38
39 39 class ApbUartPlugin : public socexplorerplugin
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 explicit ApbUartPlugin(QWidget *parent = 0);
44 44 ~ApbUartPlugin();
45 45 int VID(){return driver_VID;}
46 46 int PID(){return driver_PID;}
47 int curentAPBUart();
47 48
48 49 public slots:
49 50 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
50 51 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
51 void loopbackChangeState(int state);
52 void fifoDebugChangeState(int state);
52 53 void closeMe();
53 54 void toggleUartState();
55 void activate(bool flag);
56 void updateAPBUartsList();
57 void setCurentAPBUart(int index);
58 void openUart();
59 void closeUart();
60 void setFifoDebugEnabled(bool enable);
61 void setAPBUartIndex(int index);
62 void setUARTPortNane(QString name);
63 void setUARTPortSpeed(int speed);
54 64 signals:
55 65
56 66 private:
57 67 APBUART_Plugin_ui* UI;
58 68 bool uartConnected;
69 int p_curentAPBUart;
59 70 UARTPollingThread* UartThread;
60 71 int enableLoopback();
61 72 int disableLoopback();
62 73 };
63 74
64 75 #endif // APBUARTPLUGIN_H
65 76
@@ -1,72 +1,75
1 1 #
2 2 # Project created by QtCreator 2011-09-20T08:15:30
3 3 #
4 4 #-------------------------------------------------
5 5
6 6 CONFIG += socexplorerplugin
7
7 8 win32:CONFIG += dll
8 9 win32:CONFIG -= static
9 10
10 11 CONFIG(debug, debug|release) {
11 12 DEBUG_EXT = _d
12 13 } else {
13 14 DEBUG_EXT =
14 15 }
15 16
16 17 TARGET = ApbUartPlugin$${DEBUG_EXT}
17 18
18 19 DEFINES += PLUGIN=ApbUartPlugin
19 20 DEFINES += PLUGINHEADER="\"\\\"APBUARTPLUGIN.h"\\\"\"
20 21 DEFINES += driver_Name="\"\\\"APB_UART_PLUGIN"\\\"\"
21 22 DEFINES += driver_Author="\"\\\"Alexis Jeandet alexis.jeandet@member.fsf.org"\\\"\"
22 23 DEFINES += driver_Version="\"\\\"0.0.1"\\\"\"
23 24 DEFINES += driver_Description="\"\\\"This plugin provides a terminal widget connected to Gaisler\'s APBUART with or without loop-back mode."\\\"\"
24 25 DEFINES += driver_can_be_root=0
25 26 DEFINES += driver_can_be_child=1
26 27 DEFINES += driver_VID=1
27 28 DEFINES += driver_PID=0x0c
28 29
29 30
30 31
31 32 INCLUDEPATH += \
32 33 $${PWD}
33 34
34 35 HEADERS += \
35 36 APBUARTPLUGIN.h \
36 37 apbuartterminal.h \
37 38 apbuart_plugin_ui.h \
38 uartpollingthread.h
39 uartpollingthread.h \
40 apbuartpywrapper.h
39 41
40 42
41 43 SOURCES += \
42 44 APBUARTPLUGIN.cpp \
43 45 apbuartterminal.cpp \
44 46 apbuart_plugin_ui.cpp \
45 uartpollingthread.cpp
47 uartpollingthread.cpp \
48 apbuartpywrapper.cpp
46 49
47 50 FORMS += \
48 51 apbuart_plugin_ui.ui
49 52
50 53
51 54
52 55
53 56
54 57
55 58
56 59
57 60
58 61
59 62
60 63
61 64
62 65
63 66
64 67
65 68
66 69
67 70
68 71
69 72
70 73
71 74
72 75
@@ -1,100 +1,145
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuart_plugin_ui.h"
23 23 #include "ui_apbuart_plugin_ui.h"
24 24 #include "apbuartterminal.h"
25 #include <QComboBox>
25 26
26 27 APBUART_Plugin_ui::APBUART_Plugin_ui(QWidget *parent) :
27 28 QWidget(parent),
28 29 ui(new Ui::APBUART_Plugin_ui)
29 30 {
30 31 ui->setupUi(this);
31 32 connect(this->ui->FIFODebugChkBx,SIGNAL(stateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
32 33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->ui->UART_TERM,SLOT(apbUartTextReceived(QString)));
33 34 connect(this->ui->ConnectQpb,SIGNAL(clicked()),this,SIGNAL(connectPort()));
34 35 connect(this->ui->UART_TERM,SIGNAL(sendChar(char)),this,SIGNAL(sendChar(char)));
35 36 connect(this->ui->PortNameLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(PortNameChanged(QString)));
36 37 connect(this->ui->UartSpeedLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(UartSpeedChanged(QString)));
37 38 connect(this->ui->rescanQpb,SIGNAL(clicked()),this,SLOT(updatePortList()));
39 connect(this->ui->APBUartsUpdateQpb,SIGNAL(clicked()),this,SIGNAL(updateAPBUartsList()));
40 connect(this->ui->UARTSelector,SIGNAL(currentIndexChanged(int)),this,SIGNAL(curentAPBUartChanged(int)));
38 41 this->portListcompleter = NULL;
39 42 this->updatePortList();
40 43 }
41 44
42 45 APBUART_Plugin_ui::~APBUART_Plugin_ui()
43 46 {
44 47 delete ui;
45 48 }
46 49
50 int APBUART_Plugin_ui::curentAPBUart()
51 {
52 return this->ui->UARTSelector->currentIndex();
53 }
54
47 55 void APBUART_Plugin_ui::setEnableForLoopBack(bool enable)
48 56 {
49 57 this->ui->PortNameLineEdit->setEnabled(enable);
50 58 this->ui->ConnectQpb->setEnabled(enable);
51 59 this->ui->UartSpeedLineEdit->setEnabled(enable);
60 this->ui->APBUartsUpdateQpb->setEnabled(enable);
61 this->ui->rescanQpb->setEnabled(enable);
62 this->ui->UARTSelector->setEnabled(enable);
63 if(this->ui->FIFODebugChkBx->isChecked()==enable)
64 this->ui->FIFODebugChkBx->toggle();
65
52 66 }
53 67
54 68 void APBUART_Plugin_ui::setUartConnected(bool enable)
55 69 {
56 70 this->ui->PortNameLineEdit->setDisabled(enable);
57 71 this->ui->UartSpeedLineEdit->setDisabled(enable);
58 72 this->ui->FIFODebugChkBx->setDisabled(enable);
73 this->ui->APBUartsUpdateQpb->setDisabled(enable);
74 this->ui->rescanQpb->setDisabled(enable);
75 this->ui->UARTSelector->setDisabled(enable);
59 76 if(enable)
60 77 {
61 78 this->ui->ConnectQpb->setText("Close Port");
62 79 }
63 80 else
64 81 {
65 82 this->ui->ConnectQpb->setText("Open Port");
66 83 }
67 84 }
68 85
69 86 #include <RS232.h>
70 87
71 88 void APBUART_Plugin_ui::updatePortList()
72 89 {
73 90 if(this->portListcompleter==(QCompleter*)NULL)
74 91 {
75 92 this->portListcompleter=new QCompleter(this);
76 93 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
77 94 this->portListcompleterModel = new QStringListModel(this);
78 95 this->portListcompleter->setModel(this->portListcompleterModel);
79 96 this->ui->PortNameLineEdit->setCompleter(this->portListcompleter);
80 97 }
81 98 rs232portslist_t* portlist = rs232getportlist();
82 99 rs232portslist_t* portlistenum = portlist;
83 100 QStringList wordList;
84 101 while(portlistenum!=NULL)
85 102 {
86 103 wordList << portlistenum->name;
87 104 portlistenum = portlistenum->next;
88 105 }
89 106 rs232deleteportlist(portlist);
90 107 this->portListcompleterModel->setStringList(wordList);
91 108 }
92 109
110 void APBUART_Plugin_ui::updateAPBUartList(QList<unsigned int> addresses)
111 {
112 this->ui->UARTSelector->clear();
113 for(int i=0;i<addresses.count();i++)
114 {
115 this->ui->UARTSelector->addItem(QString("APBUart %1 @0x%2").arg(i).arg(addresses.at(i),8,16));
116 }
117 if(addresses.count()==0)
118 this->ui->UARTSelector->addItem("None");
119 }
120
121 void APBUART_Plugin_ui::setUartSpeed(int speed)
122 {
123 this->ui->UartSpeedLineEdit->setText(QString::number(speed));
124 }
125
126 void APBUART_Plugin_ui::setUartPortName(QString name)
127 {
128 this->ui->PortNameLineEdit->setText(name);
129 }
130
131 void APBUART_Plugin_ui::setAPBUartIndex(int index)
132 {
133 if((index<this->ui->UARTSelector->count()) && (index>0) )
134 this->ui->UARTSelector->setCurrentIndex(index);
135 }
93 136
94 137
95 138
96 139
97 140
98 141
99 142
100 143
144
145
@@ -1,58 +1,66
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUART_PLUGIN_UI_H
23 23 #define APBUART_PLUGIN_UI_H
24 24
25 25 #include <QWidget>
26 26 #include <QCompleter>
27 27 #include <QStringListModel>
28 28
29 29 namespace Ui {
30 30 class APBUART_Plugin_ui;
31 31 }
32 32
33 33 class APBUART_Plugin_ui : public QWidget
34 34 {
35 35 Q_OBJECT
36 36
37 37 public:
38 38 explicit APBUART_Plugin_ui(QWidget *parent = 0);
39 39 ~APBUART_Plugin_ui();
40
40 int curentAPBUart();
41 41 public slots:
42 42 void setEnableForLoopBack(bool enable);
43 43 void setUartConnected(bool enable);
44 44 void updatePortList();
45 void updateAPBUartList(QList<unsigned int> addresses);
46 void setUartSpeed(int speed);
47 void setUartPortName(QString name);
48 void setAPBUartIndex(int index);
49 private slots:
50
45 51 signals:
52 void curentAPBUartChanged(int index);
46 53 void loopbackChkBxStateChanged( int state );
47 54 void apbUartTextReceived(QString text);
48 55 void connectPort();
49 56 void sendChar(char c);
50 57 void UartSpeedChanged(QString text);
51 58 void PortNameChanged(QString text);
59 void updateAPBUartsList();
52 60 private:
53 61 Ui::APBUART_Plugin_ui *ui;
54 62 QCompleter *portListcompleter;
55 63 QStringListModel *portListcompleterModel;
56 64 };
57 65
58 66 #endif // APBUART_PLUGIN_UI_H
@@ -1,96 +1,128
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>APBUART_Plugin_ui</class>
4 4 <widget class="QWidget" name="APBUART_Plugin_ui">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 <width>400</width>
10 <height>300</height>
9 <width>608</width>
10 <height>319</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QVBoxLayout" name="verticalLayout">
17 17 <item>
18 18 <widget class="QTabWidget" name="TabWidget">
19 19 <property name="currentIndex">
20 20 <number>0</number>
21 21 </property>
22 22 <widget class="QWidget" name="Config">
23 23 <attribute name="title">
24 24 <string>Configuration</string>
25 25 </attribute>
26 26 <layout class="QGridLayout" name="gridLayout">
27 <item row="1" column="1">
28 <widget class="QLineEdit" name="PortNameLineEdit"/>
29 </item>
30 <item row="0" column="0" colspan="2">
31 <widget class="QCheckBox" name="FIFODebugChkBx">
32 <property name="text">
33 <string>Enable FIFO debug mode</string>
27 <item row="2" column="0" colspan="3">
28 <widget class="QGroupBox" name="Uartconfig">
29 <property name="title">
30 <string>APB UART Config</string>
34 31 </property>
35 <property name="checked">
36 <bool>false</bool>
37 </property>
38 </widget>
39 </item>
40 <item row="1" column="0">
32 <layout class="QGridLayout" name="gridLayout_2">
33 <item row="2" column="0">
41 34 <widget class="QLabel" name="PortNameLbl">
42 35 <property name="text">
43 36 <string>Port Name</string>
44 37 </property>
45 38 </widget>
46 39 </item>
47 40 <item row="3" column="0">
48 41 <widget class="QLabel" name="UartSpeedLbl">
49 42 <property name="text">
50 43 <string>Uart Speed</string>
51 44 </property>
52 45 </widget>
53 46 </item>
54 <item row="1" column="2">
47 <item row="0" column="0">
48 <widget class="QCheckBox" name="FIFODebugChkBx">
49 <property name="text">
50 <string>Enable FIFO debug mode</string>
51 </property>
52 <property name="checked">
53 <bool>false</bool>
54 </property>
55 </widget>
56 </item>
57 <item row="0" column="3">
58 <widget class="QPushButton" name="APBUartsUpdateQpb">
59 <property name="text">
60 <string>Update</string>
61 </property>
62 </widget>
63 </item>
64 <item row="3" column="1" colspan="3">
65 <widget class="QLineEdit" name="UartSpeedLineEdit"/>
66 </item>
67 <item row="2" column="3">
55 68 <widget class="QPushButton" name="rescanQpb">
56 69 <property name="text">
57 70 <string>Rescan ports</string>
58 71 </property>
59 72 </widget>
60 73 </item>
61 <item row="3" column="1" colspan="2">
62 <widget class="QLineEdit" name="UartSpeedLineEdit"/>
74 <item row="2" column="1" colspan="2">
75 <widget class="QLineEdit" name="PortNameLineEdit"/>
76 </item>
77 <item row="0" column="2">
78 <widget class="QComboBox" name="UARTSelector">
79 <item>
80 <property name="text">
81 <string>None</string>
82 </property>
63 83 </item>
64 <item row="4" column="1" colspan="2">
84 </widget>
85 </item>
86 <item row="0" column="1">
87 <widget class="QLabel" name="label">
88 <property name="text">
89 <string>Chose UART</string>
90 </property>
91 </widget>
92 </item>
93 <item row="4" column="2" colspan="2">
65 94 <widget class="QPushButton" name="ConnectQpb">
66 95 <property name="text">
67 96 <string>Open Port</string>
68 97 </property>
69 98 </widget>
70 99 </item>
71 100 </layout>
72 101 </widget>
102 </item>
103 </layout>
104 </widget>
73 105 <widget class="QWidget" name="Terminal">
74 106 <attribute name="title">
75 107 <string>Terminal</string>
76 108 </attribute>
77 109 <layout class="QVBoxLayout" name="verticalLayout_2">
78 110 <item>
79 111 <widget class="ApbUartTerminal" name="UART_TERM"/>
80 112 </item>
81 113 </layout>
82 114 </widget>
83 115 </widget>
84 116 </item>
85 117 </layout>
86 118 </widget>
87 119 <customwidgets>
88 120 <customwidget>
89 121 <class>ApbUartTerminal</class>
90 122 <extends>QTextEdit</extends>
91 123 <header>apbuartterminal.h</header>
92 124 </customwidget>
93 125 </customwidgets>
94 126 <resources/>
95 127 <connections/>
96 128 </ui>
@@ -1,217 +1,222
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "uartpollingthread.h"
23 23 #include <socexplorerengine.h>
24 24
25 25 UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
26 26 QThread((QObject*)parent)
27 27 {
28 28 this->plugin = parent;
29 29 uartMutex = new QMutex();
30 30 uartOpened = false;
31 31 fifoDebugConfigured = false;
32 fifoDebugEnabled = false;
32 p_fifoDebugEnabled = false;
33 33 this->moveToThread(this);
34 34 }
35 35
36 36 UARTPollingThread::~UARTPollingThread()
37 37 {
38 38 this->requestInterruption();
39 39 while(isRunning());
40 40 }
41 41
42 42 void UARTPollingThread::run()
43 43 {
44 44
45 45 char ch[4097];
46 46 int timeout =10;
47 47 SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3);
48 48 while (!this->isInterruptionRequested())
49 49 {
50 if(fifoDebugEnabled)
50 if(p_fifoDebugEnabled)
51 51 {
52 52 if(fifoDebugConfigured)
53 53 {
54 54 if(this->plugin->baseAddress()!=-1)
55 55 {
56 56 unsigned int status_reg,data;
57 57 char ch;
58 58 QString printdata="";
59 59 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
60 60 while ((status_reg&4)==0) {
61 61 plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
62 62 ch = (char)(0xff & data);
63 63 printdata+=ch;
64 64 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
65 65 }
66 66 if(printdata!="")
67 67 emit apbUartTextReceived(printdata);
68 68 }
69 69 else
70 70 {
71 71 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
72 72 }
73 73 }
74 74 else
75 75 {
76 76 configFifoDebug(true);
77 77 }
78 78 }
79 79 else
80 80 {
81 81 int read =0,avail=0;
82 82 uartMutex->lock();
83 83 if(uartOpened)
84 84 {
85 85 avail = rs232availablebytes(this->uart);
86 86 SocExplorerEngine::message(this->plugin,QString("%1 available bytes on uart").arg(read),3);
87 87 if(avail)
88 88 {
89 89 if(avail>=4096)
90 90 {
91 91 read = rs232read(this->uart,ch,4096);
92 92 timeout = 0;
93 93 }
94 94 else
95 95 {
96 96 read = rs232read(this->uart,ch,avail);
97 97 timeout = 10;
98 98 }
99 99 SocExplorerEngine::message(this->plugin,QString("Read %1 bytes on uart").arg(read),3);
100 100 ch[read]='\0';
101 101 }
102 102 }
103 103 uartMutex->unlock();
104 104 if(read>=1)
105 105 {
106 106 SocExplorerEngine::message(this->plugin,QString("Received %1 char(s) from APBUART").arg(read),3);
107 107 emit this->apbUartTextReceived(QString(ch));
108 108 }
109 109 msleep(timeout);
110 110 }
111 111 }
112 112 }
113 113
114 114 void UARTPollingThread::sendChar(char c)
115 115 {
116 if(fifoDebugEnabled)
116 if(p_fifoDebugEnabled)
117 117 {
118 118 if(this->plugin->baseAddress()!=-1)
119 119 {
120 120 unsigned int i=0x0FF & c;
121 121 plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
122 122 }
123 123 }
124 124 else
125 125 {
126 126 uartMutex->lock();
127 127 rs232write(this->uart,&c,1);
128 128 uartMutex->unlock();
129 129 }
130 130 }
131 131
132 132 bool UARTPollingThread::openUart()
133 133 {
134 134 uartMutex->lock();
135 135 if(uartOpened)
136 136 {
137 137 closeUart();
138 138 }
139 139 SocExplorerEngine::message(this->plugin,"Opening UART "+this->portName,3);
140 140 this->uart = rs232open((char*)this->portName.toStdString().c_str());
141 141 if(this->uart!=badPortValue)
142 142 {
143 143 SocExplorerEngine::message(this->plugin,QString("Configuring UART, speed =%1").arg(this->uartSpeed),3);
144 144 rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop);
145 145 uartOpened = true;
146 146 }
147 147 uartMutex->unlock();
148 148 return uartOpened;
149 149 }
150 150
151 151 void UARTPollingThread::closeUart()
152 152 {
153 153 uartMutex->lock();
154 154 rs232close(this->uart);
155 155 uartOpened = false;
156 156 uartMutex->unlock();
157 157 }
158 158
159 159 void UARTPollingThread::setPortName(QString name)
160 160 {
161 161 SocExplorerEngine::message(this->plugin,"Changing UART port Name: "+name,3);
162 162 this->portName = name;
163 163 }
164 164
165 165 void UARTPollingThread::setPortSpeedStr(QString speed)
166 166 {
167 167 SocExplorerEngine::message(this->plugin,"Changing UART speed: "+speed,3);
168 168 this->uartSpeed = speed.toInt();
169 169 }
170 170
171 171 void UARTPollingThread::setPortSpeed(int speed)
172 172 {
173 173 SocExplorerEngine::message(this->plugin,QString("Changing UART speed: %1").arg(speed),3);
174 174 this->uartSpeed = speed;
175 175 }
176 176
177 177 void UARTPollingThread::setFifoDebugEable(bool enable)
178 178 {
179 179 if(enable)
180 180 SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3);
181 181 else
182 182 SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3);
183 183 if(uartOpened && enable)
184 184 {
185 185 closeUart();
186 186 }
187 187 this->fifoDebugConfigured = false;
188 188 configFifoDebug(enable);
189 this->fifoDebugEnabled = enable;
189 this->p_fifoDebugEnabled = enable;
190 }
191
192 bool UARTPollingThread::fifoDebugEnabled()
193 {
194 return p_fifoDebugEnabled;
190 195 }
191 196
192 197 void UARTPollingThread::configFifoDebug(bool enable)
193 198 {
194 199 SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3);
195 200 if(this->plugin->baseAddress()==-1)
196 201 {
197 202 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
198 203 }
199 204 if(this->plugin->baseAddress()!=-1)
200 205 {
201 206 if(enable)
202 207 {
203 208 unsigned int ctrl_reg= 0x843;
204 209 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
205 210 this->fifoDebugConfigured = true;
206 211 }
207 212 else
208 213 {
209 214 unsigned int ctrl_reg;
210 215 /* Firts get Control reg value*/
211 216 this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
212 217 ctrl_reg = ctrl_reg & (~(1<<11));
213 218 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
214 219 this->fifoDebugConfigured = true;
215 220 }
216 221 }
217 222 }
@@ -1,66 +1,67
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef UARTPOLLINGTHREAD_H
23 23 #define UARTPOLLINGTHREAD_H
24 24
25 25 #include <QObject>
26 26 #include <QThread>
27 27 #include <socexplorerplugin.h>
28 28 #include <RS232.h>
29 29 #include <QMutex>
30 30
31 31 #define APB_UART_DATA_REG 0x0
32 32 #define APB_UART_STATUS_REG 0x4
33 33 #define APB_UART_CONTROL_REG 0x8
34 34 #define APB_UART_SCALE_REG 0xC
35 35 #define APB_UART_FIFO_DEBUG_REG 0x10
36 36
37 37 class UARTPollingThread : public QThread
38 38 {
39 39 Q_OBJECT
40 40 public:
41 41 explicit UARTPollingThread(socexplorerplugin *parent = 0);
42 42 ~UARTPollingThread();
43 43 void run();
44 44 signals:
45 45 void apbUartTextReceived(QString text);
46 46 public slots:
47 47 void sendChar(char c);
48 48 bool openUart();
49 49 void closeUart();
50 50 void setPortName(QString name);
51 51 void setPortSpeedStr(QString speed);
52 52 void setPortSpeed(int speed);
53 53 void setFifoDebugEable(bool enable);
54 bool fifoDebugEnabled();
54 55 private:
55 56 void configFifoDebug(bool enable);
56 bool fifoDebugEnabled;
57 bool p_fifoDebugEnabled;
57 58 bool fifoDebugConfigured;
58 59 QString portName;
59 60 int uartSpeed;
60 61 bool uartOpened;
61 62 socexplorerplugin* plugin;
62 63 rs232port_t uart;
63 64 QMutex* uartMutex;
64 65 };
65 66
66 67 #endif // UARTPOLLINGTHREAD_H
@@ -1,492 +1,490
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include <socexplorerengine.h>
23 23 #include "ahbuartplugin.h"
24 24 #include <unistd.h>
25 25 #include <errno.h>
26 26 #include <QApplication>
27 27 #include <QProgressBar>
28 28 #include <stdio.h>
29 29 #include <QThread>
30 30 #include "ahbuartpywrapper.h"
31 31 #include <QCompleter>
32 32 #include <QStringList>
33 33 #include <QLineEdit>
34 34 #include <socexplorerproxy.h>
35 35
36 36 ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false)
37 37 {
38 38 this->port =(rs232port_t)NULL;
39 39 this->portMutex = new QMutex(QMutex::Recursive);
40 40 this->UI = new ahbUartPluginUI();
41 41 this->setWidget((QWidget*)this->UI);
42 42 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
43 43 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
44 44 this->pyObject = new ahbuartPywrapper(this);
45 45 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
46 46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
47 47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
48 48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
49 49 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
50 50 QObject::connect(this,SIGNAL(addReadBytes(int)),this->UI,SLOT(addReadBytes(int)));
51 51 QObject::connect(this,SIGNAL(addWritenBytes(int)),this->UI,SLOT(addWritenBytes(int)));
52 52 this->portListcompleter = NULL;
53 53 this->scanDone = false;
54 54 updatePortList();
55 55 }
56 56
57 57
58 58 ahbuartplugin::~ahbuartplugin()
59 59 {
60 60 if(this->port!=(rs232port_t)NULL)
61 61 {
62 62 rs232close(this->port);
63 63 this->port = (rs232port_t)NULL;
64 64 }
65 65 this->UI->close();
66 66 this->UI->~ahbUartPluginUI();
67 67 }
68 68
69 69
70 70 void ahbuartplugin::closeMe()
71 71 {
72 72 if(this->port!=(rs232port_t)NULL)
73 73 {
74 74 rs232close(this->port);
75 75 this->port = (rs232port_t)NULL;
76 76 }
77 77 emit this->closePlugin(this);
78 78 }
79 79
80 80 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
81 81 {
82 82 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
83 83 this->closeAction = this->menu->addAction(tr("Close plugin"));
84 84 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
85 85 return 1;
86 86 }
87 87
88 88
89
90
91 89 bool ahbuartplugin::checkConnection()
92 90 {
93 91 QTime timeout;
94 92 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
95 93 char test2[1024];
96 94 int writen =0;
97 95 int read = 0;
98 96 timeout.start();
99 97 SocExplorerEngine::message(this,"Check connection",2);
100 98 QMutexLocker lock(portMutex);
101 99 while(writen!=5)
102 100 {
103 101 writen+=rs232write(this->port,test+writen,5-writen);
104 102 if(timeout.elapsed()>1000)
105 103 {
106 104 SocExplorerEngine::message(this,"Can't write any data on serial port",2);
107 105 return false;
108 106 }
109 107 }
110 108 #ifdef WIN32
111 109 usleep(1000);
112 110 #endif
113 111 timeout.restart();
114 112 int avail = 0;
115 113 do
116 114 {
117 115 avail = rs232availablebytes(this->port);
118 116 if(timeout.elapsed()>1000)
119 117 {
120 118 if(avail)
121 119 rs232read(this->port,test2,avail);
122 120 SocExplorerEngine::message(this,"Connection Error",2);
123 121 return false;
124 122 }
125 123 }while(avail<4);
126 124 read = rs232read(this->port,test2,avail);
127 125 if(read>0)
128 126 {
129 127 SocExplorerEngine::message(this,"Connection Ok",2);
130 128 return true;
131 129 }
132 130 else
133 131 {
134 132 SocExplorerEngine::message(this,"Connection Error",2);
135 133 return false;
136 134 }
137 135 }
138 136
139 137 void ahbuartplugin::connectPort(QString PortName, int baudrate)
140 138 {
141 139 QTime timeout;
142 140 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
143 141 timeout.start();
144 142 QMutexLocker lock(portMutex);
145 143 if(this->port==(rs232port_t)NULL)
146 144 {
147 145 SocExplorerEngine::message(this,"Open port "+PortName,2);
148 146 this->port=rs232open((char*)PortName.toStdString().c_str());
149 147 }
150 148 if(this->port!=badPortValue)
151 149 {
152 150 SocExplorerEngine::message(this,"Port opened "+PortName,2);
153 151 SocExplorerEngine::message(this,"Configure port "+PortName,2);
154 152 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
155 153 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
156 154 char test2[1024];
157 155 SAFEWRITE(test,1,timeout,2000,return);
158 156 SAFEWRITE((test+1),1,timeout,2000,return);
159 157 rs232read(this->port,test2,512);
160 158 int read = 0;
161 159 for(int i=0;i<10;i++)
162 160 {
163 161 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
164 162 SAFEWRITE(test+2,5,timeout,2000,return);
165 163 SocExplorerEngine::message(this,"Read Result",2);
166 164 read=rs232read(this->port,test2+read,16);
167 165 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
168 166 if(read>0)
169 167 {
170 168 SocExplorerEngine::message(this,"Flush port ",2);
171 169 while(rs232read(this->port,test2,1)>0);
172 170 this->Connected = true;
173 171 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
174 172 emit this->activate(true);
175 173 if(this->scanDone==false)
176 174 {
177 175 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
178 176 this->scanDone=true;
179 177 }
180 178 break;
181 179 }
182 180 }
183 181 }
184 182 else
185 183 {
186 184 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
187 185 this->port = (rs232port_t)NULL;
188 186 this->Connected = false;
189 187 emit this->activateSig(false);
190 188 return;
191 189 }
192 190 if(this->Connected == false)
193 191 {
194 192 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
195 193 rs232close(this->port);
196 194 this->port = (rs232port_t)NULL;
197 195 emit this->activateSig(false);
198 196 }
199 197
200 198 }
201 199
202 200 bool ahbuartplugin::open(QString PortName,int baudrate)
203 201 {
204 202 if(this->port!=(rs232port_t)NULL)
205 203 this->close();
206 204 this->UI->setconfig(PortName,baudrate);
207 205 this->connectPort(PortName,baudrate);
208 206 return (this->port!=(rs232port_t)NULL);
209 207 }
210 208
211 209 void ahbuartplugin::close()
212 210 {
213 211 if(this->port!=(rs232port_t)NULL)
214 212 {
215 213 rs232close(this->port);
216 214 this->port = (rs232port_t)NULL;
217 215 this->Connected = false;
218 216 emit this->activateSig(false);
219 217 }
220 218 }
221 219
222 220 void ahbuartplugin::togglePort(QString PortName,int baudrate)
223 221 {
224 222 if(this->port!=(rs232port_t)NULL)
225 223 {
226 224 this->close();
227 225 }
228 226 else
229 227 {
230 228 this->connectPort(PortName,baudrate);
231 229 }
232 230 }
233 231
234 232
235 233 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
236 234 {
237 235 QTime timeout;
238 236 timeout.start();
239 237 unsigned int read=0;
240 238 unsigned int cnt=count;
241 239 unsigned int nextUpdateTrig=0,updateStep=512;
242 240 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
243 241 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
244 242 {
245 243 QMutexLocker lock(portMutex);
246 244 if(!this->checkConnection())
247 245 {
248 246 this->Connected = false;
249 247 emit this->activateSig(false);
250 248 this->portMutex->unlock();
251 249 return 0;
252 250 }
253 251 QProgressBar* progress=NULL;
254 252 if(cnt>128)
255 253 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
256 254 char CMD[5];
257 255 char* result = (char*)malloc(count*4);
258 256 while(count>32)
259 257 {
260 258 CMD[0] = 0x80 | (32-1);
261 259 CMD[1] = (char)((address>>24)&0xFF);
262 260 CMD[2] = (char)((address>>16)&0xFF);
263 261 CMD[3] = (char)((address>>8)&0xFF);
264 262 CMD[4] = (char)((address)&0xFF);
265 263 SAFEWRITE(CMD,5,timeout,1000,return 0);
266 264 timeout.restart();
267 265 int avail=0;
268 266 do{
269 267 avail=rs232availablebytes(this->port);
270 268 if(timeout.elapsed()>1000)
271 269 {
272 270 rs232close(this->port);
273 271 this->port = (rs232port_t)NULL;
274 272 this->Connected = false;
275 273 emit this->activateSig(false);
276 274 return 0;
277 275 }
278 276 }while(avail<(32*4));
279 277 rs232read(this->port,result+((cnt-count)*4),32*4);
280 278 count-=32;
281 279 address+=32*4;
282 280 if(cnt>128)
283 281 {
284 282
285 283 if((cnt-count)>=nextUpdateTrig)
286 284 {
287 285 progress->setValue(cnt-count);
288 286 qApp->processEvents();
289 287 nextUpdateTrig+=updateStep;
290 288 }
291 289 }
292 290 }
293 291 if(count>0)
294 292 {
295 293 CMD[0] = 0x80 | (count-1);
296 294 CMD[1] = (char)((address>>24)&0xFF);
297 295 CMD[2] = (char)((address>>16)&0xFF);
298 296 CMD[3] = (char)((address>>8)&0xFF);
299 297 CMD[4] = (char)((address)&0xFF);
300 298 SAFEWRITE(CMD,5,timeout,1000,return 0);
301 299 timeout.restart();
302 300 int avail=0;
303 301 do{
304 302 avail=rs232availablebytes(this->port);
305 303 if(timeout.elapsed()>1000)
306 304 {
307 305 rs232close(this->port);
308 306 this->port = (rs232port_t)NULL;
309 307 this->Connected = false;
310 308 emit this->activateSig(false);
311 309 return 0;
312 310 }
313 311 }while(avail<(count*4));
314 312 rs232read(this->port,result+((cnt-count)*4),count*4);
315 313 }
316 314 if(cnt>128)
317 315 {
318 316 progress->setValue(cnt-count);
319 317 qApp->processEvents();
320 318 }
321 319 for(int i=0;(unsigned int)i<cnt;i++)
322 320 {
323 321 for(int j =0;j<4;j++)
324 322 {
325 323 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
326 324 }
327 325 read = cnt*4;
328 326
329 327 }
330 328 if(cnt>128)
331 329 SocExplorerEngine::deleteProgressBar(progress);
332 330 free(result);
333 331 }
334 332 emit this->addReadBytes(read);
335 333 return read/4;
336 334 }
337 335
338 336 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
339 337 {
340 338 QTime timeout;
341 339 timeout.start();
342 340 unsigned int writen=0;
343 341 unsigned int nextUpdateTrig=0,updateStep=512;
344 342 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
345 343 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
346 344 {
347 345 QMutexLocker lock(portMutex);
348 346 if(!this->checkConnection())
349 347 {
350 348 emit this->activateSig(false);
351 349 this->Connected = false;
352 350 this->portMutex->unlock();
353 351 return 0;
354 352 }
355 353 QProgressBar* progress = NULL;
356 354 if(count>128)
357 355 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
358 356 int offset = 0;
359 357 char* CMD= (char*)malloc((32*4)+5);
358 writen=0;
360 359 while(count>32)
361 360 {
362 writen=0;
363 361 CMD[0] = 0xC0 | (32-1);
364 362 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
365 363 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
366 364 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
367 365 CMD[4] = (char)(((unsigned int)address)&0xFF);
368 366 for(int i=0;i<32;i++)
369 367 {
370 368 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
371 369 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
372 370 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
373 371 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
374 372 }
375 373 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
376 374 writen+=32;
377 375 count-=32;
378 376 offset+=32;
379 377 address+=32*4;
380 378 if(offset>=nextUpdateTrig && progress!=NULL)
381 379 {
382 380 progress->setValue(offset);
383 381 qApp->processEvents();
384 382 nextUpdateTrig +=updateStep;
385 383 }
386 384
387 385 }
388 386 if(count>0)
389 387 {
390 388 CMD[0] = 0xC0 | (count-1);
391 389 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
392 390 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
393 391 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
394 392 CMD[4] = (char)(((unsigned int)address)&0xFF);
395 393 for(int i=0;(unsigned int) i<(count);i++)
396 394 {
397 395 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
398 396 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
399 397 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
400 398 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
401 399 }
402 400 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
403 401 writen+=count;
404 402 }
405 403 if(progress!=NULL)
406 404 {
407 405 progress->setValue(writen);
408 406 qApp->processEvents();
409 407 SocExplorerEngine::deleteProgressBar(progress);
410 408 }
411 409 free(CMD);
412 emit this->addWritenBytes(writen);
410 emit this->addWritenBytes(writen*4);
413 411 return writen;
414 412 }
415 413 return 0;
416 414 }
417 415
418 416
419 417
420 418
421 419 void ahbuartplugin::updatePortList()
422 420 {
423 421 if(this->portListcompleter==(QCompleter*)NULL)
424 422 {
425 423 this->portListcompleter=new QCompleter(this);
426 424 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
427 425 this->portListcompleterModel = new QStringListModel(this);
428 426 this->portListcompleter->setModel(this->portListcompleterModel);
429 427 this->UI->setCompleter(this->portListcompleter);
430 428 }
431 429 rs232portslist_t* portlist = rs232getportlist();
432 430 rs232portslist_t* portlistenum = portlist;
433 431 QStringList wordList;
434 432 while(portlistenum!=NULL)
435 433 {
436 434 wordList << portlistenum->name;
437 435 portlistenum = portlistenum->next;
438 436 }
439 437 rs232deleteportlist(portlist);
440 438 this->portListcompleterModel->setStringList(wordList);
441 439 }
442 440
443 441 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
444 442 {
445 443 unsigned int data[(count/4)+1];
446 444 QVariantList result;
447 445 this->Read(data,(count/4)+1,address);
448 446 for(unsigned int i = 0;i<count/4;i++)
449 447 {
450 448 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
451 449 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
452 450 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
453 451 result.append(QVariant((int)(0x0FF&(data[i]))));
454 452 }
455 453
456 454 for(int i=0;i<(count%4);i++)
457 455 {
458 456 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
459 457 }
460 458
461 459 return result;
462 460 }
463 461
464 462 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
465 463 {
466 464 unsigned int data[dataList.count()/4];
467 465 for(int i = 0;i<(dataList.count()/4);i++)
468 466 {
469 467 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
470 468 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt()));
471 469 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt()));
472 470 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
473 471 }
474 472 this->Write(data,dataList.count()/4,address);
475 473 }
476 474
477 475
478 476
479 477
480 478
481 479
482 480
483 481
484 482
485 483
486 484
487 485
488 486
489 487
490 488
491 489
492 490
@@ -1,23 +1,25
1 1 #ifndef AHBUARTPYWRAPPER_H
2 2 #define AHBUARTPYWRAPPER_H
3 #include <socexplorerplugin.h>
3 4 #include <genericPySysdriver.h>
4 5 #include <QString>
6 #include <qobject.h>
5 7
6 8 class ahbuartPywrapper : public genericPySysdriver
7 9 {
8 10 Q_OBJECT
9 11 public:
10 12 explicit ahbuartPywrapper(socexplorerplugin *parent = 0);
11 13
12 14 signals:
13 15 bool open(QString PortName,int baudrate);
14 16 void close();
15 17 QVariantList ReadBytes(unsigned int address,unsigned int count);
16 18 void WriteBytes(unsigned int address,QList<QVariant> dataList);
17 19 public slots:
18 20 // bool dumpMemory(unsigned int address,unsigned int count,QString file);
19 21 // bool memSet(unsigned int address,int value, unsigned int count);
20 22 // bool loadbin(unsigned int address,QString file);
21 23 };
22 24
23 25 #endif // AHBUARTPYWRAPPER_H
General Comments 0
You need to be logged in to leave comments. Login now