ALMA Computing Group

acsexmplRampedPowerSupplyImpl.cpp

Go to the documentation of this file.
00001 /******************************************************************************* 00002 * ALMA - Atacama Large Millimiter Array 00003 * (c) European Southern Observatory, 2002 00004 * Copyright by ESO (in the framework of the ALMA collaboration) 00005 * and Cosylab 2002, All rights reserved 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * 00022 * 00023 * "@(#) $Id: acsexmplRampedPowerSupplyImpl.cpp,v 1.109 2008/10/01 04:30:47 cparedes Exp $" 00024 * 00025 * who when what 00026 * -------- --------- ---------------------------------------------- 00027 * acaproni 2004-04-06 Use of the smart pointer for properties 00028 * david 2002-08-08-changed defines to const static int's 00029 * msekoran 2002-02-15 New Completion applied. 00030 * msekoran 2002-02-02 Fixed DO initialization 00031 * almamgr 2002-01-22-Replaced old include files with new axsexmpl... files 00032 * msekoran 2001-07-07 created 00033 */ 00034 00035 #include "acsexmplRampedPowerSupplyImpl.h" 00036 00037 ACE_RCSID(acsexmpl, acsexmplRampedPowerSupplyImpl, "$Id: acsexmplRampedPowerSupplyImpl.cpp,v 1.109 2008/10/01 04:30:47 cparedes Exp $") 00038 using namespace baci; 00039 00041 // Ramped PowerSupply 00043 00044 RampedPowerSupply::RampedPowerSupply( 00045 const ACE_CString &name, 00046 maci::ContainerServices * containerServices) : 00047 PowerSupply(name, containerServices), 00048 m_rampingStep_sp(this), 00049 m_rampingStep_devio_p(0), 00050 m_rampingStatus_sp(new RWstring(name+":rampingStatus", getComponent()),this) 00051 { 00052 ACS_TRACE("::RampedPowerSupply::RampedPowerSupply"); 00053 00054 // RampedPowerSupply properties 00055 00056 // Create an instance of the custom devIO before it's passed to the BACI property 00057 m_rampingStep_devio_p = new LongDevIO(); 00058 00059 // This is a little different from the rest of the BACI properties throughout acsexmpl 00060 // in the fact a custom devIO is being passed to the constructor. 00061 m_rampingStep_sp = new ROlong(name+":rampingStep", getComponent(), m_rampingStep_devio_p); 00062 } 00063 00064 RampedPowerSupply::~RampedPowerSupply() 00065 { 00066 00067 ACS_TRACE("::RampedPowerSupply::~RampedPowerSupply"); 00068 00069 // devIO 00070 if (m_rampingStep_devio_p != 0) 00071 { 00072 delete m_rampingStep_devio_p; 00073 m_rampingStep_devio_p=0; 00074 } 00075 00076 ACS_DEBUG("::RampedPowerSupply::~RampedPowerSupply", "Properties destroyed"); 00077 } 00078 00079 /* --------------- [ Action implementator interface ] -------------- */ 00080 ActionRequest 00081 RampedPowerSupply::invokeAction (int function, 00082 BACIComponent *cob_p, 00083 const int &callbackID, 00084 const CBDescIn &descIn, 00085 BACIValue *value_p, 00086 Completion &completion, 00087 CBDescOut &descOut) 00088 { 00089 00090 // better implementation with array is possible 00091 switch (function) 00092 { 00093 case ON_ACTION: 00094 { 00095 return onAction(cob_p, callbackID, descIn, value_p, completion, descOut); 00096 } 00097 case OFF_ACTION: 00098 { 00099 return offAction(cob_p, callbackID, descIn, value_p, completion, descOut); 00100 } 00101 case RESET_ACTION: 00102 { 00103 return resetAction(cob_p, callbackID, descIn, value_p, completion, descOut); 00104 } 00105 case START_RAMPING: 00106 { 00107 return startRampingAction(cob_p, callbackID, descIn, value_p, completion, descOut); 00108 } 00109 case STOP_RAMPING: 00110 { 00111 return stopRampingAction(cob_p, callbackID, descIn, value_p, completion, descOut); 00112 } 00113 default: 00114 { 00115 return reqDestroy; 00116 } 00117 } 00118 } 00119 /* ----------------------------------------------------------------*/ 00120 /* ------------------ [ Action implementations ] ----------------- */ 00121 /* ----------------------------------------------------------------*/ 00123 ActionRequest 00124 RampedPowerSupply::startRampingAction (BACIComponent *cob_p, 00125 const int &callbackID, 00126 const CBDescIn &descIn, 00127 BACIValue *value_p, 00128 Completion &completion, 00129 CBDescOut &descOut) 00130 { 00131 ACE_UNUSED_ARG(descOut); 00132 ACE_UNUSED_ARG(value_p); 00133 ACE_UNUSED_ARG(descIn); 00134 ACE_UNUSED_ARG(callbackID); 00135 ACE_UNUSED_ARG(cob_p); 00136 00137 ACS_DEBUG_PARAM("::RampedPowerSupply::startRampingAction", "%s", getComponent()->getName()); 00138 completion = ACSErrTypeOK::ACSErrOKCompletion(); 00139 00140 try 00141 { 00142 // simulate something in hardware... 00143 ACE_OS::sleep(5); 00144 ACS::Time timestamp; 00145 m_status_sp->getDevIO()->write(0x00000100 | m_status_sp->getDevIO()->read(timestamp), completion.timeStamp); 00146 } 00147 catch (ACSErr::ACSbaseExImpl &ex) 00148 { 00149 // it might be better to create here another more descriptive method but .... for show how to do is is not important 00150 ACSErrTypeCommon::IOErrorCompletion com(ex, __FILE__, __LINE__, "PowerSupply::offAction"); 00151 completion = com; 00152 } 00153 00154 // complete action requesting done invokation, 00155 // otherwise return reqInvokeWorking and set descOut.estimated_timeout 00156 return reqInvokeDone; 00157 } 00158 00160 ActionRequest 00161 RampedPowerSupply::stopRampingAction (BACIComponent *cob_p, 00162 const int &callbackID, 00163 const CBDescIn &descIn, 00164 BACIValue *value_p, 00165 Completion &completion, 00166 CBDescOut &descOut) 00167 { 00168 ACE_UNUSED_ARG(descOut); 00169 ACE_UNUSED_ARG(value_p); 00170 ACE_UNUSED_ARG(descIn); 00171 ACE_UNUSED_ARG(callbackID); 00172 ACE_UNUSED_ARG(cob_p); 00173 00174 ACS_DEBUG_PARAM("::RampedPowerSupply::stopRampingAction", "%s", getComponent()->getName()); 00175 00176 // simulate something in hardware... 00177 00178 completion = ACSErrTypeOK::ACSErrOKCompletion(); 00179 00180 try 00181 { 00182 ACS::Time timestamp; 00183 m_status_sp->getDevIO()->write(0x11111011 & m_status_sp->getDevIO()->read(timestamp), completion.timeStamp); 00184 } 00185 catch (ACSErr::ACSbaseExImpl &ex) 00186 { 00187 // it might be better to create here another more descriptive method but .... for show how to do is is not important 00188 ACSErrTypeCommon::IOErrorCompletion com(ex, __FILE__, __LINE__, "PowerSupply::offAction"); 00189 completion = com; 00190 } 00191 ACE_OS::sleep(5); 00192 00193 // complete action requesting done invokation, 00194 // otherwise return reqInvokeWorking and set descOut.estimated_timeout 00195 return reqInvokeDone; 00196 } 00197 00198 /* --------------------- [ CORBA interface ] ----------------------*/ 00199 00200 void 00201 RampedPowerSupply::startRamping (CORBA::Long rampingSteps, 00202 ACS::CBvoid_ptr cb, 00203 const ACS::CBDescIn &desc) 00204 { 00205 //registers the action to the BACI and returns control immediately 00206 getComponent()->registerAction(BACIValue::type_null, cb, desc, this, START_RAMPING); 00207 } 00208 00209 void 00210 RampedPowerSupply::stopRamping (ACS::CBvoid_ptr cb, 00211 const ACS::CBDescIn &desc) 00212 { 00213 //registers the action to the BACI and returns control immediately 00214 getComponent()->registerAction(BACIValue::type_null, cb, desc, this, STOP_RAMPING); 00215 } 00216 00217 ACS::RWstring_ptr 00218 RampedPowerSupply::rampingStatus () 00219 { 00220 if (m_rampingStatus_sp == 0) 00221 { 00222 return ACS::RWstring::_nil(); 00223 } 00224 00225 ACS::RWstring_var prop = ACS::RWstring::_narrow(m_status_sp->getCORBAReference()); 00226 return prop._retn(); 00227 } 00228 00229 ACS::ROlong_ptr 00230 RampedPowerSupply::rampingStep () 00231 { 00232 if (m_rampingStep_sp == 0) 00233 { 00234 return ACS::ROlong::_nil(); 00235 } 00236 00237 ACS::ROlong_var prop = ACS::ROlong::_narrow(m_rampingStep_sp->getCORBAReference()); 00238 return prop._retn(); 00239 } 00240 00242 // MACI DLL support functions 00244 #include <maciACSComponentDefines.h> 00245 MACI_DLL_SUPPORT_FUNCTIONS(RampedPowerSupply) 00246 00247