##// END OF EJS Templates
Functions added to the plugin to get the number of CCSDS packets...
Functions added to the plugin to get the number of CCSDS packets transmitted (linked to the lfrcontrol plugin counter of TC transmitted, it is possible to flush the TC transmission before changing the spacewire link in use)

File last commit:

r40:cda6b4e8adc1 Patch 3 from Paul on spwplugin default
r40:cda6b4e8adc1 Patch 3 from Paul on spwplugin default
Show More
spwtcppacketserver.cpp
231 lines | 6.9 KiB | text/x-c | CppLexer
Added stop function to dsu3plugin...
r14 /*------------------------------------------------------------------------------
-- 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
----------------------------------------------------------------------------*/
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 #include "spwtcppacketserver.h"
#include "ui_spwtcppacketserver.h"
Jeandet Alexis
Sync
r20 #include <QNetworkInterface>
#include <QByteArray>
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12
SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) :
QWidget(parent),
ui(new Ui::SpwTcpPacketServer)
{
ui->setupUi(this);
Jeandet Alexis
Sync
r18 this->p_bridge = NULL;
this->p_server = new QTcpServer();
paul
Functions added to the plugin to get the number of CCSDS packets...
r40 this->incomingTCParser = new IncomingTCParser();
Jeandet Alexis
Sync
r18 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
Jeandet Alexis
Sync
r20 updateHostIP();
this->ui->PortLineEdit->setText("2200");
Sync
r21 connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
paul
Functions added to the Python API:...
r35 resetStatististics();
paul
Functions added to the plugin to get the number of CCSDS packets...
r40
connect( this->incomingTCParser, SIGNAL(sendPacketUsingSpaceWire(QByteArray)),
this, SLOT(sendTCUsingSpaceWire(QByteArray)));
Jeandet Alexis
STAR-Dundee USB Brick driver ready for testing.
r12 }
SpwTcpPacketServer::~SpwTcpPacketServer()
{
delete ui;
}
Jeandet Alexis
Sync
r18
void SpwTcpPacketServer::setBridge(abstractSpwBridge *bridge)
{
if(this->p_bridge!=NULL)
{
disconnect(this,SLOT(pushPacket(char*,int)));
}
this->p_bridge = bridge;
connect(bridge,SIGNAL(pushPacketOverTCP(char*,int)),SLOT(pushPacket(char*,int)));
}
void SpwTcpPacketServer::pushPacket(char *packet, int size)
{
Jeandet Alexis
Sync
r20 QByteArray data;
char sizech[3];
data.append((char)0);
sizech[0]=size & 0x0FF;
sizech[1]=(size>>8) & 0x0FF;
sizech[2]=(size>>16) & 0x0FF;
data.append(sizech,3);
data.append(packet,size);
for(int i=0;i<connectedClients.count();i++)
{
QTcpSocket* soc=connectedClients.at(i);
if(soc->state()!=QAbstractSocket::ConnectedState)
{
connectedClients.removeAt(i);
delete soc;
}
else
{
connectedClients.at(i)->write(data);
paul
Functions added to the Python API:...
r35 onePacketTransmitted();
Jeandet Alexis
Sync
r20 }
}
Jeandet Alexis
Started GR-ESB driver.
r22 free(packet);
Jeandet Alexis
Sync
r18 }
void SpwTcpPacketServer::toggleServer()
{
if(this->p_server->isListening())
{
Jeandet Alexis
Sync
r20 disconnectServer();
Jeandet Alexis
Sync
r18 }
else
{
Jeandet Alexis
Sync
r20 connectServer();
Jeandet Alexis
Sync
r18 }
}
Jeandet Alexis
Sync
r20
void SpwTcpPacketServer::connectServer()
{
this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt());
this->ui->startServeQpb->setText("Stop Server");
paul
Functions added to the Python API:...
r35 resetStatististics();
Jeandet Alexis
Sync
r20 }
void SpwTcpPacketServer::disconnectServer()
{
this->ui->startServeQpb->setText("Start Server");
this->p_server->close();
}
void SpwTcpPacketServer::setServerPort(qint32 port)
{
this->ui->PortLineEdit->setText(QString("%1").arg(port));
}
Sync
r21 void SpwTcpPacketServer::setServerSetIP(QString ip)
{
this->ui->IPLineEdit->setText(ip);
}
Jeandet Alexis
Sync
r20 void SpwTcpPacketServer::newConnection()
{
Jeandet Alexis
Started GR-ESB driver.
r22 QTcpSocket* soc=this->p_server->nextPendingConnection();
this->connectedClients.append(soc);
Sync
r21 this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString());
paul
Functions added to the plugin to get the number of CCSDS packets...
r40 connect(soc,SIGNAL(readyRead()),this,SLOT(parseIncomingTC()));
}
void SpwTcpPacketServer::parseIncomingTC()
{
for(int i=0;i<connectedClients.count();i++)
{
QTcpSocket* soc=connectedClients.at(i);
if(soc->state()!=QAbstractSocket::ConnectedState)
{
connectedClients.removeAt(i);
delete soc;
}
else
{
if(soc->bytesAvailable()!=0)
{
do
{
QByteArray data = soc->readAll();
incomingTCParser->processIncomingQByteArray( data );
}while(soc->bytesAvailable()!=0);
}
}
}
}
void SpwTcpPacketServer::sendTCUsingSpaceWire(QByteArray data)
{
onePacketReceived();
if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission
{
int size = (data[1]*256*256) + (data[2]*256) + data[3];
char* SPWpacket = (char*)malloc(size);
memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
emit sendSPWPacket(SPWpacket,size);
}
Jeandet Alexis
Started GR-ESB driver.
r22 }
void SpwTcpPacketServer::readReady()
{
for(int i=0;i<connectedClients.count();i++)
{
QTcpSocket* soc=connectedClients.at(i);
if(soc->state()!=QAbstractSocket::ConnectedState)
{
connectedClients.removeAt(i);
delete soc;
}
else
{
if(soc->bytesAvailable()!=0)
{
do
{
QByteArray data = soc->readAll();
paul
Functions added to the Python API:...
r35 onePacketReceived();
if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission
Jeandet Alexis
Started GR-ESB driver.
r22 {
int size = (data[1]*256*256) + (data[2]*256) + data[3];
char* SPWpacket = (char*)malloc(size);
paul
Functions added to the Python API:...
r35 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
Jeandet Alexis
Started GR-ESB driver.
r22 emit sendSPWPacket(SPWpacket,size);
}
}while(soc->bytesAvailable()!=0);
}
}
}
Jeandet Alexis
Sync
r20 }
paul
Functions added to the Python API:...
r35 void SpwTcpPacketServer::resetStatististics()
{
receivedPackets = 0;
transmittedPackets = 0;
this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
}
Jeandet Alexis
Sync
r20 void SpwTcpPacketServer::updateHostIP()
{
QList<QHostAddress> list = QNetworkInterface::allAddresses();
for(int nIter=0; nIter<list.count(); nIter++)
{
if(!list[nIter].isLoopback())
if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
this->ui->IPLineEdit->setText(list[nIter].toString());
}
}
paul
Functions added to the Python API:...
r35
void SpwTcpPacketServer::onePacketReceived()
{
receivedPackets = receivedPackets + 1;
this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) );
}
void SpwTcpPacketServer::onePacketTransmitted()
{
transmittedPackets = transmittedPackets + 1;
this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) );
}