|
|
#include "gresb.h"
|
|
|
#include <QTime>
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
gresb::gresb(QWidget *parent) :
|
|
|
QWidget(parent)
|
|
|
{
|
|
|
RMAPSend_SOCKET = new QTcpSocket;
|
|
|
RMAPReceive_SOCKET = new QTcpSocket;
|
|
|
GRESBStatusQuery_SOCKET = new QTcpSocket;
|
|
|
spwPacketReceiverOBJECT = new spwpacketreceiver;
|
|
|
spwPacketReceiverOBJECT->gresbReceptionSocket = RMAPReceive_SOCKET;
|
|
|
|
|
|
//*** QLABEL ***//
|
|
|
gresbBridgeIPLabel = new QLabel(tr("GRESB Bridge IP: "));
|
|
|
gresbVirtualLinkLabel = new QLabel(tr("GRESB Virtual Link: "));
|
|
|
spwLinkLabel = new QLabel(tr("GRESB SPW Link: "));
|
|
|
rmapSourceLogicalAddressLabel = new QLabel(tr("RMAP Source Logical Address: "));
|
|
|
rmapSendStateLabel = new QLabel(tr("RMAP Send Socket State: waiting for connection"));
|
|
|
rmapReceiveStateLabel = new QLabel(tr("RMAP Receive Socket State: waiting for connection"));
|
|
|
gresbStatusQueryLabel = new QLabel(tr("GRESB status query socket (port 3010): waiting for connection"));
|
|
|
gresbStatusQueryDialogLabel = new QLabel(tr("sockets opened but SpaceWire link not running"));
|
|
|
|
|
|
//*** SPINBOX ***//
|
|
|
gresbVirtualLinkSpinBox = new QSpinBox;
|
|
|
rmapSourceLogicalAddressSpinBox = new QSpinBox;
|
|
|
spwLinkSpinBox = new QSpinBox;;
|
|
|
gresbVirtualLinkSpinBox->setRange(0, 4);
|
|
|
gresbVirtualLinkSpinBox->setValue(1);
|
|
|
rmapSourceLogicalAddressSpinBox->setRange(0, 255);
|
|
|
rmapSourceLogicalAddressSpinBox->setValue(33);
|
|
|
spwLinkSpinBox->setRange(0, 2);
|
|
|
spwLinkSpinBox->setValue(0);
|
|
|
|
|
|
//*** QPUSHBUTTON ***//
|
|
|
gresbStatusQueryRetryButton = new QPushButton(tr("Retry"));
|
|
|
gresbStatusQueryAbortButton = new QPushButton(tr("Abort"));
|
|
|
|
|
|
//*** LAYOUT ***//
|
|
|
connectionLayout = new QGridLayout;
|
|
|
|
|
|
//*** MISC ***//
|
|
|
gresbStatusQueryDialog = new QDialog;
|
|
|
gresbBridgeIPDialogBox = new QIPDialogBox;
|
|
|
spwLinkStatusEnquiry = new gresbStatusEnquiry;
|
|
|
|
|
|
connectionLayout->addWidget(gresbBridgeIPLabel, 0, 0, 0);
|
|
|
connectionLayout->addWidget(gresbBridgeIPDialogBox, 0, 1, 0);
|
|
|
connectionLayout->addWidget(gresbVirtualLinkLabel, 1, 0, 0);
|
|
|
connectionLayout->addWidget(gresbVirtualLinkSpinBox, 1, 1, 0);
|
|
|
connectionLayout->addWidget(spwLinkLabel, 2, 0, 0);
|
|
|
connectionLayout->addWidget(spwLinkSpinBox, 2, 1, 0);
|
|
|
connectionLayout->addWidget(rmapSourceLogicalAddressLabel, 3, 0, 0);
|
|
|
connectionLayout->addWidget(rmapSourceLogicalAddressSpinBox, 3, 1, 0);
|
|
|
connectionLayout->addWidget(rmapSendStateLabel, 4, 0, 1, 2);
|
|
|
connectionLayout->addWidget(rmapReceiveStateLabel, 5, 0, 1, 2);
|
|
|
connectionLayout->addWidget(gresbStatusQueryLabel, 6, 0, 1, 2);
|
|
|
|
|
|
connectionLayout->setRowStretch(7, 1);
|
|
|
connectionLayout->setColumnStretch(2, 1);
|
|
|
|
|
|
// GRESB STATUS QUERY DIALOG
|
|
|
gresbStatusQueryDialogLayout = new QGridLayout;
|
|
|
gresbStatusQueryDialogLayout->addWidget(gresbStatusQueryDialogLabel, 0, 0, 1, 2);
|
|
|
gresbStatusQueryDialogLayout->addWidget(gresbStatusQueryRetryButton, 1, 0, 0);
|
|
|
gresbStatusQueryDialogLayout->addWidget(gresbStatusQueryAbortButton, 1, 1, 0);
|
|
|
gresbStatusQueryDialog->setLayout(gresbStatusQueryDialogLayout);
|
|
|
|
|
|
this->setLayout(connectionLayout);
|
|
|
|
|
|
connect(gresbStatusQueryAbortButton, SIGNAL(clicked()), gresbStatusQueryDialog, SLOT(reject()));
|
|
|
}
|
|
|
|
|
|
void gresb::Open() // SLOT
|
|
|
{
|
|
|
bool spwRunning = true;
|
|
|
RMAPSend_SOCKET->connectToHost( QHostAddress(gresbBridgeIPDialogBox->getGRESBIP()),
|
|
|
3000 + gresbVirtualLinkSpinBox->value()*2,
|
|
|
QIODevice::WriteOnly);
|
|
|
RMAPReceive_SOCKET->connectToHost( QHostAddress(gresbBridgeIPDialogBox->getGRESBIP()),
|
|
|
3000 + gresbVirtualLinkSpinBox->value()*2+1,
|
|
|
QIODevice::ReadOnly);
|
|
|
GRESBStatusQuery_SOCKET->connectToHost( QHostAddress(gresbBridgeIPDialogBox->getGRESBIP()),
|
|
|
3010,
|
|
|
QIODevice::ReadWrite);
|
|
|
GRESBStatusQuery_SOCKET->waitForConnected(10000);
|
|
|
RMAPReceive_SOCKET->readAll(); // read all remaining data from the reception socket
|
|
|
// initialize SPW packet semaphores
|
|
|
while (spwPacketReceiverOBJECT->rmapPacketSEMAPHORE->available()!=0) spwPacketReceiverOBJECT->rmapPacketSEMAPHORE->acquire();
|
|
|
while (spwPacketReceiverOBJECT->ccsdsPacketSEMAPHORE->available()!=0) spwPacketReceiverOBJECT->ccsdsPacketSEMAPHORE->acquire();
|
|
|
if (GRESBStatusQueryRequest(LinkStatus, spwLinkSpinBox->value()) != 0)
|
|
|
{
|
|
|
spwRunning = gresbStatusQueryDialog->exec();
|
|
|
}
|
|
|
if (spwRunning == false) this->Close();
|
|
|
else
|
|
|
{
|
|
|
emit appendToLog(QString("SpaceWire running on virtual link ")+ QString::number(spwLinkSpinBox->value()));
|
|
|
emit isOpen(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void gresb::Close() // SLOT
|
|
|
{
|
|
|
RMAPSend_SOCKET->disconnectFromHost();
|
|
|
RMAPReceive_SOCKET->disconnectFromHost();
|
|
|
GRESBStatusQuery_SOCKET->disconnectFromHost();
|
|
|
emit isOpen(false);
|
|
|
}
|
|
|
|
|
|
int gresb::GRESBStatusQuery() // SLOT
|
|
|
{
|
|
|
GRESBStatusQueryRequest(LinkStatus, 0);
|
|
|
GRESBStatusQueryRequest(LinkStatus, 1);
|
|
|
GRESBStatusQueryRequest(LinkStatus, 2);
|
|
|
GRESBStatusQueryRequest(LinkStatistics, 0);
|
|
|
GRESBStatusQueryRequest(LinkStatistics, 1);
|
|
|
GRESBStatusQueryRequest(LinkStatistics, 2);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int gresb::GRESBStatusQueryRequest(GresbStatusQueryOption option, char link)
|
|
|
{
|
|
|
gresb_status_query_t statusQueryCommand;
|
|
|
gresb_link_status_reply_t linkStatusReply;
|
|
|
gresb_link_statistics_reply_t linkStatisticsReply;
|
|
|
QTime statusQueryTimeout;
|
|
|
QString console_message;
|
|
|
|
|
|
statusQueryCommand.protocolIdentifier = (char) 0x02;
|
|
|
statusQueryCommand.reserved1 = (char) 0x00;
|
|
|
statusQueryCommand.reserved0 = (char) 0x00;
|
|
|
statusQueryCommand.option = (char) option;
|
|
|
statusQueryCommand.value3 = (char) 0x00;
|
|
|
statusQueryCommand.value2 = (char) 0x00;
|
|
|
statusQueryCommand.value1 = (char) 0x00;
|
|
|
statusQueryCommand.value0 = (char) link;
|
|
|
|
|
|
GRESBStatusQuery_SOCKET->write((char*) ((void*) &statusQueryCommand), sizeof(statusQueryCommand));
|
|
|
GRESBStatusQuery_SOCKET->flush();
|
|
|
GRESBStatusQuery_SOCKET->waitForBytesWritten(1000);
|
|
|
|
|
|
statusQueryTimeout.start();
|
|
|
while(GRESBStatusQuery_SOCKET->bytesToWrite() > 0)
|
|
|
{
|
|
|
GRESBStatusQuery_SOCKET->waitForBytesWritten(100);
|
|
|
if(statusQueryTimeout.elapsed()>1000)
|
|
|
{
|
|
|
emit appendToLog("WARNING === in function GRESBStatusQueryRequest of rmapplugin *** sending StatusQueryCommand timeout");
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
switch (option)
|
|
|
{
|
|
|
case LinkStatus:
|
|
|
{
|
|
|
statusQueryTimeout.start();
|
|
|
while(GRESBStatusQuery_SOCKET->bytesAvailable() < (int) sizeof(linkStatusReply))
|
|
|
{
|
|
|
GRESBStatusQuery_SOCKET->waitForReadyRead(100);
|
|
|
if(statusQueryTimeout.elapsed()>1000)
|
|
|
{
|
|
|
console_message.sprintf("GRESBStatusQueryRequest / LinkStatus => error timeout bytesAvailable()\n");
|
|
|
emit appendToLog(console_message);
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
GRESBStatusQuery_SOCKET->read((char*) ((void*) &linkStatusReply), (int) sizeof(linkStatusReply));
|
|
|
console_message.sprintf("%x", linkStatusReply.byte0);
|
|
|
spwLinkStatusEnquiry->statusQueryTable->item(0, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", linkStatusReply.byte1);
|
|
|
spwLinkStatusEnquiry->statusQueryTable->item(1, link)->setText(console_message);
|
|
|
if (linkStatusReply.byte0 == 0) return 1;
|
|
|
break;
|
|
|
}
|
|
|
case LinkStatistics:
|
|
|
{
|
|
|
statusQueryTimeout.start();
|
|
|
while(GRESBStatusQuery_SOCKET->bytesAvailable() < (int) sizeof(linkStatisticsReply))
|
|
|
{
|
|
|
GRESBStatusQuery_SOCKET->waitForReadyRead(100);
|
|
|
if(statusQueryTimeout.elapsed()>1000)
|
|
|
{
|
|
|
console_message.sprintf("GRESBStatusQueryRequest / LinkStatistics => error timeout bytesAvailable()\n");
|
|
|
emit appendToLog(console_message);
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
GRESBStatusQuery_SOCKET->read((char*) ((void*) &linkStatisticsReply), sizeof(linkStatisticsReply));
|
|
|
/*console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.sizeOfDataTransmitted));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(9, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.numberOfPacketsTransmitted));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(8, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.numberOfTruncatedPacketsReceived));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(6, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.numberOfPacketsWithEEPReceived));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(5, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.sizeOfDataReceived));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(4, link)->setText(console_message);
|
|
|
console_message.sprintf("%d", charTab_TO_int(linkStatisticsReply.numberOfPacketsReceived));
|
|
|
UI->spwLinkStatusEnquiry->statusQueryTable->item(3, link)->setText(console_message);*/
|
|
|
break;
|
|
|
}
|
|
|
case NodeAddressStatistics:
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
case GetRoute:
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|