io_state_conversions.h
Go to the documentation of this file.
1 // Copyright (c) 2022 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef PSEN_SCAN_V2_STANDALONE_IO_STATE_CONVERSIONS_H
17 #define PSEN_SCAN_V2_STANDALONE_IO_STATE_CONVERSIONS_H
18 
21 
22 #include <vector>
23 
25 {
26 namespace data_conversion_layer
27 {
29  std::size_t byte_location,
30  std::size_t bit_location)
31 {
32  return { static_cast<uint32_t>(byte_location * 8 + bit_location),
33  monitoring_frame::io::getInputName(byte_location, bit_location),
34  pin_data.input_state.at(byte_location).test(bit_location) };
35 }
36 
38  std::size_t byte_location,
39  std::size_t bit_location)
40 {
41  return { static_cast<uint32_t>(byte_location * 8 + bit_location),
42  monitoring_frame::io::getOutputName(byte_location, bit_location),
43  pin_data.output_state.at(byte_location).test(bit_location) };
44 }
45 
46 static inline bool isUsedInputBit(std::size_t byte_n, std::size_t bit_n)
47 {
50 }
51 
52 static inline bool isUsedOutputBit(std::size_t byte_n, std::size_t bit_n)
53 {
56 }
57 
58 static inline std::vector<PinState> generateInputPinStates(const monitoring_frame::io::PinData& pin_data)
59 {
60  std::vector<PinState> pin_states;
61  for (std::size_t byte_n = 0; byte_n < monitoring_frame::io::NUMBER_OF_INPUT_BYTES; ++byte_n)
62  {
63  for (std::size_t bit_n = 0; bit_n < 8; ++bit_n)
64  {
65  if (isUsedInputBit(byte_n, bit_n))
66  {
67  pin_states.emplace_back(generateInputPinState(pin_data, byte_n, bit_n));
68  }
69  }
70  }
71  return pin_states;
72 }
73 
74 static inline std::vector<PinState> generateOutputPinStates(const monitoring_frame::io::PinData& pin_data)
75 {
76  std::vector<PinState> pin_states;
77  for (std::size_t byte_n = 0; byte_n < monitoring_frame::io::NUMBER_OF_OUTPUT_BYTES; ++byte_n)
78  {
79  for (std::size_t bit_n = 0; bit_n < 8; ++bit_n)
80  {
81  if (isUsedOutputBit(byte_n, bit_n))
82  {
83  pin_states.emplace_back(generateOutputPinState(pin_data, byte_n, bit_n));
84  }
85  }
86  }
87  return pin_states;
88 }
89 
90 static inline std::vector<PinState> generateChangedInputStates(const monitoring_frame::io::PinData& new_state,
91  const monitoring_frame::io::PinData& old_state)
92 {
93  std::vector<PinState> pin_states;
94  for (std::size_t byte_n = 0; byte_n < new_state.input_state.size(); ++byte_n)
95  {
96  for (std::size_t bit_n = 0; bit_n < 8; ++bit_n)
97  {
98  if (isUsedInputBit(byte_n, bit_n) &&
99  (new_state.input_state.at(byte_n).test(bit_n) ^ old_state.input_state.at(byte_n).test(bit_n)))
100  {
101  pin_states.emplace_back(generateInputPinState(new_state, byte_n, bit_n));
102  }
103  }
104  }
105  return pin_states;
106 }
107 
108 static inline std::vector<PinState> generateChangedOutputStates(const monitoring_frame::io::PinData& new_state,
109  const monitoring_frame::io::PinData& old_state)
110 {
111  std::vector<PinState> pin_states;
112  for (std::size_t byte_n = 0; byte_n < new_state.output_state.size(); ++byte_n)
113  {
114  for (std::size_t bit_n = 0; bit_n < 8; ++bit_n)
115  {
116  if (isUsedOutputBit(byte_n, bit_n) &&
117  (new_state.output_state.at(byte_n).test(bit_n) ^ old_state.output_state.at(byte_n).test(bit_n)))
118  {
119  pin_states.emplace_back(generateOutputPinState(new_state, byte_n, bit_n));
120  }
121  }
122  }
123  return pin_states;
124 }
125 
126 } // namespace data_conversion_layer
127 } // namespace psen_scan_v2_standalone
128 
129 #endif // PSEN_SCAN_V2_STANDALONE_IO_STATE_CONVERSIONS_H
psen_scan_v2_standalone::PinState
Represents a single I/O pin.
Definition: io_state.h:29
psen_scan_v2_standalone::data_conversion_layer::generateInputPinState
static PinState generateInputPinState(const monitoring_frame::io::PinData &pin_data, std::size_t byte_location, std::size_t bit_location)
Definition: io_state_conversions.h:28
psen_scan_v2_standalone::data_conversion_layer::generateChangedOutputStates
static std::vector< PinState > generateChangedOutputStates(const monitoring_frame::io::PinData &new_state, const monitoring_frame::io::PinData &old_state)
Definition: io_state_conversions.h:108
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::getInputName
static std::string getInputName(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:52
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::PinData
Represents the IO PIN field of a monitoring frame.
Definition: io_pin_data.h:72
psen_scan_v2_standalone::data_conversion_layer::isUsedInputBit
static bool isUsedInputBit(std::size_t byte_n, std::size_t bit_n)
Definition: io_state_conversions.h:46
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::getOutputType
static OutputType getOutputType(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:58
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::PinData::input_state
std::array< std::bitset< 8 >, NUMBER_OF_INPUT_BYTES > input_state
Definition: io_pin_data.h:75
psen_scan_v2_standalone::data_conversion_layer::generateChangedInputStates
static std::vector< PinState > generateChangedInputStates(const monitoring_frame::io::PinData &new_state, const monitoring_frame::io::PinData &old_state)
Definition: io_state_conversions.h:90
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::getInputType
static LogicalInputType getInputType(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:46
psen_scan_v2_standalone::data_conversion_layer::generateOutputPinStates
static std::vector< PinState > generateOutputPinStates(const monitoring_frame::io::PinData &pin_data)
Definition: io_state_conversions.h:74
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::getOutputName
static std::string getOutputName(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:64
psen_scan_v2_standalone::data_conversion_layer::generateInputPinStates
static std::vector< PinState > generateInputPinStates(const monitoring_frame::io::PinData &pin_data)
Definition: io_state_conversions.h:58
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::NUMBER_OF_INPUT_BYTES
static constexpr uint32_t NUMBER_OF_INPUT_BYTES
Definition: io_pin_data.h:42
io_state.h
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::OutputType::unused
@ unused
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::PinData::output_state
std::array< std::bitset< 8 >, NUMBER_OF_OUTPUT_BYTES > output_state
Definition: io_pin_data.h:76
psen_scan_v2_standalone
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::LogicalInputType::unused
@ unused
psen_scan_v2_standalone::data_conversion_layer::generateOutputPinState
static PinState generateOutputPinState(const monitoring_frame::io::PinData &pin_data, std::size_t byte_location, std::size_t bit_location)
Definition: io_state_conversions.h:37
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::NUMBER_OF_OUTPUT_BYTES
static constexpr uint32_t NUMBER_OF_OUTPUT_BYTES
Definition: io_pin_data.h:43
io_pin_data.h
psen_scan_v2_standalone::data_conversion_layer::isUsedOutputBit
static bool isUsedOutputBit(std::size_t byte_n, std::size_t bit_n)
Definition: io_state_conversions.h:52


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:11