diff --git a/api/classethercat__interface_1_1EcPdoChannelManager.html b/api/classethercat__interface_1_1EcPdoChannelManager.html index 4ba6d3d..6dacf43 100644 --- a/api/classethercat__interface_1_1EcPdoChannelManager.html +++ b/api/classethercat__interface_1_1EcPdoChannelManager.html @@ -111,7 +111,7 @@   std::string interface_name   -uint8_t data_mask = 0 +uint8_t data_mask = 255   double default_value = std::numeric_limits<double>::quiet_NaN()   @@ -459,7 +459,7 @@

- +
uint8_t ethercat_interface::EcPdoChannelManager::data_mask = 0uint8_t ethercat_interface::EcPdoChannelManager::data_mask = 255
diff --git a/api/ec__pdo__channel__manager_8hpp_source.html b/api/ec__pdo__channel__manager_8hpp_source.html index d0841c9..ae87d02 100644 --- a/api/ec__pdo__channel__manager_8hpp_source.html +++ b/api/ec__pdo__channel__manager_8hpp_source.html @@ -138,194 +138,196 @@
65  last_value = static_cast<double>(EC_READ_U64(domain_address));
66  } else if (data_type == "int64") {
67  last_value = static_cast<double>(EC_READ_S64(domain_address));
-
68  } else {
-
69  last_value = static_cast<double>(EC_READ_U8(domain_address) & data_mask);
-
70  }
- -
72  return last_value;
-
73  }
-
74 
-
75  void ec_write(uint8_t * domain_address, double value)
-
76  {
-
77  if (data_type == "uint8") {
-
78  EC_WRITE_U8(domain_address, static_cast<uint8_t>(value));
-
79  } else if (data_type == "int8") {
-
80  EC_WRITE_S8(domain_address, static_cast<int8_t>(value));
-
81  } else if (data_type == "uint16") {
-
82  EC_WRITE_U16(domain_address, static_cast<uint16_t>(value));
-
83  } else if (data_type == "int16") {
-
84  EC_WRITE_S16(domain_address, static_cast<int16_t>(value));
-
85  } else if (data_type == "uint32") {
-
86  EC_WRITE_U32(domain_address, static_cast<uint32_t>(value));
-
87  } else if (data_type == "int32") {
-
88  EC_WRITE_S32(domain_address, static_cast<int32_t>(value));
-
89  } else if (data_type == "uint64") {
-
90  EC_WRITE_U64(domain_address, static_cast<uint64_t>(value));
-
91  } else if (data_type == "int64") {
-
92  EC_WRITE_S64(domain_address, static_cast<int64_t>(value));
-
93  } else {
-
94  buffer_ = EC_READ_U8(domain_address);
-
95  if (popcount(data_mask) == 1) {
-
96  buffer_ &= (data_mask - 1);
-
97  if (value) {buffer_ += data_mask;}
-
98  } else if (data_mask != 0) {
-
99  buffer_ = 0;
-
100  buffer_ |= (static_cast<uint8_t>(value) & data_mask);
-
101  }
-
102  EC_WRITE_U8(domain_address, buffer_);
-
103  }
-
104  last_value = value;
-
105  }
-
106 
-
107  void ec_update(uint8_t * domain_address)
-
108  {
-
109  // update state interface
-
110  if (pdo_type == TPDO) {
-
111  ec_read(domain_address);
-
112  if (interface_index >= 0) {
-
113  state_interface_ptr_->at(interface_index) = last_value;
-
114  }
-
115  } else if (pdo_type == RPDO && allow_ec_write) {
-
116  if (interface_index >= 0 &&
-
117  !std::isnan(command_interface_ptr_->at(interface_index)) &&
- -
119  {
-
120  ec_write(domain_address, factor * command_interface_ptr_->at(interface_index) + offset);
-
121  } else {
-
122  if (!std::isnan(default_value)) {
-
123  ec_write(domain_address, default_value);
-
124  }
-
125  }
-
126  }
-
127  }
-
128 
-
129  bool load_from_config(YAML::Node channel_config)
-
130  {
-
131  // index
-
132  if (channel_config["index"]) {
-
133  index = channel_config["index"].as<uint16_t>();
-
134  } else {
-
135  std::cerr << "missing channel index info" << std::endl;
-
136  }
-
137  // sub_index
-
138  if (channel_config["sub_index"]) {
-
139  sub_index = channel_config["sub_index"].as<uint8_t>();
-
140  } else {
-
141  std::cerr << "channel " << index << ": missing channel info" << std::endl;
-
142  }
-
143  // data type
-
144  if (channel_config["type"]) {
-
145  data_type = channel_config["type"].as<std::string>();
-
146  } else {
-
147  std::cerr << "channel " << index << ": missing channel data type info" << std::endl;
-
148  }
-
149 
-
150  if (pdo_type == RPDO) {
-
151  // interface name
-
152  if (channel_config["command_interface"]) {
-
153  interface_name = channel_config["command_interface"].as<std::string>();
-
154  }
-
155  // default value
-
156  if (channel_config["default"]) {
-
157  default_value = channel_config["default"].as<double>();
-
158  }
-
159 
-
160  } else if (pdo_type == TPDO) {
-
161  // interface name
-
162  if (channel_config["state_interface"]) {
-
163  interface_name = channel_config["state_interface"].as<std::string>();
-
164  }
-
165  }
-
166 
-
167  // factor
-
168  if (channel_config["factor"]) {
-
169  factor = channel_config["factor"].as<double>();
-
170  }
-
171  // offset
-
172  if (channel_config["offset"]) {
-
173  offset = channel_config["offset"].as<double>();
-
174  }
-
175  // mask
-
176  if (channel_config["mask"]) {
-
177  data_mask = channel_config["mask"].as<uint8_t>();
-
178  }
-
179 
-
180  return true;
-
181  }
-
182 
-
183  uint8_t type2bits(std::string type)
-
184  {
-
185  if (type == "bool") {
-
186  return 1;
-
187  } else if (type == "int16" || type == "uint16") {
-
188  return 16;
-
189  } else if (type == "int8" || type == "uint8") {
-
190  return 8;
-
191  } else if (type == "int16" || type == "uint16") {
-
192  return 16;
-
193  } else if (type == "int32" || type == "uint32") {
-
194  return 32;
-
195  } else if (type == "int64" || type == "uint64") {
-
196  return 64;
-
197  } else if (type.find("bit") != std::string::npos) {
-
198  std::string n_bits = type.substr(type.find("bit") + 3);
-
199  return static_cast<uint8_t>(std::stoi(n_bits));
-
200  }
-
201  return -1;
-
202  }
-
203 
- -
205  uint16_t index;
-
206  uint8_t sub_index;
-
207  std::string data_type;
-
208  std::string interface_name;
-
209  uint8_t data_mask = 0;
-
210  double default_value = std::numeric_limits<double>::quiet_NaN();
-
211  int interface_index = -1;
-
212  double last_value = std::numeric_limits<double>::quiet_NaN();
-
213  bool allow_ec_write = true;
-
214  bool override_command = false;
-
215  double factor = 1;
-
216  double offset = 0;
-
217 
-
218 private:
-
219  std::vector<double> * command_interface_ptr_;
-
220  std::vector<double> * state_interface_ptr_;
-
221  uint8_t buffer_ = 0;
-
222 
-
223  int popcount(uint8_t x)
-
224  {
-
225  int count = 0;
-
226  for (; x != 0; x >>= 1) {if (x & 1) {count++;}}
-
227  return count;
-
228  }
-
229 };
-
230 
-
231 } // namespace ethercat_interface
-
232 #endif // ETHERCAT_INTERFACE__EC_PDO_CHANNEL_MANAGER_HPP_
+
68  } else if (data_type == "bool") {
+
69  last_value = (EC_READ_U8(domain_address) & data_mask) ? 1 : 0;
+
70  } else {
+
71  last_value = static_cast<double>(EC_READ_U8(domain_address) & data_mask);
+
72  }
+ +
74  return last_value;
+
75  }
+
76 
+
77  void ec_write(uint8_t * domain_address, double value)
+
78  {
+
79  if (data_type == "uint8") {
+
80  EC_WRITE_U8(domain_address, static_cast<uint8_t>(value));
+
81  } else if (data_type == "int8") {
+
82  EC_WRITE_S8(domain_address, static_cast<int8_t>(value));
+
83  } else if (data_type == "uint16") {
+
84  EC_WRITE_U16(domain_address, static_cast<uint16_t>(value));
+
85  } else if (data_type == "int16") {
+
86  EC_WRITE_S16(domain_address, static_cast<int16_t>(value));
+
87  } else if (data_type == "uint32") {
+
88  EC_WRITE_U32(domain_address, static_cast<uint32_t>(value));
+
89  } else if (data_type == "int32") {
+
90  EC_WRITE_S32(domain_address, static_cast<int32_t>(value));
+
91  } else if (data_type == "uint64") {
+
92  EC_WRITE_U64(domain_address, static_cast<uint64_t>(value));
+
93  } else if (data_type == "int64") {
+
94  EC_WRITE_S64(domain_address, static_cast<int64_t>(value));
+
95  } else {
+
96  buffer_ = EC_READ_U8(domain_address);
+
97  if (popcount(data_mask) == 1) {
+
98  buffer_ &= (data_mask - 1);
+
99  if (value) {buffer_ += data_mask;}
+
100  } else if (data_mask != 0) {
+
101  buffer_ = 0;
+
102  buffer_ |= (static_cast<uint8_t>(value) & data_mask);
+
103  }
+
104  EC_WRITE_U8(domain_address, buffer_);
+
105  }
+
106  last_value = value;
+
107  }
+
108 
+
109  void ec_update(uint8_t * domain_address)
+
110  {
+
111  // update state interface
+
112  if (pdo_type == TPDO) {
+
113  ec_read(domain_address);
+
114  if (interface_index >= 0) {
+
115  state_interface_ptr_->at(interface_index) = last_value;
+
116  }
+
117  } else if (pdo_type == RPDO && allow_ec_write) {
+
118  if (interface_index >= 0 &&
+
119  !std::isnan(command_interface_ptr_->at(interface_index)) &&
+ +
121  {
+
122  ec_write(domain_address, factor * command_interface_ptr_->at(interface_index) + offset);
+
123  } else {
+
124  if (!std::isnan(default_value)) {
+
125  ec_write(domain_address, default_value);
+
126  }
+
127  }
+
128  }
+
129  }
+
130 
+
131  bool load_from_config(YAML::Node channel_config)
+
132  {
+
133  // index
+
134  if (channel_config["index"]) {
+
135  index = channel_config["index"].as<uint16_t>();
+
136  } else {
+
137  std::cerr << "missing channel index info" << std::endl;
+
138  }
+
139  // sub_index
+
140  if (channel_config["sub_index"]) {
+
141  sub_index = channel_config["sub_index"].as<uint8_t>();
+
142  } else {
+
143  std::cerr << "channel " << index << ": missing channel info" << std::endl;
+
144  }
+
145  // data type
+
146  if (channel_config["type"]) {
+
147  data_type = channel_config["type"].as<std::string>();
+
148  } else {
+
149  std::cerr << "channel " << index << ": missing channel data type info" << std::endl;
+
150  }
+
151 
+
152  if (pdo_type == RPDO) {
+
153  // interface name
+
154  if (channel_config["command_interface"]) {
+
155  interface_name = channel_config["command_interface"].as<std::string>();
+
156  }
+
157  // default value
+
158  if (channel_config["default"]) {
+
159  default_value = channel_config["default"].as<double>();
+
160  }
+
161 
+
162  } else if (pdo_type == TPDO) {
+
163  // interface name
+
164  if (channel_config["state_interface"]) {
+
165  interface_name = channel_config["state_interface"].as<std::string>();
+
166  }
+
167  }
+
168 
+
169  // factor
+
170  if (channel_config["factor"]) {
+
171  factor = channel_config["factor"].as<double>();
+
172  }
+
173  // offset
+
174  if (channel_config["offset"]) {
+
175  offset = channel_config["offset"].as<double>();
+
176  }
+
177  // mask
+
178  if (channel_config["mask"]) {
+
179  data_mask = channel_config["mask"].as<uint8_t>();
+
180  }
+
181 
+
182  return true;
+
183  }
+
184 
+
185  uint8_t type2bits(std::string type)
+
186  {
+
187  if (type == "bool") {
+
188  return 1;
+
189  } else if (type == "int16" || type == "uint16") {
+
190  return 16;
+
191  } else if (type == "int8" || type == "uint8") {
+
192  return 8;
+
193  } else if (type == "int16" || type == "uint16") {
+
194  return 16;
+
195  } else if (type == "int32" || type == "uint32") {
+
196  return 32;
+
197  } else if (type == "int64" || type == "uint64") {
+
198  return 64;
+
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));
+
202  }
+
203  return -1;
+
204  }
+
205 
+ +
207  uint16_t index;
+
208  uint8_t sub_index;
+
209  std::string data_type;
+
210  std::string interface_name;
+
211  uint8_t data_mask = 255;
+
212  double default_value = std::numeric_limits<double>::quiet_NaN();
+
213  int interface_index = -1;
+
214  double last_value = std::numeric_limits<double>::quiet_NaN();
+
215  bool allow_ec_write = true;
+
216  bool override_command = false;
+
217  double factor = 1;
+
218  double offset = 0;
+
219 
+
220 private:
+
221  std::vector<double> * command_interface_ptr_;
+
222  std::vector<double> * state_interface_ptr_;
+
223  uint8_t buffer_ = 0;
+
224 
+
225  int popcount(uint8_t x)
+
226  {
+
227  int count = 0;
+
228  for (; x != 0; x >>= 1) {if (x & 1) {count++;}}
+
229  return count;
+
230  }
+
231 };
+
232 
+
233 } // namespace ethercat_interface
+
234 #endif // ETHERCAT_INTERFACE__EC_PDO_CHANNEL_MANAGER_HPP_
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:208
-
void ec_update(uint8_t *domain_address)
Definition: ec_pdo_channel_manager.hpp:107
-
bool load_from_config(YAML::Node channel_config)
Definition: ec_pdo_channel_manager.hpp:129
-
double last_value
Definition: ec_pdo_channel_manager.hpp:212
+
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:213
-
int interface_index
Definition: ec_pdo_channel_manager.hpp:211
-
uint16_t index
Definition: ec_pdo_channel_manager.hpp:205
-
double offset
Definition: ec_pdo_channel_manager.hpp:216
-
double default_value
Definition: ec_pdo_channel_manager.hpp:210
-
uint8_t sub_index
Definition: ec_pdo_channel_manager.hpp:206
-
uint8_t data_mask
Definition: ec_pdo_channel_manager.hpp:209
-
PdoType pdo_type
Definition: ec_pdo_channel_manager.hpp:204
-
std::string data_type
Definition: ec_pdo_channel_manager.hpp:207
+
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:214
-
void ec_write(uint8_t *domain_address, double value)
Definition: ec_pdo_channel_manager.hpp:75
+
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:183
-
double factor
Definition: ec_pdo_channel_manager.hpp:215
+
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