SCTDCSCommand.cxx

00001 
00002 // This file contains the class definition to issue 
00003 // non-transition command and request data (SCT special commands)
00004 //                  
00005 //    Created 01.04.03
00006 //    by A. Abdesselam
00008 
00009 #include <iostream>
00010 #include <string>
00011 #include <vector>
00012 #include <time.h>
00013 //#include <stdlib.h>
00014 
00015 //IS stuff
00016 //#include <is/isinfotmpl.h>
00017 //#include <is/isnamedinfo.h>
00018 //#include <is/isinfoany.h>
00019 #include <is/info.h>
00020 #include <is/infodictionary.h>
00021 #include <is/infoiterator.h>
00022 #include <is/inforeceiver.h>
00023 #include <is/infoT.h>
00024 
00025 #include <cmdl/cmdargs.h>
00026 
00027 using namespace std;
00028 
00029 //this package stuff
00030 #include "sctddc/SCTDdcCommandSender.hxx"
00031 #include "sctddc/SCTDdcRequest.hxx"
00032 #include "sctddc/SCTDCSCommand.hxx"
00033 
00034 //constructor: need partition, controler list (at least one controller).
00035 SCTDCSCommand::SCTDCSCommand(IPCPartition& partition, string** ctrlList) 
00036 {
00037   //this for no-transition commands
00038   m_sctDdcCommandSender = new SCTDdcCommandSender(partition, ctrlList);
00039 
00040   //this for data request: "RunCtrl" is the name of the default IS server where DAQ issues data request
00041   string is_server("RunCtrl");
00042   m_sctDdcRequest = new SCTDdcRequest(partition, is_server);
00043 }
00044 SCTDCSCommand::~SCTDCSCommand() 
00045 {
00046   //free memory
00047   delete m_sctDdcCommandSender;
00048   delete m_sctDdcRequest;
00049 }
00050 
00051 //**********************************************************************************************************
00052 //========================================= ADDRESS HELP METHODS ===========================================
00053 //**********************************************************************************************************
00054 
00055 //=========================================== Methods for Channels ========================================
00056 
00057 // these two  methods  convert PS coordinates to PVSS addresses (channel case)
00058 //---------------------------------------------------------------------------------------------------------
00059 void SCTDCSCommand::psToPVSSChannelAddress(int crate, int channel, string dpeName,
00060                        const char* direction, 
00061                        string& pvssAddress)
00062 //---------------------------------------------------------------------------------------------------------
00063 {
00064   std::vector<string> tmp_vec1, tmp_vec2;
00065   tmp_vec1.push_back(dpeName);
00066   psToPVSSChannelAddress(crate, channel, tmp_vec1, direction, tmp_vec2);
00067   pvssAddress = tmp_vec2.front();
00068   return;
00069 }
00070 //---------------------------------------------------------------------------------------------------------
00071 void SCTDCSCommand::psToPVSSChannelAddress(int crate, int channel, std::vector<string> dpeNames, 
00072                        const char* direction,
00073                        std::vector<string>& pvssAddresses)
00074 //---------------------------------------------------------------------------------------------------------
00075 {
00076   // PVSS DataPoint addresses
00077   char addresses[200];
00078   
00079   // make the crate addressese
00080   if(crate < 10)
00081     {
00082       //add 0 to make two digit number
00083       sprintf(addresses, "Crate0%d", crate);
00084     }
00085   else if(crate < 100)
00086     {
00087       sprintf(addresses, "Crate%d", crate);
00088     }
00089   else
00090     {
00091       cout<< "SCTDCSCommand::setParameter: The crate number"<<crate<<" is not correct"<<endl;
00092     }
00093 
00094   // add the rest of the addresses: channel, parameter,... 
00095   if(channel < 10)
00096     {
00097       //add 0 to make two digit number
00098       sprintf(addresses, "%s.Channel0%d", addresses, channel);
00099     }
00100   else if(channel < 100)
00101     {
00102       sprintf(addresses, "%s.Channel%d", addresses, channel);
00103     }
00104   else
00105     {
00106       cout<< "SCTDCSCommand::setParameter: The channel number"<<channel<<" is not correct"
00107       <<endl;
00108     }
00109   
00110   char addressesTmp[200];
00111   for(unsigned int i=0; i< dpeNames.size(); i++)
00112     {
00113       const char* c_dpeName = dpeNames[i].c_str();
00114       sprintf(addressesTmp, "%s.%s.%s", addresses, c_dpeName, direction);
00115       // put addresses in a string and then in a vector
00116       pvssAddresses.push_back(string(addressesTmp)); 
00117     }
00118   return;
00119 }
00120 
00121 //=========================================== Methods for Cards ========================================
00122 
00123 // these two  methods  convert PS coordinates to PVSS addresses (card case)
00124 //---------------------------------------------------------------------------------------------------------
00125 void SCTDCSCommand::psToPVSSCardAddress(int crate, int card, string dpeName,
00126                     const char* direction, string& pvssAddress)
00127 //---------------------------------------------------------------------------------------------------------
00128 {
00129   std::vector<string> tmp_vec1, tmp_vec2;
00130   tmp_vec1.push_back(dpeName);
00131   psToPVSSCardAddress(crate, card, tmp_vec1, direction, tmp_vec2);
00132   pvssAddress = tmp_vec2.front();
00133   return;
00134 }
00135 
00136 //---------------------------------------------------------------------------------------------------------
00137 void SCTDCSCommand::psToPVSSCardAddress(int crate, int card, std::vector<string> dpeNames,
00138                     const char* direction,
00139                     std::vector<string>& pvssAddresses)
00140 //---------------------------------------------------------------------------------------------------------
00141 {
00142   // PVSS DataPoint addresses
00143   char addresses[200];
00144   
00145   // make the crate addressese
00146   if(crate < 10)
00147     {
00148       //add 0 to make two digit number
00149       sprintf(addresses, "Crate0%d", crate);
00150     }
00151   else if(crate < 100)
00152     {
00153       sprintf(addresses, "Crate%d", crate);
00154     }
00155   else
00156     {
00157       cout<< "SCTDCSCommand::setParameter: The crate number"<<crate<<" is not correct"<<endl;
00158     }
00159 
00160   // add the rest of the addresses: card, parameter,...
00161   //first find card type
00162   string card_type;
00163   if(dpeNames.size()!=0) card_type = dpeNames[0].substr(0,2);
00164 
00165   if(card < 10)
00166     {
00167  
00168       //add 0 to make two digit number
00169       if(card_type == "LV")
00170     sprintf(addresses, "%s.LV_card0%d", addresses, card);
00171       else
00172     sprintf(addresses, "%s.HV_card0%d", addresses, card);
00173     }
00174   else if(card < 100)
00175     {
00176       if(card_type == "LV")
00177     sprintf(addresses, "%s.LV_card%d", addresses, card);
00178       else
00179     sprintf(addresses, "%s.HV_card%d", addresses, card);
00180     }
00181   else
00182     {
00183       cout<< "SCTDCSCommand::setParameter: The card number"<<card<<" is not correct"
00184       <<endl;
00185     }
00186   char addressesTmp[200];
00187   for(unsigned int i=0; i< dpeNames.size(); i++)
00188     {
00189       const char* c_dpeName = dpeNames[i].c_str();
00190       sprintf(addressesTmp, "%s.%s.%s", addresses, c_dpeName, direction);
00191       // put addresses in a string and then in a vector
00192       pvssAddresses.push_back(string(addressesTmp)); 
00193     }
00194   return;
00195 }
00196 
00197 //======================================== Methods for Crates Controllers =================================
00198 
00199 // these two  methods  convert PS coordinates to PVSS addresses (crate controller case)
00200 //---------------------------------------------------------------------------------------------------------
00201 void SCTDCSCommand::psToPVSSCrateCtrlAddress(int crate, string dpeName, const char* direction,
00202                      string& pvssAddress)
00203 //---------------------------------------------------------------------------------------------------------
00204 {
00205   std::vector<string> tmp_vec1, tmp_vec2;
00206   tmp_vec1.push_back(dpeName);
00207   psToPVSSCrateCtrlAddress(crate, tmp_vec1, direction, tmp_vec2);
00208   pvssAddress = tmp_vec2.front();
00209   return;
00210 }
00211 
00212 //---------------------------------------------------------------------------------------------------------
00213 void SCTDCSCommand::psToPVSSCrateCtrlAddress(int crate, std::vector<string> dpeNames,
00214                      const char* direction,
00215                      std::vector<string>& pvssAddresses)
00216 //---------------------------------------------------------------------------------------------------------
00217 {
00218   // PVSS DataPoint addresses 
00219   char addresses[200];
00220   
00221   // make the crate addressese
00222   if(crate < 10)
00223     {
00224       //add 0 to make two digit number
00225       sprintf(addresses, "Crate0%d.Controller", crate);
00226     }
00227   else if(crate < 100)
00228     {
00229       sprintf(addresses, "Crate%d.Controller", crate);
00230     }
00231   else
00232     {
00233       cout<< "SCTDCSCommand::setParameter: The crate number"<<crate<<" is not correct"<<endl;
00234     }
00235 
00236   char addressesTmp[200];
00237   for(unsigned int i=0; i< dpeNames.size(); i++)
00238     {
00239       const char* c_dpeName = dpeNames[i].c_str();
00240       sprintf(addressesTmp, "%s.%s.%s", addresses, c_dpeName, direction);
00241       // put addresses in a string and then in a vector
00242       pvssAddresses.push_back(string(addressesTmp)); 
00243     }
00244   return;
00245 }
00246 
00247 //======================================== Methods for Crates =========== =================================
00248 
00249 // these two  methods  convert PS coordinates to PVSS addresses (crate case)
00250 //---------------------------------------------------------------------------------------------------------
00251 void SCTDCSCommand::psToPVSSCrateAddress(int crate, string dpeName, string& pvssAddress)
00252 //---------------------------------------------------------------------------------------------------------
00253 {
00254   std::vector<string> tmp_vec1, tmp_vec2;
00255   tmp_vec1.push_back(dpeName);
00256   psToPVSSCrateAddress(crate, tmp_vec1, tmp_vec2);
00257   pvssAddress = tmp_vec2.front();
00258   return;
00259 }
00260 
00261 //---------------------------------------------------------------------------------------------------------
00262 void SCTDCSCommand::psToPVSSCrateAddress(int crate, std::vector<string> dpeNames,
00263                      std::vector<string>& pvssAddresses)
00264 //---------------------------------------------------------------------------------------------------------
00265 {
00266   // PVSS DataPoint addresses
00267   char addresses[200];
00268   
00269   // make the crate addressese
00270   if(crate < 10)
00271     {
00272       //add 0 to make two digit number
00273       sprintf(addresses, "Crate0%d", crate);
00274     }
00275   else if(crate < 100)
00276     {
00277       sprintf(addresses, "Crate%d", crate);
00278     }
00279   else
00280     {
00281       cout<< "SCTDCSCommand::setParameter: The crate number"<<crate<<" is not correct"<<endl;
00282     }
00283 
00284   char addressesTmp[200];
00285   for(unsigned int i=0; i< dpeNames.size(); i++)
00286     {
00287       const char* c_dpeName = dpeNames[i].c_str();
00288       sprintf(addressesTmp, "%s.%s", addresses, c_dpeName);
00289       // put addresses in a string and then in a vector
00290       pvssAddresses.push_back(string(addressesTmp)); 
00291     }
00292 }
00293 
00294 // read from IS DCS data. the corresponding datapoint element must be declare in the 
00295 //DDC config. file
00296 void SCTDCSCommand::readFromIS(string dpName, float& value)
00297 {
00298   m_sctDdcRequest->readFromIS(dpName, value);
00299   return;
00300 }
00301 
00302 //**********************************************************************************************************
00303 //================================================ SOME COMMANDS ===========================================
00304 //**********************************************************************************************************
00305 
00306 //request IV curve for one channel
00307 bool SCTDCSCommand::requestIVCurve(int crate, int channel, float Vstart, float Vstop, float Vstep, 
00308                    float Vend, float Iwarn, float Imax, int delay, int timeout)
00309 {
00310   char commandPara[200];
00311   sprintf(commandPara, "%d|%d|%f|%f|%f|%f|%f|%f|%d", crate, channel, Vstart, Vstop, Vstep, 
00312       Vend, Iwarn, Imax, delay);
00313   cout<< "================== commandPara = "<<commandPara<<endl;
00314 
00315   // the command Name in PVSS (data point of type DdcCommand) 
00316   string commandName = "requestIVCurve";
00317   // put commandPara in a string
00318   string commandParameters(commandPara);
00319   // send the command to only the controller name given in the command line
00320   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00321                         commandParameters, timeout);  
00322 }
00323 //request IV curve for all channel
00324 bool SCTDCSCommand::requestIVCurveAll(int crate, float Vstart, float Vstop, float Vstep, 
00325                       float Vend, float Iwarn, float Imax, int delay, int timeout)
00326 {
00327   char commandPara[200];
00328   const char* channel = "ALL";
00329   sprintf(commandPara, "%d|%s|%f|%f|%f|%f|%f|%f|%d", crate, channel, Vstart, Vstop, Vstep, 
00330       Vend, Iwarn, Imax, delay);
00331   
00332   // the command Name in PVSS (data point of type DdcCommand) 
00333   string commandName = "requestIVCurve";
00334   // put commandPara in a string
00335   string commandParameters(commandPara);
00336   // send the command to only the controller name given in the command line
00337   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00338                         commandParameters, timeout); 
00339 }
00340 //change the select line for all the channels in a given crate
00341 //---------------------------------------------------------------------------------------------------------
00342 int SCTDCSCommand::setChannelsSelectLine(int crate, int selectLine, int timeout)
00343 //---------------------------------------------------------------------------------------------------------
00344 {
00345   // Revised PWP 19.07.2004 - use "official" datapoint names
00346 
00347   //command parameters 
00348   char commandPara[200];
00349   sprintf(commandPara, "%d|all|%d", crate, selectLine);
00350   
00351   // the command Name in PVSS (data point of type DdcCommand) 
00352   string commandName = "ChangeClock";
00353   // put commandPara in a string
00354   string commandParameters(commandPara);
00355   // send the command to only the controller name given in the command line
00356   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00357                         commandParameters, timeout);
00358 }
00359 
00360 //transition state command for a given channel in a given crate
00361 //---------------------------------------------------------------------------------------------------------
00362 int SCTDCSCommand::changeState(int crate, int channel, int state, int timeout)
00363 //---------------------------------------------------------------------------------------------------------
00364 {
00365   //command parameters 
00366   char commandPara[200];
00367   sprintf(commandPara, "%d|%d|%d", crate, channel, state);
00368   
00369   // the command Name in PVSS (data point of type DdcCommand) 
00370   string commandName = "changeState";
00371   // put commandPara in a string
00372   string commandParameters(commandPara);
00373   // send the command to only the controller name given in the command line
00374   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00375                         commandParameters, timeout);
00376 }
00377 //transition state command for all channels in a given crate
00378 //---------------------------------------------------------------------------------------------------------
00379 int SCTDCSCommand::changeState(int crate, const char* allChannels, int state, int timeout)
00380 //---------------------------------------------------------------------------------------------------------
00381 {
00382   //command parameters 
00383   char commandPara[200];
00384   sprintf(commandPara, "%d|%s|%d", crate, allChannels, state);
00385   
00386   // the command Name in PVSS (data point of type DdcCommand) 
00387   string commandName = "changeState";
00388   // put commandPara in a string
00389   string commandParameters(commandPara);
00390   // send the command to only the controller name given in the command line
00391   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00392                         commandParameters, timeout);
00393 }
00394 
00395 //load configuration constants for all channels in a given crate
00396 //---------------------------------------------------------------------------------------------------------
00397 int SCTDCSCommand::loadConfiguration(int crate, int state, int timeout)
00398 //---------------------------------------------------------------------------------------------------------
00399 {
00400   //command parameters 
00401   char commandPara[200];
00402   sprintf(commandPara, "%d|%d", crate, state);
00403   
00404   // the command Name in PVSS (data point of type DdcCommand) 
00405   string commandName = "loadConfiguration";
00406   // put commandPara in a string
00407   string commandParameters(commandPara);
00408   // send the command to only the controller name given in the command line
00409   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00410                         commandParameters, timeout);
00411 }
00412 
00413 // reset a module (corresponding to one channel in one crate)
00414 //---------------------------------------------------------------------------------------------------------
00415 int SCTDCSCommand::hardReset(int crate, int channel, int timeout)
00416 //---------------------------------------------------------------------------------------------------------
00417 {
00418   //command parameters 
00419   char commandPara[200];
00420   sprintf(commandPara, "%d|%d|%d", crate, channel,timeout);
00421   
00422   // the command Name in PVSS (data point of type DdcCommand) 
00423   string commandName = "HardReset";
00424   // put commandPara in a string
00425   string commandParameters(commandPara);
00426   // send the command to only the controller name given in the command line
00427   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00428                         commandParameters, timeout);
00429 }
00430 
00431 // reset all the modules (48) (all the channels in a given crate)
00432 //---------------------------------------------------------------------------------------------------------
00433 int SCTDCSCommand::hardReset(int crate, const char* allChannels, int timeout)
00434 //---------------------------------------------------------------------------------------------------------
00435 {
00436   //command parameters 
00437   char commandPara[200];
00438   sprintf(commandPara, "%d|%s|%d", crate, allChannels, timeout);
00439   
00440   // the command Name in PVSS (data point of type DdcCommand) 
00441   string commandName = "HardReset";
00442   // put commandPara in a string
00443   string commandParameters(commandPara);
00444   // send the command to only the controller name given in the command line
00445   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00446                         commandParameters, timeout);
00447 }
00448 
00449 //**********************************************************************************************************
00450 //========================================= ACCESS CONTROL METHODS =========================================
00451 //**********************************************************************************************************
00452 
00453 // this is to get the control of the DCS (Arbitration procedure! realized with B. Serguey).
00454 //---------------------------------------------------------------------------------------------------------
00455 bool SCTDCSCommand::openDCSControl(string subSystem, int timeout)
00456 //---------------------------------------------------------------------------------------------------------
00457 {
00458   // PVSS DataPoint address
00459   char commandPara[200];
00460   
00461   //name of the subsystem (eg SCTdcs01, SCTdcs02...)
00462   const char* csubSystem = subSystem.c_str();
00463 
00464   //some help variables
00465   int priority = 1;
00466   int priorityResponse = -99999;
00467   int commandResponse  = -99999;
00468   int counter = 0;
00469 
00470   //time when the access trial start
00471   time_t startAccessTime = time(&startAccessTime);
00472   //how many time the access lasts (waits)
00473   int deltaAccessTime = 0;
00474   time_t timenow = 0;
00475 
00476   //loop managing the access request and the waiting time
00477   while(priorityResponse!=priority && deltaAccessTime<timeout*10)
00478     {
00479       //counter of attemp to get DCS access
00480       counter++;
00481       // first: check the value of Hold in arbitration mechanism
00482       sprintf(commandPara, "%s:RequArbi.Hold|%d", csubSystem, 0);
00483 
00484       // this is the command name in PVSS (look at sys:DdcCommand)
00485       string commandName = "TakeStat";
00486       string commandParameters1(commandPara);
00487 
00488       time_t startHoldTime = time(&startHoldTime);
00489       int deltaHoldTime = 0;
00490 
00491       while(deltaHoldTime<timeout)
00492     {
00493       // send the command to only the controller name given in the command line
00494       commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00495                                    commandParameters1, 
00496                                    timeout);
00497       if(commandResponse == 0) break;
00498       //counting time for getting Hold access
00499       timenow = time(&timenow);
00500       deltaHoldTime = timenow - startHoldTime;
00501     }
00502       
00503       if(deltaHoldTime >= timeout) 
00504     {
00505       cout << "\nWARNING: attempt number: "<< counter << endl;
00506       cout << "WARNING: TimeOut to get Hold -> 0 is out, next attempt will be made\n"
00507            <<endl; 
00508     } 
00509       else
00510     {
00511       // second: set Hold equal to 1   
00512       int value = 1;
00513       commandResponse  = -99999;
00514       sprintf(commandPara, "%s:RequArbi.Hold|%d", csubSystem, value);
00515       
00516       commandName = "SendStat";
00517       string commandParameters2(commandPara);
00518       
00519       commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00520                                    commandParameters2, timeout);
00521       
00522       if(commandResponse != value)
00523         {
00524           cerr <<"DDC ERROR: got Hold value is not equal to sent one: " << 
00525         commandResponse<<endl;
00526           return false;
00527         }
00528       
00529       // third: send priority request No 1
00530       sprintf(commandPara, "%s:RequArbi.Req1|%d", csubSystem, priority);
00531       
00532       commandName = "SendRequ";
00533       string commandParameters3(commandPara);
00534       
00535       priorityResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00536                                 commandParameters3, timeout);
00537       
00538       if(priorityResponse != priority)
00539         {
00540           cout<<" \nWARNING: low priority, a next attemp will be made\n"<<endl;
00541         }
00542       else
00543         {
00544           return true;
00545         }
00546     } //end of else and if(deltaHold...)
00547       
00548       //counting time for DCS control access
00549       timenow = time(&timenow);
00550       deltaAccessTime = timenow - startAccessTime;
00551     }// end of while(priorityResponse!=priority ...)
00552   
00553   
00554   return false;
00555 }
00556 
00557 // this method is to set a stat varibale (one can use also setParameter(...), see below!
00558 //---------------------------------------------------------------------------------------------------------
00559 bool SCTDCSCommand::setDPStatus(string dpName, int state, int timeout)
00560 //---------------------------------------------------------------------------------------------------------
00561 {
00562   // PVSS DataPoint address
00563   char commandPara[200];
00564   int commandResponse  = -99999;
00565 
00566   const char* cdpName = dpName.c_str();
00567   sprintf(commandPara, "%s|%d", cdpName, state);
00568   
00569   // this is the command name in PVSS (look at sys:DdcCommand)
00570   string commandName = "SendStat";
00571   string commandParameters(commandPara);
00572   
00573   // send the command to only the controller name given in the command line
00574   commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00575                                commandParameters, timeout);
00576   
00577   if(commandResponse != state)
00578     {
00579       cerr <<"DDC ERROR: got Stat value is not equal to sent one: " << commandResponse<<endl;
00580       return false;
00581     }
00582   
00583   return true;
00584 }
00585 
00586 // this is a generic method, it set any parameter in the power supply PVSS project
00587 //---------------------------------------------------------------------------------------------------------
00588 int SCTDCSCommand::setParameter(int crate, int channel, string para, float value, 
00589                 int timeout)
00590 //---------------------------------------------------------------------------------------------------------
00591 {
00592   // PVSS DataPoint address and parameter value
00593   char commandPara[200];
00594   
00595   // make the crate addresse
00596   if(crate < 10)
00597     {
00598       //add 0 to make two digit number
00599       sprintf(commandPara, "Crate0%d", crate);
00600     }
00601   else if(crate < 100)
00602     {
00603       sprintf(commandPara, "Crate%d", crate);
00604     }
00605   else
00606     {
00607       cout<< "SCTDCSCommand::setParameter: The crate number"<<crate<<" is not correct"<<endl;
00608     }
00609 
00610   // add the rest of the address: channel, parameter,... and add the value
00611   const char* c_para = para.c_str();
00612   if(channel < 10)
00613     {
00614       //add 0 to make two digit number
00615       sprintf(commandPara, "%s.Channel0%d.%s.Send|%f", commandPara, channel, c_para, value);
00616     }
00617   else if(channel < 100)
00618     {
00619       sprintf(commandPara, "%s.Channel%d.%s.Send|%f", commandPara, channel, c_para, value);
00620     }
00621   else
00622     {
00623       cout<< "SCTDCSCommand::setParameter: The channel number"<<channel<<" is not correct"
00624       <<endl;
00625     }
00626 
00627   // the command Name in PVSS (data point of type DdcCommand) 
00628   string commandName = "setParameter";
00629   // put commandPara in a string
00630   string commandParameters(commandPara);
00631 
00632   // send the command to only the controller name given in the command line
00633   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00634                         commandParameters, timeout);
00635 }
00636 
00637 //**********************************************************************************************************
00638 //================================================ SET METHODS =============================================
00639 //**********************************************************************************************************
00640 
00641 //========================================== Set methods for Channels =======================================
00642 
00643 //set one parameter in a channel
00644 //---------------------------------------------------------------------------------------------------------
00645 int SCTDCSCommand::setChannelParameter(int crate, int channel, string dpeName, 
00646                       float dpeValue, int timeout)
00647 //---------------------------------------------------------------------------------------------------------
00648 {
00649   //convrtion from PS coordiante to PVSS cordinates
00650   string pvssAddress;
00651   psToPVSSChannelAddress(crate, channel, dpeName, "Send", pvssAddress);
00652   const char* c_pvssAddress = pvssAddress.c_str();
00653   //add the value to the address string
00654   char commandPara[200];
00655   sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00656   
00657   // the command Name in PVSS (data point of type DdcCommand) 
00658   string commandName = "setParameters";
00659   // put commandPara in a string
00660   string commandParameters(commandPara);
00661   // send the command to only the controller name given in the command line
00662   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00663                         commandParameters, timeout);
00664 }
00665 
00666 //set several parameter in a channel
00667 //---------------------------------------------------------------------------------------------------------
00668 int SCTDCSCommand::setChannelParameters(int crate, int channel, 
00669                     std::map<string, float> dpeNamesAndValues, int timeout)
00670 //---------------------------------------------------------------------------------------------------------
00671 {
00672   //convrtion from PS coordiante to PVSS cordinates
00673   std::vector<string> pvssAddresses;
00674   std::vector<string> dpeNames;
00675   map<string, float>::const_iterator map_itr;
00676   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00677     {
00678       dpeNames.push_back(map_itr->first);
00679     }
00680   psToPVSSChannelAddress(crate, channel, dpeNames, "Send", pvssAddresses);
00681   
00682   //add the value to the address string
00683   char commandPara[8000];
00684   const char* c_pvssAddress;
00685   float dpeValue;
00686   int item = 0;
00687   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00688     {
00689       c_pvssAddress = pvssAddresses[item].c_str();
00690       dpeValue = map_itr->second;
00691       
00692       if(item == 0) 
00693     sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00694       else
00695     sprintf(commandPara, "%s|%s|%f",commandPara, c_pvssAddress, dpeValue);
00696       
00697       item++;
00698     }
00699   // the command Name in PVSS (data point of type DdcCommand) 
00700   string commandName = "setParameters";
00701   // put commandPara in a string
00702   string commandParameters(commandPara);
00703   
00704   // send the command to only the controller name given in the command line
00705   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00706                         commandParameters, timeout);
00707 }
00708 
00709 //========================================== Set methods for Cards =======================================
00710 
00711 //set one parameter in a card
00712 //---------------------------------------------------------------------------------------------------------
00713 int SCTDCSCommand::setCardParameter(int crate, int card, string dpeName, 
00714                     float dpeValue, int timeout)
00715 //---------------------------------------------------------------------------------------------------------
00716 {
00717   //convrtion from PS coordiante to PVSS cordinates
00718   string pvssAddress;
00719   psToPVSSCardAddress(crate, card, dpeName, "Send", pvssAddress);
00720   const char* c_pvssAddress = pvssAddress.c_str();
00721   //add the value to the address string
00722   char commandPara[200];
00723   sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00724   
00725   // the command Name in PVSS (data point of type DdcCommand) 
00726   string commandName = "setParameters";
00727   // put commandPara in a string
00728   string commandParameters(commandPara);
00729   // send the command to only the controller name given in the command line
00730   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00731                         commandParameters, timeout);
00732 }
00733 
00734 //set several parameter in a card
00735 //---------------------------------------------------------------------------------------------------------
00736 int SCTDCSCommand::setCardParameters(int crate, int card, 
00737                      std::map<string, float> dpeNamesAndValues, int timeout)
00738 //---------------------------------------------------------------------------------------------------------
00739 {
00740   //convrtion from PS coordiante to PVSS cordinates
00741   std::vector<string> pvssAddresses;
00742   std::vector<string> dpeNames;
00743   map<string, float>::const_iterator map_itr;
00744   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00745     {
00746       dpeNames.push_back(map_itr->first);
00747     }
00748   psToPVSSCardAddress(crate, card, dpeNames, "Send", pvssAddresses);
00749   
00750   //add the value to the address string
00751   char commandPara[8000];
00752   const char* c_pvssAddress;
00753   float dpeValue;
00754   int item = 0;
00755   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00756     {
00757       c_pvssAddress = pvssAddresses[item].c_str();
00758       dpeValue = map_itr->second;
00759       
00760       if(item == 0) 
00761     sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00762       else
00763     sprintf(commandPara, "%s|%s|%f",commandPara, c_pvssAddress, dpeValue);
00764       
00765       item++;
00766     }
00767 
00768   // the command Name in PVSS (data point of type DdcCommand) 
00769   string commandName = "setParameters";
00770   // put commandPara in a string
00771   string commandParameters(commandPara);
00772   
00773   // send the command to only the controller name given in the command line
00774   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00775                         commandParameters, timeout);
00776 }
00777 
00778 //======================================= Set methods for Crates Controllers =====================================
00779 
00780 //set one parameter in a crate
00781 //---------------------------------------------------------------------------------------------------------
00782 int SCTDCSCommand::setCrateCtrlParameter(int crate, string dpeName, float dpeValue, int timeout)
00783 //---------------------------------------------------------------------------------------------------------
00784 {
00785   //convrtion from PS coordiante to PVSS cordinates
00786   string pvssAddress;
00787   psToPVSSCrateCtrlAddress(crate, dpeName, "Send", pvssAddress);
00788   const char* c_pvssAddress = pvssAddress.c_str();
00789   //add the value to the address string
00790   char commandPara[200];
00791   sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00792   
00793   // the command Name in PVSS (data point of type DdcCommand) 
00794   string commandName = "setParameters";
00795   // put commandPara in a string
00796   string commandParameters(commandPara);
00797   // send the command to only the controller name given in the command line
00798   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00799                         commandParameters, timeout);
00800 }
00801 
00802 //set several parameter in a crate
00803 //---------------------------------------------------------------------------------------------------------
00804 int SCTDCSCommand::setCrateCtrlParameters(int crate, std::map<string, float> dpeNamesAndValues, 
00805                       int timeout)
00806 //---------------------------------------------------------------------------------------------------------
00807 {
00808   //convrtion from PS coordiante to PVSS cordinates
00809   std::vector<string> pvssAddresses;
00810   std::vector<string> dpeNames;
00811   map<string, float>::const_iterator map_itr;
00812   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00813     {
00814       dpeNames.push_back(map_itr->first);
00815     }
00816   psToPVSSCrateCtrlAddress(crate, dpeNames, "Send", pvssAddresses);
00817   
00818   //add the value to the address string
00819   char commandPara[8000];
00820   const char* c_pvssAddress;
00821   float dpeValue;
00822   int item = 0;
00823   for(map_itr=dpeNamesAndValues.begin(); map_itr!=dpeNamesAndValues.end(); map_itr++)
00824     {
00825       c_pvssAddress = pvssAddresses[item].c_str();
00826       dpeValue = map_itr->second;
00827       
00828       if(item == 0) 
00829     sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00830       else
00831     sprintf(commandPara, "%s|%s|%f",commandPara, c_pvssAddress, dpeValue);
00832       
00833       item++;
00834     }
00835 
00836   // the command Name in PVSS (data point of type DdcCommand) 
00837   string commandName = "setParameters";
00838   // put commandPara in a string
00839   string commandParameters(commandPara);
00840   
00841   // send the command to only the controller name given in the command line
00842   return  m_sctDdcCommandSender->ddcSendCommand(commandName, 
00843                         commandParameters, timeout);
00844 }
00845 
00846 
00847 //---------------------------------------------------------------------------------------------------------
00848 bool SCTDCSCommand::closeDCSControl(string subSystem, int timeout)
00849 //---------------------------------------------------------------------------------------------------------
00850 {
00851   // PVSS DataPoint address
00852   char commandPara[200];
00853 
00854   int value = 0;
00855   int commandResponse  = -99999;
00856 
00857   const char* csubSystem = subSystem.c_str();
00858   sprintf(commandPara, "%s:SendStat.Req1|%d", csubSystem, value);
00859   
00860   //this is the command name in PVSS (look at sys:DdcCommand)
00861   string commandName = "SendStat";
00862   string commandParameters1(commandPara);
00863   
00864   // send the command to only the controller name given in the command line
00865   commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00866                                commandParameters1, timeout);
00867   
00868   if(commandResponse != value)
00869     {
00870       cerr<<"DDC ERROR: got Req1 value is not equal to sent one: " << commandResponse<<endl;
00871       return false;
00872     }
00873   
00874   // second: set Hold equal to 0  
00875   value = 0;
00876   sprintf(commandPara, "%s:RequArbi.Hold|%d", csubSystem, value);
00877   
00878   //string commandName = "setParameter";
00879   commandName = "SendStat";
00880   string commandParameters2(commandPara);
00881   
00882   // send the command to only the controller name given in the command line
00883   commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName, 
00884                                commandParameters2, timeout);
00885   
00886   if(commandResponse != value)
00887     {
00888       cerr<<"DDC ERROR: got Hold value is not equal to sent one: " << commandResponse<<endl;
00889       return false;
00890     }
00891 
00892   return true;
00893 }
00894 
00895 
00896 //**********************************************************************************************************
00897 //================================================ GET METHODS =============================================
00898 //**********************************************************************************************************
00899 
00900 //=========================================== Get Methods for Channels ========================================
00901 
00902 //this method reads an int channel variables from DCS (this is an overloading for the previous ones)
00903 //---------------------------------------------------------------------------------------------------------
00904 void SCTDCSCommand::getChannelParameter(int crate, int channel, string dpeName, 
00905                     int& dpeValue, int timeout,
00906                     const char* direction)
00907 //---------------------------------------------------------------------------------------------------------
00908 {
00909   string pvssAddress;
00910   psToPVSSChannelAddress(crate, channel, dpeName, direction, pvssAddress);
00911   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00912   return;
00913 }
00914 //this method reads a float channel variables from DCS (this is an overloading for the previous ones)
00915 //---------------------------------------------------------------------------------------------------------
00916 void SCTDCSCommand::getChannelParameter(int crate, int channel, string dpeName, 
00917                     float& dpeValue, int timeout,
00918                     const char* direction)
00919 //---------------------------------------------------------------------------------------------------------
00920 {
00921   string pvssAddress;
00922   psToPVSSChannelAddress(crate, channel, dpeName, direction, pvssAddress);
00923   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00924 
00925   // Scale HV current to microA (PWP 19.07.2004)
00926   if(dpeName == "HVchCurr"){
00927     dpeValue = dpeValue/1000;
00928   }
00929   return;
00930 }
00931 //this method reads a string channel variables from DCS (this is an overloading for the previous ones)
00932 //---------------------------------------------------------------------------------------------------------
00933 void SCTDCSCommand::getChannelParameter(int crate, int channel, string dpeName, 
00934                     string& dpeValue, int timeout,
00935                     const char* direction)
00936 //---------------------------------------------------------------------------------------------------------
00937 {
00938   string pvssAddress;
00939   psToPVSSChannelAddress(crate, channel, dpeName, direction, pvssAddress);
00940   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00941   return;
00942 }
00943 //this method reads several (float) channel variables from DCS (this is an overloading for the previous ones)
00944 //---------------------------------------------------------------------------------------------------------
00945 void SCTDCSCommand::getChannelParameters(int crate, int channel, std::vector<string> dpeNames, 
00946                 std::map<string, float>& dpeValues, int timeout,
00947                      const char* direction)
00948 //---------------------------------------------------------------------------------------------------------
00949 {
00950   std::vector<string> pvssAddresses;
00951   psToPVSSChannelAddress(crate, channel, dpeNames, direction, pvssAddresses);
00952   m_sctDdcRequest->ddcSendRequest(pvssAddresses, dpeValues, timeout);
00953   return;
00954 }
00955 
00956 //=========================================== Get Methods for Cards ========================================
00957 
00958 //this method reads an int card variables from DCS (this is an overloading for the previous ones)
00959 //---------------------------------------------------------------------------------------------------------
00960 void SCTDCSCommand::getCardParameter(int crate, int card, string dpeName, 
00961                      int& dpeValue, int timeout,
00962                      const char* direction)
00963 //---------------------------------------------------------------------------------------------------------
00964 {
00965   string pvssAddress;
00966   psToPVSSCardAddress(crate, card, dpeName, direction, pvssAddress);
00967   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00968   return;
00969 }
00970 //this method reads a float card variables from DCS (this is an overloading for the previous ones)
00971 //---------------------------------------------------------------------------------------------------------
00972 void SCTDCSCommand::getCardParameter(int crate, int card, string dpeName, 
00973                      float& dpeValue, int timeout,
00974                      const char* direction)
00975 //---------------------------------------------------------------------------------------------------------
00976 {
00977   string pvssAddress;
00978   psToPVSSCardAddress(crate, card, dpeName, direction, pvssAddress);
00979   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00980   return;
00981 }
00982 //this method reads a string card variables from DCS (this is an overloading for the previous ones)
00983 //---------------------------------------------------------------------------------------------------------
00984 void SCTDCSCommand::getCardParameter(int crate, int card, string dpeName, 
00985                      string& dpeValue, int timeout,
00986                     const char* direction)
00987 //---------------------------------------------------------------------------------------------------------
00988 {
00989   string pvssAddress;
00990   psToPVSSCardAddress(crate, card, dpeName, direction, pvssAddress);
00991   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
00992   return;
00993 }
00994 //this method reads several (float) card variables from DCS (this is an overloading for the previous ones)
00995 //---------------------------------------------------------------------------------------------------------
00996 void SCTDCSCommand::getCardParameters(int crate, int card, std::vector<string> dpeNames, 
00997                 std::map<string, float>& dpeValues, int timeout,
00998                     const char* direction)
00999 //---------------------------------------------------------------------------------------------------------
01000 {
01001   std::vector<string> pvssAddresses;
01002   psToPVSSCardAddress(crate, card, dpeNames, direction, pvssAddresses);
01003   m_sctDdcRequest->ddcSendRequest(pvssAddresses, dpeValues, timeout);
01004   return;
01005 }
01006 
01007 //================================== Get Methods for Crates Controllers  ==================================
01008 
01009 //this method reads an int card variables from DCS (this is an overloading for the previous ones)
01010 //---------------------------------------------------------------------------------------------------------
01011 void SCTDCSCommand::getCrateCtrlParameter(int crate, string dpeName, int& dpeValue, int timeout,
01012                       const char* direction)
01013 //---------------------------------------------------------------------------------------------------------
01014 {
01015   string pvssAddress;
01016   psToPVSSCrateCtrlAddress(crate, dpeName, direction, pvssAddress);
01017   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01018   return;
01019 }
01020 //this method reads a float card variables from DCS (this is an overloading for the previous ones)
01021 //---------------------------------------------------------------------------------------------------------
01022 void SCTDCSCommand::getCrateCtrlParameter(int crate, string dpeName, float& dpeValue, int timeout,
01023                       const char* direction)
01024 //---------------------------------------------------------------------------------------------------------
01025 {
01026   string pvssAddress;
01027   psToPVSSCrateCtrlAddress(crate, dpeName, direction, pvssAddress);
01028   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01029   return;
01030 }
01031 //this method reads a string card variables from DCS (this is an overloading for the previous ones)
01032 //---------------------------------------------------------------------------------------------------------
01033 void SCTDCSCommand::getCrateCtrlParameter(int crate, string dpeName, string& dpeValue, int timeout,
01034                       const char* direction)
01035 //---------------------------------------------------------------------------------------------------------
01036 {
01037   string pvssAddress;
01038   psToPVSSCrateCtrlAddress(crate, dpeName, direction, pvssAddress);
01039   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01040   return;
01041 }
01042 //this method reads several (float) crate variables from DCS (this is an overloading for the previous ones)
01043 //---------------------------------------------------------------------------------------------------------
01044 void SCTDCSCommand::getCrateCtrlParameters(int crate, std::vector<string> dpeNames, 
01045                 std::map<string, float>& dpeValues, int timeout,
01046                        const char* direction)
01047 //---------------------------------------------------------------------------------------------------------
01048 {
01049   std::vector<string> pvssAddresses;
01050   psToPVSSCrateCtrlAddress(crate, dpeNames, direction, pvssAddresses);
01051   m_sctDdcRequest->ddcSendRequest(pvssAddresses, dpeValues, timeout);
01052   return;
01053 }
01054 
01055 //=========================================== Get Methods for Crates ========================================
01056 
01057 //this method reads an int card variables from DCS (this is an overloading for the previous ones)
01058 //---------------------------------------------------------------------------------------------------------
01059 void SCTDCSCommand::getCrateParameter(int crate, string dpeName, int& dpeValue, int timeout)
01060 //---------------------------------------------------------------------------------------------------------
01061 {
01062   string pvssAddress;
01063   psToPVSSCrateAddress(crate, dpeName, pvssAddress);
01064   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01065   return;
01066 }
01067 //this method reads a float card variables from DCS (this is an overloading for the previous ones)
01068 //---------------------------------------------------------------------------------------------------------
01069 void SCTDCSCommand::getCrateParameter(int crate, string dpeName, float& dpeValue, int timeout)
01070 //---------------------------------------------------------------------------------------------------------
01071 {
01072   string pvssAddress;
01073   psToPVSSCrateAddress(crate, dpeName, pvssAddress);
01074   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01075   return;
01076 }
01077 //this method reads a string card variables from DCS (this is an overloading for the previous ones)
01078 //---------------------------------------------------------------------------------------------------------
01079 void SCTDCSCommand::getCrateParameter(int crate, string dpeName, string& dpeValue, int timeout)
01080 //---------------------------------------------------------------------------------------------------------
01081 {
01082   string pvssAddress;
01083   psToPVSSCrateAddress(crate, dpeName, pvssAddress);
01084   m_sctDdcRequest->ddcSendRequest(pvssAddress, dpeValue, timeout);
01085   return;
01086 }
01087 //this method reads several (float) crate variables from DCS (this is an overloading for the previous ones)
01088 //---------------------------------------------------------------------------------------------------------
01089 void SCTDCSCommand::getCrateParameters(int crate, std::vector<string> dpeNames, 
01090                 std::map<string, float>& dpeValues, int timeout)
01091 //---------------------------------------------------------------------------------------------------------
01092 {
01093   std::vector<string> pvssAddresses;
01094   psToPVSSCrateAddress(crate, dpeNames, pvssAddresses);
01095   m_sctDdcRequest->ddcSendRequest(pvssAddresses, dpeValues, timeout);
01096   return;
01097 }
01098 
01099 //====================================== Get Methods for IV Curve Data  ===================================
01100 
01101 //this method reads an array of float (PVSS dyn_float) from DCS 
01102 //---------------------------------------------------------------------------------------------------------
01103 void SCTDCSCommand::getIVCurveData(float* float_array, int& array_size, int timeout)
01104 //---------------------------------------------------------------------------------------------------------
01105 {
01106   string pvssAddress("dyn_array_test.float_array");
01107   //psToPVSSCrateAddress(crate, dpeName, pvssAddress);
01108   m_sctDdcRequest->ddcSendRequest(pvssAddress, float_array, array_size, timeout);
01109   return;
01110 }
01111 
01112 void SCTDCSCommand::run(string** controllers)
01113 {
01114   cout << endl;
01115   cout << "#############   Simulation   ##############" << endl;
01116   cout << "#######       of DAQ sending        #######" << endl;
01117   cout << "##    non-transition commands for DCS    ##" << endl;
01118   cout << "###########################################" << endl;
01119   
01120   string           commandName;
01121   string           commParameters;
01122   char         timeBuf[16];
01123   unsigned int   timeout = 0;
01124   
01125   
01126   while(true) 
01127     {
01128       // Input the command name
01129       cout << endl << "Type the name of a command to be issued: ";
01130       cin >>  commandName;
01131       if(commandName == EXIT_COMMAND)
01132     return;
01133       
01134       // Input the command parameters
01135       cout << "Has the " << commandName << " any parameters (y/n)? ";
01136       cin >> commParameters;
01137       if((commParameters[0] == 'y') || (commParameters[0] == 'Y')) 
01138     {
01139       cout << "Type the command parameters (p1|p2|...): ";
01140       cin >>  commParameters;
01141     }
01142       else
01143     commParameters = "";
01144       
01145       // Input the timeout value
01146       cout << "Type the timeout value (sec): ";
01147       cin >>  timeBuf;
01148       timeout = atoi(timeBuf);
01149       
01150       // Input the controller(s) name to be addressed to
01151       string    ctrlName;
01152       string    ctrlPrompt = "*|" + *controllers[0];
01153       int i = 1;
01154       while(controllers[i] != 0) 
01155     {
01156       ctrlPrompt = ctrlPrompt + '|' + *controllers[i];
01157       i++;
01158     }
01159       cout << "Type the controller name to be addressed to" << endl;
01160       cout << "(" << ctrlPrompt << "): ";
01161       cin >> ctrlName;
01162       
01163       // Send the command
01164        m_sctDdcCommandSender->ddcSendCommand(ctrlName, commandName, commParameters, timeout); 
01165      
01166     } //end while(true)
01167 }
01168 

Generated on Mon Feb 6 14:01:29 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6