##// END OF EJS Templates
Added ui file for APB_UART_PLUGIN.
Added ui file for APB_UART_PLUGIN.

File last commit:

r25:8fdbbdd7a3a4 default
r26:5e1f92d2bac2 default
Show More
gr_esb_bridge.cpp
202 lines | 4.7 KiB | text/x-c | CppLexer
#include "gr_esb_bridge.h"
#include "gr_esb_ui.h"
#include <unistd.h>
#include "spw.h"
#include <socexplorerengine.h>
GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
abstractSpwBridge(parent)
{
this->p_GUI = new GR_ESB_ui();
this->manager = new GR_ESB_Manager(parent,this);
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
this->manager->virtualLinkIndex = 0;
this->manager->start();
}
GR_ESB_bridge::~GR_ESB_bridge()
{
}
void GR_ESB_bridge::toggleBridgeConnection()
{
if(this->plugin->isConnected())
{
this->disconnectBridge();
}
else
{
this->connectBridge();
}
}
bool GR_ESB_bridge::connectBridge()
{
if(this->manager->connectBridge())
{
((GR_ESB_ui*)this->p_GUI)->lock(true);
emit setConnected(true);
return true;
}
return false;
}
bool GR_ESB_bridge::disconnectBridge()
{
if(this->manager->disconnectBridge())
{
((GR_ESB_ui*)this->p_GUI)->lock(false);
emit setConnected(false);
return true;
}
return false;
}
void GR_ESB_bridge::setIP(QString ip)
{
this->manager->IP = ip;
}
void GR_ESB_bridge::setVirtualLink(QString vlink)
{
vlink = vlink.section("Virtual link",0,0);
bool success;
int vlinkTmp = vlink.toInt(&success);
if(success)
{
setVirtualLink(vlinkTmp);
}
}
void GR_ESB_bridge::setVirtualLink(qint32 vlink)
{
if(vlink<6 && vlink>=0)
{
this->manager->virtualLinkIndex = vlink;
}
}
unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
{
}
unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
{
}
int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
{
return this->manager->sendPacket(packet,size);
}
GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
:QThread((QObject*)parent)
{
this->Read_soc = new QTcpSocket(this);
this->Write_soc = new QTcpSocket(this);
this->RMAPtimeout = 2000;
this->handleMutex = new QMutex(QMutex::NonRecursive);
this->RMAP_AnswersSem = new QSemaphore(0);
this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
this->plugin = plugin;
connected = false;
this->moveToThread(this);
}
GR_ESB_Manager::~GR_ESB_Manager()
{
}
void GR_ESB_Manager::run()
{
SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
while (!this->isInterruptionRequested())
{
if(this->connected)
{
handleMutex->lock();
SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
}
else
{
//do some sanity checks!
usleep(RMAPtimeout/2);
}
usleep(1000);
}
SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
}
bool GR_ESB_Manager::connectBridge()
{
int timeout=60;
if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
{
this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
this->Read_soc->waitForConnected(30000);
}
if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
{
this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
this->Write_soc->waitForConnected(30000);
}
while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
{
usleep(100000);
if(timeout--==0)return false;
}
return true;
}
bool GR_ESB_Manager::disconnectBridge()
{
int timeout=60;
if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
{
this->Read_soc->disconnectFromHost();
this->Read_soc->waitForDisconnected(30000);
}
if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
{
this->Write_soc->disconnectFromHost();
this->Write_soc->waitForDisconnected(30000);
}
while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
{
usleep(100000);
if(timeout--==0)return false;
}
return true;
}
int GR_ESB_Manager::getRMAPtransactionID()
{
}
int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
{
}
bool GR_ESB_Manager::sendPacket(char *packet, int size)
{
}
void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
{
}