mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 13:57:13 +02:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
5ededf9be4 | |||
a2986784d3 | |||
308d44e452 | |||
69da61b1fb | |||
460168ce04 | |||
dd0a1f60c6 | |||
e819ed26e1 | |||
09c853ae26 | |||
44a69e2aee | |||
121e9faf56 | |||
673e7c8f20 | |||
749c64204e | |||
03cdda99ae | |||
28f96f4b51 | |||
dce9911164 | |||
2fdc4389e2 | |||
5082435501 | |||
94667c5dde | |||
2a4bd8022e | |||
0979d04693 |
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -18,8 +19,12 @@ using namespace std;
|
||||
|
||||
|
||||
/** Error flags */
|
||||
/*Assumption: Only upto 63 detectors */
|
||||
#define CRITICAL_ERROR_MASK 0xFFFFFFFF
|
||||
|
||||
#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL
|
||||
|
||||
|
||||
#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL
|
||||
#define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL
|
||||
#define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL
|
||||
@ -61,6 +66,7 @@ using namespace std;
|
||||
#define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL
|
||||
#define RATE_CORRECTION_NOT_32BIT 0x0000000000800000ULL
|
||||
#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL
|
||||
#define RECEIVER_ACTIVATE 0x0000000002000000ULL
|
||||
|
||||
// 0x00000000FFFFFFFFULL
|
||||
/** @short class returning all error messages for error mask */
|
||||
@ -70,7 +76,9 @@ class errorDefs {
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
errorDefs():errorMask(0){};
|
||||
errorDefs():errorMask(0){
|
||||
strcpy(notAddedList,"");
|
||||
};
|
||||
|
||||
/** Gets the error message
|
||||
* param errorMask error mask
|
||||
@ -198,7 +206,8 @@ public:
|
||||
if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED)
|
||||
retval.append("Rate correction Deactivated. No default tau provided in file\n");
|
||||
|
||||
|
||||
if(slsErrorMask&RECEIVER_ACTIVATE)
|
||||
retval.append("Could not activate/deactivate receiver\n");
|
||||
|
||||
|
||||
|
||||
@ -224,12 +233,29 @@ public:
|
||||
*/
|
||||
int64_t clearErrorMask(){errorMask=0;return errorMask;};
|
||||
|
||||
/** Gets the not added detector list
|
||||
/returns list
|
||||
*/
|
||||
char* getNotAddedList(){return notAddedList;};
|
||||
|
||||
/** Append the detector to not added detector list
|
||||
* @param name append to the list
|
||||
/returns list
|
||||
*/
|
||||
void appendNotAddedList(const char* name){strcat(notAddedList,name);strcat(notAddedList,"+");};
|
||||
|
||||
/** Clears not added detector list
|
||||
/returns error mask
|
||||
*/
|
||||
void clearNotAddedList(){strcpy(notAddedList,"");};
|
||||
|
||||
protected:
|
||||
|
||||
/** Error Mask */
|
||||
int64_t errorMask;
|
||||
|
||||
/** Detectors Not added List */
|
||||
char notAddedList[MAX_STR_LENGTH];
|
||||
};
|
||||
|
||||
#endif /* ERROR_DEFS_H_ */
|
||||
|
@ -46,6 +46,8 @@
|
||||
short Beb_bit_mode;
|
||||
int BEB_MMAP_SIZE = 0x1000;
|
||||
|
||||
int Beb_activated = 1;
|
||||
|
||||
|
||||
|
||||
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){
|
||||
@ -172,6 +174,10 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){
|
||||
|
||||
/* do not work at the moment */
|
||||
int Beb_SetMasterViaSoftware(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 0;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -200,6 +206,10 @@ int Beb_SetMasterViaSoftware(){
|
||||
|
||||
/* do not work at the moment */
|
||||
int Beb_SetSlaveViaSoftware(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 0;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -268,11 +278,18 @@ int Beb_Activate(int enable){
|
||||
if(fd > 0)
|
||||
Beb_close(fd,csp0base);
|
||||
|
||||
Beb_activated = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){
|
||||
|
||||
if(!Beb_activated)
|
||||
return val;
|
||||
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t valueread = 0;
|
||||
@ -325,6 +342,10 @@ int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){
|
||||
|
||||
|
||||
int Beb_ResetToHardwareSettings(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -396,6 +417,10 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion(){
|
||||
}
|
||||
|
||||
void Beb_ResetFrameNumber(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return;
|
||||
|
||||
//mapping new memory to read master top module configuration
|
||||
u_int32_t* csp0base=0;
|
||||
//open file pointer
|
||||
@ -446,7 +471,6 @@ int Beb_InitBebInfos(){//file name at some point
|
||||
bebInfoSize++;
|
||||
|
||||
|
||||
//if(!Beb_ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0;
|
||||
/*
|
||||
//loop through file to fill vector.
|
||||
BebInfo* b = new BebInfo(26);
|
||||
@ -477,52 +501,6 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac
|
||||
}
|
||||
|
||||
|
||||
int Beb_ReadSetUpFromFile(char* file_name){
|
||||
char line[100];
|
||||
char str[100];
|
||||
|
||||
int i0,i1;
|
||||
char mac0[50],mac1[50],ip0[50],ip1[0];
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the beb setup file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Setting up beb side of detector:\n");
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if (str[0]=='#')
|
||||
continue;
|
||||
|
||||
if(!strcmp(str,"add_beb")){
|
||||
if( sscanf (line,"%s %d %d %s %s %s %s",str,&i0,&i1,mac0,ip0,mac1,ip1) < 7){
|
||||
printf("Error adding beb from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf ("Read: %s %d %d %s %s %s %s\n", str,i0,i1,mac0,ip0,mac1,ip1);
|
||||
|
||||
if(Beb_GetBebInfoIndex(i0)){
|
||||
printf("Error adding beb from %s, beb number %d already added.\n",file_name,i0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
struct BebInfo b0;
|
||||
BebInfo_BebInfo(&b0,i0);
|
||||
BebInfo_SetSerialAddress(&b0,i1);
|
||||
BebInfo_SetHeaderInfo(&b0,0,mac0,ip0,42000+i0);
|
||||
BebInfo_SetHeaderInfo(&b0,1,mac1,ip1,52000+i0);
|
||||
beb_infos[bebInfoSize] = b0;
|
||||
bebInfoSize++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Beb_CheckSourceStuffBebInfo(){
|
||||
@ -552,6 +530,10 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){
|
||||
|
||||
|
||||
int Beb_WriteTo(unsigned int index){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
if(index>=bebInfoSize){
|
||||
printf("WriteTo index error.\n");
|
||||
return 0;
|
||||
@ -575,35 +557,15 @@ void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d){
|
||||
|
||||
|
||||
int Beb_SetByteOrder(){
|
||||
/*
|
||||
Beb_send_data_raw[0] = 0x8fff0000;
|
||||
if(Local_Write(ll_beb,4,Beb_send_data_raw)!=4) return 0;
|
||||
|
||||
while((Local_Read(ll_beb,Beb_recv_buffer_size*4,Beb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n");
|
||||
|
||||
if(bebInfoSize<2) return 0;
|
||||
|
||||
Beb_send_ndata = 3;
|
||||
Beb_send_data[0] = 0x000c0000;
|
||||
Beb_send_data[1] = 0;
|
||||
Beb_send_data[2] = 0;
|
||||
Beb_WriteTo(0);
|
||||
|
||||
//using little endian for data, big endian not fully tested, swap on 16 bit boundary.
|
||||
Beb_send_ndata = 3;
|
||||
Beb_send_data[0] = 0x000c0000;
|
||||
Beb_send_data[1] = 1;
|
||||
Beb_send_data[2] = 0;
|
||||
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
|
||||
Beb_WriteTo(0);
|
||||
|
||||
printf("\tSetting Byte Order .............. ok\n");
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
u_int32_t bram_phy_addr;
|
||||
u_int32_t* csp0base=0;
|
||||
/*u_int32_t* bram_ptr = NULL;*/
|
||||
@ -809,7 +771,9 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i
|
||||
cprintf(GREEN, "Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]);
|
||||
#endif
|
||||
|
||||
if(!Beb_WriteTo(i)) return 0;
|
||||
if(Beb_activated){
|
||||
if(!Beb_WriteTo(i)) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -828,6 +792,9 @@ int Beb_SetUpTransferParameters(short the_bit_mode){
|
||||
|
||||
int Beb_StopAcquisition()
|
||||
{
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
u_int32_t* csp0base=0;
|
||||
volatile u_int32_t valuel,valuer;
|
||||
//open file pointer
|
||||
@ -854,6 +821,10 @@ int Beb_StopAcquisition()
|
||||
}
|
||||
|
||||
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
if(dst_number>64) return 0;
|
||||
|
||||
unsigned int header_size = 4; //4*64 bits
|
||||
|
@ -41,7 +41,6 @@ struct BebInfo{
|
||||
|
||||
void Beb_ClearBebInfos();
|
||||
int Beb_InitBebInfos();
|
||||
int Beb_ReadSetUpFromFile(char* file_name);
|
||||
int Beb_CheckSourceStuffBebInfo();
|
||||
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
|
||||
|
||||
|
@ -65,6 +65,8 @@ int Feb_control_master = 0;
|
||||
unsigned int Feb_Control_rate_correction_table[1024];
|
||||
double Feb_Control_rate_meas[16384];
|
||||
|
||||
int Feb_Control_activated = 1;
|
||||
|
||||
|
||||
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
|
||||
unsigned int i;
|
||||
@ -152,6 +154,10 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i)
|
||||
|
||||
|
||||
|
||||
void Feb_Control_activate(int activate){
|
||||
Feb_Control_activated = activate;
|
||||
}
|
||||
|
||||
int Feb_Control_IsBottomModule(){
|
||||
if(Module_BottomAddressIsValid(&modules[Feb_Control_current_index]))
|
||||
return 1;
|
||||
@ -186,40 +192,10 @@ int Feb_Control_Init(int master, int top, int module_num){
|
||||
Feb_Control_module_number = (module_num & 0xFF);
|
||||
|
||||
int serial = !top;
|
||||
|
||||
/*
|
||||
//for Gemmas modules: if master, serial 0, else 1
|
||||
int serial = 1;
|
||||
if(master)
|
||||
serial = 0;
|
||||
switch(Feb_Control_module_number){
|
||||
case 34: serial = 0; break; //martin half
|
||||
case 26: serial = 0; break; //leo
|
||||
|
||||
case 31: serial = 0; break; //martin
|
||||
case 32: serial = 1; break;
|
||||
case 24: serial = 2; break;
|
||||
case 25: serial = 3; break;
|
||||
|
||||
case 15: serial = 0; break; //dhanya
|
||||
case 16: serial = 1; break;
|
||||
case 30: serial = 2; break;
|
||||
case 38: serial = 3; break;
|
||||
|
||||
case 49: serial = 0; break; // Gemma
|
||||
case 48: serial = 1; break; // Gemma
|
||||
}*/
|
||||
printf("serial: %d\n",serial);
|
||||
|
||||
Feb_Control_current_index = 1;
|
||||
|
||||
/*for(i=1;i<moduleSize;i++){
|
||||
if(Module_GetModuleNumber(&modules[i])==Feb_Control_module_number)
|
||||
Feb_Control_current_index = i;
|
||||
}
|
||||
printf("****current index:%d\n",i);
|
||||
*/
|
||||
//Feb_Control_ReadSetUpFileToAddModules("/home/root/executables/setup.txt");
|
||||
|
||||
//Add the half module
|
||||
Feb_Control_AddModule1(Feb_Control_module_number,top,serial,serial,1);
|
||||
@ -242,7 +218,8 @@ printf("****current index:%d\n",i);
|
||||
Feb_Interface_SendCompleteList(nfebs,feb_list);
|
||||
free(feb_list);
|
||||
printf("\n");
|
||||
Feb_Interface_SetByteOrder();
|
||||
if(Feb_Control_activated)
|
||||
Feb_Interface_SetByteOrder();
|
||||
|
||||
|
||||
return 1;
|
||||
@ -250,106 +227,6 @@ printf("****current index:%d\n",i);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void Feb_Control_Set_Master(){
|
||||
Feb_Control_am_i_master = 1;
|
||||
unsigned int halfmastermodule = 0x80000000;
|
||||
unsigned int reg_nums[1];
|
||||
unsigned int reg_vals[1];
|
||||
reg_nums[0]=DAQ_REG_CHIP_CMDS;
|
||||
reg_vals[0]=(halfmastermodule|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
|
||||
|
||||
if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),1,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble writing commands....\n");;
|
||||
return 0;
|
||||
}
|
||||
printf("master is set\n");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int Feb_Control_ReadSetUpFileToAddModules(char* file_name){
|
||||
char line[100];
|
||||
char str[100];
|
||||
int i0,i1,i2;
|
||||
// int memaddress = 1;
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nSetting up detectors:\n");
|
||||
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if (str[0]=='#')
|
||||
continue;
|
||||
|
||||
|
||||
if(!strcmp(str,"add_module")){
|
||||
if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){
|
||||
cprintf(RED,"Error adding module from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2);
|
||||
if(!Feb_Control_AddModule1(i0,1,i1,i2,0)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
else if(!strcmp(str,"add_half_module")){
|
||||
if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){
|
||||
cprintf(RED,"Error adding half module from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2);
|
||||
|
||||
if(!Feb_Control_AddModule1(i0,i1,i2,i2,1)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//memaddress++;
|
||||
Feb_Control_PrintModuleList();
|
||||
|
||||
/* if(!Feb_Control_AddModule1(i0,i1)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
|
||||
Feb_Control_PrintModuleList();
|
||||
unsigned int nfebs = 0;
|
||||
unsigned int* feb_list = malloc(moduleSize*4 * sizeof(unsigned int));
|
||||
unsigned int i;
|
||||
for(i=1;i<moduleSize;i++){
|
||||
if(Module_TopAddressIsValid(&modules[i])){
|
||||
feb_list[nfebs++] = Module_GetTopRightAddress(&modules[i]);
|
||||
feb_list[nfebs++] = Module_GetTopLeftAddress(&modules[i]);
|
||||
}
|
||||
if(Module_BottomAddressIsValid(&modules[i])){
|
||||
feb_list[nfebs++] = Module_GetBottomRightAddress(&modules[i]);
|
||||
feb_list[nfebs++] = Module_GetBottomLeftAddress(&modules[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Feb_Interface_SendCompleteList(nfebs,feb_list);
|
||||
free(feb_list);
|
||||
|
||||
printf("\n");
|
||||
|
||||
return Feb_Interface_SetByteOrder();
|
||||
}
|
||||
|
||||
void Feb_Control_PrintModuleList(){
|
||||
unsigned int i;
|
||||
printf("\tModule list:\n");
|
||||
@ -447,92 +324,6 @@ int Feb_Control_AddModule1(unsigned int module_number, int top_enable, unsigned
|
||||
return parameters_ok;
|
||||
}
|
||||
|
||||
/* not called anywhere**/
|
||||
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
|
||||
printf("Reading Setup file for module number:%d\n",module_num);
|
||||
char line[100];
|
||||
char str[100];
|
||||
int i0;
|
||||
float f0;
|
||||
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if ((str[0]=='#') || (!strcmp(str,"add_module")) || (!strcmp(str,"add_half_module")))
|
||||
continue;
|
||||
|
||||
if(!strcmp("iodelay",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading io_delay\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetIDelays(module_num,i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("high_voltage",str)){
|
||||
if(sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading high_voltage\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetHighVoltage(f0);
|
||||
}
|
||||
/*
|
||||
else if(!strcmp("photon_energy",str)){
|
||||
if(sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading photon_energy\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetPhotonEnergy(f0);
|
||||
}*/
|
||||
|
||||
else if(!strcmp("dynamic_range",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading dynamic_range\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetDynamicRange(i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("readout_speed",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading readout_speed\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetReadoutSpeed(i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("readout_mode",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading readout_mode\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetReadoutMode(i0);
|
||||
}
|
||||
|
||||
else {
|
||||
if( sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading dac\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(module_num>0)
|
||||
sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/
|
||||
if(!Feb_Control_SetDAC(str,f0,1))
|
||||
cprintf(RED,"Error in string: %s",str);
|
||||
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
printf("Done reading set up file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_CheckSetup(int master){
|
||||
@ -675,12 +466,14 @@ int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int chan
|
||||
|
||||
printf(", tracks 0x%x to: %d, %d clks and %d units.\n",channels,(((15-delay_data_valid_nclks)<<6)|ndelay_units),delay_data_valid_nclks,ndelay_units);
|
||||
|
||||
if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){
|
||||
cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){
|
||||
cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -738,9 +531,11 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
|
||||
}
|
||||
|
||||
unsigned int r = 0x20000000 | (b&0xff);
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
|
||||
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
|
||||
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*value = Feb_Control_DACToVoltage(b,nsteps,vmin,vmax);
|
||||
@ -752,43 +547,15 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
|
||||
|
||||
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){
|
||||
char* local_s = dac_str;
|
||||
//char temp[50];
|
||||
*module_index = Feb_Control_current_index;
|
||||
|
||||
/*
|
||||
char* p1 = strstr(local_s,"mod");//size_t p1 = local_s.find("mod");
|
||||
char* p2 = strstr(local_s,"::");//size_t p2 =local_s.find("::");
|
||||
if(p1!=NULL&&p2!=NULL&&(p1+3)<p2){//if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){
|
||||
strncpy(temp, p1+3, (p2-p1));
|
||||
temp[p2-p1] = '\0';
|
||||
unsigned int number = atoi(temp); //unsigned int number = atoi((local_s.substr(p1+3,p2-3)).c_str());
|
||||
|
||||
if(!Feb_Control_GetModuleIndex(number,module_index)){
|
||||
cprintf(RED,"Error in dac_name \"%s\", module number %d not in list.\n",dac_str,number);
|
||||
return 0;
|
||||
}
|
||||
strcpy(local_s,p2+2);//local_s = local_s.substr(p2+2);
|
||||
}
|
||||
*/
|
||||
|
||||
*top = 1;//make them both 1 instead of this
|
||||
*bottom = 1;
|
||||
/*if(p1 = strstr(local_s,"top::")!=NULL){
|
||||
strcpy(local_s,p1+5);
|
||||
*bottom=0;
|
||||
}else if(p1 = strstr(local_s,"bottom::")!=NULL){
|
||||
strcpy(local_s,p1+8);
|
||||
*top=0;
|
||||
}*/
|
||||
|
||||
if(Module_BottomAddressIsValid(&modules[*module_index]))
|
||||
*top=0;
|
||||
else
|
||||
*bottom=0;
|
||||
|
||||
|
||||
|
||||
|
||||
*dac_ch = 0;
|
||||
if(!Feb_Control_GetDACNumber(local_s,dac_ch)){
|
||||
cprintf(RED,"Error in dac_name: %s (%s)\n",dac_str,local_s);
|
||||
@ -799,37 +566,6 @@ int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int*
|
||||
}
|
||||
|
||||
int Feb_Control_SetDAC(char* dac_str, int value, int is_a_voltage_mv){
|
||||
/*
|
||||
string local_s = dac_str;
|
||||
unsigned int module_index = 0;
|
||||
|
||||
size_t p1 = local_s.find("mod");
|
||||
size_t p2 = local_s.find("::");
|
||||
if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){
|
||||
unsigned int number = atoi((local_s.substr(p1+3,p2-3)).c_str());
|
||||
if(!GetModuleIndex(number,module_index)){
|
||||
cprintf(RED,"Error in dac_name \""<<dac_str<<"\", module number "<<number<<" not in list.\n");;
|
||||
return 0;
|
||||
}
|
||||
local_s = local_s.substr(p2+2);
|
||||
}
|
||||
|
||||
int top = 1;
|
||||
int bottom = 1;
|
||||
if((p1 = local_s.find("top::"))!=string::npos){
|
||||
local_s = local_s.substr(p1+5);
|
||||
bottom=0;
|
||||
}else if((p1 = local_s.find("bottom::"))!=string::npos){
|
||||
local_s = local_s.substr(p1+8);
|
||||
top=0;
|
||||
}
|
||||
|
||||
unsigned int dac_ch = 0;
|
||||
if(!GetDACNumber(local_s,dac_ch)){
|
||||
cprintf(RED,"Error in dac_name: "<<dac_str<<" ("<<local_s<<")\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
unsigned int i;
|
||||
unsigned int module_index, dac_ch;
|
||||
int top, bottom;
|
||||
@ -901,10 +637,6 @@ int Feb_Control_GetDACNumber(char* s, unsigned int* n){
|
||||
|
||||
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value){
|
||||
|
||||
//static unsigned int nsteps = 4096; //12 bit dac
|
||||
//static float vmin = 0;
|
||||
//static float vmax = 2;
|
||||
|
||||
if(ch<0||ch>15){
|
||||
cprintf(RED,"Warning invalid ch for SetDAC.\n");
|
||||
return 0;
|
||||
@ -918,9 +650,11 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int
|
||||
unsigned int r = dac_ic<<30 | 3<<16 | dac_ch<<12 | *value; //3 write and power up
|
||||
|
||||
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){
|
||||
cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch);
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){
|
||||
cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float voltage=Feb_Control_DACToVoltage(*value,4096,0,2048);
|
||||
@ -929,14 +663,7 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
float GetDAC(string s){
|
||||
static unsigned int n;
|
||||
if(!GetDACNumber(s,n)) return 0;
|
||||
|
||||
return dac[n];
|
||||
}
|
||||
*/
|
||||
|
||||
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
printf("Setting Trimbits\n");
|
||||
@ -959,12 +686,15 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
for(l_r=0;l_r<2;l_r++){ // l_r loop
|
||||
//printf("\nl_r:%d\t\t",l_r);
|
||||
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
|
||||
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
|
||||
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
printf("Could not select chips\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
|
||||
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
|
||||
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
printf("Could not select chips\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int row_set;
|
||||
for(row_set=0;row_set<16;row_set++){ //16 rows at a time
|
||||
//printf("row_set:%d\t\t",row_set);
|
||||
@ -1020,22 +750,26 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
} //end row loop
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[1])){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1077,14 +811,20 @@ return Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[
|
||||
}
|
||||
|
||||
int Feb_Control_SetCommandRegister(unsigned int cmd){
|
||||
return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0);
|
||||
if(Feb_Control_activated)
|
||||
return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status){
|
||||
if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){
|
||||
cprintf(RED,"Error: reading status register.\n");
|
||||
return 0;
|
||||
//if deactivated, should be handled earlier and should not get into this function
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){
|
||||
cprintf(RED,"Error: reading status register.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*ret_status = (0x02FF0000 & *ret_status) >> 16;
|
||||
@ -1093,11 +833,12 @@ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret
|
||||
|
||||
|
||||
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){
|
||||
cprintf(RED,"Warning: could not start.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){
|
||||
cprintf(RED,"Warning: could not start.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Feb_Control_WaitForFinishedFlag(sleep_time_us);
|
||||
}
|
||||
|
||||
@ -1105,6 +846,10 @@ int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){
|
||||
int Feb_Control_AcquisitionInProgress(){
|
||||
unsigned int status_reg_r=0,status_reg_l=0;
|
||||
|
||||
//deactivated should return end of acquisition
|
||||
if(!Feb_Control_activated)
|
||||
return 0;
|
||||
|
||||
int ind = Feb_Control_current_index;
|
||||
if(Module_BottomAddressIsValid(&modules[ind])){
|
||||
|
||||
@ -1132,6 +877,10 @@ int Feb_Control_AcquisitionInProgress(){
|
||||
int Feb_Control_AcquisitionStartedBit(){
|
||||
unsigned int status_reg_r=0,status_reg_l=0;
|
||||
|
||||
//deactivated should return acquisition started/ready
|
||||
if(!Feb_Control_activated)
|
||||
return 1;
|
||||
|
||||
int ind = Feb_Control_current_index;
|
||||
if(Module_BottomAddressIsValid(&modules[ind])){
|
||||
|
||||
@ -1172,6 +921,11 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
|
||||
|
||||
|
||||
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
||||
|
||||
//deactivated dont wait (otherwise give a toggle value back)
|
||||
if(!Feb_Control_activated)
|
||||
return 1;
|
||||
|
||||
int value = prev_flag;
|
||||
while(value == prev_flag){
|
||||
usleep(sleep_time_us);
|
||||
@ -1186,10 +940,13 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_Reset(){printf("Reset daq\n");
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
|
||||
cprintf(RED,"Warning: Could not reset daq, no response.\n");
|
||||
return 0;
|
||||
int Feb_Control_Reset(){
|
||||
printf("Reset daq\n");
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
|
||||
cprintf(RED,"Warning: Could not reset daq, no response.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Feb_Control_WaitForFinishedFlag(5000);
|
||||
@ -1199,10 +956,12 @@ int Feb_Control_Reset(){printf("Reset daq\n");
|
||||
|
||||
|
||||
int Feb_Control_SetStaticBits(){
|
||||
//program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: Could not set static bits\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
//program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: Could not set static bits\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1447,13 +1206,7 @@ void Feb_Control_PrintAcquisitionSetup(){
|
||||
}
|
||||
|
||||
int Feb_Control_SendBitModeToBebServer(){
|
||||
/*
|
||||
static int first_pass = 1;
|
||||
static char buffer[1024];
|
||||
|
||||
if(first_pass&&!Feb_Control_SetupSendToSocket("localhost",43212)) return 0;
|
||||
else first_pass=0;
|
||||
*/
|
||||
unsigned int just_bit_mode = (DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8) & Feb_Control_staticBits;
|
||||
unsigned int bit_mode = 16; //default
|
||||
if(just_bit_mode == DAQ_STATIC_BIT_M4) bit_mode = 4;
|
||||
@ -1466,60 +1219,9 @@ int Feb_Control_SendBitModeToBebServer(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
bzero(buffer,1024);
|
||||
sprintf(buffer,"setbitmode %d",bit_mode);
|
||||
|
||||
if(Feb_Control_WriteNRead(buffer,strlen(buffer),1024)<1||strncmp(buffer,"0",1)){
|
||||
cprintf(RED,"Error: sending bit mode ...\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port){
|
||||
|
||||
struct hostent *server;
|
||||
if((server = gethostbyname(ip_address_hostname)) == NULL){ //or look into getaddrinfo(3)
|
||||
fprintf(stderr,"ERROR, no such host\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//struct sockaddr_in serv_addr;
|
||||
bzero((char *) &Feb_Control_serv_addr, sizeof(Feb_Control_serv_addr));
|
||||
Feb_Control_serv_addr.sin_family = AF_INET;
|
||||
bcopy((char *)server->h_addr,(char *)&Feb_Control_serv_addr.sin_addr.s_addr,server->h_length);
|
||||
Feb_Control_serv_addr.sin_port = htons(port);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Feb_Control_WriteNRead(char* message, int length, int max_length){
|
||||
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sockfd <0){
|
||||
fprintf(stderr,"ERROR opening socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(connect(sockfd,(struct sockaddr *) &Feb_Control_serv_addr,sizeof(Feb_Control_serv_addr)) < 0){
|
||||
fprintf(stderr,"ERROR connecting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int n = write(sockfd,message,length);
|
||||
if(n<0) cprintf(RED,"Error writing to socket");
|
||||
|
||||
length = read(sockfd,message,max_length);
|
||||
if(length<0) cprintf(RED,"Error reading to socket");
|
||||
|
||||
close(sockfd);
|
||||
|
||||
return length;
|
||||
}
|
||||
*/
|
||||
|
||||
int Feb_Control_PrepareForAcquisition(){//return 1;
|
||||
static unsigned int reg_nums[20];
|
||||
@ -1567,30 +1269,13 @@ int Feb_Control_PrepareForAcquisition(){//return 1;
|
||||
reg_nums[5]=DAQ_REG_SUBFRAME_EXPOSURES;
|
||||
reg_vals[5]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns)
|
||||
// if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
reg_nums[0]=DAQ_REG_NEXPOSURES;
|
||||
reg_vals[0]=Feb_Control_nimages;
|
||||
reg_nums[1]=DAQ_REG_EXPOSURE_TIMER;
|
||||
reg_vals[1]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec);
|
||||
reg_nums[2]=DAQ_REG_EXPOSURE_REPEAT_TIMER;
|
||||
reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec);
|
||||
reg_nums[3]=DAQ_REG_CHIP_CMDS;
|
||||
reg_vals[3]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
|
||||
reg_nums[4]=DAQ_REG_SUBFRAME_EXPOSURES;
|
||||
reg_vals[4]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns)
|
||||
// if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),5,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1611,22 +1296,13 @@ int Feb_Control_StartAcquisition(){
|
||||
reg_nums[14]=DAQ_REG_CTRL;
|
||||
reg_vals[14]=ACQ_CTRL_START;
|
||||
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){
|
||||
cprintf(RED,"Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){
|
||||
cprintf(RED,"Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
reg_nums[0]=DAQ_REG_CTRL;
|
||||
reg_vals[0]=0;
|
||||
reg_nums[1]=DAQ_REG_CTRL;
|
||||
reg_vals[1]=ACQ_CTRL_START;
|
||||
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),2,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1705,11 +1381,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){
|
||||
c |= (inc_x_pos) ? DAQ_CLK_MAIN_CLK_TO_SELECT_NEXT_PIXEL : 0;
|
||||
c |= (inc_y_pos) ? DAQ_CLK_ROW_CLK_TO_SELECT_NEXT_ROW : 0;
|
||||
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) ||
|
||||
!Feb_Control_SetCommandRegister(c) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not PulsePixelNMove(...).\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) ||
|
||||
!Feb_Control_SetCommandRegister(c) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not PulsePixelNMove(...).\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1717,11 +1395,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){
|
||||
|
||||
/**new*/
|
||||
int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not shift in 32.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not shift in 32.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -1741,11 +1421,13 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){
|
||||
ntimes=1023;
|
||||
}
|
||||
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not clock row clock.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not clock row clock.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1919,18 +1601,22 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
||||
printf("daq reset completely\n");
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[1])){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -1974,7 +1660,7 @@ int Feb_Control_GetLeftFPGATemp(){
|
||||
Feb_Interface_ReadRegister(Module_GetTopLeftAddress (&modules[1]),FEB_REG_STATUS, &temperature);
|
||||
temperature = temperature >> 16;
|
||||
//division done in client to send int over network
|
||||
return temperature;
|
||||
return (int)temperature;
|
||||
}
|
||||
|
||||
int Feb_Control_GetRightFPGATemp(){
|
||||
|
@ -64,6 +64,7 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
|
||||
|
||||
|
||||
|
||||
void Feb_Control_activate(int activate);
|
||||
|
||||
int Feb_Control_IsBottomModule();
|
||||
int Feb_Control_GetModuleNumber();
|
||||
@ -112,8 +113,6 @@ int Feb_Control_GetModuleNumber();
|
||||
|
||||
void Feb_Control_FebControl();
|
||||
int Feb_Control_Init(int master, int top, int module_num);
|
||||
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
|
||||
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
|
||||
int Feb_Control_CheckSetup();
|
||||
|
||||
unsigned int Feb_Control_GetNModules();
|
||||
@ -195,4 +194,4 @@ int Feb_Control_GetModuleNumber();
|
||||
int Feb_Control_GetLeftFPGATemp();
|
||||
int Feb_Control_GetRightFPGATemp();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -95,6 +95,7 @@
|
||||
#define DAQ_STATUS_DAQ_RUNNING 0x01
|
||||
#define DAQ_DATA_COLLISION_ERROR 0x02
|
||||
|
||||
|
||||
#define DAQ_STATUS_CURRENT_M4 0x04
|
||||
#define DAQ_STATUS_CURRENT_M8 0x08
|
||||
#define DAQ_STATUS_CURRENT_M12 0x00 //in 12 bit mode both are cleared
|
||||
@ -151,3 +152,4 @@
|
||||
|
||||
//temp so far
|
||||
#define FEB_REG_STATUS 0xa
|
||||
|
||||
|
Binary file not shown.
@ -1318,7 +1318,9 @@ int getBebFPGATemp(){
|
||||
|
||||
|
||||
int activate(int enable){
|
||||
return Beb_Activate(enable);
|
||||
int ret = Beb_Activate(enable);
|
||||
Feb_Control_activate(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -694,6 +694,8 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
|
||||
t=slsDetector::getDetectorType(name, DEFAULT_PORTNO);
|
||||
if (t==GENERIC) {
|
||||
cout << "Detector " << name << "does not exist in shared memory and could not connect to it to determine the type (which is not specified)!" << endl;
|
||||
setErrorMask(getErrorMask()|MULTI_DETECTORS_NOT_ADDED);
|
||||
appendNotAddedList(name);
|
||||
return -1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
@ -4343,8 +4345,12 @@ int multiSlsDetector::readConfigurationFile(string const fname){
|
||||
setNumberOfModules(-1);
|
||||
getMaxNumberOfModules();
|
||||
|
||||
if (getErrorMask())
|
||||
if (getErrorMask()){
|
||||
int c;
|
||||
cprintf(RED,"\n----------------\n Error Messages\n----------------\n%s\n",
|
||||
getErrorMessage(c).c_str());
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@ -4896,19 +4902,30 @@ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){
|
||||
|
||||
|
||||
int multiSlsDetector::getFramesCaughtByReceiver() {
|
||||
int ret=0,ret1=0;
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
|
||||
if (detectors[i]){
|
||||
ret1+=detectors[i]->getFramesCaughtByReceiver();
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
|
||||
}
|
||||
if(!thisMultiDetector->numberOfDetectors)
|
||||
return ret;
|
||||
ret=(int)(ret1/thisMultiDetector->numberOfDetectors);
|
||||
int ret=0,ret1=0;
|
||||
|
||||
return ret;
|
||||
|
||||
if(thisMultiDetector->numberOfDetectors>10) {
|
||||
if (detectors[0]){
|
||||
ret =detectors[0]->getFramesCaughtByReceiver();
|
||||
if(detectors[0]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<0));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
|
||||
if (detectors[i]){
|
||||
ret1+=detectors[i]->getFramesCaughtByReceiver();
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
|
||||
}
|
||||
if(!thisMultiDetector->numberOfDetectors)
|
||||
return ret;
|
||||
ret=(int)(ret1/thisMultiDetector->numberOfDetectors);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -5183,6 +5200,9 @@ string multiSlsDetector::getErrorMessage(int &critical){
|
||||
|
||||
multiMask = getErrorMask();
|
||||
if(multiMask){
|
||||
if(multiMask & MULTI_DETECTORS_NOT_ADDED)
|
||||
retval.append("Detectors not added:\n"+string(getNotAddedList())+string("\n"));
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
//if the detector has error
|
||||
@ -5213,6 +5233,7 @@ string multiSlsDetector::getErrorMessage(int &critical){
|
||||
|
||||
int64_t multiSlsDetector::clearAllErrorMask(){
|
||||
clearErrorMask();
|
||||
clearNotAddedList();
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
|
||||
if (detectors[idet])
|
||||
detectors[idet]->clearErrorMask();
|
||||
|
@ -1270,6 +1270,13 @@ int slsDetector::activate(int const enable){
|
||||
int arg = enable;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
int ret = OK;
|
||||
|
||||
if(thisDetector->myDetectorType != EIGER){
|
||||
std::cout<< "Not implemented for this detector" << std::endl;
|
||||
setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if(!enable)
|
||||
std::cout<< "Deactivating Detector" << std::endl;
|
||||
@ -1296,11 +1303,36 @@ int slsDetector::activate(int const enable){
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
if(retval)
|
||||
if(retval==1)
|
||||
std::cout << "Detector Activated" << std::endl;
|
||||
else
|
||||
else if(retval==0)
|
||||
std::cout << "Detector Deactivated" << std::endl;
|
||||
else
|
||||
std::cout << "Detector Activation unknown:" << retval << std::endl;
|
||||
#endif
|
||||
|
||||
if(ret!=FAIL){
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Activating/Deactivating Receiver: " << retval << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendInt(fnum,retval,retval);
|
||||
disconnectData();
|
||||
if(ret==FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE));
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
if(retval==1)
|
||||
std::cout << "Receiver Activated" << std::endl;
|
||||
else if(retval==0)
|
||||
std::cout << "Receiver Deactivated" << std::endl;
|
||||
else
|
||||
std::cout << "Receiver Activation unknown:" << retval << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
@ -5535,6 +5567,7 @@ char* slsDetector::setReceiver(string receiverIP){
|
||||
setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]);
|
||||
setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]);
|
||||
setDynamicRange(thisDetector->dynamicRange);
|
||||
activate(-1);
|
||||
//set scan tag
|
||||
setUDPConnection();
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
|
@ -171,7 +171,9 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
//resets frames caught in receiver
|
||||
if(receiver){
|
||||
pthread_mutex_lock(&mg);
|
||||
resetFramesCaught();
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
for(int im=0;im<nm;im++) {
|
||||
@ -340,9 +342,9 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
|
||||
//offline
|
||||
pthread_mutex_lock(&mg);
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
// wait until data processing thread has finished the data
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
if (*threadedProcessing) {
|
||||
@ -372,7 +374,6 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
//online
|
||||
else{
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
|
@ -512,12 +512,10 @@ void* postProcessing::processData(int delflag) {
|
||||
usleep(20000); //20ms need this else connecting error to receiver (too fast)
|
||||
|
||||
//get progress
|
||||
if(setReceiverOnline() == ONLINE_FLAG){
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg);
|
||||
if(setReceiverOnline() == ONLINE_FLAG)
|
||||
caught = getFramesCaughtByReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mg);
|
||||
//updating progress
|
||||
if(caught!= -1){
|
||||
setCurrentProgress(caught);
|
||||
@ -609,13 +607,12 @@ void* postProcessing::processData(int delflag) {
|
||||
}
|
||||
//gui
|
||||
else{
|
||||
pthread_mutex_lock(&mg);
|
||||
if(setReceiverOnline()==ONLINE_FLAG){
|
||||
//get data
|
||||
strcpy(currentfName,"");
|
||||
pthread_mutex_lock(&mg);
|
||||
//int* receiverData = new int [getTotalNumberOfChannels()];
|
||||
int* receiverData = readFrameFromReceiver(currentfName,currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex);
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
//if detector returned null
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
@ -659,6 +656,7 @@ void* postProcessing::processData(int delflag) {
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,6 +193,14 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
runStatus getStatus() const;
|
||||
|
||||
/**
|
||||
* Get activate
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
* @return 0 for deactivated, 1 for activated
|
||||
*/
|
||||
int getActivate() const;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -417,6 +425,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
void closeFile(int i = -1);
|
||||
|
||||
/**
|
||||
* Activate / Deactivate Receiver
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
*/
|
||||
int setActivate(int enable = -1);
|
||||
|
||||
|
||||
//***callback functions***
|
||||
/**
|
||||
@ -485,6 +500,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
const static int MAX_NUMBER_OF_LISTENING_THREADS = 2;
|
||||
/** Receiver Status */
|
||||
runStatus status;
|
||||
/** Activated/Deactivated */
|
||||
int activated;
|
||||
|
||||
//***connection parameters***
|
||||
/** Ethernet Interface */
|
||||
@ -528,6 +545,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
|
||||
|
||||
|
||||
|
||||
//***callback parameters***
|
||||
/**
|
||||
* function being called back for start acquisition
|
||||
|
@ -252,6 +252,14 @@ class UDPInterface {
|
||||
*/
|
||||
virtual slsReceiverDefs::runStatus getStatus() const = 0;
|
||||
|
||||
/**
|
||||
* Get activate
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
* @return 0 for deactivated, 1 for activated
|
||||
*/
|
||||
virtual int getActivate() const = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -474,6 +482,13 @@ class UDPInterface {
|
||||
*/
|
||||
virtual void closeFile(int i = -1) = 0;
|
||||
|
||||
/**
|
||||
* Activate / Deactivate Receiver
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
*/
|
||||
virtual int setActivate(int enable = -1) = 0;
|
||||
|
||||
|
||||
//***callback functions***
|
||||
/**
|
||||
|
@ -597,6 +597,7 @@ private:
|
||||
|
||||
/** Missing Packet identifier value */
|
||||
const static uint16_t missingPacketValue = 0xFFFF;
|
||||
const static uint16_t deactivatedPacketValue = 0xFEFE;
|
||||
|
||||
/** Dummy Packet identifier value */
|
||||
const static uint32_t dummyPacketValue = 0xFFFFFFFF;
|
||||
@ -675,6 +676,9 @@ private:
|
||||
bool killAllWritingThreads;
|
||||
|
||||
|
||||
//***deactivated parameters***
|
||||
uint64_t deactivated_framenumber[MAX_NUMBER_OF_LISTENING_THREADS];
|
||||
uint32_t deactivated_packetnumber[MAX_NUMBER_OF_LISTENING_THREADS];
|
||||
|
||||
|
||||
|
||||
|
@ -207,6 +207,10 @@ private:
|
||||
/** set fifo depth */
|
||||
int set_fifo_depth();
|
||||
|
||||
/** activate/ deactivate */
|
||||
int set_activate();
|
||||
|
||||
|
||||
//General Functions
|
||||
/** Locks Receiver */
|
||||
int lock_receiver();
|
||||
|
@ -49,6 +49,7 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
|
||||
//***receiver parameters***
|
||||
status = IDLE;
|
||||
activated = true;
|
||||
|
||||
//***connection parameters***
|
||||
strcpy(eth,"");
|
||||
@ -187,7 +188,7 @@ uint32_t UDPBaseImplementation::getFifoDepth() const{ FILE_LOG(logDEBUG) << __AT
|
||||
/***receiver status***/
|
||||
slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;}
|
||||
|
||||
|
||||
int UDPBaseImplementation::getActivate() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return activated;}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@ -448,6 +449,17 @@ void UDPBaseImplementation::closeFile(int i){
|
||||
}
|
||||
|
||||
|
||||
int UDPBaseImplementation::setActivate(int enable){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
if(enable != -1){
|
||||
activated = enable;
|
||||
FILE_LOG(logINFO) << "Activation: " << stringEnable(activated);
|
||||
}
|
||||
|
||||
return activated;
|
||||
}
|
||||
|
||||
/***callback functions***/
|
||||
void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){
|
||||
startAcquisitionCallBack=func;
|
||||
|
@ -191,6 +191,12 @@ void UDPStandardImplementation::initializeMembers(){
|
||||
createFileMask = 0x0;
|
||||
killAllWritingThreads = false;
|
||||
|
||||
//***deactivated parameters***
|
||||
for(int i=0; i < MAX_NUMBER_OF_LISTENING_THREADS; i++){
|
||||
deactivated_framenumber[i] = 0;
|
||||
deactivated_packetnumber[i] = 0;
|
||||
}
|
||||
|
||||
//***filter parameters***
|
||||
commonModeSubtractionEnable = false;
|
||||
moenchCommonModeSubtraction = NULL;
|
||||
@ -837,6 +843,11 @@ int UDPStandardImplementation::startReceiver(char *c){
|
||||
fileCreateSuccess = false;
|
||||
pthread_mutex_unlock(&statusMutex);
|
||||
|
||||
//deactivated parameters
|
||||
for(int i = 0; i < numberofListeningThreads; ++i){
|
||||
deactivated_framenumber[i] = 0;
|
||||
deactivated_packetnumber[i] = 0;
|
||||
}
|
||||
|
||||
//Print Receiver Configuration
|
||||
if(myDetectorType != EIGER){
|
||||
@ -959,32 +970,34 @@ void UDPStandardImplementation::startReadout(){
|
||||
|
||||
if(status == RUNNING){
|
||||
|
||||
//check if all packets got
|
||||
int totalP = 0,prev,i;
|
||||
for(i=0; i<numberofListeningThreads; ++i){
|
||||
totalP += totalListeningFrameCount[i];
|
||||
}
|
||||
//wait for all packets
|
||||
if(totalP!=numberOfFrames*packetsPerFrame){
|
||||
//needs to wait for packets only if activated
|
||||
if(activated){
|
||||
//check if all packets got
|
||||
int totalP = 0,prev,i;
|
||||
for(i=0; i<numberofListeningThreads; ++i){
|
||||
totalP += totalListeningFrameCount[i];
|
||||
}
|
||||
//wait for all packets
|
||||
if(totalP!=numberOfFrames*packetsPerFrame){
|
||||
|
||||
prev = -1;
|
||||
//wait as long as there is change from prev totalP
|
||||
while(prev != totalP){
|
||||
prev = -1;
|
||||
//wait as long as there is change from prev totalP
|
||||
while(prev != totalP){
|
||||
#ifdef DEBUG5
|
||||
cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP);
|
||||
cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP);
|
||||
#endif
|
||||
|
||||
usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/
|
||||
prev = totalP;
|
||||
totalP=0;
|
||||
for(i=0; i<numberofListeningThreads; ++i){
|
||||
totalP += totalListeningFrameCount[i];
|
||||
usleep(50000);/* Need to find optimal time (exposure time and acquisition period) **/
|
||||
prev = totalP;
|
||||
totalP=0;
|
||||
for(i=0; i<numberofListeningThreads; ++i){
|
||||
totalP += totalListeningFrameCount[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//set status
|
||||
pthread_mutex_lock(&statusMutex);
|
||||
status = TRANSMITTING;
|
||||
@ -1359,7 +1372,6 @@ int UDPStandardImplementation::setupWriter(){
|
||||
int UDPStandardImplementation::createNewFile(){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " called";
|
||||
|
||||
|
||||
int index = 0;
|
||||
if(packetsCaught){
|
||||
index = frameIndex;
|
||||
@ -1405,16 +1417,15 @@ int UDPStandardImplementation::createNewFile(){
|
||||
previousFrameNumber = -1;
|
||||
cout << "File:" << completeFileName << endl;
|
||||
}else{
|
||||
|
||||
cout //<< "Packet Loss:" <<
|
||||
//setw(4)<<fixed << setprecision(4) <<
|
||||
//dec << (int)((( (currentFrameNumber-1-previousFrameNumber) - ((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))/
|
||||
// (double)(currentFrameNumber-1-previousFrameNumber))*100.000)
|
||||
//<< "%\t"
|
||||
// setw(4)<<fixed << setprecision(4) <<
|
||||
// dec << (int)((( (currentFrameNumber-1-previousFrameNumber) - ((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))/
|
||||
// (double)(currentFrameNumber-1-previousFrameNumber))*100.000)
|
||||
// << "%\t"
|
||||
<< "Packets Lost:" << dec << ( ((int)(currentFrameNumber-1-previousFrameNumber)) -
|
||||
((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))
|
||||
((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))
|
||||
<< "\tCurrentFrameNumber:" << currentFrameNumber
|
||||
<< "\tPreviousFrameNumber:" << previousFrameNumber
|
||||
<< "\tPreviousFrameNumber:" << previousFrameNumber
|
||||
//<< "\tIndex:" << dec << index
|
||||
<< endl;
|
||||
}
|
||||
@ -1554,7 +1565,7 @@ void UDPStandardImplementation::startListening(){
|
||||
|
||||
|
||||
//problem in receiving or end of acquisition
|
||||
if (status == TRANSMITTING){
|
||||
if ((status == TRANSMITTING)||(rc == 0 && activated == 0)){
|
||||
stopListening(ithread,rc);
|
||||
continue;
|
||||
}
|
||||
@ -1609,6 +1620,39 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in
|
||||
if(cSize)
|
||||
memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize);
|
||||
|
||||
if(!activated){
|
||||
//first time
|
||||
if(!deactivated_framenumber[ithread])
|
||||
deactivated_framenumber[ithread]++;
|
||||
|
||||
//new frame
|
||||
if(deactivated_packetnumber[ithread] == (packetsPerFrame/numberofListeningThreads)){
|
||||
deactivated_packetnumber[ithread] = 0;
|
||||
deactivated_framenumber[ithread]++;
|
||||
//last time
|
||||
if(deactivated_framenumber[ithread] == (numberOfFrames+1))
|
||||
return 0;
|
||||
}
|
||||
deactivated_packetnumber[ithread]++;
|
||||
|
||||
//copy dummy packet
|
||||
memset(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, 0xFF,onePacketSize);
|
||||
eiger_packet_header_t* header = (eiger_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize);
|
||||
eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize + footerOffset);
|
||||
*( (uint16_t*) header->missingPacket) = deactivatedPacketValue;
|
||||
*( (uint64_t*) footer) = deactivated_framenumber[ithread];
|
||||
*( (uint16_t*) footer->packetNumber) = deactivated_packetnumber[ithread];
|
||||
//*( (uint16_t*) footer->packetNumber) = ithread*(packetsPerFrame/numberofListeningThreads)+deactivated_packetnumber[ithread];
|
||||
#ifdef MANUALDEBUG
|
||||
eiger_packet_footer_t* efooter = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS);
|
||||
cprintf(GREEN,"thread:%d pnum:%d fnum:%d\n",
|
||||
ithread,
|
||||
(*( (uint16_t*) efooter->packetNumber)),
|
||||
(uint32_t)(*( (uint64_t*) efooter)));
|
||||
#endif
|
||||
return onePacketSize;
|
||||
}
|
||||
|
||||
int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize);
|
||||
|
||||
//throw away packets that is not one packet size, need to check status if socket is shut down
|
||||
@ -1624,6 +1668,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in
|
||||
}
|
||||
totalListeningFrameCount[ithread] += (receivedSize/onePacketSize);
|
||||
|
||||
|
||||
#ifdef MANUALDEBUG
|
||||
if(receivedSize>0){
|
||||
if(myDetectorType == JUNGFRAU){
|
||||
@ -2531,17 +2576,16 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
|
||||
if(packetsCaught){
|
||||
cout << endl << "File:" << completeFileName <<endl;
|
||||
cout //<< "Packet Loss:" <<
|
||||
//setw(4)<<fixed << setprecision(4) <<
|
||||
//dec << (int)((( (currentFrameNumber-previousFrameNumber) - ((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))/
|
||||
// (double)(currentFrameNumber-previousFrameNumber))*100.000)
|
||||
// <<"%\t"
|
||||
<< "Packets Lost:" << dec << ( ((int)(currentFrameNumber-previousFrameNumber)) -
|
||||
((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))
|
||||
<< "\tCurrentFrameNumber:" << currentFrameNumber
|
||||
<< "\tPreviousFrameNumber:" << previousFrameNumber
|
||||
//<< "\tIndex:" << dec << frameIndex
|
||||
|
||||
<< endl;
|
||||
// setw(4)<<fixed << setprecision(4) <<
|
||||
// dec << (int)((( (currentFrameNumber-1-previousFrameNumber) - ((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))/
|
||||
// (double)(currentFrameNumber-1-previousFrameNumber))*100.000)
|
||||
// << "%\t"
|
||||
<< "Packets Lost:" << dec << ( ((int)(currentFrameNumber-previousFrameNumber)) -
|
||||
((packetsInFile-numTotMissingPacketsInFile)/packetsPerFrame))
|
||||
<< "\tCurrentFrameNumber:" << currentFrameNumber
|
||||
<< "\tPreviousFrameNumber:" << previousFrameNumber
|
||||
//<< "\tIndex:" << dec << index
|
||||
<< endl;
|
||||
}
|
||||
closeFile(ithread);
|
||||
pthread_mutex_lock(&statusMutex);
|
||||
@ -2584,6 +2628,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
|
||||
cprintf(GREEN, "Total Packets Caught:%lld\n", (long long int)totalPacketsCaught);
|
||||
cprintf(GREEN, "Total Frames Caught:%lld\n",(long long int)(totalPacketsCaught/packetsPerFrame));
|
||||
}
|
||||
if(!activated)
|
||||
cprintf(RED,"Note: Deactivated Receiver\n");
|
||||
//acquisition end
|
||||
if (acquisitionFinishedCallBack)
|
||||
acquisitionFinishedCallBack((int)(totalPacketsCaught/packetsPerFrame), pAcquisitionFinished);
|
||||
|
@ -262,6 +262,7 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
|
||||
flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga;
|
||||
flist[F_SET_RECEIVER_FIFO_DEPTH] = &slsReceiverTCPIPInterface::set_fifo_depth;
|
||||
flist[F_ACTIVATE] = &slsReceiverTCPIPInterface::set_activate;
|
||||
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
@ -2720,8 +2721,75 @@ int slsReceiverTCPIPInterface::set_fifo_depth() {
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_activate() {
|
||||
ret=OK;
|
||||
int retval=-1;
|
||||
int enable;
|
||||
strcpy(mess,"Could not activate/deactivate\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && socket->differentClients==1){
|
||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
if(ret!=FAIL){
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else if(receiverBase->getStatus()==RUNNING){
|
||||
strcpy(mess,"Cannot activate/deactivate while status is running\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else{
|
||||
if(enable != -1)
|
||||
receiverBase->setActivate(enable);
|
||||
retval = receiverBase->getActivate();
|
||||
if(enable >= 0 && retval != enable){
|
||||
sprintf(mess,"Tried to set activate to %d, but returned %d\n",enable,retval);
|
||||
ret = FAIL;
|
||||
cprintf(RED,"%s",mess);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "Activate: " << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && socket->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
socket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
socket->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
socket->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user