ESI.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Stefan Reither( stefan.reither at kit dot edu)
20  * @date 2021
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 #include <bitset>
28 #include <cstdint>
29 #include <optional>
30 #include <vector>
31 
33 {
34 
35  constexpr std::uint16_t ESI_Header_StartAdress = 0x0000;
36  constexpr std::uint16_t ESI_Header_EndAdress = 0x0040;
37 
38  /**
39  * @class ESIHandler
40  * @ingroup Library-ethercat
41  * @brief Brief description of class ESIHandler.
42  *
43  * Detailed description of class ESIHandler.
44  */
45  class ESIHandler
46  {
47  protected:
48  // 2 Byte access, data at end address not included in blob
49  std::optional<std::vector<std::byte>> readESIBinaryBlob(std::uint16_t slaveIndex,
50  std::uint16_t startAddress,
51  std::uint16_t endAddress) const;
52 
53  private:
54  std::vector<std::byte> readFromEEPROM(std::uint16_t slaveIndex,
55  std::uint16_t startAddress,
56  std::uint16_t endAddress,
57  bool has64BitPackets) const;
58  };
59 
60 
61  // TODO
62  // ------------------------------------------
63  // Following code has been copied from etherkitten and should be replaced by the original
64  // project code once etherkitten has been made a dependecy of armarx
65  // ------------------------------------------
66 
67  struct ESIHeader
68  {
69  std::uint16_t pdiControl;
70  std::uint16_t pdiConfiguration;
71  std::uint16_t syncImpulseLen;
72  std::uint16_t pdiConfiguration2;
73  std::uint16_t stationAlias;
74  std::uint16_t checkSum;
75  std::uint32_t vendorID;
76  std::uint32_t productCode;
77  std::uint32_t revisionNumber;
78  std::uint32_t serialNumber;
82  std::uint16_t bootstrapSendMailboxSize;
86  std::uint16_t standardSendMailboxSize;
87  std::uint16_t mailboxProtocol;
88  std::uint16_t eepromSize;
89  std::uint16_t version;
90  };
91 
92  enum class MailboxProtocols
93  {
94  AOE = 0x1,
95  EOE = 0x2,
96  COE = 0x4,
97  FOE = 0x8,
98  SOE = 0x10,
99  VOE = 0x20,
100  };
101 
102  using ESIStrings = std::vector<std::string>;
103 
104  struct ESIGeneral
105  {
106  std::uint8_t groupIdx;
107  std::uint8_t imgIdx;
108  std::uint8_t orderIdx;
109  std::uint8_t nameIdx;
110  std::uint8_t coEDetails;
111  std::uint8_t foEDetails;
112  std::uint8_t eoEDetails;
113  std::uint8_t soEChannels;
114  std::uint8_t dS402Channels;
115  std::uint8_t sysmanClass;
116  std::uint8_t flags;
117  std::int16_t currentOnEBus;
118  std::uint16_t physicalPort;
119  std::uint16_t physicalMemoryAddress;
120  std::bitset<3> identALStatus;
122  };
123 
124  using ESIFMMU = std::vector<std::uint8_t>;
125 
127  {
128  std::uint16_t physicalStartAddress;
129  std::uint16_t length;
130  std::uint8_t controlRegister;
131  std::uint8_t statusRegister;
132  std::uint8_t enableSynchManager;
133  std::uint8_t syncManagerType;
134  };
135 
136  using ESISyncM = std::vector<ESISyncMElement>;
137 
138  struct ESIPDOEntry
139  {
140  std::uint16_t index;
141  std::uint8_t subIndex;
142  std::uint8_t nameIdx;
143  std::uint8_t dataType;
144  std::uint8_t bitLength;
145  std::uint16_t flags;
146  };
147 
149  {
150  std::uint16_t pdoIndex;
151  std::uint8_t entryCount;
152  std::uint8_t syncManager;
153  std::uint8_t synchronization;
154  std::uint8_t nameIdx;
155  std::uint16_t flags;
156  std::vector<ESIPDOEntry> entries;
157  };
158 
159  using ESITxPDO = std::vector<ESIPDOObject>;
160  using ESIRxPDO = std::vector<ESIPDOObject>;
161 
162  /*!
163  * \brief Holds ESI data that can be read from slaves via SII.
164  *
165  * For details regarding contents and structure, see ETG1000.6.
166  */
167  struct ESIData
168  {
171  std::optional<ESIGeneral> general;
176  };
177 
178 
179  class ESIParser
180  {
181  public:
182  ESIHeader parseHeader(const std::vector<std::byte>& esiBinary);
183 
184  std::vector<std::string> parseStrings(const std::vector<std::byte>& esiBinary,
185  std::uint16_t wordOffset);
186 
187  ESIGeneral parseGeneral(const std::vector<std::byte>& esiBinary, std::uint16_t wordOffset);
188 
189  ESIFMMU parseFMMU(const std::vector<std::byte>& esiBinary,
190  std::uint16_t wordOffset,
191  std::uint16_t len);
192 
193  ESISyncM parseSyncM(const std::vector<std::byte>& esiBinary,
194  std::uint16_t wordOffset,
195  std::uint16_t len);
196 
197  std::vector<ESIPDOObject> parsePDOs(const std::vector<std::byte>& esiBinary,
198  std::uint16_t wordOffset,
199  std::uint16_t len);
200 
201  /*!
202  * \brief Parse a standard-conformant binary in SII format to an ESI structure.
203  *
204  * See ETG1000.6 for the SII specification.
205  * \param esiBinary the binary SII to parse
206  * \return the parsed ESI data structure
207  * \exception ParseException iff esiBinary is not standard-conformant
208  */
209  ESIData parseESI(const std::vector<std::byte>& esiBinary);
210  };
211 
212 } // namespace armarx::control::ethercat
armarx::control::ethercat::ESIHeader::stationAlias
std::uint16_t stationAlias
Definition: ESI.h:73
armarx::control::ethercat::ESISyncMElement::length
std::uint16_t length
Definition: ESI.h:129
armarx::control::ethercat::ESITxPDO
std::vector< ESIPDOObject > ESITxPDO
Definition: ESI.h:159
armarx::control::ethercat::ESIParser::parseGeneral
ESIGeneral parseGeneral(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset)
Definition: ESI.cpp:238
armarx::control::ethercat::ESIHeader::serialNumber
std::uint32_t serialNumber
Definition: ESI.h:78
armarx::control::ethercat::ESISyncMElement::physicalStartAddress
std::uint16_t physicalStartAddress
Definition: ESI.h:128
armarx::control::ethercat::ESIPDOEntry::index
std::uint16_t index
Definition: ESI.h:140
armarx::control::ethercat::ESIGeneral::sysmanClass
std::uint8_t sysmanClass
Definition: ESI.h:115
armarx::control::ethercat::ESIHeader::standardSendMailboxSize
std::uint16_t standardSendMailboxSize
Definition: ESI.h:86
armarx::control::ethercat::ESIPDOObject::entryCount
std::uint8_t entryCount
Definition: ESI.h:151
armarx::control::ethercat::ESIGeneral::physicalMemoryAddress
std::uint16_t physicalMemoryAddress
Definition: ESI.h:119
armarx::control::ethercat::ESIData::rxPDO
ESIRxPDO rxPDO
Definition: ESI.h:175
armarx::control::ethercat::ESIGeneral::imgIdx
std::uint8_t imgIdx
Definition: ESI.h:107
armarx::control::ethercat::ESIPDOObject::syncManager
std::uint8_t syncManager
Definition: ESI.h:152
armarx::control::ethercat::ESIHeader::version
std::uint16_t version
Definition: ESI.h:89
armarx::control::ethercat::MailboxProtocols::FOE
@ FOE
armarx::control::ethercat::ESIPDOObject::entries
std::vector< ESIPDOEntry > entries
Definition: ESI.h:156
armarx::control::ethercat::ESIData::syncM
ESISyncM syncM
Definition: ESI.h:173
armarx::control::ethercat::ESIHandler::readESIBinaryBlob
std::optional< std::vector< std::byte > > readESIBinaryBlob(std::uint16_t slaveIndex, std::uint16_t startAddress, std::uint16_t endAddress) const
Definition: ESI.cpp:16
armarx::control::ethercat::ESIHeader::productCode
std::uint32_t productCode
Definition: ESI.h:76
armarx::control::ethercat::ESIGeneral::identALStatus
std::bitset< 3 > identALStatus
Definition: ESI.h:120
armarx::control::ethercat::ESIHeader::standardReceiveMailboxSize
std::uint16_t standardReceiveMailboxSize
Definition: ESI.h:84
armarx::control::ethercat::ESIHandler
Brief description of class ESIHandler.
Definition: ESI.h:45
armarx::control::ethercat::ESIHeader::pdiControl
std::uint16_t pdiControl
Definition: ESI.h:69
armarx::control::ethercat::ESIData::txPDO
ESITxPDO txPDO
Definition: ESI.h:174
armarx::control::ethercat::ESIHeader::bootstrapReceiveMailboxOffset
std::uint16_t bootstrapReceiveMailboxOffset
Definition: ESI.h:79
armarx::control::ethercat::MailboxProtocols
MailboxProtocols
Definition: ESI.h:92
armarx::control::ethercat::ESIPDOObject::flags
std::uint16_t flags
Definition: ESI.h:155
armarx::control::ethercat::ESIParser::parseHeader
ESIHeader parseHeader(const std::vector< std::byte > &esiBinary)
Definition: ESI.cpp:188
armarx::control::ethercat::ESIHeader
Definition: ESI.h:67
armarx::control::ethercat::ESIGeneral::dS402Channels
std::uint8_t dS402Channels
Definition: ESI.h:114
armarx::control::ethercat::ESIParser::parseSyncM
ESISyncM parseSyncM(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset, std::uint16_t len)
Definition: ESI.cpp:275
armarx::control::ethercat::ESIPDOEntry
Definition: ESI.h:138
armarx::control::ethercat::ESIHeader::standardReceiveMailboxOffset
std::uint16_t standardReceiveMailboxOffset
Definition: ESI.h:83
armarx::control::ethercat::ESIData
Holds ESI data that can be read from slaves via SII.
Definition: ESI.h:167
armarx::control::ethercat::ESIGeneral::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:109
armarx::control::ethercat::ESIGeneral::currentOnEBus
std::int16_t currentOnEBus
Definition: ESI.h:117
armarx::control::ethercat::ESIHeader::checkSum
std::uint16_t checkSum
Definition: ESI.h:74
armarx::control::ethercat::ESIData::general
std::optional< ESIGeneral > general
Definition: ESI.h:171
armarx::control::ethercat::ESIHeader::bootstrapSendMailboxOffset
std::uint16_t bootstrapSendMailboxOffset
Definition: ESI.h:81
armarx::control::ethercat::ESIGeneral
Definition: ESI.h:104
armarx::control::ethercat::ESI_Header_StartAdress
constexpr std::uint16_t ESI_Header_StartAdress
Definition: ESI.h:35
armarx::control::ethercat::MailboxProtocols::COE
@ COE
armarx::control::ethercat::ESI_Header_EndAdress
constexpr std::uint16_t ESI_Header_EndAdress
Definition: ESI.h:36
armarx::control::ethercat::ESIStrings
std::vector< std::string > ESIStrings
Definition: ESI.h:102
armarx::control::ethercat::MailboxProtocols::AOE
@ AOE
armarx::control::ethercat::ESIParser::parsePDOs
std::vector< ESIPDOObject > parsePDOs(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset, std::uint16_t len)
Definition: ESI.cpp:300
armarx::control::ethercat::ESIPDOEntry::subIndex
std::uint8_t subIndex
Definition: ESI.h:141
armarx::control::ethercat::ESIHeader::vendorID
std::uint32_t vendorID
Definition: ESI.h:75
armarx::control::ethercat::ESIHeader::bootstrapReceiveMailboxSize
std::uint16_t bootstrapReceiveMailboxSize
Definition: ESI.h:80
armarx::control::ethercat::ESIGeneral::identPhysicalMemoryAddress
std::bitset< 4 > identPhysicalMemoryAddress
Definition: ESI.h:121
armarx::control::ethercat::ESISyncMElement::syncManagerType
std::uint8_t syncManagerType
Definition: ESI.h:133
armarx::control::ethercat::ESIPDOObject::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:154
armarx::control::ethercat
Definition: Bus.cpp:24
armarx::control::ethercat::ESISyncMElement::enableSynchManager
std::uint8_t enableSynchManager
Definition: ESI.h:132
armarx::control::ethercat::ESIParser
Definition: ESI.h:179
armarx::control::ethercat::ESIHeader::eepromSize
std::uint16_t eepromSize
Definition: ESI.h:88
armarx::control::ethercat::ESIHeader::mailboxProtocol
std::uint16_t mailboxProtocol
Definition: ESI.h:87
armarx::control::ethercat::ESIRxPDO
std::vector< ESIPDOObject > ESIRxPDO
Definition: ESI.h:160
armarx::control::ethercat::ESIGeneral::eoEDetails
std::uint8_t eoEDetails
Definition: ESI.h:112
armarx::control::ethercat::ESIParser::parseFMMU
ESIFMMU parseFMMU(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset, std::uint16_t len)
Definition: ESI.cpp:260
armarx::control::ethercat::ESISyncMElement::controlRegister
std::uint8_t controlRegister
Definition: ESI.h:130
armarx::control::ethercat::ESIPDOEntry::dataType
std::uint8_t dataType
Definition: ESI.h:143
armarx::control::ethercat::ESIGeneral::soEChannels
std::uint8_t soEChannels
Definition: ESI.h:113
armarx::control::ethercat::ESIPDOObject::pdoIndex
std::uint16_t pdoIndex
Definition: ESI.h:150
armarx::control::ethercat::ESIHeader::pdiConfiguration
std::uint16_t pdiConfiguration
Definition: ESI.h:70
armarx::control::ethercat::ESIData::fmmu
ESIFMMU fmmu
Definition: ESI.h:172
armarx::control::ethercat::ESIPDOObject
Definition: ESI.h:148
armarx::control::ethercat::ESIData::strings
ESIStrings strings
Definition: ESI.h:170
armarx::control::ethercat::ESIGeneral::orderIdx
std::uint8_t orderIdx
Definition: ESI.h:108
armarx::control::ethercat::ESIGeneral::physicalPort
std::uint16_t physicalPort
Definition: ESI.h:118
armarx::control::ethercat::ESISyncMElement
Definition: ESI.h:126
armarx::control::ethercat::ESIGeneral::foEDetails
std::uint8_t foEDetails
Definition: ESI.h:111
armarx::control::ethercat::MailboxProtocols::VOE
@ VOE
armarx::control::ethercat::ESIData::header
ESIHeader header
Definition: ESI.h:169
armarx::control::ethercat::MailboxProtocols::SOE
@ SOE
armarx::control::ethercat::ESIPDOEntry::bitLength
std::uint8_t bitLength
Definition: ESI.h:144
armarx::control::ethercat::ESIHeader::syncImpulseLen
std::uint16_t syncImpulseLen
Definition: ESI.h:71
armarx::control::ethercat::ESISyncM
std::vector< ESISyncMElement > ESISyncM
Definition: ESI.h:136
armarx::control::ethercat::ESISyncMElement::statusRegister
std::uint8_t statusRegister
Definition: ESI.h:131
armarx::control::ethercat::ESIParser::parseStrings
std::vector< std::string > parseStrings(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset)
Definition: ESI.cpp:216
armarx::control::ethercat::ESIParser::parseESI
ESIData parseESI(const std::vector< std::byte > &esiBinary)
Parse a standard-conformant binary in SII format to an ESI structure.
Definition: ESI.cpp:131
armarx::control::ethercat::ESIHeader::revisionNumber
std::uint32_t revisionNumber
Definition: ESI.h:77
armarx::control::ethercat::ESIHeader::bootstrapSendMailboxSize
std::uint16_t bootstrapSendMailboxSize
Definition: ESI.h:82
armarx::control::ethercat::ESIPDOObject::synchronization
std::uint8_t synchronization
Definition: ESI.h:153
armarx::control::ethercat::ESIPDOEntry::flags
std::uint16_t flags
Definition: ESI.h:145
armarx::control::ethercat::ESIGeneral::flags
std::uint8_t flags
Definition: ESI.h:116
armarx::control::ethercat::MailboxProtocols::EOE
@ EOE
armarx::control::ethercat::ESIGeneral::groupIdx
std::uint8_t groupIdx
Definition: ESI.h:106
armarx::control::ethercat::ESIHeader::standardSendMailboxOffset
std::uint16_t standardSendMailboxOffset
Definition: ESI.h:85
armarx::control::ethercat::ESIHeader::pdiConfiguration2
std::uint16_t pdiConfiguration2
Definition: ESI.h:72
armarx::control::ethercat::ESIGeneral::coEDetails
std::uint8_t coEDetails
Definition: ESI.h:110
armarx::control::ethercat::ESIPDOEntry::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:142
armarx::control::ethercat::ESIFMMU
std::vector< std::uint8_t > ESIFMMU
Definition: ESI.h:124