/* r_tcpServer.c to run tcpServer on ROC */ #include #include #include #include #include #include "fadcLib.h" #include "sspLib.h" /* ssh rocbcal9 source /home/somov/setups/bcal_cosmic_test/src/rol/setupcoda3 cd /gluex/devel/SP/tcpServer_SP source /gluex/devel/src/tcpServer/setupcoda3 source ~sergpozd/.aliases cd /gluex/devel/src/tcpServer ./r_tcpServer tcpClient rocbcal8 "fadc250Config('/home/halld/test_setup/rocbcal9/fadc250_example.cnf')" tcpClient rocbcal8 "fadc250Mon(0)" tcpClient roctof3 "dsc2Init(0x100000,0x80000,20,0)" tcpClient roctof3 "dsc2Config('/home/halld/test_setup/rocbcal9/dsc2_example.cnf')" tcpClient roctof3 "dsc2Mon(0)" tcpClient roctof2 "tdc1190Init(0x09A00000,0,1,0)" tcpClient roctof2 "tdc1290Config('/home/halld/test_setup/rocbcal9/tdc1290_example.cnf')" tcpClient roctof2 "tdc1290Mon(0)" */ #define RESET "\033[0m" #define BLACK "\033[30m" /* Black */ #define RED "\033[31m" /* Red */ #define GREEN "\033[32m" /* Green */ #define YELLOW "\033[33m" /* Yellow */ #define BLUE "\033[34m" /* Blue */ #define MAGENTA "\033[35m" /* Magenta */ #define CYAN "\033[36m" /* Cyan */ #define WHITE "\033[37m" /* White */ #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ #define BOLDRED "\033[1m\033[31m" /* Bold Red */ #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ int test1() { printf("test1\n"); } int test2(int a) { printf("test2: a=%d\n",a); } #include "tcpServer.c" #include "fadc250Config.c" #include "dsc2Config.c" #include "tdc1290Config.c" #include "f1tdcConfig.c" #include "v851.c" #include static int init_fADC250, init_fADC125, init_F1TDCV2; static int init_SSP, init_CTP, init_SD, init_TI, init_TS; static int init_DSC2, init_VX1290A, init_TD; static char board[22][216]; int main(int argc, char *argv[]) { char str[256], myname[256]; char *host, *saveptr; int iFlag = 0; int sl, ii; int NFADC=18; int FA_SLOT; /* Open the default VME windows */ vmeOpenDefaultWindows(); printf("= 0 ======================================================\n");fflush(stdout); printf("argc=%d\n",argc);fflush(stdout); if(argc==2) { printf("= 1 ======================================================\n");fflush(stdout); strncpy(myname, argv[1], 255); printf("get host name from argument >%s< \n",myname);fflush(stdout); } else { printf("= 2 ======================================================\n");fflush(stdout); /* use HOST insdead of HOSTNAME, HOSTNAME not determinated in cron */ strncpy(str, getenv("HOST"), 255); host = strtok_r(str,".",&saveptr); strncpy(myname, host, 255); printf("= 3 ======================================================\n");fflush(stdout); printf("get short host name from env var HOST >%s< \n",str);fflush(stdout); printf("host = >%s< \n",host);fflush(stdout); printf("short host name (myname) = >%s< \n",myname);fflush(stdout); printf("= 4 ======================================================\n");fflush(stdout); } printf("2 < 19 =0x%x \n",(2 << 19));fflush(stdout); printf("3 < 19 =0x%x \n",(3 << 19));fflush(stdout); printf("4 < 19 =0x%x \n",(4 << 19));fflush(stdout); printf("==========================================================\n\n"); BoardsFromDB(myname); /* for(ii=1; ii<22; ii++) printf(" sl.%02d = %s\n", ii, board[ii]); */ if(init_DSC2) { printf(BOLDBLUE "\n==========================================================\n\n" RESET); printf(BOLDBLUE " INITIALIZE DSC2 \n\n" RESET); dsc2Init(0x100000,0x80000,20,0); dsc2Mon(0); } if(init_VX1290A) { printf(BOLDBLUE "\n==========================================================\n\n" RESET); printf(BOLDBLUE " INITIALIZE VX1290A \n\n" RESET); /*tdc1190Init(0x09A00000,0,1,0);*/ tdc1190Init(0x11180000,0x80000,20,0); tdc1290Mon(0); } if(init_F1TDCV2) { printf(BOLDBLUE "\n==========================================================\n\n" RESET); printf(BOLDBLUE " INITIALIZE F1TDCV2 \n\n" RESET); /* Setup the iFlag.. flags for FADC initialization */ iFlag = 0; iFlag |= (1<<18); /* skip firmware check */ /*f1Init(0x480000,0,1,iFlag);*/ f1Init(0x180000,0x80000,20,iFlag); } if(init_TI) { printf("\n==========================================================\n\n"); printf(" INITIALIZE TI \n\n"); printf("TI mode = 3, iFlag = 0"); // #define TI_READOUT_EXT_INT 0 // #define TI_READOUT_TS_INT 1 // #define TI_READOUT_EXT_POLL 2 // #define TI_READOUT_TS_POLL 3 // tiInit((21<<19),3,0); tiInit((21<<19),2,0); tiStatus(); } if(init_fADC250) { printf(BOLDBLUE "\n==========================================================\n\n" RESET); printf(BOLDBLUE " INITIALIZE fADC250 \n\n" RESET); /* Setup the iFlag.. flags for FADC initialization */ iFlag = 0; /* Sync Source */ iFlag |= (1<<0); /* VXS */ /* Trigger Source */ iFlag |= (1<<2); /* VXS */ /* Clock Source */ /*iFlag |= (1<<5);*/ /* VXS */ iFlag |= (0<<5); /* self*/ printf(" TEST: NFADC = %d\n",NFADC); vmeSetQuietFlag(1); /* skip the errors associated with BUS Errors */ faInit((unsigned int)(3<<19),(1<<19),NFADC,iFlag); /* start from 0x00180000, increment 0x00080000 */ NFADC=nfadc; /* Redefine our NFADC with what was found from the driver */ printf(" TEST............NFADC= %d \n",NFADC); int board, channel; // Alex for(board = 0; board < NFADC; board++) { int slot = fadcID[board]; printf(BOLDBLUE "\n==========================================================\n\n" RESET); printf(BOLDBLUE " INITIALIZE fADC250 , Slot number %d \n\n" RESET, slot); int status = 0; // status = faInit((unsigned int)(slot<<19), 0, 1, iFlag); if(status==0) { /* FADC is present in slot */ faSetProcMode(slot, 10, 500, 100, 3, 12, 1, 4, 512, 1); printf(" Find %d FADC250 in host %s \n", NFADC, host); // Alex // Reset DAC // faDACReset(slot); time_t seconds; seconds = time(NULL); printf("Time = %d \n",seconds); /* load DACs, thresholds ... */ for(channel = 0; channel<16; channel++) { faSetDAC(slot, 3300, (0x1<%s< \n\n",query); conn = mysql_init(NULL); /* connect to database */ if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); return(-1); } /* send MySQL query */ if (mysql_query(conn, query)) { fprintf(stderr, "%s\n", mysql_error(conn)); return(-2); } res = mysql_use_result(conn); /* output from MySQL */ printf("MySQL query result: \n\n"); while ((row = mysql_fetch_row(res)) != NULL) { printf(" %8s >%s< \n", row[0], row[1]); if(strcasestr(row[0],"slot") != NULL) { sscanf (row[0], "%*s %d", &slot); if(slot<1 || slot>21) { printf("\nBoardsFromDB: Wrong slot number %d, %s\n",slot,row[0]); return(-3); } else { sprintf(board[slot],"%s", row[1]); if (strcmp(board[slot],"fADC250") == 0) init_fADC250 = 1; else if(strcmp(board[slot],"fADC125") == 0) init_fADC125 = 1; else if(strcmp(board[slot],"F1TDCV2") == 0) init_F1TDCV2 = 1; else if(strcmp(board[slot],"SSP") == 0) init_SSP = 1; else if(strcmp(board[slot],"CTP") == 0) init_CTP = 1; else if(strcmp(board[slot],"SD") == 0) init_SD = 1; else if(strcmp(board[slot],"TI") == 0) init_TI = 1; else if(strcmp(board[slot],"TS") == 0) init_TS = 1; else if(strcmp(board[slot],"DSC2") == 0) init_DSC2 = 1; else if(strcmp(board[slot],"VX1290A") == 0) init_VX1290A = 1; else if(strcmp(board[slot],"TD") == 0) init_TD = 1; } } } /* close connection */ mysql_free_result(res); mysql_close(conn); return(0); } /*******************************************************************************/ /*******************************************************************************/ /*******************************************************************************/ #if 0 #endif #if 1 #endif