1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 | /* File: slave_device_pimpl.h
* This file is part of the program ethercatcpp-core
* Program description : EtherCAT driver libraries for UNIX
* Copyright (C) 2017-2024 - Robin Passama (LIRMM / CNRS) Arnaud Meline (LIRMM / CNRS) Benjamin Navarro (LIRMM / CNRS). All Right reserved.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the CeCILL-C license as published by
* the CEA CNRS INRIA, either version 1
* of the License, or (at your option) any later version.
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* CeCILL-C License for more details.
*
* You should have received a copy of the CeCILL-C License
* along with this software. If not, it can be found on the official website
* of the CeCILL licenses family (http://www.cecill.info/index.en.html).
*/
#pragma once
#include <ethercatcpp/slave_device.h>
#include "slave.h"
#include <ethercat.h> //SOEM include
#include <vector>
namespace ethercatcpp {
class SlaveDevice::Impl {
public:
Impl(SlaveDevice* self);<--- Class 'Impl' has a constructor with 1 argument that is not explicit. [+]Class 'Impl' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
void set_serial_number(uint32_t serial_number);
uint32_t eep_manufacturer() const;
uint32_t eep_device() const;
uint32_t serial_number() const;
// public API of ethercat unit device
void print_slave_info() const;
uint8_t run_steps();<--- Technically the member function 'ethercatcpp::Impl::run_steps' can be const. [+]The member function 'ethercatcpp::Impl::run_steps' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
void pre_run_step(uint8_t step);
void post_run_step(uint8_t step);
uint8_t init_steps();<--- Technically the member function 'ethercatcpp::Impl::init_steps' can be const. [+]The member function 'ethercatcpp::Impl::init_steps' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
void pre_init_step(uint8_t step);
void post_init_step(uint8_t step);
uint8_t end_steps();<--- Technically the member function 'ethercatcpp::Impl::end_steps' can be const. [+]The member function 'ethercatcpp::Impl::end_steps' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
void pre_end_step(uint8_t step);
void post_end_step(uint8_t step);
void update_buffers();
void launch_init_configuration();
void launch_end_configuration();
void set_command_mappings(uint8_t mappings);
uint8_t get_command_mappings() const;
void set_status_mappings(uint8_t mappings);
uint8_t get_status_mappings() const;
// private API of public device
SlaveInfo* slave_address();
// protected API of unit device
void set_id(const std::string& name, uint32_t manufacturer, uint32_t model);
void define_physical_buffer(syncmanager_buffer_t type, uint16_t start_addr,
uint32_t flags, uint16_t length);
uint8_t* input_buffer(uint16_t start_addr);
uint8_t* output_buffer(uint16_t start_addr);
void add_run_step(std::function<void()>&& pre,
std::function<void()>&& post);
void add_init_step(std::function<void()>&& pre,
std::function<void()>&& post);
void add_end_step(std::function<void()>&& pre,
std::function<void()>&& post);
void set_input_buffer_size(uint16_t size);
void set_output_buffer_size(uint16_t size);
void define_distributed_clock(bool have_dc);
void define_period_for_non_cyclic_steps(int period);
void configure_at_init(std::function<void()>&& func);
void configure_at_end(std::function<void()>&& func);
int read_sdo(uint16_t index, uint8_t sub_index, int32_t buffer_size,
void* buffer_ptr);
int write_sdo(uint16_t index, uint8_t sub_index, int32_t buffer_size,
void* buffer_ptr);
void configure_dc_sync0(uint32_t cycle_time_0, int32_t cycle_shift);
void configure_dc_sync0_1(uint32_t cycle_time_0, uint32_t cycle_time_1,
int32_t cycle_shift); // time in ns
int32_t read_file(std::string_view filename, uint32_t password,
int32_t size, uint8_t* buffer);
bool write_file(std::string_view filename, uint32_t password, int32_t size,
uint8_t* buffer);
bool read_sercos(uint8_t drive, uint8_t flags, uint16_t idn, int32_t size,
uint8_t* buffer);
bool write_sercos(uint8_t drive, uint8_t flags, uint16_t idn, int32_t size,
uint8_t* buffer);
#ifdef EOE_AVAILABLE
bool detect_ethernet_configuration(uint8_t port,
EthernetConfiguration& config);
bool configure_ethernet(uint8_t port, const EthernetConfiguration& config);
int32_t read_ethernet(uint8_t port, int32_t size, uint8_t* buffer);
bool write_ethernet(uint8_t port, int32_t size, uint8_t* buffer);
#endif
private:
SlaveInfo slave_;
std::function<void()> preop_init_;
std::function<void()> preop_end_;
std::vector<std::pair<std::function<void()>, std::function<void()>>>
run_steps_; // Pair : first = pre , second = post
std::vector<std::pair<std::function<void()>, std::function<void()>>>
init_steps_; // Pair : first = pre , second = post
std::vector<std::pair<std::function<void()>, std::function<void()>>>
end_steps_; // Pair : first = pre , second = post
int nb_physical_buffer_; // Number of physical buffer
uint16_t buffer_length_in_,
buffer_length_out_; // Sum of size of all input/output buffer
uint8_t nb_command_PDO_mapping_,
nb_status_PDO_mapping_; // Used to count nb of PDO declared
// Input & Output vector
std::map<uint16_t, uint16_t>
buffer_out_by_address_; // key = physical address, value = index of the
// corresponding elemnt in buffers_out_
std::map<uint16_t, uint16_t>
buffer_in_by_address_; // key = physical address, value = index of the
// corresponding elemnt in buffers_in_
std::vector<std::pair<uint8_t*, uint16_t>>
buffers_out_; // Pair : First = pointer of data struct buffer, second =
// size of data struct in bits
std::vector<std::pair<uint8_t*, uint16_t>>
buffers_in_; // Pair : First = pointer of data struct buffer, second =
// size of data struct in bits
};
} // namespace ethercatcpp
|