00001 // $Id: ethercat_frame.h,v 1.21 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_frame_h__ 00034 #define __ethercat_frame_h__ 00035 00036 #include "ros_ethercat_eml/ethercat_telegram.h" 00037 #include "ros_ethercat_eml/netif.h" 00038 00048 int framedump(const struct EtherCAT_Frame * frame, 00049 unsigned char * buffer, 00050 size_t bufferlength); 00051 00058 int framebuild(struct EtherCAT_Frame * frame, 00059 const unsigned char * buffer); 00060 00062 00066 typedef struct EtherCAT_Frame 00067 { 00068 virtual ~EtherCAT_Frame() 00069 { 00070 } 00072 virtual size_t length(void) const = 0; 00073 00075 virtual unsigned char * dump(unsigned char * a_buffer) const = 0; 00076 00078 00081 virtual int build(const unsigned char * a_buffer) = 0; 00082 00084 virtual EC_Telegram * get_telegram() const = 0; 00085 00086 } ECFrame; 00087 00089 00094 class EC_Frame : public ECFrame 00095 { 00096 public: 00098 00100 size_t length(void) const 00101 { 00102 return header_length() + body_length(); 00103 } 00104 00106 virtual unsigned char * dump(unsigned char * a_buffer) const; 00107 00109 virtual int build(const unsigned char * a_buffer); 00110 00112 EC_Telegram * get_telegram() const 00113 { 00114 return m_telegram; 00115 } 00116 00117 protected: 00119 EC_Frame(); 00120 EC_Frame(const EC_Frame & a_frame); 00121 EC_Frame(EC_Telegram * a_telegram); 00122 00124 EC_Telegram * m_telegram; 00125 00127 virtual unsigned char * dump_header(unsigned char * a_buffer) const = 0; 00129 virtual bool check_header(const unsigned char * a_buffer) const = 0; 00130 00132 virtual size_t header_length(void) const = 0; 00134 virtual size_t body_length(void) const; 00135 00136 }; 00137 00139 static const size_t ETHERCAT_ETHERNET_FRAME_HEADER_SIZE = 2; 00140 00142 00143 class EC_Ethernet_Frame : public EC_Frame 00144 { 00145 public: 00147 00148 EC_Ethernet_Frame(EC_Telegram * a_telegram); 00149 00150 protected: 00151 virtual size_t header_length(void) const 00152 { 00153 return ETHERCAT_ETHERNET_FRAME_HEADER_SIZE; 00154 } 00155 00156 virtual unsigned char * dump_header(unsigned char * a_buffer) const; 00157 00158 virtual bool check_header(const unsigned char * a_buffer) const; 00159 }; 00160 00162 // FIXME TO BE IMPLEMENTED 00163 // class EC_UDP_Frame : public EC_Ethernet_Frame 00164 // redefine virtual header_length() function and 00165 00166 #endif // __ethercat_frame_h__