00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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,
00042 EC_EoE = 0x02,
00043 EC_CoE = 0x03,
00044 EC_FoE = 0x04,
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
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
00145 EC_MbxMsgPriority m_priority;
00146 EC_MbxMsgType m_type;
00147
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
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
00272
00273
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__