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

66 lines
1.3 KiB
C++

/*
* 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_ */