added SettingsExplorer to inspect and change setting files
This commit is contained in:
parent
649cb1554a
commit
6652416901
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,6 +13,7 @@ DataReader
|
||||||
pid.dat
|
pid.dat
|
||||||
DAQLock.dat
|
DAQLock.dat
|
||||||
DumpFSU2ROOT
|
DumpFSU2ROOT
|
||||||
|
SettingsExplorer
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
|
||||||
|
|
||||||
OBJS = ClassDigitizer.o MultiBuilder.o
|
OBJS = ClassDigitizer.o MultiBuilder.o
|
||||||
|
|
||||||
ALL = test test_indep DataGenerator EventBuilder DataReader DumpFSU2ROOT
|
ALL = test test_indep DataGenerator EventBuilder DataReader DumpFSU2ROOT SettingsExplorer
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
|
@ -52,3 +52,7 @@ EventBuilder : EventBuilder.cpp ../ClassData.h MultiBuilder.o
|
||||||
DumpFSU2ROOT : DumpFSU2ROOT.cpp ../ClassData.h MultiBuilder.o
|
DumpFSU2ROOT : DumpFSU2ROOT.cpp ../ClassData.h MultiBuilder.o
|
||||||
@echo "--------- making DumpFSU2ROOT"
|
@echo "--------- making DumpFSU2ROOT"
|
||||||
$(CC) $(COPTS) -o DumpFSU2ROOT DumpFSU2ROOT.cpp ../ClassData.h MultiBuilder.o $(ROOTLIBS)
|
$(CC) $(COPTS) -o DumpFSU2ROOT DumpFSU2ROOT.cpp ../ClassData.h MultiBuilder.o $(ROOTLIBS)
|
||||||
|
|
||||||
|
SettingsExplorer : SettingsExplorer.cpp ../ClassDigitizer.o ../RegisterAddress.h
|
||||||
|
@echo "--------- making SettingsExplorer"
|
||||||
|
$(CC) $(COPTS) -o SettingsExplorer SettingsExplorer.cpp ../ClassDigitizer.o $(CAENLIBS)
|
||||||
|
|
342
Aux/SettingsExplorer.cpp
Normal file
342
Aux/SettingsExplorer.cpp
Normal file
|
@ -0,0 +1,342 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <bitset>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <ctime>
|
||||||
|
#include <sys/time.h> /* struct timeval, select() */
|
||||||
|
#include <termios.h> /* tcgetattr(), tcsetattr() */
|
||||||
|
|
||||||
|
#include "../RegisterAddress.h"
|
||||||
|
#include "../ClassDigitizer.h"
|
||||||
|
|
||||||
|
static struct termios g_old_kbd_mode;
|
||||||
|
static void cooked(void); ///set keyboard behaviour as wait-for-enter
|
||||||
|
static void uncooked(void); ///set keyboard behaviour as immediate repsond
|
||||||
|
static void raw(void);
|
||||||
|
int getch(void);
|
||||||
|
bool isNumeric(const std::string& str) ;
|
||||||
|
int keyboardhit();
|
||||||
|
|
||||||
|
Digitizer * digi = nullptr;
|
||||||
|
|
||||||
|
std::vector<Reg> RegList;
|
||||||
|
|
||||||
|
bool QuitFlag = false;
|
||||||
|
|
||||||
|
void PrintCommands(){
|
||||||
|
if (QuitFlag) return;
|
||||||
|
printf("\n");
|
||||||
|
printf("\e[96m============= Command List ===================\e[0m\n");
|
||||||
|
printf("q ) Quit \n");
|
||||||
|
printf("b ) Print Board Settings\n");
|
||||||
|
printf("c ) Print Channel Settings\n");
|
||||||
|
printf("x ) Export binary to text file\n");
|
||||||
|
printf("* invalid input = back to upper level \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void keyPressCommand(){
|
||||||
|
|
||||||
|
char c = getch();
|
||||||
|
if (c == 'q') { //========== quit
|
||||||
|
QuitFlag = true;
|
||||||
|
}
|
||||||
|
if (c == 'b') { //==========
|
||||||
|
|
||||||
|
if( digi->GetDPPType() == DPPType::DPP_PHA_CODE || digi->GetDPPType() == DPPType::DPP_PSD_CODE ){
|
||||||
|
RegList = RegisterBoardList_PHAPSD;
|
||||||
|
}else if(digi->GetDPPType() == DPPType::DPP_QDC_CODE) {
|
||||||
|
RegList = RegisterBoardList_QDC;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < (int) RegList.size(); i++){
|
||||||
|
std::string typeStr ;
|
||||||
|
if( RegList[i].GetRWType() == RW::ReadWrite ) typeStr = "R/W";
|
||||||
|
if( RegList[i].GetRWType() == RW::ReadONLY ) typeStr = "R ";
|
||||||
|
if( RegList[i].GetRWType() == RW::WriteONLY ) typeStr = " W";
|
||||||
|
|
||||||
|
|
||||||
|
printf("%2d | 0x%04X %30s %s 0x%08X = %u\n", i,
|
||||||
|
RegList[i].GetAddress(),
|
||||||
|
RegList[i].GetNameChar(),
|
||||||
|
typeStr.c_str(),
|
||||||
|
digi->GetSettingFromMemory(RegList[i], 0),
|
||||||
|
digi->GetSettingFromMemory(RegList[i], 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string input = "-1";
|
||||||
|
cooked();
|
||||||
|
do{
|
||||||
|
std::cout << "Enter Setting ID to change the setting : ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
|
||||||
|
if( !isNumeric(input) ) break;
|
||||||
|
|
||||||
|
int ID = atoi(input.c_str());
|
||||||
|
if( 0 <= ID && ID < (int) RegList.size() ){
|
||||||
|
|
||||||
|
printf("\e[34mSelected %s = 0x%08X = %u \e[0m\n", RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], 0),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], 0));
|
||||||
|
|
||||||
|
if( RegList[ID].GetRWType() == RW::ReadONLY ) {
|
||||||
|
printf("This register is READ-ONLY.\n");
|
||||||
|
}else if (RegList[ID].GetRWType() == RW::WriteONLY){
|
||||||
|
printf("This register is WRITE-ONLY, which is a command. no need to set value.\n");
|
||||||
|
}else{
|
||||||
|
std::cout << "What value ? ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
if( isNumeric(input) ){
|
||||||
|
digi->SetSettingToMemory(RegList[ID], atoi(input.c_str()), 0);
|
||||||
|
digi->SaveSettingToFile(RegList[ID], atoi(input.c_str()), 0);
|
||||||
|
printf("\e[31mNow %s = 0x%08X = %u \e[0m\n", RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], 0),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], 0));
|
||||||
|
}else{
|
||||||
|
printf("Entered non numerical.\n");
|
||||||
|
input = "-1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}while( isNumeric( input) );
|
||||||
|
uncooked();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c == 'c' ){
|
||||||
|
cooked();
|
||||||
|
std::string input = "-1";
|
||||||
|
std::cout << "Enter channel number (# of ch = " << digi->GetNumRegChannels() << ") : ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
|
||||||
|
if( !isNumeric(input) ) {
|
||||||
|
uncooked();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
int ch = atoi(input.c_str());
|
||||||
|
|
||||||
|
if( ch < 0 || ch >= digi->GetNumRegChannels() ){
|
||||||
|
printf("Input channel number = %d, outrange of the supported channel\n", ch);
|
||||||
|
uncooked();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( digi->GetDPPType() == DPPType::DPP_PHA_CODE ) RegList = RegisterChannelList_PHA;
|
||||||
|
if( digi->GetDPPType() == DPPType::DPP_PSD_CODE ) RegList = RegisterChannelList_PSD;
|
||||||
|
if( digi->GetDPPType() == DPPType::DPP_QDC_CODE ) RegList = RegisterChannelList_QDC;
|
||||||
|
|
||||||
|
for( int i = 0; i < (int) RegList.size(); i++){
|
||||||
|
std::string typeStr ;
|
||||||
|
if( RegList[i].GetRWType() == RW::ReadWrite ) typeStr = "R/W";
|
||||||
|
if( RegList[i].GetRWType() == RW::ReadONLY ) typeStr = "R ";
|
||||||
|
if( RegList[i].GetRWType() == RW::WriteONLY ) typeStr = " W";
|
||||||
|
|
||||||
|
RegList[i].ActualAddress(ch);
|
||||||
|
|
||||||
|
printf("%2d | 0x%04X %30s %s 0x%08X = %u\n", i,
|
||||||
|
RegList[i].GetAddress(),
|
||||||
|
RegList[i].GetNameChar(),
|
||||||
|
typeStr.c_str(),
|
||||||
|
digi->GetSettingFromMemory(RegList[i], ch),
|
||||||
|
digi->GetSettingFromMemory(RegList[i], ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
do{
|
||||||
|
std::cout << "Enter Setting ID to change the setting : ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
|
||||||
|
if( !isNumeric(input) ) break;
|
||||||
|
|
||||||
|
int ID = atoi(input.c_str());
|
||||||
|
if( 0 <= ID && ID < (int) RegList.size() ){
|
||||||
|
|
||||||
|
printf("\e[34mID=%d | ch-%d | Selected %s = 0x%08X = %u \e[0m\n", ID, ch, RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], ch),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], ch));
|
||||||
|
|
||||||
|
if( RegList[ID].GetRWType() == RW::ReadONLY ) {
|
||||||
|
printf("This register is READ-ONLY.\n");
|
||||||
|
}else if (RegList[ID].GetRWType() == RW::WriteONLY){
|
||||||
|
printf("This register is WRITE-ONLY, which is a command. no need to set value.\n");
|
||||||
|
}else{
|
||||||
|
std::cout << "What value (negative will change all channels) ? ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
if( isNumeric(input) ){
|
||||||
|
|
||||||
|
int value = atoi(input.c_str());
|
||||||
|
|
||||||
|
printf(" input : %s %d\n", input.c_str(), value);
|
||||||
|
if( value < 0 ){
|
||||||
|
value = abs(value);
|
||||||
|
for( int i = 0; i < digi->GetNumRegChannels(); i++){
|
||||||
|
digi->SetSettingToMemory(RegList[ID], value, i);
|
||||||
|
digi->SaveSettingToFile(RegList[ID], value, i);
|
||||||
|
printf("\e[31mNow ch-%2d %s = 0x%08X = %u \e[0m\n", i, RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], i),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], i));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
|
||||||
|
|
||||||
|
digi->SetSettingToMemory(RegList[ID], value, ch);
|
||||||
|
digi->SaveSettingToFile(RegList[ID], value, ch);
|
||||||
|
printf("\e[31mNow ch-%2d %s = 0x%08X = %u \e[0m\n", ch, RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], ch),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], ch));
|
||||||
|
|
||||||
|
if( RegList[ID].IsCoupled() ){
|
||||||
|
int cpCh = (ch%2 == 0 ? ch + 1 : ch - 1);
|
||||||
|
digi->SetSettingToMemory(RegList[ID], value, cpCh);
|
||||||
|
digi->SaveSettingToFile(RegList[ID], value, cpCh);
|
||||||
|
printf("\e[31mNow ch-%2d %s = 0x%08X = %u \e[0m\n", cpCh, RegList[ID].GetNameChar(),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], cpCh),
|
||||||
|
digi->GetSettingFromMemory(RegList[ID], cpCh));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
printf("Entered non numerical.\n");
|
||||||
|
input = "-1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}while( isNumeric( input) );
|
||||||
|
|
||||||
|
|
||||||
|
uncooked();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 'x') { //==========
|
||||||
|
cooked(); ///set keyboard need enter to responds
|
||||||
|
|
||||||
|
std::string input = "haha.txt";
|
||||||
|
std::cout << "Eneter file name : ";
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
digi->SaveAllSettingsAsText(input);
|
||||||
|
uncooked();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//################################################
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
printf("=========================================\n");
|
||||||
|
printf("=== Setting Binary Explorer ===\n");
|
||||||
|
printf("=========================================\n");
|
||||||
|
if (argc != 2) {
|
||||||
|
printf("Incorrect number of arguments:\n");
|
||||||
|
printf("%s *bin \n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
digi = new Digitizer();
|
||||||
|
digi->LoadSettingBinaryToMemory(argv[1]);
|
||||||
|
|
||||||
|
if( !(digi->GetDPPType() == DPPType::DPP_PHA_CODE ||
|
||||||
|
digi->GetDPPType() == DPPType::DPP_PSD_CODE ||
|
||||||
|
digi->GetDPPType() == DPPType::DPP_QDC_CODE )){
|
||||||
|
printf("DPP-type not supported. Or Binary file is not supported.\n");
|
||||||
|
delete digi;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//digi->PrintSettingFromMemory();
|
||||||
|
|
||||||
|
PrintCommands();
|
||||||
|
|
||||||
|
do{
|
||||||
|
|
||||||
|
if(keyboardhit()) {
|
||||||
|
|
||||||
|
keyPressCommand();
|
||||||
|
|
||||||
|
PrintCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
}while(!QuitFlag);
|
||||||
|
|
||||||
|
delete digi;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//################################################
|
||||||
|
|
||||||
|
bool isNumeric(const std::string& str) {
|
||||||
|
try {
|
||||||
|
size_t pos = 0;
|
||||||
|
std::stoi(str, &pos);
|
||||||
|
return pos == str.size(); // Check if the entire string was used in conversion
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cooked(void){
|
||||||
|
tcsetattr(0, TCSANOW, &g_old_kbd_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uncooked(void){
|
||||||
|
struct termios new_kbd_mode;
|
||||||
|
/* put keyboard (stdin, actually) in raw, unbuffered mode */
|
||||||
|
tcgetattr(0, &g_old_kbd_mode);
|
||||||
|
memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios));
|
||||||
|
new_kbd_mode.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
new_kbd_mode.c_cc[VTIME] = 0;
|
||||||
|
new_kbd_mode.c_cc[VMIN] = 1;
|
||||||
|
tcsetattr(0, TCSANOW, &new_kbd_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void raw(void){
|
||||||
|
|
||||||
|
static char init;
|
||||||
|
if(init) return;
|
||||||
|
/* put keyboard (stdin, actually) in raw, unbuffered mode */
|
||||||
|
uncooked();
|
||||||
|
/* when we exit, go back to normal, "cooked" mode */
|
||||||
|
atexit(cooked);
|
||||||
|
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getch(void){
|
||||||
|
unsigned char temp;
|
||||||
|
raw();
|
||||||
|
/* stdin = fd 0 */
|
||||||
|
if(read(0, &temp, 1) != 1) return 0;
|
||||||
|
//printf("%s", &temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int keyboardhit(){
|
||||||
|
|
||||||
|
struct timeval timeout;
|
||||||
|
fd_set read_handles;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
raw();
|
||||||
|
/* check stdin (fd 0) for activity */
|
||||||
|
FD_ZERO(&read_handles);
|
||||||
|
FD_SET(0, &read_handles);
|
||||||
|
timeout.tv_sec = timeout.tv_usec = 0;
|
||||||
|
status = select(0 + 1, &read_handles, NULL, NULL, &timeout);
|
||||||
|
if(status < 0){
|
||||||
|
printf("select() failed in keyboardhit()\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return (status);
|
||||||
|
}
|
|
@ -937,9 +937,9 @@ int Digitizer::LoadSettingBinaryToMemory(std::string fileName){
|
||||||
if( dummy != 0 ) printf("reach the end of file (read %ld).\n", dummy);
|
if( dummy != 0 ) printf("reach the end of file (read %ld).\n", dummy);
|
||||||
|
|
||||||
uint32_t boardInfo = GetSettingFromMemory(DPP::BoardInfo_R);
|
uint32_t boardInfo = GetSettingFromMemory(DPP::BoardInfo_R);
|
||||||
if( (boardInfo & 0xFF) == 0x0E ) tick2ns = 4.0; // 725
|
if( (boardInfo & 0xFF) == 0x0E ) {tick2ns = 4.0; NumRegChannel = 16;}// 725
|
||||||
if( (boardInfo & 0xFF) == 0x0B ) tick2ns = 2.0; // 730
|
if( (boardInfo & 0xFF) == 0x0B ) {tick2ns = 2.0; NumRegChannel = 16;}// 730
|
||||||
if( (boardInfo & 0xFF) == 0x04 ) tick2ns = 16.0; // 740
|
if( (boardInfo & 0xFF) == 0x04 ) {tick2ns = 16.0; NumRegChannel = 8;}// 740
|
||||||
|
|
||||||
///Should seperate file<->memory, memory<->board
|
///Should seperate file<->memory, memory<->board
|
||||||
///ProgramSettingsToBoard(); /// do nothing if not connected.
|
///ProgramSettingsToBoard(); /// do nothing if not connected.
|
||||||
|
@ -1006,7 +1006,7 @@ void Digitizer::SaveAllSettingsAsBin(std::string fileName){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Digitizer::SaveAllSettingsAsText(std::string fileName){
|
void Digitizer::SaveAllSettingsAsText(std::string fileName){
|
||||||
if( !isSettingFilledinMemeory ) return;
|
if( !isSettingFilledinMemeory && isConnected) return;
|
||||||
|
|
||||||
FILE * txtFile = fopen(fileName.c_str(), "w+");
|
FILE * txtFile = fopen(fileName.c_str(), "w+");
|
||||||
if( txtFile == NULL ) {
|
if( txtFile == NULL ) {
|
||||||
|
@ -1060,6 +1060,10 @@ void Digitizer::SaveAllSettingsAsText(std::string fileName){
|
||||||
setting[i]);
|
setting[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Saved setting as text to %s.\n", fileName.c_str());
|
||||||
|
fclose(txtFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Digitizer::GetDPPString(int DPPType){
|
std::string Digitizer::GetDPPString(int DPPType){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user