33 #include "canopen_error.h"
44 : type(Type::invalid),
45 m_value_changed_callbacks_mutex(new std::mutex),
46 m_read_write_mutex(new std::recursive_mutex)
50 Entry::Entry(
const uint16_t _index,
const uint8_t _subindex,
const std::string& _name,
const Type _type,
const AccessType _access_type)
55 access_type(_access_type),
59 m_value_changed_callbacks_mutex(new std::mutex),
60 m_read_write_mutex(new std::recursive_mutex)
69 bool value_changed =
false;
72 std::lock_guard<std::recursive_mutex> lock(*m_read_write_mutex);
74 if (m_value.
type !=
type || m_value != value) {
84 std::lock_guard<std::mutex> lock(*m_value_changed_callbacks_mutex);
85 for (
auto& callback : m_value_changed_callbacks) {
95 std::lock_guard<std::recursive_mutex> lock(*m_read_write_mutex);
97 throw canopen_error(
"[Entry::get_value] Value is not valid.");
111 std::lock_guard<std::mutex> lock(*m_value_changed_callbacks_mutex);
112 m_value_changed_callbacks.push_back(std::move(callback));
117 std::cout <<
"0x"<<std::hex<<
index;
119 std::cout << std::dec<<(unsigned)
subindex;
123 std::cout << std::setw(75) << std::left <<
name;
127 std::cout << std::setw(10) <<
get_value();
129 std::cout << std::setw(10) <<
"empty";
132 std::cout << std::endl;
Type get_type() const
Returns the data type.
static std::string access_type_to_string(AccessType type)
Converts access types to a string.
void add_value_changed_callback(ValueChangedCallback callback)
Registers a given function to be called when the value is changed.
Type type
Data type of the value.
std::function< void(const Value &value) > ValueChangedCallback
type of a callback for a value changed event Important: Never call add_value_changed_callback() from ...
const Value & get_value() const
Returns the value.
void set_value(const Value &value)
Sets the value.
AccessType access_type
Accessibility of the entry.
uint16_t index
index in dictionary
std::string name
Human-readable name Should be escaped for consitency using Utils::escape().
uint8_t subindex
subindex in dictionary. if is_array==true, this variable is not used
This is the base class of all types of exceptions thrown by the KaCanOpen library. It can be used directly like std::runtime_error if there isn't any more specific error class.
static std::string type_to_string(Type type)
Converts data types to a string.
Type type
Tyoe of the value.
bool valid() const
Returns if the value is set/valid.
bool operator<(const Entry &other) const
Compares entries by index and subindex. This can be used for sorting the dictionary.
This class represents an entry in the object dictionary of a device.
void print() const
Prints relevant information concerning this entry on standard output - name, index, possibly value, ... This is used by Device::print_dictionary()
Entry()
Constructs an empty entry.
This class contains a value to be stored in the object dictionary. The value can have one of the type...