MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/schematic/StorableValue.hh

66 lines
1.4 KiB
C++
Raw Permalink Normal View History

2024-06-07 11:12:56 +03:00
/*
* StorableValue.hh
*
* Created on: 3 сент. 2020 г.
* Author: ПО и ВТ ЭП
*/
#ifndef UMLIBRARY_SCHEMATIC_STORABLEVALUE_HH_
#define UMLIBRARY_SCHEMATIC_STORABLEVALUE_HH_
#include "../systemic/IValueAsync.hpp"
#include "../systemic/IProcess.hh"
#include "../peripheral/IMemoryAccess.hh"
namespace schematic {
//!Хранимое значение.
/*!Персистентное значение, сохраняемое в предоставленной памяти.
*
*/
class StorableValue : public systemic::IValueType<float>, public systemic::IProcess {
public:
struct Constraints {
float min;
float max;
};
StorableValue( const Constraints &, peripheral::IMemoryAccess & memory, std::size_t offset, float default_value );
void set( float value );
float get() const;
const float & value() const;
const bool & valid() const;
void process();
private:
float current_value;
const float default_value;
bool need_set = false;
enum {
read,
waitReadComplete,
write,
waitWriteComplete,
idle,
} value_state;
Constraints limits;
static const size_t buff_size = sizeof(float) + 1;
char buff[buff_size];
bool is_value_valid;
peripheral::IMemoryAccess & memory;
const std::size_t offset;
char calcCrcValue( float value );
};
}
#endif /* UMLIBRARY_SCHEMATIC_STORABLEVALUE_HH_ */