mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 15:20:02 +02:00
in the process of rewriting detector client interface
This commit is contained in:
parent
178b832223
commit
86fb843021
@ -1,335 +0,0 @@
|
||||
|
||||
/**
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*#include <iostream>
|
||||
#include <iomanip>*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "xparameters.h"
|
||||
#include "Feb.h"
|
||||
|
||||
|
||||
|
||||
void Feb_Feb(){
|
||||
|
||||
Feb_nfebs = 0;
|
||||
Feb_feb_numb = 0;
|
||||
|
||||
Feb_send_ndata = 0;
|
||||
Feb_send_buffer_size = 1026;
|
||||
Feb_send_data_raw = malloc((Feb_send_buffer_size+1)*sizeof(int));
|
||||
Feb_send_data = &Feb_send_data_raw[1];
|
||||
|
||||
Feb_recv_ndata = 0;
|
||||
Feb_recv_buffer_size = 1026;
|
||||
Feb_recv_data_raw = malloc((Feb_recv_buffer_size+1)*sizeof(int));
|
||||
Feb_recv_data = &Feb_recv_data_raw[1];
|
||||
|
||||
Local_LocalLinkInterface1(ll,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
||||
|
||||
}
|
||||
/*
|
||||
~Feb(){
|
||||
delete ll;
|
||||
if(feb_numb) delete [] feb_numb;
|
||||
delete [] send_data_raw;
|
||||
delete [] recv_data_raw;
|
||||
}
|
||||
*/
|
||||
|
||||
void Feb_SendCompleteFebList(unsigned int n,unsigned int* list){
|
||||
unsigned int i;
|
||||
if(Feb_feb_numb) free(Feb_feb_numb);
|
||||
Feb_nfebs = n;
|
||||
Feb_feb_numb = malloc(n*sizeof(unsigned int));
|
||||
for(i=0;i<n;i++) Feb_feb_numb[i] = list[i];
|
||||
}
|
||||
|
||||
int Feb_WriteTo(unsigned int ch){
|
||||
if(ch>0xfff) return 0;
|
||||
|
||||
Feb_send_data_raw[0] = 0x90000000 | (ch<<16); //we
|
||||
if(Local_Write(ll,4,Feb_send_data_raw)!=4) return 0;
|
||||
|
||||
Feb_send_data_raw[0] = 0xc0000000; //data
|
||||
return 1;//((Feb_send_ndata+1)*4==Local_Write(ll,(Feb_send_ndata+1)*4,Feb_send_data_raw));
|
||||
}
|
||||
|
||||
int Feb_ReadFrom(unsigned int ch, unsigned int ntrys){
|
||||
unsigned int t;
|
||||
if(ch>=0xfff) return 0;
|
||||
|
||||
Feb_recv_data_raw[0] = 0xa0000000 | (ch<<16); //read data
|
||||
Local_Write(ll,4,Feb_recv_data_raw);
|
||||
usleep(20);
|
||||
|
||||
Feb_recv_ndata=-1;
|
||||
for(t=0;t<ntrys;t++){
|
||||
if((Feb_recv_ndata=Local_Read(ll,Feb_recv_buffer_size*4,Feb_recv_data_raw)/4)>0){
|
||||
Feb_recv_ndata--;
|
||||
break;
|
||||
}
|
||||
printf("\t Read try number: %d\n",t);
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
|
||||
return (Feb_recv_ndata>=0);
|
||||
}
|
||||
|
||||
void Feb_PrintData(){
|
||||
int i;
|
||||
printf("Sent data: %d\n",Feb_send_ndata);
|
||||
for(i=0;i<Feb_send_ndata;i++) printf("\t%d)%d (0x%x)\n",i,Feb_send_data[i],Feb_send_data[i]);
|
||||
printf("Receive data: %d\n",Feb_recv_ndata);
|
||||
for(i=0;i<Feb_recv_ndata;i++) printf("\t%d)%d (0x%x)\n",i,Feb_recv_data[i],Feb_recv_data[i]);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
int Feb_CheckHeader(unsigned int valid_bit_mask, int print_error_info){
|
||||
|
||||
int header_returned_is_ok = (Feb_send_data[0] & valid_bit_mask)==(Feb_recv_data[0] & valid_bit_mask);
|
||||
|
||||
if(print_error_info && !header_returned_is_ok){
|
||||
printf("Error: Command received not the same as command recieved.\n");
|
||||
printf("\t\t Header sent: %d (0x%x) received: %d (0x%x)\n",Feb_send_data[0], Feb_send_data[0], Feb_recv_data[0], Feb_recv_data[0]);
|
||||
if(Feb_send_ndata>1&&Feb_recv_ndata>1){
|
||||
printf("\t\t Tail sent: %d (0x%x) receiver: %d (0x%x)\n",Feb_send_data[Feb_send_ndata-1],Feb_send_data[Feb_send_ndata-1],Feb_recv_data[Feb_recv_ndata-1],Feb_recv_data[Feb_recv_ndata-1]);
|
||||
}else{
|
||||
printf("Error printing tail, too little data nsent = 0x%x, nrecv = 0x%x.\n",Feb_send_ndata, Feb_recv_ndata);
|
||||
}
|
||||
Feb_PrintData();
|
||||
}
|
||||
return header_returned_is_ok;
|
||||
}
|
||||
|
||||
|
||||
int Feb_CheckTail(unsigned int valid_bit_mask){
|
||||
if(Feb_send_ndata<=1&&Feb_recv_ndata<=1){
|
||||
printf("Error checking tail, too little data nsent = %d, nrecv = %d.\n",Feb_send_ndata, Feb_recv_ndata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int the_tail = Feb_recv_data[Feb_recv_ndata-1]&valid_bit_mask;
|
||||
if(the_tail!=0){
|
||||
printf("Error returned in tail: 0x%x (%d)\n",the_tail,the_tail);
|
||||
if(the_tail&0x10000000) printf("\t\tBusy flag address error.\n");
|
||||
if(the_tail&0x20000000) printf("\t\tRead register address error.\n");
|
||||
if(the_tail&0x40000000) printf("\t\tWrite register address error.\n");
|
||||
if(the_tail&0x80000000) printf("\t\tBram number error.\n");
|
||||
if(the_tail&0x08000000) printf("\t\tFifo to read from error.\n");
|
||||
if(the_tail&0x3ff) printf("\t\tNumber of data send error.\n");
|
||||
return 0; //error
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int Feb_CheckCommunication(){
|
||||
Feb_send_data_raw[0] = 0x8fff0000; //rst-all serial coms and lls
|
||||
if(Local_Write(ll,4,Feb_send_data_raw)!=4) return 0;
|
||||
|
||||
printf("CheckingCommunication ....\n");
|
||||
while((Local_Read(ll,Feb_recv_buffer_size*4,Feb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n");
|
||||
|
||||
return Feb_SetByteOrder();
|
||||
}
|
||||
|
||||
|
||||
int Feb_SetByteOrder(){
|
||||
|
||||
unsigned int i;
|
||||
Feb_send_ndata = 2;
|
||||
Feb_send_data[0] = 0; //header
|
||||
Feb_send_data[1] = 0; //tail
|
||||
|
||||
unsigned int dst = 0xff;
|
||||
for( i=0;i<Feb_nfebs;i++) dst = (dst | Feb_feb_numb[i]); //get sub dst bits (left right in this case)
|
||||
int passed = Feb_WriteTo(dst);
|
||||
|
||||
for(i=0;i<Feb_nfebs;i++){
|
||||
printf("\t%d) Set Byte Order .............. ",i);
|
||||
unsigned int current_passed = Feb_ReadFrom(Feb_feb_numb[i],20)&&(Feb_recv_ndata==2)&&Feb_CheckHeader(0xffffffff,1);
|
||||
if(current_passed) printf("passed.\n");
|
||||
else printf("failed.\n");
|
||||
passed&=current_passed;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
/* feb_ needed
|
||||
int Feb_CheckSubNumber(unsigned int Feb_sub_num){
|
||||
if(sub_num>=nfebs){
|
||||
cout<<"Error invalid sub number "<<sub_num<<" must be less than "<<nfebs<<"."<<endl;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Feb_SetStartOnEndOnFebs(int sub_num_s, unsigned int& start_on, unsigned int& end_on){
|
||||
// -1 means write to all
|
||||
|
||||
if(sub_num_s<=-2){
|
||||
cout<<"Error bad subnumber "<<sub_num_s<<"."<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
start_on = sub_num_s!=-1 ? sub_num_s : 0;
|
||||
end_on = sub_num_s!=-1 ? sub_num_s : nfebs - 1;
|
||||
|
||||
return Feb_CheckSubNumber(start_on);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
int Feb_ReadRegister(unsigned int Feb_sub_num, unsigned int Feb_reg_num,unsigned int& Feb_value_read){
|
||||
return Feb_ReadRegisters(Feb_sub_num,1,&Feb_reg_num,&Feb_value_read);
|
||||
}
|
||||
*/
|
||||
int Feb_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read){
|
||||
return Feb_ReadRegisters(sub_num,1,®_num,value_read);
|
||||
}
|
||||
|
||||
int Feb_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
|
||||
//here cout<<"Reading Register ...."<<endl;
|
||||
unsigned int i;
|
||||
nreads &= 0x3ff; //10 bits
|
||||
if(!nreads||nreads>Feb_send_buffer_size-2) return 0;
|
||||
|
||||
Feb_send_ndata = nreads+2;
|
||||
Feb_send_data[0] = 0x20000000 | nreads << 14; //cmd -> read "00" , nreads
|
||||
|
||||
for(i=0;i<nreads;i++) Feb_send_data[i+1]=reg_nums[i];
|
||||
Feb_send_data[nreads+1] = 0; //tail
|
||||
|
||||
if(!Feb_WriteTo(sub_num)||!Feb_ReadFrom(sub_num,20)||Feb_recv_ndata!=(int)(nreads+2)||!Feb_CheckHeader(0xffffffff,1)||!Feb_CheckTail(0xffffffff)){
|
||||
Feb_PrintData();
|
||||
printf("Error reading register.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i=0;i<nreads;i++) values_read[i] = Feb_recv_data[i+1];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Feb_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address){
|
||||
return Feb_WriteRegisters(sub_num,1,®_num,&value,&wait_on,&wait_on_address);
|
||||
}
|
||||
|
||||
int Feb_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses){
|
||||
unsigned int i;
|
||||
// sub_num == 0xfff means write to all
|
||||
|
||||
nwrites &= 0x3ff; //10 bits
|
||||
if(!nwrites||nwrites>Feb_send_buffer_size-2) return 0;
|
||||
|
||||
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
|
||||
Feb_send_ndata = 2*nwrites+2;
|
||||
Feb_send_data[0] = 0x80000000 | nwrites << 14; //cmd -> write nwrites and how many
|
||||
Feb_send_data[2*nwrites+1] = 0; //tail
|
||||
|
||||
for(i=0;i<nwrites;i++) Feb_send_data[2*i+1] = 0x3fff®_nums[i]; // register address data_in(13 downto 0)
|
||||
for(i=0;i<nwrites;i++) Feb_send_data[2*i+2] = values[i]; // value is data_in(31 downto 0)
|
||||
// wait on busy data(28), address of busy flag data(27 downto 14)
|
||||
if(wait_ons&&wait_on_addresses) for(i=0;i<nwrites;i++) Feb_send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
|
||||
|
||||
if(!Feb_WriteTo(sub_num)){
|
||||
printf("%d) Error writing register(s).\n",sub_num);
|
||||
Feb_PrintData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int passed = 1;
|
||||
unsigned int n = (sub_num&0xff)==0xff ? Feb_nfebs : 1;
|
||||
unsigned int* nums = (sub_num&0xff)==0xff ? Feb_feb_numb : &sub_num;
|
||||
for(i=0;i<n;i++){
|
||||
if((sub_num&0xf00&(nums[i]))==0) continue;
|
||||
if(!Feb_ReadFrom(nums[i],20)||Feb_recv_ndata!=2||!Feb_CheckHeader(0xffffffff,1)){
|
||||
printf("%d) Error writing register(s) response.\n",nums[i]);
|
||||
Feb_PrintData();
|
||||
passed = 0;
|
||||
}else{
|
||||
passed = passed && Feb_CheckTail(0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
|
||||
int Feb_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
|
||||
// -1 means write to all
|
||||
unsigned int i;
|
||||
mem_num &= 0x3f; //6 bits
|
||||
start_address &= 0x3fff; //14 bits
|
||||
nwrites &= 0x3ff; //10 bits
|
||||
if(!nwrites||nwrites>Feb_send_buffer_size-2) return 0;
|
||||
|
||||
Feb_send_ndata = nwrites+2;
|
||||
Feb_send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
|
||||
Feb_send_data[nwrites+1] = 0; //tail
|
||||
for(i=0;i<nwrites;i++) Feb_send_data[i+1] = values[i];
|
||||
|
||||
|
||||
if(!Feb_WriteTo(sub_num)){
|
||||
printf("%d) Error writing memory.\n",sub_num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int passed = 1;
|
||||
unsigned int n = (sub_num&0xff)==0xff ? Feb_nfebs : 1;
|
||||
unsigned int* nums = (sub_num&0xff)==0xff ? Feb_feb_numb : &sub_num;
|
||||
for(i=0;i<n;i++){
|
||||
if((sub_num&0xf00&(nums[i]))==0) continue;
|
||||
if(!Feb_ReadFrom(nums[i],20)||Feb_recv_ndata!=2||!Feb_CheckHeader(0xffffffff,1)){
|
||||
printf("%d) Error writing memory response. \n",nums[i]);
|
||||
Feb_PrintData();
|
||||
passed = 0;
|
||||
}else{
|
||||
passed = passed && Feb_CheckTail(0xffffffff);
|
||||
}
|
||||
}
|
||||
// unsigned int n = sub_num==0xfff ? nfebs : 1;
|
||||
// unsigned int* nums = sub_num==0xfff ? feb_numb : &sub_num;
|
||||
// for(unsigned int i=0;i<n;i++){
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Feb_Test(){//int sub_num_s, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
|
||||
// -1 means write to all
|
||||
unsigned int i;
|
||||
unsigned int reg_nums[10]={0,1,2,3,1,2,3,1,2,3};
|
||||
|
||||
printf("Test\n\n\n\n");
|
||||
|
||||
unsigned int value = 0;
|
||||
for(i=0;i<10;i++){
|
||||
Feb_WriteRegister(0xfff,reg_nums[i%10],i,0,0);
|
||||
Feb_ReadRegister(256,reg_nums[i%10],&value);
|
||||
printf("%d %d\n",i,value);
|
||||
Feb_ReadRegister(512,reg_nums[i%10],&value);
|
||||
printf("%d %d\n",i,value);
|
||||
Feb_WriteMemory(0xfff,0,0,10,reg_nums);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
|
||||
/**
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FEB_H
|
||||
#define FEB_H
|
||||
|
||||
#include "LocalLinkInterface.h"
|
||||
|
||||
|
||||
struct LocalLinkInterface* ll;
|
||||
|
||||
unsigned int Feb_nfebs;
|
||||
unsigned int* Feb_feb_numb;
|
||||
|
||||
int Feb_send_ndata;
|
||||
unsigned int Feb_send_buffer_size;
|
||||
unsigned int* Feb_send_data_raw;
|
||||
unsigned int* Feb_send_data;
|
||||
|
||||
int Feb_recv_ndata;
|
||||
unsigned int Feb_recv_buffer_size;
|
||||
unsigned int* Feb_recv_data_raw;
|
||||
unsigned int* Feb_recv_data;
|
||||
|
||||
int Feb_WriteTo(unsigned int ch);
|
||||
/*int Feb_ReadFrom(unsigned int Feb_ch, unsigned int Feb_ntrys=20);*/
|
||||
int Feb_ReadFrom(unsigned int ch, unsigned int ntrys);
|
||||
/* int Feb_CheckHeader(unsigned int Feb_valid_bit_mask=0xffffffff, int Feb_print_error_info=1);*/
|
||||
int Feb_CheckHeader(unsigned int valid_bit_mask, int print_error_info);
|
||||
/*int Feb_CheckTail(unsigned int Feb_valid_bit_mask=0xffffffff);*/
|
||||
int Feb_CheckTail(unsigned int valid_bit_mask);
|
||||
|
||||
int Feb_SetByteOrder();
|
||||
//int Feb_CheckSubNumber(unsigned int Feb_sub_num);
|
||||
//int Feb_SetStartOnEndOnFebs(int Feb_sub_num_s, unsigned int& Feb_start_on, unsigned int& Feb_end_on);
|
||||
void Feb_PrintData();
|
||||
|
||||
|
||||
void Feb_Feb();
|
||||
/*virtual ~Feb();*/
|
||||
void Feb_SendCompleteFebList(unsigned int n,unsigned int* list);
|
||||
int Feb_CheckCommunication();
|
||||
/*int Feb_ReadRegister(unsigned int Feb_sub_num, unsigned int Feb_reg_num,unsigned int& Feb_value_read);*/
|
||||
int Feb_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read);
|
||||
int Feb_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
|
||||
/*int WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on=0, unsigned int wait_on_address=0);*/
|
||||
int Feb_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address);
|
||||
/*int WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons=0, unsigned int* wait_on_addresses=0);*/
|
||||
int Feb_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
|
||||
int Feb_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
|
||||
int Feb_Test();
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
CC = powerpc-4xx-softfloat-gcc
|
||||
BLACKFIN_CC = bfin-uclinux-gcc
|
||||
CFLAGS += -Wall -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -DPCCOMPILE -DMARTIN
|
||||
CFLAGS += -Wall -DEIGERD -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE -DPCCOMPILE -DMARTIN
|
||||
LDLIBS += -lm -lstdc++
|
||||
|
||||
PROGS = eigerDetectorServer
|
||||
@ -8,7 +8,7 @@ DESTDIR ?= bin
|
||||
INSTMODE = 0777
|
||||
|
||||
|
||||
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c FebControl.c Beb.c HardwareIO.c LocalLinkInterface.c Feb.c FebInterface.c
|
||||
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c FebControl.c Beb.c HardwareIO.c LocalLinkInterface.c FebInterface.c
|
||||
OBJS = $(SRC_CLNT:.c=.o)
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
CC = gcc
|
||||
CFLAGS += -Wall -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DPCCOMPILE -DSTOP_SERVER #-DVERBOSE
|
||||
CFLAGS += -Wall -DEIGERD -DPCCOMPILE -DSTOP_SERVER #-DVERBOSE
|
||||
CFLAGS += -DVIRTUAL -DVIRTUAL_9M
|
||||
MASTERFLAG += -DVIRTUAL_MASTER
|
||||
LDLIBS += -lm -lstdc++ -pthread
|
||||
|
@ -1,9 +1,9 @@
|
||||
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
|
||||
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
|
||||
Repsitory UUID: c24a9b223cbb066d3851599f4d977ae835feffe4
|
||||
Revision: 0
|
||||
Repsitory UUID: 178b83222380f7b7294cde66e66719c5d1c1363c
|
||||
Revision: 2
|
||||
Branch: refactor
|
||||
Last Changed Author: Dhanya_Thattil
|
||||
Last Changed Rev: 4099
|
||||
Last Changed Date: 2018-10-11 13:46:08.000000002 +0200 ./xparameters.h
|
||||
Last Changed Rev: 4125
|
||||
Last Changed Date: 2018-10-16 09:02:45.000000002 +0200 ./Makefile
|
||||
|
@ -1,6 +1,6 @@
|
||||
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
|
||||
#define GITREPUUID "c24a9b223cbb066d3851599f4d977ae835feffe4"
|
||||
#define GITREPUUID "178b83222380f7b7294cde66e66719c5d1c1363c"
|
||||
#define GITAUTH "Dhanya_Thattil"
|
||||
#define GITREV 0x4099
|
||||
#define GITDATE 0x20181011
|
||||
#define GITREV 0x4125
|
||||
#define GITDATE 0x20181016
|
||||
#define GITBRANCH "refactor"
|
||||
|
1
slsDetectorServers/eigerDetectorServer/logger.h
Symbolic link
1
slsDetectorServers/eigerDetectorServer/logger.h
Symbolic link
@ -0,0 +1 @@
|
||||
../slsDetectorServer/logger.h
|
@ -1,5 +1,3 @@
|
||||
//#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> //to gethostname
|
||||
@ -17,6 +15,9 @@
|
||||
#include "versionAPI.h"
|
||||
#endif
|
||||
|
||||
// Global variable from slsDetectorServer
|
||||
extern int debugflag;
|
||||
|
||||
int default_tau_from_file= -1;
|
||||
|
||||
#define BEB_NUM 34
|
||||
@ -106,7 +107,7 @@ int getFirmwareCheckResult(char** mess) {
|
||||
return firmware_compatibility;
|
||||
}
|
||||
|
||||
void checkFirmwareCompatibility(int flag){
|
||||
void checkFirmwareCompatibility(){
|
||||
firmware_compatibility = OK;
|
||||
firmware_check_done = 0;
|
||||
memset(firmware_message, 0, MAX_STR_LENGTH);
|
||||
@ -148,8 +149,8 @@ void checkFirmwareCompatibility(int flag){
|
||||
REQUIRED_FIRMWARE_VERSION,
|
||||
(long long int)client_sw_apiversion);
|
||||
|
||||
// return if flag is not zero, debug mode
|
||||
if (flag) {
|
||||
// return if debugflag is not zero, debug mode
|
||||
if (debugflag) {
|
||||
firmware_check_done = 1;
|
||||
return;
|
||||
}
|
||||
@ -1100,7 +1101,7 @@ int setHighVoltage(int val){
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
|
||||
void setTiming( enum externalCommunicationMode arg){
|
||||
enum externalCommunicationMode ret=GET_EXTERNAL_COMMUNICATION_MODE;
|
||||
if(arg != GET_EXTERNAL_COMMUNICATION_MODE){
|
||||
switch((int)arg){
|
||||
@ -1115,7 +1116,11 @@ enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
|
||||
#endif
|
||||
eiger_triggermode = ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum externalCommunicationMode getTiming() {
|
||||
enum externalCommunicationMode ret = GET_EXTERNAL_COMMUNICATION_MODE;
|
||||
ret = eiger_triggermode;
|
||||
switch((int)ret){
|
||||
case 0: ret = AUTO_TIMING; break;
|
||||
@ -1131,9 +1136,6 @@ enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* configure mac */
|
||||
|
||||
int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2, int ival) {
|
||||
@ -1832,4 +1834,3 @@ int getNumberOfOffsets(){return NOFFSET;}
|
||||
|
||||
|
||||
|
||||
//#endif
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
|
||||
#define GOODBYE (-200)
|
||||
#define PROGRAMMING_MODE (-200)
|
||||
#define MIN_REQRD_VRSN_T_RD_API 0x171220
|
||||
#define REQRD_FRMWR_VRSN 0x180615
|
||||
|
||||
|
@ -1,240 +1,231 @@
|
||||
|
||||
|
||||
#include "communication_funcs.h"
|
||||
//#include <sys/socket.h>
|
||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#include "logger.h"
|
||||
|
||||
//#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
char lastClientIP[INET_ADDRSTRLEN];
|
||||
char thisClientIP[INET_ADDRSTRLEN];
|
||||
int lockStatus;
|
||||
int differentClients;
|
||||
|
||||
//int socketDescriptor, file_des;
|
||||
const int send_rec_max_size=SEND_REC_MAX_SIZE;
|
||||
// Global variables from errno.h
|
||||
extern int errno;
|
||||
|
||||
// Variables that will be exported
|
||||
int lockStatus = 0;
|
||||
char lastClientIP[INET_ADDRSTRLEN] = "";
|
||||
char thisClientIP[INET_ADDRSTRLEN] = "";
|
||||
int differentClients = 0;
|
||||
int isControlServer = 1;
|
||||
int ret = FAIL;
|
||||
int fnum = 0;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
|
||||
char dummyClientIP[INET_ADDRSTRLEN];
|
||||
|
||||
|
||||
// Local variables
|
||||
char dummyClientIP[INET_ADDRSTRLEN] = "";
|
||||
const int send_rec_max_size = SEND_REC_MAX_SIZE;
|
||||
int myport = -1;
|
||||
// socket descriptor set
|
||||
fd_set readset, tempset;
|
||||
int isock=0, maxfd;
|
||||
// number of socket descrptor listening to
|
||||
int isock = 0;
|
||||
// value of socket descriptor,
|
||||
//becomes max value of socket descriptor (listen) and file descriptor (accept)
|
||||
int maxfd = 0;
|
||||
|
||||
|
||||
int myport=-1;
|
||||
|
||||
//struct sockaddr_in address;
|
||||
//#define VERBOSE
|
||||
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
int bindSocket(unsigned short int port_number) {
|
||||
int i;
|
||||
ret = FAIL;
|
||||
int socketDescriptor = -1;
|
||||
int i = 0;
|
||||
struct sockaddr_in addressS;
|
||||
|
||||
struct sockaddr_in addressS;
|
||||
int socketDescriptor;
|
||||
//int file_des;
|
||||
// same port
|
||||
if (myport == port_number) {
|
||||
sprintf(mess, "Cannot create %s socket with port %d. Already in use before.\n",
|
||||
(isControlServer ? "control":"stop"), port_number);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
// port ok
|
||||
else {
|
||||
|
||||
//file_des= -1;
|
||||
// create socket
|
||||
socketDescriptor = socket(AF_INET, SOCK_STREAM,0);
|
||||
// socket error
|
||||
if (socketDescriptor < 0) {
|
||||
sprintf(mess, "Cannot create %s socket with port %d\n",
|
||||
(isControlServer ? "control":"stop"), port_number);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
// socket success
|
||||
else {
|
||||
i = 1;
|
||||
// set port reusable
|
||||
setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
|
||||
// Set some fields in the serverAddress structure
|
||||
addressS.sin_family = AF_INET;
|
||||
addressS.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
addressS.sin_port = htons(port_number);
|
||||
|
||||
// bind socket error
|
||||
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS)) < 0){
|
||||
sprintf(mess, "Cannot bind %s socket to port %d.\n",
|
||||
(isControlServer ? "control":"stop"), port_number);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
// bind socket ok
|
||||
else {
|
||||
|
||||
// listen to socket
|
||||
if (listen(socketDescriptor, DEFAULT_BACKLOG) == 0) {
|
||||
// clear set of descriptors. set of descriptors needed?
|
||||
if (isock == 0) {
|
||||
FD_ZERO(&readset);
|
||||
}
|
||||
// add a socket descriptor from listen
|
||||
FD_SET(socketDescriptor, &readset);
|
||||
isock++;
|
||||
maxfd = socketDescriptor;
|
||||
// success
|
||||
myport = port_number;
|
||||
ret = OK;
|
||||
FILE_LOG(logINFO, (" %s socket bound: isock=%d port=%d fd=%d\n",
|
||||
(isControlServer ? "Control":"Stop"), isock, port_number, socketDescriptor));
|
||||
|
||||
}
|
||||
// listen socket error
|
||||
else {
|
||||
sprintf(mess, "Cannot bind %s socket to port %d.\n",
|
||||
(isControlServer ? "control":"stop"), port_number);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (myport==port_number)
|
||||
return -10;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
|
||||
|
||||
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
|
||||
|
||||
|
||||
|
||||
if (socketDescriptor < 0) {
|
||||
printf("Can not create socket\n");
|
||||
} else {
|
||||
|
||||
i = 1;
|
||||
setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
|
||||
// setsockopt(socketDescriptor, IPPROTO_TCP, TCP_NODELAY, (char *) &i, sizeof(i));
|
||||
// TCP_CORK
|
||||
|
||||
// Set some fields in the serverAddress structure.
|
||||
addressS.sin_family = AF_INET;
|
||||
addressS.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
addressS.sin_port = htons(port_number);
|
||||
|
||||
// memset(&address.sin_addr, 0, sizeof(address.sin_addr));
|
||||
|
||||
|
||||
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){
|
||||
|
||||
printf("Can not create socket\n");
|
||||
|
||||
socketDescriptor=-1;
|
||||
} else {
|
||||
if (listen(socketDescriptor, 5)==0) {
|
||||
|
||||
if (isock==0) {
|
||||
FD_ZERO(&readset);
|
||||
}
|
||||
|
||||
|
||||
FD_SET(socketDescriptor, &readset);
|
||||
isock++;
|
||||
maxfd = socketDescriptor;
|
||||
printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor);
|
||||
myport=port_number;
|
||||
} else
|
||||
printf("error on listen");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int getrlimit(int resource, struct rlimit *rlim);
|
||||
|
||||
|
||||
|
||||
return socketDescriptor;
|
||||
|
||||
return socketDescriptor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getServerError(int socketDescriptor)
|
||||
{
|
||||
if (socketDescriptor<0) return 1;
|
||||
else return 0;
|
||||
};
|
||||
|
||||
|
||||
int acceptConnection(int socketDescriptor) {
|
||||
int j;
|
||||
struct sockaddr_in addressC;
|
||||
int file_des = -1;
|
||||
struct timeval tv;
|
||||
socklen_t address_length = sizeof(struct sockaddr_in);
|
||||
|
||||
if (socketDescriptor < 0)
|
||||
return -1;
|
||||
|
||||
int j;
|
||||
// copy file descriptor set temporarily
|
||||
memcpy(&tempset, &readset, sizeof(tempset));
|
||||
|
||||
// set time out as 2777.77 hours?
|
||||
tv.tv_sec = 10000000;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
struct sockaddr_in addressC;
|
||||
int file_des=-1;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
// monitor file descrptors
|
||||
int result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
|
||||
|
||||
// timeout
|
||||
if (result == 0) {
|
||||
FILE_LOG(logDEBUG5, ("%s socket select() timed out!\n",
|
||||
(isControlServer ? "control":"stop"), myport));
|
||||
}
|
||||
|
||||
//socklen_t address_length;
|
||||
socklen_t address_length=sizeof(struct sockaddr_in);
|
||||
// error (not signal caught)
|
||||
else if (result < 0 && errno != EINTR) {
|
||||
FILE_LOG(logERROR, ("%s socket select() error: %s\n",
|
||||
(isControlServer ? "control":"stop"), myport, strerror(errno)));
|
||||
}
|
||||
|
||||
if (socketDescriptor<0)
|
||||
return -1;
|
||||
// activity in descriptor set
|
||||
else if (result > 0) {
|
||||
FILE_LOG(logDEBUG5, ("%s select returned!\n", (isControlServer ? "control":"stop")));
|
||||
|
||||
memcpy(&tempset, &readset, sizeof(tempset));
|
||||
tv.tv_sec = 10000000;
|
||||
tv.tv_usec = 0;
|
||||
result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
|
||||
// loop through the file descriptor set
|
||||
for (j = 0; j < maxfd + 1; ++j) {
|
||||
|
||||
if (result == 0) {
|
||||
printf("select() timed out!\n");
|
||||
} else if (result < 0 && errno != EINTR) {
|
||||
printf("Error in select(): %s\n", strerror(errno));
|
||||
} else if (result > 0) {
|
||||
#ifdef VERBOSE
|
||||
printf("select returned!\n");
|
||||
#endif
|
||||
for (j=0; j<maxfd+1; j++) {
|
||||
if (FD_ISSET(j, &tempset)) {
|
||||
#ifdef VERBOSE
|
||||
printf("fd %d is set\n",j);
|
||||
#endif
|
||||
FD_CLR(j, &tempset);
|
||||
// checks if file descriptor part of set
|
||||
if (FD_ISSET(j, &tempset)) {
|
||||
FILE_LOG(logDEBUG5, ("fd %d is set\n",j));
|
||||
|
||||
// clear the temporary set
|
||||
FD_CLR(j, &tempset);
|
||||
|
||||
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
|
||||
printf("Error in accept(): %s\n", strerror(errno));
|
||||
printf("Error: with server accept, connection refused %d\n", errno);
|
||||
|
||||
|
||||
switch(errno) {
|
||||
case EWOULDBLOCK:
|
||||
printf("ewouldblock eagain\n");
|
||||
break;
|
||||
case EBADF:
|
||||
printf("ebadf\n");
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
printf("econnaborted\n");
|
||||
break;
|
||||
case EFAULT:
|
||||
printf("efault\n");
|
||||
break;
|
||||
case EINTR:
|
||||
printf("eintr\n");
|
||||
break;
|
||||
case EINVAL:
|
||||
printf("einval\n");
|
||||
break;
|
||||
case EMFILE:
|
||||
printf("emfile\n");
|
||||
break;
|
||||
case ENFILE:
|
||||
printf("enfile\n");
|
||||
break;
|
||||
case ENOTSOCK:
|
||||
printf("enotsock\n");
|
||||
break;
|
||||
case EOPNOTSUPP:
|
||||
printf("eOPNOTSUPP\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
printf("ENOBUFS\n");
|
||||
break;
|
||||
case ENOMEM:
|
||||
printf("ENOMEM\n");
|
||||
break;
|
||||
case ENOSR:
|
||||
printf("ENOSR\n");
|
||||
break;
|
||||
case EPROTO:
|
||||
printf("EPROTO\n");
|
||||
break;
|
||||
default:
|
||||
printf("unknown error\n");
|
||||
}
|
||||
|
||||
// should remove descriptor
|
||||
|
||||
socketDescriptor=-1;
|
||||
} else {
|
||||
|
||||
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||
#ifdef VERBOSE
|
||||
printf("connection accepted %d\n",file_des);
|
||||
#endif
|
||||
FD_SET(file_des, &readset);
|
||||
maxfd = (maxfd < file_des)?file_des:maxfd;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return file_des;
|
||||
// accept connection (if error)
|
||||
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
|
||||
FILE_LOG(logERROR, ("%s socket accept() error. Connection refused.\n",
|
||||
"Error Number: %d, Message: %s\n",
|
||||
(isControlServer ? "control":"stop"),
|
||||
myport, errno, strerror(errno)));
|
||||
switch(errno) {
|
||||
case EWOULDBLOCK:
|
||||
FILE_LOG(logERROR, ("ewouldblock eagain"));
|
||||
break;
|
||||
case EBADF:
|
||||
FILE_LOG(logERROR, ("ebadf\n"));
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
FILE_LOG(logERROR, ("econnaborted\n"));
|
||||
break;
|
||||
case EFAULT:
|
||||
FILE_LOG(logERROR, ("efault\n"));
|
||||
break;
|
||||
case EINTR:
|
||||
FILE_LOG(logERROR, ("eintr\n"));
|
||||
break;
|
||||
case EINVAL:
|
||||
FILE_LOG(logERROR, ("einval\n"));
|
||||
break;
|
||||
case EMFILE:
|
||||
FILE_LOG(logERROR, ("emfile\n"));
|
||||
break;
|
||||
case ENFILE:
|
||||
FILE_LOG(logERROR, ("enfile\n"));
|
||||
break;
|
||||
case ENOTSOCK:
|
||||
FILE_LOG(logERROR, ("enotsock\n"));
|
||||
break;
|
||||
case EOPNOTSUPP:
|
||||
FILE_LOG(logERROR, ("eOPNOTSUPP\n"));
|
||||
break;
|
||||
case ENOBUFS:
|
||||
FILE_LOG(logERROR, ("ENOBUFS\n"));
|
||||
break;
|
||||
case ENOMEM:
|
||||
FILE_LOG(logERROR, ("ENOMEM\n"));
|
||||
break;
|
||||
case ENOSR:
|
||||
FILE_LOG(logERROR, ("ENOSR\n"));
|
||||
break;
|
||||
case EPROTO:
|
||||
FILE_LOG(logERROR, ("EPROTO\n"));
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR, ("unknown error\n"));
|
||||
}
|
||||
}
|
||||
// accept success
|
||||
else {
|
||||
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||
FILE_LOG(logDEBUG5, ("%s socket accepted connection, fd= %d\n",
|
||||
(isControlServer ? "control":"stop"), file_des));
|
||||
// add the file descriptor from accept
|
||||
FD_SET(file_des, &readset);
|
||||
maxfd = (maxfd < file_des)?file_des:maxfd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return file_des;
|
||||
}
|
||||
|
||||
|
||||
@ -244,22 +235,18 @@ int acceptConnection(int socketDescriptor) {
|
||||
|
||||
|
||||
void closeConnection(int file_des) {
|
||||
#ifdef VERY_VERBOSE
|
||||
#endif
|
||||
if(file_des>=0)
|
||||
close(file_des);
|
||||
FD_CLR(file_des, &readset);
|
||||
if(file_des >= 0)
|
||||
close(file_des);
|
||||
// remove file descriptor from set
|
||||
FD_CLR(file_des, &readset);
|
||||
}
|
||||
|
||||
void exitServer(int socketDescriptor) {
|
||||
if (socketDescriptor>=0)
|
||||
close(socketDescriptor);
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Closing server\n");
|
||||
#endif
|
||||
FD_CLR(socketDescriptor, &readset);
|
||||
socketDescriptor=-1;
|
||||
isock--;
|
||||
if (socketDescriptor >= 0)
|
||||
close(socketDescriptor);
|
||||
FILE_LOG(logDEBUG5, ("Closing %s server\n", (isControlServer ? "control":"stop")));
|
||||
FD_CLR(socketDescriptor, &readset);
|
||||
isock--;
|
||||
}
|
||||
|
||||
|
||||
@ -267,18 +254,18 @@ void exitServer(int socketDescriptor) {
|
||||
|
||||
void swapData(void* val,int length,intType itype){
|
||||
int i;
|
||||
int16_t* c= (int16_t*)val;
|
||||
int32_t* a= (int32_t*)val;
|
||||
int64_t* b= (int64_t*)val;
|
||||
for(i=0; length > 0; i++){
|
||||
int16_t* c = (int16_t*)val;
|
||||
int32_t* a = (int32_t*)val;
|
||||
int64_t* b = (int64_t*)val;
|
||||
for(i = 0; length > 0; i++){
|
||||
switch(itype){
|
||||
case INT16:
|
||||
c[i] = ((c[i] & 0x00FF) << 8) | ((c[i] & 0xFF00) >> 8);
|
||||
length -= sizeof(int16_t);
|
||||
break;
|
||||
case INT32:
|
||||
a[i]=((a[i] << 8) & 0xFF00FF00) | ((a[i] >> 8) & 0xFF00FF );
|
||||
a[i]=(a[i] << 16) | ((a[i] >> 16) & 0xFFFF);
|
||||
a[i] = ((a[i] << 8) & 0xFF00FF00) | ((a[i] >> 8) & 0xFF00FF );
|
||||
a[i] = (a[i] << 16) | ((a[i] >> 16) & 0xFFFF);
|
||||
length -= sizeof(int32_t);
|
||||
break;
|
||||
case INT64:
|
||||
@ -305,57 +292,59 @@ int sendData(int file_des, void* buf,int length, intType itype){
|
||||
|
||||
|
||||
int receiveData(int file_des, void* buf,int length, intType itype){
|
||||
int ret = receiveDataOnly(file_des, buf, length);
|
||||
int lret = receiveDataOnly(file_des, buf, length);
|
||||
#ifndef PCCOMPILE
|
||||
#ifdef EIGERD
|
||||
if (ret >= 0) swapData(buf, length, itype);
|
||||
if (lret >= 0) swapData(buf, length, itype);
|
||||
#endif
|
||||
#endif
|
||||
return ret;
|
||||
return lret;
|
||||
}
|
||||
|
||||
|
||||
int sendDataOnly(int file_des, void* buf,int length) {
|
||||
if (!length)
|
||||
return 0;
|
||||
int ret = write(file_des, buf, length); //value of -1 is other end socket crash as sigpipe is ignored
|
||||
if (ret < 0) cprintf(BG_RED, "Error writing to socket. Possible socket crash\n");
|
||||
return ret;
|
||||
int sendDataOnly(int file_des, void* buf,int length) {
|
||||
if (!length)
|
||||
return 0;
|
||||
int lret = write(file_des, buf, length); //value of -1 is other end socket crash as sigpipe is ignored
|
||||
if (lret < 0) {
|
||||
FILE_LOG(logERROR, ("Could not write to %s socket. Possible socket crash\n",
|
||||
(isControlServer ? "control":"stop")));
|
||||
}
|
||||
return lret;
|
||||
}
|
||||
|
||||
|
||||
int receiveDataOnly(int file_des, void* buf,int length) {
|
||||
int receiveDataOnly(int file_des, void* buf,int length) {
|
||||
|
||||
int total_received=0;
|
||||
int nreceiving;
|
||||
int nreceived;
|
||||
if (file_des<0) return -1;
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("want to receive %d Bytes\n", length);
|
||||
#endif
|
||||
int total_received = 0;
|
||||
int nreceiving;
|
||||
int nreceived;
|
||||
if (file_des<0) return -1;
|
||||
FILE_LOG(logDEBUG5, ("want to receive %d Bytes to %s server\n",
|
||||
length, (isControlServer ? "control":"stop")));
|
||||
|
||||
while(length > 0) {
|
||||
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; // (condition) ? if_true : if_false
|
||||
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
|
||||
if(!nreceived){
|
||||
if(!total_received) {
|
||||
return -1; //to handle it
|
||||
}
|
||||
break;
|
||||
}
|
||||
length-=nreceived;
|
||||
total_received+=nreceived;
|
||||
}
|
||||
while(length > 0) {
|
||||
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; // (condition) ? if_true : if_false
|
||||
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
|
||||
if(!nreceived){
|
||||
if(!total_received) {
|
||||
return -1; //to handle it
|
||||
}
|
||||
break;
|
||||
}
|
||||
length -= nreceived;
|
||||
total_received += nreceived;
|
||||
}
|
||||
|
||||
if (total_received>0)
|
||||
strcpy(thisClientIP,dummyClientIP);
|
||||
if (total_received>0)
|
||||
strcpy(thisClientIP,dummyClientIP);
|
||||
|
||||
if (strcmp(lastClientIP,thisClientIP))
|
||||
differentClients=1;
|
||||
else
|
||||
differentClients=0;
|
||||
if (strcmp(lastClientIP,thisClientIP))
|
||||
differentClients = 1;
|
||||
else
|
||||
differentClients = 0;
|
||||
|
||||
return total_received;
|
||||
return total_received;
|
||||
}
|
||||
|
||||
|
||||
@ -367,55 +356,49 @@ int sendModule(int file_des, sls_detector_module *myMod) {
|
||||
|
||||
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
|
||||
int ts=0;
|
||||
#ifdef VERBOSE
|
||||
int idac;
|
||||
#endif
|
||||
int nChips=myMod->nchip;
|
||||
int nChans=myMod->nchan;
|
||||
int nAdcs=myMod->nadc;
|
||||
int nDacs=myMod->ndac;
|
||||
//ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||
ts+=sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
|
||||
ts+=sendData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
|
||||
ts+=sendData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
|
||||
ts+=sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts+=sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
int ts = 0;
|
||||
int nChips = myMod->nchip;
|
||||
int nChans = myMod->nchan;
|
||||
int nAdcs = myMod->nadc;
|
||||
int nDacs = myMod->ndac;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("module of size %d sent\n",ts);
|
||||
#endif
|
||||
ts+= sendData(file_des,myMod->dacs,sizeof(int)*nDacs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("dacs of size %d sent\n",ts);
|
||||
int idac;
|
||||
for (idac=0; idac< nDacs; idac++)
|
||||
printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]);
|
||||
#endif
|
||||
ts+= sendData(file_des,myMod->adcs,sizeof(int)*nAdcs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("adcs of size %d sent\n", ts);
|
||||
#endif
|
||||
// send module structure
|
||||
ts += sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
|
||||
ts += sendData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
|
||||
ts += sendData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
|
||||
ts += sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts += sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts += sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts += sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts += sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
FILE_LOG(logDEBUG5, ("module of size %d sent\n",ts));
|
||||
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(sendAll){
|
||||
ts+=sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips of size %d sent\n", ts);
|
||||
#endif
|
||||
ts+=sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans of size %d sent - %d\n", ts, myMod->nchan);
|
||||
#endif
|
||||
}
|
||||
// send dac
|
||||
ts += sendData(file_des,myMod->dacs,sizeof(int)*nDacs,INT32);
|
||||
FILE_LOG(logDEBUG5, ("dacs of size %d sent\n",ts));
|
||||
{
|
||||
int idac;
|
||||
for (idac = 0; idac < nDacs; idac++)
|
||||
FILE_LOG(logDEBUG5, ("dac %d is %d\n",idac,(int)myMod->dacs[idac]));
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("module of size %d sent register %x\n", ts, myMod->reg);
|
||||
#endif
|
||||
return ts;
|
||||
// send adc
|
||||
ts += sendData(file_des,myMod->adcs,sizeof(int)*nAdcs,INT32);
|
||||
FILE_LOG(logDEBUG5, ("adcs of size %d sent\n", ts));
|
||||
|
||||
// some detectors dont require sending all trimbits etc.
|
||||
if(sendAll) {
|
||||
// chips
|
||||
ts += sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
|
||||
FILE_LOG(logDEBUG5, ("chips of size %d sent\n", ts));
|
||||
|
||||
// channels
|
||||
ts += sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
|
||||
FILE_LOG(logDEBUG5, ("chans of size %d sent - %d\n", ts, myMod->nchan));
|
||||
}
|
||||
|
||||
FILE_LOG(logDEBUG5, ("module of size %d sent register %x\n", ts, myMod->reg));
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
@ -425,146 +408,163 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||
}
|
||||
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) {
|
||||
int ts=0;
|
||||
int *dacptr=myMod->dacs;
|
||||
int *adcptr=myMod->adcs;
|
||||
int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs;
|
||||
int nChips, nchipold=myMod->nchip, nchipdiff;
|
||||
int nChans, nchanold=myMod->nchan, nchandiff;
|
||||
int nDacs, ndold=myMod->ndac, ndacdiff;
|
||||
int nAdcs, naold=myMod->nadc, nadcdiff;
|
||||
ts+=receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts+=receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts+=receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
int ts = 0;
|
||||
int *dacptr = myMod->dacs;
|
||||
int *adcptr = myMod->adcs;
|
||||
int *chipptr = myMod->chipregs, *chanptr = myMod->chanregs;
|
||||
int nChips, nchipold = myMod->nchip, nchipdiff;
|
||||
int nChans, nchanold = myMod->nchan, nchandiff;
|
||||
int nDacs, ndold = myMod->ndac, ndacdiff;
|
||||
int nAdcs, naold = myMod->nadc, nadcdiff;
|
||||
ts += receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
|
||||
ts += receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
|
||||
ts += receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
|
||||
ts += receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
|
||||
ts += receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
|
||||
ts += receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
|
||||
ts += receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
|
||||
ts += receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
|
||||
|
||||
myMod->dacs=dacptr;
|
||||
myMod->adcs=adcptr;
|
||||
myMod->chipregs=chipptr;
|
||||
myMod->chanregs=chanptr;
|
||||
myMod->dacs = dacptr;
|
||||
myMod->adcs = adcptr;
|
||||
myMod->chipregs = chipptr;
|
||||
myMod->chanregs = chanptr;
|
||||
|
||||
#ifdef EIGERD
|
||||
//feature to exclude sending of trimbtis, nchips=0,nchans=0 in that case
|
||||
if(myMod->nchip == 0 && myMod->nchan == 0) {
|
||||
receiveAll=0;
|
||||
nchipold=0;
|
||||
nchanold=0;
|
||||
}
|
||||
//exclude sending of trimbtis, nchips = 0,nchans = 0 in that case
|
||||
if(myMod->nchip == 0 && myMod->nchan == 0) {
|
||||
receiveAll = 0;
|
||||
nchipold = 0;
|
||||
nchanold = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nChips=myMod->nchip;
|
||||
nchipdiff=nChips-nchipold;
|
||||
if (nchipold!=nChips) {
|
||||
printf("received wrong number of chips\n");
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("received %d chips\n",nChips);
|
||||
#endif
|
||||
nChips = myMod->nchip;
|
||||
nchipdiff = nChips-nchipold;
|
||||
if (nchipold != nChips) {
|
||||
FILE_LOG(logERROR, ("received wrong number of chips\n"));
|
||||
}
|
||||
else
|
||||
FILE_LOG(logDEBUG5, ("received %d chips\n",nChips));
|
||||
|
||||
nChans=myMod->nchan;
|
||||
nchandiff=nChans-nchanold;
|
||||
if (nchanold!=nChans) {
|
||||
printf("received wrong number of channels\n");
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("received %d chans\n",nChans);
|
||||
#endif
|
||||
nChans = myMod->nchan;
|
||||
nchandiff = nChans-nchanold;
|
||||
if (nchanold != nChans) {
|
||||
FILE_LOG(logERROR, ("received wrong number of channels\n"));
|
||||
}
|
||||
else
|
||||
FILE_LOG(logDEBUG5, ("received %d chans\n",nChans));
|
||||
|
||||
|
||||
nDacs=myMod->ndac;
|
||||
ndacdiff=nDacs-ndold;
|
||||
if (ndold!=nDacs) {
|
||||
printf("received wrong number of dacs\n");
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("received %d dacs\n",nDacs);
|
||||
#endif
|
||||
nDacs = myMod->ndac;
|
||||
ndacdiff = nDacs-ndold;
|
||||
if (ndold != nDacs) {
|
||||
FILE_LOG(logERROR, ("received wrong number of dacs\n"));
|
||||
}
|
||||
else
|
||||
FILE_LOG(logDEBUG5, ("received %d dacs\n",nDacs));
|
||||
|
||||
nAdcs=myMod->nadc;
|
||||
nadcdiff=nAdcs-naold;
|
||||
if (naold!=nAdcs) {
|
||||
printf("received wrong number of adcs\n");
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("received %d adcs\n",nAdcs);
|
||||
#endif
|
||||
if (ndacdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->dacs, sizeof(int)*nDacs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("dacs received\n");
|
||||
int id;
|
||||
for (id=0; id<nDacs; id++)
|
||||
printf("dac %d val %d\n",id, (int)myMod->dacs[id]);
|
||||
nAdcs = myMod->nadc;
|
||||
nadcdiff = nAdcs-naold;
|
||||
if (naold != nAdcs) {
|
||||
FILE_LOG(logERROR, ("received wrong number of adcs\n"));
|
||||
}
|
||||
else
|
||||
FILE_LOG(logDEBUG5, ("received %d adcs\n",nAdcs));
|
||||
if (ndacdiff <= 0) {
|
||||
ts += receiveData(file_des,myMod->dacs, sizeof(int)*nDacs,INT32);
|
||||
FILE_LOG(logDEBUG5, ("dacs received\n"));
|
||||
int id;
|
||||
for (id = 0; id<nDacs; id++)
|
||||
FILE_LOG(logDEBUG5, ("dac %d val %d\n",id, (int)myMod->dacs[id]));
|
||||
} else {
|
||||
dacptr = (int*)malloc(ndacdiff*sizeof(int));
|
||||
myMod->ndac = ndold;
|
||||
ts += receiveData(file_des,myMod->dacs, sizeof(int)*ndold,INT32);
|
||||
ts += receiveData(file_des,dacptr, sizeof(int)*ndacdiff,INT32);
|
||||
free(dacptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nadcdiff <= 0) {
|
||||
ts += receiveData(file_des,myMod->adcs, sizeof(int)*nAdcs,INT32);
|
||||
FILE_LOG(logDEBUG5, ("adcs received\n"));
|
||||
} else {
|
||||
adcptr = (int*)malloc(nadcdiff*sizeof(int));
|
||||
myMod->nadc = naold;
|
||||
ts += receiveData(file_des,myMod->adcs, sizeof(int)*naold,INT32);
|
||||
ts += receiveData(file_des,adcptr, sizeof(int)*nadcdiff,INT32);
|
||||
free(adcptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
} else {
|
||||
dacptr=(int*)malloc(ndacdiff*sizeof(int));
|
||||
myMod->ndac=ndold;
|
||||
ts+=receiveData(file_des,myMod->dacs, sizeof(int)*ndold,INT32);
|
||||
ts+=receiveData(file_des,dacptr, sizeof(int)*ndacdiff,INT32);
|
||||
free(dacptr);
|
||||
return FAIL;
|
||||
}
|
||||
// some detectors dont require sending all trimbits etc.
|
||||
if(receiveAll){
|
||||
|
||||
if (nadcdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->adcs, sizeof(int)*nAdcs,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("adcs received\n");
|
||||
#endif
|
||||
} else {
|
||||
adcptr=(int*)malloc(nadcdiff*sizeof(int));
|
||||
myMod->nadc=naold;
|
||||
ts+=receiveData(file_des,myMod->adcs, sizeof(int)*naold,INT32);
|
||||
ts+=receiveData(file_des,adcptr, sizeof(int)*nadcdiff,INT32);
|
||||
free(adcptr);
|
||||
return FAIL;
|
||||
}
|
||||
if (nchipdiff <= 0) {
|
||||
ts += receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
FILE_LOG(logDEBUG5, ("chips received\n"));
|
||||
} else {
|
||||
chipptr = (int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip = nchipold;
|
||||
ts += receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts += receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
/*some detectors dont require sending all trimbits etc.*/
|
||||
if(receiveAll){
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chipptr=(int*)malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
|
||||
ts+=receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=(int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts+=receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("received module of size %d register %x\n",ts,myMod->reg);
|
||||
#endif
|
||||
|
||||
return ts;
|
||||
if (nchandiff <= 0) {
|
||||
ts += receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
|
||||
FILE_LOG(logDEBUG5, ("chans received\n"));
|
||||
} else {
|
||||
chanptr = (int*)malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan = nchanold;
|
||||
ts += receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
|
||||
ts += receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
|
||||
free(chanptr);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
FILE_LOG(logDEBUG5, ("received module of size %d register %x\n",ts,myMod->reg));
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
void Server_LockedError() {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Detector locked by %s\n", lastClientIP);
|
||||
FILE_LOG(logWARNING, (mess));
|
||||
}
|
||||
|
||||
|
||||
int Server_VerifyLock() {
|
||||
if (differentClients && lockStatus)
|
||||
Server_LockedError();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize) {
|
||||
|
||||
// update if different clients
|
||||
if (update && ret == OK && differentClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
int ret1 = ret;
|
||||
sendData(fileDes, &ret1,sizeof(ret1), INT32);
|
||||
if(ret == FAIL) {
|
||||
// send error message
|
||||
if (strlen(mess))
|
||||
sendData(fileDes, mess, MAX_STR_LENGTH, OTHER);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
FILE_LOG(logERROR, ("No error message provided for this failure in %s "
|
||||
"server. Will mess up TCP.\n",
|
||||
(isControlServer ? "control":"stop")));
|
||||
}
|
||||
// send return value
|
||||
sendData(fileDes, retval, retvalSize, itype);
|
||||
}
|
||||
|
@ -37,11 +37,34 @@ int receiveData(int file_des, void* buf,int length, intType itype);
|
||||
int sendDataOnly(int file_des, void* buf,int length);
|
||||
int receiveDataOnly(int file_des, void* buf,int length);
|
||||
|
||||
|
||||
int getServerError(int socketDescriptor);
|
||||
int sendModule(int file_des, sls_detector_module *myMod);
|
||||
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll);
|
||||
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll);
|
||||
|
||||
/**
|
||||
* Servers sets and prints error message for locked server
|
||||
* @returns success of operaton
|
||||
*/
|
||||
void Server_LockedError();
|
||||
|
||||
|
||||
/**
|
||||
* Server verifies if it is unlocked,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @returns success of operaton
|
||||
*/
|
||||
int Server_VerifyLock();
|
||||
|
||||
|
||||
/**
|
||||
* Server sends result to client (also set ret to force_update if different clients)
|
||||
* @param fileDes file descriptor for the socket
|
||||
* @param itype 32 or 64 or others to determine to swap data from big endian to little endian
|
||||
* @param update 1 if one must update if different clients, else 0
|
||||
* @param retval pointer to result
|
||||
* @param retvalSize size of result
|
||||
*/
|
||||
void Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize);
|
||||
|
||||
#endif
|
||||
|
63
slsDetectorServers/slsDetectorServer/logger.h
Normal file
63
slsDetectorServers/slsDetectorServer/logger.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifdef FIFODEBUG
|
||||
#define FILELOG_MAX_LEVEL logDEBUG5
|
||||
#elif VERYVERBOSE
|
||||
#define FILELOG_MAX_LEVEL logDEBUG4
|
||||
#elif VERBOSE
|
||||
#define FILELOG_MAX_LEVEL logDEBUG
|
||||
#endif
|
||||
|
||||
#ifndef FILELOG_MAX_LEVEL
|
||||
#define FILELOG_MAX_LEVEL logINFOBLUE
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
logERROR, logWARNING, logINFO, logINFOBLUE,
|
||||
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5
|
||||
}TLogLevel;
|
||||
|
||||
#define ERROR_MSG_LENGTH 1000
|
||||
|
||||
#define FILE_LOG(lvl, fmt, ...) \
|
||||
if (lvl > FILELOG_MAX_LEVEL); \
|
||||
else {char* temp = FILELOG_BuildLog fmt; FILELOG_PrintLog(lvl, temp);free(temp);}
|
||||
|
||||
static inline void FILELOG_PrintLog(TLogLevel level, char* m) {
|
||||
switch(level) {
|
||||
case logERROR: cprintf(RED BOLD, "ERROR: %s", m); break;
|
||||
case logWARNING: cprintf(YELLOW BOLD, "WARNING: %s", m); break;
|
||||
case logINFOBLUE: cprintf(BLUE, "INFO: %s", m); break;
|
||||
case logINFO: cprintf(RESET, "INFO: %s", m); break;
|
||||
case logDEBUG: cprintf(MAGENTA, "DEBUG: %s", m); break;
|
||||
case logDEBUG1: cprintf(MAGENTA, "DEBUG1: %s", m); break;
|
||||
case logDEBUG2: cprintf(MAGENTA, "DEBUG2: %s", m); break;
|
||||
case logDEBUG3: cprintf(MAGENTA, "DEBUG3: %s", m); break;
|
||||
case logDEBUG4: cprintf(MAGENTA, "DEBUG4: %s", m); break;
|
||||
case logDEBUG5: cprintf(MAGENTA, "DEBUG5: %s", m); break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline char* FILELOG_BuildLog(const char* fmt, ...) {
|
||||
char* p;
|
||||
va_list ap;
|
||||
p = malloc(ERROR_MSG_LENGTH);
|
||||
va_start(ap, fmt);
|
||||
int ret = vsnprintf(p, ERROR_MSG_LENGTH, fmt, ap);
|
||||
va_end(ap);
|
||||
if (ret < 0 || ret >= ERROR_MSG_LENGTH) {
|
||||
FILELOG_PrintLog(logERROR, ("Could not print the "
|
||||
"complete error message in the next print.\n"));
|
||||
}
|
||||
return p;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
#ifndef SLS_DETECTOR_FUNCTION_LIST_H
|
||||
#define SLS_DETECTOR_FUNCTION_LIST_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorServer_defs.h" // DAC_INDEX, ADC_INDEX, also include RegisterDefs.h
|
||||
|
||||
@ -22,7 +18,7 @@ int isFirmwareCheckDone();
|
||||
int getFirmwareCheckResult(char** mess);
|
||||
#endif
|
||||
|
||||
void checkFirmwareCompatibility(int flag);
|
||||
void checkFirmwareCompatibility();
|
||||
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
|
||||
int checkType();
|
||||
u_int32_t testFpga(void);
|
||||
@ -166,7 +162,8 @@ int setHighVoltage(int val);
|
||||
|
||||
|
||||
// parameters - timing, extsig
|
||||
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg);
|
||||
void setTiming( enum externalCommunicationMode arg);
|
||||
enum externalCommunicationMode getTiming();
|
||||
|
||||
// configure mac
|
||||
#ifdef JUNGFRAUD
|
||||
@ -264,6 +261,3 @@ int getNumberOfOffsets();
|
||||
int getNumberOfChannelsPerChip();
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "communication_funcs.h"
|
||||
#include "slsDetectorServer_funcs.h"
|
||||
|
||||
@ -12,8 +12,13 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int sockfd;
|
||||
// Global variables from communication_funcs
|
||||
extern int isControlServer;
|
||||
extern int ret;
|
||||
|
||||
// Global variables from slsDetectorServer_funcs
|
||||
extern int sockfd;
|
||||
extern int debugflag;
|
||||
|
||||
void error(char *msg){
|
||||
perror(msg);
|
||||
@ -22,9 +27,7 @@ void error(char *msg){
|
||||
int main(int argc, char *argv[]){
|
||||
int portno = DEFAULT_PORTNO;
|
||||
int retval = OK;
|
||||
int sd, fd;
|
||||
int debugflag = 0;
|
||||
int controlserver = 1;
|
||||
int fd = 0;
|
||||
|
||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||
// subsequent read/write to socket gives error - must handle locally
|
||||
@ -35,21 +38,21 @@ int main(int argc, char *argv[]){
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||
cprintf(BLUE,"Detected stop server\n");
|
||||
controlserver = 0;
|
||||
FILE_LOG(logINFO, ("Detected stop server\n"));
|
||||
isControlServer = 0;
|
||||
}
|
||||
else if(!strcasecmp(argv[i],"-devel")){
|
||||
cprintf(BLUE,"Detected developer mode\n");
|
||||
FILE_LOG(logINFO, ("Detected developer mode\n"));
|
||||
debugflag = 1;
|
||||
}
|
||||
#ifdef JUNGFRAUD
|
||||
else if(!strcasecmp(argv[i],"-update")){
|
||||
cprintf(BLUE,"Detected update mode\n");
|
||||
FILE_LOG(logINFO, ("Detected update mode\n"));
|
||||
debugflag = PROGRAMMING_MODE;
|
||||
}
|
||||
#endif
|
||||
else if(strchr(argv[i],'-') != NULL) {
|
||||
cprintf(RED,"cannot scan program argument %s\n", argv[1]);
|
||||
FILE_LOG(logERROR, ("cannot scan program argument %s\n", argv[1]));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -59,79 +62,60 @@ int main(int argc, char *argv[]){
|
||||
char cmd[100];
|
||||
memset(cmd, 0, 100);
|
||||
#endif
|
||||
if (controlserver) {
|
||||
if (isControlServer) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
FILE_LOG(logINFOBLUE,
|
||||
("***************************************************\n"
|
||||
"********* opening control server on port %d **********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
, portno));
|
||||
#ifdef STOP_SERVER
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < argc; ++i)
|
||||
sprintf(cmd, "%s %s", cmd, argv[i]);
|
||||
sprintf(cmd,"%s -stopserver&", cmd);
|
||||
cprintf(BLUE,"cmd:%s\n", cmd);
|
||||
FILE_LOG(logINFO, ("Command to start stop server:%s\n", cmd));
|
||||
system(cmd);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
portno = DEFAULT_PORTNO + 1;
|
||||
FILE_LOG(logINFOBLUE,
|
||||
("***************************************************\n"
|
||||
"*********** opening stop server on port %d ***********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
, portno));
|
||||
}
|
||||
|
||||
setModeFlag(debugflag); //defined in slsDetectorServer_funcs
|
||||
init_detector(controlserver); //defined in slsDetectorServer_funcs
|
||||
init_detector();
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
sockfd=sd;
|
||||
if (getServerError(sd)) { //defined in communication_funcs
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
{ // bind socket
|
||||
sockfd = bindSocket(portno);
|
||||
if (ret == FAIL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table(); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERBOSE
|
||||
printf("function table assigned \n");
|
||||
#endif
|
||||
// assign function table
|
||||
function_table();
|
||||
|
||||
if (controlserver)
|
||||
printf("\nControl Server Ready...\n\n");
|
||||
else
|
||||
printf("\nStop Server Ready...\n\n");
|
||||
if (isControlServer) {
|
||||
FILE_LOG(logINFO, ("Control Server Ready...\n\n"));
|
||||
} else {
|
||||
FILE_LOG(logINFO, ("Stop Server Ready...\n\n"));
|
||||
}
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
if (fd>0) {
|
||||
retval=decode_function(fd); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
// waits for connection
|
||||
while(retval != GOODBYE) {
|
||||
fd = acceptConnection(sockfd);
|
||||
if (fd > 0) {
|
||||
retval = decode_function(fd);
|
||||
closeConnection(fd);
|
||||
}
|
||||
}
|
||||
|
||||
exitServer(sockfd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
exitServer(sockfd);
|
||||
FILE_LOG(logINFO,("Goodbye!\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,12 +6,12 @@
|
||||
|
||||
// initialization functions
|
||||
int printSocketReadError();
|
||||
void setModeFlag(int);
|
||||
void basictests();
|
||||
void init_detector(int);
|
||||
void init_detector();
|
||||
int decode_function(int);
|
||||
const char* getFunctionName(enum detFuncs func);
|
||||
void function_table();
|
||||
void functionNotImplemented();
|
||||
int M_nofunc(int);
|
||||
int M_nofuncMode(int);
|
||||
|
||||
|
@ -27,6 +27,8 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
|
||||
: detId(id),
|
||||
sharedMemory(0),
|
||||
thisDetector(0),
|
||||
thisDetectorControl(0),
|
||||
thisDetectorStop(0),
|
||||
thisReceiver(0),
|
||||
controlSocket(0),
|
||||
stopSocket(0),
|
||||
@ -55,10 +57,13 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
|
||||
initializeDetectorStructurePointers();
|
||||
}
|
||||
|
||||
|
||||
slsDetector::slsDetector(int multiId, int id, bool verify)
|
||||
: detId(id),
|
||||
sharedMemory(0),
|
||||
thisDetector(0),
|
||||
thisDetectorControl(0),
|
||||
thisDetectorStop(0),
|
||||
thisReceiver(0),
|
||||
controlSocket(0),
|
||||
stopSocket(0),
|
||||
@ -85,6 +90,10 @@ slsDetector::~slsDetector() {
|
||||
sharedMemory->UnmapSharedMemory(thisDetector);
|
||||
delete sharedMemory;
|
||||
}
|
||||
if(thisDetectorControl)
|
||||
delete thisDetectorControl;
|
||||
if(thisDetectorStop)
|
||||
delete thisDetectorStop;
|
||||
if(thisReceiver)
|
||||
delete thisReceiver;
|
||||
if(controlSocket)
|
||||
@ -107,8 +116,7 @@ int slsDetector::checkVersionCompatibility(portType t) {
|
||||
if (t == DATA_PORT)
|
||||
fnum = F_RECEIVER_CHECK_VERSION;
|
||||
int ret = FAIL;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
char mess[MAX_STR_LENGTH] = {0};
|
||||
int64_t arg = 0;
|
||||
|
||||
// detector
|
||||
@ -205,57 +213,56 @@ int slsDetector::checkVersionCompatibility(portType t) {
|
||||
|
||||
|
||||
int64_t slsDetector::getId( idMode mode) {
|
||||
int fnum = F_GET_ID;
|
||||
int ret = FAIL;
|
||||
int arg = (int)mode;
|
||||
int64_t retval = -1;
|
||||
|
||||
int64_t retval=-1;
|
||||
int fnum=F_GET_ID,fnum2 = F_GET_RECEIVER_ID;
|
||||
int ret=FAIL;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
FILE_LOG(logDEBUG5) << "Getting id type " << mode;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl << "Getting id type "<< mode << std::endl;
|
||||
#endif
|
||||
if (mode==THIS_SOFTWARE_VERSION) {
|
||||
ret=OK;
|
||||
retval=GITDATE;
|
||||
} else if (mode==RECEIVER_VERSION) {
|
||||
// client version
|
||||
if (mode == THIS_SOFTWARE_VERSION) {
|
||||
ret = OK;
|
||||
retval = GITDATE;
|
||||
}
|
||||
|
||||
// receiver version
|
||||
else if (mode==RECEIVER_VERSION) {
|
||||
fnum = F_GET_RECEIVER_ID;
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum2, NULL, 0, &retval, sizeof(retval));
|
||||
ret=thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if(ret==FORCE_UPDATE)
|
||||
ret=updateReceiver();
|
||||
// handle ret
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(OTHER_ERROR_CODE));
|
||||
else if(ret == FORCE_UPDATE)
|
||||
ret = updateReceiver();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
// detector versions
|
||||
else {
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() != OK)
|
||||
ret = FAIL;
|
||||
else{
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&mode,sizeof(mode));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
else {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
if (connectControl() == OK){
|
||||
ret = thisDetectorControl->Client_Send(fnum,
|
||||
&arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
// handle ret
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(OTHER_ERROR_CODE));
|
||||
else if (ret == FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret==FAIL) {
|
||||
std::cout<< "Get id failed " << std::endl;
|
||||
return ret;
|
||||
} else {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Id "<< mode <<" is " << hex <<retval << std::setbase(10)
|
||||
<< std::endl;
|
||||
#endif
|
||||
return retval;
|
||||
|
||||
if (ret != FAIL) {
|
||||
FILE_LOG(logDEBUG5) << "Id ("<< mode << "): 0x" << std::hex << retval << std::setbase(10);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -583,10 +590,20 @@ void slsDetector::initializeMembers() {
|
||||
chanregs = (int*)(goff + thisDetector->chanoff);
|
||||
gain = (int*)(goff + thisDetector->gainoff);
|
||||
offset = (int*)(goff + thisDetector->offsetoff);
|
||||
if (thisDetectorControl) {
|
||||
delete thisDetectorControl;
|
||||
thisDetectorControl = 0;
|
||||
}
|
||||
if (thisDetectorStop) {
|
||||
delete thisDetectorStop;
|
||||
thisDetectorStop = 0;
|
||||
}
|
||||
if (thisReceiver) {
|
||||
delete thisReceiver;
|
||||
thisReceiver = 0;
|
||||
}
|
||||
thisDetectorControl = new ClientInterface(controlSocket, detId, "Detector (Control server)");
|
||||
thisDetectorStop = new ClientInterface(stopSocket, detId, "Detector (Stop server)");
|
||||
thisReceiver = new ClientInterface(dataSocket, detId, "Receiver");
|
||||
}
|
||||
|
||||
@ -853,43 +870,32 @@ slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multiId, b
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
// static function
|
||||
slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cport) {
|
||||
int fnum=F_GET_DETECTOR_TYPE;
|
||||
int retval = FAIL;
|
||||
detectorType t = GENERIC;
|
||||
int fnum = F_GET_DETECTOR_TYPE;
|
||||
detectorType retval = GENERIC;
|
||||
MySocketTCP* mySocket = 0;
|
||||
|
||||
try {
|
||||
mySocket = new MySocketTCP(name, cport);
|
||||
} catch(...) {
|
||||
std::cout << "Cannot create socket to server " << name << " over port " << cport << std::endl;
|
||||
return t;
|
||||
FILE_LOG(logERROR) << "Cannot create socket to control server " << name << " over port " << cport;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Getting detector type " << std::endl;
|
||||
#endif
|
||||
FILE_LOG(logINFO) << "Getting detector type ";
|
||||
if (mySocket->Connect() >= 0) {
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
int ret = FAIL; // not needed but is in protocol from server
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
mySocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
if (retval!=FAIL) {
|
||||
mySocket->ReceiveDataOnly(&t,sizeof(t));
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Detector type is "<< t << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
char mess[MAX_STR_LENGTH];
|
||||
mySocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
FILE_LOG(logDEBUG5) << "Detector type is " << retval;
|
||||
mySocket->Disconnect();
|
||||
} else {
|
||||
std::cout << "Cannot connect to server " << name << " over port " << cport << std::endl;
|
||||
FILE_LOG(logERROR) << "Cannot connect to server " << name << " over port " << cport;
|
||||
}
|
||||
delete mySocket;
|
||||
return t;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -897,8 +903,6 @@ int slsDetector::setDetectorType(detectorType const type) {
|
||||
int ret=FAIL;
|
||||
int fnum=F_GET_DETECTOR_TYPE,fnum2=F_GET_RECEIVER_TYPE;
|
||||
detectorType retval = type;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
|
||||
if (type != GET_DETECTOR_TYPE) {
|
||||
#ifdef VERBOSE
|
||||
@ -1217,7 +1221,8 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in
|
||||
|
||||
if (retval!=FAIL) {
|
||||
checkOnline();
|
||||
|
||||
thisDetectorControl->SetSocket(controlSocket);
|
||||
thisDetectorStop->SetSocket(stopSocket);
|
||||
// check for version compatibility
|
||||
switch (thisDetector->myDetectorType) {
|
||||
case EIGER:
|
||||
@ -1352,16 +1357,15 @@ int slsDetector::setPort(portType index, int num) {
|
||||
if(s==dataSocket)
|
||||
fnum = fnum2;
|
||||
s->SendDataOnly(&fnum,sizeof(fnum));
|
||||
s->SendDataOnly(&index,sizeof(index));
|
||||
s->SendDataOnly(&num,sizeof(num));
|
||||
s->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
s->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
} else {
|
||||
s->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
s->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
|
||||
s->Disconnect();
|
||||
}else{
|
||||
if (index == CONTROL_PORT){
|
||||
@ -1539,24 +1543,23 @@ int slsDetector::exitServer() {
|
||||
|
||||
|
||||
int slsDetector::execCommand(std::string cmd) {
|
||||
int fnum = F_EXEC_COMMAND;
|
||||
int ret = FAIL;
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
char arg[MAX_STR_LENGTH]="", retval[MAX_STR_LENGTH]="";
|
||||
int fnum=F_EXEC_COMMAND;
|
||||
int ret=FAIL;
|
||||
strcpy(arg,cmd.c_str());
|
||||
FILE_LOG(logDEBUG5) << "Sending command to detector " << arg;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Sending command " << arg << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(arg,MAX_STR_LENGTH);
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
controlSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH);
|
||||
std::cout << "Detector returned:" << retval << std::endl;
|
||||
ret = thisDetectorControl->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectControl();
|
||||
// handle ret
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(OTHER_ERROR_CODE));
|
||||
else
|
||||
FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -1840,8 +1843,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
||||
slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings isettings) {
|
||||
int fnum = F_SET_SETTINGS;
|
||||
int ret = FAIL;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
char mess[MAX_STR_LENGTH] = {0};
|
||||
int retval = -1;
|
||||
int arg = isettings;
|
||||
#ifdef VERBOSE
|
||||
@ -2417,7 +2419,7 @@ int slsDetector::configureMAC() {
|
||||
int ret=FAIL;
|
||||
int fnum=F_CONFIGURE_MAC;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
char arg[6][50];memset(arg,0,sizeof(char)*6*50);
|
||||
char arg[6][50] = {0};
|
||||
int retval=-1;
|
||||
|
||||
// to send 3d positions to detector
|
||||
@ -2572,8 +2574,7 @@ int slsDetector::configureMAC() {
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
if (thisDetector->myDetectorType == EIGER) {
|
||||
//rewrite detectormac, detector ip
|
||||
char arg[2][50];
|
||||
memset(arg,0,sizeof(arg));
|
||||
char arg[2][50] = {0};
|
||||
uint64_t idetectormac = 0;
|
||||
uint32_t idetectorip = 0;
|
||||
controlSocket->ReceiveDataOnly(arg,sizeof(arg));
|
||||
@ -3058,41 +3059,23 @@ int slsDetector::getADC(dacIndex index) {
|
||||
|
||||
slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunicationMode(
|
||||
externalCommunicationMode pol) {
|
||||
int fnum = F_SET_EXTERNAL_COMMUNICATION_MODE;
|
||||
int ret = FAIL;
|
||||
int arg = pol;
|
||||
externalCommunicationMode retval = GET_EXTERNAL_COMMUNICATION_MODE;;
|
||||
int fnum=F_SET_EXTERNAL_COMMUNICATION_MODE;
|
||||
int ret=FAIL;
|
||||
|
||||
FILE_LOG(logDEBUG5) << "Setting communication to mode "<< pol;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Setting communication to mode " << pol << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
else {
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
// handle ret
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(OTHER_ERROR_CODE));
|
||||
else if (ret == FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
} else {
|
||||
retval=GET_EXTERNAL_COMMUNICATION_MODE;
|
||||
ret=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Communication mode "<< " set to" << retval << std::endl;
|
||||
#endif
|
||||
if (ret==FAIL) {
|
||||
std::cout<< "Setting communication mode failed" << std::endl;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@ -3101,57 +3084,25 @@ slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunication
|
||||
|
||||
slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags(
|
||||
externalSignalFlag pol, int signalindex) {
|
||||
int fnum = F_SET_EXTERNAL_SIGNAL_FLAG;
|
||||
int ret = FAIL;
|
||||
int arg[2] = {signalindex, pol};
|
||||
externalSignalFlag retval = GET_EXTERNAL_SIGNAL_FLAG;
|
||||
|
||||
FILE_LOG(logDEBUG5) << "Setting signal "<< signalindex << " to flag" << pol;
|
||||
|
||||
|
||||
|
||||
int arg[2];
|
||||
externalSignalFlag retval;
|
||||
int ret=FAIL;
|
||||
int fnum=F_SET_EXTERNAL_SIGNAL_FLAG;
|
||||
char mess[MAX_STR_LENGTH]="";
|
||||
|
||||
arg[0]=signalindex;
|
||||
arg[1]=pol;
|
||||
|
||||
retval=GET_EXTERNAL_SIGNAL_FLAG;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Setting signal "<< signalindex << " to flag" << pol << std::endl;
|
||||
#endif
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (connectControl() == OK){
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&arg,sizeof(arg));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
else {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
ret = thisDetectorControl->Client_Send(fnum, arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectControl();
|
||||
if (ret==FORCE_UPDATE)
|
||||
// handle ret
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(OTHER_ERROR_CODE));
|
||||
else if (ret == FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
} else {
|
||||
retval=GET_EXTERNAL_SIGNAL_FLAG;
|
||||
ret=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Signal "<< signalindex << " flag set to" << retval << std::endl;
|
||||
if (ret==FAIL) {
|
||||
std::cout<< "Set signal flag failed " << std::endl;
|
||||
}
|
||||
#endif
|
||||
return retval;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3833,10 +3784,8 @@ std::string slsDetector::setReceiverStreamingIP(std::string sourceIP) {
|
||||
|
||||
int fnum=F_RECEIVER_STREAMING_SRC_IP;
|
||||
int ret = FAIL;
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg,0,sizeof(arg));
|
||||
char retval[MAX_STR_LENGTH];
|
||||
memset(retval,0, sizeof(retval));
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
// if empty, give rx_hostname
|
||||
if (sourceIP.empty()) {
|
||||
@ -3861,7 +3810,7 @@ std::string slsDetector::setReceiverStreamingIP(std::string sourceIP) {
|
||||
}
|
||||
// on success put IP as std::string into arg
|
||||
else {
|
||||
dataSocket->ConvertInternetAddresstoIpString(result, arg, MAX_STR_LENGTH);
|
||||
dataSocket->ConvertInternetAddresstoIpString(result, arg, sizeof(arg));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3881,7 +3830,7 @@ std::string slsDetector::setReceiverStreamingIP(std::string sourceIP) {
|
||||
std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, MAX_STR_LENGTH, retval, MAX_STR_LENGTH);
|
||||
ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if(ret==FAIL) {
|
||||
@ -3901,10 +3850,8 @@ std::string slsDetector::setAdditionalJsonHeader(std::string jsonheader) {
|
||||
|
||||
int fnum=F_ADDITIONAL_JSON_HEADER;
|
||||
int ret = FAIL;
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg,0,sizeof(arg));
|
||||
char retval[MAX_STR_LENGTH];
|
||||
memset(retval,0, sizeof(retval));
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
strcpy(arg, jsonheader.c_str());
|
||||
|
||||
@ -3913,7 +3860,7 @@ std::string slsDetector::setAdditionalJsonHeader(std::string jsonheader) {
|
||||
std::cout << "Sending additional json header " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, MAX_STR_LENGTH, retval, MAX_STR_LENGTH);
|
||||
ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if(ret==FAIL) {
|
||||
@ -4003,10 +3950,8 @@ int slsDetector::setUDPConnection() {
|
||||
|
||||
int ret = FAIL;
|
||||
int fnum = F_SETUP_RECEIVER_UDP;
|
||||
char args[3][MAX_STR_LENGTH];
|
||||
memset(args,0,sizeof(args));
|
||||
char retval[MAX_STR_LENGTH];
|
||||
memset(retval,0,sizeof(retval));
|
||||
char args[3][MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
//called before set up
|
||||
if(!strcmp(thisDetector->receiver_hostname,"none")){
|
||||
@ -4961,8 +4906,7 @@ int slsDetector::setTemperatureEvent(int val) {
|
||||
int slsDetector::setStoragecellStart(int pos) {
|
||||
int ret=FAIL;
|
||||
int fnum=F_STORAGE_CELL_START;
|
||||
char mess[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
char mess[MAX_STR_LENGTH] = {0};
|
||||
int retval=-1;
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -5929,24 +5873,22 @@ int slsDetector::exitReceiver() {
|
||||
}
|
||||
|
||||
int slsDetector::execReceiverCommand(std::string cmd) {
|
||||
|
||||
int fnum=F_EXEC_RECEIVER_COMMAND;
|
||||
int ret=FAIL;
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg,0,sizeof(arg));
|
||||
char retval[MAX_STR_LENGTH];
|
||||
memset(retval,0, sizeof(retval));
|
||||
int fnum = F_EXEC_RECEIVER_COMMAND;
|
||||
int ret = FAIL;
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
strcpy(arg,cmd.c_str());
|
||||
FILE_LOG(logDEBUG5) << "Sending command to receiver " << arg;
|
||||
|
||||
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending to receiver the command: " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, MAX_STR_LENGTH, retval, MAX_STR_LENGTH);
|
||||
ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if (ret != FAIL) {
|
||||
FILE_LOG(logINFO) << "Receiver " << detId << " returned:\n" << retval;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -6157,26 +6099,27 @@ std::string slsDetector::setFilePath(std::string s) {
|
||||
char retval[MAX_STR_LENGTH] = "";
|
||||
|
||||
strcpy(arg,s.c_str());
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending file path to receiver " << arg << std::endl;
|
||||
std::cout << "Sending file path to receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, MAX_STR_LENGTH, retval, MAX_STR_LENGTH);
|
||||
disconnectData();
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if(ret!=FAIL){
|
||||
strcpy(thisDetector->receiver_filePath,retval);
|
||||
}
|
||||
else {
|
||||
if(!s.empty()){
|
||||
std::cout << "file path does not exist" << std::endl;
|
||||
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
|
||||
} else
|
||||
setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET));
|
||||
}
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
if(ret!=FAIL){
|
||||
strcpy(thisDetector->receiver_filePath,retval);
|
||||
}
|
||||
else {
|
||||
if(!s.empty()){
|
||||
std::cout << "file path does not exist" << std::endl;
|
||||
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
|
||||
} else
|
||||
setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET));
|
||||
}
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
|
||||
return getFilePath();
|
||||
}
|
||||
|
||||
@ -6202,7 +6145,7 @@ std::string slsDetector::setFileName(std::string s) {
|
||||
std::cout << "Sending file name to receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, arg, MAX_STR_LENGTH, retval, MAX_STR_LENGTH);
|
||||
ret=thisReceiver->Client_Send(fnum, arg, sizeof(arg), retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if (ret == FAIL)
|
||||
@ -6309,20 +6252,21 @@ slsDetectorDefs::fileFormat slsDetector::setFileFormat(fileFormat f) {
|
||||
int ret = FAIL;
|
||||
int arg = f;
|
||||
int retval = -1;
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending file format to receiver " << arg << std::endl;
|
||||
std::cout << "Sending file format to receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectData();
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_FILE_FORMAT));
|
||||
else
|
||||
thisDetector->receiver_fileFormatType = (fileFormat)retval;
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_FILE_FORMAT));
|
||||
else
|
||||
thisDetector->receiver_fileFormatType = (fileFormat)retval;
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
|
||||
return getFileFormat();
|
||||
}
|
||||
|
||||
@ -6346,21 +6290,21 @@ int slsDetector::setFileIndex(int i) {
|
||||
int retval=-1;
|
||||
int arg = i;
|
||||
|
||||
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending file index to receiver " << arg << std::endl;
|
||||
std::cout << "Sending file index to receiver " << arg << std::endl;
|
||||
#endif
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectData();
|
||||
if (connectData() == OK){
|
||||
ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||
disconnectData();
|
||||
}
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET));
|
||||
else
|
||||
thisDetector->receiver_fileIndex = retval;
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
}
|
||||
if (ret == FAIL)
|
||||
setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET));
|
||||
else
|
||||
thisDetector->receiver_fileIndex = retval;
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
|
||||
|
||||
return getFileIndex();
|
||||
}
|
||||
@ -7055,110 +6999,6 @@ int slsDetector::setCTBPatWaitTime(int level, uint64_t t) {
|
||||
|
||||
|
||||
|
||||
int slsDetector::readCalibrationFile(std::string fname, double &gain, double &offset) {
|
||||
|
||||
std::string str;
|
||||
std::ifstream infile;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Opening file "<< fname << std::endl;
|
||||
#endif
|
||||
infile.open(fname.c_str(), std::ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< str << std::endl;
|
||||
#endif
|
||||
std::istringstream ssstr(str);
|
||||
ssstr >> offset >> gain;
|
||||
infile.close();
|
||||
std::cout << "Calibration file loaded: " << fname << std::endl;
|
||||
} else {
|
||||
std::cout<< "Could not open calibration file "<< fname << std::endl;
|
||||
gain=0.;
|
||||
offset=0.;
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetector::writeCalibrationFile(std::string fname, double gain, double offset) {
|
||||
|
||||
std::ofstream outfile;
|
||||
outfile.open (fname.c_str());
|
||||
|
||||
if (outfile.is_open()) {
|
||||
outfile << offset << " " << gain << std::endl;
|
||||
} else {
|
||||
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
|
||||
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::readCalibrationFile(std::string fname, int *gain, int *offset) {
|
||||
|
||||
std::string str;
|
||||
std::ifstream infile;
|
||||
double o,g;
|
||||
int ig=0;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Opening file "<< fname << std::endl;
|
||||
#endif
|
||||
infile.open(fname.c_str(), std::ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
//get gain and offset
|
||||
for (ig=0; ig<4; ig++) {
|
||||
//while ( (getline(infile,str)) > -1) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< str << std::endl;
|
||||
#endif
|
||||
std::istringstream ssstr(str);
|
||||
ssstr >> o >> g;
|
||||
offset[ig]=(int)(o*1000);
|
||||
gain[ig]=(int)(g*1000);
|
||||
// ig++;
|
||||
if (ig>=4)
|
||||
break;
|
||||
}
|
||||
infile.close();
|
||||
std::cout << "Calibration file loaded: " << fname << std::endl;
|
||||
} else {
|
||||
std::cout << "Could not open calibration file: "<< fname << std::endl;
|
||||
gain[0]=0;
|
||||
offset[0]=0;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::writeCalibrationFile(std::string fname, int *gain, int *offset){
|
||||
|
||||
std::ofstream outfile;
|
||||
outfile.open (fname.c_str());
|
||||
|
||||
if (outfile.is_open()) {
|
||||
for (int ig=0; ig<4; ig++)
|
||||
outfile << ((double)offset[ig]/1000) << " " << ((double)gain[ig]/1000) << std::endl;
|
||||
} else {
|
||||
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim(
|
||||
sls_detector_module* a, sls_detector_module* b,
|
||||
const int energy, const int e1, const int e2, int tb) {
|
||||
|
@ -1796,42 +1796,6 @@ private:
|
||||
*/
|
||||
int setUDPConnection();
|
||||
|
||||
/**
|
||||
* reads a calibration file
|
||||
* @param fname file to be read
|
||||
* @param gain reference to the gain variable
|
||||
* @param offset reference to the offset variable
|
||||
* @returns OK if successful, else FAIL or -1
|
||||
*/
|
||||
static int readCalibrationFile(std::string fname, double &gain, double &offset);
|
||||
|
||||
/**
|
||||
* writes a calibration file
|
||||
* @param fname file to be written
|
||||
* @param gain
|
||||
* @param offset
|
||||
* @returns OK if successful, else FAIL or -1
|
||||
*/
|
||||
static int writeCalibrationFile(std::string fname, double gain, double offset);
|
||||
|
||||
/**
|
||||
* reads a calibration file
|
||||
* @param fname file to be read
|
||||
* @param gain reference to the gain variable
|
||||
* @param offset reference to the offset variable
|
||||
* @returns OK if successful, else FAIL or -1
|
||||
*/
|
||||
static int readCalibrationFile(std::string fname, int *gain, int *offset);
|
||||
|
||||
/**
|
||||
* writes a calibration file
|
||||
* @param fname file to be written
|
||||
* @param gain reference to the gain variable
|
||||
* @param offset reference to the offset variable
|
||||
* @returns OK if successful, else FAIL or -1
|
||||
*/
|
||||
static int writeCalibrationFile(std::string fname, int *gain, int *offset);
|
||||
|
||||
/*
|
||||
* Template function to do linear interpolation between two points (Eiger only)
|
||||
*/
|
||||
@ -1893,6 +1857,12 @@ private:
|
||||
/** Shared memory structure */
|
||||
sharedSlsDetector *thisDetector;
|
||||
|
||||
/** control socket interface */
|
||||
ClientInterface *thisDetectorControl;
|
||||
|
||||
/** stop socket interface */
|
||||
ClientInterface *thisDetectorStop;
|
||||
|
||||
/** receiver interface */
|
||||
ClientInterface *thisReceiver;
|
||||
|
||||
|
@ -396,33 +396,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class PropixData : public GeneralData {
|
||||
|
||||
private:
|
||||
|
||||
/**bytes per pixel for calculating image size */
|
||||
const static uint32_t bytesPerPixel = 2;
|
||||
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
PropixData(){
|
||||
myDetectorType = slsDetectorDefs::PROPIX;
|
||||
nPixelsX = 22;
|
||||
nPixelsY = 22;
|
||||
headerSizeinPacket = 4;
|
||||
dataSize = 1280;
|
||||
packetSize = 1286;
|
||||
packetsPerFrame = 2; //not really
|
||||
imageSize = nPixelsX*nPixelsY*bytesPerPixel;
|
||||
frameIndexMask = 0xFFFFFFFE;
|
||||
frameIndexOffset = 1;
|
||||
packetIndexMask = 1;
|
||||
maxFramesPerFile = MAX_FRAMES_PER_FILE;
|
||||
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
|
||||
defaultFifoDepth = 50000;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class Moench02Data : public GeneralData {
|
||||
|
@ -897,8 +897,6 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
|
||||
myDetectorType = d;
|
||||
switch(myDetectorType) {
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case MOENCH:
|
||||
case EIGER:
|
||||
case JUNGFRAUCTB:
|
||||
case JUNGFRAU:
|
||||
@ -913,8 +911,6 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
|
||||
//set detector specific variables
|
||||
switch(myDetectorType) {
|
||||
case GOTTHARD: generalData = new GotthardData(); break;
|
||||
case PROPIX: generalData = new PropixData(); break;
|
||||
case MOENCH: generalData = new Moench02Data(); break;
|
||||
case EIGER: generalData = new EigerData(); break;
|
||||
case JUNGFRAUCTB: generalData = new JCTBData(); break;
|
||||
case JUNGFRAU: generalData = new JungfrauData(); break;
|
||||
|
@ -20,8 +20,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <syscall.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include <array>
|
||||
#include <memory> //unique_ptr
|
||||
|
||||
slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
|
||||
stop();
|
||||
@ -241,31 +241,28 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
|
||||
int slsReceiverTCPIPInterface::decode_function(){
|
||||
ret = FAIL;
|
||||
|
||||
FILE_LOG(logDEBUG1) << "waiting to receive data";
|
||||
int n = mySock->ReceiveDataOnly(&fnum,sizeof(fnum));
|
||||
if (n <= 0) {
|
||||
FILE_LOG(logDEBUG1) << "ERROR reading from socket. "
|
||||
FILE_LOG(logDEBUG5) << "Could not read socket. "
|
||||
"Received " << n << " bytes," <<
|
||||
"fnum:" << fnum << " "
|
||||
"(" << getFunctionNameFromEnum((enum detFuncs)fnum) << ")";
|
||||
return FAIL;
|
||||
}
|
||||
else
|
||||
FILE_LOG(logDEBUG1) << "Received " << n << " bytes";
|
||||
|
||||
FILE_LOG(logDEBUG5) << "Received " << n << " bytes";
|
||||
|
||||
if (fnum <= NUM_DET_FUNCTIONS || fnum >= NUM_REC_FUNCTIONS) {
|
||||
FILE_LOG(logERROR) << "Unknown function enum " << fnum;
|
||||
ret = (this->M_nofunc)();
|
||||
} else{
|
||||
FILE_LOG(logDEBUG1) << "calling function fnum: "<< fnum << " "
|
||||
FILE_LOG(logDEBUG5) << "calling function fnum: "<< fnum << " "
|
||||
"(" << getFunctionNameFromEnum((enum detFuncs)fnum) << ") "
|
||||
"located at " << flist[fnum];
|
||||
ret = (this->*flist[fnum])();
|
||||
|
||||
if (ret == FAIL) {
|
||||
FILE_LOG(logERROR) << "Failed to execute function = " << fnum << " ("
|
||||
FILE_LOG(logDEBUG5) << "Failed to execute function = " << fnum << " ("
|
||||
<< getFunctionNameFromEnum((enum detFuncs)fnum) << ")";
|
||||
}
|
||||
}
|
||||
@ -281,7 +278,7 @@ void slsReceiverTCPIPInterface::functionNotImplemented() {
|
||||
}
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::M_nofunc(){printf("111 \n");
|
||||
int slsReceiverTCPIPInterface::M_nofunc(){
|
||||
ret = FAIL;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int n = 0;
|
||||
@ -302,9 +299,10 @@ int slsReceiverTCPIPInterface::M_nofunc(){printf("111 \n");
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::exec_command() {
|
||||
ret = FAIL;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char cmd[MAX_STR_LENGTH];
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
char cmd[MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
// get args, return if socket crashed
|
||||
if (interface->Server_ReceiveArg(ret, mess, cmd, MAX_STR_LENGTH) == FAIL)
|
||||
@ -312,14 +310,26 @@ int slsReceiverTCPIPInterface::exec_command() {
|
||||
|
||||
// verify if receiver is unlocked
|
||||
if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) {
|
||||
ret = (system(cmd) == 0) ? OK : FAIL;
|
||||
if(ret == FAIL) {
|
||||
|
||||
const size_t tempsize = 256;
|
||||
std::array<char, tempsize> temp;
|
||||
std::string sresult;
|
||||
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Executing Command failed\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
} else {
|
||||
while (!feof(pipe.get())) {
|
||||
if (fgets(temp.data(), tempsize, pipe.get()) != NULL)
|
||||
sresult += temp.data();
|
||||
}
|
||||
strncpy(retval, sresult.c_str(), MAX_STR_LENGTH);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
|
||||
interface->Server_SendResult(false, ret, NULL, 0, mess);
|
||||
interface->Server_SendResult(false, ret, retval, MAX_STR_LENGTH, mess);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -378,17 +388,13 @@ int slsReceiverTCPIPInterface::get_last_client_ip() {
|
||||
int slsReceiverTCPIPInterface::set_port() {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int p_type = 0;
|
||||
int p_number = -1;
|
||||
MySocketTCP* mySocket = 0;
|
||||
char oldLastClientIP[INET_ADDRSTRLEN];
|
||||
memset(oldLastClientIP, 0, sizeof(oldLastClientIP));
|
||||
char oldLastClientIP[INET_ADDRSTRLEN] = {0};
|
||||
|
||||
// receive arguments
|
||||
if (mySock->ReceiveDataOnly(&p_type,sizeof(p_type)) < 0 )
|
||||
return interface->Server_SocketCrash();
|
||||
if (mySock->ReceiveDataOnly(&p_number,sizeof(p_number)) < 0 )
|
||||
return interface->Server_SocketCrash();
|
||||
// get args, return if socket crashed
|
||||
if (interface->Server_ReceiveArg(ret, mess, &p_number, sizeof(p_number)) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
// verify if receiver is unlocked
|
||||
if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) {
|
||||
@ -450,8 +456,7 @@ int slsReceiverTCPIPInterface::update_client() {
|
||||
|
||||
int slsReceiverTCPIPInterface::send_update() {
|
||||
int ind = -1;
|
||||
char defaultVal[MAX_STR_LENGTH];
|
||||
memset(defaultVal, 0, sizeof(defaultVal));
|
||||
char defaultVal[MAX_STR_LENGTH] = {0};
|
||||
char* path = NULL;
|
||||
int n = 0;
|
||||
|
||||
@ -581,8 +586,6 @@ int slsReceiverTCPIPInterface::set_detector_type(){
|
||||
if (ret == OK) {
|
||||
switch(dr) {
|
||||
case GOTTHARD:
|
||||
case PROPIX:
|
||||
case MOENCH:
|
||||
case EIGER:
|
||||
case JUNGFRAUCTB:
|
||||
case JUNGFRAU:
|
||||
@ -628,8 +631,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){
|
||||
|
||||
int slsReceiverTCPIPInterface::set_detector_hostname() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char hostname[MAX_STR_LENGTH];
|
||||
memset(hostname, 0, sizeof(hostname));
|
||||
char hostname[MAX_STR_LENGTH] = {0};
|
||||
char* retval = NULL;
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
@ -706,10 +708,8 @@ int slsReceiverTCPIPInterface::set_roi() {
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::setup_udp(){
|
||||
char args[3][MAX_STR_LENGTH];
|
||||
memset(args,0,sizeof(args));
|
||||
char retval[MAX_STR_LENGTH];
|
||||
memset(retval,0,sizeof(retval));
|
||||
char args[3][MAX_STR_LENGTH] = {0};
|
||||
char retval[MAX_STR_LENGTH] = {0};
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
if (interface->Server_ReceiveArg(ret, mess, args, sizeof(args), true, receiver) == FAIL)
|
||||
@ -1062,8 +1062,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){
|
||||
|
||||
int slsReceiverTCPIPInterface::set_file_dir() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char fPath[MAX_STR_LENGTH];
|
||||
memset(fPath, 0, sizeof(fPath));
|
||||
char fPath[MAX_STR_LENGTH] = {0};
|
||||
char* retval=NULL;
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
@ -1100,8 +1099,7 @@ int slsReceiverTCPIPInterface::set_file_dir() {
|
||||
|
||||
int slsReceiverTCPIPInterface::set_file_name() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char fName[MAX_STR_LENGTH];
|
||||
memset(fName, 0, sizeof(fName));
|
||||
char fName[MAX_STR_LENGTH] = {0};
|
||||
char* retval = NULL;
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
@ -1672,8 +1670,7 @@ int slsReceiverTCPIPInterface::set_streaming_port() {
|
||||
|
||||
int slsReceiverTCPIPInterface::set_streaming_source_ip() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg, 0, sizeof(arg));
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char* retval=NULL;
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
@ -1813,8 +1810,7 @@ int slsReceiverTCPIPInterface::restream_stop(){
|
||||
|
||||
int slsReceiverTCPIPInterface::set_additional_json_header() {
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char arg[MAX_STR_LENGTH];
|
||||
memset(arg, 0, sizeof(arg));
|
||||
char arg[MAX_STR_LENGTH] = {0};
|
||||
char* retval=NULL;
|
||||
|
||||
// get args, return if socket crashed, ret is fail if receiver is not null
|
||||
|
@ -1,16 +1,6 @@
|
||||
#include "ClientInterface.h"
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
ClientInterface::ClientInterface(MySocketTCP *socket, int n, std::string t):
|
||||
mySocket(socket),
|
||||
index(n),
|
||||
@ -55,29 +45,7 @@ int ClientInterface::Client_Send(int fnum,
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
if (Client_GetMesage(mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
void* args2, int sizeOfArgs2,
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess) {
|
||||
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
mySocket->SendDataOnly(args, sizeOfArgs);
|
||||
mySocket->SendDataOnly(args2, sizeOfArgs2);
|
||||
|
||||
int ret = FAIL;
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
if (Client_GetMesage(mess) == FAIL)
|
||||
return FAIL;
|
||||
return FAIL;
|
||||
}
|
||||
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
|
||||
|
||||
@ -89,7 +57,7 @@ void ClientInterface::Server_SendResult(bool update, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (update && mySocket->differentClients)
|
||||
if (update && ret == OK && mySocket->differentClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
@ -143,7 +111,6 @@ int ClientInterface::Server_VerifyLockAndIdle(int& ret, char* mess, int lockstat
|
||||
|
||||
|
||||
void ClientInterface::Server_NullObjectError(int& ret, char* mess) {
|
||||
// only for receiver
|
||||
ret=FAIL;
|
||||
strcpy(mess,"Receiver not set up. Please use rx_hostname first.\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
@ -158,7 +125,7 @@ int ClientInterface::Server_SocketCrash() {
|
||||
|
||||
int ClientInterface::Server_LockedError(int& ret, char* mess) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"%s locked by %s\n",type.c_str(), mySocket->lastClientIP);
|
||||
sprintf(mess,"Receiver locked by %s\n", mySocket->lastClientIP);
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
@ -166,8 +133,8 @@ int ClientInterface::Server_LockedError(int& ret, char* mess) {
|
||||
|
||||
int ClientInterface::Server_NotIdleError(int& ret, char* mess, int fnum) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Can not execute %s when %s is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum), type.c_str());
|
||||
sprintf(mess,"Can not execute %s when receiver is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum));
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
@ -57,24 +57,8 @@ public:
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess = 0);
|
||||
|
||||
/**
|
||||
* Send Arguments (second set) to server and get result back
|
||||
* @param fnum function enum to determine what parameter
|
||||
* @param args pointer to arguments
|
||||
* @param sizeOfArgs argument size
|
||||
* @param args2 pointer to arguments 2
|
||||
* @param sizeOfArgs2 argument size 2
|
||||
* @param retval pointer to return value
|
||||
* @param sizeOfRetval return value size
|
||||
* @param mess pointer to message if message required externally
|
||||
*/
|
||||
int Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
void* args2, int sizeOfArgs2,
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess = 0);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server sends result to client (also set ret to force_update if different clients)
|
||||
* @param update true if one must update if different clients, else false
|
||||
* @param ret success of operation
|
||||
@ -84,7 +68,7 @@ public:
|
||||
*/
|
||||
void Server_SendResult(bool update, int ret, void* retval, int retvalSize, char* mess = 0);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server receives arguments and checks if base object is null (if checkbase is true)
|
||||
* checking base object is null (for reciever only when it has not been configured yet)
|
||||
* @param ret pointer to success of operation
|
||||
@ -97,8 +81,9 @@ public:
|
||||
*/
|
||||
int Server_ReceiveArg(int& ret, char* mess, void* arg, int sizeofArg,bool checkbase=false, void* base=NULL);
|
||||
|
||||
/**
|
||||
* Server verifies if it is locked, sets and prints appropriate message if it is
|
||||
/** only Receiver
|
||||
* Server verifies if it is unlocked,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @param ret pointer to sucess
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
@ -106,8 +91,9 @@ public:
|
||||
*/
|
||||
int Server_VerifyLock(int& ret, char* mess, int lockstatus);
|
||||
|
||||
/**
|
||||
* Server verifies if it is locked and idle, sets and prints appropriate message if it is
|
||||
/** only Receiver
|
||||
* Server verifies if it is unlocked and idle,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @param ret pointer to sucess
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
@ -117,20 +103,20 @@ public:
|
||||
*/
|
||||
int Server_VerifyLockAndIdle(int& ret, char* mess, int lockstatus, slsDetectorDefs::runStatus status, int fnum);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server sets and prints error message for null object error (receiver only)
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
*/
|
||||
void Server_NullObjectError(int& ret, char* mess);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers prints error message for socket crash when reading
|
||||
* @returns always FAIL
|
||||
*/
|
||||
int Server_SocketCrash();
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers sets and prints error message for locked server
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
@ -138,7 +124,7 @@ public:
|
||||
*/
|
||||
int Server_LockedError(int& ret, char* mess);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers sets and prints error message for server not being idle
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
@ -154,7 +140,7 @@ private:
|
||||
*/
|
||||
MySocketTCP *mySocket;
|
||||
|
||||
/** index for debugging purposes */
|
||||
/** index for client debugging purposes */
|
||||
int index;
|
||||
|
||||
/** string for type to differentiate between Detector & Receiver in printouts */
|
||||
|
@ -81,11 +81,10 @@ public:
|
||||
GENERIC, /**< generic sls detector */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
MOENCH, /**< moench */
|
||||
JUNGFRAU, /**< jungfrau */
|
||||
JUNGFRAUCTB, /**< jungfrauCTBversion */
|
||||
PROPIX, /**< propix */
|
||||
MYTHEN3 /**< mythen 3 */
|
||||
MYTHEN3, /**< mythen 3 */
|
||||
MOENCH /**< moench */
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user