00001 // $Id: ethercat_FSM.h,v 1.16 2006/02/20 15:57:33 kgad Exp $ 00002 //=========================================================================== 00003 // This file is part of "EtherCAT Master Library". 00004 // Copyright (C) 2005 FMTC vzw, Diamant Building, A. Reyerslaan 80, 00005 // B-1030 Brussels, Belgium. 00006 // 00007 // EtherCAT Master Library is free software; you can redistribute it 00008 // and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 or 00010 // (at your option) any later version. 00011 // 00012 // EtherCAT Master Code is distributed in the hope that it will be 00013 // useful, but WITHOUT ANY WARRANTY; without even the implied 00014 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 // PURPOSE. See the GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with the EtherCAT Master Library; if not, write to the Free 00019 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00020 // 02111-1307 USA. 00021 // 00022 // EtherCAT, the EtherCAT trade name and logo are the intellectual 00023 // property of, and protected by Beckhoff. You can use "EtherCAT 00024 // Master Library" for creating and/or selling or otherwise 00025 // distributing an EtherCAT network master under the terms of the 00026 // EtherCAT Master License. 00027 // 00028 // You should have received a copy of the EtherCAT Master License 00029 // along with the EtherCAT Master Library; if not, write to Beckhoff 00030 // Automation GmbH, Eiserstrasse 5, D-33415 Verl, Germany. 00031 //=========================================================================== 00032 00033 #ifndef __ethercat_fsm__ 00034 #define __ethercat_fsm__ 00035 00036 /* Note, this class is supposed to be programmed according to the 00037 FSM design Pattern. 00038 */ 00039 00040 // forward declarations 00041 class EtherCAT_AL; 00042 class EC_Logic; 00043 class EtherCAT_SlaveHandler; 00044 class EtherCAT_DataLinkLayer; 00045 class EtherCAT_Router; 00046 class EtherCAT_PD_Buffer; 00047 00048 // FIXME how to do forward declaration of typedef enum?, with "extern" 00049 // keyword? 00050 #include "ros_ethercat_eml/ethercat_slave_memory.h" 00051 00053 00054 class EC_ESM_Ops 00055 { 00056 protected: 00058 bool start_mbx_comm(); 00060 bool stop_mbx_comm(); 00062 bool start_input_update(); 00064 bool stop_input_update(); 00066 bool start_output_update(); 00068 bool stop_output_update(); 00069 00070 protected: 00072 00074 EC_ESM_Ops(EtherCAT_SlaveHandler * a_SH); 00075 00076 EtherCAT_DataLinkLayer * m_dll_instance; 00077 EC_Logic * m_logic_instance; 00078 EtherCAT_SlaveHandler * m_SH; 00079 EtherCAT_Router * m_router_instance; 00080 EtherCAT_PD_Buffer * m_pdbuf_instance; 00081 00083 00087 bool set_state(EC_State a_state); 00088 }; 00089 00090 // More forward declarations :-) 00091 class EC_ESM; 00092 class EC_ESM_InitState; 00093 class EC_ESM_PreOpState; 00094 class EC_ESM_SafeOpState; 00095 class EC_ESM_OpState; 00096 00098 00101 class EC_ESM_State 00102 { 00103 friend class EC_ESM; 00104 00105 public: 00106 virtual ~EC_ESM_State() 00107 { 00108 } 00109 00111 00119 virtual bool to_state(EC_ESM * a_ESM, EC_State a_state) = 0; 00120 virtual EC_State get_state() const = 0; 00121 protected: 00122 static EC_ESM_InitState initState; 00123 static EC_ESM_PreOpState preopState; 00124 static EC_ESM_SafeOpState safeopState; 00125 static EC_ESM_OpState opState; 00126 }; 00127 00129 00136 class EC_ESM : public EC_ESM_Ops 00137 { 00138 friend class EC_ESM_State; 00139 friend class EC_ESM_InitState; 00140 friend class EC_ESM_PreOpState; 00141 friend class EC_ESM_SafeOpState; 00142 friend class EC_ESM_OpState; 00143 00144 public: 00146 00153 bool to_state(EC_State a_state) 00154 { 00155 return (m_esm_state->to_state(this, a_state)); 00156 } 00157 EC_State get_state() 00158 { 00159 return m_esm_state->get_state(); 00160 } 00161 00162 protected: 00164 void setState(EC_ESM_State * a_esm_state) 00165 { 00166 m_esm_state = a_esm_state; 00167 } 00168 00170 00172 EC_ESM(EtherCAT_SlaveHandler * a_SH); 00173 00174 private: 00175 EC_ESM_State * m_esm_state; 00176 }; 00177 00178 class EC_ESM_InitState : public EC_ESM_State 00179 { 00180 public: 00181 virtual EC_State get_state() const; 00182 virtual bool to_state(EC_ESM * a_ESM, EC_State a_state); 00183 }; 00184 00185 class EC_ESM_PreOpState : public EC_ESM_State 00186 { 00187 public: 00188 virtual EC_State get_state() const; 00189 virtual bool to_state(EC_ESM * a_ESM, EC_State a_state); 00190 }; 00191 00192 class EC_ESM_SafeOpState : public EC_ESM_State 00193 { 00194 public: 00195 virtual EC_State get_state() const; 00196 virtual bool to_state(EC_ESM * a_ESM, EC_State a_state); 00197 }; 00198 00199 class EC_ESM_OpState : public EC_ESM_State 00200 { 00201 public: 00202 virtual EC_State get_state() const; 00203 virtual bool to_state(EC_ESM * a_ESM, EC_State a_state); 00204 }; 00205 00206 #endif // __ethercat_fsm__