APBUARTPLUGIN.cpp
176 lines
| 5.4 KiB
| text/x-c
|
CppLexer
/ APBUARTPLUGIN / APBUARTPLUGIN.cpp
Jeandet Alexis
|
r4 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the SocExplorer Software | ||||
Jeandet Alexis
|
r11 | -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS | ||
r0 | -- | |||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
Jeandet Alexis
|
r4 | -- the Free Software Foundation; either version 2 of the License, or | ||
r0 | -- (at your option) any later version. | |||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
#include "APBUARTPLUGIN.h" | ||||
#include <socexplorerengine.h> | ||||
r34 | ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent,false) | |||
r0 | { | |||
r28 | this->setBaseAddress(-1); | |||
r34 | this->p_curentAPBUart = 0; | |||
r26 | this->UI = new APBUART_Plugin_ui(); | |||
r0 | this->setWidget((QWidget*)this->UI); | |||
r28 | this->uartConnected = false; | |||
this->UartThread = new UARTPollingThread(this); | ||||
r52 | // this->pyObject = new APBUartPyWrapper(this); | |||
r34 | connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(fifoDebugChangeState(int))); | |||
r28 | connect(this->UartThread,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString))); | |||
connect(this->UI,SIGNAL(connectPort()),this,SLOT(toggleUartState())); | ||||
connect(this->UI,SIGNAL(sendChar(char)),this->UartThread,SLOT(sendChar(char))); | ||||
connect(this->UI,SIGNAL(PortNameChanged(QString)),this->UartThread,SLOT(setPortName(QString))); | ||||
connect(this->UI,SIGNAL(UartSpeedChanged(QString)),this->UartThread,SLOT(setPortSpeedStr(QString))); | ||||
r34 | connect(this->UI,SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList())); | |||
connect(this->UI,SIGNAL(curentAPBUartChanged(int)),this,SLOT(setCurentAPBUart(int))); | ||||
r52 | // connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(openUart()),this,SLOT(openUart())); | |||
// connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(closeUart()),this,SLOT(closeUart())); | ||||
// connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setFifoDebugEnabled(bool)),this,SLOT(setFifoDebugEnabled(bool))); | ||||
// connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortNane(QString)),this,SLOT(setUARTPortNane(QString))); | ||||
// connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortSpeed(int)),this,SLOT(setUARTPortSpeed(int))); | ||||
// connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList())); | ||||
r28 | this->UartThread->start(); | |||
r0 | } | |||
ApbUartPlugin::~ApbUartPlugin() | ||||
{ | ||||
} | ||||
r34 | int ApbUartPlugin::curentAPBUart() | |||
{ | ||||
return p_curentAPBUart; | ||||
} | ||||
r0 | void ApbUartPlugin::closeMe() | |||
{ | ||||
emit this->closePlugin(this); | ||||
} | ||||
r28 | void ApbUartPlugin::toggleUartState() | |||
r0 | { | |||
r28 | if(!uartConnected) | |||
r0 | { | |||
r34 | this->openUart(); | |||
r0 | } | |||
r28 | else | |||
{ | ||||
r34 | this->closeUart(); | |||
r28 | } | |||
r34 | } | |||
void ApbUartPlugin::activate(bool flag) | ||||
{ | ||||
socexplorerplugin::activate(flag); | ||||
this->updateAPBUartsList(); | ||||
} | ||||
void ApbUartPlugin::updateAPBUartsList() | ||||
{ | ||||
QList<unsigned int> addresses; | ||||
int count = SocExplorerEngine::self()->getEnumDeviceCount(this,this->VID(),this->PID()); | ||||
for(int i=0;i<count;i++) | ||||
{ | ||||
addresses.append(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),i)); | ||||
} | ||||
this->UI->updateAPBUartList(addresses); | ||||
} | ||||
void ApbUartPlugin::setCurentAPBUart(int index) | ||||
{ | ||||
this->p_curentAPBUart = index; | ||||
this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),index)); | ||||
} | ||||
void ApbUartPlugin::openUart() | ||||
{ | ||||
if(this->UartThread->fifoDebugEnabled()) | ||||
setFifoDebugEnabled(false); | ||||
if(!uartConnected) | ||||
uartConnected = this->UartThread->openUart(); | ||||
r28 | this->UI->setUartConnected(uartConnected); | |||
r0 | } | |||
r34 | void ApbUartPlugin::closeUart() | |||
{ | ||||
if(uartConnected) | ||||
this->UartThread->closeUart(); | ||||
this->uartConnected = false; | ||||
this->UI->setUartConnected(uartConnected); | ||||
} | ||||
void ApbUartPlugin::setFifoDebugEnabled(bool enable) | ||||
{ | ||||
if(uartConnected) | ||||
closeUart(); | ||||
this->UI->setEnableForLoopBack(!enable); | ||||
this->UartThread->setFifoDebugEable(enable); | ||||
} | ||||
void ApbUartPlugin::setAPBUartIndex(int index) | ||||
{ | ||||
this->UI->setAPBUartIndex(index); | ||||
} | ||||
void ApbUartPlugin::setUARTPortNane(QString name) | ||||
{ | ||||
this->UI->setUartPortName(name); | ||||
} | ||||
void ApbUartPlugin::setUARTPortSpeed(int speed) | ||||
{ | ||||
this->UI->setUartSpeed(speed); | ||||
} | ||||
void ApbUartPlugin::fifoDebugChangeState(int state) | ||||
r0 | { | |||
if(state==Qt::Checked) | ||||
{ | ||||
r34 | this->setFifoDebugEnabled(true); | |||
r0 | } | |||
else | ||||
{ | ||||
r34 | this->setFifoDebugEnabled(false); | |||
r0 | } | |||
} | ||||
unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address) | ||||
{ | ||||
if(parent!=NULL) | ||||
return parent->Read(Value,count,address); | ||||
return 0; | ||||
} | ||||
unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address) | ||||
{ | ||||
if(parent!=NULL) | ||||
return parent->Write(Value,count,address); | ||||
return 0; | ||||
} | ||||