mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-08 11:00:42 +02:00
added receiver in here
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@328 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
007995a5ec
commit
2338de4054
@ -87,7 +87,7 @@ typedef struct mac_header_struct{
|
|||||||
|
|
||||||
typedef struct ip_header_struct {
|
typedef struct ip_header_struct {
|
||||||
u_int16_t ip_len;
|
u_int16_t ip_len;
|
||||||
u_int8_t ip_tos;
|
u_int8_t ip_tos;
|
||||||
u_int8_t ip_ihl:4 ,ip_ver:4;
|
u_int8_t ip_ihl:4 ,ip_ver:4;
|
||||||
u_int16_t ip_offset:13,ip_flag:3;
|
u_int16_t ip_offset:13,ip_flag:3;
|
||||||
u_int16_t ip_ident;
|
u_int16_t ip_ident;
|
||||||
@ -109,15 +109,15 @@ typedef struct mac_conf_struct{
|
|||||||
mac_header mac;
|
mac_header mac;
|
||||||
ip_header ip;
|
ip_header ip;
|
||||||
udp_header udp;
|
udp_header udp;
|
||||||
u_int32_t npack;
|
u_int32_t npack;
|
||||||
u_int32_t lpack;
|
u_int32_t lpack;
|
||||||
u_int32_t npad;
|
u_int32_t npad;
|
||||||
u_int32_t cdone;
|
u_int32_t cdone;
|
||||||
} mac_conf;
|
} mac_conf;
|
||||||
|
|
||||||
typedef struct tse_conf_struct{
|
typedef struct tse_conf_struct{
|
||||||
u_int32_t rev; //0x0
|
u_int32_t rev; //0x0
|
||||||
u_int32_t scratch;
|
u_int32_t scratch;
|
||||||
u_int32_t command_config;
|
u_int32_t command_config;
|
||||||
u_int32_t mac_0; //0x3
|
u_int32_t mac_0; //0x3
|
||||||
u_int32_t mac_1;
|
u_int32_t mac_1;
|
||||||
@ -152,7 +152,7 @@ int mapCSP0(void) {
|
|||||||
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
|
if (CSP0BASE == (u_int32_t)MAP_FAILED) {
|
||||||
printf("\nCan't map memmory area!!\n");
|
printf("\nCan't map memmory area!!\n");
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
printf("CSP0 mapped\n");
|
printf("CSP0 mapped\n");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -168,7 +168,7 @@ int mapCSP0(void) {
|
|||||||
#endif
|
#endif
|
||||||
printf("CSPObase is 0x%x \n",CSP0BASE);
|
printf("CSPObase is 0x%x \n",CSP0BASE);
|
||||||
printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
|
printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE);
|
||||||
|
|
||||||
u_int32_t address;
|
u_int32_t address;
|
||||||
address = FIFO_DATA_REG_OFF;
|
address = FIFO_DATA_REG_OFF;
|
||||||
values=(u_int16_t*)(CSP0BASE+address*2);
|
values=(u_int16_t*)(CSP0BASE+address*2);
|
||||||
@ -210,7 +210,7 @@ u_int32_t bus_w(u_int32_t offset, u_int32_t data) {
|
|||||||
|
|
||||||
u_int32_t bus_r(u_int32_t offset) {
|
u_int32_t bus_r(u_int32_t offset) {
|
||||||
volatile u_int32_t *ptr1;
|
volatile u_int32_t *ptr1;
|
||||||
|
|
||||||
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
ptr1=(u_int32_t*)(CSP0BASE+offset*2);
|
||||||
return *ptr1;
|
return *ptr1;
|
||||||
}
|
}
|
||||||
@ -314,27 +314,27 @@ u_int32_t readin(int modnum) {
|
|||||||
u_int32_t setClockDivider(int d) {
|
u_int32_t setClockDivider(int d) {
|
||||||
u_int32_t c;
|
u_int32_t c;
|
||||||
c=bus_r(SPEED_REG);
|
c=bus_r(SPEED_REG);
|
||||||
bus_w(SPEED_REG,(d<<CLK_DIVIDER_OFFSET)|(c&~(CLK_DIVIDER_MASK)));
|
bus_w(SPEED_REG,(d<<CLK_DIVIDER_OFFSET)|(c&~(CLK_DIVIDER_MASK)));
|
||||||
return ((bus_r(SPEED_REG)& CLK_DIVIDER_MASK)>>CLK_DIVIDER_OFFSET);
|
return ((bus_r(SPEED_REG)& CLK_DIVIDER_MASK)>>CLK_DIVIDER_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t getClockDivider() {
|
u_int32_t getClockDivider() {
|
||||||
u_int32_t clk_div;
|
u_int32_t clk_div;
|
||||||
clk_div=((bus_r(SPEED_REG)&CLK_DIVIDER_MASK)>>CLK_DIVIDER_OFFSET);
|
clk_div=((bus_r(SPEED_REG)&CLK_DIVIDER_MASK)>>CLK_DIVIDER_OFFSET);
|
||||||
return clk_div;
|
return clk_div;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t setSetLength(int d) {
|
u_int32_t setSetLength(int d) {
|
||||||
u_int32_t c;
|
u_int32_t c;
|
||||||
c=bus_r(SPEED_REG);
|
c=bus_r(SPEED_REG);
|
||||||
bus_w(SPEED_REG,(d<<SET_LENGTH_OFFSET)|(c&~(SET_LENGTH_MASK)));
|
bus_w(SPEED_REG,(d<<SET_LENGTH_OFFSET)|(c&~(SET_LENGTH_MASK)));
|
||||||
return ((bus_r(SPEED_REG)& SET_LENGTH_MASK)>>SET_LENGTH_OFFSET);
|
return ((bus_r(SPEED_REG)& SET_LENGTH_MASK)>>SET_LENGTH_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t getSetLength() {
|
u_int32_t getSetLength() {
|
||||||
u_int32_t clk_div;
|
u_int32_t clk_div;
|
||||||
clk_div=((bus_r(SPEED_REG)& SET_LENGTH_MASK)>>SET_LENGTH_OFFSET);
|
clk_div=((bus_r(SPEED_REG)& SET_LENGTH_MASK)>>SET_LENGTH_OFFSET);
|
||||||
return clk_div;
|
return clk_div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -346,49 +346,49 @@ u_int32_t setWaitStates(int d1) {
|
|||||||
if (d1<=0xf) {
|
if (d1<=0xf) {
|
||||||
sprintf(cmd,"bus -a 0xb0000000 -w 0x%x0008",d1);
|
sprintf(cmd,"bus -a 0xb0000000 -w 0x%x0008",d1);
|
||||||
c=bus_r(SPEED_REG);
|
c=bus_r(SPEED_REG);
|
||||||
bus_w(SPEED_REG,(d<<WAIT_STATES_OFFSET)|(c&~(WAIT_STATES_MASK)));
|
bus_w(SPEED_REG,(d<<WAIT_STATES_OFFSET)|(c&~(WAIT_STATES_MASK)));
|
||||||
system(cmd);
|
system(cmd);
|
||||||
}
|
}
|
||||||
return ((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET)+2;
|
return ((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET)+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t getWaitStates() {
|
u_int32_t getWaitStates() {
|
||||||
u_int32_t clk_div;
|
u_int32_t clk_div;
|
||||||
clk_div=((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET);
|
clk_div=((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET);
|
||||||
return clk_div+2;
|
return clk_div+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u_int32_t setTotClockDivider(int d) {
|
u_int32_t setTotClockDivider(int d) {
|
||||||
u_int32_t c;
|
u_int32_t c;
|
||||||
c=bus_r(SPEED_REG);
|
c=bus_r(SPEED_REG);
|
||||||
bus_w(SPEED_REG,(d<<TOTCLK_DIVIDER_OFFSET)|(c&~(TOTCLK_DIVIDER_MASK)));
|
bus_w(SPEED_REG,(d<<TOTCLK_DIVIDER_OFFSET)|(c&~(TOTCLK_DIVIDER_MASK)));
|
||||||
return ((bus_r(SPEED_REG)& TOTCLK_DIVIDER_MASK)>>TOTCLK_DIVIDER_OFFSET);
|
return ((bus_r(SPEED_REG)& TOTCLK_DIVIDER_MASK)>>TOTCLK_DIVIDER_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t getTotClockDivider() {
|
u_int32_t getTotClockDivider() {
|
||||||
u_int32_t clk_div;
|
u_int32_t clk_div;
|
||||||
clk_div=((bus_r(SPEED_REG)&TOTCLK_DIVIDER_MASK)>>TOTCLK_DIVIDER_OFFSET);
|
clk_div=((bus_r(SPEED_REG)&TOTCLK_DIVIDER_MASK)>>TOTCLK_DIVIDER_OFFSET);
|
||||||
return clk_div;
|
return clk_div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u_int32_t setTotDutyCycle(int d) {
|
u_int32_t setTotDutyCycle(int d) {
|
||||||
u_int32_t c;
|
u_int32_t c;
|
||||||
c=bus_r(SPEED_REG);
|
c=bus_r(SPEED_REG);
|
||||||
bus_w(SPEED_REG,(d<<TOTCLK_DUTYCYCLE_OFFSET)|(c&~(TOTCLK_DUTYCYCLE_MASK)));
|
bus_w(SPEED_REG,(d<<TOTCLK_DUTYCYCLE_OFFSET)|(c&~(TOTCLK_DUTYCYCLE_MASK)));
|
||||||
return ((bus_r(SPEED_REG)& TOTCLK_DUTYCYCLE_MASK)>>TOTCLK_DUTYCYCLE_OFFSET);
|
return ((bus_r(SPEED_REG)& TOTCLK_DUTYCYCLE_MASK)>>TOTCLK_DUTYCYCLE_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int32_t getTotDutyCycle() {
|
u_int32_t getTotDutyCycle() {
|
||||||
u_int32_t clk_div;
|
u_int32_t clk_div;
|
||||||
clk_div=((bus_r(SPEED_REG)&TOTCLK_DUTYCYCLE_MASK)>>TOTCLK_DUTYCYCLE_OFFSET);
|
clk_div=((bus_r(SPEED_REG)&TOTCLK_DUTYCYCLE_MASK)>>TOTCLK_DUTYCYCLE_OFFSET);
|
||||||
return clk_div;
|
return clk_div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u_int32_t setExtSignal(int d, enum externalSignalFlag mode) {
|
u_int32_t setExtSignal(int d, enum externalSignalFlag mode) {
|
||||||
|
|
||||||
//int modes[]={EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING};
|
//int modes[]={EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING};
|
||||||
// int off=d*SIGNAL_OFFSET;
|
// int off=d*SIGNAL_OFFSET;
|
||||||
|
|
||||||
@ -470,7 +470,7 @@ u_int32_t setFPGASignal(int d, enum externalSignalFlag mode) {
|
|||||||
int getExtSignal(int d) {
|
int getExtSignal(int d) {
|
||||||
|
|
||||||
/* int modes[]={SIGNAL_OFF, GATE_IN_ACTIVE_HIGH, GATE_IN_ACTIVE_LOW,TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE,RO_TRIGGER_IN_RISING_EDGE, RO_TRIGGER_IN_FALLING_EDGE, GATE_OUT_ACTIVE_HIGH, GATE_OUT_ACTIVE_LOW, TRIGGER_OUT_RISING_EDGE, TRIGGER_OUT_FALLING_EDGE, RO_TRIGGER_OUT_RISING_EDGE,RO_TRIGGER_OUT_FALLING_EDGE};
|
/* int modes[]={SIGNAL_OFF, GATE_IN_ACTIVE_HIGH, GATE_IN_ACTIVE_LOW,TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE,RO_TRIGGER_IN_RISING_EDGE, RO_TRIGGER_IN_FALLING_EDGE, GATE_OUT_ACTIVE_HIGH, GATE_OUT_ACTIVE_LOW, TRIGGER_OUT_RISING_EDGE, TRIGGER_OUT_FALLING_EDGE, RO_TRIGGER_OUT_RISING_EDGE,RO_TRIGGER_OUT_FALLING_EDGE};
|
||||||
|
|
||||||
int off=d*SIGNAL_OFFSET;
|
int off=d*SIGNAL_OFFSET;
|
||||||
int mode=((bus_r(EXT_SIGNAL_REG)&(SIGNAL_MASK<<off))>>off);
|
int mode=((bus_r(EXT_SIGNAL_REG)&(SIGNAL_MASK<<off))>>off);
|
||||||
|
|
||||||
@ -671,7 +671,7 @@ int setToT(int d) {
|
|||||||
bus_w(CONFIG_REG,reg|TOT_ENABLE_BIT);
|
bus_w(CONFIG_REG,reg|TOT_ENABLE_BIT);
|
||||||
} else if (d==0) {
|
} else if (d==0) {
|
||||||
bus_w(CONFIG_REG,reg&(~TOT_ENABLE_BIT));
|
bus_w(CONFIG_REG,reg&(~TOT_ENABLE_BIT));
|
||||||
}
|
}
|
||||||
reg=bus_r(CONFIG_REG);
|
reg=bus_r(CONFIG_REG);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("ToT is %x\n", reg);
|
printf("ToT is %x\n", reg);
|
||||||
@ -696,7 +696,7 @@ int setContinousReadOut(int d) {
|
|||||||
bus_w(CONFIG_REG,reg|CONT_RO_ENABLE_BIT);
|
bus_w(CONFIG_REG,reg|CONT_RO_ENABLE_BIT);
|
||||||
} else if (d==0) {
|
} else if (d==0) {
|
||||||
bus_w(CONFIG_REG,reg&(~CONT_RO_ENABLE_BIT));
|
bus_w(CONFIG_REG,reg&(~CONT_RO_ENABLE_BIT));
|
||||||
}
|
}
|
||||||
reg=bus_r(CONFIG_REG);
|
reg=bus_r(CONFIG_REG);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Continous readout is %x\n", reg);
|
printf("Continous readout is %x\n", reg);
|
||||||
@ -874,7 +874,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
|
|||||||
v64=(v64<<32) | vLSB;
|
v64=(v64<<32) | vLSB;
|
||||||
return v64;
|
return v64;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t setFrames(int64_t value){
|
int64_t setFrames(int64_t value){
|
||||||
return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
|
return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
|
||||||
}
|
}
|
||||||
@ -885,13 +885,13 @@ int64_t getFrames(){
|
|||||||
|
|
||||||
int64_t setExposureTime(int64_t value){
|
int64_t setExposureTime(int64_t value){
|
||||||
/* time is in ns */
|
/* time is in ns */
|
||||||
if (value!=-1)
|
if (value!=-1)
|
||||||
value*=(1E-9*CLK_FREQ);
|
value*=(1E-9*CLK_FREQ);
|
||||||
return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
|
return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t getExposureTime(){
|
int64_t getExposureTime(){
|
||||||
return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
|
return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t setGates(int64_t value){
|
int64_t setGates(int64_t value){
|
||||||
@ -914,7 +914,7 @@ int64_t setPeriod(int64_t value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int64_t getPeriod(){
|
int64_t getPeriod(){
|
||||||
return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ);
|
return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t setDelay(int64_t value){
|
int64_t setDelay(int64_t value){
|
||||||
@ -926,7 +926,7 @@ int64_t setDelay(int64_t value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int64_t getDelay(){
|
int64_t getDelay(){
|
||||||
return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ);
|
return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t setTrains(int64_t value){
|
int64_t setTrains(int64_t value){
|
||||||
@ -966,7 +966,7 @@ int64_t setProbes(int64_t value){
|
|||||||
initChipWithProbes(0, ow,value, ALLMOD);
|
initChipWithProbes(0, ow,value, ALLMOD);
|
||||||
putout("0000000000000000",ALLMOD);
|
putout("0000000000000000",ALLMOD);
|
||||||
setNMod(nm);
|
setNMod(nm);
|
||||||
getDynamicRange(); // needed to change dataBytes
|
getDynamicRange(); // needed to change dataBytes
|
||||||
}
|
}
|
||||||
return getProbes();
|
return getProbes();
|
||||||
}
|
}
|
||||||
@ -985,13 +985,13 @@ int64_t getProgress() {
|
|||||||
|
|
||||||
|
|
||||||
//should be done in firmware!!!!
|
//should be done in firmware!!!!
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t getActualTime(){
|
int64_t getActualTime(){
|
||||||
return get64BitReg(GET_ACTUAL_TIME_LSB_REG, GET_ACTUAL_TIME_MSB_REG)/(1E-9*CLK_FREQ);
|
return get64BitReg(GET_ACTUAL_TIME_LSB_REG, GET_ACTUAL_TIME_MSB_REG)/(1E-9*CLK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t getMeasurementTime(){
|
int64_t getMeasurementTime(){
|
||||||
@ -1042,9 +1042,9 @@ int64_t getProbes(){
|
|||||||
printf("%08x ",shiftin);
|
printf("%08x ",shiftin);
|
||||||
printf("probes==%01x\n",np);
|
printf("probes==%01x\n",np);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return np;
|
return np;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1053,7 +1053,7 @@ int setDACRegister(int idac, int val, int imod) {
|
|||||||
int off;
|
int off;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
if(val==-1)
|
if(val==-1)
|
||||||
printf("Getting dac register%d module %d\n",idac,imod);
|
printf("Getting dac register%d module %d\n",idac,imod);
|
||||||
else
|
else
|
||||||
printf("Setting dac register %d module %d to %d\n",idac,imod,val);
|
printf("Setting dac register %d module %d to %d\n",idac,imod,val);
|
||||||
#endif
|
#endif
|
||||||
@ -1071,7 +1071,7 @@ int setDACRegister(int idac, int val, int imod) {
|
|||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
case 7:
|
case 7:
|
||||||
addr=MOD_DACS3_REG;
|
addr=MOD_DACS3_REG;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("weird idac value %d\n",idac);
|
printf("weird idac value %d\n",idac);
|
||||||
@ -1095,7 +1095,7 @@ int setDACRegister(int idac, int val, int imod) {
|
|||||||
val=val<<2;
|
val=val<<2;
|
||||||
|
|
||||||
//val=(bus_r(addr)>>off)&0x3ff;
|
//val=(bus_r(addr)>>off)&0x3ff;
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Dac %d module %d register is %d\n\n",idac,imod,val);
|
printf("Dac %d module %d register is %d\n\n",idac,imod,val);
|
||||||
@ -1106,7 +1106,7 @@ int setDACRegister(int idac, int val, int imod) {
|
|||||||
|
|
||||||
int getTemperature(int tempSensor, int imod){
|
int getTemperature(int tempSensor, int imod){
|
||||||
int val;
|
int val;
|
||||||
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
|
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
|
||||||
imod=0;//ignoring more than 1 mod for now
|
imod=0;//ignoring more than 1 mod for now
|
||||||
int i,j,repeats=6;
|
int i,j,repeats=6;
|
||||||
u_int32_t tempVal=0;
|
u_int32_t tempVal=0;
|
||||||
@ -1151,12 +1151,12 @@ int initHighVoltage(int val, int imod){
|
|||||||
switch(val){
|
switch(val){
|
||||||
case -1: break;
|
case -1: break;
|
||||||
case 0: writeVal=0x0; writeVal2=0x0; break;
|
case 0: writeVal=0x0; writeVal2=0x0; break;
|
||||||
case 90: writeVal=0x0; writeVal2=0x1; break;
|
case 90: writeVal=0x0; writeVal2=0x1; break;
|
||||||
case 110:writeVal=0x2; writeVal2=0x3; break;
|
case 110:writeVal=0x2; writeVal2=0x3; break;
|
||||||
case 120:writeVal=0x4; writeVal2=0x5; break;
|
case 120:writeVal=0x4; writeVal2=0x5; break;
|
||||||
case 150:writeVal=0x6; writeVal2=0x7; break;
|
case 150:writeVal=0x6; writeVal2=0x7; break;
|
||||||
case 180:writeVal=0x8; writeVal2=0x9; break;
|
case 180:writeVal=0x8; writeVal2=0x9; break;
|
||||||
case 200:writeVal=0xA; writeVal2=0xB; break;
|
case 200:writeVal=0xA; writeVal2=0xB; break;
|
||||||
default :printf("Invalid voltage\n");return -2;break;
|
default :printf("Invalid voltage\n");return -2;break;
|
||||||
}
|
}
|
||||||
//to set value
|
//to set value
|
||||||
@ -1281,9 +1281,9 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(ival)
|
if(ival)
|
||||||
bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset)
|
bus_w(addrr,(RESET_BIT|DIGITAL_TEST_BIT)); //0x080,reset mac (reset)
|
||||||
else
|
else
|
||||||
bus_w(addrr,RESET_BIT); //0x080,reset mac (reset)
|
bus_w(addrr,RESET_BIT); //0x080,reset mac (reset)
|
||||||
val=bus_r(addrr);
|
val=bus_r(addrr);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Value read from Multi-purpose Reg:%x\n",val);
|
printf("Value read from Multi-purpose Reg:%x\n",val);
|
||||||
@ -1291,7 +1291,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
// if(val!=0x080) return -1;
|
// if(val!=0x080) return -1;
|
||||||
|
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
|
|
||||||
if(ival)
|
if(ival)
|
||||||
bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak)
|
bus_w(addrr,(ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x840,write shadow regs(enet reset,write bak)
|
||||||
else
|
else
|
||||||
@ -1313,12 +1313,12 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
// if(val!=0x800) return -1;
|
// if(val!=0x800) return -1;
|
||||||
|
|
||||||
|
|
||||||
mac_conf_regs->mac.mac_dest_mac1 =((macad>>(8*5))&0xFF);// 0x00; //pc7060
|
mac_conf_regs->mac.mac_dest_mac1 =((macad>>(8*5))&0xFF);// 0x00; //pc7060
|
||||||
mac_conf_regs->mac.mac_dest_mac2 =((macad>>(8*4))&0xFF);// 0x19; //pc7060
|
mac_conf_regs->mac.mac_dest_mac2 =((macad>>(8*4))&0xFF);// 0x19; //pc7060
|
||||||
mac_conf_regs->mac.mac_dest_mac3 =((macad>>(8*3))&0xFF);// 0x99; //pc7060
|
mac_conf_regs->mac.mac_dest_mac3 =((macad>>(8*3))&0xFF);// 0x99; //pc7060
|
||||||
mac_conf_regs->mac.mac_dest_mac4 =((macad>>(8*2))&0xFF);// 0x24; //pc7060
|
mac_conf_regs->mac.mac_dest_mac4 =((macad>>(8*2))&0xFF);// 0x24; //pc7060
|
||||||
mac_conf_regs->mac.mac_dest_mac5 =((macad>>(8*1))&0xFF);// 0xEB; //pc7060
|
mac_conf_regs->mac.mac_dest_mac5 =((macad>>(8*1))&0xFF);// 0xEB; //pc7060
|
||||||
mac_conf_regs->mac.mac_dest_mac6 =((macad>>(8*0))&0xFF);// 0xEE; //pc7060
|
mac_conf_regs->mac.mac_dest_mac6 =((macad>>(8*0))&0xFF);// 0xEE; //pc7060
|
||||||
/*
|
/*
|
||||||
mac_conf_regs->mac.mac_src_mac1 = 0x00;
|
mac_conf_regs->mac.mac_src_mac1 = 0x00;
|
||||||
mac_conf_regs->mac.mac_src_mac2 = 0xAA;
|
mac_conf_regs->mac.mac_src_mac2 = 0xAA;
|
||||||
@ -1334,7 +1334,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
mac_conf_regs->mac.mac_src_mac5 =((servermacad>>(8*1))&0xFF);
|
mac_conf_regs->mac.mac_src_mac5 =((servermacad>>(8*1))&0xFF);
|
||||||
mac_conf_regs->mac.mac_src_mac6 =((servermacad>>(8*0))&0xFF);
|
mac_conf_regs->mac.mac_src_mac6 =((servermacad>>(8*0))&0xFF);
|
||||||
mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4
|
mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4
|
||||||
|
|
||||||
|
|
||||||
mac_conf_regs->ip.ip_ver = 0x4;
|
mac_conf_regs->ip.ip_ver = 0x4;
|
||||||
mac_conf_regs->ip.ip_ihl = 0x5;
|
mac_conf_regs->ip.ip_ihl = 0x5;
|
||||||
@ -1345,7 +1345,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
mac_conf_regs->ip.ip_offset = 0x00;
|
mac_conf_regs->ip.ip_offset = 0x00;
|
||||||
mac_conf_regs->ip.ip_ttl = 0x70;
|
mac_conf_regs->ip.ip_ttl = 0x70;
|
||||||
mac_conf_regs->ip.ip_protocol = 0x11;
|
mac_conf_regs->ip.ip_protocol = 0x11;
|
||||||
mac_conf_regs->ip.ip_chksum = 0x0000 ; //6E42 now is automatically computed
|
mac_conf_regs->ip.ip_chksum = 0x0000 ; //6E42 now is automatically computed
|
||||||
mac_conf_regs->ip.ip_sourceip = 0x8181CA2E;
|
mac_conf_regs->ip.ip_sourceip = 0x8181CA2E;
|
||||||
mac_conf_regs->ip.ip_destip = ipad; //CA57
|
mac_conf_regs->ip.ip_destip = ipad; //CA57
|
||||||
|
|
||||||
@ -1376,8 +1376,8 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
sum += *addr++;
|
sum += *addr++;
|
||||||
count -= 2;
|
count -= 2;
|
||||||
}
|
}
|
||||||
if( count > 0 ) sum += *addr; // Add left-over byte, if any
|
if( count > 0 ) sum += *addr; // Add left-over byte, if any
|
||||||
while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits
|
while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits
|
||||||
checksum = (~sum)&0xffff;
|
checksum = (~sum)&0xffff;
|
||||||
mac_conf_regs->ip.ip_chksum = checksum;
|
mac_conf_regs->ip.ip_chksum = checksum;
|
||||||
//#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
@ -1394,7 +1394,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
#endif
|
#endif
|
||||||
tse_conf_regs->rev = 0xA00;
|
tse_conf_regs->rev = 0xA00;
|
||||||
tse_conf_regs->scratch = 0xCCCCCCCC;
|
tse_conf_regs->scratch = 0xCCCCCCCC;
|
||||||
tse_conf_regs->command_config = 0xB;
|
tse_conf_regs->command_config = 0xB;
|
||||||
tse_conf_regs->mac_0 = 0x17231C00;
|
tse_conf_regs->mac_0 = 0x17231C00;
|
||||||
tse_conf_regs->mac_1 = 0xCB4A;
|
tse_conf_regs->mac_1 = 0xCB4A;
|
||||||
tse_conf_regs->frm_length = 0x5DC; //max frame length (1500 bytes) (was 0x41C)
|
tse_conf_regs->frm_length = 0x5DC; //max frame length (1500 bytes) (was 0x41C)
|
||||||
@ -1413,10 +1413,10 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
|
|
||||||
|
|
||||||
if(ival)
|
if(ival)
|
||||||
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs..
|
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT|DIGITAL_TEST_BIT)); //0x2840,write shadow regs..
|
||||||
else
|
else
|
||||||
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs..
|
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|WRITE_BACK_BIT)); //0x2840,write shadow regs..
|
||||||
|
|
||||||
val=bus_r(addrr);
|
val=bus_r(addrr);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Value read from Multi-purpose Reg:%x\n",val);
|
printf("Value read from Multi-purpose Reg:%x\n",val);
|
||||||
@ -1426,9 +1426,9 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
usleep(100000);
|
usleep(100000);
|
||||||
|
|
||||||
if(ival)
|
if(ival)
|
||||||
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs..
|
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT|DIGITAL_TEST_BIT)); //0x2820,write shadow regs..
|
||||||
else
|
else
|
||||||
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs..
|
bus_w(addrr,(INT_RSTN_BIT|ENET_RESETN_BIT|SW1_BIT)); //0x2820,write shadow regs..
|
||||||
|
|
||||||
val=bus_r(addrr);
|
val=bus_r(addrr);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -1446,10 +1446,6 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
|
|||||||
|
|
||||||
u_int32_t runBusy(void) {
|
u_int32_t runBusy(void) {
|
||||||
u_int32_t s = bus_r(STATUS_REG);
|
u_int32_t s = bus_r(STATUS_REG);
|
||||||
//s=((s & RUN_BUSY_BIT) | (s & READMACHINE_BUSY_BIT));
|
|
||||||
//s=(s & RUN_BUSY_BIT);
|
|
||||||
//if(s!=0x62721)
|
|
||||||
// printf("status=%x\n",s);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1463,7 +1459,7 @@ u_int32_t runState(void) {
|
|||||||
if (s&RUN_BUSY_BIT)
|
if (s&RUN_BUSY_BIT)
|
||||||
write_status_sm("Running");
|
write_status_sm("Running");
|
||||||
else
|
else
|
||||||
write_status_sm("Stopped");
|
write_status_sm("Stopped");
|
||||||
#endif
|
#endif
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("status %04x\n",s);
|
printf("status %04x\n",s);
|
||||||
@ -1518,8 +1514,8 @@ int stopStateMachine(){
|
|||||||
// if (!runBusy())
|
// if (!runBusy())
|
||||||
if(!(bus_r(STATUS_REG)&RUNMACHINE_BUSY_BIT))
|
if(!(bus_r(STATUS_REG)&RUNMACHINE_BUSY_BIT))
|
||||||
return OK;
|
return OK;
|
||||||
else
|
else
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1544,7 +1540,7 @@ u_int32_t fifoReset(void) {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("resetting fifo\n");
|
printf("resetting fifo\n");
|
||||||
#endif
|
#endif
|
||||||
bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<<SHIFTMOD), FIFO_RESET_BIT);
|
bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<<SHIFTMOD), FIFO_RESET_BIT);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1563,7 +1559,7 @@ u_int32_t getNBits()
|
|||||||
|
|
||||||
u_int32_t fifoReadCounter(int fifonum)
|
u_int32_t fifoReadCounter(int fifonum)
|
||||||
{
|
{
|
||||||
int rval=0;
|
int rval=0;
|
||||||
int shiftfifo;
|
int shiftfifo;
|
||||||
switch (dynamicRange) {
|
switch (dynamicRange) {
|
||||||
case 16:
|
case 16:
|
||||||
@ -1593,7 +1589,7 @@ u_int32_t fifoReadCounter(int fifonum)
|
|||||||
u_int32_t fifoReadStatus()
|
u_int32_t fifoReadStatus()
|
||||||
{
|
{
|
||||||
// reads from the global status register
|
// reads from the global status register
|
||||||
|
|
||||||
return bus_r(STATUS_REG)&(SOME_FIFO_FULL_BIT | ALL_FIFO_EMPTY_BIT);
|
return bus_r(STATUS_REG)&(SOME_FIFO_FULL_BIT | ALL_FIFO_EMPTY_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1619,11 +1615,10 @@ u_int32_t* fifo_read_event()
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("lookatmereg=x%x\n",t);
|
printf("lookatmereg=x%x\n",t);
|
||||||
#endif
|
#endif
|
||||||
while ((t&0x1)==0)
|
while ((t&0x1)==0)
|
||||||
{
|
{
|
||||||
t = bus_r(LOOK_AT_ME_REG);
|
t = bus_r(LOOK_AT_ME_REG);
|
||||||
if (!runBusy()){
|
if (!runBusy()){
|
||||||
printf("\n\ngonna return null STATUS=%08x\n",runState());
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1670,7 +1665,7 @@ u_int32_t* fifo_read_event()
|
|||||||
#endif
|
#endif
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes);
|
printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes);
|
||||||
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (storeInRAM>0) {
|
if (storeInRAM>0) {
|
||||||
@ -1731,12 +1726,12 @@ u_int32_t* decode_data(int *datain)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (ichan=0; ichan<nChans*nChips*nModX; ichan++)
|
for (ichan=0; ichan<nChans*nChips*nModX; ichan++)
|
||||||
dataout[ichan]=datain[ichan]&0xffffff;
|
dataout[ichan]=datain[ichan]&0xffffff;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("decoded %d channels\n",ichan);
|
printf("decoded %d channels\n",ichan);
|
||||||
#endif
|
#endif
|
||||||
@ -1797,7 +1792,7 @@ int getDynamicRange() {
|
|||||||
printf("%08x ",shiftin);
|
printf("%08x ",shiftin);
|
||||||
printf("outmux=%02x probes=%d\n",outmux,probes);
|
printf("outmux=%02x probes=%d\n",outmux,probes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (outmux) {
|
switch (outmux) {
|
||||||
case 2:
|
case 2:
|
||||||
dr=16;
|
dr=16;
|
||||||
@ -1888,7 +1883,7 @@ int allocateRAM() {
|
|||||||
size=dataBytes*nf*nt;
|
size=dataBytes*nf*nt;
|
||||||
if (size<dataBytes)
|
if (size<dataBytes)
|
||||||
size=dataBytes;
|
size=dataBytes;
|
||||||
} else
|
} else
|
||||||
size=dataBytes;
|
size=dataBytes;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -1896,14 +1891,14 @@ int allocateRAM() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (size==ram_size) {
|
if (size==ram_size) {
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("RAM of size %d already allocated: nothing to be done\n",(int) size);
|
printf("RAM of size %d already allocated: nothing to be done\n",(int) size);
|
||||||
#endif
|
#endif
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("reallocating ram %x\n",(unsigned int)ram_values);
|
printf("reallocating ram %x\n",(unsigned int)ram_values);
|
||||||
@ -1943,7 +1938,7 @@ int allocateRAM() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -508,10 +508,7 @@ double slsDetectorUtils::getCurrentProgress() {
|
|||||||
|
|
||||||
void slsDetectorUtils::incrementProgress(int i) {
|
void slsDetectorUtils::incrementProgress(int i) {
|
||||||
pthread_mutex_lock(&mp);
|
pthread_mutex_lock(&mp);
|
||||||
if(i==-1)
|
progressIndex+=i;
|
||||||
progressIndex++;
|
|
||||||
else
|
|
||||||
progressIndex+=i;
|
|
||||||
cout << fixed << setprecision(2) << setw (6) << 100.*((double)progressIndex)/((double)totalProgress) << " \%";
|
cout << fixed << setprecision(2) << setw (6) << 100.*((double)progressIndex)/((double)totalProgress) << " \%";
|
||||||
pthread_mutex_unlock(&mp);
|
pthread_mutex_unlock(&mp);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
51
slsDetectorSoftware/slsReceiver/.cproject
Normal file
51
slsDetectorSoftware/slsReceiver/.cproject
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?fileVersion 4.0.0?>
|
||||||
|
|
||||||
|
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||||
|
<cconfiguration id="0.1592123610">
|
||||||
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1592123610" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||||
|
<externalSettings/>
|
||||||
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
</extensions>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<configuration buildProperties="" description="" id="0.1592123610" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
|
||||||
|
<folderInfo id="0.1592123610." name="/" resourcePath="">
|
||||||
|
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.2043853512" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
|
||||||
|
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.2043853512.1428560959" name=""/>
|
||||||
|
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1228246701" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
|
||||||
|
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.891716849" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
||||||
|
<tool id="org.eclipse.cdt.build.core.settings.holder.1775606856" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.98773194" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="org.eclipse.cdt.build.core.settings.holder.41809089" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.817253715" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="org.eclipse.cdt.build.core.settings.holder.1467561536" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.210475521" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
|
</tool>
|
||||||
|
</toolChain>
|
||||||
|
</folderInfo>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
|
</cconfiguration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<project id="slsReceiver.null.670781774" name="slsReceiver"/>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="scannerConfiguration">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
<scannerConfigBuildInfo instanceId="0.1592123610">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</scannerConfigBuildInfo>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
|
</cproject>
|
28
slsDetectorSoftware/slsReceiver/.project
Normal file
28
slsDetectorSoftware/slsReceiver/.project
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Receiver</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
<project>newMythenSoftware</project>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||||
|
<triggers>clean,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||||
|
<triggers>full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
32
slsDetectorSoftware/slsReceiver/Makefile
Normal file
32
slsDetectorSoftware/slsReceiver/Makefile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
CFLAGS+= -Wall -DC_ONLY -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DVERBOSE
|
||||||
|
LDLIBS+= -lm -lstdc++ -lpthread
|
||||||
|
PROGS= slsReceiver
|
||||||
|
INSTDIR= bin
|
||||||
|
INSTMODE= 0777
|
||||||
|
|
||||||
|
SRC_CLNT = slsReceiver.c communication_funcs.c slsReceiverFunctionList.c slsReceiver_funcs.c
|
||||||
|
OBJS = $(SRC_CLNT:.c=.o)
|
||||||
|
|
||||||
|
|
||||||
|
all: clean $(PROGS)
|
||||||
|
|
||||||
|
boot: $(OBJS)
|
||||||
|
|
||||||
|
#doc: $(SRC_CLNT)
|
||||||
|
# doxygen doxy.config
|
||||||
|
|
||||||
|
|
||||||
|
$(PROGS): $(OBJS)
|
||||||
|
echo $(OBJS)
|
||||||
|
mkdir -p $(INSTDIR)
|
||||||
|
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) -o $@
|
||||||
|
mv $(PROGS) $(INSTDIR)
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROGS) *.o $(INSTDIR)/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
slsDetectorSoftware/slsReceiver/communication_funcs.c
Symbolic link
1
slsDetectorSoftware/slsReceiver/communication_funcs.c
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../commonFiles/communication_funcs.c
|
1
slsDetectorSoftware/slsReceiver/communication_funcs.h
Symbolic link
1
slsDetectorSoftware/slsReceiver/communication_funcs.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../commonFiles/communication_funcs.h
|
337
slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.c
Normal file
337
slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.c
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
#include "slsReceiverFunctionList.h"
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>/* exit() */
|
||||||
|
#include <string.h> /* memset(), memcpy() */
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h> /* fork(), write(), close() */
|
||||||
|
#include <asm/page.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/socket.h>/* socket(), bind(), listen(), accept() */
|
||||||
|
#include <signal.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/utsname.h> /* uname() */
|
||||||
|
|
||||||
|
#include <pthread.h> /* thread */
|
||||||
|
|
||||||
|
//constants
|
||||||
|
#define MAX_BUFLEN 1048576
|
||||||
|
#define TCP_PORT_NUMBER 2233
|
||||||
|
|
||||||
|
#define SRVNAME "localhost"
|
||||||
|
#define SERVER_PORT 50001
|
||||||
|
#define BUFFER_LENGTH 1286
|
||||||
|
#define FALSE 0
|
||||||
|
|
||||||
|
int gui_acquisition_thread_running = 0;
|
||||||
|
int err = 0;
|
||||||
|
pthread_t gui_acquisition_thread;
|
||||||
|
|
||||||
|
|
||||||
|
char buffer[BUFFER_LENGTH];
|
||||||
|
int sd = -1;
|
||||||
|
int sockfd, sfilefd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char filePath[MAX_STR_LENGTH]="";
|
||||||
|
char fileName[MAX_STR_LENGTH]="run";
|
||||||
|
int fileIndex=0;
|
||||||
|
int frameIndex=0;
|
||||||
|
int startFrameIndex=-1;
|
||||||
|
int framesInFile=0;
|
||||||
|
int framesCaught=0;
|
||||||
|
|
||||||
|
enum runStatus status = IDLE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void closeFile(){
|
||||||
|
if(gui_acquisition_thread_running){
|
||||||
|
printf("Closing file\n");
|
||||||
|
fclose(sfilefd);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum runStatus getReceiverStatus(){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Status:%d\n",status);
|
||||||
|
#endif
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* getFileName(){
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* setFileName(char fName[]){
|
||||||
|
if(strlen(fName)){
|
||||||
|
strcpy(fileName,fName);
|
||||||
|
}
|
||||||
|
return getFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* getFilePath(){
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* setFilePath(char fPath[]){
|
||||||
|
if(strlen(fPath)){
|
||||||
|
/*check if filepath exists and chop off last '/'*/
|
||||||
|
struct stat st;
|
||||||
|
if(stat(fPath,&st) == 0)
|
||||||
|
strcpy(filePath,fPath);
|
||||||
|
}
|
||||||
|
return getFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int getFileIndex(){
|
||||||
|
return fileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
int setFileIndex(int index){
|
||||||
|
if(index>=0){
|
||||||
|
fileIndex=index;
|
||||||
|
}
|
||||||
|
return getFileIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int getFramesCaught(){
|
||||||
|
return framesCaught;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getFrameIndex(){
|
||||||
|
if(startFrameIndex==-1)
|
||||||
|
frameIndex=0;
|
||||||
|
else
|
||||||
|
frameIndex=((int)(*((int*)buffer)) - startFrameIndex)/2;
|
||||||
|
return frameIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void* startListening(void *arg){
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
printf("In startListening()\n");
|
||||||
|
#endif
|
||||||
|
/***********************************************************************/
|
||||||
|
/* Variable and structure definitions. */
|
||||||
|
/***********************************************************************/
|
||||||
|
sd = -1;
|
||||||
|
int rc1, rc2, rc;
|
||||||
|
int currframenum, prevframenum;
|
||||||
|
char buffer2[BUFFER_LENGTH];
|
||||||
|
char savefilename[128];
|
||||||
|
struct sockaddr_in serveraddr;
|
||||||
|
struct sockaddr_in clientaddr;
|
||||||
|
|
||||||
|
int clientaddrlen = sizeof(clientaddr);
|
||||||
|
framesInFile=0;
|
||||||
|
framesCaught=0;
|
||||||
|
frameIndex = 0;
|
||||||
|
startFrameIndex=-1;
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* Catch signal SIGINT to close files properly */
|
||||||
|
/***********************************************************************/
|
||||||
|
signal(SIGINT, closeFile);
|
||||||
|
|
||||||
|
|
||||||
|
//create file name
|
||||||
|
sprintf(savefilename, "%s/%s_f%09d_%d.dat", filePath,fileName,frameIndex,fileIndex);
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* A do/while(FALSE) loop is used to make error cleanup easier. The */
|
||||||
|
/* close() of each of the socket descriptors is only done once at the */
|
||||||
|
/* very end of the program. */
|
||||||
|
/***********************************************************************/
|
||||||
|
do {
|
||||||
|
/********************************************************************/
|
||||||
|
/* The socket() function returns a socket descriptor, which represents */
|
||||||
|
/* an endpoint. The statement also identifies that the INET */
|
||||||
|
/* (Internet Protocol) address family with the UDP transport */
|
||||||
|
/* (SOCK_DGRAM) will be used for this socket. */
|
||||||
|
/********************************************************************/
|
||||||
|
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (sd < 0) {
|
||||||
|
perror("socket() failed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************/
|
||||||
|
/* After the socket descriptor is created, a bind() function gets a */
|
||||||
|
/* unique name for the socket. In this example, the user sets the */
|
||||||
|
/* s_addr to zero, which means that the UDP port of 3555 will be */
|
||||||
|
/* bound to all IP addresses on the system. */
|
||||||
|
/********************************************************************/
|
||||||
|
memset(&serveraddr, 0, sizeof(serveraddr));
|
||||||
|
serveraddr.sin_family = AF_INET;
|
||||||
|
serveraddr.sin_port = htons(SERVER_PORT);
|
||||||
|
//serveraddr.sin_addr.s_addr = inet_addr(server_ip);
|
||||||
|
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
|
rc = bind(sd, (struct sockaddr *) &serveraddr, sizeof(serveraddr));
|
||||||
|
if (rc < 0) {
|
||||||
|
perror("bind() failed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sfilefd = fopen((const char *) (savefilename), "w");
|
||||||
|
printf("Saving to ... %s. Ready! \n", savefilename);
|
||||||
|
|
||||||
|
while (gui_acquisition_thread_running) {
|
||||||
|
/********************************************************************/
|
||||||
|
/* The server uses the recvfrom() function to receive that data. */
|
||||||
|
/* The recvfrom() function waits indefinitely for data to arrive. */
|
||||||
|
/********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
if (framesInFile == 20000) {
|
||||||
|
fclose(sfilefd);
|
||||||
|
|
||||||
|
currframenum=(int)(*((int*)buffer));
|
||||||
|
getFrameIndex();
|
||||||
|
sprintf(savefilename, "%s/%s_f%09d_%d.dat", filePath,fileName,frameIndex,fileIndex);
|
||||||
|
|
||||||
|
printf("saving to %s\t\tpacket loss %f \%\t\tframenum %d\n", savefilename,((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000,currframenum);
|
||||||
|
sfilefd = fopen((const char *) (savefilename), "w");
|
||||||
|
prevframenum=currframenum;
|
||||||
|
framesInFile = 0;
|
||||||
|
}
|
||||||
|
status = RUNNING;
|
||||||
|
|
||||||
|
rc1 = recvfrom(sd, buffer, sizeof(buffer), 0,
|
||||||
|
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||||
|
//printf("rc1 done\n");
|
||||||
|
rc2 = recvfrom(sd, buffer2, sizeof(buffer2), 0,
|
||||||
|
(struct sockaddr *) &clientaddr, &clientaddrlen);
|
||||||
|
|
||||||
|
if(startFrameIndex==-1){
|
||||||
|
startFrameIndex=(int)(*((int*)buffer))-2;
|
||||||
|
prevframenum=startFrameIndex;
|
||||||
|
}
|
||||||
|
//printf("rc2 done\n");
|
||||||
|
if ((rc1 < 0) || (rc2 < 0)) {
|
||||||
|
perror("recvfrom() failed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//so that it doesnt write the last frame twice
|
||||||
|
if(gui_acquisition_thread_running){
|
||||||
|
fwrite(buffer, 1, rc1, sfilefd);
|
||||||
|
fwrite(buffer2, 1, rc2, sfilefd);
|
||||||
|
framesInFile++;
|
||||||
|
framesCaught++;
|
||||||
|
//printf("saving\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (gui_acquisition_thread_running);
|
||||||
|
gui_acquisition_thread_running=0;
|
||||||
|
status = IDLE;
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* Close down any open socket descriptors */
|
||||||
|
/***********************************************************************/
|
||||||
|
if (sd != -1){
|
||||||
|
printf("Closing sd\n");fflush(stdout);
|
||||||
|
close(sd);
|
||||||
|
}
|
||||||
|
|
||||||
|
//close file
|
||||||
|
fclose(sfilefd);
|
||||||
|
printf("sfield:%d\n",sfilefd);
|
||||||
|
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int startReceiver(){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Starting Receiver\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(!gui_acquisition_thread_running){
|
||||||
|
printf("Starting new acquisition threadddd ....\n");
|
||||||
|
gui_acquisition_thread_running=1;
|
||||||
|
//status = RUNNING;
|
||||||
|
err = pthread_create(&gui_acquisition_thread, NULL,&startListening, NULL);
|
||||||
|
if(!err){
|
||||||
|
while(status!=RUNNING);
|
||||||
|
printf("\n Thread created successfully.\n");
|
||||||
|
}else{
|
||||||
|
gui_acquisition_thread_running=0;
|
||||||
|
status = IDLE;
|
||||||
|
printf("\n Cant create thread. Status:%d\n",status);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int stopReceiver(){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Stopping Receiver\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(gui_acquisition_thread_running){
|
||||||
|
printf("Stopping new acquisition threadddd ....\n");
|
||||||
|
//stop thread
|
||||||
|
gui_acquisition_thread_running=0;
|
||||||
|
if (sd != -1)
|
||||||
|
shutdown(sd, SHUT_RDWR);
|
||||||
|
pthread_join(gui_acquisition_thread,NULL);
|
||||||
|
status = IDLE;
|
||||||
|
}
|
||||||
|
printf("Status:%d\n",status);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
25
slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h
Normal file
25
slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
|
||||||
|
|
||||||
|
//int initializeReceiver();
|
||||||
|
|
||||||
|
void closeFile();
|
||||||
|
|
||||||
|
enum runStatus getReceiverStatus();
|
||||||
|
|
||||||
|
char* getFileName();
|
||||||
|
char* setFileName(char fName[]);
|
||||||
|
char* getFilePath();
|
||||||
|
char* setFilePath(char fName[]);
|
||||||
|
int getFileIndex();
|
||||||
|
int setFileIndex(int index);
|
||||||
|
int getFramesCaught();
|
||||||
|
int getFrameIndex();
|
||||||
|
|
||||||
|
void* startListening(void *arg);
|
||||||
|
|
||||||
|
int startReceiver();
|
||||||
|
int stopReceiver();
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
810
slsDetectorSoftware/slsReceiver/slsReceiver_funcs.c
Normal file
810
slsDetectorSoftware/slsReceiver/slsReceiver_funcs.c
Normal file
@ -0,0 +1,810 @@
|
|||||||
|
//#include "sls_detector_defs.h"
|
||||||
|
#include "slsReceiver_funcs.h"
|
||||||
|
#include "slsReceiverFunctionList.h"
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
#include "sls_detector_funcs.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// Global variables
|
||||||
|
|
||||||
|
int (*flist[256])(int);
|
||||||
|
|
||||||
|
|
||||||
|
//defined in the detector specific file
|
||||||
|
#ifdef MYTHEND
|
||||||
|
const enum detectorType myDetectorType=MYTHEN;
|
||||||
|
#elif GOTTHARDD
|
||||||
|
const enum detectorType myDetectorType=GOTTHARD;
|
||||||
|
#elif EIGERD
|
||||||
|
const enum detectorType myDetectorType=EIGER;
|
||||||
|
#elif PICASSOD
|
||||||
|
const enum detectorType myDetectorType=PICASSO;
|
||||||
|
#else
|
||||||
|
const enum detectorType myDetectorType=GENERIC;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//define in communication_funcs
|
||||||
|
extern int lockStatus;
|
||||||
|
extern char lastClientIP[INET_ADDRSTRLEN];
|
||||||
|
extern char thisClientIP[INET_ADDRSTRLEN];
|
||||||
|
extern int differentClients;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* global variables for optimized readout */
|
||||||
|
|
||||||
|
char *dataretval=NULL;
|
||||||
|
int dataret;
|
||||||
|
char mess[1000];
|
||||||
|
int dataBytes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
int init_receiver() {
|
||||||
|
|
||||||
|
|
||||||
|
initializeReceiver();
|
||||||
|
|
||||||
|
strcpy(mess,"dummy message");
|
||||||
|
strcpy(lastClientIP,"none");
|
||||||
|
strcpy(thisClientIP,"none1");
|
||||||
|
lockStatus=0;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int decode_function(int file_des) {
|
||||||
|
int fnum,n;
|
||||||
|
int retval=FAIL;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf( "receive data\n");
|
||||||
|
#endif
|
||||||
|
n = receiveDataOnly(file_des,&fnum,sizeof(fnum));
|
||||||
|
if (n <= 0) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des);
|
||||||
|
#endif
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else
|
||||||
|
printf("size of data received %d\n",n);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
|
||||||
|
#endif
|
||||||
|
if (fnum<0 || fnum>255)
|
||||||
|
fnum=255;
|
||||||
|
retval=(*flist[fnum])(file_des);
|
||||||
|
if (retval==FAIL)
|
||||||
|
printf( "Error executing the function = %d \n",fnum);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int function_table() {
|
||||||
|
int i;
|
||||||
|
for (i=0;i<256;i++){
|
||||||
|
flist[i]=&M_nofunc;
|
||||||
|
}
|
||||||
|
flist[F_EXIT_SERVER]=&exit_server; //not implemented in client
|
||||||
|
flist[F_EXEC_COMMAND]=&exec_command; //not implemented in client
|
||||||
|
|
||||||
|
|
||||||
|
flist[F_SET_FILE_NAME]=&set_file_name;
|
||||||
|
flist[F_SET_FILE_PATH]=&set_file_dir;
|
||||||
|
flist[F_SET_FILE_INDEX]=&set_file_index;
|
||||||
|
flist[F_START_RECEIVER]=&start_receiver;
|
||||||
|
flist[F_STOP_RECEIVER]=&stop_receiver;
|
||||||
|
flist[F_GET_RECEIVER_STATUS]=&get_receiver_status;
|
||||||
|
flist[F_GET_FRAMES_CAUGHT]=&get_frames_caught;
|
||||||
|
flist[F_GET_FRAME_INDEX]=&get_frame_index;
|
||||||
|
|
||||||
|
flist[F_LOCK_RECEIVER]=&lock_receiver;
|
||||||
|
flist[F_SET_PORT]=&set_port;
|
||||||
|
flist[F_GET_LAST_CLIENT_IP]=&get_last_client_ip;
|
||||||
|
flist[F_UPDATE_CLIENT]=&update_client;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
/* for (i=0;i<256;i++){
|
||||||
|
printf("function %d located at %x\n",i,flist[i]);
|
||||||
|
}*/
|
||||||
|
#endif
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int set_file_name(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
char fName[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||||
|
|
||||||
|
strcpy(mess,"Could not set file name");
|
||||||
|
|
||||||
|
|
||||||
|
/* receive arguments */
|
||||||
|
n = receiveDataOnly(file_des,fName,MAX_STR_LENGTH);
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
if (ret==OK) {
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else if((strlen(fName))&&(getReceiverStatus()==RUNNING)){
|
||||||
|
strcpy(mess,"Can not set file name while receiver running");
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strcpy(retval,setFileName(fName));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if(ret!=FAIL)
|
||||||
|
printf("file name:%s\n",retval);
|
||||||
|
else
|
||||||
|
printf("%s",mess);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
n = sendDataOnly(file_des,retval,MAX_STR_LENGTH);
|
||||||
|
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int set_file_dir(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
char fPath[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]="";
|
||||||
|
|
||||||
|
strcpy(mess,"Could not set file path\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* receive arguments */
|
||||||
|
n = receiveDataOnly(file_des,fPath,MAX_STR_LENGTH);
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
if (ret==OK) {
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else if((strlen(fPath))&&(getReceiverStatus()==RUNNING)){
|
||||||
|
strcpy(mess,"Can not set file path while receiver running\n");
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
strcpy(retval,setFilePath(fPath));
|
||||||
|
/* if file path doesnt exist*/
|
||||||
|
if(strlen(fPath))
|
||||||
|
if (strcmp(retval,fPath)){
|
||||||
|
strcpy(mess,"receiver file path does not exist\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if(ret!=FAIL)
|
||||||
|
printf("file path:%s\n",retval);
|
||||||
|
else
|
||||||
|
printf("%s",mess);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
n = sendDataOnly(file_des,retval,MAX_STR_LENGTH);
|
||||||
|
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int set_file_index(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
int index,retval=-1;
|
||||||
|
|
||||||
|
strcpy(mess,"Could not set file index\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* receive arguments */
|
||||||
|
n = receiveDataOnly(file_des,&index,sizeof(index));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
if (ret==OK) {
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else if((index>=0)&&(getReceiverStatus()==RUNNING)){
|
||||||
|
strcpy(mess,"Can not set file index while receiver running\n");
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
retval=setFileIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if(ret!=FAIL)
|
||||||
|
printf("file index:%d\n",retval);
|
||||||
|
else
|
||||||
|
printf("%s",mess);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int start_receiver(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
|
||||||
|
strcpy(mess,"Could not start receiver\n");
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else if(!strlen(setFilePath(""))){
|
||||||
|
strcpy(mess,"receiver not set up. set receiver ip again.\n");
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
else if(getReceiverStatus()!=RUNNING)
|
||||||
|
ret=startReceiver();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int stop_receiver(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
|
||||||
|
strcpy(mess,"Could not stop receiver\n");
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
if (lockStatus==1 && differentClients==1){//necessary???
|
||||||
|
sprintf(mess,"Receiver locked by %s\n", lastClientIP);
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
else if(getReceiverStatus()!=IDLE)
|
||||||
|
ret=stopReceiver();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if(ret==FAIL)
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int get_receiver_status(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
enum runStatus retval;
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
retval=getReceiverStatus();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int get_frames_caught(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
int retval=-1;
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
retval=getFramesCaught();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int get_frame_index(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n=0;
|
||||||
|
int retval=-1;
|
||||||
|
|
||||||
|
/* execute action if the arguments correctly arrived*/
|
||||||
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
retval=getFrameIndex();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(ret==OK && differentClients){
|
||||||
|
printf("Force update\n");
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send answer */
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
/*return ok/fail*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int M_nofunc(int file_des){
|
||||||
|
|
||||||
|
int retval=FAIL;
|
||||||
|
sprintf(mess,"Unrecognized Function\n");
|
||||||
|
printf(mess);
|
||||||
|
sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
return GOODBYE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int exit_server(int file_des) {
|
||||||
|
int retval=FAIL;
|
||||||
|
sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
printf("closing server.");
|
||||||
|
sprintf(mess,"closing server");
|
||||||
|
sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
return GOODBYE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exec_command(int file_des) {
|
||||||
|
char cmd[MAX_STR_LENGTH];
|
||||||
|
char answer[MAX_STR_LENGTH];
|
||||||
|
int retval=OK;
|
||||||
|
int sysret=0;
|
||||||
|
int n=0;
|
||||||
|
|
||||||
|
// receive arguments
|
||||||
|
n = receiveDataOnly(file_des,cmd,MAX_STR_LENGTH);
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
retval=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute action if the arguments correctly arrived
|
||||||
|
if (retval==OK) {
|
||||||
|
//#ifdef VERBOSE
|
||||||
|
printf("executing command %s\n", cmd);
|
||||||
|
//#endif
|
||||||
|
if (lockStatus==0 || differentClients==0)
|
||||||
|
sysret=system(cmd);
|
||||||
|
|
||||||
|
//should be replaced by popen
|
||||||
|
if (sysret==0) {
|
||||||
|
sprintf(answer,"Succeeded\n");
|
||||||
|
if (lockStatus==1 && differentClients==1)
|
||||||
|
sprintf(answer,"Detector locked by %s\n", lastClientIP);
|
||||||
|
} else {
|
||||||
|
sprintf(answer,"Failed\n");
|
||||||
|
retval=FAIL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sprintf(answer,"Could not receive the command\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// send answer
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
n = sendDataOnly(file_des,answer,MAX_STR_LENGTH);
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error writing to socket");
|
||||||
|
retval=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//return ok/fail
|
||||||
|
return retval;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int lock_receiver(int file_des) {
|
||||||
|
|
||||||
|
|
||||||
|
int n;
|
||||||
|
int ret=OK;
|
||||||
|
|
||||||
|
int lock;
|
||||||
|
n = receiveDataOnly(file_des,&lock,sizeof(lock));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
printf("Error reading from socket (lock)\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
if (lock>=0) {
|
||||||
|
if (lockStatus==0 || strcmp(lastClientIP,thisClientIP)==0 || strcmp(lastClientIP,"none")==0) {
|
||||||
|
lockStatus=lock;
|
||||||
|
strcpy(lastClientIP,thisClientIP);
|
||||||
|
} else {
|
||||||
|
ret=FAIL;
|
||||||
|
sprintf(mess,"Receiver already locked by %s\n", lastClientIP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (differentClients && ret==OK)
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if (ret==FAIL) {
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
} else
|
||||||
|
n = sendDataOnly(file_des,&lockStatus,sizeof(lockStatus));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int set_port(int file_des) {
|
||||||
|
int n;
|
||||||
|
int ret=OK;
|
||||||
|
int sd=-1;
|
||||||
|
|
||||||
|
enum portType p_type; /** data? control? stop? Unused! */
|
||||||
|
int p_number; /** new port number */
|
||||||
|
|
||||||
|
n = receiveDataOnly(file_des,&p_type,sizeof(p_type));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
printf("Error reading from socket (ptype)\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = receiveDataOnly(file_des,&p_number,sizeof(p_number));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
printf("Error reading from socket (pnum)\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
if (differentClients==1 && lockStatus==1 ) {
|
||||||
|
ret=FAIL;
|
||||||
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
|
} else {
|
||||||
|
if (p_number<1024) {
|
||||||
|
sprintf(mess,"Too low port number %d\n", p_number);
|
||||||
|
printf("\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("set port %d to %d\n",p_type, p_number);
|
||||||
|
|
||||||
|
sd=bindSocket(p_number);
|
||||||
|
}
|
||||||
|
if (sd>=0) {
|
||||||
|
ret=OK;
|
||||||
|
if (differentClients )
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
} else {
|
||||||
|
ret=FAIL;
|
||||||
|
sprintf(mess,"Could not bind port %d\n", p_number);
|
||||||
|
printf("Could not bind port %d\n", p_number);
|
||||||
|
if (sd==-10) {
|
||||||
|
sprintf(mess,"Port %d already set\n", p_number);
|
||||||
|
printf("Port %d already set\n", p_number);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if (ret==FAIL) {
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
} else {
|
||||||
|
n = sendDataOnly(file_des,&p_number,sizeof(p_number));
|
||||||
|
closeConnection(file_des);
|
||||||
|
exitServer(sockfd);
|
||||||
|
sockfd=sd;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_last_client_ip(int file_des) {
|
||||||
|
int ret=OK;
|
||||||
|
int n;
|
||||||
|
if (differentClients )
|
||||||
|
ret=FORCE_UPDATE;
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int send_update(int file_des) {
|
||||||
|
|
||||||
|
int ret=OK;
|
||||||
|
int n,ind;
|
||||||
|
char path[MAX_STR_LENGTH];
|
||||||
|
|
||||||
|
|
||||||
|
n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP));
|
||||||
|
//index
|
||||||
|
ind=getFileIndex(-1);
|
||||||
|
n = sendDataOnly(file_des,&ind,sizeof(ind));
|
||||||
|
//filepath
|
||||||
|
strcpy(path,getFilePath(""));
|
||||||
|
n = sendDataOnly(file_des,path,MAX_STR_LENGTH);
|
||||||
|
//filename
|
||||||
|
strcpy(path,getFileName(""));
|
||||||
|
n = sendDataOnly(file_des,path,MAX_STR_LENGTH);
|
||||||
|
|
||||||
|
if (lockStatus==0) {
|
||||||
|
strcpy(lastClientIP,thisClientIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int update_client(int file_des) {
|
||||||
|
|
||||||
|
int ret=OK;
|
||||||
|
sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
return send_update(file_des);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int set_master(int file_des) {
|
||||||
|
|
||||||
|
enum masterFlags retval=GET_MASTER;
|
||||||
|
enum masterFlags arg;
|
||||||
|
int n;
|
||||||
|
int ret=OK;
|
||||||
|
// int regret=OK;
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(mess,"can't set master flags\n");
|
||||||
|
|
||||||
|
|
||||||
|
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("setting master flags to %d\n",arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) {
|
||||||
|
ret=FAIL;
|
||||||
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
|
} else {
|
||||||
|
retval=setMaster(arg);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (retval==GET_MASTER) {
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if (ret==FAIL) {
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
} else {
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int set_synchronization(int file_des) {
|
||||||
|
|
||||||
|
enum synchronizationMode retval=GET_MASTER;
|
||||||
|
enum synchronizationMode arg;
|
||||||
|
int n;
|
||||||
|
int ret=OK;
|
||||||
|
//int regret=OK;
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(mess,"can't set synchronization mode\n");
|
||||||
|
|
||||||
|
|
||||||
|
n = receiveDataOnly(file_des,&arg,sizeof(arg));
|
||||||
|
if (n < 0) {
|
||||||
|
sprintf(mess,"Error reading from socket\n");
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("setting master flags to %d\n",arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) {
|
||||||
|
ret=FAIL;
|
||||||
|
sprintf(mess,"Detector locked by %s\n",lastClientIP);
|
||||||
|
} else {
|
||||||
|
retval=setSynchronization(arg);
|
||||||
|
}
|
||||||
|
if (retval==GET_SYNCHRONIZATION_MODE) {
|
||||||
|
ret=FAIL;
|
||||||
|
}
|
||||||
|
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||||
|
if (ret==FAIL) {
|
||||||
|
n = sendDataOnly(file_des,mess,sizeof(mess));
|
||||||
|
} else {
|
||||||
|
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
*/
|
42
slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h
Normal file
42
slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef RECEIVER_H
|
||||||
|
#define RECEIVER_H
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "communication_funcs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define GOODBYE -200
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
|
||||||
|
int function_table();
|
||||||
|
int decode_function(int);
|
||||||
|
int M_nofunc(int);
|
||||||
|
int exit_server(int);
|
||||||
|
int exec_command(int);
|
||||||
|
|
||||||
|
|
||||||
|
int lock_receiver(int);
|
||||||
|
int set_port(int);
|
||||||
|
int get_last_client_ip(int);
|
||||||
|
int update_client(int);
|
||||||
|
int send_update(int);
|
||||||
|
//int set_master(int);
|
||||||
|
//int set_synchronization(int);
|
||||||
|
|
||||||
|
// General purpose functions
|
||||||
|
|
||||||
|
//int init_receiver();
|
||||||
|
int set_file_name(int);
|
||||||
|
int set_file_dir(int);
|
||||||
|
int set_file_index(int);
|
||||||
|
int start_receiver(int);
|
||||||
|
int stop_receiver(int);
|
||||||
|
int get_receiver_status(int);
|
||||||
|
int get_frames_caught(int);
|
||||||
|
int get_frame_index(int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
1
slsDetectorSoftware/slsReceiver/sls_detector_defs.h
Symbolic link
1
slsDetectorSoftware/slsReceiver/sls_detector_defs.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../commonFiles/sls_detector_defs.h
|
1
slsDetectorSoftware/slsReceiver/sls_detector_funcs.h
Symbolic link
1
slsDetectorSoftware/slsReceiver/sls_detector_funcs.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../commonFiles/sls_detector_funcs.h
|
Loading…
x
Reference in New Issue
Block a user