EthercatSlaveBase.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // std
4 #include <cstdint>
5 #include <memory>
6 #include <mutex>
7 
8 #include <ros/console.h>
9 
10 namespace rokubimini
11 {
12 namespace soem_interface
13 {
14 class EthercatBusBase;
15 
20 {
21 public:
25  struct PdoInfo
26  {
27  // The id of the rx pdo
29  // The id of the tx pdo
31  // The size of the rx pdo
33  // The size of the tx pdo
35  // The value referencing the current pdo type on slave side
37  };
38 
39  EthercatSlaveBase(EthercatBusBase* bus, const uint32_t address);
40  virtual ~EthercatSlaveBase() = default;
41 
47  virtual std::string getName() const = 0;
48 
54  virtual bool startup() = 0;
55 
60  virtual void updateRead() = 0;
61 
66  virtual void updateWrite() = 0;
67 
71  virtual void shutdown() = 0;
72 
78  virtual PdoInfo getCurrentPdoInfo() const = 0;
79 
86  {
87  return address_;
88  }
89 
98  template <typename Value>
99  bool sendSdoWrite(const uint16_t index, const uint8_t subindex, const bool completeAccess, const Value value);
100 
109  template <typename Value>
110  bool sendSdoRead(const uint16_t index, const uint8_t subindex, const bool completeAccess, Value& value);
111 
112  // Send SDOs.
113  virtual bool sendSdoReadInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, int8_t& value)
114  {
115  return sendSdoRead(index, subindex, completeAccess, value);
116  }
117 
118  virtual bool sendSdoReadInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess, int16_t& value)
119  {
120  return sendSdoRead(index, subindex, completeAccess, value);
121  }
122 
123  virtual bool sendSdoReadInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess, int32_t& value)
124  {
125  return sendSdoRead(index, subindex, completeAccess, value);
126  }
127 
128  virtual bool sendSdoReadInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess, int64_t& value)
129  {
130  return sendSdoRead(index, subindex, completeAccess, value);
131  }
132 
133  virtual bool sendSdoReadUInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, uint8_t& value)
134  {
135  return sendSdoRead(index, subindex, completeAccess, value);
136  }
137 
138  virtual bool sendSdoReadUInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess,
139  uint16_t& value)
140  {
141  return sendSdoRead(index, subindex, completeAccess, value);
142  }
143 
144  virtual bool sendSdoReadUInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess,
145  uint32_t& value)
146  {
147  return sendSdoRead(index, subindex, completeAccess, value);
148  }
149 
150  virtual bool sendSdoReadUInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess,
151  uint64_t& value)
152  {
153  return sendSdoRead(index, subindex, completeAccess, value);
154  }
155 
156  virtual bool sendSdoReadFloat(const uint16_t index, const uint8_t subindex, const bool completeAccess, float& value)
157  {
158  return sendSdoRead(index, subindex, completeAccess, value);
159  }
160 
161  virtual bool sendSdoReadDouble(const uint16_t index, const uint8_t subindex, const bool completeAccess, double& value)
162  {
163  return sendSdoRead(index, subindex, completeAccess, value);
164  }
165 
166  virtual bool sendSdoWriteInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess,
167  const int8_t value)
168  {
169  return sendSdoWrite(index, subindex, false, value);
170  }
171 
172  virtual bool sendSdoWriteInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess,
173  const int16_t value)
174  {
175  return sendSdoWrite(index, subindex, false, value);
176  }
177 
178  virtual bool sendSdoWriteInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess,
179  const int32_t value)
180  {
181  return sendSdoWrite(index, subindex, false, value);
182  }
183 
184  virtual bool sendSdoWriteInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess,
185  const int64_t value)
186  {
187  return sendSdoWrite(index, subindex, false, value);
188  }
189 
190  virtual bool sendSdoWriteUInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess,
191  const uint8_t value)
192  {
193  return sendSdoWrite(index, subindex, false, value);
194  }
195 
196  virtual bool sendSdoWriteUInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess,
197  const uint16_t value)
198  {
199  return sendSdoWrite(index, subindex, false, value);
200  }
201 
202  virtual bool sendSdoWriteUInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess,
203  const uint32_t value)
204  {
205  return sendSdoWrite(index, subindex, false, value);
206  }
207 
208  virtual bool sendSdoWriteUInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess,
209  const uint64_t value)
210  {
211  return sendSdoWrite(index, subindex, false, value);
212  }
213 
214  virtual bool sendSdoWriteFloat(const uint16_t index, const uint8_t subindex, const bool completeAccess,
215  const float value)
216  {
217  return sendSdoWrite(index, subindex, false, value);
218  }
219 
220  virtual bool sendSdoWriteDouble(const uint16_t index, const uint8_t subindex, const bool completeAccess,
221  const double value)
222  {
223  return sendSdoWrite(index, subindex, false, value);
224  }
225 
226  virtual bool sendSdoReadGeneric(const std::string& indexString, const std::string& subindexString,
227  const std::string& valueTypeString, std::string& valueString);
228  virtual bool sendSdoWriteGeneric(const std::string& indexString, const std::string& subindexString,
229  const std::string& valueTypeString, const std::string& valueString);
230 
231 protected:
236  {
237  ROS_WARN_STREAM("Functionality is not implemented.");
238  }
239 
240  // Mutex prohibiting simultaneous access to EtherCAT slave.
241  mutable std::recursive_mutex mutex_;
242  // Non owning pointer to the ethercat bus
244  // The bus address
245  const uint32_t address_{ 0 };
246 };
247 
248 using EthercatSlaveBasePtr = std::shared_ptr<EthercatSlaveBase>;
249 
250 } // namespace soem_interface
251 } // namespace rokubimini
virtual bool sendSdoWriteUInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess, const uint32_t value)
virtual PdoInfo getCurrentPdoInfo() const =0
Gets the current pdo information.
void printWarnNotImplemented()
Prints a warning. Use this method to suppress compiler warnings.
virtual bool sendSdoWriteDouble(const uint16_t index, const uint8_t subindex, const bool completeAccess, const double value)
virtual bool startup()=0
Startup non-ethercat specific objects for the slave.
virtual void updateWrite()=0
Called during writing to the ethercat bus. Use this method to stage a command for the slave...
virtual bool sendSdoWriteInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess, const int16_t value)
EthercatSlaveBase(EthercatBusBase *bus, const uint32_t address)
virtual bool sendSdoReadInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess, int32_t &value)
virtual bool sendSdoReadInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, int8_t &value)
Base class for generic ethercat slaves using soem.
virtual bool sendSdoWriteInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, const int8_t value)
unsigned short uint16_t
bool sendSdoRead(const uint16_t index, const uint8_t subindex, const bool completeAccess, Value &value)
unsigned char uint8_t
virtual bool sendSdoWriteFloat(const uint16_t index, const uint8_t subindex, const bool completeAccess, const float value)
uint32_t getAddress() const
Returns the bus address of the slave.
virtual bool sendSdoWriteUInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, const uint8_t value)
virtual bool sendSdoWriteUInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess, const uint16_t value)
virtual bool sendSdoWriteInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess, const int32_t value)
virtual bool sendSdoReadUInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess, uint64_t &value)
unsigned int uint32_t
virtual bool sendSdoWriteInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess, const int64_t value)
signed short int16_t
virtual void shutdown()=0
Used to shutdown slave specific objects.
virtual void updateRead()=0
Called during reading the ethercat bus. Use this method to extract readings from the ethercat bus buf...
std::shared_ptr< EthercatSlaveBase > EthercatSlaveBasePtr
virtual bool sendSdoReadInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess, int16_t &value)
unsigned __int64 uint64_t
virtual bool sendSdoWriteGeneric(const std::string &indexString, const std::string &subindexString, const std::string &valueTypeString, const std::string &valueString)
virtual bool sendSdoReadFloat(const uint16_t index, const uint8_t subindex, const bool completeAccess, float &value)
signed char int8_t
#define ROS_WARN_STREAM(args)
virtual bool sendSdoReadUInt32(const uint16_t index, const uint8_t subindex, const bool completeAccess, uint32_t &value)
virtual bool sendSdoReadDouble(const uint16_t index, const uint8_t subindex, const bool completeAccess, double &value)
signed __int64 int64_t
Struct defining the Pdo characteristic.
Class for managing an ethercat bus containing one or multiple slaves.
virtual bool sendSdoReadUInt8(const uint16_t index, const uint8_t subindex, const bool completeAccess, uint8_t &value)
bool sendSdoWrite(const uint16_t index, const uint8_t subindex, const bool completeAccess, const Value value)
virtual bool sendSdoReadInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess, int64_t &value)
signed int int32_t
virtual std::string getName() const =0
Returns the name of the slave.
virtual bool sendSdoWriteUInt64(const uint16_t index, const uint8_t subindex, const bool completeAccess, const uint64_t value)
virtual bool sendSdoReadUInt16(const uint16_t index, const uint8_t subindex, const bool completeAccess, uint16_t &value)
virtual bool sendSdoReadGeneric(const std::string &indexString, const std::string &subindexString, const std::string &valueTypeString, std::string &valueString)


rokubimini_ethercat
Author(s):
autogenerated on Wed Mar 3 2021 03:09:16