Go to the documentation of this file.00001 #include "boardwidget.h"
00002
00003 #include "roctabswidget.h"
00004
00005 #include <stdio.h>
00006
00007 #include "roc/defines_roc.h"
00008 #include "nxyter/defines_nxyter.h"
00009 #include "feet/defines_feet.h"
00010
00011 #include <QApplication>
00012 #include <QLineEdit>
00013 #include <QMessageBox>
00014 #include <QDateTime>
00015
00016 BoardWidget::BoardWidget(QWidget* parent, base::Board* brd) :
00017 SubWidget(parent),
00018 fBoard(brd)
00019 {
00020 setupUi(this);
00021
00022 QObject::connect(CloseButton, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
00023 QObject::connect(ResetButton, SIGNAL(clicked()), this, SLOT(resetBoard()));
00024 QObject::connect(PutButton, SIGNAL(clicked()), this, SLOT(putRegister()));
00025 QObject::connect(GetButton, SIGNAL(clicked()), this, SLOT(getRegister()));
00026
00027 std::list<std::string> lst;
00028 fBoard->fillRegAddrNames(lst);
00029
00030 std::list<std::string>::iterator iter = lst.begin();
00031 while (iter != lst.end()) {
00032 std::string name = *iter++;
00033 AddrCombo->addItem(name.c_str());
00034 }
00035
00036 int indx = AddrCombo->findText("ROC_ROCID");
00037 AddrCombo->setCurrentIndex(indx>=0 ? indx : 0);
00038
00039 getSubConfig();
00040 }
00041
00042 bool BoardWidget::getSubConfig()
00043 {
00044 InfoLbl->setText("Board information");
00045
00046 return true;
00047 }
00048
00049 bool BoardWidget::setSubToDefault()
00050 {
00051 int res = fBoard->setToDefault();
00052
00053 if (res!=0) showMessage("Communication problems", 1000);
00054 else showMessage("Set ROC regs to default", 3000);
00055
00056 getSubConfig();
00057
00058 return true;
00059 }
00060
00061
00062 void BoardWidget::putRegister()
00063 {
00064 uint32_t addr = fBoard->findRegAddressByName(AddrCombo->currentText().toAscii());
00065
00066 bool ok = addr!=base::Board::kAddrError;
00067 if (!ok) addr = AddrCombo->currentText().toUInt(&ok, 0);
00068
00069 if (!ok) {
00070 AddrLbl->setStyleSheet("QFrame { background-color:red; }");
00071 return;
00072 }
00073
00074 AddrLbl->setStyleSheet("QFrame { background-color:0; }");
00075
00076 uint32_t value = ValueCombo->currentText().toUInt(&ok, 0);
00077 if (!ok) {
00078 ValueLbl->setStyleSheet("QFrame { background-color:red; }");
00079
00080 return;
00081 }
00082 ValueLbl->setStyleSheet("QFrame { background-color:0; }");
00083
00084 int err = fBoard->put(addr, value);
00085
00086 if (err!=0)
00087 QMessageBox::warning(this, "Put register", QString("Operation fail with code %1").arg(err));
00088 }
00089
00090 void BoardWidget::getRegister()
00091 {
00092 uint32_t addr = fBoard->findRegAddressByName(AddrCombo->currentText().toAscii());
00093 bool ok = addr!=base::Board::kAddrError;
00094 if (!ok) addr = AddrCombo->currentText().toUInt(&ok, 0);
00095
00096 if (!ok) {
00097 AddrLbl->setStyleSheet("QFrame { background-color:red; }");
00098 return;
00099 }
00100
00101 AddrLbl->setStyleSheet("QFrame { background-color:0; }");
00102
00103 uint32_t value(0);
00104 int err = fBoard->get(addr, value);
00105
00106 if (err==0) {
00107 QString txt = QString::number(value) + " (0x" + QString("%1").arg(value, 8, 16, QChar('0')).toUpper() + ")";
00108 ValueCombo->addItem(txt);
00109 ValueCombo->setCurrentIndex(ValueCombo->findText(txt));
00110 } else
00111 QMessageBox::warning(this, "Get register", QString("Operation fail with code %1").arg(err));
00112 }
00113
00114 void BoardWidget::resetBoard()
00115 {
00116 if (QMessageBox::question(this, "Board reset", "Program will exit after board restart. Are you sure?",
00117 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
00118 fBoard->restartBoard();
00119 QApplication::instance()->quit();
00120 }
00121 }