io_state.cpp
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 #include <ostream>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 #include <fmt/format.h>
22 #include <fmt/ostream.h>
23 
27 
29 {
30 PinState::PinState(uint32_t pin_id, const std::string& name, bool state) : id_(pin_id), name_(name), state_(state)
31 {
32 }
33 
34 bool PinState::operator==(const PinState& ps) const
35 {
36  return id() == ps.id() && name() == ps.name() && state() == ps.state();
37 }
38 
39 bool PinState::operator!=(const PinState& ps) const
40 {
41  return !operator==(ps);
42 }
43 
44 uint32_t PinState::id() const
45 {
46  return id_;
47 }
48 
49 std::string PinState::name() const
50 {
51  return name_;
52 }
53 
54 bool PinState::state() const
55 {
56  return state_;
57 }
58 
59 std::ostream& operator<<(std::ostream& os, const PinState& pin_state)
60 {
61  os << fmt::format("PinState(id = {}, name = {}, state = {})", pin_state.id(), pin_state.name(), pin_state.state());
62  return os;
63 }
64 
66  : pin_data_(pin_data), timestamp_(timestamp)
67 {
68 }
69 
70 bool IOState::operator==(const IOState& io_state) const
71 {
72  return pin_data_ == io_state.pin_data_;
73 }
74 
75 bool IOState::operator!=(const IOState& io_state) const
76 {
77  return !operator==(io_state);
78 }
79 
80 std::vector<PinState> IOState::input() const
81 {
83 }
84 
85 std::vector<PinState> IOState::output() const
86 {
88 }
89 
90 int64_t IOState::timestamp() const
91 {
92  return timestamp_;
93 }
94 
95 std::vector<PinState> IOState::changedInputStates(const IOState& ref_state) const
96 {
98 }
99 
100 std::vector<PinState> IOState::changedOutputStates(const IOState& ref_state) const
101 {
103 }
104 
105 std::ostream& operator<<(std::ostream& os, const IOState& io_state)
106 {
107  return os << "IOState(timestamp = " << io_state.timestamp_ << " nsec, " << io_state.pin_data_ << ")";
108 }
109 } // namespace psen_scan_v2_standalone
psen_scan_v2_standalone::PinState::name
std::string name() const
Definition: io_state.cpp:49
psen_scan_v2_standalone::PinState
Represents a single I/O pin.
Definition: io_state.h:29
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::IOState::pin_data_
data_conversion_layer::monitoring_frame::io::PinData pin_data_
Definition: io_state.h:105
psen_scan_v2_standalone::PinState::name_
std::string name_
Definition: io_state.h:46
psen_scan_v2_standalone::IOState::IOState
IOState()=default
psen_scan_v2_standalone::IOState::operator==
bool operator==(const IOState &io_state) const
Definition: io_state.cpp:70
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::IOState::input
std::vector< PinState > input() const
Definition: io_state.cpp:80
psen_scan_v2_standalone::IOState::changedOutputStates
std::vector< PinState > changedOutputStates(const IOState &ref_state) const
Definition: io_state.cpp:100
psen_scan_v2_standalone::PinState::id
uint32_t id() const
Definition: io_state.cpp:44
psen_scan_v2_standalone::PinState::operator==
bool operator==(const PinState &ps) const
Definition: io_state.cpp:34
psen_scan_v2_standalone::IOState::timestamp_
int64_t timestamp_
Definition: io_state.h:106
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::PinState::id_
uint32_t id_
Definition: io_state.h:45
psen_scan_v2_standalone::PinState::PinState
PinState(uint32_t pin_id, const std::string &name, bool state)
Definition: io_state.cpp:30
psen_scan_v2_standalone::IOState::output
std::vector< PinState > output() const
Definition: io_state.cpp:85
psen_scan_v2_standalone::IOState::changedInputStates
std::vector< PinState > changedInputStates(const IOState &ref_state) const
Definition: io_state.cpp:95
psen_scan_v2_standalone::PinState::state
bool state() const
Definition: io_state.cpp:54
io_state_conversions.h
psen_scan_v2_standalone::PinState::operator!=
bool operator!=(const PinState &ps) const
Definition: io_state.cpp:39
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::generateInputPinStates
static std::vector< PinState > generateInputPinStates(const monitoring_frame::io::PinData &pin_data)
Definition: io_state_conversions.h:58
psen_scan_v2_standalone::IOState::timestamp
int64_t timestamp() const
Definition: io_state.cpp:90
io_state.h
psen_scan_v2_standalone::IOState
Represents the set of all I/Os of the scanner and their states.
Definition: io_state.h:76
psen_scan_v2_standalone::IOState::operator!=
bool operator!=(const IOState &io_state) const
Definition: io_state.cpp:75
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::operator<<
std::ostream & operator<<(std::ostream &os, const PinState &pin_state)
Definition: io_state.cpp:59
io_pin_data.h
psen_scan_v2_standalone::PinState::state_
bool state_
Definition: io_state.h:47


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