/* * * Jul 1, 2013 R.P. Add command REMOTE_CMD_WRITE_SC to write to scalers (instead of REMOTE_CMD_WRITE32, that used before) */ #include "RootHeader.h" #include #include #include #define HTONS(v) htons(v) #define NTOHS(v) ntohs(v) #define NTOHL(v) ntohl(v) #define HTONL(v) htonl(v) #define CMD_RSP(cmd) (cmd | 0x40) #define CMD_ERR(cmd) (cmd & 0x80) #define REMOTE_CMD_READ32 0x07 #define REMOTE_CMD_WRITE32 0x08 #define REMOTE_CMD_READ_SC 0x0B #define REMOTE_CMD_WRITE_SC 0x0C #define REMOTE_CMD_READ_SC_ALL 0x0D #define REMOTE_CMD_READ_PED_ALL 0x0E #define REMOTE_CMD_READ_TS 0x10 #define REMOTE_CMD_READ_TD 0x11 #define VMESERVER_PORT 6002 #define MAX_MSG_SIZE 10000 #define EVENT_MAX_LEN 2048 #define REMOTE_MSG_SIZE(type) (sizeof(RemoteMsgStruct)-MAX_MSG_SIZE+sizeof(type)) typedef struct { unsigned int Length; unsigned int BoardType; unsigned int MsgType; unsigned char Msg[MAX_MSG_SIZE]; } RemoteMsgStruct; /*****************************************************/ /*********** Some Board Generic Commands *************/ /*****************************************************/ typedef struct { unsigned int Address; } Cmd_Read32; typedef struct { unsigned int Value; } Cmd_Read32_Rsp; typedef struct { unsigned int ID; /* slot number or fadc ID */ unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Address; unsigned int Value; } Cmd_Write_SC; typedef struct { unsigned int ID; /* slot number or fadc ID */ unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Value[17]; /* 16ch scalers data + timer*/ } Cmd_Read_SC; typedef struct { unsigned int IDF; /* first fadc slot number */ unsigned int IDL; /* last fadc slot number */ unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Value[272]; /* 256 ch scalers data + timers*/ } Cmd_Read_SC_ALL; typedef struct { unsigned int IDF; /* first fadc slot number */ unsigned int IDL; /* last fadc slot number */ unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Value[128]; /* 256 ch pedestal data */ } Cmd_Read_PED_ALL; typedef struct { unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Value[66]; /* 64 scalers + livetime + busytime */ } Cmd_Read_TS; typedef struct { unsigned int Status; /* status returned by call of fadcLib functions */ unsigned int Value[99]; /* 9 TD boards For each board read 8 optical links + loopback + livetime + busytime */ } Cmd_Read_TD; /************************************************************/ /*** Check if client program is already running somewhere ***/ /************************************************************/ FILE *f_cl; char fGUI_dir[255] = "/home/hdops/CDAQ/config/hd_server"; char dname[20] = ""; char fname[255] = ""; char hostname[80] = ""; char logname[80] = ""; char str_tmp[255]; struct stat buffer; /************************************************************/ #define CHECK_CLIENT_RUNNING(DET) \ sprintf(dname,"%s", (DET)); \ sprintf(fname,"%s/%s_client.log", fGUI_dir, dname); \ \ int exist = stat(fname,&buffer); \ if(exist == 0) \ { \ printf(BOLDRED "\n %s_client is already running !!! \n" RESET,dname); \ \ if((f_cl = fopen(fname,"r")) == NULL){ \ printf(BOLDRED "\n Can't open log file >%s<\n\n" RESET, fname); \ } else { \ fgets(str_tmp, 255, f_cl); \ sscanf (str_tmp, "%*s %s", logname); \ fgets(str_tmp, 255, f_cl); \ sscanf (str_tmp, "%*s %s", hostname); \ printf(BOLDRED "\n by user: %s\n at node: %s\n" RESET,logname,hostname); \ printf("\n see file: %s \n\n", fname); \ } \ fclose(f_cl); \ gApplication->Terminate(); \ } \ else \ { \ gethostname(hostname,80); \ printf("\nhostname: >%s<\n",hostname); \ getlogin_r(logname,80); \ printf("\nlogname: >%s<\n",logname); \ \ if((f_cl = fopen(fname,"w")) == NULL){ \ printf(BOLDRED "\n Can't open log file >%s<\n\n" RESET, fname); \ } else { \ printf("\n Put logname and hostname into log file >%s<\n\n",fname); \ fprintf(f_cl,"user: %s\n", logname); \ fprintf(f_cl,"node: %s\n", hostname); \ fclose(f_cl); \ } \ } /************************************************************/ void sig_handler(int signo) { sprintf(fname,"%s/%s_client.log", fGUI_dir, dname); switch(signo) { case SIGINT: printf("\n\n received SIGINT\n\n"); case SIGTERM: printf("\n\n received SIGTERM\n\n"); } if((remove(fname)) == 0) printf(" Log file deleted successfully \n\n"); else printf(" Error: unable to delete log file \n\n"); exit(1); } /************************************************************/ /************************************************************/