Merge branch 'refactor' of github.com:slsdetectorgroup/slsDetectorPackage into refactor

This commit is contained in:
Erik Frojdh
2018-10-30 14:46:19 +01:00
84 changed files with 8252 additions and 14747 deletions

View File

@ -11,7 +11,7 @@ option (USE_TESTS "TESTS" ON)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -Wno-misleading-indentation")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 ")
endif ()
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread")

View File

@ -101,15 +101,15 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){
PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row,
"#### %d GetData: ####\n"
"frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu"
"\t\ttimestamp: %llu\t\tmodId: %u\t\t"
"frameNumber: %lu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %lu"
"\t\ttimestamp: %lu\t\tmodId: %u\t\t"
"row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u"
"\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u"
//"\t\tpacketsMask:%s"
"\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
detectorHeader.row, (long long unsigned int)detectorHeader.frameNumber,
detectorHeader.expLength, detectorHeader.packetNumber, (long long unsigned int)detectorHeader.bunchId,
(long long unsigned int)detectorHeader.timestamp, detectorHeader.modId,
detectorHeader.row, (long unsigned int)detectorHeader.frameNumber,
detectorHeader.expLength, detectorHeader.packetNumber, (long unsigned int)detectorHeader.bunchId,
(long unsigned int)detectorHeader.timestamp, detectorHeader.modId,
detectorHeader.row, detectorHeader.column, detectorHeader.reserved,
detectorHeader.debug, detectorHeader.roundRNumber,
detectorHeader.detType, detectorHeader.version,

File diff suppressed because it is too large Load Diff

View File

@ -1,103 +1,84 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#ifndef BEB_H
#define BEB_H
#pragma once
#include "LocalLinkInterface.h"
#include "slsDetectorServer_defs.h"
struct BebInfo{
unsigned int beb_number;
unsigned int serial_address;
char src_mac_1GbE[50];
char src_mac_10GbE[50];
char src_ip_1GbE[50];
char src_ip_10GbE[50];
unsigned int src_port_1GbE;
unsigned int src_port_10GbE;
unsigned int beb_number;
unsigned int serial_address;
char src_mac_1GbE[50];
char src_mac_10GbE[50];
char src_ip_1GbE[50];
char src_ip_10GbE[50];
unsigned int src_port_1GbE;
unsigned int src_port_10GbE;
};
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num);
void BebInfo_BebDstInfo(struct BebInfo* bebInfo, unsigned int beb_num);
int BebInfo_SetSerialAddress(struct BebInfo* bebInfo, unsigned int add);
int BebInfo_SetHeaderInfo(struct BebInfo* bebInfo, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);//src_port fixed 42000+beb_number or 52000 + beb_number);
unsigned int BebInfo_GetBebNumber(struct BebInfo* bebInfo);
unsigned int BebInfo_GetSerialAddress(struct BebInfo* bebInfo);
char* BebInfo_GetSrcMAC(struct BebInfo* bebInfo, int ten_gig);
char* BebInfo_GetSrcIP(struct BebInfo* bebInfo, int ten_gig);
unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig);
void BebInfo_Print(struct BebInfo* bebInfo);
void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num);
void BebInfo_BebDstInfo(struct BebInfo* bebInfo, unsigned int beb_num);
int BebInfo_SetSerialAddress(struct BebInfo* bebInfo, unsigned int add);
int BebInfo_SetHeaderInfo(struct BebInfo* bebInfo, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);//src_port fixed 42000+beb_number or 52000 + beb_number);
unsigned int BebInfo_GetBebNumber(struct BebInfo* bebInfo);
unsigned int BebInfo_GetSerialAddress(struct BebInfo* bebInfo);
char* BebInfo_GetSrcMAC(struct BebInfo* bebInfo, int ten_gig);
char* BebInfo_GetSrcIP(struct BebInfo* bebInfo, int ten_gig);
unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig);
void BebInfo_Print(struct BebInfo* bebInfo);
void Beb_ClearBebInfos();
int Beb_InitBebInfos();
int Beb_CheckSourceStuffBebInfo();
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
void Beb_GetModuleConfiguration(int* master, int* top, int* normal);
void Beb_EndofDataSend(int tengiga);
void Beb_ClearBebInfos();
int Beb_InitBebInfos();
int Beb_CheckSourceStuffBebInfo();
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
int Beb_SetMasterViaSoftware();
int Beb_SetSlaveViaSoftware();
int Beb_Activate(int enable);
int Beb_Set32bitOverflow(int val);
int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val);
int Beb_ResetToHardwareSettings();
u_int32_t Beb_GetFirmwareRevision();
u_int32_t Beb_GetFirmwareSoftwareAPIVersion();
void Beb_ResetFrameNumber();
int Beb_WriteTo(unsigned int index);
int Beb_SetMAC(char* mac, uint8_t* dst_ptr);
int Beb_SetIP(char* ip, uint8_t* dst_ptr);
int Beb_SetPortNumber(unsigned int port_number, uint8_t* dst_ptr);
void Beb_AdjustIPChecksum(struct udp_header_type *ip);
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port);
int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char* dst_mac, char* dst_ip, unsigned int dst_port);
void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d);
int Beb_SetByteOrder();
void Beb_Beb();
int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port);
/*int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);*/
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty);
int Beb_StopAcquisition();
int Beb_SetUpTransferParameters(short the_bit_mode);
/*int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait=0); //all images go to the same destination!*/
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait);
int Beb_Test(unsigned int beb_number);
int Beb_GetBebFPGATemp();
void Beb_SetDetectorNumber(uint32_t detid);
int Beb_SetDetectorPosition(int pos[]);
uint16_t Beb_swap_uint16( uint16_t val);
int Beb_open(u_int32_t** csp0base, u_int32_t offset);
u_int32_t Beb_Read32 (u_int32_t* baseaddr, u_int32_t offset);
u_int32_t Beb_Write32 (u_int32_t* baseaddr, u_int32_t offset, u_int32_t data);
void Beb_close(int fd,u_int32_t* csp0base);
void Beb_GetModuleConfiguration(int* master, int* top, int* normal);
void Beb_EndofDataSend(int tengiga);
int Beb_SetMasterViaSoftware();
int Beb_SetSlaveViaSoftware();
int Beb_Activate(int enable);
int Beb_Set32bitOverflow(int val);
int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val);
int Beb_ResetToHardwareSettings();
u_int32_t Beb_GetFirmwareRevision();
u_int32_t Beb_GetFirmwareSoftwareAPIVersion();
void Beb_ResetFrameNumber();
int Beb_WriteTo(unsigned int index);
int Beb_SetMAC(char* mac, uint8_t* dst_ptr);
int Beb_SetIP(char* ip, uint8_t* dst_ptr);
int Beb_SetPortNumber(unsigned int port_number, uint8_t* dst_ptr);
void Beb_AdjustIPChecksum(struct udp_header_type *ip);
int Beb_SetHeaderData(unsigned int beb_number, int ten_gig, char* dst_mac, char* dst_ip, unsigned int dst_port);
int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char* dst_mac, char* dst_ip, unsigned int dst_port);
void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d);
int Beb_SetByteOrder();
void Beb_Beb();
int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac, char* src_ip, unsigned int src_port);
int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port);
/*int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);*/
int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty);
int Beb_StopAcquisition();
int Beb_SetUpTransferParameters(short the_bit_mode);
/*int Beb_RequestNImages(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait=0); //all images go to the same destination!*/
int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait);
int Beb_Test(unsigned int beb_number);
int Beb_GetBebFPGATemp();
void Beb_SetDetectorNumber(uint32_t detid);
int Beb_SetDetectorPosition(int pos[]);
uint16_t Beb_swap_uint16( uint16_t val);
int Beb_open(u_int32_t** csp0base, u_int32_t offset);
u_int32_t Beb_Read32 (u_int32_t* baseaddr, u_int32_t offset);
u_int32_t Beb_Write32 (u_int32_t* baseaddr, u_int32_t offset, u_int32_t data);
void Beb_close(int fd,u_int32_t* csp0base);
#endif

View File

@ -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,&reg_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,&reg_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&reg_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;
}

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,24 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#ifndef FEBCONTROL_H
#define FEBCONTROL_H
#include <netinet/in.h>
#include <stdlib.h>
//#include <string>
//#include <vector>
#pragma once
#include "FebInterface.h"
#include <netinet/in.h>
#include <stdlib.h>
struct Module{
unsigned int module_number;
int top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
int bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int module_number;
int top_address_valid;
unsigned int top_left_address;
unsigned int top_right_address;
int bottom_address_valid;
unsigned int bottom_left_address;
unsigned int bottom_right_address;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
unsigned int idelay_top[4]; //ll,lr,rl,ll
unsigned int idelay_bottom[4]; //ll,lr,rl,ll
float high_voltage;
int* top_dac;
int* bottom_dac;
};
@ -38,12 +26,12 @@ void Module_Module(struct Module* mod,unsigned int number, unsigned int address_
void Module_ModuleBottom(struct Module* mod,unsigned int number, unsigned int address_bottom);
void Module_Module1(struct Module* mod,unsigned int number, unsigned int address_top, unsigned int address_bottom);
unsigned int Module_GetModuleNumber(struct Module* mod);
int Module_TopAddressIsValid(struct Module* mod);
int Module_TopAddressIsValid(struct Module* mod);
unsigned int Module_GetTopBaseAddress(struct Module* mod);
unsigned int Module_GetTopLeftAddress(struct Module* mod) ;
unsigned int Module_GetTopRightAddress(struct Module* mod);
unsigned int Module_GetBottomBaseAddress(struct Module* mod);
int Module_BottomAddressIsValid(struct Module* mod);
int Module_BottomAddressIsValid(struct Module* mod);
unsigned int Module_GetBottomLeftAddress(struct Module* mod);
unsigned int Module_GetBottomRightAddress(struct Module* mod);
unsigned int Module_SetTopIDelay(struct Module* mod,unsigned int chip,unsigned int value);
@ -51,17 +39,13 @@ unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) ;
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value);
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip);
float Module_SetHighVoltage(struct Module* mod,float value);
float Module_GetHighVoltage(struct Module* mod);
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetTopDACValue(struct Module* mod,unsigned int i);
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
float Module_SetHighVoltage(struct Module* mod,float value);
float Module_GetHighVoltage(struct Module* mod);
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetTopDACValue(struct Module* mod,unsigned int i);
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value);
int Module_GetBottomDACValue(struct Module* mod,unsigned int i);
void Feb_Control_activate(int activate);
@ -69,142 +53,107 @@ void Feb_Control_activate(int activate);
int Feb_Control_IsBottomModule();
int Feb_Control_GetModuleNumber();
void Feb_Control_PrintModuleList();
int Feb_Control_GetModuleIndex(unsigned int module_number, unsigned int* module_index);
int Feb_Control_CheckModuleAddresses(struct Module* m);
int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address);
int Feb_Control_AddModule1(unsigned int module_number, int top_enable, unsigned int top_address, unsigned int bottom_address, int half_module);
int Feb_Control_GetDACNumber(char* s, unsigned int* n);
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value);
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
int Feb_Control_SetStaticBits();
int Feb_Control_SetStaticBits1(unsigned int the_static_bits);
int Feb_Control_SendBitModeToBebServer();
unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec);
unsigned int Feb_Control_AddressToAll();
int Feb_Control_SetCommandRegister(unsigned int cmd);
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status);
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);
int Feb_Control_ResetChipCompletely();
int Feb_Control_ResetChipPartially();
void Feb_Control_FebControl();
int Feb_Control_Init(int master, int top, int normal, int module_num);
int Feb_Control_OpenSerialCommunication();
void Feb_Control_CloseSerialCommunication();
int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(int value);
int Feb_Control_GetHighVoltage(int* value);
int Feb_Control_SendHighVoltage(int dacvalue);
int Feb_Control_ReceiveHighVoltage(unsigned int* value);
void Feb_Control_PrintModuleList();
int Feb_Control_GetModuleIndex(unsigned int module_number, unsigned int* module_index);
int Feb_Control_CheckModuleAddresses(struct Module* m);
int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address);
/*int Feb_Control_AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, int half_module=0);*/
int Feb_Control_AddModule1(unsigned int module_number, int top_enable, unsigned int top_address, unsigned int bottom_address, int half_module);
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
int Feb_Control_GetDACNumber(char* s, unsigned int* n);
int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int* value);
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch);
int Feb_Control_SetDAC(char* s, int value, int is_a_voltage_mv);
int Feb_Control_GetDAC(char* s, int* ret_value, int voltage_mv);
int Feb_Control_GetDACName(unsigned int dac_num,char* s);
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int* trimbits);
unsigned int* Feb_Control_GetTrimbits();
int Feb_Control_SaveAllTrimbitsTo(int value);
int Feb_Control_Reset();
int Feb_Control_PrepareForAcquisition();
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition();
int Feb_Control_AcquisitionInProgress();
int Feb_Control_AcquisitionStartedBit();
int Feb_Control_WaitForFinishedFlag(int sleep_time_us);
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag);
void Feb_Control_PrintAcquisitionSetup();
int Feb_Control_SetNExposures(unsigned int n_images);
unsigned int Feb_Control_GetNExposures();
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
double Feb_Control_GetExposureTime();
int64_t Feb_Control_GetExposureTime_in_nsec();
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec);
int64_t Feb_Control_GetSubFrameExposureTime();
int Feb_Control_SetSubFramePeriod(int64_t the_subframe_period_in_10nsec);
int64_t Feb_Control_GetSubFramePeriod();
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
double Feb_Control_GetExposurePeriod();
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int Feb_Control_GetDynamicRange();
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); //0 was default, 0->full,1->half,2->quarter or 3->super_slow
int Feb_Control_SetReadoutMode(unsigned int readout_mode); ///0 was default,0->parallel,1->non-parallel,2-> safe_mode
int Feb_Control_SetTriggerMode(unsigned int trigger_mode, int polarity);//0 and 1 was default,
int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity);//0 and 1 was default,
int Feb_Control_SetStaticBits();
int Feb_Control_SetStaticBits1(unsigned int the_static_bits);
int Feb_Control_SetInTestModeVariable(int on);
int Feb_Control_GetTestModeVariable();
int Feb_Control_SendBitModeToBebServer();
void Feb_Control_Set_Counter_Bit(int value);
int Feb_Control_Get_Counter_Bit();
int Feb_Control_Pulse_Pixel(int npulses,int x, int y);
int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos);
int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in);
int Feb_Control_SendTokenIn();
int Feb_Control_ClockRowClock(unsigned int ntimes);
int Feb_Control_PulseChip(int npulses);
unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec);
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
int64_t Feb_Control_Get_RateTable_Period_in_nsec();
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
int Feb_Control_GetRateCorrectionVariable();
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
int Feb_Control_PrintCorrectedValues();
unsigned int Feb_Control_AddressToAll();
int Feb_Control_SetCommandRegister(unsigned int cmd);
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status);
/*int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);*/
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);
int Feb_Control_GetLeftFPGATemp();
int Feb_Control_GetRightFPGATemp();
int Feb_Control_ResetChipCompletely();
int Feb_Control_ResetChipPartially();
int64_t Feb_Control_GetMeasuredPeriod();
int64_t Feb_Control_GetSubMeasuredPeriod();
//struct sockaddr_in Feb_Control_serv_addr;
/*
int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port);
int Feb_Control_WriteNRead(char* message, int length, int max_length);
*/
int Feb_Control_SoftwareTrigger();
uint32_t Feb_Control_WriteRegister(uint32_t offset, uint32_t data);
uint32_t Feb_Control_ReadRegister(uint32_t offset);
void Feb_Control_FebControl();
int Feb_Control_Init(int master, int top, int normal, int module_num);
int Feb_Control_OpenSerialCommunication();
void Feb_Control_CloseSerialCommunication();
int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(int value);
int Feb_Control_GetHighVoltage(int* value);
int Feb_Control_SendHighVoltage(int dacvalue);
int Feb_Control_ReceiveHighVoltage(unsigned int* value);
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch);
/*int Feb_Control_SetDAC(string s, int value, int is_a_voltage_mv=0);*/
int Feb_Control_SetDAC(char* s, int value, int is_a_voltage_mv);
/* int Feb_Control_GetDAC(string s, int* ret_value, int voltage_mv=0);*/
int Feb_Control_GetDAC(char* s, int* ret_value, int voltage_mv);
int Feb_Control_GetDACName(unsigned int dac_num,char* s);
int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int* trimbits);
unsigned int* Feb_Control_GetTrimbits();
/**Added by Dhanya */
int Feb_Control_SaveAllTrimbitsTo(int value);
int Feb_Control_Reset();
int Feb_Control_PrepareForAcquisition();
int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition();
int Feb_Control_AcquisitionInProgress();
int Feb_Control_AcquisitionStartedBit();
/*int Feb_Control_WaitForFinishedFlag(int sleep_time_us=5000);*/
int Feb_Control_WaitForFinishedFlag(int sleep_time_us);
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag);
//functions for setting up exposure
void Feb_Control_PrintAcquisitionSetup();
int Feb_Control_SetNExposures(unsigned int n_images);
unsigned int Feb_Control_GetNExposures();
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
double Feb_Control_GetExposureTime();
int64_t Feb_Control_GetExposureTime_in_nsec();
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec);
int64_t Feb_Control_GetSubFrameExposureTime();
int Feb_Control_SetSubFramePeriod(int64_t the_subframe_period_in_10nsec);
int64_t Feb_Control_GetSubFramePeriod();
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
double Feb_Control_GetExposurePeriod();
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
unsigned int Feb_Control_GetDynamicRange();
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); //0 was default, 0->full,1->half,2->quarter or 3->super_slow
int Feb_Control_SetReadoutMode(unsigned int readout_mode); ///0 was default,0->parallel,1->non-parallel,2-> safe_mode
int Feb_Control_SetTriggerMode(unsigned int trigger_mode, int polarity);//0 and 1 was default,
int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity);//0 and 1 was default,
//functions for testing
/*int Feb_Control_SetTestModeVariable(int on=1);*/
int Feb_Control_SetInTestModeVariable(int on);
int Feb_Control_GetTestModeVariable();
void Feb_Control_Set_Counter_Bit(int value);
int Feb_Control_Get_Counter_Bit();
int Feb_Control_Pulse_Pixel(int npulses,int x, int y);
int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos);
int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in);
int Feb_Control_SendTokenIn();
int Feb_Control_ClockRowClock(unsigned int ntimes);
int Feb_Control_PulseChip(int npulses);
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
int64_t Feb_Control_Get_RateTable_Period_in_nsec();
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
int Feb_Control_GetRateCorrectionVariable();
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
int Feb_Control_PrintCorrectedValues();
int Feb_Control_GetLeftFPGATemp();
int Feb_Control_GetRightFPGATemp();
int64_t Feb_Control_GetMeasuredPeriod();
int64_t Feb_Control_GetSubMeasuredPeriod();
int Feb_Control_SoftwareTrigger();
uint32_t Feb_Control_WriteRegister(uint32_t offset, uint32_t data);
uint32_t Feb_Control_ReadRegister(uint32_t offset);
#endif

View File

