RokubiminiEthercatBusManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // std
4 #include <memory>
5 #include <mutex>
6 
7 // rokubimini
9 
10 #include <rokubimini/setup/Rokubimini.hpp>
12 
14 
16 
18 namespace rokubimini
19 {
20 namespace ethercat
21 {
22 using namespace soem_interface;
23 
33 {
34 public:
35  using BusMap = std::unordered_map<std::string, std::unique_ptr<rokubimini::soem_interface::EthercatBusBase>>;
36 
37  RokubiminiEthercatBusManager() = default;
38  ~RokubiminiEthercatBusManager() override = default;
39 
48  bool addEthercatBus(rokubimini::soem_interface::EthercatBusBase* bus);
49 
58  bool addEthercatBus(std::unique_ptr<rokubimini::soem_interface::EthercatBusBase> bus);
59 
65  bool startupAllBuses();
66 
72  bool startupCommunication() override;
73 
77  void setBussesSafeOperational();
78 
82  void setBussesPreOperational();
83 
87  void setBussesOperational();
88 
98  void waitForState(const uint16_t state, const uint16_t slave = 0, const std::string& busName = "",
99  const unsigned int maxRetries = 40, const double retrySleep = 0.001);
100 
104  void readAllBuses() override;
105 
109  void writeToAllBuses() override;
110 
114  void shutdownAllBuses() override;
115 
125  {
126  return buses_.at(name).get();
127  }
128 
137  std::unique_ptr<rokubimini::soem_interface::EthercatBusBase> extractBusByName(const std::string& name);
138 
145  BusMap extractBuses();
146 
169  bool loadSetup(std::vector<std::shared_ptr<rokubimini::Rokubimini>>& rokubiminis) override;
170 
172 
190  const std::shared_ptr<setup::RokubiminiEthercat>& rokubiminiEthercatSetup) const;
191 
201  void setConfigMode() override;
202 
214  void setRunMode() override;
215 
216 protected:
223  std::recursive_mutex busMutex_;
224 
231 };
232 
233 using RokubiminiEthercatBusManagerPtr = std::shared_ptr<RokubiminiEthercatBusManager>;
234 
235 } // namespace ethercat
236 } // namespace rokubimini
std::recursive_mutex busMutex_
Mutex prohibiting simultaneous access to EtherCAT bus manager.
BusMap buses_
Map with all the Ethercat buses available.
virtual bool addRokubiminiToBus(Rokubimini *rokubimini, const std::shared_ptr< setup::Rokubimini > &rokubiminiSetup) const
rokubimini::soem_interface::EthercatBusBase * getBusByName(const std::string &name) const
Returns a non owning bus pointer. The manager still manages all the buses.
unsigned short uint16_t
std::unordered_map< std::string, std::unique_ptr< rokubimini::soem_interface::EthercatBusBase >> BusMap
std::shared_ptr< RokubiminiEthercatBusManager > RokubiminiEthercatBusManagerPtr
Class for managing an ethercat bus containing one or multiple slaves.
uint8_t state
Inherits from RokubiminiBusManager. It&#39;s used for managing the Ethercat buses.


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