Motion Master
Loading...
Searching...
No Matches
soem_od_entry.h
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4#include <string>
5
6#include <nlohmann/json.hpp>
7
8#include "virtual_parameter.h"
9
11 public:
12 friend class Soem;
13 friend class Soes;
14 friend class SoemMaster;
15 friend class SoemSlave;
17
18 friend void to_json(nlohmann::json& j, const SoemOdEntry& e);
19 friend void from_json(const nlohmann::json& j, SoemOdEntry& e);
20
21 Type get_parameter_type() override;
22 uint16_t get_index() override;
23 uint8_t get_subindex() override;
24 bool is_pdo_mapped() override;
25 bool set_pdo_mapping(PdoMapping pdo_mapping);
26 uint64_t get_raw_value() override;
27 uint64_t get_raw_value(bool force_refresh) override;
28 int32_t get_int_value() override;
29 int32_t get_int_value(bool force_refresh) override;
30 float get_float_value() override;
31 float get_float_value(bool force_refresh) override;
32 std::string get_string_value() override;
33 std::string get_string_value(bool force_refresh) override;
34 bool get_value_status() override;
35 int32_t set_raw_value(uint64_t value) override;
36 int32_t set_value(int32_t value) override;
37 int32_t set_value(float value) override;
38 int32_t set_value(const std::string& value) override;
39 ValueType get_value_type() override;
40 std::string get_name() override;
41 std::string get_parent_name() override;
42 bool is_read() override;
43 bool is_write() override;
44 std::string get_unit() override;
45 int32_t get_min() override;
46 int32_t get_max() override;
47 bool is_value_fresh() override;
48 bool has_value() override;
49 bool is_read_attempted() override;
50 std::string get_last_error() override;
51
52 private:
53 uint16_t absolute_slave_position_;
54
55 uint16_t index_;
56 uint8_t subindex_;
57
58 uint8_t value_[128] = {};
59
60 int32_t bit_length_;
61 uint8_t object_type_; // define(s) in co_dictionary.h
62 uint16_t entry_type_; // defined in ethercattype.h - ec_datatype
63 std::string name_;
64 std::string parent_name_;
65 uint16_t access_;
66 std::string unit_;
67 int32_t min_value_ = INT32_MIN;
68 int32_t max_value_ = INT32_MAX;
69
70 std::atomic<uint64_t> pdo_value_ = 0;
71 std::atomic_bool value_status_ = false;
72 std::atomic_bool value_initially_refreshed_ = false;
73 std::atomic_bool read_attempted_ = false;
74
77 std::string last_error_;
78 std::mutex last_error_mutex_;
79
80 void set_last_error(const std::string& error);
81
83 bool write_succeeded(int wkc, const std::string& reason);
84
86
88 enum class SdoReadMode {
91 kOnDemand,
95 kPolled,
96 };
97
99 int32_t refresh_value(SdoReadMode mode = SdoReadMode::kOnDemand);
100 int32_t set_value_sdo(uint64_t value);
101 int32_t set_value_sdo(float value);
102 int32_t set_value_sdo(const std::string& value);
103};
Definition soem_od_entry.h:10
bool is_read_attempted() override
Check if a read of the value has finished, successfully or not.
Definition soem_od_entry.cc:601
friend class ParameterValueRefresher
Definition soem_od_entry.h:16
friend class Soem
Definition soem_od_entry.h:12
bool is_pdo_mapped() override
Check if the parameter is PDO mapped.
Definition soem_od_entry.cc:205
bool set_pdo_mapping(PdoMapping pdo_mapping)
Definition soem_od_entry.cc:209
int32_t get_int_value() override
Get the integer value of the parameter.
Definition soem_od_entry.cc:229
friend void to_json(nlohmann::json &j, const SoemOdEntry &e)
Definition soem_od_entry.cc:742
std::string get_last_error() override
Get why the last read or write of the value failed.
Definition soem_od_entry.cc:732
std::string get_name() override
Get the name of the parameter.
Definition soem_od_entry.cc:555
int32_t set_value(int32_t value) override
Set an integer value.
Definition soem_od_entry.cc:336
friend class Soes
Definition soem_od_entry.h:13
bool has_value() override
Check if the parameter holds a value that was read at least once.
Definition soem_od_entry.cc:597
std::string get_parent_name() override
Get the parameter parent name.
Definition soem_od_entry.cc:557
std::string get_unit() override
Get the defined unit of the parameter value.
Definition soem_od_entry.cc:577
friend class SoemSlave
Definition soem_od_entry.h:15
Type get_parameter_type() override
Get the type of the parameter.
Definition soem_od_entry.cc:197
bool is_write() override
Definition soem_od_entry.cc:575
ValueType get_value_type() override
Get the parameter value type.
Definition soem_od_entry.cc:520
float get_float_value() override
Get the float value of the parameter.
Definition soem_od_entry.cc:279
bool get_value_status() override
Check the current status of the parameter value.
Definition soem_od_entry.cc:309
int32_t get_max() override
Get the maximum value the parameter should hold.
Definition soem_od_entry.cc:581
bool is_read() override
Definition soem_od_entry.cc:566
bool is_value_fresh() override
Check if the value is fresh.
Definition soem_od_entry.cc:583
uint8_t get_subindex() override
Get the subindex of the parameter.
Definition soem_od_entry.cc:203
int32_t get_min() override
Get the minimum value the parameter should hold.
Definition soem_od_entry.cc:579
int32_t set_raw_value(uint64_t value) override
Set a raw (64-bit unsigned integer) value.
Definition soem_od_entry.cc:311
uint16_t get_index() override
Get the index of the parameter.
Definition soem_od_entry.cc:201
friend class SoemMaster
Definition soem_od_entry.h:14
std::string get_string_value() override
Get the string value of the parameter.
Definition soem_od_entry.cc:295
uint64_t get_raw_value() override
Get the raw (64-bit unsigned integer) value of the OD entry.
Definition soem_od_entry.cc:214
friend void from_json(const nlohmann::json &j, SoemOdEntry &e)
Definition soem_od_entry.cc:765
Definition virtual_parameter.h:9
PdoMapping
Definition virtual_parameter.h:36
@ kNotPdoMapped
Definition virtual_parameter.h:36
Type
Definition virtual_parameter.h:11
ValueType
Definition virtual_parameter.h:19
uint8_t * value
Definition co_dictionary.h:9