merged to developer

This commit is contained in:
bergamaschi 2016-12-19 12:26:53 +01:00
commit 68b13a0ecd
29 changed files with 1113 additions and 868 deletions

View File

@ -8,16 +8,14 @@
#ifndef ERROR_DEFS_H_ #ifndef ERROR_DEFS_H_
#define ERROR_DEFS_H_ #define ERROR_DEFS_H_
#include "ansi.h"
#include "sls_detector_defs.h"
#include <stdio.h>
#include <string> #include <string>
#include <cstring> #include <cstring>
using namespace std;
#include "sls_detector_defs.h"
#include <cstring>
#include <iostream> #include <iostream>
using namespace std;
/** Error flags */ /** Error flags */
/*Assumption: Only upto 63 detectors */ /*Assumption: Only upto 63 detectors */
@ -26,52 +24,57 @@ using namespace std;
#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL
#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL #define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL
#define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL #define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL
#define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL #define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL
#define COULDNOT_SET_STOP_PORT 0x1000000000000000ULL #define COULDNOT_SET_STOP_PORT 0x0800000000000000ULL
#define COULDNOT_SET_DATA_PORT 0x0800000000000000ULL #define COULDNOT_SET_DATA_PORT 0x0400000000000000ULL
#define FILE_PATH_DOES_NOT_EXIST 0x0400000000000000ULL #define FILE_PATH_DOES_NOT_EXIST 0x0200000000000000ULL
#define COULDNOT_CREATE_UDP_SOCKET 0x0200000000000000ULL #define COULDNOT_CREATE_UDP_SOCKET 0x0100000000000000ULL
#define COULDNOT_CREATE_FILE 0x0100000000000000ULL #define COULDNOT_CREATE_FILE 0x0080000000000000ULL
#define COULDNOT_ENABLE_COMPRESSION 0x0080000000000000ULL #define COULDNOT_ENABLE_COMPRESSION 0x0040000000000000ULL
#define RECEIVER_DET_HOSTNAME_NOT_SET 0x0040000000000000ULL #define RECEIVER_DET_HOSTNAME_NOT_SET 0x0020000000000000ULL
#define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0020000000000000ULL #define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0010000000000000ULL
#define DETECTOR_TEN_GIGA 0x0010000000000000ULL #define DETECTOR_TEN_GIGA 0x0008000000000000ULL
#define DETECTOR_ACTIVATE 0x0008000000000000ULL #define DETECTOR_ACTIVATE 0x0004000000000000ULL
#define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL
#define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads
#define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL
// 0xFFFFFFFF00000000ULL // 0xFFFFFFFF00000000ULL
#define COULD_NOT_CONFIGURE_MAC 0x0000000000000001ULL
#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000002ULL #define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL
#define COULDNOT_SET_ROI 0x0000000000000004ULL #define COULDNOT_SET_ROI 0x0000000000000002ULL
#define RECEIVER_READ_FREQUENCY 0x0000000000000008ULL #define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL
#define SETTINGS_NOT_SET 0x0000000000000010ULL #define SETTINGS_NOT_SET 0x0000000000000008ULL
#define SETTINGS_FILE_NOT_OPEN 0x0000000000000020ULL #define SETTINGS_FILE_NOT_OPEN 0x0000000000000010ULL
#define COULDNOT_START_RECEIVER 0x0000000000000040ULL // default error like starting threads #define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000020ULL
#define COULDNOT_STOP_RECEIVER 0x0000000000000080ULL #define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000040ULL
#define DETECTOR_TIMER_VALUE_NOT_SET 0x0000000000000100ULL #define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000080ULL
#define RECEIVER_ACQ_PERIOD_NOT_SET 0x0000000000000200ULL #define RECEIVER_DYNAMIC_RANGE 0x0000000000000100ULL
#define RECEIVER_FRAME_NUM_NOT_SET 0x0000000000000400ULL #define RECEIVER_TEN_GIGA 0x0000000000000200ULL
#define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL #define ALLTIMBITS_NOT_SET 0x0000000000000400ULL
#define RECEIVER_TEN_GIGA 0x0000000000001000ULL #define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000000800ULL
#define ALLTIMBITS_NOT_SET 0x0000000000002000ULL #define COULD_NOT_SET_READOUT_FLAGS 0x0000000000001000ULL
#define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000004000ULL #define COULD_NOT_SET_FIFO_DEPTH 0x0000000000002000ULL
#define COULD_NOT_SET_READOUT_FLAGS 0x0000000000008000ULL #define COULD_NOT_SET_COUNTER_BIT 0x0000000000004000ULL
#define COULD_NOT_SET_FIFO_DEPTH 0x0000000000010000ULL #define COULD_NOT_PULSE_PIXEL 0x0000000000008000ULL
#define COULD_NOT_SET_COUNTER_BIT 0x0000000000020000ULL #define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000010000ULL
#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL #define COULD_NOT_PULSE_CHIP 0x0000000000020000ULL
#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL #define COULD_NOT_SET_RATE_CORRECTION 0x0000000000040000ULL
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL #define DETECTOR_NETWORK_PARAMETER 0x0000000000080000ULL
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL #define RATE_CORRECTION_NOT_32or16BIT 0x0000000000100000ULL
#define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL #define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000000200000ULL
#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000800000ULL #define PROGRAMMING_ERROR 0x0000000000400000ULL
#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL #define RECEIVER_ACTIVATE 0x0000000000800000ULL
#define PROGRAMMING_ERROR 0x0000000002000000ULL #define DATA_STREAMING 0x0000000001000000ULL
#define RECEIVER_ACTIVATE 0x0000000004000000ULL #define RESET_ERROR 0x0000000002000000ULL
#define DATA_STREAMING 0x0000000008000000ULL #define POWER_CHIP 0x0000000004000000ULL
#define RESET_ERROR 0x0000000010000000ULL #define RECEIVER_READ_TIMER 0x0000000008000000ULL
#define POWER_CHIP 0x0000000020000000ULL #define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL
#define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL
// 0x00000000FFFFFFFFULL // 0x00000000FFFFFFFFULL
/** @short class returning all error messages for error mask */ /** @short class returning all error messages for error mask */
class errorDefs { class errorDefs {
@ -225,6 +228,12 @@ public:
if(slsErrorMask&POWER_CHIP) if(slsErrorMask&POWER_CHIP)
retval.append("Could not power on/off/get the chip\n"); retval.append("Could not power on/off/get the chip\n");
if(slsErrorMask&RECEIVER_READ_TIMER)
retval.append("Could not set receiver read timer\n");
if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET)
retval.append("Could not set receiver flipped data/bottom\n");
//------------------------------------------------------ length of message //------------------------------------------------------ length of message

View File

@ -149,7 +149,7 @@ void Beb_Beb(){
void Beb_GetModuleCopnfiguration(int* master, int* top){ void Beb_GetModuleConfiguration(int* master, int* top, int* normal){
*top = 0; *top = 0;
*master = 0; *master = 0;
//mapping new memory to read master top module configuration //mapping new memory to read master top module configuration
@ -168,6 +168,8 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){
*top = 1; *top = 1;
if(ret&MASTER_BIT_MASK) if(ret&MASTER_BIT_MASK)
*master = 1; *master = 1;
if(ret&NORMAL_MODULE_BIT_MASK)
*normal = 1;
//close file pointer //close file pointer
Beb_close(fd,csp0base); Beb_close(fd,csp0base);
} }

View File

@ -45,7 +45,7 @@ struct BebInfo{
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb); unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
void Beb_GetModuleCopnfiguration(int* master, int* top); void Beb_GetModuleConfiguration(int* master, int* top, int* normal);
void Beb_EndofDataSend(int tengiga); void Beb_EndofDataSend(int tengiga);
int Beb_SetMasterViaSoftware(); int Beb_SetMasterViaSoftware();

View File

@ -61,6 +61,7 @@ int Feb_Control_current_index;
int Feb_Control_counter_bit = 1; int Feb_Control_counter_bit = 1;
int Feb_control_master = 0; int Feb_control_master = 0;
int Feb_control_normal = 0;
unsigned int Feb_Control_rate_correction_table[1024]; unsigned int Feb_Control_rate_correction_table[1024];
double Feb_Control_rate_meas[16384]; double Feb_Control_rate_meas[16384];
@ -181,11 +182,12 @@ void Feb_Control_FebControl(){
int Feb_Control_Init(int master, int top, int module_num){ int Feb_Control_Init(int master, int top, int normal, int module_num){
unsigned int i; unsigned int i;
Feb_Control_module_number = 0; Feb_Control_module_number = 0;
Feb_Control_current_index = 0; Feb_Control_current_index = 0;
Feb_control_master = master; Feb_control_master = master;
Feb_control_normal = normal;
//global send //global send
Feb_Control_AddModule1(0,1,0xff,0,1); Feb_Control_AddModule1(0,1,0xff,0,1);
@ -492,59 +494,94 @@ float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vm
} }
int Feb_Control_SetHighVoltage(float value){ //only master gets to call this function
return Feb_Control_SetHighVoltage1(Feb_Control_module_number,value); int Feb_Control_SetHighVoltage(int value){
}
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){ if(!Feb_control_normal){
unsigned int module_index=0; cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n");
unsigned int i;
if(Feb_control_master){//if(Module_TopAddressIsValid(&modules[module_index])){
if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/
cprintf(RED,"Error could not set high voltage module number %d invalid.\n",module_num);
return 0;
}
}else
return 0; return 0;
}
if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0; printf(" Setting High Voltage: %d(v)\t",value);
if(module_index!=0) Module_SetHighVoltage(&modules[module_index],value);
else for(i=0;i<moduleSize;i++) Module_SetHighVoltage(&modules[i],value);
printf("\tHigh voltage of dst %d set to %f.\n",Module_GetTopRightAddress(&modules[module_index]),Module_GetHighVoltage(&modules[module_index]));
return 1;
}
int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
// printf("sending high voltage to dst_num "<<dst_num<<".\n");;
static const unsigned int nsteps = 256; static const unsigned int nsteps = 256;
static const float vmin=0; static const float vmin=0;
static const float vmax=300; static const float vmax=300;
unsigned int dacval = 0;
unsigned int b = 0; //open file
if(!Feb_Control_VoltageToDAC(*value,&b,nsteps,vmin,vmax)){ FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/out0_output","w");
printf("Waring: SetHighVoltage bad value, %f. The range is 0 to 300 V.\n",*value); if(fd==NULL){
cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n");
return 0; return 0;
} }
//calculate dac value
unsigned int r = 0x20000000 | (b&0xff); if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vmax)){
if(Feb_Control_activated){ cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to 300 V.\n",value);
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){ return 0;
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
return 0;
}
} }
//convert to string, add 0 and write to file
fprintf(fd, "%d0\n", dacval);
*value = Feb_Control_DACToVoltage(b,nsteps,vmin,vmax); printf("%d(dac)\n", dacval);
fclose(fd);
return 1; return 1;
} }
int Feb_Control_GetHighVoltage(int* value){
if(!Feb_control_normal){
cprintf(RED,"\nError: Getting High Voltage not implemented for special modules\n");
return 0;
}
printf(" Getting High Voltage: ");
static const unsigned int nsteps = 256;
static const float vmin=0;
static const float vmax=300;
unsigned int dacval = 0;
size_t readbytes=0;
char* line=NULL;
//open file
FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/in0_input","r");
if(fd==NULL){
cprintf(RED,"\nWarning: Could not open file for writing to get high voltage\n");
return 0;
}
// Read twice, since the first value is sometimes outdated
if(getline(&line, &readbytes, fd) == -1){
cprintf(RED,"\nWarning: could not read file to get high voltage\n");
return 0;
}
rewind(fd);
free(line);
readbytes=0;
readbytes = getline(&line, &readbytes, fd);
if(readbytes == -1){
cprintf(RED,"\nWarning: could not read file to get high voltage\n");
return 0;
}
// Remove the trailing 0
dacval = atoi(line)/10;
//convert dac to v
*value = (int)(Feb_Control_DACToVoltage(dacval,nsteps,vmin,vmax)+0.5);
printf("%d(v)\t%d(dac)\n", *value, dacval);
free(line);
fclose(fd);
return 1;
}
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){ 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* local_s = dac_str;

View File

@ -84,7 +84,6 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax); int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax); float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
int Feb_Control_SendHighVoltage(unsigned int module_index, float* value);
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units); int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
@ -112,15 +111,14 @@ int Feb_Control_GetModuleNumber();
void Feb_Control_FebControl(); void Feb_Control_FebControl();
int Feb_Control_Init(int master, int top, int module_num); int Feb_Control_Init(int master, int top, int normal, int module_num);
int Feb_Control_CheckSetup(); int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules(); unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules(); unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(float value); int Feb_Control_SetHighVoltage(int value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value); int Feb_Control_GetHighVoltage(int* value);
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units); int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units); int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);

