io_pin_data.h
Go to the documentation of this file.
1 // Copyright (c) 2021-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_PIN_DATA_H
17 #define PSEN_SCAN_V2_STANDALONE_IO_PIN_DATA_H
18 
19 #include <array>
20 #include <bitset>
21 #include <ostream>
22 #include <string>
23 
24 #include <fmt/format.h>
25 #include <fmt/ostream.h>
26 
29 
31 {
32 namespace data_conversion_layer
33 {
34 namespace monitoring_frame
35 {
40 namespace io
41 {
44 
46 static inline LogicalInputType getInputType(std::size_t byte_location, std::size_t bit_location)
47 {
48  return LOGICAL_INPUT_BITS.at(byte_location).at(bit_location);
49 }
50 
52 static inline std::string getInputName(std::size_t byte_location, std::size_t bit_location)
53 {
54  return LOGICAL_INPUT_BIT_TO_NAME.at(getInputType(byte_location, bit_location));
55 }
56 
58 static inline OutputType getOutputType(std::size_t byte_location, std::size_t bit_location)
59 {
60  return OUTPUT_BITS.at(byte_location).at(bit_location);
61 }
62 
64 static inline std::string getOutputName(std::size_t byte_location, std::size_t bit_location)
65 {
66  return OUTPUT_BIT_TO_NAME.at(getOutputType(byte_location, bit_location));
67 }
68 
72 struct PinData
73 {
74  bool operator==(const PinData& pin_data) const;
75  std::array<std::bitset<8>, NUMBER_OF_INPUT_BYTES> input_state{};
76  std::array<std::bitset<8>, NUMBER_OF_OUTPUT_BYTES> output_state{};
77 };
78 
79 inline bool PinData::operator==(const PinData& pin_data) const
80 {
81  return input_state == pin_data.input_state && output_state == pin_data.output_state;
82 }
83 
84 inline std::ostream& operator<<(std::ostream& os, const PinData& pd)
85 {
86  return os << fmt::format("io::PinData(input = {}, output = {})",
89 }
90 
91 } // namespace io
92 } // namespace monitoring_frame
93 } // namespace data_conversion_layer
94 } // namespace psen_scan_v2_standalone
95 #endif // PSEN_SCAN_V2_STANDALONE_IO_PIN_DATA_H
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::RAW_CHUNK_LOGICAL_INPUT_SIGNALS_IN_BYTES
static constexpr uint32_t RAW_CHUNK_LOGICAL_INPUT_SIGNALS_IN_BYTES
Definition: io_constants.h:36
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::operator<<
std::ostream & operator<<(std::ostream &os, const PinData &pd)
Definition: io_pin_data.h:84
format_range.h
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::monitoring_frame::io::OUTPUT_BITS
static constexpr std::array< std::array< Ot, 8 >, RAW_CHUNK_OUTPUT_SIGNALS_IN_BYTES > OUTPUT_BITS
Definition: io_constants.h:154
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::LOGICAL_INPUT_BITS
static constexpr std::array< std::array< Lit, 8 >, RAW_CHUNK_LOGICAL_INPUT_SIGNALS_IN_BYTES > LOGICAL_INPUT_BITS
Definition: io_constants.h:109
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::monitoring_frame::io::OutputType
OutputType
Definition: io_constants.h:122
io_constants.h
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::monitoring_frame::io::LogicalInputType
LogicalInputType
Definition: io_constants.h:48
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::util::formatRange
std::string formatRange(const T &range)
Definition: format_range.h:38
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::LOGICAL_INPUT_BIT_TO_NAME
static const std::map< Lit, IoName > LOGICAL_INPUT_BIT_TO_NAME
Definition: io_constants.h:80
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
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::PinData::operator==
bool operator==(const PinData &pin_data) const
Definition: io_pin_data.h:79
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
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::RAW_CHUNK_OUTPUT_SIGNALS_IN_BYTES
static constexpr uint32_t RAW_CHUNK_OUTPUT_SIGNALS_IN_BYTES
Definition: io_constants.h:37
psen_scan_v2_standalone::data_conversion_layer::monitoring_frame::io::OUTPUT_BIT_TO_NAME
static const std::map< Ot, IoName > OUTPUT_BIT_TO_NAME
Definition: io_constants.h:141


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