io_state.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_STATE_H
17 #define PSEN_SCAN_V2_STANDALONE_IO_STATE_H
18 
19 #include <cstdint>
20 #include <ostream>
21 #include <string>
22 #include <vector>
23 
25 
27 {
29 class PinState
30 {
31 public:
37  PinState(uint32_t pin_id, const std::string& name, bool state);
38  bool operator==(const PinState& ps) const;
39  bool operator!=(const PinState& ps) const;
40  uint32_t id() const;
41  std::string name() const;
42  bool state() const;
43 
44 private:
45  uint32_t id_;
46  std::string name_;
47  bool state_;
48 };
49 
50 std::ostream& operator<<(std::ostream& os, const PinState& pin_state);
51 
53 inline std::string formatPinState(const PinState& pin)
54 {
55  return fmt::format("{} = {}", pin.name(), pin.state());
56 }
57 
59 inline std::string formatPinStates(const std::vector<PinState>& pins)
60 {
61  std::stringstream strstr;
62  strstr << "{";
63  for (auto it = pins.begin(); std::next(it) < pins.end(); ++it)
64  {
65  strstr << formatPinState(*it) << ", ";
66  }
67  if (!pins.empty())
68  {
69  strstr << formatPinState(pins.back());
70  }
71  strstr << "}";
72  return strstr.str();
73 }
74 
76 class IOState
77 {
78 public:
79  IOState() = default;
82  std::vector<PinState> input() const;
84  std::vector<PinState> output() const;
86  int64_t timestamp() const;
91  std::vector<PinState> changedInputStates(const IOState& ref_state) const;
96  std::vector<PinState> changedOutputStates(const IOState& ref_state) const;
97 
98  bool operator==(const IOState& io_state) const;
99  bool operator!=(const IOState& io_state) const;
100 
101 public:
102  friend std::ostream& operator<<(std::ostream& os, const IOState& io_state);
103 
104 private:
106  int64_t timestamp_{};
107 };
108 
109 std::ostream& operator<<(std::ostream& os, const IOState& io_state);
110 } // namespace psen_scan_v2_standalone
111 
112 #endif // PSEN_SCAN_V2_STANDALONE_IO_STATE_H
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::formatPinStates
std::string formatPinStates(const std::vector< PinState > &pins)
Formats a vector of PinStates.
Definition: io_state.h:59
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::formatPinState
std::string formatPinState(const PinState &pin)
Formats a PinState just using its name and state. (e.g. Safety 1 intrusion = true)
Definition: io_state.h:53
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::PinState::id_
uint32_t id_
Definition: io_state.h:45
psen_scan_v2_standalone::IOState::operator<<
friend std::ostream & operator<<(std::ostream &os, const IOState &io_state)
Definition: io_state.cpp:105
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
psen_scan_v2_standalone::PinState::operator!=
bool operator!=(const PinState &ps) const
Definition: io_state.cpp:39
psen_scan_v2_standalone::IOState::timestamp
int64_t timestamp() const
Definition: io_state.cpp:90
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