KaCanOpen
 All Classes Functions Variables Typedefs Enumerations Pages
master.h
1 /*
2  * Copyright (c) 2015, Thomas Keh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 #include "core.h"
35 #include "device.h"
36 
37 #include <vector>
38 #include <bitset>
39 
40 namespace kaco {
41 
47  class Master {
48 
49  public:
50 
53  Master();
54 
56  Master(const Master&) = delete;
57 
59  Master(Master&&) = delete;
60 
62  ~Master();
63 
71  bool start(const std::string busname, const std::string& baudrate);
72 
81  bool start(const std::string busname, const unsigned baudrate);
82 
84  void stop();
85 
88  size_t num_devices() const;
89 
93  Device& get_device(size_t index) const;
94 
97 
98  private:
99 
100  static const bool debug = false;
101 
102  std::vector<std::unique_ptr<Device>> m_devices;
103  std::bitset<265> m_device_alive;
104 
105  NMT::DeviceAliveCallback m_device_alive_callback_functional;
106  bool m_running{false};
107 
108  void device_alive_callback(const uint8_t node_id);
109 
110  };
111 
112 } // end namespace kaco
Device & get_device(size_t index) const
Returns a reference to a slave device object.
Definition: master.cpp:84
~Master()
Destructor.
Definition: master.cpp:45
size_t num_devices() const
Returns the number of slave devices in the network.
Definition: master.cpp:80
void stop()
Stops master and core.
Definition: master.cpp:75
bool start(const std::string busname, const std::string &baudrate)
Starts master and creates Core.
Definition: master.cpp:51
Master()
Constructor. Creates Core instance and adds NMT listener for new devices.
Definition: master.cpp:40
This class implements the Core of KaCanOpen It communicates with the CAN driver, sends CAN messages a...
Definition: core.h:59
This class represents a master node. It listens for new slaves and provides access to them via get_sl...
Definition: master.h:47
Core core
Core instance.
Definition: master.h:96
This class represents a CanOpen slave device in the network.
Definition: device.h:83
std::function< void(const uint8_t node_id) > DeviceAliveCallback
Type of a device alive callback function Important: Never call register_device_alive_callback() from ...
Definition: nmt.h:57