@ -1,45 +1,31 @@
/**
* @author Ian Johnson
* @version 1.0
*/
//#include <iostream>
//#include <iomanip>
//#include <unistd.h>
//#include <string.h>
//#include <sys/mman.h>
//#include <fcntl.h>
#include "FebInterface.h"
#include "LocalLinkInterface.h"
#include "xparameters.h"
#include "logger.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "xparameters.h"
#include "FebInterface.h"
struct LocalLinkInterface ll_local,* ll;
struct LocalLinkInterface ll_local,* ll;
unsigned int Feb_Interface_nfebs;
unsigned int* Feb_Interface_feb_numb;
unsigned int Feb_Interface_nfebs;
unsigned int* Feb_Interface_feb_numb;
int Feb_Interface_send_ndata;
unsigned int Feb_Interface_send_buffer_size;
unsigned int* Feb_Interface_send_data_raw;
unsigned int* Feb_Interface_send_data;
int Feb_Interface_send_ndata;
unsigned int Feb_Interface_send_buffer_size;
unsigned int* Feb_Interface_send_data_raw;
unsigned int* Feb_Interface_send_data;
int Feb_Interface_recv_ndata;
unsigned int Feb_Interface_recv_buffer_size;
unsigned int* Feb_Interface_recv_data_raw;
unsigned int* Feb_Interface_recv_data;
int Feb_Interface_recv_ndata;
unsigned int Feb_Interface_recv_buffer_size;
unsigned int* Feb_Interface_recv_data_raw;
unsigned int* Feb_Interface_recv_data;
void Feb_Interface_FebInterface(){
void Feb_Interface_FebInterface() {
ll = &ll_local;
Feb_Interface_nfebs = 0;
Feb_Interface_feb_numb = 0;
@ -54,131 +40,129 @@ void Feb_Interface_FebInterface(){
Feb_Interface_recv_data_raw = malloc((Feb_Interface_recv_buffer_size+1) * sizeof(unsigned int));
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
Local_LocalLinkInterface1(ll,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
Local_LocalLinkInterface1(ll,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
}
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list){
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list) {
unsigned int i;
if(Feb_Interface_feb_numb) free(Feb_Interface_feb_numb);
Feb_Interface_nfebs = n;
Feb_Interface_feb_numb = malloc(n * sizeof(unsigned int));
for(i=0;i<n;i++) Feb_Interface_feb_numb[i] = list[i];
if (Feb_Interface_feb_numb) free(Feb_Interface_feb_numb);
Feb_Interface_nfebs = n;
Feb_Interface_feb_numb = malloc(n * sizeof(unsigned int));
for(i=0;i<n;i++) Feb_Interface_feb_numb[i] = list[i];
}
int Feb_Interface_WriteTo(unsigned int ch){
if(ch>0xfff) return 0;
int Feb_Interface_WriteTo(unsigned int ch) {
if (ch>0xfff) return 0;
#ifdef MARTIN
cprintf(YELLOW, "FIW ch %d\n", ch);
#endif
FILE_LOG(logDEBUG1, ("FIW ch %d\n", ch));
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if (Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0x90000000 | (ch<<16);
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0x90000000 | (ch<<16);
if (Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_data_raw[0] = 0xc0000000;
return ((Feb_Interface_send_ndata+1)*4==Local_Write(ll,(Feb_Interface_send_ndata+1)*4,Feb_Interface_send_data_raw));
Feb_Interface_send_data_raw[0] = 0xc0000000;
return ((Feb_Interface_send_ndata+1)*4==Local_Write(ll,(Feb_Interface_send_ndata+1)*4,Feb_Interface_send_data_raw));
}
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys){
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys) {
unsigned int t;
if(ch>=0xfff) return 0;
if (ch>=0xfff) return 0;
Feb_Interface_recv_data_raw[0] = 0xa0000000 | (ch<<16);
Local_Write(ll,4,Feb_Interface_recv_data_raw);
usleep(20);
Feb_Interface_recv_ndata=-1;
for(t=0;t<ntrys;t++){
if((Feb_Interface_recv_ndata=Local_Read(ll,Feb_Interface_recv_buffer_size*4,Feb_Interface_recv_data_raw)/4)>0){
Feb_Interface_recv_ndata--;
break;
}
usleep(1000);
}
Feb_Interface_recv_data_raw[0] = 0xa0000000 | (ch<<16);
Local_Write(ll,4,Feb_Interface_recv_data_raw);
usleep(20);
return (Feb_Interface_recv_ndata>=0);
Feb_Interface_recv_ndata=-1;
for(t=0;t<ntrys;t++) {
if ((Feb_Interface_recv_ndata=Local_Read(ll,Feb_Interface_recv_buffer_size*4,Feb_Interface_recv_data_raw)/4)>0) {
Feb_Interface_recv_ndata--;
break;
}
usleep(1000);
}
return (Feb_Interface_recv_ndata>=0);
}
int Feb_Interface_SetByteOrder(){
int Feb_Interface_SetByteOrder() {
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if(Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_ndata = 2;
Feb_Interface_send_data[0] = 0;
Feb_Interface_send_data[1] = 0;
unsigned int i;
unsigned int dst = 0xff;
for(i=0;i<Feb_Interface_nfebs;i++) dst = (dst | Feb_Interface_feb_numb[i]);
int passed = Feb_Interface_WriteTo(dst);
return passed;
}
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read){
return Feb_Interface_ReadRegisters(sub_num,1,&reg_num,value_read);
}
int Feb_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
//here cout<<"Reading Register ...."<<endl;
if (Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
Feb_Interface_send_ndata = 2;
Feb_Interface_send_data[0] = 0;
Feb_Interface_send_data[1] = 0;
unsigned int i;
nreads &= 0x3ff;
if(!nreads||nreads>Feb_Interface_send_buffer_size-2) return 0;
unsigned int dst = 0xff;
for(i=0;i<Feb_Interface_nfebs;i++) dst = (dst | Feb_Interface_feb_numb[i]);
int passed = Feb_Interface_WriteTo(dst);
Feb_Interface_send_ndata = nreads+2;
Feb_Interface_send_data[0] = 0x20000000 | nreads << 14;
for(i=0;i<nreads;i++) Feb_Interface_send_data[i+1]=reg_nums[i];
Feb_Interface_send_data[nreads+1] = 0;
if(!Feb_Interface_WriteTo(sub_num)||!Feb_Interface_ReadFrom(sub_num,20)||Feb_Interface_recv_ndata!=(int)(nreads+2)) return 0;
for(i=0;i<nreads;i++) values_read[i] = Feb_Interface_recv_data[i+1];
return 1;
return passed;
}
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address){
return Feb_Interface_WriteRegisters(sub_num,1,&reg_num,&value,&wait_on,&wait_on_address);
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read) {
return Feb_Interface_ReadRegisters(sub_num,1,&reg_num,value_read);
}
int Feb_Interface_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_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read) {
//here cout<<"Reading Register ...."<<endl;
unsigned int i;
nwrites &= 0x3ff; //10 bits
if(!nwrites||2*nwrites>Feb_Interface_send_buffer_size-2) return 0;
nreads &= 0x3ff;
if (!nreads||nreads>Feb_Interface_send_buffer_size-2) return 0;
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
Feb_Interface_send_ndata = 2*nwrites+2;
Feb_Interface_send_data[0] = 0x80000000 | nwrites << 14;
Feb_Interface_send_data[2*nwrites+1] = 0;
Feb_Interface_send_ndata = nreads+2;
Feb_Interface_send_data[0] = 0x20000000 | nreads << 14;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+1] = 0x3fff&reg_nums[i];
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+2] = values[i];
// 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_Interface_send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
for(i=0;i<nreads;i++) Feb_Interface_send_data[i+1]=reg_nums[i];
Feb_Interface_send_data[nreads+1] = 0;
if(!Feb_Interface_WriteTo(sub_num)) return 0;
if (!Feb_Interface_WriteTo(sub_num)||!Feb_Interface_ReadFrom(sub_num,20)||Feb_Interface_recv_ndata!=(int)(nreads+2)) return 0;
return 1;
for(i=0;i<nreads;i++) values_read[i] = Feb_Interface_recv_data[i+1];
return 1;
}
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address) {
return Feb_Interface_WriteRegisters(sub_num,1,&reg_num,&value,&wait_on,&wait_on_address);
}
int Feb_Interface_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;
nwrites &= 0x3ff; //10 bits
if (!nwrites||2*nwrites>Feb_Interface_send_buffer_size-2) return 0;
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
Feb_Interface_send_ndata = 2*nwrites+2;
Feb_Interface_send_data[0] = 0x80000000 | nwrites << 14;
Feb_Interface_send_data[2*nwrites+1] = 0;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+1] = 0x3fff&reg_nums[i];
for(i=0;i<nwrites;i++) Feb_Interface_send_data[2*i+2] = values[i];
// 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_Interface_send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
if (!Feb_Interface_WriteTo(sub_num)) return 0;
return 1;
}
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values) {
unsigned int max_single_packet_size = 352;
int passed=1;
unsigned int n_to_send = max_single_packet_size;
unsigned int ndata_sent = 0;
unsigned int ndata_countdown = nwrites;
while(ndata_countdown>0){
while(ndata_countdown>0) {
n_to_send = ndata_countdown<max_single_packet_size ? ndata_countdown:max_single_packet_size;
if(!Feb_Interface_WriteMemory(sub_num,mem_num,start_address,n_to_send,&(values[ndata_sent]))){passed=0; break;}
if (!Feb_Interface_WriteMemory(sub_num,mem_num,start_address,n_to_send,&(values[ndata_sent]))) {passed=0; break;}
ndata_countdown-=n_to_send;
ndata_sent +=n_to_send;
start_address +=n_to_send;
@ -187,23 +171,26 @@ int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num,
return passed;
}
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
// -1 means write to all
int Feb_Interface_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;
start_address &= 0x3fff;
nwrites &= 0x3ff;
if(!nwrites||nwrites>Feb_Interface_send_buffer_size-2) {printf("error herer: nwrites:%d\n",nwrites);return 0;}//*d-1026
mem_num &= 0x3f;
start_address &= 0x3fff;
nwrites &= 0x3ff;
if (!nwrites||nwrites>Feb_Interface_send_buffer_size-2) {
FILE_LOG(logERROR, ("invalid nwrites:%d\n",nwrites));
return 0;
}//*d-1026
Feb_Interface_send_ndata = nwrites+2;//*d-1026
Feb_Interface_send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
Feb_Interface_send_data[nwrites+1] = 0;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[i+1] = values[i];
Feb_Interface_send_ndata = nwrites+2;//*d-1026
Feb_Interface_send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
Feb_Interface_send_data[nwrites+1] = 0;
for(i=0;i<nwrites;i++) Feb_Interface_send_data[i+1] = values[i];
if(!Feb_Interface_WriteTo(sub_num)) return 0;
if (!Feb_Interface_WriteTo(sub_num)) return 0;
return 1;
return 1;
}

View File

@ -1,43 +1,14 @@
#pragma once
/**
* @author Ian Johnson
* @version 1.0
*/
int Feb_Interface_WriteTo(unsigned int ch);
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys);
void Feb_Interface_FebInterface();
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list);
int Feb_Interface_SetByteOrder();
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read);
int Feb_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address);
int Feb_Interface_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_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
#ifndef FEBINTERFACE_H
#define FEBINTERFACE_H
#include "LocalLinkInterface.h"
int Feb_Interface_WriteTo(unsigned int ch);
/*int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys=20);*/
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys);
void Feb_Interface_FebInterface();
void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list);
int Feb_Interface_SetByteOrder();
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int* value_read);
int Feb_Interface_ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read);
/*int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on=0, unsigned int wait_on_address=0);*/
int Feb_Interface_WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, int wait_on, unsigned int wait_on_address);
/*int Feb_Interface_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_Interface_WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, int* wait_ons, unsigned int* wait_on_addresses);
//mem_num is 0 for trimbit BRAM and 1 for rate correction BRAM
int Feb_Interface_WriteMemoryInLoops(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values);
#endif

View File

@ -1,14 +1,3 @@
//Class initially from Gerd and was called mmap_test.c
//return reversed 1 means good, 0 means failed
//#include <stdio.h>
//#include <unistd.h>
//#include <string.h>
//#include <sys/mman.h>
//#include <fcntl.h>
#include "HardwareIO.h"
xfs_u8 HWIO_xfs_in8(xfs_u32 InAddress)

View File

@ -1,44 +1,36 @@
//Class initially from Gerd and was called mmap_test.c
//return reversed 1 means good, 0 means failed
#include "LocalLinkInterface.h"
#include "HardwareMMappingDefs.h"
#include "logger.h"
#include "ansi.h"
#include <stdio.h>
#include <unistd.h>
//#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "HardwareMMappingDefs.h"
#include "LocalLinkInterface.h"
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
// printf("\n v 1 \n");
printf("Initialize PLB LL FIFOs\n");
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr) {
FILE_LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
ll->ll_fifo_base=0;
ll->ll_fifo_ctrl_reg=0;
if(Local_Init(ll,ll_fifo_badr)){
if (Local_Init(ll,ll_fifo_badr)) {
Local_Reset(ll);
printf("\tFIFO Status : 0x%08x\n",Local_StatusVector(ll));
}else printf("\tError LocalLink Mappping : 0x%08x\n",ll_fifo_badr);
printf("\n\n");
FILE_LOG(logDEBUG1, ("\tFIFO Status : 0x%08x\n\n\n", Local_StatusVector(ll)));
} else FILE_LOG(logERROR, ("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
}
/*~LocalLinkInterface(){};*/
void Local_LocalLinkInterface(struct LocalLinkInterface* ll){
printf("Initializing new memory\n");
void Local_LocalLinkInterface(struct LocalLinkInterface* ll) {
FILE_LOG(logDEBUG1, ("Initializing new memory\n"));
}
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr) {
int fd;
void *plb_ll_fifo_ptr;
if ((fd=open("/dev/mem", O_RDWR)) < 0){
if ((fd=open("/dev/mem", O_RDWR)) < 0) {
fprintf(stderr, "Could not open /dev/mem\n");
return 0;
}
@ -46,7 +38,7 @@ int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
plb_ll_fifo_ptr = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, ll_fifo_badr);
close(fd);
if (plb_ll_fifo_ptr == MAP_FAILED){
if (plb_ll_fifo_ptr == MAP_FAILED) {
perror ("mmap");
return 0;
}
@ -59,13 +51,13 @@ int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr){
int Local_Reset(struct LocalLinkInterface* ll){
int Local_Reset(struct LocalLinkInterface* ll) {
return Local_Reset1(ll,PLB_LL_FIFO_CTRL_RESET_STD);
}
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask){
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask) {
ll->ll_fifo_ctrl_reg |= rst_mask;
printf("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg);
FILE_LOG(logDEBUG1, ("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg));
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
@ -75,17 +67,16 @@ int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask){
ll->ll_fifo_ctrl_reg &= (~rst_mask);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
// printf("FIFO CTRL Address: 0x%08x\n FIFO CTRL Register: 0x%08x\n",PLB_LL_FIFO_REG_CTRL,plb_ll_fifo[PLB_LL_FIFO_REG_CTRL]);
return 1;
}
unsigned int Local_StatusVector(struct LocalLinkInterface* ll){
unsigned int Local_StatusVector(struct LocalLinkInterface* ll) {
return HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
}
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer) {
// note: buffer must be word (4 byte) aligned
// frame_len in byte
int vacancy=0;
@ -101,22 +92,19 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
last_word = (buffer_len-1)/4;
word_ptr = (unsigned int *)buffer;
#ifdef MARTIN
cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base);
FILE_LOG(logDEBUG1, ("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base));
for (i=0; i < buffer_len/4; i++)
cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i));
printf("\n");
#endif
FILE_LOG(logDEBUG1, ("%.8X ",*(((unsigned *) buffer)+i)));
while (words_send <= last_word)
{
while (!vacancy)//wait for Fifo to be empty again
{
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
#ifdef MARTIN
if (vacancy == 0) cprintf(RED, "Fifo full!\n");
#endif
if ((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
if (vacancy == 0) {
FILE_LOG(logERROR, ("Fifo full!\n"));
}
}
//Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100
@ -140,7 +128,7 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
}
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer) {
static unsigned int buffer_ptr = 0;
// note: buffer must be word (4 byte) aligned
// frame_len in byte
@ -150,9 +138,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
volatile unsigned int fifo_val;
int sof = 0;
#ifdef MARTIN
cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base);
#endif
FILE_LOG(logDEBUG1, ("LL Read - If: %X - Data: ",ll->ll_fifo_base));
word_ptr = (unsigned int *)buffer;
do
@ -168,7 +154,6 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
buffer_ptr = 0;
return -1; // buffer overflow
}
// printf(">>>> SOF\n\r");
buffer_ptr = 0;
sof = 1;
}
@ -179,9 +164,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
{
if ( (buffer_len >> 2) > buffer_ptr)
{
#ifdef MARTIN
cprintf(CYAN, "%.8X ", fifo_val);
#endif
FILE_LOG(logDEBUG1, ("%.8X ", fifo_val));
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
}
else
@ -193,10 +176,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
if (status & PLB_LL_FIFO_STATUS_LL_EOF)
{
len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT );
#ifdef MARTIN
cprintf(CYAN, "Len: %d\n",len);
#endif
// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len);
FILE_LOG(logDEBUG1, ("Len: %d\n",len));
buffer_ptr = 0;
return len;
}
@ -209,19 +189,15 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
return 0;
}
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val){
// printf("Fifo CTRL Reg(1): 0x%08x\n",plb_ll_fifo_ctrl_reg);
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val) {
ll->ll_fifo_ctrl_reg &= (~mask);
//printf("Fifo CTRL Reg(2): 0x%08x\n",plb_ll_fifo_ctrl_reg);
ll->ll_fifo_ctrl_reg |= ( mask & val);
// printf("Fifo CTRL Reg: 0x%08x\n",plb_ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
// printf("Fifo STAT Reg: 0x%08x\n", plb_ll_fifo[PLB_LL_FIFO_REG_STATUS]);
return 1;
}
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer){
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer) {
int len;
unsigned int rec_buff_len = 4096;
@ -233,28 +209,14 @@ int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
do{
len = Local_Read(ll,rec_buff_len,rec_buffer);
printf("receive length: %i\n",len);
FILE_LOG(logDEBUG1, ("receive length: %i\n",len));
if (len > 0){
if (len > 0) {
rec_buffer[len]=0;
printf((char*) rec_buffer);
printf("\n");
FILE_LOG(logINFO, ("%s\n", (char*) rec_buffer));
}
} while(len > 0);
printf("\n\n\n\n");
return 1;
}
void Local_llfifo_print_frame(struct LocalLinkInterface* ll,unsigned char* fbuff, int len){
int i;
printf("\n\r----Frame of len : %d Byte\n\r",len);
for(i=0;i<len;i++){
printf("0x%02x ",fbuff[i] );
if ((i&0xf) == 0x7) printf(" ");
if ((i&0xf) == 0xf) printf("\n\r");
}
printf("\n\r");
}

View File

@ -1,54 +1,21 @@
#pragma once
//Class initially from Gerd and was called mmap_test.c
#ifndef LOCALLINKINTERFACE_H
#define LOCALLINKINTERFACE_H
#include "xfs_types.h"
#include "HardwareIO.h"
#include <sys/types.h>
#include "ansi.h"
#include <sys/mman.h>
#include <fcntl.h>
/*class LocalLinkInterface: public HardwareIO{ //*/
struct LocalLinkInterface{
xfs_u32 ll_fifo_base;
unsigned int ll_fifo_ctrl_reg;
xfs_u32 ll_fifo_base;
unsigned int ll_fifo_ctrl_reg;
};
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask);
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val);
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
unsigned int Local_StatusVector(struct LocalLinkInterface* ll);
int Local_Reset(struct LocalLinkInterface* ll);
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
void Local_LocalLinkInterface(struct LocalLinkInterface* ll);
int Local_Init(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask);
int Local_ctrl_reg_write_mask(struct LocalLinkInterface* ll,unsigned int mask, unsigned int val);
void Local_llfifo_print_frame(struct LocalLinkInterface* ll,unsigned char* fbuff, int len);
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr);
/* virtual ~LocalLinkInterface();*/
unsigned int Local_StatusVector(struct LocalLinkInterface* ll);
int Local_Reset(struct LocalLinkInterface* ll);
int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buffer);
void Local_LocalLinkInterface(struct LocalLinkInterface* ll);
/*
int FiFoReset(unsigned int numb);
int FifoSend(unsigned int numb, unsigned int frame_len, void *buffer);
int FifoReceive(unsigned int numb, unsigned int frame_len, void *buffer);
int FifoTest(unsigned int numb,unsigned int send_len, char *send_str);
*/
#endif

View File

@ -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)

View File

@ -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

View File

@ -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: 92fc837eb490650d91c2283943cbd729b2e36567
Revision: 6
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: 4131
Last Changed Date: 2018-10-29 17:14:27.000000002 +0100 ./Beb.c

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "c24a9b223cbb066d3851599f4d977ae835feffe4"
#define GITREPUUID "92fc837eb490650d91c2283943cbd729b2e36567"
#define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4099
#define GITDATE 0x20181011
#define GITREV 0x4131
#define GITDATE 0x20181029
#define GITBRANCH "refactor"

View File

@ -0,0 +1 @@
../slsDetectorServer/logger.h

View File

@ -42,15 +42,13 @@ enum DACINDEX {SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RX
};
enum ADCINDEX {TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_FPGA, TEMP_FPGAFEBL, TEMP_FPGAFEBR};
enum NETWORKINDEX {TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G};
enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE};
/* Hardware Definitions */
#define NCHAN (256 * 256)
#define NCHIP (4)
#define NADC (0)
#define NDAC (16)
#define NGAIN (0)
#define NOFFSET (0)
#define TEN_GIGA_BUFFER_SIZE (4112)

View File

