32 #include "entry_subscriber.h"
36 #include "sdo_error.h"
43 : m_device(device), m_entry_name(entry_name), m_access_method(access_method)
47 m_device_prefix =
"device" + std::to_string(node_id) +
"/";
56 std::string topic = m_device_prefix+
"set_"+m_name;
57 DEBUG_LOG(
"Advertising "<<topic);
62 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_uint8,
this);
65 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_uint16,
this);
68 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_uint32,
this);
71 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_int8,
this);
74 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_int16,
this);
77 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_int32,
this);
80 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_boolean,
this);
83 m_subscriber = nh.subscribe(topic, queue_size, &EntrySubscriber::receive_string,
this);
86 ERROR(
"[EntryPublisher::advertise] Invalid entry type.")
91 void EntrySubscriber::receive_uint8(
const std_msgs::UInt8& msg) {
93 DEBUG_LOG(
"Recieved msg: "<<msg.data);
94 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
95 }
catch (
const sdo_error& error) {
97 ERROR(
"Exception in EntrySubscriber::receive_uint8(): "<<error.what());
101 void EntrySubscriber::receive_uint16(
const std_msgs::UInt16& msg) {
103 DEBUG_LOG(
"Recieved msg: "<<msg.data);
104 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
105 }
catch (
const sdo_error& error) {
107 ERROR(
"Exception in EntrySubscriber::receive_uint16(): "<<error.what());
111 void EntrySubscriber::receive_uint32(
const std_msgs::UInt32& msg) {
113 DEBUG_LOG(
"Recieved msg: "<<msg.data);
114 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
115 }
catch (
const sdo_error& error) {
117 ERROR(
"Exception in EntrySubscriber::receive_uint32(): "<<error.what());
121 void EntrySubscriber::receive_int8(
const std_msgs::Int8& msg) {
123 DEBUG_LOG(
"Recieved msg: "<<msg.data);
124 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
125 }
catch (
const sdo_error& error) {
127 ERROR(
"Exception in EntrySubscriber::receive_int8(): "<<error.what());
131 void EntrySubscriber::receive_int16(
const std_msgs::Int16& msg) {
133 DEBUG_LOG(
"Recieved msg: "<<msg.data);
134 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
135 }
catch (
const sdo_error& error) {
137 ERROR(
"Exception in EntrySubscriber::receive_int16(): "<<error.what());
141 void EntrySubscriber::receive_int32(
const std_msgs::Int32& msg) {
143 DEBUG_LOG(
"Recieved msg: "<<msg.data);
144 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
145 }
catch (
const sdo_error& error) {
147 ERROR(
"Exception in EntrySubscriber::receive_int32(): "<<error.what());
151 void EntrySubscriber::receive_boolean(
const std_msgs::Bool& msg) {
153 DEBUG_LOG(
"Recieved msg: "<<msg.data);
154 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
155 }
catch (
const sdo_error& error) {
157 ERROR(
"Exception in EntrySubscriber::receive_boolean(): "<<error.what());
161 void EntrySubscriber::receive_string(
const std_msgs::String& msg) {
163 DEBUG_LOG(
"Recieved msg: "<<msg.data);
164 m_device.
set_entry(m_entry_name, msg.data, m_access_method);
165 }
catch (
const sdo_error& error) {
167 ERROR(
"Exception in EntrySubscriber::receive_string(): "<<error.what());
EntrySubscriber(Device &device, const std::string &entry_name, const WriteAccessMethod access_method=WriteAccessMethod::use_default)
Constructor.
static std::string escape(const std::string &str)
Converts entry names to lower case and replaces all spaces and '-' by underscores.
uint8_t get_node_id() const
Returns the node ID of the device.
void advertise() override
This class represents a CanOpen slave device in the network.
void set_entry(const std::string &entry_name, const Value &value, const WriteAccessMethod access_method=WriteAccessMethod::use_default)
Sets the value of a dictionary entry by name internally. If the entry is configured to send an SDO on...
Type get_entry_type(const std::string &entry_name)
Returns the type of a dictionary entry identified by name as it is defined in the local dictionary...