/* * Title: PupeSimulateWin.cpp * Author: M.Thomas BEAM Ltd * Date: 2007-02-13 * * Contents: Status Display * * Mod Rec: * */ #include #include #include #include #include #include #include #include #include #include #include #include PupeSimulateWin::PupeSimulateWin(QWidget* w,Control& c) : ocontrol(c) { QGridLayout* grid; QLabel* channelLabel; QLabel* dataFileLabel; QLabel* contentsLabel; QButton* fileSelectButton; QGroupBox* internalTimings; QGroupBox* cycleType; BString s; int row = 0; this->setMaximumSize(QSize(600,650)); grid = new QGridLayout(this,5,3); grid->setMargin(20); grid->setSpacing(20); s = "

Pupe Test Data

"; s += "

Enter specifications for the test data of a Pupe channel

"; contentsLabel = new QLabel(s.retStr(),this); ochannel = new QSpinBox(1,60,1,this,""); ochannel->setWrapping(true); channelLabel = new QLabel("Channel Number",this); dataFileLabel = new QLabel("Test Data file",this); osimulationRamFilename = new QLineEdit(this,"ramfilename"); fileSelectButton = new QPushButton("Select",this,""); oloadSimulationRam = new QPushButton("Load Test Data",this,""); oclearSimulationRam = new QPushButton("Clear Test Data",this,""); internalTimings = new QVGroupBox("Internal Timing Control",this); oiAdcClk = new QCheckBox("Use Internal Adc Clock",internalTimings,""); oiTiming = new QCheckBox("Use Internal Timings",internalTimings,""); oiCycleStop = new QCheckBox("Use Internal Timings for Cycle Stop",internalTimings,""); oiApply = new QPushButton("Apply",internalTimings,""); cycleType = new QVGroupBox("Cycle Type",this); ocycleType = new QLineEdit("",cycleType); oapplyCycleType = new QPushButton("Apply",cycleType); oInitialise = new QPushButton("Initialise FPGA",this); row = 0; grid->addWidget(contentsLabel,row,1); row++; grid->addWidget(channelLabel,row,0); grid->addWidget(ochannel,row,1); row++; grid->addWidget(dataFileLabel,row,0); grid->addWidget(osimulationRamFilename,row,1); grid->addWidget(fileSelectButton,row,2); row++; grid->addWidget(oloadSimulationRam,row,1); row++; grid->addWidget(oclearSimulationRam,row,1); row++; row++; grid->addWidget(internalTimings,row,1); row++; grid->addWidget(cycleType,row,1); row++; grid->addWidget(oInitialise,row,1); row++; connect(fileSelectButton,SIGNAL(clicked()),this,SLOT(selectFile())); connect(oloadSimulationRam,SIGNAL(clicked()),this,SLOT(loadRam())); connect(oclearSimulationRam,SIGNAL(clicked()),this,SLOT(clearRam())); connect(oInitialise,SIGNAL(clicked()),this,SLOT(initialiseFPGA())); connect(oiApply,SIGNAL(clicked()),this,SLOT(applyInternalTimings())); connect(oapplyCycleType,SIGNAL(clicked()),this,SLOT(applyCycleType())); } PupeSimulateWin::~PupeSimulateWin() {} void PupeSimulateWin::selectFile() { QString s = QFileDialog::getOpenFileName( "/usr/tms/data", "Tms Channel Test Data File (*.psd)", this, "open file dialog", "Choose a file" ); osimulationRamFilename->setText(s); } void PupeSimulateWin::show() { BError err; Tms::ConfigInfo info; QWidget::show(); if (err = ocontrol.getConfiguration(info)) { return; } ochannel->setMaxValue(info.puReferences.size()); } void PupeSimulateWin::loadRam() { BError err; BFile f; BString fname; Tms::PuChannel puChannel; BArray< UInt32 > data; int nb; fname = osimulationRamFilename->text().ascii(); if(err = ocontrol.getPuChannel(ochannel->value(), puChannel)){ warningDialog("Pupe Test Data - Loading",err); return; } if (err = f.open(fname,"r")) { warningDialog("Pupe Test Data - Loading",err); return; } data.resize(1024); if((nb = f.read(&data[0], 1024 * sizeof(UInt32))) <= 0){ err.set(1, BString("Error: Reading 1024 32bit data items from file: ") + fname); warningDialog("Pupe Test Data",err); return; } data.resize(nb / sizeof(UInt32)); if (err = ocontrol.setTestData(puChannel,true,data)) { warningDialog("Pupe Test Data - Loading",err); return; } gstatusbar->message("Ram Loaded",2000); } void PupeSimulateWin::initialiseFPGA() { BError err; if (err = ocontrol.initialiseServer()) { warningDialog("Attempind tmsControl::init()",err); return; } gstatusbar->message("FPGA initialised",2000); } void PupeSimulateWin::applyInternalTimings() { BError err; Tms::PuChannel puChannel; Tms::PupeConfig pupeConfig; pupeConfig.internalAdcClock = oiAdcClk->isChecked(); pupeConfig.internalTiming = oiTiming->isChecked(); pupeConfig.internalCycleStop = oiCycleStop->isChecked(); if(err = ocontrol.getPuChannel(ochannel->value(), puChannel)){ warningDialog("Pupe Apply Timings - ",err); return; } if(err = ocontrol.setPupeConfig(puChannel, pupeConfig)){ warningDialog("Pupe Apply Timings - ",err); return; } gstatusbar->message("Internal Timings Applied",2000); } void PupeSimulateWin::applyCycleType() { BError err; UInt32 cn; BString ct; BString cycleType = ocycleType->text().ascii(); // Get current cycle info if(err = ocontrol.getCycleNumber(cn)){ warningDialog("Setting Cycle Type - GetCycleInfo",err); return; } // Set NextCycle type if(err = ocontrol.setNextCycle(cn + 1, cycleType)){ warningDialog("Setting Cycle Type - SetNextCycle",err); return; } gstatusbar->message("Next Cycle Type set",2000); } void PupeSimulateWin::clearRam() { BError err; Tms::PuChannel puChannel; BArray< UInt32 > data; if(err = ocontrol.getPuChannel(ochannel->value(), puChannel)){ warningDialog("Pupe Test Data - Clear",err); return; } if(err = ocontrol.setTestData(puChannel, 0, data)){ warningDialog("Pupe Test Data- Clear",err); return; } gstatusbar->message("Ram Cleared",2000); } void PupeSimulateWin::warningDialog(BString title, BError err){ BString m; m = BString("
") + title + "

" + err.getString() + "

"; QMessageBox::warning(this, "Warning", m.retStr()); }