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