fprime/TestUtils/OnChangeChannel.hpp
M Starch 0659f0940b
Refactored type organization (#3422)
* Refactored type organization

* Creating better configuration/types header hierarchy

* Replace FpConfig type aliases with FPP generated aliases

* Add the aliases to the FPP model

* Config + Type Aliases builds

* Renamed Fw/Types.h,hpp to Fw/FPrimeBasicTypes.h,hpp

* Updating to FPP-a7

* Adding newline

* sp

* Fixing minor nit from review

* Spurious ;

---------

Co-authored-by: Andrei Tumbar <andrei.tumbar@jpl.nasa.gov>
2025-04-03 12:11:36 -07:00

53 lines
1.5 KiB
C++

// ======================================================================
// \title OnChangeChannel.hpp
// \author Rob Bocchino
// \brief A model of an on-change channel for testing
//
// \copyright
// Copyright (C) 2023 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged. Any commercial use must be negotiated with the Office
// of Technology Transfer at the California Institute of Technology.
// ======================================================================
#ifndef TestUtils_OnChangeChannel_HPP
#define TestUtils_OnChangeChannel_HPP
#include <Fw/FPrimeBasicTypes.hpp>
#include <cstring>
#include "TestUtils/Option.hpp"
namespace TestUtils {
//! The status of an on-change telemetry channel
enum class OnChangeStatus { CHANGED, NOT_CHANGED };
//! A model of an on-change telemetry channel
template <typename T>
class OnChangeChannel {
public:
//! Constructor
explicit OnChangeChannel(T a_value) : value(a_value) {}
//! Update the previous value
OnChangeStatus updatePrev() {
const auto status = ((!this->prev.hasValue()) || (this->value != this->prev.get()))
? OnChangeStatus::CHANGED
: OnChangeStatus::NOT_CHANGED;
this->prev.set(this->value);
return status;
}
public:
//! The current value
T value;
private:
//! The previous value
Option<T> prev;
};
} // namespace TestUtils
#endif