Motion Master
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1#pragma once
2
3#include <condition_variable>
4#include <map>
5#include <optional>
6#include <set>
7#include <sstream>
8#include <string>
9#include <typeindex>
10#include <unordered_map>
11#include <utility>
12#include <variant>
13#include <vector>
14
15#include <nlohmann/json.hpp>
16
17#include "core/util.h"
18
19namespace mm::comm::base {
30 std::map<std::uint16_t, std::vector<std::uint32_t>> rx;
31 std::map<std::uint16_t, std::vector<std::uint32_t>> tx;
32};
33
42
54void from_json(const nlohmann::json& j, UiPdoMapping& p);
55
65void from_json(const nlohmann::json& j, UiConfigJson& r);
66
74enum class EtherCATVendorID : uint32_t {
80 SYNAPTICON = 0x000022d2,
81
82 SENSODRIVE = 0x0000063a
83};
84
85inline constexpr std::size_t kDeviceFilePartSize =
86 9000;
88
100inline bool operator==(uint32_t lhs, EtherCATVendorID rhs) {
101 return lhs == static_cast<uint32_t>(rhs);
102}
103
115inline bool operator==(EtherCATVendorID lhs, uint32_t rhs) {
116 return static_cast<uint32_t>(lhs) == rhs;
117}
118
129 uint16_t pdoIndex;
130 uint16_t index;
131 uint8_t subindex;
132 uint8_t
134};
135
151 std::vector<PdoMappingEntry> rxPdos;
153 std::vector<PdoMappingEntry> txPdos;
155};
156
164enum class ObjectFlags : uint16_t {
165 None = 0x0000,
166
167 // Read access
168 PO_RD = 0x0001,
169 SO_RD = 0x0002,
170 OP_RD = 0x0004,
172
173 // Write access
174 PO_WR = 0x0008,
175 SO_WR = 0x0010,
176 OP_WR = 0x0020,
178
179 // Read/Write combinations
184
185 // Mapping
186 RXPDO_MAP = 0x0040,
187 TXPDO_MAP = 0x0080,
188 RXTXPDO_MAP = 0x00C0,
189
190 // Other flags
191 BACKUP = 0x0100,
192 STARTUP = 0x0200,
193
195};
196
208 return static_cast<ObjectFlags>(static_cast<uint16_t>(lhs) |
209 static_cast<uint16_t>(rhs));
210}
211
223 return static_cast<ObjectFlags>(static_cast<uint16_t>(lhs) &
224 static_cast<uint16_t>(rhs));
225}
226
238 lhs = lhs | rhs;
239 return lhs;
240}
241
256 ObjectFlags a) {
257 return b | s | p | a;
258}
259
272enum class ObjectDataType : uint16_t {
273 UNSPECIFIED = 0x0000,
274
275 BOOLEAN = 0x0001,
276 BYTE = 0x001E,
277 WORD = 0x001F,
278 DWORD = 0x0020,
279
280 BIT1 = 0x0030,
281 BIT2 = 0x0031,
282 BIT3 = 0x0032,
283 BIT4 = 0x0033,
284 BIT5 = 0x0034,
285 BIT6 = 0x0035,
286 BIT7 = 0x0036,
287 BIT8 = 0x0037,
288 BIT9 = 0x0038,
289 BIT10 = 0x0039,
290 BIT11 = 0x003A,
291 BIT12 = 0x003B,
292 BIT13 = 0x003C,
293 BIT14 = 0x003D,
294 BIT15 = 0x003E,
295 BIT16 = 0x003F,
296
297 BITARR8 = 0x002D,
298 BITARR16 = 0x002E,
299 BITARR32 = 0x002F,
300
301 INTEGER8 = 0x0002,
302 INTEGER16 = 0x0003,
303 INTEGER24 = 0x0010,
304 INTEGER32 = 0x0004,
305 INTEGER40 = 0x0012,
306 INTEGER48 = 0x0013,
307 INTEGER56 = 0x0014,
308 INTEGER64 = 0x0015,
309
310 UNSIGNED8 = 0x0005,
311 UNSIGNED16 = 0x0006,
312 UNSIGNED24 = 0x0016,
313 UNSIGNED32 = 0x0007,
314 UNSIGNED40 = 0x0018,
315 UNSIGNED48 = 0x0019,
316 UNSIGNED56 = 0x001A,
317 UNSIGNED64 = 0x001B,
318
319 REAL32 = 0x0008,
320 REAL64 = 0x0011,
321
322 GUID = 0x001D,
323
324 VISIBLE_STRING = 0x0009,
325 OCTET_STRING = 0x000A,
326 UNICODE_STRING = 0x000B,
328 ARRAY_OF_INT = 0x0260,
329 ARRAY_OF_SINT = 0x0261,
330 ARRAY_OF_DINT = 0x0262,
331 ARRAY_OF_UDINT = 0x0263,
332
333 PDO_MAPPING = 0x0021,
334 IDENTITY = 0x0023,
335 COMMAND_PAR = 0x0025,
336 PDO_PARAMETER = 0x0027,
337 ENUM = 0x0028,
339 0x0029,
340 RECORD = 0x002A,
345 ERROR_SETTING = 0x0281,
347 0x0282,
355 0x0286,
357
358 TIME_OF_DAY = 0x000C,
360 0x000D,
361 UTYPE_START = 0x0800,
362 UTYPE_END = 0x0FFF
363};
364
374enum class ObjectCode : uint16_t {
375 DEFTYPE = 0x0005,
376 DEFSTRUCT = 0x0006,
377 VAR = 0x0007,
378 ARRAY = 0x0008,
379 RECORD = 0x0009,
380};
381
406 std::variant<bool, std::int8_t, std::int16_t, std::int32_t, std::int64_t,
407 std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t,
408 float, double, std::string,
409 std::vector<std::uint8_t>>;
411
423
431 std::vector<MappedParameterValue> rx;
432 std::vector<MappedParameterValue> tx;
433};
434
446
469 public:
478 using Address = std::pair<uint16_t, uint8_t>;
479
484 std::string group;
485
489 std::string name;
490
494 std::uint16_t index;
495
499 std::uint8_t subindex;
500
504 std::uint16_t bitLength;
505
510
515
520
525
530
538
542 std::vector<std::uint8_t> data;
543
574 ParameterValue getValue() const;
575
593 template <typename T>
594 T getValue() const {
595 // Get the value as a ParameterValue
596 const ParameterValue& val = getValue();
597
598 // Try to get the value of type T from the variant
599 if (auto ptr = std::get_if<T>(&val)) {
600 return *ptr; // Return the value of type T
601 } else {
602 throw std::bad_variant_access(); // If type T is not found in the variant
603 }
604 }
605
621 template <typename T>
622 std::optional<T> tryGetValue() const {
623 const ParameterValue& val = getValue();
624 if (auto ptr = std::get_if<T>(&val)) {
625 return *ptr;
626 } else {
627 return std::nullopt;
628 }
629 }
630
642 template <typename T>
647
668 void setValue(const ParameterValue& value);
669
686 template <typename T>
687 void setValue(const T& value) {
688 // Convert the input value to ParameterValue (variant)
689 ParameterValue parameterValue(value);
690
691 // Reuse the existing setValue function to handle the assignment
692 setValue(parameterValue);
693 }
694
709 template <typename T>
710 bool trySetValue(const T& value) {
711 auto expectedType = [this]() -> std::type_index {
712 switch (dataType) {
714 return typeid(bool);
715 }
717 return typeid(std::int8_t);
718 }
720 return typeid(std::int16_t);
721 }
724 return typeid(std::int32_t);
725 }
727 return typeid(std::int64_t);
728 }
734 return typeid(std::uint8_t);
735 }
737 return typeid(std::uint16_t);
738 }
741 return typeid(std::uint32_t);
742 }
744 return typeid(std::uint64_t);
745 }
747 return typeid(float);
748 }
750 return typeid(double);
751 }
755 return typeid(std::string);
756 }
757 default: {
758 return typeid(void);
759 }
760 }
761 };
762
763 const std::type_index expected = expectedType();
764 if (expected != typeid(T) &&
765 typeid(T) != typeid(std::vector<std::uint8_t>)) {
766 return false;
767 }
768
770 return true;
771 }
772
781 bool hasAllRead() const;
782
791 bool hasAllWrite() const;
792
803 bool operator<(const Parameter& other) const {
804 if (index != other.index) {
805 return index < other.index; // Compare by index first
806 }
807 return subindex <
808 other.subindex; // Compare by subindex if indices are equal
809 }
810
821 bool operator>(const Parameter& other) const {
822 if (index != other.index) {
823 return index > other.index; // Compare by index first
824 }
825 return subindex >
826 other.subindex; // Compare by subindex if indices are equal
827 }
828
839 bool operator==(const Parameter& other) const {
840 return index == other.index && subindex == other.subindex;
841 }
842
853 static void to_json(nlohmann::json& j, const Parameter& p);
854
865 static void from_json(const nlohmann::json& j, Parameter& p);
866};
867
881
896void assignGroupsToParameters(std::vector<Parameter>& parameters);
897
918 const std::unordered_map<Parameter::Address, Parameter>& parametersMap,
919 bool sortParameters = true);
920
933inline bool isAppBinFile(const std::string& filename) {
934 return filename.rfind("app_", 0) == 0 && filename.size() >= 4 &&
935 filename.compare(filename.size() - 4, 4, ".bin") == 0;
936}
937
950inline bool isComBinFile(const std::string& filename) {
951 return filename.rfind("com_", 0) == 0 && filename.size() >= 4 &&
952 filename.compare(filename.size() - 4, 4, ".bin") == 0;
953}
954
964inline bool isFirmwareBinFile(const std::string& filename) {
965 return isAppBinFile(filename) || isComBinFile(filename);
966}
967
1000
1007inline std::string deviceFileErrorToString(DeviceFileError error) {
1008 switch (error) {
1010 return "No error";
1012 return "File not found";
1014 return "File is empty";
1016 return "File starts with a null terminator";
1018 return "Failed to unzip file";
1020 return "Failed to flash device";
1022 return "Failed to write to device";
1024 return "An unknown error occurred";
1025 default:
1026 return "Unrecognized error";
1027 }
1028}
1029
1037class Device {
1038 public:
1047 virtual ~Device() = default;
1048
1057 virtual uint16_t getPosition() const = 0;
1058
1076 virtual uint8_t getState(
1077 bool refresh = false,
1078 const std::chrono::steady_clock::duration expiryTime =
1079 std::chrono::milliseconds(5000)) = 0;
1080
1093 virtual bool setState(uint8_t state,
1094 const std::chrono::steady_clock::duration expiryTime =
1095 std::chrono::milliseconds(5000)) = 0;
1096
1111 virtual std::vector<uint8_t> readFile(
1112 const std::string& filename,
1113 const std::chrono::steady_clock::duration expiryTime =
1114 std::chrono::milliseconds(5000)) = 0;
1115
1138 virtual std::vector<std::string> readFileList(
1139 const bool stripSizeSuffix,
1140 const std::chrono::steady_clock::duration expiryTime =
1141 std::chrono::milliseconds(5000)) = 0;
1142
1155 virtual void writeFile(const std::string& filename,
1156 const std::vector<uint8_t>& data,
1157 const std::chrono::steady_clock::duration expiryTime =
1158 std::chrono::milliseconds(5000)) = 0;
1159
1167 virtual void removeFile(const std::string& filename,
1168 const std::chrono::steady_clock::duration expiryTime =
1169 std::chrono::milliseconds(5000)) = 0;
1170
1182 virtual void updateFirmware(
1183 const std::vector<std::uint8_t>& data,
1184 const std::vector<std::string>& skipFiles = {},
1185 std::function<void(uint8_t, std::string)> progressCallback = nullptr,
1186 const std::chrono::steady_clock::duration expiryTime =
1187 std::chrono::milliseconds(60000)) = 0;
1188
1198 virtual size_t loadParameters(
1199 bool readValues, const std::chrono::steady_clock::duration expiryTime =
1200 std::chrono::milliseconds(9000)) = 0;
1201
1208 virtual void clearParameters() = 0;
1209
1216 virtual std::vector<std::reference_wrapper<Parameter>> parameters() = 0;
1217
1233 virtual Parameter& findParameter(uint16_t index, uint8_t subindex) = 0;
1234
1253 uint16_t index, uint8_t subindex,
1254 const std::chrono::steady_clock::duration expiryTime =
1255 std::chrono::milliseconds(5000)) = 0;
1256
1272 virtual void download(uint16_t index, uint8_t subindex,
1273 const std::chrono::steady_clock::duration expiryTime =
1274 std::chrono::milliseconds(5000)) = 0;
1275
1293 virtual void download(uint16_t index, uint8_t subindex,
1294 const ParameterValue& value,
1295 const std::chrono::steady_clock::duration expiryTime =
1296 std::chrono::milliseconds(5000)) = 0;
1297
1310 uint64_t missedCycles = 0) = 0;
1311
1328 uint8_t subindex) const = 0;
1329
1335 virtual bool isOnline() = 0;
1336};
1337
1347 public:
1362 virtual bool setState(
1363 uint8_t state, const std::chrono::steady_clock::duration expiryTime) = 0;
1364
1377 virtual std::vector<uint8_t> exchangeProcessData(
1378 const std::vector<uint8_t>& data,
1379 const std::chrono::steady_clock::duration expiryTime) = 0;
1380
1393 uint64_t missedCycles,
1394 const std::chrono::steady_clock::duration expiryTime) = 0;
1395 virtual std::vector<Device>& devices() = 0;
1396
1397 private:
1398 // Container holding all managed devices.
1399 std::vector<Device> devices_;
1400};
1401
1410class DeviceResponseException : public std::runtime_error {
1411 public:
1418 DeviceResponseException(const std::string& what_arg, uint16_t position,
1419 int code);
1420
1424 uint16_t position() const noexcept;
1425
1429 int code() const noexcept;
1430
1431 private:
1432 uint16_t position_;
1433 int code_;
1434};
1435
1448extern std::set<std::string> kNonPartedFileNames;
1449
1480std::vector<std::uint8_t> readCompleteDeviceFile(
1481 Device& device, const std::string& filename,
1482 const std::chrono::steady_clock::duration expiryTime =
1483 std::chrono::milliseconds(20000));
1484
1511 Device& device, const std::string& filename,
1512 const std::vector<std::uint8_t>& data,
1513 std::function<void(uint8_t, std::string)> progressCallback = nullptr,
1514 const std::chrono::steady_clock::duration expiryTime =
1515 std::chrono::milliseconds(30000));
1516
1535void removeDeviceFileOrParts(Device& device, const std::string& filename,
1536 const std::chrono::steady_clock::duration
1537 expiryTime = std::chrono::milliseconds(20000));
1538
1559 Device& device, const std::vector<std::uint8_t>& data,
1560 const std::vector<std::string>& skipFiles = {},
1561 std::function<void(uint8_t, std::string)> progressCallback = nullptr,
1562 const std::chrono::steady_clock::duration expiryTime =
1563 std::chrono::milliseconds(60000));
1564
1579inline std::string makeParameterId(int index, int subindex) {
1580 std::stringstream oss;
1581 // Format index and subindex into "0xINDEX:SUBINDEX"
1582 oss << "0x" << std::setw(4) << std::setfill('0') << std::hex << std::uppercase
1583 << index << ":" << std::setw(2) << std::setfill('0') << std::hex
1584 << std::uppercase << subindex;
1585
1586 return oss.str();
1587}
1588
1611 public:
1619 std::chrono::milliseconds intervalBetweenUploads);
1620
1625
1633 void add(uint16_t index, uint8_t subindex);
1634
1643 void remove(uint16_t index, uint8_t subindex);
1644
1650 void clear();
1651
1662 void start();
1663
1676 void stop();
1677
1687 void triggerManualRefresh(bool async = false);
1688
1689 protected:
1705 virtual void refresh(const std::vector<Parameter::Address>& addresses) = 0;
1706
1707 std::chrono::milliseconds
1709 std::condition_variable
1711 std::mutex mutex_;
1712 std::vector<Parameter::Address>
1716 std::thread worker_;
1717
1718 private:
1739 void run();
1740};
1741
1742} // namespace mm::comm::base
1743
1744namespace nlohmann {
1749template <>
1750struct adl_serializer<mm::comm::base::ParameterValue> {
1752 std::visit([&j](const auto& val) { j = val; }, value);
1753 }
1754
1756 if (j.is_boolean()) {
1757 value = j.get<bool>();
1758 } else if (j.is_number_integer()) {
1759 int64_t num = j.get<int64_t>();
1760 if (num >= -128 && num <= 127) {
1761 value = static_cast<int8_t>(num);
1762 } else if (num >= -32768 && num <= 32767) {
1763 value = static_cast<int16_t>(num);
1764 } else if (num >= -2147483648LL && num <= 2147483647LL) {
1765 value = static_cast<int32_t>(num);
1766 } else {
1767 value = num; // int64_t
1768 }
1769 } else if (j.is_number_unsigned()) {
1770 uint64_t num = j.get<uint64_t>();
1771 if (num <= 255) {
1772 value = static_cast<uint8_t>(num);
1773 } else if (num <= 65535) {
1774 value = static_cast<uint16_t>(num);
1775 } else if (num <= 4294967295ULL) {
1776 value = static_cast<uint32_t>(num);
1777 } else {
1778 value = num; // uint64_t
1779 }
1780 } else if (j.is_number_float()) {
1781 double f = j.get<double>();
1782 // float range: approx ±3.4e38
1783 if (f >= -3.4e38 && f <= 3.4e38) {
1784 value = static_cast<float>(f);
1785 } else {
1786 value = f; // double
1787 }
1788 } else if (j.is_string()) {
1789 value = j.get<std::string>();
1790 } else if (j.is_array()) {
1791 value = j.get<std::vector<uint8_t>>();
1792 } else {
1793 throw std::runtime_error("Unsupported JSON type for ParameterValue");
1794 }
1795 }
1796};
1797
1803inline void to_json(nlohmann::json& j,
1805 j = nlohmann::json{
1806 {"index", p.index}, {"subindex", p.subindex}, {"value", p.value}};
1807}
1808
1814inline void from_json(const nlohmann::json& j,
1816 j.at("index").get_to(p.index);
1817 j.at("subindex").get_to(p.subindex);
1818 j.at("value").get_to(p.value);
1819}
1820
1827 j = json{{"rx", p.rx}, {"tx", p.tx}};
1828}
1829
1836 j.at("rx").get_to(p.rx);
1837 j.at("tx").get_to(p.tx);
1838}
1839} // namespace nlohmann
nlohmann::json json
Definition circulo_encoder_configuration.cc:13
Manages devices and performs cyclic process data exchange.
Definition base.h:1346
virtual void exchangeProcessDataAndUpdateParameters(uint64_t missedCycles, const std::chrono::steady_clock::duration expiryTime)=0
Exchanges process data and updates internal parameters for each device.
virtual std::vector< Device > & devices()=0
virtual bool setState(uint8_t state, const std::chrono::steady_clock::duration expiryTime)=0
Sets the operational state of all managed devices.
virtual std::vector< uint8_t > exchangeProcessData(const std::vector< uint8_t > &data, const std::chrono::steady_clock::duration expiryTime)=0
Exchanges process data with devices.
virtual void refresh(const std::vector< Parameter::Address > &addresses)=0
Rereads the specified device parameters.
void triggerManualRefresh(bool async=false)
Triggers a manual refresh of device parameters.
Definition base.cc:697
void remove(uint16_t index, uint8_t subindex)
Remove a parameter identified by (index, subindex) from the refresh list.
Definition base.cc:628
void start()
Starts the refresher background thread if it is not already running.
Definition base.cc:640
std::vector< Parameter::Address > addresses_
List of parameter addresses to refresh.
Definition base.h:1713
~DeviceParameterRefresher()
Destructor ensures the refresher thread is stopped cleanly.
Definition base.cc:607
bool running_
Flag indicating whether the refresher thread is running.
Definition base.h:1715
void clear()
Remove all parameters from the refresh list.
Definition base.cc:635
Device & device_
Reference to the device instance used for uploading.
Definition base.h:1714
DeviceParameterRefresher(Device &device, std::chrono::milliseconds intervalBetweenUploads)
Constructor initializes the refresher with a device reference and upload interval.
Definition base.cc:603
std::chrono::milliseconds interval_
Time to wait between consecutive parameter uploads.
Definition base.h:1708
std::mutex mutex_
Mutex protecting access to shared data members.
Definition base.h:1711
std::condition_variable cv_
Condition variable used to notify the worker thread.
Definition base.h:1710
std::thread worker_
The background thread performing periodic uploads.
Definition base.h:1716
void add(uint16_t index, uint8_t subindex)
Add a parameter identified by (index, subindex) to the refresh list.
Definition base.cc:609
void stop()
Stops the refresher background thread if it is running.
Definition base.cc:651
uint16_t position() const noexcept
Returns the device position or ID.
Definition base.cc:324
int code() const noexcept
Returns the device-specific error code.
Definition base.cc:328
DeviceResponseException(const std::string &what_arg, uint16_t position, int code)
Constructs a DeviceResponseException.
Definition base.cc:320
Abstract interface representing a generic device.
Definition base.h:1037
virtual ~Device()=default
Virtual destructor for Device interface.
virtual uint16_t getPosition() const =0
Gets the device's position in the network chain.
virtual size_t loadParameters(bool readValues, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(9000))=0
Loads parameters from the device and stores them locally.
virtual Parameter & upload(uint16_t index, uint8_t subindex, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Uploads a parameter from the device via SDO and updates the local parameter store.
virtual void removeFile(const std::string &filename, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Removes a file from the device.
virtual void exchangeProcessDataAndUpdateParameters(uint64_t missedCycles=0)=0
Exchanges process data with the remote device and updates local parameters accordingly.
virtual void writeFile(const std::string &filename, const std::vector< uint8_t > &data, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Sends a file to the device.
virtual void download(uint16_t index, uint8_t subindex, const ParameterValue &value, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Sets a parameter value in the local store and downloads it to the device.
virtual PdoMappingStatus getPdoMappingStatus(uint16_t index, uint8_t subindex) const =0
Determines the PDO mapping status of a parameter by its index and subindex.
virtual void updateFirmware(const std::vector< std::uint8_t > &data, const std::vector< std::string > &skipFiles={}, std::function< void(uint8_t, std::string)> progressCallback=nullptr, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(60000))=0
Updates the device firmwares.
virtual std::vector< uint8_t > readFile(const std::string &filename, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Reads the contents of a file from the device.
virtual std::vector< std::string > readFileList(const bool stripSizeSuffix, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Reads a list of file names from the device.
virtual void clearParameters()=0
Clears all loaded object dictionary parameters.
virtual bool isOnline()=0
Checks if the device is online.
virtual void download(uint16_t index, uint8_t subindex, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Downloads a parameter to the device using SDO communication.
virtual bool setState(uint8_t state, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Sets the device to a specified state.
virtual Parameter & findParameter(uint16_t index, uint8_t subindex)=0
Finds and returns a reference to a parameter by its index and subindex.
virtual std::vector< std::reference_wrapper< Parameter > > parameters()=0
Get a vector of references to parameters.
virtual uint8_t getState(bool refresh=false, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
Reads and returns the current state of the device.
Represents a device parameter identified by index and subindex.
Definition base.h:468
bool hasAllRead() const
Checks if all read access flags are set in the access field.
Definition base.cc:208
ParameterValue getValue() const
Retrieves the value of the parameter based on its data type.
Definition base.cc:41
ObjectDataType dataType
The data type of the parameter.
Definition base.h:514
T getIntValue()
Converts the internal byte vector to an integer of type T.
Definition base.h:643
ObjectCode code
The object code for the parameter.
Definition base.h:519
ObjectFlags access
The access flags for the parameter.
Definition base.h:529
std::optional< T > tryGetValue() const
Attempts to retrieve the parameter value from the ParameterValue variant as the specified type.
Definition base.h:622
std::string name
Name of the parameter.
Definition base.h:489
static void to_json(nlohmann::json &j, const Parameter &p)
Serializes a Parameter object to JSON.
Definition base.cc:216
static void from_json(const nlohmann::json &j, Parameter &p)
Deserializes a Parameter object from JSON.
Definition base.cc:228
std::pair< uint16_t, uint8_t > Address
Alias for a pair of uint16_t and uint8_t representing a parameter address.
Definition base.h:478
void setValue(const T &value)
Sets the parameter value using a strongly-typed input.
Definition base.h:687
std::vector< std::uint8_t > data
Holds raw data as a vector of uint8_t elements.
Definition base.h:542
bool operator==(const Parameter &other) const
Checks if two Parameter objects are equal.
Definition base.h:839
std::uint16_t index
Index of the parameter.
Definition base.h:494
T getValue() const
Retrieves the parameter value from the ParameterValue variant as the specified type.
Definition base.h:594
bool operator<(const Parameter &other) const
Compares two Parameter objects for ordering.
Definition base.h:803
bool trySetValue(const T &value)
Attempts to set the parameter value with a strongly-typed input.
Definition base.h:710
std::uint16_t bitLength
Bit length of the parameter.
Definition base.h:504
bool hasAllWrite() const
Checks if all write access flags are set in the access field.
Definition base.cc:212
std::string group
Name of the group this parameter belongs to. Applicable only to ARRAY and RECORD objects.
Definition base.h:484
ObjectFlags flags
The object flags for the parameter.
Definition base.h:524
bool operator>(const Parameter &other) const
Compares two Parameter objects for reverse ordering.
Definition base.h:821
std::uint8_t subindex
Subindex of the parameter.
Definition base.h:499
void setValue(const ParameterValue &value)
Sets the internal raw data representation from a given value.
Definition base.cc:129
int byteLength
Byte length of the parameter.
Definition base.h:509
PdoMappingStatus pdoMappingStatus
PDO mapping status of this parameter.
Definition base.h:537
uint8_t * value
Definition co_dictionary.h:9
uint16_t index
Definition co_dictionary.h:0
Definition base.cc:13
void from_json(const nlohmann::json &j, UiPdoMapping &p)
Deserialize a JSON object into a UiPdoMapping structure.
Definition base.cc:15
std::string makeParameterId(int index, int subindex)
Formats the given index and subindex into a parameter identifier string.
Definition base.h:1579
std::string deviceFileErrorToString(DeviceFileError error)
Convert a DeviceFileError enum value to a human-readable string.
Definition base.h:1007
std::set< std::string > kNonPartedFileNames
Set of filenames that are always stored as complete files and can be read directly.
Definition base.cc:330
bool operator==(uint32_t lhs, EtherCATVendorID rhs)
Compares a uint32_t value with an EtherCATVendorID enum value.
Definition base.h:100
constexpr std::size_t kDeviceFilePartSize
Definition base.h:85
ObjectDataType
Enumerates the supported data types for parameters.
Definition base.h:272
@ BIT14
14-bit field.
Definition base.h:293
@ UNSIGNED40
40-bit unsigned integer.
Definition base.h:314
@ INTEGER16
16-bit signed integer.
Definition base.h:302
@ UNICODE_STRING
Definition base.h:326
@ BACKUP_PARAMETER
For BACKUP_PARAMETER definition see ETG.1020.
Definition base.h:342
@ UNSPECIFIED
Undefined or unknown data type.
Definition base.h:273
@ INTEGER64
64-bit signed integer.
Definition base.h:308
@ SM_SYNCHRONIZATION
For SM_SYNCHRONIZATION definition see ETG.1000.
Definition base.h:338
@ EXTERNAL_SYNC_STATUS
Definition base.h:348
@ BIT8
8-bit field.
Definition base.h:287
@ ERROR_SETTING
For ERROR_SETTING definition see ETG.1020.
Definition base.h:345
@ INTEGER32
32-bit signed integer.
Definition base.h:304
@ BIT10
10-bit field.
Definition base.h:289
@ ARRAY_OF_INT
Sequence of INT.
Definition base.h:328
@ TIME_OF_DAY
Time of day format (implementation-defined).
Definition base.h:358
@ REAL32
32-bit floating-point number.
Definition base.h:319
@ UNSIGNED56
56-bit unsigned integer.
Definition base.h:316
@ UNSIGNED8
8-bit unsigned integer.
Definition base.h:310
@ MODULAR_DEVICE_PARAMETER
Definition base.h:343
@ BITARR8
Array of 8 bits.
Definition base.h:297
@ BITARR32
Array of 32 bits.
Definition base.h:299
@ UNSIGNED64
64-bit unsigned integer.
Definition base.h:317
@ BIT3
3-bit field.
Definition base.h:282
@ REAL64
64-bit floating-point number (double).
Definition base.h:320
@ DEFTYPE_FSOECOMMPAR
Definition base.h:354
@ BIT13
13-bit field.
Definition base.h:292
@ GUID
128-bit globally unique identifier.
Definition base.h:322
@ BIT1
1-bit field.
Definition base.h:280
@ INTEGER40
40-bit signed integer.
Definition base.h:305
@ PDO_PARAMETER
For PDO_PARAMETER definition see ETG.1020.
Definition base.h:336
@ ENUM
For ENUM definition see ETG.1020.
Definition base.h:337
@ EXTERNAL_SYNC_SETTINGS
Definition base.h:350
@ UNSIGNED48
48-bit unsigned integer.
Definition base.h:315
@ DWORD
Four octets (32 bits) unsigned integer.
Definition base.h:278
@ BIT9
9-bit field.
Definition base.h:288
@ BIT16
16-bit field.
Definition base.h:295
@ UTYPE_END
End of user-defined type range.
Definition base.h:362
@ ARRAY_OF_SINT
Sequence of SINT.
Definition base.h:329
@ RECORD
Definition base.h:340
@ UNSIGNED16
16-bit unsigned integer.
Definition base.h:311
@ INTEGER48
48-bit signed integer.
Definition base.h:306
@ ARRAY_OF_UDINT
Sequence of UDINT.
Definition base.h:331
@ BIT6
6-bit field.
Definition base.h:285
@ BIT2
2-bit field.
Definition base.h:281
@ INTEGER56
56-bit signed integer.
Definition base.h:307
@ DEFTYPE_FSOEFRAME
Definition base.h:352
@ BITARR16
Array of 16 bits.
Definition base.h:298
@ VISIBLE_STRING
Null-terminated ASCII string.
Definition base.h:324
@ BIT11
11-bit field.
Definition base.h:290
@ BIT4
4-bit field.
Definition base.h:283
@ BIT12
12-bit field.
Definition base.h:291
@ WORD
Two octets (16 bits) unsigned integer.
Definition base.h:277
@ BIT5
5-bit field.
Definition base.h:284
@ BIT15
15-bit field.
Definition base.h:294
@ BOOLEAN
Boolean value (true or false).
Definition base.h:275
@ BIT7
7-bit field.
Definition base.h:286
@ UNSIGNED32
32-bit unsigned integer.
Definition base.h:313
@ DIAGNOSIS_HISTORY
For DIAGNOSIS_HISTORY definition see ETG.1020.
Definition base.h:346
@ INTEGER24
24-bit signed integer.
Definition base.h:303
@ ARRAY_OF_DINT
Sequence of DINT.
Definition base.h:330
@ COMMAND_PAR
For COMMAND_PAR definition see ETG.1000.
Definition base.h:335
@ IDENTITY
For IDENTITY definition see ETG.1000.
Definition base.h:334
@ TIME_DIFFERENCE
Time difference format (implementation-defined).
Definition base.h:359
@ BYTE
8-bit unsigned integer.
Definition base.h:276
@ PDO_MAPPING
For PDO_MAPPING definition see ETG.1000.
Definition base.h:333
@ UNSIGNED24
24-bit unsigned integer.
Definition base.h:312
@ OCTET_STRING
Array of raw bytes.
Definition base.h:325
@ INTEGER8
8-bit signed integer.
Definition base.h:301
@ UTYPE_START
Start of user-defined type range.
Definition base.h:361
void writeDeviceFileInOptionalParts(Device &device, const std::string &filename, const std::vector< std::uint8_t > &data, std::function< void(uint8_t, std::string)> progressCallback, const std::chrono::steady_clock::duration expiryTime)
Write a file to a device, splitting it into parts if necessary.
Definition base.cc:430
EtherCATVendorID
Enum class representing EtherCAT vendor IDs.
Definition base.h:74
@ SYNAPTICON
Vendor ID for Synapticon GmbH.
Definition base.h:80
@ SENSODRIVE
Vendor ID for Sensodrive GmbH.
Definition base.h:82
ObjectCode
Enum class representing different object types used in the EtherCAT protocol.
Definition base.h:374
@ DEFSTRUCT
Definition structure object.
Definition base.h:376
@ DEFTYPE
Definition type object.
Definition base.h:375
@ ARRAY
Array object type.
Definition base.h:378
@ VAR
Variable object type.
Definition base.h:377
void logParametersMap(const std::unordered_map< Parameter::Address, Parameter > &parametersMap, bool sortParameters)
Logs the contents of a map of parameters with an option to sort them.
Definition base.cc:293
ObjectFlags SetObjectFlags(ObjectFlags b, ObjectFlags s, ObjectFlags p, ObjectFlags a)
Combine multiple ObjectFlags values into one.
Definition base.h:255
bool isComBinFile(const std::string &filename)
Checks whether a given filename starts with "com_" and ends with ".bin".
Definition base.h:950
void removeDeviceFileOrParts(Device &device, const std::string &filename, const std::chrono::steady_clock::duration expiryTime)
Removes a file from the device, including handling multipart files if applicable.
Definition base.cc:503
ObjectFlags operator|(ObjectFlags lhs, ObjectFlags rhs)
Bitwise OR operator for ObjectFlags enum class.
Definition base.h:207
DeviceFileError
Enumeration of possible device file-related error codes.
Definition base.h:972
@ CommunicationBridgeError
Definition base.h:990
@ StorageFull
Definition base.h:976
@ PacketNumber
Definition base.h:978
@ EmptyContent
Definition base.h:991
@ FilenameLength
Definition base.h:986
@ ZipFailure
Definition base.h:993
@ FlashBusy
Definition base.h:988
@ NotFound
Definition base.h:974
@ None
Definition base.h:973
@ IllegalRequest
Definition base.h:977
@ BootstrapOnly
Definition base.h:981
@ Unknown
Definition base.h:998
@ SuccessAcknowledgement
Definition base.h:989
@ AlreadyExists
Definition base.h:979
@ UnzipFailure
Definition base.h:994
@ RemoveFailure
Definition base.h:997
@ NoUser
Definition base.h:980
@ NoRights
Definition base.h:983
@ FlashFailure
Definition base.h:995
@ Timeout
Definition base.h:987
@ AccessDenied
Definition base.h:975
@ NotBootstrap
Definition base.h:982
@ Busy
Definition base.h:985
@ ProgramError
Definition base.h:984
@ UnexpectedNullTerminator
Definition base.h:992
@ WriteFailure
Definition base.h:996
PdoMappingStatus
Represents the PDO mapping status of a parameter.
Definition base.h:441
@ MAPPED_RX_PDO
The parameter is mapped as a Receive PDO.
Definition base.h:443
@ NOT_MAPPED
The parameter is not mapped in any PDO.
Definition base.h:442
@ MAPPED_TX_PDO
The parameter is mapped as a Transmit PDO.
Definition base.h:444
void writeFirmwarePackage(Device &device, const std::vector< std::uint8_t > &data, const std::vector< std::string > &skipFiles, std::function< void(uint8_t, std::string)> progressCallback, const std::chrono::steady_clock::duration expiryTime)
Writes a firmware package to the given device.
Definition base.cc:550
std::variant< bool, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, float, double, std::string, std::vector< std::uint8_t > > ParameterValue
Alias for a variant that can hold multiple types of values.
Definition base.h:405
void assignGroupsToParameters(std::vector< Parameter > &parameters)
Assigns group names to parameters based on their index and subindex.
Definition base.cc:259
std::vector< std::uint8_t > readCompleteDeviceFile(Device &device, const std::string &filename, const std::chrono::steady_clock::duration expiryTime)
Reads a file from the device, supporting both complete and multipart zipped files.
Definition base.cc:336
ObjectFlags operator&(ObjectFlags lhs, ObjectFlags rhs)
Bitwise AND operator for ObjectFlags enum class.
Definition base.h:222
ObjectFlags & operator|=(ObjectFlags &lhs, ObjectFlags rhs)
Bitwise OR assignment operator for ObjectFlags enum class.
Definition base.h:237
ObjectFlags
Enum class representing various object flags.
Definition base.h:164
@ ALL_WR
Definition base.h:177
@ ALL_LIST_FLAGS
Definition base.h:194
@ RXPDO_MAP
Definition base.h:186
@ STARTUP
Definition base.h:192
@ OP_RDWR
Definition base.h:182
@ ALL_RDWR
Definition base.h:183
@ PO_RD
Definition base.h:168
@ ALL_RD
Definition base.h:171
@ PO_RDWR
Definition base.h:180
@ None
Definition base.h:165
@ RXTXPDO_MAP
Definition base.h:188
@ SO_WR
Definition base.h:175
@ OP_RD
Definition base.h:170
@ OP_WR
Definition base.h:176
@ SO_RDWR
Definition base.h:181
@ BACKUP
Definition base.h:191
@ SO_RD
Definition base.h:169
@ TXPDO_MAP
Definition base.h:187
@ PO_WR
Definition base.h:174
bool isAppBinFile(const std::string &filename)
Checks whether a given filename starts with "app_" and ends with ".bin".
Definition base.h:933
bool isFirmwareBinFile(const std::string &filename)
Checks whether the given file is a firmware binary file.
Definition base.h:964
std::string convertParameterValueToString(const ParameterValue &value)
Converts a ParameterValue to a string representation.
Definition base.cc:240
@ LITTLE
Definition util.h:77
T toInteger(const std::vector< std::uint8_t > &data, std::size_t offset=0, Endianness endian=Endianness::LITTLE)
Converts a byte sequence to an integer of type T with optional offset and endianness.
Definition util.h:103
Definition base.cc:13
Definition base.h:1744
void to_json(nlohmann::json &j, const mm::comm::base::MappedParameterValue &p)
Serialize MappedParameterValue to JSON.
Definition base.h:1803
void from_json(const nlohmann::json &j, mm::comm::base::MappedParameterValue &p)
Deserialize JSON into MappedParameterValue.
Definition base.h:1814
Represents a single mapped parameter value.
Definition base.h:418
uint8_t subindex
Definition base.h:420
uint16_t index
Definition base.h:419
ParameterValue value
Definition base.h:421
Holds collections of mapped parameter values for RX and TX directions.
Definition base.h:430
std::vector< MappedParameterValue > rx
Definition base.h:431
std::vector< MappedParameterValue > tx
Definition base.h:432
Represents a single PDO (Process Data Object) mapping entry.
Definition base.h:128
uint16_t index
The object dictionary index (e.g., 0x607A)
Definition base.h:130
uint8_t subindex
The subindex of the object (e.g., 0x00)
Definition base.h:131
uint8_t bitlength
The size of the mapped entry in bits (e.g., 16, 32, etc.)
Definition base.h:133
uint16_t pdoIndex
The PDO index (e.g., 0x1600 or 0x1A00)
Definition base.h:129
Represents the mapped PDO entries for a slave device.
Definition base.h:150
std::vector< PdoMappingEntry > txPdos
Definition base.h:153
std::vector< PdoMappingEntry > rxPdos
Definition base.h:151
Top-level UI configuration JSON structure.
Definition base.h:39
UiPdoMapping pdoMapping
Definition base.h:40
Represents the PDO mapping for RX and TX channels.
Definition base.h:29
std::map< std::uint16_t, std::vector< std::uint32_t > > rx
Definition base.h:30
std::map< std::uint16_t, std::vector< std::uint32_t > > tx
Definition base.h:31
static void to_json(json &j, const mm::comm::base::ParameterValue &value)
Definition base.h:1751
static void from_json(const json &j, mm::comm::base::ParameterValue &value)
Definition base.h:1755