| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title OnChangeChannel.hpp | ||
| 3 | // \author Rob Bocchino | ||
| 4 | // \brief A model of an on-change channel for testing | ||
| 5 | // | ||
| 6 | // \copyright | ||
| 7 | // Copyright (C) 2023 California Institute of Technology. | ||
| 8 | // ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 9 | // acknowledged. Any commercial use must be negotiated with the Office | ||
| 10 | // of Technology Transfer at the California Institute of Technology. | ||
| 11 | // ====================================================================== | ||
| 12 | |||
| 13 | #ifndef TestUtils_OnChangeChannel_HPP | ||
| 14 | #define TestUtils_OnChangeChannel_HPP | ||
| 15 | |||
| 16 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 17 | #include <cstring> | ||
| 18 | |||
| 19 | #include <Fw/Types/Optional.hpp> | ||
| 20 | |||
| 21 | namespace TestUtils { | ||
| 22 | |||
| 23 | //! The status of an on-change telemetry channel | ||
| 24 | enum class OnChangeStatus { CHANGED, NOT_CHANGED }; | ||
| 25 | |||
| 26 | //! A model of an on-change telemetry channel | ||
| 27 | template <typename T> | ||
| 28 | class OnChangeChannel { | ||
| 29 | public: | ||
| 30 | //! Constructor | ||
| 31 | 338 | explicit OnChangeChannel(T a_value) : value(a_value) {} | |
| 32 | //! Update the previous value | ||
| 33 | 13232 | OnChangeStatus updatePrev() { | |
| 34 | 26426 | const auto status = ((!this->prev.has_value()) || (this->value != this->prev.value())) | |
| 35 | 26426 | ? OnChangeStatus::CHANGED | |
| 36 | : OnChangeStatus::NOT_CHANGED; | ||
| 37 | 13232 | this->prev = this->value; | |
| 38 | 13232 | return status; | |
| 39 | } | ||
| 40 | |||
| 41 | public: | ||
| 42 | //! The current value | ||
| 43 | T value; | ||
| 44 | |||
| 45 | private: | ||
| 46 | //! The previous value | ||
| 47 | Fw::Optional<T> prev; | ||
| 48 | }; | ||
| 49 | |||
| 50 | } // namespace TestUtils | ||
| 51 | |||
| 52 | #endif | ||
| 53 |