Motion Master
Loading...
Searching...
No Matches
soem.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <functional>
6#include <map>
7#include <memory>
8#include <mutex>
9#include <sstream>
10#include <string>
11#include <type_traits>
12#include <unordered_map>
13#include <utility>
14#include <variant>
15#include <vector>
16
17#include <tl/expected.hpp>
18
19#include "base.h"
20#include "ethercat.h"
21#include "loguru.h"
22
23namespace mm::comm::soem {
24
25// 3-second SDO read/write timeout — long enough for devices with slower mailbox
26// implementations.
27inline constexpr int kSdoTimeoutUs = 3'000'000;
28
29// 10-second FoE write timeout — covers large firmware files over slow links.
30inline constexpr int kFoeTimeoutUs = 10'000'000;
31
32// 6-second FoE read timeout. A SOMANET bootloader can take several seconds to
33// answer a read, and 6 s is the timeout known to work on such drives. A read
34// given up too early fails on every attempt, because each attempt starts the
35// read again after the abort (see abortFoeTransfer). The full wait is spent
36// only when the device does not answer.
37inline constexpr int kFoeReadTimeoutUs = 6'000'000;
38
39// 100-millisecond wait for the answer to an FoE abort. The device's EtherCAT
40// stack answers an abort itself, without involving the file system.
41inline constexpr int kFoeAbortReplyTimeoutUs = 100'000;
42
43// 10-second timeout for a file removal ("fs-remove=<name>" issued as an FoE
44// read). Removing a file erases flash, which can take several seconds — much
45// longer than reading one back.
46inline constexpr int kFoeRemoveTimeoutUs = 10'000'000;
47
48// 30-second timeout for removing the ESI file. It is large and its erase takes
49// considerably longer than other files (measured at ~17 s on a SOMANET drive).
50inline constexpr int kFoeRemoveEsiTimeoutUs = 30'000'000;
51
71std::recursive_mutex& controlPlaneMutex();
72
93std::string drainMailboxErrors(ecx_contextt* context);
94
120int drainMailbox(ecx_contextt* context, uint16_t slave);
121
132std::vector<uint8_t> makeFoeAbortRequest(uint8_t counter);
133
153void abortFoeTransfer(ecx_contextt* context, uint16_t slave);
154
175bool isTransientFoeFailure(int wkc);
176
187std::string describeFoeFailure(int wkc);
188
200std::map<std::string, std::string> mapMacAddressesToInterfaces();
201
212 bool loaded = false;
217 std::vector<std::string> devices;
218
221 [[nodiscard]] bool isConfiguredFor(const std::string& macAddress) const;
222};
223
235 const std::string& moduleDirectory = "/sys/module/ec_master");
236
252inline std::string uiConfigWithDefaultPdoMapping = R"(
253{
254 "pdoMapping": {
255 "rx": {
256 "0x1600": [
257 "0x60400010",
258 "0x60600008",
259 "0x60710010",
260 "0x607a0020",
261 "0x60ff0020",
262 "0x60b20010",
263 "0x27010020"
264 ],
265 "0x1601": [
266 "0x60fe0120",
267 "0x60fe0220"
268 ],
269 "0x1602": [
270 "0x27030020",
271 "0x60b10020",
272 "0x20120120"
273 ]
274 },
275 "tx": {
276 "0x1a00": [
277 "0x60410010",
278 "0x60610008",
279 "0x60640020",
280 "0x606c0020",
281 "0x60770010",
282 "0x60f40020",
283 "0x21110220",
284 "0x21130220"
285 ],
286 "0x1a01": [
287 "0x24010010",
288 "0x24020010",
289 "0x24030010",
290 "0x24040010",
291 "0x27020020"
292 ],
293 "0x1a02": [
294 "0x60fd0020"
295 ],
296 "0x1a03": [
297 "0x27040020",
298 "0x20f00020",
299 "0x60fc0020",
300 "0x606b0020",
301 "0x60740010",
302 "0x60790020"
303 ]
304 }
305 }
306})";
307
334int setPdoMappingFromUiConfig(ecx_contextt* context, uint16 slave);
335
353void checkPdoMapping(ecx_contextt* context, uint16 slave);
354
374uint16_t getSlaveState(ecx_contextt* context, uint16_t slave,
375 int timeoutUs = EC_TIMEOUTRET);
376
396bool isSlaveAnswering(ecx_contextt* context, uint16_t slave);
397
421
424 uint16_t value = 0;
426 uint16_t expected = 0;
427
429 [[nodiscard]] std::string describe() const;
430};
431
443 ecx_contextt* context, uint16_t slave, int timeoutUs = EC_TIMEOUTRET);
444
464std::string convertSlaveStateToString(int state);
465
488void updateMailboxSyncManagersOnNextState(ecx_contextt* context, uint16_t slave,
489 int targetState);
490
505
527bool resetMailboxCounter(ecx_contextt* context, uint16_t slave);
528
544void configureDetectedSmmModule(ecx_contextt* context, uint16_t slave);
545
583void transitionSlaves(ecx_contextt* context,
584 const std::vector<uint16_t>& positions,
585 uint16_t requiredState, uint16_t targetState,
586 const char* targetName,
587 std::chrono::steady_clock::duration timeout,
588 std::chrono::steady_clock::duration resendInterval =
589 std::chrono::seconds(2),
590 std::function<void()> tick = nullptr,
591 std::function<bool()> shouldAbort = nullptr);
592
605bool setSlaveState(
606 ecx_contextt* context, uint16_t slave, uint16_t targetState,
607 std::chrono::steady_clock::duration timeout = std::chrono::seconds(5));
608
642std::vector<uint8_t> readSii(ecx_contextt* context, uint16 position);
643
655mm::comm::base::PdoMappings readPdoMappings(ecx_contextt* context,
656 uint16_t slave);
657
673 const std::vector<mm::comm::base::PdoMappingEntry>& entries);
674
686void logIoMap(uint8_t* ioMap, size_t totalBytes);
687
702struct Fieldbus {
703 ecx_contextt context;
704 std::string iface;
705 uint8 group;
707
708 /* Used by the context */
709 uint8 map[4096];
710 ecx_portt port;
711 ec_slavet slavelist[EC_MAXSLAVE];
713 ec_groupt grouplist[EC_MAXGROUP];
714 uint8 esibuf[EC_MAXEEPBUF];
715 uint32 esimap[EC_MAXEEPBITMAP];
716 ec_eringt elist;
717 ec_idxstackT idxstack;
718 boolean ecaterror;
719 int64 DCtime;
720 ec_SMcommtypet SMcommtype[EC_MAX_MAPT];
721 ec_PDOassignt PDOassign[EC_MAX_MAPT];
722 ec_PDOdesct PDOdesc[EC_MAX_MAPT];
723 ec_eepromSMt eepSM;
724 ec_eepromFMMUt eepFMMU;
725};
726
741 uint16_t readLength;
742
749 uint16_t readOffset;
750
762
769 uint16_t writeLength;
770
777 uint16_t writeOffset;
778};
779
781 supportedProtocols, writeLength, writeOffset)
782
783
790struct SlaveInfoSyncManager {
799 uint32_t flags;
800
807 uint16_t length;
808
814 uint16_t startAddress;
815
826 uint8_t type;
827};
828
829NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfoSyncManager, flags, length,
830 startAddress, type)
831
832
839struct SlaveInfoFmmu {
845 uint8_t active;
846
853 uint8_t logicalEndBit;
854
861 uint8_t logicalStartBit;
862
868 uint32_t logicalStartAddress;
869
875 uint16_t logicalLength;
876
883 uint8_t physicalStartBit;
884
890 uint16_t physicalStartAddress;
891
898 uint8_t type;
899};
900
901NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfoFmmu, active, logicalEndBit,
902 logicalStartBit, logicalStartAddress,
903 logicalLength, physicalStartBit,
904 physicalStartAddress, type)
905
906
912struct SlaveInfo {
919 uint16_t alStatusCode;
920
927 uint16_t aliasAddress;
928
934 std::vector<SlaveInfoFmmu> fmmus;
935
942 SlaveInfoMailbox mailbox;
943
951 uint32_t productCode;
952
958 uint32_t position;
959
967 uint32_t revisionNumber;
968
975 std::vector<SlaveInfoSyncManager> syncManagers;
976
982 std::string name;
983
992 uint32_t vendorId;
993};
994
995NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfo, alStatusCode, aliasAddress, fmmus,
996 mailbox, productCode, position,
997 revisionNumber, syncManagers, name, vendorId)
998
999
1011SlaveInfo getSlaveInfo(ecx_contextt* context, uint16 position);
1012
1029void logSlaveInfo(ecx_contextt* context, uint16 position);
1030
1048void initFieldbus(std::unique_ptr<Fieldbus>& fieldbus,
1049 const std::string& iface);
1050
1055class Slave {
1056 public:
1067 explicit Slave(ecx_contextt& context, uint16_t position);
1068
1077 uint16_t position() const;
1078
1087 uint32_t vendorId() const;
1088
1097 uint32_t productCode() const;
1098
1107 uint32_t revisionNumber() const;
1108
1114 int getState() const;
1115
1135 bool setState(int targetState, int timeoutMs = 0, int intervalMs = 100);
1136
1158 tl::expected<void, std::string> loadParameters(bool readValues = false);
1159
1172 void logParameters() const;
1173
1190
1207
1214 void clearParameters();
1215
1224 std::unordered_map<mm::comm::base::Parameter::Address,
1226 parametersMap();
1227
1240 mm::comm::base::Parameter& findParameter(uint16_t index, uint8_t subindex);
1241
1269 template <typename T = std::vector<uint8_t>>
1270 T upload(uint16_t index, uint8_t subindex, bool refresh = true) {
1271 std::lock_guard<std::recursive_mutex> lock(controlPlaneMutex());
1272
1273 // Check if the device is in a valid state for uploading
1274 auto state = context_.slavelist[position_].state;
1275 if (state == EC_STATE_INIT || state == EC_STATE_BOOT) {
1276 throw std::runtime_error(
1277 "To upload object dictionary entries, the device must be in the (2) "
1278 "PRE-OPERATIONAL, (4) SAFE-OPERATIONAL, or (8) OPERATIONAL state. "
1279 "The current state is " +
1280 convertSlaveStateToString(state) + ".");
1281 }
1282
1283 // Find the previously loaded parameter
1284 auto& parameter = findParameter(index, subindex);
1285
1286 // Refresh data if needed (SDO read)
1287 if (refresh) {
1288 const std::unique_ptr<std::uint8_t[]> data =
1289 std::make_unique<std::uint8_t[]>(parameter.byteLength);
1290 auto wkc =
1291 ecx_SDOread(&context_, position_, parameter.index, parameter.subindex,
1292 false, &parameter.byteLength, data.get(), kSdoTimeoutUs);
1293 if (wkc <= 0) {
1294 LOG_F(ERROR, "Device %d: SDO read failed for %#04x:%02x! WKC: %d",
1295 position_, parameter.index, parameter.subindex, wkc);
1296 auto id = mm::comm::base::makeParameterId(parameter.index,
1297 parameter.subindex);
1298 throw std::runtime_error("Device " + std::to_string(position_) +
1299 ": SDO read failed for " + id +
1300 "! WKC: " + std::to_string(wkc));
1301 } else {
1302 std::vector<uint8_t> receivedData(data.get(),
1303 data.get() + parameter.byteLength);
1304 if (!parameter.trySetValue(receivedData)) {
1305 LOG_F(ERROR,
1306 "Device %d: Failed to set the value of parameter %#04x:%02x!",
1307 position_, parameter.index, parameter.subindex);
1308 }
1309 }
1310 }
1311
1312 // Return the appropriate type
1313 if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
1314 return parameter.data; // parameter.data should be std::vector<uint8_t>
1315 } else {
1316 // Otherwise, try to get the value as the requested type T
1317 auto value = parameter.getValue();
1318 if (auto ptr = std::get_if<T>(&value)) {
1319 return *ptr;
1320 } else {
1321 throw std::bad_variant_access(); // Type mismatch
1322 }
1323 }
1324 }
1325
1350 template <typename T = std::vector<uint8_t>>
1351 bool download(uint16_t index, uint8_t subindex, const T& value) {
1352 std::lock_guard<std::recursive_mutex> lock(controlPlaneMutex());
1353
1354 // Check if device is in valid state for download
1355 auto state = context_.slavelist[position_].state;
1356 if (state == EC_STATE_INIT || state == EC_STATE_BOOT) {
1357 throw std::runtime_error(
1358 "To download object dictionary entries, the device must be in the "
1359 "(2) PRE-OPERATIONAL, (4) SAFE-OPERATIONAL, or (8) OPERATIONAL "
1360 "state. The current state is " +
1361 convertSlaveStateToString(state) + ".");
1362 }
1363
1364 auto& parameter = findParameter(index, subindex);
1365
1366 // Convert value to raw byte data
1367 std::vector<uint8_t> data;
1368 if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
1369 data = value;
1370 } else {
1371 // Set the value in the parameter model
1372 if (!parameter.trySetValue(value)) {
1373 LOG_F(ERROR,
1374 "Device %d: Failed to set the value of parameter %#04x:%02x!",
1375 position_, parameter.index, parameter.subindex);
1376 return false;
1377 }
1378 data = parameter.data; // Use the parameter's byte representation
1379 }
1380
1381 // Check if data size matches the expected parameter size
1382 if (data.size() != parameter.byteLength) {
1383 LOG_F(ERROR, "Data size mismatch: expected %d, got %zu",
1384 parameter.byteLength, data.size());
1385 throw std::runtime_error("Data size does not match the parameter size!");
1386 }
1387
1388 // Perform the SDO write
1389 auto wkc =
1390 ecx_SDOwrite(&context_, position_, parameter.index, parameter.subindex,
1391 false, parameter.byteLength, data.data(), kSdoTimeoutUs);
1392
1393 // Check write result
1394 if (wkc <= 0) {
1395 LOG_F(ERROR, "Device %d: SDO write failed for %#04x:%02x! WKC: %d",
1396 position_, parameter.index, parameter.subindex, wkc);
1397 return false;
1398 }
1399
1400 return true;
1401 }
1402
1412
1421 void updatePdoMappings();
1422
1434 void logPdoMappings() const;
1435
1441 mm::comm::base::PdoMappings& getPdoMappings();
1442
1465 void updateOutputs();
1466
1488 void updateParametersFromInputs();
1489
1517 tl::expected<std::vector<uint8_t>, std::string> readFile(
1518 const std::string& filename,
1519 size_t maxFileSize = 1 * 1024 * 1024, // 1 MB default max file size
1520 int retries = 3,
1521 std::chrono::steady_clock::duration retryWait =
1522 std::chrono::milliseconds(100));
1523
1537 tl::expected<std::vector<std::uint8_t>, std::string> readSdo(
1538 uint16_t index, uint8_t subindex);
1539
1553 tl::expected<ec_ODlistt, std::string> readODList(
1554 int retries = 5, std::chrono::steady_clock::duration retryWait =
1555 std::chrono::milliseconds(100));
1556
1575 tl::expected<void, std::string> readODDescription(
1576 uint16_t item, ec_ODlistt& odList, int retries = 5,
1577 std::chrono::steady_clock::duration retryWait =
1578 std::chrono::milliseconds(100));
1579
1596 tl::expected<ec_OElistt, std::string> readOE(
1597 uint16_t item, ec_ODlistt& odList, int retries = 5,
1598 std::chrono::steady_clock::duration retryWait =
1599 std::chrono::milliseconds(100));
1600
1601 private:
1602 ecx_contextt& context_;
1603 const uint16_t position_;
1606 std::unordered_map<mm::comm::base::Parameter::Address,
1608 parametersMap_;
1611 pdoMappings_;
1612};
1613
1614class Master {
1615 public:
1622 explicit Master();
1623
1634 explicit Master(const std::string& iface);
1635
1687 void init(const std::string& iface);
1688
1699 void deinit();
1700
1707 ~Master();
1708
1718 Fieldbus& getFieldbus() const;
1719
1728 std::string getInterfaceName() const;
1729
1738 size_t getIoMapSize() const;
1739
1802 tl::expected<int, std::string> initSlaves();
1803
1815 const std::vector<std::unique_ptr<Slave>>& slaves() const;
1816
1826 inline int expectedWkc() const {
1827 return fieldbus_->context.grouplist[fieldbus_->group].outputsWKC * 2 +
1828 fieldbus_->context.grouplist[fieldbus_->group].inputsWKC;
1829 }
1830
1840 int roundtrip();
1841
1871
1882 bool start();
1883
1884 private:
1898 std::unique_ptr<Fieldbus> fieldbus_;
1899
1911 std::vector<std::unique_ptr<Slave>> slaves_;
1912};
1913}; // namespace mm::comm::soem
Represents a device parameter identified by index and subindex.
Definition base.h:529
std::pair< uint16_t, uint8_t > Address
Alias for a pair of uint16_t and uint8_t representing a parameter address.
Definition base.h:539
int roundtrip()
Performs a complete send/receive process data cycle on the fieldbus.
Definition soem.cc:2062
Master()
Default constructor for the Master class.
Definition soem.cc:1979
const std::vector< std::unique_ptr< Slave > > & slaves() const
Returns a reference to the list of slaves.
Definition soem.cc:2058
tl::expected< int, std::string > initSlaves()
Initializes the slave devices on the EtherCAT network.
Definition soem.cc:2031
void exchangeProcessDataAndUpdateParameters()
Exchanges process data with slaves and updates parameters based on the response.
Definition soem.cc:2067
size_t getIoMapSize() const
Returns the total size of the I/O map for the current group.
Definition soem.cc:2026
Fieldbus & getFieldbus() const
Returns a reference to the Fieldbus instance.
Definition soem.cc:2022
void init(const std::string &iface)
Initializes the fieldbus using the specified network interface.
Definition soem.cc:1986
std::string getInterfaceName() const
Retrieves the interface name used by the fieldbus.
Definition soem.cc:2024
void deinit()
Deinitializes the fieldbus and releases associated resources.
Definition soem.cc:2004
bool start()
Initializes and starts the fieldbus master.
Definition soem.cc:2090
~Master()
Destructor for the Master class.
Definition soem.cc:2020
int expectedWkc() const
Calculates the expected working counter (WKC) for the current fieldbus group.
Definition soem.h:1826
uint32_t productCode() const
Gets the Product Code of the slave device.
Definition soem.cc:1435
uint32_t vendorId() const
Gets the Vendor ID of the slave device.
Definition soem.cc:1431
std::unordered_map< mm::comm::base::Parameter::Address, mm::comm::base::Parameter > & parametersMap()
Returns a reference to the internal parameters map.
Definition soem.cc:1749
mm::comm::base::Parameter & findParameter(uint16_t index, uint8_t subindex)
Finds and returns a reference to a Parameter in the parameters map.
Definition soem.cc:1753
uint32_t revisionNumber() const
Gets the Revision Number of the slave device.
Definition soem.cc:1439
T upload(uint16_t index, uint8_t subindex, bool refresh=true)
Uploads a parameter value from the device's object dictionary.
Definition soem.h:1270
tl::expected< void, std::string > loadParameters(bool readValues=false)
Loads the parameters (object dictionary entries) from the EtherCAT slave device.
Definition soem.cc:1561
void clearParameters()
Clears all loaded object dictionary parameters.
Definition soem.cc:1745
void logTxPdoMappedParameters()
Logs all mapped TxPDO parameters with their current values.
Definition soem.cc:1730
Slave(ecx_contextt &context, uint16_t position)
Constructs a Slave object with a given context and position.
Definition soem.cc:1426
void logRxPdoMappedParameters()
Logs all mapped RxPDO parameters with their current values.
Definition soem.cc:1715
bool setState(int targetState, int timeoutMs=0, int intervalMs=100)
Attempts to set the slave to the specified EtherCAT state and optionally waits until it is reached.
Definition soem.cc:1445
void logParameters() const
Logs all loaded object dictionary parameters.
Definition soem.cc:1709
int getState() const
Reads the current state of the slave directly from the device.
Definition soem.cc:1443
uint16_t position() const
Gets the position of the slave.
Definition soem.cc:1429
bool download(uint16_t index, uint8_t subindex, const T &value)
Downloads a value to the specified object dictionary entry via SDO.
Definition soem.h:1351
uint8_t type
Definition co_dictionary.h:1
const char ** name
Definition co_dictionary.h:7
uint8_t * value
Definition co_dictionary.h:9
uint16_t index
Definition co_dictionary.h:0
std::string makeParameterId(int index, int subindex)
Formats the given index and subindex into a parameter identifier string.
Definition base.h:1657
Definition soem.cc:44
constexpr int kFoeReadTimeoutUs
Definition soem.h:37
IghMasterModule readIghMasterModule(const std::string &moduleDirectory)
Reads the IgH EtherCAT Master kernel module's state from sysfs.
Definition soem.cc:351
mm::comm::base::PdoMappings readPdoMappings(ecx_contextt *context, uint16_t slave)
Read and parse all mapped PDO entries for a given slave.
Definition soem.cc:1324
std::vector< uint8_t > makeFoeAbortRequest(uint8_t counter)
Builds an FoE ERROR request, which aborts a slave's FoE transfer.
Definition soem.cc:137
std::string describeFoeFailure(int wkc)
Describes the value a failed FoE transfer returned, for a log line.
Definition soem.cc:200
constexpr int kFoeTimeoutUs
Definition soem.h:30
void logPdoMappingEntries(const std::vector< mm::comm::base::PdoMappingEntry > &entries)
Logs PDO mapping entries grouped by PDO index.
Definition soem.cc:1395
uint16_t getSlaveState(ecx_contextt *context, uint16_t slave, int timeoutUs)
Reads the current state of a specific EtherCAT slave directly from the device via an FPRD datagram.
Definition soem.cc:813
std::string convertSlaveStateToString(int state)
Converts a numeric EtherCAT state value into a human-readable string.
Definition soem.cc:891
void resetBootMailboxTracking()
Clears the internal record of which slaves hold BOOT-sized mailbox sync managers.
Definition soem.cc:929
bool isTransientFoeFailure(int wkc)
Tells whether a failed FoE transfer is worth another attempt.
Definition soem.cc:194
constexpr int kSdoTimeoutUs
Definition soem.h:27
std::string drainMailboxErrors(ecx_contextt *context)
Empties SOEM's error list and describes the first entry found.
Definition soem.cc:57
void abortFoeTransfer(ecx_contextt *context, uint16_t slave)
Aborts the FoE transfer a slave may still have in progress.
Definition soem.cc:168
void transitionSlaves(ecx_contextt *context, const std::vector< uint16_t > &positions, uint16_t requiredState, uint16_t targetState, const char *targetName, std::chrono::steady_clock::duration timeout, std::chrono::steady_clock::duration resendInterval, std::function< void()> tick, std::function< bool()> shouldAbort)
Transitions multiple EtherCAT slaves to a target state using a single-threaded fire-then-poll pattern...
Definition soem.cc:972
std::string uiConfigWithDefaultPdoMapping
Default UI configuration used for PDO mapping.
Definition soem.h:252
void initFieldbus(std::unique_ptr< Fieldbus > &fieldbus, const std::string &iface)
Initializes a Fieldbus instance for EtherCAT communication.
Definition soem.cc:1946
void updateMailboxSyncManagersOnNextState(ecx_contextt *context, uint16_t slave, int targetState)
Updates the mailbox and sync manager (SM) configurations for an EtherCAT slave when transitioning to ...
Definition soem.cc:1106
bool isSlaveAnswering(ecx_contextt *context, uint16_t slave)
Tells whether a slave still answers at its configured station address.
Definition soem.cc:828
void logIoMap(uint8_t *ioMap, size_t totalBytes)
Logs the I/O map as a formatted hexadecimal string.
Definition soem.cc:1416
void checkPdoMapping(ecx_contextt *context, uint16 slave)
Diagnoses and prints the PDO mapping for a given slave.
Definition soem.cc:729
void configureDetectedSmmModule(ecx_contextt *context, uint16_t slave)
Reads the detected SMM module ID from the slave device and configures the module identification objec...
Definition soem.cc:1236
constexpr int kFoeRemoveTimeoutUs
Definition soem.h:46
int drainMailbox(ecx_contextt *context, uint16_t slave)
Discards whatever is sitting in a slave's read mailbox.
Definition soem.cc:103
std::map< std::string, std::string > mapMacAddressesToInterfaces()
Maps MAC addresses to their corresponding network interface names.
Definition soem.cc:219
int setPdoMappingFromUiConfig(ecx_contextt *context, uint16 slave)
Sets PDO mapping for a specified EtherCAT slave using UI configuration.
Definition soem.cc:528
uint16 position
Definition soem.h:1011
void logSlaveInfo(ecx_contextt *context, uint16 position)
Logs detailed information about a specific EtherCAT slave in JSON format.
Definition soem.cc:435
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfoMailbox, readLength, readOffset, supportedProtocols, writeLength, writeOffset) struct SlaveInfoSyncManager
Information about a slave's Sync Manager (SM) configuration.
Definition soem.h:780
StationAddressReading readStationAddressByPosition(ecx_contextt *context, uint16_t slave, int timeoutUs)
Reads a slave's station address register (0x0010) by the slave's position on the bus.
Definition soem.cc:866
std::recursive_mutex & controlPlaneMutex()
The single mutex that serialises every control-plane transaction.
Definition soem.cc:52
constexpr int kFoeAbortReplyTimeoutUs
Definition soem.h:41
constexpr int kFoeRemoveEsiTimeoutUs
Definition soem.h:50
SlaveInfo getSlaveInfo(ecx_contextt *context, uint16 position)
Definition soem.cc:383
std::vector< uint8_t > readSii(ecx_contextt *context, uint16 position)
Read the complete Slave Information Interface (SII) EEPROM from an EtherCAT slave device.
Definition soem.cc:1281
bool resetMailboxCounter(ecx_contextt *context, uint16_t slave)
Makes the slave forget the counter of the last mailbox request.
Definition soem.cc:934
bool setSlaveState(ecx_contextt *context, uint16_t slave, uint16_t targetState, std::chrono::steady_clock::duration timeout)
Transitions a single EtherCAT slave to targetState.
Definition soem.cc:1098
Specialization of std::hash for std::pair<uint16_t, uint8_t>.
Definition util.h:612
Represents the mapped PDO entries for a slave device.
Definition base.h:171
Structure representing the Fieldbus configuration and context for EtherCAT communication.
Definition soem.h:702
boolean ecaterror
Definition soem.h:718
ec_idxstackT idxstack
Definition soem.h:717
ec_eepromFMMUt eepFMMU
Definition soem.h:724
ec_groupt grouplist[EC_MAXGROUP]
Definition soem.h:713
std::string iface
Definition soem.h:704
uint8 group
Definition soem.h:705
int slavecount
Definition soem.h:712
uint8 esibuf[EC_MAXEEPBUF]
Definition soem.h:714
uint32 esimap[EC_MAXEEPBITMAP]
Definition soem.h:715
int64 DCtime
Definition soem.h:719
ec_eepromSMt eepSM
Definition soem.h:723
ec_PDOassignt PDOassign[EC_MAX_MAPT]
Definition soem.h:721
uint8 map[4096]
Definition soem.h:709
ecx_contextt context
Definition soem.h:703
int roundtripTime
Definition soem.h:706
ec_PDOdesct PDOdesc[EC_MAX_MAPT]
Definition soem.h:722
ecx_portt port
Definition soem.h:710
ec_slavet slavelist[EC_MAXSLAVE]
Definition soem.h:711
ec_SMcommtypet SMcommtype[EC_MAX_MAPT]
Definition soem.h:720
ec_eringt elist
Definition soem.h:716
The IgH EtherCAT Master kernel module, as the running kernel reports it.
Definition soem.h:210
bool isConfiguredFor(const std::string &macAddress) const
Definition soem.cc:340
std::vector< std::string > devices
Definition soem.h:217
bool loaded
Whether the ec_master module is loaded.
Definition soem.h:212
Information about a slave's mailbox configuration.
Definition soem.h:734
uint16_t writeOffset
Offset of the mailbox write area within the slave's memory.
Definition soem.h:777
uint16_t supportedProtocols
Supported mailbox protocols as a bitmask.
Definition soem.h:761
uint16_t readOffset
Offset of the mailbox read area within the slave's memory.
Definition soem.h:749
uint16_t readLength
Length of the mailbox read area (in bytes).
Definition soem.h:741
uint16_t writeLength
Length of the mailbox write area (in bytes).
Definition soem.h:769
What a slave's station address register holds, read by the slave's position on the bus.
Definition soem.h:405
@ kIntact
The register holds the configured address. The address is intact.
Definition soem.h:419
Kind kind
Definition soem.h:422
uint16_t expected
The station address ec_config_init() gave the slave.
Definition soem.h:426
std::string describe() const
One sentence for the log that says what the reading means.
Definition soem.cc:841
uint16_t value
The value read from the register. 0 when kind is kNoAnswer.
Definition soem.h:424