ALMA Computing Group

acsexmplPowerSupplyImpl.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: acsexmplPowerSupplyImpl.cpp,v 1.115 2008/10/09 08:41:11 cparedes Exp $"
00024 *
00025 * who       when      what
00026 * --------  --------  ----------------------------------------------
00027 * acaproni 2004-04-06 Use of smart pointer for properties
00028 * david 2002-08-08 changed defines to const static int's
00029 * almamgr 2002-04-07 Removed poa parameter from call to ConstructorEpilogue()
00030 * blopez   2002-04-05 Modified for ACSDO usage. Header removed.
00031 * msekoran 2002-02-15 New Completion applied.
00032 * msekoran 2002-02-02 Fixed DO initialization
00033 * almamgr 2002-01-22 Replaced old include files with new axsexmpl... files
00034 * msekoran 2001-07-06 improved error handling
00035 * msekoran 2001-03-10 integrated with new BACI; ALMA coding convention used
00036 * gchiozzi 2001-02-15 Added real implementation for method descriptor()
00037 * gchiozzi 2001-02-15 Added body of get_interface() method for Object Explorer
00038 * gchiozzi 2001-02-15 created standard header 
00039 */
00040 
00041 
00042 #include <acsexmplPowerSupplyImpl.h>
00043 
00044 ACE_RCSID(acsexmpl, acsexmplPowerSupplyImpl, "$Id: acsexmplPowerSupplyImpl.cpp,v 1.115 2008/10/09 08:41:11 cparedes Exp $")
00045 
00046 using namespace baci;
00047 
00049 // PowerSupply
00051 
00052 PowerSupply::PowerSupply( 
00053                          const ACE_CString &name,
00054                          maci::ContainerServices * containerServices) :
00055     CharacteristicComponentImpl(name,containerServices),
00056     m_status_sp(new ROpattern(name+":status", getComponent()),this),
00057     m_readback_sp(new ROdouble(name+":readback", getComponent()),this),
00058     m_current_sp(this)
00059 {
00060     ACS_TRACE("::PowerSupply::PowerSupply"); 
00061     
00062     // Properties are created in two ways:
00063     // 1. passing to the constructor the Characteristic Component that owns the 
00064     //    property, the pointer to the porperty and the idl accessor function 
00065     // 2. passing to the constructor the Characteristic Component that owns the  
00066     //    property and the calling the init method of the smart pointer with
00067     //    the pointer to the property and the idl accessor as parameters
00068     // The property's name must be composed of the server's name and the
00069     //   property name.
00070     m_current_sp=new PowerSupplyCurrent(name+":current", getComponent(), m_readback_sp);
00071 }
00072 
00073 void
00074 PowerSupply::execute()
00075 {
00076     ACS_SHORT_LOG((LM_INFO,"PowerSupply::execute"));
00077     
00078     // The PowerSupply is initially turned off...
00079     ACS::Time timestamp;
00080     m_status_sp->getDevIO()->write(0x00000000, timestamp);
00081    
00082     ACS_SHORT_LOG((LM_INFO,"PowerSupply::COMPSTATE_OPERATIONAL"));
00083 }
00084 
00085 
00086 PowerSupply::~PowerSupply()
00087 {
00088     ACS_TRACE("::PowerSupply::~PowerSupply");
00089 
00090     
00091     ACS_DEBUG("::PowerSupply::~PowerSupply", "Properties destroyed");
00092 }
00093 
00094 /* --------------- [ Action implementator interface ] -------------- */
00095 
00096 ActionRequest 
00097 PowerSupply::invokeAction (int function,
00098                            BACIComponent *cob_p, 
00099                            const int &callbackID, 
00100                            const CBDescIn &descIn, 
00101                            BACIValue *value_p, 
00102                            Completion &completion, 
00103                            CBDescOut &descOut) 
00104 {
00105     // better implementation with array is possible
00106     switch (function) 
00107         {
00108         case ON_ACTION:
00109         {
00110         return onAction(cob_p, callbackID, descIn, value_p, completion, descOut);
00111         }
00112         case OFF_ACTION:
00113         {
00114         return offAction(cob_p, callbackID, descIn, value_p, completion, descOut);
00115         }
00116         case RESET_ACTION:
00117         {
00118         return resetAction(cob_p, callbackID, descIn, value_p, completion, descOut);
00119         }
00120         default:
00121         {
00122         return reqDestroy;
00123         }
00124         }
00125 }
00126 
00127 /* ------------------ [ Action implementations ] ----------------- */
00128 
00130 ActionRequest 
00131 PowerSupply::onAction (BACIComponent *cob_p, 
00132                        const int &callbackID,
00133                        const CBDescIn &descIn, 
00134                        BACIValue *value_p,
00135                        Completion &completion, 
00136                        CBDescOut &descOut)
00137 {
00138     ACS_DEBUG_PARAM("::PowerSupply::onAction", "%s", getComponent()->getName());
00139     
00140     // simulate something in hardware...
00141     ACE_OS::sleep(5);
00142     // since this method is only simulated, we just change it's state  
00143     completion = ACSErrTypeOK::ACSErrOKCompletion();
00144     try
00145         {
00146         ACS::Time timestamp;
00147         m_status_sp->getDevIO()->write(0x00000001 | m_status_sp->getDevIO()->read(timestamp), completion.timeStamp);
00148         }
00149     catch (ACSErr::ACSbaseExImpl &ex)
00150         {
00151         // it might be better to create here another more descriptive method but .... for show how to do is is not important
00152         ACSErrTypeCommon::IOErrorCompletion com(ex, __FILE__, __LINE__, "PowerSupply::onAction");
00153         completion  = com;
00154         }
00155     // complete action requesting done invakation,
00156     // otherwise return reqInvokeWorking and set descOut.estimated_timeout
00157     return reqInvokeDone;
00158 }
00159 
00161 ActionRequest 
00162 PowerSupply::offAction (BACIComponent *cob_p, 
00163                         const int &callbackID,
00164                         const CBDescIn &descIn, 
00165                         BACIValue *value_p,
00166                         Completion &completion, 
00167                         CBDescOut &descOut)
00168 {
00169     ACS_DEBUG_PARAM("::PowerSupply::offAction", "%s", getComponent()->getName());
00170         
00171     // since this method is only simulated, we just change it's state  
00172     completion = ACSErrTypeOK::ACSErrOKCompletion();
00173 
00174     try
00175         {
00176         ACS::Time timestamp;
00177         m_status_sp->getDevIO()->write(0x11111110 & m_status_sp->getDevIO()->read(timestamp), completion.timeStamp);
00178         
00179         }
00180     catch (ACSErr::ACSbaseExImpl &ex)
00181         {
00182         // it might be better to create here another more descriptive method but .... for show how to do is is not important
00183         ACSErrTypeCommon::IOErrorCompletion com(ex, __FILE__, __LINE__, "PowerSupply::offAction");
00184         completion  = com;
00185         }
00186     // simulate something in hardware...
00187     ACE_OS::sleep(5);
00188     
00189     // complete action requesting done invakation, 
00190     // otherwise return reqInvokeWorking and set descOut.estimated_timeout
00191     return reqInvokeDone;
00192 }
00193 
00195 ActionRequest 
00196 PowerSupply::resetAction (BACIComponent *cob_p, 
00197                           const int &callbackID,
00198                           const CBDescIn &descIn, 
00199                           BACIValue *value_p,
00200                           Completion &completion, 
00201                           CBDescOut &descOut)
00202 {
00203     ACS_DEBUG_PARAM("::PowerSupply::resetAction", "%s", getComponent()->getName());
00204     
00205     completion = ACSErrTypeOK::ACSErrOKCompletion();
00206 
00207     // simulate the PS turning off...
00208     try
00209         {
00210         m_status_sp->getDevIO()->write(static_cast<unsigned long>(0x11111110) & m_status_sp->getDevIO()->read(completion.timeStamp), completion.timeStamp);
00211         ACE_OS::sleep(5);
00212         // now turn it back on
00213 
00214         m_status_sp->getDevIO()->write(static_cast<unsigned long>(0x00000001) | m_status_sp->getDevIO()->read(completion.timeStamp), completion.timeStamp);
00215         }
00216     catch (ACSErr::ACSbaseExImpl &ex)
00217         {
00218         // it might be better to create here another more descriptive method but .... for show how to do is is not important
00219         ACSErrTypeCommon::IOErrorCompletion com(ex, __FILE__, __LINE__, "PowerSupply::offAction");
00220         completion  = com;
00221         }
00222 
00223  
00224     ACE_OS::sleep(5);
00225 
00226     // complete action requesting done invocation, 
00227     // otherwise return reqInvokeWorking and set descOut.estimated_timeout
00228     return reqInvokeDone;
00229 }
00230 
00231 /* --------------------- [ CORBA interface ] ----------------------*/
00232  
00233 void
00234 PowerSupply::on (ACS::CBvoid_ptr cb,
00235                  const ACS::CBDescIn &desc
00236                  )
00237 {
00238     //registers the action to the BACI and returns control immediately
00239     getComponent()->registerAction(BACIValue::type_null, cb, desc, this, ON_ACTION);
00240 }
00241 
00242 void
00243 PowerSupply::off (ACS::CBvoid_ptr cb,
00244                   const ACS::CBDescIn &desc
00245                   )
00246 {
00247     //registers the action to the BACI and returns control immediately
00248     getComponent()->registerAction(BACIValue::type_null, cb, desc, this, OFF_ACTION);
00249 }
00250 
00251 void
00252 PowerSupply::reset (ACS::CBvoid_ptr cb,
00253                     const ACS::CBDescIn &desc
00254                     )
00255 {
00256     //registers the action to the BACI and returns control immediately
00257     getComponent()->registerAction(BACIValue::type_null, cb, desc, this, RESET_ACTION);
00258 }
00259 
00260 ACS::RWdouble_ptr
00261 PowerSupply::current ()
00262 {
00263     if (m_current_sp == 0)
00264         {
00265         return ACS::RWdouble::_nil();
00266         }
00267     
00268     ACS::RWdouble_var prop = ACS::RWdouble::_narrow(m_current_sp->getCORBAReference());
00269     return prop._retn();
00270 }
00271 
00272 ACS::ROdouble_ptr
00273 PowerSupply::readback ()
00274 {
00275     if (m_readback_sp == 0)
00276         {
00277         return ACS::ROdouble::_nil();
00278         }
00279     
00280     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_readback_sp->getCORBAReference());
00281     return prop._retn();
00282 }
00283 
00284 
00285 ACS::ROpattern_ptr
00286 PowerSupply::status ()
00287 {
00288     if (m_status_sp == 0)
00289         {
00290         return ACS::ROpattern::_nil();
00291         }
00292     
00293     ACS::ROpattern_var prop = ACS::ROpattern::_narrow(m_status_sp->getCORBAReference());
00294     return prop._retn();
00295 }
00296 
00297