trdpcu0002_initialize(string domain, string device) { } #uses "lookuptable_SM_Channel_CERN_A.ctl" #uses "lookuptable_SM_PCU_CERN_A.ctl" #uses "lookuptable_SM_PCU_CERN_A.ctl" #uses "lookuptable_SM_Channel_CERN_A.ctl" trdpcu0002_valueChanged( string domain, string device, unsigned Supermodules_dot_StatusWord_dot_Value, string &fwState) { string DP; bit32 StatusWord; DP=device+".Supermodules.StatusWord.Value"; dpGet(DP,StatusWord); StatusWord(StatusWord,Supermodules_dot_StatusWord_dot_Value, fwState,device); DebugN("Functoin"); } //******************************************-------------------------------------------------------------************************************** //Function to set the the Status Word for the States needed in the FSM StatusWord(bit32 b,unsigned Supermodules_dot_StatusWord_dot_Value, string &fwState, string device ) { //Get Number of powered Supermodule from database bit32 Supermodule_Config=0; //bit32 Config; //string filename; //filename=PROJ_PATH+"Test/Supermodule_config_test.txt"; //file f; //int Config=1; //f= fopen(filename,"r"); //if(f==0){DebugN("Can't open file "+filename);return;} //fprintf(f,"%d",Config); //fscanf(f,"%d",Config); //else{ //Supermodule_Config=fscanf(f,"%x",Config); //} //DebugN("Supermodule_Config"+Config); //return; //Fixed Value for test Supermodule_Config=257; //Staus Word for the ON State bit32 SW_MIXED; //Status Word for the STANDBY State bit32 SW_STANDBY; //Status word for the OFF State bit32 SW_OFF; //Status Word for the Error State bit32 SW_ERROR; //Loop over the Supermodules in Supermodule_Config for(int SM=1;SM<19;SM++) { dyn_bool Status_SM; Status_SM[SM]=checkSupermodule(Supermodule_Config,SM); //if at least one Supermodule is supposed to be powered if (Status_SM[SM]){ //Get the Variables PCU Number and Channel for the active Supermodule dyn_bool Status_SM_Channel; Status_SM_Channel[SM]=SM_PCU(SM-1); //Condition for the PCU, that the right channel ias chosen if(PCU==0||PCU==2){ DebugN("Supermodule: "+(SM-1)+" "+Status_SM[SM]+" CHANNEL: "+channel); //Loop over the different parts of the Status Word from the PCU; and creating the Status Words for the different States in the FSM //Check the connection between PCU and PDB for(int connection=1;connection<10;connection++) { dyn_bool status_connection; status_connection[connection]=checkStatusWord(b,connection); if(connection==channel+1){ if(status_connection[channel+1]){ setBit(SW_MIXED,(channel),TRUE); setBit(SW_STANDBY,(channel),TRUE); setBit(SW_OFF,(channel),TRUE); } else {fwState="NO_CONTROL";continue;} } //else {fwState="NO_CONTROL";} }//connection loop // Check if the channel is active; means if commands are sent for(int activity=10;activity<19;activity++) { dyn_bool status_activity; status_activity[activity]=checkStatusWord(b,activity); if (status_activity[activity]){ setBit(SW_MIXED,(activity-1),TRUE); setBit(SW_ERROR,(activity-1),TRUE); } //check the readValue for the Supermodule if an ERROR occured if(activity==channel+10){ if(status_activity[channel+10]==TRUE) { DebugN("Channel: "+channel+10); bool Error_activity; Error_activity=Error_State(device,fwState,SM); DebugN("Error Status: "+Error_activity); time t; t=getCurrentTime(); if (Error_activity){fwState="ERROR";DebugN("Error at channel: "+channel+"SM: "+(SM-1)+" at: "+t);return;} else continue; } else fwState="NO_CONTROL"; } }//activity loop //Check if the sentword and the word from the feedback channel is identical if not -->ERROR for(int read=19;read<28;read++){ dyn_bool status_read; status_read[read]=checkStatusWord(b,read); if (!status_read[read]){ setBit(SW_MIXED,(read-1),FALSE); setBit(SW_STANDBY,(read-1),FALSE); setBit(SW_OFF,(read-1),FALSE); //setBit(SW_ERROR,(read-1),FALSE); } else{setBit(SW_MIXED,(read-1),TRUE); setBit(SW_STANDBY,(read-1),TRUE); setBit(SW_OFF,(read-1),TRUE); setBit(SW_ERROR,(read-1),TRUE); } if (read==channel+19){ if (status_read[channel+19]){ fwState="NO_CONTROL";DebugN("NO_CONTROL because Read");return; } } }//read loop //Check the timeout bit (30) int timeout=31; dyn_bool status_timeout; status_timeout[timeout]=checkStatusWord(b,timeout); if (status_timeout[timeout]){ setBit(SW_STANDBY,(timeout-1),TRUE); setBit(SW_MIXED,(timeout-1),TRUE); setBit(SW_ERROR,(timeout-1),TRUE); } else{ bool t_status; t_status=On_Single_State(device,fwState,SM); if(t_status) {fwState="NO_TIMEOUT";return;} } //Set the States in the FSM according to the created StatusWords if (Supermodules_dot_StatusWord_dot_Value == SW_MIXED && SW_MIXED!=SW_STANDBY) { fwState = "MIXED"; DebugN("MIXED"); bool ON; ON=ON_State(device,fwState,SM); if(ON) fwState="ON"; } else if (Supermodules_dot_StatusWord_dot_Value == SW_STANDBY && SW_STANDBY!=SW_OFF) { fwState = "STANDBY"; DebugN("STANDBY"); } else if (Supermodules_dot_StatusWord_dot_Value == SW_OFF) { fwState = "OFF"; DebugN("OFF"); } else if(Supermodules_dot_StatusWord_dot_Value == SW_ERROR) { fwState = "ERROR"; DebugN("ERROR"); } }//PCU condition end }//Status_SM end //if all 18/9 Supermodules are supposed to be active!! else {//fwState="NO_CONTROL"; DebugN("NO_CONTROL for SM: "+(SM-1)); } }//SM loop end }//end of function //*********************************-----------------------------------------------------------------------------------------------******** //Function to check the single bits of the Status Word bool checkStatusWord(bit32 a,int pos) { { if(pos>33 || pos < 0) { DebugN("wrong position(out of range"); return false; } unsigned mask= (1 << (pos-1)); return a & mask; } } //****************************_-------------------------------************************************************************************ bool checkSupermodule(bit32 c,int pos) { { if(pos>19 || pos < 0) { DebugN("wrong position(out of range"); return false; } unsigned mask= (1 << (pos-1)); return c & mask; } } //*************************************------------------------------------------------------------************************************************** bool Error_State(string device,string &fwState,int SM) { string DP_Single_SM; bit32 Single_ReadValue; bool Error_Status; bool a,b; //DebugN("Error_function 1"); if(SM<10) sprintf(DP_Single_SM,device+".Supermodules.SM0%dPCU.readValue",(SM-1)); else sprintf(DP_Single_SM,device+".Supermodules.SM%dPCU.readValue",(SM-1)); DebugN("Error function DP: "+DP_Single_SM+"_____"+(SM-1)); dpGet(DP_Single_SM,Single_ReadValue); DebugN("Error_function RV: "+Single_ReadValue); { a=getBit(Single_ReadValue,31); b=getBit(Single_ReadValue,32); //DebugN("Error_function 3"); DebugN("Bit1: "+a+"; Bit2"+b); if (a || b) {Error_Status=TRUE;DebugN("ERROR Ocurred");} else Error_Status=FALSE; } return Error_Status; } bool ON_State(string device,string &fwState,int SM) { string DP_Single_SM; bit32 Single_ReadValue; bool ON_Status; if(SM<10) sprintf(DP_Single_SM,device+".Supermodules.SM0%dPCU.readValue",(SM-1)); else sprintf(DP_Single_SM,device+".Supermodules.SM%dPCU.readValue",(SM-1)); DebugN("ON function DP: "+DP_Single_SM+"_____"+(SM-1)); dpGet(DP_Single_SM,Single_ReadValue); DebugN("ON_function RV: "+Single_ReadValue); if (Single_ReadValue==1073741823) ON_Status=TRUE; else ON_Status=FALSE; return ON_Status; } bool On_Single_State(string device,string &fwState,int SM) { string DP_Single_SM; bit32 Single_ReadValue; bool On_Single_Status; if(SM<10) sprintf(DP_Single_SM,device+".Supermodules.SM0%dPCU.readValue",(SM-1)); else sprintf(DP_Single_SM,device+".Supermodules.SM%dPCU.readValue",(SM-1)); DebugN("ON_Single function DP: "+DP_Single_SM+"_____"+(SM-1)); dpGet(DP_Single_SM,Single_ReadValue); DebugN("ON_Single function RV: "+Single_ReadValue); if (Single_ReadValue>0) On_Single_Status=TRUE; else On_Single_Status=FALSE; return On_Single_Status; } trdpcu0002_doCommand(string domain, string device, string command) { string DP_Co,DP_SW; DP_Co=device+".Command.Command"; DP_SW=device+".Supermodules.StatusWord.Value"; bit32 StatusWord_Co; dyn_bool status_connection_co; string Command; dpGet(DP_SW,StatusWord_Co); //DebugN("StatusWord"); //DebugN("This is the SW in doCommand: "+ StatusWord_Co); for (int channel=1;channel<10;channel++){ status_connection_co[channel]=checkStatusWord_co(StatusWord_Co,channel); //DebugN("Channels Activity: "+status_connection_co); if(status_connection_co[channel]){ //DebugN("after True : " + channel); if (command == "SWITCH_OFF") { Command="off,"+(channel-1)+",all,all"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command OFF: "+Command); } if (command == "SETTIMEOUT") { int length_timeout; length_timeout=20/0.0016; Command="timeout,"+length_timeout; dpSet(DP_Co,Command); DebugN("Timeout is set to: " +timeout+"channel is active:" +(channel-1)); } if (command == "SWITCH_ON") { Command="on,"+(channel-1)+",all,all"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } if (command == "RECOVER") { Command="off,"+(channel-1)+",all,all"; dpSet(DP_Co,Command,Command); delay(1); DebugN("Set SW to zero"); dpSet(DP_SW,0); DebugN("Done"); } if (command== "SWITCH_ON_STACK0") {Command="on,"+(channel-1)+",all,0"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } if (command== "SWITCH_ON_STACK1") {Command="on,"+(channel-1)+",all,1"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } if (command== "SWITCH_ON_STACK2") {Command="on,"+(channel-1)+",all,2"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } if (command== "SWITCH_ON_STACK3") {Command="on,"+(channel-1)+",all,3"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } if (command== "SWITCH_ON_STACK4") {Command="on,"+(channel-1)+",all,4"; dpSet(DP_Co,Command); DebugN("Channel"+(channel-1)+"received Command ON: "+Command); } } } } //Function to check the single bits of the Status Word bool checkStatusWord_co(bit32 a,int pos) { { if(pos>33 || pos < 0) { DebugN("wrong position(out of range"); return false; } unsigned mask= (1 << (pos-1)); return a & mask; } }