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
static std::string getOutputName(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:64
static OutputType getOutputType(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:58
static std::string getInputName(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:52
Represents a single I/O pin.
Definition: io_state.h:29
static std::vector< PinState > generateChangedOutputStates(const monitoring_frame::io::PinData &new_state, const monitoring_frame::io::PinData &old_state)
static std::vector< PinState > generateChangedInputStates(const monitoring_frame::io::PinData &new_state, const monitoring_frame::io::PinData &old_state)
static PinState generateInputPinState(const monitoring_frame::io::PinData &pin_data, std::size_t byte_location, std::size_t bit_location)
Represents the IO PIN field of a monitoring frame.
Definition: io_pin_data.h:72
static std::vector< PinState > generateOutputPinStates(const monitoring_frame::io::PinData &pin_data)
static PinState generateOutputPinState(const monitoring_frame::io::PinData &pin_data, std::size_t byte_location, std::size_t bit_location)
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
static bool isUsedInputBit(std::size_t byte_n, std::size_t bit_n)
static LogicalInputType getInputType(std::size_t byte_location, std::size_t bit_location)
Definition: io_pin_data.h:46
std::array< std::bitset< 8 >, NUMBER_OF_OUTPUT_BYTES > output_state
Definition: io_pin_data.h:76
std::array< std::bitset< 8 >, NUMBER_OF_INPUT_BYTES > input_state
Definition: io_pin_data.h:75
static bool isUsedOutputBit(std::size_t byte_n, std::size_t bit_n)
static std::vector< PinState > generateInputPinStates(const monitoring_frame::io::PinData &pin_data)


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 5 2022 02:13:36