rmappluginui.cpp
240 lines
| 10.7 KiB
| text/x-c
|
CppLexer
/ rmapplugin / rmappluginui.cpp
r0 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the LPPMON Software | ||||
-- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
#include "rmapplugin.h" | ||||
rmapPluginUI::rmapPluginUI(QWidget *parent) : | ||||
QWidget(parent) | ||||
{ | ||||
spectralMatricesDMASimulator = new SpectralMatricesDMASimulator; | ||||
spwTabWidget = new QTabWidget; | ||||
QWidget* spwTabWidgetPage0 = new QWidget; | ||||
QWidget* spwTabWidgetPage1 = new QWidget; | ||||
QWidget* spwTabWidgetPage2 = new QWidget; | ||||
QWidget* spwTabWidgetPage3 = new QWidget; | ||||
QWidget* spwTabWidgetPage4 = new QWidget; | ||||
QWidget* spwTabWidgetPage5 = new QWidget; | ||||
mainLayout = new QVBoxLayout; | ||||
connectionLayout = new QGridLayout; | ||||
ccsdsLayout = new QVBoxLayout; | ||||
consoleLayout = new QVBoxLayout; | ||||
//*** 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: ")); | ||||
rmapTargetLogicalAddressLabel = new QLabel(tr("RMAP Target Logical Address: ")); | ||||
rmapSendStateLabel = new QLabel(tr("RMAP Send Socket State: waiting for connection")); | ||||
rmapReceiveStateLabel = new QLabel(tr("RMAP Receive Socket State: waiting for connection")); | ||||
logFileName = new QLabel; | ||||
gresbStatusQueryLabel = new QLabel(tr("GRESB status query socket (port 3010): waiting for connection")); | ||||
gresbStatusQueryDialogLabel = new QLabel(tr("sockets opened but SpaceWire link not running")); | ||||
sendCCSDSCommandLabel = new QLabel(tr("Address of the target")); | ||||
//*** QPUSHBUTTON ***// | ||||
rmapOpenCommunicationButton = new QPushButton(tr("Open RMAP Communication")); | ||||
rmapCloseCommunicationButton = new QPushButton(tr("Close RMAP Communication")); | ||||
rmapCloseCommunicationButton->setEnabled(false); | ||||
logFileChooseButton = new QPushButton(tr("Choose file")); | ||||
gresbStatusQueryRetryButton = new QPushButton(tr("Retry")); | ||||
gresbStatusQueryAbortButton = new QPushButton(tr("Abort")); | ||||
sendCCSDSCommandButton = new QPushButton(tr("Send CCSDS Command")); | ||||
send_TC_LFR_UPDATE_TIME_Button = new QPushButton(tr("Send TC_LFR_UPDATE_TIME Packet")); | ||||
reset_TC_LFR_UPDATE_TIME_Button = new QPushButton(tr("reset the TC_LFR_UPDATE_TIME Packet coarse and fine times")); | ||||
clearConsoleButton = new QPushButton(tr("Clear")); | ||||
//*** SPINBOX ***// | ||||
gresbVirtualLinkSpinBox = new QSpinBox; | ||||
rmapSourceLogicalAddressSpinBox = new QSpinBox; | ||||
rmapTargetLogicalAddressSpinBox = new QSpinBox; | ||||
spwLinkSpinBox = new QSpinBox;; | ||||
CCSDSTargetLogicalAddressSpinBox = new QSpinBox; | ||||
gresbVirtualLinkSpinBox->setRange(0, 4); | ||||
gresbVirtualLinkSpinBox->setValue(1); | ||||
rmapSourceLogicalAddressSpinBox->setRange(0, 255); | ||||
rmapSourceLogicalAddressSpinBox->setValue(33); | ||||
rmapTargetLogicalAddressSpinBox->setRange(0, 255); | ||||
rmapTargetLogicalAddressSpinBox->setValue(254); | ||||
spwLinkSpinBox->setRange(0, 2); | ||||
spwLinkSpinBox->setValue(0); | ||||
CCSDSTargetLogicalAddressSpinBox->setRange(0,255); | ||||
CCSDSTargetLogicalAddressSpinBox->setValue(254); | ||||
//*** MISC **// | ||||
starDundee = new StarDundee; | ||||
console = new QTextEdit; | ||||
gresbBridgeIPDialogBox = new QIPDialogBox; | ||||
gresbStatusQueryDialog = new QDialog; | ||||
logEnableCheckBox = new QCheckBox(tr("Enable Logs")); | ||||
RMAP_write_verify = new QCheckBox(tr("data checked before write\nlimited to 4 bytes\nNOT IMPLEMENTED")); | ||||
RMAP_write_reply = new QCheckBox(tr("reply to the write command required\nlast reply status: unavailable")); | ||||
spwLinkStatusEnquiry = new gresbStatusEnquiry; | ||||
logFile = new QFile(); | ||||
logFileEn = false; | ||||
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(rmapSourceLogicalAddressLabel, 2, 0, 0); | ||||
connectionLayout->addWidget(rmapSourceLogicalAddressSpinBox, 2, 1, 0); | ||||
connectionLayout->addWidget(spwLinkLabel, 3, 0, 0); | ||||
connectionLayout->addWidget(spwLinkSpinBox, 3, 1, 0); | ||||
connectionLayout->addWidget(rmapTargetLogicalAddressLabel, 4, 0, 0); | ||||
connectionLayout->addWidget(rmapTargetLogicalAddressSpinBox, 4, 1, 0); | ||||
connectionLayout->addWidget(rmapOpenCommunicationButton, 5, 0, 1, 2); | ||||
connectionLayout->addWidget(rmapCloseCommunicationButton, 6, 0, 1, 2); | ||||
connectionLayout->addWidget(rmapSendStateLabel, 7, 0, 1, 2); | ||||
connectionLayout->addWidget(rmapReceiveStateLabel, 8, 0, 1, 2); | ||||
connectionLayout->addWidget(gresbStatusQueryLabel, 9, 0, 1, 2); | ||||
connectionLayout->addWidget(logEnableCheckBox, 10, 0, 0); | ||||
connectionLayout->addWidget(logFileChooseButton, 10, 1, 0); | ||||
connectionLayout->addWidget(RMAP_write_verify, 11, 0, 1, 2); | ||||
connectionLayout->addWidget(RMAP_write_reply, 12, 0, 1, 2); | ||||
connectionLayout->setRowStretch(13, 1); | ||||
connectionLayout->setColumnStretch(2, 1); | ||||
ccsdsLayout->addWidget(sendCCSDSCommandButton); | ||||
ccsdsLayout->addWidget(send_TC_LFR_UPDATE_TIME_Button); | ||||
ccsdsLayout->addWidget(reset_TC_LFR_UPDATE_TIME_Button); | ||||
ccsdsLayout->addWidget(sendCCSDSCommandLabel); | ||||
ccsdsLayout->addWidget(CCSDSTargetLogicalAddressSpinBox); | ||||
consoleLayout->addWidget(console); | ||||
consoleLayout->addWidget(clearConsoleButton); | ||||
connect(this->logFileChooseButton, SIGNAL(clicked()), this, SLOT(chooseLogFile())); | ||||
connect(this, SIGNAL(setLogFileName(QString)), this->logFileName, SLOT(setText(QString))); | ||||
connect(this->logEnableCheckBox, SIGNAL(stateChanged(int)), this, SLOT(logFileEnDisable(int))); | ||||
spwTabWidget->addTab(spwTabWidgetPage0, tr("connection")); | ||||
spwTabWidget->addTab(spwTabWidgetPage1, tr("ccsds")); | ||||
spwTabWidget->addTab(spwTabWidgetPage2, tr("status")); | ||||
spwTabWidget->addTab(spwTabWidgetPage3, tr("console")); | ||||
spwTabWidget->addTab(spwTabWidgetPage4, tr("DMA")); | ||||
spwTabWidget->addTab(spwTabWidgetPage5, tr("Star Dundee")); | ||||
spwTabWidgetPage0->setLayout(connectionLayout); | ||||
spwTabWidgetPage1->setLayout(ccsdsLayout); | ||||
spwTabWidgetPage2->setLayout(this->spwLinkStatusEnquiry->mainLayout); | ||||
spwTabWidgetPage3->setLayout(consoleLayout); | ||||
spwTabWidgetPage4->setLayout(spectralMatricesDMASimulator->mainLayout); | ||||
spwTabWidgetPage5->setLayout(starDundee->layout()); | ||||
mainLayout->addWidget(spwTabWidget); | ||||
setLayout(mainLayout); | ||||
// 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); | ||||
connect(gresbStatusQueryAbortButton, SIGNAL(clicked()), gresbStatusQueryDialog, SLOT(reject())); | ||||
connect(this->clearConsoleButton, SIGNAL(clicked()), this->console, SLOT(clear())); | ||||
} | ||||
void rmapPluginUI::connectPort() | ||||
{ | ||||
//emit this->connectPortsig(ui->PortName->text(),ui->PortspeedSlider->value()); | ||||
} | ||||
void rmapPluginUI::setConnected(bool connected) | ||||
{ | ||||
/*if(connected == true) | ||||
{ | ||||
ui->OpenPort->setText(tr("Close port")); | ||||
} | ||||
else | ||||
ui->OpenPort->setText(tr("Open port"));*/ | ||||
} | ||||
rmapPluginUI::~rmapPluginUI() | ||||
{ | ||||
//delete ui; | ||||
} | ||||
void rmapPluginUI::chooseLogFile() | ||||
{ | ||||
if(this->logFile->isOpen()) | ||||
this->logFile->close(); | ||||
this->logFile->setFileName(QFileDialog::getSaveFileName(this,tr("Open Log file"), | ||||
QDir::homePath() | ||||
+ "/" | ||||
+ QDate::currentDate().toString() | ||||
+ "_" | ||||
+ QTime::currentTime().toString() | ||||
+ "_rmapPluginUI.log", | ||||
tr("Log Files (*.txt *.log)"))); | ||||
if(this->logFile->open(QIODevice::WriteOnly)) | ||||
{ | ||||
this->logFileStrm = new QTextStream(this->logFile); | ||||
emit this->setLogFileName(this->logFile->fileName()); | ||||
} | ||||
} | ||||
void rmapPluginUI::logFileEnDisable(int state) | ||||
{ | ||||
if(state==Qt::Checked) | ||||
{ | ||||
this->logFileEn = true; | ||||
} | ||||
else if(state==Qt::Unchecked) | ||||
{ | ||||
this->logFileEn = false; | ||||
} | ||||
} | ||||
bool rmapPluginUI::islogfileenable() | ||||
{ | ||||
return this->logFileEn; | ||||
} | ||||
void rmapPluginUI::appendToLogFile(const QString & text) | ||||
{ | ||||
if(this->logFileEn && this->logFile->isOpen()) | ||||
{ | ||||
*(this->logFileStrm) << text << endl; | ||||
} | ||||
} | ||||
void rmapPluginUI::closeEvent(QCloseEvent *event) | ||||
{ | ||||
if(this->logFile->isOpen()) | ||||
{ | ||||
this->logFileStrm->flush(); | ||||
this->logFile->waitForBytesWritten(3000); | ||||
this->logFile->close(); | ||||
} | ||||
event->accept(); | ||||
} | ||||
RMAP_command_codes rmapPluginUI::getCommandCode() | ||||
{ | ||||
if (RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) return writeSingle_ver_rep; | ||||
if (RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) return writeSingle_ver_noRep; | ||||
if (!RMAP_write_verify->isChecked() and RMAP_write_reply->isChecked()) return writeSingle_noVer_Rep; | ||||
if (!RMAP_write_verify->isChecked() and !RMAP_write_reply->isChecked()) return writeSingle_noVer_noRep; | ||||
else return invalid0; | ||||
} | ||||