# HG changeset patch # User paul # Date 2014-12-18 11:50:39 # Node ID cda6b4e8adc1d6a1767e5eb4a72fc751f8ce6960 # Parent 26ccc22ea43d6a70dba58f467b2dedbff98a0990 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) diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp @@ -31,11 +31,16 @@ SpwTcpPacketServer::SpwTcpPacketServer(Q ui->setupUi(this); this->p_bridge = NULL; this->p_server = new QTcpServer(); + this->incomingTCParser = new IncomingTCParser(); + connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer())); updateHostIP(); this->ui->PortLineEdit->setText("2200"); connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection())); resetStatististics(); + + connect( this->incomingTCParser, SIGNAL(sendPacketUsingSpaceWire(QByteArray)), + this, SLOT(sendTCUsingSpaceWire(QByteArray))); } SpwTcpPacketServer::~SpwTcpPacketServer() @@ -120,7 +125,43 @@ void SpwTcpPacketServer::newConnection() QTcpSocket* soc=this->p_server->nextPendingConnection(); this->connectedClients.append(soc); this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString()); - connect(soc,SIGNAL(readyRead()),this,SLOT(readReady())); + connect(soc,SIGNAL(readyRead()),this,SLOT(parseIncomingTC())); +} + +void SpwTcpPacketServer::parseIncomingTC() +{ + for(int i=0;istate()!=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); + } } void SpwTcpPacketServer::readReady() diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace Ui { class SpwTcpPacketServer; @@ -51,6 +52,8 @@ public slots: void setServerPort(qint32 port); void setServerSetIP(QString ip); void newConnection(); + void parseIncomingTC(); + void sendTCUsingSpaceWire(QByteArray data ); void readReady(); void resetStatististics(); private: @@ -63,6 +66,7 @@ private: QList connectedClients; unsigned int receivedPackets; unsigned int transmittedPackets; + IncomingTCParser *incomingTCParser; }; #endif // SPWTCPPACKETSERVER_H diff --git a/spwplugin/StarDundee/stardundeegui.cpp b/spwplugin/StarDundee/stardundeegui.cpp --- a/spwplugin/StarDundee/stardundeegui.cpp +++ b/spwplugin/StarDundee/stardundeegui.cpp @@ -254,6 +254,7 @@ void StarDundeeGUI::resetBytesPacketsSta nbBytesTransmittedToSpw = 0; nbPacketsReceivedFromSpw = 0; nbPacketsTransmittedToSpw = 0; + nbCCSDSPacketsTransmittedToSpw = 0; } void StarDundeeGUI::resetStatistics( void ) @@ -286,3 +287,18 @@ void StarDundeeGUI::updateNbTransmittedB this->ui->starDundeeTransmittedBytes->setText( QString::number(nbBytesTransmittedToSpw) ); this->ui->starDundeeTransmittedPackets->setText( QString::number(nbPacketsTransmittedToSpw) ); } + +void StarDundeeGUI::updateCCSDSPacketTransmittedToSpw( void ) +{ + nbCCSDSPacketsTransmittedToSpw = nbCCSDSPacketsTransmittedToSpw + 1; +} + +unsigned int StarDundeeGUI::getNbCCSDSPacketsTransmittedToSpw(void) +{ + return this->nbCCSDSPacketsTransmittedToSpw; +} + +unsigned int StarDundeeGUI::getNbPacketsTransmittedToSpw() +{ + return this->nbPacketsTransmittedToSpw; +} diff --git a/spwplugin/StarDundee/stardundeegui.h b/spwplugin/StarDundee/stardundeegui.h --- a/spwplugin/StarDundee/stardundeegui.h +++ b/spwplugin/StarDundee/stardundeegui.h @@ -74,12 +74,16 @@ public slots: void resetStatistics( void ); void updateNbReceivedBytesFromSpw( unsigned int nbBytes); void updateNbTransmittedBytesToSpw( unsigned int nbBytes); + void updateCCSDSPacketTransmittedToSpw( void ); + unsigned int getNbPacketsTransmittedToSpw( void ); + unsigned int getNbCCSDSPacketsTransmittedToSpw( void ); private: Ui::StarDundeeUI *ui; unsigned int nbBytesReceivedFromSpw; unsigned int nbBytesTransmittedToSpw; unsigned int nbPacketsReceivedFromSpw; unsigned int nbPacketsTransmittedToSpw; + unsigned int nbCCSDSPacketsTransmittedToSpw; }; #endif // STARDUNDEEGUI_H diff --git a/spwplugin/StarDundee/stardundeespw_usb.cpp b/spwplugin/StarDundee/stardundeespw_usb.cpp --- a/spwplugin/StarDundee/stardundeespw_usb.cpp +++ b/spwplugin/StarDundee/stardundeespw_usb.cpp @@ -43,6 +43,7 @@ stardundeeSPW_USB::stardundeeSPW_USB(soc connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int))); connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint))); connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint))); + connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw())); } stardundeeSPW_USB::~stardundeeSPW_USB() @@ -358,12 +359,18 @@ void stardundeeSPW_USB::makeGUI(socexplo connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString))); connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString))); connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount())); + connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw())); + connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()), + ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw())); connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool))); connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool))); connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint))); connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint))); + connect(this, SIGNAL(CCSDSPacketTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw())); connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(QString))); connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool))); + + connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber())); } void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size) @@ -374,10 +381,10 @@ void stardundeeSPW_USB::sendPacketComing data = (char *) malloc( size + 5 ); data[0] = this->manager->linkNumber; - data[1] = this->manager->destinationLogicalAddress; // target logical address - data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier - data[3] = 0x00; // reserved - data[4] = 0x00; // user application + data[1] = this->manager->destinationLogicalAddress; // target logical address + data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier + data[3] = 0x00; // reserved + data[4] = 0x00; // user application for ( i=0; iplugin,"Sending SPW packet",2); @@ -998,6 +1006,12 @@ bool stardundeeSPW_USB_Manager::sendPack else { emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link + + // read the protocole identifier + protocoleIdentifier = packet[2]; + if (protocoleIdentifier == SPW_PROTO_ID_CCSDS) + emit ccsdsPacketTransmittedToSpw(); + SocExplorerEngine::message(this->plugin,"Packet sent",2); USBSpaceWire_FreeSend(hDevice, pIdentifier); } @@ -1029,6 +1043,11 @@ void stardundeeSPW_USB_Manager::sendTime } } +int stardundeeSPW_USB_Manager::getLinkNumber( void ) +{ + return this->linkNumber; +} + void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency) { U32 rtr_clk_freq; 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 @@ -65,9 +65,11 @@ signals: void emitPacket(char* packet,int size); void bytesReceivedFromSpw( unsigned int ); void bytesTransmittedToSpw( unsigned int); + void ccsdsPacketTransmittedToSpw( void ); public slots: void sendTimecodePeriodically( bool onOff ); + int getLinkNumber( void ); private: QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx; @@ -123,9 +125,13 @@ signals: void SetBrickAsAnInterface( bool ); void SetBrickAsARouter( bool ); int GetAvailableBrickCount( void ); + unsigned int GetNbPacketsTransmittedToSpw( void ); + unsigned int GetNbCCSDSPacketsTransmittedToSpw( void ); void BytesReceivedFromSpw( unsigned int ); void BytesTransmittedToSpw( unsigned int ); + void CCSDSPacketTransmittedToSpw( void ); void StartSendingTimecodes( bool ); + int GetLinkNumber(); public slots: void toggleBridgeConnection(); diff --git a/spwplugin/incomingtcparser.cpp b/spwplugin/incomingtcparser.cpp new file mode 100644 --- /dev/null +++ b/spwplugin/incomingtcparser.cpp @@ -0,0 +1,43 @@ +#include "incomingtcparser.h" + +IncomingTCParser::IncomingTCParser(QObject *parent) : + QObject(parent) +{ + incompleteData = false; + localDataArray.clear(); +} + +void IncomingTCParser::processIncomingQByteArray(QByteArray incomingQByteArray) +{ + int ccsdsSize; + bool keepParsing; + QByteArray tcPacket; + + keepParsing = true; + + localDataArray.append( incomingQByteArray ); + + if (localDataArray.size() >= 4 ) + { + while(keepParsing == true) + { + ccsdsSize = ( (unsigned char) localDataArray[1] ) * 256 * 256 + + ( (unsigned char) localDataArray[2] ) * 256 + + ( (unsigned char) localDataArray[3] ); + + if (localDataArray.size() < (ccsdsSize+4) ) keepParsing = false; + else + { + tcPacket = QByteArray( localDataArray ); + tcPacket.resize( ccsdsSize + 4 ); + + emit sendPacketUsingSpaceWire( tcPacket ); + + localDataArray.remove(0, ccsdsSize + 4); + } + + if (localDataArray.size() >= 4 ) keepParsing = true; + else keepParsing = false; + } + } +} diff --git a/spwplugin/incomingtcparser.h b/spwplugin/incomingtcparser.h new file mode 100644 --- /dev/null +++ b/spwplugin/incomingtcparser.h @@ -0,0 +1,26 @@ +#ifndef INCOMINGTCPARSER_H +#define INCOMINGTCPARSER_H + +#include + +class IncomingTCParser : public QObject +{ + Q_OBJECT +public: + explicit IncomingTCParser(QObject *parent = 0); + + void processIncomingQByteArray(QByteArray incomingQByteArray); + +signals: + void sendMessage( QString ); + void sendPacketUsingSpaceWire( QByteArray packet ); + +public slots: + +private: + QByteArray localDataArray; + bool incompleteData; + +}; + +#endif // INCOMINGTCPARSER_H diff --git a/spwplugin/spwplugin.cpp b/spwplugin/spwplugin.cpp --- a/spwplugin/spwplugin.cpp +++ b/spwplugin/spwplugin.cpp @@ -104,7 +104,13 @@ void spwplugin::bridgeSelectionChanged(c connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString))); connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge())); connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge())); - connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetAvailableBrickCount()),((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetAvailableBrickCount()), + ((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetNbPacketsTransmittedToSpw()), + ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbPacketsTransmittedToSpw())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetNbCCSDSPacketsTransmittedToSpw()), + ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbCCSDSPacketsTransmittedToSpw())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetLinkNumber()),((stardundeeSPW_USB*)bridge),SIGNAL(GetLinkNumber())); connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsAninterface(bool)), ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsAnInterface(bool))); connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsARouter(bool)), diff --git a/spwplugin/spwplugin.pro b/spwplugin/spwplugin.pro --- a/spwplugin/spwplugin.pro +++ b/spwplugin/spwplugin.pro @@ -46,7 +46,8 @@ HEADERS += \ SpwTcpPacketServer/spwtcppacketserver.h \ spwpywrapper.h \ GR-ESB/gr_esb_bridge.h \ - GR-ESB/gr_esb_ui.h + GR-ESB/gr_esb_ui.h \ + incomingtcparser.h SOURCES += \ @@ -57,7 +58,8 @@ SOURCES += \ SpwTcpPacketServer/spwtcppacketserver.cpp \ spwpywrapper.cpp \ GR-ESB/gr_esb_bridge.cpp \ - GR-ESB/gr_esb_ui.cpp + GR-ESB/gr_esb_ui.cpp \ + incomingtcparser.cpp FORMS += \ StarDundee/stardundeeGUI.ui \ diff --git a/spwplugin/spwpywrapper.h b/spwplugin/spwpywrapper.h --- a/spwplugin/spwpywrapper.h +++ b/spwplugin/spwpywrapper.h @@ -19,6 +19,9 @@ signals: void StarDundeeSetDestinationKey(const QString & key); void StarDundeeSetRmapTimeout(const QString & timeout); int StarDundeeGetAvailableBrickCount(); + unsigned int StarDundeeGetNbPacketsTransmittedToSpw( void ); + unsigned int StarDundeeGetNbCCSDSPacketsTransmittedToSpw( void ); + int StarDundeeGetLinkNumber(); void StarDundeeSetBrickAsAninterface( bool ); void StarDundeeSetBrickAsARouter( bool ); void StarDundeeSetTimecodeFrequency( double ); @@ -28,8 +31,8 @@ signals: void TCPServerDisconnect(); void TCPServerSetPort(qint32 port); void TCPServerSetIP(QString ip); + public slots: - }; #endif // SPWPYWRAPPER_H