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

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

View File

@ -45,7 +45,7 @@ struct BebInfo{
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);
int Beb_SetMasterViaSoftware();

View File

@ -61,6 +61,7 @@ int Feb_Control_current_index;
int Feb_Control_counter_bit = 1;
int Feb_control_master = 0;
int Feb_control_normal = 0;
unsigned int Feb_Control_rate_correction_table[1024];
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;
Feb_Control_module_number = 0;
Feb_Control_current_index = 0;
Feb_control_master = master;
Feb_control_normal = normal;
//global send
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){
return Feb_Control_SetHighVoltage1(Feb_Control_module_number,value);
}
//only master gets to call this function
int Feb_Control_SetHighVoltage(int value){
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
unsigned int module_index=0;
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);
if(!Feb_control_normal){
cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n");
return 0;
}
}else
return 0;
if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0;
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");;
printf(" Setting High Voltage: %d(v)\t",value);
static const unsigned int nsteps = 256;
static const float vmin=0;
static const float vmax=300;
unsigned int dacval = 0;
unsigned int b = 0;
if(!Feb_Control_VoltageToDAC(*value,&b,nsteps,vmin,vmax)){
printf("Waring: SetHighVoltage bad value, %f. The range is 0 to 300 V.\n",*value);
//open file
FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/out0_output","w");
if(fd==NULL){
cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n");
return 0;
}
unsigned int r = 0x20000000 | (b&0xff);
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);
//calculate dac value
if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vmax)){
cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to 300 V.\n",value);
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;
}
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){
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);
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);
@ -112,15 +111,14 @@ int Feb_Control_GetModuleNumber();
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();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(float value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
int Feb_Control_SetHighVoltage(int value);
int Feb_Control_GetHighVoltage(int* value);
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);

View File

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

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/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
Repsitory UUID: 279965f286cc6364dec8bf7e2a837214d11bb296
Revision: 258
Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 263
Branch: developer
Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 358
Last Changed Date: 2016-11-03 12:31:34 +0100
Last Changed Rev: 1313
Last Changed Date: 2016-11-30 10:36:34 +0100

View File

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

View File

