MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/ParamStaticStorage.hh
2024-06-07 11:12:56 +03:00

169 lines
6.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ParamStaticStorage.h
*
* Created on: 19 нояб. 2018 г.
* Author: titov
*/
#ifndef SOURCE_DRIVER_PARAMSTATICSTORAGE_H_
#define SOURCE_DRIVER_PARAMSTATICSTORAGE_H_
#include "IParamStorage.hh"
#include "../systemic/IParameterProvider.hh"
#include "../systemic/IProcess.hh"
#include "../peripheral/IMemoryAccess.hh"
#include <memory_resource>
#include <deque>
#include <cstddef>
#include <stdint.h>
namespace driver { namespace detail {
class ParamStaticStorage : public IParamStorage, public systemic::IProcess {
private:
peripheral::IMemoryAccess & memory; //!<Указатель на интерфейс работы с памятью
char * const buff; //!<Буфер для работы с данными хранимыми в памяти.
const std::size_t buff_size; //!<Размер буфера.
//systemic::IProcessControl * proc_ctrl;
//!Структура описания данных в буфере, данных хранимых в memory.
struct DataImage {
//!Заголовок: описание данных в памяти.
struct Head {
uint16_t setting_count; //!<Количество настроек.
uint16_t buff_size; //!<Суммарный размер всех настроек.
uint32_t setting_crc; //!<Контрольная сумма всего DataImage.
} * head;
//!Информационная структура описания параметра, образ в ПЗУ.
struct SettingInfo {
uint16_t id; //!<Идентификатор настройки
uint16_t setting_size; //!<Размер структуры
} * info; //!<Массив структур
char * data_buff; //!<Указатель на начало данных настроек.
std::size_t max_size; //!<Максимальный размер данных в буфере.
std::size_t data_align; //!<Выравнивание данных в буфере.
//!Функция вычисляет указатель на буфер настройки.
char * extract_setting_data_buff( unsigned int id, unsigned int size ) const;
unsigned int show_setting_size( unsigned int id ) const;
const char * show_setting_data_buff( unsigned int id ) const;
//!Функция изменяет структуру буфера под новые потребности.
/*!Функция изменяет структуру буфера для возможности хранения настройки с идентификатором id, размером size.
* \param[in] id Идентификатор настройки, новый или существующий.
* \param[in] size Размерл настройки.
* \return Признак завершения операции: true - если место под настройку выделено, false - в случае ошибки.
*/
bool change_setting_info( unsigned int id, unsigned int size );
//!Функция строит образ данных исходя из предоставленного массива байт.
//!\param[in] buff Массив байт в котором храняться данные соотвествующие образу.
bool build_from_buff( char * buff, std::size_t buff_size, std::size_t buff_align );
//!Функция возвращает размер образа.
std::size_t get_image_size() const;
void reset();
private:
bool insert_new_setting( unsigned int id, unsigned int size );
bool change_size( unsigned int size, unsigned int index,
char * data_pointer );
//!Функция перемещает отрезок памяти на выбранное смещение.
/*!Функция перемещает отрезок памяти на выбранное смещение.
* \param[in] from Указатель на начало отрезка памяти.
* \param[in] to Указатель на конец отрезка памяти.
* \param[in] delta Смещение на которое необходимо все переместить.
*/
void move_buff( char * from, char * to, int delta );
//!Функция возвращает размер занимаемой памяти в соотвествии с выравниванием.
std::size_t aligned_size( std::size_t ) const;
} image;
struct State {
enum Id {
Idle,
StartWrite,
WaitWrite,
StartReadHead,
WaitReadHead,
StartReadEnd,
WaitReadEnd,
StartWriteOnce,
WaitWriteOnce,
StartReadOnce,
WaitReadOnce,
StartUpdateCrc,
WaitUpdateCrc,
StartReadCrc,
};
};
State::Id state;
bool data_ready;
bool crc_error;
bool check_crc();
void update_crc();
bool isMemoryProcessing() const;
void disableProcess() {}
void enableProcess() {}
void temp_construct();
void temp_destruct();
typedef systemic::IParameterProvider::Id Id;
std::deque<Id, std::pmr::polymorphic_allocator<Id> > tasks;
struct Temp {
std::pair<char *, std::size_t> buff;
char * target;
std::size_t offset;
} temp;
public:
ParamStaticStorage( peripheral::IMemoryAccess & memory,
char * buff, std::size_t buff_size, std::pmr::memory_resource * task_buffer );
systemic::SharedData getParameterBuff( Id parameter_id ) const;
bool flushParameterBuff( Id parameter_id );
public:
void flush(); //!<
void load();
systemic::SharedData createParameterBuff( IParamStorage::Id parameter_id, std::size_t parameter_size );
std::pair<const char *, std::size_t> get4read( IParamStorage::Id id ) const;
bool isDataSync() const;
void clear(); //!<
//!Запрос ошибки параметров.
/*!
* \return Признак ошибки параметров
*/
bool isCrcError() const;
public:
void init( float );
void process();
};
}}
#endif /* SOURCE_DRIVER_PARAMSTATICSTORAGE_H_ */