stardundeegui.cpp
310 lines
| 9.8 KiB
| text/x-c
|
CppLexer
Jeandet Alexis
|
r22 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the SocExplorer Software | ||||
-- Copyright (C) 2014, Plasma Physics Laboratory - 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@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
#include "stardundeegui.h" | ||||
#include "ui_stardundeeGUI.h" | ||||
r63 | #include "fakestardundeespwusb_lib.h" | |||
Jeandet Alexis
|
r22 | |||
StarDundeeGUI::StarDundeeGUI(QWidget *parent) : | ||||
QWidget(parent),ui(new Ui::StarDundeeUI) | ||||
{ | ||||
paul
|
r35 | resetBytesPacketsStatistics(); | ||
Jeandet Alexis
|
r22 | this->ui->setupUi(this); | ||
connect(this->ui->selectBrickCmbx,SIGNAL(currentIndexChanged(int)),this,SIGNAL(brickSelectionChanged(int))); | ||||
connect(this->ui->selectLinkCmbx,SIGNAL(currentIndexChanged(int)),this,SIGNAL(linkNumberSelectionChanged(int))); | ||||
connect(this->ui->setLinkSpeedCmbx,SIGNAL(currentIndexChanged(QString)),this,SIGNAL(linkSpeedSelectionChanged(QString))); | ||||
paul
|
r47 | // connect(this->ui->sourceAddressLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(destinationKeyChanged(QString))); | ||
connect(this->ui->sourceAddressLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(sourceLogicalAddressChanged(QString))); | ||||
paul
|
r38 | connect(this->ui->destinationAddressLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapAddressChanged(QString))); | ||
connect(this->ui->destinationKeyLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapKeyChanged(QString))); | ||||
Jeandet Alexis
|
r22 | connect(this->ui->RMAPTimeoutLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapTimeoutChanged(QString))); | ||
paul
|
r38 | connect(this->ui->timecodeFrequencyLineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(timecodeFrequencyChange(QString))); | ||
Jeandet Alexis
|
r22 | connect(this->ui->connectQpb,SIGNAL(clicked()),this,SIGNAL(connectClicked())); | ||
paul
|
r35 | connect(this->ui->setInterfaceModeQrb, SIGNAL(toggled(bool)), this, SIGNAL(brickModeChanged(bool))); | ||
connect(this->ui->resetStatsQpb, SIGNAL(clicked()), this, SLOT(resetStatistics())); | ||||
paul
|
r38 | connect(this->ui->spwTimecodes, SIGNAL(toggled(bool)), this, SIGNAL(startSendingTimecode(bool))); | ||
r65 | connect(this->ui->driverStatusQpb,SIGNAL(clicked(bool)),this,SLOT(showDriverStatus())); | |||
if(FakeStarDundeeSpwUSB_Lib::fullresolved()) | ||||
this->ui->driverstatuslbl->setText("<html><head/><body><p><span style=\" color:#00ff00;\">Driver loaded</span></p></body></html>"); | ||||
else | ||||
this->ui->driverstatuslbl->setText("<html><head/><body><p><span style=\" color:#ff0000;\">Driver not loaded(error!)</span></p></body></html>"); | ||||
Jeandet Alexis
|
r22 | } | ||
int StarDundeeGUI::getBrickSelection() | ||||
{ | ||||
return ui->selectBrickCmbx->currentIndex(); | ||||
} | ||||
int StarDundeeGUI::getLinkNumberSelection() | ||||
{ | ||||
return ui->selectLinkCmbx->currentIndex(); | ||||
} | ||||
QString StarDundeeGUI::getLinkSpeedSelection() | ||||
{ | ||||
return ui->setLinkSpeedCmbx->currentText(); | ||||
} | ||||
paul
|
r38 | QString StarDundeeGUI::getSourceAddress() | ||
Jeandet Alexis
|
r22 | { | ||
paul
|
r38 | return ui->sourceAddressLineEdit->text(); | ||
Jeandet Alexis
|
r22 | } | ||
paul
|
r38 | QString StarDundeeGUI::getDestinationAddress() | ||
Jeandet Alexis
|
r22 | { | ||
paul
|
r38 | return ui->destinationAddressLineEdit->text(); | ||
Jeandet Alexis
|
r22 | } | ||
paul
|
r38 | QString StarDundeeGUI::getDestinationKey() | ||
Jeandet Alexis
|
r22 | { | ||
paul
|
r38 | return ui->destinationKeyLineEdit->text(); | ||
Jeandet Alexis
|
r22 | } | ||
QString StarDundeeGUI::getRmapTimeout() | ||||
{ | ||||
return ui->RMAPTimeoutLineEdit->text(); | ||||
} | ||||
paul
|
r38 | QString StarDundeeGUI::getTimecodeFrequency() | ||
{ | ||||
return ui->timecodeFrequencyLineEdit->text(); | ||||
} | ||||
bool StarDundeeGUI::getStartSendingTimecodes() | ||||
{ | ||||
return ui->spwTimecodes->isChecked(); | ||||
} | ||||
paul
|
r35 | bool StarDundeeGUI::isBrickSetAsAnInterface() | ||
{ | ||||
return ui->setInterfaceModeQrb->isChecked(); | ||||
} | ||||
Jeandet Alexis
|
r22 | |||
r65 | void StarDundeeGUI::showDriverStatus() | |||
{ | ||||
this->driverStatus.update(); | ||||
this->driverStatus.show(); | ||||
} | ||||
paul
|
r35 | void StarDundeeGUI::setBrickAsAnInterface( bool interfaceMode ) | ||
{ | ||||
if (interfaceMode == true) | ||||
{ | ||||
this->ui->setInterfaceModeQrb->setChecked( true ); | ||||
} | ||||
else | ||||
{ | ||||
this->ui->setRouterModeQrb->setChecked( true ); | ||||
} | ||||
} | ||||
void StarDundeeGUI::setBrickAsARouter( bool interfaceMode ) | ||||
{ | ||||
if (interfaceMode==true) | ||||
{ | ||||
this->ui->setRouterModeQrb->setChecked( true ); | ||||
} | ||||
else | ||||
{ | ||||
this->ui->setInterfaceModeQrb->setChecked( true ); | ||||
} | ||||
} | ||||
Jeandet Alexis
|
r22 | |||
void StarDundeeGUI::lock(bool lock) | ||||
{ | ||||
this->ui->selectBrickCmbx->setDisabled(lock); | ||||
this->ui->selectLinkCmbx->setDisabled(lock); | ||||
this->ui->setLinkSpeedCmbx->setDisabled(lock); | ||||
paul
|
r38 | this->ui->sourceAddressLineEdit->setDisabled(lock); | ||
this->ui->destinationAddressLineEdit->setDisabled(lock); | ||||
this->ui->destinationKeyLineEdit->setDisabled(lock); | ||||
Jeandet Alexis
|
r22 | this->ui->RMAPTimeoutLineEdit->setDisabled(lock); | ||
paul
|
r35 | this->ui->setInterfaceModeQrb->setDisabled(lock); | ||
this->ui->setRouterModeQrb->setDisabled(lock); | ||||
Jeandet Alexis
|
r22 | if(lock) | ||
this->ui->connectQpb->setText("Disconnect"); | ||||
else | ||||
this->ui->connectQpb->setText("Connect"); | ||||
} | ||||
void StarDundeeGUI::updateAvailableBrickCount(int count) | ||||
{ | ||||
this->ui->selectBrickCmbx->clear(); | ||||
this->ui->selectBrickCmbx->addItem("none"); | ||||
for(int i =0;i<32;i++) | ||||
{ | ||||
if((count&1)==1) | ||||
{ | ||||
star_device_handle hDevice; | ||||
char serial[11]=""; | ||||
if (USBSpaceWire_Open(&hDevice, 0)) | ||||
{ | ||||
USBSpaceWire_GetSerialNumber(hDevice,(U8*) serial); | ||||
USBSpaceWire_Close(hDevice); | ||||
} | ||||
this->ui->selectBrickCmbx->addItem("STAR-Dundee USB brick "+QString::number(i)+" sn:" + serial); | ||||
} | ||||
count>>=1; | ||||
} | ||||
} | ||||
void StarDundeeGUI::setRmapTimeout(const QString &timeout) | ||||
{ | ||||
this->ui->RMAPTimeoutLineEdit->setText(timeout); | ||||
} | ||||
void StarDundeeGUI::selectBrick(int brickIndex) | ||||
{ | ||||
if(brickIndex>=0&& brickIndex<this->ui->selectBrickCmbx->count()) | ||||
{ | ||||
this->ui->selectBrickCmbx->setCurrentIndex(brickIndex); | ||||
} | ||||
} | ||||
void StarDundeeGUI::selectLinkNumber(int linkNumber) | ||||
{ | ||||
if(linkNumber==1 || linkNumber==2) | ||||
{ | ||||
this->ui->selectLinkCmbx->setCurrentIndex(linkNumber-1); | ||||
} | ||||
} | ||||
void StarDundeeGUI::selectLinkSpeed(int linkSpeed) | ||||
{ | ||||
#define MHz *(1000*1000) | ||||
if(linkSpeed==10 MHz) | ||||
{ | ||||
this->ui->selectLinkCmbx->setCurrentIndex(0); | ||||
} | ||||
} | ||||
paul
|
r38 | void StarDundeeGUI::setSourceAddress(const QString &address) | ||
Jeandet Alexis
|
r22 | { | ||
bool ok; | ||||
paul
|
r38 | address.toInt(&ok,10); | ||
Jeandet Alexis
|
r22 | if(ok) | ||
{ | ||||
paul
|
r38 | this->ui->sourceAddressLineEdit->setText(address); | ||
} | ||||
} | ||||
void StarDundeeGUI::setDestinationAddress(const QString &address) | ||||
{ | ||||
bool ok; | ||||
address.toInt(&ok,10); | ||||
if(ok) | ||||
{ | ||||
this->ui->destinationAddressLineEdit->setText(address); | ||||
Jeandet Alexis
|
r22 | } | ||
} | ||||
paul
|
r38 | void StarDundeeGUI::setDestinationKey(const QString &key) | ||
Jeandet Alexis
|
r22 | { | ||
bool ok; | ||||
paul
|
r38 | key.toInt(&ok,10); | ||
Jeandet Alexis
|
r22 | if(ok) | ||
{ | ||||
paul
|
r38 | this->ui->destinationKeyLineEdit->setText(key); | ||
Jeandet Alexis
|
r22 | } | ||
} | ||||
paul
|
r47 | void StarDundeeGUI::setTimecodeFrequency( double frequency ) | ||
Jeandet Alexis
|
r22 | { | ||
paul
|
r47 | this->ui->timecodeFrequencyLineEdit->setText( QString::number( frequency, 'g', 3 ) ); | ||
paul
|
r38 | } | ||
void StarDundeeGUI::setStartSendingTimecodes( bool onOff ) | ||||
{ | ||||
if (this->ui->spwTimecodes->isChecked()) | ||||
{ | ||||
if (onOff==false) this->ui->spwTimecodes->setChecked(false); | ||||
} | ||||
else | ||||
{ | ||||
if (onOff==true) this->ui->spwTimecodes->setChecked(true); | ||||
Jeandet Alexis
|
r22 | } | ||
} | ||||
paul
|
r35 | |||
int StarDundeeGUI::getAvailableBrickCount( void ) | ||||
{ | ||||
int list = USBSpaceWire_ListDevices(); | ||||
emit updateAvailableBrickCount(list); | ||||
QCoreApplication::processEvents(); | ||||
return list; | ||||
} | ||||
void StarDundeeGUI::resetBytesPacketsStatistics( void ) | ||||
{ | ||||
nbBytesReceivedFromSpw = 0; | ||||
nbBytesTransmittedToSpw = 0; | ||||
nbPacketsReceivedFromSpw = 0; | ||||
nbPacketsTransmittedToSpw = 0; | ||||
paul
|
r40 | nbCCSDSPacketsTransmittedToSpw = 0; | ||
paul
|
r35 | } | ||
void StarDundeeGUI::resetStatistics( void ) | ||||
{ | ||||
nbBytesReceivedFromSpw = 0; | ||||
nbBytesTransmittedToSpw = 0; | ||||
nbPacketsReceivedFromSpw = 0; | ||||
nbPacketsTransmittedToSpw = 0; | ||||
this->ui->starDundeeReceivedBytes->setText( QString::number(nbBytesReceivedFromSpw) ); | ||||
this->ui->starDundeeReceivedPackets->setText( QString::number(nbPacketsReceivedFromSpw) ); | ||||
this->ui->starDundeeTransmittedBytes->setText( QString::number(nbBytesTransmittedToSpw) ); | ||||
this->ui->starDundeeTransmittedPackets->setText( QString::number(nbPacketsTransmittedToSpw) ); | ||||
} | ||||
void StarDundeeGUI::updateNbReceivedBytesFromSpw( unsigned int nbBytes) | ||||
{ | ||||
nbBytesReceivedFromSpw = nbBytesReceivedFromSpw + nbBytes; | ||||
nbPacketsReceivedFromSpw = nbPacketsReceivedFromSpw + 1; | ||||
this->ui->starDundeeReceivedBytes->setText( QString::number(nbBytesReceivedFromSpw) ); | ||||
this->ui->starDundeeReceivedPackets->setText( QString::number(nbPacketsReceivedFromSpw) ); | ||||
} | ||||
void StarDundeeGUI::updateNbTransmittedBytesToSpw( unsigned int nbBytes) | ||||
{ | ||||
nbBytesTransmittedToSpw = nbBytesTransmittedToSpw + nbBytes; | ||||
nbPacketsTransmittedToSpw = nbPacketsTransmittedToSpw + 1; | ||||
this->ui->starDundeeTransmittedBytes->setText( QString::number(nbBytesTransmittedToSpw) ); | ||||
this->ui->starDundeeTransmittedPackets->setText( QString::number(nbPacketsTransmittedToSpw) ); | ||||
} | ||||
paul
|
r40 | |||
void StarDundeeGUI::updateCCSDSPacketTransmittedToSpw( void ) | ||||
{ | ||||
nbCCSDSPacketsTransmittedToSpw = nbCCSDSPacketsTransmittedToSpw + 1; | ||||
} | ||||
unsigned int StarDundeeGUI::getNbCCSDSPacketsTransmittedToSpw(void) | ||||
{ | ||||
return this->nbCCSDSPacketsTransmittedToSpw; | ||||
} | ||||
unsigned int StarDundeeGUI::getNbPacketsTransmittedToSpw() | ||||
{ | ||||
return this->nbPacketsTransmittedToSpw; | ||||
} | ||||