• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

gui/rocnxwidget.cpp (r4864/r4195)

Go to the documentation of this file.
00001 #include "rocnxwidget.h"
00002 
00003 #include "nxyter/RocNx.h"
00004 #include "nxyter/FebBase.h"
00005 #include "nxyter/defines_nxyter.h"
00006 
00007 #include "febwidget.h"
00008 
00009 #include <QGridLayout>
00010 #include <QLabel>
00011 #include <QSignalMapper>
00012 #include <QMessageBox>
00013 
00014 const int DelayAddrs[5] = { ROC_NX_DELAY_NX0, ROC_NX_DELAY_NX1, ROC_NX_DELAY_NX2, ROC_NX_DELAY_NX3, ROC_NX_DELAY_LTS };
00015 const char* DelayAddrsNames[5] = { "ROC_NX_DELAY_NX0", "ROC_NX_DELAY_NX1", "ROC_NX_DELAY_NX2", "ROC_NX_DELAY_NX3", "ROC_NX_DELAY_LTS" };
00016 const int LatencyAddrs[4] = { ROC_NX_ADC_LATENCY1, ROC_NX_ADC_LATENCY2, ROC_NX_ADC_LATENCY3, ROC_NX_ADC_LATENCY4 };
00017 
00018 
00019 RocNxWidget::RocNxWidget(QWidget* parent, base::Board* brd) :
00020    SubWidget(parent),
00021    fBoard(brd)
00022 {
00023    setupUi(this);
00024 
00025    QObject::connect(FirePulseButton, SIGNAL(clicked()), this, SLOT(firePulse()));
00026    QObject::connect(StopPulseButton, SIGNAL(clicked()), this, SLOT(stopPulse()));
00027    QObject::connect(ParityCheck, SIGNAL(stateChanged(int)), this, SLOT(parityChanged(int)));
00028 
00029    QObject::connect(DetectFebsButton, SIGNAL(clicked()), this, SLOT(detectFebs()));
00030    QObject::connect(AddFebButton, SIGNAL(clicked()), this, SLOT(addFeb()));
00031 
00032    addFebKind(nxyter::FebBase::kFeb1nxGenB, 0);
00033    addFebKind(nxyter::FebBase::kFeb1nxGenB, 1);
00034    addFebKind(nxyter::FebBase::kFeb1nxGenC, 0);
00035    addFebKind(nxyter::FebBase::kFeb1nxGenC, 1);
00036    addFebKind(nxyter::FebBase::kFeb1nxGenD, 0);
00037    addFebKind(nxyter::FebBase::kFeb1nxGenD, 1);
00038    addFebKind(nxyter::FebBase::kFeb2nxGas, 0);
00039    addFebKind(nxyter::FebBase::kFeb2nxGas, 1);
00040    addFebKind(nxyter::FebBase::kFeb4nxBT, 2);
00041 
00042    // delay
00043 
00044    QGridLayout* grid = new QGridLayout(DelayGroup);
00045    grid->setMargin(3);
00046    grid->setSpacing(3);
00047 
00048    QSignalMapper* map = new QSignalMapper(this);
00049 
00050    for (int n=0;n<5;n++) {
00051       grid->addWidget(new QLabel(QString(DelayAddrsNames[n]), this), n, 0);
00052 
00053       fDelaySpins[n] = new QSpinBox(this);
00054       fDelaySpins[n]->setMinimum(0);
00055       fDelaySpins[n]->setMaximum(1024);
00056       fDelaySpins[n]->setMinimumWidth(70);
00057       QObject::connect(fDelaySpins[n], SIGNAL(valueChanged(int)), map, SLOT(map()));
00058       map->setMapping(fDelaySpins[n], n);
00059 
00060       grid->addWidget(fDelaySpins[n], n, 1);
00061    }
00062 
00063    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(delayChanged(int)));
00064 
00065    DelayGroup->adjustSize();
00066 
00067    // latency
00068 
00069    grid = new QGridLayout(LatencyGroup);
00070    grid->setMargin(3);
00071    grid->setSpacing(3);
00072 
00073    map = new QSignalMapper(this);
00074 
00075    for (int n=0;n<4;n++) {
00076       grid->addWidget(new QLabel(QString("ROC_NX_ADC_LATENCY%1").arg(n+1), this), n, 0);
00077 
00078       fLatencySpins[n] = new QSpinBox(this);
00079       fLatencySpins[n]->setMinimum(0);
00080       fLatencySpins[n]->setMaximum(1024);
00081       fLatencySpins[n]->setMinimumWidth(70);
00082       QObject::connect(fLatencySpins[n], SIGNAL(valueChanged(int)), map, SLOT(map()));
00083       map->setMapping(fLatencySpins[n], n);
00084 
00085       grid->addWidget(fLatencySpins[n], n, 1);
00086    }
00087 
00088    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(latencyChanged(int)));
00089 
00090    LatencyGroup->adjustSize();
00091 
00092 
00093    getSubConfig();
00094 
00095 }
00096 
00097 bool RocNxWidget::getSubConfig()
00098 {
00099    base::OperList lst;
00100    for (int n=0;n<5;n++) lst.addGet(DelayAddrs[n]);
00101    for (int n=0;n<4;n++) lst.addGet(LatencyAddrs[n]);
00102    lst.addGet(ROC_NX_PARITY_CHECK);
00103    lst.addGet(ROC_NX_HWV);
00104 
00105    int res = fBoard->operGen(lst, 1.);
00106 
00107    if (res==0) {
00108       for (int n=0;n<5;n++) fDelaySpins[n]->setValue(lst.oper(n).value);
00109       for (int n=0;n<4;n++) fLatencySpins[n]->setValue(lst.oper(n+5).value);
00110 
00111       ParityCheck->setCheckState(lst.oper(9).value==0 ? Qt::Unchecked : Qt::Checked);
00112 
00113       VersionLabel->setText(QString("NX HW Version: %1").arg(roc::Board::versionToString(lst.oper(10).value)));
00114    }
00115 
00116    return res==0;
00117 }
00118 
00119 bool RocNxWidget::setSubConfig()
00120 {
00121    base::OperList lst;
00122    for (int n=0;n<5;n++) lst.addPut(DelayAddrs[n], fDelaySpins[n]->value());
00123    for (int n=0;n<4;n++) lst.addPut(LatencyAddrs[n], fLatencySpins[n]->value());
00124    lst.addPut(ROC_NX_PARITY_CHECK, (ParityCheck->checkState() == Qt::Checked) ? 1 : 0);
00125 
00126    return fBoard->operGen(lst, 1.) == 0;
00127 }
00128 
00129 bool RocNxWidget::setSubToDefault()
00130 {
00131    nxyter::RocNx r(fBoard);
00132    r.setToDefault();
00133 
00134 //   for (int n=0;n<4;n++) fDelaySpins[n]->setValue(288);
00135 //   fDelaySpins[4]->setValue(512);
00136 //   for (int n=0;n<4;n++) fLatencySpins[n]->setValue(65);
00137 //   ParityCheck->setCheckState(Qt::Checked);
00138 //   setSubChangedOn();
00139 
00140    return getSubConfig();
00141 }
00142 
00143 bool RocNxWidget::fillCmdFile(FILE* f)
00144 {
00145    fprintf(f, "\n// ROC-NX relevant settings Delay and latency\n");
00146    for (int n=0;n<5;n++)
00147       fprintf(f, "putroc %s,%d\n", DelayAddrsNames[n], fDelaySpins[n]->value());
00148    for (int n=0;n<4;n++)
00149       fprintf(f, "putroc ROC_NX_ADC_LATENCY%d,%d\n", n+1, fLatencySpins[n]->value());
00150    fprintf(f, "putroc ROC_NX_PARITY_CHECK,%d\n", (ParityCheck->checkState() == Qt::Checked) ? 1 : 0);
00151    fprintf(f, "// uncomment following line to disable testpulser\n");
00152    fprintf(f, "// firepulser -s\n");
00153 
00154    return true;
00155 }
00156 
00157 
00158 void RocNxWidget::firePulse()
00159 {
00160    nxyter::RocNx r(fBoard);
00161 
00162    r.fireTestPulse(PulsePeriodSpin->value()/4, PulseWidthSpin->value()/4, PulseNumberSpin->value());
00163 }
00164 
00165 void RocNxWidget::stopPulse()
00166 {
00167    nxyter::RocNx r(fBoard);
00168 
00169    r.fireTestPulse(0, 0, 0);
00170 }
00171 
00172 void RocNxWidget::delayChanged(int id)
00173 {
00174    uint32_t value = fDelaySpins[id]->value();
00175    fBoard->put(DelayAddrs[id], value, 1.);
00176 }
00177 
00178 void RocNxWidget::latencyChanged(int id)
00179 {
00180    uint32_t value = fLatencySpins[id]->value();
00181    fBoard->put(LatencyAddrs[id], value, 1.);
00182 }
00183 
00184 void RocNxWidget::parityChanged(int)
00185 {
00186    fBoard->put(ROC_NX_PARITY_CHECK, (ParityCheck->checkState() == Qt::Checked) ? 1 : 0, 1.);
00187 }
00188 
00189 void RocNxWidget::detectFebs()
00190 {
00191    int typeport0(0), typeport1(0);
00192 
00193    nxyter::FebBase::discoverFebs(fBoard, typeport0, typeport1);
00194 
00195    if (typeport0>0) addFebWidget(typeport0, 0);
00196    if (typeport1>0) addFebWidget(typeport1, 1);
00197 }
00198 
00199 void RocNxWidget::addFebKind(int kind, int port)
00200 {
00201    QString lbl = nxyter::FebBase::typeToString(kind);
00202    if (port<2) lbl += QString(":%1").arg(port);
00203    SelectFebsCombo->addItem(lbl, kind + port*1000000);
00204 }
00205 
00206 void RocNxWidget::selectFeb(const char* name)
00207 {
00208    int indx = SelectFebsCombo->findText(name);
00209    if (indx<0) indx = 0;
00210    SelectFebsCombo->setCurrentIndex(indx);
00211 }
00212 
00213 void RocNxWidget::addFebWidget(int kind, int port)
00214 {
00215    nxyter::FebBase* feb = nxyter::FebBase::newFeb(fBoard, port < 2 ? port : 0, kind);
00216 
00217    if (feb==0) {
00218       QMessageBox::warning(this, "Add Feb", "Cannot create FEB with specified parameters");
00219       return;
00220   }
00221 
00222    QString name = nxyter::FebBase::typeToString(kind);
00223    if (port<2) name += QString(":%1").arg(port);
00224 
00225    RocTabsWidget* tabs = dynamic_cast<RocTabsWidget*> (parentWidget()->parentWidget());
00226    if (tabs==0) exit(10);
00227 
00228    FebWidget* febw = new FebWidget(0, feb);
00229    tabs->addTab(febw, name);
00230    febw->createTabs(tabs);
00231 
00232    tabs->setCurrentWidget(febw);
00233 }
00234 
00235 void RocNxWidget::addFeb()
00236 {
00237    int kind = SelectFebsCombo->itemData(SelectFebsCombo->currentIndex()).toInt();
00238 
00239    addFebWidget(kind % 1000000, kind / 1000000);
00240 }
00241 

Generated on Tue Dec 10 2013 04:52:22 for ROCsoft by  doxygen 1.7.1