Go to the documentation of this file.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
00034
00035 #pragma once
00036
00037 #include "ethercat_hardware/ethercat_com.h"
00038 #include <diagnostic_updater/DiagnosticStatusWrapper.h>
00039
00040 namespace ethercat_hardware
00041 {
00042
00043
00044 struct MbxDiagnostics
00045 {
00046 MbxDiagnostics();
00047 uint32_t write_errors_;
00048 uint32_t read_errors_;
00049 uint32_t lock_errors_;
00050 uint32_t retries_;
00051 uint32_t retry_errors_;
00052 };
00053
00054
00055 class WGMailbox
00056 {
00057 public:
00058 WGMailbox();
00059
00060 bool initialize(EtherCAT_SlaveHandler *sh);
00061 int writeMailbox(EthercatCom *com, unsigned address, void const *data, unsigned length);
00062 int readMailbox(EthercatCom *com, unsigned address, void *data, unsigned length);
00063 void publishMailboxDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &d);
00064
00065 static const unsigned MBX_COMMAND_PHY_ADDR = 0x1400;
00066 static const unsigned MBX_COMMAND_SIZE = 512;
00067 static const unsigned MBX_STATUS_PHY_ADDR = 0x2400;
00068 static const unsigned MBX_STATUS_SIZE = 512;
00069
00070 static const unsigned MBX_COMMAND_SYNCMAN_NUM = 2;
00071 static const unsigned MBX_STATUS_SYNCMAN_NUM = 3;
00072
00073 protected:
00074
00075 bool lockMailbox();
00076 void unlockMailbox();
00077 pthread_mutex_t mailbox_lock_;
00078 MbxDiagnostics mailbox_diagnostics_;
00079 MbxDiagnostics mailbox_publish_diagnostics_;
00080
00081
00082 int writeMailbox_(EthercatCom *com, unsigned address, void const *data, unsigned length);
00083 int readMailbox_(EthercatCom *com, unsigned address, void *data, unsigned length);
00084 bool verifyDeviceStateForMailboxOperation();
00085 bool clearReadMailbox(EthercatCom *com);
00086 bool waitForReadMailboxReady(EthercatCom *com);
00087 bool waitForWriteMailboxReady(EthercatCom *com);
00088 bool readMailboxRepeatRequest(EthercatCom *com);
00089 bool _readMailboxRepeatRequest(EthercatCom *com);
00090 bool writeMailboxInternal(EthercatCom *com, void const *data, unsigned length);
00091 bool readMailboxInternal(EthercatCom *com, void *data, unsigned length);
00092 void diagnoseMailboxError(EthercatCom *com);
00093
00094 EtherCAT_SlaveHandler *sh_;
00095 };
00096
00097
00098 };