SctApiDDC.cxx

00001 
00007 #include "SctApiDDC.h"
00008 
00009 //#include <vector>
00010 using namespace std;
00011 #include "sctddc/SCTDCSCommand.hxx"  // This needs using std before it!
00012 
00013 #include "sctConf/configuration.h"
00014 
00015 #include "utility.h"
00016 #include "SctApiException.h"
00017 #include "Sct/SctNames.h"
00018 
00019 //#include "SctApi.h" // for the SctApi DDC related commands that are not yet part of SctApiDDC
00020 #include "log.h"
00021 
00022 using namespace SctApi::Utility;
00023 
00024 namespace SctApi {
00025 
00026   SctApiDDC::SctApiDDC(boost::shared_ptr<SctConfiguration::Configuration> conf,
00027                        boost::shared_ptr<Log> log) :
00028     m_config(conf),
00029     m_log(log),
00030     m_ddcPartition(0),
00031     m_ddcCmd(0) {
00032   };
00033 
00034   void SctApiDDC::initDDC() 
00035   {
00036     // Initialise DDC command
00037     m_ddcPartition = new IPCPartition(::Sct::SctNames::getPartitionName());
00038     m_ddcCtrls[0] = new string("ddc_ct1");
00039     m_ddcCtrls[1] = 0;
00040 
00041     m_ddcCmd = new SCTDCSCommand(*m_ddcPartition, m_ddcCtrls);
00042   }
00043 
00044   SCTDCSCommand * SctApiDDC::ddcCmd() { if (!m_ddcCmd) { this->initDDC(); }; return m_ddcCmd; };
00045 
00047   SctConfiguration::Configuration * SctApiDDC::config() { return m_config.get(); };
00048 
00049   std::ostream & SctApiDDC::log() { 
00050     if (m_log.get()) { 
00051       return *m_log;
00052     } else {
00053       return std::cout;
00054     }; 
00055   };
00056   
00057   void SctApiDDC::requestHardResetAll() 
00058   {
00059     cout << "Unimplemented!\n";
00060   }
00061 
00062   void SctApiDDC::requestHardReset(UINT32 mid)
00063   {
00064     unsigned int MUR, module;
00065 
00066     unsigned int partition, crate, rod, channel;
00067     getpcrc(mid, partition, crate, rod, channel);
00068 
00069     config()->translateFromROD(partition, crate, rod, channel,
00070                                MUR, module);
00071 
00072     unsigned int ppartition, pcrate, pchannel;
00073 
00074     config()->translateToPowerSupply(MUR, module, 
00075                                      ppartition, pcrate, pchannel);
00076 
00077     std::cout << "Should do hard reset on module in " 
00078               << " partition: " << ppartition 
00079               << " crate: " << pcrate 
00080               << " channel: " << pchannel << std::endl;
00081   }
00082 
00083   void SctApiDDC::requestIVCurve(UINT32 mid, FLOAT32 start, FLOAT32 stop, FLOAT32 step, UINT16 delay, FLOAT32 currentLim)
00084   {
00085     log() << "requestIVCurve: " << mid << ", " << start << ", " << stop << ", " 
00086           << step << " " << delay << " " << currentLim << std::endl;
00087 
00088     unsigned int MUR, module;
00089 
00090     unsigned int partition, crate, rod, channel;
00091     getpcrc(mid, partition, crate, rod, channel);
00092 
00093     config()->translateFromROD(partition, crate, rod, channel,
00094                                MUR, module);
00095 
00096     unsigned int ppartition, pcrate, pchannel;
00097 
00098     config()->translateToPowerSupply(MUR, module, 
00099                                      ppartition, pcrate, pchannel);
00100 
00101     log() << "ddc->requestIVCurve: " << crate << ", " << channel 
00102           << ", " << start << ", " << stop << ", " << step 
00103           << " " << 0 << " " << currentLim << " " << delay << " 10" << std::endl;
00104 
00105 #warning "End voltage and current of request IV curve should be changeable"
00106     float Vend = 0.0;
00107     float Iwarn = currentLim;
00108 
00109     bool result = ddcCmd()->requestIVCurve(crate, channel, start, stop, step, Vend, 
00110                                            Iwarn, currentLim, delay, 10);
00111 
00112     log() << "iv curve success got: " << result << std::endl;
00113   
00114   }
00115 
00116   void SctApiDDC::requestIVCurveAll(FLOAT32 start, FLOAT32 stop, FLOAT32 step, UINT16 delay, FLOAT32 currentLim)
00117   {
00118   }
00119 
00120 
00121   void SctApiDDC::setSelect(UINT32 mid, bool value)
00122   {
00123     unsigned int MUR, module;
00124 
00125     unsigned int partition, crate, rod, channel;
00126     getpcrc(mid, partition, crate, rod, channel);
00127 
00128     config()->translateFromROD(partition, crate, rod, channel,
00129                                MUR, module);
00130     
00131     unsigned int ppartition, pcrate, pchannel;
00132 
00133     config()->translateToPowerSupply(MUR, module, 
00134                                      ppartition, pcrate, pchannel);
00135 
00136     ddcSetChannelParameter(pcrate, pchannel, "LVchCLKS", value?1.0:0.0);
00137   }
00138 
00139   void SctApiDDC::setSelectAllInCrate(int crate, bool value, int timeout)
00140   {
00141     ddcCmd()->setChannelsSelectLine(crate, value, timeout);
00142   }
00143 
00144   void SctApiDDC::changeRunState(int state)
00145   {
00146     throw SctApiException("changeRunState not implemented!");
00147   }
00148 
00149   // void SctApiDDC::ddcGetChannelParameter(int crate, int channel, string dpeName,
00150   //                                     int& dpeValue, int timeout) 
00151   // {
00152   //   log() << "ddcGetChannelParameter: " << crate << ", " << channel << ", (" << dpeName << "), " << dpeName.size() << " " << timeout << std::endl;
00153 
00154   //   ddcCmd()->getChannelParameter(crate, channel, dpeName, dpeValue, timeout);
00155 
00156   //   log() << "channel parameter got: " << dpeValue << std::endl;
00157   // }
00158 
00159   void SctApiDDC::ddcChangeState (int crate, int channel, short state, int timeout) 
00160   {
00161     ddcCmd()->changeState(crate, channel, state, timeout);
00162   }
00163 
00164   void SctApiDDC::ddcChangeStates (int crate, const char* name, short state, int timeout)
00165   {
00166     ddcCmd()->changeState(crate, name, state, timeout);
00167   }
00168 
00169   void SctApiDDC::ddcChangeStateAll (int crate, short state, int timeout)
00170   {
00171     ddcCmd()->changeState(crate, "all", state, timeout);
00172   }
00173 
00174   void SctApiDDC::ddcLoadConfiguration (int crate, short state, int timeout)
00175   {
00176     ddcCmd()->loadConfiguration(crate, state, timeout);
00177   }
00178 
00179   void SctApiDDC::ddcHardReset (int crate, int channel, int timeout)
00180   {
00181     ddcCmd()->hardReset(crate, channel, timeout);
00182   }
00183 
00184   void SctApiDDC::ddcHardResetAll (int crate, int timeout)
00185   {
00186     ddcCmd()->hardReset(crate, "all", timeout);
00187   }
00188 
00189   int SctApiDDC::ddcGetChannelParameterInt (int crate, int channel, string name, int timeout)
00190   {
00191     log() << "ddcGetChannelParameterInt: " << crate << ", " << channel 
00192           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00193 
00194     int dpeValue;
00195     ddcCmd()->getChannelParameter(crate, channel, name, dpeValue, timeout);
00196     log() << "channel parameter got: " << dpeValue << std::endl;
00197 
00198     return dpeValue;
00199   }
00200 
00201   float SctApiDDC::ddcGetChannelParameterFloat (int crate, int channel, string name, int timeout)
00202   {
00203     log() << "ddcGetChannelParameterFloat: " << crate << ", " << channel 
00204           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00205 
00206     float dpeValue;
00207     ddcCmd()->getChannelParameter(crate, channel, name, dpeValue, timeout);
00208     log() << "channel parameter got: " << dpeValue << std::endl;
00209 
00210     return dpeValue;
00211   }
00212 
00213   string SctApiDDC::ddcGetChannelParameterString (int crate, int channel, string name, int timeout)
00214   {
00215     log() << "ddcGetChannelParameterString: " << crate << ", " << channel 
00216           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00217 
00218     string dpeValue;
00219     ddcCmd()->getChannelParameter(crate, channel, name, dpeValue, timeout);
00220     log() << "channel parameter got: " << dpeValue << std::endl;
00221 
00222     return dpeValue;
00223   }
00224 
00225   int SctApiDDC::ddcGetCardParameterInt (int crate, int card, string name, int timeout)
00226   {
00227     log() << "ddcGetCardParameterInt: " << crate << ", " << card 
00228           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00229 
00230     int dpeValue;
00231     ddcCmd()->getCardParameter(crate, card, name, dpeValue, timeout);
00232     log() << "card parameter got: " << dpeValue << std::endl;
00233 
00234     return dpeValue;
00235   }
00236 
00237   float SctApiDDC::ddcGetCardParameterFloat (int crate, int card, string name, int timeout)
00238   {
00239     log() << "ddcGetCardParameterFloat: " << crate << ", " << card 
00240           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00241 
00242     float dpeValue;
00243     ddcCmd()->getCardParameter(crate, card, name, dpeValue, timeout);
00244     log() << "card parameter got: " << dpeValue << std::endl;
00245 
00246     return dpeValue;
00247   }
00248 
00249   string SctApiDDC::ddcGetCardParameterString (int crate, int card, string name, int timeout)
00250   {
00251     log() << "ddcGetCardParameterString: " << crate << ", " << card 
00252           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00253 
00254     string dpeValue;
00255     ddcCmd()->getCardParameter(crate, card, name, dpeValue, timeout);
00256     log() << "card parameter got: " << dpeValue << std::endl;
00257 
00258     return dpeValue;
00259   }
00260 
00261   int SctApiDDC::ddcGetCrateParameterInt (int crate, string name, int timeout)
00262   {
00263     log() << "ddcGetCrateParameterInt: " << crate 
00264           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00265 
00266     int dpeValue;
00267     ddcCmd()->getCrateCtrlParameter(crate, name, dpeValue, timeout);
00268     log() << " crate parameter got: " << dpeValue << std::endl;
00269 
00270     return dpeValue;
00271   }
00272 
00273   float SctApiDDC::ddcGetCrateParameterFloat (int crate, string name, int timeout)
00274   {
00275     log() << "ddcGetCrateParameterFloat: " << crate 
00276           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00277 
00278     float dpeValue;
00279     ddcCmd()->getCrateCtrlParameter(crate, name, dpeValue, timeout);
00280     log() << " crate parameter got: " << dpeValue << std::endl;
00281 
00282     return dpeValue;
00283   }
00284 
00285   string SctApiDDC::ddcGetCrateParameterString (int crate, string name, int timeout)
00286   {
00287     log() << "ddcGetCrateParameterString: " << crate 
00288           << ", (" << name << "), " << name.size() << " " << timeout << std::endl;
00289 
00290     string dpeValue;
00291     ddcCmd()->getCrateCtrlParameter(crate, name, dpeValue, timeout);
00292     log() << " crate parameter got: " << dpeValue << std::endl;
00293 
00294     return dpeValue;
00295   }
00296 
00297   void SctApiDDC::ddcGetCrateParameters(int crate, std::vector<std::string> names, 
00298                                         std::map<std::string, float>& nameValues, int timeout)
00299   {
00300     log() << "ddcGetCrateParameters: " << crate << " " << timeout << std::endl;
00301     ddcCmd()->getCrateParameters(crate, names, nameValues, timeout);
00302   }
00303 
00304   void SctApiDDC::ddcSetChannelParameter (int crate, int channel, std::string name, float value, int timeout)
00305   {
00306     log() << "ddcSetChannelParameter: " << crate << " " << channel
00307           << ", (" << name << "), " << value << " " << timeout << std::endl;
00308 
00309     ddcCmd()->setChannelParameter(crate, channel, name, value, timeout);
00310   }
00311 
00312   void SctApiDDC::ddcSetCardParameter (int crate, int card, std::string name, float value, int timeout)
00313   {
00314     log() << "ddcSetCardParameter: " << crate << " " << card
00315           << ", (" << name << "), " << value << " " << timeout << std::endl;
00316 
00317     ddcCmd()->setCardParameter(crate, card, name, value, timeout);
00318   }
00319 
00320   void SctApiDDC::ddcSetCrateParameter (int crate, std::string name, float value, int timeout)
00321   {
00322     log() << "ddcSetCrateParameter: " << crate 
00323           << ", (" << name << "), " << value << " " << timeout << std::endl;
00324 
00325     ddcCmd()->setCrateCtrlParameter(crate, name, value, timeout);
00326   }
00327 
00328 }

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