Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

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

Generated on Fri Sep 16 18:01:58 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5