|
|
#include "mainwindow.h"
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
QWidget(parent)
|
|
|
{
|
|
|
hDevice = NULL;
|
|
|
UI = new mainwindowui();
|
|
|
time = new QTimer();
|
|
|
|
|
|
connect(UI->starDundeeStatusQueryRetryButton, SIGNAL(clicked()), this, SLOT(reTestSPWLink()));
|
|
|
connect(UI->startTimeButton, SIGNAL(clicked()), this, SLOT(startSpacewireTime()));
|
|
|
connect(UI->sendTimecodeButton, SIGNAL(clicked()), this, SLOT(sendOneTimecode()));
|
|
|
connect(UI->sendPacketAndTimecodeButton, SIGNAL(clicked()), this, SLOT(sendOnePacketAndOneTimecode()));
|
|
|
connect(this, SIGNAL(sendMessage(QString)), this->UI, SLOT(displayMessage(QString)));
|
|
|
|
|
|
this->setLayout(UI->layout());
|
|
|
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::startSpacewireTime()
|
|
|
{
|
|
|
unsigned int result;
|
|
|
if (hDevice==NULL)
|
|
|
{
|
|
|
result = Open();
|
|
|
}
|
|
|
if (getLinkStatus(UI->linkNumber_SPINBOX->value()))
|
|
|
{
|
|
|
emit sendMessage("OK *** in Start *** start sending packet periodically");
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
emit sendMessage("ERR *** in Start *** ");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::sendOneTimecode()
|
|
|
{
|
|
|
unsigned int result;
|
|
|
U32 timecodeReg, val;
|
|
|
|
|
|
if (hDevice==NULL)
|
|
|
{
|
|
|
result = Open();
|
|
|
}
|
|
|
if (getLinkStatus(UI->linkNumber_SPINBOX->value()))
|
|
|
{
|
|
|
emit sendMessage("OK *** in sendOneTimecode *** stardundee brick running");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
emit sendMessage("ERR *** in sendOneTimecode *** stardundee brick not running");
|
|
|
}
|
|
|
if(!USBSpaceWire_TC_EnableExternalTimecodeSelection(hDevice,0))
|
|
|
{
|
|
|
emit sendMessage("ERR *** disable external timecode selection");
|
|
|
return;
|
|
|
}
|
|
|
emit sendMessage("OK *** in sendOneTimecode *** next valid tick will be performed");
|
|
|
if(!USBSpaceWire_TC_PerformTickIn(hDevice, 0))
|
|
|
{
|
|
|
emit sendMessage("ERR *** in sendOneTimecode *** perform TickIn");
|
|
|
return;
|
|
|
}
|
|
|
emit sendMessage("OK *** in sendOneTimecode *** tick performed");
|
|
|
// Read the timecode register
|
|
|
if (CFGSpaceWire_GetTimecodeRegister(hDevice, &timecodeReg) != CFG_TRANSFER_SUCCESS)
|
|
|
{
|
|
|
emit sendMessage("Could not read the timecode register");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
CFGSpaceWire_TCGetValue(timecodeReg, &val);
|
|
|
emit sendMessage("The timecode value is currently: " + QString::number(val));
|
|
|
CFGSpaceWire_TCGetFlags(timecodeReg, &val);
|
|
|
emit sendMessage("The timecode flag value is currently: " + QString::number(val));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::sendOnePacketAndOneTimecode()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
unsigned int MainWindow::Open()
|
|
|
{
|
|
|
U32 dwTickEnableStatus;
|
|
|
|
|
|
if (!USBSpaceWire_Open(&hDevice, UI->usbDeviceNumber_SPINBOX->value())) // Open the USB device
|
|
|
{
|
|
|
emit sendMessage("ERR *** in Open *** USBSpaceWire_Open(&hDevice, 0))");
|
|
|
return 0;
|
|
|
}
|
|
|
emit sendMessage("OK *** in Open *** USBSpaceWire_Open successful, device number: "
|
|
|
+ QString::number(UI->usbDeviceNumber_SPINBOX->value()));
|
|
|
|
|
|
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
|
|
|
CFGSpaceWire_StackClear();
|
|
|
CFGSpaceWire_AddrStackPush(0);
|
|
|
CFGSpaceWire_AddrStackPush(254);
|
|
|
CFGSpaceWire_RetAddrStackPush(254);
|
|
|
|
|
|
if (getLinkStatus(UI->linkNumber_SPINBOX->value())==0)
|
|
|
{
|
|
|
return UI->starDundeeStatusQueryDialog->exec();
|
|
|
}
|
|
|
if (!USBSpaceWire_TC_Reset(hDevice))
|
|
|
{
|
|
|
emit sendMessage("ERR *** in Open *** Could not reset timecodes\n");
|
|
|
}
|
|
|
emit sendMessage("OK *** in Open *** reset timecodes");
|
|
|
|
|
|
// Clear the tick enable register
|
|
|
if (CFGSpaceWire_SetTickEnableStatus(hDevice, 6) != CFG_TRANSFER_SUCCESS)
|
|
|
emit sendMessage("Could not clear the tick enable register");
|
|
|
else
|
|
|
emit sendMessage("Cleared the tick enable register");
|
|
|
|
|
|
CFGSpaceWire_GetTickEnableStatus(hDevice, &dwTickEnableStatus);
|
|
|
emit sendMessage("OK *** in Open *** CFGSpaceWire_GetTickEnableStatus, code is " + QString::number(dwTickEnableStatus, 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
unsigned int MainWindow::getLinkStatus(unsigned char link)
|
|
|
{
|
|
|
U32 statusControl = 0, errorStatus = 0, portType = 0;
|
|
|
U32 linkStatus = 0, operatingSpeed = 0, outputPortConnection = 0;
|
|
|
char isLinkRunning = 0, isAutoStart = 0, isStart = 0, isDisabled = 0, isTristate = 0;
|
|
|
|
|
|
// Read the link status control register
|
|
|
if (CFGSpaceWire_GetLinkStatusControl(hDevice, 1, &statusControl) != CFG_TRANSFER_SUCCESS)
|
|
|
{
|
|
|
emit sendMessage("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);
|
|
|
//emit appendToLog("Configuration port error status = " + QString::number(errorStatus));
|
|
|
}
|
|
|
else if (portType == CFG_SPACEWIRE_EXTERNAL_PORT)
|
|
|
{
|
|
|
CFGSpaceWire_LSExternalErrorStatus(statusControl, &errorStatus);
|
|
|
//emit appendToLog("External port error status = " + QString::number(errorStatus));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
CFGSpaceWire_LSErrorStatus(statusControl, &errorStatus);
|
|
|
//emit appendToLog("SpaceWire link error status = " + QString::number(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);
|
|
|
//emit appendToLog("The link state is = " + QString::number(linkStatus));
|
|
|
//emit appendToLog("The link is running = " + QString::number(isLinkRunning));
|
|
|
//emit appendToLog("The autostart bit is enabled = " + QString::number(isAutoStart));
|
|
|
//emit appendToLog("The start bit is enabled = " + QString::number(isStart));
|
|
|
//emit appendToLog("The link is disabled = " + QString::number(isDisabled));
|
|
|
//emit appendToLog("The tri-state bit is enabled = " + QString::number(isAutoStart));
|
|
|
//emit appendToLog("The operating speed is = " + QString::number(operatingSpeed));
|
|
|
//emit appendToLog("This port is currently connected to output port = " + QString::number(outputPortConnection));
|
|
|
}
|
|
|
if (linkStatus == 5) return 1;
|
|
|
else return 0;
|
|
|
}
|
|
|
|
|
|
void MainWindow::reTestSPWLink() // SLOT
|
|
|
{
|
|
|
if (getLinkStatus(UI->linkNumber_SPINBOX->value()))
|
|
|
{
|
|
|
UI->starDundeeStatusQueryDialog->accept();
|
|
|
}
|
|
|
}
|
|
|
|