-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We will need that later for `framIsWorking`.
- Loading branch information
Showing
5 changed files
with
183 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Utility/ErrorDetectionAndCorrection.hpp> | ||
|
||
|
||
namespace sts1cobcsw | ||
{ | ||
template<typename T> | ||
constexpr EdacVariable<T>::EdacVariable(T const & value) | ||
: value0_(value), value1_(value), value2_(value) | ||
{ | ||
} | ||
|
||
|
||
template<typename T> | ||
constexpr auto EdacVariable<T>::Load() const -> T | ||
{ | ||
// TODO: Make Load() thread-safe/atomic | ||
auto voteResult = ComputeMajorityVote(value0_, value1_, value2_); | ||
auto value = voteResult.value_or(value0_); | ||
SetAllValues(value); | ||
return value; | ||
} | ||
|
||
|
||
template<typename T> | ||
constexpr auto EdacVariable<T>::Store(T const & value) -> void | ||
{ | ||
// TODO: Make Store() thread-safe/atomic | ||
SetAllValues(value); | ||
} | ||
|
||
|
||
template<typename T> | ||
constexpr auto EdacVariable<T>::SetAllValues(T const & value) const -> void | ||
{ | ||
value0_ = value; | ||
value1_ = value; | ||
value2_ = value; | ||
} | ||
|
||
|
||
template<typename T> | ||
constexpr auto ComputeMajorityVote(T const & value0, T const & value1, T const & value2) | ||
-> std::optional<T> | ||
{ | ||
if(value0 == value1 or value0 == value2) | ||
{ | ||
return value0; | ||
} | ||
if(value1 == value2) | ||
{ | ||
return value1; | ||
} | ||
return std::nullopt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters