simplifed DigitizerClass read write using const Reg

This commit is contained in:
Ryan Tang 2023-02-28 17:36:40 -05:00
parent 58969da70e
commit ec7d8ff740
5 changed files with 39 additions and 77 deletions

View File

@ -101,16 +101,13 @@ std::string Digitizer2Gen::GetPath(uint64_t handle){
//########################################### Read Write //########################################### Read Write
int Digitizer2Gen::FindIndex(const Reg para){ int Digitizer2Gen::FindIndex(const Reg para){
switch (para.GetType() ){ switch (para.GetType() ){
case TYPE::CH: return chMap[para.GetPara()]; case TYPE::CH: return chMap[para.GetPara()];
case TYPE::DIG: return boardMap[para.GetPara()]; case TYPE::DIG: return boardMap[para.GetPara()];
case TYPE::VGA: return 0; case TYPE::VGA: return 0;
case TYPE::LVDS: return -1; case TYPE::LVDS: return -1;
} }
return -1; return -1;
} }
std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){ std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){
@ -140,29 +137,6 @@ std::string Digitizer2Gen::ReadValue(const Reg para, int ch_index, bool verbose
return ans; return ans;
} }
std::string Digitizer2Gen::ReadDigValue(std::string shortPara, bool verbose){
std::string haha = "/par/" + shortPara;
std::string ans = ReadValue(haha.c_str(), verbose);
for( int i = 0; i < (int) boardSettings.size(); i++){
if( boardSettings[i].GetPara() == shortPara ) boardSettings[i].SetValue(ans);
}
return ans;
}
std::string Digitizer2Gen::ReadChValue(std::string ch, std::string shortPara, bool verbose){
std::string haha = "/ch/" + ch + "/par/" + shortPara;
std::string ans = ReadValue(haha.c_str(), verbose);
const int index = atoi(ch.c_str());
for( int i = 0; i < (int) chSettings[index].size(); i++){
if( chSettings[index][i].GetPara() == shortPara ) chSettings[index][i].SetValue(ans);
}
return ans;
}
bool Digitizer2Gen::WriteValue(const char * parameter, std::string value){ bool Digitizer2Gen::WriteValue(const char * parameter, std::string value){
if( !isConnected ) return false; if( !isConnected ) return false;
printf(" %s|%-45s|%s|\n", __func__, parameter, value.c_str()); printf(" %s|%-45s|%s|\n", __func__, parameter, value.c_str());
@ -180,7 +154,13 @@ bool Digitizer2Gen::WriteValue(const Reg para, std::string value, int ch_index){
int index = FindIndex(para); int index = FindIndex(para);
if( index != -1 ){ if( index != -1 ){
switch(para.GetType()){ switch(para.GetType()){
case TYPE::CH : chSettings[ch_index][index].SetValue(value); break; case TYPE::CH :{
if( ch_index >= 0 ){
chSettings[ch_index][index].SetValue(value);
}else{
for( int ch = 0; ch < nChannels; ch++ ) chSettings[ch][index].SetValue(value);
}
}break;
case TYPE::VGA : VGASetting[ch_index].SetValue(value); break; case TYPE::VGA : VGASetting[ch_index].SetValue(value); break;
case TYPE::DIG : boardSettings[index].SetValue(value); break; case TYPE::DIG : boardSettings[index].SetValue(value); break;
case TYPE::LVDS : break; case TYPE::LVDS : break;
@ -192,16 +172,6 @@ bool Digitizer2Gen::WriteValue(const Reg para, std::string value, int ch_index){
} }
} }
bool Digitizer2Gen::WriteDigValue(std::string shortPara, std::string value){
std::string haha = "/par/" + shortPara;
return WriteValue(haha.c_str(), value);
}
bool Digitizer2Gen::WriteChValue(std::string ch, std::string shortPara, std::string value){
std::string haha = "/ch/" + ch + "/par/" + shortPara;
return WriteValue(haha.c_str(), value);
}
void Digitizer2Gen::SendCommand(const char * parameter){ void Digitizer2Gen::SendCommand(const char * parameter){
if( !isConnected ) return; if( !isConnected ) return;
printf("Send Command : %s \n", parameter); printf("Send Command : %s \n", parameter);

View File

@ -91,12 +91,8 @@ class Digitizer2Gen {
std::string ReadValue(const char * parameter, bool verbose = false); std::string ReadValue(const char * parameter, bool verbose = false);
std::string ReadValue(const Reg para, int ch_index = -1, bool verbose = false); std::string ReadValue(const Reg para, int ch_index = -1, bool verbose = false);
std::string ReadDigValue(std::string shortPara, bool verbose = false);
std::string ReadChValue(std::string ch, std::string shortPara, bool verbose = false);
bool WriteValue(const char * parameter, std::string value); bool WriteValue(const char * parameter, std::string value);
bool WriteValue(const Reg para, std::string value, int ch_index = -1); bool WriteValue(const Reg para, std::string value, int ch_index = -1);
bool WriteDigValue(std::string shortPara, std::string value);
bool WriteChValue(std::string ch, std::string shortPara, std::string value);
void SendCommand(const char * parameter); void SendCommand(const char * parameter);
void SendCommand(std::string shortPara); void SendCommand(std::string shortPara);

View File

@ -706,10 +706,10 @@ void MainWindow::UpdateScalar(){
//=========== another method, directly readValue //=========== another method, directly readValue
digiMTX.lock(); digiMTX.lock();
for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){ for( int ch = 0; ch < digi[iDigi]->GetNChannels(); ch ++){
std::string time = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelRealtime); // for refreashing SelfTrgRate and SavedCount std::string time = digi[iDigi]->ReadValue(DIGIPARA::CH::ChannelRealtime, ch); // for refreashing SelfTrgRate and SavedCount
haha[ch] = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::SelfTrgRate); haha[ch] = digi[iDigi]->ReadValue(DIGIPARA::CH::SelfTrgRate, ch);
leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch])); leTrigger[iDigi][ch]->setText(QString::fromStdString(haha[ch]));
std::string kaka = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelSavedCount); std::string kaka = digi[iDigi]->ReadValue(DIGIPARA::CH::ChannelSavedCount, ch);
acceptRate[ch] = atoi(kaka.c_str())*1e9*1.0 / atol(time.c_str()); acceptRate[ch] = atoi(kaka.c_str())*1e9*1.0 / atol(time.c_str());
//if( kaka != "0" ) printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate); //if( kaka != "0" ) printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1)); leAccept[iDigi][ch]->setText(QString::number(acceptRate[ch],'f', 1));

View File

@ -80,8 +80,8 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue("0..63", DIGIPARA::CH::ChannelEnable, "false"); digi[iDigi]->WriteValue(DIGIPARA::CH::ChannelEnable, "false", -1);
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::ChannelEnable, "true"); digi[iDigi]->WriteValue(DIGIPARA::CH::ChannelEnable, "true", ch);
ReadScopeSettings(iDigi, ch); ReadScopeSettings(iDigi, ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
@ -141,7 +141,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveAnalogProbe0, (cbAnaProbe[0]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveAnalogProbe0, (cbAnaProbe[0]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
@ -150,7 +150,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveAnalogProbe1, (cbAnaProbe[1]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveAnalogProbe1, (cbAnaProbe[1]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
@ -195,7 +195,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveDigitalProbe0, (cbDigProbe[0]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveDigitalProbe0, (cbDigProbe[0]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
connect(cbDigProbe[1], &QComboBox::currentIndexChanged, this, [=](){ connect(cbDigProbe[1], &QComboBox::currentIndexChanged, this, [=](){
@ -203,7 +203,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveDigitalProbe1, (cbDigProbe[1]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveDigitalProbe1, (cbDigProbe[1]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
connect(cbDigProbe[2], &QComboBox::currentIndexChanged, this, [=](){ connect(cbDigProbe[2], &QComboBox::currentIndexChanged, this, [=](){
@ -211,7 +211,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveDigitalProbe2, (cbDigProbe[2]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveDigitalProbe2, (cbDigProbe[2]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
connect(cbDigProbe[3], &QComboBox::currentIndexChanged, this, [=](){ connect(cbDigProbe[3], &QComboBox::currentIndexChanged, this, [=](){
@ -219,7 +219,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
int ch = cbScopeCh->currentIndex(); int ch = cbScopeCh->currentIndex();
digiMTX.lock(); digiMTX.lock();
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::WaveDigitalProbe3, (cbDigProbe[3]->currentData()).toString().toStdString()); digi[iDigi]->WriteValue(DIGIPARA::CH::WaveDigitalProbe3, (cbDigProbe[3]->currentData()).toString().toStdString(), ch);
digiMTX.unlock(); digiMTX.unlock();
}); });
@ -432,8 +432,8 @@ void Scope::StartScope(){
ReadScopeSettings(iDigi, ch); ReadScopeSettings(iDigi, ch);
digi[iDigi]->WriteChValue("0..63", DIGIPARA::CH::ChannelEnable, "false"); digi[iDigi]->WriteValue(DIGIPARA::CH::ChannelEnable, "false", -1);
digi[iDigi]->WriteChValue(std::to_string(ch), DIGIPARA::CH::ChannelEnable, "true"); digi[iDigi]->WriteValue(DIGIPARA::CH::ChannelEnable, "true", ch);
digi[iDigi]->SetPHADataFormat(0); digi[iDigi]->SetPHADataFormat(0);
digi[iDigi]->StartACQ(); digi[iDigi]->StartACQ();
@ -461,7 +461,7 @@ void Scope::StopScope(){
if( digi[i]->IsDummy() ) continue; if( digi[i]->IsDummy() ) continue;
digiMTX.lock(); digiMTX.lock();
digi[i]->StopACQ(); digi[i]->StopACQ();
digi[i]->WriteChValue("0..63", DIGIPARA::CH::ChannelEnable, "true"); digi[i]->WriteValue(DIGIPARA::CH::ChannelEnable, "true", -1);
digiMTX.unlock(); digiMTX.unlock();
readDataThread[i]->quit(); readDataThread[i]->quit();
@ -488,8 +488,8 @@ void Scope::UpdateScope(){
for( int j = 0; j < 6; j++ ) dataTrace[j]->removePoints(0, dataLength); for( int j = 0; j < 6; j++ ) dataTrace[j]->removePoints(0, dataLength);
digiMTX.lock(); digiMTX.lock();
std::string time = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::ChannelRealtime); // for refreashing SelfTrgRate and SavedCount std::string time = digi[iDigi]->ReadValue(DIGIPARA::CH::ChannelRealtime, ch); // for refreashing SelfTrgRate and SavedCount
std::string haha = digi[iDigi]->ReadChValue(std::to_string(ch), DIGIPARA::CH::SelfTrgRate); std::string haha = digi[iDigi]->ReadValue(DIGIPARA::CH::SelfTrgRate, ch);
leTriggerRate->setText(QString::fromStdString(haha)); leTriggerRate->setText(QString::fromStdString(haha));
if( atoi(haha.c_str()) == 0 ) { if( atoi(haha.c_str()) == 0 ) {
digiMTX.unlock(); digiMTX.unlock();
@ -569,13 +569,13 @@ void Scope::ScopeControlOnOff(bool on){
cbLowFreqFilter->setEnabled(on); cbLowFreqFilter->setEnabled(on);
} }
void Scope::ScopeReadSpinBoxValue(int iDigi, int ch, QSpinBox *sb, std::string digPara){ void Scope::ScopeReadSpinBoxValue(int iDigi, int ch, QSpinBox *sb, const Reg digPara){
std::string ans = digi[iDigi]->ReadChValue(std::to_string(ch), digPara); std::string ans = digi[iDigi]->ReadValue(digPara, ch);
sb->setValue(atoi(ans.c_str())); sb->setValue(atoi(ans.c_str()));
} }
void Scope::ScopeReadComboBoxValue(int iDigi, int ch, QComboBox *cb, std::string digPara){ void Scope::ScopeReadComboBoxValue(int iDigi, int ch, QComboBox *cb, const Reg digPara){
std::string ans = digi[iDigi]->ReadChValue(std::to_string(ch), digPara); std::string ans = digi[iDigi]->ReadValue(digPara, ch);
int index = cb->findData(QString::fromStdString(ans)); int index = cb->findData(QString::fromStdString(ans));
if( index >= 0 && index < cb->count()) { if( index >= 0 && index < cb->count()) {
cb->setCurrentIndex(index); cb->setCurrentIndex(index);
@ -584,7 +584,7 @@ void Scope::ScopeReadComboBoxValue(int iDigi, int ch, QComboBox *cb, std::string
} }
} }
void Scope::ScopeMakeSpinBox(QSpinBox *sb, QString str, QGridLayout *layout, int row, int col, int min, int max, int step, std::string digPara){ void Scope::ScopeMakeSpinBox(QSpinBox *sb, QString str, QGridLayout *layout, int row, int col, int min, int max, int step, const Reg digPara){
QLabel * lb = new QLabel(str, this); QLabel * lb = new QLabel(str, this);
lb->setAlignment(Qt::AlignRight | Qt::AlignCenter); lb->setAlignment(Qt::AlignRight | Qt::AlignCenter);
layout->addWidget(lb, row, col); layout->addWidget(lb, row, col);
@ -597,15 +597,13 @@ void Scope::ScopeMakeSpinBox(QSpinBox *sb, QString str, QGridLayout *layout, int
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
if( step > 1 ) sb->setValue(step*((sb->value() + step - 1)/step)); if( step > 1 ) sb->setValue(step*((sb->value() + step - 1)/step));
digiMTX.lock(); digiMTX.lock();
//TODO change to use Reg digi[iDigi]->WriteValue(digPara, std::to_string(sb->value()), cbScopeCh->currentIndex() );
digi[iDigi]->WriteChValue(std::to_string(cbScopeCh->currentIndex()), digPara, std::to_string(sb->value()));
digi[iDigi]->ReadChValue(std::to_string(cbScopeCh->currentIndex()), digPara);
digiMTX.unlock(); digiMTX.unlock();
}); });
//TODO digiSettingPanel update setting //TODO digiSettingPanel update setting
} }
void Scope::ScopeMakeComoBox(QComboBox *cb, QString str, QGridLayout *layout, int row, int col, std::string digPara){ void Scope::ScopeMakeComoBox(QComboBox *cb, QString str, QGridLayout *layout, int row, int col, const Reg digPara){
QLabel * lb = new QLabel(str, this); QLabel * lb = new QLabel(str, this);
lb->setAlignment(Qt::AlignRight | Qt::AlignCenter); lb->setAlignment(Qt::AlignRight | Qt::AlignCenter);
layout->addWidget(lb, row, col); layout->addWidget(lb, row, col);
@ -614,9 +612,7 @@ void Scope::ScopeMakeComoBox(QComboBox *cb, QString str, QGridLayout *layout, in
if( !allowChange ) return; if( !allowChange ) return;
int iDigi = cbScopeDigi->currentIndex(); int iDigi = cbScopeDigi->currentIndex();
digiMTX.lock(); digiMTX.lock();
//TODO change to use Reg digi[iDigi]->WriteValue(digPara, cb->currentData().toString().toStdString(), cbScopeCh->currentIndex());
digi[iDigi]->WriteChValue(std::to_string(cbScopeCh->currentIndex()), digPara, cb->currentData().toString().toStdString());
digi[iDigi]->ReadChValue(std::to_string(cbScopeCh->currentIndex()), digPara);
digiMTX.unlock(); digiMTX.unlock();
}); });
//TODO digiSettingPanel update setting //TODO digiSettingPanel update setting

View File

@ -113,10 +113,10 @@ private slots:
void StopScope(); void StopScope();
void UpdateScope(); void UpdateScope();
void ScopeControlOnOff(bool on); void ScopeControlOnOff(bool on);
void ScopeReadSpinBoxValue(int iDigi, int ch, QSpinBox *sb, std::string digPara); void ScopeReadSpinBoxValue(int iDigi, int ch, QSpinBox *sb, const Reg digPara);
void ScopeReadComboBoxValue(int iDigi, int ch, QComboBox *cb, std::string digPara); void ScopeReadComboBoxValue(int iDigi, int ch, QComboBox *cb, const Reg digPara);
void ScopeMakeSpinBox(QSpinBox * sb, QString str, QGridLayout* layout, int row, int col, int min, int max, int step, std::string digPara); void ScopeMakeSpinBox(QSpinBox * sb, QString str, QGridLayout* layout, int row, int col, int min, int max, int step, const Reg digPara);
void ScopeMakeComoBox(QComboBox * cb, QString str, QGridLayout* layout, int row, int col, std::string digPara); void ScopeMakeComoBox(QComboBox * cb, QString str, QGridLayout* layout, int row, int col, const Reg digPara);
void ProbeChange(QComboBox * cb[], const int size); void ProbeChange(QComboBox * cb[], const int size);
void closeEvent(QCloseEvent * event){ void closeEvent(QCloseEvent * event){