From 29a540818fe3a49edc8205ac9ff2c4e1cd33fa0c Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 11 Oct 2012 12:53:48 +0000 Subject: [PATCH] configuremac after starting receiver, also telling the server to send packets to receiver or cpu with receiver start and receiver stop git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@290 951219d9-93cf-4727-9268-0efd64621fa3 --- .../gotthardDetectorServer/firmware_funcs.c | 27 ++++++ .../gotthardDetectorServer/firmware_funcs.h | 1 + .../gotthardDetectorServer/registers_g.h | 3 +- .../gotthardDetectorServer/server_funcs.c | 82 +++++++++++++++++-- .../gotthardDetectorServer/server_funcs.h | 3 + .../slsDetector/slsDetector.cpp | 49 ++++++++++- .../slsDetector/slsDetectorCommand.cpp | 27 +++--- 7 files changed, 174 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index 46455d691..42d5d528b 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -705,6 +705,33 @@ int setContinousReadOut(int d) { } +int startReceiver(int start) { + u_int32_t addr=CONFIG_REG; +#ifdef VERBOSE + if(start) + printf("Setting up detector to send to Receiver\n"); + else + printf("Setting up detector to send to CPU\n"); +#endif + int reg=bus_r(addr); + //for start recever, write 0 and for stop, write 1 + if (!start) + bus_w(CONFIG_REG,reg|CPU_OR_RECEIVER_BIT); + else + bus_w(CONFIG_REG,reg&(~CPU_OR_RECEIVER_BIT)); + + reg=bus_r(addr); +#ifdef VERBOSE + printf("Config Reg %x\n", reg); +#endif + if (start && (!(reg&CPU_OR_RECEIVER_BIT))) + return OK; + if(!start && (reg&CPU_OR_RECEIVER_BIT)) + return OK; + return FAIL; +} + + u_int64_t getDetectorNumber() { char output[255],mac[255]=""; u_int64_t res=0; diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h index 43ff3c606..75c7b0b67 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h @@ -53,6 +53,7 @@ int setTiming(int t); int setConfigurationRegister(int d); int setToT(int d); int setContinousReadOut(int d); +int startReceiver(int d); int setDACRegister(int idac, int val, int imod); diff --git a/slsDetectorSoftware/gotthardDetectorServer/registers_g.h b/slsDetectorSoftware/gotthardDetectorServer/registers_g.h index 36e209eaa..af72416e1 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/registers_g.h +++ b/slsDetectorSoftware/gotthardDetectorServer/registers_g.h @@ -181,7 +181,8 @@ /* for config register *///not really used yet #define TOT_ENABLE_BIT 0x00000002 #define TIMED_GATE_BIT 0x00000004 -#define CONT_RO_ENABLE_BIT 0x00080000 +#define CONT_RO_ENABLE_BIT 0x00080000 +#define CPU_OR_RECEIVER_BIT 0x00001000 diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c index 854e48cbb..578f3c34a 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c @@ -175,6 +175,8 @@ int function_table() { flist[F_SET_SYNCHRONIZATION_MODE]=&set_synchronization; flist[F_READ_COUNTER_BLOCK]=&read_counter_block; flist[F_RESET_COUNTER_BLOCK]=&reset_counter_block; + flist[F_START_RECEIVER]=&start_receiver; + flist[F_STOP_RECEIVER]=&stop_receiver; return OK; } @@ -2788,18 +2790,19 @@ int configure_mac(int file_des) { if (imod<0) imod=ALLMOD; -#ifdef VERBOSE +//#ifdef VERBOSE printf("Configuring MAC of module %d\n", imod); -#endif +//#endif #ifdef MCB_FUNCS if (ret==OK) { retval=configureMAC(ipad,imacadd,iservermacadd,digitalTestBit); - if(retval==-1) ret=FAIL; + if(retval==-1) + ret=FAIL; } #endif -#ifdef VERBOSE +//#ifdef VERBOSE printf("Configured MAC with retval %d\n", retval); -#endif +//#endif if (ret==FAIL) { printf("configuring MAC of mod %d failed\n", imod); } @@ -3081,3 +3084,72 @@ int reset_counter_block(int file_des) { + + + +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 MCB_FUNCS + if (lockStatus==1 && differentClients==1){//necessary??? + sprintf(mess,"Receiver locked by %s\n", lastClientIP); + ret=FAIL; + } + else + ret = startReceiver(1); +#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 MCB_FUNCS + if (lockStatus==1 && differentClients==1){//necessary??? + sprintf(mess,"Receiver locked by %s\n", lastClientIP); + ret=FAIL; + } + else + ret=startReceiver(0); +#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; +} + + + diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h index e33f276d0..d632f86bc 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.h @@ -81,4 +81,7 @@ int load_image(int); int read_counter_block(int); int reset_counter_block(int); +int start_receiver(int); +int stop_receiver(int); + #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index f1c3225a1..303299ad4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5543,10 +5543,35 @@ int slsDetector::startReceiver(){ } dataSocket->Disconnect(); if (ret==FORCE_UPDATE) - updateReceiver(); + ret=updateReceiver(); } } } + + //configuremac for gotthard + if(ret==OK) + if(thisDetector->myDetectorType==GOTTHARD) + ret=configureMAC(); + + //tell the server to send to receiver and not CPU + if(ret==OK){ + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + ret=updateDetector(); + } + } + } + } + return ret; } @@ -5574,10 +5599,30 @@ int slsDetector::stopReceiver(){ dataSocket->Disconnect(); if (ret==FORCE_UPDATE) - updateReceiver(); + ret=updateReceiver(); } } } + + //tell the server to NOT send to receiver and instead to CPU + if(ret==OK){ + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + ret=updateDetector(); + } + } + } + } + return ret; } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 8024efc0f..1ab4a5731 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -3566,19 +3566,26 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { if(cmd=="receiver"){ if (action==PUT_ACTION) { if(!strcasecmp(args[1],"start")){ - //update receiver index - if(myDet->setReceiverFileIndex(myDet->getFileIndex())==-1) - return string("could not set receiver file index"); - myDet->startReceiver(); + if(myDet->getReceiverStatus()==IDLE){ + //update receiver index + if(myDet->setReceiverFileIndex(myDet->getFileIndex())==-1) + return string("could not set receiver file index"); + //to configure the server + myDet->setOnline(ONLINE_FLAG); + myDet->startReceiver(); + } } else if(!strcasecmp(args[1],"stop")){ - if(myDet->stopReceiver()!=FAIL){ - //update index - int index = myDet->setReceiverFileIndex(); - if(index==-1) - return string("could not get receiver file index"); - myDet->setFileIndex(index); + if(myDet->getReceiverStatus()==RUNNING){ + myDet->setOnline(ONLINE_FLAG); + if(myDet->stopReceiver()!=FAIL){ + //update index + int index = myDet->setReceiverFileIndex(); + if(index==-1) + return string("could not get receiver file index"); + myDet->setFileIndex(index); + } } }else return helpReceiver(narg, args, action);