View File

@ -115,6 +115,8 @@
//module configuration //module configuration
#define TOP_BIT_MASK 0x00f #define TOP_BIT_MASK 0x00f
#define MASTER_BIT_MASK 0x200 #define MASTER_BIT_MASK 0x200
#define NORMAL_MODULE_BIT_MASK 0x400
// Master Slave Top Bottom Definition // Master Slave Top Bottom Definition
#define MODULE_CONFIGURATION_MASK 0x84 #define MODULE_CONFIGURATION_MASK 0x84
//Software Configuration //Software Configuration

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/eigerDetectorServer Path: slsDetectorsPackage/slsDetectorSoftware/eigerDetectorServer
URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer
Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git
Repsitory UUID: 279965f286cc6364dec8bf7e2a837214d11bb296 Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 258 Revision: 263
Branch: developer Branch: developer
Last Changed Author: Dhanya_Maliakal Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 358 Last Changed Rev: 1313
Last Changed Date: 2016-11-03 12:31:34 +0100 Last Changed Date: 2016-11-30 10:36:34 +0100

View File

@ -1,11 +1,11 @@
//#define SVNPATH "" //#define SVNPATH ""
#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "279965f286cc6364dec8bf7e2a837214d11bb296" #define SVNREPUUID "230d6b36e9852214f4ba5ae7c92647f35000b24d"
//#define SVNREV 0x358 //#define SVNREV 0x1313
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "Dhanya_Maliakal" #define SVNAUTH "Dhanya_Maliakal"
#define SVNREV 0x358 #define SVNREV 0x1313
#define SVNDATE 0x20161103 #define SVNDATE 0x20161130
// //

View File

