##// END OF EJS Templates
Improved AHB UART Plugin, now check how many bytes are available on uart...
Improved AHB UART Plugin, now check how many bytes are available on uart before reading.

File last commit:

r29:8466dbc97576 default
r33:de3df68ac881 default
Show More
gr_esb_bridge.cpp
225 lines | 5.9 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------
-- This file is a part of the SocExplorer Software
-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
--
-- 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
-- the Free Software Foundation; either version 3 of the License, or
-- (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 "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()
{
this->manager->requestInterruption();
while(this->manager->isRunning());
}
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)
{
}