ethercat_defs.h
Go to the documentation of this file.
00001 // $Id: ethercat_defs.h,v 1.6 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_defs_h__
00034 #define __ethercat_defs_h__
00035 
00036 // NOTE: Contrary to all logic ethercat data is transmitted in Little
00037 // Endian!
00038 
00039 #include <stdint.h>
00040 #include <string.h>
00041 inline uint16_t le16_to_cpu(uint16_t data)
00042 {
00043   return data;
00044 }
00045 inline uint16_t le16_to_cpu(int16_t data)
00046 {
00047   return (uint16_t) data;
00048 }
00049 inline uint32_t le32_to_cpu(uint32_t data)
00050 {
00051   return data;
00052 }
00053 inline uint32_t le32_to_cpu(int32_t data)
00054 {
00055   return (uint32_t) data;
00056 }
00057 inline uint16_t cpu_to_le16(uint16_t data)
00058 {
00059   return data;
00060 }
00061 inline uint16_t cpu_to_le16(int16_t data)
00062 {
00063   return (uint16_t) data;
00064 }
00065 inline uint32_t cpu_to_le32(uint32_t data)
00066 {
00067   return data;
00068 }
00069 inline uint32_t cpu_to_le32(int32_t data)
00070 {
00071   return (uint32_t) data;
00072 }
00073 inline unsigned char * host2nw(unsigned char * a_buffer, int8_t a_value)
00074 {
00075   *a_buffer++ = static_cast<unsigned char> (a_value);
00076   return a_buffer;
00077 }
00078 inline unsigned char * host2nw(unsigned char * a_buffer, uint8_t a_value)
00079 {
00080   *a_buffer++ = static_cast<unsigned char> (a_value);
00081   return a_buffer;
00082 }
00083 inline unsigned char * host2nw(unsigned char * a_buffer, int16_t a_value)
00084 {
00085   uint16_t tmp = cpu_to_le16(a_value);
00086   memcpy(a_buffer, &tmp, sizeof (tmp));
00087   return a_buffer + sizeof (tmp);
00088 }
00089 inline unsigned char * host2nw(unsigned char * a_buffer, uint16_t a_value)
00090 {
00091   uint16_t tmp = cpu_to_le16(a_value);
00092   memcpy(a_buffer, &tmp, sizeof (tmp));
00093   return a_buffer + sizeof (tmp);
00094 }
00095 inline unsigned char * host2nw(unsigned char * a_buffer, int32_t a_value)
00096 {
00097   uint32_t tmp = cpu_to_le32(a_value);
00098   memcpy(a_buffer, &tmp, sizeof (tmp));
00099   return a_buffer + sizeof (tmp);
00100 }
00101 inline unsigned char * host2nw(unsigned char * a_buffer, uint32_t a_value)
00102 {
00103   uint32_t tmp = cpu_to_le32(a_value);
00104   memcpy(a_buffer, &tmp, sizeof (tmp));
00105   return a_buffer + sizeof (tmp);
00106 }
00107 inline unsigned char * host2nw(unsigned char * a_buffer, const unsigned char * a_data,
00108                                size_t a_datalen)
00109 {
00110   memcpy(a_buffer, a_data, a_datalen);
00111   return a_buffer + a_datalen;
00112 }
00113 inline const unsigned char * nw2host(const unsigned char * a_data, int8_t& a_value)
00114 {
00115   a_value = static_cast<int8_t> (*a_data);
00116   return a_data + sizeof (a_value);
00117 }
00118 inline const unsigned char * nw2host(const unsigned char * a_data, uint8_t& a_value)
00119 {
00120   a_value = static_cast<uint8_t> (*a_data);
00121   return a_data + sizeof (a_value);
00122 }
00123 inline const unsigned char * nw2host(const unsigned char * a_data, int16_t& a_value)
00124 {
00125   uint16_t tmp;
00126   memcpy(&tmp, a_data, sizeof (tmp));
00127   tmp = le16_to_cpu(tmp);
00128 
00129   a_value = static_cast<int16_t> (tmp);
00130   return a_data + sizeof (a_value);
00131 }
00132 inline const unsigned char * nw2host(const unsigned char * a_data, uint16_t& a_value)
00133 {
00134   uint16_t tmp;
00135   memcpy(&tmp, a_data, sizeof (tmp));
00136   tmp = le16_to_cpu(tmp);
00137 
00138   a_value = tmp; //reinterpret_cast<uint16_t>(tmp);
00139   return a_data + sizeof (a_value);
00140 }
00141 inline const unsigned char * nw2host(const unsigned char * a_data, int32_t& a_value)
00142 {
00143   uint32_t tmp;
00144   memcpy(&tmp, a_data, sizeof (tmp));
00145   tmp = le32_to_cpu(tmp);
00146 
00147   a_value = static_cast<int32_t> (tmp);
00148   return a_data + sizeof (a_value);
00149 }
00150 inline const unsigned char * nw2host(const unsigned char * a_data, uint32_t& a_value)
00151 {
00152   uint32_t tmp;
00153   memcpy(&tmp, a_data, sizeof (tmp));
00154   tmp = le32_to_cpu(tmp);
00155 
00156   a_value = static_cast<uint32_t> (tmp);
00157   return a_data + sizeof (a_value);
00158 }
00159 
00160 #endif // __ethercat_defs_h__


ros_ethercat_eml
Author(s): Tom Panis, Klaas Gadeyne, Bob Koninckx, Austin Hendrix, Manos Nikolaidis
autogenerated on Thu Jul 4 2019 20:01:49