ethercat_mbx.h
Go to the documentation of this file.
00001 // $Id: ethercat_mbx.h,v 1.14 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_mbx__
00034 #define __ethercat_mbx__
00035 
00036 #include "ros_ethercat_eml/ethercat_defs.h"
00037 #include "ros_ethercat_eml/ethercat_slave_memory.h"
00038 
00039 typedef enum
00040 {
00041   EC_AoE = 0x01, // ADS over EtherCAT
00042   EC_EoE = 0x02, // Ethernet over EtherCAT
00043   EC_CoE = 0x03, // CANOpen over EtherCAT
00044   EC_FoE = 0x04, // File Access over EtherCAT
00045 } ECMbxMsgType;
00046 
00048 
00049 class EC_MbxMsgType
00050 {
00051 public:
00053 
00059   EC_MbxMsgType(ECMbxMsgType type = EC_CoE) :
00060     msg_type(type)
00061   {
00062   }
00063 
00065   operator uint8_t() const
00066   {
00067     return msg_type;
00068   }
00069 private:
00070   uint8_t msg_type;
00071 };
00072 
00074 
00075 class EC_MbxMsgPriority
00076 {
00077 public:
00079 
00082   EC_MbxMsgPriority(uint8_t priority = 0x00)
00083   {
00084     if (priority < 4)
00085       msg_priority = priority;
00086     else
00087     {
00088       ec_log(EC_LOG_WARNING, "EC_MbxMsgPriority: Max Priority is 0x03, using 0x03\n");
00089       msg_priority = 0x03;
00090     }
00091   }
00092 
00094   operator uint8_t() const
00095   {
00096     return msg_priority;
00097   }
00098 private:
00099   uint8_t msg_priority;
00100 };
00101 
00102 // Header size is 6 bytes
00103 static const size_t EC_MBXMSG_HDR_SIZE = 6;
00104 
00106 
00107 class EC_MbxMsgHdr : public EC_DataStruct
00108 {
00109   friend class EtherCAT_Router;
00110 
00111 public:
00113 
00125   EC_MbxMsgHdr(uint16_t a_length,
00126                EC_FixedStationAddress a_address,
00127                EC_MbxMsgPriority a_priority,
00128                EC_MbxMsgType a_type)
00129     :
00130     EC_DataStruct(EC_MBXMSG_HDR_SIZE),
00131     m_length(a_length), m_address(a_address),
00132     m_priority(a_priority), m_type(a_type)
00133   {
00134   }
00135 
00137   EC_MbxMsgHdr(const unsigned char * a_buffer);
00138 
00139   virtual unsigned char * dump(unsigned char * a_buffer) const;
00140 
00141 public:
00142   uint16_t m_length;
00143   EC_FixedStationAddress m_address;
00144   // uint8_t  m_channel; 6 bits unused for now...;
00145   EC_MbxMsgPriority m_priority;
00146   EC_MbxMsgType m_type;
00147   // uint16_t reserved : 4;
00148 };
00149 
00151 
00152 class EtherCAT_MbxMsg
00153 {
00154   friend class EtherCAT_Router;
00155 
00156 public:
00158   EtherCAT_MbxMsg(EC_MbxMsgHdr a_hdr, unsigned char * a_MbxMsgdata)
00159     :
00160     m_hdr(a_hdr), m_MbxMsgdata(a_MbxMsgdata)
00161   {
00162   }
00163   EtherCAT_MbxMsg(uint16_t a_length, uint16_t a_address,
00164                   EC_MbxMsgPriority a_priority,
00165                   EC_MbxMsgType a_type,
00166                   unsigned char * a_MbxMsgdata)
00167     :
00168     m_hdr(a_length, a_address, a_priority, a_type), m_MbxMsgdata(a_MbxMsgdata)
00169   {
00170   }
00171   EtherCAT_MbxMsg(const unsigned char * a_buffer);
00172   virtual ~EtherCAT_MbxMsg()
00173   {
00174   }
00175 
00177   virtual unsigned char * dump(unsigned char * a_buffer) const;
00178 
00179 protected:
00181   EC_MbxMsgHdr m_hdr;
00183   const unsigned char * m_MbxMsgdata;
00184 
00185   virtual unsigned char * dump_data(unsigned char * a_buffer) const;
00186 };
00187 
00189 
00190 class EtherCAT_Mbx
00191 {
00192 public:
00194   bool write(EtherCAT_MbxMsg * a_msg);
00196   bool read(EtherCAT_MbxMsg * a_msg);
00197   EtherCAT_Mbx()
00198   {
00199   }
00200 };
00201 
00202 // ==================================================
00203 // CANopen over EtherCAT
00204 // ==================================================
00205 
00206 typedef enum
00207 {
00208   CANopen_Emergency = 0x01,
00209   CANopen_SDORequest = 0x02,
00210   CANopen_SDOResponse = 0x03,
00211   CANopen_txPDO = 0x04,
00212   CANopen_rxPDO = 0x05,
00213   CANopen_txPDORemoteReq = 0x06,
00214   CANopen_rxPDORemoteReq = 0x07,
00215   CANopen_SDOInformation = 0x08,
00216 } CANopenService;
00217 
00219 
00220 class CANopen_Service
00221 {
00222 public:
00224 
00234   CANopen_Service(CANopenService a_service = CANopen_Emergency)
00235     :
00236     m_service(a_service)
00237   {
00238   }
00239 
00241   operator uint8_t() const
00242   {
00243     return m_service;
00244   }
00245 
00246 private:
00247   CANopenService m_service;
00248 };
00249 
00250 static const size_t EC_MBXMSG_COE_HDR_SIZE = 2;
00251 
00253 
00254 class EC_CoE_Hdr : public EC_DataStruct
00255 {
00256 public:
00258 
00260   EC_CoE_Hdr(CANopen_Service a_service = CANopen_Emergency) :
00261     EC_DataStruct(EC_MBXMSG_COE_HDR_SIZE),
00262     m_service(a_service)
00263   {
00264   }
00265 
00266   EC_CoE_Hdr(const unsigned char * a_buffer);
00267 
00268   virtual unsigned char * dump(unsigned char * a_buffer) const;
00269 
00270 private:
00271   // FIXME meaning of these is nog clear from spec
00272   // Number Low: 8 bits depending on CANopen service
00273   // Number High: 1 bit depending on CANopen service
00274   CANopen_Service m_service;
00275 };
00276 
00278 
00279 class EtherCAT_CoE_MbxMsg : public EtherCAT_MbxMsg
00280 {
00281 public:
00282   EtherCAT_CoE_MbxMsg(EC_MbxMsgHdr a_hdr,
00283                       EC_CoE_Hdr a_CoE_hdr,
00284                       unsigned char * a_MbxMsgdata)
00285     :
00286     EtherCAT_MbxMsg(a_hdr, a_MbxMsgdata), m_CoE_Hdr(a_CoE_hdr)
00287   {
00288   }
00289   EtherCAT_CoE_MbxMsg(uint16_t a_length, uint16_t a_address,
00290                       EC_MbxMsgPriority a_priority,
00291                       EC_MbxMsgType a_type,
00292                       CANopen_Service a_service,
00293                       unsigned char * a_MbxMsgdata)
00294     :
00295     EtherCAT_MbxMsg(a_length, a_address, a_priority, a_type, a_MbxMsgdata), m_CoE_Hdr(a_service)
00296   {
00297   }
00298   EtherCAT_CoE_MbxMsg(unsigned char * a_buffer);
00299 
00300   virtual unsigned char * dump(unsigned char * a_buffer) const;
00301 protected:
00302   EC_CoE_Hdr m_CoE_Hdr;
00303 };
00304 
00305 #endif // __ethercat_mbx__


ros_ethercat_eml
Author(s): Tom Panis, Klaas Gadeyne, Bob Koninckx, Austin Hendrix, Manos Nikolaidis
autogenerated on Thu Aug 27 2015 14:47:07