eis/eqpm/EqpmRecord.h

54 lines
1.7 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.

#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