mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 01:00:02 +02:00
some changes for jctb
This commit is contained in:
commit
12cd3d07a2
@ -35,6 +35,15 @@ usersFunctions
|
||||
../slsReceiverSoftware/MySocketTCP
|
||||
)
|
||||
|
||||
add_definitions(
|
||||
-DDACS_INT
|
||||
)
|
||||
|
||||
add_library(zmq STATIC IMPORTED )
|
||||
|
||||
set_target_properties(zmq PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../slsReceiverSoftware/include/libzmq.a
|
||||
)
|
||||
|
||||
add_library(slsDetectorStatic STATIC
|
||||
${SOURCES}
|
||||
|
@ -18,6 +18,9 @@ INCLUDES?= -IcommonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -Ius
|
||||
SRC_CLNT=slsDetectorAnalysis/fileIO.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/angularConversionStatic.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsDetectorAnalysis/postProcessingFuncs.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp #../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp
|
||||
|
||||
|
||||
LIBZMQDIR = ../slsReceiverSoftware/include
|
||||
LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq
|
||||
|
||||
$(info )
|
||||
$(info #######################################)
|
||||
$(info # Compiling slsDetectorSoftware #)
|
||||
@ -66,14 +69,14 @@ gotthardVirtualServer: $(SRC_MYTHEN_SVC)
|
||||
|
||||
|
||||
%.o : %.cpp %.h Makefile
|
||||
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS)
|
||||
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS)
|
||||
|
||||
|
||||
package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a
|
||||
|
||||
|
||||
$(DESTDIR)/libSlsDetector.so: $(OBJS)
|
||||
$(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread
|
||||
$(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ)
|
||||
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
|
||||
mv libSlsDetector.so $(DESTDIR)
|
||||
|
||||
|
@ -137,7 +137,7 @@ int acceptConnection(int socketDescriptor) {
|
||||
|
||||
|
||||
//socklen_t address_length;
|
||||
size_t address_length=sizeof(struct sockaddr_in);
|
||||
socklen_t address_length=sizeof(struct sockaddr_in);
|
||||
|
||||
if (socketDescriptor<0)
|
||||
return -1;
|
||||
|
@ -10,16 +10,22 @@
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/** Error flags */
|
||||
/*Assumption: Only upto 63 detectors */
|
||||
#define CRITICAL_ERROR_MASK 0xFFFFFFFF
|
||||
|
||||
#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL
|
||||
|
||||
|
||||
#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL
|
||||
#define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL
|
||||
#define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL
|
||||
@ -59,9 +65,13 @@ using namespace std;
|
||||
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
|
||||
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL
|
||||
#define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL
|
||||
#define RATE_CORRECTION_NOT_32BIT 0x0000000000800000ULL
|
||||
#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
|
||||
// 0x00000000FFFFFFFFULL
|
||||
/** @short class returning all error messages for error mask */
|
||||
class errorDefs {
|
||||
@ -70,7 +80,9 @@ class errorDefs {
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
errorDefs():errorMask(0){};
|
||||
errorDefs():errorMask(0){
|
||||
strcpy(notAddedList,"");
|
||||
};
|
||||
|
||||
/** Gets the error message
|
||||
* param errorMask error mask
|
||||
@ -192,15 +204,26 @@ public:
|
||||
if(slsErrorMask&DETECTOR_NETWORK_PARAMETER)
|
||||
retval.append("Could not set/get detector network parameter\n");
|
||||
|
||||
if(slsErrorMask&RATE_CORRECTION_NOT_32BIT)
|
||||
retval.append("Rate correction Deactivated, must be in 32 bit mode\n");
|
||||
if(slsErrorMask&RATE_CORRECTION_NOT_32or16BIT)
|
||||
retval.append("Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
|
||||
if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED)
|
||||
retval.append("Rate correction Deactivated. No default tau provided in file\n");
|
||||
|
||||
if(slsErrorMask&PROGRAMMING_ERROR)
|
||||
retval.append("Could not program FPGA\n");
|
||||
|
||||
if(slsErrorMask&RECEIVER_ACTIVATE)
|
||||
retval.append("Could not activate/deactivate receiver\n");
|
||||
|
||||
if(slsErrorMask&DATA_STREAMING)
|
||||
retval.append("Could not set/reset Data Streaming\n");
|
||||
|
||||
if(slsErrorMask&RESET_ERROR)
|
||||
retval.append("Could not reset the FPGA\n");
|
||||
|
||||
if(slsErrorMask&POWER_CHIP)
|
||||
retval.append("Could not power on/off/get the chip\n");
|
||||
|
||||
//------------------------------------------------------ length of message
|
||||
|
||||
@ -224,12 +247,31 @@ public:
|
||||
*/
|
||||
int64_t clearErrorMask(){errorMask=0;return errorMask;};
|
||||
|
||||
/** Gets the not added detector list
|
||||
/returns list
|
||||
*/
|
||||
char* getNotAddedList(){return notAddedList;};
|
||||
|
||||
/** Append the detector to not added detector list
|
||||
* @param name append to the list
|
||||
/returns list
|
||||
*/
|
||||
void appendNotAddedList(const char* name){strcat(notAddedList,name);strcat(notAddedList,"+");};
|
||||
|
||||
/** Clears not added detector list
|
||||
/returns error mask
|
||||
*/
|
||||
void clearNotAddedList(){strcpy(notAddedList,"");};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Error Mask */
|
||||
int64_t errorMask;
|
||||
|
||||
/** Detectors Not added List */
|
||||
char notAddedList[MAX_STR_LENGTH];
|
||||
|
||||
};
|
||||
|
||||
#endif /* ERROR_DEFS_H_ */
|
||||
|
@ -25,6 +25,9 @@
|
||||
/** maximum rois */
|
||||
#define MAX_ROIS 100
|
||||
|
||||
/** maximum unit size of program sent to detector */
|
||||
#define MAX_FPGAPROGRAMSIZE (2 * 1024 *1024)
|
||||
|
||||
|
||||
typedef char mystring[MAX_STR_LENGTH];
|
||||
typedef double mysteps[MAX_SCAN_STEPS];
|
||||
@ -362,6 +365,8 @@ enum dacIndex {
|
||||
TEMPERATURE_DCDC, /**< temperature sensor (close to DCDC) */
|
||||
TEMPERATURE_SODL, /**< temperature sensor (close to SODL) */
|
||||
TEMPERATURE_SODR, /**< temperature sensor (close to SODR) */
|
||||
TEMPERATURE_FPGA2, /**< temperature sensor (fpga2 (eiger:febl) */
|
||||
TEMPERATURE_FPGA3, /**< temperature sensor (fpga3 (eiger:febr) */
|
||||
V_POWER_A = 100, /**new chiptest board */
|
||||
V_POWER_B = 101, /**new chiptest board */
|
||||
V_POWER_C = 102, /**new chiptest board */
|
||||
@ -434,7 +439,10 @@ enum speedVariable {
|
||||
OVERSAMPLING, /**< oversampling for analog detectors */
|
||||
ADC_CLOCK, /**< adc clock divider */
|
||||
ADC_PHASE, /**< adc clock phase */
|
||||
ADC_PIPELINE /**< adc pipeline */
|
||||
ADC_PIPELINE, /**< adc pipeline */
|
||||
DBIT_CLOCK, /**< adc clock divider */
|
||||
DBIT_PHASE, /**< adc clock phase */
|
||||
DBIT_PIPELINE /**< adc pipeline */
|
||||
};
|
||||
|
||||
|
||||
|
@ -103,9 +103,12 @@ enum {
|
||||
F_SET_RATE_CORRECT, /** < set/reset rate correction tau */
|
||||
F_GET_RATE_CORRECT, /** < get rate correction tau */
|
||||
|
||||
F_ACTIVATE, /** < activate/deactivate readout */
|
||||
|
||||
F_SET_NETWORK_PARAMETER, /**< set network parameters such as transmission delay, flow control */
|
||||
|
||||
F_PROGRAM_FPGA, /**< program FPGA */
|
||||
F_RESET_FPGA, /**< reset FPGA */
|
||||
F_POWER_CHIP, /**< power chip */
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "Beb.h"
|
||||
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
|
||||
struct BebInfo beb_infos[10];
|
||||
@ -46,6 +47,8 @@
|
||||
short Beb_bit_mode;
|
||||
int BEB_MMAP_SIZE = 0x1000;
|
||||
|
||||
int Beb_activated = 1;
|
||||
|
||||
|
||||
|
||||
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){
|
||||
@ -170,8 +173,117 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Beb_EndofDataSend(int tengiga){
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
int l_framepktcounter2, l_txndelaycounter, l_framedelaycounter, r_framepktcounter2, r_txndelaycounter, r_framedelaycounter;
|
||||
int l_framepktcounter2_new, l_txndelaycounter_new, l_framedelaycounter_new, r_framepktcounter2_new, r_txndelaycounter_new, r_framedelaycounter_new;
|
||||
int addr_l_framepktcounter2, addr_l_txndelaycounter, addr_l_framedelaycounter, addr_r_framepktcounter2, addr_r_txndelaycounter, addr_r_framedelaycounter;
|
||||
|
||||
switch(tengiga){
|
||||
case 0:
|
||||
addr_l_framepktcounter2 = ONE_GIGA_LEFT_PKT_SEND_COUNTER;
|
||||
addr_l_txndelaycounter = ONE_GIGA_LEFT_TXN_DELAY_COUNTER;
|
||||
addr_l_framedelaycounter = ONE_GIGA_LEFT_FRAME_DELAY_COUNTER;
|
||||
addr_r_framepktcounter2 = ONE_GIGA_RIGHT_PKT_SEND_COUNTER;
|
||||
addr_r_txndelaycounter = ONE_GIGA_RIGHT_TXN_DELAY_COUNTER;
|
||||
addr_r_framedelaycounter = ONE_GIGA_RIGHT_FRAME_DELAY_COUNTER;
|
||||
break;
|
||||
case 1:
|
||||
addr_l_framepktcounter2 = TEN_GIGA_LEFT_PKT_SEND_COUNTER;
|
||||
addr_l_txndelaycounter = TEN_GIGA_LEFT_TXN_DELAY_COUNTER;
|
||||
addr_l_framedelaycounter = TEN_GIGA_LEFT_FRAME_DELAY_COUNTER;
|
||||
addr_r_framepktcounter2 = TEN_GIGA_RIGHT_PKT_SEND_COUNTER;
|
||||
addr_r_txndelaycounter = TEN_GIGA_RIGHT_TXN_DELAY_COUNTER;
|
||||
addr_r_framedelaycounter = TEN_GIGA_RIGHT_FRAME_DELAY_COUNTER;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//open file pointer
|
||||
int fd = Beb_open(&csp0base,XPAR_COUNTER_BASEADDR);
|
||||
if(fd < 0){
|
||||
cprintf(BG_RED,"Delay read counter fail\n");
|
||||
return;
|
||||
}else{
|
||||
//read data first time
|
||||
l_framepktcounter2 = Beb_Read32(csp0base, addr_l_framepktcounter2);
|
||||
l_txndelaycounter = Beb_Read32(csp0base, addr_l_txndelaycounter);
|
||||
l_framedelaycounter = Beb_Read32(csp0base, addr_l_framedelaycounter);
|
||||
r_framepktcounter2 = Beb_Read32(csp0base, addr_r_framepktcounter2);
|
||||
r_txndelaycounter = Beb_Read32(csp0base, addr_r_txndelaycounter);
|
||||
r_framedelaycounter = Beb_Read32(csp0base, addr_r_framedelaycounter);
|
||||
//#ifdef VERBOSE
|
||||
printf("\nLeft\n"
|
||||
"Framepacketcounter: %d\n"
|
||||
"Txndelaycounter:%d\n"
|
||||
"Framedelaycounter:%d\n"
|
||||
"\nRight\n"
|
||||
"Framepacketcounter: %d\n"
|
||||
"Txndelaycounter:%d\n"
|
||||
"Framedelaycounter:%d\n\n",
|
||||
l_framepktcounter2,l_txndelaycounter,l_framedelaycounter,
|
||||
r_framepktcounter2,r_txndelaycounter,r_framedelaycounter);
|
||||
//#endif
|
||||
|
||||
//keep comparing with previous values
|
||||
int maxtimer;
|
||||
while(1){
|
||||
maxtimer = MAX(MAX(l_txndelaycounter,l_framedelaycounter),MAX(r_txndelaycounter,r_framedelaycounter));
|
||||
maxtimer /= 100;
|
||||
printf("Will wait for %d us\n",maxtimer);
|
||||
usleep(maxtimer);
|
||||
|
||||
//read new values
|
||||
l_framepktcounter2_new = Beb_Read32(csp0base, addr_l_framepktcounter2);
|
||||
l_txndelaycounter_new = Beb_Read32(csp0base, addr_l_txndelaycounter);
|
||||
l_framedelaycounter_new = Beb_Read32(csp0base, addr_l_framedelaycounter);
|
||||
r_framepktcounter2_new = Beb_Read32(csp0base, addr_r_framepktcounter2);
|
||||
r_txndelaycounter_new = Beb_Read32(csp0base, addr_r_txndelaycounter);
|
||||
r_framedelaycounter_new = Beb_Read32(csp0base, addr_r_framedelaycounter);
|
||||
//#ifdef VERBOSE
|
||||
printf("\nLeft\n"
|
||||
"Framepacketcounter: %d\n"
|
||||
"Txndelaycounter:%d\n"
|
||||
"Framedelaycounter:%d\n"
|
||||
"\nRight\n"
|
||||
"Framepacketcounter: %d\n"
|
||||
"Txndelaycounter:%d\n"
|
||||
"Framedelaycounter:%d\n\n",
|
||||
l_framepktcounter2_new,l_txndelaycounter_new,l_framedelaycounter_new,
|
||||
r_framepktcounter2_new,r_txndelaycounter_new,r_framedelaycounter_new);
|
||||
//#endif
|
||||
|
||||
if ((l_framepktcounter2 == l_framepktcounter2_new) && (r_framepktcounter2 == r_framepktcounter2_new))
|
||||
break;
|
||||
|
||||
//update old values
|
||||
l_framepktcounter2 = l_framepktcounter2_new;
|
||||
l_txndelaycounter = l_txndelaycounter_new;
|
||||
l_framedelaycounter = l_framedelaycounter_new;
|
||||
r_framepktcounter2 = r_framepktcounter2_new;
|
||||
r_txndelaycounter = r_txndelaycounter_new;
|
||||
r_framedelaycounter = r_framedelaycounter_new;
|
||||
|
||||
}
|
||||
|
||||
printf("Detector has send all data\n");
|
||||
//close file pointer
|
||||
Beb_close(fd,csp0base);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* do not work at the moment */
|
||||
int Beb_SetMasterViaSoftware(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 0;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -200,6 +312,10 @@ int Beb_SetMasterViaSoftware(){
|
||||
|
||||
/* do not work at the moment */
|
||||
int Beb_SetSlaveViaSoftware(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 0;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -268,11 +384,18 @@ int Beb_Activate(int enable){
|
||||
if(fd > 0)
|
||||
Beb_close(fd,csp0base);
|
||||
|
||||
Beb_activated = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){
|
||||
|
||||
if(!Beb_activated)
|
||||
return val;
|
||||
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t valueread = 0;
|
||||
@ -325,6 +448,10 @@ int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){
|
||||
|
||||
|
||||
int Beb_ResetToHardwareSettings(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
//mapping new memory
|
||||
u_int32_t* csp0base=0;
|
||||
u_int32_t value = 0, ret = 1;
|
||||
@ -396,6 +523,10 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion(){
|
||||
}
|
||||
|
||||
void Beb_ResetFrameNumber(){
|
||||
|
||||
if(!Beb_activated)
|
||||
return;
|
||||
|
||||
//mapping new memory to read master top module configuration
|
||||
u_int32_t* csp0base=0;
|
||||
//open file pointer
|
||||
@ -446,7 +577,6 @@ int Beb_InitBebInfos(){//file name at some point
|
||||
bebInfoSize++;
|
||||
|
||||
|
||||
//if(!Beb_ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0;
|
||||
/*
|
||||
//loop through file to fill vector.
|
||||
BebInfo* b = new BebInfo(26);
|
||||
@ -477,52 +607,6 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac
|
||||
}
|
||||
|
||||
|
||||
int Beb_ReadSetUpFromFile(char* file_name){
|
||||
char line[100];
|
||||
char str[100];
|
||||
|
||||
int i0,i1;
|
||||
char mac0[50],mac1[50],ip0[50],ip1[0];
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the beb setup file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Setting up beb side of detector:\n");
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if (str[0]=='#')
|
||||
continue;
|
||||
|
||||
if(!strcmp(str,"add_beb")){
|
||||
if( sscanf (line,"%s %d %d %s %s %s %s",str,&i0,&i1,mac0,ip0,mac1,ip1) < 7){
|
||||
printf("Error adding beb from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf ("Read: %s %d %d %s %s %s %s\n", str,i0,i1,mac0,ip0,mac1,ip1);
|
||||
|
||||
if(Beb_GetBebInfoIndex(i0)){
|
||||
printf("Error adding beb from %s, beb number %d already added.\n",file_name,i0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
struct BebInfo b0;
|
||||
BebInfo_BebInfo(&b0,i0);
|
||||
BebInfo_SetSerialAddress(&b0,i1);
|
||||
BebInfo_SetHeaderInfo(&b0,0,mac0,ip0,42000+i0);
|
||||
BebInfo_SetHeaderInfo(&b0,1,mac1,ip1,52000+i0);
|
||||
beb_infos[bebInfoSize] = b0;
|
||||
bebInfoSize++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Beb_CheckSourceStuffBebInfo(){
|
||||
@ -552,6 +636,10 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){
|
||||
|
||||
|
||||
int Beb_WriteTo(unsigned int index){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
if(index>=bebInfoSize){
|
||||
printf("WriteTo index error.\n");
|
||||
return 0;
|
||||
@ -575,35 +663,15 @@ void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d){
|
||||
|
||||
|
||||
int Beb_SetByteOrder(){
|
||||
/*
|
||||
Beb_send_data_raw[0] = 0x8fff0000;
|
||||
if(Local_Write(ll_beb,4,Beb_send_data_raw)!=4) return 0;
|
||||
|
||||
while((Local_Read(ll_beb,Beb_recv_buffer_size*4,Beb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n");
|
||||
|
||||
if(bebInfoSize<2) return 0;
|
||||
|
||||
Beb_send_ndata = 3;
|
||||
Beb_send_data[0] = 0x000c0000;
|
||||
Beb_send_data[1] = 0;
|
||||
Beb_send_data[2] = 0;
|
||||
Beb_WriteTo(0);
|
||||
|
||||
//using little endian for data, big endian not fully tested, swap on 16 bit boundary.
|
||||
Beb_send_ndata = 3;
|
||||
Beb_send_data[0] = 0x000c0000;
|
||||
Beb_send_data[1] = 1;
|
||||
Beb_send_data[2] = 0;
|
||||
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
|
||||
Beb_WriteTo(0);
|
||||
|
||||
printf("\tSetting Byte Order .............. ok\n");
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
u_int32_t bram_phy_addr;
|
||||
u_int32_t* csp0base=0;
|
||||
/*u_int32_t* bram_ptr = NULL;*/
|
||||
@ -809,7 +877,9 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i
|
||||
cprintf(GREEN, "Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]);
|
||||
#endif
|
||||
|
||||
if(!Beb_WriteTo(i)) return 0;
|
||||
if(Beb_activated){
|
||||
if(!Beb_WriteTo(i)) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -828,6 +898,9 @@ int Beb_SetUpTransferParameters(short the_bit_mode){
|
||||
|
||||
int Beb_StopAcquisition()
|
||||
{
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
u_int32_t* csp0base=0;
|
||||
volatile u_int32_t valuel,valuer;
|
||||
//open file pointer
|
||||
@ -854,6 +927,10 @@ int Beb_StopAcquisition()
|
||||
}
|
||||
|
||||
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){
|
||||
|
||||
if(!Beb_activated)
|
||||
return 1;
|
||||
|
||||
if(dst_number>64) return 0;
|
||||
|
||||
unsigned int header_size = 4; //4*64 bits
|
||||
|
@ -41,12 +41,13 @@ struct BebInfo{
|
||||
|
||||
void Beb_ClearBebInfos();
|
||||
int Beb_InitBebInfos();
|
||||
int Beb_ReadSetUpFromFile(char* file_name);
|
||||
int Beb_CheckSourceStuffBebInfo();
|
||||
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
|
||||
|
||||
|
||||
void Beb_GetModuleCopnfiguration(int* master, int* top);
|
||||
void Beb_EndofDataSend(int tengiga);
|
||||
|
||||
int Beb_SetMasterViaSoftware();
|
||||
int Beb_SetSlaveViaSoftware();
|
||||
int Beb_Activate(int enable);
|
||||
|
@ -50,7 +50,7 @@ int64_t Feb_Control_subframe_exposure_time_in_10nsec;
|
||||
double Feb_Control_exposure_period_in_sec;
|
||||
|
||||
int64_t Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
int64_t Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
int64_t Feb_Control_RateTable_Period_in_nsec = -1;
|
||||
|
||||
unsigned int Feb_Control_trimbit_size;
|
||||
unsigned int* Feb_Control_last_downloaded_trimbits;
|
||||
@ -65,6 +65,9 @@ int Feb_control_master = 0;
|
||||
unsigned int Feb_Control_rate_correction_table[1024];
|
||||
double Feb_Control_rate_meas[16384];
|
||||
|
||||
double ratemax=-1;
|
||||
int Feb_Control_activated = 1;
|
||||
|
||||
|
||||
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
|
||||
unsigned int i;
|
||||
@ -152,6 +155,10 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i)
|
||||
|
||||
|
||||
|
||||
void Feb_Control_activate(int activate){
|
||||
Feb_Control_activated = activate;
|
||||
}
|
||||
|
||||
int Feb_Control_IsBottomModule(){
|
||||
if(Module_BottomAddressIsValid(&modules[Feb_Control_current_index]))
|
||||
return 1;
|
||||
@ -186,40 +193,10 @@ int Feb_Control_Init(int master, int top, int module_num){
|
||||
Feb_Control_module_number = (module_num & 0xFF);
|
||||
|
||||
int serial = !top;
|
||||
|
||||
/*
|
||||
//for Gemmas modules: if master, serial 0, else 1
|
||||
int serial = 1;
|
||||
if(master)
|
||||
serial = 0;
|
||||
switch(Feb_Control_module_number){
|
||||
case 34: serial = 0; break; //martin half
|
||||
case 26: serial = 0; break; //leo
|
||||
|
||||
case 31: serial = 0; break; //martin
|
||||
case 32: serial = 1; break;
|
||||
case 24: serial = 2; break;
|
||||
case 25: serial = 3; break;
|
||||
|
||||
case 15: serial = 0; break; //dhanya
|
||||
case 16: serial = 1; break;
|
||||
case 30: serial = 2; break;
|
||||
case 38: serial = 3; break;
|
||||
|
||||
case 49: serial = 0; break; // Gemma
|
||||
case 48: serial = 1; break; // Gemma
|
||||
}*/
|
||||
printf("serial: %d\n",serial);
|
||||
|
||||
Feb_Control_current_index = 1;
|
||||
|
||||
/*for(i=1;i<moduleSize;i++){
|
||||
if(Module_GetModuleNumber(&modules[i])==Feb_Control_module_number)
|
||||
Feb_Control_current_index = i;
|
||||
}
|
||||
printf("****current index:%d\n",i);
|
||||
*/
|
||||
//Feb_Control_ReadSetUpFileToAddModules("/home/root/executables/setup.txt");
|
||||
|
||||
//Add the half module
|
||||
Feb_Control_AddModule1(Feb_Control_module_number,top,serial,serial,1);
|
||||
@ -242,7 +219,8 @@ printf("****current index:%d\n",i);
|
||||
Feb_Interface_SendCompleteList(nfebs,feb_list);
|
||||
free(feb_list);
|
||||
printf("\n");
|
||||
Feb_Interface_SetByteOrder();
|
||||
if(Feb_Control_activated)
|
||||
Feb_Interface_SetByteOrder();
|
||||
|
||||
|
||||
return 1;
|
||||
@ -250,106 +228,6 @@ printf("****current index:%d\n",i);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void Feb_Control_Set_Master(){
|
||||
Feb_Control_am_i_master = 1;
|
||||
unsigned int halfmastermodule = 0x80000000;
|
||||
unsigned int reg_nums[1];
|
||||
unsigned int reg_vals[1];
|
||||
reg_nums[0]=DAQ_REG_CHIP_CMDS;
|
||||
reg_vals[0]=(halfmastermodule|Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
|
||||
|
||||
if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),1,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble writing commands....\n");;
|
||||
return 0;
|
||||
}
|
||||
printf("master is set\n");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int Feb_Control_ReadSetUpFileToAddModules(char* file_name){
|
||||
char line[100];
|
||||
char str[100];
|
||||
int i0,i1,i2;
|
||||
// int memaddress = 1;
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nSetting up detectors:\n");
|
||||
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if (str[0]=='#')
|
||||
continue;
|
||||
|
||||
|
||||
if(!strcmp(str,"add_module")){
|
||||
if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){
|
||||
cprintf(RED,"Error adding module from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2);
|
||||
if(!Feb_Control_AddModule1(i0,1,i1,i2,0)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
else if(!strcmp(str,"add_half_module")){
|
||||
if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){
|
||||
cprintf(RED,"Error adding half module from %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2);
|
||||
|
||||
if(!Feb_Control_AddModule1(i0,i1,i2,i2,1)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//memaddress++;
|
||||
Feb_Control_PrintModuleList();
|
||||
|
||||
/* if(!Feb_Control_AddModule1(i0,i1)){
|
||||
cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name);
|
||||
exit(0);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
|
||||
Feb_Control_PrintModuleList();
|
||||
unsigned int nfebs = 0;
|
||||
unsigned int* feb_list = malloc(moduleSize*4 * sizeof(unsigned int));
|
||||
unsigned int i;
|
||||
for(i=1;i<moduleSize;i++){
|
||||
if(Module_TopAddressIsValid(&modules[i])){
|
||||
feb_list[nfebs++] = Module_GetTopRightAddress(&modules[i]);
|
||||
feb_list[nfebs++] = Module_GetTopLeftAddress(&modules[i]);
|
||||
}
|
||||
if(Module_BottomAddressIsValid(&modules[i])){
|
||||
feb_list[nfebs++] = Module_GetBottomRightAddress(&modules[i]);
|
||||
feb_list[nfebs++] = Module_GetBottomLeftAddress(&modules[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Feb_Interface_SendCompleteList(nfebs,feb_list);
|
||||
free(feb_list);
|
||||
|
||||
printf("\n");
|
||||
|
||||
return Feb_Interface_SetByteOrder();
|
||||
}
|
||||
|
||||
void Feb_Control_PrintModuleList(){
|
||||
unsigned int i;
|
||||
printf("\tModule list:\n");
|
||||
@ -447,92 +325,6 @@ int Feb_Control_AddModule1(unsigned int module_number, int top_enable, unsigned
|
||||
return parameters_ok;
|
||||
}
|
||||
|
||||
/* not called anywhere**/
|
||||
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
|
||||
printf("Reading Setup file for module number:%d\n",module_num);
|
||||
char line[100];
|
||||
char str[100];
|
||||
int i0;
|
||||
float f0;
|
||||
|
||||
FILE* fp = fopen(file_name, "r");
|
||||
if( fp == NULL ){
|
||||
perror("Error while opening the file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ( fgets (line , 255 , fp) != NULL ){
|
||||
if(strlen(line)<=1)
|
||||
continue;
|
||||
sscanf (line, "%s", str);
|
||||
if ((str[0]=='#') || (!strcmp(str,"add_module")) || (!strcmp(str,"add_half_module")))
|
||||
continue;
|
||||
|
||||
if(!strcmp("iodelay",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading io_delay\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetIDelays(module_num,i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("high_voltage",str)){
|
||||
if(sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading high_voltage\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetHighVoltage(f0);
|
||||
}
|
||||
/*
|
||||
else if(!strcmp("photon_energy",str)){
|
||||
if(sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading photon_energy\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetPhotonEnergy(f0);
|
||||
}*/
|
||||
|
||||
else if(!strcmp("dynamic_range",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading dynamic_range\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetDynamicRange(i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("readout_speed",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading readout_speed\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetReadoutSpeed(i0);
|
||||
}
|
||||
|
||||
else if(!strcmp("readout_mode",str)){
|
||||
if(sscanf (line,"%s %d", str,&i0) < 2){
|
||||
cprintf(RED,"Error reading readout_mode\n");
|
||||
exit(0);
|
||||
}
|
||||
Feb_Control_SetReadoutMode(i0);
|
||||
}
|
||||
|
||||
else {
|
||||
if( sscanf (line,"%s %f", str,&f0) < 2){
|
||||
cprintf(RED,"Error reading dac\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(module_num>0)
|
||||
sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/
|
||||
if(!Feb_Control_SetDAC(str,f0,1))
|
||||
cprintf(RED,"Error in string: %s",str);
|
||||
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
printf("Done reading set up file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_CheckSetup(int master){
|
||||
@ -675,12 +467,14 @@ int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int chan
|
||||
|
||||
printf(", tracks 0x%x to: %d, %d clks and %d units.\n",channels,(((15-delay_data_valid_nclks)<<6)|ndelay_units),delay_data_valid_nclks,ndelay_units);
|
||||
|
||||
if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){
|
||||
cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) ||
|
||||
!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){
|
||||
cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -738,9 +532,11 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
|
||||
}
|
||||
|
||||
unsigned int r = 0x20000000 | (b&0xff);
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
|
||||
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
|
||||
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*value = Feb_Control_DACToVoltage(b,nsteps,vmin,vmax);
|
||||
@ -752,43 +548,15 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
|
||||
|
||||
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){
|
||||
char* local_s = dac_str;
|
||||
//char temp[50];
|
||||
*module_index = Feb_Control_current_index;
|
||||
|
||||
/*
|
||||
char* p1 = strstr(local_s,"mod");//size_t p1 = local_s.find("mod");
|
||||
char* p2 = strstr(local_s,"::");//size_t p2 =local_s.find("::");
|
||||
if(p1!=NULL&&p2!=NULL&&(p1+3)<p2){//if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){
|
||||
strncpy(temp, p1+3, (p2-p1));
|
||||
temp[p2-p1] = '\0';
|
||||
unsigned int number = atoi(temp); //unsigned int number = atoi((local_s.substr(p1+3,p2-3)).c_str());
|
||||
|
||||
if(!Feb_Control_GetModuleIndex(number,module_index)){
|
||||
cprintf(RED,"Error in dac_name \"%s\", module number %d not in list.\n",dac_str,number);
|
||||
return 0;
|
||||
}
|
||||
strcpy(local_s,p2+2);//local_s = local_s.substr(p2+2);
|
||||
}
|
||||
*/
|
||||
|
||||
*top = 1;//make them both 1 instead of this
|
||||
*bottom = 1;
|
||||
/*if(p1 = strstr(local_s,"top::")!=NULL){
|
||||
strcpy(local_s,p1+5);
|
||||
*bottom=0;
|
||||
}else if(p1 = strstr(local_s,"bottom::")!=NULL){
|
||||
strcpy(local_s,p1+8);
|
||||
*top=0;
|
||||
}*/
|
||||
|
||||
if(Module_BottomAddressIsValid(&modules[*module_index]))
|
||||
*top=0;
|
||||
else
|
||||
*bottom=0;
|
||||
|
||||
|
||||
|
||||
|
||||
*dac_ch = 0;
|
||||
if(!Feb_Control_GetDACNumber(local_s,dac_ch)){
|
||||
cprintf(RED,"Error in dac_name: %s (%s)\n",dac_str,local_s);
|
||||
@ -799,37 +567,6 @@ int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int*
|
||||
}
|
||||
|
||||
int Feb_Control_SetDAC(char* dac_str, int value, int is_a_voltage_mv){
|
||||
/*
|
||||
string local_s = dac_str;
|
||||
unsigned int module_index = 0;
|
||||
|
||||
size_t p1 = local_s.find("mod");
|
||||
size_t p2 = local_s.find("::");
|
||||
if(p1!=string::npos&&p2!=string::npos&&(p1+3)<p2){
|
||||
unsigned int number = atoi((local_s.substr(p1+3,p2-3)).c_str());
|
||||
if(!GetModuleIndex(number,module_index)){
|
||||
cprintf(RED,"Error in dac_name \""<<dac_str<<"\", module number "<<number<<" not in list.\n");;
|
||||
return 0;
|
||||
}
|
||||
local_s = local_s.substr(p2+2);
|
||||
}
|
||||
|
||||
int top = 1;
|
||||
int bottom = 1;
|
||||
if((p1 = local_s.find("top::"))!=string::npos){
|
||||
local_s = local_s.substr(p1+5);
|
||||
bottom=0;
|
||||
}else if((p1 = local_s.find("bottom::"))!=string::npos){
|
||||
local_s = local_s.substr(p1+8);
|
||||
top=0;
|
||||
}
|
||||
|
||||
unsigned int dac_ch = 0;
|
||||
if(!GetDACNumber(local_s,dac_ch)){
|
||||
cprintf(RED,"Error in dac_name: "<<dac_str<<" ("<<local_s<<")\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
unsigned int i;
|
||||
unsigned int module_index, dac_ch;
|
||||
int top, bottom;
|
||||
@ -901,10 +638,6 @@ int Feb_Control_GetDACNumber(char* s, unsigned int* n){
|
||||
|
||||
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value){
|
||||
|
||||
//static unsigned int nsteps = 4096; //12 bit dac
|
||||
//static float vmin = 0;
|
||||
//static float vmax = 2;
|
||||
|
||||
if(ch<0||ch>15){
|
||||
cprintf(RED,"Warning invalid ch for SetDAC.\n");
|
||||
return 0;
|
||||
@ -918,9 +651,11 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int
|
||||
unsigned int r = dac_ic<<30 | 3<<16 | dac_ch<<12 | *value; //3 write and power up
|
||||
|
||||
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){
|
||||
cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch);
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){
|
||||
cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float voltage=Feb_Control_DACToVoltage(*value,4096,0,2048);
|
||||
@ -929,14 +664,7 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
float GetDAC(string s){
|
||||
static unsigned int n;
|
||||
if(!GetDACNumber(s,n)) return 0;
|
||||
|
||||
return dac[n];
|
||||
}
|
||||
*/
|
||||
|
||||
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
printf("Setting Trimbits\n");
|
||||
@ -959,12 +687,15 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
for(l_r=0;l_r<2;l_r++){ // l_r loop
|
||||
//printf("\nl_r:%d\t\t",l_r);
|
||||
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
|
||||
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
|
||||
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
printf("Could not select chips\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
|
||||
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
|
||||
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
|
||||
printf("Could not select chips\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int row_set;
|
||||
for(row_set=0;row_set<16;row_set++){ //16 rows at a time
|
||||
//printf("row_set:%d\t\t",row_set);
|
||||
@ -1020,22 +751,26 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
|
||||
} //end row loop
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[1])){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)||
|
||||
//if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)||
|
||||
// !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
printf(" some errror!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1077,14 +812,20 @@ return Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[
|
||||
}
|
||||
|
||||
int Feb_Control_SetCommandRegister(unsigned int cmd){
|
||||
return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0);
|
||||
if(Feb_Control_activated)
|
||||
return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status){
|
||||
if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){
|
||||
cprintf(RED,"Error: reading status register.\n");
|
||||
return 0;
|
||||
//if deactivated, should be handled earlier and should not get into this function
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){
|
||||
cprintf(RED,"Error: reading status register.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*ret_status = (0x02FF0000 & *ret_status) >> 16;
|
||||
@ -1093,11 +834,12 @@ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret
|
||||
|
||||
|
||||
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){
|
||||
cprintf(RED,"Warning: could not start.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){
|
||||
cprintf(RED,"Warning: could not start.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Feb_Control_WaitForFinishedFlag(sleep_time_us);
|
||||
}
|
||||
|
||||
@ -1105,6 +847,10 @@ int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){
|
||||
int Feb_Control_AcquisitionInProgress(){
|
||||
unsigned int status_reg_r=0,status_reg_l=0;
|
||||
|
||||
//deactivated should return end of acquisition
|
||||
if(!Feb_Control_activated)
|
||||
return 0;
|
||||
|
||||
int ind = Feb_Control_current_index;
|
||||
if(Module_BottomAddressIsValid(&modules[ind])){
|
||||
|
||||
@ -1132,6 +878,10 @@ int Feb_Control_AcquisitionInProgress(){
|
||||
int Feb_Control_AcquisitionStartedBit(){
|
||||
unsigned int status_reg_r=0,status_reg_l=0;
|
||||
|
||||
//deactivated should return acquisition started/ready
|
||||
if(!Feb_Control_activated)
|
||||
return 1;
|
||||
|
||||
int ind = Feb_Control_current_index;
|
||||
if(Module_BottomAddressIsValid(&modules[ind])){
|
||||
|
||||
@ -1172,6 +922,11 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){
|
||||
|
||||
|
||||
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
||||
|
||||
//deactivated dont wait (otherwise give a toggle value back)
|
||||
if(!Feb_Control_activated)
|
||||
return 1;
|
||||
|
||||
int value = prev_flag;
|
||||
while(value == prev_flag){
|
||||
usleep(sleep_time_us);
|
||||
@ -1186,10 +941,13 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_Reset(){printf("Reset daq\n");
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
|
||||
cprintf(RED,"Warning: Could not reset daq, no response.\n");
|
||||
return 0;
|
||||
int Feb_Control_Reset(){
|
||||
printf("Reset daq\n");
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
|
||||
cprintf(RED,"Warning: Could not reset daq, no response.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Feb_Control_WaitForFinishedFlag(5000);
|
||||
@ -1199,10 +957,12 @@ int Feb_Control_Reset(){printf("Reset daq\n");
|
||||
|
||||
|
||||
int Feb_Control_SetStaticBits(){
|
||||
//program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: Could not set static bits\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
//program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: Could not set static bits\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1371,6 +1131,7 @@ int Feb_Control_SetExposureTime(double the_exposure_time_in_sec){
|
||||
return 1;
|
||||
}
|
||||
double Feb_Control_GetExposureTime(){return Feb_Control_exposure_time_in_sec;}
|
||||
int64_t Feb_Control_GetExposureTime_in_nsec(){return (int64_t)(Feb_Control_exposure_time_in_sec*(1E9));}
|
||||
|
||||
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec){
|
||||
Feb_Control_subframe_exposure_time_in_10nsec = the_subframe_exposure_time_in_10nsec;
|
||||
@ -1447,13 +1208,7 @@ void Feb_Control_PrintAcquisitionSetup(){
|
||||
}
|
||||
|
||||
int Feb_Control_SendBitModeToBebServer(){
|
||||
/*
|
||||
static int first_pass = 1;
|
||||
static char buffer[1024];
|
||||
|
||||
if(first_pass&&!Feb_Control_SetupSendToSocket("localhost",43212)) return 0;
|
||||
else first_pass=0;
|
||||
*/
|
||||
unsigned int just_bit_mode = (DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8) & Feb_Control_staticBits;
|
||||
unsigned int bit_mode = 16; //default
|
||||
if(just_bit_mode == DAQ_STATIC_BIT_M4) bit_mode = 4;
|
||||
@ -1466,60 +1221,9 @@ int Feb_Control_SendBitModeToBebServer(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
bzero(buffer,1024);
|
||||
sprintf(buffer,"setbitmode %d",bit_mode);
|
||||
|
||||
if(Feb_Control_WriteNRead(buffer,strlen(buffer),1024)<1||strncmp(buffer,"0",1)){
|
||||
cprintf(RED,"Error: sending bit mode ...\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port){
|
||||
|
||||
struct hostent *server;
|
||||
if((server = gethostbyname(ip_address_hostname)) == NULL){ //or look into getaddrinfo(3)
|
||||
fprintf(stderr,"ERROR, no such host\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//struct sockaddr_in serv_addr;
|
||||
bzero((char *) &Feb_Control_serv_addr, sizeof(Feb_Control_serv_addr));
|
||||
Feb_Control_serv_addr.sin_family = AF_INET;
|
||||
bcopy((char *)server->h_addr,(char *)&Feb_Control_serv_addr.sin_addr.s_addr,server->h_length);
|
||||
Feb_Control_serv_addr.sin_port = htons(port);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Feb_Control_WriteNRead(char* message, int length, int max_length){
|
||||
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sockfd <0){
|
||||
fprintf(stderr,"ERROR opening socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(connect(sockfd,(struct sockaddr *) &Feb_Control_serv_addr,sizeof(Feb_Control_serv_addr)) < 0){
|
||||
fprintf(stderr,"ERROR connecting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int n = write(sockfd,message,length);
|
||||
if(n<0) cprintf(RED,"Error writing to socket");
|
||||
|
||||
length = read(sockfd,message,max_length);
|
||||
if(length<0) cprintf(RED,"Error reading to socket");
|
||||
|
||||
close(sockfd);
|
||||
|
||||
return length;
|
||||
}
|
||||
*/
|
||||
|
||||
int Feb_Control_PrepareForAcquisition(){//return 1;
|
||||
static unsigned int reg_nums[20];
|
||||
@ -1567,30 +1271,13 @@ int Feb_Control_PrepareForAcquisition(){//return 1;
|
||||
reg_nums[5]=DAQ_REG_SUBFRAME_EXPOSURES;
|
||||
reg_vals[5]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns)
|
||||
// if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
reg_nums[0]=DAQ_REG_NEXPOSURES;
|
||||
reg_vals[0]=Feb_Control_nimages;
|
||||
reg_nums[1]=DAQ_REG_EXPOSURE_TIMER;
|
||||
reg_vals[1]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec);
|
||||
reg_nums[2]=DAQ_REG_EXPOSURE_REPEAT_TIMER;
|
||||
reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec);
|
||||
reg_nums[3]=DAQ_REG_CHIP_CMDS;
|
||||
reg_vals[3]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode);
|
||||
reg_nums[4]=DAQ_REG_SUBFRAME_EXPOSURES;
|
||||
reg_vals[4]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns)
|
||||
// if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),5,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1611,22 +1298,13 @@ int Feb_Control_StartAcquisition(){
|
||||
reg_nums[14]=DAQ_REG_CTRL;
|
||||
reg_vals[14]=ACQ_CTRL_START;
|
||||
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){
|
||||
cprintf(RED,"Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){
|
||||
cprintf(RED,"Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
reg_nums[0]=DAQ_REG_CTRL;
|
||||
reg_vals[0]=0;
|
||||
reg_nums[1]=DAQ_REG_CTRL;
|
||||
reg_vals[1]=ACQ_CTRL_START;
|
||||
|
||||
if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),2,reg_nums,reg_vals,0,0)){
|
||||
printf("Trouble starting acquisition....\n");;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1705,11 +1383,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){
|
||||
c |= (inc_x_pos) ? DAQ_CLK_MAIN_CLK_TO_SELECT_NEXT_PIXEL : 0;
|
||||
c |= (inc_y_pos) ? DAQ_CLK_ROW_CLK_TO_SELECT_NEXT_ROW : 0;
|
||||
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) ||
|
||||
!Feb_Control_SetCommandRegister(c) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not PulsePixelNMove(...).\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) ||
|
||||
!Feb_Control_SetCommandRegister(c) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not PulsePixelNMove(...).\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1717,11 +1397,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){
|
||||
|
||||
/**new*/
|
||||
int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not shift in 32.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not shift in 32.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -1741,11 +1423,13 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){
|
||||
ntimes=1023;
|
||||
}
|
||||
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not clock row clock.\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) ||
|
||||
!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) ||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(RED,"Warning: could not clock row clock.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1789,26 +1473,40 @@ int Feb_Control_PulseChip(int npulses){
|
||||
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;}
|
||||
int64_t Feb_Control_Get_RateTable_Period_in_nsec(){ return Feb_Control_RateTable_Period_in_nsec;}
|
||||
|
||||
//returns -1 if slope is too high
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
|
||||
double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
|
||||
//period = exptime if 16bit, period = subexptime if 32 bit
|
||||
int dr = Feb_Control_GetDynamicRange();
|
||||
double period_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
|
||||
if(dr == 16)
|
||||
period_in_sec = Feb_Control_GetExposureTime();
|
||||
|
||||
|
||||
double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
|
||||
printf(" tau %lf %lf ", (double)tau_in_Nsec, (double) tau_in_sec);
|
||||
|
||||
unsigned int np = 16384; //max slope 16 * 1024
|
||||
double b0[1024];
|
||||
double m[1024];
|
||||
|
||||
if(tau_in_sec<0||sub_expure_time_in_sec<0){
|
||||
printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec);
|
||||
if(tau_in_sec<0||period_in_sec<0){
|
||||
if(dr == 32)
|
||||
printf("Error tau %lf and sub_exposure_time %lf must be greater than 0.\n", tau_in_sec, period_in_sec);
|
||||
else
|
||||
printf("Error tau %lf and exposure_time %lf must be greater than 0.\n", tau_in_sec, period_in_sec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cprintf(BLUE, "Changing Rate Correction Table tau:%0.8f sec, period:%f sec",tau_in_sec,period_in_sec);
|
||||
|
||||
printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec);
|
||||
int i;
|
||||
for(i=0;i<np;i++)
|
||||
Feb_Control_rate_meas[i] = i*exp(-i/sub_expure_time_in_sec*tau_in_sec);
|
||||
for(i=0;i<np;i++){
|
||||
Feb_Control_rate_meas[i] = i*exp(-i/period_in_sec*tau_in_sec);
|
||||
if(Feb_Control_rate_meas[i] > ratemax) ratemax= Feb_Control_rate_meas[i];
|
||||
}
|
||||
|
||||
/*
|
||||
b : index/address of block ram/rate correction table
|
||||
@ -1827,13 +1525,11 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
*/
|
||||
|
||||
int next_i=0;
|
||||
double beforemax;
|
||||
b0[0] = 0;
|
||||
m[0] = 1;
|
||||
|
||||
for(i=0; i<1024; i++)
|
||||
Feb_Control_rate_correction_table[i] = 65535;
|
||||
|
||||
Feb_Control_rate_correction_table[0] = (((int)(m[0]+0.5)&0xf)<<14) | ((int)(b0[0]+0.5)&0x3fff);
|
||||
Feb_Control_rate_correction_table[0] = (((int)(m[0]+0.5)&0xf)<<14) | ((int)(b0[0]+0.5)&0x3fff);
|
||||
|
||||
int b=0;
|
||||
for(b=1;b<1024;b++){
|
||||
@ -1841,9 +1537,13 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
double s=0,sx=0,sy=0,sxx=0,sxy=0;
|
||||
for(;;next_i++){
|
||||
if(next_i>=np){
|
||||
for(; b<1024; b++){
|
||||
if(beforemax>ratemax) b0[b] = beforemax;
|
||||
else b0[b] = ratemax;
|
||||
m[b] = 15;
|
||||
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
|
||||
}
|
||||
b=1024;
|
||||
b0[b] = 16383;
|
||||
m[b] = 15;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1867,17 +1567,20 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
double delta = s*sxx - sx*sx;
|
||||
b0[b] = (sxx*sy - sx*sxy)/delta;
|
||||
m[b] = (s*sxy - sx*sy) /delta;
|
||||
|
||||
beforemax= b0[b];
|
||||
|
||||
if(m[b]<0||m[b]>15){
|
||||
m[b]=15;
|
||||
b0[b]=16383;
|
||||
if(beforemax>ratemax) b0[b] = beforemax;
|
||||
else b0[b] = ratemax;
|
||||
}
|
||||
/*printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||
s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
|
||||
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
|
||||
}else{
|
||||
b0[b] = 16383;
|
||||
if(beforemax>ratemax) b0[b] = beforemax;
|
||||
else b0[b] = ratemax;
|
||||
m[b] = 15;
|
||||
}
|
||||
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
|
||||
@ -1886,11 +1589,11 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
|
||||
if(Feb_Control_SetRateCorrectionTable(Feb_Control_rate_correction_table)){
|
||||
Feb_Control_RateTable_Tau_in_nsec = tau_in_Nsec;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
|
||||
Feb_Control_RateTable_Period_in_nsec = period_in_sec;
|
||||
return 1;
|
||||
}else{
|
||||
Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
Feb_Control_RateTable_Period_in_nsec = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1919,18 +1622,22 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
||||
printf("daq reset completely\n");
|
||||
|
||||
if(Module_TopAddressIsValid(&modules[1])){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
if(Feb_Control_activated){
|
||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@ -1943,7 +1650,7 @@ int Feb_Control_GetRateCorrectionVariable(){ return (Feb_Control_subFrameMode&DA
|
||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction){
|
||||
if(activate_rate_correction){
|
||||
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||
printf("Rate correction activated. Note: the rate correction applied only when run in auto summing mode.\n");
|
||||
printf("Rate correction activated.\n");
|
||||
}else{
|
||||
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||
printf("Rate correction deactivated.\n");
|
||||
@ -1958,13 +1665,39 @@ int Feb_Control_PrintCorrectedValues(){
|
||||
lsb = i&3;
|
||||
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
|
||||
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
|
||||
delta = slope*lsb;
|
||||
corr = delta+base;
|
||||
if(base==16383 && slope==15) corr=4095;
|
||||
|
||||
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
|
||||
delta = slope*lsb;
|
||||
corr = delta+base;
|
||||
if(slope==15) corr= 3*slope+base;
|
||||
|
||||
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%lf\n",
|
||||
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_Control_GetLeftFPGATemp(){
|
||||
unsigned int temperature=0;
|
||||
if(Module_TopAddressIsValid(&modules[1]))
|
||||
Feb_Interface_ReadRegister(Module_GetTopLeftAddress (&modules[1]),FEB_REG_STATUS, &temperature);
|
||||
else
|
||||
Feb_Interface_ReadRegister(Module_GetBottomLeftAddress (&modules[1]),FEB_REG_STATUS, &temperature);
|
||||
temperature = temperature >> 16;
|
||||
//division done in client to send int over network
|
||||
return (int)temperature;
|
||||
}
|
||||
|
||||
int Feb_Control_GetRightFPGATemp(){
|
||||
unsigned int temperature=0;
|
||||
if(Module_TopAddressIsValid(&modules[1]))
|
||||
Feb_Interface_ReadRegister(Module_GetTopRightAddress (&modules[1]),FEB_REG_STATUS, &temperature);
|
||||
else
|
||||
Feb_Interface_ReadRegister(Module_GetBottomRightAddress (&modules[1]),FEB_REG_STATUS, &temperature);
|
||||
temperature = temperature >> 16;
|
||||
//division done in client to send int over network
|
||||
return (int)temperature;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -64,6 +64,7 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
|
||||
|
||||
|
||||
|
||||
void Feb_Control_activate(int activate);
|
||||
|
||||
int Feb_Control_IsBottomModule();
|
||||
int Feb_Control_GetModuleNumber();
|
||||
@ -112,8 +113,6 @@ int Feb_Control_GetModuleNumber();
|
||||
|
||||
void Feb_Control_FebControl();
|
||||
int Feb_Control_Init(int master, int top, int module_num);
|
||||
int Feb_Control_ReadSetUpFileToAddModules(char* file_name);
|
||||
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name);
|
||||
int Feb_Control_CheckSetup();
|
||||
|
||||
unsigned int Feb_Control_GetNModules();
|
||||
@ -159,6 +158,7 @@ int Feb_Control_GetModuleNumber();
|
||||
unsigned int Feb_Control_GetNExposures();
|
||||
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
|
||||
double Feb_Control_GetExposureTime();
|
||||
int64_t Feb_Control_GetExposureTime_in_nsec();
|
||||
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec);
|
||||
int64_t Feb_Control_GetSubFrameExposureTime();
|
||||
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
|
||||
@ -185,11 +185,14 @@ int Feb_Control_GetModuleNumber();
|
||||
int Feb_Control_PulseChip(int npulses);
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
int64_t Feb_Control_Get_RateTable_Period_in_nsec();
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
|
||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
|
||||
int Feb_Control_GetRateCorrectionVariable();
|
||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
|
||||
int Feb_Control_PrintCorrectedValues();
|
||||
|
||||
int Feb_Control_GetLeftFPGATemp();
|
||||
int Feb_Control_GetRightFPGATemp();
|
||||
|
||||
#endif
|
||||
|
@ -95,6 +95,7 @@
|
||||
#define DAQ_STATUS_DAQ_RUNNING 0x01
|
||||
#define DAQ_DATA_COLLISION_ERROR 0x02
|
||||
|
||||
|
||||
#define DAQ_STATUS_CURRENT_M4 0x04
|
||||
#define DAQ_STATUS_CURRENT_M8 0x08
|
||||
#define DAQ_STATUS_CURRENT_M12 0x00 //in 12 bit mode both are cleared
|
||||
@ -149,3 +150,49 @@
|
||||
|
||||
#define FRAME_NUM_RESET_OFFSET 0xA0
|
||||
|
||||
//temp so far
|
||||
#define FEB_REG_STATUS 0xa
|
||||
|
||||
//1g counters
|
||||
#define ONE_GIGA_LEFT_FRAME_SEND_COUNTER 0x04
|
||||
#define ONE_GIGA_LEFT_PKT_SEND_COUNTER 0x24
|
||||
|
||||
#define ONE_GIGA_LEFT_TXN_DELAY_COUNTER 0x104
|
||||
#define ONE_GIGA_LEFT_FRAME_DELAY_COUNTER 0x124
|
||||
|
||||
#define ONE_GIGA_RIGHT_FRAME_SEND_COUNTER 0x44
|
||||
#define ONE_GIGA_RIGHT_PKT_SEND_COUNTER 0x64
|
||||
|
||||
#define ONE_GIGA_RIGHT_TXN_DELAY_COUNTER 0x144
|
||||
#define ONE_GIGA_RIGHT_FRAME_DELAY_COUNTER 0x164
|
||||
|
||||
//10g counters
|
||||
#define TEN_GIGA_LEFT_FRAME_SEND_COUNTER 0x84
|
||||
#define TEN_GIGA_LEFT_PKT_SEND_COUNTER 0xa4
|
||||
|
||||
#define TEN_GIGA_LEFT_TXN_DELAY_COUNTER 0x184
|
||||
#define TEN_GIGA_LEFT_FRAME_DELAY_COUNTER 0x1a4
|
||||
|
||||
#define TEN_GIGA_RIGHT_FRAME_SEND_COUNTER 0xc4
|
||||
#define TEN_GIGA_RIGHT_PKT_SEND_COUNTER 0xe4
|
||||
|
||||
#define TEN_GIGA_RIGHT_TXN_DELAY_COUNTER 0x1c4
|
||||
#define TEN_GIGA_RIGHT_FRAME_DELAY_COUNTER 0x1e4
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.0
Executable file
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.0
Executable file
Binary file not shown.
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.1
Executable file
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.1
Executable file
Binary file not shown.
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.0
Executable file
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.0
Executable file
Binary file not shown.
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.1
Executable file
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.1
Executable file
Binary file not shown.
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.2
Executable file
BIN
slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.2
Executable file
Binary file not shown.
@ -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: e9878a26ffb7e57c6e6724215e46ae5634871e64
|
||||
Revision: 231
|
||||
Repsitory UUID: 279965f286cc6364dec8bf7e2a837214d11bb296
|
||||
Revision: 258
|
||||
Branch: developer
|
||||
Last Changed Author: Dhanya_Maliakal
|
||||
Last Changed Rev: 336
|
||||
Last Changed Date: 2016-08-24 16:47:14 +0200
|
||||
Last Changed Rev: 358
|
||||
Last Changed Date: 2016-11-03 12:31:34 +0100
|
||||
|
@ -1,11 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer"
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID "e9878a26ffb7e57c6e6724215e46ae5634871e64"
|
||||
//#define SVNREV 0x336
|
||||
#define SVNREPUUID "279965f286cc6364dec8bf7e2a837214d11bb296"
|
||||
//#define SVNREV 0x358
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH "Dhanya_Maliakal"
|
||||
#define SVNREV 0x336
|
||||
#define SVNDATE 0x20160824
|
||||
#define SVNREV 0x358
|
||||
#define SVNDATE 0x20161103
|
||||
//
|
||||
|
@ -130,7 +130,7 @@ int initDetector(){
|
||||
detectorGain[i] = default_gain_values[(int)STANDARD];
|
||||
for(i=0;i<NOFFSET;i++)
|
||||
detectorOffset[i] = default_offset_values[(int)STANDARD];
|
||||
thisSettings = STANDARD;/**UNITIALIZED*/
|
||||
thisSettings = UNINITIALIZED;
|
||||
/*sChan=noneSelected;
|
||||
sChip=noneSelected;
|
||||
sMod=noneSelected;
|
||||
@ -449,6 +449,12 @@ int getADC(enum detAdcIndex ind, int imod){
|
||||
case TEMP_FPGA:
|
||||
retval=getBebFPGATemp()*1000;
|
||||
break;
|
||||
case TEMP_FPGAFEBL:
|
||||
retval=Feb_Control_GetLeftFPGATemp();
|
||||
break;
|
||||
case TEMP_FPGAFEBR:
|
||||
retval=Feb_Control_GetRightFPGATemp();
|
||||
break;
|
||||
case TEMP_FPGAEXT:
|
||||
case TEMP_10GE:
|
||||
case TEMP_DCDC:
|
||||
@ -533,12 +539,29 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec){//in nanosec (will never b
|
||||
return 0;
|
||||
}
|
||||
|
||||
//when dynamic range changes, use old tau
|
||||
else if(custom_tau_in_nsec == -1)
|
||||
custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
|
||||
|
||||
int dr = Feb_Control_GetDynamicRange();
|
||||
//get period = subexptime if 32bit , else period = exptime if 16 bit
|
||||
int64_t actual_period = Feb_Control_GetSubFrameExposureTime(); //already in nsec
|
||||
if(dr == 16)
|
||||
actual_period = Feb_Control_GetExposureTime_in_nsec();
|
||||
|
||||
int64_t ratetable_period_in_nsec = Feb_Control_Get_RateTable_Period_in_nsec();
|
||||
int64_t tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t subexp_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
|
||||
|
||||
//same setting
|
||||
if((tau_in_nsec == custom_tau_in_nsec) && (subexp_in_nsec == Feb_Control_GetSubFrameExposureTime())){
|
||||
if((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)){
|
||||
if(dr == 32)
|
||||
printf("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
|
||||
tau_in_nsec,subexp_in_nsec);
|
||||
tau_in_nsec,ratetable_period_in_nsec);
|
||||
else
|
||||
printf("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
|
||||
tau_in_nsec,ratetable_period_in_nsec);
|
||||
}
|
||||
//different setting, calculate table
|
||||
else{
|
||||
@ -731,7 +754,9 @@ int setThresholdEnergy(int ev, int imod){
|
||||
}
|
||||
|
||||
enum detectorSettings setSettings(enum detectorSettings sett, int imod){
|
||||
if(sett != GET_SETTINGS)
|
||||
if(sett == UNINITIALIZED){
|
||||
return thisSettings;
|
||||
}if(sett != GET_SETTINGS)
|
||||
thisSettings = sett;
|
||||
return thisSettings;
|
||||
}
|
||||
@ -833,25 +858,27 @@ enum runStatus getRunStatus(){
|
||||
|
||||
|
||||
|
||||
char *readFrame(int *ret, char *mess){
|
||||
//if(master){
|
||||
if(!Feb_Control_WaitForFinishedFlag(5000))
|
||||
cprintf(RED,"Error: Waiting for finished flag\n");
|
||||
cprintf(GREEN,"Acquisition finished***\n");
|
||||
void readFrame(int *ret, char *mess){
|
||||
if(!Feb_Control_WaitForFinishedFlag(5000))
|
||||
cprintf(RED,"Error: Waiting for finished flag\n");
|
||||
cprintf(GREEN,"Acquisition finished***\n");
|
||||
|
||||
if(eiger_storeinmem){
|
||||
printf("requesting images after storing in memory\n");
|
||||
if(startReadOut() == FAIL){
|
||||
cprintf(RED, "Could not read out images\n");
|
||||
*ret = (int)FAIL;
|
||||
return NULL;
|
||||
}
|
||||
if(eiger_storeinmem){
|
||||
printf("requesting images after storing in memory\n");
|
||||
if(startReadOut() == FAIL){
|
||||
strcpy(mess,"Could not execute read image requests\n");
|
||||
*ret = (int)FAIL;
|
||||
return;
|
||||
}
|
||||
//usleep(1000000);
|
||||
printf("*****Done Waiting...\n");
|
||||
//}
|
||||
*ret = (int)FINISHED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//wait for detector to send
|
||||
Beb_EndofDataSend(send_to_ten_gig);
|
||||
|
||||
|
||||
printf("*****Done Waiting...\n");
|
||||
*ret = (int)FINISHED;
|
||||
strcpy(mess,"acquisition successfully finished\n");
|
||||
}
|
||||
|
||||
|
||||
@ -1310,7 +1337,9 @@ int getBebFPGATemp(){
|
||||
|
||||
|
||||
int activate(int enable){
|
||||
return Beb_Activate(enable);
|
||||
int ret = Beb_Activate(enable);
|
||||
Feb_Control_activate(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define FEB_PORT 43210
|
||||
#define BEB_PORT 43212
|
||||
|
||||
#define REQUIRED_FIRMWARE_VERSION 14
|
||||
#define REQUIRED_FIRMWARE_VERSION 16
|
||||
|
||||
#define FIRMWAREREV 0xcaba //temporary should be in firmware
|
||||
|
||||
@ -40,9 +40,10 @@
|
||||
|
||||
enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD};
|
||||
|
||||
enum detAdcIndex{TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_FPGA};
|
||||
enum detAdcIndex{TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_FPGA, TEMP_FPGAFEBL, TEMP_FPGAFEBR};
|
||||
|
||||
enum detNetworkParameter{TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G};
|
||||
|
||||
|
||||
|
||||
#endif /* SLSDETECTORSERVER_DEFS_H_ */
|
||||
|
@ -61,6 +61,12 @@ XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR
|
||||
#define XPAR_PLB_GPIO_TEST_HIGHADDR 0xD101FFFF
|
||||
|
||||
|
||||
|
||||
/* Definitions for packet, frame and delay down counters */
|
||||
#define XPAR_COUNTER_BASEADDR 0xD1020000
|
||||
#define XPAR_COUNTER_HIGHADDR 0xD102FFFF
|
||||
|
||||
|
||||
/* Definitions for peripheral PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT */
|
||||
#define XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR 0xC4100000
|
||||
#define XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_HIGHADDR 0xC410FFFF
|
||||
|
@ -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: e9878a26ffb7e57c6e6724215e46ae5634871e64
|
||||
Revision: 1149
|
||||
Repsitory UUID: a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc
|
||||
Revision: 1297
|
||||
Branch: developer
|
||||
Last Changed Author: Dhanya_Maliakal
|
||||
Last Changed Rev: 1149
|
||||
Last Changed Date: 2016-08-24 16:47:14 +0200
|
||||
Last Changed Rev: 1297
|
||||
Last Changed Date: 2016-11-08 15:25:56 +0100
|
||||
|
@ -571,9 +571,15 @@ u_int32_t setClockDivider(int d, int ic) {
|
||||
|
||||
// int ic=0 is run clk; ic=1 is adc clk
|
||||
printf("set clk divider %d to %d\n", ic, d);
|
||||
if (ic>1)
|
||||
if (ic>2)
|
||||
return -1;
|
||||
|
||||
if (ic==2) {
|
||||
printf("dbit clock is the same as adc clk\n");
|
||||
ic=1;
|
||||
|
||||
}
|
||||
|
||||
if (ic==1 && d>40)
|
||||
return -1;
|
||||
|
||||
@ -621,6 +627,17 @@ int phaseStep(int st){
|
||||
return clkPhase[0];
|
||||
}
|
||||
|
||||
int dbitPhaseStep(int st){
|
||||
|
||||
printf("dbit clock is the same as adc clk\n");
|
||||
return phaseStep(st);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getPhase() {
|
||||
return clkPhase[0];
|
||||
@ -628,10 +645,25 @@ int getPhase() {
|
||||
};
|
||||
|
||||
|
||||
|
||||
int getDbitPhase() {
|
||||
|
||||
printf("dbit clock is the same as adc clk\n");
|
||||
return getPhase();
|
||||
|
||||
};
|
||||
|
||||
|
||||
u_int32_t getClockDivider(int ic) {
|
||||
|
||||
if (ic>1)
|
||||
if (ic>2)
|
||||
return -1;
|
||||
|
||||
if (ic==2) {
|
||||
printf("dbit clock is the same as adc clk\n");
|
||||
ic=1;
|
||||
|
||||
}
|
||||
return clkDivider[ic];
|
||||
|
||||
|
||||
@ -667,9 +699,24 @@ u_int32_t getClockDivider(int ic) {
|
||||
|
||||
|
||||
u_int32_t adcPipeline(int d) {
|
||||
if (d>=0)
|
||||
bus_w(DAQ_REG, d);
|
||||
return bus_r(DAQ_REG)&0xff;
|
||||
u_int32_t v;
|
||||
if (d>=0) {
|
||||
v=bus_r(ADC_PIPELINE_REG)&0x00ff0000;
|
||||
bus_w(ADC_PIPELINE_REG, d|v);
|
||||
}
|
||||
return bus_r(ADC_PIPELINE_REG)&0xff;
|
||||
}
|
||||
|
||||
|
||||
u_int32_t dbitPipeline(int d) {
|
||||
u_int32_t v;
|
||||
if (d>=0) {
|
||||
v=bus_r(ADC_PIPELINE_REG)&0x000000ff;
|
||||
bus_w(ADC_PIPELINE_REG, v|(d<<16));
|
||||
|
||||
}
|
||||
v=bus_r(ADC_PIPELINE_REG)>>16;
|
||||
return v&0xff;
|
||||
}
|
||||
|
||||
|
||||
@ -1273,7 +1320,7 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){
|
||||
v64=value>> 32;
|
||||
vMSB=v64&(0xffffffff);
|
||||
bus_w(aMSB,vMSB);
|
||||
printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value);
|
||||
// printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value);
|
||||
}
|
||||
return get64BitReg(aLSB, aMSB);
|
||||
|
||||
@ -1287,7 +1334,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
|
||||
v64=vMSB;
|
||||
v64=(v64<<32) | vLSB;
|
||||
|
||||
printf("reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, v64);
|
||||
// printf("reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, v64);
|
||||
|
||||
return v64;
|
||||
}
|
||||
@ -2142,52 +2189,20 @@ u_int16_t* fifo_read_event(int ns)
|
||||
// printf("LAM: %08x\n",a);
|
||||
}
|
||||
|
||||
|
||||
// printf(".");
|
||||
a = bus_r(LOOK_AT_ME_REG);
|
||||
|
||||
if (analogEnable) {
|
||||
printf("*");
|
||||
bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos
|
||||
bus_w16(DUMMY_REG,0);
|
||||
|
||||
/* for (i=0; i<32; i++) { */
|
||||
/* bus_w16(DUMMY_REG,i); */
|
||||
/* printf("%04x ",bus_r16(FIFO_STATUS_REG)); */
|
||||
/* // a = bus_r(LOOK_AT_ME_REG); */
|
||||
/* // printf("%d %08x\n",i,a); */
|
||||
/* } */
|
||||
/* printf("\n"); */
|
||||
// i=0;//
|
||||
/* for (i=0; i<32; i++) { */
|
||||
|
||||
/* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */
|
||||
/* /\* i++; *\/ */
|
||||
/* /\* if (i>15) *\/ */
|
||||
/* /\* break; *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* if (i<16) { *\/ */
|
||||
/* bus_w16(DUMMY_REG,i); */
|
||||
/* } */
|
||||
/* val=*values; */
|
||||
//printf("sample %d ",ns);
|
||||
|
||||
// bus_w16(DUMMY_REG,0); //
|
||||
for (i=0; i<32; i++) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (~(mask&adcDisableMask)) {
|
||||
*((u_int16_t*)now_ptr)=*values;//bus_r16(FIFO_DATA_REG);//*values;//bus_r(FIFO_DATA_REG);
|
||||
|
||||
|
||||
*((u_int16_t*)now_ptr)=*values;//bus_r16(FIFO_DATA_REG);
|
||||
if (i!=0 || ns!=0) {
|
||||
a=0;
|
||||
while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10) {
|
||||
|
||||
// printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1));
|
||||
*((u_int16_t*)now_ptr)=*values;
|
||||
// printf(".",i);
|
||||
|
||||
}
|
||||
}
|
||||
now_ptr+=2;
|
||||
@ -2195,15 +2210,10 @@ u_int16_t* fifo_read_event(int ns)
|
||||
mask=mask<<1;
|
||||
// if (~(mask&adcDisableMask)
|
||||
bus_w16(DUMMY_REG,i+1);
|
||||
|
||||
// a = bus_r(LOOK_AT_ME_REG);
|
||||
// printf("%d %08x\n",i,a);
|
||||
//#ifdef VERBOSE
|
||||
// }
|
||||
// *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG);
|
||||
}
|
||||
}
|
||||
if (digitalEnable) {
|
||||
printf("+");
|
||||
|
||||
bus_w16(DUMMY_REG,1<<9); // read strobe to digital fifo
|
||||
bus_w16(DUMMY_REG,0<<9); // read strobe to digital fifo
|
||||
@ -2776,8 +2786,13 @@ int prepareADC(){
|
||||
cdx=0; ddx=1;
|
||||
csmask=0x7c; // 1111100
|
||||
|
||||
/* #define ADCREG1 0x08 */
|
||||
/* #define ADCREG2 0x14//20 */
|
||||
/* #define ADCREG3 0x4 */
|
||||
/* #define ADCREG4 0x5 */
|
||||
codata=0;
|
||||
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
|
||||
writeADC(ADCREG1,0x3);
|
||||
writeADC(ADCREG1,0x0);
|
||||
|
||||
|
||||
writeADC(ADCREG3,0xf);
|
||||
@ -2831,9 +2846,9 @@ int prepareADC(){
|
||||
|
||||
|
||||
bus_w(ADC_LATCH_DISABLE_REG,0x0); // enable all ADCs
|
||||
bus_w(DAQ_REG,0x12); //adc pipeline=18
|
||||
// bus_w(DAQ_REG,0x12); //adc pipeline=18
|
||||
|
||||
bus_w(DAQ_REG,0xbbbbbbbb);
|
||||
//bus_w(DAQ_REG,0xbbbbbbbb);
|
||||
// bus_w(ADC_INVERSION_REG,0x1f6170c6);
|
||||
|
||||
return OK;
|
||||
@ -3764,7 +3779,23 @@ int setPower(int ind, int val) {
|
||||
|
||||
|
||||
|
||||
int powerChip(int arg) {
|
||||
//#ifndef CTB
|
||||
u_int32_t preg=bus_r(POWER_ON_REG);
|
||||
if (arg>=0) {
|
||||
if (arg)
|
||||
bus_w(POWER_ON_REG,preg|0xffff0000);
|
||||
else
|
||||
bus_w(POWER_ON_REG,preg&0x0000ffff);
|
||||
preg=bus_r(POWER_ON_REG);
|
||||
}
|
||||
|
||||
printf("Power register is %08x\n",preg);
|
||||
if (preg&0xffff0000)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3798,12 +3829,12 @@ int nextDac(){
|
||||
valw=0xffff&(~(0x1<<csdx));
|
||||
|
||||
|
||||
#ifdef CTB
|
||||
if (myDetectorType==JUNGFRAUCTB)
|
||||
for (i=0;i<8;i++) {
|
||||
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
|
||||
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
codata=((0xf)<<DAC_CMD_OFF); // no operation
|
||||
// printf("%08x\n",codata);
|
||||
@ -3851,23 +3882,25 @@ int setThisDac(int dacnum,int dacvalue){
|
||||
int dacch=0;
|
||||
|
||||
ddx=0; cdx=1;
|
||||
#ifdef CTB
|
||||
csdx=2;
|
||||
#else
|
||||
csdx=dacnum/8+2;
|
||||
#endif
|
||||
|
||||
|
||||
if (myDetectorType==JUNGFRAUCTB)
|
||||
csdx=2;
|
||||
else
|
||||
csdx=dacnum/8+2;
|
||||
|
||||
dacch=dacnum%8;
|
||||
//setting int reference
|
||||
offw=DAC_REG;
|
||||
|
||||
valw=0xffff&(~(0x1<<csdx));
|
||||
|
||||
#ifdef CTB
|
||||
for (i=0;i<8;i++) {
|
||||
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
|
||||
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
|
||||
}
|
||||
#endif
|
||||
/* if (myDetectorType==JUNGFRAUCTB) */
|
||||
/* for (i=0;i<8;i++) { */
|
||||
/* valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn */
|
||||
/* valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup */
|
||||
/* } */
|
||||
|
||||
// printf("**************************************************set dac\n");
|
||||
if (dacvalue>=0) {
|
||||
|
||||
@ -3892,15 +3925,15 @@ int setThisDac(int dacnum,int dacvalue){
|
||||
//printf("%08x\n",codata);
|
||||
|
||||
|
||||
for (i=1;i<25;i++) {
|
||||
// printf("%d",((codata>>(24-i)))&0x1);
|
||||
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
|
||||
valw=((valw&(~(0x1<<ddx)))+(((codata>>(24-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i)
|
||||
for (i=1;i<25;i++) {
|
||||
// printf("%d",((codata>>(24-i)))&0x1);
|
||||
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
|
||||
valw=((valw&(~(0x1<<ddx)))+(((codata>>(24-i))&0x1)<<ddx));bus_w(offw,valw);//write data (i)
|
||||
// printf("%d ", ((codata>>(24-i))&0x1));
|
||||
|
||||
|
||||
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
|
||||
}
|
||||
|
||||
|
||||
valw=((valw&(~(0x1<<cdx)))+(0x1<<cdx));bus_w(offw,valw);//clkup
|
||||
}
|
||||
|
||||
// printf("\n ");
|
||||
|
||||
@ -3930,17 +3963,22 @@ int setDac(int dacnum,int dacvalue){
|
||||
int i,ddx,csdx,cdx;
|
||||
|
||||
int dacch=0;
|
||||
|
||||
ichip=2-dacnum/8;
|
||||
if (myDetectorType==JUNGFRAUCTB)
|
||||
ichip=2-dacnum/8;
|
||||
else
|
||||
ichip=dacnum/8;
|
||||
|
||||
if (myDetectorType==JUNGFRAUCTB) printf("This is a CTB\n");
|
||||
else printf("This is not a CTB\n");
|
||||
|
||||
|
||||
if (dacvalue!=-1) {
|
||||
printf("************************************************** set dac %d chip %d value %d ------ %d\n", dacnum, ichip, dacvalue, DAC_CMD_OFF);
|
||||
printf("************** set dac %d chip %d value %d ------ %d\n", dacnum, ichip, dacvalue, DAC_CMD_OFF);
|
||||
ddx=0; cdx=1;
|
||||
#ifdef CTB
|
||||
csdx=2;
|
||||
#else
|
||||
csdx=dacnum/8+2;
|
||||
#endif
|
||||
if (myDetectorType==JUNGFRAUCTB)
|
||||
csdx=2;
|
||||
else
|
||||
csdx=ichip+2;
|
||||
//setting int reference
|
||||
offw=DAC_REG;
|
||||
|
||||
@ -3949,21 +3987,20 @@ int setDac(int dacnum,int dacvalue){
|
||||
valw=((valw&(~(0x1<<csdx))));bus_w(offw,valw); //chip sel bar down
|
||||
valw=(valw&(~(0x1<<cdx)));bus_w(offw,valw); //cldwn
|
||||
|
||||
#ifdef CTB
|
||||
for (i=0; i<ichip; i++) {
|
||||
// printf("--------before %d ",i);
|
||||
nextDac();
|
||||
}
|
||||
#endif
|
||||
// printf("--------thisdac %d ",i);
|
||||
//#ifdef CTB
|
||||
if (myDetectorType==JUNGFRAUCTB) for (i=0; i<ichip; i++) {nextDac();printf("next DAC\n");}
|
||||
|
||||
//#endif
|
||||
printf("--------thisdac %d ",i);
|
||||
setThisDac(dacnum,dacvalue);
|
||||
// printf("--------thisdac %d ",i);
|
||||
#ifdef CTB
|
||||
for (i=ichip+1; i<3; i++) {
|
||||
|
||||
// printf("--------after %d ",i);
|
||||
|
||||
if (myDetectorType==JUNGFRAUCTB) {
|
||||
nextDac();
|
||||
printf("next DAC\n");
|
||||
}
|
||||
#endif
|
||||
valw=bus_r(offw);
|
||||
valw=(valw|(0x1<<csdx));bus_w(offw,valw); //csup
|
||||
|
||||
|
@ -30,6 +30,8 @@ u_int32_t bus_r(u_int32_t offset);
|
||||
|
||||
int setPhaseShiftOnce();
|
||||
int phaseStep(int st);
|
||||
int dbitPhaseStep(int st);
|
||||
int getDbitPhase();
|
||||
int getPhase();
|
||||
int cleanFifo();
|
||||
int setDAQRegister();
|
||||
@ -53,6 +55,7 @@ u_int32_t setTotDutyCycle(int d);
|
||||
u_int32_t getTotDutyCycle();
|
||||
u_int32_t setOversampling(int d);
|
||||
u_int32_t adcPipeline(int d);
|
||||
u_int32_t dbitPipeline(int d);
|
||||
|
||||
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
|
||||
int getExtSignal(int d);
|
||||
|
Binary file not shown.
@ -14,6 +14,7 @@
|
||||
int (*flist[256])(int);
|
||||
|
||||
|
||||
|
||||
//defined in the detector specific file
|
||||
/* #ifdef MYTHEND */
|
||||
/* const enum detectorType myDetectorType=MYTHEN; */
|
||||
@ -334,6 +335,7 @@ int function_table() {
|
||||
flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal;
|
||||
flist[F_SET_CTB_PATTERN]=&set_ctb_pattern;
|
||||
flist[F_WRITE_ADC_REG]=&write_adc_register;
|
||||
flist[F_POWER_CHIP]=&power_chip;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -420,7 +422,7 @@ int get_detector_type(int file_des) {
|
||||
|
||||
/* receive arguments */
|
||||
/* execute action */
|
||||
ret=myDetectorType;
|
||||
ret=JUNGFRAUCTB;//myDetectorType;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Returning detector type %d\n",ret);
|
||||
@ -2537,6 +2539,8 @@ int set_speed(int file_des) {
|
||||
|
||||
retval=phaseStep(val);
|
||||
|
||||
} else if ( arg==DBIT_PHASE) {
|
||||
retval=dbitPhaseStep(val);
|
||||
} else {
|
||||
|
||||
|
||||
@ -2564,9 +2568,10 @@ int set_speed(int file_des) {
|
||||
retval=setClockDivider(val,1);
|
||||
break;
|
||||
|
||||
/* case ADC_PHASE: */
|
||||
/* retval=phaseStep(val,1); */
|
||||
/* break; */
|
||||
case DBIT_CLOCK:
|
||||
retval=setClockDivider(val,2);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case ADC_PIPELINE:
|
||||
@ -2574,6 +2579,11 @@ int set_speed(int file_des) {
|
||||
break;
|
||||
|
||||
|
||||
case DBIT_PIPELINE:
|
||||
retval=dbitPipeline(val);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
ret=FAIL;
|
||||
@ -2606,16 +2616,29 @@ int set_speed(int file_des) {
|
||||
retval=getClockDivider(1);
|
||||
break;
|
||||
|
||||
case DBIT_CLOCK:
|
||||
retval=getClockDivider(2);
|
||||
break;
|
||||
|
||||
case ADC_PHASE:
|
||||
retval=getPhase();
|
||||
break;
|
||||
|
||||
case DBIT_PHASE:
|
||||
retval=getDbitPhase();
|
||||
break;
|
||||
|
||||
|
||||
case ADC_PIPELINE:
|
||||
retval=adcPipeline(-1);
|
||||
break;
|
||||
|
||||
|
||||
case DBIT_PIPELINE:
|
||||
retval=dbitPipeline(-1);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Unknown speed parameter %d",arg);
|
||||
@ -3546,3 +3569,51 @@ int write_adc_register(int file_des) {
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int power_chip(int file_des) {
|
||||
|
||||
int retval=-1;
|
||||
int ret=OK;
|
||||
int arg=-1;
|
||||
int n;
|
||||
|
||||
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Power chip to %d\n", arg);
|
||||
#endif
|
||||
|
||||
if (differentClients==1 && lockStatus==1 && arg!=-1) {
|
||||
ret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
} else {
|
||||
retval=powerChip(arg);
|
||||
#ifdef VERBOSE
|
||||
printf("Chip powered: %d\n",retval);
|
||||
#endif
|
||||
|
||||
if (retval==arg || arg<0) {
|
||||
ret=OK;
|
||||
} else {
|
||||
ret=FAIL;
|
||||
printf("Powering chip failed, wrote %d but read %d\n", arg, retval);
|
||||
}
|
||||
|
||||
}
|
||||
if (ret==OK && differentClients==1)
|
||||
ret=FORCE_UPDATE;
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n += sendDataOnly(file_des,mess,sizeof(mess));
|
||||
} else
|
||||
n += sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -94,5 +94,6 @@ int calibrate_pedestal(int);
|
||||
int set_roi(int);
|
||||
int set_ctb_pattern(int);
|
||||
|
||||
int write_adc_register(int);;
|
||||
int write_adc_register(int);
|
||||
int power_chip(int);
|
||||
#endif
|
||||
|
1
slsDetectorSoftware/jungfrauDetectorServer/.gitignore
vendored
Normal file
1
slsDetectorSoftware/jungfrauDetectorServer/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.gdb
|
@ -6,17 +6,17 @@
|
||||
CROSS = bfin-uclinux-
|
||||
CC = $(CROSS)gcc
|
||||
|
||||
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER
|
||||
CFLAGS += -Wall -DJUNGFRAUD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL
|
||||
|
||||
|
||||
PROGS= jungfrauDetectorServerTest
|
||||
PROGS= jungfrauDetectorServer
|
||||
INSTDIR= /tftpboot
|
||||
INSTMODE= 0777
|
||||
|
||||
|
||||
|
||||
BINS = testlib_sharedlibc
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c sharedmemory.c
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
||||
|
||||
@ -27,15 +27,11 @@ test: clean jungfrauADCTEst
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
jungfrauDetectorServerTest: $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
|
||||
|
||||
|
||||
jungfrauDetectorServer: $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
|
||||
|
||||
|
||||
jungfrauADCTEst: $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) -DTESTADC
|
||||
|
11
slsDetectorSoftware/jungfrauDetectorServer/README.txt
Normal file
11
slsDetectorSoftware/jungfrauDetectorServer/README.txt
Normal file
@ -0,0 +1,11 @@
|
||||
add the following to /etc/rc before using programfpga command before cat motd
|
||||
|
||||
|
||||
#registering 7th and 9th pin to linux kernel
|
||||
echo 7 > /sys/class/gpio/export
|
||||
echo 9 > /sys/class/gpio/export
|
||||
#define direction for the linux kernel
|
||||
echo in > /sys/class/gpio/gpio7/direction
|
||||
echo out > /sys/class/gpio/gpio9/direction
|
||||
#needed, else all write errors when server starts up, because linux tries to take control fof gpio
|
||||
echo 1 > /sys/class/gpio/gpio9/value
|
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,12 @@
|
||||
|
||||
|
||||
int mapCSP0(void);
|
||||
void defineGPIOpins();
|
||||
void resetFPGA();
|
||||
void FPGAdontTouchFlash();
|
||||
void FPGATouchFlash();
|
||||
int powerChip (int on);
|
||||
void initializeDetector();
|
||||
|
||||
u_int16_t bus_r16(u_int32_t offset);
|
||||
u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function
|
||||
@ -29,15 +35,15 @@ u_int32_t bus_w(u_int32_t offset, u_int32_t data);
|
||||
u_int32_t bus_r(u_int32_t offset);
|
||||
|
||||
int setPhaseShiftOnce();
|
||||
int phaseStep(int st);
|
||||
int adcPhase(int st);
|
||||
int getPhase();
|
||||
int cleanFifo();
|
||||
int setDAQRegister();
|
||||
|
||||
u_int32_t putout(char *s, int modnum);
|
||||
u_int32_t readin(int modnum);
|
||||
u_int32_t setClockDivider(int d, int ic);
|
||||
u_int32_t getClockDivider(int ic);
|
||||
u_int32_t setClockDivider(int d);
|
||||
u_int32_t getClockDivider();
|
||||
|
||||
void resetPLL();
|
||||
u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig);
|
||||
@ -53,6 +59,7 @@ u_int32_t setTotDutyCycle(int d);
|
||||
u_int32_t getTotDutyCycle();
|
||||
u_int32_t setOversampling(int d);
|
||||
u_int32_t adcPipeline(int d);
|
||||
u_int32_t dbitPipeline(int d);
|
||||
|
||||
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
|
||||
int getExtSignal(int d);
|
||||
@ -66,7 +73,6 @@ int setTiming(int t);
|
||||
int setConfigurationRegister(int d);
|
||||
int setToT(int d);
|
||||
int setContinousReadOut(int d);
|
||||
int startReceiver(int d);
|
||||
|
||||
int setDACRegister(int idac, int val, int imod);
|
||||
int getDacRegister(int dacnum);
|
||||
@ -75,6 +81,7 @@ int getDacRegister(int dacnum);
|
||||
int getTemperature(int tempSensor,int imod);
|
||||
int initHighVoltage(int val,int imod);
|
||||
int initConfGain(int isettings,int val,int imod);
|
||||
int initSpeedConfGain(int val);
|
||||
|
||||
int setADC(int adc);
|
||||
//int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int udpport);
|
||||
@ -143,9 +150,7 @@ u_int32_t fifoReadStatus();
|
||||
u_int32_t fifo_full(void);
|
||||
|
||||
|
||||
|
||||
u_int16_t* fifo_read_event(int ns);
|
||||
u_int16_t* fifo_read_frame();
|
||||
void waitForAcquisitionEnd();
|
||||
u_int32_t* decode_data(int* datain);
|
||||
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
|
||||
int setDynamicRange(int dr);
|
||||
@ -188,6 +193,11 @@ int setDac(int dacnum,int dacvalue);
|
||||
ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret);
|
||||
int getChannels();
|
||||
|
||||
void eraseFlash();
|
||||
int startWritingFPGAprogram(FILE** filefp);
|
||||
int stopWritingFPGAprogram(FILE* filefp);
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp);
|
||||
|
||||
/*
|
||||
|
||||
u_int32_t setNBits(u_int32_t);
|
||||
|
@ -1,9 +1,9 @@
|
||||
Path: slsDetectorsPackage/slsDetectorSoftware/moenchDetectorServer
|
||||
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer
|
||||
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
|
||||
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
|
||||
Revision: 55
|
||||
Branch: separate_receiver
|
||||
Last Changed Author: Maliakal_Dhanya
|
||||
Last Changed Rev: 14
|
||||
Last Changed Date: 2014-06-03 12:26:45 +0200
|
||||
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
|
||||
Branch: developer
|
||||
Last Changed Author: Dhanya_Maliakal
|
||||
Last Changed Rev: 1296
|
||||
Last Changed Date: 2016-11-08 15:25:16 +0100
|
||||
|
11
slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h
Normal file
11
slsDetectorSoftware/jungfrauDetectorServer/gitInfoJungfrau.h
Normal file
@ -0,0 +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 SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH "Dhanya_Maliakal"
|
||||
#define SVNREV 0x1296
|
||||
#define SVNDATE 0x20161108
|
||||
//
|
@ -1,11 +0,0 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer"
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
|
||||
//#define SVNREV 0x14
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH "Maliakal_Dhanya"
|
||||
#define SVNREV 0x14
|
||||
#define SVNDATE 0x20140603
|
||||
//
|
Binary file not shown.
Binary file not shown.
BIN
slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.0
Executable file
BIN
slsDetectorSoftware/jungfrauDetectorServer/jungfrauDetectorServerv2.2.0
Executable file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -10,6 +10,15 @@
|
||||
#define MEM_SIZE 0x100000
|
||||
|
||||
|
||||
//Constants
|
||||
#define HALFSPEED_DBIT_PIPELINE 0x7f7c
|
||||
#define QUARTERSPEED_DBIT_PIPELINE 0x8981
|
||||
#define HALFSPEED_ADC_PIPELINE 0x20
|
||||
#define QUARTERSPEED_ADC_PIPELINE 0x10
|
||||
#define HALFSPEED_CONF 0x0
|
||||
#define QUARTERSPEED_CONF 0xf
|
||||
#define HALFSPEED_ADC_PHASE 65
|
||||
#define QUARTERSPEED_ADC_PHASE 25
|
||||
|
||||
/* values defined for FPGA */
|
||||
#define MCSNUM 0x0
|
||||
@ -21,23 +30,23 @@
|
||||
|
||||
//#ifdef JUNGFRAU_DHANYA
|
||||
#define POWER_ON_REG 0x5e<<11
|
||||
#define ADCREG1 8 //same as PLL_BANDWIDTH_REG
|
||||
#define ADCREG2 20 //0x14
|
||||
#define ADCREG3 4 //same as PLL_M_COUNTER_REG
|
||||
#define ADCREG4 5 //same as PLL_C_COUNTER_REG
|
||||
#define ADCREG_VREFS 24 //0x18
|
||||
#define DBIT_PIPELINE_REG 89<<11 //0x59 same PATTERN_N_LOOP2_REG
|
||||
#define MEM_MACHINE_FIFOS_REG 79<<11 //0x4f same as CONTROL_REG
|
||||
#define CONFGAIN_REG 93<<11 //0x5d same as DAQ_REG
|
||||
#define ADC_PIPELINE_REG 66<<11 //0x42 same as ADC_OFFSET_REG
|
||||
#define ADCREG1 0x8 //same as PLL_BANDWIDTH_REG
|
||||
#define ADCREG2 0x14
|
||||
#define ADCREG3 0x4 //same as PLL_M_COUNTER_REG
|
||||
#define ADCREG4 0x5 //same as PLL_C_COUNTER_REG
|
||||
#define ADCREG_VREFS 0x18
|
||||
#define DBIT_PIPELINE_REG 0x59<<11 //same PATTERN_N_LOOP2_REG
|
||||
#define MEM_MACHINE_FIFOS_REG 0x4f<<11 //same as CONTROL_REG
|
||||
#define CONFGAIN_REG 0x5d<<11 //same as DAQ_REG
|
||||
#define ADC_PIPELINE_REG 0x42<<11 //same as ADC_OFFSET_REG
|
||||
//#endif
|
||||
|
||||
#define ADC_OFFSET_REG 66<<11 //same as ADC_PIPELINE_REG
|
||||
#define ADC_INVERSION_REG 67<<11
|
||||
//#define ADC_OFFSET_REG 66<<11 //same as CONFGAIN_REG
|
||||
#define ADC_INVERSION_REG 0x43<<11
|
||||
|
||||
#define DAC_REG 64<<11//0x17<<11// control the dacs
|
||||
#define DAC_REG 64<<11//0x17<<11// control the dacs
|
||||
//ADC
|
||||
#define ADC_WRITE_REG 65<<11//0x18<<11
|
||||
#define ADC_WRITE_REG 65<<11//0x18<<11
|
||||
//#define ADC_SYNC_REG 66<<11//0x19<<11
|
||||
//#define HV_REG 67<<11//0x20<<11
|
||||
|
||||
@ -55,7 +64,7 @@
|
||||
//HV
|
||||
|
||||
|
||||
#define DUMMY_REG 68<<11//0x21<<11
|
||||
#define DUMMY_REG 0x44<<11
|
||||
#define FPGA_VERSION_REG 0<<11 //0x22<<11
|
||||
#define PCB_REV_REG 0<<11
|
||||
#define FIX_PATT_REG 1<<11 //0x23<<11
|
||||
@ -182,7 +191,7 @@
|
||||
|
||||
|
||||
|
||||
#define DAQ_REG 93<<11
|
||||
//#define DAQ_REG 0x5d<<11 //same as CONFGAIN_REG
|
||||
#define ADC_LATCH_DISABLE_REG 94<<11
|
||||
|
||||
#define HV_REG 95<<11
|
||||
@ -303,7 +312,7 @@
|
||||
#define RUNSTATE_0_BIT 0x00001000
|
||||
#define RUNSTATE_1_BIT 0x00002000
|
||||
#define RUNSTATE_2_BIT 0x00004000
|
||||
#define STOPPED_BIT 0x00008000 // error!
|
||||
#define STOPPED_BIT 0x00008000 // stopped!
|
||||
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
|
||||
#define RUNMACHINE_BUSY_BIT 0x00020000
|
||||
#define READMACHINE_BUSY_BIT 0x00040000
|
||||
@ -409,10 +418,11 @@
|
||||
|
||||
|
||||
/* settings/conf gain register */
|
||||
#define GAIN_MASK 0x0000000f
|
||||
#define GAIN_MASK 0x0000ffff
|
||||
#define GAIN_OFFSET 0
|
||||
#define SETTINGS_MASK 0x000000f0
|
||||
#define SETTINGS_OFFSET 4
|
||||
#define SPEED_GAIN_MASK 0xf0000000
|
||||
#define SPEED_GAIN_OFFSET 28
|
||||
|
||||
|
||||
|
||||
/* CHIP_OF_INTRST_REG */
|
||||
|
@ -27,7 +27,6 @@ int main(int argc, char *argv[])
|
||||
int retval=OK;
|
||||
int sd, fd;
|
||||
int iarg;
|
||||
int checkType = 1;
|
||||
|
||||
|
||||
for(iarg=1; iarg<argc; iarg++){
|
||||
@ -48,13 +47,6 @@ int main(int argc, char *argv[])
|
||||
printf("No test condition given. Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
if(!strcasecmp(argv[iarg+1],"with_gotthard")){
|
||||
checkType = 0;
|
||||
}else{
|
||||
printf("could not decode test condition. Possible arguments: with_gotthard. Exiting\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,31 +60,21 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
b=0;
|
||||
printf("\n\nStop Server\nOpening stop server on port %d\n",portno);
|
||||
checkType=0;
|
||||
|
||||
}
|
||||
|
||||
//control server
|
||||
else {
|
||||
portno = DEFAULT_PORTNO;
|
||||
if(checkType)
|
||||
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
|
||||
else
|
||||
sprintf(cmd,"%s %d stopserver -test with_gotthard &",argv[0],DEFAULT_PORTNO+1);
|
||||
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
|
||||
printf("\n\nControl Server\nOpening control server on port %d\n",portno );
|
||||
|
||||
//printf("\n\ncmd:%s\n",cmd);
|
||||
system(cmd);
|
||||
b=1;
|
||||
checkType=1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
init_detector(b, checkType);
|
||||
init_detector(b);
|
||||
|
||||
|
||||
sd=bindSocket(portno);
|
||||
|
@ -7,23 +7,15 @@
|
||||
|
||||
|
||||
// Hardware definitions
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD (NMAXMODX*NMAXMODY)
|
||||
|
||||
#define NCHAN 32
|
||||
#define NCHIP 1
|
||||
#define NADC 1
|
||||
#define NDAC 16
|
||||
#define NMAXMODX 1
|
||||
#define NCHANS (NCHAN*NCHIP*NMAXMOD)
|
||||
#define NDACS (NDAC*NMAXMOD)
|
||||
|
||||
#define JUNGFRAU_NCHAN (256*256)
|
||||
#define JUNGFRAU_NCHIP 8
|
||||
#define JUNGFRAU_NADC 0
|
||||
#define JUNGFRAU_NDAC 16
|
||||
#define JUNGFRAU_NCHANS (JUNGFRAU_NCHAN*JUNGFRAU_NCHIP*NMAXMOD)
|
||||
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMODX 1
|
||||
#define NMAXMOD (NMAXMODX*NMAXMODY)
|
||||
#define NCHAN (256*256)
|
||||
#define NCHIP 8
|
||||
#define NADC 0
|
||||
#define NDAC 16
|
||||
#define NCHANS (NCHAN*NCHIP*NMAXMOD)
|
||||
#define NDACS (NDAC*NMAXMOD)
|
||||
|
||||
|
||||
/**when moench readout tested with gotthard module*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@ int sockfd;
|
||||
int function_table();
|
||||
|
||||
int decode_function(int);
|
||||
int init_detector(int,int);
|
||||
int init_detector(int);
|
||||
|
||||
int M_nofunc(int);
|
||||
int exit_server(int);
|
||||
@ -95,4 +95,8 @@ int set_roi(int);
|
||||
int set_ctb_pattern(int);
|
||||
|
||||
int write_adc_register(int);;
|
||||
|
||||
int program_fpga(int);
|
||||
int reset_fpga(int);
|
||||
int power_chip(int);
|
||||
#endif
|
||||
|
@ -1,39 +0,0 @@
|
||||
#include "sharedmemory.h"
|
||||
|
||||
struct statusdata *stdata;
|
||||
|
||||
int inism(int clsv) {
|
||||
|
||||
static int scansmid;
|
||||
|
||||
if (clsv==SMSV) {
|
||||
if ( (scansmid=shmget(SMKEY,1024,IPC_CREAT | 0666 ))==-1 ) {
|
||||
return -1;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (clsv==SMCL) {
|
||||
if ( (scansmid=shmget(SMKEY,0,0) )==-1 ) {
|
||||
return -3;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void write_status_sm(char *status) {
|
||||
strcpy(stdata->status,status);
|
||||
}
|
||||
|
||||
void write_stop_sm(int v) {
|
||||
stdata->stop=v;
|
||||
}
|
||||
|
||||
void write_runnumber_sm(int v) {
|
||||
stdata->runnumber=v;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
#ifndef SM
|
||||
#define SM
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
//#include <asm/page.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* key for shared memory */
|
||||
#define SMKEY 10001
|
||||
|
||||
#define SMSV 1
|
||||
#define SMCL 2
|
||||
|
||||
|
||||
struct statusdata {
|
||||
int runnumber;
|
||||
int stop;
|
||||
char status[20];
|
||||
} ;
|
||||
|
||||
|
||||
/* for shared memory */
|
||||
|
||||
int inism(int clsv);
|
||||
void write_status_sm(char *status);
|
||||
void write_stop_sm(int v);
|
||||
void write_runnumber_sm(int v);
|
||||
|
||||
#endif
|
@ -23,6 +23,8 @@ ID: $Id$
|
||||
#include <sys/shm.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <zmq.h>
|
||||
#include <rapidjson/document.h> //to scan json header in zmq stream
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -266,6 +268,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
||||
|
||||
getNMods();
|
||||
getMaxMods();
|
||||
threadStarted = false;
|
||||
threadpool = 0;
|
||||
if(createThreadPool() == FAIL)
|
||||
exit(-1);
|
||||
@ -299,7 +302,7 @@ int multiSlsDetector::createThreadPool(){
|
||||
break;
|
||||
default:
|
||||
#ifdef VERBOSE
|
||||
cout << "Initialized Threadpool" << endl;
|
||||
cout << "Initialized Threadpool " << threadpool << endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@ -311,7 +314,7 @@ void multiSlsDetector::destroyThreadPool(){
|
||||
threadpool->destroy_threadpool();
|
||||
threadpool=0;
|
||||
#ifdef VERBOSE
|
||||
cout<<"Destroyed Threadpool"<<endl;
|
||||
cout<<"Destroyed Threadpool "<< threadpool << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -392,7 +395,6 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
|
||||
|
||||
//set offsets
|
||||
updateOffsets();
|
||||
destroyThreadPool();
|
||||
if(createThreadPool() == FAIL)
|
||||
exit(-1);
|
||||
|
||||
@ -654,7 +656,6 @@ int multiSlsDetector::setDetectorId(int ival, int pos){
|
||||
|
||||
int multiSlsDetector::addSlsDetector(const char *name, int pos) {
|
||||
|
||||
|
||||
detectorType t=getDetectorType(string(name));
|
||||
int online=0;
|
||||
slsDetector *s=NULL;
|
||||
@ -694,6 +695,8 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) {
|
||||
t=slsDetector::getDetectorType(name, DEFAULT_PORTNO);
|
||||
if (t==GENERIC) {
|
||||
cout << "Detector " << name << "does not exist in shared memory and could not connect to it to determine the type (which is not specified)!" << endl;
|
||||
setErrorMask(getErrorMask()|MULTI_DETECTORS_NOT_ADDED);
|
||||
appendNotAddedList(name);
|
||||
return -1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
@ -864,7 +867,6 @@ int multiSlsDetector::removeSlsDetector(int pos) {
|
||||
}
|
||||
|
||||
updateOffsets();
|
||||
destroyThreadPool();
|
||||
if(createThreadPool() == FAIL)
|
||||
exit(-1);
|
||||
|
||||
@ -1196,6 +1198,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=posmin; idet<posmax; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -1243,6 +1246,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=posmin; idet<posmax; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -1346,7 +1350,6 @@ int multiSlsDetector::startAcquisition(){
|
||||
|
||||
|
||||
int multiSlsDetector::stopAcquisition(){
|
||||
|
||||
int i=0;
|
||||
int ret=OK, ret1=OK;
|
||||
|
||||
@ -1436,24 +1439,27 @@ int* multiSlsDetector::getDataFromDetector() {
|
||||
#ifdef VERBOSE
|
||||
cout << "Detector " << id << " does not have data left " << endl;
|
||||
#endif
|
||||
if(detectors[id]->getDetectorsType() != EIGER)
|
||||
break;
|
||||
/*if((detectors[id]->getDetectorsType() != EIGER)||(detectors[id]->getDetectorsType() != JUNGFRAU))
|
||||
break;*/
|
||||
}
|
||||
p+=n/sizeof(int);
|
||||
}
|
||||
}
|
||||
|
||||
//eiger returns only null
|
||||
if(getDetectorsType() == EIGER)
|
||||
detectorType types = getDetectorsType();
|
||||
if(types == EIGER || types == JUNGFRAU){
|
||||
delete [] retval;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (nodatadet>=0) {
|
||||
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
|
||||
if (id!=nodatadet) {
|
||||
if (detectors[id]) {
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
cout << "Stopping detector "<< id << endl;
|
||||
#endif
|
||||
//#endif
|
||||
detectors[id]->stopAcquisition();
|
||||
if(detectors[id]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<id));
|
||||
@ -1627,6 +1633,7 @@ int multiSlsDetector::startAndReadAllNoWait(){
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=posmin; idet<posmax; idet++){
|
||||
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
|
||||
@ -1756,7 +1763,7 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){
|
||||
if (ret1==-100)
|
||||
ret1=ret;
|
||||
else if (ret!=ret1)
|
||||
ret1=FAIL;
|
||||
ret1=-1;
|
||||
|
||||
}
|
||||
}
|
||||
@ -2229,6 +2236,7 @@ slsDetectorDefs::ROI* multiSlsDetector::getROI(int &n){
|
||||
|
||||
double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
|
||||
double *dataout;
|
||||
|
||||
if (fdata)
|
||||
dataout=fdata;
|
||||
else {
|
||||
@ -2240,12 +2248,12 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) {
|
||||
nn=thisMultiDetector->numberOfChannels;
|
||||
}
|
||||
}
|
||||
|
||||
// int ich=0;
|
||||
int n;
|
||||
double *detp=dataout;
|
||||
int *datap=datain;
|
||||
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
if (detectors[i]) {
|
||||
detectors[i]->decodeData(datap, n, detp);
|
||||
@ -3331,6 +3339,7 @@ char* multiSlsDetector::setNetworkParameter(networkParameter p, string s){
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -3362,6 +3371,7 @@ char* multiSlsDetector::setNetworkParameter(networkParameter p, string s){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return getNetworkParameter(p);
|
||||
|
||||
}
|
||||
@ -3940,6 +3950,7 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -3963,6 +3974,54 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo
|
||||
|
||||
|
||||
|
||||
int multiSlsDetector::programFPGA(string fname){
|
||||
int ret=OK, ret1=OK;
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
if (detectors[i]) {
|
||||
ret=detectors[i]->programFPGA(fname);
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
if (ret==FAIL)
|
||||
ret1=FAIL;
|
||||
}
|
||||
}
|
||||
return ret1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int multiSlsDetector::resetFPGA(){
|
||||
int ret=OK, ret1=OK;
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
if (detectors[i]) {
|
||||
ret=detectors[i]->resetFPGA();
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
if (ret==FAIL)
|
||||
ret1=FAIL;
|
||||
}
|
||||
}
|
||||
return ret1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int multiSlsDetector::powerChip(int ival){
|
||||
int ret=OK, ret1=OK;
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
if (detectors[i]) {
|
||||
ret=detectors[i]->powerChip(ival);
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
if (ret==FAIL)
|
||||
ret1=FAIL;
|
||||
}
|
||||
}
|
||||
return ret1;
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::loadSettingsFile(string fname, int imod) {
|
||||
@ -3991,6 +4050,7 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -4065,6 +4125,7 @@ int multiSlsDetector::setAllTrimbits(int val, int imod){
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -4114,6 +4175,7 @@ int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -4268,7 +4330,7 @@ int multiSlsDetector::readConfigurationFile(string const fname){
|
||||
multiSlsDetectorClient *cmd;
|
||||
// char ext[100];
|
||||
|
||||
|
||||
setAcquiringFlag(false);
|
||||
|
||||
string ans;
|
||||
string str;
|
||||
@ -4357,8 +4419,12 @@ int multiSlsDetector::readConfigurationFile(string const fname){
|
||||
setNumberOfModules(-1);
|
||||
getMaxNumberOfModules();
|
||||
|
||||
if (getErrorMask())
|
||||
if (getErrorMask()){
|
||||
int c;
|
||||
cprintf(RED,"\n----------------\n Error Messages\n----------------\n%s\n",
|
||||
getErrorMessage(c).c_str());
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@ -4688,7 +4754,8 @@ string multiSlsDetector::checkReceiverOnline() {
|
||||
string multiSlsDetector::setFilePath(string s) {
|
||||
|
||||
string ret="errorerror", ret1;
|
||||
if(!s.empty()){
|
||||
//if the sls file paths are different, it should be realized by always using setfilepath even if string empty
|
||||
//if(!s.empty()){
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
@ -4702,7 +4769,7 @@ string multiSlsDetector::setFilePath(string s) {
|
||||
}
|
||||
}
|
||||
fileIO::setFilePath(ret);
|
||||
}
|
||||
//}
|
||||
|
||||
return fileIO::getFilePath();
|
||||
}
|
||||
@ -4766,6 +4833,7 @@ int multiSlsDetector::startReceiver(){
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=posmin; idet<posmax; idet++){
|
||||
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
|
||||
@ -4827,6 +4895,7 @@ int multiSlsDetector::stopReceiver(){
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=posmin; idet<posmax; idet++){
|
||||
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
|
||||
@ -4909,19 +4978,30 @@ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){
|
||||
|
||||
|
||||
int multiSlsDetector::getFramesCaughtByReceiver() {
|
||||
int ret=0,ret1=0;
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
|
||||
if (detectors[i]){
|
||||
ret1+=detectors[i]->getFramesCaughtByReceiver();
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
|
||||
}
|
||||
if(!thisMultiDetector->numberOfDetectors)
|
||||
return ret;
|
||||
ret=(int)(ret1/thisMultiDetector->numberOfDetectors);
|
||||
int ret=0,ret1=0;
|
||||
|
||||
return ret;
|
||||
if(thisMultiDetector->numberOfDetectors>10) {
|
||||
if (detectors[0]){
|
||||
ret =detectors[0]->getFramesCaughtByReceiver();
|
||||
if(detectors[0]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<0));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
|
||||
if (detectors[i]){
|
||||
ret1+=detectors[i]->getFramesCaughtByReceiver();
|
||||
if(detectors[i]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<i));
|
||||
|
||||
}
|
||||
if(!thisMultiDetector->numberOfDetectors)
|
||||
return ret;
|
||||
ret=(int)(ret1/thisMultiDetector->numberOfDetectors);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -4945,6 +5025,7 @@ int multiSlsDetector::getReceiverCurrentFrameIndex() {
|
||||
|
||||
int multiSlsDetector::resetFramesCaught() {
|
||||
int ret=-100, ret1;
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++){
|
||||
if (detectors[i]){
|
||||
ret1=detectors[i]->resetFramesCaught();
|
||||
@ -4961,101 +5042,427 @@ int multiSlsDetector::resetFramesCaught() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
int multiSlsDetector::createReceivingDataThreads(bool destroy){
|
||||
if(!destroy) cprintf(MAGENTA,"Going to create data threads\n");
|
||||
else cprintf(MAGENTA,"Going to destroy data threads\n");
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
int numReadouts = thisMultiDetector->numberOfDetectors;
|
||||
if(getDetectorsType() == EIGER)
|
||||
numReadouts *= 2;
|
||||
|
||||
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;
|
||||
//reset masks
|
||||
killAllReceivingDataThreads = false;
|
||||
|
||||
//destroy
|
||||
if(destroy){
|
||||
#ifdef DEBUG
|
||||
cout << "Destroying Receiving Data Thread(s)" << endl;
|
||||
#endif
|
||||
delete [] retval;
|
||||
return NULL;
|
||||
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
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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://";
|
||||
char rx_hostname[100];
|
||||
strcpy(rx_hostname, detectors[ithread]->getReceiver());
|
||||
cout<<"rx_hostname:"<<rx_hostname<<endl;
|
||||
if(strchr(rx_hostname,'.')!=NULL)
|
||||
strcat(hostname,rx_hostname);
|
||||
else{
|
||||
struct hostent *he = gethostbyname(rx_hostname);
|
||||
if (he == NULL){
|
||||
cprintf(RED,"ERROR: could not convert receiver hostname to ip\n");
|
||||
exit(-1);
|
||||
}else
|
||||
strcat(hostname,inet_ntoa(*(struct in_addr*)he->h_addr));
|
||||
}
|
||||
strcat(hostname,":");
|
||||
//server details
|
||||
//char hostname[100] = "tcp://127.0.0.1:";
|
||||
int portno = DEFAULT_ZMQ_PORTNO + ithread;
|
||||
sprintf(hostname,"%s%d",hostname,portno);
|
||||
|
||||
//socket details
|
||||
zmq_msg_t message;
|
||||
void *context;
|
||||
void *zmqsocket;
|
||||
context = zmq_ctx_new();
|
||||
zmqsocket = zmq_socket(context, ZMQ_PULL);
|
||||
//int hwmval = 10;
|
||||
//zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets)
|
||||
cprintf(RED,"connect ret:%d\n",zmq_connect(zmqsocket, hostname));
|
||||
cout << "ZMQ Client of " << ithread << " at " << hostname << endl;
|
||||
cprintf(BLUE,"%d Created socket\n",ithread);
|
||||
|
||||
|
||||
//initializations
|
||||
int numReadoutPerDetector = 1;
|
||||
bool jungfrau = false;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
//scan header-------------------------------------------------------------------
|
||||
zmq_msg_init (&message);
|
||||
len = zmq_msg_recv(&message, zmqsocket, 0);
|
||||
if (len == -1) {
|
||||
cprintf(BG_RED,"Could not read header for socket %d\n",ithread);
|
||||
zmq_msg_close(&message);
|
||||
cprintf(RED, "%d message null\n",ithread);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 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);
|
||||
rapidjson::Document d;
|
||||
d.Parse( (char*)zmq_msg_data(&message), zmq_msg_size(&message));
|
||||
#ifdef VERYVERBOSE
|
||||
// htype is an array of strings
|
||||
rapidjson::Value::Array htype = d["htype"].GetArray();
|
||||
for(int i=0; i< htype.Size(); i++)
|
||||
std::cout << ithread << "htype: " << htype[i].GetString() << std::endl;
|
||||
// shape is an array of ints
|
||||
rapidjson::Value::Array shape = d["shape"].GetArray();
|
||||
cout << ithread << "shape: ";
|
||||
for(int i=0; i< shape.Size(); i++)
|
||||
cout << ithread << shape[i].GetInt() << " ";
|
||||
cout << endl;
|
||||
|
||||
cout << ithread << "type: " << d["type"].GetString() << endl;
|
||||
|
||||
#endif
|
||||
if(!ithread && (d["acqIndex"].GetInt()!=-9)){
|
||||
currentAcquisitionIndex = d["acqIndex"].GetInt();
|
||||
currentFrameIndex = d["fIndex"].GetInt();
|
||||
currentSubFrameIndex = d["subfnum"].GetInt();
|
||||
currentFileName = d["fname"].GetString();
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Acquisition index: " << currentAcquisitionIndex << endl;
|
||||
cout << "Frame index: " << currentFrameIndex << endl;
|
||||
cout << "Subframe index: " << currentSubFrameIndex << endl;
|
||||
cout << "File name: " << currentFileName << endl;
|
||||
#endif
|
||||
if(currentFrameIndex ==-1) cprintf(RED,"multi frame index -1!!\n");
|
||||
}
|
||||
singleframe[ithread]=image;
|
||||
|
||||
// close the message
|
||||
zmq_msg_close(&message);
|
||||
|
||||
|
||||
//scan data-------------------------------------------------------------------
|
||||
zmq_msg_init (&message);
|
||||
len = zmq_msg_recv(&message, zmqsocket, 0);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
//actual data
|
||||
//cprintf(BLUE,"%d actual dataaa\n",ithread);
|
||||
memcpy((char*)(singleframe[ithread]),(char*)zmq_msg_data(&message),singleDatabytes/numReadoutPerDetector);
|
||||
|
||||
|
||||
//jungfrau masking adcval
|
||||
if(jungfrau){
|
||||
for(unsigned int i=0;i<nel;i++){
|
||||
singleframe[ithread][i] = (singleframe[ithread][i] & 0x3FFF3FFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sem_post(&sem_singledone[ithread]);//let multi know is ready
|
||||
zmq_msg_close(&message); // close the message
|
||||
}
|
||||
//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;
|
||||
};
|
||||
|
||||
cprintf(RED,"%d Closing socket\n",ithread);
|
||||
//close socket
|
||||
zmq_disconnect(zmqsocket, hostname);
|
||||
zmq_close(zmqsocket);
|
||||
zmq_ctx_destroy(context);
|
||||
|
||||
//free resources
|
||||
delete [] image;
|
||||
|
||||
#ifdef DEBUG
|
||||
cprintf(MAGENTA,"Receiving Data Thread %d:Goodbye!\n",ithread);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void multiSlsDetector::readFrameFromReceiver(){
|
||||
|
||||
// //determine number of half readouts and maxX and maxY
|
||||
// int maxX=0,maxY=0;
|
||||
// int numReadoutPerDetector = 1;
|
||||
// if(getDetectorsType() == EIGER){
|
||||
// numReadoutPerDetector = 2;
|
||||
// maxX = thisMultiDetector->numberOfChannel[X];
|
||||
// maxY = thisMultiDetector->numberOfChannel[Y];
|
||||
// }
|
||||
// int numReadouts = numReadoutPerDetector * thisMultiDetector->numberOfDetectors;
|
||||
|
||||
// //initializing variables
|
||||
// currentFileName="";
|
||||
// currentAcquisitionIndex = -1;
|
||||
// currentFrameIndex = -1;
|
||||
// currentSubFrameIndex = -1;
|
||||
|
||||
|
||||
// //getting values
|
||||
// int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0;
|
||||
// if(detectors[0]){
|
||||
// slsdatabytes = detectors[0]->getDataBytes();
|
||||
// slsmaxchannels = detectors[0]->getMaxNumberOfChannels();
|
||||
// bytesperchannel = slsdatabytes/slsmaxchannels;
|
||||
// slsmaxX = detectors[0]->getTotalNumberOfChannels(X);
|
||||
// slsmaxY = detectors[0]->getTotalNumberOfChannels(Y);
|
||||
// }
|
||||
// int nel=(thisMultiDetector->dataBytes)/sizeof(int);
|
||||
// if(nel <= 0){
|
||||
// cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes);
|
||||
// return;
|
||||
// }
|
||||
// int* multiframe=new int[nel];
|
||||
// int idet,offsetY,offsetX;
|
||||
// int halfreadoutoffset = (slsmaxX/numReadoutPerDetector);
|
||||
// int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
|
||||
// int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
|
||||
|
||||
// volatile uint64_t dataThreadMask = 0x0;
|
||||
// for(int i = 0; i < numReadouts; ++i)
|
||||
// dataThreadMask|=(1<<i);
|
||||
|
||||
|
||||
// //construct complete image and send to callback
|
||||
// while(true){
|
||||
// //memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
|
||||
|
||||
// //post all of them to start
|
||||
// for(int ireadout=0; ireadout<numReadouts; ++ireadout){
|
||||
// if((1 << ireadout) & dataThreadMask){
|
||||
// sem_post(&sem_singlewait[ireadout]); //sls to continue
|
||||
// }
|
||||
// }
|
||||
|
||||
// //get each frame
|
||||
// for(int ireadout=0; ireadout<numReadouts; ++ireadout){
|
||||
// //cprintf(BLUE,"multi checking %d mask:0x%x\n",ireadout,receivingDataThreadMask);
|
||||
// idet = ireadout/numReadoutPerDetector;
|
||||
// if((1 << ireadout) & dataThreadMask){ //if running
|
||||
|
||||
// sem_wait(&sem_singledone[ireadout]); //wait for sls to copy
|
||||
|
||||
// //this socket closed
|
||||
// if(singleframe[ireadout] == NULL){ //if got nothing
|
||||
// dataThreadMask^=(1<<ireadout);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //assemble data
|
||||
// if(maxX){ //eiger, so interleaving between ports in one readout itself
|
||||
// offsetY = (maxY - (thisMultiDetector->offsetY[idet] + slsmaxY)) * maxX * bytesperchannel;
|
||||
// //the left half or right half
|
||||
// if(!(ireadout%numReadoutPerDetector))
|
||||
// offsetX = thisMultiDetector->offsetX[idet];
|
||||
// else
|
||||
// offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset;
|
||||
// offsetX *= bytesperchannel;
|
||||
// //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n",
|
||||
// // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel);
|
||||
// // cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadoutPerDetector)*bytesperchannel);
|
||||
// //itnerleaving with other detectors
|
||||
|
||||
// //bottom
|
||||
// if(((idet+1)%2) == 0){
|
||||
// for(int i=0;i<slsmaxY;++i)
|
||||
// memcpy(((char*)multiframe) + offsetY + offsetX + ((slsmaxY-i)*maxX*bytesperchannel),
|
||||
// (char*)singleframe[ireadout]+ i*(slsmaxX/numReadoutPerDetector)*bytesperchannel,
|
||||
// (slsmaxX/numReadoutPerDetector)*bytesperchannel);
|
||||
// }
|
||||
// //top
|
||||
// else{
|
||||
// for(int i=0;i<slsmaxY;++i)
|
||||
// memcpy(((char*)multiframe) + offsetY + offsetX + (i*maxX*bytesperchannel),
|
||||
// (char*)singleframe[ireadout]+ i*(slsmaxX/numReadoutPerDetector)*bytesperchannel,
|
||||
// (slsmaxX/numReadoutPerDetector)*bytesperchannel);
|
||||
// }
|
||||
// }
|
||||
// //no interleaving, just add to the end
|
||||
// //numReadout always 1 here
|
||||
// else{
|
||||
// memcpy((char*)multiframe+slsdatabytes*ireadout,(char*)singleframe[ireadout],slsdatabytes);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //all done
|
||||
// if(!dataThreadMask)
|
||||
// break;
|
||||
|
||||
|
||||
// //send data to callback
|
||||
// fdata = decodeData(multiframe);
|
||||
// if ((fdata) && (dataReady)){
|
||||
// thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
|
||||
// dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
|
||||
// delete thisData;
|
||||
// fdata = NULL;
|
||||
// //cout<<"Send frame #"<< currentFrameIndex << " to gui"<<endl;
|
||||
// }
|
||||
// setCurrentProgress(currentAcquisitionIndex+1);
|
||||
// }
|
||||
|
||||
// //free resources
|
||||
// delete[] multiframe;
|
||||
// }
|
||||
|
||||
int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ int nel=(thisMultiDetector->dataBytes)/sizeof(int); if(nel <= 0){ cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; acquisitionIndex = -1; return NULL; } int n,complete=OK; int i,k,offsetX, offsetY, maxX, maxY; double dr; int* retval=new int[nel]; int *retdet = NULL, *p=retval; string fullFName=""; string ext=""; int index=-1,f_index=-1,p_index=-1,det_index=-1; double sv0=-1,sv1=-1; if(getDetectorsType() == EIGER){ maxX = thisMultiDetector->numberOfChannel[X]; maxY = thisMultiDetector->numberOfChannel[Y]; } for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) { if (detectors[id]) { n=detectors[id]->getDataBytes(); retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex, subFrameIndex); if(detectors[id]->getErrorMask()) setErrorMask(getErrorMask()|(1<<id)); if (retdet){ if (acquisitionIndex==-1){ complete = FAIL; delete [] retdet; }else{ n=detectors[id]->getDataBytes(); if(getDetectorsType() == EIGER){
|
||||
//cout << "fname:"<<fName<<" findex:"<<fIndex<<endl;//cout<<"n:"<<n<<endl;//cout<<"maxchan:"<<detectors[id]->getMaxNumberOfChannels()<<" n:"<<n<<endl;
|
||||
dr = (double)n/detectors[id]->getMaxNumberOfChannels();
|
||||
k=(int)(detectors[id]->getMaxNumberOfChannels(X)*dr);
|
||||
//bit mode
|
||||
//cout << "dr:"<<dr<<endl;//cout << "k:"<<k<<endl;
|
||||
offsetY = (int)(((maxY - (thisMultiDetector->offsetY[id] + detectors[id]->getMaxNumberOfChannels(Y))) * maxX)*dr);//bit mode
|
||||
offsetX = (int)(thisMultiDetector->offsetX[id]*dr);
|
||||
//cout << "offsetY"<<offsetY<< " offsetX:"<<offsetX<<endl;
|
||||
for(i=0; i< 256;i++){
|
||||
memcpy((((char*)p) + offsetY + offsetX + ((int)(i*maxX*dr))) ,(((char*)retdet) + (i*k)),k);//bit mode
|
||||
}
|
||||
} else{
|
||||
memcpy(p,retdet,n);
|
||||
p+=n/sizeof(int);
|
||||
}
|
||||
delete [] retdet;
|
||||
//concatenate filenames
|
||||
if(!fullFName.length()){
|
||||
//assign file prefix
|
||||
fullFName.assign(fileIO::getFileName());
|
||||
if (strrchr(fName,'.')!=NULL){
|
||||
ext.assign(fName);
|
||||
size_t dot = ext.rfind(".");
|
||||
if(dot != string::npos)
|
||||
ext = ext.erase(0,dot);
|
||||
else
|
||||
ext = "";
|
||||
//get variables
|
||||
fileIOStatic::getVariablesFromFileName(fName,index, f_index, p_index, sv0, sv1, det_index);
|
||||
//append scan and det variables
|
||||
fullFName.append(fileIOStatic::getReceiverFileNameToConcatenate(fName));
|
||||
}
|
||||
}
|
||||
//append only if scan variables are different
|
||||
if(!fileIOStatic::verifySameFrame(fName,index,f_index, p_index, sv0, sv1, det_index)){
|
||||
fullFName.append(fileIOStatic::getReceiverFileNameToConcatenate(fName));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef VERBOSE
|
||||
cout << "Receiver for detector " << id << " does not have data left " << endl;
|
||||
#endif
|
||||
delete [] retval;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
//append extension
|
||||
fullFName.append(ext);
|
||||
strcpy(fName,fullFName.c_str());
|
||||
//if some of the receivers did not give data, dont count it
|
||||
if((getDetectorsType() == EIGER) &&(complete ==FAIL))
|
||||
acquisitionIndex = -1;
|
||||
return retval;
|
||||
};
|
||||
|
||||
|
||||
int multiSlsDetector::lockReceiver(int lock) {
|
||||
@ -5195,6 +5602,9 @@ string multiSlsDetector::getErrorMessage(int &critical){
|
||||
|
||||
multiMask = getErrorMask();
|
||||
if(multiMask){
|
||||
if(multiMask & MULTI_DETECTORS_NOT_ADDED)
|
||||
retval.append("Detectors not added:\n"+string(getNotAddedList())+string("\n"));
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
//if the detector has error
|
||||
@ -5225,6 +5635,7 @@ string multiSlsDetector::getErrorMessage(int &critical){
|
||||
|
||||
int64_t multiSlsDetector::clearAllErrorMask(){
|
||||
clearErrorMask();
|
||||
clearNotAddedList();
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
|
||||
if (detectors[idet])
|
||||
detectors[idet]->clearErrorMask();
|
||||
@ -5252,7 +5663,7 @@ int multiSlsDetector::calibratePedestal(int frames){
|
||||
return ret;
|
||||
}
|
||||
|
||||
int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
|
||||
int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
|
||||
int ret=-100, ret1;
|
||||
|
||||
if(!getFromReceiver)
|
||||
@ -5260,7 +5671,7 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
|
||||
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
ret1=detectors[idet]->setReadReceiverFrequency(getFromReceiver,i);
|
||||
ret1=detectors[idet]->setReadReceiverFrequency(getFromReceiver,freq);
|
||||
if(detectors[idet]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<idet));
|
||||
if (ret==-100)
|
||||
@ -5276,6 +5687,48 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
|
||||
}
|
||||
|
||||
|
||||
// only called from gui or that wants zmq data packets
|
||||
int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
|
||||
|
||||
if(enable >= 0){
|
||||
|
||||
if(threadStarted != enable){
|
||||
//destroy data threads
|
||||
if(threadStarted)
|
||||
createReceivingDataThreads(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;
|
||||
//only for the first det as theres no general one
|
||||
setErrorMask(getErrorMask()|(1<<0));
|
||||
detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else enable = threadStarted;
|
||||
|
||||
int ret=-100, ret1;
|
||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||
if (detectors[idet]) {
|
||||
ret1=detectors[idet]->enableDataStreamingFromReceiver(enable);
|
||||
if(detectors[idet]->getErrorMask())
|
||||
setErrorMask(getErrorMask()|(1<<idet));
|
||||
if (ret==-100)
|
||||
ret=ret1;
|
||||
else if (ret!=ret1)
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(enable == -1)
|
||||
return threadStarted;
|
||||
*/
|
||||
return (threadStarted & ret);
|
||||
}
|
||||
|
||||
int multiSlsDetector::enableReceiverCompression(int i){
|
||||
int ret=-100,ret1;
|
||||
@ -5482,6 +5935,7 @@ int multiSlsDetector::pulsePixel(int n,int x,int y) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -5518,6 +5972,7 @@ int multiSlsDetector::pulsePixelNMove(int n,int x,int y) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
@ -5554,6 +6009,7 @@ int multiSlsDetector::pulseChip(int n) {
|
||||
threadpool->add_task(task);
|
||||
}
|
||||
}
|
||||
threadpool->startExecuting();
|
||||
threadpool->wait_for_tasks_to_complete();
|
||||
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||
if(detectors[idet]){
|
||||
|
@ -488,6 +488,22 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
|
||||
int decodeNMod(int i, int &idet, int &imod);
|
||||
|
||||
/** programs FPGA with pof file
|
||||
\param fname file name
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int programFPGA(string fname);
|
||||
|
||||
/** resets FPGA
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int resetFPGA();
|
||||
|
||||
/** power on/off the chip
|
||||
\param ival on is 1, off is 0, -1 to get
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int powerChip(int ival= -1);
|
||||
|
||||
/** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */
|
||||
int loadSettingsFile(string fname, int nmod=0);
|
||||
@ -1176,19 +1192,22 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
/**
|
||||
* resets framescaught
|
||||
* @param index frames caught by receiver
|
||||
*/
|
||||
*/
|
||||
int resetFramesCaught();
|
||||
|
||||
/**
|
||||
* Reads a frame from receiver
|
||||
* @param fName file name of current frame()
|
||||
* @param acquisitionIndex current acquisition index
|
||||
* @param frameIndex current frame index (for each scan)
|
||||
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
|
||||
/returns a frame read from recever
|
||||
*/
|
||||
int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex);
|
||||
* Create Receiving Data Threads
|
||||
* @param destroy is true to destroy all the threads
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int createReceivingDataThreads(bool destroy = false);
|
||||
|
||||
|
||||
|
||||
/** 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
|
||||
@ -1248,14 +1267,20 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
int calibratePedestal(int frames = 0);
|
||||
|
||||
/** Sets the read receiver frequency
|
||||
if Receiver read upon gui request, readRxrFrequency=0,
|
||||
if data required from receiver randomly readRxrFrequency=0,
|
||||
else every nth frame to be sent to gui
|
||||
@param getFromReceiver is 1 if it should ask the receiver,
|
||||
0 if it can get it from multislsdetecter
|
||||
@param i is the receiver read frequency
|
||||
0 if it can get it from multi structure
|
||||
@param freq is the receiver read frequency
|
||||
/returns read receiver frequency
|
||||
*/
|
||||
int setReadReceiverFrequency(int getFromReceiver, int i=-1);
|
||||
int setReadReceiverFrequency(int getFromReceiver, int freq=-1);
|
||||
|
||||
/** 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
|
||||
*/
|
||||
int enableDataStreamingFromReceiver(int enable=-1);
|
||||
|
||||
/** updates the multidetector offsets */
|
||||
void updateOffsets();
|
||||
@ -1358,11 +1383,36 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
bool getAcquiringFlag();
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
void startReceivingDataThread();
|
||||
|
||||
/* 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;
|
||||
|
||||
protected:
|
||||
|
||||
@ -1380,7 +1430,6 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
ThreadPool* threadpool;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git"
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUIDLIB "e9878a26ffb7e57c6e6724215e46ae5634871e64"
|
||||
//#define SVNREV 0x1149
|
||||
#define SVNREPUUIDLIB "a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc"
|
||||
//#define SVNREV 0x1297
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTHLIB "Dhanya_Maliakal"
|
||||
#define SVNREVLIB 0x1149
|
||||
#define SVNDATELIB 0x20160824
|
||||
#define SVNREVLIB 0x1297
|
||||
#define SVNDATELIB 0x20161108
|
||||
//
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <math.h>
|
||||
#include "gitInfoLib.h"
|
||||
|
||||
|
||||
int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
|
||||
|
||||
@ -24,7 +23,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
int sz;
|
||||
|
||||
//shmId=-1;
|
||||
#ifdef VERBOSE
|
||||
cout << "init shm"<< endl;
|
||||
#endif
|
||||
switch(type) {
|
||||
case MYTHEN:
|
||||
nch=128; // complete mythen system
|
||||
@ -124,7 +125,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
std::cout<<"*** shmat error (server) ***" << std::endl;
|
||||
return shm_id;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout <<"shm done"<<endl;
|
||||
#endif
|
||||
|
||||
/**
|
||||
shm_id returns -1 is shared memory initialization fails
|
||||
@ -1282,6 +1285,13 @@ int slsDetector::activate(int const enable){
|
||||
int arg = enable;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
int ret = OK;
|
||||
|
||||
if(thisDetector->myDetectorType != EIGER){
|
||||
std::cout<< "Not implemented for this detector" << std::endl;
|
||||
setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if(!enable)
|
||||
std::cout<< "Deactivating Detector" << std::endl;
|
||||
@ -1308,11 +1318,36 @@ int slsDetector::activate(int const enable){
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
if(retval)
|
||||
if(retval==1)
|
||||
std::cout << "Detector Activated" << std::endl;
|
||||
else
|
||||
else if(retval==0)
|
||||
std::cout << "Detector Deactivated" << std::endl;
|
||||
else
|
||||
std::cout << "Detector Activation unknown:" << retval << std::endl;
|
||||
#endif
|
||||
|
||||
if(ret!=FAIL){
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Activating/Deactivating Receiver: " << retval << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendInt(fnum,retval,retval);
|
||||
disconnectData();
|
||||
if(ret==FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE));
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
if(retval==1)
|
||||
std::cout << "Receiver Activated" << std::endl;
|
||||
else if(retval==0)
|
||||
std::cout << "Receiver Deactivated" << std::endl;
|
||||
else
|
||||
std::cout << "Receiver Activation unknown:" << retval << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
@ -1760,7 +1795,7 @@ int slsDetector::setNumberOfModules(int n, dimension d){
|
||||
thisDetector->nModMax[Y]=thisDetector->nMod[Y];
|
||||
|
||||
int dr=thisDetector->dynamicRange;
|
||||
if (dr==24)
|
||||
if ((thisDetector->myDetectorType==MYTHEN) && (dr==24))
|
||||
dr=32;
|
||||
|
||||
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8;
|
||||
@ -3678,7 +3713,6 @@ int slsDetector::startAcquisition(){
|
||||
};
|
||||
int slsDetector::stopAcquisition(){
|
||||
|
||||
|
||||
int fnum=F_STOP_ACQUISITION;
|
||||
int ret=FAIL;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
@ -4019,7 +4053,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
|
||||
int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER;
|
||||
int64_t retval = -1;
|
||||
int64_t ut = -2;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
@ -4027,9 +4060,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
if (index!=MEASUREMENTS_NUMBER) {
|
||||
|
||||
|
||||
//#ifdef VERBOSE
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl;
|
||||
//#endif
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
@ -4056,7 +4089,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
} else {
|
||||
//std::cout<< "offline " << std::endl;
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
thisDetector->timerValue[index]=t;
|
||||
if((thisDetector->myDetectorType==GOTTHARD)||
|
||||
(thisDetector->myDetectorType==PROPIX)||
|
||||
(thisDetector->myDetectorType==JUNGFRAU)||
|
||||
@ -4066,10 +4099,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
getTotalNumberOfChannels();
|
||||
// thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
if (t>=0)
|
||||
thisDetector->timerValue[index]=t;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
|
||||
@ -4089,58 +4123,88 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
setTotalProgress();
|
||||
}
|
||||
|
||||
double r;
|
||||
if((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->myDetectorType == EIGER) && (t>=0) && getRateCorrection(r)){
|
||||
setRateCorrection(r);
|
||||
if(t!=-1){
|
||||
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
|
||||
setDynamicRange();
|
||||
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
|
||||
}
|
||||
|
||||
/* set progress */
|
||||
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
|
||||
setTotalProgress();
|
||||
}
|
||||
|
||||
//if eiger, rate corr on, a put statement, dr=32 &setting subexp or dr =16 & setting exptime, set ratecorr to update table
|
||||
double r;
|
||||
if( (thisDetector->myDetectorType == EIGER) &&
|
||||
getRateCorrection(r) &&
|
||||
(t>=0) &&
|
||||
|
||||
(((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->dynamicRange == 32))||
|
||||
((index == ACQUISITION_TIME) && (thisDetector->dynamicRange == 16)))
|
||||
|
||||
&& (t>=0) && getRateCorrection(r)){
|
||||
setRateCorrection(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//send acquisiton period/frame number to receiver
|
||||
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
|
||||
if(ret != FAIL){
|
||||
retval = thisDetector->timerValue[index];
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
int64_t args[2];
|
||||
args[1] = retval;
|
||||
if((t == -1) && (ret!= FORCE_UPDATE)) args[1] = -1;
|
||||
|
||||
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
|
||||
#endif
|
||||
args[0] = FRAME_NUMBER;
|
||||
retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]);
|
||||
if(args[1] != -1) args[1]=retval;
|
||||
}else{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
|
||||
#endif
|
||||
args[0] = FRAME_PERIOD;
|
||||
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
|
||||
if(!retval) args[1] = timerValue[ACQUISITION_TIME];
|
||||
}
|
||||
|
||||
if(ret != FAIL){
|
||||
int64_t args[2];
|
||||
retval = -1;
|
||||
args[0] = index;
|
||||
args[1] = thisDetector->timerValue[index];
|
||||
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendIntArray(fnum2,ut,args);
|
||||
disconnectData();
|
||||
if((ut != retval)|| (ret==FAIL)){
|
||||
ret = FAIL;
|
||||
if(index==FRAME_PERIOD){
|
||||
//exptime sent if acq period = 0
|
||||
if(retval){
|
||||
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
|
||||
}
|
||||
}else{
|
||||
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
|
||||
if(setReceiverOnline(ONLINE_FLAG)==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;
|
||||
#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
|
||||
else{
|
||||
#ifdef VERBOSE
|
||||
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)
|
||||
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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
}
|
||||
}
|
||||
return thisDetector->timerValue[index];
|
||||
};
|
||||
@ -4580,7 +4644,7 @@ int slsDetector::setDynamicRange(int n){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting dynamic range to "<< n << std::endl;
|
||||
#endif
|
||||
if (n==24)
|
||||
if ((thisDetector->myDetectorType == MYTHEN) &&(n==24))
|
||||
n=32;
|
||||
|
||||
|
||||
@ -4595,8 +4659,12 @@ int slsDetector::setDynamicRange(int n){
|
||||
if (rateret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
if(strstr(mess,"Rate Correction")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
|
||||
if(strstr(mess,"Rate Correction")!=NULL){
|
||||
if(strstr(mess,"32")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
|
||||
else
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
}
|
||||
}
|
||||
}
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
@ -5198,7 +5266,7 @@ int slsDetector::setRateCorrection(double t){
|
||||
if(strstr(mess,"default tau")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED));
|
||||
if(strstr(mess,"32")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
|
||||
else
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
}
|
||||
@ -5554,7 +5622,7 @@ char* slsDetector::setDetectorMAC(string detectorMAC){
|
||||
(detectorMAC[11]==':')&&(detectorMAC[14]==':')){
|
||||
strcpy(thisDetector->detectorMAC,detectorMAC.c_str());
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL)
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}else{
|
||||
@ -5581,7 +5649,7 @@ char* slsDetector::setDetectorIP(string detectorIP){
|
||||
if(result!=0){
|
||||
strcpy(thisDetector->detectorIP,detectorIP.c_str());
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL)
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}else{
|
||||
@ -5600,6 +5668,7 @@ char* slsDetector::setReceiver(string receiverIP){
|
||||
cprintf(RED,"Acquisition already running, Stopping it.\n");
|
||||
stopAcquisition();
|
||||
}
|
||||
updateDetector();
|
||||
|
||||
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
|
||||
|
||||
@ -5620,6 +5689,7 @@ char* slsDetector::setReceiver(string receiverIP){
|
||||
std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl;
|
||||
std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl;
|
||||
std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl;
|
||||
//std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl;
|
||||
/** enable compresison, */
|
||||
#endif
|
||||
if(setDetectorType()!= GENERIC){
|
||||
@ -5643,6 +5713,10 @@ char* slsDetector::setReceiver(string receiverIP){
|
||||
setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]);
|
||||
setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]);
|
||||
setDynamicRange(thisDetector->dynamicRange);
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
activate(-1);
|
||||
//std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl;
|
||||
//parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1));
|
||||
//set scan tag
|
||||
setUDPConnection();
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
@ -5668,7 +5742,7 @@ char* slsDetector::setReceiverUDPIP(string udpip){
|
||||
}else{
|
||||
strcpy(thisDetector->receiverUDPIP,udpip.c_str());
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL){
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}
|
||||
@ -5691,7 +5765,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
|
||||
(udpmac[11]==':')&&(udpmac[14]==':')){
|
||||
strcpy(thisDetector->receiverUDPMAC,udpmac.c_str());
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL){
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}
|
||||
@ -5710,7 +5784,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
|
||||
int slsDetector::setReceiverUDPPort(int udpport){
|
||||
thisDetector->receiverUDPPort = udpport;
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL){
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}
|
||||
@ -5720,7 +5794,7 @@ int slsDetector::setReceiverUDPPort(int udpport){
|
||||
int slsDetector::setReceiverUDPPort2(int udpport){
|
||||
thisDetector->receiverUDPPort2 = udpport;
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none"))
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
else if(setUDPConnection()==FAIL){
|
||||
std::cout<< "Warning: UDP connection set up failed" << std::endl;
|
||||
}
|
||||
@ -5774,7 +5848,7 @@ int slsDetector::setUDPConnection(){
|
||||
|
||||
//called before set up
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none")){
|
||||
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
|
||||
std::cout << "Warning: Receiver hostname not set yet." << endl;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@ -6478,6 +6552,260 @@ int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
|
||||
|
||||
|
||||
|
||||
int slsDetector::programFPGA(string fname){
|
||||
int ret=FAIL;
|
||||
int fnum=F_PROGRAM_FPGA;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
int64_t retval = -1;
|
||||
size_t filesize=0;
|
||||
char* fpgasrc = NULL;
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
std::cout << "Not implemented for this detector" << std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
//check if it exists
|
||||
struct stat st;
|
||||
if(stat(fname.c_str(),&st)){
|
||||
std::cout << "Programming file does not exist" << endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
//create destination file name,replaces original filename with Jungfrau.rawbin
|
||||
string destfname;
|
||||
size_t found = fname.find_last_of("/\\");
|
||||
if(found == string::npos)
|
||||
destfname = "";
|
||||
else
|
||||
destfname = fname.substr(0,found+1);
|
||||
destfname.append("Jungfrau_MCB.rawbin");
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Converting " << fname << " to " << destfname << std::endl;
|
||||
#endif
|
||||
int filepos,x,y,i;
|
||||
FILE* src = fopen(fname.c_str(),"rb");
|
||||
FILE* dst = fopen(destfname.c_str(),"wb");
|
||||
// Remove header (0...11C)
|
||||
for (filepos=0; filepos < 0x11C; filepos++)
|
||||
fgetc(src);
|
||||
// Write 0x80 times 0xFF (0...7F)
|
||||
for (filepos=0; filepos < 0x80; filepos++)
|
||||
fputc(0xFF,dst);
|
||||
// Swap bits and write to file
|
||||
for (filepos=0x80; filepos < 0x1000000; filepos++) {
|
||||
x = fgetc(src);
|
||||
if (x < 0) break;
|
||||
y=0;
|
||||
for (i=0; i < 8; i++)
|
||||
y=y| ( (( x & (1<<i) ) >> i) << (7-i) ); // This swaps the bits
|
||||
fputc(y,dst);
|
||||
}
|
||||
if (filepos < 0x1000000){
|
||||
std::cout << "Could not convert programming file. EOF before end of flash" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout << "File has been converted to " << destfname << std::endl;
|
||||
#endif
|
||||
//loading file to memory
|
||||
FILE* fp = fopen(destfname.c_str(),"r");
|
||||
if(fp == NULL){
|
||||
std::cout << "Could not open rawbin file" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
if(fseek(fp,0,SEEK_END)){
|
||||
std::cout << "Seek error in rawbin file" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
filesize = ftell(fp);
|
||||
if(filesize <= 0){
|
||||
std::cout << "Could not get length of rawbin file" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
rewind(fp);
|
||||
fpgasrc = (char*)malloc(filesize+1);
|
||||
if(fpgasrc == NULL){
|
||||
std::cout << "Could not allocate size of program" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
if(fread(fpgasrc, sizeof(char), filesize, fp) != filesize){
|
||||
std::cout << "Could not read rawbin file" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if(fclose(fp)){
|
||||
std::cout << "Could not close rawbin file" << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Successfully loaded the rawbin file to program memory" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Sending programming binary to detector " << endl;
|
||||
#endif
|
||||
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&filesize,sizeof(filesize));
|
||||
//check opening error
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
filesize = 0;
|
||||
}
|
||||
|
||||
|
||||
//erasing flash
|
||||
if(ret!=FAIL){
|
||||
std::cout<< "This can take awhile. Please be patient..." << endl;
|
||||
printf("Erasing Flash:%d%%\r",0);
|
||||
std::cout << flush;
|
||||
//erasing takes 65 seconds, printing here (otherwise need threads in server-unnecessary)
|
||||
int count = 66;
|
||||
while(count>0){
|
||||
usleep(1 * 1000 * 1000);
|
||||
count--;
|
||||
printf("Erasing Flash:%d%%\r",(int) (((double)(65-count)/65)*100));
|
||||
std::cout << flush;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
printf("Writing to Flash:%d%%\r",0);
|
||||
std::cout << flush;
|
||||
}
|
||||
|
||||
|
||||
//sending program in parts of 2mb each
|
||||
size_t unitprogramsize = 0;
|
||||
int currentPointer = 0;
|
||||
size_t totalsize= filesize;
|
||||
while(ret != FAIL && (filesize > 0)){
|
||||
|
||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
|
||||
if(unitprogramsize > filesize) //less than 2mb
|
||||
unitprogramsize = filesize;
|
||||
#ifdef VERBOSE
|
||||
std::cout << "unitprogramsize:" << unitprogramsize << "\t filesize:" << filesize << std::endl;
|
||||
#endif
|
||||
controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize);
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL) {
|
||||
filesize-=unitprogramsize;
|
||||
currentPointer+=unitprogramsize;
|
||||
|
||||
//print progress
|
||||
printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100));
|
||||
std::cout << flush;
|
||||
}else{
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
}
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
|
||||
//check ending error
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
|
||||
}
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
|
||||
//free resources
|
||||
if(fpgasrc != NULL)
|
||||
free(fpgasrc);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::resetFPGA(){
|
||||
int ret=FAIL;
|
||||
int fnum=F_RESET_FPGA;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU){
|
||||
std::cout << "Not implemented for this detector" << std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Sending reset to FPGA " << endl;
|
||||
#endif
|
||||
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
|
||||
//check opening error
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(RESET_ERROR));
|
||||
}
|
||||
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetector::powerChip(int ival){
|
||||
int ret=FAIL;
|
||||
int fnum=F_POWER_CHIP;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
int retval=-1;
|
||||
|
||||
if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB ){
|
||||
std::cout << "Not implemented for this detector" << std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Sending power on/off/get to the chip " << endl;
|
||||
#endif
|
||||
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&ival,sizeof(ival));
|
||||
//check opening error
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(POWER_CHIP));
|
||||
}else
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
|
||||
}
|
||||
int slsDetector::loadSettingsFile(string fname, int imod) {
|
||||
|
||||
sls_detector_module *myMod=NULL;
|
||||
@ -6933,8 +7261,11 @@ string slsDetector::setFilePath(string s) {
|
||||
if(stat(s.c_str(),&st)){
|
||||
std::cout << "path does not exist" << endl;
|
||||
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
|
||||
}else
|
||||
}else{
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFilePath(s);
|
||||
pthread_mutex_unlock(&ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6946,8 +7277,11 @@ string slsDetector::setFilePath(string s) {
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendString(fnum,retval,arg);
|
||||
disconnectData();
|
||||
if(ret!=FAIL)
|
||||
if(ret!=FAIL){
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFilePath(string(retval));
|
||||
pthread_mutex_unlock(&ms);
|
||||
}
|
||||
else if(!s.empty()){
|
||||
std::cout << "path does not exist" << endl;
|
||||
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
|
||||
@ -6956,7 +7290,11 @@ string slsDetector::setFilePath(string s) {
|
||||
updateReceiver();
|
||||
}
|
||||
|
||||
return fileIO::getFilePath();
|
||||
pthread_mutex_lock(&ms);
|
||||
s = fileIO::getFilePath();
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -7001,7 +7339,11 @@ string slsDetector::setFileName(string s) {
|
||||
}
|
||||
}
|
||||
|
||||
return fileIO::getFileName();
|
||||
pthread_mutex_lock(&ms);
|
||||
s = fileIO::getFileName();
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -7252,65 +7594,54 @@ int slsDetector::resetFramesCaught(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
|
||||
int fnum=F_READ_RECEIVER_FRAME;
|
||||
int nel=thisDetector->dataBytes/sizeof(int);
|
||||
int* retval=new int[nel];
|
||||
int ret=FAIL;
|
||||
int n;
|
||||
char mess[MAX_STR_LENGTH]="Nothing";
|
||||
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
|
||||
if (ret==FAIL) {
|
||||
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
|
||||
delete [] retval;
|
||||
disconnectData();
|
||||
return NULL;
|
||||
} else {
|
||||
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
|
||||
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
|
||||
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||
#endif
|
||||
if (n!=thisDetector->dataBytes) {
|
||||
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
|
||||
ret=FAIL;
|
||||
delete [] retval;
|
||||
disconnectData();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//jungfrau masking adcval
|
||||
if(thisDetector->myDetectorType == JUNGFRAU){
|
||||
for(unsigned int i=0;i<nel;i++){
|
||||
retval[i] = (retval[i] & 0x3FFF3FFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnectData();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
|
||||
int fnum=F_READ_RECEIVER_FRAME;
|
||||
int nel=thisDetector->dataBytes/sizeof(int);
|
||||
int* retval=new int[nel];
|
||||
int ret=FAIL;
|
||||
int n;
|
||||
char mess[MAX_STR_LENGTH]="Nothing";
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
|
||||
delete [] retval;
|
||||
disconnectData();
|
||||
return NULL;
|
||||
} else {
|
||||
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
|
||||
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
if(thisDetector->myDetectorType == EIGER)
|
||||
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
|
||||
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||
#endif
|
||||
if (n!=thisDetector->dataBytes) {
|
||||
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
|
||||
ret=FAIL;
|
||||
delete [] retval;
|
||||
disconnectData();
|
||||
return NULL; }
|
||||
//jungfrau masking adcval
|
||||
if(thisDetector->myDetectorType == JUNGFRAU){
|
||||
for(unsigned int i=0;i<nel;i++){
|
||||
retval[i] = (retval[i] & 0x3FFF3FFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnectData();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -7373,16 +7704,22 @@ int slsDetector::updateReceiverNoWait() {
|
||||
#ifdef VERBOSE
|
||||
cout << "Updating receiver last modified by " << lastClientIP << std::endl;
|
||||
#endif
|
||||
|
||||
n = dataSocket->ReceiveDataOnly(&ind,sizeof(ind));
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFileIndex(ind);
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFilePath(path);
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFileName(path);
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
@ -7533,7 +7870,9 @@ int slsDetector::setFrameIndex(int index){
|
||||
int arg = index;
|
||||
|
||||
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){
|
||||
fileIO::setFrameIndex(index);
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFrameIndex(index);
|
||||
pthread_mutex_unlock(&ms);
|
||||
}
|
||||
|
||||
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
@ -7542,14 +7881,20 @@ int slsDetector::setFrameIndex(int index){
|
||||
#endif
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||
disconnectData();
|
||||
if(ret!=FAIL)
|
||||
disconnectData();
|
||||
if(ret!=FAIL){
|
||||
pthread_mutex_lock(&ms);
|
||||
fileIO::setFrameIndex(retval);
|
||||
pthread_mutex_unlock(&ms);
|
||||
}
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
pthread_mutex_lock(&ms);
|
||||
retval = fileIO::getFrameIndex();
|
||||
pthread_mutex_unlock(&ms);
|
||||
|
||||
return fileIO::getFrameIndex();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -7600,18 +7945,18 @@ int64_t slsDetector::clearAllErrorMask(){
|
||||
|
||||
|
||||
|
||||
int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
|
||||
int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
|
||||
int fnum=F_READ_RECEIVER_FREQUENCY;
|
||||
int ret = FAIL;
|
||||
int retval=-1;
|
||||
int arg = i;
|
||||
int arg = freq;
|
||||
|
||||
if(!getFromReceiver)
|
||||
return retval;
|
||||
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending read frequency to receiver " << arg << std::endl;
|
||||
std::cout << "Sending read frequency to receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||
@ -7622,14 +7967,44 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
|
||||
updateReceiver();
|
||||
}
|
||||
|
||||
if ((i > 0) && (retval != i)){
|
||||
cout << "could not set receiver read frequency:" << retval << endl;
|
||||
if ((freq > 0) && (retval != freq)){
|
||||
cout << "could not set receiver read frequency to " << freq <<" Returned:" << retval << endl;
|
||||
setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetector::enableDataStreamingFromReceiver(int enable){
|
||||
int fnum=F_STREAM_DATA_FROM_RECEIVER;
|
||||
int ret = FAIL;
|
||||
int retval=-1;
|
||||
int arg = enable;
|
||||
|
||||
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK)
|
||||
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||
disconnectData();
|
||||
if(ret==FAIL)
|
||||
retval = -1;
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
|
||||
if ((enable > 0) && (retval != enable)){
|
||||
cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl;
|
||||
setErrorMask((getErrorMask())|(DATA_STREAMING));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetector::enableReceiverCompression(int i){
|
||||
int fnum=F_ENABLE_RECEIVER_COMPRESSION;
|
||||
int ret = FAIL;
|
||||
|
@ -522,7 +522,24 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** programs FPGA with pof file
|
||||
\param fname file name
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int programFPGA(string fname);
|
||||
|
||||
/** resets FPGA
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int resetFPGA();
|
||||
|
||||
/** power on/off the chip
|
||||
\param ival on is 1, off is 0, -1 to get
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int powerChip(int ival= -1);
|
||||
|
||||
|
||||
/** loads the modules settings/trimbits reading from a file
|
||||
\param fname file name . If not specified, extension is automatically generated!
|
||||
\param imod module number, -1 means all modules
|
||||
@ -1580,15 +1597,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
int resetFramesCaught();
|
||||
|
||||
/**
|
||||
* Reads a frame from receiver
|
||||
* @param fName file name of current frame()
|
||||
* @param acquisitionIndex current acquisition index
|
||||
* @param frameIndex current frame index (for each scan)
|
||||
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
|
||||
/returns a frame read from recever
|
||||
*/
|
||||
int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex);
|
||||
* 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
|
||||
@ -1688,14 +1708,20 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
char* setDetectorNetworkParameter(networkParameter index, int delay);
|
||||
|
||||
/** Sets the read receiver frequency
|
||||
if Receiver read upon gui request, readRxrFrequency=0,
|
||||
if data required from receiver randomly readRxrFrequency=0,
|
||||
else every nth frame to be sent to gui
|
||||
@param getFromReceiver is 1 if it should ask the receiver,
|
||||
0 if it can get it from multislsdetecter
|
||||
@param i is the receiver read frequency
|
||||
0 if it can get it from multi structure
|
||||
@param freq is the receiver read frequency
|
||||
/returns read receiver frequency
|
||||
*/
|
||||
int setReadReceiverFrequency(int getFromReceiver, int i=-1);
|
||||
int setReadReceiverFrequency(int getFromReceiver, int freq=-1);
|
||||
|
||||
/** 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
|
||||
*/
|
||||
int enableDataStreamingFromReceiver(int enable=-1);
|
||||
|
||||
/** enable/disable or get data compression in receiver
|
||||
* @param i is -1 to get, 0 to disable and 1 to enable
|
||||
|
@ -146,6 +146,7 @@ int slsDetectorActions::getActionMode(int iaction){
|
||||
int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *values, string par, int precision) {
|
||||
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
|
||||
|
||||
// cout << "settings script to " << script <<endl;
|
||||
if (script=="") {
|
||||
scanMode[iscan]=noScan;
|
||||
} else {
|
||||
@ -160,6 +161,8 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
|
||||
scanMode[iscan]=trimbitsScan;
|
||||
} else if (script=="position") {
|
||||
scanMode[iscan]=positionScan;
|
||||
} else if (script=="dac") {
|
||||
scanMode[iscan]=dacScan;
|
||||
} else {
|
||||
scanMode[iscan]=scriptScan;
|
||||
}
|
||||
@ -202,15 +205,6 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
|
||||
|
||||
setTotalProgress();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return scanMode[iscan];
|
||||
} else
|
||||
return -1;
|
||||
@ -233,6 +227,8 @@ int slsDetectorActions::setScanScript(int iscan, string script) {
|
||||
scanMode[iscan]=trimbitsScan;
|
||||
} else if (script=="position") {
|
||||
scanMode[iscan]=positionScan;
|
||||
} else if (script=="dac") {
|
||||
scanMode[iscan]=dacScan;
|
||||
} else {
|
||||
scanMode[iscan]=scriptScan;
|
||||
}
|
||||
@ -425,6 +421,9 @@ int slsDetectorActions::executeScan(int level, int istep) {
|
||||
case thresholdScan:
|
||||
setDAC((dacs_t)currentScanVariable[level],THRESHOLD,0); // threshold scan
|
||||
break;
|
||||
case dacScan:
|
||||
setDAC((dacs_t)currentScanVariable[level],(slsDetectorDefs::dacIndex)atoi(getScanParameter(level).c_str()),0);
|
||||
break;
|
||||
case trimbitsScan:
|
||||
trimbit=(int)currentScanVariable[level];
|
||||
if(getDetectorsType() == EIGER)
|
||||
|
@ -25,7 +25,7 @@ class slsDetectorActions : public virtual slsDetectorBase
|
||||
{
|
||||
public :
|
||||
|
||||
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan };
|
||||
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan, dacScan };
|
||||
|
||||
|
||||
/** default constructor */
|
||||
|
@ -506,26 +506,20 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
|
||||
virtual int lockReceiver(int lock=-1)=0;
|
||||
|
||||
|
||||
/**
|
||||
* Reads a frame from receiver
|
||||
* @param fName file name of current frame()
|
||||
* @param acquisitionIndex current acquisition index
|
||||
* @param frameIndex current frame index (for each scan)
|
||||
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
|
||||
/returns a frame read from recever
|
||||
/** Reads frames from receiver through a constant socket
|
||||
*/
|
||||
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
|
||||
|
||||
|
||||
/** Sets the read receiver frequency
|
||||
if Receiver read upon gui request, readRxrFrequency=0,
|
||||
if data required from receiver randomly readRxrFrequency=0,
|
||||
else every nth frame to be sent to gui
|
||||
@param getFromReceiver is 1 if it should ask the receiver,
|
||||
0 if it can get it from multislsdetecter
|
||||
@param i is the receiver read frequency
|
||||
0 if it can get it from multi structure
|
||||
@param freq is the receiver read frequency
|
||||
/returns read receiver frequency
|
||||
*/
|
||||
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
|
||||
virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0;
|
||||
|
||||
/** Sets the receiver to start any readout remaining in the fifo and
|
||||
* change status to transmitting.
|
||||
|
@ -37,6 +37,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="datastream"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream;
|
||||
i++;
|
||||
|
||||
/* Detector structure configuration and debugging commands */
|
||||
|
||||
@ -441,6 +444,23 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
|
||||
i++;
|
||||
|
||||
|
||||
/* fpga */
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="programfpga";
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="resetfpga";
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
|
||||
i++;
|
||||
|
||||
|
||||
/* chip */
|
||||
descrToFuncMap[i].m_pFuncName="powerchip";
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
|
||||
i++;
|
||||
|
||||
/* versions/ serial numbers getId */
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="moduleversion"; //
|
||||
@ -791,10 +811,19 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
|
||||
i++;
|
||||
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="adc"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="temp_fpgafl"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="temp_fpgafr"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
|
||||
i++;
|
||||
|
||||
|
||||
/* r/w timers */
|
||||
|
||||
@ -929,6 +958,20 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
||||
i++;
|
||||
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="dbitclk"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="dbitphase"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
|
||||
i++;
|
||||
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="dbitpipeline"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
|
||||
i++;
|
||||
|
||||
|
||||
|
||||
/* settings dump/retrieve */
|
||||
descrToFuncMap[i].m_pFuncName="config";
|
||||
@ -1339,6 +1382,43 @@ string slsDetectorCommand::helpStatus(int narg, char *args[], int action) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdDataStream(int narg, char *args[], int action) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
|
||||
#endif
|
||||
int ival=-1;
|
||||
char ans[100]="";
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
myDet->setReceiverOnline(ONLINE_FLAG);
|
||||
|
||||
if (action==HELP_ACTION)
|
||||
return helpStatus(narg,args,HELP_ACTION);
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
if (!sscanf(args[1],"%d",&ival))
|
||||
return string ("cannot scan datastream mode");
|
||||
myDet->enableDataStreamingFromReceiver(ival);
|
||||
}
|
||||
sprintf(ans,"%d",myDet->enableDataStreamingFromReceiver());
|
||||
return string(ans);
|
||||
}
|
||||
|
||||
|
||||
string slsDetectorCommand::helpDataStream(int narg, char *args[], int action) {
|
||||
|
||||
ostringstream os;
|
||||
if (action==GET_ACTION || action==HELP_ACTION)
|
||||
os << string("datastream \t gets if zmq data stream from receiver is enabled. \n");
|
||||
if (action==PUT_ACTION || action==HELP_ACTION)
|
||||
os << string("datastream i\t enables/disables the zmq data stream from receiver. \n");
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdFree(int narg, char *args[], int action) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -3894,6 +3974,10 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
|
||||
adc=TEMPERATURE_SODL;
|
||||
else if (cmd=="temp_sodr")
|
||||
adc=TEMPERATURE_SODR;
|
||||
else if (cmd=="temp_fpgafl")
|
||||
adc=TEMPERATURE_FPGA2;
|
||||
else if (cmd=="temp_fpgafr")
|
||||
adc=TEMPERATURE_FPGA3;
|
||||
else
|
||||
return string("cannot decode adc ")+cmd;
|
||||
|
||||
@ -3926,6 +4010,8 @@ string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
|
||||
os << "temp_dcdc " << "Cannot be set" << std::endl;
|
||||
os << "temp_sodl " << "Cannot be set" << std::endl;
|
||||
os << "temp_sodr " << "Cannot be set" << std::endl;
|
||||
os << "temp_fpgafl " << "Cannot be set" << std::endl;
|
||||
os << "temp_fpgafr " << "Cannot be set" << std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION) {
|
||||
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
|
||||
@ -3935,6 +4021,8 @@ string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
|
||||
os << "temp_dcdc " << "\t gets the temperature close to the dc dc converter" << std::endl;
|
||||
os << "temp_sodl " << "\t gets the temperature close to the left so-dimm memory" << std::endl;
|
||||
os << "temp_sodr " << "\t gets the temperature close to the right so-dimm memory" << std::endl;
|
||||
os << "temp_fpgafl " << "\t gets the temperature of the left front end board fpga" << std::endl;
|
||||
os << "temp_fpgafr " << "\t gets the temperature of the left front end board fpga" << std::endl;
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
@ -4201,6 +4289,13 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) {
|
||||
index=ADC_CLOCK;
|
||||
else if (cmd=="adcphase") {
|
||||
index=ADC_PHASE;
|
||||
t=100000;
|
||||
} else if (cmd=="adcpipeline")
|
||||
index=ADC_PIPELINE;
|
||||
else if (cmd=="dbitclk")
|
||||
index=DBIT_CLOCK;
|
||||
else if (cmd=="dbitphase") {
|
||||
index=DBIT_PHASE;
|
||||
t=100000;
|
||||
} else if (cmd=="adcpipeline")
|
||||
index=ADC_PIPELINE;
|
||||
@ -4268,15 +4363,16 @@ string slsDetectorCommand::helpSpeed(int narg, char *args[], int action) {
|
||||
|
||||
string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) {
|
||||
|
||||
int retval;
|
||||
char answer[1000]="";
|
||||
int retval;
|
||||
char answer[1000]="";
|
||||
|
||||
if (action==HELP_ACTION)
|
||||
return helpAdvanced(narg, args, action);
|
||||
|
||||
if (cmd=="flags") {
|
||||
if (action==HELP_ACTION)
|
||||
return helpAdvanced(narg, args, action);
|
||||
|
||||
if (cmd=="flags") {
|
||||
|
||||
readOutFlags flag=GET_READOUT_FLAGS;
|
||||
|
||||
readOutFlags flag=GET_READOUT_FLAGS;
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
string sval=string(args[1]);
|
||||
@ -4302,9 +4398,7 @@ char answer[1000]="";
|
||||
return string("could not scan flag ")+string(args[1]);
|
||||
}
|
||||
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
retval = myDet->setReadOutFlags(flag);
|
||||
|
||||
// cout << hex << flag << " " << retval << endl;
|
||||
@ -4333,25 +4427,67 @@ char answer[1000]="";
|
||||
|
||||
return string("unknown");
|
||||
|
||||
} else if (cmd=="extsig") {
|
||||
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG;
|
||||
int is=-1;
|
||||
if (sscanf(args[0],"extsig:%d",&is))
|
||||
;
|
||||
else
|
||||
return string("could not scan signal number ")+string(args[0]);
|
||||
|
||||
if (action==PUT_ACTION) {
|
||||
flag=myDet->externalSignalType(args[1]);
|
||||
if (flag==GET_EXTERNAL_SIGNAL_FLAG)
|
||||
return string("could not scan external signal mode ")+string(args[1]);
|
||||
}
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
|
||||
} else if (cmd=="extsig") {
|
||||
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG;
|
||||
int is=-1;
|
||||
if (sscanf(args[0],"extsig:%d",&is))
|
||||
;
|
||||
else
|
||||
return string("could not scan signal number ")+string(args[0]);
|
||||
|
||||
} else
|
||||
return string("could not decode flag ")+cmd;
|
||||
if (action==PUT_ACTION) {
|
||||
flag=myDet->externalSignalType(args[1]);
|
||||
if (flag==GET_EXTERNAL_SIGNAL_FLAG)
|
||||
return string("could not scan external signal mode ")+string(args[1]);
|
||||
}
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
|
||||
|
||||
|
||||
} else if (cmd=="programfpga") {
|
||||
if (action==GET_ACTION)
|
||||
return string("cannot get");
|
||||
if(strstr(args[1],".pof")==NULL)
|
||||
return string("wrong usage: programming file should have .pof extension");
|
||||
string sval=string(args[1]);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< " programming file " << sval << std::endl;
|
||||
#endif
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
if(myDet->programFPGA(sval) == OK)
|
||||
return string("successful");
|
||||
return string("unsuccessful");
|
||||
}
|
||||
|
||||
|
||||
else if (cmd=="resetfpga") {
|
||||
if (action==GET_ACTION)
|
||||
return string("cannot get");
|
||||
#ifdef VERBOSE
|
||||
std::cout<< " resetting fpga " << sval << std::endl;
|
||||
#endif
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
if(myDet->resetFPGA() == OK)
|
||||
return string("successful");
|
||||
return string("unsuccessful");
|
||||
}
|
||||
|
||||
|
||||
else if (cmd=="powerchip") {
|
||||
char ans[100];
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
if (action==PUT_ACTION){
|
||||
int ival = -1;
|
||||
if (!sscanf(args[1],"%d",&ival))
|
||||
return string("could not scan powerchip parameter " + string(args[1]));
|
||||
myDet->powerChip(ival);
|
||||
}
|
||||
sprintf(ans,"%d",myDet->powerChip());
|
||||
return string(ans);
|
||||
}
|
||||
else
|
||||
return string("unknown command ")+cmd;
|
||||
|
||||
}
|
||||
|
||||
@ -4363,7 +4499,9 @@ string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) {
|
||||
|
||||
os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl;
|
||||
os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl;
|
||||
|
||||
|
||||
os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl;
|
||||
os << "resetfpga f \t resets fpga, f can be any value" << std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION) {
|
||||
|
||||
@ -4482,7 +4620,8 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
|
||||
if(!strcasecmp(args[1],"start"))
|
||||
myDet->startReceiver();
|
||||
else if(!strcasecmp(args[1],"stop")){
|
||||
myDet->startReceiverReadout();
|
||||
//myDet->stopReceiver();
|
||||
// myDet->startReceiverReadout();
|
||||
/*runStatus s = myDet->getReceiverStatus();
|
||||
while(s != RUN_FINISHED){
|
||||
usleep(50000);
|
||||
|
@ -38,6 +38,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
static string helpData(int narg, char *args[], int action);
|
||||
static string helpFrame(int narg, char *args[], int action);
|
||||
static string helpStatus(int narg, char *args[], int action);
|
||||
static string helpDataStream(int narg, char *args[], int action);
|
||||
static string helpFree(int narg, char *args[], int action);
|
||||
static string helpAdd(int narg, char *args[], int action);
|
||||
static string helpRemove(int narg, char *args[], int action);
|
||||
@ -109,6 +110,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
string cmdData(int narg, char *args[], int action);
|
||||
string cmdFrame(int narg, char *args[], int action);
|
||||
string cmdStatus(int narg, char *args[], int action);
|
||||
string cmdDataStream(int narg, char *args[], int action);
|
||||
string cmdFree(int narg, char *args[], int action);
|
||||
string cmdAdd(int narg, char *args[], int action);
|
||||
string cmdRemove(int narg, char *args[], int action);
|
||||
|
@ -240,7 +240,9 @@ int slsDetectorUsers::setReceiverMode(int n){
|
||||
return myDetector->setReadReceiverFrequency(1,n);
|
||||
}
|
||||
|
||||
|
||||
int slsDetectorUsers::enableDataStreamingFromReceiver(int i){
|
||||
return myDetector->enableDataStreamingFromReceiver(i);
|
||||
}
|
||||
|
||||
|
||||
int64_t slsDetectorUsers::getModuleFirmwareVersion(){
|
||||
|
@ -450,6 +450,15 @@ class slsDetectorUsers
|
||||
|
||||
virtual void finalizeDataset(double *a, double *v, double *e, int &np);
|
||||
|
||||
|
||||
/**
|
||||
Enable data streaming from receiver (zmq)
|
||||
\param i 1 to set, 0 to reset and -1 to get
|
||||
\returns data streaming enable
|
||||
*/
|
||||
int enableDataStreamingFromReceiver(int i=-1);
|
||||
|
||||
|
||||
/**
|
||||
get get Module Firmware Version
|
||||
\returns id
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <cstdlib>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include <time.h> //clock()
|
||||
using namespace std;
|
||||
slsDetectorUtils::slsDetectorUtils() {
|
||||
|
||||
@ -42,6 +42,8 @@ slsDetectorUtils::slsDetectorUtils() {
|
||||
|
||||
|
||||
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)
|
||||
@ -58,11 +60,15 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
}else{
|
||||
//put receiver read frequency to random if no gui
|
||||
int ret = setReadReceiverFrequency(0);
|
||||
if(ret>0 && (acquisition_finished == NULL)){
|
||||
std::cout << "Error: receiver read frequency is set to " << ret << " but should be > 0 only when using gui." << std::endl;
|
||||
if(ret>0 && (dataReady == NULL)){
|
||||
ret = setReadReceiverFrequency(1,0);
|
||||
std::cout << "Current receiver read frequency: " << ret << std::endl;
|
||||
std::cout << "No Data call back and hence receiver read frequency reset to " << ret <<" (Random)" << std::endl;
|
||||
}
|
||||
|
||||
//start/stop data streaming threads if threads in client enabled/disabled
|
||||
ret = enableDataStreamingFromReceiver(-1);
|
||||
// cout<<"getting datastream:"<<ret<<endl;
|
||||
// cout<<"result of enabledatastream:"<<enableDataStreamingFromReceiver(ret)<<endl;
|
||||
}
|
||||
|
||||
int nc=setTimer(CYCLES_NUMBER,-1);
|
||||
@ -72,10 +78,6 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
int multiframe = nc*nf;
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 0;
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
// setTotalProgress();
|
||||
//moved these 2 here for measurement change
|
||||
progressIndex=0;
|
||||
@ -144,36 +146,34 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
}
|
||||
|
||||
if(receiver){
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
if(getReceiverStatus()!=IDLE)
|
||||
stopReceiver();
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
*stoppedFlag=1;
|
||||
|
||||
//multi detectors shouldnt have different receiver read frequencies enabled/disabled
|
||||
if(setReadReceiverFrequency(0) < 0){
|
||||
std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl;
|
||||
*stoppedFlag=1;
|
||||
*stoppedFlag=1;
|
||||
}
|
||||
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
*stoppedFlag=1;
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (*threadedProcessing) {
|
||||
sem_init(&sem_queue,0,0);
|
||||
startThread(delflag);
|
||||
}
|
||||
if (*threadedProcessing)
|
||||
startThread(delflag);
|
||||
#ifdef VERBOSE
|
||||
cout << " starting thread " << endl;
|
||||
#endif
|
||||
|
||||
//resets frames caught in receiver
|
||||
if(receiver){
|
||||
resetFramesCaught();
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
resetFramesCaught();
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
}
|
||||
|
||||
|
||||
for(int im=0;im<nm;im++) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -271,7 +271,7 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
setCurrentFrameIndex(0);
|
||||
|
||||
if(receiver)
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
if (multiframe>1)
|
||||
setFrameIndex(0);
|
||||
else
|
||||
@ -279,34 +279,36 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
|
||||
if(receiver){
|
||||
pthread_mutex_unlock(&mg);//unlock previous
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
pthread_mutex_lock(&mp);
|
||||
createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
//send receiver file name
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
setFileName(fileIO::getFileName());
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
stopReceiver();
|
||||
*stoppedFlag=1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
break;
|
||||
}
|
||||
//start receiver
|
||||
if(startReceiver() == FAIL) {
|
||||
cout << "Start receiver failed " << endl;
|
||||
stopReceiver();
|
||||
*stoppedFlag=1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&mg);
|
||||
cout << "Receiver started " << endl;
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "Acquiring " << endl;
|
||||
#endif
|
||||
startAndReadAll();
|
||||
cout << "detector finished " << endl;
|
||||
#ifdef VERBOSE
|
||||
cout << "finished " << endl;
|
||||
cout << "returned! " << endl;
|
||||
#endif
|
||||
|
||||
@ -339,56 +341,23 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
break;
|
||||
|
||||
|
||||
// cout << "mglock " << endl;;
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
// cout << "done " << endl;;
|
||||
//offline
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
// wait until data processing thread has finished the data
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
if (*threadedProcessing) {
|
||||
sem_wait(&sem_queue);
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 0;
|
||||
pthread_mutex_unlock(&mg);
|
||||
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){
|
||||
if((*correctionMask)&(1<<WRITE_FILE))
|
||||
closeDataFile();
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "check data queue size " << endl;
|
||||
#endif
|
||||
/*while (dataQueueSize()){
|
||||
//#ifdef VERBOSE
|
||||
cout << "AAAAAAAAA check data queue size " << endl;
|
||||
//#endif
|
||||
usleep(100000);
|
||||
}*/
|
||||
|
||||
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){
|
||||
if((*correctionMask)&(1<<WRITE_FILE))
|
||||
closeDataFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//online
|
||||
else{
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
// wait until data processing thread has taken the last frame
|
||||
if (*threadedProcessing) {
|
||||
sem_wait(&sem_queue);
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 0;
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
pthread_mutex_lock(&mg);
|
||||
cout << "Stopping receiver " << endl;;
|
||||
stopReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
cout<<"***********receiver stopped"<<endl;
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
|
||||
|
||||
|
||||
@ -466,9 +435,9 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
#endif
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
IncrementFileIndex();
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
setFileIndex(fileIO::getFileIndex());
|
||||
pthread_mutex_unlock(&mg);
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -479,15 +448,14 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
#endif
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
IncrementFileIndex();
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
setFileIndex(fileIO::getFileIndex());
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
|
||||
if (measurement_finished){
|
||||
pthread_mutex_lock(&mg);
|
||||
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
|
||||
measurement_finished(im,*fileIndex,measFinished_p);
|
||||
pthread_mutex_unlock(&mg);
|
||||
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
|
||||
}
|
||||
|
||||
if (*stoppedFlag) {
|
||||
@ -506,7 +474,6 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
#endif
|
||||
setJoinThread(1);
|
||||
pthread_join(dataProcessingThread, &status);
|
||||
sem_destroy(&sem_queue);
|
||||
#ifdef VERBOSE
|
||||
cout << "data processing thread joined" << endl;
|
||||
#endif
|
||||
@ -537,6 +504,10 @@ int slsDetectorUtils::acquire(int delflag){
|
||||
#endif
|
||||
|
||||
setAcquiringFlag(false);
|
||||
|
||||
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;
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ extern "C" {
|
||||
#include <sstream>
|
||||
#include <queue>
|
||||
#include <math.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -491,7 +491,22 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||
*/
|
||||
virtual int loadSettingsFile(string fname, int imod=-1)=0;
|
||||
|
||||
/** programs FPGA with pof file
|
||||
\param fname file name
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int programFPGA(string fname)=0;
|
||||
|
||||
/** resets FPGA
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int resetFPGA()=0;
|
||||
|
||||
/** power on/off the chip
|
||||
\param ival on is 1, off is 0, -1 to get
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int powerChip(int ival= -1)=0;
|
||||
|
||||
/** saves the modules settings/trimbits writing to a file
|
||||
\param fname file name . Axtension is automatically generated!
|
||||
@ -641,16 +656,17 @@ virtual int getReceiverCurrentFrameIndex()=0;
|
||||
virtual int resetFramesCaught()=0;
|
||||
|
||||
/**
|
||||
* Reads a frame from receiver
|
||||
* @param fName file name of current frame()
|
||||
* @param acquisitionIndex current acquisition index
|
||||
* @param frameIndex current frame index (for each scan)
|
||||
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
|
||||
/returns a frame read from recever
|
||||
* Create Receiving Data Threads
|
||||
* @param destroy is true to destroy all the threads
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
virtual int createReceivingDataThreads(bool destroy = false)=0;
|
||||
|
||||
|
||||
/** Reads frames from receiver through a constant socket
|
||||
*/
|
||||
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
|
||||
|
||||
|
||||
//virtual void readFrameFromReceiver()=0;
|
||||
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
|
||||
/**
|
||||
Turns off the receiver server!
|
||||
*/
|
||||
@ -693,14 +709,20 @@ virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0;
|
||||
virtual ROI* getROI(int &n)=0;
|
||||
|
||||
/** Sets the read receiver frequency
|
||||
if Receiver read upon gui request, readRxrFrequency=0,
|
||||
if data required from receiver randomly readRxrFrequency=0,
|
||||
else every nth frame to be sent to gui
|
||||
@param getFromReceiver is 1 if it should ask the receiver,
|
||||
0 if it can get it from multislsdetecter
|
||||
@param i is the receiver read frequency
|
||||
0 if it can get it from multi structure
|
||||
@param freq is the receiver read frequency
|
||||
/returns read receiver frequency
|
||||
*/
|
||||
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
|
||||
virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0;
|
||||
|
||||
/** Enable or disable streaming of data from receiver to client
|
||||
* @param enable 0 to disable 1 to enable -1 to only get the value
|
||||
* @returns data streaming
|
||||
*/
|
||||
virtual int enableDataStreamingFromReceiver(int enable=-1)=0;
|
||||
|
||||
|
||||
/** enable/disable or get data compression in receiver
|
||||
@ -824,7 +846,6 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
|
||||
|
||||
//protected:
|
||||
int *stoppedFlag;
|
||||
|
||||
int64_t *timerValue;
|
||||
detectorSettings *currentSettings;
|
||||
int *currentThresholdEV;
|
||||
@ -850,6 +871,8 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
|
||||
int (*progress_call)(double,void*);
|
||||
void *pProgressCallArg;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -17,7 +17,9 @@ class detectorData {
|
||||
\param np number of points in x coordinate defaults to the number of detector channels (1D detector)
|
||||
\param ny dimension in y (1D detector)
|
||||
*/
|
||||
detectorData(double *val=NULL, double *err=NULL, double *ang=NULL, double p_ind=-1, const char *fname="", int np=-1, int ny=1) : values(val), errors(err), angles(ang), progressIndex(p_ind), npoints(np), npy(ny){strcpy(fileName,fname);};
|
||||
detectorData(double *val=NULL, double *err=NULL, double *ang=NULL, double p_ind=-1, const char *fname="", int np=-1, int ny=1) : values(val), errors(err), angles(ang), progressIndex(p_ind), npoints(np), npy(ny){
|
||||
strcpy(fileName,fname);
|
||||
};
|
||||
/**
|
||||
@short The destructor
|
||||
deletes also the arrays pointing to data/errors/angles if not NULL
|
||||
|
@ -120,7 +120,7 @@ int fileIO::writeDataFile(void *data, int iframe) {
|
||||
|
||||
|
||||
int fileIO::closeDataFile() {
|
||||
// cout << "close file...." << endl;
|
||||
cout << "close file...." << endl;
|
||||
if (filefd)
|
||||
fclose(filefd);
|
||||
filefd=NULL;
|
||||
|
@ -6,6 +6,8 @@
|
||||
#elif EXTPP
|
||||
#include "usersFunctions.h"
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
|
||||
//#define VERBOSE
|
||||
|
||||
@ -24,6 +26,17 @@ static void* startProcessDataNoDelete(void *n){
|
||||
};
|
||||
|
||||
|
||||
int postProcessing::kbhit(){
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0
|
||||
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
|
||||
return FD_ISSET(STDIN_FILENO, &fds);
|
||||
}
|
||||
|
||||
|
||||
postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL), numberOfChannels(0), badChannelMask(NULL){
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
@ -398,7 +411,9 @@ int postProcessing::fillBadChannelMask() {
|
||||
|
||||
|
||||
void* postProcessing::processData(int delflag) {
|
||||
pthread_mutex_lock(&mg);
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< " ??????????????????????????????????????????? processing data - threaded mode " << *threadedProcessing << endl;
|
||||
@ -465,12 +480,7 @@ void* postProcessing::processData(int delflag) {
|
||||
|
||||
|
||||
}
|
||||
/** IF detector acquisition is done, let the acquire() thread know to finish up and force join thread */
|
||||
if(acquiringDone){
|
||||
sem_post(&sem_queue);
|
||||
// cout << "Sem posted" << endl;
|
||||
} //else
|
||||
// cout << "Sem not posted" << endl;
|
||||
|
||||
/* IF THERE ARE NO DATA look if acquisition is finished */
|
||||
if (checkJoinThread()) {
|
||||
if (dataQueueSize()==0) {
|
||||
@ -487,115 +497,148 @@ void* postProcessing::processData(int delflag) {
|
||||
fdata = NULL;
|
||||
//cout << "delete done "<< endl;
|
||||
}
|
||||
}
|
||||
//receiver
|
||||
} //receiver
|
||||
else{
|
||||
int nn;
|
||||
|
||||
int progress = 0;
|
||||
char currentfName[MAX_STR_LENGTH]="";
|
||||
int caught = -1;
|
||||
int currentAcquisitionIndex = -1;
|
||||
int currentFrameIndex = -1;
|
||||
int currentSubFrameIndex = -1;
|
||||
bool newData = false;
|
||||
int nthframe = setReadReceiverFrequency(0);
|
||||
int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
|
||||
int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "receiver read freq:" << nthframe << std::endl;
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock(&mg);
|
||||
// //cprintf(RED,"In post processing threads\n");
|
||||
|
||||
|
||||
//repeat forever until joined by the calling thread
|
||||
while(1){
|
||||
// if(dataReady){
|
||||
// readFrameFromReceiver();
|
||||
// }
|
||||
|
||||
cout.flush();
|
||||
cout<<flush;
|
||||
usleep(20000); //20ms need this else connecting error to receiver (too fast)
|
||||
// //only update progress
|
||||
// else{
|
||||
// int caught = -1;
|
||||
// char c;
|
||||
// int ifp;
|
||||
// while(true){
|
||||
|
||||
//get progress
|
||||
if(setReceiverOnline() == ONLINE_FLAG){
|
||||
pthread_mutex_lock(&mg);
|
||||
caught = getFramesCaughtByReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
// //cout.flush();
|
||||
// //cout<<flush;
|
||||
// usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
|
||||
|
||||
//updating progress
|
||||
if(caught!= -1){
|
||||
setCurrentProgress(caught);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "caught:" << caught << endl;
|
||||
#endif
|
||||
}
|
||||
// if (checkJoinThread()){
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
// ifp=kbhit();
|
||||
// if (ifp!=0){
|
||||
// c=fgetc(stdin);
|
||||
// if (c=='q') {
|
||||
// cout<<"gonna stop"<<endl;
|
||||
// stopAcquisition();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// //get progress
|
||||
// pthread_mutex_lock(&mg);
|
||||
// if(setReceiverOnline() == ONLINE_FLAG){
|
||||
// caught = getFramesCaughtByReceiver();
|
||||
// }
|
||||
// pthread_mutex_unlock(&mg);
|
||||
|
||||
|
||||
// //updating progress
|
||||
// if(caught!= -1){
|
||||
// setCurrentProgress(caught);
|
||||
// #ifdef VERY_VERY_DEBUG
|
||||
// cout << "caught:" << caught << endl;
|
||||
// #endif
|
||||
// }
|
||||
// if (checkJoinThread()){
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
//detector acquistion done, wait for all frames received
|
||||
if(acquiringDone > 0){
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
if(acquiringDone == 1) cout << "acquiring seems to be done" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
//IF GUI, check for last frames (counter upto 5)
|
||||
if(dataReady){
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone++;
|
||||
pthread_mutex_unlock(&mg);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquiringDone :" << acquiringDone << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//post to stopReceiver in acquire(), but continue reading frames
|
||||
if (!dataReady || (acquiringDone >= 5)){
|
||||
if(!dataReady || (!nthframe) ||(!newData)){
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "gonna post for it to end" << endl;
|
||||
#endif
|
||||
sem_post(&sem_queue);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "Sem posted" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
//random reads and for nthframe, checks if there is no new data
|
||||
else if((!nthframe) ||(!newData)){
|
||||
//cout <<"cecking now" << endl;
|
||||
if (checkJoinThread()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//for random reads, ask only if it has new data
|
||||
if(!newData){
|
||||
if(caught > progress){
|
||||
newData = true;
|
||||
|
||||
// If new data and acquiringDone>0 (= det acq over), reset to get more frames
|
||||
if(dataReady && (acquiringDone > 0)){
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "Keeping acquiringDone at 1 " << endl;
|
||||
#endif
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//cout<<"exiting from proccessing thread"<<endl;
|
||||
int progress = 0;
|
||||
char currentfName[MAX_STR_LENGTH]="";
|
||||
int caught = -1;
|
||||
int currentAcquisitionIndex = -1;
|
||||
int currentFrameIndex = -1;
|
||||
int currentSubFrameIndex = -1;
|
||||
bool newData = false;
|
||||
int nthframe = setReadReceiverFrequency(0);
|
||||
int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
|
||||
int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
|
||||
int nn;
|
||||
#ifdef VERBOSE
|
||||
std::cout << "receiver read freq:" << nthframe << std::endl;
|
||||
#endif
|
||||
//repeat forever until joined by the calling thread
|
||||
while(1){
|
||||
cout.flush();
|
||||
//cout<<flush;
|
||||
usleep(20000); //20ms need this else connecting error to receiver (too fast)
|
||||
//get progress
|
||||
if(setReceiverOnline() == ONLINE_FLAG){
|
||||
pthread_mutex_lock(&mg);
|
||||
caught = getFramesCaughtByReceiver();
|
||||
pthread_mutex_unlock(&mg); }
|
||||
//updating progress
|
||||
if(caught!= -1){
|
||||
setCurrentProgress(caught);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "caught:" << caught << endl;
|
||||
#endif
|
||||
}
|
||||
//detector acquistion done, wait for all frames received
|
||||
if(acquiringDone > 0){
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
if(acquiringDone == 1)
|
||||
cout << "acquiring seems to be done" << endl;
|
||||
#endif
|
||||
//IF GUI, check for last frames (counter upto 5)
|
||||
if(dataReady){
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone++;
|
||||
pthread_mutex_unlock(&mg);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquiringDone :" << acquiringDone << endl;
|
||||
#endif
|
||||
}
|
||||
//post to stopReceiver in acquire(), but continue reading frames
|
||||
if (!dataReady || (acquiringDone >= 5)){
|
||||
if(!dataReady || (!nthframe) ||(!newData)){
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "gonna post for it to end" << endl;
|
||||
#endif
|
||||
sem_post(&sem_queue);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "Sem posted" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
//random reads and for nthframe, checks if there is no new data
|
||||
else if((!nthframe) ||(!newData)){
|
||||
//cout <<"cecking now" << endl;
|
||||
if (checkJoinThread()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
//for random reads, ask only if it has new data
|
||||
if(!newData){
|
||||
if(caught > progress){
|
||||
newData = true; // If new data and acquiringDone>0 (= det acq over), reset to get more frames
|
||||
if(dataReady && (acquiringDone > 0)){
|
||||
pthread_mutex_lock(&mg);
|
||||
acquiringDone = 1;
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "Keeping acquiringDone at 1 " << endl;
|
||||
#endif
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
} }
|
||||
|
||||
if(newData){
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "new data" << endl;
|
||||
@ -667,6 +710,9 @@ void* postProcessing::processData(int delflag) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//cprintf(RED,"Exiting post processing thread\n");
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -295,16 +295,14 @@ s
|
||||
queue containing the postprocessed data
|
||||
*/
|
||||
queue<detectorData*> finalDataQueue;
|
||||
|
||||
|
||||
/** data queue size */
|
||||
int queuesize;
|
||||
|
||||
/** queue mutex */
|
||||
sem_t sem_queue;
|
||||
|
||||
/** set when detector finishes acquiring */
|
||||
int acquiringDone;
|
||||
/** queue mutex */
|
||||
sem_t sem_queue;
|
||||
/** set when detector finishes acquiring */
|
||||
int acquiringDone;
|
||||
|
||||
|
||||
/**
|
||||
@ -333,18 +331,24 @@ s
|
||||
|
||||
|
||||
|
||||
private:
|
||||
double *fdata;
|
||||
|
||||
int (*dataReady)(detectorData*,int, int,void*);
|
||||
void *pCallbackArg;
|
||||
|
||||
detectorData *thisData;
|
||||
|
||||
private:
|
||||
int kbhit(void);
|
||||
|
||||
// double *fdata;
|
||||
// int (*dataReady)(detectorData*,int, int,void*);
|
||||
// void *pCallbackArg;
|
||||
|
||||
int (*rawDataReady)(double*,int,void*);
|
||||
void *pRawDataArg;
|
||||
|
||||
|
||||
postProcessingFuncs *ppFun;
|
||||
detectorData *thisData;
|
||||
//detectorData *thisData;
|
||||
|
||||
|
||||
double *ang;
|
||||
@ -374,4 +378,5 @@ s
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,8 @@ add_executable(sls_detector_get
|
||||
target_link_libraries(sls_detector_get
|
||||
slsDetectorShared
|
||||
pthread
|
||||
zmq
|
||||
rt
|
||||
)
|
||||
set_target_properties(sls_detector_get PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
@ -30,6 +32,8 @@ add_executable(sls_detector_put
|
||||
target_link_libraries(sls_detector_put
|
||||
slsDetectorShared
|
||||
pthread
|
||||
zmq
|
||||
rt
|
||||
)
|
||||
set_target_properties(sls_detector_put PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
@ -42,6 +46,8 @@ add_executable(sls_detector_acquire
|
||||
target_link_libraries(sls_detector_acquire
|
||||
slsDetectorShared
|
||||
pthread
|
||||
zmq
|
||||
rt
|
||||
)
|
||||
set_target_properties(sls_detector_acquire PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
@ -54,6 +60,8 @@ add_executable(sls_detector_help
|
||||
target_link_libraries(sls_detector_help
|
||||
slsDetectorShared
|
||||
pthread
|
||||
zmq
|
||||
rt
|
||||
)
|
||||
set_target_properties(sls_detector_help PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
|
@ -92,7 +92,7 @@ int startStateMachine();
|
||||
int stopStateMachine();
|
||||
int startReadOut();
|
||||
enum runStatus getRunStatus();
|
||||
char *readFrame(int *ret, char *mess);
|
||||
void readFrame(int *ret, char *mess);
|
||||
|
||||
|
||||
int64_t setTimer(enum timerIndex ind, int64_t val);
|
||||
|
@ -36,7 +36,6 @@ extern enum detectorSettings thisSettings;
|
||||
|
||||
//global variables for optimized readout
|
||||
char mess[MAX_STR_LENGTH];
|
||||
char *dataretval=NULL;
|
||||
int dataret;
|
||||
//extern
|
||||
int dataBytes = 10;
|
||||
@ -1325,9 +1324,6 @@ int get_adc(int file_des) {
|
||||
#endif
|
||||
switch (ind) {
|
||||
#ifdef EIGERD
|
||||
case TEMPERATURE_FPGA:
|
||||
iadc = TEMP_FPGA;
|
||||
break;
|
||||
case TEMPERATURE_FPGAEXT:
|
||||
iadc = TEMP_FPGAEXT;
|
||||
break;
|
||||
@ -1343,6 +1339,15 @@ int get_adc(int file_des) {
|
||||
case TEMPERATURE_SODR:
|
||||
iadc = TEMP_SODR;
|
||||
break;
|
||||
case TEMPERATURE_FPGA:
|
||||
iadc = TEMP_FPGA;
|
||||
break;
|
||||
case TEMPERATURE_FPGA2:
|
||||
iadc = TEMP_FPGAFEBL;
|
||||
break;
|
||||
case TEMPERATURE_FPGA3:
|
||||
iadc = TEMP_FPGAFEBR;
|
||||
break;
|
||||
#endif
|
||||
#ifdef GOTTHARDD
|
||||
case TEMPERATURE_FPGA:
|
||||
@ -1932,6 +1937,7 @@ int set_module(int file_des) {
|
||||
case LOWGAIN:
|
||||
case VERYHIGHGAIN:
|
||||
case VERYLOWGAIN:
|
||||
case UNINITIALIZED:
|
||||
break;
|
||||
default:
|
||||
sprintf(mess,"This setting %d does not exist for this detector\n",myModule.reg);
|
||||
@ -2520,9 +2526,8 @@ int start_and_read_all(int file_des) {
|
||||
|
||||
|
||||
int read_frame(int file_des) {
|
||||
|
||||
dataret=OK;
|
||||
int dataret1;
|
||||
|
||||
if (differentClients==1 && lockStatus==1) {
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||
@ -2531,25 +2536,28 @@ int read_frame(int file_des) {
|
||||
dataret1 = dataret;
|
||||
sendData(file_des,&dataret1,sizeof(dataret1),INT32);
|
||||
sendData(file_des,mess,sizeof(mess),OTHER);
|
||||
#ifdef VERBOSE
|
||||
printf("dataret %d\n",dataret);
|
||||
#endif
|
||||
return dataret;
|
||||
}
|
||||
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
dataretval=readFrame(&dataret, mess);
|
||||
readFrame(&dataret, mess);
|
||||
#endif
|
||||
|
||||
|
||||
//dataret could be swapped during sendData
|
||||
dataret1 = dataret;
|
||||
sendData(file_des,&dataret1,sizeof(dataret1),INT32);
|
||||
if (dataret==FAIL)
|
||||
sendData(file_des,mess,sizeof(mess),OTHER);//sizeof(mess));//sizeof(mess));
|
||||
else if(dataret==OK){printf("shouldnt be sending anything but i am\n");
|
||||
sendData(file_des,dataretval,dataBytes,OTHER);}
|
||||
|
||||
printf("dataret %d\n",dataret);
|
||||
return dataret;
|
||||
if (differentClients)
|
||||
dataret=FORCE_UPDATE;
|
||||
//dataret could be swapped during sendData
|
||||
dataret1 = dataret;
|
||||
sendData(file_des,&dataret1,sizeof(dataret1),INT32);
|
||||
//always fail or finished
|
||||
sendData(file_des,mess,sizeof(mess),OTHER);
|
||||
if(dataret == FAIL)
|
||||
cprintf(RED,"%s\n",mess);
|
||||
else
|
||||
cprintf(GREEN,"%s",mess);
|
||||
return dataret;
|
||||
}
|
||||
|
||||
|
||||
@ -2787,15 +2795,26 @@ int set_dynamic_range(int file_des) {
|
||||
#endif
|
||||
}
|
||||
if(ret == OK){
|
||||
int old_dr = setDynamicRange(-1);
|
||||
retval=setDynamicRange(dr);
|
||||
if (dr>=0 && retval!=dr)
|
||||
ret=FAIL;
|
||||
//look at rate correction only if dr change worked
|
||||
if((ret==OK) && (dr!=32) && (dr!=-1) && (getRateCorrectionEnable())){
|
||||
if((ret==OK) && (dr!=32) && (dr!=16) && (dr!=-1) && (getRateCorrectionEnable())){
|
||||
setRateCorrection(0);
|
||||
strcpy(mess,"Switching off Rate Correction. Must be in 32 bit mode\n");
|
||||
strcpy(mess,"Switching off Rate Correction. Must be in 32 or 16 bit mode\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
rateret = FAIL;
|
||||
}else{
|
||||
//setting it if dr changed from 16 to 32 or vice versa with tau value as in rate table
|
||||
if((dr!=-1) && (old_dr != dr) && getRateCorrectionEnable() && (dr == 16 || dr == 32)){
|
||||
setRateCorrection(-1); //tau_ns will not be -1 here
|
||||
if(!getRateCorrectionEnable()){
|
||||
strcpy(mess,"Deactivating Rate Correction. Could not set it.\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -3977,9 +3996,9 @@ int set_rate_correct(int file_des) {
|
||||
|
||||
//set rate
|
||||
else{
|
||||
//not 32 bit mode
|
||||
if((setDynamicRange(-1)!=32) && (tau_ns!=0)){
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 bit mode\n");
|
||||
//not 32 or 16 bit mode
|
||||
if((setDynamicRange(-1)!=32) && (setDynamicRange(-1)!=16) && (tau_ns!=0)){
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ receiverInterface::~receiverInterface(){
|
||||
|
||||
int receiverInterface::sendString(int fnum, char retval[], char arg[]){
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,MAX_STR_LENGTH);
|
||||
@ -42,7 +42,7 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){
|
||||
int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_STR_LENGTH]){
|
||||
char args[3][MAX_STR_LENGTH];
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,sizeof(args));
|
||||
@ -60,7 +60,7 @@ int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_S
|
||||
|
||||
int receiverInterface::sendInt(int fnum, int &retval, int arg){
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
@ -78,7 +78,7 @@ int receiverInterface::sendInt(int fnum, int &retval, int arg){
|
||||
|
||||
int receiverInterface::getInt(int fnum, int &retval){
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
@ -95,7 +95,7 @@ int receiverInterface::getInt(int fnum, int &retval){
|
||||
|
||||
int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
@ -111,10 +111,28 @@ int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){
|
||||
|
||||
|
||||
|
||||
int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2]){
|
||||
int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2], char mess[]){
|
||||
int64_t args[2];
|
||||
char messs[MAX_STR_LENGTH];
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[100] = "";
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,sizeof(args));
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==slsDetectorDefs::FAIL){
|
||||
dataSocket->ReceiveDataOnly(mess,sizeof(messs));
|
||||
std::cout<< "Receiver returned error: " << mess << std::endl;
|
||||
}
|
||||
dataSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int receiverInterface::sendIntArray(int fnum, int &retval, int arg[2]){
|
||||
int args[2];
|
||||
int ret = slsDetectorDefs::FAIL;
|
||||
char mess[MAX_STR_LENGTH] = "";
|
||||
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
dataSocket->SendDataOnly(arg,sizeof(args));
|
||||
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
|
@ -91,9 +91,20 @@ public:
|
||||
* @param fnum function enum to determine what parameter
|
||||
* @param retval return value
|
||||
* @param arg values to send
|
||||
* @param mess message returned
|
||||
* \returns success of operation
|
||||
*/
|
||||
int sendIntArray(int fnum, int64_t &retval, int64_t arg[2]);
|
||||
int sendIntArray(int fnum, int64_t &retval, int64_t arg[2],char mess[]);
|
||||
|
||||
|
||||
/**
|
||||
* Send an integer to receiver
|
||||
* @param fnum function enum to determine what parameter
|
||||
* @param retval return value
|
||||
* @param arg values to send
|
||||
* \returns success of operation
|
||||
*/
|
||||
int sendIntArray(int fnum, int &retval, int arg[2]);
|
||||
|
||||
/**
|
||||
* Get an integer value from receiver
|
||||
|
@ -16,6 +16,18 @@ using namespace std;
|
||||
|
||||
class slsDetector;
|
||||
|
||||
template<typename _Ret, typename _Class>
|
||||
class func00_t{
|
||||
public:
|
||||
func00_t(_Ret (_Class::*fn)(),_Class* ptr):
|
||||
m_fn(fn),m_ptr(ptr){}
|
||||
~func00_t() {}
|
||||
void operator()() const {((m_ptr->*m_fn)());}
|
||||
private:
|
||||
_Class* m_ptr;
|
||||
_Ret (_Class::*m_fn)();
|
||||
};
|
||||
|
||||
template<typename _Ret, typename _Class, typename _Store>
|
||||
class func0_t{
|
||||
public:
|
||||
@ -94,27 +106,32 @@ private:
|
||||
class Task: public virtual slsDetectorDefs{
|
||||
public:
|
||||
/* Return: int, Param: int */
|
||||
Task(func1_t <int,slsDetector,int,int>* t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func1_t <int,slsDetector,int,int>* t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: int, Param: string,int */
|
||||
Task(func2_t <int,slsDetector,string,int,int>* t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func2_t <int,slsDetector,string,int,int>* t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: string, Param: string */
|
||||
Task(func1_t <string,slsDetector,string,string>* t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func1_t <string,slsDetector,string,string>* t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: char*, Param: char* */
|
||||
Task(func1_t <char*,slsDetector,char*,string>* t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func1_t <char*,slsDetector,char*,string>* t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: detectorSettings, Param: int */
|
||||
Task(func1_t <detectorSettings,slsDetector,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func1_t <detectorSettings,slsDetector,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: detectorSettings, Param: detectorSettings,int */
|
||||
Task(func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: int, Param: int,int */
|
||||
Task(func2_t <int,slsDetector,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0){};
|
||||
Task(func2_t <int,slsDetector,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: int, Param: int,int */
|
||||
Task(func3_t <int,slsDetector,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0){};
|
||||
Task(func3_t <int,slsDetector,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0){};
|
||||
/* Return: int, Param: trimMode,int,int,int */
|
||||
Task(func4_t <int,slsDetector,trimMode,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0){};
|
||||
/* Return: int, Param: int */
|
||||
Task(func0_t <int,slsDetector,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0){};
|
||||
Task(func4_t <int,slsDetector,trimMode,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0){};
|
||||
/* Return: int, Param: none */
|
||||
Task(func0_t <int,slsDetector,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0){};
|
||||
/* Return: char*, Param: networkParameter,string,string */
|
||||
Task(func2_t <char*,slsDetector,networkParameter,string,string>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t){};
|
||||
Task(func2_t <char*,slsDetector,networkParameter,string,string>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0){};
|
||||
/* Return: void, Param: none */
|
||||
Task(func00_t <void,slsDetector>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t){};
|
||||
|
||||
|
||||
|
||||
~Task(){}
|
||||
|
||||
void operator()(){
|
||||
@ -129,6 +146,7 @@ public:
|
||||
else if(m9) (*m9)();
|
||||
else if(m10) (*m10)();
|
||||
else if(m11) (*m11)();
|
||||
else if(m12) (*m12)();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -154,6 +172,8 @@ private:
|
||||
func0_t <int,slsDetector,int>* m10;
|
||||
/* Return: char*, Param: networkParameter,string,string */
|
||||
func2_t <char*,slsDetector,networkParameter,string,string>* m11;
|
||||
/* Return: void, Param: none */
|
||||
func00_t <void,slsDetector>* m12;
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,8 +7,10 @@ ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size){
|
||||
#endif
|
||||
m_tasks_loaded = false;
|
||||
thread_started = false;
|
||||
zmqthreadpool = false;
|
||||
current_thread_number = -1;
|
||||
number_of_ongoing_tasks = 0;
|
||||
number_of_total_tasks = 0;
|
||||
}
|
||||
|
||||
ThreadPool::~ThreadPool(){
|
||||
@ -34,6 +36,7 @@ int ThreadPool::initialize_threadpool(){
|
||||
m_pool_state = STARTED;
|
||||
int ret = -1;
|
||||
sem_init(&semStart,1,0);
|
||||
sem_init(&semDone,1,0);
|
||||
for (int i = 0; i < m_pool_size; i++) {
|
||||
pthread_t tid;
|
||||
thread_started = false;
|
||||
@ -68,12 +71,15 @@ int ThreadPool::destroy_threadpool(){
|
||||
for (int i = 0; i < m_pool_size; i++) {
|
||||
void* result;
|
||||
sem_post(&semStart);
|
||||
sem_post(&semDone);
|
||||
ret = pthread_join(m_threads[i], &result);
|
||||
/*cout << "pthread_join() returned " << ret << ": " << strerror(errno) << endl;*/
|
||||
m_task_cond_var.broadcast(); // try waking up a bunch of threads that are still waiting
|
||||
}
|
||||
sem_destroy(&semStart);
|
||||
sem_destroy(&semDone);
|
||||
number_of_ongoing_tasks = 0;
|
||||
number_of_total_tasks = 0;
|
||||
/* cout << m_pool_size << " threads exited from the thread pool" << endl;*/
|
||||
return 0;
|
||||
}
|
||||
@ -109,25 +115,28 @@ void* ThreadPool::execute_thread(){
|
||||
/*cout << "Unlocking: " << pthread_self() << endl;*/
|
||||
m_task_mutex.unlock();
|
||||
|
||||
//if(zmqthreadpool) cout<<"***"<<ithread<<" semaphore start address wait:"<<&semStart<<endl;
|
||||
sem_wait(&semStart);
|
||||
|
||||
//cout<<"***"<<ithread<<" checking out semaphore done address:"<<&semDone<<endl;
|
||||
|
||||
/*cout << ithread <<" Executing thread " << pthread_self() << endl;*/
|
||||
// execute the task
|
||||
(*task)(); // could also do task->run(arg);
|
||||
/*cout << ithread <<" Done executing thread " << pthread_self() << endl;*/
|
||||
|
||||
m_all_tasks_mutex.lock();
|
||||
m_task_mutex.lock();
|
||||
number_of_ongoing_tasks--;
|
||||
m_all_tasks_mutex.unlock();
|
||||
m_task_mutex.unlock();
|
||||
|
||||
//if(zmqthreadpool) cout<<ithread <<" task done: "<<number_of_ongoing_tasks<<endl;
|
||||
//last task and check m_tasks_loaded to ensure done only once
|
||||
if((!number_of_ongoing_tasks) && m_tasks_loaded){
|
||||
/*cout << ithread << " all tasks done."<<endl;*/
|
||||
m_all_tasks_mutex.lock();
|
||||
//if(zmqthreadpool) cout << ithread << " all tasks done."<<endl;
|
||||
m_tasks_loaded = false;
|
||||
m_all_tasks_cond_var.signal();// wake up thread that is waiting for all tasks to be complete
|
||||
m_all_tasks_mutex.unlock();
|
||||
}
|
||||
//if(zmqthreadpool) cout<<"***"<<ithread<<" semaphore done address post:"<<&semDone<<endl;
|
||||
sem_post(&semDone);
|
||||
delete task;
|
||||
/*cout << ithread << " task deleted" << endl;*/
|
||||
}
|
||||
@ -143,28 +152,37 @@ int ThreadPool::add_task(Task* task){
|
||||
// TODO: put a limit on how many tasks can be added at most
|
||||
m_tasks.push_back(task);
|
||||
number_of_ongoing_tasks++;
|
||||
number_of_total_tasks++;
|
||||
m_task_cond_var.signal(); // wake up one thread that is waiting for a task to be available
|
||||
m_task_mutex.unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ThreadPool::startExecuting(){
|
||||
if(m_pool_size == 1)
|
||||
return;
|
||||
|
||||
/*cout << "waiting for tasks: locked. gonna wait" << endl;*/
|
||||
m_tasks_loaded = true;
|
||||
|
||||
//giving all threads permission to start as all tasks have been added
|
||||
//if(zmqthreadpool) cout<<"*** semaphore start address post:"<<&semStart<<endl;
|
||||
for(int i=0;i<number_of_total_tasks;i++)
|
||||
sem_post(&semStart);
|
||||
|
||||
}
|
||||
|
||||
void ThreadPool::wait_for_tasks_to_complete(){
|
||||
if(m_pool_size == 1)
|
||||
return;
|
||||
m_all_tasks_mutex.lock();
|
||||
/*cout << "waiting for tasks: locked. gonna wait" << endl;*/
|
||||
m_tasks_loaded = true;
|
||||
|
||||
//giving all threads permission to start as all tasks have been added
|
||||
//using a different variable as number_of_ongoing_tasks is likely to change during the loop
|
||||
int totalnumtasks = number_of_ongoing_tasks;
|
||||
for(int i=0;i<totalnumtasks;i++)
|
||||
sem_post(&semStart);
|
||||
|
||||
while ((m_pool_state != STOPPED) && m_tasks_loaded) {
|
||||
m_all_tasks_cond_var.wait(m_all_tasks_mutex.get_mutex_ptr());
|
||||
}
|
||||
/*cout << "waiting for tasks:totall out, must be locked again" << endl;*/
|
||||
m_all_tasks_mutex.unlock();
|
||||
//if(zmqthreadpool) cout<<"waiting for all tasks to be done "<<endl;
|
||||
//if(zmqthreadpool) cout<<"*** semaphore done address wait:"<<&semDone<<endl;
|
||||
for(int i=0;i<number_of_total_tasks;i++)
|
||||
sem_wait(&semDone);
|
||||
number_of_total_tasks = 0;
|
||||
//if(zmqthreadpool) cout<<"complete"<<endl<<endl;
|
||||
}
|
||||
|
||||
void ThreadPool::setzeromqThread(){
|
||||
zmqthreadpool = true;
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ public:
|
||||
int destroy_threadpool();
|
||||
void* execute_thread();
|
||||
int add_task(Task* task);
|
||||
void startExecuting();
|
||||
void wait_for_tasks_to_complete();
|
||||
void setzeromqThread();
|
||||
|
||||
private:
|
||||
int m_pool_size;
|
||||
@ -36,16 +38,16 @@ private:
|
||||
std::deque<Task*> m_tasks;
|
||||
volatile int m_pool_state;
|
||||
|
||||
Mutex m_all_tasks_mutex;
|
||||
CondVar m_all_tasks_cond_var;
|
||||
bool m_tasks_loaded;
|
||||
bool thread_started;
|
||||
int current_thread_number;
|
||||
|
||||
//volatile uint64_t tasks_done_mask;
|
||||
volatile int number_of_ongoing_tasks;
|
||||
volatile int number_of_total_tasks;
|
||||
|
||||
sem_t semStart;
|
||||
|
||||
sem_t semDone;
|
||||
bool zmqthreadpool;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user