# HG changeset patch # User Jeandet Alexis # Date 2014-03-23 17:49:49 # Node ID 8fdbbdd7a3a47d4563daa67ebfa756aeca9e8914 # Parent f6b7bed80207ab7397be015f015ef51c42b05499 Some work on GRESB driver for spwplugin. diff --git a/spwplugin/GR-ESB/gr_esb_bridge.cpp b/spwplugin/GR-ESB/gr_esb_bridge.cpp --- a/spwplugin/GR-ESB/gr_esb_bridge.cpp +++ b/spwplugin/GR-ESB/gr_esb_bridge.cpp @@ -1,23 +1,145 @@ #include "gr_esb_bridge.h" #include "gr_esb_ui.h" #include +#include "spw.h" +#include GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) : abstractSpwBridge(parent) { this->p_GUI = new GR_ESB_ui(); - this->Read_soc = new QTcpSocket(this); - this->Write_soc = new QTcpSocket(this); + 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(setPort(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) { @@ -35,60 +157,46 @@ bool GR_ESB_bridge::connectBridge() if(timeout--==0)return false; } return true; + } -bool GR_ESB_bridge::disconnectBridge() +bool GR_ESB_Manager::disconnectBridge() { int timeout=60; if(this->Read_soc->state()!=QTcpSocket::UnconnectedState) { this->Read_soc->disconnectFromHost(); this->Read_soc->waitForDisconnected(30000); - while(this->Read_soc->state()!=QTcpSocket::UnconnectedState) - { - usleep(100000); - if(timeout--==0)return false; - } + } + 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; } -void GR_ESB_bridge::setIP(QString ip) +int GR_ESB_Manager::getRMAPtransactionID() { - this->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) - { - virtualLinkIndex = vlink; - } -} - - -unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address) +int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer) { } -unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address) +bool GR_ESB_Manager::sendPacket(char *packet, int size) { } -int GR_ESB_bridge::pushRMAPPacket(char *packet, int size) +void GR_ESB_Manager::pushRmapPacket(char *packet, int len) { } diff --git a/spwplugin/GR-ESB/gr_esb_bridge.h b/spwplugin/GR-ESB/gr_esb_bridge.h --- a/spwplugin/GR-ESB/gr_esb_bridge.h +++ b/spwplugin/GR-ESB/gr_esb_bridge.h @@ -2,6 +2,9 @@ #define GR_ESB_BRIDGE_H #include "abstractspwbridge.h" #include +#include +#include +#include struct gresb_Conf_str { @@ -9,6 +12,7 @@ struct gresb_Conf_str qint32 Write_port; }; + const struct gresb_Conf_str gresb_Conf[]= { {3000,3001}, //Virtual link 0 @@ -19,6 +23,41 @@ const struct gresb_Conf_str gresb_Conf[] {3010,3011} //Virtual link 5 }; + +class GR_ESB_Manager: public QThread +{ + Q_OBJECT +public: + explicit GR_ESB_Manager(socexplorerplugin *plugin = 0,QObject* parent=0); + ~GR_ESB_Manager(); + void run(); + bool connectBridge(); + bool disconnectBridge(); + int getRMAPtransactionID(); + int getRMAPanswer(int transactionID,char** buffer); + bool sendPacket(char* packet,int size); + +signals: + void emitPacket(char* packet,int size); +private: + QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx; + QSemaphore* RMAP_AnswersSem; + void pushRmapPacket(char* packet,int len); + socexplorerplugin* plugin; + bool connected; + char* SPWPacketBuff; + QList RMAP_Answers; + QList RMAP_pending_transaction_IDs; + +public: + QTcpSocket* Read_soc; + QTcpSocket* Write_soc; + QString IP; + int virtualLinkIndex; + int RMAPtimeout; +}; + + class GR_ESB_bridge : public abstractSpwBridge { Q_OBJECT @@ -29,6 +68,7 @@ signals: public slots: + void toggleBridgeConnection(); bool connectBridge(); bool disconnectBridge(); void setIP(QString ip); @@ -40,10 +80,8 @@ public slots: void packetReceived(); private: - QTcpSocket* Read_soc; - QTcpSocket* Write_soc; - QString IP; - int virtualLinkIndex; + + GR_ESB_Manager* manager; }; diff --git a/spwplugin/GR-ESB/gr_esb_ui.cpp b/spwplugin/GR-ESB/gr_esb_ui.cpp --- a/spwplugin/GR-ESB/gr_esb_ui.cpp +++ b/spwplugin/GR-ESB/gr_esb_ui.cpp @@ -9,6 +9,7 @@ GR_ESB_ui::GR_ESB_ui(QWidget *parent) : ui->setupUi(this); connect(this->ui->GRESB_IP_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changeIp(QString))); connect(this->ui->GRESB_Vlink_CmBx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(vlinkchanged(QString))); + connect(this->ui->connectQpb,SIGNAL(clicked()),this,SIGNAL(connectClicked())); } void GR_ESB_ui::changeIp(QString ip) @@ -17,3 +18,14 @@ void GR_ESB_ui::changeIp(QString ip) emit this->ipchanged(ip); } +void GR_ESB_ui::lock(bool lock) +{ + this->ui->GRESB_IP_lineEdit->setDisabled(lock); + this->ui->GRESB_LinkNum_CmBx->setDisabled(lock); + this->ui->GRESB_Vlink_CmBx->setDisabled(lock); + if(lock) + this->ui->connectQpb->setText("Disconnect"); + else + this->ui->connectQpb->setText("Connect"); +} + diff --git a/spwplugin/GR-ESB/gr_esb_ui.h b/spwplugin/GR-ESB/gr_esb_ui.h --- a/spwplugin/GR-ESB/gr_esb_ui.h +++ b/spwplugin/GR-ESB/gr_esb_ui.h @@ -16,10 +16,11 @@ public: public slots: void changeIp(QString ip); - + void lock(bool lock); signals: void ipchanged(QString ip); void vlinkchanged(QString vlink); + void connectClicked(); private: Ui::GR_ESB_ui *ui; }; diff --git a/spwplugin/GR-ESB/gr_esb_ui.ui b/spwplugin/GR-ESB/gr_esb_ui.ui --- a/spwplugin/GR-ESB/gr_esb_ui.ui +++ b/spwplugin/GR-ESB/gr_esb_ui.ui @@ -6,8 +6,8 @@ 0 0 - 489 - 295 + 968 + 392 @@ -107,6 +107,13 @@ + + + + Connect + + + diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui @@ -6,8 +6,8 @@ 0 0 - 671 - 409 + 726 + 535 @@ -65,16 +65,45 @@ - + - Connected clients + Server Statistics - - false - - - - + + + + + Connected clients + + + false + + + + + + + + + + + + + + + Sended Packets + + + + + + + Received Packets + + + + + diff --git a/spwplugin/StarDundee/stardundeespw_usb.h b/spwplugin/StarDundee/stardundeespw_usb.h --- a/spwplugin/StarDundee/stardundeespw_usb.h +++ b/spwplugin/StarDundee/stardundeespw_usb.h @@ -36,19 +36,7 @@ #include #include "stardundeegui.h" -class RMAP_Answer -{ - public: - RMAP_Answer(int ID,char* data,int len) - { - transactionID = ID; - this->data = data; - this->len = len; - } - int transactionID; - char* data; - int len; -}; + class stardundeeSPW_USB_Manager: public QThread { diff --git a/spwplugin/abstractspwbridge.h b/spwplugin/abstractspwbridge.h --- a/spwplugin/abstractspwbridge.h +++ b/spwplugin/abstractspwbridge.h @@ -27,6 +27,20 @@ #define RMAP_MAX_XFER_SIZE 4000 //slightly less than 16kBytes #include +class RMAP_Answer +{ + public: + RMAP_Answer(int ID,char* data,int len) + { + transactionID = ID; + this->data = data; + this->len = len; + } + int transactionID; + char* data; + int len; +}; + class abstractSpwBridge : public QObject { Q_OBJECT diff --git a/spwplugin/spwplugin.cpp b/spwplugin/spwplugin.cpp --- a/spwplugin/spwplugin.cpp +++ b/spwplugin/spwplugin.cpp @@ -26,6 +26,7 @@ #include #include "spwpywrapper.h" + spwplugin::spwplugin(QWidget *parent):socexplorerplugin(parent,false) { Q_UNUSED(parent) diff --git a/spwplugin/spwplugin.h b/spwplugin/spwplugin.h --- a/spwplugin/spwplugin.h +++ b/spwplugin/spwplugin.h @@ -35,6 +35,8 @@ #include "SpwTcpPacketServer/spwtcppacketserver.h" +// TODO switch to a class factory approach with self registration + class spwplugin : public socexplorerplugin { Q_OBJECT @@ -70,6 +72,7 @@ private: QGroupBox* mainGroupBox; QComboBox* bridgeSelector; QGridLayout* mainLayout; + }; #endif // spwplugin_H