mainwindow.cpp
723 lines
| 27.9 KiB
| text/x-c
|
CppLexer
/ gse_lesia / mainwindow.cpp
r23 | #include "mainwindow.h" | |||
#include <iostream> | ||||
#include <QNetworkInterface> | ||||
MainWindow::MainWindow(QWidget *parent) | ||||
r39 | : QMainWindow(parent) | |||
r23 | { | |||
r24 | parsingContinue = false; | |||
r23 | totalOfBytes = 0; | |||
r24 | totalOfPackets = 0; | |||
r23 | ||||
r60 | spectraPacketNormalSpectrumF0 = new SpectraPacket(0, 128); | |||
r45 | ||||
r58 | //********* | |||
// wfPacket | ||||
wfPacketNormal[0] = new WFPacket(0, 2048); | ||||
wfPacketNormal[1] = new WFPacket(0, 2048); | ||||
wfPacketNormal[2] = new WFPacket(0, 2048); | ||||
r59 | 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); | ||||
r58 | ||||
r24 | //**** | |||
// XML | ||||
// xml handlers | ||||
r23 | xmlHandler = new LFRXmlHandler(); | |||
r24 | // xml sources | |||
sourceTC = new QXmlInputSource(); | ||||
// xml writer | ||||
r23 | lfrXmlWriter = new LFRXmlWriter(); | |||
r24 | // setup xml parser for the echo bridge | |||
lfrXmlParser = new LFRXmlParser(); | ||||
r23 | ||||
UI = new MainWindowUI(); | ||||
r28 | readSettings(); | |||
this->UI->serverTMEchoDialogBox->setIP(echoBridgeIP0, echoBridgeIP1, echoBridgeIP2, echoBridgeIP3); | ||||
r23 | ||||
r27 | lfrXmlParser->generalCCSDSPacketStore = &this->generalCCSDSPacketStore; | |||
r23 | initSocketStatesList(); | |||
r39 | this->setCentralWidget(this->UI); | |||
//this->setLayout(UI->layout()); | ||||
r23 | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r34 | analyserSGSEServerTC = new QTcpServer(); | ||
analyserSGSEServerTM = new QTcpServer(); | ||||
socketTC = NULL; | ||||
socketTM = NULL; | ||||
socketEchoServer = new QTcpSocket(); | ||||
r23 | 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())); | ||||
r24 | ||||
// socket echo server | ||||
r23 | connect(this->socketEchoServer, SIGNAL(stateChanged(QAbstractSocket::SocketState)), | |||
this, SLOT(socket_TMEcho_ServerHasChanged())); | ||||
connect(this->socketEchoServer, SIGNAL(readyRead()), | ||||
this, SLOT(readDataOnSocketEchoServer())); | ||||
r24 | ||||
// 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))); | ||||
r23 | // | |||
r27 | connect(this->lfrXmlParser, SIGNAL(processPacketStore()), | |||
this, SLOT(processPacketStore())); | ||||
r24 | // | |||
connect(this->UI->button_resetStatistics, SIGNAL(clicked()), | ||||
this, SLOT(resetStatistics())); | ||||
r23 | ||||
displayNetworkInterfaces(); | ||||
this->xmlHandler->packetStoreHasChanged(&generalCCSDSPacketStore); | ||||
r24 | }; | |||
r23 | ||||
MainWindow::~MainWindow() | ||||
{ | ||||
r58 | delete wfPacketNormal[0]; | |||
delete wfPacketNormal[1]; | ||||
delete wfPacketNormal[2]; | ||||
delete wfPacketNormal[3]; | ||||
delete wfPacketBurst; | ||||
delete wfPacketSBM1; | ||||
delete wfPacketSBM2; | ||||
r59 | delete wfPacketCWF_F3; | |||
r23 | } | |||
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() | ||||
{ | ||||
r24 | QString dataString; | |||
r23 | ||||
r24 | dataArray.append(socketEchoServer->readAll()); | |||
r57 | // dataString = QString::fromAscii(dataArray); | |||
dataString = QString::fromLatin1(dataArray); | ||||
r24 | this->lfrXmlParser->processIncomingStr(dataString); | |||
dataArray.clear(); | ||||
r23 | } | |||
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()) ); | ||||
} | ||||
r58 | void MainWindow::buildWFAndDisplay_SWF(TMPacketToRead *packet, WFPacket *wfPacket, unsigned char num_page) | |||
r23 | { | |||
unsigned int i = 0; | ||||
r62 | static unsigned int nbSamples = 0; | |||
r23 | unsigned char *data; | |||
r62 | unsigned char pa_lfr_pkt_cnt; | |||
r58 | unsigned char pa_lfr_pkt_nr; | |||
unsigned int pa_lfr_swf_blk_nr = 0; | ||||
r59 | double deltaT; | |||
r23 | ||||
r58 | 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; | ||||
} | ||||
r62 | pa_lfr_pkt_cnt = packet->Value[22]; | |||
r58 | 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 | ||||
r27 | data = &packet->Value[32]; // start of the first data block; | |||
r58 | ||||
if (pa_lfr_pkt_nr == 1) // the acquisition time of the first packet of the snapshot is taken as starting time | ||||
{ | ||||
r62 | nbSamples = 0; | |||
wfPacket->coarseTime = ((packet->Value[24] & 0x7f) << 24) | ||||
r58 | + (packet->Value[25] << 16) | |||
+ (packet->Value[26] << 8) | ||||
+ packet->Value[27]; | ||||
r62 | wfPacket->fineTime = (packet->Value[28] << 8) + packet->Value[29]; | |||
r58 | } | |||
for ( i=0; i<pa_lfr_swf_blk_nr; i++ ){ | ||||
r62 | 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]) ); | ||||
r23 | } | |||
r62 | ||||
nbSamples = nbSamples + pa_lfr_swf_blk_nr; | ||||
if (pa_lfr_pkt_nr == pa_lfr_pkt_cnt) | ||||
r23 | { | |||
r62 | 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); | ||||
r23 | } | |||
} | ||||
r59 | void MainWindow::buildWFAndDisplay_CWF_LONG_F3(TMPacketToRead *packet, WFPacket *wfPacket) | |||
r46 | { | |||
unsigned int i = 0; | ||||
unsigned int j = 0; | ||||
unsigned char *data; | ||||
static unsigned char pkt_nr = 1; | ||||
unsigned int blk_nr = 0; | ||||
r59 | static unsigned int coarseTime; | |||
static unsigned int fineTime; | ||||
unsigned int tmpCoarseTime; | ||||
unsigned int tmpFineTime; | ||||
double deltaT; | ||||
double DELTA; | ||||
r58 | unsigned int nbData; | |||
r46 | ||||
r59 | deltaT = 1 / 16.; | |||
r58 | ||||
r59 | 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) ); | ||||
} | ||||
r58 | blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWFL3_BLK_NR | |||
r46 | data = &packet->Value[30]; // start of the first data block; | |||
r58 | ||||
r62 | j = (pkt_nr-1) * blk_nr; | |||
r46 | for ( i=0; i<blk_nr; i++ ){ | |||
r52 | 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]) ); | ||||
r46 | 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; | ||||
r59 | if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1)) | |||
r46 | { | |||
r58 | nbData = j + blk_nr; | |||
r59 | 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); | ||||
r52 | pkt_nr = 1; | |||
} | ||||
} | ||||
r59 | void MainWindow::buildWFAndDisplay_CWF_F3_light(TMPacketToRead *packet, WFPacket *wfPacket) | |||
r52 | { | |||
unsigned int i = 0; | ||||
unsigned int j = 0; | ||||
unsigned char *data; | ||||
static unsigned char pkt_nr = 1; | ||||
unsigned int blk_nr = 0; | ||||
r59 | static unsigned int coarseTime; | |||
static unsigned int fineTime; | ||||
unsigned int tmpCoarseTime; | ||||
unsigned int tmpFineTime; | ||||
double deltaT; | ||||
double DELTA; | ||||
r58 | unsigned int nbData; | |||
r52 | ||||
r59 | deltaT = 1 / 16.; | |||
r58 | ||||
r59 | 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) ); | ||||
} | ||||
r58 | blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWF3_BLK_NR | |||
r52 | data = &packet->Value[30]; // start of the first data block; | |||
r58 | ||||
r62 | j = (pkt_nr-1) * blk_nr; | |||
r52 | 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; | ||||
r59 | if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF_LIGHT+1)) | |||
r52 | { | |||
r58 | nbData = j + blk_nr; | |||
r59 | 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); | ||||
r46 | pkt_nr = 1; | |||
} | ||||
} | ||||
r58 | void MainWindow::buildWFAndDisplay_CWF_F1(TMPacketToRead *packet, WFPacket *wfPacket) | |||
r27 | { | |||
unsigned int i = 0; | ||||
unsigned int j = 0; | ||||
unsigned char *data; | ||||
static unsigned char pkt_nr = 1; | ||||
unsigned int blk_nr = 0; | ||||
r59 | static unsigned int coarseTime; | |||
static unsigned int fineTime; | ||||
double deltaT; | ||||
r58 | unsigned int nbData; | |||
r27 | ||||
r59 | deltaT = 1. / 4096.; | |||
r58 | ||||
r59 | 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 | ||||
r27 | data = &packet->Value[30]; // start of the first data block; | |||
r58 | ||||
r62 | j = (pkt_nr-1) * blk_nr; | |||
r27 | for ( i=0; i<blk_nr; i++ ){ | |||
r52 | 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]) ); | ||||
r59 | wfPacket->wf_b3[j + i] = (short) ( (data[ (i * BLK_SIZE) + 10] << 8) + (data[ (i*BLK_SIZE) + 11]) ); | |||
r52 | } | |||
pkt_nr = pkt_nr + 1; | ||||
r59 | if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1)) | |||
r52 | { | |||
r58 | 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); | ||||
r52 | pkt_nr = 1; | |||
} | ||||
} | ||||
r58 | void MainWindow::buildWFAndDisplay_CWF_F2(TMPacketToRead *packet, WFPacket *wfPacket) | |||
r27 | { | |||
unsigned int i = 0; | ||||
unsigned int j = 0; | ||||
unsigned char *data; | ||||
static unsigned char pkt_nr = 1; | ||||
unsigned int blk_nr = 0; | ||||
r59 | static unsigned int coarseTime; | |||
static unsigned int fineTime; | ||||
double deltaT; | ||||
r58 | unsigned int nbData; | |||
r27 | ||||
r59 | deltaT = 1. / 256.; | |||
r58 | ||||
r59 | 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]; | ||||
} | ||||
r58 | blk_nr = packet->Value[28] * 256 + packet->Value[29]; // PA_LFR_CWF3_BLK_NR | |||
r27 | data = &packet->Value[30]; // start of the first data block; | |||
r58 | ||||
r62 | j = (pkt_nr-1) * blk_nr; | |||
r27 | for ( i=0; i<blk_nr; i++ ){ | |||
r52 | 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]) ); | ||||
r46 | 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]) ); | ||||
r27 | } | |||
pkt_nr = pkt_nr + 1; | ||||
r59 | if (pkt_nr == (NB_PACKETS_PER_GROUP_OF_CWF+1)) | |||
r27 | { | |||
r58 | 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); | ||||
r27 | pkt_nr = 1; | |||
} | ||||
} | ||||
r61 | void MainWindow::build_ASM_AndDisplay_NORM_F0(TMPacketToRead *packet, SpectraPacket *spectraPacket) | |||
r45 | { | |||
r60 | unsigned int i; | |||
unsigned int j; | ||||
r45 | unsigned char *data; | |||
r60 | unsigned char *aux; | |||
unsigned char cntASM; | ||||
r45 | unsigned char nrASM; | |||
unsigned int blkNR; | ||||
r60 | double deltaF; | |||
unsigned int nbData; | ||||
r45 | ||||
r60 | cntASM = packet->Value[22]; | |||
r45 | nrASM = packet->Value[23]; | |||
blkNR = packet->Value[30] * 256 + packet->Value[31]; | ||||
r60 | ||||
r45 | data = &packet->Value[32]; // start of the first data block; | |||
j = (nrASM-1) * blkNR; | ||||
for ( i=0; i<blkNR; i++ ){ | ||||
r60 | 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 | ||||
r45 | aux[3] = data[ (i * 50 + 2*16) ]; | |||
aux[2] = data[ (i * 50 + 2*16) + 1]; | ||||
r60 | aux = (unsigned char*) &spectraPacket->s44[ j + i ]; // s44 is a table of float | |||
r45 | aux[3] = data[ (i * 50 + 2*21) ]; | |||
aux[2] = data[ (i * 50 + 2*21) + 1]; | ||||
r60 | aux = (unsigned char*) &spectraPacket->s55[ j + i ]; // s55 is a table of float | |||
r45 | aux[3] = data[ (i * 50 + 2*24) ]; | |||
aux[2] = data[ (i * 50 + 2*24) + 1]; | ||||
} | ||||
r60 | ||||
deltaF = 24576. / 256. ; | ||||
nbData = j + blkNR; | ||||
if (nrASM == cntASM) | ||||
r45 | { | |||
r60 | 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); | ||||
r45 | } | |||
} | ||||
r24 | void MainWindow::resetStatistics() | |||
{ | ||||
totalOfBytes = 0; | ||||
totalOfPackets = 0; | ||||
this->UI->totalOfBytesHasChanged(totalOfBytes); | ||||
this->UI->totalOfPacketsHasChanged(totalOfPackets); | ||||
} | ||||
r27 | ||||
r46 | //****************** | |||
// packet processing | ||||
r27 | void MainWindow::processPacketStore() | |||
{ | ||||
TMPacketToRead *packet; | ||||
while(!generalCCSDSPacketStore.isEmpty()) | ||||
{ | ||||
packet = generalCCSDSPacketStore.takeFirst(); | ||||
processIncomingPacket(packet); | ||||
delete(packet); | ||||
} | ||||
} | ||||
r28 | ||||
r46 | 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 | ||||
r52 | if ( (pid == TM_PACKET_PID_DEFAULT) & (cat == TM_PACKET_CAT_HK) | |||
& (typ == TM_TYPE_HK) & (sub == TM_SUBTYPE_HK) ) | ||||
r46 | { | |||
this->UI->hkDisplay->displayPacket(packet); | ||||
} | ||||
//************************************************************** | ||||
// if the packet is a parameter dump packet, display its content | ||||
r52 | if ( (pid == TM_PACKET_PID_DEFAULT) & (cat == TM_PACKET_CAT_PARAMETER_DUMP) | |||
& (typ == TM_TYPE_PARAMETER_DUMP) & (sub == TM_SUBTYPE_PARAMETER_DUMP) ) | ||||
r46 | { | |||
this->UI->parameterDump->updateParameterDump(packet); | ||||
} | ||||
//**************************************** | ||||
// if the packet is a waveform, display it | ||||
if ( (typ == TM_TYPE_LFR_SCIENCE) & (sub == TM_SUBTYPE_LFR_SCIENCE) ) | ||||
{ | ||||
r52 | //sid = packet->Value[20]; // SID | |||
r46 | switch (sid){ | |||
case SID_NORMAL_SWF_F0: | ||||
r58 | buildWFAndDisplay_SWF(packet, wfPacketNormal[0], 0); | |||
r46 | break; | |||
case SID_NORMAL_SWF_F1: | ||||
r58 | buildWFAndDisplay_SWF(packet, wfPacketNormal[1], 1); | |||
r46 | break; | |||
case SID_NORMAL_SWF_F2: | ||||
r58 | buildWFAndDisplay_SWF(packet, wfPacketNormal[2], 2); | |||
r46 | break; | |||
case SID_NORMAL_CWF_F3: | ||||
r59 | buildWFAndDisplay_CWF_F3_light(packet, wfPacketCWF_F3); | |||
r58 | break; | |||
case SID_NORMAL_CWF_LONG_F3: | ||||
r59 | buildWFAndDisplay_CWF_LONG_F3(packet, wfPacketCWF_F3); | |||
r46 | break; | |||
case SID_BURST_CWF_F2: | ||||
r58 | buildWFAndDisplay_CWF_F2(packet, wfPacketBurst); | |||
r46 | break; | |||
case SID_SBM1_CWF_F1: | ||||
r58 | buildWFAndDisplay_CWF_F1(packet, wfPacketSBM1); | |||
r46 | break; | |||
case SID_SBM2_CWF_F2: | ||||
r58 | buildWFAndDisplay_CWF_F2(packet, wfPacketSBM2); | |||
r46 | break; | |||
case SID_NORMAL_ASM_F0: | ||||
r61 | build_ASM_AndDisplay_NORM_F0(packet, spectraPacketNormalSpectrumF0); | |||
r46 | break; | |||
} | ||||
} | ||||
} | ||||
//****************** | ||||
// general functions | ||||
r28 | void MainWindow::readSettings() | |||
{ | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r33 | QSettings settings("lpp", "lfrsgse"); | ||
r28 | 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() | ||||
{ | ||||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r33 | 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()); | ||||
r28 | } | |||
void MainWindow::closeEvent(QCloseEvent *) | ||||
{ | ||||
writeSettings(); | ||||
} | ||||