mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 15:15:56 +01:00
added trimval function, but sending trimbits from char to int bug
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
#include "slsDetectorServer_defs.h" //include port number
|
||||
|
||||
struct sockaddr_in eiger_socket_addr;
|
||||
int eiger_max_message_length = 1024;
|
||||
char eiger_message[1024];
|
||||
int eiger_max_message_length = 270000;//263681
|
||||
char eiger_message[270000];//263681
|
||||
int eiger_message_length = 0;
|
||||
int eiger_ret_val=0;
|
||||
|
||||
@@ -55,6 +55,8 @@ int EigerGetExternalGating(){return eiger_extgating;}
|
||||
int EigerGetExternalGatingPolarity(){return eiger_extgatingpolarity;}
|
||||
|
||||
int EigerInit(){
|
||||
saved_trimbits[0] = -1;
|
||||
|
||||
static int passed = 0;
|
||||
|
||||
if(!passed){
|
||||
@@ -145,7 +147,7 @@ int EigerSetTrimbits(const int *data){
|
||||
int ichip;
|
||||
|
||||
// convert the trimbits from int32 to chars and add border pixels.
|
||||
for(iy=0;iy<256;y++) {
|
||||
for(iy=0;iy<256;iy++) {
|
||||
for (ichip=0; ichip<4; ichip++) {
|
||||
for(ix=0;ix<256;ix++) {
|
||||
tt[ip++]=(char)(data[ich++]&(0x3f));
|
||||
@@ -170,12 +172,13 @@ int EigerSetAllTrimbits(unsigned int value){
|
||||
int ip=0, ich=0;
|
||||
int iy, ix;
|
||||
int ichip;
|
||||
int sl=0;
|
||||
|
||||
// convert the trimbits from int32 to chars and add border pixels.
|
||||
for(iy=0;iy<256;y++) {
|
||||
for(iy=0;iy<256;iy++) {
|
||||
for (ichip=0; ichip<4; ichip++) {
|
||||
for(ix=0;ix<256;ix++) {
|
||||
tt[ip++]=value&0x3f;
|
||||
tt[ip++]=(char)(value&0x3f);
|
||||
}
|
||||
if (ichip<3) {
|
||||
tt[ip++]=0;
|
||||
@@ -183,30 +186,27 @@ int EigerSetAllTrimbits(unsigned int value){
|
||||
}
|
||||
}
|
||||
}
|
||||
eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
|
||||
memcpy(saved_trimbits,data,256*256*4*sizeof(int));
|
||||
|
||||
char s2[270000];
|
||||
strcpy(s2,"settrimbits ");
|
||||
//for()
|
||||
sl=strlen(s2);
|
||||
strncpy(s2+sl,tt, 263680);
|
||||
s2[263680+sl]='\0';
|
||||
|
||||
eiger_message_length = strlen(s2);
|
||||
//eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
|
||||
for (iy=0;iy<263680;++iy)
|
||||
printf("%d:%c\t\t",iy,tt[iy]);
|
||||
printf("tfggt:%s , length :%d\n",tt, strlen(tt));
|
||||
printf("Command sent:%s , length :%d\n",s2, eiger_message_length);
|
||||
for(iy=0;iy<256*256*4;++iy)
|
||||
saved_trimbits[iy] = value;
|
||||
return EigerSendCMD();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* int EigerGetTrimbits(const int *data){ */
|
||||
/* eiger_ret_val=0; */
|
||||
/* char tt[263681]; */
|
||||
/* tt[263680]='\0'; */
|
||||
/* int ip=0, ich=0; */
|
||||
/* int iy, ix; */
|
||||
/* int ichip; */
|
||||
|
||||
/* eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt); */
|
||||
/* memcpy(data,saved_trimbits,256*256*4*sizeof(int)); */
|
||||
/* return EigerSendCMD(); */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
||||
int EigerGetTrimbits(const int *data){
|
||||
eiger_ret_val=0;
|
||||
char tt[263681];
|
||||
@@ -222,9 +222,6 @@ int EigerSetAllTrimbits(unsigned int value){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int EigerGetDAC(const char* iname){
|
||||
eiger_ret_val=1;
|
||||
eiger_message_length = sprintf(eiger_message,"getdacvalue %s",iname);
|
||||
|
||||
@@ -698,62 +698,62 @@ float FebControl::GetDAC(string s){
|
||||
*/
|
||||
|
||||
bool FebControl::SetTrimbits(unsigned int module_num, unsigned char *trimbits){
|
||||
|
||||
unsigned int module_index=0;
|
||||
if(!GetModuleIndex(module_num,module_index)){
|
||||
cout<<"Warning could not set trimbits, bad module number."<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!Reset()) cout<<"Warning could not reset DAQ."<<endl;
|
||||
|
||||
for(int l_r=0;l_r<2;l_r++){ // l_r loop
|
||||
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
|
||||
|
||||
if(!(WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8)&&SetCommandRegister(DAQ_SET_STATIC_BIT)&&StartDAQOnlyNWaitForFinish())){
|
||||
cout<<"Could not select chips"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(int row_set=0;row_set<16;row_set++){ //16 rows at a time
|
||||
if(row_set==0){
|
||||
if(!SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){
|
||||
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
|
||||
return 0;
|
||||
printf("aaa\n");
|
||||
unsigned int module_index=0;
|
||||
if(!GetModuleIndex(module_num,module_index)){
|
||||
cout<<"Warning could not set trimbits, bad module number."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
if(!SetCommandRegister(DAQ_LOAD_16ROWS_OF_TRIMBITS)){
|
||||
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("bbb\n");
|
||||
if(!Reset()) cout<<"Warning could not reset DAQ."<<endl;
|
||||
printf("ccc\n");
|
||||
for(int l_r=0;l_r<2;l_r++){ // l_r loop
|
||||
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
|
||||
|
||||
static unsigned int trimbits_to_load_l[1024];
|
||||
static unsigned int trimbits_to_load_r[1024];
|
||||
for(int row=0;row<16;row++){ //row loop
|
||||
int offset = 2*32*row;
|
||||
for(int sc=0;sc<32;sc++){ //supercolumn loop sc
|
||||
int super_column_start_position_l = 1030*row + l_r *258 + sc*8;
|
||||
int super_column_start_position_r = 1030*row + 516 + l_r *258 + sc*8;
|
||||
int chip_sc = 31 - sc;
|
||||
trimbits_to_load_l[offset+chip_sc] = 0;
|
||||
trimbits_to_load_r[offset+chip_sc] = 0;
|
||||
for(int i=0;i<8;i++){ // column loop i
|
||||
trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])<<((7-i)*4);//low
|
||||
trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])>>3)<<((7-i)*4);//upper
|
||||
trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low
|
||||
trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper
|
||||
} // end column loop i
|
||||
} //end supercolumn loop sc
|
||||
} //end row loop
|
||||
if(!(WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8)&&SetCommandRegister(DAQ_SET_STATIC_BIT)&&StartDAQOnlyNWaitForFinish())){
|
||||
cout<<"Could not select chips"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) return 0;
|
||||
} //end row_set loop (groups of 16 rows)
|
||||
} // end l_r loop
|
||||
for(int row_set=0;row_set<16;row_set++){ //16 rows at a time
|
||||
if(row_set==0){
|
||||
if(!SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){
|
||||
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
if(!SetCommandRegister(DAQ_LOAD_16ROWS_OF_TRIMBITS)){
|
||||
cout<<"Warning: Could not SetCommandRegister for loading trim bits."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char));
|
||||
static unsigned int trimbits_to_load_l[1024];
|
||||
static unsigned int trimbits_to_load_r[1024];
|
||||
for(int row=0;row<16;row++){ //row loop
|
||||
int offset = 2*32*row;
|
||||
for(int sc=0;sc<32;sc++){ //supercolumn loop sc
|
||||
int super_column_start_position_l = 1030*row + l_r *258 + sc*8;
|
||||
int super_column_start_position_r = 1030*row + 516 + l_r *258 + sc*8;
|
||||
int chip_sc = 31 - sc;
|
||||
trimbits_to_load_l[offset+chip_sc] = 0;
|
||||
trimbits_to_load_r[offset+chip_sc] = 0;
|
||||
for(int i=0;i<8;i++){ // column loop i
|
||||
trimbits_to_load_l[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])<<((7-i)*4);//low
|
||||
trimbits_to_load_l[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_l+i)])>>3)<<((7-i)*4);//upper
|
||||
trimbits_to_load_r[offset+chip_sc] |= ( 0x7 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])<<((7-i)*4);//low
|
||||
trimbits_to_load_r[offset+chip_sc+32] |= ((0x38 & trimbits[263679 - (row_set*16480+super_column_start_position_r+i)])>>3)<<((7-i)*4);//upper
|
||||
} // end column loop i
|
||||
} //end supercolumn loop sc
|
||||
} //end row loop
|
||||
|
||||
return SetStaticBits(); //send the static bits
|
||||
if(!WriteMemory(modules[0]->GetTopLeftAddress(),0,0,1024,trimbits_to_load_r)||!WriteMemory(modules[0]->GetTopRightAddress(),0,0,1024,trimbits_to_load_l)||!StartDAQOnlyNWaitForFinish()) return 0;
|
||||
} //end row_set loop (groups of 16 rows)
|
||||
} // end l_r loop
|
||||
|
||||
memcpy(last_downloaded_trimbits,trimbits,trimbit_size*sizeof(unsigned char));
|
||||
|
||||
return SetStaticBits(); //send the static bits
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -259,7 +259,12 @@ int main(int argc, char* argv[]){
|
||||
break;
|
||||
|
||||
case evSetTrimBits :
|
||||
feb_controler->SetTrimbits(0,(unsigned char*)data);
|
||||
tmp_str[0] = GetNextString(data);
|
||||
/*char tt[263681];*/
|
||||
for(int i=0;i<10;i++)
|
||||
cout <<i<<":"<<tmp_str[0][i]<<"\t\t";
|
||||
printf("Cjhgkfdjg :%s\n",tmp_str[0].c_str());
|
||||
feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));
|
||||
return_message.append("\tExecuted: SetTrimBits "); AddNumber(return_message,n[0]); return_message.append("\n");
|
||||
ret_val = 0;
|
||||
break;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -141,6 +141,7 @@ int64_t getDetectorId(enum idMode arg){
|
||||
|
||||
|
||||
int getDetectorNumber(){
|
||||
|
||||
int res=0;
|
||||
char hostname[100];
|
||||
if (gethostname(hostname, sizeof hostname) == 0)
|
||||
@@ -159,8 +160,13 @@ int getDetectorNumber(){
|
||||
pclose(sysFile);
|
||||
sscanf(output,"%x",&res);
|
||||
return res;
|
||||
*/
|
||||
/*
|
||||
int res=0;
|
||||
char hostname[100] = "beb000";
|
||||
sscanf(hostname,"%x",&res);
|
||||
return res;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -291,8 +297,9 @@ int setModule(sls_detector_module myMod){
|
||||
// thisSettings = (enum detectorSettings)myMod.reg;
|
||||
// thisSettings = 0;
|
||||
|
||||
setSettings( (enum detectorSettings)myMod.reg); // put the settings in the module register?!?!?
|
||||
/** set trimbits*/
|
||||
setSettings( (enum detectorSettings)myMod.reg,-1); // put the settings in the module register?!?!?
|
||||
EigerSetTrimbits(myMod.chanregs);
|
||||
|
||||
if (detectorModules)
|
||||
copyModule(detectorModules,&myMod);
|
||||
return 0;
|
||||
@@ -598,6 +605,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();};//NCHIP*NCHAN*nModBoard;}
|
||||
int getTotalNumberOfChips(){return 4;};//NCHIP*nModBoard;}
|
||||
int getTotalNumberOfModules(){return 1;}//nModBoard;}
|
||||
@@ -675,6 +683,21 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg){
|
||||
return NO_SYNCHRONIZATION;
|
||||
}
|
||||
|
||||
void setAllTrimbits(int val){
|
||||
int ichan;
|
||||
EigerSetAllTrimbits(val);
|
||||
#ifdef VERBOSE
|
||||
printf("Copying register %x value %d\n",destMod->reg,val);
|
||||
#endif
|
||||
if (detectorModules){
|
||||
for (ichan=0; ichan<(detectorModules->nchan); ichan++) {
|
||||
*((detectorModules->chanregs)+ichan)=val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getAllTrimbits(){
|
||||
return *((detectorModules->chanregs));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user