Statusword.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // std
4 #include <chrono>
5 #include <mutex>
6 #include <vector>
7 
8 // rokubimini
9 // #include "rokubimini/mode/ModeEnum.hpp"
11 
12 namespace rokubimini
13 {
21 {
22 public:
29  struct DataBits
30  {
31  uint32_t errorAdcSaturated_ : 1;
32  uint32_t errorAccSaturated_ : 1;
33  uint32_t errorGyroSaturated_ : 1;
34  uint32_t errorAdcOutOfSync_ : 1;
37  uint32_t fatalSupplyVoltage_ : 1;
38  uint32_t reserved1_ : 1;
39 
40  uint32_t reserved2_ : 8;
41 
42  uint32_t unused_ : 16;
43  };
44 
51  union Data
52  {
60 
67  uint32_t all_ = 0;
68 
75  Data() = default;
76 
85  explicit Data(const uint32_t data);
86 
95  bool operator==(const Data& other);
96 
105  bool operator!=(const Data& other);
106  };
107 
108 protected:
109  using TimePoint = std::chrono::system_clock::time_point;
110  using Duration = std::chrono::duration<double>;
111 
118  mutable std::recursive_mutex mutex_;
119 
127 
135 
136 public:
143  Statusword() = default;
144 
153  Statusword(const Statusword& statusword);
154 
162  explicit Statusword(const uint32_t data);
163  virtual ~Statusword() = default;
164 
174  Statusword& operator=(const Statusword& statusword);
175 
184  bool isEmpty() const;
185 
193  double getAge() const;
194 
202  TimePoint getStamp() const;
203 
211  void setData(const uint32_t data);
212 
220  uint32_t getData() const;
221 
222  // fsm::StateEnum getStateEnum() const;
223  // void setStateEnum(const fsm::StateEnum stateEnum);
224 
237  void getMessages(std::vector<std::string>& infos, std::vector<std::string>& warnings,
238  std::vector<std::string>& errors, std::vector<std::string>& fatals) const;
239 
254  void getMessagesDiff(Statusword& previousStatusword, std::vector<std::string>& infos,
255  std::vector<std::string>& warnings, std::vector<std::string>& errors,
256  std::vector<std::string>& fatals) const;
257 
265  bool hasErrorAdcSaturated() const;
266 
274  bool hasErrorAccSaturated() const;
275 
283  bool hasErrorGyroSaturated() const;
284 
292  bool hasErrorAdcOutOfSync() const;
293 
301  bool hasErrorSensingRangeExceeded() const;
302 
310  bool hasWarningOvertemperature() const;
311 
319  bool hasFatalSupplyVoltage() const;
320 };
321 
330 std::ostream& operator<<(std::ostream& os, const Statusword& statusword);
331 
332 } // namespace rokubimini
bool hasErrorAccSaturated() const
Checks if the statusword has error ACC saturated.
Definition: Statusword.cpp:162
std::recursive_mutex mutex_
Mutex enabling synchronization.
Definition: Statusword.hpp:118
void getMessages(std::vector< std::string > &infos, std::vector< std::string > &warnings, std::vector< std::string > &errors, std::vector< std::string > &fatals) const
Gets all the messages relevant to statuswords.
Definition: Statusword.cpp:82
double getAge() const
Gets the age variable.
Definition: Statusword.cpp:43
std::ostream & operator<<(std::ostream &os, const Statusword &statusword)
Outputs the statusword data to an output stream.
Definition: Statusword.cpp:198
bool hasErrorSensingRangeExceeded() const
Checks if the statusword has error sensing range exceeded.
Definition: Statusword.cpp:180
void setData(const uint32_t data)
Sets the data variable.
Definition: Statusword.cpp:56
std::chrono::system_clock::time_point TimePoint
Definition: Statusword.hpp:109
Class representing the different states the communication or the sensors can be in.
Definition: Statusword.hpp:20
bool isEmpty() const
Checks whether the statusword is empty.
Definition: Statusword.cpp:37
Bits representing errors.
Definition: Statusword.hpp:29
uint32_t getData() const
Gets the data variable.
Definition: Statusword.cpp:63
void getMessagesDiff(Statusword &previousStatusword, std::vector< std::string > &infos, std::vector< std::string > &warnings, std::vector< std::string > &errors, std::vector< std::string > &fatals) const
Gets the different messages form the previous statusword.
Definition: Statusword.cpp:89
Data data_
The data variable.
Definition: Statusword.hpp:134
Statusword & operator=(const Statusword &statusword)
Assignment operator.
Definition: Statusword.cpp:29
bool hasErrorGyroSaturated() const
Checks if the statusword has error gyro saturated.
Definition: Statusword.cpp:168
bool hasErrorAdcOutOfSync() const
Checks if the statusword has error ADC out-of-sync.
Definition: Statusword.cpp:174
TimePoint stamp_
Timestamp associated with the Data.
Definition: Statusword.hpp:126
bool hasFatalSupplyVoltage() const
Checks if the statusword has fatal supply voltage.
Definition: Statusword.cpp:192
TimePoint getStamp() const
Gets the stamp variable.
Definition: Statusword.cpp:50
Data associated with a Status Word.
Definition: Statusword.hpp:51
std::chrono::duration< double > Duration
Definition: Statusword.hpp:110
virtual ~Statusword()=default
bool hasWarningOvertemperature() const
Checks if the statusword has warning over temperature.
Definition: Statusword.cpp:186
bool hasErrorAdcSaturated() const
Checks if the statusword has error ADC saturated.
Definition: Statusword.cpp:156
Statusword()=default
Default constructor.
Tests Configuration.
DataBits bits_
The bits of the data.
Definition: Statusword.hpp:59


rokubimini
Author(s):
autogenerated on Wed Mar 3 2021 03:09:12