@ -78,6 +78,7 @@ int default_offset_values[3] = {3851000,3851000,3851000};
enum masterFlags masterMode=IS_SLAVE;
int top = 0;
int master = 0;
int normal = 0;
#define TEN_GIGA_BUFFER_SIZE 4112
@ -142,7 +143,7 @@ int initDetector(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber());
Feb_Control_Init(master,top,normal, getDetectorNumber());
printf("FEB Initialization done\n");
Beb_Beb();
printf("BEB Initialization done\n");
@ -184,7 +185,7 @@ int initDetectorStop(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber());
Feb_Control_Init(master,top,normal,getDetectorNumber());
printf("FEB Initialization done\n");
/* Beb_Beb(-1);
printf("BEB constructor done\n");*/
@ -198,15 +199,18 @@ int initDetectorStop(){
void getModuleConfiguration(){
int *m=&master;
int *t=&top;
int *n=&normal;
/*if(getDetectorNumber() == 0xbeb015){
master = 1;
top = 1;
}*/
Beb_GetModuleCopnfiguration(m,t);
Beb_GetModuleConfiguration(m,t,n);
if(top) printf("*************** TOP ***************\n");
else printf("*************** BOTTOM ***************\n");
if(master) printf("*************** MASTER ***************\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){
if(val!=-1){
printf(" Setting High Voltage: %d\n",val);
if(!master)
eiger_highvoltage = val;
else if(Feb_Control_SetHighVoltage(val))
eiger_highvoltage = val;
if(master)
Feb_Control_SetHighVoltage(val);
}
if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){
cprintf(RED,"Warning: Could not read high voltage\n");
return 0;
}
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 header_number = 0;
int dst_port = udpport;
if(!top)
dst_port = udpport2;
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;
dst_port = udpport2;
if(!top)
dst_port = udpport;
printf("dst_port:%d\n\n",dst_port);
/*for(i=0;i<32;i++){*//** modified for Aldo*/

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware
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
Repsitory UUID: a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc
Revision: 1297
Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 1313
Branch: developer
Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 1297
Last Changed Date: 2016-11-08 15:25:56 +0100
Last Changed Rev: 1313
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 ipPacketSize=DEFAULT_IP_PACKETSIZE;
int udpPacketSize=DEFAULT_UDP_PACKETSIZE;
int clockdivider = 20;
int clockdivider_exptime = 40;
int clockdivider_fc = 20;
/*
#ifndef NEW_PLL_RECONFIG
u_int32_t clkDivider[2]={32,16};
@ -496,7 +497,7 @@ void configurePll(int i) {
#endif
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;
h=l;
if (tot>2*l) {
@ -1221,15 +1222,15 @@ int64_t getFrames(){
int64_t setExposureTime(int64_t value){
if (value!=-1){
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);
return retval;
}
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){
@ -1248,31 +1249,31 @@ int64_t getGates(){
int64_t setPeriod(int64_t value){
if (value!=-1){
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);
return retval;
}
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){
if (value!=-1){
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);
return retval;
}
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){

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/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
Repsitory UUID: 69e9e77d6b5517bc932f2ff4d54386d886ef6c39
Revision: 53
Repsitory UUID: 230d6b36e9852214f4ba5ae7c92647f35000b24d
Revision: 56
Branch: developer
Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 1296
Last Changed Date: 2016-11-08 15:25:16 +0100
Last Changed Rev: 1313
Last Changed Date: 2016-11-30 10:36:34 +0100

View File

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

View File

@ -251,7 +251,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
#ifdef VERBOSE
cout << thisMultiDetector->detectorIds[i] << endl;
#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);
@ -268,7 +268,12 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
getNMods();
getMaxMods();
threadStarted = false;
dataSocketsStarted = false;
for(int i=0;i<MAXDET;++i){
context[i] = NULL;
zmqsocket[i] = NULL;
strcpy(dataSocketServerDetails[i],"");
}
threadpool = 0;
if(createThreadPool() == FAIL)
exit(-1);
@ -367,7 +372,7 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
cout << "Creating new detector " << pos << endl;
#endif
detectors[pos]=new slsDetector(id, this);
detectors[pos]=new slsDetector(pos, id, this);
thisMultiDetector->detectorIds[pos]=detectors[pos]->getDetectorId();
thisMultiDetector->numberOfDetectors++;
@ -682,7 +687,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
#ifdef VERBOSE
cout << "Detector " << id << " already exists" << endl;
#endif
s=new slsDetector(id, this);
s=new slsDetector(pos, id, this);
if (s->getHostname()==string(name))
break;
delete s;
@ -723,7 +728,7 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
#ifdef VERBOSE
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
#endif
s=new slsDetector(t, id, this);
s=new slsDetector(pos, t, id, this);
if (online) {
s->setTCPSocket(name);
setOnline(ONLINE_FLAG);
@ -756,7 +761,7 @@ int multiSlsDetector::addSlsDetector(detectorType t, int pos) {
#ifdef VERBOSE
cout << "Creating detector " << id << " of type " << getDetectorType(t) << endl;
#endif
slsDetector *s=new slsDetector(t, id, this);
slsDetector *s=new slsDetector(pos, t, id, this);
s=NULL;
#ifdef VERBOSE
cout << "Adding it to the multi detector structure" << endl;
@ -1415,20 +1420,28 @@ int multiSlsDetector::startReadOut(){
int* multiSlsDetector::getDataFromDetector() {
int nel=thisMultiDetector->dataBytes/sizeof(int);
int n;
int* retval=new int[nel];
int n = 0;
int* retval= NULL;
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;
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (detectors[id]) {
retdet=detectors[id]->getDataFromDetector(p);
n=detectors[id]->getDataBytes();
if(detectors[id]->getErrorMask())
setErrorMask(getErrorMask()|(1<<id));
if(!nodatadetectortype){
n=detectors[id]->getDataBytes();
if (retdet) {
nodata=0;
#ifdef VERBOSE
@ -1439,17 +1452,14 @@ int* multiSlsDetector::getDataFromDetector() {
#ifdef VERBOSE
cout << "Detector " << id << " does not have data left " << endl;
#endif
/*if((detectors[id]->getDetectorsType() != EIGER)||(detectors[id]->getDetectorsType() != JUNGFRAU))
break;*/
}
p+=n/sizeof(int);
}
}
}
//eiger returns only null
detectorType types = getDetectorsType();
if(types == EIGER || types == JUNGFRAU){
delete [] retval;
if(nodatadetectortype){
return NULL;
}
@ -2280,6 +2290,7 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
}
}
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 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) {
#ifdef VERBOSE
cout << " Module " << i << " belongs to detector " << id << endl;;
@ -4331,6 +4374,7 @@ int multiSlsDetector::readConfigurationFile(string const fname){
// char ext[100];
setAcquiringFlag(false);
clearAllErrorMask();
string ans;
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;
if(getDetectorsType() == EIGER)
numReadouts *= 2;
//number of sockets
int numSockets = thisMultiDetector->numberOfDetectors;
int numSocketsPerDetector = 1;
if(getDetectorsType() == EIGER){
numSocketsPerDetector = 2;
}
numSockets *= numSocketsPerDetector;
//reset masks
killAllReceivingDataThreads = false;
//destroy
if(destroy){
#ifdef DEBUG
cout << "Destroying Receiving Data Thread(s)" << endl;
#endif
killAllReceivingDataThreads = true;
for(int i = 0; i < numReadouts; ++i){
sem_post(&sem_singlewait[i]);
pthread_join(receivingDataThreads[i],NULL);
sem_destroy(&sem_singlewait[i]);
sem_destroy(&sem_singledone[i]);
#ifdef DEBUG
cout << "." << flush << endl;
#endif
cprintf(MAGENTA,"Going to destroy data sockets\n");
//close socket
for(int i=0;i<numSockets; ++i){
if(strlen(dataSocketServerDetails[i])){
zmq_disconnect(zmqsocket[i], dataSocketServerDetails[i]);
zmq_close(zmqsocket[i]);
zmq_ctx_destroy(context[i]);
context[i] = NULL;
zmqsocket[i] = NULL;
strcpy(dataSocketServerDetails[i],"");
}
killAllReceivingDataThreads = false;
threadStarted = false;
cout << "Destroyed Receiving Data Thread(s)" << endl;
}
//create
else{
#ifdef DEBUG
cout << "Creating Receiving Data Thread(s)" << endl;
#endif
//reset current index
currentThreadIndex = -1;
for(int i = 0; i < numReadouts; ++i){
sem_init(&sem_singlewait[i],1,0);
sem_init(&sem_singledone[i],1,0);
threadStarted = false;
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;
}
dataSocketsStarted = false;
cout << "Destroyed Receiving Data Socket(s)" << endl;
return OK;
}
cprintf(MAGENTA,"Going to create data sockets\n");
void* multiSlsDetector::staticstartReceivingDataThread(void* this_pointer){
((multiSlsDetector*)this_pointer)->startReceivingDataThread();
//while(true);
return this_pointer;
}
void multiSlsDetector::startReceivingDataThread(){
int ithread = currentThreadIndex; //set current thread value index
char hostname[100] = "tcp://";
for(int i=0;i<numSockets; ++i){
//get name of rx_hostname
char rx_hostname[100];
strcpy(rx_hostname, detectors[ithread]->getReceiver());
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(hostname,rx_hostname);
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(hostname,inet_ntoa(*(struct in_addr*)he->h_addr));
strcat(dataSocketServerDetails[i],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);
//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)
//socket details
zmq_msg_t message;
void *context;
void *zmqsocket;
context = zmq_ctx_new();
zmqsocket = zmq_socket(context, ZMQ_PULL);
//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,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;
int expectedsize = 1024*256;/**shouldnt work for other bit modes or anythign*/
if(getDetectorsType() == EIGER){
numReadoutPerDetector = 2;
expectedsize = 1024*256;
}else if(getDetectorsType() == JUNGFRAU){
jungfrau = true;
expectedsize = 8192*128;
//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 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
//infinite loop, exited only (if gui restarted/ enabledatastreaming called)
while(true){
sem_wait(&sem_singlewait[ithread]); //wait for it to be copied
//check to exit thread
if(killAllReceivingDataThreads)
break;
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);
len = zmq_msg_recv(&message, zmqsocket, 0);
int len = zmq_msg_recv(&message, zmqsocket[isocket], 0);
if (len == -1) {
cprintf(BG_RED,"Could not read header for socket %d\n",ithread);
cprintf(BG_RED,"Could not read header for socket %d\n",isocket);
zmq_msg_close(&message);
cprintf(RED, "%d message null\n",ithread);
continue;
cprintf(RED, "%d message null\n",isocket);
return FAIL;
}
// error if you print it
// cout << ithread << " header len:"<<len<<" value:"<< (char*)zmq_msg_data(&message)<<endl;
//cprintf(BLUE,"%d header %d\n",ithread,len);
// 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 << ithread << "htype: " << htype[i].GetString() << std::endl;
std::cout << isocket << "htype: " << htype[i].GetString() << std::endl;
// shape is an array of ints
rapidjson::Value::Array shape = d["shape"].GetArray();
cout << ithread << "shape: ";
cout << isocket << "shape: ";
for(int i=0; i< shape.Size(); i++)
cout << ithread << shape[i].GetInt() << " ";
cout << isocket << shape[i].GetInt() << " ";
cout << endl;
cout << ithread << "type: " << d["type"].GetString() << endl;
cout << isocket << "type: " << d["type"].GetString() << endl;
#endif
if(!ithread && (d["acqIndex"].GetInt()!=-9)){
currentAcquisitionIndex = d["acqIndex"].GetInt();
currentFrameIndex = d["fIndex"].GetInt();
currentSubFrameIndex = d["subfnum"].GetInt();
currentFileName = d["fname"].GetString();
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: " << currentAcquisitionIndex << endl;
cout << "Frame index: " << currentFrameIndex << endl;
cout << "Subframe index: " << currentSubFrameIndex << endl;
cout << "File name: " << currentFileName << endl;
cout << "Acquisition index: " << acqIndex << endl;
cout << "Frame index: " << frameIndex << endl;
cout << "Subframe index: " << subframeIndex << endl;
cout << "File name: " << filename << endl;
#endif
if(currentFrameIndex ==-1) cprintf(RED,"multi frame index -1!!\n");
if(frameIndex ==-1) cprintf(RED,"multi frame index -1!!\n");
}
singleframe[ithread]=image;
// close the message
zmq_msg_close(&message);
//scan data-------------------------------------------------------------------
zmq_msg_init (&message);
len = zmq_msg_recv(&message, zmqsocket, 0);
len = zmq_msg_recv(&message, zmqsocket[isocket], 0);
//cprintf(BLUE,"%d data %d\n",isocket,len);
//cprintf(BLUE,"%d data %d\n",ithread,len);
//end of socket ("end")
if (len < expectedsize ) {
if(len == 3){
//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);
//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{
//actual data
//cprintf(BLUE,"%d actual dataaa\n",ithread);
memcpy((char*)(singleframe[ithread]),(char*)zmq_msg_data(&message),singleDatabytes/numReadoutPerDetector);
//cprintf(BLUE,"%d actual dataaa\n",isocket);
memcpy((char*)image,(char*)zmq_msg_data(&message),size);
//jungfrau masking adcval
if(jungfrau){
for(unsigned int i=0;i<nel;i++){
singleframe[ithread][i] = (singleframe[ithread][i] & 0x3FFF3FFF);
if(masking){
int snel = size/sizeof(int);
for(unsigned int i=0;i<snel;++i){
image[i] = (image[i] & 0x3FFF3FFF);
}
}
}
sem_post(&sem_singledone[ithread]);//let multi know is ready
zmq_msg_close(&message); // close the message
return OK;
}
cprintf(RED,"%d Closing socket\n",ithread);
//close socket
zmq_disconnect(zmqsocket, hostname);
zmq_close(zmqsocket);
zmq_ctx_destroy(context);
void multiSlsDetector::readFrameFromReceiver(){
//determine number of half readouts and maxX and maxY
int maxX=0,maxY=0;
int numSockets = thisMultiDetector->numberOfDetectors;
int numSocketsPerSLSDetector = 1;
bool jungfrau = false;
switch(getDetectorsType()){
case EIGER:
numSocketsPerSLSDetector = 2;
numSockets *= numSocketsPerSLSDetector;
maxX = thisMultiDetector->numberOfChannel[X];
maxY = thisMultiDetector->numberOfChannel[Y];
break;
case JUNGFRAU:
jungfrau = true;
break;
default:
break;
}
//gui variables
int currentAcquisitionIndex = -1;
int currentFrameIndex = -1;
int currentSubFrameIndex = -1;
string currentFileName = "";
//getting sls values
int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0, nx=0, ny=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);
}
//getting multi values
nx = getTotalNumberOfChannels(slsDetectorDefs::X);
ny = getTotalNumberOfChannels(slsDetectorDefs::Y);
//calculating offsets (for eiger interleaving ports)
int offsetX[numSockets]; int offsetY[numSockets];
int bottom[numSockets];
if(maxX){
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]();
volatile uint64_t dataThreadMask = 0x0;
//wait for real time acquisition to start
bool running = true;
sem_wait(&sem_newRTAcquisition);
if(checkJoinThread())
running = false;
for(int i = 0; i < numSockets; ++i)
dataThreadMask|=(1<<i);
//exit when last message for each socket received
while(running){
//memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
//get each frame
for(int isocket=0; isocket<numSockets; ++isocket){
//if running
if((1 << isocket) & dataThreadMask){
//get individual images
if(FAIL == getData(isocket, jungfrau, image, expectedslssize, currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex,currentFileName)){
dataThreadMask^=(1<<isocket);
continue;
}
//assemble data with interleaving
if(maxX){
//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);
}
}
}
//assemble data with no interleaving, assumed detectors appended vertically
else{
memcpy((char*)multiframe+slsdatabytes*isocket,(char*)image,slsdatabytes);
}
}
}
//all done
if(!dataThreadMask){
sem_wait(&sem_newRTAcquisition);
//done with complete acquisition
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
delete [] image;
#ifdef DEBUG
cprintf(MAGENTA,"Receiving Data Thread %d:Goodbye!\n",ithread);
#endif
delete[] multiframe;
}
// 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 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
int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
if(enable >= 0){
if(threadStarted != enable){
if(dataSocketsStarted != enable){
//destroy data threads
if(threadStarted)
createReceivingDataThreads(true);
if(dataSocketsStarted)
createReceivingDataSockets(true);
//create data threads
if(enable > 0){
if(createReceivingDataThreads() == FAIL){
std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl;
if(createReceivingDataSockets() == FAIL){
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
setErrorMask(getErrorMask()|(1<<0));
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;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
@ -5725,9 +5695,9 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
}
/*
if(enable == -1)
return threadStarted;
return dataSocketsStarted;
*/
return (threadStarted & ret);
return (dataSocketsStarted & ret);
}
int multiSlsDetector::enableReceiverCompression(int i){

View File

@ -340,6 +340,12 @@ class multiSlsDetector : public slsDetectorUtils {
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];};
double getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];};
@ -979,6 +985,14 @@ class multiSlsDetector : public slsDetectorUtils {
int configureMAC();
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 setDynamicRange(int i=-1);
@ -1196,18 +1210,17 @@ class multiSlsDetector : public slsDetectorUtils {
int resetFramesCaught();
/**
* Create Receiving Data Threads
* @param destroy is true to destroy all the threads
* Create Receiving Data Sockets
* @param destroy is true to destroy all the sockets
* @return OK or FAIL
*/
int createReceivingDataThreads(bool destroy = false);
int createReceivingDataSockets(const bool destroy = false);
/** Reads frames from receiver through a constant socket
*/
//void readFrameFromReceiver();
int* readFrameFromReceiver(char*, int&, int&, int&);
void readFrameFromReceiver();
/** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver
@ -1276,6 +1289,14 @@ class multiSlsDetector : public slsDetectorUtils {
*/
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
* @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming
@ -1384,35 +1405,17 @@ class multiSlsDetector : public slsDetectorUtils {
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 */
sem_t sem_singledone[MAXDET];
sem_t sem_singlewait[MAXDET];
int* singleframe[MAXDET];
/* 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;
/** Ensures if sockets created successfully */
bool dataSocketsStarted;
void *context[MAXDET];
void *zmqsocket[MAXDET];
char dataSocketServerDetails[MAXDET][100];
protected:

View File

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

View File

@ -156,9 +156,10 @@ int slsDetector::freeSharedMemory() {
slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(),
slsDetector::slsDetector(int pos, int id, multiSlsDetector *p) :slsDetectorUtils(),
thisDetector(NULL),
detId(id),
posId(pos),
parentDet(p),
shmId(-1),
controlSocket(NULL),
@ -208,9 +209,10 @@ slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(),
slsDetector::slsDetector(detectorType type, int id,multiSlsDetector *p): slsDetectorUtils(),
slsDetector::slsDetector(int pos, detectorType type, int id, multiSlsDetector *p): slsDetectorUtils(),
thisDetector(NULL),
detId(id),
posId(pos),
parentDet(p),
shmId(-1),
controlSocket(NULL),
@ -265,9 +267,10 @@ slsDetector::~slsDetector(){
delete thisReceiver;
};
slsDetector::slsDetector(char *name, int id, int cport,multiSlsDetector *p) : slsDetectorUtils(),
slsDetector::slsDetector(int pos, char *name, int id, int cport,multiSlsDetector *p) : slsDetectorUtils(),
thisDetector(NULL),
detId(id),
posId(pos),
parentDet(p),
shmId(-1),
controlSocket(NULL),
@ -761,6 +764,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->tenGigaEnable=0;
thisDetector->acquiringFlag = false;
thisDetector->flippedData[0] = 0;
thisDetector->flippedData[1] = 0;
for (int ia=0; ia<MAX_ACTIONS; ia++) {
strcpy(thisDetector->actionScript[ia],"none");
@ -1327,13 +1332,14 @@ int slsDetector::activate(int const enable){
#endif
if(ret!=FAIL){
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Activating/Deactivating Receiver: " << retval << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,retval);
disconnectData();
}
if(ret==FAIL)
setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE));
}
@ -1638,15 +1644,16 @@ int slsDetector::setDetectorType(detectorType const type){
//receiver
if((retType != GENERIC) && (setReceiverOnline()==ONLINE_FLAG)) {
if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG)) {
retval = FAIL;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending detector type to Receiver " << (int)thisDetector->myDetectorType << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType);
disconnectData();
}
if(retval==FAIL){
cout << "ERROR: Could not send detector type to receiver" << endl;
setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET));
@ -1880,6 +1887,57 @@ int slsDetector::getMaxNumberOfModules(dimension d){
int slsDetector::setFlippedData(dimension d, int value){
int retval=-1;
int fnum=F_SET_FLIPPED_DATA_RECEIVER;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
int args[2]={X,-1};
if(thisDetector->myDetectorType!= EIGER){
std::cout << "Flipped Data is not implemented in this detector" << std::endl;
setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET));
return -1;
}
#ifdef VERBOSE
std::cout << std::endl;
std::cout << "Setting/Getting flipped data across axis " << d <<" with value " << value << std::endl;
#endif
if(value > -1){
thisDetector->flippedData[d] = value;
args[1] = value;
}else
args[1] = thisDetector->flippedData[d];
args[0] = d;
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
if (connectData() == OK){
ret=thisReceiver->sendIntArray(fnum,retval,args);
disconnectData();
}
if((args[1] != retval && args[1]>=0) || (ret==FAIL)){
ret = FAIL;
setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET));
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
return thisDetector->flippedData[d];
}
/*
This function is used to set the polarity and meaning of the digital I/O signals (signal index)
@ -2051,10 +2109,11 @@ int64_t slsDetector::getId( idMode mode, int imod){
retval=SVNREVLIB;
retval=(retval<<32) | SVNDATELIB;
} else if (mode==RECEIVER_VERSION) {
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectData() == OK)
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
if (connectData() == OK){
ret=thisReceiver->getInt(fnum2,retval);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
}
@ -3824,24 +3883,26 @@ int* slsDetector::readFrame(){
int* slsDetector::getDataFromDetector(int *retval){
int nel=thisDetector->dataBytes/sizeof(int);
int n;
int *r=retval;
// int* retval=new int[nel];
if (retval==NULL) {
retval=new int[nel];
// cout << "*****"<<endl;
} //else cout <<"----"<< retval <<endl;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="Nothing";
int nel=thisDetector->dataBytes/sizeof(int);
int n;
int *r=retval;
//#ifdef VERBOSE
int nodatadetectortype = false;
detectorType types = getDetectorsType();
if(types == EIGER || types == JUNGFRAU){
nodatadetectortype = true;
}
if (!nodatadetectortype && retval==NULL)
retval=new int[nel];
#ifdef VERBOSE
std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl;
//#endif
#endif
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
#ifdef VERBOSE
cout << "ret=" << ret << endl;
@ -3859,11 +3920,12 @@ int* slsDetector::getDataFromDetector(int *retval){
std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl;
#endif
}
if (r==NULL) {
if ((!nodatadetectortype) && (r==NULL)){
delete [] retval;
}
return NULL;
} else {
} else if (!nodatadetectortype){
n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
//#ifdef VERBOSE
@ -4152,55 +4214,56 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//send acquisiton period/frame number to receiver
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)||(index==ACQUISITION_TIME)){
if(ret != FAIL){
int64_t args[2];
retval = -1;
args[0] = index;
args[1] = thisDetector->timerValue[index];
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
//set #frames, #cycles
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
#ifdef VERBOSE
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
std::cout << "Setting/Getting number of frames*cycles " << index <<" to/from receiver " << args[1] << std::endl;
#endif
if(thisDetector->timerValue[CYCLES_NUMBER]==0)
args[1] = thisDetector->timerValue[FRAME_NUMBER];
else
args[1] = thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER];
}
//set period
//set period/exptime
else{
#ifdef VERBOSE
if(index==ACQUISITION_TIME)
std::cout << "Setting/Getting acquisition time " << index << " to/from receiver " << args[1] << std::endl;
else
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
#endif
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
if(!args[1])
args[1] = timerValue[ACQUISITION_TIME];
}
char mess[MAX_STR_LENGTH]="";
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendIntArray(fnum2,retval,args,mess);
disconnectData();
}
if((args[1] != retval)|| (ret==FAIL)){
ret = FAIL;
if(index==FRAME_PERIOD){
//exptime sent if acq period = 0
if(retval){
if(index==ACQUISITION_TIME){
if(strstr(mess,"receiver not idle")==NULL)
cout << "ERROR:Acquisition Time in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET));
}else if(index==FRAME_PERIOD){
if(strstr(mess,"receiver not idle")==NULL)
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
}
}else{
if(strstr(mess,"receiver not idle")==NULL)
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
}
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
@ -4722,13 +4785,14 @@ int slsDetector::setDynamicRange(int n){
if(ret != FAIL){
retval = thisDetector->dynamicRange;
if((n==-1) && (ret!= FORCE_UPDATE)) n =-1;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending/Getting dynamic range to/from receiver " << n << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum2,retval1,n);
disconnectData();
}
if ((ret==FAIL) || (retval1 != retval)){
ret = FAIL;
cout << "ERROR:Dynamic range in receiver set incorrectly to " << retval1 << " instead of " << retval << endl;
@ -4964,12 +5028,12 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
double *dataout;
if (fdata) {
dataout=fdata;
// printf("not allocating fdata!\n");
}
else {
} else {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
dataout=new double[thisDetector->dataBytes/2];
nn=thisDetector->dataBytes/2;
@ -4992,22 +5056,13 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
// cout << "nch " << nch << endl;
for (ichan=0; ichan<thisDetector->dataBytes/2; ichan++) {
// // dataout[ichan]=0;
// ival=0;
// // for (ibyte=0; ibyte<2; ibyte++) {
// ibyte=0;
// iptr=ptr[ichan*2+ibyte];
// ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
// ibyte=1;
// iptr=ptr[ichan*2+ibyte];
// ival|=((iptr<<(ibyte*bytesize))&(0x3f<<(ibyte*bytesize)));
for (ichan=0; ichan<thisDetector->dataBytes/2; ichan++) {
// // }
dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
}
} else {
switch (nbits) {
case 1:
@ -5050,11 +5105,16 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
}
break;
default:
if(thisDetector->myDetectorType == MYTHEN){
for (ichan=0; ichan<nch; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
}
}
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
}
} else {
for (ichan=0; ichan<nch; ichan++) {
@ -5067,7 +5127,6 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
std::cout<< "decoded "<< ichan << " channels" << std::endl;
#endif
return dataout;
}
@ -5255,7 +5314,7 @@ int slsDetector::setRateCorrection(double t){
#ifdef VERBOSE
std::cout<< "Setting Rate Correction to " << arg << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&arg,sizeof(arg));
@ -5337,7 +5396,7 @@ double slsDetector::getRateCorrectionTau(){
#ifdef VERBOSE
std::cout<< "Setting Rate Correction to " << arg << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
@ -5712,9 +5771,12 @@ char* slsDetector::setReceiver(string receiverIP){
setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]);
setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]);
setTimer(ACQUISITION_TIME,thisDetector->timerValue[ACQUISITION_TIME]);
setDynamicRange(thisDetector->dynamicRange);
if(thisDetector->myDetectorType == EIGER)
if(thisDetector->myDetectorType == EIGER){
setFlippedData(X,-1);
activate(-1);
}
//std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl;
//parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1));
//set scan tag
@ -5843,7 +5905,7 @@ int slsDetector::setUDPConnection(){
int ret = FAIL;
int fnum = F_SETUP_RECEIVER_UDP;
char args[3][MAX_STR_LENGTH];
char args[3][MAX_STR_LENGTH]={"","",""};
char retval[MAX_STR_LENGTH]="";
//called before set up
@ -5881,13 +5943,14 @@ int slsDetector::setUDPConnection(){
#endif
//set up receiver for UDP Connection and get receivermac address
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Setting up UDP Connection for Receiver " << args[0] << "\t" << args[1] << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendUDPDetails(fnum,retval,args);
disconnectData();
}
if(ret!=FAIL){
strcpy(thisDetector->receiverUDPMAC,retval);
@ -5918,7 +5981,7 @@ int slsDetector::configureMAC(){
int ret=FAIL;
int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME;
char mess[MAX_STR_LENGTH]="";
char arg[6][50];
char arg[6][50]={"","","","","",""};
char cword[50]="", *pcword;
string sword;
int retval=-1;
@ -6046,18 +6109,17 @@ int slsDetector::configureMAC(){
pthread_mutex_unlock(&ms);
//connect to receiver
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending adc val to receiver " << retval << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum2,retval,retval);
disconnectData();
}
if(ret==FAIL)
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
}
}
}
return ret;
}
@ -6655,7 +6717,7 @@ int slsDetector::programFPGA(string fname){
#ifdef VERBOSE
std::cout<< "Sending programming binary to detector " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&filesize,sizeof(filesize));
@ -6750,7 +6812,7 @@ int slsDetector::resetFPGA(){
#ifdef VERBOSE
std::cout<< "Sending reset to FPGA " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -6786,7 +6848,7 @@ int slsDetector::powerChip(int ival){
#ifdef VERBOSE
std::cout<< "Sending power on/off/get to the chip " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&ival,sizeof(ival));
@ -7160,10 +7222,10 @@ string slsDetector::checkReceiverOnline() {
thisDetector->receiverOnlineFlag=OFFLINE_FLAG;
delete dataSocket;
dataSocket=NULL;
retval = FAIL;
#ifdef VERBOSE
std::cout<< "receiver offline!" << std::endl;
#endif
return string(thisDetector->receiver_hostname);
} else {
thisDetector->receiverOnlineFlag=ONLINE_FLAG;
dataSocket->SetTimeOut(100);
@ -7171,9 +7233,9 @@ string slsDetector::checkReceiverOnline() {
#ifdef VERBOSE
std::cout<< "receiver online!" << std::endl;
#endif
return string("");
}
}
return retval;
}
@ -7252,7 +7314,7 @@ int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port
string slsDetector::setFilePath(string s) {
int fnum = F_SET_RECEIVER_FILE_PATH;
int ret = FAIL;
char arg[MAX_STR_LENGTH];
char arg[MAX_STR_LENGTH]="";
char retval[MAX_STR_LENGTH] = "";
struct stat st;
@ -7269,14 +7331,15 @@ string slsDetector::setFilePath(string s) {
}
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
else{
strcpy(arg,s.c_str());
#ifdef VERBOSE
std::cout << "Sending file path to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendString(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
pthread_mutex_lock(&ms);
fileIO::setFilePath(string(retval));
@ -7302,29 +7365,29 @@ string slsDetector::setFilePath(string s) {
string slsDetector::setFileName(string s) {
int fnum=F_SET_RECEIVER_FILE_NAME;
int ret = FAIL;
char arg[MAX_STR_LENGTH];
char arg[MAX_STR_LENGTH]="";
char retval[MAX_STR_LENGTH]="";
if(!s.empty()){
pthread_mutex_lock(&ms);
fileIO::setFileName(s);
if(thisDetector->myDetectorType == EIGER)
parentDet->setDetectorIndex(detId);
parentDet->setDetectorIndex(posId);
else if(parentDet->getNumberOfDetectors()>1)
parentDet->setDetectorIndex(detId);
parentDet->setDetectorIndex(posId);
s=parentDet->createReceiverFilePrefix();
pthread_mutex_unlock(&ms);
}
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
strcpy(arg,s.c_str());
#ifdef VERBOSE
std::cout << "Sending file name to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendString(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
#ifdef VERBOSE
std::cout << "Complete file prefix from receiver: " << retval << std::endl;
@ -7337,7 +7400,6 @@ string slsDetector::setFileName(string s) {
if(ret==FORCE_UPDATE)
updateReceiver();
}
}
pthread_mutex_lock(&ms);
s = fileIO::getFileName();
@ -7365,13 +7427,14 @@ int slsDetector::setFileIndex(int i) {
}
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
else{
#ifdef VERBOSE
std::cout << "Sending file index to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
pthread_mutex_lock(&ms);
fileIO::setFileIndex(retval);
@ -7392,18 +7455,18 @@ int slsDetector::startReceiver(){
int ret = FAIL;
char mess[MAX_STR_LENGTH] = "";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Starting Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->executeFunction(fnum,mess);
disconnectData();
if(ret==FORCE_UPDATE) {
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
// cout<< "FU"<<endl;
} else if (ret == FAIL){
// cout << mess <<endl;
else if (ret == FAIL){
if(strstr(mess,"UDP")!=NULL)
setErrorMask((getErrorMask())|(COULDNOT_CREATE_UDP_SOCKET));
else if(strstr(mess,"file")!=NULL)
@ -7430,13 +7493,14 @@ int slsDetector::stopReceiver(){
if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU)
detectorSendToReceiver(false);
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Stopping Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->executeFunction(fnum,mess);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
else if (ret == FAIL)
@ -7455,13 +7519,14 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){
int retval=-1;
runStatus s=ERROR;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Starting Receiver Readout" << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->getInt(fnum,retval);
disconnectData();
}
if(retval!=-1)
s=(runStatus)retval;
if(ret==FORCE_UPDATE)
@ -7512,13 +7577,14 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){
int retval=-1;
runStatus s=ERROR;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Getting Receiver Status" << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->getInt(fnum,retval);
disconnectData();
}
if(retval!=-1)
s=(runStatus)retval;
if(ret==FORCE_UPDATE)
@ -7536,13 +7602,14 @@ int slsDetector::getFramesCaughtByReceiver(){
int ret = FAIL;
int retval=-1;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Getting Frames Caught by Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->getInt(fnum,retval);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
}
@ -7557,13 +7624,14 @@ int slsDetector::getReceiverCurrentFrameIndex(){
int ret = FAIL;
int retval=-1;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Getting Current Frame Index of Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->getInt(fnum,retval);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
}
@ -7579,13 +7647,14 @@ int slsDetector::resetFramesCaught(){
int ret = FAIL;
char mess[MAX_STR_LENGTH] = "";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Reset Frames Caught by Receiver" << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->executeFunction(fnum,mess);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
}
@ -7652,13 +7721,14 @@ int slsDetector::lockReceiver(int lock){
int arg=lock;
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Locking or Unlocking Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
@ -7676,13 +7746,14 @@ string slsDetector::getReceiverLastClientIP(){
int ret = FAIL;
char retval[INET_ADDRSTRLEN]="";
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Geting Last Client IP connected to Receiver " << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->getLastClientIP(fnum,retval);
disconnectData();
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
@ -7733,7 +7804,7 @@ int slsDetector::updateReceiver() {
int ret=OK;
char mess[MAX_STR_LENGTH]="";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
if (connectData() == OK){
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
@ -7760,7 +7831,7 @@ int slsDetector::exitReceiver(){
int retval;
int fnum=F_EXIT_RECEIVER;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
if (dataSocket) {
dataSocket->Connect();
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -7796,13 +7867,14 @@ int slsDetector::enableWriteToFile(int enable){
}
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending enable file write to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
pthread_mutex_lock(&ms);
parentDet->enableWriteToFileMask(retval);
@ -7837,13 +7909,14 @@ int slsDetector::overwriteFile(int enable){
}
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending enable file write to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
pthread_mutex_lock(&ms);
parentDet->enableOverwriteMask(retval);
@ -7875,13 +7948,14 @@ int slsDetector::setFrameIndex(int index){
pthread_mutex_unlock(&ms);
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
else if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending frame index to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret!=FAIL){
pthread_mutex_lock(&ms);
fileIO::setFrameIndex(retval);
@ -7954,13 +8028,14 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
if(!getFromReceiver)
return retval;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending read frequency to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret==FAIL)
retval = -1;
if(ret==FORCE_UPDATE)
@ -7976,6 +8051,33 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
int slsDetector::setReceiverReadTimer(int time_in_ms){
int fnum=F_READ_RECEIVER_TIMER;
int ret = FAIL;
int arg = time_in_ms;
int retval = -1;
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending read timer to receiver " << arg << std::endl;
#endif
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
if ((time_in_ms > 0) && (retval != time_in_ms)){
cout << "could not set receiver read timer to " << time_in_ms <<" Returned:" << retval << endl;
setErrorMask((getErrorMask())|(RECEIVER_READ_TIMER));
}
return retval;
}
int slsDetector::enableDataStreamingFromReceiver(int enable){
int fnum=F_STREAM_DATA_FROM_RECEIVER;
int ret = FAIL;
@ -7983,13 +8085,14 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){
int arg = enable;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
}
if(ret==FAIL)
retval = -1;
if(ret==FORCE_UPDATE)
@ -8011,13 +8114,14 @@ int slsDetector::enableReceiverCompression(int i){
int retval=-1;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Getting/Enabling/Disabling Receiver Compression with argument " << i << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,i);
disconnectData();
}
if(ret==FAIL)
setErrorMask((getErrorMask())|(COULDNOT_ENABLE_COMPRESSION));
}
@ -8032,13 +8136,14 @@ void slsDetector::setDetectorHostname(){
char retval[MAX_STR_LENGTH]="";
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname);
disconnectData();
}
if((ret==FAIL) || (strcmp(retval,thisDetector->hostname)))
setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET));
}
@ -8080,13 +8185,14 @@ int slsDetector::enableTenGigabitEthernet(int i){
if(configureMAC() != FAIL){
ret = FAIL;
retval=-1;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Enabling / Disabling 10Gbe in receiver: " << i << std::endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum2,retval,i);
disconnectData();
}
if(ret==FAIL)
setErrorMask((getErrorMask())|(RECEIVER_TEN_GIGA));
}
@ -8107,16 +8213,17 @@ int slsDetector::setReceiverFifoDepth(int i){
int retval=-1;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
if(i ==-1)
std::cout<< "Getting Receiver Fifo Depth" << endl;
else
std::cout<< "Setting Receiver Fifo Depth to " << i << endl;
#endif
if (connectData() == OK)
if (connectData() == OK){
ret=thisReceiver->sendInt(fnum,retval,i);
disconnectData();
}
if(ret==FAIL)
setErrorMask((getErrorMask())|(COULD_NOT_SET_FIFO_DEPTH));
}
@ -8141,7 +8248,7 @@ int slsDetector::setCTBPattern(string fname) {
char retval[MAX_STR_LENGTH]="";
// if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
// if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
// #ifdef VERBOSE
// std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl;
// #endif

View File

@ -267,6 +267,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** flag for acquiring */
bool acquiringFlag;
/** flipped data across x or y axis */
int flippedData[2];
} sharedSlsDetector;
@ -295,20 +297,22 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** (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 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
*/
slsDetector(detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL);
slsDetector(int pos, detectorType type=GENERIC, int id=0, multiSlsDetector *p=NULL);
/** 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 pos is the index of object in the parent multislsdet array
\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(){while(dataQueue.size()>0){}};
/** 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];};
/** 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 */
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
/** 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;};
/**
Receives a data frame from the detector socket
\returns pointer to the data (or NULL if failed)
@ -1596,19 +1613,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
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
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver
@ -1717,6 +1722,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
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
* @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming
@ -1838,6 +1851,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
int detId;
/**
position ID
*/
int posId;
/**
* parent multi detector

View File

@ -432,7 +432,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize;
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 */
@ -1251,12 +1257,13 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if(myDet->acquire() == FAIL)
return string("acquire unsuccessful");
if(myDet->setReceiverOnline()==ONLINE_FLAG){
char answer[100];
sprintf(answer,"\n%d",myDet->getFramesCaughtByReceiver());
sprintf(answer,"\nAcquired %d",myDet->getFramesCaughtByReceiver());
return string(answer);
}
@ -1295,6 +1302,7 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action) {
b=myDet->setThreadedProcessing(-1);
myDet->setThreadedProcessing(0);
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->readAll();
//processdata in receiver is useful only for gui purposes
if(myDet->setReceiverOnline()==OFFLINE_FLAG)
@ -1329,6 +1337,7 @@ string slsDetectorCommand::cmdFrame(int narg, char *args[], int action) {
b=myDet->setThreadedProcessing(-1);
myDet->setThreadedProcessing(0);
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
myDet->readFrame();
//processdata in receiver is useful only for gui purposes
if(myDet->setReceiverOnline()==OFFLINE_FLAG)
@ -1737,6 +1746,7 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action){
return string("Error closing server\n");
}
else if (cmd=="exitreceiver"){
myDet->setReceiverOnline(ONLINE_FLAG);
if(myDet->exitReceiver()!=OK)
return string("Receiver shut down\n");
else
@ -1858,6 +1868,7 @@ string slsDetectorCommand::helpTrimEn(int narg, char *args[], int action) {
string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_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){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION)
return helpFileName(narg, args, action);
if (cmd=="fname") {
@ -1911,7 +1923,7 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){
int i;
char ans[100];
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) {
return helpEnablefwrite(narg, args, action);
}
@ -1943,7 +1955,7 @@ string slsDetectorCommand::cmdOverwrite(int narg, char *args[], int action){
int i;
char ans[100];
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_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){
char ans[100];
int i;
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION) {
return helpFileName(narg, args, action);
}
@ -2088,6 +2100,8 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){
double fval;
char answer[1000];
myDet->setOnline(ONLINE_FLAG);
if (action==PUT_ACTION) {
sscanf(args[1],"%lf",&fval);
myDet->setRateCorrection(fval);
@ -2785,6 +2799,7 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
return helpNetworkParameter(narg,args,action);
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if (cmd=="detectormac") {
t=DETECTOR_MAC;
@ -2954,6 +2969,7 @@ string slsDetectorCommand::cmdLock(int narg, char *args[], int action) {
else if(cmd=="r_lock"){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&val))
myDet->lockReceiver(val);
@ -3004,8 +3020,10 @@ string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action) {
return myDet->getLastClientIP();
}
else if(cmd=="r_lastclient")
else if(cmd=="r_lastclient"){
myDet->setReceiverOnline(ONLINE_FLAG);
return myDet->getReceiverLastClientIP();
}
return string("cannot decode command");
}
@ -3051,6 +3069,7 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
}
else if(cmd=="activate"){
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) {
if (!sscanf(args[1],"%d",&ival))
return string("Could not scan activate mode ")+string(args[1]);
@ -3072,11 +3091,12 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) {
else{
if (action==PUT_ACTION)
return string("cannot set");
myDet->setReceiverOnline(ONLINE_FLAG);
strcpy(ans,myDet->checkReceiverOnline().c_str());
if(!strlen(ans))
strcpy(ans,"All receiver online");
else
strcat(ans," :Not receiver online");
strcat(ans," :Not all receiver online");
}
return ans;
@ -3113,6 +3133,7 @@ string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action) {
if (action==PUT_ACTION){
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->configureMAC();
}
else
@ -3139,7 +3160,7 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
if (action==HELP_ACTION)
return helpDetectorSize(narg,args,action);
int ret, val=-1, pos=-1,i;
char ans[1000], temp[100];
char ans[1000];
myDet->setOnline(ONLINE_FLAG);
@ -3176,6 +3197,21 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
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") {
@ -3183,14 +3219,23 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
} else if (cmd=="maxmod") {
ret=myDet->getMaxNumberOfModules();
} else if (cmd=="dr") {
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->setDynamicRange(val);
} else if (cmd=="roi") {
myDet->getROI(ret);
} else if (cmd=="detsizechan") {
sprintf(ans,"%d",myDet->getMaxNumberOfChannelsPerDetector(X));
sprintf(temp,"%d",myDet->getMaxNumberOfChannelsPerDetector(Y));
strcat(ans," ");
strcat(ans,temp);
sprintf(ans,"%d %d",myDet->getMaxNumberOfChannelsPerDetector(X),myDet->getMaxNumberOfChannelsPerDetector(Y));
return string(ans);
}
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);
}
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 << "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 << "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) {
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 << "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 << "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();
@ -3422,6 +3470,7 @@ string slsDetectorCommand::cmdSN(int narg, char *args[], int action) {
}
if (cmd=="receiverversion") {
myDet->setReceiverOnline(ONLINE_FLAG);
sprintf(answer,"%llx",myDet->getId(RECEIVER_VERSION));
return string(answer);
}
@ -4102,6 +4151,7 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
ret=myDet->setTimer(index,t);
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;
} else if (cmd=="rx_printconfig"){
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION)
return string("cannot put");
return string(""+myDet->printReceiverConfiguration());
}else if (cmd=="parameters") {
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) {
sval=string(args[1]);
myDet->retrieveDetectorSetup(sval);
@ -4560,6 +4612,7 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action)
}
return sval;
} else if (cmd=="setup") {
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==PUT_ACTION) {
sval=string(args[1]);
myDet->retrieveDetectorSetup(sval,2);
@ -4614,6 +4667,7 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if(cmd=="receiver"){
if (action==PUT_ACTION) {

View File

@ -45,6 +45,7 @@ int slsDetectorUtils::acquire(int delflag){
struct timespec begin,end;
clock_gettime(CLOCK_REALTIME, &begin);
//ensure acquire isnt started multiple times by same client
if(getAcquiringFlag() == false)
setAcquiringFlag(true);
@ -53,6 +54,10 @@ int slsDetectorUtils::acquire(int delflag){
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);
if(!receiver){
@ -220,6 +225,10 @@ int slsDetectorUtils::acquire(int delflag){
ResetPositionIndex();
for (int ip=0; ip<np; ip++) {
//let processing thread listen to these packets
sem_post(&sem_newRTAcquisition);
// cout << "positions " << endl;
if (*stoppedFlag==0) {
if (getNumberOfPositions()>0) {
@ -286,12 +295,7 @@ int slsDetectorUtils::acquire(int delflag){
//send receiver file name
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileName(fileIO::getFileName());
if(setReceiverOnline()==OFFLINE_FLAG){
stopReceiver();
*stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
//start receiver
if(startReceiver() == FAIL) {
cout << "Start receiver failed " << endl;
@ -353,9 +357,15 @@ int slsDetectorUtils::acquire(int delflag){
}
//online
else{
cout << "Stopping receiver " << endl;;
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){
stopAcquisition();
stopReceiver();
cout<<"***********receiver stopped"<<endl;
pthread_mutex_unlock(&mg);
break;
}
stopReceiver();
// cout<<"***********receiver stopped"<<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!
if (*threadedProcessing) {
#ifdef VERBOSE
cout << "wait for data processing thread" << endl;
#endif
setJoinThread(1);
//let processing thread continue and checkjointhread
sem_post(&sem_newRTAcquisition);
pthread_join(dataProcessingThread, &status);
#ifdef VERBOSE
cout << "data processing thread joined" << endl;
@ -504,6 +519,7 @@ int slsDetectorUtils::acquire(int delflag){
#endif
setAcquiringFlag(false);
sem_destroy(&sem_newRTAcquisition);
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;

View File

@ -70,6 +70,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
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 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(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();
@ -656,17 +669,18 @@ virtual int getReceiverCurrentFrameIndex()=0;
virtual int resetFramesCaught()=0;
/**
* Create Receiving Data Threads
* @param destroy is true to destroy all the threads
* Create Receiving Data Sockets
* @param destroy is true to destroy all the sockets
* @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
*/
//virtual void readFrameFromReceiver()=0;
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
virtual void readFrameFromReceiver(){};
/**
Turns off the receiver server!
*/
@ -865,12 +879,10 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
int (*acquisition_finished)(double,int,void*);
int (*measurement_finished)(int,int,void*);
void *acqFinished_p, *measFinished_p;
int (*progress_call)(double,void*);
void *pProgressCallArg;
sem_t sem_newRTAcquisition;
};

View File

@ -524,14 +524,16 @@ void* postProcessing::processData(int delflag) {
// }
// ifp=kbhit();
// if (ifp!=0){
// c=fgetc(stdin);
// if (c=='q') {
// cout<<"gonna stop"<<endl;
// stopAcquisition();
// }
// }
ifp=kbhit();
if (ifp!=0){
c=fgetc(stdin);
if (c=='q') {
cout<<"Caught the command to stop acquisition"<<endl;
stopAcquisition();
}
}
// //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]);
#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)
temp = retval[1];
else
temp = retval[0];
if ((abs(temp-val)<=5) || val==-1) {
ret=OK;
if (differentClients)
ret=FORCE_UPDATE;
} else {
ret=FAIL;
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 OK/failed */