17 #ifndef ETHERCAT_INTERFACE__EC_PDO_CHANNEL_MANAGER_HPP_
18 #define ETHERCAT_INTERFACE__EC_PDO_CHANNEL_MANAGER_HPP_
25 #include "yaml-cpp/yaml.h"
41 std::vector<double> * state_interface,
42 std::vector<double> * command_interface)
44 command_interface_ptr_ = command_interface;
45 state_interface_ptr_ = state_interface;
53 last_value =
static_cast<double>(EC_READ_U8(domain_address));
55 last_value =
static_cast<double>(EC_READ_S8(domain_address));
57 last_value =
static_cast<double>(EC_READ_U16(domain_address));
59 last_value =
static_cast<double>(EC_READ_S16(domain_address));
61 last_value =
static_cast<double>(EC_READ_U32(domain_address));
63 last_value =
static_cast<double>(EC_READ_S32(domain_address));
65 last_value =
static_cast<double>(EC_READ_U64(domain_address));
67 last_value =
static_cast<double>(EC_READ_S64(domain_address));
77 void ec_write(uint8_t * domain_address,
double value)
80 EC_WRITE_U8(domain_address,
static_cast<uint8_t
>(value));
82 EC_WRITE_S8(domain_address,
static_cast<int8_t
>(value));
84 EC_WRITE_U16(domain_address,
static_cast<uint16_t
>(value));
86 EC_WRITE_S16(domain_address,
static_cast<int16_t
>(value));
88 EC_WRITE_U32(domain_address,
static_cast<uint32_t
>(value));
90 EC_WRITE_S32(domain_address,
static_cast<int32_t
>(value));
92 EC_WRITE_U64(domain_address,
static_cast<uint64_t
>(value));
94 EC_WRITE_S64(domain_address,
static_cast<int64_t
>(value));
96 buffer_ = EC_READ_U8(domain_address);
102 buffer_ |= (
static_cast<uint8_t
>(value) &
data_mask);
104 EC_WRITE_U8(domain_address, buffer_);
134 if (channel_config[
"index"]) {
135 index = channel_config[
"index"].as<uint16_t>();
137 std::cerr <<
"missing channel index info" << std::endl;
140 if (channel_config[
"sub_index"]) {
141 sub_index = channel_config[
"sub_index"].as<uint8_t>();
143 std::cerr <<
"channel " <<
index <<
": missing channel info" << std::endl;
146 if (channel_config[
"type"]) {
147 data_type = channel_config[
"type"].as<std::string>();
149 std::cerr <<
"channel " <<
index <<
": missing channel data type info" << std::endl;
154 if (channel_config[
"command_interface"]) {
155 interface_name = channel_config[
"command_interface"].as<std::string>();
158 if (channel_config[
"default"]) {
164 if (channel_config[
"state_interface"]) {
165 interface_name = channel_config[
"state_interface"].as<std::string>();
170 if (channel_config[
"factor"]) {
171 factor = channel_config[
"factor"].as<
double>();
174 if (channel_config[
"offset"]) {
175 offset = channel_config[
"offset"].as<
double>();
178 if (channel_config[
"mask"]) {
179 data_mask = channel_config[
"mask"].as<uint8_t>();
187 if (type ==
"bool") {
189 }
else if (type ==
"int16" || type ==
"uint16") {
191 }
else if (type ==
"int8" || type ==
"uint8") {
193 }
else if (type ==
"int16" || type ==
"uint16") {
195 }
else if (type ==
"int32" || type ==
"uint32") {
197 }
else if (type ==
"int64" || type ==
"uint64") {
199 }
else if (type.find(
"bit") != std::string::npos) {
200 std::string n_bits = type.substr(type.find(
"bit") + 3);
201 return static_cast<uint8_t
>(std::stoi(n_bits));
214 double last_value = std::numeric_limits<double>::quiet_NaN();
221 std::vector<double> * command_interface_ptr_;
222 std::vector<double> * state_interface_ptr_;
225 int popcount(uint8_t x)
228 for (; x != 0; x >>= 1) {
if (x & 1) {count++;}}
Definition: ec_pdo_channel_manager.hpp:36
void setup_interface_ptrs(std::vector< double > *state_interface, std::vector< double > *command_interface)
Definition: ec_pdo_channel_manager.hpp:40
ec_pdo_entry_info_t get_pdo_entry_info()
Definition: ec_pdo_channel_manager.hpp:48
std::string interface_name
Definition: ec_pdo_channel_manager.hpp:210
void ec_update(uint8_t *domain_address)
Definition: ec_pdo_channel_manager.hpp:109
bool load_from_config(YAML::Node channel_config)
Definition: ec_pdo_channel_manager.hpp:131
double last_value
Definition: ec_pdo_channel_manager.hpp:214
double ec_read(uint8_t *domain_address)
Definition: ec_pdo_channel_manager.hpp:50
bool allow_ec_write
Definition: ec_pdo_channel_manager.hpp:215
int interface_index
Definition: ec_pdo_channel_manager.hpp:213
uint16_t index
Definition: ec_pdo_channel_manager.hpp:207
double offset
Definition: ec_pdo_channel_manager.hpp:218
double default_value
Definition: ec_pdo_channel_manager.hpp:212
uint8_t sub_index
Definition: ec_pdo_channel_manager.hpp:208
uint8_t data_mask
Definition: ec_pdo_channel_manager.hpp:211
PdoType pdo_type
Definition: ec_pdo_channel_manager.hpp:206
std::string data_type
Definition: ec_pdo_channel_manager.hpp:209
EcPdoChannelManager()
Definition: ec_pdo_channel_manager.hpp:38
bool override_command
Definition: ec_pdo_channel_manager.hpp:216
void ec_write(uint8_t *domain_address, double value)
Definition: ec_pdo_channel_manager.hpp:77
~EcPdoChannelManager()
Definition: ec_pdo_channel_manager.hpp:39
uint8_t type2bits(std::string type)
Definition: ec_pdo_channel_manager.hpp:185
double factor
Definition: ec_pdo_channel_manager.hpp:217
Definition: ec_master.hpp:29
PdoType
Definition: ec_pdo_channel_manager.hpp:30
@ TPDO
Definition: ec_pdo_channel_manager.hpp:32
@ RPDO
Definition: ec_pdo_channel_manager.hpp:31