##// END OF EJS Templates
Functions added to the plugin to get the number of CCSDS packets...
paul -
r40:cda6b4e8adc1 Patch 3 from Paul on spwplugin default
parent child
Show More
@@ -0,0 +1,43
1 #include "incomingtcparser.h"
2
3 IncomingTCParser::IncomingTCParser(QObject *parent) :
4 QObject(parent)
5 {
6 incompleteData = false;
7 localDataArray.clear();
8 }
9
10 void IncomingTCParser::processIncomingQByteArray(QByteArray incomingQByteArray)
11 {
12 int ccsdsSize;
13 bool keepParsing;
14 QByteArray tcPacket;
15
16 keepParsing = true;
17
18 localDataArray.append( incomingQByteArray );
19
20 if (localDataArray.size() >= 4 )
21 {
22 while(keepParsing == true)
23 {
24 ccsdsSize = ( (unsigned char) localDataArray[1] ) * 256 * 256
25 + ( (unsigned char) localDataArray[2] ) * 256
26 + ( (unsigned char) localDataArray[3] );
27
28 if (localDataArray.size() < (ccsdsSize+4) ) keepParsing = false;
29 else
30 {
31 tcPacket = QByteArray( localDataArray );
32 tcPacket.resize( ccsdsSize + 4 );
33
34 emit sendPacketUsingSpaceWire( tcPacket );
35
36 localDataArray.remove(0, ccsdsSize + 4);
37 }
38
39 if (localDataArray.size() >= 4 ) keepParsing = true;
40 else keepParsing = false;
41 }
42 }
43 }
@@ -0,0 +1,26
1 #ifndef INCOMINGTCPARSER_H
2 #define INCOMINGTCPARSER_H
3
4 #include <QObject>
5
6 class IncomingTCParser : public QObject
7 {
8 Q_OBJECT
9 public:
10 explicit IncomingTCParser(QObject *parent = 0);
11
12 void processIncomingQByteArray(QByteArray incomingQByteArray);
13
14 signals:
15 void sendMessage( QString );
16 void sendPacketUsingSpaceWire( QByteArray packet );
17
18 public slots:
19
20 private:
21 QByteArray localDataArray;
22 bool incompleteData;
23
24 };
25
26 #endif // INCOMINGTCPARSER_H
@@ -31,11 +31,16 SpwTcpPacketServer::SpwTcpPacketServer(Q
31 31 ui->setupUi(this);
32 32 this->p_bridge = NULL;
33 33 this->p_server = new QTcpServer();
34 this->incomingTCParser = new IncomingTCParser();
35
34 36 connect(this->ui->startServeQpb,SIGNAL(clicked(bool)),SLOT(toggleServer()));
35 37 updateHostIP();
36 38 this->ui->PortLineEdit->setText("2200");
37 39 connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
38 40 resetStatististics();
41
42 connect( this->incomingTCParser, SIGNAL(sendPacketUsingSpaceWire(QByteArray)),
43 this, SLOT(sendTCUsingSpaceWire(QByteArray)));
39 44 }
40 45
41 46 SpwTcpPacketServer::~SpwTcpPacketServer()
@@ -120,7 +125,43 void SpwTcpPacketServer::newConnection()
120 125 QTcpSocket* soc=this->p_server->nextPendingConnection();
121 126 this->connectedClients.append(soc);
122 127 this->ui->listWidget->addItem(this->connectedClients.last()->peerAddress().toString());
123 connect(soc,SIGNAL(readyRead()),this,SLOT(readReady()));
128 connect(soc,SIGNAL(readyRead()),this,SLOT(parseIncomingTC()));
129 }
130
131 void SpwTcpPacketServer::parseIncomingTC()
132 {
133 for(int i=0;i<connectedClients.count();i++)
134 {
135 QTcpSocket* soc=connectedClients.at(i);
136 if(soc->state()!=QAbstractSocket::ConnectedState)
137 {
138 connectedClients.removeAt(i);
139 delete soc;
140 }
141 else
142 {
143 if(soc->bytesAvailable()!=0)
144 {
145 do
146 {
147 QByteArray data = soc->readAll();
148 incomingTCParser->processIncomingQByteArray( data );
149 }while(soc->bytesAvailable()!=0);
150 }
151 }
152 }
153 }
154
155 void SpwTcpPacketServer::sendTCUsingSpaceWire(QByteArray data)
156 {
157 onePacketReceived();
158 if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission
159 {
160 int size = (data[1]*256*256) + (data[2]*256) + data[3];
161 char* SPWpacket = (char*)malloc(size);
162 memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet
163 emit sendSPWPacket(SPWpacket,size);
164 }
124 165 }
125 166
126 167 void SpwTcpPacketServer::readReady()
@@ -27,6 +27,7
27 27 #include <QTcpServer>
28 28 #include <QList>
29 29 #include <QTcpSocket>
30 #include <incomingtcparser.h>
30 31
31 32 namespace Ui {
32 33 class SpwTcpPacketServer;
@@ -51,6 +52,8 public slots:
51 52 void setServerPort(qint32 port);
52 53 void setServerSetIP(QString ip);
53 54 void newConnection();
55 void parseIncomingTC();
56 void sendTCUsingSpaceWire(QByteArray data );
54 57 void readReady();
55 58 void resetStatististics();
56 59 private:
@@ -63,6 +66,7 private:
63 66 QList<QTcpSocket*> connectedClients;
64 67 unsigned int receivedPackets;
65 68 unsigned int transmittedPackets;
69 IncomingTCParser *incomingTCParser;
66 70 };
67 71
68 72 #endif // SPWTCPPACKETSERVER_H
@@ -254,6 +254,7 void StarDundeeGUI::resetBytesPacketsSta
254 254 nbBytesTransmittedToSpw = 0;
255 255 nbPacketsReceivedFromSpw = 0;
256 256 nbPacketsTransmittedToSpw = 0;
257 nbCCSDSPacketsTransmittedToSpw = 0;
257 258 }
258 259
259 260 void StarDundeeGUI::resetStatistics( void )
@@ -286,3 +287,18 void StarDundeeGUI::updateNbTransmittedB
286 287 this->ui->starDundeeTransmittedBytes->setText( QString::number(nbBytesTransmittedToSpw) );
287 288 this->ui->starDundeeTransmittedPackets->setText( QString::number(nbPacketsTransmittedToSpw) );
288 289 }
290
291 void StarDundeeGUI::updateCCSDSPacketTransmittedToSpw( void )
292 {
293 nbCCSDSPacketsTransmittedToSpw = nbCCSDSPacketsTransmittedToSpw + 1;
294 }
295
296 unsigned int StarDundeeGUI::getNbCCSDSPacketsTransmittedToSpw(void)
297 {
298 return this->nbCCSDSPacketsTransmittedToSpw;
299 }
300
301 unsigned int StarDundeeGUI::getNbPacketsTransmittedToSpw()
302 {
303 return this->nbPacketsTransmittedToSpw;
304 }
@@ -74,12 +74,16 public slots:
74 74 void resetStatistics( void );
75 75 void updateNbReceivedBytesFromSpw( unsigned int nbBytes);
76 76 void updateNbTransmittedBytesToSpw( unsigned int nbBytes);
77 void updateCCSDSPacketTransmittedToSpw( void );
78 unsigned int getNbPacketsTransmittedToSpw( void );
79 unsigned int getNbCCSDSPacketsTransmittedToSpw( void );
77 80 private:
78 81 Ui::StarDundeeUI *ui;
79 82 unsigned int nbBytesReceivedFromSpw;
80 83 unsigned int nbBytesTransmittedToSpw;
81 84 unsigned int nbPacketsReceivedFromSpw;
82 85 unsigned int nbPacketsTransmittedToSpw;
86 unsigned int nbCCSDSPacketsTransmittedToSpw;
83 87 };
84 88
85 89 #endif // STARDUNDEEGUI_H
@@ -43,6 +43,7 stardundeeSPW_USB::stardundeeSPW_USB(soc
43 43 connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int)));
44 44 connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint)));
45 45 connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint)));
46 connect(this->manager, SIGNAL(ccsdsPacketTransmittedToSpw()), this, SIGNAL(CCSDSPacketTransmittedToSpw()));
46 47 }
47 48
48 49 stardundeeSPW_USB::~stardundeeSPW_USB()
@@ -358,12 +359,18 void stardundeeSPW_USB::makeGUI(socexplo
358 359 connect(this,SIGNAL(SetSourceAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setSourceAddress(QString)));
359 360 connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString)));
360 361 connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount()));
362 connect(this,SIGNAL(GetNbPacketsTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(getNbPacketsTransmittedToSpw()));
363 connect(this,SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()),
364 ((StarDundeeGUI*)this->p_GUI),SLOT(getNbCCSDSPacketsTransmittedToSpw()));
361 365 connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool)));
362 366 connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool)));
363 367 connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint)));
364 368 connect(this,SIGNAL(BytesTransmittedToSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint)));
369 connect(this, SIGNAL(CCSDSPacketTransmittedToSpw()),((StarDundeeGUI*)this->p_GUI),SLOT(updateCCSDSPacketTransmittedToSpw()));
365 370 connect(this,SIGNAL(SetTimecodeFrequency(double)), ((StarDundeeGUI*)this->p_GUI),SLOT(setTimecodeFrequency(QString)));
366 371 connect(this,SIGNAL(StartSendingTimecodes(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setStartSendingTimecodes(bool)));
372
373 connect(this,SIGNAL(GetLinkNumber()), this->manager, SLOT(getLinkNumber()));
367 374 }
368 375
369 376 void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size)
@@ -374,10 +381,10 void stardundeeSPW_USB::sendPacketComing
374 381 data = (char *) malloc( size + 5 );
375 382
376 383 data[0] = this->manager->linkNumber;
377 data[1] = this->manager->destinationLogicalAddress; // target logical address
378 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
379 data[3] = 0x00; // reserved
380 data[4] = 0x00; // user application
384 data[1] = this->manager->destinationLogicalAddress; // target logical address
385 data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier
386 data[3] = 0x00; // reserved
387 data[4] = 0x00; // user application
381 388
382 389 for ( i=0; i<size; i++ )
383 390 {
@@ -984,6 +991,7 int stardundeeSPW_USB_Manager::getRMAPan
984 991
985 992 bool stardundeeSPW_USB_Manager::sendPacket(char *packet, int size)
986 993 {
994 char protocoleIdentifier;
987 995 USB_SPACEWIRE_STATUS result;
988 996 USB_SPACEWIRE_ID pIdentifier;
989 997 SocExplorerEngine::message(this->plugin,"Sending SPW packet",2);
@@ -998,6 +1006,12 bool stardundeeSPW_USB_Manager::sendPack
998 1006 else
999 1007 {
1000 1008 emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link
1009
1010 // read the protocole identifier
1011 protocoleIdentifier = packet[2];
1012 if (protocoleIdentifier == SPW_PROTO_ID_CCSDS)
1013 emit ccsdsPacketTransmittedToSpw();
1014
1001 1015 SocExplorerEngine::message(this->plugin,"Packet sent",2);
1002 1016 USBSpaceWire_FreeSend(hDevice, pIdentifier);
1003 1017 }
@@ -1029,6 +1043,11 void stardundeeSPW_USB_Manager::sendTime
1029 1043 }
1030 1044 }
1031 1045
1046 int stardundeeSPW_USB_Manager::getLinkNumber( void )
1047 {
1048 return this->linkNumber;
1049 }
1050
1032 1051 void stardundeeSPW_USB_Manager::setTimecodeFrequency(double requestedFrequency)
1033 1052 {
1034 1053 U32 rtr_clk_freq;
@@ -65,9 +65,11 signals:
65 65 void emitPacket(char* packet,int size);
66 66 void bytesReceivedFromSpw( unsigned int );
67 67 void bytesTransmittedToSpw( unsigned int);
68 void ccsdsPacketTransmittedToSpw( void );
68 69
69 70 public slots:
70 71 void sendTimecodePeriodically( bool onOff );
72 int getLinkNumber( void );
71 73
72 74 private:
73 75 QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx;
@@ -123,9 +125,13 signals:
123 125 void SetBrickAsAnInterface( bool );
124 126 void SetBrickAsARouter( bool );
125 127 int GetAvailableBrickCount( void );
128 unsigned int GetNbPacketsTransmittedToSpw( void );
129 unsigned int GetNbCCSDSPacketsTransmittedToSpw( void );
126 130 void BytesReceivedFromSpw( unsigned int );
127 131 void BytesTransmittedToSpw( unsigned int );
132 void CCSDSPacketTransmittedToSpw( void );
128 133 void StartSendingTimecodes( bool );
134 int GetLinkNumber();
129 135
130 136 public slots:
131 137 void toggleBridgeConnection();
@@ -104,7 +104,13 void spwplugin::bridgeSelectionChanged(c
104 104 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString)));
105 105 connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge()));
106 106 connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge()));
107 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetAvailableBrickCount()),((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount()));
107 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetAvailableBrickCount()),
108 ((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount()));
109 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetNbPacketsTransmittedToSpw()),
110 ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbPacketsTransmittedToSpw()));
111 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetNbCCSDSPacketsTransmittedToSpw()),
112 ((stardundeeSPW_USB*)bridge),SIGNAL(GetNbCCSDSPacketsTransmittedToSpw()));
113 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetLinkNumber()),((stardundeeSPW_USB*)bridge),SIGNAL(GetLinkNumber()));
108 114 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsAninterface(bool)),
109 115 ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsAnInterface(bool)));
110 116 connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsARouter(bool)),
@@ -46,7 +46,8 HEADERS += \
46 46 SpwTcpPacketServer/spwtcppacketserver.h \
47 47 spwpywrapper.h \
48 48 GR-ESB/gr_esb_bridge.h \
49 GR-ESB/gr_esb_ui.h
49 GR-ESB/gr_esb_ui.h \
50 incomingtcparser.h
50 51
51 52
52 53 SOURCES += \
@@ -57,7 +58,8 SOURCES += \
57 58 SpwTcpPacketServer/spwtcppacketserver.cpp \
58 59 spwpywrapper.cpp \
59 60 GR-ESB/gr_esb_bridge.cpp \
60 GR-ESB/gr_esb_ui.cpp
61 GR-ESB/gr_esb_ui.cpp \
62 incomingtcparser.cpp
61 63
62 64 FORMS += \
63 65 StarDundee/stardundeeGUI.ui \
@@ -19,6 +19,9 signals:
19 19 void StarDundeeSetDestinationKey(const QString & key);
20 20 void StarDundeeSetRmapTimeout(const QString & timeout);
21 21 int StarDundeeGetAvailableBrickCount();
22 unsigned int StarDundeeGetNbPacketsTransmittedToSpw( void );
23 unsigned int StarDundeeGetNbCCSDSPacketsTransmittedToSpw( void );
24 int StarDundeeGetLinkNumber();
22 25 void StarDundeeSetBrickAsAninterface( bool );
23 26 void StarDundeeSetBrickAsARouter( bool );
24 27 void StarDundeeSetTimecodeFrequency( double );
@@ -28,8 +31,8 signals:
28 31 void TCPServerDisconnect();
29 32 void TCPServerSetPort(qint32 port);
30 33 void TCPServerSetIP(QString ip);
34
31 35 public slots:
32
33 36 };
34 37
35 38 #endif // SPWPYWRAPPER_H
General Comments 0
You need to be logged in to leave comments. Login now