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 <optional>
10#include <sstream>
11#include <string>
12#include <type_traits>
13#include <unordered_map>
14#include <utility>
15#include <variant>
16#include <vector>
17
18#include <tl/expected.hpp>
19
20#include "base.h"
21#include "ethercat.h"
22#include "loguru.h"
23
24namespace mm::comm::soem {
25
26// 3-second SDO read/write timeout — long enough for devices with slower mailbox
27// implementations.
28inline constexpr int kSdoTimeoutUs = 3'000'000;
29
30// 10-second FoE write timeout — covers large firmware files over slow links.
31inline constexpr int kFoeTimeoutUs = 10'000'000;
32
33// 6-second FoE read timeout. A SOMANET bootloader can take several seconds to
34// answer a read, and 6 s is the timeout known to work on such drives. A read
35// given up too early fails on every attempt, because each attempt starts the
36// read again after the abort (see abortFoeTransfer). The full wait is spent
37// only when the device does not answer.
38inline constexpr int kFoeReadTimeoutUs = 6'000'000;
39
40// 100-millisecond wait for the answer to an FoE abort. The device's EtherCAT
41// stack answers an abort itself, without involving the file system.
42inline constexpr int kFoeAbortReplyTimeoutUs = 100'000;
43
44// 10-second timeout for a file removal ("fs-remove=<name>" issued as an FoE
45// read). Removing a file erases flash, which can take several seconds — much
46// longer than reading one back.
47inline constexpr int kFoeRemoveTimeoutUs = 10'000'000;
48
49// 30-second timeout for removing the ESI file. It is large and its erase takes
50// considerably longer than other files (measured at ~17 s on a SOMANET drive).
51inline constexpr int kFoeRemoveEsiTimeoutUs = 30'000'000;
52
72std::recursive_mutex& controlPlaneMutex();
73
97std::string drainMailboxErrors(ecx_contextt* context);
98
108std::vector<ec_errort> popMailboxErrors(ecx_contextt* context);
109
119std::string describeMailboxErrors(const std::vector<ec_errort>& errors);
120
137bool isNonexistentEntryAbort(const std::vector<ec_errort>& errors,
138 uint16_t index, uint8_t subindex);
139
154std::optional<uint32_t> findSdoAbort(const std::vector<ec_errort>& errors,
155 uint16_t slave, uint16_t index,
156 uint8_t subindex);
157
165std::string describeSdoAbort(uint32_t code);
166
192int drainMailbox(ecx_contextt* context, uint16_t slave);
193
205std::vector<uint8_t> makeFoeAbortRequest(uint8_t counter);
206
226void abortFoeTransfer(ecx_contextt* context, uint16_t slave);
227
248bool isTransientFoeFailure(int wkc);
249
265std::string describeFoeFailure(int wkc);
266
278std::map<std::string, std::string> mapMacAddressesToInterfaces();
279
290 bool loaded = false;
295 std::vector<std::string> devices;
296
299 [[nodiscard]] bool isConfiguredFor(const std::string& macAddress) const;
300};
301
313 const std::string& moduleDirectory = "/sys/module/ec_master");
314
330inline std::string uiConfigWithDefaultPdoMapping = R"(
331{
332 "pdoMapping": {
333 "rx": {
334 "0x1600": [
335 "0x60400010",
336 "0x60600008",
337 "0x60710010",
338 "0x607a0020",
339 "0x60ff0020",
340 "0x60b20010",
341 "0x27010020"
342 ],
343 "0x1601": [
344 "0x60fe0120",
345 "0x60fe0220"
346 ],
347 "0x1602": [
348 "0x27030020",
349 "0x60b10020",
350 "0x20120120"
351 ]
352 },
353 "tx": {
354 "0x1a00": [
355 "0x60410010",
356 "0x60610008",
357 "0x60640020",
358 "0x606c0020",
359 "0x60770010",
360 "0x60f40020",
361 "0x21110220",
362 "0x21130220"
363 ],
364 "0x1a01": [
365 "0x24010010",
366 "0x24020010",
367 "0x24030010",
368 "0x24040010",
369 "0x27020020"
370 ],
371 "0x1a02": [
372 "0x60fd0020"
373 ],
374 "0x1a03": [
375 "0x27040020",
376 "0x20f00020",
377 "0x60fc0020",
378 "0x606b0020",
379 "0x60740010",
380 "0x60790020"
381 ]
382 }
383 }
384})";
385
412int setPdoMappingFromUiConfig(ecx_contextt* context, uint16 slave);
413
431void checkPdoMapping(ecx_contextt* context, uint16 slave);
432
452uint16_t getSlaveState(ecx_contextt* context, uint16_t slave,
453 int timeoutUs = EC_TIMEOUTRET);
454
474bool isSlaveAnswering(ecx_contextt* context, uint16_t slave);
475
499
502 uint16_t value = 0;
504 uint16_t expected = 0;
505
507 [[nodiscard]] std::string describe() const;
508};
509
521 ecx_contextt* context, uint16_t slave, int timeoutUs = EC_TIMEOUTRET);
522
542std::string convertSlaveStateToString(int state);
543
566void updateMailboxSyncManagersOnNextState(ecx_contextt* context, uint16_t slave,
567 int targetState);
568
583
616bool resetMailboxCounter(ecx_contextt* context, uint16_t slave);
617
633void configureDetectedSmmModule(ecx_contextt* context, uint16_t slave);
634
672void transitionSlaves(ecx_contextt* context,
673 const std::vector<uint16_t>& positions,
674 uint16_t requiredState, uint16_t targetState,
675 const char* targetName,
676 std::chrono::steady_clock::duration timeout,
677 std::chrono::steady_clock::duration resendInterval =
678 std::chrono::seconds(2),
679 std::function<void()> tick = nullptr,
680 std::function<bool()> shouldAbort = nullptr);
681
694bool setSlaveState(
695 ecx_contextt* context, uint16_t slave, uint16_t targetState,
696 std::chrono::steady_clock::duration timeout = std::chrono::seconds(5));
697
731std::vector<uint8_t> readSii(ecx_contextt* context, uint16 position);
732
744mm::comm::base::PdoMappings readPdoMappings(ecx_contextt* context,
745 uint16_t slave);
746
762 const std::vector<mm::comm::base::PdoMappingEntry>& entries);
763
775void logIoMap(uint8_t* ioMap, size_t totalBytes);
776
791struct Fieldbus {
792 ecx_contextt context;
793 std::string iface;
794 uint8 group;
796
797 /* Used by the context */
798 uint8 map[4096];
799 ecx_portt port;
800 ec_slavet slavelist[EC_MAXSLAVE];
802 ec_groupt grouplist[EC_MAXGROUP];
803 uint8 esibuf[EC_MAXEEPBUF];
804 uint32 esimap[EC_MAXEEPBITMAP];
805 ec_eringt elist;
806 ec_idxstackT idxstack;
807 boolean ecaterror;
808 int64 DCtime;
809 ec_SMcommtypet SMcommtype[EC_MAX_MAPT];
810 ec_PDOassignt PDOassign[EC_MAX_MAPT];
811 ec_PDOdesct PDOdesc[EC_MAX_MAPT];
812 ec_eepromSMt eepSM;
813 ec_eepromFMMUt eepFMMU;
814};
815
830 uint16_t readLength;
831
838 uint16_t readOffset;
839
851
858 uint16_t writeLength;
859
866 uint16_t writeOffset;
867};
868
870 supportedProtocols, writeLength, writeOffset)
871
872
879struct SlaveInfoSyncManager {
888 uint32_t flags;
889
896 uint16_t length;
897
903 uint16_t startAddress;
904
915 uint8_t type;
916};
917
918NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfoSyncManager, flags, length,
919 startAddress, type)
920
921
928struct SlaveInfoFmmu {
934 uint8_t active;
935
942 uint8_t logicalEndBit;
943
950 uint8_t logicalStartBit;
951
957 uint32_t logicalStartAddress;
958
964 uint16_t logicalLength;
965
972 uint8_t physicalStartBit;
973
979 uint16_t physicalStartAddress;
980
987 uint8_t type;
988};
989
990NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfoFmmu, active, logicalEndBit,
991 logicalStartBit, logicalStartAddress,
992 logicalLength, physicalStartBit,
993 physicalStartAddress, type)
994
995
1001struct SlaveInfo {
1008 uint16_t alStatusCode;
1009
1016 uint16_t aliasAddress;
1017
1023 std::vector<SlaveInfoFmmu> fmmus;
1024
1031 SlaveInfoMailbox mailbox;
1032
1040 uint32_t productCode;
1041
1047 uint32_t position;
1048
1056 uint32_t revisionNumber;
1057
1064 std::vector<SlaveInfoSyncManager> syncManagers;
1065
1071 std::string name;
1072
1081 uint32_t vendorId;
1082};
1083
1084NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SlaveInfo, alStatusCode, aliasAddress, fmmus,
1085 mailbox, productCode, position,
1086 revisionNumber, syncManagers, name, vendorId)
1087
1088
1100SlaveInfo getSlaveInfo(ecx_contextt* context, uint16 position);
1101
1118void logSlaveInfo(ecx_contextt* context, uint16 position);
1119
1137void initFieldbus(std::unique_ptr<Fieldbus>& fieldbus,
1138 const std::string& iface);
1139
1144class Slave {
1145 public:
1156 explicit Slave(ecx_contextt& context, uint16_t position);
1157
1166 uint16_t position() const;
1167
1176 uint32_t vendorId() const;
1177
1186 uint32_t productCode() const;
1187
1196 uint32_t revisionNumber() const;
1197
1203 int getState() const;
1204
1224 bool setState(int targetState, int timeoutMs = 0, int intervalMs = 100);
1225
1247 tl::expected<void, std::string> loadParameters(bool readValues = false);
1248
1261 void logParameters() const;
1262
1279
1296
1303 void clearParameters();
1304
1313 std::unordered_map<mm::comm::base::Parameter::Address,
1315 parametersMap();
1316
1329 mm::comm::base::Parameter& findParameter(uint16_t index, uint8_t subindex);
1330
1358 template <typename T = std::vector<uint8_t>>
1359 T upload(uint16_t index, uint8_t subindex, bool refresh = true) {
1360 std::lock_guard<std::recursive_mutex> lock(controlPlaneMutex());
1361
1362 // Check if the device is in a valid state for uploading
1363 auto state = context_.slavelist[position_].state;
1364 if (state == EC_STATE_INIT || state == EC_STATE_BOOT) {
1365 throw std::runtime_error(
1366 "To upload object dictionary entries, the device must be in the (2) "
1367 "PRE-OPERATIONAL, (4) SAFE-OPERATIONAL, or (8) OPERATIONAL state. "
1368 "The current state is " +
1369 convertSlaveStateToString(state) + ".");
1370 }
1371
1372 // Find the previously loaded parameter
1373 auto& parameter = findParameter(index, subindex);
1374
1375 // Refresh data if needed (SDO read)
1376 if (refresh) {
1377 const std::unique_ptr<std::uint8_t[]> data =
1378 std::make_unique<std::uint8_t[]>(parameter.byteLength);
1379 auto wkc =
1380 ecx_SDOread(&context_, position_, parameter.index, parameter.subindex,
1381 false, &parameter.byteLength, data.get(), kSdoTimeoutUs);
1382 if (wkc <= 0) {
1383 LOG_F(ERROR, "Device %d: SDO read failed for %#04x:%02x! WKC: %d",
1384 position_, parameter.index, parameter.subindex, wkc);
1385 auto id = mm::comm::base::makeParameterId(parameter.index,
1386 parameter.subindex);
1387 throw std::runtime_error("Device " + std::to_string(position_) +
1388 ": SDO read failed for " + id +
1389 "! WKC: " + std::to_string(wkc));
1390 } else {
1391 std::vector<uint8_t> receivedData(data.get(),
1392 data.get() + parameter.byteLength);
1393 if (!parameter.trySetValue(receivedData)) {
1394 LOG_F(ERROR,
1395 "Device %d: Failed to set the value of parameter %#04x:%02x!",
1396 position_, parameter.index, parameter.subindex);
1397 }
1398 }
1399 }
1400
1401 // Return the appropriate type
1402 if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
1403 return parameter.data; // parameter.data should be std::vector<uint8_t>
1404 } else {
1405 // Otherwise, try to get the value as the requested type T
1406 auto value = parameter.getValue();
1407 if (auto ptr = std::get_if<T>(&value)) {
1408 return *ptr;
1409 } else {
1410 throw std::bad_variant_access(); // Type mismatch
1411 }
1412 }
1413 }
1414
1439 template <typename T = std::vector<uint8_t>>
1440 bool download(uint16_t index, uint8_t subindex, const T& value) {
1441 std::lock_guard<std::recursive_mutex> lock(controlPlaneMutex());
1442
1443 // Check if device is in valid state for download
1444 auto state = context_.slavelist[position_].state;
1445 if (state == EC_STATE_INIT || state == EC_STATE_BOOT) {
1446 throw std::runtime_error(
1447 "To download object dictionary entries, the device must be in the "
1448 "(2) PRE-OPERATIONAL, (4) SAFE-OPERATIONAL, or (8) OPERATIONAL "
1449 "state. The current state is " +
1450 convertSlaveStateToString(state) + ".");
1451 }
1452
1453 auto& parameter = findParameter(index, subindex);
1454
1455 // Convert value to raw byte data
1456 std::vector<uint8_t> data;
1457 if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
1458 data = value;
1459 } else {
1460 // Set the value in the parameter model
1461 if (!parameter.trySetValue(value)) {
1462 LOG_F(ERROR,
1463 "Device %d: Failed to set the value of parameter %#04x:%02x!",
1464 position_, parameter.index, parameter.subindex);
1465 return false;
1466 }
1467 data = parameter.data; // Use the parameter's byte representation
1468 }
1469
1470 // Check if data size matches the expected parameter size
1471 if (data.size() != parameter.byteLength) {
1472 LOG_F(ERROR, "Data size mismatch: expected %d, got %zu",
1473 parameter.byteLength, data.size());
1474 throw std::runtime_error("Data size does not match the parameter size!");
1475 }
1476
1477 // Perform the SDO write
1478 auto wkc =
1479 ecx_SDOwrite(&context_, position_, parameter.index, parameter.subindex,
1480 false, parameter.byteLength, data.data(), kSdoTimeoutUs);
1481
1482 // Check write result
1483 if (wkc <= 0) {
1484 LOG_F(ERROR, "Device %d: SDO write failed for %#04x:%02x! WKC: %d",
1485 position_, parameter.index, parameter.subindex, wkc);
1486 return false;
1487 }
1488
1489 return true;
1490 }
1491
1501
1510 void updatePdoMappings();
1511
1523 void logPdoMappings() const;
1524
1530 mm::comm::base::PdoMappings& getPdoMappings();
1531
1554 void updateOutputs();
1555
1577 void updateParametersFromInputs();
1578
1606 tl::expected<std::vector<uint8_t>, std::string> readFile(
1607 const std::string& filename,
1608 size_t maxFileSize = 1 * 1024 * 1024, // 1 MB default max file size
1609 int retries = 3,
1610 std::chrono::steady_clock::duration retryWait =
1611 std::chrono::milliseconds(100));
1612
1626 tl::expected<std::vector<std::uint8_t>, std::string> readSdo(
1627 uint16_t index, uint8_t subindex);
1628
1642 tl::expected<ec_ODlistt, std::string> readODList(
1643 int retries = 5, std::chrono::steady_clock::duration retryWait =
1644 std::chrono::milliseconds(100));
1645
1664 tl::expected<void, std::string> readODDescription(
1665 uint16_t item, ec_ODlistt& odList, int retries = 5,
1666 std::chrono::steady_clock::duration retryWait =
1667 std::chrono::milliseconds(100));
1668
1685 tl::expected<ec_OElistt, std::string> readOE(
1686 uint16_t item, ec_ODlistt& odList, int retries = 5,
1687 std::chrono::steady_clock::duration retryWait =
1688 std::chrono::milliseconds(100));
1689
1690 private:
1691 ecx_contextt& context_;
1692 const uint16_t position_;
1695 std::unordered_map<mm::comm::base::Parameter::Address,
1697 parametersMap_;
1700 pdoMappings_;
1701};
1702
1703class Master {
1704 public:
1711 explicit Master();
1712
1723 explicit Master(const std::string& iface);
1724
1776 void init(const std::string& iface);
1777
1788 void deinit();
1789
1796 ~Master();
1797
1807 Fieldbus& getFieldbus() const;
1808
1817 std::string getInterfaceName() const;
1818
1827 size_t getIoMapSize() const;
1828
1891 tl::expected<int, std::string> initSlaves();
1892
1904 const std::vector<std::unique_ptr<Slave>>& slaves() const;
1905
1915 inline int expectedWkc() const {
1916 return fieldbus_->context.grouplist[fieldbus_->group].outputsWKC * 2 +
1917 fieldbus_->context.grouplist[fieldbus_->group].inputsWKC;
1918 }
1919
1929 int roundtrip();
1930
1960
1971 bool start();
1972
1973 private:
1987 std::unique_ptr<Fieldbus> fieldbus_;
1988
2000 std::vector<std::unique_ptr<Slave>> slaves_;
2001};
2002}; // 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:2293
Master()
Default constructor for the Master class.
Definition soem.cc:2210
const std::vector< std::unique_ptr< Slave > > & slaves() const
Returns a reference to the list of slaves.
Definition soem.cc:2289
tl::expected< int, std::string > initSlaves()
Initializes the slave devices on the EtherCAT network.
Definition soem.cc:2262
void exchangeProcessDataAndUpdateParameters()
Exchanges process data with slaves and updates parameters based on the response.
Definition soem.cc:2298
size_t getIoMapSize() const
Returns the total size of the I/O map for the current group.
Definition soem.cc:2257
Fieldbus & getFieldbus() const
Returns a reference to the Fieldbus instance.
Definition soem.cc:2253
void init(const std::string &iface)
Initializes the fieldbus using the specified network interface.
Definition soem.cc:2217
std::string getInterfaceName() const
Retrieves the interface name used by the fieldbus.
Definition soem.cc:2255
void deinit()
Deinitializes the fieldbus and releases associated resources.
Definition soem.cc:2235
bool start()
Initializes and starts the fieldbus master.
Definition soem.cc:2321
~Master()
Destructor for the Master class.
Definition soem.cc:2251
int expectedWkc() const
Calculates the expected working counter (WKC) for the current fieldbus group.
Definition soem.h:1915
uint32_t productCode() const
Gets the Product Code of the slave device.
Definition soem.cc:1666
uint32_t vendorId() const
Gets the Vendor ID of the slave device.
Definition soem.cc:1662
std::unordered_map< mm::comm::base::Parameter::Address, mm::comm::base::Parameter > & parametersMap()
Returns a reference to the internal parameters map.
Definition soem.cc:1980
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:1984
uint32_t revisionNumber() const
Gets the Revision Number of the slave device.
Definition soem.cc:1670
T upload(uint16_t index, uint8_t subindex, bool refresh=true)
Uploads a parameter value from the device's object dictionary.
Definition soem.h:1359
tl::expected< void, std::string > loadParameters(bool readValues=false)
Loads the parameters (object dictionary entries) from the EtherCAT slave device.
Definition soem.cc:1792
void clearParameters()
Clears all loaded object dictionary parameters.
Definition soem.cc:1976
void logTxPdoMappedParameters()
Logs all mapped TxPDO parameters with their current values.
Definition soem.cc:1961
Slave(ecx_contextt &context, uint16_t position)
Constructs a Slave object with a given context and position.
Definition soem.cc:1657
void logRxPdoMappedParameters()
Logs all mapped RxPDO parameters with their current values.
Definition soem.cc:1946
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:1676
void logParameters() const
Logs all loaded object dictionary parameters.
Definition soem.cc:1940
int getState() const
Reads the current state of the slave directly from the device.
Definition soem.cc:1674
uint16_t position() const
Gets the position of the slave.
Definition soem.cc:1660
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:1440
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:45
constexpr int kFoeReadTimeoutUs
Definition soem.h:38
IghMasterModule readIghMasterModule(const std::string &moduleDirectory)
Reads the IgH EtherCAT Master kernel module's state from sysfs.
Definition soem.cc:469
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:1555
std::vector< ec_errort > popMailboxErrors(ecx_contextt *context)
Empties SOEM's error list and returns its entries.
Definition soem.cc:58
std::vector< uint8_t > makeFoeAbortRequest(uint8_t counter)
Builds an FoE ERROR request, which aborts a slave's FoE transfer.
Definition soem.cc:185
std::string describeFoeFailure(int wkc)
Describes the value a failed FoE transfer returned, for a log line or an error message.
Definition soem.cc:304
constexpr int kFoeTimeoutUs
Definition soem.h:31
void logPdoMappingEntries(const std::vector< mm::comm::base::PdoMappingEntry > &entries)
Logs PDO mapping entries grouped by PDO index.
Definition soem.cc:1626
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:1022
std::string convertSlaveStateToString(int state)
Converts a numeric EtherCAT state value into a human-readable string.
Definition soem.cc:1100
void resetBootMailboxTracking()
Clears the internal record of which slaves hold BOOT-sized mailbox sync managers.
Definition soem.cc:1138
bool isTransientFoeFailure(int wkc)
Tells whether a failed FoE transfer is worth another attempt.
Definition soem.cc:261
constexpr int kSdoTimeoutUs
Definition soem.h:28
std::string drainMailboxErrors(ecx_contextt *context)
Empties SOEM's error list and describes the first entry found.
Definition soem.cc:112
void abortFoeTransfer(ecx_contextt *context, uint16_t slave)
Aborts the FoE transfer a slave may still have in progress.
Definition soem.cc:248
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:1202
std::string uiConfigWithDefaultPdoMapping
Default UI configuration used for PDO mapping.
Definition soem.h:330
void initFieldbus(std::unique_ptr< Fieldbus > &fieldbus, const std::string &iface)
Initializes a Fieldbus instance for EtherCAT communication.
Definition soem.cc:2177
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:1336
bool isSlaveAnswering(ecx_contextt *context, uint16_t slave)
Tells whether a slave still answers at its configured station address.
Definition soem.cc:1037
void logIoMap(uint8_t *ioMap, size_t totalBytes)
Logs the I/O map as a formatted hexadecimal string.
Definition soem.cc:1647
std::string describeMailboxErrors(const std::vector< ec_errort > &errors)
Describes the first of the given error-list entries, for a log line.
Definition soem.cc:67
void checkPdoMapping(ecx_contextt *context, uint16 slave)
Diagnoses and prints the PDO mapping for a given slave.
Definition soem.cc:938
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:1466
constexpr int kFoeRemoveTimeoutUs
Definition soem.h:47
int drainMailbox(ecx_contextt *context, uint16_t slave)
Discards whatever is sitting in a slave's read mailbox.
Definition soem.cc:151
std::map< std::string, std::string > mapMacAddressesToInterfaces()
Maps MAC addresses to their corresponding network interface names.
Definition soem.cc:337
int setPdoMappingFromUiConfig(ecx_contextt *context, uint16 slave)
Sets PDO mapping for a specified EtherCAT slave using UI configuration.
Definition soem.cc:671
uint16 position
Definition soem.h:1100
std::optional< uint32_t > findSdoAbort(const std::vector< ec_errort > &errors, uint16_t slave, uint16_t index, uint8_t subindex)
Finds the SDO abort a slave answered an SDO upload or download with.
Definition soem.cc:131
void logSlaveInfo(ecx_contextt *context, uint16 position)
Logs detailed information about a specific EtherCAT slave in JSON format.
Definition soem.cc:553
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:869
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:1075
std::recursive_mutex & controlPlaneMutex()
The single mutex that serialises every control-plane transaction.
Definition soem.cc:53
constexpr int kFoeAbortReplyTimeoutUs
Definition soem.h:42
constexpr int kFoeRemoveEsiTimeoutUs
Definition soem.h:51
std::string describeSdoAbort(uint32_t code)
Describes an SDO abort code with its meaning from ETG.1000.6.
Definition soem.cc:145
bool isNonexistentEntryAbort(const std::vector< ec_errort > &errors, uint16_t index, uint8_t subindex)
Tells whether a slave answered that an object entry does not exist.
Definition soem.cc:116
SlaveInfo getSlaveInfo(ecx_contextt *context, uint16 position)
Definition soem.cc:501
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:1512
bool resetMailboxCounter(ecx_contextt *context, uint16_t slave)
Makes the slave forget the counter of the last mailbox request.
Definition soem.cc:1143
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:1328
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:791
boolean ecaterror
Definition soem.h:807
ec_idxstackT idxstack
Definition soem.h:806
ec_eepromFMMUt eepFMMU
Definition soem.h:813
ec_groupt grouplist[EC_MAXGROUP]
Definition soem.h:802
std::string iface
Definition soem.h:793
uint8 group
Definition soem.h:794
int slavecount
Definition soem.h:801
uint8 esibuf[EC_MAXEEPBUF]
Definition soem.h:803
uint32 esimap[EC_MAXEEPBITMAP]
Definition soem.h:804
int64 DCtime
Definition soem.h:808
ec_eepromSMt eepSM
Definition soem.h:812
ec_PDOassignt PDOassign[EC_MAX_MAPT]
Definition soem.h:810
uint8 map[4096]
Definition soem.h:798
ecx_contextt context
Definition soem.h:792
int roundtripTime
Definition soem.h:795
ec_PDOdesct PDOdesc[EC_MAX_MAPT]
Definition soem.h:811
ecx_portt port
Definition soem.h:799
ec_slavet slavelist[EC_MAXSLAVE]
Definition soem.h:800
ec_SMcommtypet SMcommtype[EC_MAX_MAPT]
Definition soem.h:809
ec_eringt elist
Definition soem.h:805
The IgH EtherCAT Master kernel module, as the running kernel reports it.
Definition soem.h:288
bool isConfiguredFor(const std::string &macAddress) const
Definition soem.cc:458
std::vector< std::string > devices
Definition soem.h:295
bool loaded
Whether the ec_master module is loaded.
Definition soem.h:290
Information about a slave's mailbox configuration.
Definition soem.h:823
uint16_t writeOffset
Offset of the mailbox write area within the slave's memory.
Definition soem.h:866
uint16_t supportedProtocols
Supported mailbox protocols as a bitmask.
Definition soem.h:850
uint16_t readOffset
Offset of the mailbox read area within the slave's memory.
Definition soem.h:838
uint16_t readLength
Length of the mailbox read area (in bytes).
Definition soem.h:830
uint16_t writeLength
Length of the mailbox write area (in bytes).
Definition soem.h:858
What a slave's station address register holds, read by the slave's position on the bus.
Definition soem.h:483
@ kIntact
The register holds the configured address. The address is intact.
Definition soem.h:497
Kind kind
Definition soem.h:500
uint16_t expected
The station address ec_config_init() gave the slave.
Definition soem.h:504
std::string describe() const
One sentence for the log that says what the reading means.
Definition soem.cc:1050
uint16_t value
The value read from the register. 0 when kind is kNoAnswer.
Definition soem.h:502