@ -78,6 +78,7 @@ int default_offset_values[3] = {3851000,3851000,3851000};
enum masterFlags masterMode=IS_SLAVE; enum masterFlags masterMode=IS_SLAVE;
int top = 0; int top = 0;
int master = 0; int master = 0;
int normal = 0;
#define TEN_GIGA_BUFFER_SIZE 4112 #define TEN_GIGA_BUFFER_SIZE 4112
@ -142,7 +143,7 @@ int initDetector(){
getModuleConfiguration(); getModuleConfiguration();
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber()); Feb_Control_Init(master,top,normal, getDetectorNumber());
printf("FEB Initialization done\n"); printf("FEB Initialization done\n");
Beb_Beb(); Beb_Beb();
printf("BEB Initialization done\n"); printf("BEB Initialization done\n");
@ -184,7 +185,7 @@ int initDetectorStop(){
getModuleConfiguration(); getModuleConfiguration();
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber()); Feb_Control_Init(master,top,normal,getDetectorNumber());
printf("FEB Initialization done\n"); printf("FEB Initialization done\n");
/* Beb_Beb(-1); /* Beb_Beb(-1);
printf("BEB constructor done\n");*/ printf("BEB constructor done\n");*/
@ -198,15 +199,18 @@ int initDetectorStop(){
void getModuleConfiguration(){ void getModuleConfiguration(){
int *m=&master; int *m=&master;
int *t=&top; int *t=&top;
int *n=&normal;
/*if(getDetectorNumber() == 0xbeb015){ /*if(getDetectorNumber() == 0xbeb015){
master = 1; master = 1;
top = 1; top = 1;
}*/ }*/
Beb_GetModuleCopnfiguration(m,t); Beb_GetModuleConfiguration(m,t,n);
if(top) printf("*************** TOP ***************\n"); if(top) printf("*************** TOP ***************\n");
else printf("*************** BOTTOM ***************\n"); else printf("*************** BOTTOM ***************\n");
if(master) printf("*************** MASTER ***************\n"); if(master) printf("*************** MASTER ***************\n");
else printf("*************** SLAVE ***************\n"); else printf("*************** SLAVE ***************\n");
if(normal) printf("*************** NORMAL ***************\n");
else printf("*************** SPECIAL ***************\n");
} }
@ -428,13 +432,17 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){
} }
int setHighVoltage(int val, int imod){ int setHighVoltage(int val, int imod){
if(val!=-1){ if(val!=-1){
printf(" Setting High Voltage: %d\n",val); eiger_highvoltage = val;
if(!master) if(master)
eiger_highvoltage = val; Feb_Control_SetHighVoltage(val);
else if(Feb_Control_SetHighVoltage(val)) }
eiger_highvoltage = val;
if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){
cprintf(RED,"Warning: Could not read high voltage\n");
return 0;
} }
return eiger_highvoltage; return eiger_highvoltage;
} }
@ -1112,6 +1120,8 @@ int configureMAC(int ipad, long long int macad, long long int detectormacadd, in
int beb_num = BEB_NUM;//Feb_Control_GetModuleNumber(); int beb_num = BEB_NUM;//Feb_Control_GetModuleNumber();
int header_number = 0; int header_number = 0;
int dst_port = udpport; int dst_port = udpport;
if(!top)
dst_port = udpport2;
printf("dst_port:%d\n\n",dst_port); printf("dst_port:%d\n\n",dst_port);
@ -1125,6 +1135,8 @@ int configureMAC(int ipad, long long int macad, long long int detectormacadd, in
header_number = 32; header_number = 32;
dst_port = udpport2; dst_port = udpport2;
if(!top)
dst_port = udpport;
printf("dst_port:%d\n\n",dst_port); printf("dst_port:%d\n\n",dst_port);
/*for(i=0;i<32;i++){*//** modified for Aldo*/ /*for(i=0;i<32;i++){*//** modified for Aldo*/

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware Path: slsDetectorsPackage/slsDetectorSoftware
URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git
Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git
Repsitory UUID: a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 1297 Revision: 1313
Branch: developer Branch: developer
Last Changed Author: Dhanya_Maliakal Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 1297 Last Changed Rev: 1313
Last Changed Date: 2016-11-08 15:25:56 +0100 Last Changed Date: 2016-11-30 10:36:34 +0100

View File

@ -91,7 +91,8 @@ u_int32_t progressMask=0;
int phase_shift=0;//DEFAULT_PHASE_SHIFT; int phase_shift=0;//DEFAULT_PHASE_SHIFT;
int ipPacketSize=DEFAULT_IP_PACKETSIZE; int ipPacketSize=DEFAULT_IP_PACKETSIZE;
int udpPacketSize=DEFAULT_UDP_PACKETSIZE; int udpPacketSize=DEFAULT_UDP_PACKETSIZE;
int clockdivider = 20; int clockdivider_exptime = 40;
int clockdivider_fc = 20;
/* /*
#ifndef NEW_PLL_RECONFIG #ifndef NEW_PLL_RECONFIG
u_int32_t clkDivider[2]={32,16}; u_int32_t clkDivider[2]={32,16};
@ -496,7 +497,7 @@ void configurePll(int i) {
#endif #endif
if (i<2) { if (i<2) {
tot= PLL_VCO_FREQ_MHZ/clockdivider; /* check if it always reads clock */ tot= PLL_VCO_FREQ_MHZ/clockdivider_fc; /* which clock divider?????? Is it called? clean up!! */
l=tot/2; l=tot/2;
h=l; h=l;
if (tot>2*l) { if (tot>2*l) {
@ -1221,15 +1222,15 @@ int64_t getFrames(){
int64_t setExposureTime(int64_t value){ int64_t setExposureTime(int64_t value){
if (value!=-1){ if (value!=-1){
printf("\nSetting exptime to %lldns\n",(long long int)value); printf("\nSetting exptime to %lldns\n",(long long int)value);
value*=(1E-3*clockdivider); value*=(1E-3*clockdivider_exptime);
} }
int64_t retval = set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); int64_t retval = set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clockdivider_exptime);//(1E-9*CLK_FREQ);
printf("Getting exptime: %lldns\n",(long long int)retval); printf("Getting exptime: %lldns\n",(long long int)retval);
return retval; return retval;
} }
int64_t getExposureTime(){ int64_t getExposureTime(){
return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clockdivider_exptime);//(1E-9*CLK_FREQ);
} }
int64_t setGates(int64_t value){ int64_t setGates(int64_t value){
@ -1248,31 +1249,31 @@ int64_t getGates(){
int64_t setPeriod(int64_t value){ int64_t setPeriod(int64_t value){
if (value!=-1){ if (value!=-1){
printf("\nSetting period to %lldns\n",(long long int)value); printf("\nSetting period to %lldns\n",(long long int)value);
value*=(1E-3*clockdivider); value*=(1E-3*clockdivider_fc);
} }
int64_t retval = set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); int64_t retval = set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ);
printf("Getting period: %lldns\n",(long long int)retval); printf("Getting period: %lldns\n",(long long int)retval);
return retval; return retval;
} }
int64_t getPeriod(){ int64_t getPeriod(){
return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ);
} }
int64_t setDelay(int64_t value){ int64_t setDelay(int64_t value){
if (value!=-1){ if (value!=-1){
printf("\nSetting delay to %lldns\n",(long long int)value); printf("\nSetting delay to %lldns\n",(long long int)value);
value*=(1E-3*clockdivider); value*=(1E-3*clockdivider_fc);
} }
int64_t retval = set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); int64_t retval = set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ);
printf("Getting delay: %lldns\n",(long long int)retval); printf("Getting delay: %lldns\n",(long long int)retval);
return retval; return retval;
} }
int64_t getDelay(){ int64_t getDelay(){
return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clockdivider);//(1E-9*CLK_FREQ); return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clockdivider_fc);//(1E-9*CLK_FREQ);
} }
int64_t setTrains(int64_t value){ int64_t setTrains(int64_t value){

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer
URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer
Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git
Repsitory UUID: 69e9e77d6b5517bc932f2ff4d54386d886ef6c39 Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 53 Revision: 56
Branch: developer Branch: developer
Last Changed Author: Dhanya_Maliakal Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 1296 Last Changed Rev: 1313
Last Changed Date: 2016-11-08 15:25:16 +0100 Last Changed Date: 2016-11-30 10:36:34 +0100

View File

@ -1,11 +1,11 @@
//#define SVNPATH "" //#define SVNPATH ""
#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/jungfrauDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "69e9e77d6b5517bc932f2ff4d54386d886ef6c39" #define SVNREPUUID "230d6b36e9852214f4ba5ae7c92647f35000b24d"
//#define SVNREV 0x1296 //#define SVNREV 0x1313
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "Dhanya_Maliakal" #define SVNAUTH "Dhanya_Maliakal"
#define SVNREV 0x1296 #define SVNREV 0x1313
#define SVNDATE 0x20161108 #define SVNDATE 0x20161130
// //

View File

@ -251,7 +251,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
#ifdef VERBOSE #ifdef VERBOSE
cout << thisMultiDetector->detectorIds[i] << endl; cout << thisMultiDetector->detectorIds[i] << endl;
#endif #endif
detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i], this); detectors[i]=new slsDetector(i, thisMultiDetector->detectorIds[i], this);
// setAngularConversionPointer(detectors[i]->getAngularConversionPointer(),detectors[i]->getNModsPointer(),detectors[i]->getNChans()*detectors[i]->getNChips(), i); // setAngularConversionPointer(detectors[i]->getAngularConversionPointer(),detectors[i]->getNModsPointer(),detectors[i]->getNChans()*detectors[i]->getNChips(), i);
@ -268,7 +268,12 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
getNMods(); getNMods();
getMaxMods(); getMaxMods();
threadStarted = false; dataSocketsStarted = false;
for(int i=0;i<MAXDET;++i){
context[i] = NULL;
zmqsocket[i] = NULL;
strcpy(dataSocketServerDetails[i],"");
}
threadpool = 0; threadpool = 0;
if(createThreadPool() == FAIL) if(createThreadPool() == FAIL)
exit(-1); exit(-1);
@ -367,7 +372,7 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
cout << "Creating new detector " << pos << endl; cout << "Creating new detector " << pos << endl;
#endif #endif
detectors[pos]=new slsDetector(id, this); detectors[pos]=new slsDetector(pos, id, this);
thisMultiDetector->detectorIds[pos]=detectors[pos]->getDetectorId(); thisMultiDetector->detectorIds[pos]=detectors[pos]->getDetectorId();
thisMultiDetector->numberOfDetectors++; thisMultiDetector->numberOfDetectors++;
@ -682,7 +687,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "Detector " << id << " already exists" << endl; cout << "Detector " << id << " already exists" << endl;
#endif #endif
s=new slsDetector(id, this); s=new slsDetector(pos, id, this);
if (s->getHostname()==string(name)) if (s->getHostname()==string(name))
break; break;
delete s; delete s;
@ -723,7 +728,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl; cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
#endif #endif
s=new slsDetector(t, id, this); s=new slsDetector(pos, t, id, this);
if (online) { if (online) {
s->setTCPSocket(name); s->setTCPSocket(name);
setOnline(ONLINE_FLAG); setOnline(ONLINE_FLAG);
@ -756,7 +761,7 @@ int multiSlsDetector::addSlsDetector(detectorType t, int pos) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl; cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
#endif #endif
slsDetector *s=new slsDetector(t, id, this); slsDetector *s=new slsDetector(pos, t, id, this);
s=NULL; s=NULL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Adding it to the multi detector structure" << endl; cout << "Adding it to the multi detector structure" << endl;
@ -1415,41 +1420,46 @@ int multiSlsDetector::startReadOut(){
int* multiSlsDetector::getDataFromDetector() { int* multiSlsDetector::getDataFromDetector() {
int nel=thisMultiDetector->dataBytes/sizeof(int); int nel=thisMultiDetector->dataBytes/sizeof(int);
int n; int n = 0;
int* retval=new int[nel]; int* retval= NULL;
int *retdet, *p=retval; int *retdet, *p=retval;
int nodata=1, nodatadet=-1;; int nodata=1, nodatadet=-1;
int nodatadetectortype = false;
detectorType types = getDetectorsType();
if(types == EIGER || types == JUNGFRAU){
nodatadetectortype = true;
}
if(!nodatadetectortype)
retval=new int[nel];
// cout << "multi: " << thisMultiDetector->dataBytes << endl; // cout << "multi: " << thisMultiDetector->dataBytes << endl;
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) { for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (detectors[id]) { if (detectors[id]) {
retdet=detectors[id]->getDataFromDetector(p); retdet=detectors[id]->getDataFromDetector(p);
n=detectors[id]->getDataBytes();
if(detectors[id]->getErrorMask()) if(detectors[id]->getErrorMask())
setErrorMask(getErrorMask()|(1<<id)); setErrorMask(getErrorMask()|(1<<id));
if(!nodatadetectortype){
if (retdet) { n=detectors[id]->getDataBytes();
nodata=0; if (retdet) {
nodata=0;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Detector " << id << " returned " << n << " bytes " << endl; cout << "Detector " << id << " returned " << n << " bytes " << endl;
#endif #endif
} else { } else {
nodatadet=id; nodatadet=id;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Detector " << id << " does not have data left " << endl; cout << "Detector " << id << " does not have data left " << endl;
#endif #endif
/*if((detectors[id]->getDetectorsType() != EIGER)||(detectors[id]->getDetectorsType() != JUNGFRAU)) }
break;*/ p+=n/sizeof(int);
} }
p+=n/sizeof(int);
} }
} }
//eiger returns only null //eiger returns only null
detectorType types = getDetectorsType(); if(nodatadetectortype){
if(types == EIGER || types == JUNGFRAU){
delete [] retval;
return NULL; return NULL;
} }
@ -2280,6 +2290,7 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
} }
} }
return dataout; return dataout;
} }
@ -3803,6 +3814,20 @@ int multiSlsDetector::getMaxNumberOfModules(dimension d) {
} }
int multiSlsDetector::getFlippedData(dimension d){
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->getFlippedData(d);
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
return ret;
}
int multiSlsDetector::setNumberOfModules(int p, dimension d) { int multiSlsDetector::setNumberOfModules(int p, dimension d) {
int ret=0;//, ret1; int ret=0;//, ret1;
@ -3842,6 +3867,24 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) {
} }
int multiSlsDetector::setFlippedData(dimension d, int value){
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->setFlippedData(d,value);
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
return ret;
}
int multiSlsDetector::decodeNMod(int i, int &id, int &im) { int multiSlsDetector::decodeNMod(int i, int &id, int &im) {
#ifdef VERBOSE #ifdef VERBOSE
cout << " Module " << i << " belongs to detector " << id << endl;; cout << " Module " << i << " belongs to detector " << id << endl;;
@ -4331,6 +4374,7 @@ int multiSlsDetector::readConfigurationFile(string const fname){
// char ext[100]; // char ext[100];
setAcquiringFlag(false); setAcquiringFlag(false);
clearAllErrorMask();
string ans; string ans;
string str; string str;
@ -5042,429 +5086,336 @@ int multiSlsDetector::resetFramesCaught() {
} }
int multiSlsDetector::createReceivingDataThreads(bool destroy){
if(!destroy) cprintf(MAGENTA,"Going to create data threads\n");
else cprintf(MAGENTA,"Going to destroy data threads\n");
int multiSlsDetector::createReceivingDataSockets(const bool destroy){
int numReadouts = thisMultiDetector->numberOfDetectors; //number of sockets
if(getDetectorsType() == EIGER) int numSockets = thisMultiDetector->numberOfDetectors;
numReadouts *= 2; int numSocketsPerDetector = 1;
if(getDetectorsType() == EIGER){
numSocketsPerDetector = 2;
}
numSockets *= numSocketsPerDetector;
//reset masks
killAllReceivingDataThreads = false;
//destroy
if(destroy){ if(destroy){
#ifdef DEBUG cprintf(MAGENTA,"Going to destroy data sockets\n");
cout << "Destroying Receiving Data Thread(s)" << endl; //close socket
#endif for(int i=0;i<numSockets; ++i){
killAllReceivingDataThreads = true; if(strlen(dataSocketServerDetails[i])){
for(int i = 0; i < numReadouts; ++i){ zmq_disconnect(zmqsocket[i], dataSocketServerDetails[i]);
sem_post(&sem_singlewait[i]); zmq_close(zmqsocket[i]);
pthread_join(receivingDataThreads[i],NULL); zmq_ctx_destroy(context[i]);
sem_destroy(&sem_singlewait[i]); context[i] = NULL;
sem_destroy(&sem_singledone[i]); zmqsocket[i] = NULL;
#ifdef DEBUG strcpy(dataSocketServerDetails[i],"");
cout << "." << flush << endl; }
#endif }
}
killAllReceivingDataThreads = false;
threadStarted = false;
cout << "Destroyed Receiving Data Thread(s)" << endl; dataSocketsStarted = false;
cout << "Destroyed Receiving Data Socket(s)" << endl;
return OK;
} }
//create cprintf(MAGENTA,"Going to create data sockets\n");
for(int i=0;i<numSockets; ++i){
//get name of rx_hostname
char rx_hostname[100];
strcpy(dataSocketServerDetails[i],"tcp://");
strcpy(rx_hostname, detectors[i/numSocketsPerDetector]->getReceiver());
cout<<"rx_hostname:"<<rx_hostname<<endl;
//append it (first into ip) to tcp://
if(strchr(rx_hostname,'.')!=NULL)
strcat(dataSocketServerDetails[i],rx_hostname);
else{
//convert hostname to ip
struct hostent *he = gethostbyname(rx_hostname);
if (he == NULL){
cprintf(RED,"ERROR: could not convert receiver hostname to ip\n");
exit(-1);
}else
strcat(dataSocketServerDetails[i],inet_ntoa(*(struct in_addr*)he->h_addr));
}
//add port
sprintf(dataSocketServerDetails[i],"%s:%d",dataSocketServerDetails[i],DEFAULT_ZMQ_PORTNO +
(i/numSocketsPerDetector)*numSocketsPerDetector + (i%numSocketsPerDetector));//using this instead of i in the offchance, detid doesnt start at 0 (shmget error)
//create context
context[i] = zmq_ctx_new();
//create socket
zmqsocket[i] = zmq_socket(context[i], ZMQ_PULL);
//connect socket
zmq_connect(zmqsocket[i], dataSocketServerDetails[i]);
//int hwmval = 10;
//zmq_setsockopt(zmqsocket[i],ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets)
cout << "ZMQ Client[" << i << "] from " << dataSocketServerDetails[i] << endl;
}
dataSocketsStarted = true;
cout << "Receiving Data Socket(s) created" << endl;
return OK;
}
int multiSlsDetector::getData(const int isocket, const bool masking, int* image, const int size, int &acqIndex, int &frameIndex, int &subframeIndex, string &filename){
zmq_msg_t message;
//scan header-------------------------------------------------------------------
zmq_msg_init (&message);
int len = zmq_msg_recv(&message, zmqsocket[isocket], 0);
if (len == -1) {
cprintf(BG_RED,"Could not read header for socket %d\n",isocket);
zmq_msg_close(&message);
cprintf(RED, "%d message null\n",isocket);
return FAIL;
}
// error if you print it
// cout << isocket << " header len:"<<len<<" value:"<< (char*)zmq_msg_data(&message)<<endl;
//cprintf(BLUE,"%d header %d\n",isocket,len);
rapidjson::Document d;
d.Parse( (char*)zmq_msg_data(&message), zmq_msg_size(&message));
#ifdef VERYVERBOSE
// htype is an array of strings
rapidjson::Value::Array htype = d["htype"].GetArray();
for(int i=0; i< htype.Size(); i++)
std::cout << isocket << "htype: " << htype[i].GetString() << std::endl;
// shape is an array of ints
rapidjson::Value::Array shape = d["shape"].GetArray();
cout << isocket << "shape: ";
for(int i=0; i< shape.Size(); i++)
cout << isocket << shape[i].GetInt() << " ";
cout << endl;
cout << isocket << "type: " << d["type"].GetString() << endl;
#endif
if(d["acqIndex"].GetInt()!=-9){ //!isocket &&
acqIndex = d["acqIndex"].GetInt();
frameIndex = d["fIndex"].GetInt();
subframeIndex = d["subfnum"].GetInt();
filename = d["fname"].GetString();
#ifdef VERYVERBOSE
cout << "Acquisition index: " << acqIndex << endl;
cout << "Frame index: " << frameIndex << endl;
cout << "Subframe index: " << subframeIndex << endl;
cout << "File name: " << filename << endl;
#endif
if(frameIndex ==-1) cprintf(RED,"multi frame index -1!!\n");
}
// close the message
zmq_msg_close(&message);
//scan data-------------------------------------------------------------------
zmq_msg_init (&message);
len = zmq_msg_recv(&message, zmqsocket[isocket], 0);
//cprintf(BLUE,"%d data %d\n",isocket,len);
//end of socket ("end")
if(len == 3){
//cprintf(RED,"%d Received end of acquisition\n", isocket);
return FAIL;
}
//crappy image
if (len < size ) {
cprintf(RED,"Received weird packet size %d in socket for %d\n", len, isocket);
memset((char*)image,0xFF,size);
}
//actual image
else{ else{
#ifdef DEBUG //actual data
cout << "Creating Receiving Data Thread(s)" << endl; //cprintf(BLUE,"%d actual dataaa\n",isocket);
#endif memcpy((char*)image,(char*)zmq_msg_data(&message),size);
//reset current index
currentThreadIndex = -1; //jungfrau masking adcval
for(int i = 0; i < numReadouts; ++i){ if(masking){
sem_init(&sem_singlewait[i],1,0); int snel = size/sizeof(int);
sem_init(&sem_singledone[i],1,0); for(unsigned int i=0;i<snel;++i){
threadStarted = false; image[i] = (image[i] & 0x3FFF3FFF);
currentThreadIndex = i;
if(pthread_create(&receivingDataThreads[i], NULL,staticstartReceivingDataThread, (void*) this)){
cprintf(RED, "Could not create receiving data thread with index %d\n",i);
return FAIL;
} }
while(!threadStarted);
#ifdef DEBUG
cout << "." << flush << endl;
#endif
} }
cout << "Receiving Data Thread(s) created" << endl;
} }
zmq_msg_close(&message); // close the message
return OK; return OK;
} }
void* multiSlsDetector::staticstartReceivingDataThread(void* this_pointer){
((multiSlsDetector*)this_pointer)->startReceivingDataThread();
//while(true);
return this_pointer;
}
void multiSlsDetector::startReceivingDataThread(){ void multiSlsDetector::readFrameFromReceiver(){
int ithread = currentThreadIndex; //set current thread value index //determine number of half readouts and maxX and maxY
int maxX=0,maxY=0;
char hostname[100] = "tcp://"; int numSockets = thisMultiDetector->numberOfDetectors;
char rx_hostname[100]; int numSocketsPerSLSDetector = 1;
strcpy(rx_hostname, detectors[ithread]->getReceiver());
cout<<"rx_hostname:"<<rx_hostname<<endl;
if(strchr(rx_hostname,'.')!=NULL)
strcat(hostname,rx_hostname);
else{
struct hostent *he = gethostbyname(rx_hostname);
if (he == NULL){
cprintf(RED,"ERROR: could not convert receiver hostname to ip\n");
exit(-1);
}else
strcat(hostname,inet_ntoa(*(struct in_addr*)he->h_addr));
}
strcat(hostname,":");
//server details
//char hostname[100] = "tcp://127.0.0.1:";
int portno = DEFAULT_ZMQ_PORTNO + ithread;
sprintf(hostname,"%s%d",hostname,portno);
//socket details
zmq_msg_t message;
void *context;
void *zmqsocket;
context = zmq_ctx_new();
zmqsocket = zmq_socket(context, ZMQ_PULL);
//int hwmval = 10;
//zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets)
cprintf(RED,"connect ret:%d\n",zmq_connect(zmqsocket, hostname));
cout << "ZMQ Client of " << ithread << " at " << hostname << endl;
cprintf(BLUE,"%d Created socket\n",ithread);
//initializations
int numReadoutPerDetector = 1;
bool jungfrau = false; bool jungfrau = false;
int expectedsize = 1024*256;/**shouldnt work for other bit modes or anythign*/ switch(getDetectorsType()){
if(getDetectorsType() == EIGER){ case EIGER:
numReadoutPerDetector = 2; numSocketsPerSLSDetector = 2;
expectedsize = 1024*256; numSockets *= numSocketsPerSLSDetector;
}else if(getDetectorsType() == JUNGFRAU){ maxX = thisMultiDetector->numberOfChannel[X];
maxY = thisMultiDetector->numberOfChannel[Y];
break;
case JUNGFRAU:
jungfrau = true; jungfrau = true;
expectedsize = 8192*128; break;
default:
break;
} }
int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes();
int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int);
int* image = new int[nel];
int len,idet = 0;
singleframe[ithread]=NULL;
threadStarted = true; //let calling function know thread started and obtained current
//gui variables
int currentAcquisitionIndex = -1;
int currentFrameIndex = -1;
int currentSubFrameIndex = -1;
string currentFileName = "";
//infinite loop, exited only (if gui restarted/ enabledatastreaming called) //getting sls values
while(true){ int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0, nx=0, ny=0;
if(detectors[0]){
slsdatabytes = detectors[0]->getDataBytes();
sem_wait(&sem_singlewait[ithread]); //wait for it to be copied slsmaxchannels = detectors[0]->getMaxNumberOfChannels();
//check to exit thread bytesperchannel = slsdatabytes/slsmaxchannels;
if(killAllReceivingDataThreads) slsmaxX = detectors[0]->getTotalNumberOfChannels(X);
break; slsmaxY = detectors[0]->getTotalNumberOfChannels(Y);
}
//scan header------------------------------------------------------------------- //getting multi values
zmq_msg_init (&message); nx = getTotalNumberOfChannels(slsDetectorDefs::X);
len = zmq_msg_recv(&message, zmqsocket, 0); ny = getTotalNumberOfChannels(slsDetectorDefs::Y);
if (len == -1) { //calculating offsets (for eiger interleaving ports)
cprintf(BG_RED,"Could not read header for socket %d\n",ithread); int offsetX[numSockets]; int offsetY[numSockets];
zmq_msg_close(&message); int bottom[numSockets];
cprintf(RED, "%d message null\n",ithread); if(maxX){
continue; for(int i=0; i<numSockets; ++i){
offsetY[i] = (maxY - (thisMultiDetector->offsetY[i/numSocketsPerSLSDetector] + slsmaxY)) * maxX * bytesperchannel;
//the left half or right half
if(!(i%numSocketsPerSLSDetector))
offsetX[i] = thisMultiDetector->offsetX[i/numSocketsPerSLSDetector];
else
offsetX[i] = thisMultiDetector->offsetX[i/numSocketsPerSLSDetector] + (slsmaxX/numSocketsPerSLSDetector);
offsetX[i] *= bytesperchannel;
bottom[i] = detectors[i/numSocketsPerSLSDetector]->getFlippedData(X);/*only for eiger*/
} }
}
int expectedslssize = slsdatabytes/numSocketsPerSLSDetector;
int* image = new int[(expectedslssize/sizeof(int))]();
int nel=(thisMultiDetector->dataBytes)/sizeof(int);
if(nel <= 0){
cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes);
return;
}
int* multiframe=new int[nel]();
// error if you print it volatile uint64_t dataThreadMask = 0x0;
// cout << ithread << " header len:"<<len<<" value:"<< (char*)zmq_msg_data(&message)<<endl;
//cprintf(BLUE,"%d header %d\n",ithread,len);
rapidjson::Document d;
d.Parse( (char*)zmq_msg_data(&message), zmq_msg_size(&message));
#ifdef VERYVERBOSE
// htype is an array of strings
rapidjson::Value::Array htype = d["htype"].GetArray();
for(int i=0; i< htype.Size(); i++)
std::cout << ithread << "htype: " << htype[i].GetString() << std::endl;
// shape is an array of ints
rapidjson::Value::Array shape = d["shape"].GetArray();
cout << ithread << "shape: ";
for(int i=0; i< shape.Size(); i++)
cout << ithread << shape[i].GetInt() << " ";
cout << endl;
cout << ithread << "type: " << d["type"].GetString() << endl; //wait for real time acquisition to start
bool running = true;
sem_wait(&sem_newRTAcquisition);
if(checkJoinThread())
running = false;
#endif for(int i = 0; i < numSockets; ++i)
if(!ithread && (d["acqIndex"].GetInt()!=-9)){ dataThreadMask|=(1<<i);
currentAcquisitionIndex = d["acqIndex"].GetInt();
currentFrameIndex = d["fIndex"].GetInt();
currentSubFrameIndex = d["subfnum"].GetInt();
currentFileName = d["fname"].GetString();
#ifdef VERYVERBOSE
cout << "Acquisition index: " << currentAcquisitionIndex << endl;
cout << "Frame index: " << currentFrameIndex << endl;
cout << "Subframe index: " << currentSubFrameIndex << endl;
cout << "File name: " << currentFileName << endl;
#endif
if(currentFrameIndex ==-1) cprintf(RED,"multi frame index -1!!\n");
}
singleframe[ithread]=image;
// close the message //exit when last message for each socket received
zmq_msg_close(&message); while(running){
//memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
//get each frame
for(int isocket=0; isocket<numSockets; ++isocket){
//scan data------------------------------------------------------------------- //if running
zmq_msg_init (&message); if((1 << isocket) & dataThreadMask){
len = zmq_msg_recv(&message, zmqsocket, 0);
//cprintf(BLUE,"%d data %d\n",ithread,len); //get individual images
//end of socket ("end") if(FAIL == getData(isocket, jungfrau, image, expectedslssize, currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex,currentFileName)){
if (len < expectedsize ) { dataThreadMask^=(1<<isocket);
if(len == 3){ continue;
//cprintf(RED,"%d Received end of acquisition\n", ithread); }
singleframe[ithread] = NULL;
//break;
}else{
cprintf(RED,"Received weird packet size %d in socket for %d\n", len, ithread);
memset((char*)(singleframe[ithread]),0xFF,singleDatabytes/numReadoutPerDetector);
}
} //assemble data with interleaving
else{ if(maxX){
//actual data
//cprintf(BLUE,"%d actual dataaa\n",ithread);
memcpy((char*)(singleframe[ithread]),(char*)zmq_msg_data(&message),singleDatabytes/numReadoutPerDetector);
//bottom
if(bottom[isocket]){
//if((((isocket/numSocketsPerSLSDetector)+1)%2) == 0){
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + ((slsmaxY-1-i)*maxX*bytesperchannel),
(char*)image+ i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel,
(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
}
}
//top
else{
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + (i*maxX*bytesperchannel),
(char*)image+ i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel,
(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
}
}
}
//jungfrau masking adcval //assemble data with no interleaving, assumed detectors appended vertically
if(jungfrau){ else{
for(unsigned int i=0;i<nel;i++){ memcpy((char*)multiframe+slsdatabytes*isocket,(char*)image,slsdatabytes);
singleframe[ithread][i] = (singleframe[ithread][i] & 0x3FFF3FFF);
} }
} }
} }
sem_post(&sem_singledone[ithread]);//let multi know is ready
zmq_msg_close(&message); // close the message
}
cprintf(RED,"%d Closing socket\n",ithread); //all done
//close socket if(!dataThreadMask){
zmq_disconnect(zmqsocket, hostname); sem_wait(&sem_newRTAcquisition);
zmq_close(zmqsocket); //done with complete acquisition
zmq_ctx_destroy(context); if(checkJoinThread())
break;
else{
//starting a new scan/measurement
for(int i = 0; i < numSockets; ++i)
dataThreadMask|=(1<<i);
running = false;
}
}
//send data to callback
if(running){
fdata = decodeData(multiframe);
if ((fdata) && (dataReady)){
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
delete thisData;
fdata = NULL;
//cout<<"Send frame #"<< currentFrameIndex << " to gui"<<endl;
}
setCurrentProgress(currentAcquisitionIndex+1);
}
//setting it back for each scan/measurement
running = true;
}
//free resources //free resources
delete [] image; delete [] image;
delete[] multiframe;
#ifdef DEBUG
cprintf(MAGENTA,"Receiving Data Thread %d:Goodbye!\n",ithread);
#endif
} }
// void multiSlsDetector::readFrameFromReceiver(){
// //determine number of half readouts and maxX and maxY
// int maxX=0,maxY=0;
// int numReadoutPerDetector = 1;
// if(getDetectorsType() == EIGER){
// numReadoutPerDetector = 2;
// maxX = thisMultiDetector->numberOfChannel[X];
// maxY = thisMultiDetector->numberOfChannel[Y];
// }
// int numReadouts = numReadoutPerDetector * thisMultiDetector->numberOfDetectors;
// //initializing variables
// currentFileName="";
// currentAcquisitionIndex = -1;
// currentFrameIndex = -1;
// currentSubFrameIndex = -1;
// //getting values
// int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0;
// if(detectors[0]){
// slsdatabytes = detectors[0]->getDataBytes();
// slsmaxchannels = detectors[0]->getMaxNumberOfChannels();
// bytesperchannel = slsdatabytes/slsmaxchannels;
// slsmaxX = detectors[0]->getTotalNumberOfChannels(X);
// slsmaxY = detectors[0]->getTotalNumberOfChannels(Y);
// }
// int nel=(thisMultiDetector->dataBytes)/sizeof(int);
// if(nel <= 0){
// cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes);
// return;
// }
// int* multiframe=new int[nel];
// int idet,offsetY,offsetX;
// int halfreadoutoffset = (slsmaxX/numReadoutPerDetector);
// int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
// int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
// volatile uint64_t dataThreadMask = 0x0;
// for(int i = 0; i < numReadouts; ++i)
// dataThreadMask|=(1<<i);
// //construct complete image and send to callback
// while(true){
// //memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
// //post all of them to start
// for(int ireadout=0; ireadout<numReadouts; ++ireadout){
// if((1 << ireadout) & dataThreadMask){
// sem_post(&sem_singlewait[ireadout]); //sls to continue
// }
// }
// //get each frame
// for(int ireadout=0; ireadout<numReadouts; ++ireadout){
// //cprintf(BLUE,"multi checking %d mask:0x%x\n",ireadout,receivingDataThreadMask);
// idet = ireadout/numReadoutPerDetector;
// if((1 << ireadout) & dataThreadMask){ //if running
// sem_wait(&sem_singledone[ireadout]); //wait for sls to copy
// //this socket closed
// if(singleframe[ireadout] == NULL){ //if got nothing
// dataThreadMask^=(1<<ireadout);
// continue;
// }
// //assemble data
// if(maxX){ //eiger, so interleaving between ports in one readout itself
// offsetY = (maxY - (thisMultiDetector->offsetY[idet] + slsmaxY)) * maxX * bytesperchannel;
// //the left half or right half
// if(!(ireadout%numReadoutPerDetector))
// offsetX = thisMultiDetector->offsetX[idet];
// else
// offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset;
// offsetX *= bytesperchannel;
// //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n",
// // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel);
// // cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadoutPerDetector)*bytesperchannel);
// //itnerleaving with other detectors
// //bottom
// if(((idet+1)%2) == 0){
// for(int i=0;i<slsmaxY;++i)
// memcpy(((char*)multiframe) + offsetY + offsetX + ((slsmaxY-i)*maxX*bytesperchannel),
// (char*)singleframe[ireadout]+ i*(slsmaxX/numReadoutPerDetector)*bytesperchannel,
// (slsmaxX/numReadoutPerDetector)*bytesperchannel);
// }
// //top
// else{
// for(int i=0;i<slsmaxY;++i)
// memcpy(((char*)multiframe) + offsetY + offsetX + (i*maxX*bytesperchannel),
// (char*)singleframe[ireadout]+ i*(slsmaxX/numReadoutPerDetector)*bytesperchannel,
// (slsmaxX/numReadoutPerDetector)*bytesperchannel);
// }
// }
// //no interleaving, just add to the end
// //numReadout always 1 here
// else{
// memcpy((char*)multiframe+slsdatabytes*ireadout,(char*)singleframe[ireadout],slsdatabytes);
// }
// }
// }
// //all done
// if(!dataThreadMask)
// break;
// //send data to callback
// fdata = decodeData(multiframe);
// if ((fdata) && (dataReady)){
// thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
// dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
// delete thisData;
// fdata = NULL;
// //cout<<"Send frame #"<< currentFrameIndex << " to gui"<<endl;
// }
// setCurrentProgress(currentAcquisitionIndex+1);
// }
// //free resources
// delete[] multiframe;
// }
int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ int nel=(thisMultiDetector->dataBytes)/sizeof(int); if(nel <= 0){ cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; acquisitionIndex = -1; return NULL; } int n,complete=OK; int i,k,offsetX, offsetY, maxX, maxY; double dr; int* retval=new int[nel]; int *retdet = NULL, *p=retval; string fullFName=""; string ext=""; int index=-1,f_index=-1,p_index=-1,det_index=-1; double sv0=-1,sv1=-1; if(getDetectorsType() == EIGER){ maxX = thisMultiDetector->numberOfChannel[X]; maxY = thisMultiDetector->numberOfChannel[Y]; } for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) { if (detectors[id]) { n=detectors[id]->getDataBytes(); retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex, subFrameIndex); if(detectors[id]->getErrorMask()) setErrorMask(getErrorMask()|(1<<id)); if (retdet){ if (acquisitionIndex==-1){ complete = FAIL; delete [] retdet; }else{ n=detectors[id]->getDataBytes(); if(getDetectorsType() == EIGER){
//cout << "fname:"<<fName<<" findex:"<<fIndex<<endl;//cout<<"n:"<<n<<endl;//cout<<"maxchan:"<<detectors[id]->getMaxNumberOfChannels()<<" n:"<<n<<endl;
dr = (double)n/detectors[id]->getMaxNumberOfChannels();
k=(int)(detectors[id]->getMaxNumberOfChannels(X)*dr);
//bit mode
//cout << "dr:"<<dr<<endl;//cout << "k:"<<k<<endl;
offsetY = (int)(((maxY - (thisMultiDetector->offsetY[id] + detectors[id]->getMaxNumberOfChannels(Y))) * maxX)*dr);//bit mode
offsetX = (int)(thisMultiDetector->offsetX[id]*dr);
//cout << "offsetY"<<offsetY<< " offsetX:"<<offsetX<<endl;
for(i=0; i< 256;i++){
memcpy((((char*)p) + offsetY + offsetX + ((int)(i*maxX*dr))) ,(((char*)retdet) + (i*k)),k);//bit mode
}
} else{
memcpy(p,retdet,n);
p+=n/sizeof(int);
}
delete [] retdet;
//concatenate filenames
if(!fullFName.length()){
//assign file prefix
fullFName.assign(fileIO::getFileName());
if (strrchr(fName,'.')!=NULL){
ext.assign(fName);
size_t dot = ext.rfind(".");
if(dot != string::npos)
ext = ext.erase(0,dot);
else
ext = "";
//get variables
fileIOStatic::getVariablesFromFileName(fName,index, f_index, p_index, sv0, sv1, det_index);
//append scan and det variables
fullFName.append(fileIOStatic::getReceiverFileNameToConcatenate(fName));
}
}
//append only if scan variables are different
if(!fileIOStatic::verifySameFrame(fName,index,f_index, p_index, sv0, sv1, det_index)){
fullFName.append(fileIOStatic::getReceiverFileNameToConcatenate(fName));
}
}
}
else {
#ifdef VERBOSE
cout << "Receiver for detector " << id << " does not have data left " << endl;
#endif
delete [] retval;
return NULL;
}
}
}
//append extension
fullFName.append(ext);
strcpy(fName,fullFName.c_str());
//if some of the receivers did not give data, dont count it
if((getDetectorsType() == EIGER) &&(complete ==FAIL))
acquisitionIndex = -1;
return retval;
};
int multiSlsDetector::lockReceiver(int lock) { int multiSlsDetector::lockReceiver(int lock) {
int ret=-100, ret1; int ret=-100, ret1;
@ -5687,20 +5638,39 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
} }
int multiSlsDetector::setReceiverReadTimer(int time_in_ms){
int ret=-100, ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setReceiverReadTimer(time_in_ms);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
}
return ret;
}
// only called from gui or that wants zmq data packets // only called from gui or that wants zmq data packets
int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
if(enable >= 0){ if(enable >= 0){
if(dataSocketsStarted != enable){
if(threadStarted != enable){
//destroy data threads //destroy data threads
if(threadStarted) if(dataSocketsStarted)
createReceivingDataThreads(true); createReceivingDataSockets(true);
//create data threads //create data threads
if(enable > 0){ if(enable > 0){
if(createReceivingDataThreads() == FAIL){ if(createReceivingDataSockets() == FAIL){
std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; std::cout << "Could not create data threads in client. Aborting creating data sockets in receiver" << std::endl;
//only for the first det as theres no general one //only for the first det as theres no general one
setErrorMask(getErrorMask()|(1<<0)); setErrorMask(getErrorMask()|(1<<0));
detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING));
@ -5709,7 +5679,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
} }
} }
}else enable = threadStarted; }else enable = dataSocketsStarted;
int ret=-100, ret1; int ret=-100, ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) { for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
@ -5725,9 +5695,9 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
} }
/* /*
if(enable == -1) if(enable == -1)
return threadStarted; return dataSocketsStarted;
*/ */
return (threadStarted & ret); return (dataSocketsStarted & ret);
} }
int multiSlsDetector::enableReceiverCompression(int i){ int multiSlsDetector::enableReceiverCompression(int i){

View File

@ -340,6 +340,12 @@ class multiSlsDetector : public slsDetectorUtils {
int getMaxNumberOfChannelsPerDetector(dimension d){return thisMultiDetector->maxNumberOfChannelsPerDetector[d];}; int getMaxNumberOfChannelsPerDetector(dimension d){return thisMultiDetector->maxNumberOfChannelsPerDetector[d];};
/** returns the enable if data will be flipped across x or y axis
* \param d axis across which data is flipped
* returns 1 or 0
*/
int getFlippedData(dimension d=X);
int setMaxNumberOfChannelsPerDetector(dimension d,int i){thisMultiDetector->maxNumberOfChannelsPerDetector[d]=i; return thisMultiDetector->maxNumberOfChannelsPerDetector[d];}; int setMaxNumberOfChannelsPerDetector(dimension d,int i){thisMultiDetector->maxNumberOfChannelsPerDetector[d]=i; return thisMultiDetector->maxNumberOfChannelsPerDetector[d];};
double getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];}; double getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];};
@ -979,6 +985,14 @@ class multiSlsDetector : public slsDetectorUtils {
int configureMAC(); int configureMAC();
int setNumberOfModules(int i=-1, dimension d=X); int setNumberOfModules(int i=-1, dimension d=X);
/** sets the enable which determines if data will be flipped across x or y axis
* \param d axis across which data is flipped
* \param value 0 or 1 to reset/set or -1 to get value
* \return enable flipped data across x or y axis
*/
int setFlippedData(dimension d=X, int value=-1);
int getMaxNumberOfModules(dimension d=X); int getMaxNumberOfModules(dimension d=X);
int setDynamicRange(int i=-1); int setDynamicRange(int i=-1);
@ -1196,19 +1210,18 @@ class multiSlsDetector : public slsDetectorUtils {
int resetFramesCaught(); int resetFramesCaught();
/** /**
* Create Receiving Data Threads * Create Receiving Data Sockets
* @param destroy is true to destroy all the threads * @param destroy is true to destroy all the sockets
* @return OK or FAIL * @return OK or FAIL
*/ */
int createReceivingDataThreads(bool destroy = false); int createReceivingDataSockets(const bool destroy = false);
/** Reads frames from receiver through a constant socket /** Reads frames from receiver through a constant socket
*/ */
//void readFrameFromReceiver(); void readFrameFromReceiver();
int* readFrameFromReceiver(char*, int&, int&, int&); /** Locks/Unlocks the connection to the receiver
/** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock /param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver /returns lock status of the receiver
*/ */
@ -1276,6 +1289,14 @@ class multiSlsDetector : public slsDetectorUtils {
*/ */
int setReadReceiverFrequency(int getFromReceiver, int freq=-1); int setReadReceiverFrequency(int getFromReceiver, int freq=-1);
/** Sets the read receiver timer
if data required from receiver randomly readRxrFrequency=0,
then the timer between each data stream is set with time_in_ms
@param time_in_ms timer between frames
/returns read receiver timer
*/
int setReceiverReadTimer(int time_in_ms=500);
/** Enable or disable streaming data from receiver to client /** Enable or disable streaming data from receiver to client
* @param enable 0 to disable 1 to enable -1 to only get the value * @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming * @returns data streaming
@ -1384,35 +1405,17 @@ class multiSlsDetector : public slsDetectorUtils {
private: private:
/**
* Static function - Starts Data Thread of this object
* @param this_pointer pointer to this object
*/
static void* staticstartReceivingDataThread(void *this_pointer);
/** /**
* Thread that receives data packets from receiver * Gets data from socket
*/ */
void startReceivingDataThread(); int getData(const int isocket, const bool masking, int* image, const int size, int &acqIndex, int &frameIndex, int &subframeIndex, string &filename);
/* synchronizing between zmq threads */ /** Ensures if sockets created successfully */
sem_t sem_singledone[MAXDET]; bool dataSocketsStarted;
sem_t sem_singlewait[MAXDET]; void *context[MAXDET];
int* singleframe[MAXDET]; void *zmqsocket[MAXDET];
char dataSocketServerDetails[MAXDET][100];
/* Parameters given to the gui picked up from zmq threads*/
int currentAcquisitionIndex;
int currentFrameIndex;
int currentSubFrameIndex;
string currentFileName;
pthread_t receivingDataThreads[MAXDET];
/** Ensures if threads created successfully */
bool threadStarted;
/** Current Thread Index*/
int currentThreadIndex;
/** Set to self-terminate data receiving threads waiting for semaphores */
bool killAllReceivingDataThreads;
protected: protected:

View File

@ -1,11 +1,11 @@
//#define SVNPATH "" //#define SVNPATH ""
#define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git" #define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUIDLIB "a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc" #define SVNREPUUIDLIB "230d6b36e9852214f4ba5ae7c92647f35000b24d"
//#define SVNREV 0x1297 //#define SVNREV 0x1313
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTHLIB "Dhanya_Maliakal" #define SVNAUTHLIB "Dhanya_Maliakal"
#define SVNREVLIB 0x1297 #define SVNREVLIB 0x1313
#define SVNDATELIB 0x20161108 #define SVNDATELIB 0x20161130
// //

File diff suppressed because it is too large Load Diff

View File

@ -267,6 +267,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** flag for acquiring */ /** flag for acquiring */
bool acquiringFlag; bool acquiringFlag;
/** flipped data across x or y axis */
int flippedData[2];
} sharedSlsDetector; } sharedSlsDetector;
@ -295,20 +297,22 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** (default) constructor /** (default) constructor
\param type is needed to define the size of the detector shared memory 9defaults to GENERIC i.e. the largest shared memory needed by any slsDetector is allocated \param type is needed to define the size of the detector shared memory 9defaults to GENERIC i.e. the largest shared memory needed by any slsDetector is allocated
\param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently \param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently
\param pos is the index of object in the parent multislsdet array
\param p is the parent multislsdet to access filename ,path etc \param p is the parent multislsdet to access filename ,path etc
*/ */
slsDetector(detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL); slsDetector(int pos, detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL);
/** constructor /** constructor
\param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently \param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently
\param pos is the index of object in the parent multislsdet array
\param p is the parent multislsdet to access filename ,path etc \param p is the parent multislsdet to access filename ,path etc
*/ */
slsDetector(int id, multiSlsDetector *p=NULL); slsDetector(int pos, int id, multiSlsDetector *p=NULL);
slsDetector(char *name, int id=0, int cport=DEFAULT_PORTNO, multiSlsDetector *p=NULL); slsDetector(int pos, char *name, int id=0, int cport=DEFAULT_PORTNO, multiSlsDetector *p=NULL);
//slsDetector(string const fname); //slsDetector(string const fname);
// ~slsDetector(){while(dataQueue.size()>0){}}; // ~slsDetector(){while(dataQueue.size()>0){}};
/** destructor */ /** destructor */
@ -668,6 +672,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];}; int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];};
/** returns the enable if data will be flipped across x or y axis
* \param d axis across which data is flipped
* returns 1 or 0
*/
int getFlippedData(dimension d=X){return thisDetector->flippedData[d];};
/** Returns number of rois */ /** Returns number of rois */
int getNRoi(){return thisDetector->nROI;}; int getNRoi(){return thisDetector->nROI;};
@ -733,6 +743,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int setNumberOfModules(int n=GET_FLAG, dimension d=X); // if n=GET_FLAG returns the number of installed modules int setNumberOfModules(int n=GET_FLAG, dimension d=X); // if n=GET_FLAG returns the number of installed modules
/** sets the enable which determines if data will be flipped across x or y axis
* \param d axis across which data is flipped
* \param value 0 or 1 to reset/set or -1 to get value
* \return enable flipped data across x or y axis
*/
int setFlippedData(dimension d=X, int value=-1);
/* /*
@ -1412,6 +1428,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int getDetectorId(int i=-1) {return detId;}; int getDetectorId(int i=-1) {return detId;};
/** /**
Receives a data frame from the detector socket Receives a data frame from the detector socket
\returns pointer to the data (or NULL if failed) \returns pointer to the data (or NULL if failed)
@ -1596,19 +1613,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int resetFramesCaught(); int resetFramesCaught();
/**
* Create Receiving Data Threads
* @param destroy is true to destroy all the threads
* @return OK or FAIL
*/
int createReceivingDataThreads(bool destroy = false){return 0;};
/** Reads frames from receiver through a constant socket
*/
//void readFrameFromReceiver(){};
int* readFrameFromReceiver(char*, int&, int&, int&);
/** Locks/Unlocks the connection to the receiver /** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock /param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver /returns lock status of the receiver
@ -1717,6 +1722,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int setReadReceiverFrequency(int getFromReceiver, int freq=-1); int setReadReceiverFrequency(int getFromReceiver, int freq=-1);
/** Sets the read receiver timer
if data required from receiver randomly readRxrFrequency=0,
then the timer between each data stream is set with time_in_ms
@param time_in_ms timer between frames
/returns read receiver timer
*/
int setReceiverReadTimer(int time_in_ms=500);
/** Enable or disable streaming data from receiver to client /** Enable or disable streaming data from receiver to client
* @param enable 0 to disable 1 to enable -1 to only get the value * @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming * @returns data streaming
@ -1838,6 +1851,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int detId; int detId;
/**
position ID
*/
int posId;
/** /**
* parent multi detector * parent multi detector

View File

@ -432,7 +432,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize;
i++; i++;
descrToFuncMap[i].m_pFuncName="flippeddatax"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize;
i++;
descrToFuncMap[i].m_pFuncName="flippeddatay"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize;
i++;
/* flags */ /* flags */
@ -1251,12 +1257,13 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if(myDet->acquire() == FAIL) if(myDet->acquire() == FAIL)
return string("acquire unsuccessful"); return string("acquire unsuccessful");
if(myDet->setReceiverOnline()==ONLINE_FLAG){ if(myDet->setReceiverOnline()==ONLINE_FLAG){
char answer[100]; char answer[100];
sprintf(answer,"\n%d",myDet->getFramesCaughtByReceiver()); sprintf(answer,"\nAcquired %d",myDet->getFramesCaughtByReceiver());
return string(answer); return string(answer);
} }
@ -1295,6 +1302,7 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action) {
b=myDet->setThreadedProcessing(-1); b=myDet->setThreadedProcessing(-1);
myDet->setThreadedProcessing(0); myDet->setThreadedProcessing(0);
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->readAll(); myDet->readAll();
//processdata in receiver is useful only for gui purposes //processdata in receiver is useful only for gui purposes
if(myDet->setReceiverOnline()==OFFLINE_FLAG) if(myDet->setReceiverOnline()==OFFLINE_FLAG)
@ -1329,6 +1337,7 @@ string slsDetectorCommand::cmdFrame(int narg, char *args[], int action) {
b=myDet->setThreadedProcessing(-1); b=myDet->setThreadedProcessing(-1);
myDet->setThreadedProcessing(0); myDet->setThreadedProcessing(0);
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->readFrame(); myDet->readFrame();
//processdata in receiver is useful only for gui purposes //processdata in receiver is useful only for gui purposes
if(myDet->setReceiverOnline()==OFFLINE_FLAG) if(myDet->setReceiverOnline()==OFFLINE_FLAG)
@ -1737,6 +1746,7 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action){
return string("Error closing server\n"); return string("Error closing server\n");
} }
else if (cmd=="exitreceiver"){ else if (cmd=="exitreceiver"){
myDet->setReceiverOnline(ONLINE_FLAG);
if(myDet->exitReceiver()!=OK) if(myDet->exitReceiver()!=OK)
return string("Receiver shut down\n"); return string("Receiver shut down\n");
else else
@ -1858,6 +1868,7 @@ string slsDetectorCommand::helpTrimEn(int narg, char *args[], int action) {
string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){ string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpOutDir(narg, args, action); return helpOutDir(narg, args, action);
@ -1882,6 +1893,7 @@ string slsDetectorCommand::helpOutDir(int narg, char *args[], int action){
string slsDetectorCommand::cmdFileName(int narg, char *args[], int action){ string slsDetectorCommand::cmdFileName(int narg, char *args[], int action){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpFileName(narg, args, action); return helpFileName(narg, args, action);
if (cmd=="fname") { if (cmd=="fname") {
@ -1911,7 +1923,7 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){
int i; int i;
char ans[100]; char ans[100];
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) { if (action==HELP_ACTION) {
return helpEnablefwrite(narg, args, action); return helpEnablefwrite(narg, args, action);
} }
@ -1943,7 +1955,7 @@ string slsDetectorCommand::cmdOverwrite(int narg, char *args[], int action){
int i; int i;
char ans[100]; char ans[100];
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) { if (action==HELP_ACTION) {
return helpOverwrite(narg, args, action); return helpOverwrite(narg, args, action);
} }
@ -1975,7 +1987,7 @@ string slsDetectorCommand::helpOverwrite(int narg, char *args[], int action){
string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action){ string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action){
char ans[100]; char ans[100];
int i; int i;
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) { if (action==HELP_ACTION) {
return helpFileName(narg, args, action); return helpFileName(narg, args, action);
} }
@ -2088,6 +2100,8 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){
double fval; double fval;
char answer[1000]; char answer[1000];
myDet->setOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%lf",&fval); sscanf(args[1],"%lf",&fval);
myDet->setRateCorrection(fval); myDet->setRateCorrection(fval);
@ -2785,6 +2799,7 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
return helpNetworkParameter(narg,args,action); return helpNetworkParameter(narg,args,action);
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if (cmd=="detectormac") { if (cmd=="detectormac") {
t=DETECTOR_MAC; t=DETECTOR_MAC;
@ -2954,6 +2969,7 @@ string slsDetectorCommand::cmdLock(int narg, char *args[], int action) {
else if(cmd=="r_lock"){ else if(cmd=="r_lock"){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&val)) if (sscanf(args[1],"%d",&val))
myDet->lockReceiver(val); myDet->lockReceiver(val);
@ -3004,8 +3020,10 @@ string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action) {
return myDet->getLastClientIP(); return myDet->getLastClientIP();
} }
else if(cmd=="r_lastclient") else if(cmd=="r_lastclient"){
myDet->setReceiverOnline(ONLINE_FLAG);
return myDet->getReceiverLastClientIP(); return myDet->getReceiverLastClientIP();
}
return string("cannot decode command"); return string("cannot decode command");
} }
@ -3051,6 +3069,7 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
} }
else if(cmd=="activate"){ else if(cmd=="activate"){
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
if (!sscanf(args[1],"%d",&ival)) if (!sscanf(args[1],"%d",&ival))
return string("Could not scan activate mode ")+string(args[1]); return string("Could not scan activate mode ")+string(args[1]);
@ -3072,11 +3091,12 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
else{ else{
if (action==PUT_ACTION) if (action==PUT_ACTION)
return string("cannot set"); return string("cannot set");
myDet->setReceiverOnline(ONLINE_FLAG);
strcpy(ans,myDet->checkReceiverOnline().c_str()); strcpy(ans,myDet->checkReceiverOnline().c_str());
if(!strlen(ans)) if(!strlen(ans))
strcpy(ans,"All receiver online"); strcpy(ans,"All receiver online");
else else
strcat(ans," :Not receiver online"); strcat(ans," :Not all receiver online");
} }
return ans; return ans;
@ -3113,6 +3133,7 @@ string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action) {
if (action==PUT_ACTION){ if (action==PUT_ACTION){
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->configureMAC(); ret=myDet->configureMAC();
} }
else else
@ -3139,7 +3160,7 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpDetectorSize(narg,args,action); return helpDetectorSize(narg,args,action);
int ret, val=-1, pos=-1,i; int ret, val=-1, pos=-1,i;
char ans[1000], temp[100]; char ans[1000];
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
@ -3176,6 +3197,21 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
myDet->setMaxNumberOfChannelsPerDetector(Y,val); myDet->setMaxNumberOfChannelsPerDetector(Y,val);
} }
if(cmd=="flippeddatax"){
if ((!sscanf(args[1],"%d",&val)) || (val!=0 && val != 1))
return string ("cannot scan flippeddata x mode: must be 0 or 1");
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->setFlippedData(X,val);
}
if(cmd=="flippeddatay"){
return string("Not required for this detector\n");
if ((!sscanf(args[1],"%d",&val)) || (val!=0 && val != 1))
return string ("cannot scan flippeddata y mode: must be 0 or 1");
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->setFlippedData(Y,val);
}
} }
if (cmd=="nmod" || cmd=="roimask") { if (cmd=="nmod" || cmd=="roimask") {
@ -3183,14 +3219,23 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
} else if (cmd=="maxmod") { } else if (cmd=="maxmod") {
ret=myDet->getMaxNumberOfModules(); ret=myDet->getMaxNumberOfModules();
} else if (cmd=="dr") { } else if (cmd=="dr") {
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->setDynamicRange(val); ret=myDet->setDynamicRange(val);
} else if (cmd=="roi") { } else if (cmd=="roi") {
myDet->getROI(ret); myDet->getROI(ret);
} else if (cmd=="detsizechan") { } else if (cmd=="detsizechan") {
sprintf(ans,"%d",myDet->getMaxNumberOfChannelsPerDetector(X)); sprintf(ans,"%d %d",myDet->getMaxNumberOfChannelsPerDetector(X),myDet->getMaxNumberOfChannelsPerDetector(Y));
sprintf(temp,"%d",myDet->getMaxNumberOfChannelsPerDetector(Y)); return string(ans);
strcat(ans," "); }
strcat(ans,temp); else if(cmd=="flippeddatax"){
myDet->setReceiverOnline(ONLINE_FLAG);
sprintf(ans,"%d",myDet->getFlippedData(X));
return string(ans);
}
else if(cmd=="flippeddatay"){
return string("Not required for this detector\n");
myDet->setReceiverOnline(ONLINE_FLAG);
sprintf(ans,"%d",myDet->getFlippedData(Y));
return string(ans); return string(ans);
} }
else else
@ -3214,6 +3259,8 @@ string slsDetectorCommand::helpDetectorSize(int narg, char *args[], int action)
os << "dr i \n sets the dynamic range of the detector"<< std::endl; os << "dr i \n sets the dynamic range of the detector"<< std::endl;
os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois"<< std::endl; os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois"<< std::endl;
os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl; os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl;
os << "flippeddatax x \n sets if the data should be flipped on the x axis"<< std::endl;
os << "flippeddatay y \n sets if the data should be flipped on the y axis"<< std::endl;
} }
if (action==GET_ACTION || action==HELP_ACTION) { if (action==GET_ACTION || action==HELP_ACTION) {
os << "nmod \n gets the number of modules of the detector"<< std::endl; os << "nmod \n gets the number of modules of the detector"<< std::endl;
@ -3221,7 +3268,8 @@ string slsDetectorCommand::helpDetectorSize(int narg, char *args[], int action)
os << "dr \n gets the dynamic range of the detector"<< std::endl; os << "dr \n gets the dynamic range of the detector"<< std::endl;
os << "roi \n gets region of interest"<< std::endl; os << "roi \n gets region of interest"<< std::endl;
os << "detsizechan \n gets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl; os << "detsizechan \n gets the maximum number of channels for complete detector set in both directions; -1 is no limit"<< std::endl;
os << "flippeddatax\n gets if the data will be flipped on the x axis respectively"<< std::endl;
os << "flippeddatay\n gets if the data will be flipped on the y axis respectively"<< std::endl;
} }
return os.str(); return os.str();
@ -3422,6 +3470,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) {
} }
if (cmd=="receiverversion") { if (cmd=="receiverversion") {
myDet->setReceiverOnline(ONLINE_FLAG);
sprintf(answer,"%llx",myDet->getId(RECEIVER_VERSION)); sprintf(answer,"%llx",myDet->getId(RECEIVER_VERSION));
return string(answer); return string(answer);
} }
@ -4102,6 +4151,7 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->setTimer(index,t); ret=myDet->setTimer(index,t);
if (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER) if (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER)
@ -4547,10 +4597,12 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action)
} }
return sval; return sval;
} else if (cmd=="rx_printconfig"){ } else if (cmd=="rx_printconfig"){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) if (action==PUT_ACTION)
return string("cannot put"); return string("cannot put");
return string(""+myDet->printReceiverConfiguration()); return string(""+myDet->printReceiverConfiguration());
}else if (cmd=="parameters") { }else if (cmd=="parameters") {
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sval=string(args[1]); sval=string(args[1]);
myDet->retrieveDetectorSetup(sval); myDet->retrieveDetectorSetup(sval);
@ -4560,6 +4612,7 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action)
} }
return sval; return sval;
} else if (cmd=="setup") { } else if (cmd=="setup") {
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sval=string(args[1]); sval=string(args[1]);
myDet->retrieveDetectorSetup(sval,2); myDet->retrieveDetectorSetup(sval,2);
@ -4614,6 +4667,7 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if(cmd=="receiver"){ if(cmd=="receiver"){
if (action==PUT_ACTION) { if (action==PUT_ACTION) {

View File

@ -45,6 +45,7 @@ int slsDetectorUtils::acquire(int delflag){
struct timespec begin,end; struct timespec begin,end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
//ensure acquire isnt started multiple times by same client //ensure acquire isnt started multiple times by same client
if(getAcquiringFlag() == false) if(getAcquiringFlag() == false)
setAcquiringFlag(true); setAcquiringFlag(true);
@ -53,6 +54,10 @@ int slsDetectorUtils::acquire(int delflag){
return FAIL; return FAIL;
} }
//not in the loop for real time acqusition yet,
//in the real time acquisition loop, processing thread will wait for a post each time
sem_init(&sem_newRTAcquisition,1,0);
bool receiver = (setReceiverOnline()==ONLINE_FLAG); bool receiver = (setReceiverOnline()==ONLINE_FLAG);
if(!receiver){ if(!receiver){
@ -220,6 +225,10 @@ int slsDetectorUtils::acquire(int delflag){
ResetPositionIndex(); ResetPositionIndex();
for (int ip=0; ip<np; ip++) { for (int ip=0; ip<np; ip++) {
//let processing thread listen to these packets
sem_post(&sem_newRTAcquisition);
// cout << "positions " << endl; // cout << "positions " << endl;
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
if (getNumberOfPositions()>0) { if (getNumberOfPositions()>0) {
@ -286,12 +295,7 @@ int slsDetectorUtils::acquire(int delflag){
//send receiver file name //send receiver file name
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileName(fileIO::getFileName()); setFileName(fileIO::getFileName());
if(setReceiverOnline()==OFFLINE_FLAG){
stopReceiver();
*stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
//start receiver //start receiver
if(startReceiver() == FAIL) { if(startReceiver() == FAIL) {
cout << "Start receiver failed " << endl; cout << "Start receiver failed " << endl;
@ -353,9 +357,15 @@ int slsDetectorUtils::acquire(int delflag){
} }
//online //online
else{ else{
cout << "Stopping receiver " << endl;;
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){
stopAcquisition();
stopReceiver();
pthread_mutex_unlock(&mg);
break;
}
stopReceiver(); stopReceiver();
cout<<"***********receiver stopped"<<endl; // cout<<"***********receiver stopped"<<endl;
} }
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
@ -467,12 +477,17 @@ int slsDetectorUtils::acquire(int delflag){
} }
// waiting for the data processing thread to finish! // waiting for the data processing thread to finish!
if (*threadedProcessing) { if (*threadedProcessing) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "wait for data processing thread" << endl; cout << "wait for data processing thread" << endl;
#endif #endif
setJoinThread(1); setJoinThread(1);
//let processing thread continue and checkjointhread
sem_post(&sem_newRTAcquisition);
pthread_join(dataProcessingThread, &status); pthread_join(dataProcessingThread, &status);
#ifdef VERBOSE #ifdef VERBOSE
cout << "data processing thread joined" << endl; cout << "data processing thread joined" << endl;
@ -504,6 +519,7 @@ int slsDetectorUtils::acquire(int delflag){
#endif #endif
setAcquiringFlag(false); setAcquiringFlag(false);
sem_destroy(&sem_newRTAcquisition);
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl; cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl;

View File

@ -70,6 +70,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual int setMaxNumberOfChannelsPerDetector(dimension d,int i){return -1;}; virtual int setMaxNumberOfChannelsPerDetector(dimension d,int i){return -1;};
/** sets the enable which determines if data will be flipped across x or y axis
* \param d axis across which data is flipped
* \param value 0 or 1 to reset/set or -1 to get value
* \return enable flipped data across x or y axis
*/
virtual int setFlippedData(dimension d=X, int value=-1)=0;
//int setPositions(int nPos, double *pos){return angularConversion::setPositions(nPos, pos);}; //int setPositions(int nPos, double *pos){return angularConversion::setPositions(nPos, pos);};
// int getPositions(double *pos=NULL){return angularConversion::getPositions(pos);}; // int getPositions(double *pos=NULL){return angularConversion::getPositions(pos);};
@ -425,6 +432,12 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual int getMaxNumberOfChannels()=0; virtual int getMaxNumberOfChannels()=0;
virtual int getMaxNumberOfChannels(dimension d)=0; virtual int getMaxNumberOfChannels(dimension d)=0;
/** returns the enable if data will be flipped across x or y axis
* \param d axis across which data is flipped
* returns 1 or 0
*/
virtual int getFlippedData(dimension d=X)=0;
// virtual int getParameters(); // virtual int getParameters();
@ -656,17 +669,18 @@ virtual int getReceiverCurrentFrameIndex()=0;
virtual int resetFramesCaught()=0; virtual int resetFramesCaught()=0;
/** /**
* Create Receiving Data Threads * Create Receiving Data Sockets
* @param destroy is true to destroy all the threads * @param destroy is true to destroy all the sockets
* @return OK or FAIL * @return OK or FAIL
*/ */
virtual int createReceivingDataThreads(bool destroy = false)=0; virtual int createReceivingDataSockets(const bool destroy = false){return -1;};
/** Reads frames from receiver through a constant socket /** Reads frames from receiver through a constant socket
*/ */
//virtual void readFrameFromReceiver()=0;
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0; virtual void readFrameFromReceiver(){};
/** /**
Turns off the receiver server! Turns off the receiver server!
*/ */
@ -865,12 +879,10 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
int (*acquisition_finished)(double,int,void*); int (*acquisition_finished)(double,int,void*);
int (*measurement_finished)(int,int,void*); int (*measurement_finished)(int,int,void*);
void *acqFinished_p, *measFinished_p; void *acqFinished_p, *measFinished_p;
int (*progress_call)(double,void*); int (*progress_call)(double,void*);
void *pProgressCallArg; void *pProgressCallArg;
sem_t sem_newRTAcquisition;
}; };

View File

@ -524,14 +524,16 @@ void* postProcessing::processData(int delflag) {
// } // }
// ifp=kbhit();
// if (ifp!=0){ ifp=kbhit();
// c=fgetc(stdin); if (ifp!=0){
// if (c=='q') { c=fgetc(stdin);
// cout<<"gonna stop"<<endl; if (c=='q') {
// stopAcquisition(); cout<<"Caught the command to stop acquisition"<<endl;
// } stopAcquisition();
// } }
}
// //get progress // //get progress

View File

@ -1258,21 +1258,23 @@ int set_dac(int file_des) {
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]); printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
#endif #endif
if(ret == OK){ //takes time to set high voltage, so no check for it
if(ret == OK && ind != HV_POT && ind != HV_NEW){
if(mV) if(mV)
temp = retval[1]; temp = retval[1];
else else
temp = retval[0]; temp = retval[0];
if ((abs(temp-val)<=5) || val==-1) { if ((abs(temp-val)<=5) || val==-1) {
ret=OK; ret=OK;
if (differentClients)
ret=FORCE_UPDATE;
} else { } else {
ret=FAIL; ret=FAIL;
printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp); printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp);
} }
} }
if(ret == OK && differentClients)
ret=FORCE_UPDATE;
/* send answer */ /* send answer */
/* send OK/failed */ /* send OK/failed */