Motorcortex Core  version: 2.7.6
sm_errorpub.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2020 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_SM_ERRORPUB_H
7 #define MOTORCORTEX_CORE_SM_ERRORPUB_H
8 
9 #include "motorcortex.pb.h"
10 #include "ps_parameter.h"
11 #include "sg_signalid.h"
12 #include "sm_errorhandlebase.h"
13 
14 #include <functional>
15 #include <initializer_list>
16 #include <string>
17 
18 namespace mcx::state_machine {
19 
20 constexpr auto MAX_NUM_OF_ERRORS = sizeof(MotorcortexErrorList::errors) / sizeof(MotorcortexErrorList::errors[0]);
21 
23 
24  struct ErrorHandles {
30  };
31 
32 public:
33  ErrorPublisher() = default;
34 
35  void addParameters(const std::string& param_name, parameter_server::Parameter* parent);
36 
37  bool clear(bool warnings_only);
38 
39  void update(const std::vector<std::reference_wrapper<const ErrorPublisher>>& error_pub);
40 
41  bool empty() const;
42 
43  bool hasError(const Error& error) const;
44 
45  bool hasErrorLevel(MotorcortexErrorLevel error_level) const;
46 
47  const std::map<Error, MotorcortexError>& getActiveErrors() const;
48 
49  MotorcortexError getActiveError() const;
50 
51  unsigned long getUpdateCounter() const;
52 
53  bool compare(unsigned long& counter) const;
54 
55  bool addError(const Error& error, MotorcortexErrorLevel error_level);
56 
57  void publish();
58 
59  void encode(size_t counter);
60 
61  inline void setName(const std::string& name) { name_ = name; }
62 
63  inline const std::string& getName() const { return name_; }
64 
65 private:
66  static void updateErrorHandle(ErrorHandles& error_handle);
67 
68  bool processError(const Error& error, motorcortex_ErrorLevel error_level, uint64_t timestamp, bool print_error);
69 
70  bool reset();
71 
72  bool resetWarnings();
73 
74  std::string name_;
75 
76  ErrorHandles error_handles_;
77 
78  uint8_t error_list_msg_[motorcortex_ErrorList_size]{};
79 
80  std::array<uint64_t, MAX_NUM_OF_ERRORS> es_errors_{};
81  std::array<uint64_t, MAX_NUM_OF_ERRORS> sd_errors_{};
82  std::array<uint64_t, MAX_NUM_OF_ERRORS> fd_errors_{};
83  std::array<uint64_t, MAX_NUM_OF_ERRORS> warnings_{};
84 
85  MotorcortexError active_error_{};
86  std::map<Error, MotorcortexError> active_errors_;
87  MotorcortexErrorList error_list_{};
88 
89  size_t update_counter_{};
90  size_t msg_size_{};
91 };
92 
93 } // namespace mcx::state_machine
94 
95 #endif // MOTORCORTEX_CORE_SM_ERRORPUB_H
mcx::parameter_server::Parameter
Definition: ps_parameter.h:45
mcx::state_machine::ErrorPublisher
Definition: sm_errorpub.h:22
_motorcortex_ErrorList
Definition: motorcortex.pb.h:183
mcx::signal_monitor::SignalId
Definition: sg_signalid.h:25
_motorcortex_Error
Definition: motorcortex.pb.h:130
mcx::parameter_server::ParamHandle
Definition: ps_handlers.h:43