|
|
#include "mainwindow.h"
|
|
|
#include <iostream>
|
|
|
#include <QNetworkInterface>
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
: QMainWindow(parent)
|
|
|
{
|
|
|
parsingContinue = false;
|
|
|
totalOfBytes = 0;
|
|
|
totalOfPackets = 0;
|
|
|
|
|
|
spectraPacketNormalSpectrumF0 = new SpectraPacket(0, 128);
|
|
|
|
|
|
//*********
|
|
|
// wfPacket
|
|
|
wfPacketNormal[0] = new WFPacket(0, 2048);
|
|
|
wfPacketNormal[1] = new WFPacket(0, 2048);
|
|
|
wfPacketNormal[2] = new WFPacket(0, 2048);
|
|
|
wfPacketNormal[3] = new WFPacket(0, 2688);
|
|
|
wfPacketBurst = new WFPacket(0, 2688);
|
|
|
wfPacketSBM1 = new WFPacket(0, 2688);
|
|
|
wfPacketSBM2 = new WFPacket(0, 2688);
|
|
|
wfPacketCWF_F3 = new WFPacket(0, 2688);
|
|
|
|
|
|
//****
|
|
|
// XML
|
|
|
// xml handlers
|
|
|
xmlHandler = new LFRXmlHandler();
|
|
|
// xml sources
|
|
|
sourceTC = new QXmlInputSource();
|
|
|
// xml writer
|
|
|
lfrXmlWriter = new LFRXmlWriter();
|
|
|
// setup xml parser for the echo bridge
|
|
|
lfrXmlParser = new LFRXmlParser();
|
|
|
|
|
|
UI = new MainWindowUI();
|
|
|
readSettings();
|
|
|
this->UI->serverTMEchoDialogBox->setIP(echoBridgeIP0, echoBridgeIP1, echoBridgeIP2, echoBridgeIP3);
|
|
|
|
|
|
lfrXmlParser->generalCCSDSPacketStore = &this->generalCCSDSPacketStore;
|
|
|
|
|
|
initSocketStatesList();
|
|
|
|
|
|
this->setCentralWidget(this->UI);
|
|
|
//this->setLayout(UI->layout());
|
|
|
|
|
|
analyserSGSEServerTC = new QTcpServer();
|
|
|
analyserSGSEServerTM = new QTcpServer();
|
|
|
|
|
|
socketTC = NULL;
|
|
|
socketTM = NULL;
|
|
|
socketEchoServer = new QTcpSocket();
|
|
|
|
|
|
connect(this->UI->button_openServerTCTM, SIGNAL(clicked()), this, SLOT(listenOnTCTMPorts()));
|
|
|
connect(this->UI->button_testServerTCTM, SIGNAL(clicked()), this, SLOT(testTCTMPorts()));
|
|
|
connect(this->UI->button_openSocketEchoServer, SIGNAL(clicked()), this, SLOT(openEchoServer()));
|
|
|
//
|
|
|
connect(this->analyserSGSEServerTC, SIGNAL(newConnection()), this, SLOT(newConnectionOnTCServer()));
|
|
|
connect(this->analyserSGSEServerTM, SIGNAL(newConnection()), this, SLOT(newConnectionOnTMServer()));
|
|
|
//
|
|
|
connect(this, SIGNAL(socketTMHasChanged(QTcpSocket*)), this->lfrXmlWriter, SLOT(setSocketTM(QTcpSocket*)));
|
|
|
connect(this->UI->button_TCAcknowledgement, SIGNAL(clicked()), this->lfrXmlWriter, SLOT(sendXML_TC_Acknowledgment()));
|
|
|
connect(this->UI->button_TCRejection, SIGNAL(clicked()), this->lfrXmlWriter, SLOT(sendXML_TC_rejection()));
|
|
|
connect(this->UI->button_GSEHK, SIGNAL(clicked()), this->lfrXmlWriter, SLOT(sendXML_GSE_HK()));
|
|
|
|
|
|
// socket echo server
|
|
|
connect(this->socketEchoServer, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
|
|
this, SLOT(socket_TMEcho_ServerHasChanged()));
|
|
|
connect(this->socketEchoServer, SIGNAL(readyRead()),
|
|
|
this, SLOT(readDataOnSocketEchoServer()));
|
|
|
|
|
|
// display on console
|
|
|
connect(this->xmlHandler, SIGNAL(displayMessage(QString)),
|
|
|
this, SLOT(displayOnConsole(QString)));
|
|
|
connect(this->UI->hkDisplay, SIGNAL(displayMessage(QString)),
|
|
|
this, SLOT(displayOnConsole(QString)));
|
|
|
connect(this->lfrXmlParser, SIGNAL(sendMessage(QString)),
|
|
|
this, SLOT(displayOnConsole(QString)));
|
|
|
//
|
|
|
connect(this->lfrXmlParser, SIGNAL(processPacketStore()),
|
|
|
this, SLOT(processPacketStore()));
|
|
|
//
|
|
|
connect(this->UI->button_resetStatistics, SIGNAL(clicked()),
|
|
|
this, SLOT(resetStatistics()));
|
|
|
|
|
|
displayNetworkInterfaces();
|
|
|
|
|
|
this->xmlHandler->packetStoreHasChanged(&generalCCSDSPacketStore);
|
|
|
};
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
{
|
|
|
delete wfPacketNormal[0];
|
|
|
delete wfPacketNormal[1];
|
|
|
delete wfPacketNormal[2];
|
|
|
delete wfPacketNormal[3];
|
|
|
delete wfPacketBurst;
|
|
|
delete wfPacketSBM1;
|
|
|
delete wfPacketSBM2;
|
|
|
delete wfPacketCWF_F3;
|
|
|
}
|
|
|
|
|
|
void MainWindow::displayNetworkInterfaces()
|
|
|
{
|
|
|
QList<QHostAddress> list = QNetworkInterface::allAddresses();
|
|
|
this->displayOnConsole("Network interfaces:");
|
|
|
for(int nIter=0; nIter<list.count(); nIter++)
|
|
|
{
|
|
|
this->UI->displayOnConsole(list[nIter].toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::listenOnTCTMPorts()
|
|
|
{
|
|
|
QString str;
|
|
|
|
|
|
//***
|
|
|
// TC
|
|
|
analyserSGSEServerTC->listen(QHostAddress::Any, this->UI->getTCPort());
|
|
|
str = analyserSGSEServerTC->errorString();
|
|
|
if (!str.isEmpty())
|
|
|
{
|
|
|
this->displayOnConsole(str);
|
|
|
}
|
|
|
this->displayOnConsole("Listening TC on port "
|
|
|
+ QString::number(this->UI->getTCPort())
|
|
|
);
|
|
|
|
|
|
//***
|
|
|
// TM
|
|
|
analyserSGSEServerTM->listen(QHostAddress::Any, this->UI->getTMPort());
|
|
|
str = analyserSGSEServerTM->errorString();
|
|
|
if (!str.isEmpty())
|
|
|
{
|
|
|
this->displayOnConsole(str);
|
|
|
}
|
|
|
this->displayOnConsole("Listening TM on port "
|
|
|
+ QString::number(this->UI->getTMPort())
|
|
|
);
|
|
|
}
|
|
|
|
|
|
void MainWindow::testTCTMPorts()
|
|
|
{
|
|
|
if (socketTC != NULL)
|
|
|
{
|
|
|
this->displayOnConsole("TC socket *** " + socketStates.at(socketTC->state()) );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this->displayOnConsole("TC socket *** not tested, (socketTC) is NULL" );
|
|
|
}
|
|
|
if (socketTM != NULL)
|
|
|
{
|
|
|
this->displayOnConsole("TM socket *** " + socketStates.at(socketTM->state()) );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this->displayOnConsole("TM socket *** not tested, (socketTM) is NULL" );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::newConnectionOnTCServer()
|
|
|
{
|
|
|
this->displayOnConsole("got new connection on TC port");
|
|
|
socketTC = analyserSGSEServerTC->nextPendingConnection();
|
|
|
this->displayOnConsole("TC socket *** " + socketStates.at(socketTC->state()) );
|
|
|
connect(this->socketTC, SIGNAL(readyRead()), this, SLOT(readDataOnTCPort()));
|
|
|
}
|
|
|
|
|
|
void MainWindow::newConnectionOnTMServer()
|
|
|
{
|
|
|
this->displayOnConsole("got new connection on TM port");
|
|
|
socketTM = analyserSGSEServerTM->nextPendingConnection();
|
|
|
this->displayOnConsole("TM socket *** " + socketStates.at(socketTM->state()) );
|
|
|
connect(this->socketTM, SIGNAL(readyRead()), this, SLOT(readDataOnTMPort()));
|
|
|
|
|
|
emit socketTMHasChanged(this->socketTM);
|
|
|
}
|
|
|
|
|
|
void MainWindow::readDataOnTCPort()
|
|
|
{
|
|
|
bool ok;
|
|
|
int nbBytesAvailable = 0;
|
|
|
|
|
|
nbBytesAvailable = socketTC->bytesAvailable();
|
|
|
buffer = (char *) malloc(nbBytesAvailable);
|
|
|
socketTC->read(buffer, nbBytesAvailable);
|
|
|
|
|
|
this->displayOnConsole("readDataOnTCPort *** "
|
|
|
+ QString::number(nbBytesAvailable)
|
|
|
+ " read");
|
|
|
|
|
|
QByteArray xmlData( buffer, nbBytesAvailable);
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
sourceTC->setData( xmlData );
|
|
|
|
|
|
xmlReader.setContentHandler(xmlHandler);
|
|
|
xmlReader.setErrorHandler(xmlHandler);
|
|
|
|
|
|
ok = xmlReader.parse(sourceTC);
|
|
|
if (!ok) {
|
|
|
std::cout << "Parsing failed." << std::endl;
|
|
|
}
|
|
|
else {
|
|
|
QStringList names = xmlHandler->names();
|
|
|
QList<int> indentations = xmlHandler->indentations();
|
|
|
|
|
|
int items = names.count();
|
|
|
|
|
|
for (int i = 0; i < items; ++i) {
|
|
|
displayOnConsole(
|
|
|
names[i]
|
|
|
+ " --- identations: "
|
|
|
+ QString::number(indentations[i]));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::readDataOnTMPort()
|
|
|
{
|
|
|
this->displayOnConsole("TM data received, begin parsing");
|
|
|
}
|
|
|
|
|
|
void MainWindow::readDataOnSocketEchoServer()
|
|
|
{
|
|
|
QString dataString;
|
|
|
|
|
|
dataArray.append(socketEchoServer->readAll());
|
|
|
// dataString = QString::fromAscii(dataArray);
|
|
|
dataString = QString::fromLatin1(dataArray);
|
|
|
this->lfrXmlParser->processIncomingStr(dataString);
|
|
|
dataArray.clear();
|
|
|
}
|
|
|
|
|
|
void MainWindow::displayOnConsole(QString message)
|
|
|
{
|
|
|
this->UI->displayOnConsole( message );
|
|
|
}
|
|
|
|
|
|
void MainWindow::initSocketStatesList()
|
|
|
{
|
|
|
socketStates.append("The socket is not connected");
|
|
|
socketStates.append("The socket is performing a host name lookup");
|
|
|
socketStates.append("The socket has started establishing a connection");
|
|
|
socketStates.append("A connection is established");
|
|
|
socketStates.append("The socket is bound to an address and port (for servers)");
|
|
|
socketStates.append("The socket is about to close (data may still be waiting to be written)");
|
|
|
socketStates.append("For internal use only");
|
|
|
}
|
|
|
|
|
|
void MainWindow::openEchoServer()
|
|
|
{
|
|
|
socketEchoServer->connectToHost(this->UI->serverTMEchoDialogBox->getIP(),
|
|
|
this->UI->spinbox_serverTMEchoPort->value());
|
|
|
//socketEchoServer->open();
|
|
|
}
|
|
|
|
|
|
void MainWindow::socket_TMEcho_ServerHasChanged()
|
|
|
{
|
|
|
this->displayOnConsole("TM Echo Socket socket *** " + socketStates.at(socketEchoServer->state()) );
|
|
|
}
|
|
|
|
|
|
void MainWindow::buildWFAndDisplay_SWF(TMPacketToRead *packet, WFPacket *wfPacket, unsigned char num_page)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
static unsigned int nbSamples = 0;
|
|
|
unsigned char *data;
|
|
|
unsigned char pa_lfr_pkt_cnt;
|
|
|
unsigned char pa_lfr_pkt_nr;
|
|
|
unsigned int pa_lfr_swf_blk_nr = 0;
|
|
|
double deltaT;
|
|
|
|
|
|
switch(num_page)
|
|
|
{
|
|
|
case 0: // F0
|
|
|
deltaT = 1. / 24576;
|
|
|
break;
|
|
|
case 1: // F1
|
|
|
deltaT = 1. / 4096;
|
|
|
break;
|
|
|
case 2: // F2
|
|
|
deltaT = 1. / 256;
|
|
|
break;
|
|
|
default:
|
|
|
deltaT = 0;
|
|
|
break;
|
|
|
}
|
|
|
pa_lfr_pkt_cnt = packet->Value[22];
|
|
|
pa_lfr_pkt_nr = packet->Value[23]; // PA_LFR_PKT_NR
|
|
|
pa_lfr_swf_blk_nr = packet->Value[30] * 256 + packet->Value[31]; // PA_LFR_SWF_BLK_NR
|
|
|
data = &packet->Value[32]; // start of the first data block;
|
|
|
|
|
|
if (pa_lfr_pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time
|
|
|
{
|
|
|
nbSamples = 0;
|
|
|
wfPacket->coarseTime = ((packet->Value[24] & 0x7f) << 24)
|
|
|
+ (packet->Value[25] << 16)
|
|
|
+ (packet->Value[26] << 8)
|
|
|
+ packet->Value[27];
|
|
|
wfPacket->fineTime = (packet->Value[28] << 8) + packet->Value[29];
|
|
|
}
|
|
|
|
|
|
for ( i=0; i<pa_lfr_swf_blk_nr; i++ ){
|
|
|
wfPacket->wf_v[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) ] << 8) + (data[ (i*BLK_SIZE) + 1]) );
|
|
|
wfPacket->wf_e1[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) + 2] << 8) + (data[ (i*BLK_SIZE) + 3]) );
|
|
|
wfPacket->wf_e2[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) + 4] << 8) + (data[ (i*BLK_SIZE) + 5]) );
|
|
|
wfPacket->wf_b1[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) + 6] << 8) + (data[ (i*BLK_SIZE) + 7]) );
|
|
|
wfPacket->wf_b2[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) + 8] << 8) + (data[ (i*BLK_SIZE) + 9]) );
|
|
|
wfPacket->wf_b3[nbSamples + i] = (short) ( (data[ (i * BLK_SIZE) + 10] << 8) + (data[ (i*BLK_SIZE) + 11]) );
|
|
|
}
|
|
|
|
|
|
nbSamples = nbSamples + pa_lfr_swf_blk_nr;
|
|
|
|
|
|
if (pa_lfr_pkt_nr == pa_lfr_pkt_cnt)
|
|
|
{
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_v, num_page, 0, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_e1, num_page, 1, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_e2, num_page, 2, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_b1, num_page, 3, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_b2, num_page, 4, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
this->UI->wfDisplay->displayOnPlot(wfPacket->wf_b3, num_page, 5, wfPacket->coarseTime, wfPacket->fineTime, deltaT, nbSamples);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::buildWFAndDisplay_CWF_LONG_F3(TMPacketToRead *packet, WFPacket *wfPacket)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
unsigned int j = 0;
|
|
|
unsigned char *data;
|
|
|
static unsigned char pkt_nr = 1;
|
|
|
unsigned int blk_nr = 0;
|
|
|
static unsigned int coarseTime;
|
|
|
static unsigned int fineTime;
|
|
|
unsigned int tmpCoarseTime;
|
|
|
unsigned int tmpFineTime;
|
|
|
double deltaT;
|
|
|
double DELTA;
|
|
|
unsigned int nbData;
|
|
|
|
|
|
deltaT = 1 / 16.;
|
|
|
|
|
|
if (pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time
|
|
|
{
|
|
|
tmpCoarseTime = coarseTime;
|
|
|
tmpFineTime = fineTime;
|
|
|
coarseTime = ((packet->Value[22] & 0x7f) << 24)
|
|
|
+ (packet->Value[23] << 16)
|
|
|
+ (packet->Value[24] << 8)
|
|
|
+ packet->Value[25];
|
|
|
fineTime = (packet->Value[26] << 8) + packet->Value[27];
|
|
|
DELTA = (coarseTime + fineTime * 1. / 65536.)
|
|
|
- (tmpCoarseTime + tmpFineTime * 1. / 65536);
|
|
|
displayOnConsole( "DELTA = " + QString::number(DELTA, 'f', 10) );
|
|
|
}
|
|
|
blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWFL3_BLK_NR
|
|
|
data = &packet->Value[30]; // start of the first data block;
|
|
|
|
|
|
j = (pkt_nr-1) * blk_nr;
|
|
|
for ( i=0; i<blk_nr; i++ ){
|
|
|
wfPacket->wf_v[j + i] = (short) ( (data[ (i * BLK_SIZE) ] << 8) + (data[ (i*BLK_SIZE) + 1]) );
|
|
|
wfPacket->wf_e1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 2] << 8) + (data[ (i*BLK_SIZE) + 3]) );
|
|
|
wfPacket->wf_e2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 4] << 8) + (data[ (i*BLK_SIZE) + 5]) );
|
|
|
wfPacket->wf_b1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 6] << 8) + (data[ (i*BLK_SIZE) + 7]) );
|
|
|
wfPacket->wf_b2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 8] << 8) + (data[ (i*BLK_SIZE) + 9]) );
|
|
|
wfPacket->wf_b3[j + i] = (short) ( (data[ (i * BLK_SIZE) + 10] << 8) + (data[ (i*BLK_SIZE) + 11]) );
|
|
|
}
|
|
|
pkt_nr = pkt_nr + 1;
|
|
|
if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1))
|
|
|
{
|
|
|
nbData = j + blk_nr;
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_v, 0, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_e1, 1, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_e2, 2, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b1, 3, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b2, 4, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b3, 5, coarseTime, fineTime, deltaT, nbData);
|
|
|
pkt_nr = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::buildWFAndDisplay_CWF_F3_light(TMPacketToRead *packet, WFPacket *wfPacket)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
unsigned int j = 0;
|
|
|
unsigned char *data;
|
|
|
static unsigned char pkt_nr = 1;
|
|
|
unsigned int blk_nr = 0;
|
|
|
static unsigned int coarseTime;
|
|
|
static unsigned int fineTime;
|
|
|
unsigned int tmpCoarseTime;
|
|
|
unsigned int tmpFineTime;
|
|
|
double deltaT;
|
|
|
double DELTA;
|
|
|
unsigned int nbData;
|
|
|
|
|
|
deltaT = 1 / 16.;
|
|
|
|
|
|
if (pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time
|
|
|
{
|
|
|
tmpCoarseTime = coarseTime;
|
|
|
tmpFineTime = fineTime;
|
|
|
coarseTime = ((packet->Value[22] & 0x7f) << 24)
|
|
|
+ (packet->Value[23] << 16)
|
|
|
+ (packet->Value[24] << 8)
|
|
|
+ packet->Value[25];
|
|
|
fineTime = (packet->Value[26] << 8) + packet->Value[27];
|
|
|
DELTA = (coarseTime + fineTime * 1. / 65536.)
|
|
|
- (tmpCoarseTime + tmpFineTime * 1. / 65536);
|
|
|
displayOnConsole( "DELTA = " + QString::number(DELTA, 'f', 10) );
|
|
|
}
|
|
|
blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWF3_BLK_NR
|
|
|
data = &packet->Value[30]; // start of the first data block;
|
|
|
|
|
|
j = (pkt_nr-1) * blk_nr;
|
|
|
for ( i=0; i<blk_nr; i++ ){
|
|
|
wfPacket->wf_v[j + i] = (short) ( (data[ (i * BLK_SIZE_CWF3_LIGHT) ] << 8) + (data[ (i*BLK_SIZE_CWF3_LIGHT) + 1]) );
|
|
|
wfPacket->wf_e1[j + i] = (short) ( (data[ (i * BLK_SIZE_CWF3_LIGHT) + 2] << 8) + (data[ (i*BLK_SIZE_CWF3_LIGHT) + 3]) );
|
|
|
wfPacket->wf_e2[j + i] = (short) ( (data[ (i * BLK_SIZE_CWF3_LIGHT) + 4] << 8) + (data[ (i*BLK_SIZE_CWF3_LIGHT) + 5]) );
|
|
|
wfPacket->wf_b1[j + i] = 0;
|
|
|
wfPacket->wf_b2[j + i] = 0;
|
|
|
wfPacket->wf_b3[j + i] = 0;
|
|
|
}
|
|
|
pkt_nr = pkt_nr + 1;
|
|
|
if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF_LIGHT+1))
|
|
|
{
|
|
|
nbData = j + blk_nr;
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_v, 0, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_e1, 1, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_e2, 2, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b1, 3, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b2, 4, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F3->displayOnPlot(wfPacket->wf_b3, 5, coarseTime, fineTime, deltaT, nbData);
|
|
|
pkt_nr = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::buildWFAndDisplay_CWF_F1(TMPacketToRead *packet, WFPacket *wfPacket)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
unsigned int j = 0;
|
|
|
unsigned char *data;
|
|
|
static unsigned char pkt_nr = 1;
|
|
|
unsigned int blk_nr = 0;
|
|
|
static unsigned int coarseTime;
|
|
|
static unsigned int fineTime;
|
|
|
double deltaT;
|
|
|
unsigned int nbData;
|
|
|
|
|
|
deltaT = 1. / 4096.;
|
|
|
|
|
|
if (pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time
|
|
|
{
|
|
|
coarseTime = ((packet->Value[22] & 0x7f) << 24)
|
|
|
+ (packet->Value[23] << 16)
|
|
|
+ (packet->Value[24] << 8)
|
|
|
+ packet->Value[25];
|
|
|
fineTime = (packet->Value[26] << 8) + packet->Value[27];
|
|
|
}
|
|
|
blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWF_BLK_NR
|
|
|
data = &packet->Value[30]; // start of the first data block;
|
|
|
|
|
|
j = (pkt_nr-1) * blk_nr;
|
|
|
for ( i=0; i<blk_nr; i++ ){
|
|
|
wfPacket->wf_v[j + i] = (short) ( (data[ (i * BLK_SIZE) ] << 8) + (data[ (i*BLK_SIZE) + 1]) );
|
|
|
wfPacket->wf_e1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 2] << 8) + (data[ (i*BLK_SIZE) + 3]) );
|
|
|
wfPacket->wf_e2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 4] << 8) + (data[ (i*BLK_SIZE) + 5]) );
|
|
|
wfPacket->wf_b1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 6] << 8) + (data[ (i*BLK_SIZE) + 7]) );
|
|
|
wfPacket->wf_b2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 8] << 8) + (data[ (i*BLK_SIZE) + 9]) );
|
|
|
wfPacket->wf_b3[j + i] = (short) ( (data[ (i * BLK_SIZE) + 10] << 8) + (data[ (i*BLK_SIZE) + 11]) );
|
|
|
}
|
|
|
pkt_nr = pkt_nr + 1;
|
|
|
if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1))
|
|
|
{
|
|
|
nbData = j + blk_nr;
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_v, 0, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_e1, 1, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_e2, 2, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_b1, 3, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_b2, 4, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F1->displayOnPlot(wfPacket->wf_b3, 5, coarseTime, fineTime, deltaT, nbData);
|
|
|
pkt_nr = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::buildWFAndDisplay_CWF_F2(TMPacketToRead *packet, WFPacket *wfPacket)
|
|
|
{
|
|
|
unsigned int i = 0;
|
|
|
unsigned int j = 0;
|
|
|
unsigned char *data;
|
|
|
static unsigned char pkt_nr = 1;
|
|
|
unsigned int blk_nr = 0;
|
|
|
static unsigned int coarseTime;
|
|
|
static unsigned int fineTime;
|
|
|
double deltaT;
|
|
|
unsigned int nbData;
|
|
|
|
|
|
deltaT = 1. / 256.;
|
|
|
|
|
|
if (pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time
|
|
|
{
|
|
|
coarseTime = ((packet->Value[22] & 0x7f) << 24)
|
|
|
+ (packet->Value[23] << 16)
|
|
|
+ (packet->Value[24] << 8)
|
|
|
+ packet->Value[25];
|
|
|
fineTime = (packet->Value[26] << 8) + packet->Value[27];
|
|
|
}
|
|
|
blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWF3_BLK_NR
|
|
|
data = &packet->Value[30]; // start of the first data block;
|
|
|
|
|
|
j = (pkt_nr-1) * blk_nr;
|
|
|
for ( i=0; i<blk_nr; i++ ){
|
|
|
wfPacket->wf_v[j + i] = (short) ( (data[ (i * BLK_SIZE) ] << 8) + (data[ (i*BLK_SIZE) + 1]) );
|
|
|
wfPacket->wf_e1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 2] << 8) + (data[ (i*BLK_SIZE) + 3]) );
|
|
|
wfPacket->wf_e2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 4] << 8) + (data[ (i*BLK_SIZE) + 5]) );
|
|
|
wfPacket->wf_b1[j + i] = (short) ( (data[ (i * BLK_SIZE) + 6] << 8) + (data[ (i*BLK_SIZE) + 7]) );
|
|
|
wfPacket->wf_b2[j + i] = (short) ( (data[ (i * BLK_SIZE) + 8] << 8) + (data[ (i*BLK_SIZE) + 9]) );
|
|
|
wfPacket->wf_b3[j + i] = (short) ( (data[ (i * BLK_SIZE) + 10] << 8) + (data[ (i*BLK_SIZE) + 11]) );
|
|
|
}
|
|
|
pkt_nr = pkt_nr + 1;
|
|
|
if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1))
|
|
|
{
|
|
|
nbData = j + blk_nr;
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_v, 0, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_e1, 1, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_e2, 2, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_b1, 3, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_b2, 4, coarseTime, fineTime, deltaT, nbData);
|
|
|
this->UI->wfPage_CWF_F2->displayOnPlot(wfPacket->wf_b3, 5, coarseTime, fineTime, deltaT, nbData);
|
|
|
pkt_nr = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::build_ASM_AndDisplay_NORM_F0(TMPacketToRead *packet, SpectraPacket *spectraPacket)
|
|
|
{
|
|
|
unsigned int i;
|
|
|
unsigned int j;
|
|
|
unsigned char *data;
|
|
|
unsigned char *aux;
|
|
|
unsigned char cntASM;
|
|
|
unsigned char nrASM;
|
|
|
unsigned int blkNR;
|
|
|
double deltaF;
|
|
|
unsigned int nbData;
|
|
|
|
|
|
cntASM = packet->Value[22];
|
|
|
nrASM = packet->Value[23];
|
|
|
blkNR = packet->Value[30] * 256 + packet->Value[31];
|
|
|
|
|
|
data = &packet->Value[32]; // start of the first data block;
|
|
|
|
|
|
j = (nrASM-1) * blkNR;
|
|
|
for ( i=0; i<blkNR; i++ ){
|
|
|
aux = (unsigned char*) &spectraPacket->s11[ j + i ]; // s11 is a table of float
|
|
|
aux[3] = data[ (i * 50 + 2*0 ) ];
|
|
|
aux[2] = data[ (i * 50 + 2*0 ) + 1];
|
|
|
aux = (unsigned char*) &spectraPacket->s22[ j + i ]; // s22 is a table of float
|
|
|
aux[3] = data[ (i * 50 + 2*9 ) ];
|
|
|
aux[2] = data[ (i * 50 + 2*9 ) + 1];
|
|
|
aux = (unsigned char*) &spectraPacket->s33[ j + i ]; // s33 is a table of float
|
|
|
aux[3] = data[ (i * 50 + 2*16) ];
|
|
|
aux[2] = data[ (i * 50 + 2*16) + 1];
|
|
|
aux = (unsigned char*) &spectraPacket->s44[ j + i ]; // s44 is a table of float
|
|
|
aux[3] = data[ (i * 50 + 2*21) ];
|
|
|
aux[2] = data[ (i * 50 + 2*21) + 1];
|
|
|
aux = (unsigned char*) &spectraPacket->s55[ j + i ]; // s55 is a table of float
|
|
|
aux[3] = data[ (i * 50 + 2*24) ];
|
|
|
aux[2] = data[ (i * 50 + 2*24) + 1];
|
|
|
}
|
|
|
|
|
|
deltaF = 24576. / 256. ;
|
|
|
nbData = j + blkNR;
|
|
|
if (nrASM == cntASM)
|
|
|
{
|
|
|
this->UI->asmPage_F0->displayOnPlot(spectraPacket->s11, 0, ASM_F0_INDICE_START, deltaF, nbData);
|
|
|
this->UI->asmPage_F0->displayOnPlot(spectraPacket->s22, 1, ASM_F0_INDICE_START, deltaF, nbData);
|
|
|
this->UI->asmPage_F0->displayOnPlot(spectraPacket->s33, 2, ASM_F0_INDICE_START, deltaF, nbData);
|
|
|
this->UI->asmPage_F0->displayOnPlot(spectraPacket->s44, 3, ASM_F0_INDICE_START, deltaF, nbData);
|
|
|
this->UI->asmPage_F0->displayOnPlot(spectraPacket->s55, 4, ASM_F0_INDICE_START, deltaF, nbData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::resetStatistics()
|
|
|
{
|
|
|
totalOfBytes = 0;
|
|
|
totalOfPackets = 0;
|
|
|
this->UI->totalOfBytesHasChanged(totalOfBytes);
|
|
|
this->UI->totalOfPacketsHasChanged(totalOfPackets);
|
|
|
}
|
|
|
|
|
|
//******************
|
|
|
// packet processing
|
|
|
|
|
|
void MainWindow::processPacketStore()
|
|
|
{
|
|
|
TMPacketToRead *packet;
|
|
|
while(!generalCCSDSPacketStore.isEmpty())
|
|
|
{
|
|
|
packet = generalCCSDSPacketStore.takeFirst();
|
|
|
processIncomingPacket(packet);
|
|
|
delete(packet);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::processIncomingPacket(TMPacketToRead *packet)
|
|
|
{
|
|
|
totalOfBytes = totalOfBytes + packet->size;
|
|
|
totalOfPackets = totalOfPackets + 1;
|
|
|
this->UI->totalOfBytesHasChanged(totalOfBytes);
|
|
|
this->UI->totalOfPacketsHasChanged(totalOfPackets);
|
|
|
preProcessPacket(packet);
|
|
|
}
|
|
|
|
|
|
void MainWindow::preProcessPacket(TMPacketToRead *packet)
|
|
|
{
|
|
|
unsigned char pid = 0;
|
|
|
unsigned char cat = 0;
|
|
|
unsigned char typ = 0;
|
|
|
unsigned char sub = 0;
|
|
|
unsigned int sid = 0;
|
|
|
unsigned int length = 0;
|
|
|
unsigned int coarse_t = 0;
|
|
|
unsigned int fine_t = 0;
|
|
|
|
|
|
//*********************************
|
|
|
// get the parameters of the packet
|
|
|
pid = this->UI->tmStatistics->getPID( packet );
|
|
|
cat = this->UI->tmStatistics->getCAT( packet );
|
|
|
typ = this->UI->tmStatistics->getTYPE( packet );
|
|
|
sub = this->UI->tmStatistics->getSUBTYPE( packet );
|
|
|
length = this->UI->tmStatistics->getLENGTH( packet );
|
|
|
coarse_t = this->UI->tmStatistics->getCoarseTime( packet );
|
|
|
fine_t = this->UI->tmStatistics->getFineTime( packet );
|
|
|
sid = this->UI->tmStatistics->getSID( packet, pid, cat, typ, sub );
|
|
|
|
|
|
this->UI->tmStatistics->updateStatistics(pid, cat, typ, sub, sid, length, coarse_t, fine_t);
|
|
|
|
|
|
// compare length in the packet with the size of the packet
|
|
|
if ( (length + 1 + 10) != (packet->size))
|
|
|
{
|
|
|
displayOnConsole("reception of " + QString::number(packet->size)
|
|
|
+ " bytes instead of " + QString::number(length + 1 + 10));
|
|
|
}
|
|
|
|
|
|
//***************************************************
|
|
|
// if the packet is an HK packet, display its content
|
|
|
if ( (pid == TM_PACKET_PID_DEFAULT) & (cat == TM_PACKET_CAT_HK)
|
|
|
& (typ == TM_TYPE_HK) & (sub == TM_SUBTYPE_HK) )
|
|
|
{
|
|
|
this->UI->hkDisplay->displayPacket(packet);
|
|
|
}
|
|
|
|
|
|
//**************************************************************
|
|
|
// if the packet is a parameter dump packet, display its content
|
|
|
if ( (pid == TM_PACKET_PID_DEFAULT) & (cat == TM_PACKET_CAT_PARAMETER_DUMP)
|
|
|
& (typ == TM_TYPE_PARAMETER_DUMP) & (sub == TM_SUBTYPE_PARAMETER_DUMP) )
|
|
|
{
|
|
|
this->UI->parameterDump->updateParameterDump(packet);
|
|
|
}
|
|
|
|
|
|
//****************************************
|
|
|
// if the packet is a waveform, display it
|
|
|
if ( (typ == TM_TYPE_LFR_SCIENCE) & (sub == TM_SUBTYPE_LFR_SCIENCE) )
|
|
|
{
|
|
|
//sid = packet->Value[20]; // SID
|
|
|
switch (sid){
|
|
|
case SID_NORMAL_SWF_F0:
|
|
|
buildWFAndDisplay_SWF(packet, wfPacketNormal[0], 0);
|
|
|
break;
|
|
|
case SID_NORMAL_SWF_F1:
|
|
|
buildWFAndDisplay_SWF(packet, wfPacketNormal[1], 1);
|
|
|
break;
|
|
|
case SID_NORMAL_SWF_F2:
|
|
|
buildWFAndDisplay_SWF(packet, wfPacketNormal[2], 2);
|
|
|
break;
|
|
|
case SID_NORMAL_CWF_F3:
|
|
|
buildWFAndDisplay_CWF_F3_light(packet, wfPacketCWF_F3);
|
|
|
break;
|
|
|
case SID_NORMAL_CWF_LONG_F3:
|
|
|
buildWFAndDisplay_CWF_LONG_F3(packet, wfPacketCWF_F3);
|
|
|
break;
|
|
|
case SID_BURST_CWF_F2:
|
|
|
buildWFAndDisplay_CWF_F2(packet, wfPacketBurst);
|
|
|
break;
|
|
|
case SID_SBM1_CWF_F1:
|
|
|
buildWFAndDisplay_CWF_F1(packet, wfPacketSBM1);
|
|
|
break;
|
|
|
case SID_SBM2_CWF_F2:
|
|
|
buildWFAndDisplay_CWF_F2(packet, wfPacketSBM2);
|
|
|
break;
|
|
|
case SID_NORMAL_ASM_F0:
|
|
|
build_ASM_AndDisplay_NORM_F0(packet, spectraPacketNormalSpectrumF0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//******************
|
|
|
// general functions
|
|
|
|
|
|
void MainWindow::readSettings()
|
|
|
{
|
|
|
QSettings settings("lpp", "lfrsgse");
|
|
|
echoBridgeIP0 = (unsigned char) settings.value("echoBridgeIP0", 127).toInt();
|
|
|
echoBridgeIP1 = (unsigned char) settings.value("echoBridgeIP1", 0).toInt();
|
|
|
echoBridgeIP2 = (unsigned char) settings.value("echoBridgeIP2", 0).toInt();
|
|
|
echoBridgeIP3 = (unsigned char) settings.value("echoBridgeIP3", 1).toInt();
|
|
|
}
|
|
|
|
|
|
void MainWindow::writeSettings()
|
|
|
{
|
|
|
QSettings settings("lpp", "lfrsgse");
|
|
|
settings.setValue("echoBridgeIP0", this->UI->serverTMEchoDialogBox->get_addressPart1());
|
|
|
settings.setValue("echoBridgeIP1", this->UI->serverTMEchoDialogBox->get_addressPart2());
|
|
|
settings.setValue("echoBridgeIP2", this->UI->serverTMEchoDialogBox->get_addressPart3());
|
|
|
settings.setValue("echoBridgeIP3", this->UI->serverTMEchoDialogBox->get_addressPart4());
|
|
|
}
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *)
|
|
|
{
|
|
|
writeSettings();
|
|
|
}
|
|
|
|