diagnostics.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 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_DIAGNOSTICS_H
17 #define PSEN_SCAN_V2_STANDALONE_DIAGNOSTICS_H
18 
19 #include <array>
20 #include <string>
21 #include <map>
22 #include <vector>
23 #include <set>
24 
26 
28 {
32 namespace data_conversion_layer
33 {
34 namespace monitoring_frame
35 {
40 namespace diagnostic
41 {
45 static constexpr uint32_t RAW_CHUNK_LENGTH_FOR_ONE_DEVICE_IN_BYTES{ 9 };
46 static constexpr uint32_t RAW_CHUNK_UNUSED_OFFSET_IN_BYTES{ 4 };
47 static constexpr uint32_t RAW_CHUNK_LENGTH_IN_BYTES{
49 };
50 
51 using RawChunk = std::array<uint8_t, diagnostic::RAW_CHUNK_LENGTH_IN_BYTES>;
52 
53 enum class ErrorType
54 {
55  ossd1_oc,
58  intern,
59  win_cln_al,
61  netw_prb,
64  meas_prob,
73  encod_oor,
74  edm2_err,
75  edm1_err,
76  conf_err,
80  unused
81 };
82 
83 // clang-format off
84 
85 using Et = ErrorType;
86 using ErrorMessage = std::string;
87 
88 static const std::map<ErrorType, ErrorMessage> ERROR_CODE_TO_STRING
89 {
90  { Et::ossd1_oc, "OSSD1 Overcurrent / Short circuit." },
91  { Et::ossd_shrt_c, "Short circuit between at least two OSSDs." },
92  { Et::ossd_integr, "OSSDF1: An error has occurred when testing the OSSDs." },
93  { Et::intern, "Internal error." },
94  { Et::win_cln_al, "Alarm: The front panel of the safety laser scanner must be cleaned." },
95  { Et::power_supply, "Power supply problem." },
96  { Et::netw_prb, "Network problem." },
97  { Et::dust_crc_fl, "Dust circuit failure" },
98  { Et::ossd2_overcur, "OSSD2 Overcurrent / Short circuit." },
99  { Et::meas_prob, "Measurement Problem." },
100  { Et::incoherence, "Incoherence Error" },
101  { Et::zone_inval_trans, "INPUTCF2: Configuration error. - "
102  "In the configuration, check the configured state transitions and switching operations." },
103  { Et::zone_invalid_conf, "INPUTCF1: Error in the configuration or the wiring. - "
104  "Check whether the wiring and the configuration will match." },
105  { Et::win_cln_warn, "Warning: The front panel of the safety laser scanner must be cleaned." },
106  { Et::generic_err, "Generic Error." },
107  { Et::disp_com_prb, "Display communication problem." },
108  { Et::temp_meas_prob, "Temperature measurement problem." },
109  { Et::encod_oor, "Encoder: Out of range." },
110  { Et::edm2_err, "EDM2: Error in the External Device Monitoring." },
111  { Et::edm1_err, "EDM1: Error in the External Device Monitoring." },
112  { Et::conf_err, "WAITING_CONF: The safety laser scanner waits for a configuration (e.g. after restoring a configuration). - "
113  "Configure the safety laser scanner." },
114  { Et::out_of_range_err, "Out of range error." },
115  { Et::temp_range_err, "Temperature out of range." },
116  { Et::encoder_generic_err, "Encoder: Generic error." },
117  { Et::unused, "Unexpected error" } \
118 };
119 
120 // clang-format off
121  #define REV(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1
122 
123  static constexpr std::array<std::array<ErrorType, 8>, 9> ERROR_BITS{{
124  //Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
134  }};
135 // clang-format on
136 
149 {
150 public:
151  using ByteLocation = size_t;
152  using BitLocation = size_t;
153  constexpr ErrorLocation(const ByteLocation& byte, const BitLocation& bit) : byte_(byte), bit_(bit){};
154 
155  inline constexpr ByteLocation byte() const
156  {
157  return byte_;
158  };
159 
160  inline constexpr BitLocation bit() const
161  {
162  return bit_;
163  };
164 
165 private:
168 };
169 
181 class Message
182 {
183 public:
184  constexpr Message(const configuration::ScannerId& id, const diagnostic::ErrorLocation& location);
185  constexpr bool operator==(const diagnostic::Message& rhs) const;
186 
187  friend RawChunk serialize(const std::vector<diagnostic::Message>& messages);
188 
190  {
191  return id_;
192  }
193 
194  constexpr ErrorLocation errorLocation() const
195  {
196  return error_location_;
197  }
198 
199  constexpr ErrorType diagnosticCode() const
200  {
201  return ERROR_BITS.at(error_location_.byte()).at(error_location_.bit());
202  }
203 
204 private:
207 };
208 
209 constexpr inline Message::Message(const configuration::ScannerId& id, const ErrorLocation& location)
210  : id_(id), error_location_(location)
211 {
212 }
213 
214 constexpr inline bool Message::operator==(const Message& rhs) const
215 {
216  return (error_location_.bit() == rhs.error_location_.bit() && error_location_.byte() == rhs.error_location_.byte() &&
217  id_ == rhs.id_);
218 }
219 
220 // Store ambiguous errors for additional output
221 static const std::set<Et> AMBIGUOUS_DIAGNOSTIC_CODES = { Et::unused, Et::intern };
222 
223 inline bool isAmbiguous(const ErrorType& code)
224 {
225  return AMBIGUOUS_DIAGNOSTIC_CODES.find(code) != AMBIGUOUS_DIAGNOSTIC_CODES.end();
226 }
227 
228 std::ostream& operator<<(std::ostream& os, const diagnostic::Message& msg);
229 
230 } // namespace diagnostic
231 } // namespace monitoring_frame
232 } // namespace data_conversion_layer
233 } // namespace psen_scan_v2_standalone
234 
235 #endif // PSEN_SCAN_V2_STANDALONE_DIAGNOSTICS_H
#define REV(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
Definition: diagnostics.h:121
Defines an Diagnostic message by defining the ErrorLocation and a scanner ID.
Definition: diagnostics.h:181
static const std::map< ErrorType, ErrorMessage > ERROR_CODE_TO_STRING
Definition: diagnostics.h:89
std::ostream & operator<<(std::ostream &os, const diagnostic::Message &msg)
Definition: diagnostics.cpp:31
static constexpr std::array< ScannerId, 4 > VALID_SCANNER_IDS
Definition: scanner_ids.h:35
static constexpr uint32_t RAW_CHUNK_LENGTH_FOR_ONE_DEVICE_IN_BYTES
Contains constants and types needed to define the diagnostic::Message.
Definition: diagnostics.h:45
static constexpr std::array< std::array< ErrorType, 8 >, 9 > ERROR_BITS
Definition: diagnostics.h:123
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
constexpr Message(const configuration::ScannerId &id, const diagnostic::ErrorLocation &location)
Definition: diagnostics.h:209
constexpr ErrorLocation(const ByteLocation &byte, const BitLocation &bit)
Definition: diagnostics.h:153
std::array< uint8_t, diagnostic::RAW_CHUNK_LENGTH_IN_BYTES > RawChunk
Definition: diagnostics.h:51
Defines a byte and bit position of an error in the diagnostic chunk.
Definition: diagnostics.h:148
bool operator==(const Rotation &a, const Rotation &b)


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