/* returns measured current for one channel */ float sy527GetChannelMeasuredCurrent(unsigned int id, unsigned int board, unsigned int chan) { int ret; float u; /* CHECK_OPEN(id); sy527Start(id,"129.57.69.101"); sy527PrintMap(id); sy527GetMap(id); ret = sy527GetBoard(id, board); */ LOCK_MAINFRAME(id); GET_FVALUE(IMon, u); /*GET_FVALUE(V0Set, u);*/ UNLOCK_MAINFRAME(id); #ifdef DEBUG printf("%s:%s(%d): MF id=%u board=%u Chan=%u Val=%f Status=%d\n", __FILE__, __FUNCTION__, __LINE__, id, board, chan, u, ret); #endif return(u); }
/* sets on/off status for one channel */ int sy1527SetChannelOnOff(unsigned int id, unsigned int board, unsigned int chan, unsigned int u) { LOCK_MAINFRAME(id); SET_LVALUE(Pw, u); UNLOCK_MAINFRAME(id); return(0); }
/* sets maximum voltage for one channel */ int sy1527SetChannelMaxVoltage(unsigned int id, unsigned int board, unsigned int chan, float u) { LOCK_MAINFRAME(id); SET_FVALUE(SVMax, u); UNLOCK_MAINFRAME(id); return(0); }
/* sets demand voltage for one channel */ int sy527SetChannelDemandVoltage(unsigned int id, unsigned int board, unsigned int chan, float u) { LOCK_MAINFRAME(id); SET_FVALUE(V0Set, u); UNLOCK_MAINFRAME(id); return(0); }
/* sets enable/disable for one channel */ int sy1527SetChannelEnableDisable(unsigned int id, unsigned int board, unsigned int chan, unsigned int u) { LOCK_MAINFRAME(id); SET_LVALUE1(PwEn, u); UNLOCK_MAINFRAME(id); return(0); }
/* returns Ramp-up speed for one channel */ float sy527GetChannelRampUp(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(RUp, u); UNLOCK_MAINFRAME(id); return(u); }
/* sets Ramp-down speed for one channel */ int sy1527SetChannelRampDown(unsigned int id, unsigned int board, unsigned int chan, float u) { LOCK_MAINFRAME(id); SET_FVALUE(RDWn, u); UNLOCK_MAINFRAME(id); return(0); }
/* sets maximum current for one channel */ int sy1527SetChannelMaxCurrent(unsigned int id, unsigned int board, unsigned int chan, float u) { LOCK_MAINFRAME(id); SET_FVALUE(I0Set, u); UNLOCK_MAINFRAME(id); return(0); }
/* returns measured current for one channel */ float sy1527GetChannelMeasuredCurrent(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(IMon, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns measured voltage for one channel */ float sy527GetChannelMeasuredVoltage(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(VMon, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns maximum voltage for one channel */ float sy1527GetChannelMaxVoltage(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(SVMax, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns demand voltage for one channel */ float sy1527GetChannelDemandVoltage(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(V0Set, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns on/off status for one channel */ unsigned int sy527GetChannelOnOff(unsigned int id, unsigned int board, unsigned int chan) { unsigned int u; LOCK_MAINFRAME(id); GET_LVALUE(Pw, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns maximum current for one channel */ float sy527GetChannelMaxCurrent(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); GET_FVALUE(I0Set, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns status for one channel */ unsigned int sy1527GetChannelStatus(unsigned int id, unsigned int board, unsigned int chan) { unsigned int u; LOCK_MAINFRAME(id); GET_LVALUE(Status, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns enable/disable for one channel */ unsigned int sy1527GetChannelEnableDisable(unsigned int id, unsigned int board, unsigned int chan) { unsigned int u; LOCK_MAINFRAME(id); GET_LVALUE(PwEn, u); UNLOCK_MAINFRAME(id); return(u); }
/* returns Ramp-up speed for one channel */ float sy1527GetChannelRampUp(unsigned int id, unsigned int board, unsigned int chan) { float u; //printf("===========================================id=%d board=%d chan=%d\n",id,board,chan); LOCK_MAINFRAME(id); GET_FVALUE(RUp, u); UNLOCK_MAINFRAME(id); //printf("===========================================id=%d board=%d chan=%d value=%f\n",id,board,chan,u); return(u); }
float sy1527GetChannelTripTime(unsigned int id, unsigned int board, unsigned int chan) { float u; LOCK_MAINFRAME(id); //GET_FVALUE(Trip, u); u=Measure[id].board[board].channel[chan].fval[Trip]; //printf("trip time %f %d %f\n", u, //Measure[id].board[board].channel[chan].lval[Trip],Measure[id].board[board].channel[chan].fval[Trip]); UNLOCK_MAINFRAME(id); //printf("trip time %f\n", u); return u; }
/* mainframe thread */ void * sy1527MainframeThread(void *arg) { int id, i, ret, status; //printf("+++++++++++++++++++++++++starts 00\n"); id=((THREAD *)arg)->threadid; printf("[%2d] starts thread +++ ++\n",id); while(1) { //printf("+++++++++++++++++++++++++starts 0\n"); sleep(1); //printf("+++++++++++++++++++++++++starts 1\n"); LOCK_MAINFRAME(id); //printf("+++++++++++++++++++++++++starts 2\n"); if(force_exit[id]) { pthread_mutex_unlock(&mainframe_mutex[id]); break; } /***** talk to mainframe here *****/ /* sets all existing boards in mainframe 'id' with 'setflag' */ if(Demand[id].setflag == 1) { status = CAENHV_OK; for(i=0; i<Measure[id].nslots; i++) { if(Demand[id].board[i].nchannels > 0) { if(Demand[id].board[i].setflag == 1) { printf("[%2d] sets board %d\n",id,i); // my: ret = sy1527SetBoard(id,i); if(ret == CAENHV_OK) Demand[id].board[i].setflag = 0; else status |= CAENHV_SYSERR; } } } if(status == CAENHV_OK) Demand[id].setflag = 0; } //printf("+++++++++++++++++++++++++starts 3\n"); /* gets all existing boards in mainframe 'id' */ for(i=0; i<Measure[id].nslots; i++) { // printf("[%2d] gets board %d nslots=%d\n",id,i,Measure[id].nslots); // my: /* measure all active boards */ if(Measure[id].board[i].nchannels > 0) { /*printf("[%2d] reads out board %d\n",id,i);*/ ret = sy1527GetBoard(id,i); } } /**********************************/ pthread_mutex_unlock(&mainframe_mutex[id]); //printf("+++++++++++++++++++++++++starts %d\n",id); for(i=0; i<nmainframes; i++){ if(mainframes[i]==id)is_mainframe_read[i]=1; } } printf("[%2d] exit thread\n",id); return NULL; }
/// my: smi ====================================================================================== int sy1527BoardSmiMonitor( char *epics_name, unsigned int id, unsigned int board, unsigned int first_channel, unsigned int chs_number) { char *tmp1, *tmp2=epics_name; /// temporal while((tmp1=strstr(tmp2,"_P"))){ tmp2=tmp1+1; /// my_n_smi: not used } int board_part=first_channel; /// my_n_smi: atoi(tmp2-1+strlen("_P")); int b_status=0, b_status_res=0; /// my: smi int i, i10; ///-------- my_n: // id comes from db here. // if not connection: id is absent in mainframes[] (in mainframes[] it is present as -1) // if comment in startup.all: id is absent in mainframes[] int absent_error=1; for(i=0;i<nmainframes;i++){ if(mainframes[i]==id){absent_error=0;i10=i;break;} } if(absent_error==0 && mainframes_disconnect[i10]==1)absent_error=3; else if(absent_error==0 && Demand[id].board[board].nchannels==0)absent_error=2; ///-------- LOCK_MAINFRAME(id); for(i=first_channel; i<first_channel+chs_number; i++) /// my_n_smi { /// my: smi: accumulates all channels attuses into board status b_status = b_status | Measure[id].board[board].channel[i].lval[Status]; if(!(Measure[id].board[board].channel[i].lval[Status] & 0x1))b_status = b_status | BIT_OFF; /// at least one channel in the board is OFF /*printf("Slot: %2d Ch: %3d %s: %x\n", Slot, ChList[i], ParName, lParValList[i]);*/ } /// my:smi char smi_obj_name1[150]; /// temporal char smi_command[150]; /// temporal if(b_status & BIT_ON)b_status_res=BIT_ON; if(b_status & (BIT_RAMPUP | BIT_RAMPDOWN ))b_status_res=BIT_RAMPUP; if(b_status & BIT_OFF)b_status_res=BIT_OFF; if(b_status & (BIT_INTTRIP | BIT_EXTTRIP | BIT_OVERCUR | BIT_OVERVOLT | BIT_UNDERVOLT )) b_status_res=BIT_INTTRIP; if(b_status_res==BIT_ON)strcpy(smi_command,"SET_ON"); else if(b_status_res==BIT_RAMPUP)strcpy(smi_command,"SET_RAMP"); /// temporal !!! else if(b_status_res==BIT_OFF)strcpy(smi_command,"SET_OFF"); else if(b_status_res==BIT_INTTRIP)strcpy(smi_command,"SET_ERROR"); if(absent_error){ if(absent_error==1)b_status_res=BIT_CRATE_OFF; else if(absent_error==2)b_status_res=BIT_BOARD_NOT_PRESENT; else if(absent_error==3)b_status_res=BIT_CRATE_OFF_ON_WAY; strcpy(smi_command,"SET_ERROR"); // my_n: //printf(">>> %s %d\n", epics_name, absent_error ); } if(b_status_res != boards_status[id][board][board_part]){ // sprintf(smi_obj_name1, CRATE_LABEL, id); // sprintf(smi_obj_name, "HV_TEST::%s_%d", smi_obj_name1, board); // strncpy(smi_obj_name1, smi_obj_name, strlen(smi_obj_name) - strlen("_monitor")); // smi_obj_name1[strlen(smi_obj_name) - strlen("_monitor")]=0; sprintf(smi_obj_name1, "CLAS12::%s", epics_name); smiui_send_command(smi_obj_name1, smi_command); printf("smi: smi_obj_name=%s smi_command=%s id=%d board=%d chas=%d abs_error=%d \n", smi_obj_name1, smi_command, id, board, Demand[id].board[board].nchannels, absent_error); boards_status[id][board][board_part]=b_status_res; } UNLOCK_MAINFRAME(id); return(CAENHV_OK); }
/* mainframe thread */ void * sy527Thread(void *arg) { int id, i, ret, status; id=((THREAD *)arg)->threadid; printf("[%2d] starts thread\n",id); while(1) { printf("sy527Thread 1\n"); #ifdef vxWorks ttsleep(100); #else sleep(1); #endif LOCK_MAINFRAME(id); if(force_exit[id]) { UNLOCK_MAINFRAME(id); break; } /***** talk to mainframe here *****/ /* sets all existing boards in mainframe 'id' with 'setflag' */ if(Demand[id]->setflag == 1) { status = CAENHV_OK; for(i=0; i<Measure[id]->nslots; i++) { if(Demand[id]->board[i].nchannels > 0) { if(Demand[id]->board[i].setflag == 1) { /*printf("[%2d] sets board %d\n",id,i);*/ ret = sy527SetBoard(id,i); if(ret == CAENHV_OK) Demand[id]->board[i].setflag = 0; else status |= CAENHV_SYSERR; } } } if(status == CAENHV_OK) Demand[id]->setflag = 0; } /* gets all existing boards in mainframe 'id' */ for(i=0; i<Measure[id]->nslots; i++) { /* measure all active boards */ if(Measure[id]->board[i].nchannels > 0) { /*printf("[%2d] reads out board %d\n",id,i);*/ ret = sy527GetBoard(id,i); } } /**********************************/ UNLOCK_MAINFRAME(id); } printf("[%2d] exit thread\n",id); /*return;*/ }