00001
00002
00003
00004
00005
00006
00008
00009 #include <iostream>
00010 #include <string>
00011 #include <vector>
00012 #include <time.h>
00013
00014
00015
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
00025 #include "sctddc/SCTDdcCommandSender.hxx"
00026 #include "sctddc/SCTDdcRequest.hxx"
00027 #include "sctddc/SCTDCSCommand.hxx"
00028
00029
00030 SCTDCSCommand::SCTDCSCommand(IPCPartition& partition, string** ctrlList)
00031 {
00032
00033 m_sctDdcCommandSender = new SCTDdcCommandSender(partition, ctrlList);
00034
00035
00036 string is_server("RunCtrl");
00037 m_sctDdcRequest = new SCTDdcRequest(partition, is_server);
00038 }
00039 SCTDCSCommand::~SCTDCSCommand()
00040 {
00041
00042 delete m_sctDdcCommandSender;
00043 delete m_sctDdcRequest;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
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
00072 char addresses[200];
00073
00074
00075 if(crate < 10)
00076 {
00077
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
00090 if(channel < 10)
00091 {
00092
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
00111 pvssAddresses.push_back(string(addressesTmp));
00112 }
00113 return;
00114 }
00115
00116
00117
00118
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
00138 char addresses[200];
00139
00140
00141 if(crate < 10)
00142 {
00143
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
00156
00157 string card_type;
00158 if(dpeNames.size()!=0) card_type = dpeNames[0].substr(0,2);
00159
00160 if(card < 10)
00161 {
00162
00163
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
00187 pvssAddresses.push_back(string(addressesTmp));
00188 }
00189 return;
00190 }
00191
00192
00193
00194
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
00214 char addresses[200];
00215
00216
00217 if(crate < 10)
00218 {
00219
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
00237 pvssAddresses.push_back(string(addressesTmp));
00238 }
00239 return;
00240 }
00241
00242
00243
00244
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
00262 char addresses[200];
00263
00264
00265 if(crate < 10)
00266 {
00267
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
00285 pvssAddresses.push_back(string(addressesTmp));
00286 }
00287 }
00288
00289
00290
00291 void SCTDCSCommand::readFromIS(string dpName, float& value)
00292 {
00293 m_sctDdcRequest->readFromIS(dpName, value);
00294 return;
00295 }
00296
00297
00298
00299
00300
00301
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
00311 string commandName = "requestIVCurve";
00312
00313 string commandParameters(commandPara);
00314
00315 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00316 commandParameters, timeout);
00317 }
00318
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
00328 string commandName = "requestIVCurve";
00329
00330 string commandParameters(commandPara);
00331
00332 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00333 commandParameters, timeout);
00334 }
00335
00336
00337 int SCTDCSCommand::setChannelsSelectLine(int crate, int selectLine, int timeout)
00338
00339 {
00340
00341
00342
00343 char commandPara[200];
00344 sprintf(commandPara, "%d|all|%d", crate, selectLine);
00345
00346
00347 string commandName = "ChangeClock";
00348
00349 string commandParameters(commandPara);
00350
00351 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00352 commandParameters, timeout);
00353 }
00354
00355
00356
00357 int SCTDCSCommand::changeState(int crate, int channel, int state, int timeout)
00358
00359 {
00360
00361 char commandPara[200];
00362 sprintf(commandPara, "%d|%d|%d", crate, channel, state);
00363
00364
00365 string commandName = "changeState";
00366
00367 string commandParameters(commandPara);
00368
00369 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00370 commandParameters, timeout);
00371 }
00372
00373
00374 int SCTDCSCommand::changeState(int crate, const char* allChannels, int state, int timeout)
00375
00376 {
00377
00378 char commandPara[200];
00379 sprintf(commandPara, "%d|%s|%d", crate, allChannels, state);
00380
00381
00382 string commandName = "changeState";
00383
00384 string commandParameters(commandPara);
00385
00386 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00387 commandParameters, timeout);
00388 }
00389
00390
00391
00392 int SCTDCSCommand::loadConfiguration(int crate, int state, int timeout)
00393
00394 {
00395
00396 char commandPara[200];
00397 sprintf(commandPara, "%d|%d", crate, state);
00398
00399
00400 string commandName = "loadConfiguration";
00401
00402 string commandParameters(commandPara);
00403
00404 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00405 commandParameters, timeout);
00406 }
00407
00408
00409
00410 int SCTDCSCommand::hardReset(int crate, int channel, int timeout)
00411
00412 {
00413
00414 char commandPara[200];
00415 sprintf(commandPara, "%d|%d|%d", crate, channel,timeout);
00416
00417
00418 string commandName = "HardReset";
00419
00420 string commandParameters(commandPara);
00421
00422 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00423 commandParameters, timeout);
00424 }
00425
00426
00427
00428 int SCTDCSCommand::hardReset(int crate, const char* allChannels, int timeout)
00429
00430 {
00431
00432 char commandPara[200];
00433 sprintf(commandPara, "%d|%s|%d", crate, allChannels, timeout);
00434
00435
00436 string commandName = "HardReset";
00437
00438 string commandParameters(commandPara);
00439
00440 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00441 commandParameters, timeout);
00442 }
00443
00444
00445
00446
00447
00448
00449
00450 bool SCTDCSCommand::openDCSControl(string subSystem, int timeout)
00451
00452 {
00453
00454 char commandPara[200];
00455
00456
00457 const char* csubSystem = subSystem.c_str();
00458
00459
00460 int priority = 1;
00461 int priorityResponse = -99999;
00462 int commandResponse = -99999;
00463 int counter = 0;
00464
00465
00466 time_t startAccessTime = time(&startAccessTime);
00467
00468 int deltaAccessTime = 0;
00469 time_t timenow = 0;
00470
00471
00472 while(priorityResponse!=priority && deltaAccessTime<timeout*10)
00473 {
00474
00475 counter++;
00476
00477 sprintf(commandPara, "%s:RequArbi.Hold|%d", csubSystem, 0);
00478
00479
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
00489 commandResponse = m_sctDdcCommandSender->ddcSendCommand(commandName,
00490 commandParameters1,
00491 timeout);
00492 if(commandResponse == 0) break;
00493
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
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
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 }
00542
00543
00544 timenow = time(&timenow);
00545 deltaAccessTime = timenow - startAccessTime;
00546 }
00547
00548
00549 return false;
00550 }
00551
00552
00553
00554 bool SCTDCSCommand::setDPStatus(string dpName, int state, int timeout)
00555
00556 {
00557
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
00565 string commandName = "SendStat";
00566 string commandParameters(commandPara);
00567
00568
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
00582
00583 int SCTDCSCommand::setParameter(int crate, int channel, string para, float value,
00584 int timeout)
00585
00586 {
00587
00588 char commandPara[200];
00589
00590
00591 if(crate < 10)
00592 {
00593
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
00606 const char* c_para = para.c_str();
00607 if(channel < 10)
00608 {
00609
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
00623 string commandName = "setParameter";
00624
00625 string commandParameters(commandPara);
00626
00627
00628 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00629 commandParameters, timeout);
00630 }
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 int SCTDCSCommand::setChannelParameter(int crate, int channel, string dpeName,
00641 float dpeValue, int timeout)
00642
00643 {
00644
00645 string pvssAddress;
00646 psToPVSSChannelAddress(crate, channel, dpeName, "Send", pvssAddress);
00647 const char* c_pvssAddress = pvssAddress.c_str();
00648
00649 char commandPara[200];
00650 sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00651
00652
00653 string commandName = "setParameters";
00654
00655 string commandParameters(commandPara);
00656
00657 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00658 commandParameters, timeout);
00659 }
00660
00661
00662
00663 int SCTDCSCommand::setChannelParameters(int crate, int channel,
00664 std::map<string, float> dpeNamesAndValues, int timeout)
00665
00666 {
00667
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
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
00695 string commandName = "setParameters";
00696
00697 string commandParameters(commandPara);
00698
00699
00700 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00701 commandParameters, timeout);
00702 }
00703
00704
00705
00706
00707
00708 int SCTDCSCommand::setCardParameter(int crate, int card, string dpeName,
00709 float dpeValue, int timeout)
00710
00711 {
00712
00713 string pvssAddress;
00714 psToPVSSCardAddress(crate, card, dpeName, "Send", pvssAddress);
00715 const char* c_pvssAddress = pvssAddress.c_str();
00716
00717 char commandPara[200];
00718 sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00719
00720
00721 string commandName = "setParameters";
00722
00723 string commandParameters(commandPara);
00724
00725 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00726 commandParameters, timeout);
00727 }
00728
00729
00730
00731 int SCTDCSCommand::setCardParameters(int crate, int card,
00732 std::map<string, float> dpeNamesAndValues, int timeout)
00733
00734 {
00735
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
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
00764 string commandName = "setParameters";
00765
00766 string commandParameters(commandPara);
00767
00768
00769 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00770 commandParameters, timeout);
00771 }
00772
00773
00774
00775
00776
00777 int SCTDCSCommand::setCrateCtrlParameter(int crate, string dpeName, float dpeValue, int timeout)
00778
00779 {
00780
00781 string pvssAddress;
00782 psToPVSSCrateCtrlAddress(crate, dpeName, "Send", pvssAddress);
00783 const char* c_pvssAddress = pvssAddress.c_str();
00784
00785 char commandPara[200];
00786 sprintf(commandPara, "%s|%f", c_pvssAddress, dpeValue);
00787
00788
00789 string commandName = "setParameters";
00790
00791 string commandParameters(commandPara);
00792
00793 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00794 commandParameters, timeout);
00795 }
00796
00797
00798
00799 int SCTDCSCommand::setCrateCtrlParameters(int crate, std::map<string, float> dpeNamesAndValues,
00800 int timeout)
00801
00802 {
00803
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
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
00832 string commandName = "setParameters";
00833
00834 string commandParameters(commandPara);
00835
00836
00837 return m_sctDdcCommandSender->ddcSendCommand(commandName,
00838 commandParameters, timeout);
00839 }
00840
00841
00842
00843 bool SCTDCSCommand::closeDCSControl(string subSystem, int timeout)
00844
00845 {
00846
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
00856 string commandName = "SendStat";
00857 string commandParameters1(commandPara);
00858
00859
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
00870 value = 0;
00871 sprintf(commandPara, "%s:RequArbi.Hold|%d", csubSystem, value);
00872
00873
00874 commandName = "SendStat";
00875 string commandParameters2(commandPara);
00876
00877
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
00893
00894
00895
00896
00897
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
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
00921 if(dpeName == "HVchCurr"){
00922 dpeValue = dpeValue/1000;
00923 }
00924 return;
00925 }
00926
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
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
00952
00953
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
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
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
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
01003
01004
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
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
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
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
01051
01052
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
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
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
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
01095
01096
01097
01098 void SCTDCSCommand::getIVCurveData(float* float_array, int& array_size, int timeout)
01099
01100 {
01101 string pvssAddress("dyn_array_test.float_array");
01102
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
01124 cout << endl << "Type the name of a command to be issued: ";
01125 cin >> commandName;
01126 if(commandName == EXIT_COMMAND)
01127 return;
01128
01129
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
01141 cout << "Type the timeout value (sec): ";
01142 cin >> timeBuf;
01143 timeout = atoi(timeBuf);
01144
01145
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
01159 m_sctDdcCommandSender->ddcSendCommand(ctrlName, commandName, commParameters, timeout);
01160
01161 }
01162 }
01163