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;
80  IOState(data_conversion_layer::monitoring_frame::io::PinData pin_data, const int64_t& timestamp);
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
PinState(uint32_t pin_id, const std::string &name, bool state)
Definition: io_state.cpp:30
Represents the set of all I/Os of the scanner and their states.
Definition: io_state.h:76
bool operator==(const PinState &ps) const
Definition: io_state.cpp:34
Represents a single I/O pin.
Definition: io_state.h:29
std::string name() const
Definition: io_state.cpp:49
std::string formatPinStates(const std::vector< PinState > &pins)
Formats a vector of PinStates.
Definition: io_state.h:59
std::ostream & operator<<(std::ostream &os, const PinState &pin_state)
Definition: io_state.cpp:59
Represents the IO PIN field of a monitoring frame.
Definition: io_pin_data.h:72
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
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
bool operator!=(const PinState &ps) const
Definition: io_state.cpp:39


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