Statusword.cpp
Go to the documentation of this file.
1 // rokubimini
3 
4 namespace rokubimini
5 {
6 Statusword::Data::Data(const uint32_t data) : all_(data)
7 {
8 }
9 
11 {
12  return all_ == other.all_;
13 }
14 
16 {
17  return !(*this == other);
18 }
19 
20 Statusword::Statusword(const Statusword& statusword) : stamp_(statusword.getStamp()), data_(statusword.getData())
21 {
22 }
23 
24 Statusword::Statusword(uint32_t data)
25 {
26  setData(data);
27 }
28 
30 {
31  std::lock_guard<std::recursive_mutex> lock(mutex_);
32  stamp_ = statusword.getStamp();
33  data_ = Data(statusword.getData());
34  return *this;
35 }
36 
37 bool Statusword::isEmpty() const
38 {
39  std::lock_guard<std::recursive_mutex> lock(mutex_);
40  return stamp_ == TimePoint();
41 }
42 
43 double Statusword::getAge() const
44 {
45  std::lock_guard<std::recursive_mutex> lock(mutex_);
46  const Duration age = std::chrono::system_clock::now() - stamp_;
47  return age.count();
48 }
49 
51 {
52  std::lock_guard<std::recursive_mutex> lock(mutex_);
53  return stamp_;
54 }
55 
56 void Statusword::setData(const uint32_t data)
57 {
58  std::lock_guard<std::recursive_mutex> lock(mutex_);
59  stamp_ = std::chrono::system_clock::now();
60  data_ = Data(data);
61 }
62 
63 uint32_t Statusword::getData() const
64 {
65  std::lock_guard<std::recursive_mutex> lock(mutex_);
66  return data_.all_;
67 }
68 
69 // fsm::StateEnum Statusword::getStateEnum() const
70 // {
71 // std::lock_guard<std::recursive_mutex> lock(mutex_);
72 // return fsm::stateIdToEnum(data_.bits_.warningIsBusy_);
73 // }
74 
75 // void Statusword::setStateEnum(const fsm::StateEnum stateEnum)
76 // {
77 // std::lock_guard<std::recursive_mutex> lock(mutex_);
78 // stamp_ = std::chrono::system_clock::now();
79 // data_.bits_.warningIsBusy_ = fsm::stateEnumToId(stateEnum);
80 // }
81 
82 void Statusword::getMessages(std::vector<std::string>& infos, std::vector<std::string>& warnings,
83  std::vector<std::string>& errors, std::vector<std::string>& fatals) const
84 {
85  Statusword previous_statusword;
86  return getMessagesDiff(previous_statusword, infos, warnings, errors, fatals);
87 }
88 
89 void Statusword::getMessagesDiff(Statusword& previousStatusword, std::vector<std::string>& infos,
90  std::vector<std::string>& warnings, std::vector<std::string>& errors,
91  std::vector<std::string>& fatals) const
92 {
93  // Warnings.
94  if (!previousStatusword.hasWarningOvertemperature() && hasWarningOvertemperature())
95  {
96  warnings.emplace_back("High temperature in Rokubimini Sensor");
97  }
98  else if (previousStatusword.hasWarningOvertemperature() && !hasWarningOvertemperature())
99  {
100  infos.emplace_back("Temperature in Rokubimini Sensor is normal again");
101  }
102 
103  // Errors.
104  if (!previousStatusword.hasErrorAdcSaturated() && hasErrorAdcSaturated())
105  {
106  errors.emplace_back("Force/Torque is invalid. ADC saturation");
107  }
108  else if (previousStatusword.hasErrorAdcSaturated() && !hasErrorAdcSaturated())
109  {
110  infos.emplace_back("Force/Torque is valid again. ADC is not saturated");
111  }
112  if (!previousStatusword.hasErrorAccSaturated() && hasErrorAccSaturated())
113  {
114  errors.emplace_back("Acceleration has saturated.");
115  }
116  else if (previousStatusword.hasErrorAccSaturated() && !hasErrorAccSaturated())
117  {
118  infos.emplace_back("Acceleration is not saturated anymore.");
119  }
120  if (!previousStatusword.hasErrorGyroSaturated() && hasErrorGyroSaturated())
121  {
122  errors.emplace_back("Angular rates have saturated.");
123  }
124  else if (previousStatusword.hasErrorGyroSaturated() && !hasErrorGyroSaturated())
125  {
126  infos.emplace_back("Angular rates are not saturated anymore.");
127  }
128  if (!previousStatusword.hasErrorAdcOutOfSync() && hasErrorAdcOutOfSync())
129  {
130  errors.emplace_back("Force/Torque is invalid. ADCs are not synced");
131  }
132  else if (previousStatusword.hasErrorAdcOutOfSync() && !hasErrorAdcOutOfSync())
133  {
134  infos.emplace_back("Force/Torque is valid again. ADCs are synced");
135  }
136  if (!previousStatusword.hasErrorSensingRangeExceeded() && hasErrorSensingRangeExceeded())
137  {
138  errors.emplace_back("Sensing range exceeded.");
139  }
140  else if (previousStatusword.hasErrorSensingRangeExceeded() && !hasErrorSensingRangeExceeded())
141  {
142  infos.emplace_back("Sensing range is not exceeded.");
143  }
144 
145  // Fatals.
146  if (!previousStatusword.hasFatalSupplyVoltage() && hasFatalSupplyVoltage())
147  {
148  fatals.emplace_back("Supply voltage exceeds limits.");
149  }
150  else if (previousStatusword.hasFatalSupplyVoltage() && !hasFatalSupplyVoltage())
151  {
152  infos.emplace_back("Supply voltage is normal.");
153  }
154 }
155 
157 {
158  std::lock_guard<std::recursive_mutex> lock(mutex_);
159  return static_cast<bool>(data_.bits_.errorAdcSaturated_);
160 }
161 
163 {
164  std::lock_guard<std::recursive_mutex> lock(mutex_);
165  return static_cast<bool>(data_.bits_.errorAccSaturated_);
166 }
167 
169 {
170  std::lock_guard<std::recursive_mutex> lock(mutex_);
171  return static_cast<bool>(data_.bits_.errorGyroSaturated_);
172 }
173 
175 {
176  std::lock_guard<std::recursive_mutex> lock(mutex_);
177  return static_cast<bool>(data_.bits_.errorAdcOutOfSync_);
178 }
179 
181 {
182  std::lock_guard<std::recursive_mutex> lock(mutex_);
183  return static_cast<bool>(data_.bits_.errorSensingRangeExceeded_);
184 }
185 
187 {
188  std::lock_guard<std::recursive_mutex> lock(mutex_);
189  return static_cast<bool>(data_.bits_.warningOvertemperature_);
190 }
191 
193 {
194  std::lock_guard<std::recursive_mutex> lock(mutex_);
195  return static_cast<bool>(data_.bits_.fatalSupplyVoltage_);
196 }
197 
198 std::ostream& operator<<(std::ostream& os, const Statusword& statusword)
199 {
200  for (uint32_t i = 8 * sizeof(uint32_t); i > uint32_t(0); i--)
201  {
202  os << ((statusword.getData() & (uint32_t(1) << (i - uint32_t(1)))) ? "1" : "0");
203  }
204  return os;
205 }
206 
207 } // namespace rokubimini
bool hasErrorAccSaturated() const
Checks if the statusword has error ACC saturated.
Definition: Statusword.cpp:162
Data()=default
Default constructor.
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
bool operator!=(const Data &other)
Checks if two Data are not equal.
Definition: Statusword.cpp:15
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
uint32_t all_
All the bits in a "raw" uint32_t format.
Definition: Statusword.hpp:67
bool isEmpty() const
Checks whether the statusword is empty.
Definition: Statusword.cpp:37
bool operator==(const Data &other)
Checks if two Data are equal.
Definition: Statusword.cpp:10
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
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