@@ -43,6 +43,67 @@ static auto get_mask_from_id(can::ids::SensorId sensor) -> uint8_t {
43
43
return static_cast <uint8_t >(mask_enum);
44
44
}
45
45
46
+ class SensorHardwareSyncControlSingleton {
47
+ public:
48
+ SensorHardwareSyncControlSingleton () = default ;
49
+ virtual ~SensorHardwareSyncControlSingleton () = default ;
50
+ SensorHardwareSyncControlSingleton (
51
+ const SensorHardwareSyncControlSingleton&) = default ;
52
+ auto operator =(const SensorHardwareSyncControlSingleton&)
53
+ -> SensorHardwareSyncControlSingleton& = default ;
54
+ SensorHardwareSyncControlSingleton (SensorHardwareSyncControlSingleton&&) =
55
+ default ;
56
+ auto operator =(SensorHardwareSyncControlSingleton&&)
57
+ -> SensorHardwareSyncControlSingleton& = default ;
58
+
59
+ [[nodiscard]] auto mask_satisfied () const -> bool {
60
+ if (set_sync_required_mask !=
61
+ static_cast <uint8_t >(SensorIdBitMask::UNUSED)) {
62
+ // if anything is "required" only sync when they are all triggered
63
+ return (sync_state_mask & set_sync_required_mask) ==
64
+ set_sync_required_mask;
65
+ }
66
+ return (sync_state_mask & set_sync_enabled_mask) != 0 ;
67
+ }
68
+
69
+ auto set_sync (can::ids::SensorId sensor) -> void {
70
+ // force the bit for this sensor to 1
71
+ sync_state_mask |= get_mask_from_id (sensor);
72
+ }
73
+
74
+ auto reset_sync (can::ids::SensorId sensor) -> void {
75
+ // force the bit for this sensor to 0
76
+ sync_state_mask &= ~get_mask_from_id (sensor);
77
+ }
78
+
79
+ auto set_sync_enabled (can::ids::SensorId sensor, bool enabled) -> void {
80
+ uint8_t applied_mask = get_mask_from_id (sensor);
81
+ if (!enabled) {
82
+ // force enabled bit to 0
83
+ set_sync_enabled_mask &= ~applied_mask;
84
+ } else {
85
+ // force enabled bit to 1
86
+ set_sync_enabled_mask |= applied_mask;
87
+ }
88
+ }
89
+
90
+ auto set_sync_required (can::ids::SensorId sensor, bool required) -> void {
91
+ uint8_t applied_mask = get_mask_from_id (sensor);
92
+ if (!required) {
93
+ // force required bit to 0
94
+ set_sync_required_mask &= ~applied_mask;
95
+ } else {
96
+ // force required bit to 1
97
+ set_sync_required_mask |= applied_mask;
98
+ }
99
+ }
100
+
101
+ private:
102
+ uint8_t set_sync_required_mask = 0x00 ;
103
+ uint8_t set_sync_enabled_mask = 0x00 ;
104
+ uint8_t sync_state_mask = 0x00 ;
105
+ };
106
+
46
107
class SensorHardwareVersionSingleton {
47
108
public:
48
109
SensorHardwareVersionSingleton () = default ;
@@ -66,8 +127,9 @@ class SensorHardwareVersionSingleton {
66
127
/* * abstract sensor hardware device for a sync line */
67
128
class SensorHardwareBase {
68
129
public:
69
- SensorHardwareBase (SensorHardwareVersionSingleton& version_wrapper)
70
- : version_wrapper{version_wrapper} {}
130
+ SensorHardwareBase (SensorHardwareVersionSingleton& version_wrapper,
131
+ SensorHardwareSyncControlSingleton& sync_control)
132
+ : version_wrapper{version_wrapper}, sync_control{sync_control} {}
71
133
virtual ~SensorHardwareBase () = default ;
72
134
SensorHardwareBase (const SensorHardwareBase&) = default ;
73
135
auto operator =(const SensorHardwareBase&) -> SensorHardwareBase& = delete ;
@@ -79,40 +141,27 @@ class SensorHardwareBase {
79
141
virtual auto check_tip_presence () -> bool = 0;
80
142
81
143
[[nodiscard]] auto mask_satisfied () const -> bool {
82
- if (set_sync_required_mask !=
83
- static_cast <uint8_t >(SensorIdBitMask::UNUSED)) {
84
- // if anything is "required" only sync when they are all triggered
85
- return (sync_state_mask & set_sync_required_mask) ==
86
- set_sync_required_mask;
87
- }
88
- return (sync_state_mask & set_sync_enabled_mask) != 0 ;
144
+ return sync_control.mask_satisfied ();
89
145
}
90
146
91
147
auto set_sync (can::ids::SensorId sensor) -> void {
92
- // force the bit for this sensor to 1
93
- sync_state_mask |= get_mask_from_id (sensor);
148
+ sync_control. set_sync ( sensor);
149
+ // update sync state now that requirements are different
94
150
if (mask_satisfied ()) {
95
151
set_sync ();
96
152
}
97
153
}
98
154
99
155
auto reset_sync (can::ids::SensorId sensor) -> void {
100
- // force the bit for this sensor to 0
101
- sync_state_mask &= 0xFF ^ get_mask_from_id (sensor);
156
+ sync_control. reset_sync ( sensor);
157
+ // update sync state now that requirements are different
102
158
if (!mask_satisfied ()) {
103
159
reset_sync ();
104
160
}
105
161
}
106
162
107
163
auto set_sync_enabled (can::ids::SensorId sensor, bool enabled) -> void {
108
- uint8_t applied_mask = get_mask_from_id (sensor);
109
- if (!enabled) {
110
- // force enabled bit to 0
111
- set_sync_enabled_mask &= 0xFF ^ applied_mask;
112
- } else {
113
- // force enabled bit to 1
114
- set_sync_enabled_mask |= applied_mask;
115
- }
164
+ sync_control.set_sync_enabled (sensor, enabled);
116
165
// update sync state now that requirements are different
117
166
if (mask_satisfied ()) {
118
167
set_sync ();
@@ -122,14 +171,7 @@ class SensorHardwareBase {
122
171
}
123
172
124
173
auto set_sync_required (can::ids::SensorId sensor, bool required) -> void {
125
- uint8_t applied_mask = get_mask_from_id (sensor);
126
- if (!required) {
127
- // force required bit to 0
128
- set_sync_required_mask &= 0xFF ^ applied_mask;
129
- } else {
130
- // force required bit to 1
131
- set_sync_required_mask |= applied_mask;
132
- }
174
+ sync_control.set_sync_required (sensor, required);
133
175
// update sync state now that requirements are different
134
176
if (mask_satisfied ()) {
135
177
set_sync ();
@@ -142,10 +184,8 @@ class SensorHardwareBase {
142
184
}
143
185
144
186
private:
145
- uint8_t set_sync_required_mask = 0x00 ;
146
- uint8_t set_sync_enabled_mask = 0x00 ;
147
- uint8_t sync_state_mask = 0x00 ;
148
187
SensorHardwareVersionSingleton& version_wrapper;
188
+ SensorHardwareSyncControlSingleton& sync_control;
149
189
};
150
190
151
191
struct SensorHardwareContainer {
0 commit comments