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  // TODO
61  // ------------------------------------------
62  // Following code has been copied from etherkitten and should be replaced by the original
63  // project code once etherkitten has been made a dependecy of armarx
64  // ------------------------------------------
65 
66  struct ESIHeader
67  {
68  std::uint16_t pdiControl;
69  std::uint16_t pdiConfiguration;
70  std::uint16_t syncImpulseLen;
71  std::uint16_t pdiConfiguration2;
72  std::uint16_t stationAlias;
73  std::uint16_t checkSum;
74  std::uint32_t vendorID;
75  std::uint32_t productCode;
76  std::uint32_t revisionNumber;
77  std::uint32_t serialNumber;
81  std::uint16_t bootstrapSendMailboxSize;
85  std::uint16_t standardSendMailboxSize;
86  std::uint16_t mailboxProtocol;
87  std::uint16_t eepromSize;
88  std::uint16_t version;
89  };
90 
91  enum class MailboxProtocols
92  {
93  AOE = 0x1,
94  EOE = 0x2,
95  COE = 0x4,
96  FOE = 0x8,
97  SOE = 0x10,
98  VOE = 0x20,
99  };
100 
101  using ESIStrings = std::vector<std::string>;
102 
103  struct ESIGeneral
104  {
105  std::uint8_t groupIdx;
106  std::uint8_t imgIdx;
107  std::uint8_t orderIdx;
108  std::uint8_t nameIdx;
109  std::uint8_t coEDetails;
110  std::uint8_t foEDetails;
111  std::uint8_t eoEDetails;
112  std::uint8_t soEChannels;
113  std::uint8_t dS402Channels;
114  std::uint8_t sysmanClass;
115  std::uint8_t flags;
116  std::int16_t currentOnEBus;
117  std::uint16_t physicalPort;
118  std::uint16_t physicalMemoryAddress;
119  std::bitset<3> identALStatus;
121  };
122 
123  using ESIFMMU = std::vector<std::uint8_t>;
124 
126  {
127  std::uint16_t physicalStartAddress;
128  std::uint16_t length;
129  std::uint8_t controlRegister;
130  std::uint8_t statusRegister;
131  std::uint8_t enableSynchManager;
132  std::uint8_t syncManagerType;
133  };
134 
135  using ESISyncM = std::vector<ESISyncMElement>;
136 
137  struct ESIPDOEntry
138  {
139  std::uint16_t index;
140  std::uint8_t subIndex;
141  std::uint8_t nameIdx;
142  std::uint8_t dataType;
143  std::uint8_t bitLength;
144  std::uint16_t flags;
145  };
146 
148  {
149  std::uint16_t pdoIndex;
150  std::uint8_t entryCount;
151  std::uint8_t syncManager;
152  std::uint8_t synchronization;
153  std::uint8_t nameIdx;
154  std::uint16_t flags;
155  std::vector<ESIPDOEntry> entries;
156  };
157 
158  using ESITxPDO = std::vector<ESIPDOObject>;
159  using ESIRxPDO = std::vector<ESIPDOObject>;
160 
161  /*!
162  * \brief Holds ESI data that can be read from slaves via SII.
163  *
164  * For details regarding contents and structure, see ETG1000.6.
165  */
166  struct ESIData
167  {
170  std::optional<ESIGeneral> general;
175  };
176 
177  class ESIParser
178  {
179  public:
180  ESIHeader parseHeader(const std::vector<std::byte>& esiBinary);
181 
182  std::vector<std::string> parseStrings(const std::vector<std::byte>& esiBinary,
183  std::uint16_t wordOffset);
184 
185  ESIGeneral parseGeneral(const std::vector<std::byte>& esiBinary, std::uint16_t wordOffset);
186 
187  ESIFMMU parseFMMU(const std::vector<std::byte>& esiBinary,
188  std::uint16_t wordOffset,
189  std::uint16_t len);
190 
191  ESISyncM parseSyncM(const std::vector<std::byte>& esiBinary,
192  std::uint16_t wordOffset,
193  std::uint16_t len);
194 
195  std::vector<ESIPDOObject> parsePDOs(const std::vector<std::byte>& esiBinary,
196  std::uint16_t wordOffset,
197  std::uint16_t len);
198 
199  /*!
200  * \brief Parse a standard-conformant binary in SII format to an ESI structure.
201  *
202  * See ETG1000.6 for the SII specification.
203  * \param esiBinary the binary SII to parse
204  * \return the parsed ESI data structure
205  * \exception ParseException iff esiBinary is not standard-conformant
206  */
207  ESIData parseESI(const std::vector<std::byte>& esiBinary);
208  };
209 
210 } // namespace armarx::control::ethercat
armarx::control::ethercat::ESIHeader::stationAlias
std::uint16_t stationAlias
Definition: ESI.h:72
armarx::control::ethercat::ESISyncMElement::length
std::uint16_t length
Definition: ESI.h:128
armarx::control::ethercat::ESITxPDO
std::vector< ESIPDOObject > ESITxPDO
Definition: ESI.h:158
armarx::control::ethercat::ESIParser::parseGeneral
ESIGeneral parseGeneral(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset)
Definition: ESI.cpp:237
armarx::control::ethercat::ESIHeader::serialNumber
std::uint32_t serialNumber
Definition: ESI.h:77
armarx::control::ethercat::ESISyncMElement::physicalStartAddress
std::uint16_t physicalStartAddress
Definition: ESI.h:127
armarx::control::ethercat::ESIPDOEntry::index
std::uint16_t index
Definition: ESI.h:139
armarx::control::ethercat::ESIGeneral::sysmanClass
std::uint8_t sysmanClass
Definition: ESI.h:114
armarx::control::ethercat::ESIHeader::standardSendMailboxSize
std::uint16_t standardSendMailboxSize
Definition: ESI.h:85
armarx::control::ethercat::ESIPDOObject::entryCount
std::uint8_t entryCount
Definition: ESI.h:150
armarx::control::ethercat::ESIGeneral::physicalMemoryAddress
std::uint16_t physicalMemoryAddress
Definition: ESI.h:118
armarx::control::ethercat::ESIData::rxPDO
ESIRxPDO rxPDO
Definition: ESI.h:174
armarx::control::ethercat::ESIGeneral::imgIdx
std::uint8_t imgIdx
Definition: ESI.h:106
armarx::control::ethercat::ESIPDOObject::syncManager
std::uint8_t syncManager
Definition: ESI.h:151
armarx::control::ethercat::ESIHeader::version
std::uint16_t version
Definition: ESI.h:88
armarx::control::ethercat::MailboxProtocols::FOE
@ FOE
armarx::control::ethercat::ESIPDOObject::entries
std::vector< ESIPDOEntry > entries
Definition: ESI.h:155
armarx::control::ethercat::ESIData::syncM
ESISyncM syncM
Definition: ESI.h:172
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:75
armarx::control::ethercat::ESIGeneral::identALStatus
std::bitset< 3 > identALStatus
Definition: ESI.h:119
armarx::control::ethercat::ESIHeader::standardReceiveMailboxSize
std::uint16_t standardReceiveMailboxSize
Definition: ESI.h:83
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:68
armarx::control::ethercat::ESIData::txPDO
ESITxPDO txPDO
Definition: ESI.h:173
armarx::control::ethercat::ESIHeader::bootstrapReceiveMailboxOffset
std::uint16_t bootstrapReceiveMailboxOffset
Definition: ESI.h:78
armarx::control::ethercat::MailboxProtocols
MailboxProtocols
Definition: ESI.h:91
armarx::control::ethercat::ESIPDOObject::flags
std::uint16_t flags
Definition: ESI.h:154
armarx::control::ethercat::ESIParser::parseHeader
ESIHeader parseHeader(const std::vector< std::byte > &esiBinary)
Definition: ESI.cpp:187
armarx::control::ethercat::ESIHeader
Definition: ESI.h:66
armarx::control::ethercat::ESIGeneral::dS402Channels
std::uint8_t dS402Channels
Definition: ESI.h:113
armarx::control::ethercat::ESIParser::parseSyncM
ESISyncM parseSyncM(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset, std::uint16_t len)
Definition: ESI.cpp:274
armarx::control::ethercat::ESIPDOEntry
Definition: ESI.h:137
armarx::control::ethercat::ESIHeader::standardReceiveMailboxOffset
std::uint16_t standardReceiveMailboxOffset
Definition: ESI.h:82
armarx::control::ethercat::ESIData
Holds ESI data that can be read from slaves via SII.
Definition: ESI.h:166
armarx::control::ethercat::ESIGeneral::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:108
armarx::control::ethercat::ESIGeneral::currentOnEBus
std::int16_t currentOnEBus
Definition: ESI.h:116
armarx::control::ethercat::ESIHeader::checkSum
std::uint16_t checkSum
Definition: ESI.h:73
armarx::control::ethercat::ESIData::general
std::optional< ESIGeneral > general
Definition: ESI.h:170
armarx::control::ethercat::ESIHeader::bootstrapSendMailboxOffset
std::uint16_t bootstrapSendMailboxOffset
Definition: ESI.h:80
armarx::control::ethercat::ESIGeneral
Definition: ESI.h:103
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:101
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:299
armarx::control::ethercat::ESIPDOEntry::subIndex
std::uint8_t subIndex
Definition: ESI.h:140
armarx::control::ethercat::ESIHeader::vendorID
std::uint32_t vendorID
Definition: ESI.h:74
armarx::control::ethercat::ESIHeader::bootstrapReceiveMailboxSize
std::uint16_t bootstrapReceiveMailboxSize
Definition: ESI.h:79
armarx::control::ethercat::ESIGeneral::identPhysicalMemoryAddress
std::bitset< 4 > identPhysicalMemoryAddress
Definition: ESI.h:120
armarx::control::ethercat::ESISyncMElement::syncManagerType
std::uint8_t syncManagerType
Definition: ESI.h:132
armarx::control::ethercat::ESIPDOObject::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:153
armarx::control::ethercat
Definition: Bus.cpp:24
armarx::control::ethercat::ESISyncMElement::enableSynchManager
std::uint8_t enableSynchManager
Definition: ESI.h:131
armarx::control::ethercat::ESIParser
Definition: ESI.h:177
armarx::control::ethercat::ESIHeader::eepromSize
std::uint16_t eepromSize
Definition: ESI.h:87
armarx::control::ethercat::ESIHeader::mailboxProtocol
std::uint16_t mailboxProtocol
Definition: ESI.h:86
armarx::control::ethercat::ESIRxPDO
std::vector< ESIPDOObject > ESIRxPDO
Definition: ESI.h:159
armarx::control::ethercat::ESIGeneral::eoEDetails
std::uint8_t eoEDetails
Definition: ESI.h:111
armarx::control::ethercat::ESIParser::parseFMMU
ESIFMMU parseFMMU(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset, std::uint16_t len)
Definition: ESI.cpp:259
armarx::control::ethercat::ESISyncMElement::controlRegister
std::uint8_t controlRegister
Definition: ESI.h:129
armarx::control::ethercat::ESIPDOEntry::dataType
std::uint8_t dataType
Definition: ESI.h:142
armarx::control::ethercat::ESIGeneral::soEChannels
std::uint8_t soEChannels
Definition: ESI.h:112
armarx::control::ethercat::ESIPDOObject::pdoIndex
std::uint16_t pdoIndex
Definition: ESI.h:149
armarx::control::ethercat::ESIHeader::pdiConfiguration
std::uint16_t pdiConfiguration
Definition: ESI.h:69
armarx::control::ethercat::ESIData::fmmu
ESIFMMU fmmu
Definition: ESI.h:171
armarx::control::ethercat::ESIPDOObject
Definition: ESI.h:147
armarx::control::ethercat::ESIData::strings
ESIStrings strings
Definition: ESI.h:169
armarx::control::ethercat::ESIGeneral::orderIdx
std::uint8_t orderIdx
Definition: ESI.h:107
armarx::control::ethercat::ESIGeneral::physicalPort
std::uint16_t physicalPort
Definition: ESI.h:117
armarx::control::ethercat::ESISyncMElement
Definition: ESI.h:125
armarx::control::ethercat::ESIGeneral::foEDetails
std::uint8_t foEDetails
Definition: ESI.h:110
armarx::control::ethercat::MailboxProtocols::VOE
@ VOE
armarx::control::ethercat::ESIData::header
ESIHeader header
Definition: ESI.h:168
armarx::control::ethercat::MailboxProtocols::SOE
@ SOE
armarx::control::ethercat::ESIPDOEntry::bitLength
std::uint8_t bitLength
Definition: ESI.h:143
armarx::control::ethercat::ESIHeader::syncImpulseLen
std::uint16_t syncImpulseLen
Definition: ESI.h:70
armarx::control::ethercat::ESISyncM
std::vector< ESISyncMElement > ESISyncM
Definition: ESI.h:135
armarx::control::ethercat::ESISyncMElement::statusRegister
std::uint8_t statusRegister
Definition: ESI.h:130
armarx::control::ethercat::ESIParser::parseStrings
std::vector< std::string > parseStrings(const std::vector< std::byte > &esiBinary, std::uint16_t wordOffset)
Definition: ESI.cpp:215
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:130
armarx::control::ethercat::ESIHeader::revisionNumber
std::uint32_t revisionNumber
Definition: ESI.h:76
armarx::control::ethercat::ESIHeader::bootstrapSendMailboxSize
std::uint16_t bootstrapSendMailboxSize
Definition: ESI.h:81
armarx::control::ethercat::ESIPDOObject::synchronization
std::uint8_t synchronization
Definition: ESI.h:152
armarx::control::ethercat::ESIPDOEntry::flags
std::uint16_t flags
Definition: ESI.h:144
armarx::control::ethercat::ESIGeneral::flags
std::uint8_t flags
Definition: ESI.h:115
armarx::control::ethercat::MailboxProtocols::EOE
@ EOE
armarx::control::ethercat::ESIGeneral::groupIdx
std::uint8_t groupIdx
Definition: ESI.h:105
armarx::control::ethercat::ESIHeader::standardSendMailboxOffset
std::uint16_t standardSendMailboxOffset
Definition: ESI.h:84
armarx::control::ethercat::ESIHeader::pdiConfiguration2
std::uint16_t pdiConfiguration2
Definition: ESI.h:71
armarx::control::ethercat::ESIGeneral::coEDetails
std::uint8_t coEDetails
Definition: ESI.h:109
armarx::control::ethercat::ESIPDOEntry::nameIdx
std::uint8_t nameIdx
Definition: ESI.h:141
armarx::control::ethercat::ESIFMMU
std::vector< std::uint8_t > ESIFMMU
Definition: ESI.h:123