ALMA Computing Group

acsexmplMountImpl.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: acsexmplMountImpl.cpp,v 1.111 2008/10/01 04:30:47 cparedes Exp $"
00024 *
00025 * who       when      what
00026 * --------  --------  ----------------------------------------------
00027 * acaproni 2004-04-06 Use of smart pointer for properties
00028 * bjeram 2002-06-25 added  const ACS::CBDescIn & desc
00029 * almamgr 2002-04-07 Removed poa parameter from call to ConstructorEpilogue()
00030 * blopez   2002-04-05 Modified for ACSDO usage. Header removed.
00031 * gchiozzi 2002-04-04 Replaced set_sync() with getDevIO()->write<T>()
00032 * bgustafs 2002-03-04 set properties with set_sync
00033 * msekoran 2002-02-15 New Completion applied.
00034 * msekoran 2002-02-06 Fixed DO initialization
00035 * almamgr 2002-01-22 Replaced old include files with new axsexmpl... files
00036 * msekoran 2001-07-06 improved error handling
00037 * msekoran 2001-06-23 minor changes to work with acsutil module
00038 * msekoran 2001-04-03 new baci
00039 * gchiozzi 2001-02-15 Added real implementation for method descriptor()
00040 * gchiozzi 2001-02-15 Added body of get_interface() method for Object Explorer
00041 * gchiozzi 2001-02-15 created standard header 
00042 */
00043 
00044 
00045 #include <acsexmplMountImpl.h>
00046 #include <baciDB.h>
00047 
00048 ACE_RCSID(acsexmpl, acsexmplMountImpl, "$Id: acsexmplMountImpl.cpp,v 1.111 2008/10/01 04:30:47 cparedes Exp $")
00049 using namespace baci;
00050 
00057 struct __obstar_action {
00058     double ra;
00059     double dec;
00060     double pmRa;
00061     double pmDec;
00062     double radVel;
00063     double par;
00064     MOUNT_ACS::Mount::coordType type;
00065 };
00066 
00067 struct __objfix_action {
00068     double az;
00069     double elev;
00070 };
00071 
00072 Mount::Mount( 
00073              ACE_CString _name,
00074              maci::ContainerServices * containerServices) : 
00075     CharacteristicComponentImpl(_name, containerServices),
00076     m_cmdAz_sp(new ROdouble(_name+":cmdAz", getComponent()),this),
00077     m_cmdEl_sp(new ROdouble(_name+":cmdEl", getComponent()),this),
00078     m_actAz_sp(new ROdouble(_name+":actAz", getComponent()),this),
00079     m_actEl_sp(new ROdouble(_name+":actEl", getComponent()),this)
00080 {
00081     ACS_TRACE("::Mount::Mount");
00082 
00083     
00084      
00085     // register actions for use with invokeAction(...)
00086     m_actions[0] = &Mount::obstarAction;
00087     m_actions[1] = &Mount::objfixAction;    
00088 }
00089 
00090 Mount::~Mount()
00091 {
00092 }
00093 
00094 /* --------------- [ Action implementator interface ] -------------- */
00095 
00096 ActionRequest 
00097 Mount::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     if (function < 2)
00106         {
00107         // call the asynchronous method
00108         return (this->*m_actions[function])(cob_p, callbackID, descIn, value_p, completion, descOut);
00109         }
00110     else
00111         {
00112         return reqDestroy;
00113         }
00114 }
00115 
00116 /* ------------------ [ Action implementations ] ----------------- */
00117 
00119 ActionRequest 
00120 Mount::obstarAction (BACIComponent *cob_p, 
00121                      const int &callbackID,
00122                      const CBDescIn &descIn, 
00123                      BACIValue *value_p,
00124                      Completion &completion, 
00125                      CBDescOut &descOut)
00126 {
00127     ACE_UNUSED_ARG(cob_p);
00128     ACE_UNUSED_ARG(callbackID);
00129     ACE_UNUSED_ARG(descIn);
00130     ACE_UNUSED_ARG(descOut);
00131     
00132 #ifdef debugMount
00133     ACS_SHORT_LOG((LM_DEBUG, "(Mount::obstarAction) %s", getComponent()->getName()));
00134 #endif
00135     
00136     // convert the methods parameters back into something we can use
00137     __obstar_action *param_p = static_cast<__obstar_action *>(const_cast<void *>(value_p->pointerValue()));
00138     
00139     ACS::Time timestamp;
00140     
00141     // simulate changing the antenna's commanded and actual position
00142     try
00143         {
00144         m_cmdAz_sp->getDevIO()->write(param_p->ra, timestamp);
00145         m_actAz_sp->getDevIO()->write(param_p->ra, timestamp);
00146         m_cmdEl_sp->getDevIO()->write(param_p->dec, timestamp);
00147         m_actEl_sp->getDevIO()->write(param_p->dec, timestamp);
00148         }
00149     catch(ACSErr::ACSbaseExImpl &ex)
00150         {
00151         // here some other erro should be defined and used
00152         completion = ACSErrTypeCommon::IOErrorCompletion(ex, __FILE__, __LINE__, "Mount::obstarAction");
00153         return reqInvokeDone;
00154         }
00155     
00156 #ifdef debugMount
00157     ACS_SHORT_LOG((LM_DEBUG, "(Mount::obstarAction) command: %s %s %s",
00158                getComponent()->getName(), "obstar", getStringifiedTimeStamp().c_str()));
00159 #endif
00160     
00161     DBConnector::writeCommand(getComponent()->getName(), "obstar", getStringifiedTimeStamp());
00162     
00163 #ifdef debugMount
00164     ACS_SHORT_LOG((LM_DEBUG, "(Mount::obstarAction) completion"));
00165 #endif
00166     
00167     completion = ACSErrTypeOK::ACSErrOKCompletion();
00168 
00169     // if OK action will be destroyed and we do not need it anymore
00170     if (param_p!=0) 
00171         {
00172         delete param_p;
00173         }
00174 
00175 #ifdef debugMount
00176     ACS_SHORT_LOG((LM_DEBUG, "(Mount::obstarAction) END"));
00177 #endif
00178     
00179     
00180     // complete action requesting done invokation, 
00181     // otherwise return reqInvokeWorking and set descOut.estimated_timeout
00182     return reqInvokeDone;
00183 }
00184 
00185 
00187 ActionRequest 
00188 Mount::objfixAction (BACIComponent *cob_p, 
00189                      const int &callbackID,
00190                      const CBDescIn &descIn, 
00191                      BACIValue *value_p,
00192                      Completion &completion, 
00193                      CBDescOut &descOut)
00194 {
00195     
00196     ACE_UNUSED_ARG(cob_p);
00197     ACE_UNUSED_ARG(callbackID);
00198     ACE_UNUSED_ARG(descIn);
00199     ACE_UNUSED_ARG(descOut);
00200     
00201 #ifdef debugMount
00202     ACS_SHORT_LOG((LM_DEBUG, "(Mount::objfixAction) %s", getComponent()->getName()));
00203 #endif
00204     
00205     // convert the methods parameters back into something we can use
00206     __objfix_action *param_p = static_cast<__objfix_action *>(const_cast<void *>(value_p->pointerValue()));
00207     
00208     ACS::Time timestamp;
00209 
00210     // simulate changing the antenna's commanded and actual position
00211     try
00212         {
00213         m_cmdAz_sp->getDevIO()->write(param_p->az, timestamp);
00214         m_actAz_sp->getDevIO()->write(param_p->az, timestamp);
00215         m_cmdEl_sp->getDevIO()->write(param_p->elev, timestamp);
00216         m_actEl_sp->getDevIO()->write(param_p->elev, timestamp);
00217         }
00218     catch(ACSErr::ACSbaseExImpl &ex)
00219         {
00220         // here some other erro should be defined and used
00221         completion = ACSErrTypeCommon::IOErrorCompletion(ex, __FILE__, __LINE__, "Mount::objfixAction");
00222         return reqInvokeDone;
00223         }
00224  
00225     DBConnector::writeCommand(getComponent()->getName(), "objfix", getStringifiedTimeStamp());
00226 
00227     completion = ACSErrTypeOK::ACSErrOKCompletion();
00228     
00229     // if OK action will be destroyed and we do not need it anymore
00230     if (param_p!=0) 
00231         {
00232         delete param_p;
00233         }
00234     
00235     // complete action requesting done invokation, 
00236     // otherwise return reqInvokeWorking and set descOut.estimated_timeout
00237     return reqInvokeDone;
00238 }
00239 
00240 
00241 /* --------------------- [ CORBA interface ] ----------------------*/
00242 ACS::ROdouble_ptr
00243 Mount::cmdAz ()
00244 {
00245     if (m_cmdAz_sp == 0)
00246         {
00247         return ACS::ROdouble::_nil();
00248         }
00249 
00250     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_cmdAz_sp->getCORBAReference());
00251     return prop._retn();
00252 }
00253 
00254 ACS::ROdouble_ptr
00255 Mount::cmdEl ()
00256 {
00257     if (m_cmdEl_sp == 0)
00258         {
00259         return ACS::ROdouble::_nil();
00260         }
00261 
00262     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_cmdEl_sp->getCORBAReference());
00263     return prop._retn();
00264 }
00265 
00266 ACS::ROdouble_ptr
00267 Mount::actAz ()
00268 {
00269     if (m_actAz_sp == 0)
00270         {
00271         return ACS::ROdouble::_nil();
00272         }
00273 
00274     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_actAz_sp->getCORBAReference());
00275     return prop._retn();
00276 }
00277 
00278 ACS::ROdouble_ptr
00279 Mount::actEl ()
00280 {
00281     if (m_actEl_sp == 0)
00282         {
00283         return ACS::ROdouble::_nil();
00284         }
00285     
00286     ACS::ROdouble_var prop = ACS::ROdouble::_narrow(m_actEl_sp->getCORBAReference());
00287     return prop._retn();
00288 }
00289 
00290 void
00291 Mount::obstar (CORBA::Double ra,
00292                CORBA::Double dec,
00293                CORBA::Double pmRa,
00294                CORBA::Double pmDec,
00295                CORBA::Double radVel,
00296                CORBA::Double par,
00297                MOUNT_ACS::Mount::coordType type,
00298                ACS::CBvoid_ptr callBack,
00299                const ACS::CBDescIn &desc
00300                )
00301 {
00302     // convert this method's parameters into something ActionImplementor can use
00303     __obstar_action *param_p = new __obstar_action();
00304     param_p->ra=ra; 
00305     param_p->dec=dec; 
00306     param_p->pmRa=pmRa; 
00307     param_p->pmDec=pmDec;
00308     param_p->radVel=radVel; 
00309     param_p->par=par; 
00310     param_p->type=type;    
00311     
00312     // register the action in a queue so that control is returned immediately
00313     getComponent()->registerAction(BACIValue::type_null, callBack, desc, this, 0, BACIValue(param_p));    // ID = 0
00314 }
00315 
00316 void
00317 Mount::objfix (CORBA::Double az,
00318                CORBA::Double elev,
00319                ACS::CBvoid_ptr callBack,
00320                const ACS::CBDescIn &desc
00321                )
00322 {
00323     // convert this method's parameters into something ActionImplementor can use
00324     __objfix_action *param_p = new __objfix_action();
00325     param_p->az=az; 
00326     param_p->elev=elev;
00327     
00328     // register the action in a queue so that control is returned immediately
00329     getComponent()->registerAction(BACIValue::type_null, callBack, desc, this, 1, BACIValue(param_p));    // ID = 1
00330 }
00331 
00332 
00333 /* --------------- [ MACI DLL support functions ] -----------------*/
00334 #include <maciACSComponentDefines.h>
00335 MACI_DLL_SUPPORT_FUNCTIONS(Mount)
00336 /* ----------------------------------------------------------------*/
00337 
00338 
00339 
00340 
00341