Motion Master
Loading...
Searching...
No Matches
igh_od_entry.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef LINUX_BUILD
4
5#include <atomic>
6#include <condition_variable>
7#include <cstdint>
8#include <mutex>
9#include <string>
10
11#include "igh_dynamic.h"
12#include "virtual_parameter.h"
13
14class IghEthercatMaster;
15
16class IghOdEntry : public VirtualParameter {
17 public:
18 friend class IghEthercatMaster;
19 friend class IghEthercatSlave;
20
21 union Value {
22 uint64_t i = 0;
23 float f;
24
25 Value &operator=(const Value &other) {
26 if (&other != this) {
27 i = other.i;
28 }
29
30 return *this;
31 }
32
33 bool operator==(const Value &other) const { return i == other.i; }
34 };
35
36 enum class Error {
37 kNone = 0,
38 kMasterLinkDown,
39 kSlaveNotFound,
40 kSdoRequestInvalid,
41 kSdoRequestBusy,
42 kSdoRequestFailed,
43 kTimeout,
44 kFailed,
45 kAborted,
46 kTypeUnsupported,
47 kTypeUnknown,
48 kWriteOnlyValue,
49 kUnknown
50 };
51
52 IghOdEntry(IghEthercatMaster &master, uint16_t absolute_slave_position,
53 const ec_sdo_info_t &sdo_info,
54 const ec_sdo_info_entry_t &sdo_info_entry, uint8_t subindex);
55
56 IghOdEntry(IghEthercatMaster &master, uint16_t absolute_slave_position,
57 const ec_sdo_info_t &sdo_info, uint8_t subindex,
58 int32_t bit_length, uint16_t data_type,
59 const std::string &description, bool read_access,
60 bool write_access);
61
68
74 uint16_t get_index() override;
75
81 uint8_t get_subindex() override;
82
88 bool is_pdo_mapped() override;
89
97 bool set_pdo_mapping(PdoMapping pdo_mapping);
98
104 uint64_t get_raw_value() override;
105
113 uint64_t get_raw_value(bool force_refresh) override;
114
120 int32_t get_int_value() override;
121
129 int32_t get_int_value(bool force_refresh) override;
130
136 float get_float_value() override;
137
145 float get_float_value(bool force_refresh) override;
146
152 std::string get_string_value() override;
153
161 std::string get_string_value(bool force_refresh) override;
162
170 bool get_value_status() override;
171
179 int32_t set_raw_value(uint64_t value) override;
180
188 int32_t set_value(int32_t value) override;
189
197 int32_t set_value(float value) override;
198
206 int32_t set_value(const std::string &value) override;
207
213 ValueType get_value_type() override;
214
220 std::string get_name() override;
221
230 std::string get_parent_name() override;
231
237 bool is_read() override;
238
244 bool is_write() override;
245
251 std::string get_unit() override;
252
260 int32_t get_min() override;
261
269 int32_t get_max() override;
270
276 bool is_value_fresh() override;
277
281 void set_value_stale();
282
288 IghOdEntry::Error refresh_value();
289
299 IghOdEntry::Error try_refresh_value();
300
301 private:
302 IghEthercatMaster &master_;
303 uint16_t absolute_slave_position_;
304
305 uint16_t index_;
306 uint8_t subindex_;
307
308 Value value_;
309 std::string value_string_;
310
311 int32_t bit_length_;
312 uint8_t object_type_; // define(s) in co_dictionary.h
313 uint16_t entry_type_; // define(s) in co_dictionary.h
314 std::string name_;
315 std::string parent_name_;
316 bool read_access_;
317 bool write_access_;
318 std::string unit_;
319 int32_t min_value_ = INT32_MIN;
320 int32_t max_value_ = INT32_MAX;
321
322 ec_sdo_request_t *upload_sdo_request_ = nullptr;
323 ec_request_state_t upload_sdo_request_state_ = EC_REQUEST_UNUSED;
324
325 ec_sdo_request_t *download_sdo_request_ = nullptr;
326 ec_request_state_t download_sdo_request_state_ = EC_REQUEST_UNUSED;
327
328 std::atomic_bool value_status_ = false;
329 std::atomic_bool value_initially_refreshed_ = false;
330 std::atomic_bool value_fresh_ = false;
331 std::atomic_int refresh_value_sync_timeout_counter_ = 0;
332
333 std::mutex set_value_sdo_mutex_;
334
335 PdoMapping pdo_mapping_ = PdoMapping::kNotPdoMapped;
336
344 int32_t set_value_sdo(uint64_t value);
345
353 int32_t set_value_sdo(const std::string &value);
354};
355
356#endif
Error
Definition: motion_master_error.h:8
Definition: virtual_parameter.h:9
virtual std::string get_parent_name()=0
Get the parameter parent name.
virtual bool is_pdo_mapped()=0
Check if the parameter is PDO mapped.
virtual uint16_t get_index()=0
Get the index of the parameter.
virtual int32_t get_min()
Get the minimum value the parameter should hold.
Definition: virtual_parameter.h:227
virtual bool is_value_fresh()=0
Check if the value is fresh.
virtual Type get_parameter_type()
Get the type of the parameter.
Definition: virtual_parameter.h:39
virtual std::string get_name()=0
Get the name of the parameter.
virtual bool is_read()
Check if the parameter can be read.
Definition: virtual_parameter.h:204
virtual bool is_write()
Check if the parameter can be written into.
Definition: virtual_parameter.h:211
virtual bool get_value_status()=0
Check the current status of the parameter value.
virtual uint8_t get_subindex()=0
Get the subindex of the parameter.
Type
Definition: virtual_parameter.h:11
virtual int32_t set_value(int32_t value)=0
Set an integer value.
virtual std::string get_string_value()=0
Get the string value of the parameter.
virtual uint64_t get_raw_value()=0
Get the raw (64-bit unsigned integer) value of the OD entry.
virtual int32_t get_int_value()=0
Get the integer value of the parameter.
virtual int32_t get_max()
Get the maximum value the parameter should hold.
Definition: virtual_parameter.h:236
virtual float get_float_value()=0
Get the float value of the parameter.
virtual int32_t set_raw_value(uint64_t value)=0
Set a raw (64-bit unsigned integer) value.
virtual ValueType get_value_type()=0
Get the parameter value type.
virtual std::string get_unit()
Get the defined unit of the parameter value.
Definition: virtual_parameter.h:218
uint8_t * value
Definition: co_dictionary.h:9
uint16_t data_type
Definition: co_dictionary.h:2
bool operator==(uint32_t lhs, EtherCATVendorID rhs)
Compares a uint32_t value with an EtherCATVendorID enum value.
Definition: common.h:130