@ -448,7 +448,7 @@ void setupDetector() {
bus_w(DAQ_REG, 0x0); /* Only once at server startup */
setSpeed(CLOCK_DIVIDER, HALF_SPEED);
setSpeed(HALF_SPEED);
cleanFifos();
resetCore();
@ -465,7 +465,7 @@ void setupDetector() {
setTimer(DELAY_AFTER_TRIGGER, DEFAULT_DELAY);
setTimer(STORAGE_CELL_NUMBER, DEFAULT_NUM_STRG_CLLS);
selectStoragecellStart(DEFAULT_STRG_CLL_STRT);
/*setSpeed(CLOCK_DIVIDER, HALF_SPEED); depends if all the previous stuff works*/
/*setSpeed(HALF_SPEED); depends if all the previous stuff works*/
setTiming(DEFAULT_TIMING_MODE);
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
@ -611,10 +611,7 @@ int setDynamicRange(int dr){
/* parameters - readout */
int setSpeed(enum speedVariable arg, int val) {
if (arg != CLOCK_DIVIDER)
return -1;
enum speedVariable setSpeed(int val) {
// setting
if(val >= 0) {
@ -1602,8 +1599,6 @@ void readFrame(int *ret, char *mess){
//cprintf(RED,"Waiting for finished flag\n");
usleep(5000);
}
*ret = (int)FINISHED;
strcpy(mess,"acquisition successfully finished\n");
return;
#endif
// wait for status to be done
@ -1618,9 +1613,8 @@ void readFrame(int *ret, char *mess){
sprintf(mess,"no data and run stopped: %lld frames left\n",(long long int)retval);
cprintf(RED,"%s\n",mess);
} else {
*ret = (int)FINISHED;
sprintf(mess,"acquisition successfully finished\n");
printf("%s",mess);
*ret = (int)OK;
cprintf(GREEN, "acquisition successfully finished\n");
}
}

View File

@ -8,7 +8,6 @@
#define GOODBYE (-200)
#define PROGRAMMING_MODE (-200)
#define MIN_REQRD_VRSN_T_RD_API 0x171220
#define REQRD_FRMWR_VRSN 0x180615

View File

@ -1 +0,0 @@
../slsDetectorServer/AD9257.h

View File

@ -1,33 +0,0 @@
CROSS = bfin-uclinux-
CC = $(CROSS)gcc
#CC = gcc
CLAGS += -Wall -DMYTHEN3D -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm -lstdc++
PROGS = mythen3DetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c
OBJS = $(SRC_CLNT:.c=.o)
all: clean versioning $(PROGS)
boot: $(OBJS)
versioning:
@echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;`
$(PROGS): $(OBJS)
# echo $(OBJS)
mkdir -p $(DESTDIR)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o

View File

@ -1,25 +0,0 @@
CC = gcc
CFLAGS += -Wall -DVIRTUAL -DMYTHEN3D -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm -lstdc++
PROGS = virtualMythen3DetectorServer
DESTDIR ?= bin
INSTMODE = 0777
SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c
OBJS = $(SRC_CLNT:.c=.o)
all: clean $(PROGS)
boot: $(OBJS)
$(PROGS): $(OBJS)
echo $(OBJS)
mkdir -p $(DESTDIR)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
rm *.gdb
clean:
rm -rf $(DESTDIR)/$(PROGS) *.o

View File

@ -1,101 +0,0 @@
#ifndef REGISTERS_G_H
#define REGISTERS_G_H
/* Definitions for FPGA*/
/* FPGA Version register */
#define FPGA_VERSION_REG (0x00 << 11)
#define BOARD_REVISION_OFST (0)
#define BOARD_REVISION_MSK (0x00FFFFFF << BOARD_REVISION_OFST)
#define DETECTOR_TYPE_OFST (24)
#define DETECTOR_TYPE_MSK (0x000000FF << DETECTOR_TYPE_OFST)
/* Fix pattern register */
#define FIX_PATT_REG (0x01 << 11)
/* Timer 64 bit Regiser */
#define SET_DELAY_LSB_REG (0x60 << 11) //96<<11 //0x68<<11
#define SET_DELAY_MSB_REG (0x61 << 11) //97<<11 //0x69<<11
#define SET_CYCLES_LSB_REG (0x62 << 11) //98<<11//0x6c<<11
#define SET_CYCLES_MSB_REG (0x63 << 11) //99<<11//0x6d<<11
#define SET_FRAMES_LSB_REG (0x64 << 11) //(100<<11)/** to hex */
#define SET_FRAMES_MSB_REG (0x65 << 11) //101<<11//0x71<<11
#define SET_PERIOD_LSB_REG (0x66 << 11) //102<<11//0x74<<11
#define SET_PERIOD_MSB_REG (0x67 << 11) //103<<11//0x75<<11
#define SET_GATES_LSB_REG (0x6A << 11) /*check in firmware*///106<<11//0x7c<<11
#define SET_GATES_MSB_REG (0x6B << 11) //107<<11//0x7d<<11
#define SET_EXPTIME_LSB_REG (0x72 << 11) /** check in firmware *///114<<11//0x78<<11
#define SET_EXPTIME_MSB_REG (0x73 << 11) //115<<11//0x79<<11
#define GET_ACTUAL_TIME_LSB_REG (0x10 << 11) //16<<11
#define GET_ACTUAL_TIME_MSB_REG (0x11 << 11) //17<<11
#define GET_DELAY_LSB_REG (0x12 << 11) //18<<11//0x6a<<11
#define GET_DELAY_MSB_REG (0x13 << 11) //19<<11//0x6b<<11
#define GET_CYCLES_LSB_REG (0x14 << 11) //20<<11//0x6e<<11
#define GET_CYCLES_MSB_REG (0x15 << 11) //21<<11//0x6f<<11
#define GET_FRAMES_LSB_REG (0x16 << 11) //22<<11//0x72<<11
#define GET_FRAMES_MSB_REG (0x17 << 11) //23<<11//0x73<<11
#define GET_PERIOD_LSB_REG (0x18 << 11) //24<<11//0x76<<11
#define GET_PERIOD_MSB_REG (0x19 << 11) //25<<11//0x77<<11
#define GET_EXPTIME_LSB_REG (0x1A << 11) //26<<11//0x7a<<11
#define GET_EXPTIME_MSB_REG (0x1B << 11) //27<<11//0x7b<<11
#define GET_GATES_LSB_REG (0x1C << 11) //28<<11//0x7e<<11
#define GET_GATES_MSB_REG (0x1D << 11) //29<<11//0x7f<<11
#define FRAMES_FROM_START_LSB_REG (0x22 << 11) //34<<11
#define FRAMES_FROM_START_MSB_REG (0x23 << 11) //35<<11
#define FRAMES_FROM_START_PG_LSB_REG (0x24 << 11) //36<<11
#define FRAMES_FROM_START_PG_MSB_REG (0x25 << 11) //37<<11
#define GET_MEASUREMENT_TIME_LSB_REG (0x26 << 11) //38<<11
#define GET_MEASUREMENT_TIME_MSB_REG (0x27 << 11) //39<<11
/* SPI (Serial Peripheral Interface) Register */
#define SPI_REG (0x40 << 11)
#define DAC_SERIAL_DIGITAL_OUT_OFST (0)
#define DAC_SERIAL_DIGITAL_OUT_MSK (0x00000001 << DAC_SERIAL_DIGITAL_OUT_OFST)
#define DAC_SERIAL_CLK_OUT_OFST (1)
#define DAC_SERIAL_CLK_OUT_MSK (0x00000001 << DAC_SERIAL_CLK_OUT_OFST)
#define DAC_SERIAL_CS_OUT_OFST (2)
#define DAC_SERIAL_CS_OUT_MSK (0x00000001 << DAC_SERIAL_CS_OUT_OFST)
#define HV_SERIAL_DIGITAL_OUT_OFST (8)
#define HV_SERIAL_DIGITAL_OUT_MSK (0x00000001 << HV_SERIAL_DIGITAL_OUT_OFST)
#define HV_SERIAL_CLK_OUT_OFST (9)
#define HV_SERIAL_CLK_OUT_MSK (0x00000001 << HV_SERIAL_CLK_OUT_OFST)
#define HV_SERIAL_CS_OUT_OFST (10)
#define HV_SERIAL_CS_OUT_MSK (0x00000001 << HV_SERIAL_CS_OUT_OFST)
/* Control Register */
#define CONTROL_REG (0x4F << 11) //(79 << 11) /** to hex */
/* Reconfiguratble PLL Control Regiser */
#define PLL_CONTROL_REG (0x51 << 11) //(81 << 11)/** to hex */
//#define PLL_CTRL_RECONFIG_RST_OFST (0) //parameter reset
//#define PLL_CTRL_RECONFIG_RST_MSK (0x00000001 << PLL_CTRL_RECONFIG_RST_OFST) //parameter reset
//#define PLL_CTRL_WR_PARAMETER_OFST (2)
//#define PLL_CTRL_WR_PARAMETER_MSK (0x00000001 << PLL_CTRL_WR_PARAMETER_OFST)
#define PLL_CTRL_RST_OFST (3)
#define PLL_CTRL_RST_MSK (0x00000001 << PLL_CTRL_RST_OFST)
//#define PLL_CTRL_ADDR_OFST (16)
//#define PLL_CTRL_ADDR_MSK (0x0000003F << PLL_CTRL_ADDR_OFST)
/* Samples Register */
#define NSAMPLES_REG (0x5D << 11) //93<<11
/* Power On Register */
#define POWER_ON_REG (0x5e<<11)
#define POWER_ENABLE_OFST (16)
/* Dac Registers */
#define DAC_VAL_REG (0x79 << 11) //121<<11
#define DAC_NUM_REG (0x80 << 11) //122<<11
#define DAC_VAL_OUT_REG (0x2A << 11) //42<<11
#endif

View File

@ -1 +0,0 @@
../../slsReceiverSoftware/include/ansi.h

View File

@ -1 +0,0 @@
/afs/psi.ch/project/mythen/marie_a/MythenServer/slsDetectorPackage/slsDetectorSoftware/slsDetectorServer/blackfin.h

View File

@ -1 +0,0 @@
../slsDetectorServer/commonServerFunctions.h

View File

@ -1 +0,0 @@
../commonFiles/communication_funcs.c

View File

@ -1 +0,0 @@
../commonFiles/communication_funcs.h

View File

@ -1,9 +0,0 @@
Path: slsDetectorsPackage/slsDetectorSoftware/jungfrauDetectorServer
URL: origin git@git.psi.ch:sls_detectors_software/slsDetectorPackage.git
Repository Root: origin git@git.psi.ch:sls_detectors_software/slsDetectorPackage.git
Repsitory UUID: 2f3dc8d109de8607f3217cf429619073dc9cc60e
Revision: 103
Branch: developer
Last Changed Author: Dhanya_Maliakal
Last Changed Rev: 3397
Last Changed Date: 2017-12-04 18:23:05.000000002 +0100 ./RegisterDefs.h

View File

@ -1,6 +0,0 @@
#define GITURL "git@git.psi.ch:sls_detectors_software/slsDetectorPackage.git"
#define GITREPUUID "2f3dc8d109de8607f3217cf429619073dc9cc60e"
#define GITAUTH "Dhanya_Maliakal"
#define GITREV 0x3397
#define GITDATE 0x20171204
#define GITBRANCH "developer"

View File

@ -1,6 +0,0 @@
#define GITURL ""
#define GITREPUUID ""
#define GITAUTH ""
#define GITREV ""
#define GITDATE ""
#define GITBRANCH ""

View File

@ -1 +0,0 @@
../slsDetectorServer/programfpga.h

View File

@ -1 +0,0 @@
../slsDetectorServer/slsDetectorFunctionList.h

View File

@ -1 +0,0 @@
../slsDetectorServer/slsDetectorServer.c

View File

@ -1,167 +0,0 @@
/*
* mythen3Server_defs.h
*
* Created on: Jan 24, 2013
* Author: l_maliakal_d, changed my Marie A.
*/
#ifndef SLSDETECTORSERVER_DEFS_H_
#define SLSDETECTORSERVER_DEFS_H_
#include "sls_detector_defs.h"
#include <stdint.h>
/** This is only an example file!!! */
#define GOODBYE (-200)
enum DACINDEX {vIpre, vIbias, Vrf, VrfSh, vIinSh, VdcSh, Vth2, VPL, Vth1, Vth3, Vtrim, casSh, cas, vIbiasSh, vIcin, VPH, NC, vIpreOut, V_D, V_CHIP, V_C, V_B, V_A, V_IO, V_LIM}; // Mythen 3.01
enum PWRINDEX {PWR_IO, PWR_A, PWR_B, PWR_C, PWR_D, PWR_CHIP=-1, PWR_LIMIT=-1};
enum CLKINDEX {RUN_CLK_C, ADC_CLK_C, SYNC_CLK_C, DBIT_CLK_C};
#define DEFAULT_DAC_VALS { 2150, /* vIpre */ \
1200, /* vIbias */ \
900, /* Vrf */ \
1050, /* VrfSh */ \
1400, /* vIinSh */ \
655, /* VdcSh */ \
850, /* Vth2 */ \
1400, /* VPL */ \
850, /* Vth1 */ \
850, /* Vth3 */ \
2294, /* Vtrim */ \
983, /* casSh */ \
1474, /* cas */ \
1200, /* vIbiasSh */ \
1600, /* vIcin */ \
1520, /* VPH */ \
0, /* NC */ \
1000 /* vIpreOut */ \
0 /* V_D */ \
0 /* V_CHIP */ \
0 /* V_C */ \
1335 /* V_B */ \
1335 /* V_A */ \
1350 /* V_IO */ \
};
#define DEFAULT_DAC_NAMES { "vIpre", \
"vIbias", \
"Vrf", \
"VrfSh", \
"vIinSh", \
"VdcSh", \
"Vth2", \
"VPL", \
"Vth1", \
"Vth3", \
"Vtrim", \
"casSh", \
"cas", \
"vIbiasSh", \
"vIcin", \
"VPH", \
"NC", \
"vIpreOut" \
"v_d" \
"v_chip" \
"v_c" \
"v_b" \
"v_a" \
"v_io" \
};
/*Hardware Definitions */
#define NMAXMOD (1)
#define NMOD (1)
#define NCHAN (32)
#define NCHIP (1)
#define NADC (0)
#define NDAC (24)
#define NDAC_PER_SET (8)
#define NPWR (5)
#define MAX_DACVOLTVAL (2500) //mV
#define MAX_DACVAL (4096) // dac val
#define MAX_VCHIPVAL (2700) //mV /** name ???? */
#define MIN_VCHIP_OFSTVAL (200) //mV /** name ???? */
#define MIN_VCHIP_VAL (600) //mV /** name ???? */
/** Default Parameters */
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_EXPTIME (200*1000) //ns
#define DEFAULT_PERIOD (1*1000*1000) //ns
#define DEFAULT_DELAY (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
/* Defines in the Firmware */
#define FIX_PATT_VAL (0xACDC1980)
/* LTC2620 DAC DEFINES */
#define LTC2620_DAC_CMD_OFST (20)
#define LTC2620_DAC_CMD_MSK (0x0000000F << LTC2620_DAC_CMD_OFST)
#define LTC2620_DAC_ADDR_OFST (16)
#define LTC2620_DAC_ADDR_MSK (0x0000000F << LTC2620_DAC_ADDR_OFST)
#define LTC2620_DAC_DATA_OFST (4)
#define LTC2620_DAC_DATA_MSK (0x00000FFF << LTC2620_DAC_DATA_OFST)
#define LTC2620_DAC_CMD_WRITE (0x00000000 << LTC2620_DAC_CMD_OFST)
#define LTC2620_DAC_CMD_SET (0x00000003 << LTC2620_DAC_CMD_OFST)
#define LTC2620_DAC_CMD_POWER_DOWN (0x00000004 << LTC2620_DAC_CMD_OFST)
#define LTC2620_DAC_NUMBITS (24)
/** PLL Reconfiguration Registers */
//https://www.altera.com/documentation/mcn1424769382940.html
#define PLL_MODE_REG (0x00)
#define PLL_STATUS_REG (0x01)
#define PLL_START_REG (0x02)
#define PLL_N_COUNTER_REG (0x03)
#define PLL_M_COUNTER_REG (0x04)
#define PLL_C_COUNTER_REG (0x05)
#define PLL_PHASE_SHIFT_REG (0x06)
#define PLL_SHIFT_NUM_SHIFTS_OFST (0)
#define PLL_SHIFT_NUM_SHIFTS_MSK (0x0000FFFF << PLL_SHIFT_NUM_SHIFTS_OFST)
#define PLL_SHIFT_CNT_SELECT_OFST (16)
#define PLL_SHIFT_CNT_SELECT_MSK (0x0000001F << PLL_SHIFT_CNT_SELECT_OFST)
#define PLL_SHIFT_CNT_SLCT_C0_VAL ((0x0 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C1_VAL ((0x1 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C2_VAL ((0x2 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C3_VAL ((0x3 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C4_VAL ((0x4 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C5_VAL ((0x5 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C6_VAL ((0x6 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C7_VAL ((0x7 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C8_VAL ((0x8 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C9_VAL ((0x9 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C10_VAL ((0x10 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C11_VAL ((0x11 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C12_VAL ((0x12 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C13_VAL ((0x13 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C14_VAL ((0x14 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C15_VAL ((0x15 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C16_VAL ((0x16 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_CNT_SLCT_C17_VAL ((0x17 << PLL_SHIFT_CNT_SELECT_OFST) & PLL_SHIFT_CNT_SELECT_MSK)
#define PLL_SHIFT_UP_DOWN_OFST (21)
#define PLL_SHIFT_UP_DOWN_MSK (0x00000001 << PLL_SHIFT_UP_DOWN_OFST)
#define PLL_SHIFT_UP_DOWN_NEG_VAL ((0x0 << PLL_SHIFT_UP_DOWN_OFST) & PLL_SHIFT_UP_DOWN_MSK)
#define PLL_SHIFT_UP_DOWN_POS_VAL ((0x1 << PLL_SHIFT_UP_DOWN_OFST) & PLL_SHIFT_UP_DOWN_MSK)
#define PLL_K_COUNTER_REG (0x07)
#define PLL_BANDWIDTH_REG (0x08)
#define PLL_CHARGEPUMP_REG (0x09)
#define PLL_VCO_DIV_REG (0x1c)
#define PLL_MIF_REG (0x1f)
#define PLL_VCO_FREQ_MHZ 400
#endif /* SLSDETECTORSERVER_DEFS_H_ */

View File

@ -1 +0,0 @@
../slsDetectorServer/slsDetectorServer_funcs.c

View File

@ -1 +0,0 @@
../slsDetectorServer/slsDetectorServer_funcs.h

View File

@ -1 +0,0 @@
../commonFiles/sls_detector_defs.h

View File

@ -1 +0,0 @@
../commonFiles/sls_detector_funcs.h

View File

@ -1 +0,0 @@
../../slsReceiverSoftware/include/sls_receiver_defs.h

View File

@ -1 +0,0 @@
../../slsReceiverSoftware/include/sls_receiver_funcs.h

View File

@ -1,31 +0,0 @@
SERVER=jungfrauDetectorServer
MAINDIR=slsDetectorsPackage
SPECDIR=slsDetectorSoftware/$SERVER
TMPFILE=gitInfoJungfrauTmp.h
INCLFILE=gitInfoJungfrau.h
#evaluate the variables
EVALFILE=../../evalVersionVariables.sh
source $EVALFILE
#get modified date
#RDATE1='git log --pretty=format:"%ci" -1'
RDATE1="find ../slsDetectorServer . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|bin|.git|updateGitVersion|.o' | head -n 1"
RDATE=`eval $RDATE1`
NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}')
NEWDATE=${NEWDATE/#/0x}
#get old date from INCLFILE
OLDDATE=$(more $INCLFILE | grep '#define GITDATE' | awk '{print $3}')
#update INCLFILE if changes
if [ "$OLDDATE" != "$NEWDATE" ]; then
echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt
cd ../../
./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE
cd $WD
fi

View File

@ -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(logDEBUG1, ("%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);
int j;
if (socketDescriptor < 0)
return -1;
// copy file descriptor set temporarily
memcpy(&tempset, &readset, sizeof(tempset));
struct sockaddr_in addressC;
int file_des=-1;
struct timeval tv;
int result;
// set time out as 2777.77 hours?
tv.tv_sec = 10000000;
tv.tv_usec = 0;
// monitor file descrptors
int result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
//socklen_t address_length;
socklen_t address_length=sizeof(struct sockaddr_in);
if (socketDescriptor<0)
return -1;
// timeout
if (result == 0) {
FILE_LOG(logDEBUG1, ("%s socket select() timed out!\n",
(isControlServer ? "control":"stop"), myport));
}
memcpy(&tempset, &readset, sizeof(tempset));
tv.tv_sec = 10000000;
tv.tv_usec = 0;
result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
// 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 (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);
// activity in descriptor set
else if (result > 0) {
FILE_LOG(logDEBUG1, ("%s select returned!\n", (isControlServer ? "control":"stop")));
// loop through the file descriptor set
for (j = 0; j < maxfd + 1; ++j) {
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
// checks if file descriptor part of set
if (FD_ISSET(j, &tempset)) {
FILE_LOG(logDEBUG1, ("fd %d is set\n",j));
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;
}
// clear the temporary set
FD_CLR(j, &tempset);
}
}
}
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(logDEBUG1, ("%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(logDEBUG1, ("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,266 +292,193 @@ 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(logDEBUG1, ("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 (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
if (total_received>0)
strcpy(thisClientIP,dummyClientIP);
return total_received;
if (strcmp(lastClientIP,thisClientIP))
differentClients = 1;
else
differentClients = 0;
return total_received;
}
int sendModule(int file_des, sls_detector_module *myMod) {
return sendModuleGeneral(file_des, myMod, 1);
}
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
int ts=0;
#ifdef VERBOSE
int idac;
int ts = 0, n = 0;
n = sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32);
if (!n) return -1; ts += n;
// dacs
n = sendData(file_des,myMod->dacs, sizeof(int)*(myMod->ndac), INT32);
if (!n) return -1; ts += n;
// adcs
n = sendData(file_des,myMod->adcs, sizeof(int)*(myMod->nadc), INT32);
if (!n) return -1; ts += n;
// channels
#ifdef EIGERD
n = sendData(file_des,myMod->chanregs, sizeof(int) * (myMod->nchan), INT32);
if (!n) return -1; ts += n;
#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);
#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
/*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
}
#ifdef VERBOSE
printf("module of size %d sent register %x\n", ts, myMod->reg);
#endif
return ts;
FILE_LOG(logDEBUG1, ("module of size %d sent register %x\n", ts, myMod->reg));
return ts;
}
int receiveModule(int file_des, sls_detector_module* myMod) {
return receiveModuleGeneral(file_des,myMod,1);
}
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);
myMod->dacs=dacptr;
myMod->adcs=adcptr;
myMod->chipregs=chipptr;
myMod->chanregs=chanptr;
int ts = 0, n = 0;
int nDacs = myMod->ndac;
int nAdcs = myMod->nadc;
#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;
}
int nChans = myMod->nchan; // can be zero for no trimbits
#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);
n = receiveData(file_des,&(myMod->serialnumber), sizeof(myMod->serialnumber), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32);
if (!n) return -1; ts += n;
// dacs
if (nDacs != (myMod->ndac)) {
FILE_LOG(logERROR, ("received wrong number of dacs. "
"Expected %d, got %d\n", nDacs, myMod->ndac));
return 0;
}
n = receiveData(file_des,&(myMod->dacs), sizeof(int) * (myMod->ndac), INT32);
if (!n) return -1; ts += n;
// adcs
if (nAdcs != (myMod->nadc)) {
FILE_LOG(logERROR, ("received wrong number of adcs. "
"Expected %d, got %d\n", nAdcs, myMod->nadc));
return 0;
}
n = receiveData(file_des,&(myMod->adcs), sizeof(int) * (myMod->nadc), INT32);
if (!n) return -1; ts += n;
// channels
#ifdef EIGERD
if (((myMod->nchan) != 0 ) || // no trimbits
(nChans != (myMod->nchan))) { // with trimbits
FILE_LOG(logERROR, ("received wrong number of channels. "
"Expected %d, got %d\n", nChans, (myMod->nchan)));
return 0;
}
n = receiveData(file_des,&(myMod->chanregs), sizeof(int) * (myMod->nchan), INT32);
if (!n) return -1; ts += n;
#endif
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
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
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]);
#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;
}
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;
}
/*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;
FILE_LOG(logDEBUG1, ("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;
}
int Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize) {
// update if different clients (ret can be ok or acquisition finished), not fail to not overwrite e message
if (update && ret != FAIL && 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);
return ret;
}

View File

@ -37,11 +37,33 @@ 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
* @returns result of operation
*/
int Server_SendResult(int fileDes, intType itype, int update, void* retval, int retvalSize);
#endif

View File

@ -0,0 +1,64 @@
#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, logGREEN,
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 logGREEN: cprintf(GREEN, "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;
};

View File

@ -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,16 +18,13 @@ int isFirmwareCheckDone();
int getFirmwareCheckResult(char** mess);
#endif
void checkFirmwareCompatibility(int flag);
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
void checkFirmwareCompatibility();
#ifdef JUNGFRAUD
int checkType();
u_int32_t testFpga(void);
int testBus(void);
#endif
#ifdef MYTHEN3D
int moduleTest( enum digitalTestMode arg);
#endif
#ifdef JUNGFRAUD
int detectorTest( enum digitalTestMode arg);
#endif
@ -44,7 +37,7 @@ u_int64_t getFirmwareAPIVersion();
u_int16_t getHardwareVersionNumber();
u_int16_t getHardwareSerialNumber();
#endif
#if !defined(MYTHEN3D) || !defined(EIGERD)
#ifdef EIGERD
u_int32_t getDetectorNumber();
#endif
u_int64_t getDetectorMAC();
@ -77,17 +70,11 @@ uint32_t readRegister(uint32_t offset);
// firmware functions (resets)
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
#ifdef JUNGFRAUD
int powerChip (int on);
void cleanFifos();
void resetCore();
void resetPeripheral();
#endif
#ifdef MYTHEN3D
int getPhase(int i);
int configurePhase(int val, enum CLKINDEX i);
int configureFrequency(int val, int i);
#elif JUNGFRAUD
int autoCompDisable(int on);
int adcPhase(int st);
int getPhase();
@ -101,7 +88,7 @@ int setROI(int n, ROI arg[], int *retvalsize, int *ret);
#endif
// parameters - readout
int setSpeed(enum speedVariable arg, int val);
enum speedVariable setSpeed(int val);
#ifdef EIGERD
enum readOutFlags setReadOutFlags(enum readOutFlags val);
#endif
@ -115,12 +102,7 @@ int64_t getTimeLeft(enum timerIndex ind);
// parameters - module, settings
#ifdef EIGERD
int setModule(sls_detector_module myMod, int delay);
#else
int setModule(sls_detector_module myMod);
#endif
int setModule(sls_detector_module myMod, char* mess);
int getModule(sls_detector_module *myMod);
enum detectorSettings setSettings(enum detectorSettings sett);
enum detectorSettings getSettings();
@ -133,47 +115,36 @@ int setThresholdEnergy(int ev);
#endif
// parameters - dac, adc, hv
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
#ifdef JUNGFRAUD
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset);
void initDac(int dacnum);
int voltageToDac(int value);
int dacToVoltage(unsigned int digital);
#endif
#ifdef MYTHEN3D
int setPower(enum DACINDEX ind, int val);
int powerToDac(int value, int chip);
int dacToPower(int value, int chip);
#endif
#ifdef JUNGFRAUD
extern void setAdc(int addr, int val); // AD9257.h
#endif
void setDAC(enum DACINDEX ind, int val, int mV, int retval[]);
#ifdef MYTHEN3D
int getVLimit();
void setDacRegister(int dacnum,int dacvalue);
int getDacRegister(int dacnum);
#endif
#ifndef MYTHEN3D
int getADC(enum ADCINDEX ind);
#endif
#ifndef MYTHEN3D
int setHighVoltage(int val);
#endif
// parameters - timing, extsig
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg);
void setTiming( enum externalCommunicationMode arg);
enum externalCommunicationMode getTiming();
// configure mac
#ifdef JUNGFRAUD
long int calcChecksum(int sourceip, int destip);
#endif
#ifndef MYTHEN3D
#ifdef GOTTHARDD
int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2, int ival);
#else
int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2);
#endif
#if defined(JUNGFRAUD) || defined(EIGERD)
int setDetectorPosition(int pos[]);
@ -190,7 +161,7 @@ int resetCounterBlock(int startACQ);
int calibratePedestal(int frames);
// jungfrau specific - pll, flashing firmware
#elif defined(JUNGFRAUD) || defined(MYTHEN3D)
#elif JUNGFRAUD
void resetPLL();
u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val);
void configurePll();
@ -257,13 +228,6 @@ int getTotalNumberOfChannels();
int getNumberOfChips();
int getNumberOfDACs();
int getNumberOfADCs();
#ifdef EIGERD
int getNumberOfGains();
int getNumberOfOffsets();
#endif
int getNumberOfChannelsPerChip();
#endif
#endif

View File

@ -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,34 +27,33 @@ 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
signal(SIGPIPE, SIG_IGN);
// circumvent the basic tests
{
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 +63,52 @@ int main(int argc, char *argv[]){
char cmd[100];
memset(cmd, 0, 100);
#endif
if (controlserver) {
if (isControlServer) {
portno = DEFAULT_PORTNO;
cprintf(BLUE,
"********************************************************\n"
"********* opening control server on port %d **********\n"
"********************************************************\n\n"
, portno);
FILE_LOG(logINFO, ("Opening control server on port %d \n", 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(logDEBUG1, ("Command to start stop server:%s\n", cmd));
system(cmd);
}
#endif
} else {
portno = DEFAULT_PORTNO+1;
cprintf(BLUE,
"********************************************************\n"
"*********** opening stop server on port %d ***********\n"
"********************************************************\n\n"
, portno);
portno = DEFAULT_PORTNO + 1;
FILE_LOG(logINFO,("Opening stop server on port %d \n", 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(logINFOBLUE, ("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

View File

@ -1,17 +1,18 @@
#ifndef SERVER_FUNCS_H
#define SERVER_FUNCS_H
#pragma once
#include "sls_detector_defs.h"
#include <stdlib.h>
// 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();
void modeNotImplemented(char* modename, int mode);
void validate(int arg, int retval, char* modename, int hex);
void validate64(int64_t arg, int64_t retval, char* modename, int hex);
int M_nofunc(int);
int M_nofuncMode(int);
@ -77,4 +78,3 @@ int storage_cell_start(int);
int check_version(int);
int software_trigger(int);
#endif

View File

@ -8,6 +8,8 @@
#include "slsDetector.h"
#include "sls_detector_exceptions.h"
#include "utilities.h"
#include "detectorData.h"
#include <iomanip>
#include <iostream>
@ -2107,19 +2109,9 @@ int multiSlsDetector::writeAdcRegister(int addr, int val, int detPos) {
return detectors[detPos]->writeAdcRegister(addr, val);
}
// multi
auto r = parallelCall(&slsDetector::writeAdcRegister, addr, val);
if (sls::allEqual(r))
return r.front();
// can't have different values
FILE_LOG(logERROR)
<< "Error: Different Values for function writeAdcRegister "
"(write 0x"
<< std::hex << val << " to addr 0x" << std::hex << addr << std::dec
<< ")";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES);
return -1;
// multi
auto r = parallelCall(&slsDetector::writeAdcRegister, addr, val);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
int multiSlsDetector::activate(int const enable, int detPos) {
@ -2356,62 +2348,50 @@ int multiSlsDetector::setAutoComparatorDisableMode(int ival, int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::getChanRegs(double *retval, bool fromDetector,
int detPos) {
int multiSlsDetector::getChanRegs(double* retval, int detPos) {
int offset = 0;
std::vector<int> r;
for (auto &d : detectors) {
int nch = d->getTotalNumberOfChannels();
double result[nch];
r.push_back(d->getChanRegs(result, fromDetector));
memcpy(retval + offset, result, nch * sizeof(double));
}
return sls::minusOneIfDifferent(r);
int offset = 0;
std::vector<int> r;
for (auto& d : detectors) {
int nch = d->getTotalNumberOfChannels();
double result[nch];
r.push_back(d->getChanRegs(result));
memcpy(retval + offset, result, nch * sizeof(double));
}
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::calibratePedestal(int frames, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->calibratePedestal(frames);
}
// multi
auto r = parallelCall(&slsDetector::calibratePedestal, frames);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setRateCorrection(int t, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setRateCorrection(t);
}
int multiSlsDetector::setRateCorrection(int64_t t, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setRateCorrection(t);
}
// multi
auto r = parallelCall(&slsDetector::setRateCorrection, t);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
int multiSlsDetector::getRateCorrection(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getRateCorrection();
}
int64_t multiSlsDetector::getRateCorrection(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getRateCorrection();
}
// multi
auto r = parallelCall(&slsDetector::getRateCorrection);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::printReceiverConfiguration(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->printReceiverConfiguration();
}
void multiSlsDetector::printReceiverConfiguration(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->printReceiverConfiguration();
}
// multi
auto r = parallelCall(&slsDetector::printReceiverConfiguration);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
// multi
for (auto& d : detectors)
d->printReceiverConfiguration();
}
int multiSlsDetector::setReceiverOnline(int off, int detPos) {
@ -3768,4 +3748,4 @@ bool multiSlsDetector::isDetectorIndexOutOfBounds(int detPos) {
return true;
}
return false;
}
}

View File

@ -7,9 +7,10 @@
* @short This is the base class for multi detector system functionalities
* @author Anna Bergamaschi
*/
#include "error_defs.h"
#include "sls_detector_defs.h"
#include "error_defs.h"
#include "logger.h"
class slsDetector;
class SharedMemory;
@ -230,21 +231,6 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
int64_t getId(idMode mode, int detPos = -1);
/**
* Get sls detector object from position in detectors array
* @param detPos -1 for all detectors in list or specific detector position
* @returns pointer to sls detector object
*/
// slsDetector* getSlsDetector(int detPos = -1);
/**
* Accessing the sls detector from the multi list using position
* @param detPos -1 for all detectors in list or specific detector position
* @returns slsDetector object
*/
// slsDetector *operator()(int detPos = -1) const;
// slsDetector* operator[](int detPos) const;
/**
* Free shared memory from the command line
* avoiding creating the constructor classes and mapping
@ -1192,48 +1178,36 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
int setAutoComparatorDisableMode(int ival = -1, int detPos = -1);
/**
* Returns the trimbits from the detector's shared memmory (Mythen, Eiger)
* @param retval is the array with the trimbits
* @param fromDetector is true if the trimbits shared memory have to be
* uploaded from detector
* @param detPos -1 for all detectors in list or specific detector position
* @returns total number of channels for the detector
*/
int getChanRegs(double *retval, bool fromDetector, int detPos = -1);
/**
* Returns the trimbits from the detector's shared memmory (Mythen, Eiger)
* @param retval is the array with the trimbits
* @param detPos -1 for all detectors in list or specific detector position
* @returns total number of channels for the detector
*/
int getChanRegs(double* retval, int detPos = -1);
/**
* Calibrate Pedestal (ChipTestBoard)
* Starts acquisition, calibrates pedestal and writes to fpga
* @param frames number of frames
* @param detPos -1 for all detectors in list or specific detector position
* @returns number of frames
*/
int calibratePedestal(int frames = 0, int detPos = -1);
/**
* Set Rate correction ( Eiger)
* @param t dead time in ns - if 0 disable correction,
* if >0 set dead time to t, if < 0 set deadtime to default dead time
* for current settings
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, >0 otherwise
*/
int setRateCorrection(int64_t t = 0, int detPos = -1);
/**
* Set Rate correction ( Eiger)
* @param t dead time in ns - if 0 disable correction,
* if >0 set dead time to t, if < 0 set deadtime to default dead time
* for current settings
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, >0 otherwise
*/
int setRateCorrection(int t = 0, int detPos = -1);
/**
* Get rate correction ( Eiger)
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, > 0 otherwise (ns)
*/
int64_t getRateCorrection(int detPos = -1);
/**
* Get rate correction ( Eiger)
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, > 0 otherwise (ns)
*/
int getRateCorrection(int detPos = -1);
/**
* Prints receiver configuration
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int printReceiverConfiguration(int detPos = -1);
/**
* Prints receiver configuration
* @param detPos -1 for all detectors in list or specific detector position
*/
void printReceiverConfiguration(int detPos = -1);
/**
* Sets up receiver socket if online and sets the flag

View File

@ -1,6 +1,7 @@
#include "SharedMemory.h"
#include "sls_detector_exceptions.h"
#include "ansi.h"
#include "logger.h"
#include <iostream>
#include <stdio.h> // printf
@ -51,15 +52,13 @@ void* SharedMemory::CreateSharedMemory(size_t sz){
// create
fd = shm_open(name.c_str(), O_CREAT | O_TRUNC | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) {
cprintf(RED, "Error: Create shared memory %s failed: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Create shared memory " << name << " failed: " << strerror(errno);
throw SharedMemoryException();
}
// resize
if (ftruncate(fd, sz) < 0) {
cprintf(RED, "Error: Create shared memory %s failed at ftruncate: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Create shared memory " << name << " failed at ftruncate: " << strerror(errno);
close(fd);
RemoveSharedMemory();
throw SharedMemoryException();
@ -67,7 +66,7 @@ void* SharedMemory::CreateSharedMemory(size_t sz){
// map
void* addr = MapSharedMemory(sz);
printf("Shared memory created %s \n", name.c_str());
FILE_LOG(logINFO) << "Shared memory created " << name;
return addr;
}
@ -75,8 +74,7 @@ void* SharedMemory::OpenSharedMemory(size_t sz){
// open
fd = shm_open(name.c_str(), O_RDWR, 0);
if (fd < 0) {
cprintf(RED, "Error: Open existing shared memory %s failed: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Open existing shared memory " << name << " failed: " << strerror(errno);
throw SharedMemoryException();
}
@ -86,8 +84,7 @@ void* SharedMemory::OpenSharedMemory(size_t sz){
void SharedMemory::UnmapSharedMemory(void* addr) {
if (munmap(addr, shmSize) < 0) {
cprintf(RED, "Error: Unmapping shared memory %s failed: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Unmapping shared memory " << name << " failed: " << strerror(errno);
close(fd);
throw SharedMemoryException();
}
@ -98,19 +95,17 @@ void SharedMemory::RemoveSharedMemory() {
// silent exit if shm did not exist anyway
if (errno == ENOENT)
return;
cprintf(RED, "Error: Free Shared Memory %s Failed: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Free Shared Memory " << name << " Failed: " << strerror(errno);
throw SharedMemoryException();
}
printf("Shared memory deleted %s \n", name.c_str());
FILE_LOG(logINFO) << "Shared memory deleted " << name;
}
void* SharedMemory::MapSharedMemory(size_t sz) {
void* addr = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) {
cprintf(RED, "Error: Mapping shared memory %s failed: %s\n",
name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Mapping shared memory " << name << " failed: " << strerror(errno);
close(fd);
throw SharedMemoryException();
}
@ -138,10 +133,9 @@ std::string SharedMemory::ConstructSharedMemoryName(int multiId, int slsId) {
std::string temp = ss.str();
if (temp.length() > NAME_MAX) {
cprintf(RED, "Error: Shared memory initialization failed. "
"%s has %lu characters. \n"
"Maximum is %d. Change the environment variable %s\n",
temp.c_str(), temp.length(), NAME_MAX, SHM_ENV_NAME);
FILE_LOG(logERROR) << "Shared memory initialization failed. " <<
temp << " has " << temp.length() << " characters. \n"
"Maximum is " << NAME_MAX << ". Change the environment variable " << SHM_ENV_NAME;
throw SharedMemoryException();
}
return temp;
@ -152,8 +146,8 @@ int SharedMemory::VerifySizeMatch(size_t expectedSize) {
struct stat sb;
// could not fstat
if (fstat(fd, &sb) < 0) {
cprintf(RED, "Error: Could not verify existing shared memory %s size match "
"(could not fstat): %s\n", name.c_str(), strerror(errno));
FILE_LOG(logERROR) << "Could not verify existing shared memory " << name << " size match "
"(could not fstat): " << strerror(errno);
close(fd);
throw SharedMemoryException();
}
@ -161,11 +155,8 @@ int SharedMemory::VerifySizeMatch(size_t expectedSize) {
//size does not match
long unsigned int sz = (long unsigned int)sb.st_size;
if (sz != expectedSize) {
cprintf(RED, "Warning: Existing shared memory %s size does not match.\n",
name.c_str());
#ifdef VERBOSE
cprintf(RED, " Expected %ld, found %ld\n", expectedSize, sz);
#endif
FILE_LOG(logERROR) << "Existing shared memory " << name << " size does not match";
FILE_LOG(logDEBUG1) << "Expected " << expectedSize << ", found " << sz;
throw SharedMemoryException();
return 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@
#include "sls_detector_defs.h"
#include "error_defs.h"
#include "logger.h"
#include "math.h"
class multiSlsDetector;
@ -32,8 +34,6 @@ typedef struct detParameterList {
int nChipY;
int nDacs;
int nAdcs;
int nGain;
int nOffset;
int dynamicRange;
int nGappixelsX;
int nGappixelsY;
@ -112,12 +112,6 @@ private:
/** number of adcs per module */
int nAdcs;
/** number of extra gain values*/
int nGain;
/** number of extra offset values */
int nOffset;
/** dynamic range of the detector data */
int dynamicRange;
@ -158,18 +152,9 @@ private:
/** memory offsets for the adc arrays */
int adcoff;
/** memory offsets for the chip register arrays */
int chipoff;
/** memory offsets for the channel register arrays -trimbits*/
int chanoff;
/** memory offsets for the gain register arrays */
int gainoff;
/** memory offsets for the offset register arrays -trimbits*/
int offsetoff;
/** ip address/hostname of the receiver for client control via TCP */
char receiver_hostname[MAX_STR_LENGTH];
@ -622,12 +607,10 @@ public:
* Writes a trim/settings file for module number
* the values will be read from the current detector structure
* @param fname name of the file to be written
* @param iodelay io delay (detector specific)
* @param tau tau (detector specific)
* @returns OK or FAIL if the file could not be written
* \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
*/
int writeSettingsFile(std::string fname, int iodelay, int tau);
int writeSettingsFile(std::string fname);
/**
* Get detector settings
@ -1073,11 +1056,11 @@ public:
/**
* Gets counter memory block in detector (Gotthard)
* @param arg counter memory block from detector
* @param image counter memory block from detector
* @param startACQ 1 to start acquisition afterwards, else 0
* @returns OK or FAIL
*/
int getCounterBlock(short int arg[],int startACQ=0);
int getCounterBlock(short int image[],int startACQ=0);
/**
* Resets counter in detector
@ -1276,30 +1259,22 @@ public:
/**
* Returns the trimbits from the detector's shared memmory (Mythen, Eiger)
* Returns the trimbits from the detector's shared memmory (Eiger)
* @param retval is the array with the trimbits
* @param fromDetector is true if the trimbits shared memory have to be
* uploaded from detector
* @returns total number of channels for the detector
*/
int getChanRegs(double* retval,bool fromDetector);
int getChanRegs(double* retval);
/**
* Configure Module (Eiger)
* Called for loading trimbits and settings settings to the detector
* @param module module to be set - must contain correct module number and
* also channel and chip registers
* @param iodelay iodelay (detector specific)
* @param tau tau (detector specific)
* @param e_eV threashold in eV (detector specific)
* @param gainval pointer to extra gain values
* @param offsetval pointer to extra offset values
* @param tb 1 to include trimbits, 0 to exclude (used for eiger)
* @returns current register value
* @returns ok or fail
* \sa ::sls_detector_module
*/
int setModule(sls_detector_module module, int iodelay, int tau, int e_eV,
int* gainval=0, int* offsetval=0, int tb=1);
int setModule(sls_detector_module module, int tb = 1);
/**
@ -1308,14 +1283,6 @@ public:
*/
sls_detector_module *getModule();
/**
* Calibrate Pedestal (ChipTestBoard)
* Starts acquisition, calibrates pedestal and writes to fpga
* @param frames number of frames
* @returns number of frames
*/
int calibratePedestal(int frames = 0);
/**
* Set Rate correction (Mythen, Eiger)
* @param t dead time in ns - if 0 disable correction,
@ -1323,19 +1290,19 @@ public:
* for current settings
* @returns 0 if rate correction disabled, >0 otherwise
*/
int setRateCorrection(int t=0);
int setRateCorrection(int64_t t = 0);
/**
* Get rate correction Eiger)
* @returns 0 if rate correction disabled, > 0 otherwise
*/
int getRateCorrection();
int64_t getRateCorrection();
/**
* Prints receiver configuration
* @returns OK or FAIL
* #param level print level
*/
int printReceiverConfiguration();
void printReceiverConfiguration(TLogLevel level = logINFO);
/**
* Checks if receiver is online and set flag
@ -1521,12 +1488,6 @@ public:
*/
int getFramesCaughtByReceiver();
/**
* Gets the number of frames caught by any one receiver (to avoid using threadpool)
* @returns number of frames caught by any one receiver (master receiver if exists)
*/
int getFramesCaughtByAnyReceiver();
/**
* Gets the current frame index of receiver
* @returns current frame index of receiver
@ -1573,13 +1534,6 @@ public:
*/
int setReceiverStreamingTimer(int time_in_ms=500);
/**
* Enable data streaming to client
* @param enable 0 to disable, 1 to enable, -1 to get the value
* @returns data streaming to client enable
*/
int enableDataStreamingToClient(int enable=-1);
/**
* Enable or disable streaming data from receiver to client
* @param enable 0 to disable 1 to enable -1 to only get the value
@ -1796,42 +1750,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)
*/
@ -1860,28 +1778,21 @@ private:
/**
* reads a trim/settings file
* @param fname name of the file to be read
* @param iodelay io delay (detector specific)
* @param tau tau (detector specific)
* @param myMod pointer to the module structure which has to be set. <BR>
* If it is NULL a new module structure will be created
* @param tb 1 to include trimbits, 0 to exclude (used for eiger)
* @returns the pointer to myMod or NULL if reading the file failed
*/
sls_detector_module* readSettingsFile(std::string fname,
int& iodelay, int& tau,
sls_detector_module* myMod=NULL, int tb=1);
sls_detector_module* readSettingsFile(std::string fname, sls_detector_module* myMod=NULL, int tb=1);
/**
* writes a trim/settings file
* @param fname name of the file to be written
* @param mod module structure which has to be written to file
* @param iodelay io delay (detector specific)
* @param tau tau (detector specific)
* @returns OK or FAIL if the file could not be written
*/
int writeSettingsFile(std::string fname,
sls_detector_module mod, int iodelay, int tau);
int writeSettingsFile(std::string fname, sls_detector_module mod);
/** slsDetector Id or position in the detectors list */
@ -1893,6 +1804,12 @@ private:
/** Shared memory structure */
sharedSlsDetector *thisDetector;
/** control socket interface */
ClientInterface *thisDetectorControl;
/** stop socket interface */
ClientInterface *thisDetectorStop;
/** receiver interface */
ClientInterface *thisReceiver;
@ -1914,17 +1831,8 @@ private:
/** pointer to adc valuse in shared memory */
int *adcs;
/** pointer to chip registers in shared memory */
int *chipregs;
/** pointer to channal registers in shared memory */
int *chanregs;
/** pointer to gain values in shared memory */
int *gain;
/** pointer to offset values in shared memory */
int *offset;
};
#endif

View File

@ -143,6 +143,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest;
++i;
/*! \page test
- <b>firmwaretest</b> performs the firmware test. Cannot set! Jungfrau only. Only get!
*/
descrToFuncMap[i].m_pFuncName="firmwaretest"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest;
++i;
/*! \page test
- <b>reg [addr] [val]</b> ??? writes to an register \c addr with \c value in hexadecimal format.
*/
@ -917,14 +924,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
++i;
/*! \page settings
- <b>pedestal [i]</b> starts acquisition for i frames, calculates pedestal and writes back to fpga. Used in GOTTHARD only. Only put! \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName="pedestal"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
++i;
/* pots */
/*! \page settings
@ -2155,7 +2154,7 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action, int detPo
#ifdef VERBOSE
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
#endif
int b;
//int b;
if (action==PUT_ACTION) {
return string("cannot set");
} else if (action==HELP_ACTION) {
@ -2718,16 +2717,16 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action, int d
if (action==HELP_ACTION) {
return helpRateCorr(action);
}
int fval;
int64_t ival;
char answer[1000];
myDet->setOnline(ONLINE_FLAG, detPos);
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&fval);
myDet->setRateCorrection(fval, detPos);
sscanf(args[1], "%ld",&ival);
myDet->setRateCorrection(ival, detPos);
}
sprintf(answer,"%d",myDet->getRateCorrection(detPos));
sprintf(answer,"%ld",myDet->getRateCorrection(detPos));
return string(answer);
}
@ -3542,15 +3541,6 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action, int d
}
sprintf(ans,"%d",myDet->setAllTrimbits(-1, detPos));
return ans;
} else if (cmd=="pedestal") {
if (action==GET_ACTION)
return string("cannot get");
if (sscanf(args[1],"%d",&val)){
sprintf(ans,"%d",myDet->calibratePedestal(val, detPos));
return string(ans);
}else
return string("cannot parse frame number")+cmd;
}
return string("unknown settings command ")+cmd;
@ -3567,8 +3557,6 @@ string slsDetectorCommand::helpSettings(int action) {
os << "thresholdnotb eV [sett]\n sets the detector threshold in eV without loading trimbits. If sett is provided for eiger, uses settings sett"<< std::endl;
os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl;
os << "trimval i \n sets all the trimbits to i" << std::endl;
os << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "settings \n gets the settings of the detector"<< std::endl;
@ -3706,7 +3694,14 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action, int d
if (cmd=="bustest"){
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
sprintf(answer,"0x%x",myDet->digitalTest(DETECTOR_BUS_TEST));
sprintf(answer,"%d",myDet->digitalTest(DETECTOR_BUS_TEST));
return string(answer);
}
else if (cmd=="firmwaretest"){
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
sprintf(answer,"%d",myDet->digitalTest(DETECTOR_FIRMWARE_TEST));
return string(answer);
}
@ -3716,7 +3711,7 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action, int d
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if((ival==0)||(ival==1)){
sprintf(answer,"0x%x",myDet->digitalTest(DIGITAL_BIT_TEST,ival, detPos));
sprintf(answer,"%d",myDet->digitalTest(DIGITAL_BIT_TEST,ival, detPos));
return string(answer);
}
else
@ -3737,6 +3732,7 @@ string slsDetectorCommand::helpDigiTest(int action) {
if (action==GET_ACTION || action==HELP_ACTION) {
os << "digibittest:i \t performs digital test of the module i. Returns 0 if succeeded, otherwise error mask.Gotthard only."<< std::endl;
os << "bustest \t performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes. Jungfrau only."<< std::endl;
os << "firmwaretest \t performs the firmware test. Jungfrau only." << std::endl;
}
return os.str();
}
@ -4912,7 +4908,8 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action,
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
if (action==PUT_ACTION)
return string("cannot put");
return string(""+myDet->printReceiverConfiguration(detPos));
myDet->printReceiverConfiguration(detPos);
return string("");
}else if (cmd=="parameters") {
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
if (action==PUT_ACTION) {

View File

@ -123,12 +123,14 @@ class BinaryFileStatic {
{
if(!owenable){
if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){
cprintf(RED,"Error in creating binary master file (without overwrite enable) %s\n",fname.c_str());
FILE_LOG(logERROR) << "Could not create binary master file "
"(without overwrite enable) " << fname;
fd = 0;
return 1;
}
}else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){
cprintf(RED,"Error in creating binary master file (with overwrite enable) %s\n",fname.c_str());
FILE_LOG(logERROR) << "Could not create binary master file "
"(with overwrite enable) " << fname;
fd = 0;
return 1;
}
@ -179,8 +181,8 @@ class BinaryFileStatic {
(long long int)acquisitionPeriod,
ctime(&t));
if (strlen(message) > MAX_MASTER_FILE_LENGTH) {
cprintf(RED,"Master File Size %d is greater than max str size %d\n",
(int)strlen(message), MAX_MASTER_FILE_LENGTH);
FILE_LOG(logERROR) << "Master File Size " << strlen(message) <<
" is greater than max str size " << MAX_MASTER_FILE_LENGTH;
return 1;
}

View File

@ -53,7 +53,7 @@ class File : private virtual slsDetectorDefs {
/**
* Print all member values
*/
virtual void PrintMembers();
virtual void PrintMembers(TLogLevel level = logDEBUG1);
/**
* Get Type
@ -85,8 +85,8 @@ class File : private virtual slsDetectorDefs {
* @returns OK or FAIL
*/
virtual int CreateFile(uint64_t fnum){
cprintf(RED,"This is a generic function CreateFile that should be "
"overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function CreateFile that should be "
"overloaded by a derived class";
return OK;
}
@ -94,16 +94,16 @@ class File : private virtual slsDetectorDefs {
* Close Current File
*/
virtual void CloseCurrentFile() {
cprintf(RED,"This is a generic function CloseCurrentFile that should be "
"overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function CloseCurrentFile that should be "
"overloaded by a derived class";
}
/**
* Close Files
*/
virtual void CloseAllFiles() {
cprintf(RED,"This is a generic function that should be overloaded "
"by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded "
"by a derived class";
}
/**
@ -114,8 +114,8 @@ class File : private virtual slsDetectorDefs {
* @param OK or FAIL
*/
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
cprintf(RED,"This is a generic function WriteToFile that "
"should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function WriteToFile that "
"should be overloaded by a derived class";
return FAIL;
}
@ -134,8 +134,8 @@ class File : private virtual slsDetectorDefs {
virtual int CreateMasterFile(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t st,
uint64_t sp, uint64_t ap) {
cprintf(RED,"This is a generic function CreateMasterFile that "
"should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function CreateMasterFile that "
"should be overloaded by a derived class";
return OK;
}
@ -146,8 +146,8 @@ class File : private virtual slsDetectorDefs {
* @param ny number of pixels in y direction
*/
virtual void SetNumberofPixels(uint32_t nx, uint32_t ny) {
cprintf(RED,"This is a generic function SetNumberofPixels that "
"should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function SetNumberofPixels that "
"should be overloaded by a derived class";
}
/**
@ -156,8 +156,8 @@ class File : private virtual slsDetectorDefs {
* @param numf number of images caught
*/
virtual void EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
cprintf(RED,"This is a generic function EndofAcquisition that "
"should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function EndofAcquisition that "
"should be overloaded by a derived class";
}
protected:

View File

@ -161,7 +161,7 @@ public:
* @param i ROI
*/
virtual void SetROI(std::vector<slsDetectorDefs::ROI> i) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
};
/**
@ -171,7 +171,7 @@ public:
* @returns adc configured
*/
virtual const int GetAdcConfigured(int index, std::vector<slsDetectorDefs::ROI>* i) const{
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
return 0;
};
@ -181,7 +181,7 @@ public:
* @param tgEnable true if 10GbE is enabled, else false
*/
virtual void SetDynamicRange(int dr, bool tgEnable) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
};
/**
@ -190,7 +190,7 @@ public:
* @param dr dynamic range
*/
virtual void SetTenGigaEnable(bool tgEnable, int dr) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
};
/**
@ -199,7 +199,7 @@ public:
* @param nroich number of channels in roi
*/
virtual void setNumberofSamples(const uint64_t ns, uint32_t nroich) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
};
/**
@ -207,38 +207,38 @@ public:
* @param enable true if gap pixels enable, else false
*/
virtual void SetGapPixelsEnable(bool b, int dr) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
FILE_LOG(logERROR) << "This is a generic function that should be overloaded by a derived class";
};
/**
* Print all variables
*/
virtual void Print() const {
FILE_LOG(logDEBUG) << "\n\nDetector Data Variables:";
FILE_LOG(logDEBUG) << "myDetectorType: " << slsDetectorDefs::getDetectorType(myDetectorType);
FILE_LOG(logDEBUG) << "Pixels X: " << nPixelsX;
FILE_LOG(logDEBUG) << "Pixels Y: " << nPixelsY;
FILE_LOG(logDEBUG) << "Empty Header: " << emptyHeader;
FILE_LOG(logDEBUG) << "Header Size in Packet: " << headerSizeinPacket;
FILE_LOG(logDEBUG) << "Data Size: " << dataSize;
FILE_LOG(logDEBUG) << "Packet Size: " << packetSize;
FILE_LOG(logDEBUG) << "Packets per Frame: " << packetsPerFrame;
FILE_LOG(logDEBUG) << "Image Size: " << imageSize;
FILE_LOG(logDEBUG) << "Frame Index Mask: " << frameIndexMask;
FILE_LOG(logDEBUG) << "Frame Index Offset: " << frameIndexOffset;
FILE_LOG(logDEBUG) << "Packet Index Mask: " << packetIndexMask;
FILE_LOG(logDEBUG) << "Packet Index Offset: " << packetIndexOffset;
FILE_LOG(logDEBUG) << "Max Frames Per File: " << maxFramesPerFile;
FILE_LOG(logDEBUG) << "Fifo Buffer Header Size: " << fifoBufferHeaderSize;
FILE_LOG(logDEBUG) << "Default Fifo Depth: " << defaultFifoDepth;
FILE_LOG(logDEBUG) << "Threads Per Receiver: " << threadsPerReceiver;
FILE_LOG(logDEBUG) << "Header Packet Size: " << headerPacketSize;
FILE_LOG(logDEBUG) << "Complete Pixels X: " << nPixelsXComplete;
FILE_LOG(logDEBUG) << "Complete Pixels Y: " << nPixelsYComplete;
FILE_LOG(logDEBUG) << "Complete Image Size: " << imageSizeComplete;
FILE_LOG(logDEBUG) << "Standard Header: " << standardheader;
FILE_LOG(logDEBUG) << "UDP Socket Buffer Size: " << defaultUdpSocketBufferSize;
virtual void Print(TLogLevel level = logDEBUG1) const {
FILE_LOG(level) << "\n\nDetector Data Variables:";
FILE_LOG(level) << "myDetectorType: " << slsDetectorDefs::getDetectorType(myDetectorType);
FILE_LOG(level) << "Pixels X: " << nPixelsX;
FILE_LOG(level) << "Pixels Y: " << nPixelsY;
FILE_LOG(level) << "Empty Header: " << emptyHeader;
FILE_LOG(level) << "Header Size in Packet: " << headerSizeinPacket;
FILE_LOG(level) << "Data Size: " << dataSize;
FILE_LOG(level) << "Packet Size: " << packetSize;
FILE_LOG(level) << "Packets per Frame: " << packetsPerFrame;
FILE_LOG(level) << "Image Size: " << imageSize;
FILE_LOG(level) << "Frame Index Mask: " << frameIndexMask;
FILE_LOG(level) << "Frame Index Offset: " << frameIndexOffset;
FILE_LOG(level) << "Packet Index Mask: " << packetIndexMask;
FILE_LOG(level) << "Packet Index Offset: " << packetIndexOffset;
FILE_LOG(level) << "Max Frames Per File: " << maxFramesPerFile;
FILE_LOG(level) << "Fifo Buffer Header Size: " << fifoBufferHeaderSize;
FILE_LOG(level) << "Default Fifo Depth: " << defaultFifoDepth;
FILE_LOG(level) << "Threads Per Receiver: " << threadsPerReceiver;
FILE_LOG(level) << "Header Packet Size: " << headerPacketSize;
FILE_LOG(level) << "Complete Pixels X: " << nPixelsXComplete;
FILE_LOG(level) << "Complete Pixels Y: " << nPixelsYComplete;
FILE_LOG(level) << "Complete Image Size: " << imageSizeComplete;
FILE_LOG(level) << "Standard Header: " << standardheader;
FILE_LOG(level) << "UDP Socket Buffer Size: " << defaultUdpSocketBufferSize;
};
};
@ -396,92 +396,7 @@ 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 {
public:
/** Bytes Per Adc */
const static uint32_t bytesPerAdc = (40*2);
/** Constructor */
Moench02Data(){
myDetectorType = slsDetectorDefs::MOENCH;
nPixelsX = 160;
nPixelsY = 160;
headerSizeinPacket = 4;
dataSize = 1280;
packetSize = 1286;
packetsPerFrame = 40;
imageSize = dataSize*packetsPerFrame;
frameIndexMask = 0xFFFFFF00;
frameIndexOffset = 8;
packetIndexMask = 0xFF;
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 2500;
};
/**
* Print all variables
*/
void Print() const {
GeneralData::Print();
FILE_LOG(logINFO) << "Bytes Per Adc: " << bytesPerAdc;
}
};
class Moench03Data : public GeneralData {
public:
/** Constructor */
Moench03Data(){
myDetectorType = slsDetectorDefs::MOENCH;
nPixelsX = 400;
nPixelsY = 400;
headerSizeinPacket = 22;
dataSize = 8192;
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = 40;
imageSize = dataSize*packetsPerFrame;
frameIndexMask = 0xFFFFFFFF;
frameIndexOffset = (6+8);
packetIndexMask = 0xFFFFFFFF;
maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 2500;
};
};
class JCTBData : public GeneralData {

View File

@ -55,7 +55,7 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
/**
* Print all member values
*/
void PrintMembers();
void PrintMembers(TLogLevel level = logDEBUG1);
/**
* Set Number of pixels

View File

@ -112,7 +112,7 @@ public:
fd = 0;
}
} catch(Exception error) {
cprintf(RED,"Error in closing HDF5 handles of index %d\n", ind);
FILE_LOG(logERROR) << "Could not close HDF5 handles of index " << ind;
error.printErrorStack();
}
}
@ -130,7 +130,7 @@ public:
fd = 0;
}
} catch(Exception error) {
cprintf(RED,"Error in closing master HDF5 handles\n");
FILE_LOG(logERROR) << "Could not close master HDF5 handles";
error.printErrorStack();
}
}
@ -144,7 +144,7 @@ public:
{
if(fd) {
if (H5Fclose(fd) < 0 )
cprintf(RED,"Error in closing virtual HDF5 handles\n");
FILE_LOG(logERROR) << "Could not close virtual HDF5 handles";
fd = 0;
}
}
@ -177,7 +177,7 @@ public:
memspace.close();
}
catch(Exception error){
cprintf(RED,"Error in writing to file in object %d\n",ind);
FILE_LOG(logERROR) << "Could not write to file in object " << ind;
error.printErrorStack();
return 1;
}
@ -239,7 +239,7 @@ public:
}i=14;
}
catch(Exception error){
cprintf(RED,"Error in writing parameters (index:%d) to file in object %d\n", i, ind);
FILE_LOG(logERROR) << "Could not write parameters (index:" << i << ") to file in object " << ind;
error.printErrorStack();
return 1;
}
@ -282,7 +282,7 @@ public:
}
catch(Exception error){
cprintf(RED,"Error in extending dataset in object %d\n",ind);
FILE_LOG(logERROR) << "Could not extend dataset in object " << ind;
error.printError();
return 1;
}
@ -417,7 +417,7 @@ public:
fd->close();
} catch(Exception error) {
cprintf(RED,"Error in creating master HDF5 handles\n");
FILE_LOG(logERROR) << "Could not create master HDF5 handles";
error.printErrorStack();
if (fd) fd->close();
return 1;
@ -521,7 +521,7 @@ public:
}
}
catch(Exception error){
cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind);
FILE_LOG(logERROR) << "Could not create HDF5 handles in object " << ind;
error.printErrorStack();
if (fd) fd->close();
return 1;
@ -571,36 +571,36 @@ public:
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
if (dfal < 0)
return CloseFileOnError(fd,
std::string("Error in creating file access property for virtual file ")
std::string("Could not create file access property for virtual file ")
+ virtualFileName + std::string("\n"));
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
return CloseFileOnError(fd,
std::string("Error in setting strong file close degree for virtual file ")
std::string("Could not set strong file close degree for virtual file ")
+ virtualFileName + std::string("\n"));
fd = H5Fcreate( virtualFileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, dfal);
if (fd < 0)
return CloseFileOnError(fd,
std::string("Error in creating virtual file ") + virtualFileName + std::string("\n"));
std::string("Could not create virtual file ") + virtualFileName + std::string("\n"));
//attributes - version
hid_t dataspace_attr = H5Screate (H5S_SCALAR);
if (dataspace_attr < 0)
return CloseFileOnError(fd,
std::string("Error in creating dataspace for attribute in virtual file ")
std::string("Could not create dataspace for attribute in virtual file ")
+ virtualFileName + std::string("\n"));
hid_t attrid = H5Acreate2 (fd, "version", H5T_NATIVE_DOUBLE, dataspace_attr, H5P_DEFAULT, H5P_DEFAULT);
if (attrid < 0)
return CloseFileOnError(fd,
std::string("Error in creating attribute in virtual file ")
std::string("Could not create attribute in virtual file ")
+ virtualFileName + std::string("\n"));
double attr_data = version;
if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) < 0)
return CloseFileOnError(fd,
std::string("Error in writing attribute in virtual file ")
std::string("Could not write attribute in virtual file ")
+ virtualFileName + std::string("\n"));
if (H5Aclose (attrid) < 0)
return CloseFileOnError(fd,
std::string("Error in closing attribute in virtual file ")
std::string("Could not close attribute in virtual file ")
+ virtualFileName + std::string("\n"));
@ -609,13 +609,13 @@ public:
hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL);
if (vdsDataspace < 0)
return CloseFileOnError(fd,
std::string("Error in creating virtual dataspace in virtual file ")
std::string("Could not create virtual dataspace in virtual file ")
+ virtualFileName + std::string("\n"));
hsize_t vdsdims_para[2] = {numf, (unsigned int) numDety * numDetz};
hid_t vdsDataspace_para = H5Screate_simple(2, vdsdims_para, NULL);
if (vdsDataspace_para < 0)
return CloseFileOnError(fd,
std::string("Error in creating virtual dataspace (parameters) in virtual file ")
std::string("Could not create virtual dataspace (parameters) in virtual file ")
+ virtualFileName + std::string("\n"));
@ -623,23 +623,23 @@ public:
hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE);
if (dcpl < 0)
return CloseFileOnError(fd,
std::string("Error in creating file creation properties in virtual file ")
std::string("Could not create file creation properties in virtual file ")
+ virtualFileName + std::string("\n"));
int fill_value = -1;
if (H5Pset_fill_value (dcpl, GetDataTypeinC(dataType), &fill_value) < 0)
return CloseFileOnError(fd,
std::string("Error in creating fill value in virtual file ")
std::string("Could not create fill value in virtual file ")
+ virtualFileName + std::string("\n"));
hid_t dcpl_para[parameterNames.size()];
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
dcpl_para[i] = H5Pcreate (H5P_DATASET_CREATE);
if (dcpl_para[i] < 0)
return CloseFileOnError(fd,
std::string("Error in creating file creation properties (parameters) in virtual file ")
std::string("Could not create file creation properties (parameters) in virtual file ")
+ virtualFileName + std::string("\n"));
if (H5Pset_fill_value (dcpl_para[i], GetDataTypeinC(parameterDataTypes[i]), &fill_value) < 0)
return CloseFileOnError(fd,
std::string("Error in creating fill value (parameters) in virtual file ")
std::string("Could not create fill value (parameters) in virtual file ")
+ virtualFileName + std::string("\n"));
}
@ -661,13 +661,13 @@ public:
//setect hyperslabs
if (H5Sselect_hyperslab (vdsDataspace, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) {
cprintf(RED,"could not select hyperslab\n");
FILE_LOG(logERROR) << "Could not select hyperslab";
error = true;
break;
}
if (H5Sselect_hyperslab (vdsDataspace_para, H5S_SELECT_SET,
offset_para, NULL, count_para, NULL) < 0) {
cprintf(RED,"could not select hyperslab for parameters\n");
FILE_LOG(logERROR) << "Could not select hyperslab for parameters";
error = true;
break;
}
@ -696,20 +696,20 @@ public:
hid_t srcDataspace = H5Screate_simple(3, srcdims, srcdimsmax);
if (srcDataspace < 0)
return CloseFileOnError(fd,
std::string("Error in creating source dataspace in virtual file ")
std::string("Could not create source dataspace in virtual file ")
+ virtualFileName + std::string("\n"));
hsize_t srcdims_para[1] = {nDimx};
hsize_t srcdimsmax_para[1] = {H5S_UNLIMITED};
hid_t srcDataspace_para = H5Screate_simple(1, srcdims_para, srcdimsmax_para);
if (srcDataspace_para < 0)
return CloseFileOnError(fd,
std::string("Error in creating source dataspace (parameters) in virtual file ")
std::string("Could not create source dataspace (parameters) in virtual file ")
+ virtualFileName + std::string("\n"));
//mapping
if (H5Pset_virtual(dcpl, vdsDataspace, relative_srcFileName.c_str(),
srcDatasetName.c_str(), srcDataspace) < 0) {
cprintf(RED,"could not set mapping for paramter 1\n");
FILE_LOG(logERROR) << "Could not set mapping for paramter 1";
error = true;
break;
}
@ -717,7 +717,7 @@ public:
for (unsigned int k = 0; k < parameterNames.size(); ++k) {
if (H5Pset_virtual(dcpl_para[k], vdsDataspace_para, relative_srcFileName.c_str(),
parameterNames[k], srcDataspace_para) < 0) {
cprintf(RED,"could not set mapping for paramter %d\n", k);
FILE_LOG(logERROR) << "Could not set mapping for paramter " << k;
error = true;
break;
}
@ -736,7 +736,7 @@ public:
}
if (error)
return CloseFileOnError(fd,
std::string("Error in mapping files in virtual file ")
std::string("Could not map files in virtual file ")
+ virtualFileName + std::string("\n"));
//dataset
@ -745,7 +745,7 @@ public:
GetDataTypeinC(dataType), vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
if (vdsdataset < 0)
return CloseFileOnError(fd,
std::string("Error in creating virutal dataset in virtual file ")
std::string("Could not create virutal dataset in virtual file ")
+ virtualFileName + std::string("\n"));
@ -757,7 +757,7 @@ public:
H5P_DEFAULT, dcpl_para[i], H5P_DEFAULT);
if (vdsdataset_para < 0)
return CloseFileOnError(fd,
std::string("Error in creating virutal dataset (parameters) in virtual file ")
std::string("Could not create virutal dataset (parameters) in virtual file ")
+ virtualFileName + std::string("\n"));
}
@ -798,7 +798,7 @@ public:
data_out = (T*)malloc(sizeof(T)*(nDimx*nDimy*nDimz));
break;
default:
cprintf(RED,"invalid rank. Options: 2 or 3\n");
FILE_LOG(logERROR) << "Invalid rank. Options: 2 or 3";
return 0;
}
if (datatype == PredType::STD_U16LE) {
@ -810,7 +810,7 @@ public:
} else if (datatype == PredType::STD_U8LE) {
FILE_LOG(logINFO) << "datatype:8";
} else {
FILE_LOG(logERROR) << "unknown datatype";
FILE_LOG(logERROR) << "Unknown datatype: " << datetype;
return 1;
}
FILE_LOG(logINFO) << "owenable:" << (owenable?1:0) << std::endl
@ -861,7 +861,7 @@ public:
newfd->close();
oldfd->close();
} catch(Exception error){
cprintf(RED,"Error in copying virtual files\n");
FILE_LOG(logERROR) << "Could not copy virtual files";
error.printErrorStack();
free(data_out);
oldfd->close();
@ -890,20 +890,20 @@ public:
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
if (dfal < 0)
return CloseFileOnError( vfd, std::string("Error in creating file access property for link\n"));
return CloseFileOnError( vfd, std::string("Could not create file access property for link\n"));
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
return CloseFileOnError( vfd, std::string("Error in setting strong file close degree for link\n"));
return CloseFileOnError( vfd, std::string("Could not set strong file close degree for link\n"));
//open master file
hid_t mfd = H5Fopen( masterFileName.c_str(), H5F_ACC_RDWR, dfal);
if (mfd < 0)
return CloseFileOnError( vfd, std::string("Error in opening master file\n"));
return CloseFileOnError( vfd, std::string("Could not open master file\n"));
//open virtual file
vfd = H5Fopen( virtualfname.c_str(), H5F_ACC_RDWR, dfal);
if (vfd < 0) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, std::string("Error in opening virtual file\n"));
return CloseFileOnError( vfd, std::string("Could not open virtual file\n"));
}
// find relative path
@ -918,13 +918,13 @@ public:
hid_t vdset = H5Dopen2( vfd, virtualDatasetname.c_str(), H5P_DEFAULT);
if (vdset < 0) {
H5Fclose(mfd);
return CloseFileOnError( vfd, std::string("Error in opening virtual data dataset\n"));
return CloseFileOnError( vfd, std::string("Could not open virtual data dataset\n"));
}
sprintf(linkname, "/entry/data/%s",virtualDatasetname.c_str());
if(H5Lcreate_external( relative_virtualfname.c_str(), virtualDatasetname.c_str(),
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, std::string("Error in creating link to data dataset\n"));
return CloseFileOnError( vfd, std::string("Could not create link to data dataset\n"));
}
H5Dclose(vdset);
@ -933,14 +933,14 @@ public:
hid_t vdset_para = H5Dopen2( vfd, (std::string (parameterNames[i])).c_str(), H5P_DEFAULT);
if (vdset_para < 0) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, std::string("Error in opening virtual parameter dataset to create link\n"));
return CloseFileOnError( vfd, std::string("Could not open virtual parameter dataset to create link\n"));
}
sprintf(linkname, "/entry/data/%s",(std::string (parameterNames[i])).c_str());
if(H5Lcreate_external( relative_virtualfname.c_str(), (std::string (parameterNames[i])).c_str(),
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, std::string("Error in creating link to virtual parameter dataset\n"));
return CloseFileOnError( vfd, std::string("Could not create link to virtual parameter dataset\n"));
}
}
@ -956,7 +956,7 @@ public:
* @returns 1 for fail
*/
static int CloseFileOnError(hid_t& fd, const std::string msg) {
cprintf(RED, "%s", msg.c_str());
FILE_LOG(logERROR) << msg;
if(fd > 0)
H5Fclose(fd);
fd = 0;

View File

@ -56,9 +56,9 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
/*
* Get detector hostname
* @return NULL or hostname or NULL if uninitialized (max of 1000 characters)
* @return hostname (max of 1000 characters)
*/
char *getDetectorHostname() const;
std::string getDetectorHostname() const;
/*
* Get flipped data across 'axis'
@ -81,15 +81,15 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
fileFormat getFileFormat() const;
/**
* Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
* @return NULL or file name prefix (max of 1000 characters)
* @return file name prefix
*/
char *getFileName() const;
std::string getFileName() const;
/**
* Get File Path
* @return NULL or file path (max of 1000 characters)
* @return file path
*/
char *getFilePath() const;
std::string getFilePath() const;
/**
* Get File Index
@ -163,9 +163,9 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
/**
* Get Ehernet Interface
* @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters)
* @ethernet interface. eg. eth0 or "" if listening to all
*/
char *getEthernetInterface() const;
std::string getEthernetInterface() const;
//***acquisition parameters***
@ -289,13 +289,13 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
* Get streaming source ip
* @return streaming source ip
*/
char *getStreamingSourceIP() const;
std::string getStreamingSourceIP() const;
/**
* Get additional json header
* @return additional json header
*/
char *getAdditionalJsonHeader() const;
std::string getAdditionalJsonHeader() const;
/** (not saved in client shared memory)
* Get UDP Socket Buffer Size

View File

@ -115,6 +115,13 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs {
/** function not implemented for specific detector */
void functionNotImplemented();
/** mode not implemented for specific detector */
void modeNotImplemented(std::string modename, int mode);
/** validate and set error */
template <typename T>
void validate(T arg, T retval, std::string modename, bool hex);
/** Unrecognized Function */
int M_nofunc();

View File

@ -106,8 +106,7 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_
// if write error
if (ret != buffersize) {
cprintf(RED,"%d Error: Write to file failed for image number %lld\n",
index, (long long int)fnum);
FILE_LOG(logERROR) << index << " Error: Write to file failed for image number " << fnum;
return FAIL;
}
return OK;

View File

@ -166,18 +166,14 @@ void DataProcessor::RecordFirstIndices(uint64_t fnum) {
firstAcquisitionIndex = fnum;
}
#ifdef VERBOSE
cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n",
index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex);
#endif
FILE_LOG(logDEBUG1) << index << " First Acquisition Index:" << firstAcquisitionIndex <<
"\tFirst Measurement Index:" << firstMeasurementIndex;
}
void DataProcessor::SetGeneralData(GeneralData* g) {
generalData = g;
#ifdef VERY_VERBOSE
generalData->Print();
#endif
if (file) {
if (file->GetFileType() == HDF5) {
file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY);
@ -278,16 +274,12 @@ void DataProcessor::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
void DataProcessor::ThreadExecution() {
char* buffer=0;
fifo->PopAddress(buffer);
#ifdef FIFODEBUG
if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n",
index,(void*)(buffer),buffer);
#endif
FILE_LOG(logDEBUG5) << "DataProcessor " << index << ", "
"pop 0x" << std::hex << (void*)(buffer) << std::dec << ":" << buffer;
//check dummy
uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer));
#ifdef VERBOSE
if (!index) cprintf(BLUE,"DataProcessor %d, Numbytes:%u\n", index,numBytes);
#endif
FILE_LOG(logDEBUG1) << "DataProcessor " << index << ", Numbytes:" << numBytes;
if (numBytes == DUMMY_PACKET_VALUE) {
StopProcessing(buffer);
return;
@ -304,10 +296,8 @@ void DataProcessor::ThreadExecution() {
void DataProcessor::StopProcessing(char* buf) {
#ifdef VERBOSE
if (!index)
cprintf(RED,"DataProcessing %d: Dummy\n", index);
#endif
FILE_LOG(logDEBUG1) << "DataProcessing " << index << ": Dummy";
//stream or free
if (*dataStreamEnable)
fifo->PushAddressToStream(buf);
@ -317,9 +307,7 @@ void DataProcessor::StopProcessing(char* buf) {
if (file)
file->CloseCurrentFile();
StopRunning();
#ifdef VERBOSE
FILE_LOG(logINFO) << index << ": Processing Completed";
#endif
FILE_LOG(logDEBUG1) << index << ": Processing Completed";
}
@ -335,16 +323,9 @@ void DataProcessor::ProcessAnImage(char* buf) {
numTotalFramesCaught++;
}
#ifdef VERBOSE
if (!index)
cprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum);
#endif
FILE_LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum;
if (!measurementStartedFlag) {
#ifdef VERBOSE
if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum);
#endif
RecordFirstIndices(fnum);
if (*dataStreamEnable) {
@ -418,11 +399,10 @@ bool DataProcessor::SendToStreamer() {
bool DataProcessor::CheckTimer() {
struct timespec end;
clock_gettime(CLOCK_REALTIME, &end);
#ifdef VERBOSE
cprintf(BLUE,"%d Timer elapsed time:%f seconds\n", index,
( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec )
/ 1000000000.0);
#endif
FILE_LOG(logDEBUG1) << index << " Timer elapsed time:" <<
(( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0)
<< " seconds";
//still less than streaming timer, keep waiting
if((( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec )
/ 1000000000.0) < ((double)*streamingTimerInMs/1000.00))
@ -464,9 +444,8 @@ void DataProcessor::PadMissingPackets(char* buf) {
uint32_t dsize = generalData->dataSize;
uint32_t fifohsize = generalData->fifoBufferHeaderSize;
uint32_t corrected_dsize = dsize - ((pperFrame * dsize) - generalData->imageSize);
#ifdef VERBOSE
cprintf(RED,"bitmask:%s\n", pmask.to_string().c_str());
#endif
FILE_LOG(logDEBUG1) << "bitmask: " << pmask.to_string();
for (unsigned int pnum = 0; pnum < pperFrame; ++pnum) {
// not missing packet

View File

@ -108,18 +108,14 @@ void DataStreamer::RecordFirstIndices(uint64_t fnum) {
firstAcquisitionIndex = fnum;
}
#ifdef VERBOSE
cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n",
index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex);
#endif
FILE_LOG(logDEBUG1) << index << " First Acquisition Index: " << firstAcquisitionIndex <<
"\tFirst Measurement Index: " << firstMeasurementIndex;
}
void DataStreamer::SetGeneralData(GeneralData* g) {
generalData = g;
#ifdef VERY_VERBOSE
generalData->Print();
#endif
}
int DataStreamer::SetThreadPriority(int priority) {
@ -138,7 +134,7 @@ void DataStreamer::CreateZmqSockets(int* nunits, uint32_t port, const char* srci
try {
zmqSocket = new ZmqSocket(portnum, (strlen(srcip)?srcip:NULL));
} catch (...) {
cprintf(RED, "Error: Could not create Zmq socket on port %d for Streamer %d\n", portnum, index);
FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum << " for Streamer " << index;
throw;
}
FILE_LOG(logINFO) << index << " Streamer: Zmq Server started at " << zmqSocket->GetZmqServerAddress();
@ -156,15 +152,13 @@ void DataStreamer::CloseZmqSocket() {
void DataStreamer::ThreadExecution() {
char* buffer=0;
fifo->PopAddressToStream(buffer);
#ifdef FIFODEBUG
if (!index) cprintf(BLUE,"DataStreamer %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
FILE_LOG(logDEBUG5) << "DataStreamer " << index << ", "
"pop 0x" << std::hex << (void*)(buffer) << std::dec << ":" << buffer;
//check dummy
uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer));
#ifdef VERBOSE
cprintf(GREEN,"DataStreamer %d, Numbytes:%u\n", index,numBytes);
#endif
FILE_LOG(logDEBUG1) << "DataStreamer " << index << ", Numbytes:" << numBytes;
if (numBytes == DUMMY_PACKET_VALUE) {
StopProcessing(buffer);
return;
@ -180,20 +174,17 @@ void DataStreamer::ThreadExecution() {
void DataStreamer::StopProcessing(char* buf) {
#ifdef VERBOSE
if (!index)
cprintf(RED,"DataStreamer %d: Dummy\n", index);
#endif
FILE_LOG(logDEBUG1) << "DataStreamer " << index << ": Dummy";
sls_receiver_header* header = (sls_receiver_header*) (buf);
//send dummy header and data
if (!SendHeader(header, 0, 0, 0, true))
cprintf(RED,"Error: Could not send zmq dummy header for streamer %d\n", index);
if (!SendHeader(header, 0, 0, 0, true)) {
FILE_LOG(logERROR) << "Could not send zmq dummy header for streamer " << index;
}
fifo->FreeAddress(buf);
StopRunning();
#ifdef VERBOSE
FILE_LOG(logINFO) << index << ": Streaming Completed";
#endif
FILE_LOG(logDEBUG1) << index << ": Streaming Completed";
}
/** buf includes only the standard header */
@ -201,14 +192,9 @@ void DataStreamer::ProcessAnImage(char* buf) {
sls_receiver_header* header = (sls_receiver_header*) (buf + FIFO_HEADER_NUMBYTES);
uint64_t fnum = header->detHeader.frameNumber;
#ifdef VERBOSE
cprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index,fnum);
#endif
FILE_LOG(logDEBUG1) << "DataStreamer " << index << ": fnum:" << fnum;
if (!measurementStartedFlag) {
#ifdef VERBOSE
if (!index) cprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index, fnum);
#endif
RecordFirstIndices(fnum);
}
@ -220,17 +206,16 @@ void DataStreamer::ProcessAnImage(char* buf) {
//write imagesize
if (!SendHeader(header, generalData->imageSizeComplete,
generalData->nPixelsXComplete, generalData->nPixelsYComplete, false))
cprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n",
(long long int) fnum, index);
generalData->nPixelsXComplete, generalData->nPixelsYComplete, false)) {
FILE_LOG(logERROR) << "Could not send zmq header for fnum " << fnum << " and streamer " << index;
}
memcpy(completeBuffer + ((generalData->imageSize) * adcConfigured),
buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header),
(uint32_t)(*((uint32_t*)buf)) );
if (!zmqSocket->SendData(completeBuffer, generalData->imageSizeComplete))
cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n",
(long long int) fnum, index);
if (!zmqSocket->SendData(completeBuffer, generalData->imageSizeComplete)) {
FILE_LOG(logERROR) << "Could not send zmq data for fnum " << fnum << " and streamer " << index;
}
}
@ -238,14 +223,13 @@ void DataStreamer::ProcessAnImage(char* buf) {
else {
if (!SendHeader(header, (uint32_t)(*((uint32_t*)buf)),
generalData->nPixelsX, generalData->nPixelsY, false)) // new size possibly from callback
cprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n",
(long long int) fnum, index);
generalData->nPixelsX, generalData->nPixelsY, false)) {// new size possibly from callback
FILE_LOG(logERROR) << "Could not send zmq header for fnum " << fnum << " and streamer " << index;
}
if (!zmqSocket->SendData(buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header),
(uint32_t)(*((uint32_t*)buf)) )) // new size possibly from callback
cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n",
(long long int) fnum, index);
(uint32_t)(*((uint32_t*)buf)) )) {// new size possibly from callback
FILE_LOG(logERROR) << "Could not send zmq data for fnum " << fnum << " and streamer " << index;
}
}
}

View File

@ -21,22 +21,21 @@ Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth):
fifoDepth(depth),
status_fifoBound(0),
status_fifoFree(depth){
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(CreateFifos(fifoItemSize) == FAIL)
throw std::exception();
}
Fifo::~Fifo() {
FILE_LOG(logDEBUG) << __AT__ << " called";
//cprintf(BLUE,"Fifo Object %d: Goodbye\n", index);
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
DestroyFifos();
}
int Fifo::CreateFifos(uint32_t fifoItemSize) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
//destroy if not already
DestroyFifos();
@ -69,7 +68,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
void Fifo::DestroyFifos(){
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(memory) {
free(memory);

View File

@ -38,8 +38,8 @@ std::string File::GetCurrentFileName() {
return currentFileName;
}
void File::PrintMembers() {
FILE_LOG(logINFO) << "\nGeneral Writer Variables:" << std::endl
void File::PrintMembers(TLogLevel level) {
FILE_LOG(level) << "\nGeneral Writer Variables:" << std::endl
<< "Index: " << index << std::endl
<< "Max Frames Per File: " << *maxFramesPerFile << std::endl
<< "Number of Detectors in x dir: " << numDetX << std::endl

View File

@ -38,9 +38,7 @@ HDF5File::HDF5File(int ind, uint32_t* maxf,
dataspace_para(0),
extNumImages(0)
{
#ifdef VERBOSE
PrintMembers();
#endif
dataset_para.clear();
parameterNames.clear();
parameterDataTypes.clear();
@ -95,15 +93,15 @@ HDF5File::~HDF5File() {
CloseAllFiles();
}
void HDF5File::PrintMembers() {
void HDF5File::PrintMembers(TLogLevel level) {
File::PrintMembers();
UpdateDataType();
if (datatype == PredType::STD_U8LE) {
FILE_LOG(logINFO) << "Data Type: 4 or 8";
FILE_LOG(level) << "Data Type: 4 or 8";
} else if (datatype == PredType::STD_U16LE) {
FILE_LOG(logINFO) << "Data Type: 16";
FILE_LOG(level) << "Data Type: 16";
} else if (datatype == PredType::STD_U32LE) {
FILE_LOG(logINFO) << "Data Type: 32";
FILE_LOG(level) << "Data Type: 32";
} else {
FILE_LOG(logERROR) << "unknown data type";
}
@ -154,8 +152,6 @@ int HDF5File::CreateFile(uint64_t fnum) {
return FAIL;
}
pthread_mutex_unlock(&Mutex);
if (dataspace == NULL)
cprintf(RED,"Got nothing!\n");
if(!(*silentMode)) {
FILE_LOG(logINFO) << *udpPortNumber << ": HDF5 File created: " << currentFileName;
@ -214,9 +210,8 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
if (HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
dataspace_para, dataset_para, *numImages) == OK) {
if (!(*silentMode)) {
cprintf(BLUE,"%d Extending HDF5 dataset by %llu, Total x Dimension: %llu\n",
index, (long long unsigned int)extNumImages,
(long long unsigned int)(extNumImages + *numImages));
FILE_LOG(logINFO) << index << " Extending HDF5 dataset by " <<
extNumImages << ", Total x Dimension: " << (extNumImages + *numImages);
}
extNumImages += *numImages;
}
@ -238,7 +233,7 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
}
}
pthread_mutex_unlock(&Mutex);
cprintf(RED,"%d Error: Write to file failed\n", index);
FILE_LOG(logERROR) << index << "Write to file failed";
return FAIL;
}

View File

@ -159,19 +159,18 @@ void Listener::RecordFirstIndices(uint64_t fnum) {
}
if(!(*silentMode)) {
if (!index) cprintf(BLUE,"%d First Acquisition Index:%lu\n"
"%d First Measurement Index:%lu\n",
index, firstAcquisitionIndex,
index, firstMeasurementIndex);
if (!index) {
FILE_LOG(logINFOBLUE) << index <<
" First Acquisition Index: " << firstAcquisitionIndex;
FILE_LOG(logDEBUG1) << index << " First Measurement Index: " << firstMeasurementIndex;
}
}
}
void Listener::SetGeneralData(GeneralData*& g) {
generalData = g;
#ifdef VERY_VERBOSE
generalData->Print();
#endif
}
@ -300,9 +299,8 @@ void Listener::ThreadExecution() {
int rc = 0;
fifo->GetNewAddress(buffer);
#ifdef FIFODEBUG
cprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
FILE_LOG(logDEBUG5) << "Listener " << index << ", "
"pop 0x" << std::hex << (void*)(buffer) << std::dec << ":" << buffer;
//udpsocket doesnt exist
if (*activated && !udpSocketAlive && !carryOverFlag) {
@ -320,7 +318,6 @@ void Listener::ThreadExecution() {
//error check, (should not be here) if not transmitting yet (previous if) rc should be > 0
if (rc == 0) {
//cprintf(RED,"%d Socket shut down while waiting for future packet. udpsocketalive:%d\n",index, udpSocketAlive );
if (!udpSocketAlive) {
(*((uint32_t*)buffer)) = 0;
StopListening(buffer);
@ -362,10 +359,8 @@ void Listener::StopListening(char* buf) {
StopRunning();
sem_post(&semaphore_socket);
#ifdef VERBOSE
cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught);
cprintf(GREEN,"%d: Listening Completed\n", index);
#endif
FILE_LOG(logDEBUG1) << index << ": Listening Packets (" << *udpPortNumber << ") : " << numPacketsCaught;
FILE_LOG(logDEBUG1) << index << ": Listening Completed";
}
@ -418,7 +413,7 @@ uint32_t Listener::ListenToAnImage(char* buf) {
//look for carry over
if (carryOverFlag) {
//cprintf(RED,"%d carry flag\n",index);
FILE_LOG(logDEBUG3) << index << "carry flag";
//check if its the current image packet
// -------------------------- new header ----------------------------------------------------------------------
if (standardheader) {
@ -434,7 +429,8 @@ uint32_t Listener::ListenToAnImage(char* buf) {
//------------------------------------------------------------------------------------------------------------
if (fnum != currentFrameIndex) {
if (fnum < currentFrameIndex) {
cprintf(RED,"Error:(Weird), With carry flag: Frame number %lu less than current frame number %lu\n", fnum, currentFrameIndex);
FILE_LOG(logERROR) << "(Weird), With carry flag: Frame number " <<
fnum << " less than current frame number " << currentFrameIndex;
return 0;
}
switch(*frameDiscardMode) {
@ -551,25 +547,22 @@ uint32_t Listener::ListenToAnImage(char* buf) {
// Eiger Firmware in a weird state
if (myDetectorType == EIGER && fnum == 0) {
cprintf(RED,"[%u]: Got Frame Number Zero from Firmware. Discarding Packet\n", *udpPortNumber);
FILE_LOG(logERROR) << "[" << *udpPortNumber << "]: Got Frame Number "
"Zero from Firmware. Discarding Packet";
numPacketsCaught--;
return 0;
}
lastCaughtFrameIndex = fnum;
FILE_LOG(logDEBUG5) << "Listening " << index << ": currentfindex:" << currentFrameIndex <<
", fnum:" << fnum << ", pnum:" << pnum << ", numpackets:" << numpackets;
#ifdef VERBOSE
//if (!index)
cprintf(GREEN,"Listening %d: currentfindex:%lu, fnum:%lu, pnum:%u numpackets:%u\n",
index,currentFrameIndex, fnum, pnum, numpackets);
#endif
if (!measurementStartedFlag)
RecordFirstIndices(fnum);
//future packet by looking at image number (all other detectors)
if (fnum != currentFrameIndex) {
//cprintf(RED,"setting carry over flag to true num:%llu nump:%u\n",fnum, numpackets );
carryOverFlag = true;
memcpy(carryOverPacket,listeningPacket, generalData->packetSize);
@ -641,19 +634,18 @@ uint32_t Listener::ListenToAnImage(char* buf) {
void Listener::PrintFifoStatistics() {
#ifdef VERBOSE
cout << "numFramesStatistic:" << numFramesStatistic << " numPacketsStatistic:" << numPacketsStatistic << endl;
#endif
FILE_LOG(logDEBUG1) << "numFramesStatistic:" << numFramesStatistic << " numPacketsStatistic:" << numPacketsStatistic;
//calculate packet loss
int64_t loss = -1;
loss = (numFramesStatistic*(generalData->packetsPerFrame)) - numPacketsStatistic;
numPacketsStatistic = 0;
numFramesStatistic = 0;
if (loss)
cprintf(RED,"[%u]: Packet_Loss:%lu Used_Fifo_Max_Level:%d \tFree_Slots_Min_Level:%d \tCurrent_Frame#:%lu\n",
*udpPortNumber,loss, fifo->GetMaxLevelForFifoBound() , fifo->GetMinLevelForFifoFree(), currentFrameIndex);
else
cprintf(GREEN,"[%u]: Packet_Loss:%lu Used_Fifo_Max_Level:%d \tFree_Slots_Min_Level:%d \tCurrent_Frame#:%lu\n",
*udpPortNumber,loss, fifo->GetMaxLevelForFifoBound(), fifo->GetMinLevelForFifoFree(), currentFrameIndex);
FILE_LOG(loss ? logINFORED : logINFOGREEN) << "[" << *udpPortNumber << "]: "
"Packet_Loss:" << loss <<
" Used_Fifo_Max_Level:" << fifo->GetMaxLevelForFifoBound() <<
" \tFree_Slots_Min_Level:" << fifo->GetMinLevelForFifoFree() <<
" \tCurrent_Frame#:" << currentFrameIndex;
}

View File

@ -74,7 +74,8 @@ void* ThreadObject::StartThread(void* thisPointer) {
void ThreadObject::RunningThread() {
cprintf(BLUE,"Created [ %s Thread %d, Tid: %ld ]\n", GetType().c_str(),index, (long)syscall(SYS_gettid));
FILE_LOG(logINFOBLUE) << "Created [ " << GetType() << "Thread " << index << ", "
"Tid: " << syscall(SYS_gettid) << "]";
while(true) {
while(IsRunning()) {
@ -88,7 +89,8 @@ void ThreadObject::RunningThread() {
sem_wait(&semaphore);
if(killThread) {
cprintf(BLUE,"Exiting [ %s Thread %d, Tid: %ld ]\n", GetType().c_str(),index, (long)syscall(SYS_gettid));
FILE_LOG(logINFOBLUE) << "Exiting [ " << GetType() <<
" Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
pthread_exit(NULL);
}

View File

@ -24,18 +24,21 @@ void sigInterruptHandler(int p){
keeprunning = false;
}
/** Define Colors to print data call back in different colors for different recievers */
/*
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
printf("#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
filepath, filename, fileindex, datasize);
#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
cprintf(BLUE, "--StartAcq: returning 0\n");
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
FILE_LOG(logINFO) << "#### StartAcq: "
"filepath: " << filepath << "filename: " << filename <<
"fileindex: " << fileindex << "datasize: " << datasize << " ####";
FILE_LOG(logINFO) << "--StartAcq: returning 0";
return 0;
}
void AcquisitionFinished(uint64_t frames, void*p){
cprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",frames);
FILE_LOG(logINFO) << "#### AcquisitionFinished: frames:" << frames << " ####";
}
@ -45,16 +48,16 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){
PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row,
"#### %d GetData: ####\n"
"frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu"
"\t\ttimestamp: %llu\t\tmodId: %u\t\t"
"xCrow%u\t\tcolumn: %u\t\tcolumn: %u\t\tdebug: %u"
"frameNumber: %lu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %lu"
"\t\ttimestamp: %lu\t\tmodId: %u\t\t"
"row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u"
"\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u"
//"\t\tpacketsMask:%s"
"\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
detectorHeader.row, detectorHeader.frameNumber,
detectorHeader.expLength, detectorHeader.packetNumber, detectorHeader.bunchId,
detectorHeader.timestamp, detectorHeader.modId,
detectorHeader.row, detectorHeader.column, detectorHeader.column,
detectorHeader.row, (long unsigned int)detectorHeader.frameNumber,
detectorHeader.expLength, detectorHeader.packetNumber, (long unsigned int)detectorHeader.bunchId,
(long unsigned int)detectorHeader.timestamp, detectorHeader.modId,
detectorHeader.row, detectorHeader.column, detectorHeader.reserved,
detectorHeader.debug, detectorHeader.roundRNumber,
detectorHeader.detType, detectorHeader.version,
//header->packetsMask.to_string().c_str(),
@ -66,7 +69,7 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){
int main(int argc, char *argv[]) {
keeprunning = true;
cprintf(BLUE,"Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
FILE_LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]";
// Catch signal SIGINT to close files and call destructors properly
struct sigaction sa;
@ -74,7 +77,7 @@ int main(int argc, char *argv[]) {
sa.sa_handler=sigInterruptHandler; // handler function
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
if (sigaction(SIGINT, &sa, NULL) == -1) {
cprintf(RED, "Could not set handler function for SIGINT\n");
FILE_LOG(logERROR) << "Could not set handler function for SIGINT";
}
@ -85,7 +88,7 @@ int main(int argc, char *argv[]) {
asa.sa_handler=SIG_IGN; // handler function
sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler
if (sigaction(SIGPIPE, &asa, NULL) == -1) {
cprintf(RED, "Could not set handler function for SIGPIPE\n");
FILE_LOG(logERROR) << "Could not set handler function for SIGPIPE";
}
@ -93,7 +96,7 @@ int main(int argc, char *argv[]) {
slsReceiverUsers *receiver = new slsReceiverUsers(argc, argv, ret);
if(ret==slsDetectorDefs::FAIL){
delete receiver;
cprintf(BLUE,"Exiting [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
exit(EXIT_FAILURE);
}
@ -142,18 +145,18 @@ int main(int argc, char *argv[]) {
//start tcp server thread
if (receiver->start() == slsDetectorDefs::FAIL){
delete receiver;
cprintf(BLUE,"Exiting [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
exit(EXIT_FAILURE);
}
FILE_LOG(logINFO) << "Ready ... ";
cprintf(RESET, "\n[ Press \'Ctrl+c\' to exit ]\n");
FILE_LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]";
while(keeprunning)
pause();
delete receiver;
cprintf(BLUE,"Exiting [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
// FILE_LOG(logINFO) << "Goodbye!";
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
FILE_LOG(logINFO) << "Exiting Receiver";
return 0;
}

View File

@ -24,16 +24,19 @@
/** cosntructor & destructor */
slsReceiverImplementation::slsReceiverImplementation() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
InitializeMembers();
}
slsReceiverImplementation::~slsReceiverImplementation() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
DeleteMembers();
}
void slsReceiverImplementation::DeleteMembers() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if (generalData) {
delete generalData;
generalData=0;
@ -47,7 +50,7 @@ void slsReceiverImplementation::DeleteMembers() {
void slsReceiverImplementation::InitializeMembers() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
//**detector parameters***
myDetectorType = GENERIC;
for (int i = 0; i < MAX_DIMENSIONS; ++i)
@ -101,7 +104,7 @@ void slsReceiverImplementation::InitializeMembers() {
dataStreamEnable = false;
streamingPort = 0;
memset(streamingSrcIP, 0, sizeof(streamingSrcIP));
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
//** class objects ***
generalData = 0;
@ -123,101 +126,77 @@ void slsReceiverImplementation::InitializeMembers() {
/**initial parameters***/
int* slsReceiverImplementation::getMultiDetectorSize() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return (int*) numDet;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return (int*) numDet;
}
int slsReceiverImplementation::getDetectorPositionId() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return detID;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return detID;
}
char *slsReceiverImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(detHostname))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,detHostname);
//freed by calling function
return output;
std::string slsReceiverImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(detHostname);
}
int slsReceiverImplementation::getFlippedData(int axis) const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(axis<0 || axis > 1) return -1;
return flippedData[axis];
}
bool slsReceiverImplementation::getGapPixelsEnable() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return gapPixelsEnable;
}
/***file parameters***/
slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileFormatType;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return fileFormatType;
}
char *slsReceiverImplementation::getFileName() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(fileName))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,fileName);
//freed by calling function
return output;
std::string slsReceiverImplementation::getFileName() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(fileName);
}
char *slsReceiverImplementation::getFilePath() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(filePath))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,filePath);
//freed by calling function
return output;
std::string slsReceiverImplementation::getFilePath() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(filePath);
}
uint64_t slsReceiverImplementation::getFileIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileIndex;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return fileIndex;
}
uint32_t slsReceiverImplementation::getFramesPerFile() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framesPerFile;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return framesPerFile;
}
slsDetectorDefs::frameDiscardPolicy slsReceiverImplementation::getFrameDiscardPolicy() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameDiscardMode;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return frameDiscardMode;
}
bool slsReceiverImplementation::getFramePaddingEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framePadding;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return framePadding;
}
bool slsReceiverImplementation::getFileWriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileWriteEnable;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return fileWriteEnable;
}
bool slsReceiverImplementation::getOverwriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return overwriteEnable;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return overwriteEnable;
}
@ -272,143 +251,130 @@ int64_t slsReceiverImplementation::getAcquisitionIndex() const {
/***connection parameters***/
uint32_t slsReceiverImplementation::getUDPPortNumber() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[0];
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return udpPortNum[0];
}
uint32_t slsReceiverImplementation::getUDPPortNumber2() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[1];
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return udpPortNum[1];
}
char *slsReceiverImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,eth);
//freed by calling function
return output;
std::string slsReceiverImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(eth);
}
/***acquisition parameters***/
std::vector<slsDetectorDefs::ROI> slsReceiverImplementation::getROI() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return roi;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return roi;
}
uint32_t slsReceiverImplementation::getStreamingFrequency() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingFrequency;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return streamingFrequency;
}
uint32_t slsReceiverImplementation::getStreamingTimer() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingTimerInMs;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return streamingTimerInMs;
}
bool slsReceiverImplementation::getDataStreamEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataStreamEnable;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return dataStreamEnable;
}
uint64_t slsReceiverImplementation::getAcquisitionPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionPeriod;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return acquisitionPeriod;
}
uint64_t slsReceiverImplementation::getAcquisitionTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionTime;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return acquisitionTime;
}
uint64_t slsReceiverImplementation::getSubExpTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subExpTime;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return subExpTime;
}
uint64_t slsReceiverImplementation::getSubPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subPeriod;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return subPeriod;
}
uint64_t slsReceiverImplementation::getNumberOfFrames() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfFrames;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return numberOfFrames;
}
uint64_t slsReceiverImplementation::getNumberofSamples() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfSamples;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return numberOfSamples;
}
uint32_t slsReceiverImplementation::getDynamicRange() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dynamicRange;}
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return dynamicRange;}
bool slsReceiverImplementation::getTenGigaEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return tengigaEnable;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return tengigaEnable;
}
uint32_t slsReceiverImplementation::getFifoDepth() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fifoDepth;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return fifoDepth;
}
/***receiver status***/
slsDetectorDefs::runStatus slsReceiverImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return status;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return status;
}
bool slsReceiverImplementation::getSilentMode() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return silentMode;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return silentMode;
}
bool slsReceiverImplementation::getActivate() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return activated;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return activated;
}
bool slsReceiverImplementation::getDeactivatedPadding() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return deactivatedPaddingEnable;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return deactivatedPaddingEnable;
}
uint32_t slsReceiverImplementation::getStreamingPort() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingPort;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return streamingPort;
}
char *slsReceiverImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,streamingSrcIP);
//freed by calling function
return output;
std::string slsReceiverImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(streamingSrcIP);
}
char *slsReceiverImplementation::getAdditionalJsonHeader() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
memset(output, 0, MAX_STR_LENGTH);
strcpy(output,additionalJsonHeader);
//freed by calling function
return output;
std::string slsReceiverImplementation::getAdditionalJsonHeader() const{
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return std::string(additionalJsonHeader);
}
uint32_t slsReceiverImplementation::getUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpSocketBufferSize;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return udpSocketBufferSize;
}
uint32_t slsReceiverImplementation::getActualUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return actualUDPSocketBufferSize;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
return actualUDPSocketBufferSize;
}
@ -420,7 +386,7 @@ uint32_t slsReceiverImplementation::getActualUDPSocketBufferSize() const {
/**initial parameters***/
void slsReceiverImplementation::setDetectorHostname(const char *c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(strlen(c))
strcpy(detHostname, c);
@ -429,7 +395,7 @@ void slsReceiverImplementation::setDetectorHostname(const char *c){
void slsReceiverImplementation::setMultiDetectorSize(const int* size) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
std::string log_message = "Detector Size: (";
for (int i = 0; i < MAX_DIMENSIONS; ++i) {
if (myDetectorType == EIGER && (!i))
@ -446,7 +412,7 @@ void slsReceiverImplementation::setMultiDetectorSize(const int* size) {
void slsReceiverImplementation::setFlippedData(int axis, int enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(axis<0 || axis>1)
return;
flippedData[axis] = enable==0?0:1;
@ -490,7 +456,7 @@ void slsReceiverImplementation::setFileFormat(const fileFormat f){
void slsReceiverImplementation::setFileName(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(strlen(c))
strcpy(fileName, c);
@ -499,7 +465,7 @@ void slsReceiverImplementation::setFileName(const char c[]){
void slsReceiverImplementation::setFilePath(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(strlen(c)){
@ -515,7 +481,7 @@ void slsReceiverImplementation::setFilePath(const char c[]){
void slsReceiverImplementation::setFileIndex(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
fileIndex = i;
FILE_LOG(logINFO) << "File Index: " << fileIndex;
@ -523,7 +489,7 @@ void slsReceiverImplementation::setFileIndex(const uint64_t i){
void slsReceiverImplementation::setFramesPerFile(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
framesPerFile = i;
FILE_LOG(logINFO) << "Frames per file: " << framesPerFile;
@ -531,7 +497,7 @@ void slsReceiverImplementation::setFramesPerFile(const uint32_t i){
void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if (i >= 0 && i < NUM_DISCARD_POLICIES)
frameDiscardMode = i;
@ -541,7 +507,7 @@ void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i
void slsReceiverImplementation::setFramePaddingEnable(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
framePadding = i;
FILE_LOG(logINFO) << "Frame Padding: " << framePadding;
@ -552,7 +518,7 @@ void slsReceiverImplementation::setFileWriteEnable(const bool b){
if (fileWriteEnable != b){
fileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet,
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet,
&framesPerFile, fileName, filePath, &fileIndex, &overwriteEnable,
&detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i],
generalData);
@ -564,7 +530,7 @@ void slsReceiverImplementation::setFileWriteEnable(const bool b){
void slsReceiverImplementation::setOverwriteEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
overwriteEnable = b;
FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable);
@ -573,37 +539,37 @@ void slsReceiverImplementation::setOverwriteEnable(const bool b){
/***connection parameters***/
void slsReceiverImplementation::setUDPPortNumber(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
udpPortNum[0] = i;
FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0];
}
void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
udpPortNum[1] = i;
FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1];
}
void slsReceiverImplementation::setEthernetInterface(const char* c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
strcpy(eth, c);
FILE_LOG(logINFO) << "Ethernet Interface: " << eth;
}
int slsReceiverImplementation::setUDPSocketBufferSize(const uint32_t s) {
if (listener.size())
return listener[0]->CreateDummySocketForUDPSocketBufferSize(s);
return FAIL;
if (listener.size())
return listener[0]->CreateDummySocketForUDPSocketBufferSize(s);
return FAIL;
}
/***acquisition parameters***/
int slsReceiverImplementation::setROI(const std::vector<slsDetectorDefs::ROI> i) {
if (myDetectorType != GOTTHARD) {
cprintf(RED, "Error: Can not set ROI for this detector\n");
FILE_LOG(logERROR) << "Can not set ROI for this detector";
return FAIL;
}
@ -670,7 +636,7 @@ int slsReceiverImplementation::setStreamingFrequency(const uint32_t freq) {
}
void slsReceiverImplementation::setStreamingTimer(const uint32_t time_in_ms){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
streamingTimerInMs = time_in_ms;
FILE_LOG(logINFO) << "Streamer Timer: " << streamingTimerInMs;
@ -715,21 +681,21 @@ void slsReceiverImplementation::setStreamingPort(const uint32_t i) {
void slsReceiverImplementation::setStreamingSourceIP(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
strcpy(streamingSrcIP, c);
FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
}
void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(additionalJsonHeader, c);
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
strcpy(additionalJsonHeader, c);
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
}
int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
acquisitionPeriod = i;
FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s";
@ -739,7 +705,7 @@ int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i){
}
int slsReceiverImplementation::setAcquisitionTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
acquisitionTime = i;
FILE_LOG(logINFO) << "Acquisition Time: " << (double)acquisitionTime/(1E9) << "s";
@ -749,21 +715,21 @@ int slsReceiverImplementation::setAcquisitionTime(const uint64_t i){
}
void slsReceiverImplementation::setSubExpTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
subExpTime = i;
FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime/(1E9) << "s";
}
void slsReceiverImplementation::setSubPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
subPeriod = i;
FILE_LOG(logINFO) << "Sub Exposure Period: " << (double)subPeriod/(1E9) << "s";
}
int slsReceiverImplementation::setNumberOfFrames(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
numberOfFrames = i;
FILE_LOG(logINFO) << "Number of Frames: " << numberOfFrames;
@ -829,7 +795,7 @@ int slsReceiverImplementation::setFifoDepth(const uint32_t i) {
/***receiver parameters***/
bool slsReceiverImplementation::setActivate(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
activated = enable;
FILE_LOG(logINFO) << "Activation: " << stringEnable(activated);
return activated;
@ -837,14 +803,14 @@ bool slsReceiverImplementation::setActivate(bool enable){
bool slsReceiverImplementation::setDeactivatedPadding(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
deactivatedPaddingEnable = enable;
FILE_LOG(logINFO) << "Deactivated Padding Enable: " << stringEnable(deactivatedPaddingEnable);
return deactivatedPaddingEnable;
}
void slsReceiverImplementation::setSilentMode(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
silentMode = i;
FILE_LOG(logINFO) << "Silent Mode: " << i;
@ -859,14 +825,12 @@ void slsReceiverImplementation::setSilentMode(const bool i){
/***initial functions***/
int slsReceiverImplementation::setDetectorType(const detectorType d) {
FILE_LOG(logDEBUG) << "Setting receiver type";
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
DeleteMembers();
InitializeMembers();
myDetectorType = d;
switch(myDetectorType) {
case GOTTHARD:
case PROPIX:
case MOENCH:
case EIGER:
case JUNGFRAUCTB:
case JUNGFRAU:
@ -881,8 +845,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;
@ -930,8 +892,8 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
it->SetGeneralData(generalData);
SetThreadPriorities();
// check udp socket buffer size
setUDPSocketBufferSize(udpSocketBufferSize);
// check udp socket buffer size
setUDPSocketBufferSize(udpSocketBufferSize);
FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d);
return OK;
@ -941,6 +903,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
void slsReceiverImplementation::setDetectorPositionId(const int i){
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
detID = i;
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
@ -961,6 +924,7 @@ void slsReceiverImplementation::setDetectorPositionId(const int i){
/***acquisition functions***/
void slsReceiverImplementation::resetAcquisitionCount() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (const auto& it : listener)
it->ResetParametersforNewAcquisition();
for (const auto& it : dataProcessor)
@ -974,7 +938,7 @@ void slsReceiverImplementation::resetAcquisitionCount() {
int slsReceiverImplementation::startReceiver(char *c) {
cprintf(RESET,"\n");
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
FILE_LOG(logINFO) << "Starting Receiver";
ResetParametersforNewMeasurement();
@ -1020,6 +984,7 @@ int slsReceiverImplementation::startReceiver(char *c) {
void slsReceiverImplementation::stopReceiver(){
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
FILE_LOG(logINFO) << "Stopping Receiver";
//set status to transmitting
@ -1073,20 +1038,15 @@ void slsReceiverImplementation::stopReceiver(){
tot += dataProcessor[i]->GetNumFramesCaught();
uint64_t missingpackets = numberOfFrames*generalData->packetsPerFrame-listener[i]->GetPacketsCaught();
if ((int)missingpackets > 0) {
cprintf(RED, "\n[Port %d]\n",udpPortNum[i]);
cprintf(RED, "Missing Packets\t\t: %lld\n",(long long int)missingpackets);
cprintf(RED, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(RED, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
}else{
cprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]);
cprintf(GREEN, "Missing Packets\t\t: %lld\n",(long long int)missingpackets);
cprintf(GREEN, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(GREEN, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
}
FILE_LOG(((int)missingpackets > 0) ? logINFORED : logINFOGREEN) <<
"Summary of Port " << udpPortNum[i] <<
"\n\tMissing Packets\t\t: " << missingpackets <<
"\n\tComplete Frames\t\t: " << dataProcessor[i]->GetNumFramesCaught() <<
"\n\tLast Frame Caught\t: " << listener[i]->GetLastFrameIndexCaught();
}
if(!activated) {
FILE_LOG(logINFORED) << "Deactivated Receiver";
}
if(!activated)
cprintf(RED,"Note: Deactivated Receiver\n");
//callback
if (acquisitionFinishedCallBack)
acquisitionFinishedCallBack((tot/numThreads), pAcquisitionFinished);
@ -1102,6 +1062,7 @@ void slsReceiverImplementation::stopReceiver(){
void slsReceiverImplementation::startReadout(){
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
if(status == RUNNING){
// wait for incoming delayed packets
int totalPacketsReceived = 0;
@ -1110,22 +1071,18 @@ void slsReceiverImplementation::startReadout(){
totalPacketsReceived += it->GetPacketsCaught();
//wait for all packets
const auto numPacketsToReceive = numberOfFrames*generalData->packetsPerFrame*listener.size();
const auto numPacketsToReceive = numberOfFrames * generalData->packetsPerFrame * listener.size();
if(totalPacketsReceived != numPacketsToReceive){
while(totalPacketsReceived != previousValue){
#ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets previousValue:%d totalPacketsReceived:%d\n",
previousValue,totalPacketsReceived);
#endif
FILE_LOG(logDEBUG3) << "waiting for all packets, previousValue:" << previousValue <<
" totalPacketsReceived: " << totalPacketsReceived;
usleep(5*1000);/* TODO! Need to find optimal time **/
previousValue = totalPacketsReceived;
totalPacketsReceived = 0;
for(const auto& it : listener)
totalPacketsReceived += it->GetPacketsCaught();
#ifdef VERY_VERBOSE
cprintf(MAGENTA,"\tupdated: totalP:%d\n",totalPacketsReceived);
#endif
FILE_LOG(logDEBUG3) << "\tupdated: totalPacketsReceived:" << totalPacketsReceived;
}
}
status = TRANSMITTING;
@ -1137,6 +1094,7 @@ void slsReceiverImplementation::startReadout(){
void slsReceiverImplementation::shutDownUDPSockets() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (const auto& it : listener)
it->ShutDownUDPSocket();
}
@ -1144,6 +1102,7 @@ void slsReceiverImplementation::shutDownUDPSockets() {
void slsReceiverImplementation::closeFiles() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
uint64_t maxIndexCaught = 0;
bool anycaught = false;
for (const auto& it : dataProcessor) {
@ -1158,6 +1117,7 @@ void slsReceiverImplementation::closeFiles() {
int slsReceiverImplementation::restreamStop() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
bool ret = OK;
for (const auto& it : dataStreamer){
if (it->RestreamStop() == FAIL)
@ -1191,40 +1151,41 @@ void slsReceiverImplementation::registerCallBackRawDataReady(void (*func)(char*
}
void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)(char* ,
char*, uint32_t&, void*),void *arg){
rawDataModifyReadyCallBack=func;
pRawDataReady=arg;
char*, uint32_t&, void*),void *arg){
rawDataModifyReadyCallBack=func;
pRawDataReady=arg;
}
void slsReceiverImplementation::SetLocalNetworkParameters() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
// to increase Max length of input packet queue
int max_back_log;
const char *proc_file_name = "/proc/sys/net/core/netdev_max_backlog";
{
std::ifstream proc_file(proc_file_name);
proc_file >> max_back_log;
std::ifstream proc_file(proc_file_name);
proc_file >> max_back_log;
}
if (max_back_log < MAX_SOCKET_INPUT_PACKET_QUEUE) {
std::ofstream proc_file(proc_file_name);
if (proc_file.good()) {
proc_file << MAX_SOCKET_INPUT_PACKET_QUEUE << std::endl;
cprintf(GREEN, "Max length of input packet queue "
"[/proc/sys/net/core/netdev_max_backlog] modified to %d\n",
MAX_SOCKET_INPUT_PACKET_QUEUE);
} else {
const char *msg = "Could not change max length of "
"input packet queue [net.core.netdev_max_backlog]. (No Root Privileges?)";
FILE_LOG(logWARNING) << msg;
}
std::ofstream proc_file(proc_file_name);
if (proc_file.good()) {
proc_file << MAX_SOCKET_INPUT_PACKET_QUEUE << std::endl;
FILE_LOG(logINFOBLUE) << "Max length of input packet queue "
"[/proc/sys/net/core/netdev_max_backlog] modified to " <<
MAX_SOCKET_INPUT_PACKET_QUEUE;
} else {
FILE_LOG(logWARNING) << "Could not change max length of "
"input packet queue [net.core.netdev_max_backlog]. (No Root Privileges?)";
}
}
}
void slsReceiverImplementation::SetThreadPriorities() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (const auto& it : listener){
if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
@ -1241,6 +1202,8 @@ void slsReceiverImplementation::SetThreadPriorities() {
int slsReceiverImplementation::SetupFifoStructure() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
fifo.clear();
for ( int i = 0; i < numThreads; ++i ) {
@ -1250,7 +1213,7 @@ int slsReceiverImplementation::SetupFifoStructure() {
(generalData->imageSize) + (generalData->fifoBufferHeaderSize),
fifoDepth));
} catch (...) {
cprintf(RED,"Error: Could not allocate memory for fifo structure of index %d\n", i);
FILE_LOG(logERROR) << "Could not allocate memory for fifo structure of index " << i;
fifo.clear();
return FAIL;
}
@ -1268,6 +1231,8 @@ int slsReceiverImplementation::SetupFifoStructure() {
void slsReceiverImplementation::ResetParametersforNewMeasurement() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
for (const auto& it : listener)
it->ResetParametersforNewMeasurement();
for (const auto& it : dataProcessor)
@ -1284,6 +1249,7 @@ void slsReceiverImplementation::ResetParametersforNewMeasurement() {
int slsReceiverImplementation::CreateUDPSockets() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
bool error = false;
for (unsigned int i = 0; i < listener.size(); ++i)
if (listener[i]->CreateUDPSockets() == FAIL) {
@ -1301,6 +1267,7 @@ int slsReceiverImplementation::CreateUDPSockets() {
int slsReceiverImplementation::SetupWriter() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
bool error = false;
for (unsigned int i = 0; i < dataProcessor.size(); ++i)
if (dataProcessor[i]->CreateNewFile(tengigaEnable,
@ -1319,6 +1286,7 @@ int slsReceiverImplementation::SetupWriter() {
void slsReceiverImplementation::StartRunning() {
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
//set running mask and post semaphore to start the inner loop in execution thread
for (const auto& it : listener){
it->StartRunning();

File diff suppressed because it is too large Load Diff

View File

@ -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,7 +45,7 @@ int ClientInterface::Client_Send(int fnum,
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret == FAIL) {
if (Client_GetMesage(mess) == FAIL)
return FAIL;
return FAIL;
}
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
@ -63,33 +53,11 @@ int ClientInterface::Client_Send(int fnum,
}
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;
}
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
return ret;
}
void ClientInterface::Server_SendResult(bool update, int ret,
int 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
@ -104,6 +72,8 @@ void ClientInterface::Server_SendResult(bool update, int ret,
}
// send return value
mySocket->SendDataOnly(retval, retvalSize);
return ret;
}
@ -112,7 +82,6 @@ int ClientInterface::Server_ReceiveArg(int& ret, char* mess, void* arg, int size
if (sizeofArg && mySocket->ReceiveDataOnly(arg, sizeofArg) < 0)
return Server_SocketCrash();
ret = OK;
// check if server object created
if (checkbase && base == NULL)
Server_NullObjectError(ret, mess);
@ -143,7 +112,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 +126,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 +134,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;
}

View File

@ -57,34 +57,19 @@ 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
* @param retval pointer to result
* @param retvalSize size of result
* @param mess message
* @returns success of operation
*/
void Server_SendResult(bool update, int ret, void* retval, int retvalSize, char* mess = 0);
int 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 +82,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 +92,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 +104,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 +125,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 +141,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 */

View File

@ -36,8 +36,9 @@
inline std::string NowTime();
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
// 1 normal debug, 3 function names, 5 fifodebug
enum TLogLevel {logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO,
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
template <typename T> class Log{
public:
@ -63,20 +64,11 @@ public:
static void Output(const std::string& msg, TLogLevel level);
};
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32
#define FILELOG_DECLSPEC
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
//typedef Log<Output2FILE> FILELog;
#define FILE_LOG(level) \
if (level > FILELOG_MAX_LEVEL) ; \
@ -84,29 +76,6 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
else FILELog().Get(level)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#include <windows.h>
inline std::string NowTime()
{
const int MAX_LEN = 200;
char buffer[MAX_LEN];
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
return "Error in NowTime()";
char result[100] = {0};
static DWORD first = GetTickCount();
sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
return result;
}
#else
#include <sys/time.h>
inline std::string NowTime()
@ -127,8 +96,6 @@ inline std::string NowTime()
return result;
}
#endif //WIN32
template <typename T> Log<T>::Log():lev(logDEBUG){}
@ -138,7 +105,7 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
os << "- " << NowTime();
os << " " << ToString(level) << ": ";
if (level > logDEBUG)
os << std::string(level - logDEBUG, '\t');
os << std::string(level - logDEBUG, ' ');
return os;
}
@ -156,7 +123,9 @@ template <typename T> TLogLevel& Log<T>::ReportingLevel()
template <typename T> std::string Log<T>::ToString(TLogLevel level)
{
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
static const char* const buffer[] = {
"ERROR", "WARNING", "INFO", "INFO", "INFO", "INFO",
"DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
return buffer[level];
}
@ -211,21 +180,10 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level)
case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break;
case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break;
case logINFO: cprintf(RESET,"%s",msg.c_str()); break;
case logINFOBLUE: cprintf(BLUE,"%s",msg.c_str()); break;
case logINFORED: cprintf(RED,"%s",msg.c_str()); break;
case logINFOGREEN: cprintf(GREEN,"%s",msg.c_str()); break;
default: fprintf(pStream,"%s",msg.c_str()); out = false; break;
}
fflush(out ? stdout : pStream);
}
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined (BUILDING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllexport)
# elif defined (USING_FILELOG_DLL)
# define FILELOG_DECLSPEC __declspec (dllimport)
# else
# define FILELOG_DECLSPEC
# endif // BUILDING_DBSIMPLE_DLL
#else
# define FILELOG_DECLSPEC
#endif // _WIN32

View File

@ -81,11 +81,8 @@ public:
GENERIC, /**< generic sls detector */
EIGER, /**< eiger */
GOTTHARD, /**< gotthard */
MOENCH, /**< moench */
JUNGFRAU, /**< jungfrau */
JUNGFRAUCTB, /**< jungfrauCTBversion */
PROPIX, /**< propix */
MYTHEN3 /**< mythen 3 */
JUNGFRAUCTB /**< jungfrauCTBversion */
};
@ -95,7 +92,6 @@ public:
enum {
OK, /**< function succeeded */
FAIL, /**< function failed */
FINISHED, /**< acquisition finished */
FORCE_UPDATE
};
@ -244,16 +240,13 @@ public:
int nchip; /**< is the number of chips on the module */
int ndac; /**< is the number of dacs on the module */
int nadc; /**< is the number of adcs on the module */
int reg; /**< is the module register (e.g. dynamic range?)
\see moduleRegisterBit */
int reg; /**< is the module register settings (gain level) */
int iodelay; /**< iodelay */
int tau; /**< tau */
int eV; /**< threshold energy */
int *dacs; /**< is the pointer to the array of the dac values (in V) */
int *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/
int *chipregs; /**< is the pointer to the array of the chip registers
\see ::chipRegisterBit */
int *chanregs; /**< is the pointer to the array of the channel registers
\see ::channelRegisterBit */
double gain; /**< is the module gain (V/keV) */
double offset; /**< is the module offset (V) */
int *adcs; /**< is the pointer to the array of the adc values (in V) */
int *chanregs; /**< is the pointer to the array of the channel registers */
} sls_detector_module;
@ -366,8 +359,6 @@ public:
detector IDs/versions
*/
enum idMode{
MODULE_SERIAL_NUMBER, /**<return module serial number */
MODULE_FIRMWARE_VERSION, /**<return module firmware */
DETECTOR_SERIAL_NUMBER, /**<return detector system serial number */
DETECTOR_FIRMWARE_VERSION, /**<return detector system firmware version */
DETECTOR_SOFTWARE_VERSION, /**<return detector system software version */

View File

@ -45,7 +45,6 @@ enum detFuncs{
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
F_ENABLE_TEN_GIGA, /**< enable 10Gbe */
F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */
F_SET_CTB_PATTERN, /** < loads a pattern in the CTB */
@ -160,7 +159,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_LOAD_IMAGE: return "F_LOAD_IMAGE";
case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK";
case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK";
case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL";
case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA";
case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS";
case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN";