Skip to content

Commit d87472c

Browse files
committed
two secondes and added to high frequency protections
1 parent f28d653 commit d87472c

3 files changed

Lines changed: 59 additions & 47 deletions

File tree

Inc/ST-LIB_HIGH/Protections/ProtectionManager.hpp

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,68 @@
11
#pragma once
22

3-
#include "Protection.hpp"
4-
#include "StateMachine/StateMachine.hpp"
53
#include "HALAL/HALAL.hpp"
64
#include "Notification.hpp"
5+
#include "Protection.hpp"
6+
#include "StateMachine/StateMachine.hpp"
77

88
#define getname(var) #var
9-
#define add_protection(src,...) \
10-
{\
11-
Protection& ref = ProtectionManager::_add_protection(src,__VA_ARGS__); \
12-
if (getname(src)[0] == '&'){ \
13-
ref.set_name((char*)malloc(sizeof(getname(src))-1));\
14-
sprintf(ref.get_name(),"%s",getname(src)+1); \
15-
}else{\
16-
ref.set_name((char*)malloc(sizeof(getname(src))));\
17-
sprintf(ref.get_name(),"%s",getname(src)); \
18-
}\
19-
}\
9+
#define add_protection(src, ...) \
10+
{ \
11+
Protection& ref = \
12+
ProtectionManager::_add_protection(src, __VA_ARGS__); \
13+
if (getname(src)[0] == '&') { \
14+
ref.set_name((char*)malloc(sizeof(getname(src)) - 1)); \
15+
sprintf(ref.get_name(), "%s", getname(src) + 1); \
16+
} else { \
17+
ref.set_name((char*)malloc(sizeof(getname(src)))); \
18+
sprintf(ref.get_name(), "%s", getname(src)); \
19+
} \
20+
}
2021

21-
#define add_high_frequency_protection(src,...) \
22-
{\
23-
Protection& ref = ProtectionManager::_add_high_frequency_protection(src,__VA_ARGS__); \
24-
if (getname(src)[0] == '&'){ \
25-
ref.set_name((char*)malloc(sizeof(getname(src))-1)); \
26-
sprintf(ref.get_name(),"%s",getname(src)+1); \
27-
}else{\
28-
ref.set_name((char*)malloc(sizeof(getname(src))));\
29-
sprintf(ref.get_name(),"%s",getname(src)); \
30-
}\
31-
}\
22+
#define add_high_frequency_protection(src, ...) \
23+
{ \
24+
Protection& ref = ProtectionManager::_add_high_frequency_protection( \
25+
src, __VA_ARGS__); \
26+
if (getname(src)[0] == '&') { \
27+
ref.set_name((char*)malloc(sizeof(getname(src)) - 1)); \
28+
sprintf(ref.get_name(), "%s", getname(src) + 1); \
29+
} else { \
30+
ref.set_name((char*)malloc(sizeof(getname(src)))); \
31+
sprintf(ref.get_name(), "%s", getname(src)); \
32+
} \
33+
}
3234

3335
class ProtectionManager {
34-
public:
35-
typedef uint8_t state_id;
36-
static bool external_trigger;
36+
public:
37+
typedef uint8_t state_id;
38+
static bool external_trigger;
3739

38-
static const uint64_t notify_delay_in_nanoseconds = 100'000'000;
39-
static uint64_t last_notify;
40+
static const uint64_t notify_delay_in_nanoseconds = 2000'000'000;
41+
static uint64_t last_notify;
4042

4143
static void set_id(Boards::ID id);
4244

43-
static void link_state_machine(StateMachine& general_state_machine, state_id fault_id);
45+
static void link_state_machine(StateMachine& general_state_machine,
46+
state_id fault_id);
4447

45-
template<class Type, ProtectionType... Protector, template<class,ProtectionType> class Boundaries>
46-
static Protection& _add_protection(Type* src, Boundaries<Type,Protector>... protectors){
47-
low_frequency_protections.push_back(Protection(src,protectors...));
48+
template <class Type, ProtectionType... Protector,
49+
template <class, ProtectionType> class Boundaries>
50+
static Protection& _add_protection(
51+
Type* src, Boundaries<Type, Protector>... protectors) {
52+
low_frequency_protections.push_back(Protection(src, protectors...));
4853
return low_frequency_protections.back();
4954
}
5055

51-
template<class Type, ProtectionType... Protector, template<class,ProtectionType> class Boundaries>
52-
static Protection& _add_high_frequency_protection(Type* src, Boundaries<Type,Protector>... protectors){
53-
high_frequency_protections.push_back(Protection(src,protectors...));
56+
template <class Type, ProtectionType... Protector,
57+
template <class, ProtectionType> class Boundaries>
58+
static Protection& _add_high_frequency_protection(
59+
Type* src, Boundaries<Type, Protector>... protectors) {
60+
high_frequency_protections.push_back(Protection(src, protectors...));
5461
return high_frequency_protections.back();
5562
}
5663
/**
5764
* @brief call on startup to initialize the names of the protections
58-
*/
65+
*/
5966
static void initialize();
6067
static void add_standard_protections();
6168
static void check_protections();
@@ -64,13 +71,15 @@ class ProtectionManager {
6471
static void fault_and_propagate();
6572
static void propagate_fault();
6673
static void notify(Protection& protection);
67-
private:
68-
static constexpr uint16_t warning_id = 2;
69-
static constexpr uint16_t fault_id = 3;
70-
static char* message;
71-
static size_t message_size;
74+
75+
private:
76+
static constexpr uint16_t warning_id = 2;
77+
static constexpr uint16_t fault_id = 3;
78+
static char* message;
79+
static size_t message_size;
7280
static bool test_fault;
73-
static constexpr const char* format = "{\"boardId\": %s, \"timestamp\":{%s}, %s}";
81+
static constexpr const char* format =
82+
"{\"boardId\": %s, \"timestamp\":{%s}, %s}";
7483

7584
static Boards::ID board_id;
7685
static vector<Protection> low_frequency_protections;
@@ -86,5 +95,3 @@ class ProtectionManager {
8695
static void to_fault();
8796
static void external_to_fault();
8897
};
89-
90-

Src/ST-LIB_HIGH/Protections/ProtectionManager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ void ProtectionManager::check_high_frequency_protections() {
101101

102102
if (protection.fault_type == Protections::FAULT) {
103103
ProtectionManager::to_fault();
104-
}
104+
}
105105
Global_RTC::update_rtc_data();
106+
if (Time::get_global_tick() > last_notify + notify_delay_in_nanoseconds) {
107+
ProtectionManager::notify(protection);
108+
last_notify = Time::get_global_tick();
109+
}
110+
106111
ProtectionManager::notify(protection);
107112
}
108113
}

Src/ST-LIB_LOW/ErrorHandler/ErrorHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void ErrorHandlerModel::ErrorHandlerUpdate(){
6767
return;
6868
}
6969

70-
//printf("Error: %s%s", ErrorHandlerModel::description.c_str(), endl);
70+
printf("Error: %s%s", ErrorHandlerModel::description.c_str(), endl);
7171
#endif
7272

7373
}

0 commit comments

Comments
 (0)