# HG changeset patch # User paul # Date 2014-11-19 14:35:59 # Node ID a4e9ba42be66f29274c06e69d0a14c00d2646ec6 # Parent ccd56e93ef091ceabf5134f12881c2629d0eb7cf Functions added to the Python API: StarDundeeGetAvailableBrickCount StarDundeeSetBrickAsAninterface StarDundeeSetBrickAsARouter TCP Statistics udpated when packets are received or transmitted Spacewire statistics added router mode added for the STAR-Dundee Brick other minor modifications diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp @@ -35,6 +35,7 @@ SpwTcpPacketServer::SpwTcpPacketServer(Q updateHostIP(); this->ui->PortLineEdit->setText("2200"); connect(this->p_server,SIGNAL(newConnection()),this,SLOT(newConnection())); + resetStatististics(); } SpwTcpPacketServer::~SpwTcpPacketServer() @@ -73,6 +74,7 @@ void SpwTcpPacketServer::pushPacket(char else { connectedClients.at(i)->write(data); + onePacketTransmitted(); } } free(packet); @@ -94,6 +96,7 @@ void SpwTcpPacketServer::connectServer() { this->p_server->listen(QHostAddress::Any,this->ui->PortLineEdit->text().toInt()); this->ui->startServeQpb->setText("Stop Server"); + resetStatististics(); } void SpwTcpPacketServer::disconnectServer() @@ -137,11 +140,12 @@ void SpwTcpPacketServer::readReady() do { QByteArray data = soc->readAll(); - if(data[0]==0) + onePacketReceived(); + if(data[0]==0) // Protocole = 0 => Host to SpaceWire packet transmission { int size = (data[1]*256*256) + (data[2]*256) + data[3]; char* SPWpacket = (char*)malloc(size); - memcpy(SPWpacket,data.data()+4,size); + memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet emit sendSPWPacket(SPWpacket,size); } }while(soc->bytesAvailable()!=0); @@ -150,6 +154,15 @@ void SpwTcpPacketServer::readReady() } } +void SpwTcpPacketServer::resetStatististics() +{ + receivedPackets = 0; + transmittedPackets = 0; + + this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) ); + this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) ); +} + void SpwTcpPacketServer::updateHostIP() { QList list = QNetworkInterface::allAddresses(); @@ -161,3 +174,17 @@ void SpwTcpPacketServer::updateHostIP() this->ui->IPLineEdit->setText(list[nIter].toString()); } } + +void SpwTcpPacketServer::onePacketReceived() +{ + receivedPackets = receivedPackets + 1; + + this->ui->receivedPacketsNumber->display( QString::number(receivedPackets) ); +} + +void SpwTcpPacketServer::onePacketTransmitted() +{ + transmittedPackets = transmittedPackets + 1; + + this->ui->transmittedPacketsNumber->display( QString::number(transmittedPackets) ); +} diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.h @@ -52,12 +52,17 @@ public slots: void setServerSetIP(QString ip); void newConnection(); void readReady(); + void resetStatististics(); private: void updateHostIP(); + void onePacketReceived(); + void onePacketTransmitted(); Ui::SpwTcpPacketServer *ui; abstractSpwBridge* p_bridge; QTcpServer* p_server; QList connectedClients; + unsigned int receivedPackets; + unsigned int transmittedPackets; }; #endif // SPWTCPPACKETSERVER_H diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.ui @@ -86,12 +86,12 @@ - + - Sended Packets + Transmitted Packets @@ -103,7 +103,7 @@ - + diff --git a/spwplugin/StarDundee/stardundeeGUI.ui b/spwplugin/StarDundee/stardundeeGUI.ui --- a/spwplugin/StarDundee/stardundeeGUI.ui +++ b/spwplugin/StarDundee/stardundeeGUI.ui @@ -7,7 +7,7 @@ 0 0 397 - 243 + 467 @@ -82,7 +82,7 @@ - Destination key + Source address @@ -105,7 +105,7 @@ - RMAP Target address + Destination address @@ -128,7 +128,7 @@ - RMAP Target key + Destination key @@ -148,13 +148,6 @@ - - - - Connect - - - @@ -181,6 +174,109 @@ + + + + Connect + + + + + + + interface mode + + + true + + + + + + + router mode + + + + + + + + + Packets + + + + + + + - + + + + + + + + 75 + true + + + + Received + + + + + + + - + + + + + + + Bytes + + + + + + + + 75 + true + + + + Transmitted + + + + + + + - + + + + + + + - + + + + + + + Reset stats + + + + + diff --git a/spwplugin/StarDundee/stardundeegui.cpp b/spwplugin/StarDundee/stardundeegui.cpp --- a/spwplugin/StarDundee/stardundeegui.cpp +++ b/spwplugin/StarDundee/stardundeegui.cpp @@ -28,6 +28,8 @@ StarDundeeGUI::StarDundeeGUI(QWidget *parent) : QWidget(parent),ui(new Ui::StarDundeeUI) { + resetBytesPacketsStatistics(); + 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))); @@ -37,7 +39,8 @@ StarDundeeGUI::StarDundeeGUI(QWidget *pa connect(this->ui->RMAPKeylineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapKeyChanged(QString))); connect(this->ui->RMAPTimeoutLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(rmapTimeoutChanged(QString))); connect(this->ui->connectQpb,SIGNAL(clicked()),this,SIGNAL(connectClicked())); - + connect(this->ui->setInterfaceModeQrb, SIGNAL(toggled(bool)), this, SIGNAL(brickModeChanged(bool))); + connect(this->ui->resetStatsQpb, SIGNAL(clicked()), this, SLOT(resetStatistics())); } int StarDundeeGUI::getBrickSelection() @@ -75,7 +78,35 @@ QString StarDundeeGUI::getRmapTimeout() return ui->RMAPTimeoutLineEdit->text(); } +bool StarDundeeGUI::isBrickSetAsAnInterface() +{ + return ui->setInterfaceModeQrb->isChecked(); +} +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 ); + } + +} void StarDundeeGUI::lock(bool lock) { @@ -86,6 +117,8 @@ void StarDundeeGUI::lock(bool lock) this->ui->RMAPAddresslineEdit->setDisabled(lock); this->ui->RMAPKeylineEdit->setDisabled(lock); this->ui->RMAPTimeoutLineEdit->setDisabled(lock); + this->ui->setInterfaceModeQrb->setDisabled(lock); + this->ui->setRouterModeQrb->setDisabled(lock); if(lock) this->ui->connectQpb->setText("Disconnect"); else @@ -172,3 +205,50 @@ void StarDundeeGUI::setRmapKey(const QSt this->ui->RMAPKeylineEdit->setText(key); } } + +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; +} + +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) ); +} diff --git a/spwplugin/StarDundee/stardundeegui.h b/spwplugin/StarDundee/stardundeegui.h --- a/spwplugin/StarDundee/stardundeegui.h +++ b/spwplugin/StarDundee/stardundeegui.h @@ -40,6 +40,7 @@ public: QString getRmapAddress(); QString getRmapKey(); QString getRmapTimeout(); + bool isBrickSetAsAnInterface(); signals: void brickSelectionChanged(int brickIndex); void linkNumberSelectionChanged(int linkIndex); @@ -49,6 +50,7 @@ signals: void rmapKeyChanged(const QString & key); void rmapTimeoutChanged(const QString & timeout); void connectClicked(); + void brickModeChanged(bool); public slots: void lock(bool lock); void updateAvailableBrickCount(int count); @@ -59,8 +61,19 @@ public slots: void setRmapAddress(const QString & address); void setRmapKey(const QString & key); void setRmapTimeout(const QString & timeout); + int getAvailableBrickCount( void ); + void setBrickAsAnInterface(bool interfaceMode); + void setBrickAsARouter( bool interfaceMode ); + void resetBytesPacketsStatistics( void ); + void resetStatistics( void ); + void updateNbReceivedBytesFromSpw( unsigned int nbBytes); + void updateNbTransmittedBytesToSpw( unsigned int nbBytes); private: Ui::StarDundeeUI *ui; + unsigned int nbBytesReceivedFromSpw; + unsigned int nbBytesTransmittedToSpw; + unsigned int nbPacketsReceivedFromSpw; + unsigned int nbPacketsTransmittedToSpw; }; #endif // STARDUNDEEGUI_H diff --git a/spwplugin/StarDundee/stardundeespw_usb.cpp b/spwplugin/StarDundee/stardundeespw_usb.cpp --- a/spwplugin/StarDundee/stardundeespw_usb.cpp +++ b/spwplugin/StarDundee/stardundeespw_usb.cpp @@ -24,6 +24,15 @@ #include #include +QString dwLinkStatusQString[6] = { + "CFG_SPACEWIRE_ERROR_RESET", + "CFG_SPACEWIRE_ERROR_WAIT", + "CFG_SPACEWIRE_READY", + "CFG_SPACEWIRE_STARTED", + "CFG_SPACEWIRE_CONNECTING", + "CFG_SPACEWIRE_RUN" +}; + stardundeeSPW_USB::stardundeeSPW_USB(socexplorerplugin *parent) : abstractSpwBridge(parent) { @@ -32,6 +41,8 @@ stardundeeSPW_USB::stardundeeSPW_USB(soc makeGUI(parent); this->manager->start(); connect(this->manager,SIGNAL(emitPacket(char*,int)),this,SIGNAL(pushPacketOverTCP(char*,int))); + connect(this->manager, SIGNAL(bytesReceivedFromSpw(uint)), this, SIGNAL(BytesReceivedFromSpw(uint))); + connect(this->manager, SIGNAL(bytesTransmittedToSpw(uint)), this, SIGNAL(BytesTransmittedToSpw(uint))); } stardundeeSPW_USB::~stardundeeSPW_USB() @@ -107,7 +118,14 @@ unsigned int stardundeeSPW_USB::Write(un } transactionID=manager->getRMAPtransactionID(); SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2); - RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),RMAP_MAX_XFER_SIZE*4,writeBuffer+1); + RMAP_build_tx_request_header( + this->manager->destinationLogicalAddress, + this->manager->destinationKey, + this->manager->sourceLogicalAddress, + transactionID, + address+(written*4), + RMAP_MAX_XFER_SIZE*4, + writeBuffer+1); manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(RMAP_MAX_XFER_SIZE*4)+1); manager->getRMAPanswer(transactionID,&RMAPAckBuff); free(RMAPAckBuff); @@ -127,7 +145,14 @@ unsigned int stardundeeSPW_USB::Write(un } transactionID=manager->getRMAPtransactionID(); SocExplorerEngine::message(this->plugin,QString("Sending Write request with ID=%1").arg(transactionID),2); - RMAP_build_tx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(written*4),count*4,writeBuffer+1); + RMAP_build_tx_request_header( + this->manager->destinationLogicalAddress, + this->manager->destinationKey, + this->manager->sourceLogicalAddress, + transactionID, + address+(written*4), + count*4, + writeBuffer+1); manager->sendPacket(writeBuffer,RMAP_WRITE_PACKET_MIN_SZ(count*4) +1); manager->getRMAPanswer(transactionID,&RMAPAckBuff); free(RMAPAckBuff); @@ -162,7 +187,14 @@ unsigned int stardundeeSPW_USB::Read(uns { transactionID = manager->getRMAPtransactionID(); SocExplorerEngine::message(this->plugin,QString("New transactionID:%1").arg(transactionID),2); - RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),RMAP_MAX_XFER_SIZE*4,requestBuffer+1); + RMAP_build_rx_request_header( + this->manager->destinationLogicalAddress, + this->manager->destinationKey, + this->manager->sourceLogicalAddress, + transactionID, + address+(read*4), + RMAP_MAX_XFER_SIZE*4, + requestBuffer+1); manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); if(len==-1) @@ -191,7 +223,14 @@ unsigned int stardundeeSPW_USB::Read(uns SocExplorerEngine::message(this->plugin,QString("Address = %1").arg(address+(read*4),8,16),2); SocExplorerEngine::message(this->plugin,QString("Size = %1").arg(count*4),2); SocExplorerEngine::message(this->plugin,QString("Size + 13 = %1").arg((count*4)+13),2); - RMAP_build_rx_request_header(this->manager->rmapAddress,this->manager->rmapKey,1,transactionID,address+(read*4),count*4,requestBuffer+1); + RMAP_build_rx_request_header( + this->manager->destinationLogicalAddress, + this->manager->destinationKey, + this->manager->sourceLogicalAddress, + transactionID, + address+(read*4), + count*4, + requestBuffer+1); manager->sendPacket(requestBuffer,RMAP_READ_HEADER_MIN_SZ+1); int len=manager->getRMAPanswer(transactionID,&RMAP_AnswerBuffer); if(len==-1) @@ -236,22 +275,27 @@ void stardundeeSPW_USB::linkSpeedSelecti SocExplorerEngine::message(plugin,QString("Changing Link Speed: %1").arg(manager->linkSpeed),1); } -void stardundeeSPW_USB::destinationKeyChanged(const QString &destKey) +void stardundeeSPW_USB::sourceLogicalAddressChanged(const QString &sourceAddress) { - this->manager->destinationKey = destKey.toInt(); - SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->destinationKey),1); + this->manager->sourceLogicalAddress = sourceAddress.toInt(); + SocExplorerEngine::message(plugin,QString("Changing Destination Key: %1").arg(manager->sourceLogicalAddress),1); } void stardundeeSPW_USB::rmapAddressChanged(const QString &rmapaddress) { - this->manager->rmapAddress = rmapaddress.toInt(); - SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->rmapAddress),1); + this->manager->destinationLogicalAddress = rmapaddress.toInt(); + SocExplorerEngine::message(plugin,QString("Changing RMAP address: %1").arg(manager->destinationLogicalAddress),1); } -void stardundeeSPW_USB::rmapKeyChanged(const QString &key) +void stardundeeSPW_USB::destinationKeyChanged(const QString &key) { - this->manager->rmapKey = key.toInt(); - SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->rmapKey),1); + this->manager->destinationKey = key.toInt(); + SocExplorerEngine::message(plugin,QString("Changing RMAP Key: %1").arg(manager->destinationKey),1); +} + +void stardundeeSPW_USB::brickModeChanged( bool interfaceMode ) +{ + this->manager->interfaceMode = interfaceMode; } void stardundeeSPW_USB::rmapTimeoutChanged(const QString &timeout) @@ -266,7 +310,6 @@ void stardundeeSPW_USB::rmapTimeoutChang SocExplorerEngine::message(plugin,QString("Changing RMAP Timeout: %1").arg(manager->RMAPtimeout),1); } - void stardundeeSPW_USB::makeGUI(socexplorerplugin *parent) { this->p_GUI = new StarDundeeGUI(); @@ -276,27 +319,57 @@ void stardundeeSPW_USB::makeGUI(socexplo connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickSelectionChanged(int)),this,SLOT(brickSelectionChanged(int))); connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkNumberSelectionChanged(int)),this,SLOT(linkNumberSelectionChanged(int))); connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(linkSpeedSelectionChanged(QString)),this,SLOT(linkSpeedSelectionChanged(QString))); - connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString))); + connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(sourceLogicalAddressChanged(QString)),this,SLOT(sourceLogicalAddressChanged(QString))); connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapAddressChanged(QString)),this,SLOT(rmapAddressChanged(QString))); - connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapKeyChanged(QString)),this,SLOT(rmapKeyChanged(QString))); + connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(destinationKeyChanged(QString)),this,SLOT(destinationKeyChanged(QString))); connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(rmapTimeoutChanged(QString)),this,SLOT(rmapTimeoutChanged(QString))); + connect(((StarDundeeGUI*)this->p_GUI),SIGNAL(brickModeChanged(bool)), this, SLOT(brickModeChanged(bool))); this->brickSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getBrickSelection()); this->linkNumberSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkNumberSelection()); this->linkSpeedSelectionChanged(((StarDundeeGUI*)this->p_GUI)->getLinkSpeedSelection()); - this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey()); + this->sourceLogicalAddressChanged(((StarDundeeGUI*)this->p_GUI)->getDestinationKey()); this->rmapAddressChanged(((StarDundeeGUI*)this->p_GUI)->getRmapAddress()); - this->rmapKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey()); + this->destinationKeyChanged(((StarDundeeGUI*)this->p_GUI)->getRmapKey()); this->rmapTimeoutChanged(((StarDundeeGUI*)this->p_GUI)->getRmapTimeout()); + this->brickModeChanged(((StarDundeeGUI*)this->p_GUI)->isBrickSetAsAnInterface()); + + connect(this,SIGNAL(SelectBrick(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int))); + connect(this,SIGNAL(SelectLinkNumber(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int))); + connect(this,SIGNAL(SelectLinkSpeed(int)), ((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int))); + connect(this,SIGNAL(SetDestinationKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString))); + connect(this,SIGNAL(SetRmapAddress(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapAddress(QString))); + connect(this,SIGNAL(SetRmapKey(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapKey(QString))); + connect(this,SIGNAL(SetRmapTimeout(QString)), ((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString))); + connect(this,SIGNAL(GetAvailableBrickCount()), ((StarDundeeGUI*)this->p_GUI),SLOT(getAvailableBrickCount())); + connect(this,SIGNAL(SetBrickAsAnInterface(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsAnInterface(bool))); + connect(this,SIGNAL(SetBrickAsARouter(bool)), ((StarDundeeGUI*)this->p_GUI),SLOT(setBrickAsARouter(bool))); + connect(this,SIGNAL(BytesReceivedFromSpw(uint)), ((StarDundeeGUI*)this->p_GUI),SLOT(updateNbReceivedBytesFromSpw(uint))); + connect(this,SIGNAL(BytesTransmittedToSpw(uint)),((StarDundeeGUI*)this->p_GUI),SLOT(updateNbTransmittedBytesToSpw(uint))); +} - connect(this,SIGNAL(SelectBrick(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectBrick(int))); - connect(this,SIGNAL(SelectLinkNumber(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkNumber(int))); - connect(this,SIGNAL(SelectLinkSpeed(int)),((StarDundeeGUI*)this->p_GUI),SLOT(selectLinkSpeed(int))); - connect(this,SIGNAL(SetDestinationKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setDestinationKey(QString))); - connect(this,SIGNAL(SetRmapAddress(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapAddress(QString))); - connect(this,SIGNAL(SetRmapKey(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapKey(QString))); - connect(this,SIGNAL(SetRmapTimeout(QString)),((StarDundeeGUI*)this->p_GUI),SLOT(setRmapTimeout(QString))); +void stardundeeSPW_USB::sendPacketComingFromTCPServer(char *packet, int size) +{ + char* data; + int i; + + data = (char *) malloc( size + 5 ); + data[0] = this->manager->linkNumber; + data[1] = this->manager->destinationLogicalAddress; // target logical address + data[2] = SPW_PROTO_ID_CCSDS; // protocol identifier + data[3] = 0x00; // reserved + data[4] = 0x00; // user application + + for ( i=0; imanager->sendPacket( data, size + 5); + + free(data); + free(packet); } stardundeeSPW_USB_Manager::stardundeeSPW_USB_Manager(socexplorerplugin *plugin, QObject *parent) @@ -320,7 +393,6 @@ stardundeeSPW_USB_Manager::~stardundeeSP } } - void stardundeeSPW_USB_Manager::run() { USB_SPACEWIRE_PACKET_PROPERTIES properties; @@ -346,6 +418,7 @@ void stardundeeSPW_USB_Manager::run() if(USBSpaceWire_GetReadEOPStatus(&properties, 0)== SPACEWIRE_USB_EOP) { SocExplorerEngine::message(this->plugin,"Got end of packet",2); + emit bytesReceivedFromSpw( properties.len ); if(buffer[1]==(char)SPW_PROTO_ID_RMAP) //RMAP packet { RMAP_Answer* packet; @@ -416,6 +489,26 @@ void stardundeeSPW_USB_Manager::run() bool stardundeeSPW_USB_Manager::connectBridge() { + bool ret; + + if (this->interfaceMode == BRICK_IS_SET_AS_AN_INTERFACE) + { + ret = connectBridgeAsInterface(); + } + else if (this->interfaceMode == BRICK_IS_SET_AS_A_ROUTER) + { + ret = connectBridgeAsRouter(); + } + else + { + ret = false; + } + + return ret; +} + +bool stardundeeSPW_USB_Manager::connectBridgeAsInterface() +{ QMutexLocker mlock(this->handleMutex); int status; U32 statusControl; @@ -497,6 +590,285 @@ bool stardundeeSPW_USB_Manager::connectB return true; } +bool stardundeeSPW_USB_Manager::connectBridgeAsRouter() +{ + QMutexLocker mlock(this->handleMutex); + int status; + U32 statusControl; + unsigned int linkStatus1; + unsigned int linkStatus2; + unsigned char linkNumber; + unsigned char deviceIsAnInterface; + + if (!USBSpaceWire_Open(&hDevice, this->selectedBrick)) // Open the USB device + { + SocExplorerEngine::message(this->plugin,"stardundee *** Open *** ERROR: USBSpaceWire_Open(&hDevice, 0))"); + return false; + } + SocExplorerEngine::message(this->plugin,"stardundee *** Open *** USBSpaceWire_Open successful, device number: " + + QString::number(this->selectedBrick)); + + USBSpaceWire_EnableNetworkMode(hDevice, 0); // deactivate the network mode + CFGSpaceWire_EnableRMAP(1); // Enable the use of RMAP for the StarDundee brick configuration + CFGSpaceWire_SetRMAPDestinationKey(0x20); // Set the destination key expected by STAR-Dundee devices + + // Set the path and return path to the device + // This affects just the operations performed by the Configuration Library and does not affect the packets + // sent and received using the driver API. + CFGSpaceWire_StackClear(); + CFGSpaceWire_AddrStackPush(0); + CFGSpaceWire_AddrStackPush(254); + CFGSpaceWire_RetAddrStackPush(254); + + // set the base transmit rate to 100 MHz + status = CFGSpaceWire_SetBrickBaseTransmitRate( hDevice, CFG_BRK_CLK_100_MHZ, CFG_BRK_DVDR_1, 0xff); + if (status != CFG_TRANSFER_SUCCESS) + { + SocExplorerEngine::message(this->plugin,"ERROR CFGSpaceWire_SetBrickBaseTransmitRate"); + } + else SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_SetBrickBaseTransmitRate, base rate = 100 MHz"); + + //********************* + // LINK 1 CONFIGURATION + linkNumber = 1; + if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber)); + else + { + SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber)); + + // Set the link status control register properties + CFGSpaceWire_LSEnableAutoStart(&statusControl, 1); + CFGSpaceWire_LSEnableStart(&statusControl, 1); + CFGSpaceWire_LSEnableDisabled(&statusControl, 0); + CFGSpaceWire_LSEnableTristate(&statusControl, 0); + CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz + + // Set the link status control register + if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber)); + else + SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(0x01) + " is set"); + } + + //********************* + // LINK 2 CONFIGURATION + linkNumber = 2; + if (CFGSpaceWire_GetLinkStatusControl(hDevice, linkNumber, &statusControl) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not read link status control for link " + QString::number(linkNumber)); + else + { + SocExplorerEngine::message(this->plugin,"OK CFGSpaceWire_GetLinkStatusControl of link " + QString::number(linkNumber)); + + // Set the link status control register properties + CFGSpaceWire_LSEnableAutoStart(&statusControl, 1); + CFGSpaceWire_LSEnableStart(&statusControl, 1); + CFGSpaceWire_LSEnableDisabled(&statusControl, 0); + CFGSpaceWire_LSEnableTristate(&statusControl, 0); + CFGSpaceWire_LSSetOperatingSpeed(&statusControl, 9); // sets the link speed to ( 100 MHz / (9+1) ) = 10 MHz + + // Set the link status control register + if (CFGSpaceWire_SetLinkStatusControl(hDevice, linkNumber, statusControl) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not set the link status control for link " + QString::number(linkNumber)); + else + SocExplorerEngine::message(this->plugin,"link status control for link " + QString::number(linkNumber) + " is set"); + } + + //*************************** + // SET THE DEVICE AS A ROUTER + deviceIsAnInterface = 0; // 0 = router, 1 = interface + if (CFGSpaceWire_SetAsInterface(hDevice, deviceIsAnInterface, 0) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not set the device to be an interface"); + else + SocExplorerEngine::message(this->plugin,"Device is an interface: " + QString::number(deviceIsAnInterface) + " (1 => true, 0 => false)"); + + setRoutingTableEntry(0xfe, 0x02, 0); // [0010] => route 0xfe on port 1 + setRoutingTableEntry(32 , 0x08, 0); // [1000] => route 32 on port 3 + + USBSpaceWire_RegisterReceiveOnAllPorts(hDevice); // Register to receive on port 1 only + USBSpaceWire_ClearEndpoints(hDevice); // clear the USB endpoints + + SocExplorerEngine::message(this->plugin,"The driver's current send buffer size is " + QString::number(USBSpaceWire_GetDriverSendBufferSize(hDevice)) + " bytes"); + SocExplorerEngine::message(this->plugin,"The driver's current read buffer size is " + QString::number(USBSpaceWire_GetDriverReadBufferSize(hDevice)) + " bytes"); + SocExplorerEngine::message(this->plugin,"USBSpaceWire_IsReadThrottling is " + QString::number(USBSpaceWire_IsReadThrottling(hDevice))); + + //************ + // test Link 1 and Link 2 + linkStatus1 = getLinkStatus(0x01); + linkStatus2 = getLinkStatus(0x02); + + if ((linkStatus1==1) || (linkStatus2==1)) + { + initializeTimecodeGeneration(); + this->connected=true; + return true; + } + else + { + statusLink1->setText("Link 1 status code: " + QString::number(linkStatus1)); + statusLink2->setText("Link 2 status code: " + QString::number(linkStatus2)); + starDundeeStatusQueryDialog->exec(); + this->connected = false; + return false; + } +} + +void stardundeeSPW_USB_Manager::initDialog( void ) +{ + // STAR DUNDEE STATUS QUERY DIALOG + starDundeeStatusQueryDialog = new QDialog; + starDundeeStatusQueryDialogLayout = new QGridLayout; + starDundeeStatusQueryDialogLabel = new QLabel(tr("SpaceWire links state")); + starDundeeStatusQueryContinueButton = new QPushButton(tr("Continue")); + starDundeeStatusQueryRetryButton = new QPushButton(tr("Retry")); + starDundeeStatusQueryAbortButton = new QPushButton(tr("Abort")); + statusLink1 = new QLabel(tr("Link 1 status code: -")); + statusLink2 = new QLabel(tr("Link 2 status code: -")); + + starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryDialogLabel, 0, 0, 1, 2); + starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryContinueButton, 1, 0, 0); + starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryRetryButton, 1, 1, 0); + starDundeeStatusQueryDialogLayout->addWidget(starDundeeStatusQueryAbortButton, 1, 2, 0); + starDundeeStatusQueryDialogLayout->addWidget(statusLink1, 2, 0, 0); + starDundeeStatusQueryDialogLayout->addWidget(statusLink2, 3, 0, 0); + starDundeeStatusQueryDialog->setLayout(starDundeeStatusQueryDialogLayout); +} + +unsigned char stardundeeSPW_USB_Manager::setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead) +{ + U32 routingTableEntry; + // SET THE ROUTING TABLE ENTRY FOR LOGICAL ADDRESSING, TARGET entryNumber + if (CFGSpaceWire_ClearRoutingTableEntry(hDevice, tableEntry) != CFG_TRANSFER_SUCCESS) + { + SocExplorerEngine::message(this->plugin,"Could not clear routing table entry " + QString::number(tableEntry)); + } + // Build the routing table entry + CFGSpaceWire_RTBuildRoutingTableEntry(&routingTableEntry, + dwOutputPorts, // route out of port dwOutputPorts + bDelHead, // header deletion is enabled [1] or disabled [0] + 0); // priority normal + // Set the routing table entry for logical address tableEntry + if (CFGSpaceWire_SetRoutingTableEntry(hDevice, tableEntry, routingTableEntry) != CFG_TRANSFER_SUCCESS) + { + SocExplorerEngine::message(this->plugin,"Could not set routing table entry [" + QString::number(tableEntry) + "]"); + } + else SocExplorerEngine::message(this->plugin,"Routing table entry [" + QString::number(tableEntry) + "] set" ); + return 1; +} + +unsigned int stardundeeSPW_USB_Manager::getRoutingTableEntry(int tableEntry) +{ + U32 routingTableEntry, outputPorts; + char enabled, delHead, priority; + int portNum; + + SocExplorerEngine::message(this->plugin,"GetRoutingTableEntry [" + QString::number(tableEntry) + "]"); + // Read the routing table entry + if (CFGSpaceWire_GetRoutingTableEntry(hDevice, tableEntry, &routingTableEntry) != CFG_TRANSFER_SUCCESS) + { + SocExplorerEngine::message(this->plugin,"Could not read routing table entry [" + QString::number(tableEntry) + "]"); + } + else + { + // Display the routing table entry properties + CFGSpaceWire_RTIsEnabled(routingTableEntry, &enabled); + CFGSpaceWire_RTIsDelHead(routingTableEntry, &delHead); + CFGSpaceWire_RTIsPriority(routingTableEntry, &priority); + CFGSpaceWire_RTGetOutputPorts(routingTableEntry, &outputPorts); + SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsEnabled : " + QString::number(enabled)); + SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsDelHead : " + QString::number(delHead)); + SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTIsPriority : " + QString::number(priority)); + SocExplorerEngine::message(this->plugin,"CFGSpaceWire_RTGetOutputPorts : "); + for (portNum = 0; portNum < 32; portNum++) + { + if (outputPorts & (1 << portNum)) + { + SocExplorerEngine::message(this->plugin,QString::number(portNum)); + } + } + } + + return 1; +} + +void stardundeeSPW_USB_Manager::initializeTimecodeGeneration() +{ + U32 dwTickEnableStatus; + U32 rtr_clk_freq; + + // (1) RESET + if (!USBSpaceWire_TC_Reset(hDevice)) + SocExplorerEngine::message(this->plugin,"ERR *** in Open *** Could not reset timecodes\n"); + + // (2) Clear the tick enable register + if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS) + SocExplorerEngine::message(this->plugin,"Could not clear the tick enable register"); + else + SocExplorerEngine::message(this->plugin,"Cleared the tick enable register"); + + // (3) get the tick status + CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus); + SocExplorerEngine::message(this->plugin,"OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2)); + + // (4) enable external timecode selection + if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0)) + SocExplorerEngine::message(this->plugin,"ERR *** disable external timecode selection"); + + rtr_clk_freq = USBSpaceWire_TC_GetClockFrequency(hDevice); + + SocExplorerEngine::message(this->plugin,"clock frequency = " + QString::number(rtr_clk_freq) ); + + //************************************************** + // auto _ tick _ freq = rtr _ clk _ freq / freqCount + if (!USBSpaceWire_TC_SetAutoTickInFrequency(hDevice, rtr_clk_freq) ) + SocExplorerEngine::message(this->plugin,"Could not set the tick-in frequency"); +} + +unsigned int stardundeeSPW_USB_Manager::getLinkStatus(unsigned char link) +{ + U32 statusControl, errorStatus, portType; + U32 linkStatus, operatingSpeed, outputPortConnection; + char isLinkRunning, isAutoStart, isStart, isDisabled, isTristate; + + // Read the link status control register + if (CFGSpaceWire_GetLinkStatusControl(hDevice, link, &statusControl) != CFG_TRANSFER_SUCCESS) + { + SocExplorerEngine::message(this->plugin,"Could not read link status control for link" + QString::number(link)); + } + else + { + // Display the link status control register properties + CFGSpaceWire_LSPortType(statusControl, &portType); + if (portType == CFG_CONFIGURATION_PORT) + { + CFGSpaceWire_LSConfigErrorStatus(statusControl, &errorStatus); + } + else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT) + { + CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus); + } + else + { + CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus); + } + CFGSpaceWire_LSLinkState(statusControl, &linkStatus); + CFGSpaceWire_LSIsLinkRunning(statusControl, &isLinkRunning); + CFGSpaceWire_LSIsAutoStart(statusControl, &isAutoStart); + CFGSpaceWire_LSIsStart(statusControl, &isStart); + CFGSpaceWire_LSIsDisabled(statusControl, &isDisabled); + CFGSpaceWire_LSIsTristate(statusControl, &isTristate); + CFGSpaceWire_LSOperatingSpeed(statusControl, &operatingSpeed); + CFGSpaceWire_LSOutputPortConnection(statusControl, &outputPortConnection); + } + SocExplorerEngine::message(this->plugin,"status of link " + QString::number(link) + +" is " + dwLinkStatusQString[linkStatus]); + if (linkStatus == 5) + { + return 1; + } + else return 0; +} + bool stardundeeSPW_USB_Manager::disconnectBridge() { this->handleMutex->lock(); @@ -607,6 +979,7 @@ bool stardundeeSPW_USB_Manager::sendPack } else { + emit bytesTransmittedToSpw( size-1 ); // -1 is for removing the first bytes added to the packet to route to the right link SocExplorerEngine::message(this->plugin,"Packet sent",2); USBSpaceWire_FreeSend(hDevice, pIdentifier); } diff --git a/spwplugin/StarDundee/stardundeespw_usb.h b/spwplugin/StarDundee/stardundeespw_usb.h --- a/spwplugin/StarDundee/stardundeespw_usb.h +++ b/spwplugin/StarDundee/stardundeespw_usb.h @@ -36,7 +36,8 @@ #include #include "stardundeegui.h" - +#define BRICK_IS_SET_AS_AN_INTERFACE true +#define BRICK_IS_SET_AS_A_ROUTER false class stardundeeSPW_USB_Manager: public QThread { @@ -46,6 +47,13 @@ public: ~stardundeeSPW_USB_Manager(); void run(); bool connectBridge(); + bool connectBridgeAsInterface(); + bool connectBridgeAsRouter(); + void initDialog( void ); + unsigned char setRoutingTableEntry(int tableEntry, U32 dwOutputPorts, char bDelHead); + unsigned int getRoutingTableEntry(int tableEntry); + void initializeTimecodeGeneration(); + unsigned int getLinkStatus(unsigned char link); bool disconnectBridge(); int getRMAPtransactionID(); int getRMAPanswer(int transactionID,char** buffer); @@ -54,6 +62,9 @@ public: signals: void updateAvailableBrickCount(int count); void emitPacket(char* packet,int size); + void bytesReceivedFromSpw( unsigned int ); + void bytesTransmittedToSpw( unsigned int); + private: QMutex* handleMutex,*RMAP_AnswersMtx,*RMAP_pending_transaction_IDsMtx; QSemaphore* RMAP_AnswersSem; @@ -65,15 +76,25 @@ private: QList RMAP_Answers; QList RMAP_pending_transaction_IDs; + QLabel *starDundeeStatusQueryDialogLabel; + QPushButton *starDundeeStatusQueryRetryButton; + QPushButton *starDundeeStatusQueryAbortButton; + QLabel *statusLink1; + QLabel *statusLink2; + QPushButton *starDundeeStatusQueryContinueButton; + QDialog *starDundeeStatusQueryDialog; + QGridLayout *starDundeeStatusQueryDialogLayout; + public: int selectedBrick; int linkNumber; int brickList; int linkSpeed; + int sourceLogicalAddress; + int destinationLogicalAddress; int destinationKey; - int rmapAddress; - int rmapKey; int RMAPtimeout; + bool interfaceMode; // 1 => interface mode, 0 => router mode }; class stardundeeSPW_USB : public abstractSpwBridge @@ -93,6 +114,11 @@ signals: void SetRmapAddress(const QString & address); void SetRmapKey(const QString & key); void SetRmapTimeout(const QString & timeout); + void SetBrickAsAnInterface( bool ); + void SetBrickAsARouter( bool ); + int GetAvailableBrickCount( void ); + void BytesReceivedFromSpw( unsigned int ); + void BytesTransmittedToSpw( unsigned int ); public slots: void toggleBridgeConnection(); @@ -104,10 +130,12 @@ public slots: void brickSelectionChanged(int brickIndex); void linkNumberSelectionChanged(int linkIndex); void linkSpeedSelectionChanged(const QString & linkSpeed); - void destinationKeyChanged(const QString & destKey); + void sourceLogicalAddressChanged(const QString & destKey); void rmapAddressChanged(const QString & rmapaddress); - void rmapKeyChanged(const QString & key); + void brickModeChanged( bool interfaceMode ); + void destinationKeyChanged(const QString & key); void rmapTimeoutChanged(const QString & timeout); + void sendPacketComingFromTCPServer(char *packet, int size); private: void makeGUI(socexplorerplugin *parent); stardundeeSPW_USB_Manager* manager; diff --git a/spwplugin/spwplugin.cpp b/spwplugin/spwplugin.cpp --- a/spwplugin/spwplugin.cpp +++ b/spwplugin/spwplugin.cpp @@ -104,7 +104,13 @@ void spwplugin::bridgeSelectionChanged(c connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetRmapTimeout(QString)),((stardundeeSPW_USB*)bridge),SIGNAL(SetRmapTimeout(QString))); connect(((spwPyWrapper*)this->pyObject),SIGNAL(connectBridge()),((stardundeeSPW_USB*)bridge),SLOT(connectBridge())); connect(((spwPyWrapper*)this->pyObject),SIGNAL(disconnectBridge()),((stardundeeSPW_USB*)bridge),SLOT(disconnectBridge())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeGetAvailableBrickCount()),((stardundeeSPW_USB*)bridge),SIGNAL(GetAvailableBrickCount())); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsAninterface(bool)), + ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsAnInterface(bool))); + connect(((spwPyWrapper*)this->pyObject),SIGNAL(StarDundeeSetBrickAsARouter(bool)), + ((stardundeeSPW_USB*)bridge),SIGNAL(SetBrickAsARouter(bool))); connect(this->bridge,SIGNAL(pushPacketOverTCP(char*,int)),this->tcpServer,SLOT(pushPacket(char*,int))); + connect(this->tcpServer, SIGNAL(sendSPWPacket(char*,int)), ((stardundeeSPW_USB*)bridge), SLOT(sendPacketComingFromTCPServer(char*,int))); } if(text=="GR-ESB") { @@ -146,8 +152,6 @@ void spwplugin::setConnected(bool connec } } - - unsigned int spwplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) { if(Connected) diff --git a/spwplugin/spwpywrapper.h b/spwplugin/spwpywrapper.h --- a/spwplugin/spwpywrapper.h +++ b/spwplugin/spwpywrapper.h @@ -18,6 +18,9 @@ signals: void StarDundeeSetRmapAddress(const QString & address); void StarDundeeSetRmapKey(const QString & key); void StarDundeeSetRmapTimeout(const QString & timeout); + int StarDundeeGetAvailableBrickCount(); + void StarDundeeSetBrickAsAninterface( bool ); + void StarDundeeSetBrickAsARouter( bool ); void TCPServerConnect(); void TCPServerDisconnect();