eis/eqpm/EqpmRecord.h

54 lines
1.7 KiB
C
Raw Normal View History

#pragma once
/**
* @file EqpmRecord.h
* @brief eqpm shm数据结构
* @author your name (you@domain.com)
* @version 0.1
* @date 2023-12-22
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <mix_cc/shm.h>
namespace EqpmShm {
namespace SHM = mix_cc::shm;
namespace bipc = mix_cc::shm::bip;
const static std::string dir_path = "/users/dsc/shm";
const static std::string shm_file = "EqpmRecord"; ///<映射文件名
const double data_size = 500; ///< 数据大小 MB
const static int MinTime = 1672502400; ///< 2023-01-01 000000
const static int Days = 3650; ///<最多保持10年内的数据
const static int Defalt_Days = 30; ///<默认计算从一个月前开始
const static int MaxYear = 50; ///<最多 50年后
static bipc::managed_mapped_file obj_mapped_file(
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
mix_cc::data_size::MB(data_size));
/**
* @brief
*/
struct EqpmRecord {
double weight;
double length;
};
/**
* @brief ,
*/
struct TimeRecord {
int stime;
int etime;
double per_weight; ///<千克
double per_length; ///<米
};
/*单例 map 记录每天的重量 长度*/
const static bipc::offset_ptr<SHM::Map<int, EqpmRecord>> EqpmRecordPtr =
SHM::MapBuilder<int, EqpmRecord>::find_or_construct(&obj_mapped_file,
shm_file);
/*单例 TimeRecord 保持 记录的起止时间*/
const static bipc::offset_ptr<TimeRecord> TimeRecordPtr =
obj_mapped_file.find_or_construct<TimeRecord>("TimeRecord")();
} // namespace EqpmShm