mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-03 19:30:04 +02:00
commonFiles/error_defs.h
This commit is contained in:
commit
9b3f4a3a66
@ -69,14 +69,14 @@ gotthardVirtualServer: $(SRC_MYTHEN_SVC)
|
|||||||
|
|
||||||
|
|
||||||
%.o : %.cpp %.h Makefile
|
%.o : %.cpp %.h Makefile
|
||||||
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS)
|
$(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS)
|
||||||
|
|
||||||
|
|
||||||
package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a
|
package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a
|
||||||
|
|
||||||
|
|
||||||
$(DESTDIR)/libSlsDetector.so: $(OBJS)
|
$(DESTDIR)/libSlsDetector.so: $(OBJS)
|
||||||
$(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ)
|
$(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ)
|
||||||
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
|
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
|
||||||
mv libSlsDetector.so $(DESTDIR)
|
mv libSlsDetector.so $(DESTDIR)
|
||||||
|
|
||||||
|
@ -19,11 +19,12 @@ using namespace std;
|
|||||||
|
|
||||||
/** Error flags */
|
/** Error flags */
|
||||||
/*Assumption: Only upto 63 detectors */
|
/*Assumption: Only upto 63 detectors */
|
||||||
#define CRITICAL_ERROR_MASK 0xFFFFFFFF
|
|
||||||
|
|
||||||
#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL
|
#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL
|
||||||
|
|
||||||
|
#define CRITICAL_ERROR_MASK 0xFFFFFFF
|
||||||
|
|
||||||
|
// 0xFFFFFFF000000000ULL
|
||||||
#define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL
|
#define CANNOT_CONNECT_TO_DETECTOR 0x4000000000000000ULL
|
||||||
#define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL
|
#define CANNOT_CONNECT_TO_RECEIVER 0x2000000000000000ULL
|
||||||
#define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL
|
#define COULDNOT_SET_CONTROL_PORT 0x1000000000000000ULL
|
||||||
@ -40,10 +41,9 @@ using namespace std;
|
|||||||
#define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL
|
#define COULD_NOT_CONFIGURE_MAC 0x0002000000000000ULL
|
||||||
#define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads
|
#define COULDNOT_START_RECEIVER 0x0001000000000000ULL // default error like starting threads
|
||||||
#define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL
|
#define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL
|
||||||
|
// 0xFFFFFFF000000000ULL
|
||||||
|
|
||||||
// 0xFFFFFFFF00000000ULL
|
// 0x0000000FFFFFFFFFULL
|
||||||
|
|
||||||
|
|
||||||
#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL
|
#define COULDNOT_SET_NETWORK_PARAMETER 0x0000000000000001ULL
|
||||||
#define COULDNOT_SET_ROI 0x0000000000000002ULL
|
#define COULDNOT_SET_ROI 0x0000000000000002ULL
|
||||||
#define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL
|
#define RECEIVER_READ_FREQUENCY 0x0000000000000004ULL
|
||||||
@ -74,9 +74,10 @@ using namespace std;
|
|||||||
#define RECEIVER_READ_TIMER 0x0000000008000000ULL
|
#define RECEIVER_READ_TIMER 0x0000000008000000ULL
|
||||||
#define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL
|
#define RECEIVER_ACQ_TIME_NOT_SET 0x0000000010000000ULL
|
||||||
#define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL
|
#define RECEIVER_FLIPPED_DATA_NOT_SET 0x0000000020000000ULL
|
||||||
#define RECEIVER_FILE_FORMAT 0x0000000040000000ULL
|
#define THRESHOLD_NOT_SET 0x0000000040000000ULL
|
||||||
|
#define RECEIVER_FILE_FORMAT 0x0000000080000000ULL
|
||||||
|
// 0x0000000FFFFFFFFFULL
|
||||||
|
|
||||||
// 0x00000000FFFFFFFFULL
|
|
||||||
/** @short class returning all error messages for error mask */
|
/** @short class returning all error messages for error mask */
|
||||||
class errorDefs {
|
class errorDefs {
|
||||||
|
|
||||||
@ -235,10 +236,13 @@ public:
|
|||||||
if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET)
|
if(slsErrorMask&RECEIVER_FLIPPED_DATA_NOT_SET)
|
||||||
retval.append("Could not set receiver flipped data/bottom\n");
|
retval.append("Could not set receiver flipped data/bottom\n");
|
||||||
|
|
||||||
|
if(slsErrorMask&THRESHOLD_NOT_SET)
|
||||||
|
retval.append("Could not set threshold\n");
|
||||||
|
|
||||||
if(slsErrorMask&RECEIVER_FILE_FORMAT)
|
if(slsErrorMask&RECEIVER_FILE_FORMAT)
|
||||||
retval.append("Could not set receiver file format\n");
|
retval.append("Could not set receiver file format\n");
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------ length of message
|
//------------------------------------------------------ length of message
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class slsDetectorDefs: public virtual slsReceiverDefs{
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int module; /**< is the module number */
|
int module; /**< is the module number */
|
||||||
int serialnumber; /**< is the module serial number */
|
int serialnumber; /**< is the module serial number */
|
||||||
int nchan; /**< is the number of channels per chip */
|
int nchan; /**< is the number of channels on the module*/
|
||||||
int nchip; /**< is the number of chips on the module */
|
int nchip; /**< is the number of chips on the module */
|
||||||
int ndac; /**< is the number of dacs on the module */
|
int ndac; /**< is the number of dacs on the module */
|
||||||
int nadc; /**< is the number of adcs on the module */
|
int nadc; /**< is the number of adcs on the module */
|
||||||
|
@ -1,470 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//return reversed 1 means good, 0 means failed
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
|
||||||
#include "xfs_types.h"
|
|
||||||
#include "xparameters.h"
|
|
||||||
|
|
||||||
#include "Beb.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
BebInfo::BebInfo(unsigned int beb_num){beb_number=beb_num;serial_address=0;src_mac_1GbE="";src_mac_10GbE="";src_ip_1GbE="";src_ip_10GbE=""; src_port_1GbE=src_port_10GbE=0;}
|
|
||||||
bool BebInfo::SetHeaderInfo(bool ten_gig, string src_mac, string src_ip, unsigned int src_port){
|
|
||||||
if(ten_gig){ src_mac_10GbE = src_mac; src_ip_10GbE = src_ip; src_port_10GbE = src_port;}
|
|
||||||
else { src_mac_1GbE = src_mac; src_ip_1GbE = src_ip; src_port_1GbE = src_port;}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BebInfo::SetSerialAddress(unsigned int a){
|
|
||||||
//address pre shifted
|
|
||||||
if(a>0xff) return 0;
|
|
||||||
serial_address = 0x04000000 | ((a&0xff)<<16);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BebInfo::Print(){
|
|
||||||
cout<<"\t"<<beb_number<<") Beb Info.:"<<endl;
|
|
||||||
cout<<"\t\tSerial Add: 0x"<<hex<<serial_address<<dec<<endl;
|
|
||||||
cout<<"\t\tMAC 1GbE: "<<src_mac_1GbE.c_str()<<endl;
|
|
||||||
cout<<"\t\tIP 1GbE: "<<src_ip_1GbE.c_str()<<endl;
|
|
||||||
cout<<"\t\tport 1GbE: "<<src_port_1GbE<<endl;
|
|
||||||
cout<<"\t\tMAC 10GbE: "<<src_mac_10GbE.c_str()<<endl;
|
|
||||||
cout<<"\t\tIP 10GbE: "<<src_ip_10GbE.c_str()<<endl;
|
|
||||||
cout<<"\t\tport 10GbE: "<<src_port_10GbE<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Beb::Beb(int arg1){
|
|
||||||
|
|
||||||
send_ndata = 0;
|
|
||||||
send_buffer_size = 1026;
|
|
||||||
send_data_raw = new unsigned int [send_buffer_size+1];
|
|
||||||
send_data = &send_data_raw[1];
|
|
||||||
|
|
||||||
recv_ndata = 0;
|
|
||||||
recv_buffer_size = 1026;
|
|
||||||
recv_data_raw = new unsigned int [recv_buffer_size+1];
|
|
||||||
recv_data = &recv_data_raw[1];
|
|
||||||
|
|
||||||
if(!InitBebInfos()) exit(1);
|
|
||||||
|
|
||||||
cout<<"Printing Beb infos:"<<endl;
|
|
||||||
for(unsigned int i=1;i<beb_infos.size();i++) beb_infos[i]->Print();
|
|
||||||
cout<<endl<<endl;
|
|
||||||
|
|
||||||
bit_mode = 4;
|
|
||||||
|
|
||||||
ll = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
|
|
||||||
|
|
||||||
SetByteOrder();
|
|
||||||
|
|
||||||
|
|
||||||
new_memory = new LocalLinkInterface();
|
|
||||||
if(!new_memory->InitNewMemory(XPAR_PLB_LL_NEW_MEMORY, arg1))
|
|
||||||
printf("New Memory FAIL\n");
|
|
||||||
else
|
|
||||||
printf("New Memory OK\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Beb::~Beb(){
|
|
||||||
delete ll;
|
|
||||||
delete [] send_data_raw;
|
|
||||||
delete [] recv_data_raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Beb::ClearBebInfos(){
|
|
||||||
for(unsigned int i=0;i<beb_infos.size();i++) delete beb_infos[i];
|
|
||||||
beb_infos.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beb::InitBebInfos(){//file name at some point
|
|
||||||
ClearBebInfos();
|
|
||||||
|
|
||||||
BebInfo* b0 = new BebInfo(0);
|
|
||||||
if(b0->SetSerialAddress(0xff)) beb_infos.push_back(b0); //all bebs for reset and possibly get request data?
|
|
||||||
|
|
||||||
if(!ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0;
|
|
||||||
/*
|
|
||||||
//loop through file to fill vector.
|
|
||||||
BebInfo* b = new BebInfo(26);
|
|
||||||
b->SetSerialAddress(0); //0xc4000000
|
|
||||||
b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, ip address can be acquire from the network "arp"
|
|
||||||
b->SetHeaderInfo(1,"00:50:c2:46:d9:35","10.0.26.1",52000 + 26); //10 GbE, everything calculable/setable
|
|
||||||
beb_infos.push_back(b);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return CheckSourceStuffBebInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetBebSrcHeaderInfos(unsigned int beb_number, bool ten_gig, string src_mac, string src_ip,unsigned int src_port){
|
|
||||||
//so that the values can be reset externally for now....
|
|
||||||
|
|
||||||
unsigned int i = GetBebInfoIndex(beb_number);
|
|
||||||
if(!i) return 0; //i must be greater than 0, zero is the global send
|
|
||||||
beb_infos[i]->SetHeaderInfo(ten_gig,src_mac,src_ip,src_port);
|
|
||||||
|
|
||||||
cout<<"Printing Beb info number ("<<i<<") :"<<endl;
|
|
||||||
beb_infos[i]->Print();
|
|
||||||
cout<<endl<<endl;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::ReadSetUpFromFile(string file_name){
|
|
||||||
|
|
||||||
static ifstream infile;
|
|
||||||
static string line;
|
|
||||||
static char cmd_st[2000],str_mac1[200],str_ip1[200],str_mac10[200],str_ip10[200];
|
|
||||||
static int value_i[2];
|
|
||||||
|
|
||||||
infile.open(file_name.c_str(),ios::in);
|
|
||||||
if(!infile.is_open()){
|
|
||||||
cout<<"Error could not open setup file: "<<file_name<<"."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout<<endl;
|
|
||||||
cout<<"Setting up detector:"<<endl;
|
|
||||||
while(std::getline(infile,line)){
|
|
||||||
if(line.length()<1) continue;
|
|
||||||
istringstream iss(line);
|
|
||||||
iss>>cmd_st;
|
|
||||||
if(!strcmp("add_beb",cmd_st)){
|
|
||||||
if(!(iss>>value_i[0]>>value_i[1]>>str_mac1>>str_ip1>>str_mac10>>str_ip10)){
|
|
||||||
cout<<"Error adding beb from "<<file_name<<"."<<endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetBebInfoIndex(value_i[0])){
|
|
||||||
cout<<"Error adding beb from "<<file_name<<", beb number "<<value_i[0]<<" already added."<<endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BebInfo* b = new BebInfo(value_i[0]);
|
|
||||||
b->SetSerialAddress(value_i[1]);
|
|
||||||
b->SetHeaderInfo(0,str_mac1,str_ip1,42000+value_i[0]);
|
|
||||||
b->SetHeaderInfo(1,str_mac10,str_ip10,52000+value_i[0]);
|
|
||||||
beb_infos.push_back(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
infile.close();
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::CheckSourceStuffBebInfo(){
|
|
||||||
for(unsigned int i=1;i<beb_infos.size();i++){ //header stuff always starts from 1
|
|
||||||
if(!SetHeaderData(beb_infos[i]->GetBebNumber(),0,"00:00:00:00:00:00","10.0.0.1",20000)||!SetHeaderData(beb_infos[i]->GetBebNumber(),1,"00:00:00:00:00:00","10.0.0.1",20000)){
|
|
||||||
cout<<"Error in BebInfo for module number "<<beb_infos[i]->GetBebNumber()<<"."<<endl;
|
|
||||||
beb_infos[i]->Print();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int Beb::GetBebInfoIndex(unsigned int beb_numb){
|
|
||||||
if(!beb_numb) return 0;
|
|
||||||
|
|
||||||
for(unsigned int i=1;i<beb_infos.size();i++) if(beb_numb==beb_infos[i]->GetBebNumber()) return i;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::WriteTo(unsigned int index){
|
|
||||||
if(index>=beb_infos.size()){
|
|
||||||
cout<<"WriteTo index error."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
send_data_raw[0] = 0x90000000 | beb_infos[index]->GetSerialAddress();
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0xc0000000;
|
|
||||||
if((send_ndata+1)*4!=ll->Write((send_ndata+1)*4,send_data_raw)) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Beb::SwapDataFun(bool little_endian, unsigned int n, unsigned int *d){
|
|
||||||
if(little_endian) for(unsigned int i=0;i<n;i++) d[i] = (((d[i]&0xff)<<24) | ((d[i]&0xff00)<<8) | ((d[i]&0xff0000)>>8) | ((d[i]&0xff000000)>>24)); //little_endian
|
|
||||||
else for(unsigned int i=0;i<n;i++) d[i] = (((d[i]&0xffff)<<16) | ((d[i]&0xffff0000)>>16));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetByteOrder(){
|
|
||||||
send_data_raw[0] = 0x8fff0000;
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
while((ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0) cout<<"\t) Cleanning buffer ..."<<endl;
|
|
||||||
|
|
||||||
if(beb_infos.size()<2) return 0;
|
|
||||||
|
|
||||||
send_ndata = 3;
|
|
||||||
send_data[0] = 0x000c0000;
|
|
||||||
send_data[1] = 0;
|
|
||||||
send_data[2] = 0;
|
|
||||||
WriteTo(0);
|
|
||||||
|
|
||||||
//using little endian for data, big endian not fully tested, swap on 16 bit boundary.
|
|
||||||
send_ndata = 3;
|
|
||||||
send_data[0] = 0x000c0000;
|
|
||||||
send_data[1] = 1;
|
|
||||||
send_data[2] = 0;
|
|
||||||
SwapDataFun(0,2,&(send_data[1]));
|
|
||||||
WriteTo(0);
|
|
||||||
|
|
||||||
cout<<"\tSetting Byte Order .............. ok"<<endl<<endl;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetUpUDPHeader(unsigned int beb_number, bool ten_gig, unsigned int header_number, string dst_mac, string dst_ip, unsigned int dst_port){
|
|
||||||
unsigned int i = GetBebInfoIndex(beb_number);
|
|
||||||
if(!i) return 0; //i must be greater than 0, zero is the global send
|
|
||||||
|
|
||||||
send_ndata = 14;
|
|
||||||
send_data[0] = ten_gig ? 0x00020000 : 0x00010000; //write to fanout numbers 1 or 2
|
|
||||||
send_data[1] = ((header_number*8)<<16);
|
|
||||||
if(!SetHeaderData(beb_number,ten_gig,dst_mac,dst_ip,dst_port)) return 0;
|
|
||||||
|
|
||||||
SwapDataFun(1,12,&(send_data[2]));
|
|
||||||
|
|
||||||
if(!WriteTo(i)) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetHeaderData(unsigned int beb_number, bool ten_gig, string dst_mac, string dst_ip, unsigned int dst_port){
|
|
||||||
unsigned int i = GetBebInfoIndex(beb_number);
|
|
||||||
if(!i) return 0; //i must be greater than 0, zero is the global send
|
|
||||||
return SetHeaderData(beb_infos[i]->GetSrcMAC(ten_gig),beb_infos[i]->GetSrcIP(ten_gig),beb_infos[i]->GetSrcPort(ten_gig),dst_mac,dst_ip,dst_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beb::SetHeaderData(string src_mac, string src_ip, unsigned int src_port, string dst_mac, string dst_ip, unsigned int dst_port){
|
|
||||||
/* example header*/
|
|
||||||
//static unsigned int* word_ptr = new unsigned int [16];
|
|
||||||
static udp_header_type udp_header = {
|
|
||||||
{0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC
|
|
||||||
{0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC
|
|
||||||
{0x08, 0x00},
|
|
||||||
{0x45},
|
|
||||||
{0x00},
|
|
||||||
{0x00, 0x00},
|
|
||||||
{0x00, 0x00},
|
|
||||||
{0x40},
|
|
||||||
{0x00},
|
|
||||||
{0xff},
|
|
||||||
{0x11},
|
|
||||||
{0x00, 0x00},
|
|
||||||
{129, 205, 205, 128}, // Src IP
|
|
||||||
{129, 205, 205, 122}, // Dst IP
|
|
||||||
{0x0f, 0xa1},
|
|
||||||
{0x13, 0x89},
|
|
||||||
{0x00, 0x00}, //{0x00, 0x11},
|
|
||||||
{0x00, 0x00}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0;
|
|
||||||
if(!SetIP(src_ip,&(udp_header.src_ip[0]))) return 0;
|
|
||||||
if(!SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0;
|
|
||||||
|
|
||||||
if(!SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0;
|
|
||||||
if(!SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0;
|
|
||||||
if(!SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0;
|
|
||||||
|
|
||||||
|
|
||||||
AdjustIPChecksum(&udp_header);
|
|
||||||
|
|
||||||
unsigned int* base_ptr = (unsigned int *) &udp_header;
|
|
||||||
unsigned int num_words = ( sizeof(udp_header_type) + 3 ) / 4;
|
|
||||||
// for(unsigned int i=0; i<num_words; i++) word_ptr[i] = base_ptr[i];
|
|
||||||
// for(unsigned int i=num_words; i<16; i++) word_ptr[i] = 0;
|
|
||||||
// return word_ptr;
|
|
||||||
|
|
||||||
for(unsigned int i=0; i<num_words; i++) send_data[i+2] = base_ptr[i];
|
|
||||||
for(unsigned int i=num_words; i<16; i++) send_data[i+2] = 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetMAC(string mac, unsigned char* dst_ptr){
|
|
||||||
for(int i=0;i<6;i++){
|
|
||||||
size_t p0=mac.find(':');
|
|
||||||
if((i!=5&&p0!=2)||(i==5&&mac.length()!=2)){
|
|
||||||
cout<<"Error: in mac address -> "<<mac<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
dst_ptr[i] = (unsigned char) strtoul(mac.substr(0,p0).c_str(),NULL,16);
|
|
||||||
mac=mac.substr(p0+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beb::SetIP(string ip, unsigned char* dst_ptr){
|
|
||||||
for(int i=0;i<4;i++){
|
|
||||||
size_t p0=ip.find('.');
|
|
||||||
if((i!=3&&(p0<1||p0>3))||(i==3&&(ip.length()<1||ip.length()>3))){
|
|
||||||
cout<<"Error: in ip address -> "<<ip<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
dst_ptr[i] = atoi(ip.substr(0,p0).c_str());
|
|
||||||
ip=ip.substr(p0+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beb::SetPortNumber(unsigned int port_number, unsigned char* dst_ptr){
|
|
||||||
dst_ptr[0] = (port_number >> 8) & 0xff ;
|
|
||||||
dst_ptr[1] = port_number & 0xff;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Beb::AdjustIPChecksum(udp_header_type *ip){
|
|
||||||
unsigned char *cptr = (unsigned char *) ip->ver_headerlen;
|
|
||||||
|
|
||||||
ip->ip_header_checksum[0] = 0;
|
|
||||||
ip->ip_header_checksum[1] = 0;
|
|
||||||
ip->total_length[0] = 0;
|
|
||||||
ip->total_length[1] = 28; // IP + UDP Header Length
|
|
||||||
|
|
||||||
// calc ip checksum
|
|
||||||
unsigned int ip_checksum = 0;
|
|
||||||
for(unsigned int i=0; i<10; i++){
|
|
||||||
ip_checksum += ( (cptr[2*i] << 8) + (cptr[2*i + 1]) );
|
|
||||||
if (ip_checksum & 0x00010000) ip_checksum = (ip_checksum + 1) & 0x0000ffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff ;
|
|
||||||
ip->ip_header_checksum[1] = ip_checksum & 0xff ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, bool stop_read_when_fifo_empty){
|
|
||||||
|
|
||||||
unsigned int i = GetBebInfoIndex(beb_number); //zero is the global send
|
|
||||||
|
|
||||||
send_ndata = 3;
|
|
||||||
if(left_right == 1) send_data[0] = 0x00040000;
|
|
||||||
else if(left_right == 2) send_data[0] = 0x00080000;
|
|
||||||
else if(left_right == 3) send_data[0] = 0x000c0000;
|
|
||||||
else return 0;
|
|
||||||
|
|
||||||
//packet_size/=2;
|
|
||||||
if(dst_number>0x3f) return 0;
|
|
||||||
if(packet_size>0x3ff) return 0;
|
|
||||||
if(npackets==0||npackets>0x100) return 0;
|
|
||||||
npackets--;
|
|
||||||
|
|
||||||
|
|
||||||
send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets;
|
|
||||||
send_data[2] = 0;
|
|
||||||
|
|
||||||
SwapDataFun(0,2,&(send_data[1]));
|
|
||||||
|
|
||||||
if(!WriteTo(i)) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::SetUpTransferParameters(short the_bit_mode){
|
|
||||||
if(the_bit_mode!=4&&the_bit_mode!=8&&the_bit_mode!=16&&the_bit_mode!=32) return 0;
|
|
||||||
bit_mode = the_bit_mode;
|
|
||||||
|
|
||||||
//nimages = the_number_of_images;
|
|
||||||
// on_dst = 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Beb::RequestNImages(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int nimages, bool test_just_send_out_packets_no_wait){
|
|
||||||
if(dst_number>64) return 0;
|
|
||||||
|
|
||||||
unsigned int header_size = 4; //4*64 bits
|
|
||||||
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
|
|
||||||
unsigned int npackets = ten_gig ? bit_mode*4 : bit_mode*16;
|
|
||||||
bool in_two_requests = (!ten_gig&&bit_mode==32);
|
|
||||||
if(in_two_requests) npackets/=2;
|
|
||||||
|
|
||||||
//cout<<"here: "<<beb_number<<","<<left_right<<","<<ten_gig<<","<<dst_number<<","<<1<<","<<header_size<<","<<test_just_send_out_packets_no_wait<<endl;
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nimages;i++){
|
|
||||||
//header then data request
|
|
||||||
if(!SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,1,header_size,test_just_send_out_packets_no_wait) ||
|
|
||||||
!SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait) ||
|
|
||||||
(in_two_requests&&!SendMultiReadRequest(beb_number,left_right,ten_gig,dst_number,npackets,packet_size,test_just_send_out_packets_no_wait))) return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Beb::Test(unsigned int beb_number){
|
|
||||||
cout<<"Testing module number: "<<beb_number<<endl;
|
|
||||||
|
|
||||||
|
|
||||||
//bool Beb::SetUpUDPHeader(unsigned int beb_number, bool ten_gig, unsigned int header_number, string dst_mac, string dst_ip, unsigned int dst_port){
|
|
||||||
//SetUpUDPHeader(26,0,0,"60:fb:42:f4:e3:d2","129.129.205.186",22000);
|
|
||||||
|
|
||||||
unsigned int index = GetBebInfoIndex(beb_number);
|
|
||||||
if(!index){
|
|
||||||
cout<<"Error beb number ("<<beb_number<<")not in list????"<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<64;i++){
|
|
||||||
if(!SetUpUDPHeader(beb_number,0,i,"60:fb:42:f4:e3:d2","129.129.205.186",22000+i)){
|
|
||||||
cout<<"Error setting up header table...."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, bool stop_read_when_fifo_empty=1);
|
|
||||||
for(unsigned int i=0;i<64;i++){
|
|
||||||
if(!SendMultiReadRequest(beb_number,i%3+1,0,i,1,0)){
|
|
||||||
cout<<"Error requesting data...."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,388 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <algorithm> // std::remove_if
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <time.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "Beb.h"
|
|
||||||
#include "slsDetectorServer_defs.h" //include port number
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
enum cmd_string {evNotFound,
|
|
||||||
evRequestImages,evTestRequest,
|
|
||||||
evSetBitMode,
|
|
||||||
evSetupTableEntry,evSetDstParameters,
|
|
||||||
evTest,evTestSend,
|
|
||||||
evExitServer};
|
|
||||||
|
|
||||||
map<string, cmd_string> enum_map;
|
|
||||||
|
|
||||||
void init(){
|
|
||||||
|
|
||||||
enum_map["requestimages"] = evRequestImages; //<dst>
|
|
||||||
enum_map["testrequest"] = evTestRequest; //<dst>
|
|
||||||
|
|
||||||
enum_map["setbitmode"] = evSetBitMode; // (resets on_dst and dst_requested)
|
|
||||||
|
|
||||||
enum_map["setuptableentry"] = evSetupTableEntry;
|
|
||||||
enum_map["setdstparameters"] = evSetDstParameters; //<one_ten> <ndsts> <nimages_per_request> (resets on_dst and dst_requested)
|
|
||||||
|
|
||||||
enum_map["test"] = evTest;
|
|
||||||
enum_map["testsend"] = evTestSend;
|
|
||||||
enum_map["exitserver"] = evExitServer;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int server_list_s;
|
|
||||||
int server_conn_s;
|
|
||||||
int AccpetConnectionAndWaitForData(char* buffer, int maxlength);
|
|
||||||
bool WriteNClose(const char* buffer, int length);
|
|
||||||
bool SetupListenSocket(unsigned short int port);
|
|
||||||
|
|
||||||
|
|
||||||
string LowerCase(string str);
|
|
||||||
string GetNextString(string str,bool start_from_beginning=0);
|
|
||||||
void AddNumber(string& str, int n, int location=-1);//-1 means append
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
|
||||||
cout<<endl<<endl;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(argc<2){
|
|
||||||
cout<<"Usage: eiger_beb_server port_number"<<endl<<endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
init();
|
|
||||||
|
|
||||||
int arg1;
|
|
||||||
Beb *bebs;
|
|
||||||
|
|
||||||
if(argc>1)
|
|
||||||
bebs = new Beb(atoi(argv[1]));
|
|
||||||
else
|
|
||||||
bebs = new Beb(-1);
|
|
||||||
|
|
||||||
// unsigned short int port_number = atoi(argv[1]);
|
|
||||||
|
|
||||||
unsigned short int port_number = BEB_PORT;
|
|
||||||
if(!SetupListenSocket(port_number)) return 1;
|
|
||||||
|
|
||||||
|
|
||||||
int length=1000;
|
|
||||||
char data[1000];
|
|
||||||
|
|
||||||
int stop = 0;
|
|
||||||
time_t rawtime;
|
|
||||||
struct tm *timeinfo;
|
|
||||||
|
|
||||||
bool send_to_ten_gig = 0;
|
|
||||||
int ndsts_in_use=32;
|
|
||||||
unsigned int nimages_per_request=1;
|
|
||||||
|
|
||||||
int on_dst=0;
|
|
||||||
bool dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
||||||
|
|
||||||
while(!stop){
|
|
||||||
|
|
||||||
cout<<endl<<"\n\n\n\nWaiting for command -> "<<flush;
|
|
||||||
int nread = AccpetConnectionAndWaitForData(data,length);
|
|
||||||
if(nread<=0) return 0;
|
|
||||||
|
|
||||||
time(&rawtime); timeinfo=localtime(&rawtime);
|
|
||||||
cout<<asctime(timeinfo);
|
|
||||||
cout<<" Command received: "<<data<<endl<<endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string tmp_str[5];
|
|
||||||
//float v1,v2,v3,v4,v5;
|
|
||||||
int n[5];
|
|
||||||
|
|
||||||
string cmd = GetNextString(data,1);
|
|
||||||
//static char retval_st[100];
|
|
||||||
int ret_val = 1;
|
|
||||||
string return_message = " Command recieved: ";
|
|
||||||
return_message.append(data);
|
|
||||||
return_message.append("\n");
|
|
||||||
|
|
||||||
int return_start_pos;
|
|
||||||
while(cmd.length()>0){
|
|
||||||
return_start_pos = return_message.length();
|
|
||||||
|
|
||||||
switch(enum_map.find(LowerCase(cmd))->second){
|
|
||||||
|
|
||||||
case evRequestImages :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data()); //dst number
|
|
||||||
if(tmp_str[0].length()<1||n[0]<0||n[0]>=ndsts_in_use){
|
|
||||||
return_message.append("\tError executing: RequestImages <dst_number> (note dst_number must be less than ndsts_in_use that is set with SetDstParameters\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}else{
|
|
||||||
dst_requested[n[0]] = 1;
|
|
||||||
ret_val=0;
|
|
||||||
tmp_str[1] = " ( ";
|
|
||||||
while(dst_requested[on_dst]){
|
|
||||||
//waits on data
|
|
||||||
if((ret_val = (!bebs->RequestNImages(0,1,send_to_ten_gig,on_dst,nimages_per_request)||!bebs->RequestNImages(0,2,send_to_ten_gig,0x20|on_dst,nimages_per_request)))) break;
|
|
||||||
AddNumber(tmp_str[1],on_dst);tmp_str[1].append(" ");
|
|
||||||
dst_requested[on_dst++]=0;
|
|
||||||
on_dst%=ndsts_in_use;
|
|
||||||
}
|
|
||||||
if(ret_val) return_message.append("\tError executing: RequestImages <dst_number>");
|
|
||||||
else{ return_message.append("\tExecuted: RequestImages "); AddNumber(return_message,n[0]);}
|
|
||||||
return_message.append(tmp_str[1]);
|
|
||||||
return_message.append(" )\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evTestRequest :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data()); //dst number
|
|
||||||
if(tmp_str[0].length()<1||n[0]<0||n[0]>=ndsts_in_use){
|
|
||||||
return_message.append("\tError executing: TestRequest <dst_number> (note dst_number must be less than 2xndsts_in_use that is set with SetDstParameters\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}else{
|
|
||||||
ret_val = (!bebs->RequestNImages(0,1,send_to_ten_gig,n[0],nimages_per_request,1)||!bebs->RequestNImages(0,2,send_to_ten_gig,0x20|n[0],nimages_per_request,1));
|
|
||||||
if(ret_val) return_message.append("\tError executing: TestRequest <dst_number>\n");
|
|
||||||
else{ return_message.append("\tExecuted: TestRequest "); AddNumber(return_message,n[0]); return_message.append("\n");}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetBitMode :
|
|
||||||
on_dst = 0;
|
|
||||||
for(n[0]=0;n[0]<32;n[0]++) dst_requested[n[0]] = 0; //clear dst requested
|
|
||||||
n[0] = atoi(GetNextString(data).data());
|
|
||||||
if((ret_val = !bebs->SetUpTransferParameters(n[0]))) return_message.append("\tError executing: SetBitMode <bit_mode 4,8,16,32>\n");
|
|
||||||
else{ return_message.append("\tExecuted: SetBitMode ");AddNumber(return_message,n[0]);return_message.append("\n");}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetDstParameters : //move below //<one_ten_gigabit> <ndsts> <nimages_per_request>
|
|
||||||
on_dst = 0;
|
|
||||||
for(n[0]=0;n[0]<32;n[0]++) dst_requested[n[0]] = 0; //clear dst requested
|
|
||||||
n[0] = atoi(GetNextString(data).data()); //<1GbE(0) or 10GbE(1)>
|
|
||||||
n[1] = atoi(GetNextString(data).data()); //<ndsts (1 to 32)>
|
|
||||||
n[2] = atoi(GetNextString(data).data()); // <nimages_per_request (>0)>
|
|
||||||
|
|
||||||
if((n[0]!=0&&n[0]!=1)||(n[1]<1||n[1]>32)||n[2]<1){
|
|
||||||
return_message.append("\tError executing: SetDstParameters <1GbE(0) or 10GbE(1)> <ndsts> <nimages_per_request>\n");
|
|
||||||
ret_val=1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
send_to_ten_gig = n[0];
|
|
||||||
ndsts_in_use=n[1];
|
|
||||||
nimages_per_request=n[2];
|
|
||||||
return_message.append("\tExecuted: SetDstParameters ");
|
|
||||||
AddNumber(return_message,n[0]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[1]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[2]);return_message.append(" ");
|
|
||||||
ret_val=0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetupTableEntry :
|
|
||||||
n[0] = atoi(GetNextString(data).data()); //beb_number;
|
|
||||||
n[1] = atoi(GetNextString(data).data()); //<1GbE(0) or 10GbE(1)>
|
|
||||||
n[2] = atoi(GetNextString(data).data()); //header_number
|
|
||||||
tmp_str[0] = GetNextString(data); //src_mac
|
|
||||||
tmp_str[1] = GetNextString(data); //src_ip
|
|
||||||
n[3] = atoi(GetNextString(data).data()); //src_port
|
|
||||||
tmp_str[2] = GetNextString(data); //dst_mac
|
|
||||||
tmp_str[3] = GetNextString(data); //dst_ip
|
|
||||||
n[4] = atoi((tmp_str[4]=GetNextString(data)).data()); //dst_port
|
|
||||||
|
|
||||||
if(n[0]<1||(n[1]!=0&&n[1]!=1)||(n[2]<0||n[2]>63)||tmp_str[0].length()<1||tmp_str[1].length()<1||n[3]<0||tmp_str[2].length()<1||tmp_str[3].length()<1||n[4]<0||tmp_str[4].length()<1){
|
|
||||||
return_message.append("\tError executing: SetupTableEntry <beb_number> <1GbE(0) or 10GbE(1)> <dst_number> <src_mac> <src_ip> <src_port> <dst_mac> <dst_ip> <dst_port>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}else{
|
|
||||||
for(int i=0;i<32;i++)/** modified for Aldo*/
|
|
||||||
ret_val = !bebs->SetBebSrcHeaderInfos(n[0],n[1],tmp_str[0],tmp_str[1],n[3])||!bebs->SetUpUDPHeader(n[0],n[1],n[2]+i,tmp_str[2],tmp_str[3],n[4]);
|
|
||||||
|
|
||||||
if(ret_val) return_message.append("\tError Executing: SetupTableEntry ");
|
|
||||||
else return_message.append("\tExecuted: SetupTableEntry ");
|
|
||||||
AddNumber(return_message,n[0]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[1]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[2]);return_message.append(" ");
|
|
||||||
return_message.append(tmp_str[0]);return_message.append(" ");
|
|
||||||
return_message.append(tmp_str[1]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[3]);return_message.append(" ");
|
|
||||||
return_message.append(tmp_str[2]);return_message.append(" ");
|
|
||||||
return_message.append(tmp_str[3]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[4]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evTest :
|
|
||||||
n[0] = atoi(GetNextString(data).data());
|
|
||||||
if(n[0]<1){
|
|
||||||
return_message.append("\tError executing: Test <beb_number>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}else{
|
|
||||||
ret_val = !bebs->Test(n[0]);
|
|
||||||
if(ret_val) return_message.append("\tError Executing: Test ");
|
|
||||||
else return_message.append("\tExecuted: Test ");
|
|
||||||
AddNumber(return_message,n[0]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case evTestSend :
|
|
||||||
n[0] = atoi(GetNextString(data).data()); //beb_number;
|
|
||||||
n[1] = atoi(GetNextString(data).data()); //giga bit, ten giga bit
|
|
||||||
n[2] = atoi((tmp_str[0]=GetNextString(data)).data()); //header_number
|
|
||||||
|
|
||||||
if(n[0]<1||(n[1]!=0&&n[1]!=1)||(n[2]<0||n[2]>63)||tmp_str[0].length()<1){
|
|
||||||
return_message.append("\tError executing: TestSend <beb_number> <1GbE(0) or 10GbE(1)> <dst_number>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}else{
|
|
||||||
ret_val = !bebs->SendMultiReadRequest(n[0],1,n[1],n[2],1,0);
|
|
||||||
|
|
||||||
if(ret_val) return_message.append("\tError Executing: TestSend ");
|
|
||||||
else return_message.append("\tExecuted: TestSend ");
|
|
||||||
AddNumber(return_message,n[0]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[1]);return_message.append(" ");
|
|
||||||
AddNumber(return_message,n[2]);return_message.append(" ");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evExitServer :
|
|
||||||
return_message.append("\tExiting Server ....\n");
|
|
||||||
stop = 1;
|
|
||||||
ret_val = -200;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default :
|
|
||||||
return_message.append("\tWarning command \"");
|
|
||||||
return_message.append(cmd);
|
|
||||||
return_message.append("\" not found.\n");
|
|
||||||
return_message.append("\t\tValid commands: ");
|
|
||||||
map<string, cmd_string>::iterator it = enum_map.begin();
|
|
||||||
while(it!=enum_map.end()){
|
|
||||||
return_message.append((it++)->first);
|
|
||||||
return_message.append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_val=-100;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return_message.append("\n");
|
|
||||||
AddNumber(return_message,ret_val,return_start_pos);
|
|
||||||
if(ret_val!=0) break;
|
|
||||||
|
|
||||||
cmd = GetNextString(data);
|
|
||||||
}
|
|
||||||
return_message.append("\n\n\n");
|
|
||||||
|
|
||||||
AddNumber(return_message,ret_val,0);
|
|
||||||
cout<<return_message.c_str()<<endl;
|
|
||||||
cout<<"\treturn: "<<ret_val<<endl;
|
|
||||||
|
|
||||||
if(!WriteNClose(return_message.c_str(),return_message.length())) return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
delete bebs;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
string LowerCase(string str){
|
|
||||||
string s = str;
|
|
||||||
string::iterator i = s.begin();
|
|
||||||
while(i!=s.end()) *i=tolower(*(i++));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
string GetNextString(string str,bool start_from_beginning){
|
|
||||||
static string::size_type start_pos = 0;
|
|
||||||
if(start_from_beginning) start_pos = 0;
|
|
||||||
|
|
||||||
while(start_pos != string::npos){
|
|
||||||
string::size_type found = str.find_first_of(" ",start_pos);
|
|
||||||
string sub = str.substr(start_pos,found-start_pos);
|
|
||||||
|
|
||||||
start_pos = found;
|
|
||||||
if(start_pos != string::npos) start_pos+=1;
|
|
||||||
|
|
||||||
sub.erase(remove_if(sub.begin(),sub.end(), ::isspace ),sub.end());
|
|
||||||
|
|
||||||
if(sub.length()>0) return sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AddNumber(string& str, int n, int location){
|
|
||||||
static char retval_st[100];
|
|
||||||
sprintf(retval_st,"%d",n);
|
|
||||||
|
|
||||||
if(location<0) str.append(retval_st);
|
|
||||||
else str.insert(location,retval_st);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SetupListenSocket(unsigned short int port){
|
|
||||||
server_list_s=0;
|
|
||||||
server_conn_s=0;
|
|
||||||
|
|
||||||
if((server_list_s = socket(AF_INET, SOCK_STREAM, 0))<0) return 0;
|
|
||||||
|
|
||||||
struct sockaddr_in servaddr; /* socket address structure */
|
|
||||||
memset(&servaddr, 0, sizeof(servaddr));
|
|
||||||
servaddr.sin_family = AF_INET;
|
|
||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
||||||
servaddr.sin_port = htons(port);
|
|
||||||
|
|
||||||
if(bind(server_list_s,(struct sockaddr *) &servaddr,sizeof(servaddr))<0) return 0;
|
|
||||||
|
|
||||||
if(listen(server_list_s,32) < 0){ // 1024 /* Backlog for listen() */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int AccpetConnectionAndWaitForData(char* buffer, int maxlength){
|
|
||||||
if(server_list_s==0||maxlength<=0) return 0;
|
|
||||||
|
|
||||||
if((server_conn_s = accept(server_list_s,NULL,NULL))< 0) return 0;
|
|
||||||
|
|
||||||
int nread = read(server_conn_s,buffer,maxlength-1);
|
|
||||||
|
|
||||||
if(nread<0) return 0;
|
|
||||||
|
|
||||||
buffer[nread]='\0';
|
|
||||||
return nread;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WriteNClose(const char* buffer, int length){
|
|
||||||
if(server_conn_s==0||length<=0) return 0;
|
|
||||||
|
|
||||||
int nsent = write(server_conn_s,buffer,length);
|
|
||||||
if(close(server_conn_s)<0) return 0;
|
|
||||||
|
|
||||||
server_conn_s=0;
|
|
||||||
return (nsent==length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
Internal setup:
|
|
||||||
setdac
|
|
||||||
trimbits
|
|
||||||
rate correction tau
|
|
||||||
high voltage
|
|
||||||
|
|
||||||
|
|
||||||
Setup:
|
|
||||||
photon energy
|
|
||||||
dynamic range (4,8,16,32)
|
|
||||||
number of images
|
|
||||||
exposure time
|
|
||||||
exposure period
|
|
||||||
readout speed(full speed, 1/2 speed, 1/4 or super slow)
|
|
||||||
readout mode (parallel, non-parallel or super safe)
|
|
||||||
trigger mode (internal,external start of series, external start of acquisitions, external window)
|
|
||||||
trigger polarity (pos/neg)
|
|
||||||
external gating (on, pos/neg)
|
|
||||||
|
|
||||||
|
|
||||||
Acquisition:
|
|
||||||
start acquisition
|
|
||||||
stop acquisition
|
|
||||||
acquisition in progress
|
|
||||||
wait until daq is finished
|
|
||||||
status (needs to be implemented)
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -1,179 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef EIGER_H
|
|
||||||
#define EIGER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Feb.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Module{
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int module_number;
|
|
||||||
bool top_address_valid;
|
|
||||||
unsigned int top_left_address;
|
|
||||||
unsigned int top_right_address;
|
|
||||||
bool 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;
|
|
||||||
float* top_dac;
|
|
||||||
float* bottom_dac;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Module(unsigned int number, unsigned int address_top); //for half module()
|
|
||||||
Module(unsigned int number, unsigned int address_top, unsigned int address_bottom);
|
|
||||||
~Module();
|
|
||||||
|
|
||||||
static const unsigned int ndacs;
|
|
||||||
static const std::string dac_names[16];
|
|
||||||
|
|
||||||
unsigned int GetModuleNumber() {return module_number;}
|
|
||||||
bool TopAddressIsValid() {return top_address_valid;}
|
|
||||||
unsigned int GetTopBaseAddress() {return (top_left_address&0xff);}
|
|
||||||
unsigned int GetTopLeftAddress() {return top_left_address;}
|
|
||||||
unsigned int GetTopRightAddress() {return top_right_address;}
|
|
||||||
unsigned int GetBottomBaseAddress() {return (bottom_left_address&0xff);}
|
|
||||||
bool BottomAddressIsValid() {return bottom_address_valid;}
|
|
||||||
unsigned int GetBottomLeftAddress() {return bottom_left_address;}
|
|
||||||
unsigned int GetBottomRightAddress() {return bottom_right_address;}
|
|
||||||
|
|
||||||
unsigned int SetTopIDelay(unsigned int chip,unsigned int value) { return TopAddressIsValid() &&chip<4 ? (idelay_top[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
|
||||||
unsigned int GetTopIDelay(unsigned int chip) { return chip<4 ? idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
|
||||||
unsigned int SetBottomIDelay(unsigned int chip,unsigned int value) { return BottomAddressIsValid() &&chip<4 ? (idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
|
||||||
unsigned int GetBottomIDelay(unsigned int chip) { return chip<4 ? idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
|
|
||||||
|
|
||||||
float SetHighVoltage(float value) { return TopAddressIsValid() ? (high_voltage=value) : -1;}
|
|
||||||
float GetHighVoltage() { return high_voltage;}
|
|
||||||
|
|
||||||
float SetTopDACVoltage(unsigned int i, float value) { return (i<ndacs && TopAddressIsValid()) ? (top_dac[i]=value) : -1;}
|
|
||||||
float GetTopDACVoltage(unsigned int i) { return (i<ndacs) ? top_dac[i]:-1;}
|
|
||||||
float SetBottomDACVoltage(unsigned int i, float value) { return (i<ndacs && BottomAddressIsValid()) ? (bottom_dac[i]=value) : -1;}
|
|
||||||
float GetBottomDACVoltage(unsigned int i) { return (i<ndacs) ? bottom_dac[i]:-1;}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Eiger:private Feb{
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<Module*> modules;
|
|
||||||
void ClearModules();
|
|
||||||
|
|
||||||
unsigned int staticBits; //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64
|
|
||||||
unsigned int acquireNReadoutMode; //safe or parallel, half or full speed
|
|
||||||
unsigned int triggerMode; //internal timer, external start, external window, signal polarity (external trigger and enable)
|
|
||||||
unsigned int externalEnableMode; //external enabling engaged and it's polarity
|
|
||||||
unsigned int subFrameMode;
|
|
||||||
|
|
||||||
unsigned int photon_energy_eV;
|
|
||||||
|
|
||||||
unsigned int nimages;
|
|
||||||
float exposure_time_in_sec;
|
|
||||||
float exposure_period_in_sec;
|
|
||||||
|
|
||||||
unsigned int trimbit_size;
|
|
||||||
unsigned char* last_downloaded_trimbits;
|
|
||||||
|
|
||||||
void PrintModuleList();
|
|
||||||
bool GetModuleIndex(unsigned int module_number, unsigned int& module_index);
|
|
||||||
bool CheckModuleAddresses(unsigned int top_address, unsigned int bottom_address);
|
|
||||||
bool AddModule(unsigned int module_number, unsigned int top_address);
|
|
||||||
bool AddModule(unsigned int module_number, unsigned int top_address, unsigned int bottom_address, bool half_module=0);
|
|
||||||
|
|
||||||
bool GetDACNumber(std::string s, unsigned int& n);
|
|
||||||
bool SendDACValue(unsigned int dst_num, unsigned int ch, float& value);
|
|
||||||
bool VoltageToDAC(float value, unsigned int& digital, unsigned int nsteps, float vmin, float vmax);
|
|
||||||
float DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
|
|
||||||
|
|
||||||
bool SendHighVoltage(unsigned int module_index, float& value);
|
|
||||||
|
|
||||||
bool SendIDelays(unsigned int dst_num, bool chip_lr, unsigned int channels, unsigned int ndelay_units);
|
|
||||||
|
|
||||||
bool SetStaticBits();
|
|
||||||
bool SetStaticBits(unsigned int the_static_bits);
|
|
||||||
|
|
||||||
unsigned int ConvertTimeToRegister(float time_in_sec);
|
|
||||||
|
|
||||||
bool SetCommandRegister(unsigned int cmd);
|
|
||||||
bool GetDAQStatusRegister(int socket_num, unsigned int &ret_status);
|
|
||||||
bool StartDAQOnlyNWaitForFinish(int sleep_time_us=5000);
|
|
||||||
bool ResetDataStream();
|
|
||||||
|
|
||||||
bool ResetChipCompletely();
|
|
||||||
|
|
||||||
public:
|
|
||||||
Eiger();
|
|
||||||
virtual ~Eiger();
|
|
||||||
|
|
||||||
bool Init();
|
|
||||||
bool ReadSetUpFileToAddModules(std::string file_name);
|
|
||||||
bool ReadSetUpFile(unsigned int module_num, std::string file_name);
|
|
||||||
bool CheckSetup();
|
|
||||||
|
|
||||||
unsigned int GetNModules();
|
|
||||||
unsigned int GetNHalfModules();
|
|
||||||
|
|
||||||
//bool SetHighVoltage(float value);
|
|
||||||
bool SetHighVoltage(unsigned int module_num,float value);
|
|
||||||
|
|
||||||
bool SetPhotonEnergy(unsigned int full_energy_eV);
|
|
||||||
unsigned int GetPhotonEnergy(){return photon_energy_eV;}
|
|
||||||
|
|
||||||
bool SetIDelays(unsigned int module_num, unsigned int ndelay_units);
|
|
||||||
bool SetIDelays(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
|
|
||||||
|
|
||||||
bool SetDAC(std::string s, float value);
|
|
||||||
bool GetDAC(std::string s, float& ret_value);
|
|
||||||
bool GetDACName(unsigned int dac_num, std::string &s);
|
|
||||||
|
|
||||||
bool SetTrimbits(unsigned char* trimbits);
|
|
||||||
unsigned char* GetTrimbits();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Reset();
|
|
||||||
bool StartAcquisition();
|
|
||||||
bool StopAcquisition();
|
|
||||||
bool AcquisitionInProgress();
|
|
||||||
bool WaitForFinishedFlag(int sleep_time_us=5000);
|
|
||||||
|
|
||||||
//functions for setting up exposure
|
|
||||||
void PrintAcquisitionSetup();
|
|
||||||
bool SetNImages(unsigned int n_images);
|
|
||||||
unsigned int GetNImages();
|
|
||||||
bool SetExposureTime(float the_exposure_time_in_sec);
|
|
||||||
float GetExposureTime();
|
|
||||||
bool SetExposurePeriod(float the_exposure_period_in_sec);
|
|
||||||
float GetExposurePeriod();
|
|
||||||
bool SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo);
|
|
||||||
unsigned int GetDynamicRange();
|
|
||||||
bool SetReadoutSpeed(unsigned int readout_speed=0); //0->full,1->half,2->quarter or 3->super_slow
|
|
||||||
bool SetReadoutMode(unsigned int readout_mode=0); //0->parallel,1->non-parallel,2-> safe_mode
|
|
||||||
bool SetTriggerMode(unsigned int trigger_mode=0, bool polarity=1);
|
|
||||||
bool SetExternalEnableMode(bool use_external_enable=0, bool polarity=1);
|
|
||||||
|
|
||||||
|
|
||||||
//functions for testing
|
|
||||||
bool SetTestModeVariable(bool on=1);
|
|
||||||
bool GetTestModeVariable();
|
|
||||||
|
|
||||||
bool FebTest(){return Feb::Test();}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,200 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "slsDetectorServer_defs.h" //include port number
|
|
||||||
|
|
||||||
struct sockaddr_in eiger_back_socket_addr;
|
|
||||||
int eiger_back_max_message_length = 1024;
|
|
||||||
char eiger_back_message[1024];
|
|
||||||
int eiger_back_message_length = 0;
|
|
||||||
int eiger_back_ret_val=0;
|
|
||||||
|
|
||||||
|
|
||||||
int bit_mode=0;
|
|
||||||
int ten_giga=0;
|
|
||||||
|
|
||||||
int EigerBackInit(){
|
|
||||||
static int passed = 0;
|
|
||||||
|
|
||||||
if(!passed){
|
|
||||||
struct hostent *dst_host;
|
|
||||||
if((dst_host = gethostbyname("localhost")) == NULL){ //or look into getaddrinfo(3)
|
|
||||||
fprintf(stderr,"ERROR, no such host\n");
|
|
||||||
return 0;
|
|
||||||
}else{
|
|
||||||
//struct sockaddr_in eiger_back_socket_addr;
|
|
||||||
int port = BEB_PORT;
|
|
||||||
bzero((char *) &eiger_back_socket_addr, sizeof(eiger_back_socket_addr));
|
|
||||||
eiger_back_socket_addr.sin_family = AF_INET;
|
|
||||||
bcopy((char *)dst_host->h_addr,(char *)&eiger_back_socket_addr.sin_addr.s_addr,dst_host->h_length);
|
|
||||||
eiger_back_socket_addr.sin_port = htons(port);
|
|
||||||
passed = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerBackSendCMD(){
|
|
||||||
if(!EigerBackInit()||eiger_back_message_length<=0) return 0;
|
|
||||||
|
|
||||||
int sockfd = socket(AF_INET,SOCK_STREAM,0);
|
|
||||||
if(sockfd<0){
|
|
||||||
fprintf(stderr,"ERROR opening socket\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(connect(sockfd,(struct sockaddr *) &eiger_back_socket_addr,sizeof(eiger_back_socket_addr))<0){
|
|
||||||
fprintf(stderr,"ERROR connecting\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int n = write(sockfd,eiger_back_message,eiger_back_message_length);
|
|
||||||
int ret_length = read(sockfd,eiger_back_message,eiger_back_max_message_length);
|
|
||||||
|
|
||||||
close(sockfd);
|
|
||||||
|
|
||||||
if(n<0||ret_length<0) return 0;
|
|
||||||
|
|
||||||
|
|
||||||
//fprintf(stdout,"%s\n",eiger_back_message);
|
|
||||||
if(eiger_back_ret_val>0){
|
|
||||||
int i=0;
|
|
||||||
eiger_back_message[1]='\0';
|
|
||||||
if(atoi(eiger_back_message)!=0) return 0;
|
|
||||||
|
|
||||||
for(i=2;i<ret_length;i++){
|
|
||||||
if(eiger_back_message[i] == ' '){
|
|
||||||
//fprintf(stdout," in : %d \n",i);
|
|
||||||
eiger_back_message[i]='\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eiger_back_ret_val = atoi(&eiger_back_message[2]);
|
|
||||||
//fprintf(stdout," the \"%s\" %d\n",&eiger_back_message[2],eiger_back_ret_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
eiger_back_message_length = 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetBitMode(int i){
|
|
||||||
eiger_back_ret_val=0;
|
|
||||||
eiger_back_message_length = sprintf(eiger_back_message,"setbitmode %d",i);
|
|
||||||
bit_mode = i;
|
|
||||||
return EigerBackSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerGetBitMode(){
|
|
||||||
return bit_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
//SetupTableEntry <beb_number> <1GbE(0) or 10GbE(1)> <dst_number> <src_mac> <src_ip> <src_port> <dst_mac> <dst_ip> <dst_port>
|
|
||||||
int EigerSetupTableEntryLeft(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport){
|
|
||||||
char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50];
|
|
||||||
|
|
||||||
int src_port = 0xE185;
|
|
||||||
int dst_port = udpport;
|
|
||||||
sprintf(src_ip,"%d.%d.%d.%d",(detipad>>24)&0xff,(detipad>>16)&0xff,(detipad>>8)&0xff,(detipad)&0xff);
|
|
||||||
sprintf(dst_ip,"%d.%d.%d.%d",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff);
|
|
||||||
sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((detectormacadd>>40)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>32)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>24)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>16)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>8)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>0)&0xFF));
|
|
||||||
sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((macad>>40)&0xFF),
|
|
||||||
(unsigned int)((macad>>32)&0xFF),
|
|
||||||
(unsigned int)((macad>>24)&0xFF),
|
|
||||||
(unsigned int)((macad>>16)&0xFF),
|
|
||||||
(unsigned int)((macad>>8)&0xFF),
|
|
||||||
(unsigned int)((macad>>0)&0xFF));
|
|
||||||
|
|
||||||
printf("Seting up Table Entry Left:\n");
|
|
||||||
printf("src_port:%d\n",src_port);
|
|
||||||
printf("dst_port:%d\n",dst_port);
|
|
||||||
printf("src_ip:%s\n",src_ip);
|
|
||||||
printf("dst_ip:%s\n",dst_ip);
|
|
||||||
printf("src_mac:%s\n",src_mac);
|
|
||||||
printf("dst_mac:%s\n\n",dst_mac);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eiger_back_ret_val=0;
|
|
||||||
eiger_back_message_length = sprintf(eiger_back_message,"setuptableentry %d %d %d %s %s %d %s %s %d",34,ten_giga,0,src_mac,src_ip,src_port,dst_mac,dst_ip,dst_port);
|
|
||||||
return EigerBackSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetupTableEntryRight(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport){
|
|
||||||
char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50];
|
|
||||||
|
|
||||||
int src_port = 0xE185;
|
|
||||||
int dst_port = udpport+1;
|
|
||||||
sprintf(src_ip,"%d.%d.%d.%d",(detipad>>24)&0xff,(detipad>>16)&0xff,(detipad>>8)&0xff,(detipad)&0xff);
|
|
||||||
sprintf(dst_ip,"%d.%d.%d.%d",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff);
|
|
||||||
sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((detectormacadd>>40)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>32)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>24)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>16)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>8)&0xFF),
|
|
||||||
(unsigned int)((detectormacadd>>0)&0xFF));
|
|
||||||
sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((macad>>40)&0xFF),
|
|
||||||
(unsigned int)((macad>>32)&0xFF),
|
|
||||||
(unsigned int)((macad>>24)&0xFF),
|
|
||||||
(unsigned int)((macad>>16)&0xFF),
|
|
||||||
(unsigned int)((macad>>8)&0xFF),
|
|
||||||
(unsigned int)((macad>>0)&0xFF));
|
|
||||||
|
|
||||||
printf("Seting up Table Entry Right:\n");
|
|
||||||
printf("src_port:%d\n",src_port);
|
|
||||||
printf("dst_port:%d\n",dst_port);
|
|
||||||
printf("src_ip:%s\n",src_ip);
|
|
||||||
printf("dst_ip:%s\n",dst_ip);
|
|
||||||
printf("src_mac:%s\n",src_mac);
|
|
||||||
printf("dst_mac:%s\n\n",dst_mac);
|
|
||||||
|
|
||||||
eiger_back_ret_val=0;
|
|
||||||
eiger_back_message_length = sprintf(eiger_back_message,"setuptableentry %d %d %d %s %s %d %s %s %d",34,ten_giga,32,src_mac,src_ip,src_port,dst_mac,dst_ip,dst_port);
|
|
||||||
return EigerBackSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int RequestImages(){
|
|
||||||
printf("Going to request images\n");
|
|
||||||
eiger_back_ret_val=0;
|
|
||||||
eiger_back_message_length = sprintf(eiger_back_message,"requestimages %d",0); // dst_number
|
|
||||||
return EigerBackSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int SetDestinationParameters(int i){
|
|
||||||
eiger_back_ret_val=0;
|
|
||||||
eiger_back_message_length = sprintf(eiger_back_message,"setdstparameters %d %d %d",ten_giga,1,i);// number of dsts
|
|
||||||
return EigerBackSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SetTenGigbaBitEthernet(int val){
|
|
||||||
ten_giga = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int GetTenGigbaBitEthernet(){
|
|
||||||
return ten_giga;
|
|
||||||
}
|
|
@ -1,363 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "slsDetectorServer_defs.h" //include port number
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int eiger_nexposures = 1;
|
|
||||||
float eiger_exposuretime = 0;
|
|
||||||
float eiger_exposureperiod = 0;
|
|
||||||
int eiger_ncycles = 1;
|
|
||||||
int eiger_ngates = 0;
|
|
||||||
int eiger_getphotonenergy = 0;
|
|
||||||
int eiger_dynamicrange = 0;
|
|
||||||
int eiger_readoutspeed = 0;
|
|
||||||
int eiger_readoutmode = 0;
|
|
||||||
int eiger_highvoltage = 0;
|
|
||||||
int eiger_iodelay = 0;
|
|
||||||
int eiger_triggermode = 0;
|
|
||||||
int eiger_extgating = 0;
|
|
||||||
int eiger_extgatingpolarity = 0;
|
|
||||||
|
|
||||||
const unsigned int ndacs = 16;
|
|
||||||
const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};
|
|
||||||
|
|
||||||
int saved_trimbits[256*256*4];
|
|
||||||
|
|
||||||
|
|
||||||
int EigerGetNumberOfExposures(){return eiger_nexposures;}
|
|
||||||
float EigerGetExposureTime(){return eiger_exposuretime;}
|
|
||||||
float EigerGetExposurePeriod(){return eiger_exposureperiod;}
|
|
||||||
int EigerGetNumberOfCycles(){return eiger_ncycles;}
|
|
||||||
/*int EigerGetNumberOfGates(){return eiger_ngates;}*/
|
|
||||||
unsigned int EigerGetDynamicRange(){return eiger_dynamicrange;}
|
|
||||||
int EigerGetPhotonEnergy(){return eiger_getphotonenergy;}
|
|
||||||
int EigerGetReadoutSpeed(){return eiger_readoutspeed;}
|
|
||||||
int EigerGetReadoutMode(){return eiger_readoutmode;}
|
|
||||||
int EigerGetHighVoltage(){return eiger_highvoltage;}
|
|
||||||
int EigerGetIODelay(){return eiger_iodelay;}
|
|
||||||
int EigerGetTriggerMode(){return eiger_triggermode;}
|
|
||||||
int EigerGetExternalGating(){return eiger_extgating;}
|
|
||||||
int EigerGetExternalGatingPolarity(){return eiger_extgatingpolarity;}
|
|
||||||
|
|
||||||
int EigerInit(){
|
|
||||||
saved_trimbits[0] = -1;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSendCMD(){
|
|
||||||
if(!EigerInit()||eiger_message_length<=0) return 0;
|
|
||||||
|
|
||||||
int sockfd = socket(AF_INET,SOCK_STREAM,0);
|
|
||||||
if(sockfd<0){
|
|
||||||
fprintf(stderr,"ERROR opening socket\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(connect(sockfd,(struct sockaddr *) &eiger_socket_addr,sizeof(eiger_socket_addr))<0){
|
|
||||||
fprintf(stderr,"ERROR connecting\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int n = write(sockfd,eiger_message,eiger_message_length);
|
|
||||||
|
|
||||||
int ret_length = read(sockfd,eiger_message,eiger_max_message_length);
|
|
||||||
|
|
||||||
close(sockfd);
|
|
||||||
|
|
||||||
if(n<0||ret_length<0) return 0;
|
|
||||||
|
|
||||||
|
|
||||||
//fprintf(stdout,"%s\n",eiger_message);
|
|
||||||
if(eiger_ret_val>0){
|
|
||||||
int i=0;
|
|
||||||
eiger_message[1]='\0';
|
|
||||||
if(atoi(eiger_message)!=0) return 0;
|
|
||||||
|
|
||||||
for(i=2;i<ret_length;i++){
|
|
||||||
if(eiger_message[i] == ' '){
|
|
||||||
//fprintf(stdout," in : %d \n",i);
|
|
||||||
eiger_message[i]='\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eiger_ret_val = atoi(&eiger_message[2]);
|
|
||||||
//fprintf(stdout," the \"%s\" %d\n",&eiger_message[2],eiger_ret_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
eiger_message_length = 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* EigerGetDACName(int i){
|
|
||||||
if(i>0&&i<ndacs) return dac_names[i];
|
|
||||||
return dac_names[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetDAC(const char* iname,int v, int mV){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
if(mV)
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setdacvoltage %s %d",iname,v);
|
|
||||||
else
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setdacvalue %s %d",iname,v);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetTrimbits(const int *data){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
/*char tt[263681];
|
|
||||||
tt[263680]='\0';
|
|
||||||
int ip=0, ich=0;
|
|
||||||
int iy, ix;
|
|
||||||
int ichip;
|
|
||||||
|
|
||||||
// convert the trimbits from int32 to chars and add border pixels.
|
|
||||||
for(iy=0;iy<256;iy++) {
|
|
||||||
for (ichip=0; ichip<4; ichip++) {
|
|
||||||
for(ix=0;ix<256;ix++) {
|
|
||||||
tt[ip++]=(char)((data[ich++]&(0x3f))+'0');
|
|
||||||
}
|
|
||||||
if (ichip<3) {
|
|
||||||
tt[ip++]=(char)(0+'0');
|
|
||||||
tt[ip++]=(char)(0+'0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
|
|
||||||
memcpy(saved_trimbits,data,256*256*4*sizeof(int));*/
|
|
||||||
|
|
||||||
eiger_message_length = sprintf(eiger_message,"settrimbits %d", 0);
|
|
||||||
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetAllTrimbits(unsigned int value){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
/*char tt[263681];
|
|
||||||
tt[263680]='\0';
|
|
||||||
int ip=0, ich=0;
|
|
||||||
int iy, ix;
|
|
||||||
int ichip;
|
|
||||||
int sl=0;
|
|
||||||
|
|
||||||
|
|
||||||
// convert the trimbits from int32 to chars and add border pixels.
|
|
||||||
for(iy=0;iy<256;iy++) {
|
|
||||||
for (ichip=0; ichip<4; ichip++) {
|
|
||||||
for(ix=0;ix<256;ix++) {
|
|
||||||
tt[ip++]=(char)((value&0x3f)+'0');
|
|
||||||
}
|
|
||||||
if (ichip<3) {
|
|
||||||
tt[ip++]=(char)(0+'0');
|
|
||||||
tt[ip++]=(char)(0+'0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eiger_message_length = sprintf(eiger_message,"settrimbits %s", tt);
|
|
||||||
for(iy=0;iy<256*256*4;++iy)
|
|
||||||
saved_trimbits[iy] = value;*/
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setalltrimbits %d", value);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int EigerGetTrimbits(const int *data){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
/*char tt[263681];
|
|
||||||
tt[263680]='\0';
|
|
||||||
int ip=0, ich=0;
|
|
||||||
int iy, ix;
|
|
||||||
int ichip;
|
|
||||||
|
|
||||||
eiger_message_length = sprintf(eiger_message,"gettrimbits ");
|
|
||||||
memcpy(data,saved_trimbits,256*256*4*sizeof(int));*/
|
|
||||||
|
|
||||||
eiger_message_length = sprintf(eiger_message,"gettrimbits ");
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int EigerGetDAC(const char* iname){
|
|
||||||
eiger_ret_val=1;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"getdacvalue %s",iname);
|
|
||||||
if(!EigerSendCMD()) return -1;
|
|
||||||
return eiger_ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerGetDACmV(const char* iname){
|
|
||||||
eiger_ret_val=1;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"getdacvoltage %s",iname);
|
|
||||||
if(!EigerSendCMD()) return -1;
|
|
||||||
return eiger_ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetNumberOfExposures(unsigned int n){
|
|
||||||
eiger_nexposures = n;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setnumberofexposures %u",eiger_nexposures*eiger_ncycles);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetExposureTime(float v){
|
|
||||||
eiger_exposuretime = v;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setexposuretime %f",v);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetExposurePeriod(float v){
|
|
||||||
eiger_exposureperiod = v;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setexposureperiod %f",v);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetNumberOfCycles(unsigned int n){
|
|
||||||
eiger_ncycles = n;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setnumberofexposures %u",eiger_nexposures*eiger_ncycles);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
int EigerSetNumberOfGates(unsigned int n){
|
|
||||||
eiger_ngates = n;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setnumberofexposures %u",n);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
int EigerSetDynamicRange(unsigned int i){
|
|
||||||
eiger_dynamicrange = i;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setbitmode %u",i);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerSetPhotonEnergy(int in_eV){
|
|
||||||
eiger_getphotonenergy = in_eV;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setphotonenergy %d",in_eV);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetReadoutSpeed(int speed){
|
|
||||||
eiger_readoutspeed = speed;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setreadoutspeed %d",speed);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetReadoutMode(int mode){
|
|
||||||
eiger_readoutmode = mode;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setreadoutmode %d",mode);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetHighVoltage(int hv){
|
|
||||||
eiger_highvoltage = hv;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"sethighvoltage %d",hv);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetIODelay(int io){
|
|
||||||
eiger_iodelay = io;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setinputdelays %d",io);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetTriggerMode(int m){
|
|
||||||
eiger_triggermode = m;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"settriggermode %d",m);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerSetExternalGating(int e, int p){
|
|
||||||
eiger_extgating = e;
|
|
||||||
eiger_extgatingpolarity = p;
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"setexternalgating %d %d",e,p);
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerStartAcquisition(){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"startacquisition");
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int EigerRunStatus(){
|
|
||||||
eiger_ret_val=1;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"isdaqstillrunning");
|
|
||||||
if(!EigerSendCMD()) return -1;
|
|
||||||
return eiger_ret_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerStopAcquisition(){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"stopacquisition");
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
int EigerWaitForAcquisitionFinish(){
|
|
||||||
eiger_ret_val=0;
|
|
||||||
eiger_message_length = sprintf(eiger_message,"waituntildaqfinished");
|
|
||||||
return EigerSendCMD();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TESTEIGERFUNCTIONS
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
int v=220;
|
|
||||||
char n[2000] = "Vcmp_lr";
|
|
||||||
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetDAC(EigerGetDACName(7),2200));
|
|
||||||
int t = EigerGetDAC(EigerGetDACName(7));
|
|
||||||
fprintf(stdout," v : %d\n",t);
|
|
||||||
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetDAC(n,v));
|
|
||||||
t = EigerGetDAC(n);
|
|
||||||
fprintf(stdout," ret : %d\n",t);
|
|
||||||
|
|
||||||
float f=0.12;
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetNumberOfExposures(120));
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetExposureTime(0.12));
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetExposurePeriod(0.22));
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetPhotonEnergy(9200));
|
|
||||||
fprintf(stdout," ret : %d\n",EigerSetDynamicRange(16));
|
|
||||||
fprintf(stdout," ret : %d\n",EigerStartAcquisition());
|
|
||||||
fprintf(stdout," aret : %d\n",EigerRunStatus());
|
|
||||||
sleep(1);
|
|
||||||
fprintf(stdout," ret : %d\n",EigerStopAcquisition());
|
|
||||||
fprintf(stdout," bret : %d\n",EigerRunStatus());
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//daq register definitions
|
|
||||||
#define DAQ_REG_CTRL 1
|
|
||||||
#define DAQ_REG_CHIP_CMDS 2
|
|
||||||
#define DAQ_REG_STATIC_BITS 3
|
|
||||||
#define DAQ_REG_CLK_ROW_CLK_NTIMES 3
|
|
||||||
#define DAQ_REG_SHIFT_IN_32 3
|
|
||||||
#define DAQ_REG_READOUT_NROWS 3
|
|
||||||
#define DAQ_REG_SEND_N_TESTPULSES 3
|
|
||||||
|
|
||||||
#define DAQ_REG_NEXPOSURES 3
|
|
||||||
#define DAQ_REG_EXPOSURE_TIMER 4 // == (31 downto 3) * 10^(2 downto 0)
|
|
||||||
#define DAQ_REG_EXPOSURE_REPEAT_TIMER 5 // == (31 downto 3) * 10^(2 downto 0)
|
|
||||||
#define DAQ_REG_STATUS 6 //also pg and fifo status register
|
|
||||||
|
|
||||||
#define DAQ_CTRL_RESET 0x80000000
|
|
||||||
#define DAQ_CTRL_START 0x40000000
|
|
||||||
#define ACQ_CTRL_START 0x50000000 //this is 0x10000000 (acq) | 0x40000000 (daq)
|
|
||||||
#define DAQ_CTRL_STOP 0x00000000
|
|
||||||
|
|
||||||
//direct chip commands to the DAQ_REG_CHIP_CMDS register
|
|
||||||
#define DAQ_SET_STATIC_BIT 0x00000001
|
|
||||||
#define DAQ_RESET_COMPLETELY 0x0000000E
|
|
||||||
#define DAQ_RESET_PERIPHERY 0x00000002
|
|
||||||
#define DAQ_RESET_PIXEL_COUNTERS 0x00000004
|
|
||||||
#define DAQ_RESET_COLUMN_SELECT 0x00000008
|
|
||||||
|
|
||||||
#define DAQ_STORE_IMAGE 0x00000010
|
|
||||||
#define DAQ_RELEASE_IMAGE_STORE 0x00000020
|
|
||||||
|
|
||||||
#define DAQ_SEND_A_TOKEN_IN 0x00000040
|
|
||||||
#define DAQ_CLK_ROW_CLK_NTIMES 0x00000080
|
|
||||||
#define DAQ_SERIALIN_SHIFT_IN_32 0x00000100
|
|
||||||
#define DAQ_LOAD_16ROWS_OF_TRIMBITS 0x00000200
|
|
||||||
|
|
||||||
#define DAQ_IGNORE_INITIAL_CRAP 0x00000400 //crap before readout
|
|
||||||
#define DAQ_READOUT_NROWS 0x00000800
|
|
||||||
#define DAQ_CLKOUT_LAST_4_BITS_AND_RETURN_TO_START 0x00001000 //last 4 bit of data in the last frame
|
|
||||||
|
|
||||||
#define DAQ_RELEASE_IMAGE_STORE_AFTER_READOUT 0x00002000
|
|
||||||
#define DAQ_RESET_PIXEL_COUNTERS_AFTER_READOUT 0x00004000
|
|
||||||
|
|
||||||
#define DAQ_CLK_ROW_CLK_TO_SELECT_NEXT_ROW 0x00008000
|
|
||||||
#define DAQ_CLK_MAIN_CLK_TO_SELECT_NEXT_PIXEL 0x00010000
|
|
||||||
#define DAQ_SEND_N_TEST_PULSES 0x00020000
|
|
||||||
|
|
||||||
#define DAQ_CHIP_CONTROLLER_HALF_SPEED 0x00040000 //everything at 100 MHz (50MHz ddr readout)
|
|
||||||
#define DAQ_CHIP_CONTROLLER_QUARTER_SPEED 0x00080000 //everything at 50 MHz (25MHz ddr readout)
|
|
||||||
#define DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED 0x000c0000 //everything at ~200 kHz (200 kHz MHz ddr readout)
|
|
||||||
|
|
||||||
#define DAQ_FIFO_ENABLE 0x00100000
|
|
||||||
|
|
||||||
//direct chip commands to the DAQ_REG_CHIP_CMDS register
|
|
||||||
#define DAQ_NEXPOSURERS_SAFEST_MODE_ROW_CLK_BEFORE_MODE 0x00200000 //row clk is before main clk readout sequence
|
|
||||||
#define DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE 0x00400000 //expose ->readout ->expose -> ..., with store is always closed
|
|
||||||
#define DAQ_NEXPOSURERS_PARALLEL_MODE 0x00600000 //parallel acquire/read mode
|
|
||||||
|
|
||||||
//DAQ_NEXPOSURERS_READOUT_COMPLETE_IMAGES is old now hard-wired in the firmware that every image comes with a header
|
|
||||||
//#define DAQ_NEXPOSURERS_READOUT_COMPLETE_IMAGES 0x00800000 //DAQ_IGNORE_INITIAL_CRAP and DAQ_CLKOUT_LAST_4_BITS_AND_RETURN_TO_START
|
|
||||||
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_ENABLING 0x01000000
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY 0x02000000
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY 0x04000000
|
|
||||||
|
|
||||||
#define DAQ_NEXPOSURERS_INTERNAL_ACQUISITION 0x00000000 //internally controlled
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START 0x08000000 //external acquisition start
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START 0x10000000 //external image start
|
|
||||||
#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP 0x18000000 //externally controlly, external image start and stop
|
|
||||||
|
|
||||||
#define DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING 0x20000000
|
|
||||||
#define DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION 0x40000000
|
|
||||||
|
|
||||||
//#define DAQ_MASTER_HALF_MODULE 0x80000000 currently not used
|
|
||||||
|
|
||||||
|
|
||||||
//chips static bits
|
|
||||||
#define DAQ_STATIC_BIT_PROGRAM 0x00000001
|
|
||||||
#define DAQ_STATIC_BIT_M4 0x00000002 //these are the status bits, not bit mode
|
|
||||||
#define DAQ_STATIC_BIT_M8 0x00000004 //these are the status bits, not bit mode
|
|
||||||
#define DAQ_STATIC_BIT_M12 0x00000000 //these are the status bits, not bit mode, ie. "00" is 12 bit mode
|
|
||||||
#define DAQ_STATIC_BIT_CHIP_TEST 0x00000008
|
|
||||||
#define DAQ_STATIC_BIT_ROTEST 0x00000010
|
|
||||||
#define DAQ_CS_BAR_LEFT 0x00000020
|
|
||||||
#define DAQ_CS_BAR_RIGHT 0x00000040
|
|
||||||
|
|
||||||
|
|
||||||
//status flags
|
|
||||||
#define DAQ_STATUS_DAQ_RUNNING 0x01
|
|
||||||
#define DAQ_DATA_COLLISION_ERROR 0x02
|
|
||||||
|
|
||||||
#define DAQ_STATUS_CURRENT_M4 0x04
|
|
||||||
#define DAQ_STATUS_CURRENT_M8 0x08
|
|
||||||
#define DAQ_STATUS_CURRENT_M12 0x00 //in 12 bit mode both are cleared
|
|
||||||
#define DAQ_STATUS_CURRENT_TESTMODE 0x10
|
|
||||||
#define DAQ_STATUS_TOKEN_OUT 0x20
|
|
||||||
#define DAQ_STATUS_SERIAL_OUT 0x40
|
|
||||||
#define DAQ_STATUS_PIXELS_ARE_ENABLED 0x80
|
|
||||||
#define DAQ_STATUS_DAQ_RUN_TOGGLE 0x200
|
|
||||||
|
|
||||||
//data delay registers
|
|
||||||
#define CHIP_DATA_OUT_DELAY_REG_CTRL 1
|
|
||||||
#define CHIP_DATA_OUT_DELAY_REG2 2
|
|
||||||
#define CHIP_DATA_OUT_DELAY_REG3 3
|
|
||||||
#define CHIP_DATA_OUT_DELAY_REG4 4
|
|
||||||
#define CHIP_DATA_OUT_DELAY_SET 0x20000000
|
|
||||||
|
|
||||||
|
|
||||||
//module configuration
|
|
||||||
#define TOP_BIT_MASK 0x00f
|
|
||||||
#define MASTER_BIT_MASK 0x200
|
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "Eiger.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
|
||||||
|
|
||||||
cout<<"\n\n\n\n\n\n\n\n\n\n"<<endl;
|
|
||||||
int n = (argc>1) ? atoi(argv[1]):5;
|
|
||||||
|
|
||||||
//Feb *f = new Feb();
|
|
||||||
// f->Test();
|
|
||||||
//delete f;
|
|
||||||
//return 0;
|
|
||||||
|
|
||||||
Eiger* e = new Eiger();
|
|
||||||
e->SetNImages(n);
|
|
||||||
e->SetDynamicRange(32);
|
|
||||||
e->SetExposureTime(0.02);
|
|
||||||
e->SetExposurePeriod(0.050);
|
|
||||||
e->StartAcquisition();
|
|
||||||
|
|
||||||
delete e;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,326 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//return reversed 1 means good, 0 means failed
|
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
//#include <unistd.h>
|
|
||||||
//#include <string.h>
|
|
||||||
//#include <sys/mman.h>
|
|
||||||
//#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "xparameters.h"
|
|
||||||
|
|
||||||
#include "Feb.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Feb::Feb(){
|
|
||||||
|
|
||||||
nfebs = 0;
|
|
||||||
feb_numb = 0;
|
|
||||||
|
|
||||||
send_ndata = 0;
|
|
||||||
send_buffer_size = 1026;
|
|
||||||
send_data_raw = new unsigned int [send_buffer_size+1];
|
|
||||||
send_data = &send_data_raw[1];
|
|
||||||
|
|
||||||
recv_ndata = 0;
|
|
||||||
recv_buffer_size = 1026;
|
|
||||||
recv_data_raw = new unsigned int [recv_buffer_size+1];
|
|
||||||
recv_data = &recv_data_raw[1];
|
|
||||||
|
|
||||||
ll = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Feb::~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){
|
|
||||||
if(feb_numb) delete [] feb_numb;
|
|
||||||
nfebs = n;
|
|
||||||
feb_numb = new unsigned int [n];
|
|
||||||
for(unsigned int i=0;i<n;i++) feb_numb[i] = list[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Feb::WriteTo(unsigned int ch){
|
|
||||||
if(ch>0xfff) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0x90000000 | (ch<<16); //we
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0xc0000000; //data
|
|
||||||
return ((send_ndata+1)*4==ll->Write((send_ndata+1)*4,send_data_raw));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Feb::ReadFrom(unsigned int ch, unsigned int ntrys){
|
|
||||||
if(ch>=0xfff) return 0;
|
|
||||||
|
|
||||||
recv_data_raw[0] = 0xa0000000 | (ch<<16); //read data
|
|
||||||
ll->Write(4,recv_data_raw);
|
|
||||||
usleep(20);
|
|
||||||
|
|
||||||
recv_ndata=-1;
|
|
||||||
for(unsigned int t=0;t<ntrys;t++){
|
|
||||||
if((recv_ndata=ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0){
|
|
||||||
recv_ndata--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cout<<"\t Read try number: "<<t<<endl;
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (recv_ndata>=0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Feb::PrintData(){
|
|
||||||
cout<<"Sent data: "<<send_ndata<<endl;
|
|
||||||
for(int i=0;i<send_ndata;i++) cout<<"\t"<<i<<")"<<setw(14)<<send_data[i]<<" ("<<hex<<send_data[i]<<")"<<dec<<endl;
|
|
||||||
cout<<"Receive data: "<<recv_ndata<<endl;
|
|
||||||
for(int i=0;i<recv_ndata;i++) cout<<"\t"<<i<<")"<<setw(14)<<recv_data[i]<<" ("<<hex<<recv_data[i]<<")"<<dec<<endl;
|
|
||||||
cout<<endl<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Feb::CheckHeader(unsigned int valid_bit_mask, bool print_error_info){
|
|
||||||
|
|
||||||
bool header_returned_is_ok = (send_data[0] & valid_bit_mask)==(recv_data[0] & valid_bit_mask);
|
|
||||||
|
|
||||||
if(print_error_info && !header_returned_is_ok){
|
|
||||||
cout<<"Error: Command received not the same as command recieved."<<endl;
|
|
||||||
cout<<"\t\t Header sent: "<<dec<<send_data[0]<<" ("<<hex<<send_data[0]<<") recieved: "<<dec<<recv_data[0]<<" ("<<hex<<recv_data[0]<<")"<<dec<<endl;
|
|
||||||
if(send_ndata>1&&recv_ndata>1){
|
|
||||||
cout<<"\t\t Tail sent: "<<dec<<send_data[send_ndata-1]<<" ("<<hex<<send_data[send_ndata-1]<<") recieved: "<<dec<<recv_data[recv_ndata-1]<<" ("<<hex<<recv_data[recv_ndata-1]<<")"<<dec<<endl;
|
|
||||||
}else{
|
|
||||||
cout<<"Error printing tail, too little data nsent = "<<send_ndata<<", nrecv = "<<recv_ndata<<"."<<endl;
|
|
||||||
}
|
|
||||||
PrintData();
|
|
||||||
}
|
|
||||||
return header_returned_is_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Feb::CheckTail(unsigned int valid_bit_mask){
|
|
||||||
if(send_ndata<=1&&recv_ndata<=1){
|
|
||||||
cout<<"Error checking tail, too little data nsent = "<<send_ndata<<", nrecv = "<<recv_ndata<<"."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int the_tail = recv_data[recv_ndata-1]&valid_bit_mask;
|
|
||||||
if(the_tail!=0){
|
|
||||||
cout<<"Error returned in tail: "<<hex<<the_tail<<" "<<dec<<"("<<the_tail<<")"<<endl;
|
|
||||||
if(the_tail&0x10000000) cout<<"\t\tBusy flag address error."<<endl;
|
|
||||||
if(the_tail&0x20000000) cout<<"\t\tRead register address error."<<endl;
|
|
||||||
if(the_tail&0x40000000) cout<<"\t\tWrite register address error."<<endl;
|
|
||||||
if(the_tail&0x80000000) cout<<"\t\tBram number error."<<endl;
|
|
||||||
if(the_tail&0x08000000) cout<<"\t\tFifo to read from error."<<endl;
|
|
||||||
if(the_tail&0x3ff) cout<<"\t\tNumber of data send error."<<endl;
|
|
||||||
return 0; //error
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Feb::CheckCommunication(){
|
|
||||||
send_data_raw[0] = 0x8fff0000; //rst-all serial coms and lls
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
cout<<"Feb::CheckingCommunication ...."<<endl;
|
|
||||||
while((ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0) cout<<"\t) Cleanning buffer ..."<<endl;
|
|
||||||
|
|
||||||
return SetByteOrder();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Feb::SetByteOrder(){
|
|
||||||
|
|
||||||
send_ndata = 2;
|
|
||||||
send_data[0] = 0; //header
|
|
||||||
send_data[1] = 0; //tail
|
|
||||||
|
|
||||||
unsigned int dst = 0xff;
|
|
||||||
for(unsigned int i=0;i<nfebs;i++) dst = (dst | feb_numb[i]); //get sub dst bits (left right in this case)
|
|
||||||
bool passed = WriteTo(dst);
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nfebs;i++){
|
|
||||||
cout<<"\t"<<i<<") Set Byte Order .............. ";
|
|
||||||
unsigned int current_passed = ReadFrom(feb_numb[i])&&(recv_ndata==2)&&CheckHeader();
|
|
||||||
if(current_passed) cout<<"passed."<<endl;
|
|
||||||
else cout<<"failed."<<endl;
|
|
||||||
passed&=current_passed;
|
|
||||||
}
|
|
||||||
cout<<endl;
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
bool Feb::CheckSubNumber(unsigned int sub_num){
|
|
||||||
if(sub_num>=nfebs){
|
|
||||||
cout<<"Error invalid sub number "<<sub_num<<" must be less than "<<nfebs<<"."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool 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 CheckSubNumber(start_on);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool Feb::ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int& value_read){
|
|
||||||
return ReadRegisters(sub_num,1,®_num,&value_read);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Feb::ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
|
|
||||||
//here cout<<"Reading Register ...."<<endl;
|
|
||||||
|
|
||||||
nreads &= 0x3ff; //10 bits
|
|
||||||
if(!nreads||nreads>send_buffer_size-2) return 0;
|
|
||||||
|
|
||||||
send_ndata = nreads+2;
|
|
||||||
send_data[0] = 0x20000000 | nreads << 14; //cmd -> read "00" , nreads
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nreads;i++) send_data[i+1]=reg_nums[i];
|
|
||||||
send_data[nreads+1] = 0; //tail
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)||!ReadFrom(sub_num)||recv_ndata!=int(nreads+2)||!CheckHeader()||!CheckTail()){
|
|
||||||
PrintData();
|
|
||||||
cout<<"Error reading register."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nreads;i++) values_read[i] = recv_data[i+1];
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Feb::WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, bool wait_on, unsigned int wait_on_address){
|
|
||||||
return WriteRegisters(sub_num,1,®_num,&value,&wait_on,&wait_on_address);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Feb::WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, bool* wait_ons, unsigned int* wait_on_addresses){
|
|
||||||
|
|
||||||
// sub_num == 0xfff means write to all
|
|
||||||
|
|
||||||
nwrites &= 0x3ff; //10 bits
|
|
||||||
if(!nwrites||nwrites>send_buffer_size-2) return 0;
|
|
||||||
|
|
||||||
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
|
|
||||||
send_ndata = 2*nwrites+2;
|
|
||||||
send_data[0] = 0x80000000 | nwrites << 14; //cmd -> write nwrites and how many
|
|
||||||
send_data[2*nwrites+1] = 0; //tail
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) send_data[2*i+1] = 0x3fff®_nums[i]; // register address data_in(13 downto 0)
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) 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(unsigned int i=0;i<nwrites;i++) send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)){
|
|
||||||
cout<<sub_num<<") Error writing register(s)."<<endl;
|
|
||||||
PrintData();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool passed = 1;
|
|
||||||
unsigned int n = (sub_num&0xff)==0xff ? nfebs : 1;
|
|
||||||
unsigned int* nums = (sub_num&0xff)==0xff ? feb_numb : &sub_num;
|
|
||||||
for(unsigned int i=0;i<n;i++){
|
|
||||||
if((sub_num&0xf00&(nums[i]))==0) continue;
|
|
||||||
if(!ReadFrom(nums[i])||recv_ndata!=2||!CheckHeader()){
|
|
||||||
cout<<nums[i]<<") Error writing register(s) response."<<endl;
|
|
||||||
PrintData();
|
|
||||||
passed = 0;
|
|
||||||
}else{
|
|
||||||
passed = passed && CheckTail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool 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
|
|
||||||
|
|
||||||
mem_num &= 0x3f; //6 bits
|
|
||||||
start_address &= 0x3fff; //14 bits
|
|
||||||
nwrites &= 0x3ff; //10 bits
|
|
||||||
if(!nwrites||nwrites>send_buffer_size-2) return 0;
|
|
||||||
|
|
||||||
send_ndata = nwrites+2;
|
|
||||||
send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
|
|
||||||
send_data[nwrites+1] = 0; //tail
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) send_data[i+1] = values[i];
|
|
||||||
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)){
|
|
||||||
cout<<sub_num<<") Error writing memory."<<endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool passed = 1;
|
|
||||||
unsigned int n = (sub_num&0xff)==0xff ? nfebs : 1;
|
|
||||||
unsigned int* nums = (sub_num&0xff)==0xff ? feb_numb : &sub_num;
|
|
||||||
for(unsigned int i=0;i<n;i++){
|
|
||||||
if((sub_num&0xf00&(nums[i]))==0) continue;
|
|
||||||
if(!ReadFrom(nums[i])||recv_ndata!=2||!CheckHeader()){
|
|
||||||
cout<<nums[i]<<") Error writing memory response."<<endl;
|
|
||||||
PrintData();
|
|
||||||
passed = 0;
|
|
||||||
}else{
|
|
||||||
passed = passed && CheckTail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool 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 reg_nums[10]={0,1,2,3,1,2,3,1,2,3};
|
|
||||||
|
|
||||||
cout<<"Test"<<endl<<endl<<endl<<endl;
|
|
||||||
|
|
||||||
unsigned int value = 0;
|
|
||||||
for(unsigned int i=0;i<10;i++){
|
|
||||||
WriteRegister(0xfff,reg_nums[i%10],i);
|
|
||||||
ReadRegister(256,reg_nums[i%10],value);
|
|
||||||
cout<<i<<" "<<value<<endl;
|
|
||||||
ReadRegister(512,reg_nums[i%10],value);
|
|
||||||
cout<<i<<" "<<value<<endl;
|
|
||||||
WriteMemory(0xfff,0,0,10,reg_nums);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -607,14 +607,22 @@ int Feb_Control_SendHighVoltage(int dacvalue){
|
|||||||
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
|
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
|
||||||
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0';
|
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0';
|
||||||
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n';
|
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n';
|
||||||
int n = 0;
|
int n;
|
||||||
sprintf(buffer,"p%d ",dacvalue);
|
sprintf(buffer,"p%d ",dacvalue);
|
||||||
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
||||||
|
if (n < 0) {
|
||||||
|
cprintf(RED,"\nWarning: Error writing to i2c bus\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef VERBOSEI
|
#ifdef VERBOSEI
|
||||||
cprintf(BLUE,"Sent %d Bytes\n", n);
|
cprintf(BLUE,"Sent %d Bytes\n", n);
|
||||||
#endif
|
#endif
|
||||||
//ok/fail
|
//ok/fail
|
||||||
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
||||||
|
if (n < 0) {
|
||||||
|
cprintf(RED,"\nWarning: Error reading from i2c bus\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef VERBOSEI
|
#ifdef VERBOSEI
|
||||||
cprintf(BLUE,"Received %d Bytes\n", n);
|
cprintf(BLUE,"Received %d Bytes\n", n);
|
||||||
#endif
|
#endif
|
||||||
@ -686,12 +694,20 @@ int Feb_Control_ReceiveHighVoltage(unsigned int* value){
|
|||||||
//request
|
//request
|
||||||
strcpy(buffer,"g ");
|
strcpy(buffer,"g ");
|
||||||
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
||||||
|
if (n < 0) {
|
||||||
|
cprintf(RED,"\nWarning: Error writing to i2c bus\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef VERBOSEI
|
#ifdef VERBOSEI
|
||||||
cprintf(BLUE,"Sent %d Bytes\n", n);
|
cprintf(BLUE,"Sent %d Bytes\n", n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//ok/fail
|
//ok/fail
|
||||||
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
||||||
|
if (n < 0) {
|
||||||
|
cprintf(RED,"\nWarning: Error reading from i2c bus\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef VERBOSEI
|
#ifdef VERBOSEI
|
||||||
cprintf(BLUE,"Received %d Bytes\n", n);
|
cprintf(BLUE,"Received %d Bytes\n", n);
|
||||||
#endif
|
#endif
|
||||||
@ -701,6 +717,10 @@ int Feb_Control_ReceiveHighVoltage(unsigned int* value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
|
||||||
|
if (n < 0) {
|
||||||
|
cprintf(RED,"\nWarning: Error reading from i2c bus\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef VERBOSEI
|
#ifdef VERBOSEI
|
||||||
cprintf(BLUE,"Received %d Bytes\n", n);
|
cprintf(BLUE,"Received %d Bytes\n", n);
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,175 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
//#include <unistd.h>
|
|
||||||
//#include <string.h>
|
|
||||||
//#include <sys/mman.h>
|
|
||||||
//#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "xparameters.h"
|
|
||||||
|
|
||||||
#include "FebInterface.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
FebInterface::FebInterface(){
|
|
||||||
|
|
||||||
nfebs = 0;
|
|
||||||
feb_numb = 0;
|
|
||||||
|
|
||||||
send_ndata = 0;
|
|
||||||
send_buffer_size = 1026;
|
|
||||||
send_data_raw = new unsigned int [send_buffer_size+1];
|
|
||||||
send_data = &send_data_raw[1];
|
|
||||||
|
|
||||||
recv_ndata = 0;
|
|
||||||
recv_buffer_size = 1026;
|
|
||||||
recv_data_raw = new unsigned int [recv_buffer_size+1];
|
|
||||||
recv_data = &recv_data_raw[1];
|
|
||||||
|
|
||||||
ll = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FebInterface::~FebInterface(){
|
|
||||||
delete ll;
|
|
||||||
if(feb_numb) delete [] feb_numb;
|
|
||||||
delete [] send_data_raw;
|
|
||||||
delete [] recv_data_raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FebInterface::SendCompleteList(unsigned int n,unsigned int* list){
|
|
||||||
if(feb_numb) delete [] feb_numb;
|
|
||||||
nfebs = n;
|
|
||||||
feb_numb = new unsigned int [n];
|
|
||||||
for(unsigned int i=0;i<n;i++) feb_numb[i] = list[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FebInterface::WriteTo(unsigned int ch){
|
|
||||||
if(ch>0xfff) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0x8fff0000;
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0x90000000 | (ch<<16);
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
send_data_raw[0] = 0xc0000000;
|
|
||||||
return ((send_ndata+1)*4==ll->Write((send_ndata+1)*4,send_data_raw));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FebInterface::ReadFrom(unsigned int ch, unsigned int ntrys){
|
|
||||||
if(ch>=0xfff) return 0;
|
|
||||||
|
|
||||||
recv_data_raw[0] = 0xa0000000 | (ch<<16);
|
|
||||||
ll->Write(4,recv_data_raw);
|
|
||||||
usleep(20);
|
|
||||||
|
|
||||||
recv_ndata=-1;
|
|
||||||
for(unsigned int t=0;t<ntrys;t++){
|
|
||||||
if((recv_ndata=ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0){
|
|
||||||
recv_ndata--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (recv_ndata>=0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool FebInterface::SetByteOrder(){
|
|
||||||
|
|
||||||
send_data_raw[0] = 0x8fff0000;
|
|
||||||
if(ll->Write(4,send_data_raw)!=4) return 0;
|
|
||||||
|
|
||||||
send_ndata = 2;
|
|
||||||
send_data[0] = 0;
|
|
||||||
send_data[1] = 0;
|
|
||||||
|
|
||||||
unsigned int dst = 0xff;
|
|
||||||
for(unsigned int i=0;i<nfebs;i++) dst = (dst | feb_numb[i]);
|
|
||||||
bool passed = WriteTo(dst);
|
|
||||||
|
|
||||||
return passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool FebInterface::ReadRegister(unsigned int sub_num, unsigned int reg_num,unsigned int& value_read){
|
|
||||||
return ReadRegisters(sub_num,1,®_num,&value_read);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool FebInterface::ReadRegisters(unsigned int sub_num, unsigned int nreads, unsigned int* reg_nums,unsigned int* values_read){
|
|
||||||
//here cout<<"Reading Register ...."<<endl;
|
|
||||||
|
|
||||||
nreads &= 0x3ff;
|
|
||||||
if(!nreads||nreads>send_buffer_size-2) return 0;
|
|
||||||
|
|
||||||
send_ndata = nreads+2;
|
|
||||||
send_data[0] = 0x20000000 | nreads << 14;
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nreads;i++) send_data[i+1]=reg_nums[i];
|
|
||||||
send_data[nreads+1] = 0;
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)||!ReadFrom(sub_num)||recv_ndata!=int(nreads+2)) return 0;
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nreads;i++) values_read[i] = recv_data[i+1];
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FebInterface::WriteRegister(unsigned int sub_num, unsigned int reg_num,unsigned int value, bool wait_on, unsigned int wait_on_address){
|
|
||||||
return WriteRegisters(sub_num,1,®_num,&value,&wait_on,&wait_on_address);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FebInterface::WriteRegisters(unsigned int sub_num, unsigned int nwrites, unsigned int* reg_nums, unsigned int* values, bool* wait_ons, unsigned int* wait_on_addresses){
|
|
||||||
|
|
||||||
nwrites &= 0x3ff; //10 bits
|
|
||||||
if(!nwrites||2*nwrites>send_buffer_size-2) return 0;
|
|
||||||
|
|
||||||
//cout<<"Write register : "<<this<<" "<<s_num<<" "<<nwrites<<" "<<reg_nums<<" "<<values<<" "<<wait_ons<<" "<<wait_on_addresses<<endl;
|
|
||||||
send_ndata = 2*nwrites+2;
|
|
||||||
send_data[0] = 0x80000000 | nwrites << 14;
|
|
||||||
send_data[2*nwrites+1] = 0;
|
|
||||||
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) send_data[2*i+1] = 0x3fff®_nums[i];
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) 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(unsigned int i=0;i<nwrites;i++) send_data[2*i+1] |= (wait_ons[i]<<28 | (0x3fff&wait_on_addresses[i])<<14);
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool FebInterface::WriteMemory(unsigned int sub_num, unsigned int mem_num, unsigned int start_address, unsigned int nwrites, unsigned int *values){
|
|
||||||
// -1 means write to all
|
|
||||||
|
|
||||||
mem_num &= 0x3f;
|
|
||||||
start_address &= 0x3fff;
|
|
||||||
nwrites &= 0x3ff;
|
|
||||||
if(!nwrites||nwrites>send_buffer_size-2) {cout<<"error herer: nwrites:"<<nwrites<<endl;return 0;}//*d-1026
|
|
||||||
|
|
||||||
send_ndata = nwrites+2;//*d-1025
|
|
||||||
send_data[0] = 0xc0000000 | mem_num << 24 | nwrites << 14 | start_address; //cmd -> write to memory, nwrites, mem number, start address
|
|
||||||
send_data[nwrites+1] = 0;
|
|
||||||
for(unsigned int i=0;i<nwrites;i++) send_data[i+1] = values[i];
|
|
||||||
|
|
||||||
|
|
||||||
if(!WriteTo(sub_num)) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,604 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
* @developed for running Eiger at cSAXS
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <algorithm> // std::remove_if
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <time.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "FebControl.h"
|
|
||||||
#include "slsDetectorServer_defs.h" //include port number
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
enum cmd_string {evNotFound,
|
|
||||||
evReinitialize,evReset,
|
|
||||||
|
|
||||||
evSetInputDelays,
|
|
||||||
evSetDACValue,evGetDACValue,evSetDACVoltage,evGetDACVoltage,evSetHighVoltage,//evGetHighVoltage,
|
|
||||||
|
|
||||||
evSetTrimBits,
|
|
||||||
evSetAllTrimBits,
|
|
||||||
evGetTrimBits,
|
|
||||||
//evLoadTrimBitFile,
|
|
||||||
|
|
||||||
evSetBitMode,
|
|
||||||
evSetPhotonEnergy,
|
|
||||||
// evSetPhotonEnergyCalibrationParameters,evActivateRateCorrection,evDeactivateRateCorrection,evSetRateCorrectionTau,
|
|
||||||
|
|
||||||
evSetReadoutSpeed,evSetReadoutMode,
|
|
||||||
|
|
||||||
//temp solution
|
|
||||||
// evNotFound1,evNotFound2,evNotFound3,
|
|
||||||
|
|
||||||
evSetNumberOfExposures,evSetExposureTime,evSetExposurePeriod,
|
|
||||||
// evSetTriggerPolarityToPositive,evSetTriggerPolarityToNegative,
|
|
||||||
evSetTriggerMode,
|
|
||||||
evSetExternalGating,
|
|
||||||
evStartAcquisition,evStopAcquisition,evIsDaqStillRunning,
|
|
||||||
evWaitUntilDaqFinished,
|
|
||||||
evExitServer
|
|
||||||
};
|
|
||||||
|
|
||||||
map<string, cmd_string> enum_map;
|
|
||||||
|
|
||||||
void init(){
|
|
||||||
|
|
||||||
enum_map["reinitialize"] = evReinitialize;
|
|
||||||
enum_map["reset"] = evReset;
|
|
||||||
enum_map["setinputdelays"] = evSetInputDelays;
|
|
||||||
enum_map["setdacvalue"] = evSetDACValue;
|
|
||||||
enum_map["getdacvalue"] = evGetDACValue;
|
|
||||||
enum_map["setdacvoltage"] = evSetDACVoltage;
|
|
||||||
enum_map["getdacvoltage"] = evGetDACVoltage;
|
|
||||||
enum_map["sethighvoltage"] = evSetHighVoltage;
|
|
||||||
enum_map["settrimbits"] = evSetTrimBits;
|
|
||||||
enum_map["setalltrimbits"] = evSetAllTrimBits;
|
|
||||||
enum_map["gettrimbits"] = evGetTrimBits;
|
|
||||||
// enum_map["loadtrimbitfile"] = evLoadTrimBitFile;
|
|
||||||
enum_map["setbitmode"] = evSetBitMode;
|
|
||||||
enum_map["setphotonenergy"] = evSetPhotonEnergy;
|
|
||||||
// enum_map["setphotonenergycalibrationparameters"] = evSetPhotonEnergyCalibrationParameters;
|
|
||||||
// enum_map["activateratecorrection"] = evActivateRateCorrection;
|
|
||||||
// enum_map["deactivateratecorrection"] = evDeactivateRateCorrection;
|
|
||||||
// enum_map["setratecorrectiontau"] = evSetRateCorrectionTau;
|
|
||||||
enum_map["setreadoutspeed"] = evSetReadoutSpeed;
|
|
||||||
enum_map["setreadoutmode"] = evSetReadoutMode;
|
|
||||||
enum_map["setnumberofexposures"] = evSetNumberOfExposures;
|
|
||||||
enum_map["setexposuretime"] = evSetExposureTime;
|
|
||||||
enum_map["setexposureperiod"] = evSetExposurePeriod;
|
|
||||||
// enum_map["settriggerpolaritytopositive"] = evSetTriggerPolarityToPositive;
|
|
||||||
// enum_map["settriggerpolaritytonegative"] = evSetTriggerPolarityToNegative;
|
|
||||||
enum_map["settriggermode"] = evSetTriggerMode;
|
|
||||||
enum_map["setexternalgating"] = evSetExternalGating;
|
|
||||||
enum_map["startacquisition"] = evStartAcquisition;
|
|
||||||
enum_map["stopacquisition"] = evStopAcquisition;
|
|
||||||
enum_map["isdaqstillrunning"] = evIsDaqStillRunning;
|
|
||||||
enum_map["waituntildaqfinished"] = evWaitUntilDaqFinished;
|
|
||||||
enum_map["exitserver"] = evExitServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int server_list_s;
|
|
||||||
int server_conn_s;
|
|
||||||
int AccpetConnectionAndWaitForData(char* buffer, int maxlength);
|
|
||||||
bool WriteNClose(const char* buffer, int length);
|
|
||||||
bool SetupListenSocket(unsigned short int port);
|
|
||||||
|
|
||||||
|
|
||||||
string LowerCase(string str);
|
|
||||||
string GetNextString(string str,bool start_from_beginning=0);
|
|
||||||
void AddNumber(string& str, int n, int location=-1, bool space_after=0);//-1 means append
|
|
||||||
void AddNumber(string& str, float v, int location=-1, bool space_after=0);//-1 means append
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
|
||||||
cout<<endl<<endl;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(argc<2){
|
|
||||||
cout<<"Usage: feb_server port_number"<<endl<<endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
FebControl *feb_controler = new FebControl();
|
|
||||||
|
|
||||||
unsigned short int port_number = FEB_PORT;
|
|
||||||
if(!SetupListenSocket(port_number)) return 1;
|
|
||||||
|
|
||||||
|
|
||||||
int length=270000;
|
|
||||||
char data[270000];
|
|
||||||
|
|
||||||
int stop = 0;
|
|
||||||
time_t rawtime;
|
|
||||||
struct tm *timeinfo;
|
|
||||||
|
|
||||||
|
|
||||||
while(!stop){
|
|
||||||
|
|
||||||
/*cout<<"Waiting for command -> "<<flush;*/
|
|
||||||
int nread = AccpetConnectionAndWaitForData(data,length);
|
|
||||||
|
|
||||||
if(nread<=0) return 0;
|
|
||||||
|
|
||||||
time(&rawtime); timeinfo=localtime(&rawtime);
|
|
||||||
cout<<asctime(timeinfo);
|
|
||||||
/*cout<<" Command received: "<<data<<endl;*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string tmp_str[5];
|
|
||||||
float v[4];//,v2,v3,v4,v5;
|
|
||||||
int n[5];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string cmd = GetNextString(data,1);
|
|
||||||
int ret_val = 1;
|
|
||||||
|
|
||||||
string return_message = "";/*\n\n\tCommand recieved: ";
|
|
||||||
return_message.append(data);
|
|
||||||
return_message.append("\n");
|
|
||||||
*/
|
|
||||||
int return_start_pos;
|
|
||||||
while(cmd.length()>0){
|
|
||||||
int ret_parameter = 0;
|
|
||||||
return_start_pos = return_message.length();
|
|
||||||
|
|
||||||
switch(enum_map.find(LowerCase(cmd))->second){
|
|
||||||
|
|
||||||
case evReinitialize :
|
|
||||||
if(feb_controler->Init()){
|
|
||||||
return_message.append("\tExecuted: Reinitialize\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: Reinitialize\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evReset :
|
|
||||||
if(feb_controler->Reset()){
|
|
||||||
return_message.append("\tExecuted: Reset\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: Reset\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case evSetInputDelays :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetIDelays(0,n[0])){
|
|
||||||
return_message.append("\tExecuted: SetInputDelays "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetInputDelays <delay>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case evSetDACValue :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
tmp_str[1] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[1].data());
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&tmp_str[1].length()>0&&feb_controler->SetDAC(tmp_str[0],n[0])){
|
|
||||||
return_message.append("\tExecuted: SetDACValue "); return_message.append(tmp_str[0]+" "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetDACValue <dac_name> <value>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evGetDACValue :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->GetDAC(tmp_str[0],ret_parameter)){
|
|
||||||
return_message.append("\tExecuted: GetDACValue "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: GetDACValue <dac_name>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetDACVoltage :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
tmp_str[1] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[1].data());
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&tmp_str[1].length()>0&&feb_controler->SetDAC(tmp_str[0],n[0],1)){
|
|
||||||
return_message.append("\tExecuted: SetDACVoltage "); return_message.append(tmp_str[0]+" "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetDACVoltage <dac_name> <voltage_mV>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evGetDACVoltage :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->GetDAC(tmp_str[0],ret_parameter,1)){
|
|
||||||
return_message.append("\tExecuted: GetDACVoltage "); return_message.append(tmp_str[0]+" -> ");AddNumber(return_message,ret_parameter); return_message.append(" mV\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: GetDACVoltage <dac_name>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetHighVoltage :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
v[0] = atof(tmp_str[0].data());
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetHighVoltage(v[0])){
|
|
||||||
return_message.append("\tExecuted: SetHighVoltage "); AddNumber(return_message,v[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetHighVoltage <voltage>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetTrimBits :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
if(feb_controler->LoadTrimbitFile()){
|
|
||||||
/* if(1){*/
|
|
||||||
/*tmp_str[0] = GetNextString(data);
|
|
||||||
feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/
|
|
||||||
return_message.append("\tExecuted: SetTrimBits\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetTrimBits \n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetAllTrimBits :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(feb_controler->SaveAllTrimbitsTo(n[0])){
|
|
||||||
/*feb_controler->SetTrimbits(0,(unsigned char*)(tmp_str[0].c_str()));*/
|
|
||||||
/*if(1){*/
|
|
||||||
return_message.append("\tExecuted: SetAllTrimBits\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetAllTrimBits \n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case evGetTrimBits :
|
|
||||||
if(feb_controler->SaveTrimbitFile()){
|
|
||||||
/*if(1){*/
|
|
||||||
/*tmp_str[0] = GetNextString(data);
|
|
||||||
feb_controler->GetTrimbits();*/
|
|
||||||
return_message.append("\tExecuted: GetTrimBits\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: GetTrimBits \n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
// case evLoadTrimBitFile :
|
|
||||||
|
|
||||||
case evSetBitMode :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetDynamicRange(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetBitMode "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetBitMode <mode 4,8,16,32>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetPhotonEnergy :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetPhotonEnergy(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetPhotonEnergy "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetPhotonEnergy <energy eV>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case evSetPhotonEnergyCalibrationParameters :
|
|
||||||
// case evActivateRateCorrection :
|
|
||||||
// case evDeactivateRateCorrection :
|
|
||||||
// case evSetRateCorrectionTau :
|
|
||||||
|
|
||||||
|
|
||||||
case evSetReadoutSpeed :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetReadoutSpeed(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetReadoutSpeed "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetReadoutSpeed <speed 0-full 1-half 2-quarter 3-super_slow>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetReadoutMode :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetReadoutMode(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetReadoutMode "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetReadoutMode <mode 0->parallel,1->non-parallel,2-> safe_mode>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetNumberOfExposures :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetNExposures(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetNumberOfExposures "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetNumberOfExposures <n>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetExposureTime :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
v[0] = atof(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetExposureTime(v[0])){
|
|
||||||
return_message.append("\tExecuted: SetExposureTime "); AddNumber(return_message,v[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetExposureTime <t_seconds>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetExposurePeriod :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
v[0] = atof(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetExposurePeriod(v[0])){
|
|
||||||
return_message.append("\tExecuted: SetExposurePeriod "); AddNumber(return_message,v[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetExposurePeriod <t_seconds>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// case evSetTriggerPolarityToPositive :
|
|
||||||
// case evSetTriggerPolarityToNegative :
|
|
||||||
case evSetTriggerMode :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
if(tmp_str[0].length()>0&&feb_controler->SetTriggerMode(n[0])){
|
|
||||||
return_message.append("\tExecuted: SetTriggerMode "); AddNumber(return_message,n[0]); return_message.append("\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: SetTriggerMode <n>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evSetExternalGating :
|
|
||||||
tmp_str[0] = GetNextString(data);
|
|
||||||
tmp_str[1] = GetNextString(data);
|
|
||||||
n[0] = atoi(tmp_str[0].data());
|
|
||||||
n[1] = atoi(tmp_str[1].data());
|
|
||||||
if(tmp_str[0].length()<1 || tmp_str[1].length()<1 || (n[0]!=0&&n[0]!=1) || (n[1]!=0&&n[1]!=1)){
|
|
||||||
return_message.append("\tError executing: setexternalgating <enable> <polarity>\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
feb_controler->SetExternalEnableMode(n[0],n[1]);
|
|
||||||
ret_val = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evStartAcquisition :
|
|
||||||
if(feb_controler->StartAcquisition()){
|
|
||||||
return_message.append("\tExecuted: StartAcquisition\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: StartAcquisition\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case evStopAcquisition :
|
|
||||||
if(feb_controler->StopAcquisition()){
|
|
||||||
return_message.append("\tExecuted: StopAcquisition\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: StopAcquisition\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case evIsDaqStillRunning :
|
|
||||||
return_message.append("\tExecuted: evIsDaqStillRunning\n");
|
|
||||||
ret_parameter = feb_controler->AcquisitionInProgress();
|
|
||||||
ret_val = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case evWaitUntilDaqFinished :
|
|
||||||
if(feb_controler->WaitForFinishedFlag()){
|
|
||||||
return_message.append("\tExecuted: WaitUntilDaqFinished\n");
|
|
||||||
ret_val = 0;
|
|
||||||
}else{
|
|
||||||
return_message.append("\tError executing: WaitUntilDaqFinished\n");
|
|
||||||
ret_val = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case evExitServer :
|
|
||||||
return_message.append("\tExiting Server ....\n");
|
|
||||||
stop = 1;
|
|
||||||
ret_val = -200;
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
default :
|
|
||||||
return_message.append("\tWarning command \"");
|
|
||||||
return_message.append(cmd);
|
|
||||||
return_message.append("\" not found.\n");
|
|
||||||
return_message.append("\t\tValid commands: ");
|
|
||||||
map<string, cmd_string>::iterator it = enum_map.begin();
|
|
||||||
while(it!=enum_map.end()){
|
|
||||||
return_message.append((it++)->first);
|
|
||||||
return_message.append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret_val=-100;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return_message.append("\n");
|
|
||||||
//AddNumber(return_message,ret_parameter,return_start_pos);
|
|
||||||
AddNumber(return_message,ret_val,return_start_pos,1);
|
|
||||||
AddNumber(return_message,ret_parameter,0,1);
|
|
||||||
if(ret_val!=0) break;
|
|
||||||
|
|
||||||
cmd = GetNextString(data);
|
|
||||||
}
|
|
||||||
/*return_message.append("\n\n\n");*/
|
|
||||||
|
|
||||||
AddNumber(return_message,ret_val,0,1);
|
|
||||||
cout<<return_message.c_str()<<"\t\t";
|
|
||||||
cout<<"return: "<<ret_val<<endl;
|
|
||||||
|
|
||||||
if(!WriteNClose(return_message.c_str(),return_message.length())) return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
delete feb_controler;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
string LowerCase(string str){
|
|
||||||
string s = str;
|
|
||||||
string::iterator i = s.begin();
|
|
||||||
while(i!=s.end()) *i=tolower(*(i++));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
string GetNextString(string str,bool start_from_beginning){
|
|
||||||
static string::size_type start_pos = 0;
|
|
||||||
if(start_from_beginning) start_pos = 0;
|
|
||||||
|
|
||||||
while(start_pos != string::npos){
|
|
||||||
string::size_type found = str.find_first_of(" ",start_pos);
|
|
||||||
string sub = str.substr(start_pos,found-start_pos);
|
|
||||||
|
|
||||||
start_pos = found;
|
|
||||||
if(start_pos != string::npos) start_pos+=1;
|
|
||||||
|
|
||||||
sub.erase(remove_if(sub.begin(),sub.end(), ::isspace ),sub.end());
|
|
||||||
|
|
||||||
if(sub.length()>0) return sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AddNumber(string& str, int n, int location, bool space_after){
|
|
||||||
static char retval_st[100];
|
|
||||||
if(space_after) sprintf(retval_st,"%d ",n);
|
|
||||||
else sprintf(retval_st,"%d",n);
|
|
||||||
|
|
||||||
if(location<0) str.append(retval_st);
|
|
||||||
else str.insert(location,retval_st);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddNumber(string& str, float v, int location, bool space_after){
|
|
||||||
static char retval_st[100];
|
|
||||||
if(space_after) sprintf(retval_st,"%f ",v);
|
|
||||||
else sprintf(retval_st,"%f",v);
|
|
||||||
|
|
||||||
if(location<0) str.append(retval_st);
|
|
||||||
else str.insert(location,retval_st);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SetupListenSocket(unsigned short int port){
|
|
||||||
server_list_s=0;
|
|
||||||
server_conn_s=0;
|
|
||||||
|
|
||||||
if((server_list_s = socket(AF_INET, SOCK_STREAM, 0))<0) return 0;
|
|
||||||
|
|
||||||
struct sockaddr_in servaddr; /* socket address structure */
|
|
||||||
memset(&servaddr, 0, sizeof(servaddr));
|
|
||||||
servaddr.sin_family = AF_INET;
|
|
||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
||||||
servaddr.sin_port = htons(port);
|
|
||||||
|
|
||||||
if(bind(server_list_s,(struct sockaddr *) &servaddr,sizeof(servaddr))<0) return 0;
|
|
||||||
|
|
||||||
if(listen(server_list_s,32) < 0){ // 1024 /* Backlog for listen() */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int AccpetConnectionAndWaitForData(char* buffer, int maxlength){
|
|
||||||
if(server_list_s==0||maxlength<=0) return 0;
|
|
||||||
|
|
||||||
if((server_conn_s = accept(server_list_s,NULL,NULL))< 0) return 0;
|
|
||||||
|
|
||||||
int nread = read(server_conn_s,buffer,maxlength-1);
|
|
||||||
|
|
||||||
if(nread<0) return 0;
|
|
||||||
|
|
||||||
buffer[nread]='\0';
|
|
||||||
return nread;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WriteNClose(const char* buffer, int length){
|
|
||||||
if(server_conn_s==0||length<=0) return 0;
|
|
||||||
|
|
||||||
int nsent = write(server_conn_s,buffer,length);
|
|
||||||
if(close(server_conn_s)<0) return 0;
|
|
||||||
|
|
||||||
server_conn_s=0;
|
|
||||||
return (nsent==length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
|||||||
|
|
||||||
//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 HardwareIO::xfs_in8(xfs_u32 InAddress)
|
|
||||||
{
|
|
||||||
/* read the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
xfs_u8 IoContents;
|
|
||||||
__asm__ volatile ("eieio; lbz %0,0(%1)":"=r" (IoContents):"b"
|
|
||||||
(InAddress));
|
|
||||||
return IoContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
xfs_u16 HardwareIO::xfs_in16(xfs_u32 InAddress)
|
|
||||||
{
|
|
||||||
/* read the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
xfs_u16 IoContents;
|
|
||||||
__asm__ volatile ("eieio; lhz %0,0(%1)":"=r" (IoContents):"b"
|
|
||||||
(InAddress));
|
|
||||||
return IoContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
xfs_u32 HardwareIO::xfs_in32(xfs_u32 InAddress)
|
|
||||||
{
|
|
||||||
/* read the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
xfs_u32 IoContents;
|
|
||||||
__asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (IoContents):"b"
|
|
||||||
(InAddress));
|
|
||||||
return IoContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void HardwareIO::xfs_out8(xfs_u32 OutAddress, xfs_u8 Value)
|
|
||||||
{
|
|
||||||
/* write the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
__asm__ volatile ("stb %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void HardwareIO::xfs_out16(xfs_u32 OutAddress, xfs_u16 Value)
|
|
||||||
{
|
|
||||||
/* write the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
__asm__ volatile ("sth %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
void HardwareIO::xfs_out32(xfs_u32 OutAddress, xfs_u32 Value)
|
|
||||||
{
|
|
||||||
/* write the contents of the I/O location and then synchronize the I/O
|
|
||||||
* such that the I/O operation completes before proceeding on
|
|
||||||
*/
|
|
||||||
|
|
||||||
__asm__ volatile ("stw %0,0(%1); eieio"::"r" (Value), "b"(OutAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,277 +0,0 @@
|
|||||||
|
|
||||||
//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 "HardwareMMappingDefs.h"
|
|
||||||
|
|
||||||
#include "LocalLinkInterface.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LocalLinkInterface::LocalLinkInterface(unsigned int ll_fifo_badr){
|
|
||||||
// printf("\n v 1 \n");
|
|
||||||
printf("Initialize PLB LL FIFOs\n");
|
|
||||||
ll_fifo_base=0;
|
|
||||||
ll_fifo_ctrl_reg=0;
|
|
||||||
if(Init(ll_fifo_badr)){
|
|
||||||
Reset();
|
|
||||||
printf("\tFIFO Status : 0x%08x\n",StatusVector());
|
|
||||||
}else printf("\tError LocalLink Mappping : 0x%08x\n",ll_fifo_badr);
|
|
||||||
|
|
||||||
printf("\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalLinkInterface::~LocalLinkInterface(){};
|
|
||||||
|
|
||||||
LocalLinkInterface::LocalLinkInterface(){
|
|
||||||
printf("Initialize new memory\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int LocalLinkInterface::InitNewMemory (unsigned int addr, int ifg){
|
|
||||||
unsigned int CSP0BASE;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/*fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
|
|
||||||
if (fd == -1) {
|
|
||||||
printf("\nCan't find /dev/mem!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
printf("/dev/mem opened\n");
|
|
||||||
|
|
||||||
|
|
||||||
CSP0BASE = (u_int32_t)mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, addr);
|
|
||||||
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
|
|
||||||
printf("\nCan't map memmory area!!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
printf("CSP0 mapped\n");
|
|
||||||
|
|
||||||
|
|
||||||
volatile u_int8_t *ptr1;
|
|
||||||
|
|
||||||
ptr1=(u_int8_t*)(CSP0BASE);
|
|
||||||
|
|
||||||
printf("pointer val=%x\n",(void*)ptr1);
|
|
||||||
|
|
||||||
printf("ifg_control=%02x\n",*ptr1);
|
|
||||||
|
|
||||||
*ptr1=ifg;
|
|
||||||
|
|
||||||
printf("ifg_control new=%02x\n",*ptr1);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
*/
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool LocalLinkInterface::Init(unsigned int ll_fifo_badr){
|
|
||||||
int fd;
|
|
||||||
void *plb_ll_fifo_ptr;
|
|
||||||
|
|
||||||
if ((fd=open("/dev/mem", O_RDWR)) < 0){
|
|
||||||
fprintf(stderr, "Could not open /dev/mem\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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){
|
|
||||||
perror ("mmap");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ll_fifo_base = (xfs_u32) plb_ll_fifo_ptr;
|
|
||||||
ll_fifo_ctrl_reg = 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool LocalLinkInterface::Reset(){
|
|
||||||
return Reset(PLB_LL_FIFO_CTRL_RESET_STD);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalLinkInterface::Reset(unsigned int rst_mask){
|
|
||||||
ll_fifo_ctrl_reg |= rst_mask;
|
|
||||||
printf("\tCTRL Register bits: 0x%08x\n",ll_fifo_ctrl_reg);
|
|
||||||
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg);
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg);
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg);
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg);
|
|
||||||
|
|
||||||
ll_fifo_ctrl_reg &= (~rst_mask);
|
|
||||||
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,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 LocalLinkInterface::StatusVector(){
|
|
||||||
return xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LocalLinkInterface::Write(unsigned int buffer_len, void *buffer){
|
|
||||||
// note: buffer must be word (4 byte) aligned
|
|
||||||
// frame_len in byte
|
|
||||||
int vacancy=0;
|
|
||||||
int i;
|
|
||||||
int words_send = 0;
|
|
||||||
int last_word;
|
|
||||||
unsigned int *word_ptr;
|
|
||||||
unsigned int fifo_ctrl;
|
|
||||||
xfs_u32 status;
|
|
||||||
|
|
||||||
if (buffer_len < 1) return -1;
|
|
||||||
|
|
||||||
last_word = (buffer_len-1)/4;
|
|
||||||
word_ptr = (unsigned int *)buffer;
|
|
||||||
|
|
||||||
while (words_send <= last_word)
|
|
||||||
{
|
|
||||||
while (!vacancy)//wait for Fifo to be empty again
|
|
||||||
{
|
|
||||||
status = xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
|
|
||||||
if((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Just to know: #define PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS 100
|
|
||||||
for (i=0; ((i<PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS) && (words_send <= last_word)); i++)
|
|
||||||
{
|
|
||||||
fifo_ctrl = 0;
|
|
||||||
if (words_send == 0)
|
|
||||||
{
|
|
||||||
fifo_ctrl = PLB_LL_FIFO_CTRL_LL_SOF;//announce the start of file
|
|
||||||
}
|
|
||||||
|
|
||||||
if (words_send == last_word)
|
|
||||||
{
|
|
||||||
fifo_ctrl |= (PLB_LL_FIFO_CTRL_LL_EOF | (( (buffer_len-1)<<PLB_LL_FIFO_CTRL_LL_REM_SHIFT) & PLB_LL_FIFO_CTRL_LL_REM) );
|
|
||||||
}
|
|
||||||
ctrl_reg_write_mask(PLB_LL_FIFO_CTRL_LL_MASK,fifo_ctrl);
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_FIFO,word_ptr[words_send++]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffer_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int LocalLinkInterface::Read(unsigned int buffer_len, void *buffer){
|
|
||||||
static unsigned int buffer_ptr = 0;
|
|
||||||
// note: buffer must be word (4 byte) aligned
|
|
||||||
// frame_len in byte
|
|
||||||
int len;
|
|
||||||
unsigned int *word_ptr;
|
|
||||||
unsigned int status;
|
|
||||||
volatile unsigned int fifo_val;
|
|
||||||
int sof = 0;
|
|
||||||
|
|
||||||
word_ptr = (unsigned int *)buffer;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
status = xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
|
|
||||||
|
|
||||||
if (!(status & PLB_LL_FIFO_STATUS_EMPTY))
|
|
||||||
{
|
|
||||||
if (status & PLB_LL_FIFO_STATUS_LL_SOF)
|
|
||||||
{
|
|
||||||
if (buffer_ptr)
|
|
||||||
{
|
|
||||||
buffer_ptr = 0;
|
|
||||||
return -1; // buffer overflow
|
|
||||||
}
|
|
||||||
// printf(">>>> SOF\n\r");
|
|
||||||
buffer_ptr = 0;
|
|
||||||
sof = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fifo_val = xfs_in32(ll_fifo_base+4*PLB_LL_FIFO_REG_FIFO); //read from fifo
|
|
||||||
|
|
||||||
if ((buffer_ptr > 0) || sof)
|
|
||||||
{
|
|
||||||
if ( (buffer_len >> 2) > buffer_ptr)
|
|
||||||
{
|
|
||||||
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer_ptr = 0;
|
|
||||||
return -2; // buffer overflow
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
// printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len);
|
|
||||||
buffer_ptr = 0;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(!(status & PLB_LL_FIFO_STATUS_EMPTY));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LocalLinkInterface::ctrl_reg_write_mask(unsigned int mask, unsigned int val){
|
|
||||||
// printf("Fifo CTRL Reg(1): 0x%08x\n",plb_ll_fifo_ctrl_reg);
|
|
||||||
ll_fifo_ctrl_reg &= (~mask);
|
|
||||||
//printf("Fifo CTRL Reg(2): 0x%08x\n",plb_ll_fifo_ctrl_reg);
|
|
||||||
ll_fifo_ctrl_reg |= ( mask & val);
|
|
||||||
// printf("Fifo CTRL Reg: 0x%08x\n",plb_ll_fifo_ctrl_reg);
|
|
||||||
xfs_out32(ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll_fifo_ctrl_reg);
|
|
||||||
// printf("Fifo STAT Reg: 0x%08x\n", plb_ll_fifo[PLB_LL_FIFO_REG_STATUS]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int LocalLinkInterface::Test(unsigned int buffer_len, void *buffer){
|
|
||||||
|
|
||||||
int len;
|
|
||||||
unsigned int rec_buff_len = 4096;
|
|
||||||
unsigned int rec_buffer[4097];
|
|
||||||
|
|
||||||
|
|
||||||
Write(buffer_len,buffer);
|
|
||||||
usleep(10000);
|
|
||||||
|
|
||||||
do{
|
|
||||||
len = Read(rec_buff_len,rec_buffer);
|
|
||||||
printf("receive length: %i\n",len);
|
|
||||||
|
|
||||||
if (len > 0){
|
|
||||||
rec_buffer[len]=0;
|
|
||||||
printf((char*) rec_buffer);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
} while(len > 0);
|
|
||||||
|
|
||||||
printf("\n\n\n\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalLinkInterface::llfifo_print_frame(unsigned char* fbuff, int len){
|
|
||||||
printf("\n\r----Frame of len : %d Byte\n\r",len);
|
|
||||||
for(int 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "xparameters.h"
|
|
||||||
|
|
||||||
#include "LocalLinkInterface.h"
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
char s[2000];
|
|
||||||
sprintf(s,"papamama");
|
|
||||||
|
|
||||||
LocalLinkInterface* l0 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
|
|
||||||
l0->Test(8,s);
|
|
||||||
LocalLinkInterface* l1 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_RX4_TX1_LEFT_BASEADDR);
|
|
||||||
l1->Test(8,s);
|
|
||||||
LocalLinkInterface* l2 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
|
||||||
l2->Test(8,s);
|
|
||||||
LocalLinkInterface* l3 = new LocalLinkInterface(XPAR_PLB_LL_FIFO_AURORA_RX4_TX1_RIGHT_BASEADDR);
|
|
||||||
l3->Test(8,s);
|
|
||||||
|
|
||||||
delete l0;
|
|
||||||
delete l1;
|
|
||||||
delete l2;
|
|
||||||
delete l3;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
CC = powerpc-4xx-softfloat-gcc
|
CC = powerpc-4xx-softfloat-gcc
|
||||||
CCX = powerpc-4xx-softfloat-g++
|
|
||||||
BLACKFIN_CC = bfin-uclinux-gcc
|
BLACKFIN_CC = bfin-uclinux-gcc
|
||||||
CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN
|
CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN
|
||||||
LDLIBS += -lm -lstdc++
|
LDLIBS += -lm -lstdc++
|
||||||
@ -10,13 +9,10 @@ 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 Feb.c FebInterface.c
|
||||||
#SRC_CLNT2 = FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx
|
|
||||||
#SRC_CLNT3 = BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx
|
|
||||||
|
|
||||||
OBJS = $(SRC_CLNT:.c=.o)
|
OBJS = $(SRC_CLNT:.c=.o)
|
||||||
|
|
||||||
|
|
||||||
all: clean $(PROGS) hv9m_blackfin_server #feb_debug beb_debug
|
all: clean $(PROGS) #hv9m_blackfin_server
|
||||||
|
|
||||||
|
|
||||||
boot: $(OBJS)
|
boot: $(OBJS)
|
||||||
@ -27,14 +23,7 @@ $(PROGS):
|
|||||||
$(CC) -o $@ $(SRC_CLNT) $(CFLAGS) $(LDLIBS)
|
$(CC) -o $@ $(SRC_CLNT) $(CFLAGS) $(LDLIBS)
|
||||||
mv $(PROGS) $(DESTDIR)
|
mv $(PROGS) $(DESTDIR)
|
||||||
|
|
||||||
feb_debug:$(SRC_CLNT2)
|
|
||||||
$(CCX) -o feb_debug $(SRC_CLNT2) -I.
|
|
||||||
mv feb_debug $(DESTDIR)
|
|
||||||
|
|
||||||
beb_debug:$(SRC_CLNT3)
|
|
||||||
$(CCX) -o beb_debug $(SRC_CLNT3) -I.
|
|
||||||
mv beb_debug $(DESTDIR)
|
|
||||||
|
|
||||||
hv9m_blackfin_server:9mhvserial_bf.c
|
hv9m_blackfin_server:9mhvserial_bf.c
|
||||||
$(BLACKFIN_CC) -o hv9m_blackfin_server 9mhvserial_bf.c -Wall #-DVERBOSE
|
$(BLACKFIN_CC) -o hv9m_blackfin_server 9mhvserial_bf.c -Wall #-DVERBOSE
|
||||||
mv hv9m_blackfin_server $(DESTDIR)
|
mv hv9m_blackfin_server $(DESTDIR)
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* @author Ian Johnson
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "xparameters.h"
|
|
||||||
|
|
||||||
#include "Feb.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
cout<<"\n\n\n\n\n\n\n\n\n\n"<<endl;
|
|
||||||
|
|
||||||
|
|
||||||
char s[2000];
|
|
||||||
sprintf(s,"papamama");
|
|
||||||
|
|
||||||
Feb* feb = new Feb();
|
|
||||||
|
|
||||||
unsigned int v=22;
|
|
||||||
feb->ReadRegister(0,0,v);
|
|
||||||
feb->ReadRegister(0,0xffffffff,v);
|
|
||||||
cout<<endl<<endl;
|
|
||||||
feb->ReadRegister(1,0,v);
|
|
||||||
feb->ReadRegister(1,0xffffffff,v);
|
|
||||||
|
|
||||||
delete feb;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
|
||||||
|
|
||||||
. /opt/eldk-5.1/powerpc-4xx-softfloat/environment-setup-ppc440-linux
|
|
||||||
|
|
||||||
#powerpc-4xx-softfloat-g++ -Wall -o test Test.cxx HardwareIO.cxx LocalLinkInterface.cxx Feb.cxx -I .
|
|
||||||
#powerpc-4xx-softfloat-g++ -Wall -o hardware_interface_test HardwareInterfaceTest.cxx HardwareInterface.cxx HardwareMMapping.cxx -I .
|
|
||||||
|
|
||||||
|
|
||||||
#powerpc-4xx-softfloat-g++ -Wall -o eiger_test EigerTest.cxx Eiger.cxx HardwareIO.cxx LocalLinkInterface.cxx Feb.cxx -I .
|
|
||||||
|
|
||||||
powerpc-4xx-softfloat-g++ -Wall -o feb_debug FebServer.cxx FebControl.cxx FebInterface.cxx LocalLinkInterface.cxx HardwareIO.cxx -I .
|
|
||||||
|
|
||||||
powerpc-4xx-softfloat-g++ -Wall -o beb_debug BebServer.cxx Beb.cxx LocalLinkInterface.cxx HardwareIO.cxx -I .
|
|
||||||
|
|
||||||
|
|
||||||
cp eiger_test rootfs_executables/.
|
|
||||||
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
|||||||
# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
|
|
||||||
# documentation are documented, even if no documentation was available.
|
|
||||||
# Private class members and static file members will be hidden unless
|
|
||||||
# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
|
|
||||||
|
|
||||||
EXTRACT_ALL = YES
|
|
||||||
|
|
||||||
# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
|
|
||||||
# will be included in the documentation.
|
|
||||||
|
|
||||||
EXTRACT_PRIVATE = NO
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# If the EXTRACT_STATIC tag is set to YES all static members of a file
|
|
||||||
# will be included in the documentation.
|
|
||||||
|
|
||||||
EXTRACT_STATIC = YES
|
|
||||||
|
|
||||||
# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
|
|
||||||
# defined locally in source files will be included in the documentation.
|
|
||||||
# If set to NO only classes defined in header files are included.
|
|
||||||
|
|
||||||
EXTRACT_LOCAL_CLASSES = YES
|
|
||||||
|
|
||||||
# This flag is only useful for Objective-C code. When set to YES local
|
|
||||||
# methods, which are defined in the implementation section but not in
|
|
||||||
# the interface are included in the documentation.
|
|
||||||
# If set to NO (the default) only methods in the interface are included.
|
|
||||||
|
|
||||||
EXTRACT_LOCAL_METHODS = YES
|
|
||||||
|
|
||||||
# If this flag is set to YES, the members of anonymous namespaces will be
|
|
||||||
# extracted and appear in the documentation as a namespace called
|
|
||||||
# 'anonymous_namespace{file}', where file will be replaced with the base
|
|
||||||
# name of the file that contains the anonymous namespace. By default
|
|
||||||
# anonymous namespace are hidden.
|
|
||||||
|
|
||||||
EXTRACT_ANON_NSPACES = NO
|
|
||||||
|
|
||||||
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
|
|
||||||
# undocumented members of documented classes, files or namespaces.
|
|
||||||
# If set to NO (the default) these members will be included in the
|
|
||||||
# various overviews, but no documentation section is generated.
|
|
||||||
# This option has no effect if EXTRACT_ALL is enabled.
|
|
||||||
|
|
||||||
HIDE_UNDOC_MEMBERS = NO
|
|
||||||
|
|
||||||
# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
|
|
||||||
# undocumented classes that are normally visible in the class hierarchy.
|
|
||||||
# If set to NO (the default) these classes will be included in the various
|
|
||||||
# overviews. This option has no effect if EXTRACT_ALL is enabled.
|
|
||||||
|
|
||||||
HIDE_UNDOC_CLASSES = NO
|
|
||||||
|
|
||||||
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
|
|
||||||
# friend (class|struct|union) declarations.
|
|
||||||
# If set to NO (the default) these declarations will be included in the
|
|
||||||
# documentation.
|
|
||||||
|
|
||||||
HIDE_FRIEND_COMPOUNDS = NO
|
|
||||||
|
|
||||||
INTERNAL_DOCS = NO
|
|
||||||
|
|
||||||
SHOW_INCLUDE_FILES = NO
|
|
||||||
|
|
||||||
SHOW_FILES = NO
|
|
||||||
|
|
||||||
SHOW_NAMESPACES = NO
|
|
||||||
|
|
||||||
COMPACT_LATEX = YES
|
|
||||||
|
|
||||||
PAPER_TYPE = a4
|
|
||||||
|
|
||||||
PDF_HYPERLINKS = YES
|
|
||||||
|
|
||||||
USE_PDFLATEX = YES
|
|
||||||
|
|
||||||
LATEX_HIDE_INDICES = YES
|
|
||||||
|
|
||||||
PREDEFINED = __cplusplus
|
|
||||||
|
|
||||||
HAVE_DOT = YES
|
|
||||||
CALL_GRAPH = YES
|
|
||||||
CALLER_GRAPH = YES
|
|
||||||
|
|
||||||
|
|
||||||
INPUT = Beb.h Eiger.h FebControl.h FebInterface.h gitInfoEiger.h HardwareIO.h LocalLinkInterface.h sls_detector_funcs.h slsDetectorServer_defs.h sls_receiver_defs.h xfs_types.h communication_funcs.h EigerRegisterDefs.h Feb.h FebRegisterDefs.h gitInfoEigerTmp.h HardwareMMappingDefs.h sls_detector_defs.h slsDetectorFunctionList.h slsDetectorServer_funcs.h sls_receiver_funcs.h xparameters.h Beb.cxx BebServer.cxx Eiger.cxx EigerTest.cxx FebControl.cxx Feb.cxx FebInterface.cxx FebServer.cxx HardwareIO.cxx LocalLinkInterface.cxx LocalLinkTest.cxx Test.cxx
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_DIRECTORY = docs
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
mv bin/eigerDetectorServer bin/$2
|
mv bin/eigerDetectorServer bin/$2
|
||||||
|
cp bin/$2 /tftpboot
|
||||||
git rm -f bin/$1
|
git rm -f bin/$1
|
||||||
git add bin/$2
|
git add bin/$2
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#detector setup
|
|
||||||
#add_module module_number base_address_top (for half module)
|
|
||||||
#add_module module_number base_address_top base_address_bottom (for full module)
|
|
||||||
add_half_module 17 0
|
|
||||||
#add_half_module 17 1 for bottom
|
|
||||||
#add_module 18 10 12
|
|
||||||
#add_module 2 13 15
|
|
||||||
#add_module 1 120 22
|
|
||||||
|
|
||||||
|
|
||||||
#default setting
|
|
||||||
photon_energy 8000
|
|
||||||
dynamic_range 16
|
|
||||||
readout_speed 1 #(0-full,1-half,2-quarter and 3-superslow)
|
|
||||||
readout_mode 0 #(0-parallel,1-non_parallel,2-safe_mode)
|
|
||||||
|
|
||||||
|
|
||||||
#default dacs
|
|
||||||
SvP 0
|
|
||||||
Vtr 1280
|
|
||||||
Vrf 1550
|
|
||||||
Vrs 700
|
|
||||||
SvN 2000
|
|
||||||
Vtgstv 1278
|
|
||||||
Vcmp_ll 750
|
|
||||||
Vcmp_lr 750
|
|
||||||
cal 2000
|
|
||||||
Vcmp_rl 750
|
|
||||||
rxb_rb 600
|
|
||||||
rxb_lb 600
|
|
||||||
Vcmp_rr 750
|
|
||||||
Vcp 100
|
|
||||||
Vcn 1000
|
|
||||||
Vis 775
|
|
||||||
|
|
||||||
#default high_voltage
|
|
||||||
high_voltage 152
|
|
||||||
|
|
||||||
#default iodelays
|
|
||||||
iodelay 675
|
|
||||||
|
|
||||||
#newgoodiodelay 643
|
|
||||||
#halfspeed_add_about 32
|
|
||||||
#goodiodelay 1467
|
|
||||||
#goodiodelay 1550
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#detector setup
|
|
||||||
#add_beb base_address mac_1GBE ip_1GBE mac_10GBE ip_10GBE
|
|
||||||
|
|
||||||
add_beb 26 0 00:50:c2:46:d9:34 129.129.205.78 00:50:c2:46:d9:35 10.0.26.1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,8 +28,6 @@ int *detectorChips=NULL;
|
|||||||
int *detectorChans=NULL;
|
int *detectorChans=NULL;
|
||||||
dacs_t *detectorDacs=NULL;
|
dacs_t *detectorDacs=NULL;
|
||||||
dacs_t *detectorAdcs=NULL;
|
dacs_t *detectorAdcs=NULL;
|
||||||
int* detectorGain = NULL;
|
|
||||||
int* detectorOffset = NULL;
|
|
||||||
|
|
||||||
int eiger_highvoltage = 0;
|
int eiger_highvoltage = 0;
|
||||||
int eiger_iodelay = 0;
|
int eiger_iodelay = 0;
|
||||||
@ -101,16 +99,12 @@ int initDetector(){
|
|||||||
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||||
detectorDacs=malloc(n*NDAC*sizeof(dacs_t));
|
detectorDacs=malloc(n*NDAC*sizeof(dacs_t));
|
||||||
detectorAdcs=malloc(n*NADC*sizeof(dacs_t));
|
detectorAdcs=malloc(n*NADC*sizeof(dacs_t));
|
||||||
detectorGain=malloc(n*NGAIN*sizeof(int));
|
|
||||||
detectorOffset=malloc(n*NOFFSET*sizeof(int));
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n);
|
printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n);
|
||||||
printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP);
|
printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP);
|
||||||
printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN);
|
printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN);
|
||||||
printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC);
|
printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC);
|
||||||
printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC);
|
printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC);
|
||||||
printf("gains from 0x%x to 0x%x\n",detectorGain, detectorGain+n*NGAIN);
|
|
||||||
printf("offsets from 0x%x to 0x%x\n",detectorOffset, detectorOffset+n*NOFFSET);
|
|
||||||
#endif
|
#endif
|
||||||
for (imod=0; imod<n; imod++) {
|
for (imod=0; imod<n; imod++) {
|
||||||
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
||||||
@ -125,19 +119,9 @@ int initDetector(){
|
|||||||
(detectorModules+imod)->gain=0;
|
(detectorModules+imod)->gain=0;
|
||||||
(detectorModules+imod)->offset=0;
|
(detectorModules+imod)->offset=0;
|
||||||
(detectorModules+imod)->reg=0;
|
(detectorModules+imod)->reg=0;
|
||||||
/* initialize registers, dacs, retrieve sn, adc values etc */
|
|
||||||
}
|
}
|
||||||
for(i=0;i<NGAIN;i++)
|
|
||||||
detectorGain[i] = default_gain_values[(int)STANDARD];
|
|
||||||
for(i=0;i<NOFFSET;i++)
|
|
||||||
detectorOffset[i] = default_offset_values[(int)STANDARD];
|
|
||||||
thisSettings = UNINITIALIZED;
|
thisSettings = UNINITIALIZED;
|
||||||
/*sChan=noneSelected;
|
|
||||||
sChip=noneSelected;
|
|
||||||
sMod=noneSelected;
|
|
||||||
sDac=noneSelected;
|
|
||||||
sAdc=noneSelected;
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Feb and Beb Initializations
|
//Feb and Beb Initializations
|
||||||
getModuleConfiguration();
|
getModuleConfiguration();
|
||||||
@ -619,7 +603,7 @@ void setDefaultSettingsTau_in_nsec(int t){
|
|||||||
default_tau_from_file = t;
|
default_tau_from_file = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){
|
int setModule(sls_detector_module myMod, int delay){
|
||||||
int retval[2];
|
int retval[2];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -627,25 +611,10 @@ int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){
|
|||||||
printf("Setting module with settings %d\n",myMod.reg);
|
printf("Setting module with settings %d\n",myMod.reg);
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
//set the settings variable
|
|
||||||
setSettings( (enum detectorSettings)myMod.reg,-1);
|
setSettings( (enum detectorSettings)myMod.reg,-1);
|
||||||
|
|
||||||
//set the gains and offset variables locally
|
if(setIODelay(delay, -1)!= delay){
|
||||||
for(i=0;i<NGAIN;i++){
|
cprintf(RED,"could not set iodelay %d\n",delay);
|
||||||
if(gain[i]>=0){
|
|
||||||
detectorGain[i] = gain[i];
|
|
||||||
printf("gain[%d]:%d\n",i,detectorGain[i]);
|
|
||||||
}else cprintf(RED,"gain not changed\n");
|
|
||||||
}
|
|
||||||
for(i=0;i<NOFFSET;i++){
|
|
||||||
if(offset[i]>=0){
|
|
||||||
detectorOffset[i] = offset[i];
|
|
||||||
printf("offset[%d]:%d\n",i,detectorOffset[i]);
|
|
||||||
}else cprintf(RED,"offset not changed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(setIODelay(*delay, -1)!= (*delay)){
|
|
||||||
cprintf(RED,"could not set iodelay %d\n",*delay);
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,21 +651,14 @@ int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getModule(sls_detector_module *myMod, int* gain, int* offset){
|
int getModule(sls_detector_module *myMod){
|
||||||
int i;
|
int i;
|
||||||
int retval[2];
|
int retval[2];
|
||||||
//printf("get gainval[0]:%d\n",detectorGain[0]);
|
|
||||||
|
|
||||||
//dacs
|
//dacs
|
||||||
for(i=0;i<NDAC;i++)
|
for(i=0;i<NDAC;i++)
|
||||||
setDAC((enum detDacIndex)i,-1,-1,0,retval);
|
setDAC((enum detDacIndex)i,-1,-1,0,retval);
|
||||||
|
|
||||||
//gains, offsets
|
|
||||||
for(i=0;i<NGAIN;i++)
|
|
||||||
gain[i] = detectorGain[i];
|
|
||||||
for(i=0;i<NOFFSET;i++)
|
|
||||||
offset[i] = detectorOffset[i];
|
|
||||||
|
|
||||||
//trimbits
|
//trimbits
|
||||||
unsigned int* tt;
|
unsigned int* tt;
|
||||||
tt = Feb_Control_GetTrimbits();
|
tt = Feb_Control_GetTrimbits();
|
||||||
@ -736,38 +698,8 @@ int getThresholdEnergy(int imod){
|
|||||||
|
|
||||||
int setThresholdEnergy(int ev, int imod){
|
int setThresholdEnergy(int ev, int imod){
|
||||||
printf(" Setting threshold energy:%d\n",ev);
|
printf(" Setting threshold energy:%d\n",ev);
|
||||||
int retval[2],i;
|
if(ev >= 0)
|
||||||
int thrvalue[NGAIN];
|
eiger_photonenergy = ev;
|
||||||
int average=0;
|
|
||||||
if(ev >= 0) {
|
|
||||||
|
|
||||||
enum detDacIndex ind[NGAIN]={VCMP_LL,VCMP_LR,VCMP_RL, VCMP_RR};
|
|
||||||
const char* vcmp[4]={"vcmp_ll","vcmp_lr","vcmp_rl","vcmp_rr"};
|
|
||||||
int valid=0;
|
|
||||||
|
|
||||||
//calculate thrvalues for dacs
|
|
||||||
for(i=0;i<NGAIN;i++){
|
|
||||||
|
|
||||||
thrvalue[i] = (int) (( ((double)detectorGain[i]/1000) * (-1) * ((double)ev/1000)) + ((double)detectorOffset[i]/1000));
|
|
||||||
printf("detectorGain[i]:%d detectorOffset[i]:%d thrvalue[i]:%d\n",detectorGain[i],detectorOffset[i],thrvalue[i]);
|
|
||||||
//put limits (VCMP SHOUDL ALWAYS BE BETWEEN 0 AND 2000
|
|
||||||
|
|
||||||
//setdacs
|
|
||||||
if(thrvalue[i]>=0 && thrvalue[i]<2001)valid++;
|
|
||||||
}//ngains
|
|
||||||
|
|
||||||
if( valid == NGAIN){
|
|
||||||
eiger_photonenergy = ev;
|
|
||||||
for(i=0;i<NGAIN;i++) {
|
|
||||||
average+= thrvalue[i];
|
|
||||||
setDAC(ind[i],thrvalue[i],-1,0,retval);
|
|
||||||
if(retval[0] != thrvalue[i]) cprintf(BG_RED,"Failed to set %s to %d, got %d\n",vcmp[i], thrvalue[i],retval[0]);
|
|
||||||
}
|
|
||||||
average=(int) ((float)average/4.+0.5);
|
|
||||||
setDAC(VCP,average,-1,0,retval);
|
|
||||||
if(retval[0] != average) cprintf(BG_RED,"Failed to set VCP to %d, got %d\n",average, retval[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getThresholdEnergy(imod);
|
return getThresholdEnergy(imod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#define NCHIP 4
|
#define NCHIP 4
|
||||||
#define NDAC 16
|
#define NDAC 16
|
||||||
#define NADC 0
|
#define NADC 0
|
||||||
#define NGAIN 4
|
#define NGAIN 0
|
||||||
#define NOFFSET 4
|
#define NOFFSET 0
|
||||||
|
|
||||||
#define NMAXMODX 1
|
#define NMAXMODX 1
|
||||||
#define NMAXMODY 1
|
#define NMAXMODY 1
|
||||||
|
@ -1144,41 +1144,54 @@ int multiSlsDetector::getThresholdEnergy(int pos) {
|
|||||||
|
|
||||||
int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings) {
|
int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings) {
|
||||||
|
|
||||||
int i, posmin, posmax;
|
int posmin, posmax;
|
||||||
int ret1=-100, ret;
|
int ret=-100;
|
||||||
|
if (pos<0) {
|
||||||
|
posmin=0;
|
||||||
|
posmax=thisMultiDetector->numberOfDetectors;
|
||||||
|
} else {
|
||||||
|
posmin=pos;
|
||||||
|
posmax=pos+1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pos<0) {
|
if(!threadpool){
|
||||||
posmin=0;
|
cout << "Error in creating threadpool. Exiting" << endl;
|
||||||
posmax=thisMultiDetector->numberOfDetectors;
|
return -1;
|
||||||
} else {
|
}else{
|
||||||
posmin=pos;
|
//return storage values
|
||||||
posmax=pos+1;
|
int* iret[posmax-posmin];
|
||||||
}
|
for(int idet=posmin; idet<posmax; idet++){
|
||||||
|
if(detectors[idet]){
|
||||||
for (i=posmin; i<posmax; i++) {
|
iret[idet]= new int(-1);
|
||||||
if (detectors[i]) {
|
Task* task = new Task(new func3_t<int,slsDetector,int,int,detectorSettings,int>(&slsDetector::setThresholdEnergy,
|
||||||
ret=detectors[i]->setThresholdEnergy(e_eV,-1,isettings);
|
detectors[idet],e_eV,-1,isettings,iret[idet]));
|
||||||
if(detectors[i]->getErrorMask())
|
threadpool->add_task(task);
|
||||||
setErrorMask(getErrorMask()|(1<<i));
|
}
|
||||||
#ifdef VERBOSE
|
}
|
||||||
cout << "detetcor " << i << " threshold " << ret << endl;
|
threadpool->startExecuting();
|
||||||
#endif
|
threadpool->wait_for_tasks_to_complete();
|
||||||
if (ret1==-100)
|
for(int idet=posmin; idet<posmax; idet++){
|
||||||
ret1=ret;
|
if(detectors[idet]){
|
||||||
else if (ret<(ret1-200) || ret>(ret1+200))
|
if(iret[idet] != NULL){
|
||||||
ret1=FAIL;
|
if (ret==-100)
|
||||||
|
ret=*iret[idet];
|
||||||
#ifdef VERBOSE
|
else if (ret<(*iret[idet]-200) || ret>(*iret[idet]+200))
|
||||||
cout << "return value " << ret1 << endl;
|
ret=-1;
|
||||||
#endif
|
delete iret[idet];
|
||||||
}
|
}else ret=-1;
|
||||||
|
if(detectors[idet]->getErrorMask())
|
||||||
}
|
setErrorMask(getErrorMask()|(1<<idet));
|
||||||
thisMultiDetector->currentThresholdEV=ret1;
|
}
|
||||||
return ret1;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thisMultiDetector->currentThresholdEV=ret;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
||||||
|
|
||||||
int i, posmin, posmax;
|
int i, posmin, posmax;
|
||||||
|
@ -655,8 +655,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
|||||||
thisDetector->nChip[Y]=1;
|
thisDetector->nChip[Y]=1;
|
||||||
thisDetector->nDacs=16;
|
thisDetector->nDacs=16;
|
||||||
thisDetector->nAdcs=0;
|
thisDetector->nAdcs=0;
|
||||||
thisDetector->nGain=4;
|
thisDetector->nGain=0;
|
||||||
thisDetector->nOffset=4;
|
thisDetector->nOffset=0;
|
||||||
thisDetector->nModMax[X]=1;
|
thisDetector->nModMax[X]=1;
|
||||||
thisDetector->nModMax[Y]=1;
|
thisDetector->nModMax[Y]=1;
|
||||||
thisDetector->dynamicRange=16;
|
thisDetector->dynamicRange=16;
|
||||||
@ -2825,12 +2825,8 @@ slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){
|
|||||||
|
|
||||||
int slsDetector::setModule(int reg, int imod){
|
int slsDetector::setModule(int reg, int imod){
|
||||||
sls_detector_module myModule;
|
sls_detector_module myModule;
|
||||||
int* g=0;
|
|
||||||
int* o=0;
|
|
||||||
int* iod=0;
|
|
||||||
int64_t tau=-1;
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout << "slsDetector set module " << std::endl;
|
std::cout << "slsDetector set module " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
int charegs[thisDetector->nChans*thisDetector->nChips];
|
int charegs[thisDetector->nChans*thisDetector->nChips];
|
||||||
@ -2897,14 +2893,14 @@ int slsDetector::setModule(int reg, int imod){
|
|||||||
ads[i]=-1;
|
ads[i]=-1;
|
||||||
myModule.adcs=ads;
|
myModule.adcs=ads;
|
||||||
}
|
}
|
||||||
ret=setModule(myModule,g,o,iod,tau);
|
ret=setModule(myModule,-1,-1,-1,0,0);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval, int* iodelay, int64_t tau){
|
int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval){
|
||||||
|
|
||||||
int fnum=F_SET_MODULE;
|
int fnum=F_SET_MODULE;
|
||||||
int retval;
|
int retval;
|
||||||
@ -2923,16 +2919,18 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
|
|||||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
sendModule(&module);
|
sendModule(&module);
|
||||||
|
|
||||||
//extra gain and offset - eiger
|
//not included in module
|
||||||
if((thisDetector->nGain) && (gainval))
|
if(gainval && (thisDetector->nGain))
|
||||||
controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain);
|
controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain);
|
||||||
if((thisDetector->nOffset) && (offsetval))
|
if(offsetval && (thisDetector->nOffset))
|
||||||
controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
|
controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
|
||||||
if(thisDetector->myDetectorType == EIGER){
|
if(thisDetector->myDetectorType == EIGER) {
|
||||||
controlSocket->SendDataOnly(iodelay,sizeof(int));
|
controlSocket->SendDataOnly(&iodelay,sizeof(iodelay));
|
||||||
controlSocket->SendDataOnly(&tau,sizeof(tau));
|
controlSocket->SendDataOnly(&tau,sizeof(tau));
|
||||||
|
controlSocket->SendDataOnly(&e_eV,sizeof(e_eV));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
if (ret!=FAIL)
|
if (ret!=FAIL)
|
||||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
@ -3129,13 +3127,14 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){
|
|||||||
offset[i+imod*thisDetector->nOffset]=offsetval[i];
|
offset[i+imod*thisDetector->nOffset]=offsetval[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gainval) delete[]gainval;
|
|
||||||
if(offsetval) delete[]offsetval;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
myMod=NULL;
|
myMod=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(gainval) delete[]gainval;
|
||||||
|
if(offsetval) delete[]offsetval;
|
||||||
|
|
||||||
return myMod;
|
return myMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3200,41 +3199,201 @@ int slsDetector::getThresholdEnergy(int imod){
|
|||||||
|
|
||||||
int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){
|
int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){
|
||||||
|
|
||||||
int fnum= F_SET_THRESHOLD_ENERGY;
|
//currently only for eiger
|
||||||
int retval;
|
if (thisDetector->myDetectorType == EIGER) {
|
||||||
int ret=FAIL;
|
setThresholdEnergyAndSettings(e_eV,isettings);
|
||||||
char mess[MAX_STR_LENGTH]="";
|
return thisDetector->currentThresholdEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fnum= F_SET_THRESHOLD_ENERGY;
|
||||||
|
int retval;
|
||||||
|
int ret=FAIL;
|
||||||
|
char mess[MAX_STR_LENGTH]="";
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Setting threshold energy "<< std::endl;
|
std::cout<< "Setting threshold energy "<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||||
if (connectControl() == OK){
|
if (connectControl() == OK){
|
||||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
controlSocket->SendDataOnly(&e_eV,sizeof(e_eV));
|
controlSocket->SendDataOnly(&e_eV,sizeof(e_eV));
|
||||||
controlSocket->SendDataOnly(&imod,sizeof(imod));
|
controlSocket->SendDataOnly(&imod,sizeof(imod));
|
||||||
controlSocket->SendDataOnly(&isettings,sizeof(isettings));
|
controlSocket->SendDataOnly(&isettings,sizeof(isettings));
|
||||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
if (ret==FAIL) {
|
if (ret==FAIL) {
|
||||||
std::cout<< "Detector returned error: "<< std::endl;
|
std::cout<< "Detector returned error: "<< std::endl;
|
||||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
std::cout<< mess << std::endl;
|
std::cout<< mess << std::endl;
|
||||||
} else {
|
} else {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Detector returned OK "<< std::endl;
|
std::cout<< "Detector returned OK "<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
thisDetector->currentThresholdEV=retval;
|
thisDetector->currentThresholdEV=retval;
|
||||||
}
|
}
|
||||||
disconnectControl();
|
disconnectControl();
|
||||||
if (ret==FORCE_UPDATE)
|
if (ret==FORCE_UPDATE)
|
||||||
updateDetector();
|
updateDetector();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
thisDetector->currentThresholdEV=e_eV;
|
thisDetector->currentThresholdEV=e_eV;
|
||||||
}
|
}
|
||||||
return thisDetector->currentThresholdEV;
|
return thisDetector->currentThresholdEV;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings) {
|
||||||
|
|
||||||
|
//if settings provided, use that, else use the shared memory variable
|
||||||
|
detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: thisDetector->currentSettings);
|
||||||
|
string ssettings;
|
||||||
|
switch (is) {
|
||||||
|
case STANDARD:
|
||||||
|
ssettings="/standard";
|
||||||
|
thisDetector->currentSettings=STANDARD;
|
||||||
|
break;
|
||||||
|
case HIGHGAIN:
|
||||||
|
ssettings="/highgain";
|
||||||
|
thisDetector->currentSettings=HIGHGAIN;
|
||||||
|
break;
|
||||||
|
case LOWGAIN:
|
||||||
|
ssettings="/lowgain";
|
||||||
|
thisDetector->currentSettings=LOWGAIN;
|
||||||
|
break;
|
||||||
|
case VERYHIGHGAIN:
|
||||||
|
ssettings="/veryhighgain";
|
||||||
|
thisDetector->currentSettings=VERYHIGHGAIN;
|
||||||
|
break;
|
||||||
|
case VERYLOWGAIN:
|
||||||
|
ssettings="/verylowgain";
|
||||||
|
thisDetector->currentSettings=VERYLOWGAIN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Error: Unknown settings %s for this detector!\n", getDetectorSettings(is).c_str());
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//verify e_eV exists in trimEneregies[]
|
||||||
|
if (!thisDetector->nTrimEn ||
|
||||||
|
(e_eV < thisDetector->trimEnergies[0]) ||
|
||||||
|
(e_eV > thisDetector->trimEnergies[thisDetector->nTrimEn-1]) ) {
|
||||||
|
printf("Error: This energy %d not defined for this module!\n", e_eV);
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//find if interpolation required
|
||||||
|
bool interpolate = true;
|
||||||
|
for (int i = 0; i < thisDetector->nTrimEn; ++i) {
|
||||||
|
if (thisDetector->trimEnergies[i] == e_eV) {
|
||||||
|
interpolate = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//fill detector module structure
|
||||||
|
sls_detector_module *myMod = NULL;
|
||||||
|
int iodelay = -1; //not included in the module
|
||||||
|
int tau = -1; //not included in the module
|
||||||
|
|
||||||
|
//normal
|
||||||
|
if(!interpolate) {
|
||||||
|
//find their directory names
|
||||||
|
ostringstream ostfn;
|
||||||
|
ostfn << thisDetector->settingsDir << ssettings << "/" << e_eV << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10);
|
||||||
|
string settingsfname = ostfn.str();
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Settings File is %s\n", settingsfname1.c_str());
|
||||||
|
#endif
|
||||||
|
//read the files
|
||||||
|
myMod=createModule();
|
||||||
|
if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) {
|
||||||
|
if(myMod)deleteModule(myMod);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//interpolate
|
||||||
|
else {
|
||||||
|
//find the trim values
|
||||||
|
int trim1 = -1, trim2 = -1;
|
||||||
|
for (int i = 0; i < thisDetector->nTrimEn; ++i) {
|
||||||
|
if (e_eV < thisDetector->trimEnergies[i]) {
|
||||||
|
trim2 = thisDetector->trimEnergies[i];
|
||||||
|
trim1 = thisDetector->trimEnergies[i-1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//find their directory names
|
||||||
|
ostringstream ostfn;
|
||||||
|
ostfn << thisDetector->settingsDir << ssettings << "/" << trim1 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10);
|
||||||
|
string settingsfname1 = ostfn.str();
|
||||||
|
ostfn.str(""); ostfn.clear();
|
||||||
|
ostfn << thisDetector->settingsDir << ssettings << "/" << trim2 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10);
|
||||||
|
string settingsfname2 = ostfn.str();
|
||||||
|
//read the files
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Settings Files are %s and %s\n",settingsfname1.c_str(), settingsfname2.c_str());
|
||||||
|
#endif
|
||||||
|
sls_detector_module *myMod1=createModule();
|
||||||
|
sls_detector_module *myMod2=createModule();
|
||||||
|
int iodelay1 = -1; //not included in the module
|
||||||
|
int tau1 = -1; //not included in the module
|
||||||
|
int iodelay2 = -1; //not included in the module
|
||||||
|
int tau2 = -1; //not included in the module
|
||||||
|
if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1)) {
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
||||||
|
deleteModule(myMod1);
|
||||||
|
deleteModule(myMod2);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2)) {
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
||||||
|
deleteModule(myMod1);
|
||||||
|
deleteModule(myMod2);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
if (iodelay1 != iodelay2) {
|
||||||
|
printf("iodelays do not match between files\n");
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
|
||||||
|
deleteModule(myMod1);
|
||||||
|
deleteModule(myMod2);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
iodelay = iodelay1;
|
||||||
|
|
||||||
|
//interpolate module
|
||||||
|
myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2);
|
||||||
|
if (myMod == NULL) {
|
||||||
|
printf("Could not interpolate, different dac values in files\n");
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
|
||||||
|
}
|
||||||
|
//interpolate tau
|
||||||
|
tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2);
|
||||||
|
printf("new tau:%d\n",tau);
|
||||||
|
|
||||||
|
deleteModule(myMod1);
|
||||||
|
deleteModule(myMod2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
myMod->module=0;
|
||||||
|
myMod->reg=thisDetector->currentSettings;
|
||||||
|
setModule(*myMod, iodelay, tau, e_eV, 0, 0);
|
||||||
|
deleteModule(myMod);
|
||||||
|
if (getSettings(-1) != is){
|
||||||
|
std::cout << "Could not set settings in detector" << endl;
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
select detector settings
|
select detector settings
|
||||||
*/
|
*/
|
||||||
@ -3281,20 +3440,36 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "slsDetector setSettings "<< std::endl;
|
std::cout<< "slsDetector setSettings "<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//only set client shared memory variable for Eiger, settings threshold loads the module data (trimbits, dacs etc.)
|
||||||
|
if (thisDetector->myDetectorType == EIGER) {
|
||||||
|
switch(isettings) {
|
||||||
|
case STANDARD:
|
||||||
|
case HIGHGAIN:
|
||||||
|
case LOWGAIN:
|
||||||
|
case VERYHIGHGAIN:
|
||||||
|
case VERYLOWGAIN:
|
||||||
|
thisDetector->currentSettings = isettings;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str());
|
||||||
|
}
|
||||||
|
return thisDetector->currentSettings;
|
||||||
|
}
|
||||||
|
|
||||||
sls_detector_module *myMod=createModule();
|
sls_detector_module *myMod=createModule();
|
||||||
int modmi=imod, modma=imod+1, im=imod;
|
int modmi=imod, modma=imod+1, im=imod;
|
||||||
string settingsfname, calfname;
|
string settingsfname, calfname;
|
||||||
string ssettings;
|
string ssettings;
|
||||||
|
|
||||||
|
//not included in module structure
|
||||||
|
int iodelay = -1;
|
||||||
|
int tau = -1;
|
||||||
int* gainval=0, *offsetval=0;
|
int* gainval=0, *offsetval=0;
|
||||||
int* iodelay=0;
|
|
||||||
if(thisDetector->nGain)
|
if(thisDetector->nGain)
|
||||||
gainval=new int[thisDetector->nGain];
|
gainval=new int[thisDetector->nGain];
|
||||||
if(thisDetector->nOffset)
|
if(thisDetector->nOffset)
|
||||||
offsetval=new int[thisDetector->nOffset];
|
offsetval=new int[thisDetector->nOffset];
|
||||||
if(thisDetector->myDetectorType == EIGER)
|
|
||||||
iodelay = new int;
|
|
||||||
int64_t tau=-1;
|
|
||||||
|
|
||||||
|
|
||||||
int ret=0;
|
int ret=0;
|
||||||
@ -3452,7 +3627,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "the settings file name is "<<settingsfname << endl;
|
cout << "the settings file name is "<<settingsfname << endl;
|
||||||
#endif
|
#endif
|
||||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
|
if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) {
|
||||||
//if it didnt open, try default settings file
|
//if it didnt open, try default settings file
|
||||||
ostringstream ostfn_default;
|
ostringstream ostfn_default;
|
||||||
switch(thisDetector->myDetectorType){
|
switch(thisDetector->myDetectorType){
|
||||||
@ -3472,7 +3647,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << settingsfname << endl;
|
cout << settingsfname << endl;
|
||||||
#endif
|
#endif
|
||||||
if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod,iodelay)) {
|
if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) {
|
||||||
//if default doesnt work, return error
|
//if default doesnt work, return error
|
||||||
std::cout << "Could not open settings file" << endl;
|
std::cout << "Could not open settings file" << endl;
|
||||||
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
||||||
@ -3483,41 +3658,43 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
|
|||||||
|
|
||||||
|
|
||||||
//calibration file****
|
//calibration file****
|
||||||
calfname=oscfn.str();
|
if(thisDetector->myDetectorType != EIGER) {
|
||||||
|
calfname=oscfn.str();
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Specific file:"<< calfname << endl;
|
cout << "Specific file:"<< calfname << endl;
|
||||||
#endif
|
|
||||||
//extra gain and offset
|
|
||||||
if(thisDetector->nGain)
|
|
||||||
ret = readCalibrationFile(calfname,gainval, offsetval, tau, thisDetector->myDetectorType );
|
|
||||||
//normal gain and offset inside sls_detector_module
|
|
||||||
else
|
|
||||||
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
|
||||||
|
|
||||||
//if it didnt open, try default
|
|
||||||
if(ret != OK){
|
|
||||||
ostringstream oscfn_default;
|
|
||||||
oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal";
|
|
||||||
calfname=oscfn_default.str();
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "Default file:" << calfname << endl;
|
|
||||||
#endif
|
#endif
|
||||||
//extra gain and offset
|
//extra gain and offset
|
||||||
if(thisDetector->nGain)
|
if(thisDetector->nGain)
|
||||||
ret = readCalibrationFile(calfname,gainval, offsetval, tau, thisDetector->myDetectorType );
|
ret = readCalibrationFile(calfname,gainval, offsetval);
|
||||||
//normal gain and offset inside sls_detector_module
|
//normal gain and offset inside sls_detector_module
|
||||||
else
|
else
|
||||||
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
||||||
}
|
|
||||||
//if default doesnt work, return error
|
//if it didnt open, try default
|
||||||
if(ret != OK){
|
if(ret != OK){
|
||||||
std::cout << "Could not open calibration file" << calfname << endl;
|
ostringstream oscfn_default;
|
||||||
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal";
|
||||||
return thisDetector->currentSettings;
|
calfname=oscfn_default.str();
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "Default file:" << calfname << endl;
|
||||||
|
#endif
|
||||||
|
//extra gain and offset
|
||||||
|
if(thisDetector->nGain)
|
||||||
|
ret = readCalibrationFile(calfname,gainval, offsetval);
|
||||||
|
//normal gain and offset inside sls_detector_module
|
||||||
|
else
|
||||||
|
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
||||||
|
}
|
||||||
|
//if default doesnt work, return error
|
||||||
|
if(ret != OK){
|
||||||
|
std::cout << "Could not open calibration file" << calfname << endl;
|
||||||
|
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
|
||||||
|
return thisDetector->currentSettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if everything worked, set module****
|
//if everything worked, set module****
|
||||||
setModule(*myMod,gainval,offsetval,iodelay, tau);
|
setModule(*myMod,iodelay,tau,-1,gainval,offsetval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6507,9 +6684,9 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
|
int slsDetector::writeSettingsFile(string fname, int imod, int& iodelay, int& tau){
|
||||||
|
|
||||||
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay);
|
return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay, tau);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -6774,22 +6951,9 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
|||||||
|
|
||||||
sls_detector_module *myMod=NULL;
|
sls_detector_module *myMod=NULL;
|
||||||
|
|
||||||
//tau set to -2 to not affect in any way (-1 for set settings)
|
int iodelay = -1;
|
||||||
int64_t tau =-2;
|
int tau = -1;
|
||||||
int* gainval=0; int* offsetval=0;
|
|
||||||
int *iodelay=0;
|
|
||||||
if(thisDetector->nGain){
|
|
||||||
gainval=new int[thisDetector->nGain];
|
|
||||||
for(int i=0;i<thisDetector->nGain;i++)
|
|
||||||
gainval[i] = -1;
|
|
||||||
}
|
|
||||||
if(thisDetector->nOffset){
|
|
||||||
offsetval=new int[thisDetector->nOffset];
|
|
||||||
for(int i=0;i<thisDetector->nOffset;i++)
|
|
||||||
offsetval[i] = -1;
|
|
||||||
}
|
|
||||||
if(thisDetector->myDetectorType == EIGER)
|
|
||||||
iodelay = new int;*iodelay=0;
|
|
||||||
string fn=fname;
|
string fn=fname;
|
||||||
fn=fname;
|
fn=fname;
|
||||||
int mmin=0, mmax=setNumberOfModules();
|
int mmin=0, mmax=setNumberOfModules();
|
||||||
@ -6809,17 +6973,15 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
|
|||||||
ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im);
|
ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im);
|
||||||
fn=ostfn.str();
|
fn=ostfn.str();
|
||||||
}
|
}
|
||||||
myMod=readSettingsFile(fn, thisDetector->myDetectorType,myMod,iodelay);
|
myMod=readSettingsFile(fn, thisDetector->myDetectorType,iodelay, tau, myMod);
|
||||||
|
|
||||||
if (myMod) {
|
if (myMod) {
|
||||||
myMod->module=im;
|
myMod->module=im;
|
||||||
//settings is saved in myMod.reg for all except mythen
|
//settings is saved in myMod.reg for all except mythen
|
||||||
if(thisDetector->myDetectorType!=MYTHEN)
|
if(thisDetector->myDetectorType!=MYTHEN)
|
||||||
myMod->reg=thisDetector->currentSettings;
|
myMod->reg=thisDetector->currentSettings;
|
||||||
setModule(*myMod,gainval,offsetval,iodelay,tau);
|
setModule(*myMod,iodelay,tau,-1,0,0);
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
if(gainval) delete[] gainval;
|
|
||||||
if(offsetval) delete[] offsetval;
|
|
||||||
} else
|
} else
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -6831,7 +6993,8 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
|
|||||||
|
|
||||||
sls_detector_module *myMod=NULL;
|
sls_detector_module *myMod=NULL;
|
||||||
int ret=FAIL;
|
int ret=FAIL;
|
||||||
int *iod = 0;
|
int iodelay = -1;
|
||||||
|
int tau = -1;
|
||||||
|
|
||||||
int mmin=0, mmax=setNumberOfModules();
|
int mmin=0, mmax=setNumberOfModules();
|
||||||
if (imod>=0) {
|
if (imod>=0) {
|
||||||
@ -6847,10 +7010,10 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
|
|||||||
if ((myMod=getModule(im))) {
|
if ((myMod=getModule(im))) {
|
||||||
|
|
||||||
if(thisDetector->myDetectorType == EIGER){
|
if(thisDetector->myDetectorType == EIGER){
|
||||||
iod = new int;
|
iodelay = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1);
|
||||||
*iod = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1);
|
tau = (int64_t)getRateCorrectionTau();
|
||||||
}
|
}
|
||||||
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod,iod);
|
ret=writeSettingsFile(ostfn.str(), thisDetector->myDetectorType, *myMod, iodelay, tau);
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6898,12 +7061,15 @@ int slsDetector::setAllTrimbits(int val, int imod){
|
|||||||
|
|
||||||
int slsDetector::loadCalibrationFile(string fname, int imod) {
|
int slsDetector::loadCalibrationFile(string fname, int imod) {
|
||||||
|
|
||||||
|
if(thisDetector->myDetectorType == EIGER) {
|
||||||
|
std::cout << "Not required for this detector!" << std::endl;
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
sls_detector_module *myMod=NULL;
|
sls_detector_module *myMod=NULL;
|
||||||
string fn=fname;
|
string fn=fname;
|
||||||
|
|
||||||
int64_t tau = -1;
|
|
||||||
int* gainval=0; int* offsetval=0;
|
int* gainval=0; int* offsetval=0;
|
||||||
int* iodelay=0;
|
|
||||||
if(thisDetector->nGain){
|
if(thisDetector->nGain){
|
||||||
gainval=new int[thisDetector->nGain];
|
gainval=new int[thisDetector->nGain];
|
||||||
for(int i=0;i<thisDetector->nGain;i++)
|
for(int i=0;i<thisDetector->nGain;i++)
|
||||||
@ -6935,18 +7101,16 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
|
|||||||
}
|
}
|
||||||
fn=ostfn.str();
|
fn=ostfn.str();
|
||||||
if((myMod=getModule(im))){
|
if((myMod=getModule(im))){
|
||||||
iodelay = new int;
|
|
||||||
*iodelay = (int)setDAC(-1,IO_DELAY,0);
|
|
||||||
//extra gain and offset
|
//extra gain and offset
|
||||||
if(thisDetector->nGain){
|
if(thisDetector->nGain){
|
||||||
if(readCalibrationFile(fn,gainval, offsetval,tau, thisDetector->myDetectorType)==FAIL)
|
if(readCalibrationFile(fn,gainval, offsetval)==FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
} //normal gain and offset inside sls_detector_module
|
} //normal gain and offset inside sls_detector_module
|
||||||
else{
|
else{
|
||||||
if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL)
|
if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
setModule(*myMod,gainval,offsetval,iodelay,tau);
|
setModule(*myMod,-1,-1,-1,gainval,offsetval);
|
||||||
|
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
if(gainval) delete[]gainval;
|
if(gainval) delete[]gainval;
|
||||||
@ -6978,7 +7142,7 @@ int slsDetector::saveCalibrationFile(string fname, int imod) {
|
|||||||
if ((myMod=getModule(im))) {
|
if ((myMod=getModule(im))) {
|
||||||
//extra gain and offset
|
//extra gain and offset
|
||||||
if(thisDetector->nGain)
|
if(thisDetector->nGain)
|
||||||
ret=writeCalibrationFile(ostfn.str(),gain, offset,(int64_t)thisDetector->tDead, thisDetector->myDetectorType);
|
ret=writeCalibrationFile(ostfn.str(),gain, offset);
|
||||||
//normal gain and offset inside sls_detector_module
|
//normal gain and offset inside sls_detector_module
|
||||||
else
|
else
|
||||||
ret=writeCalibrationFile(ostfn.str(),myMod->gain, myMod->offset);
|
ret=writeCalibrationFile(ostfn.str(),myMod->gain, myMod->offset);
|
||||||
|
@ -507,11 +507,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
|||||||
\param fname name of the file to be written
|
\param fname name of the file to be written
|
||||||
\param imod module number
|
\param imod module number
|
||||||
\param iodelay io delay (detector specific)
|
\param iodelay io delay (detector specific)
|
||||||
|
\param tau tau (detector specific)
|
||||||
\returns OK or FAIL if the file could not be written
|
\returns OK or FAIL if the file could not be written
|
||||||
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
|
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
|
||||||
*/
|
*/
|
||||||
using energyConversion::writeSettingsFile;
|
using energyConversion::writeSettingsFile;
|
||||||
int writeSettingsFile(string fname, int imod, int* iodelay=0);
|
int writeSettingsFile(string fname, int imod, int& iodelay, int& tau);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -948,14 +949,15 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
|||||||
/**
|
/**
|
||||||
configure chip
|
configure chip
|
||||||
\param module module to be set - must contain correct module number and also channel and chip registers
|
\param module module to be set - must contain correct module number and also channel and chip registers
|
||||||
\param gainval pointer to extra gain values
|
|
||||||
\param offsetval pointer to extra offset values
|
|
||||||
\param iodelay iodelay (detector specific)
|
\param iodelay iodelay (detector specific)
|
||||||
\param tau tau (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
|
||||||
\returns current register value
|
\returns current register value
|
||||||
\sa ::sls_detector_module
|
\sa ::sls_detector_module
|
||||||
*/
|
*/
|
||||||
int setModule(sls_detector_module module, int* gainval, int* offsetval,int* iodelay, int64_t tau);
|
int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0);
|
||||||
//virtual int setModule(sls_detector_module module);
|
//virtual int setModule(sls_detector_module module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -989,6 +991,14 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
|||||||
\returns current threshold value for imod in ev (-1 failed)
|
\returns current threshold value for imod in ev (-1 failed)
|
||||||
*/
|
*/
|
||||||
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS);
|
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
set threshold energy
|
||||||
|
\param e_eV threshold in eV
|
||||||
|
\param isettings ev. change settings
|
||||||
|
\returns OK if successful, else FAIL
|
||||||
|
*/
|
||||||
|
int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
get detector settings
|
get detector settings
|
||||||
|
@ -433,10 +433,6 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
|
|||||||
int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);};
|
int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);};
|
||||||
|
|
||||||
|
|
||||||
// int getBeamEnergy(){return 2*getThresholdEnergy();};
|
|
||||||
//int setBeamEnergy(int e){return 2*setThresholdEnergy(e/2);};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Prints receiver configuration
|
Prints receiver configuration
|
||||||
\returns OK or FAIL
|
\returns OK or FAIL
|
||||||
|
@ -184,7 +184,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
descrToFuncMap[i].m_pFuncName="trimen";
|
descrToFuncMap[i].m_pFuncName="trimen";
|
||||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment;
|
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTrimEn;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
|
||||||
@ -3297,15 +3297,28 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
|
|||||||
myDet->setOnline(ONLINE_FLAG);
|
myDet->setOnline(ONLINE_FLAG);
|
||||||
|
|
||||||
if (cmd=="settings") {
|
if (cmd=="settings") {
|
||||||
if (action==PUT_ACTION)
|
detectorSettings sett = GET_SETTINGS;
|
||||||
myDet->setSettings(myDet->getDetectorSettings(string(args[1])));
|
if (action==PUT_ACTION) {
|
||||||
|
sett = myDet->setSettings(myDet->getDetectorSettings(string(args[1])));
|
||||||
|
if (myDet->getDetectorsType() == EIGER) {
|
||||||
|
return myDet->getDetectorSettings(sett);
|
||||||
|
}
|
||||||
|
}
|
||||||
return myDet->getDetectorSettings(myDet->getSettings());
|
return myDet->getDetectorSettings(myDet->getSettings());
|
||||||
} else if (cmd=="threshold") {
|
} else if (cmd=="threshold") {
|
||||||
if (action==PUT_ACTION) {
|
if (action==PUT_ACTION) {
|
||||||
if (sscanf(args[1],"%d",&val))
|
detectorType type = myDet->getDetectorsType();
|
||||||
myDet->setThresholdEnergy(val);
|
if (!sscanf(args[1],"%d",&val)) {
|
||||||
else
|
return string("invalid threshold value");
|
||||||
return string("invalid threshold value ")+cmd;
|
}
|
||||||
|
if (type != EIGER || (type == EIGER && narg<=2)) {
|
||||||
|
myDet->setThresholdEnergy(val);
|
||||||
|
} else {
|
||||||
|
detectorSettings sett= myDet->getDetectorSettings(string(args[2]));
|
||||||
|
if(sett == -1)
|
||||||
|
return string("invalid settings value");
|
||||||
|
myDet->setThresholdEnergy(val, -1, sett);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sprintf(ans,"%d",myDet->getThresholdEnergy());
|
sprintf(ans,"%d",myDet->getThresholdEnergy());
|
||||||
return string(ans);
|
return string(ans);
|
||||||
|
@ -147,14 +147,6 @@ int slsDetectorUsers::setThresholdEnergy(int e_eV){
|
|||||||
return myDetector->setThresholdEnergy(e_eV);
|
return myDetector->setThresholdEnergy(e_eV);
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetectorUsers::getBeamEnergy(){
|
|
||||||
return 2*myDetector->getThresholdEnergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
int slsDetectorUsers::setBeamEnergy(int e_eV){
|
|
||||||
return 2*myDetector->setThresholdEnergy(e_eV/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
double slsDetectorUsers::setExposureTime(double t, bool inseconds){
|
double slsDetectorUsers::setExposureTime(double t, bool inseconds){
|
||||||
int64_t tms = (int64_t)(t * (1E+9));
|
int64_t tms = (int64_t)(t * (1E+9));
|
||||||
if (t < 0) tms = -1;
|
if (t < 0) tms = -1;
|
||||||
|
@ -302,19 +302,6 @@ class slsDetectorUsers
|
|||||||
*/
|
*/
|
||||||
int setThresholdEnergy(int e_eV);
|
int setThresholdEnergy(int e_eV);
|
||||||
|
|
||||||
/**
|
|
||||||
@short get beam energy -- only for dectris!
|
|
||||||
\returns current beam energy
|
|
||||||
*/
|
|
||||||
int getBeamEnergy();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
@short set beam energy -- only for dectris!
|
|
||||||
\param e_eV beam in eV
|
|
||||||
\returns current beam energyin ev (-1 failed)
|
|
||||||
*/
|
|
||||||
int setBeamEnergy(int e_eV);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@short set/get exposure time value
|
@short set/get exposure time value
|
||||||
|
@ -69,85 +69,58 @@ int energyConversion::writeCalibrationFile(string fname, double gain, double off
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int energyConversion::readCalibrationFile(string fname, int *gain, int *offset, int64_t &tau, detectorType myDetectorType){
|
int energyConversion::readCalibrationFile(string fname, int *gain, int *offset){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string str;
|
string str;
|
||||||
ifstream infile;
|
ifstream infile;
|
||||||
double o,g;
|
double o,g;
|
||||||
int ig=0;
|
int ig=0;
|
||||||
switch (myDetectorType) {
|
|
||||||
case EIGER:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Opening file "<< fname << std::endl;
|
std::cout<< "Opening file "<< fname << std::endl;
|
||||||
#endif
|
#endif
|
||||||
infile.open(fname.c_str(), ios_base::in);
|
infile.open(fname.c_str(), ios_base::in);
|
||||||
if (infile.is_open()) {
|
if (infile.is_open()) {
|
||||||
//get gain and offset
|
//get gain and offset
|
||||||
for (ig=0; ig<4; ig++) {
|
for (ig=0; ig<4; ig++) {
|
||||||
//while ( (getline(infile,str)) > -1) {
|
//while ( (getline(infile,str)) > -1) {
|
||||||
getline(infile,str);
|
getline(infile,str);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< str << std::endl;
|
std::cout<< str << std::endl;
|
||||||
#endif
|
#endif
|
||||||
istringstream ssstr(str);
|
istringstream ssstr(str);
|
||||||
ssstr >> o >> g;
|
ssstr >> o >> g;
|
||||||
offset[ig]=(int)(o*1000);
|
offset[ig]=(int)(o*1000);
|
||||||
gain[ig]=(int)(g*1000);
|
gain[ig]=(int)(g*1000);
|
||||||
// ig++;
|
// ig++;
|
||||||
if (ig>=4)
|
if (ig>=4)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
//get tau
|
|
||||||
if (myDetectorType == EIGER) {
|
|
||||||
if(getline(infile,str)){
|
|
||||||
istringstream ssstr(str);
|
|
||||||
ssstr >> tau;
|
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout<< "tau:" << tau << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
infile.close();
|
|
||||||
cout << "Calibration file loaded: " << fname << endl;
|
|
||||||
} else {
|
|
||||||
cout << "Could not open calibration file: "<< fname << std::endl;
|
|
||||||
gain[0]=0;
|
|
||||||
offset[0]=0;
|
|
||||||
#ifndef MYROOT
|
|
||||||
return FAIL;
|
|
||||||
#endif
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
infile.close();
|
||||||
|
cout << "Calibration file loaded: " << fname << endl;
|
||||||
|
} else {
|
||||||
|
cout << "Could not open calibration file: "<< fname << std::endl;
|
||||||
|
gain[0]=0;
|
||||||
|
offset[0]=0;
|
||||||
#ifndef MYROOT
|
#ifndef MYROOT
|
||||||
return OK;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl;
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifndef MYROOT
|
||||||
|
return OK;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset, int64_t tau, detectorType myDetectorType){
|
int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset){
|
||||||
//std::cout<< "Function not yet implemented " << std::endl;
|
//std::cout<< "Function not yet implemented " << std::endl;
|
||||||
ofstream outfile;
|
ofstream outfile;
|
||||||
switch (myDetectorType) {
|
|
||||||
case EIGER:
|
|
||||||
|
|
||||||
outfile.open (fname.c_str());
|
outfile.open (fname.c_str());
|
||||||
|
|
||||||
// >> i/o operations here <<
|
// >> i/o operations here <<
|
||||||
if (outfile.is_open()) {
|
if (outfile.is_open()) {
|
||||||
for (int ig=0; ig<4; ig++)
|
for (int ig=0; ig<4; ig++)
|
||||||
outfile << ((double)offset[ig]/1000) << " " << ((double)gain[ig]/1000) << std::endl;
|
outfile << ((double)offset[ig]/1000) << " " << ((double)gain[ig]/1000) << std::endl;
|
||||||
outfile << tau << std::endl;
|
|
||||||
} else {
|
} else {
|
||||||
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
|
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
|
||||||
#ifndef MYROOT
|
#ifndef MYROOT
|
||||||
@ -161,21 +134,53 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset,
|
|||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl;
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2){
|
||||||
|
// only implemented for eiger currently (in terms of which dacs)
|
||||||
|
if(myDetectorType != EIGER) {
|
||||||
|
printf("Interpolation of Trim values not implemented for this detector!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sls_detector_module* myMod = createModule(myDetectorType);
|
||||||
|
enum eiger_DacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS};
|
||||||
|
|
||||||
|
//Copy other dacs
|
||||||
|
int num_dacs_to_copy = 10;
|
||||||
|
int dacs_to_copy[] = {SVP,VTR,VRS,SVN,VTGSTV,CAL,RXB_RB,RXB_LB,VCN,VIS};
|
||||||
|
for (int i = 0; i < num_dacs_to_copy; ++i) {
|
||||||
|
if(a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) {
|
||||||
|
deleteModule(myMod);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
myMod->dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Interpolate vrf, vcmp, vcp
|
||||||
|
int num_dacs_to_interpolate = 6;
|
||||||
|
int dacs_to_interpolate[] = {VRF,VCMP_LL,VCMP_LR,VCMP_RL,VCMP_RR,VCP};
|
||||||
|
for (int i = 0; i < num_dacs_to_interpolate; ++i) {
|
||||||
|
myMod->dacs[dacs_to_interpolate[i]] = linearInterpolation(energy, e1, e2,
|
||||||
|
a->dacs[dacs_to_interpolate[i]], b->dacs[dacs_to_interpolate[i]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Interpolate all trimbits
|
||||||
|
for (int i = 0; i<myMod->nchan; i++)
|
||||||
|
myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]);
|
||||||
|
return myMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MYROOT
|
#ifndef MYROOT
|
||||||
|
|
||||||
/* I/O */
|
/* I/O */
|
||||||
|
|
||||||
|
|
||||||
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod, int* iodelay){
|
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -353,7 +358,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
strcpy(settingsFile,fname.c_str());
|
strcpy(settingsFile,fname.c_str());
|
||||||
cout << "Settings file loaded: " << settingsFile << endl;
|
printf("Settings file loaded: %s\n",settingsFile);
|
||||||
return myMod;
|
return myMod;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -365,12 +370,14 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
infile.open(myfname.c_str(),ifstream::binary);
|
infile.open(myfname.c_str(),ifstream::binary);
|
||||||
if (infile.is_open()) {
|
if (infile.is_open()) {
|
||||||
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
|
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
|
||||||
infile.read((char*) iodelay,sizeof(*iodelay));
|
infile.read((char*)&iodelay,sizeof(iodelay));
|
||||||
|
infile.read((char*)&tau,sizeof(tau));
|
||||||
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
|
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
for(int i=0;i<myMod->ndac;i++)
|
for(int i=0;i<myMod->ndac;i++)
|
||||||
std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl;
|
std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl;
|
||||||
std::cout << "iodelay:" << *iodelay << std::endl;
|
std::cout << "iodelay:" << iodelay << std::endl;
|
||||||
|
std::cout << "tau:" << tau << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if(infile.eof()){
|
if(infile.eof()){
|
||||||
cout<<endl<<"Error, could not load trimbits end of file, "<<myfname<<", reached."<<endl<<endl;
|
cout<<endl<<"Error, could not load trimbits end of file, "<<myfname<<", reached."<<endl<<endl;
|
||||||
@ -381,7 +388,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
}
|
}
|
||||||
infile.close();
|
infile.close();
|
||||||
strcpy(settingsFile,fname.c_str());
|
strcpy(settingsFile,fname.c_str());
|
||||||
cout << "Settings file loaded: " << settingsFile << endl;
|
printf("Settings file loaded: %s\n",settingsFile);
|
||||||
return myMod;
|
return myMod;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -423,7 +430,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
strcpy(settingsFile,fname.c_str());
|
strcpy(settingsFile,fname.c_str());
|
||||||
cout << "Settings file loaded: " << settingsFile << endl;
|
printf("Settings file loaded: %s\n",settingsFile);
|
||||||
return myMod;
|
return myMod;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -439,7 +446,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout<< "Error: Could not open settings file " << myfname << std::endl;
|
printf("Error: Could not open settings file %s\n", myfname.c_str());
|
||||||
if (nflag)
|
if (nflag)
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
|
|
||||||
@ -450,7 +457,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay){
|
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int& iodelay, int& tau){
|
||||||
|
|
||||||
ofstream outfile;
|
ofstream outfile;
|
||||||
|
|
||||||
@ -526,17 +533,19 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
for(int i=0;i<mod.ndac;i++)
|
for(int i=0;i<mod.ndac;i++)
|
||||||
std::cout << "dac " << i << ":" << mod.dacs[i] << std::endl;
|
std::cout << "dac " << i << ":" << mod.dacs[i] << std::endl;
|
||||||
std::cout << "iodelay: " << *iodelay << std::endl;
|
std::cout << "iodelay: " << iodelay << std::endl;
|
||||||
|
std::cout << "tau: " << tau << std::endl;
|
||||||
#endif
|
#endif
|
||||||
outfile.write((char*)mod.dacs, sizeof(dacs_t)*(mod.ndac));
|
outfile.write((char*)mod.dacs, sizeof(dacs_t)*(mod.ndac));
|
||||||
outfile.write((char*)iodelay, sizeof(*iodelay));
|
outfile.write((char*)iodelay, sizeof(iodelay));
|
||||||
|
outfile.write((char*)tau, sizeof(tau));
|
||||||
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
|
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
|
||||||
|
|
||||||
outfile.close();
|
outfile.close();
|
||||||
return slsDetectorDefs::OK;
|
return slsDetectorDefs::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout<< "could not open SETTINGS file " << fname << std::endl;
|
printf("Could not open Settings file %s\n", fname.c_str());
|
||||||
return slsDetectorDefs::FAIL;
|
return slsDetectorDefs::FAIL;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
@ -35,7 +35,9 @@ class energyConversion
|
|||||||
reads a calibration file
|
reads a calibration file
|
||||||
\param fname file to be read
|
\param fname file to be read
|
||||||
\param gain reference to the gain variable
|
\param gain reference to the gain variable
|
||||||
\offset reference to the offset variable
|
\param offset reference to the offset variable
|
||||||
|
\returns OK if successful, else FAIL or -1
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static int readCalibrationFile(string fname, double &gain, double &offset);
|
static int readCalibrationFile(string fname, double &gain, double &offset);
|
||||||
|
|
||||||
@ -44,36 +46,51 @@ class energyConversion
|
|||||||
\param fname file to be written
|
\param fname file to be written
|
||||||
\param gain
|
\param gain
|
||||||
\param offset
|
\param offset
|
||||||
|
\returns OK if successful, else FAIL or -1
|
||||||
*/
|
*/
|
||||||
static int writeCalibrationFile(string fname, double gain, double offset);
|
static int writeCalibrationFile(string fname, double gain, double offset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
reads a calibration file
|
reads a calibration file
|
||||||
\param fname file to be read
|
\param fname file to be read
|
||||||
\param gain reference to the gain variable
|
\param gain reference to the gain variable
|
||||||
\offset reference to the offset variable
|
\param offset reference to the offset variable
|
||||||
\tau tau
|
\returns OK if successful, else FAIL or -1
|
||||||
\tau tau
|
|
||||||
*/
|
*/
|
||||||
static int readCalibrationFile(string fname, int *gain, int *offset, int64_t &tau, detectorType myDetectorType);
|
static int readCalibrationFile(string fname, int *gain, int *offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
writes a calibration file
|
writes a calibration file
|
||||||
\param fname file to be written
|
\param fname file to be written
|
||||||
\param gain
|
\param gain reference to the gain variable
|
||||||
\param offset
|
\param offset reference to the offset variable
|
||||||
\param tau
|
\returns OK if successful, else FAIL or -1
|
||||||
*/
|
*/
|
||||||
static int writeCalibrationFile(string fname, int *gain, int *offset, int64_t tau, detectorType myDetectorType);
|
static int writeCalibrationFile(string fname, int *gain, int *offset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Template function to do linear interpolation between two points
|
||||||
|
template <typename E, typename V>
|
||||||
|
V linearInterpolation(const E x, const E x1, const E x2, const V y1, const V y2){
|
||||||
|
double k = static_cast<double>(y2-y1)/(x2-x1);
|
||||||
|
double m = y1-k*x1;
|
||||||
|
int y = round( k*x+m );
|
||||||
|
return static_cast<V>(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* interpolates dacs and trimbits between 2 trim files
|
||||||
|
\param myDetectorType detector type (needed for which dacs that neeeds to be interpolated & which kept same)
|
||||||
|
\param a first module structure
|
||||||
|
\param b second module structure
|
||||||
|
\param energy energy to trim at
|
||||||
|
\param e1 reference trim value
|
||||||
|
\param e2 reference trim value
|
||||||
|
\returns the pointer to the module structure with interpolated values or NULL if error
|
||||||
|
*/
|
||||||
|
sls_detector_module* interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -83,12 +100,13 @@ class energyConversion
|
|||||||
reads a trim/settings file
|
reads a trim/settings file
|
||||||
\param fname name of the file to be read
|
\param fname name of the file to be read
|
||||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||||
\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 iodelay io delay (detector specific)
|
\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
|
||||||
\returns the pointer to myMod or NULL if reading the file failed
|
\returns the pointer to myMod or NULL if reading the file failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL, int* iodelay=0);
|
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
writes a trim/settings file
|
writes a trim/settings file
|
||||||
@ -96,11 +114,12 @@ class energyConversion
|
|||||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||||
\param mod module structure which has to be written to file
|
\param mod module structure which has to be written to file
|
||||||
\param iodelay io delay (detector specific)
|
\param iodelay io delay (detector specific)
|
||||||
|
\param tau tau (detector specific)
|
||||||
\returns OK or FAIL if the file could not be written
|
\returns OK or FAIL if the file could not be written
|
||||||
|
|
||||||
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
||||||
*/
|
*/
|
||||||
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int* iodelay=0);
|
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod, int& iodelay, int& tau);
|
||||||
|
|
||||||
/** allocates the momery for a detector module structure
|
/** allocates the momery for a detector module structure
|
||||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||||
@ -114,6 +133,7 @@ class energyConversion
|
|||||||
*/
|
*/
|
||||||
virtual void deleteModule(sls_detector_module *myMod)=0;
|
virtual void deleteModule(sls_detector_module *myMod)=0;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** pointer to settings file name */
|
/** pointer to settings file name */
|
||||||
char *settingsFile;
|
char *settingsFile;
|
||||||
|
@ -72,14 +72,12 @@ int getChip(sls_detector_chip *myChip);
|
|||||||
|
|
||||||
|
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay);
|
int setModule(sls_detector_module myMod, int delay);
|
||||||
int getModule(sls_detector_module *myMod, int* gain, int* offset);
|
|
||||||
#else
|
#else
|
||||||
int setModule(sls_detector_module myMod);
|
int setModule(sls_detector_module myMod);
|
||||||
int getModule(sls_detector_module *myMod);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int getModule(sls_detector_module *myMod);
|
||||||
enum detectorSettings setSettings(enum detectorSettings sett, int imod);
|
enum detectorSettings setSettings(enum detectorSettings sett, int imod);
|
||||||
enum detectorSettings getSettings();
|
enum detectorSettings getSettings();
|
||||||
|
|
||||||
|
@ -1867,10 +1867,9 @@ int set_module(int file_des) {
|
|||||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||||
sls_detector_module myModule;
|
sls_detector_module myModule;
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
|
int myIODelay = -1;
|
||||||
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
|
int myTau = -1;
|
||||||
int *myIODelay = (int*)malloc(sizeof(int));
|
int myEV = -1;
|
||||||
int64_t myTau=-1;
|
|
||||||
#endif
|
#endif
|
||||||
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
|
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
|
||||||
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
|
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
|
||||||
@ -1902,16 +1901,6 @@ int set_module(int file_des) {
|
|||||||
sprintf(mess,"could not allocate chans\n");
|
sprintf(mess,"could not allocate chans\n");
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
#ifdef EIGERD
|
|
||||||
if (!myGain){
|
|
||||||
sprintf(mess,"could not allocate gains\n");
|
|
||||||
ret=FAIL;
|
|
||||||
}
|
|
||||||
if (!myOffset){
|
|
||||||
sprintf(mess,"could not allocate offsets\n");
|
|
||||||
ret=FAIL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
myModule.nchip=getNumberOfChipsPerModule();
|
myModule.nchip=getNumberOfChipsPerModule();
|
||||||
myModule.nchan=getNumberOfChannelsPerModule();
|
myModule.nchan=getNumberOfChannelsPerModule();
|
||||||
myModule.ndac=getNumberOfDACsPerModule();
|
myModule.ndac=getNumberOfDACsPerModule();
|
||||||
@ -1923,10 +1912,9 @@ int set_module(int file_des) {
|
|||||||
#endif
|
#endif
|
||||||
ret=receiveModule(file_des, &myModule);
|
ret=receiveModule(file_des, &myModule);
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
n = receiveData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
|
n = receiveData(file_des,&myIODelay,sizeof(myIODelay),INT32);
|
||||||
n = receiveData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
|
n = receiveData(file_des,&myTau,sizeof(myTau),INT32);
|
||||||
n = receiveData(file_des,myIODelay,sizeof(int),INT32);
|
n = receiveData(file_des,&myEV,sizeof(myEV),INT32);
|
||||||
n = receiveData(file_des,&myTau,sizeof(myTau),INT64);
|
|
||||||
#endif
|
#endif
|
||||||
if (ret>=0)
|
if (ret>=0)
|
||||||
ret=OK;
|
ret=OK;
|
||||||
@ -1937,16 +1925,12 @@ int set_module(int file_des) {
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset);
|
printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset);
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
int i;
|
printf("IO Delay:%d\n",myIODelay);
|
||||||
for(i=0;i<getNumberOfGainsPerModule();i++)
|
printf("Tau:%d\n",myTau);
|
||||||
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
|
printf("eV:%d\n",myEV);
|
||||||
for(i=0;i<getNumberOfOffsetsPerModule();i++)
|
|
||||||
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
|
|
||||||
printf("IO Delay:%d\n",*myIODelay);
|
|
||||||
printf("Tau:%lld\n",(long long int)myTau);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef EIGERD
|
||||||
switch(myModule.reg){
|
switch(myModule.reg){
|
||||||
case STANDARD:
|
case STANDARD:
|
||||||
case HIGHGAIN:
|
case HIGHGAIN:
|
||||||
@ -1961,7 +1945,7 @@ int set_module(int file_des) {
|
|||||||
cprintf(RED,"%s",mess);
|
cprintf(RED,"%s",mess);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret==OK) {
|
if (ret==OK) {
|
||||||
if (differentClients==1 && lockStatus==1) {
|
if (differentClients==1 && lockStatus==1) {
|
||||||
@ -1969,33 +1953,31 @@ int set_module(int file_des) {
|
|||||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
} else {
|
} else {
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
ret=setModule(myModule, myGain, myOffset,myIODelay);
|
//set threshhold
|
||||||
|
if (myEV >= 0) setThresholdEnergy(myEV,-1);
|
||||||
|
//set dacs, trimbits and iodelay
|
||||||
|
ret=setModule(myModule, myIODelay);
|
||||||
|
|
||||||
//rate correction
|
//rate correction
|
||||||
if(myTau > -2){ //ignore -2: from load settings)
|
//switch off rate correction: no value read from load calib/load settings)
|
||||||
|
if(myTau == -1){
|
||||||
//set default tau value (-1 or a normal value)
|
if(getRateCorrectionEnable()){
|
||||||
setDefaultSettingsTau_in_nsec(myTau);
|
ret = FAIL;
|
||||||
|
setRateCorrection(0);
|
||||||
//switch off rate correction: no value read from load calib/load settings)
|
strcat(mess,"Cannot set Rate correction. No default tau provided. Deactivating Rate Correction\n");
|
||||||
if(myTau == -1){
|
cprintf(RED,"%s",mess);
|
||||||
if(getRateCorrectionEnable()){
|
|
||||||
ret = FAIL;
|
|
||||||
setRateCorrection(0);
|
|
||||||
strcat(mess,"Cannot set Rate correction. No default tau provided. Deactivating Rate Correction\n");
|
|
||||||
cprintf(RED,"%s",mess);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//normal tau value (only if enabled)
|
|
||||||
else if (getRateCorrectionEnable()){
|
|
||||||
int64_t retvalTau = setRateCorrection(myTau); //myTau will not be -1 here
|
|
||||||
if(myTau != retvalTau){
|
|
||||||
cprintf(RED,"%s",mess);
|
|
||||||
ret=FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//normal tau value (only if enabled)
|
||||||
|
else if (getRateCorrectionEnable()){
|
||||||
|
int64_t retvalTau = setRateCorrection(myTau);
|
||||||
|
if(myTau != retvalTau){
|
||||||
|
cprintf(RED,"%s",mess);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
retval = getSettings();
|
retval = getSettings();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -2027,10 +2009,6 @@ int set_module(int file_des) {
|
|||||||
free(myChan);
|
free(myChan);
|
||||||
free(myDac);
|
free(myDac);
|
||||||
free(myAdc);
|
free(myAdc);
|
||||||
#ifdef EIGERD
|
|
||||||
free(myGain);
|
|
||||||
free(myOffset);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2048,10 +2026,6 @@ int get_module(int file_des) {
|
|||||||
sls_detector_module myModule;
|
sls_detector_module myModule;
|
||||||
|
|
||||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||||
#ifdef EIGERD
|
|
||||||
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
|
|
||||||
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
|
|
||||||
#endif
|
|
||||||
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
|
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
|
||||||
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
|
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
|
||||||
int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int));
|
int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int));
|
||||||
@ -2082,16 +2056,6 @@ int get_module(int file_des) {
|
|||||||
sprintf(mess,"could not allocate chans\n");
|
sprintf(mess,"could not allocate chans\n");
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
#ifdef EIGERD
|
|
||||||
if (!myGain){
|
|
||||||
sprintf(mess,"could not allocate gains\n");
|
|
||||||
ret=FAIL;
|
|
||||||
}
|
|
||||||
if (!myOffset){
|
|
||||||
sprintf(mess,"could not allocate offsets\n");
|
|
||||||
ret=FAIL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
myModule.ndac=getNumberOfDACsPerModule();
|
myModule.ndac=getNumberOfDACsPerModule();
|
||||||
myModule.nchip=getNumberOfChipsPerModule();
|
myModule.nchip=getNumberOfChipsPerModule();
|
||||||
myModule.nchan=getNumberOfChannelsPerModule();
|
myModule.nchan=getNumberOfChannelsPerModule();
|
||||||
@ -2114,18 +2078,7 @@ int get_module(int file_des) {
|
|||||||
if (imod>=0) {
|
if (imod>=0) {
|
||||||
ret=OK;
|
ret=OK;
|
||||||
myModule.module=imod;
|
myModule.module=imod;
|
||||||
#ifdef EIGERD
|
|
||||||
getModule(&myModule, myGain, myOffset);
|
|
||||||
#ifdef VERBOSE
|
|
||||||
for(i=0;i<getNumberOfGainsPerModule();i++)
|
|
||||||
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
|
|
||||||
for(i=0;i<getNumberOfOffsetsPerModule();i++)
|
|
||||||
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
getModule(&myModule);
|
getModule(&myModule);
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Returning module %d of register %x\n", imod, myModule.reg);
|
printf("Returning module %d of register %x\n", imod, myModule.reg);
|
||||||
@ -2144,10 +2097,6 @@ int get_module(int file_des) {
|
|||||||
if (ret!=FAIL) {
|
if (ret!=FAIL) {
|
||||||
/* send return argument */
|
/* send return argument */
|
||||||
ret=sendModule(file_des, &myModule);
|
ret=sendModule(file_des, &myModule);
|
||||||
#ifdef EIGERD
|
|
||||||
n = sendData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
|
|
||||||
n = sendData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
n += sendData(file_des,mess,sizeof(mess),OTHER);
|
n += sendData(file_des,mess,sizeof(mess),OTHER);
|
||||||
}
|
}
|
||||||
@ -2157,10 +2106,6 @@ int get_module(int file_des) {
|
|||||||
free(myChan);
|
free(myChan);
|
||||||
free(myDac);
|
free(myDac);
|
||||||
free(myAdc);
|
free(myAdc);
|
||||||
#ifdef EIGERD
|
|
||||||
free(myGain);
|
|
||||||
free(myOffset);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
/*return ok/fail*/
|
/*return ok/fail*/
|
||||||
return ret;
|
return ret;
|
||||||
@ -2300,7 +2245,7 @@ int set_threshold_energy(int file_des) {
|
|||||||
int ret=OK,ret1=OK;
|
int ret=OK,ret1=OK;
|
||||||
int arg[3];
|
int arg[3];
|
||||||
int n;
|
int n;
|
||||||
#if defined(MYTHEND) || defined(EIGERD)
|
#if defined(MYTHEND)
|
||||||
int ethr, imod;
|
int ethr, imod;
|
||||||
enum detectorSettings isett;
|
enum detectorSettings isett;
|
||||||
#endif
|
#endif
|
||||||
@ -2311,7 +2256,7 @@ int set_threshold_energy(int file_des) {
|
|||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MYTHEND) || defined(EIGERD)
|
#if defined(MYTHEND)
|
||||||
ethr=arg[0];
|
ethr=arg[0];
|
||||||
imod=arg[1];
|
imod=arg[1];
|
||||||
isett=arg[2];
|
isett=arg[2];
|
||||||
@ -2338,6 +2283,14 @@ int set_threshold_energy(int file_des) {
|
|||||||
sprintf(mess,"Setting threshold of module %d: wrote %d but read %d\n", imod, ethr, retval);
|
sprintf(mess,"Setting threshold of module %d: wrote %d but read %d\n", imod, ethr, retval);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(EIGERD)
|
||||||
|
sprintf(mess,"Setting Threshold only via settings implemented for this detector\n");
|
||||||
|
cprintf(RED, "%s",mess);
|
||||||
|
ret=FAIL;
|
||||||
|
#else
|
||||||
|
sprintf(mess,"Not implemented for this detector\n");
|
||||||
|
cprintf(RED, "%s",mess);
|
||||||
|
ret=FAIL;
|
||||||
#endif
|
#endif
|
||||||
if (ret==OK && differentClients==1)
|
if (ret==OK && differentClients==1)
|
||||||
ret=FORCE_UPDATE;
|
ret=FORCE_UPDATE;
|
||||||
@ -3994,20 +3947,14 @@ int set_rate_correct(int file_des) {
|
|||||||
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//tau = -1, use default tau of settings
|
|
||||||
if((ret==OK)&&(tau_ns<0)){
|
|
||||||
tau_ns = getDefaultSettingsTau_in_nsec();
|
|
||||||
}
|
|
||||||
//still negative (not set)
|
//still negative (not set)
|
||||||
if(tau_ns < 0){
|
if(tau_ns < 0){
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
if(getRateCorrectionEnable()){
|
if(getRateCorrectionEnable()){
|
||||||
setRateCorrection(0);
|
setRateCorrection(0);
|
||||||
strcpy(mess,"Cannot set rate correction as default tau not provided. Switching off Rate Correction\n");
|
strcpy(mess,"Cannot set rate correction as tau must be >=0. Switching off Rate Correction\n");
|
||||||
}else{
|
cprintf(RED,"%s",mess);
|
||||||
strcpy(mess,"Cannot set rate correction as default tau not provided\n");
|
|
||||||
}
|
}
|
||||||
cprintf(RED,"%s",mess);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//set rate
|
//set rate
|
||||||
@ -4020,7 +3967,7 @@ int set_rate_correct(int file_des) {
|
|||||||
}
|
}
|
||||||
//32 bit mode
|
//32 bit mode
|
||||||
else{
|
else{
|
||||||
int64_t retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
|
int64_t retval = setRateCorrection(tau_ns);
|
||||||
if(tau_ns != retval){
|
if(tau_ns != retval){
|
||||||
cprintf(RED,"%s",mess);
|
cprintf(RED,"%s",mess);
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
|
@ -106,29 +106,31 @@ private:
|
|||||||
class Task: public virtual slsDetectorDefs{
|
class Task: public virtual slsDetectorDefs{
|
||||||
public:
|
public:
|
||||||
/* Return: int, Param: int */
|
/* Return: int, Param: int */
|
||||||
Task(func1_t <int,slsDetector,int,int>* t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func1_t <int,slsDetector,int,int>* t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: int, Param: string,int */
|
/* Return: int, Param: string,int */
|
||||||
Task(func2_t <int,slsDetector,string,int,int>* t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func2_t <int,slsDetector,string,int,int>* t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: string, Param: string */
|
/* Return: string, Param: string */
|
||||||
Task(func1_t <string,slsDetector,string,string>* t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func1_t <string,slsDetector,string,string>* t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: char*, Param: char* */
|
/* Return: char*, Param: char* */
|
||||||
Task(func1_t <char*,slsDetector,char*,string>* t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func1_t <char*,slsDetector,char*,string>* t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: detectorSettings, Param: int */
|
/* Return: detectorSettings, Param: int */
|
||||||
Task(func1_t <detectorSettings,slsDetector,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func1_t <detectorSettings,slsDetector,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: detectorSettings, Param: detectorSettings,int */
|
/* Return: detectorSettings, Param: detectorSettings,int */
|
||||||
Task(func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: int, Param: int,int */
|
/* Return: int, Param: int,int */
|
||||||
Task(func2_t <int,slsDetector,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0){};
|
Task(func2_t <int,slsDetector,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: int, Param: int,int */
|
/* Return: int, Param: int,int,int */
|
||||||
Task(func3_t <int,slsDetector,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0){};
|
Task(func3_t <int,slsDetector,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: int, Param: trimMode,int,int,int */
|
/* Return: int, Param: trimMode,int,int,int */
|
||||||
Task(func4_t <int,slsDetector,trimMode,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0){};
|
Task(func4_t <int,slsDetector,trimMode,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0),m13(0){};
|
||||||
/* Return: int, Param: none */
|
/* Return: int, Param: none */
|
||||||
Task(func0_t <int,slsDetector,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0){};
|
Task(func0_t <int,slsDetector,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0),m13(0){};
|
||||||
/* Return: char*, Param: networkParameter,string,string */
|
/* Return: char*, Param: networkParameter,string */
|
||||||
Task(func2_t <char*,slsDetector,networkParameter,string,string>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0){};
|
Task(func2_t <char*,slsDetector,networkParameter,string,string>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0),m13(0){};
|
||||||
/* Return: void, Param: none */
|
/* Return: void, Param: none */
|
||||||
Task(func00_t <void,slsDetector>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t){};
|
Task(func00_t <void,slsDetector>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t),m13(0){};
|
||||||
|
/* Return: int, Param: int,int,detectorSettings */
|
||||||
|
Task(func3_t <int,slsDetector,int,int,detectorSettings,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t){};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -147,6 +149,7 @@ public:
|
|||||||
else if(m10) (*m10)();
|
else if(m10) (*m10)();
|
||||||
else if(m11) (*m11)();
|
else if(m11) (*m11)();
|
||||||
else if(m12) (*m12)();
|
else if(m12) (*m12)();
|
||||||
|
else if(m13) (*m13)();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -164,16 +167,18 @@ private:
|
|||||||
func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* m6;
|
func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* m6;
|
||||||
/* Return: int, Param: int,int */
|
/* Return: int, Param: int,int */
|
||||||
func2_t <int,slsDetector,int,int,int>* m7;
|
func2_t <int,slsDetector,int,int,int>* m7;
|
||||||
/* Return: int, Param: int,int */
|
/* Return: int, Param: int,int,int */
|
||||||
func3_t <int,slsDetector,int,int,int,int>* m8;
|
func3_t <int,slsDetector,int,int,int,int>* m8;
|
||||||
/* Return: int, Param: trimMode,int,int,int */
|
/* Return: int, Param: trimMode,int,int,int */
|
||||||
func4_t <int,slsDetector,trimMode,int,int,int,int>* m9;
|
func4_t <int,slsDetector,trimMode,int,int,int,int>* m9;
|
||||||
/* Return: int, Param: int */
|
/* Return: int, Param: int */
|
||||||
func0_t <int,slsDetector,int>* m10;
|
func0_t <int,slsDetector,int>* m10;
|
||||||
/* Return: char*, Param: networkParameter,string,string */
|
/* Return: char*, Param: networkParameter,string */
|
||||||
func2_t <char*,slsDetector,networkParameter,string,string>* m11;
|
func2_t <char*,slsDetector,networkParameter,string,string>* m11;
|
||||||
/* Return: void, Param: none */
|
/* Return: void, Param: none */
|
||||||
func00_t <void,slsDetector>* m12;
|
func00_t <void,slsDetector>* m12;
|
||||||
|
/* Return: int, Param: int,int,detectorSettings */
|
||||||
|
func3_t <int,slsDetector,int,int,detectorSettings,int>* m13;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user