forked from gary/ems
2
0
Fork 0
sun_ems/ems_c/clib/aarch64/include/bsp_rtdb.h

143 lines
5.1 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.

/*****************************************************************************
* @copyright Copyright (c) 2025-2055 Gary. All rights reserved.
* @file bsp_rtdb.h
* @brief rtdb组件
* @author Gary
* @date 2025/03/04
* @remark
*****************************************************************************/
#ifndef BSP_RTDB_H
#define BSP_RTDB_H
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <stdint.h>
typedef enum
{
RTDB_OK,
RTDB_ERROR
} rtdb_state_e;
typedef enum
{
Rtdb_ShMem,
Rtdb_Redis,
Rtdb_End
} rtdb_type_e;
typedef enum
{
kEE_SHM_READ, // 0
kEE_SHM_CREAT // 1
} shm_creat_type_e;
typedef enum
{
kSign_Share_Start = 0,
kSign_ShMem = kSign_Share_Start,
kSign_Redis,
kSign_MQ, // 消息队列
kSign_Share_End
} sign_share_type_e;
// 全局变量web配置变化索引
typedef enum
{
kSign_Start = 0,
kSign_SysReboot = kSign_Start, // 系统reboot标记
kSign_SysSyncTime, // 系统对时
kSign_SysSetIp, // 系统IP配置
kSign_SysUpdate, // 本机系统软件升级
kSign_Rev40 = kSign_Start + 39,
kSign_End
} cfg_web_sign_e;
// 接入控制器的所有设备类型
typedef enum
{
kDev_Type_Start = 0, // 起始值
kDev_Type_EMS = kDev_Type_Start, // EMS本机 数量一个
kDev_Type_Pccmeter, // PCC电表 数量一个
kDev_Type_Bsmeter, // 储能电表 一般数量一个
kDev_Type_BSU, // 电池堆 数量 多个可配置
kDev_Type_BCU, // 电池簇 数量 多个可配置
kDev_Type_PCS, // PCS 数量 多个可配
kDev_Type_AirCond_LiquidCool, // 空调/液冷机组
kDev_Type_Thsensor, // 温湿度传感器 数量 多个可配置
kDev_Type_WaterThsensor, // 水浸传感器
kDev_Type_YGThsensor, // 烟感传感器 数量 多个可配置
kDev_Type_FireSystem, // 消防系统
kDev_Type_DI_DO_Device, // DI/DO设备设备
kDev_Type_UPS, // UPS设备 一般数量一个
kDev_Type_Reserve2, // 预留类型2
kDev_Type_Reserve3, // 预留类型3
kDev_Type_Reserve4, // 预留类型4
kDev_Type_Reserve5, // 预留类型5
kDev_Type_End
} dev_type_e;
extern rtdb_type_e rtdbType;
/*****************************************************************************
* @brief 初始化rtdb
* @param[in] type: 实时库的类型
* @param[in] arg: 默认为空
* @param[in] shmType: 创建实时库类型
* @return 0-成功 1失败
*****************************************************************************/
uint8_t initRtdb(rtdb_type_e type, void *arg, shm_creat_type_e shmType);
/*****************************************************************************
* @brief 获取RTDB中的值
* @param[in] type: 实时库的类型 默认选择Rtdb_ShMem
* @param[in] devType: 设备类型
* @param[in] devId: 设备序号 从0开始
* @param[in] pointId: 该设备中点号从0开始
* @return 获取值
*****************************************************************************/
double getRtdbPointValue(rtdb_type_e type, uint16_t devType, uint16_t devId, uint16_t pointId);
/*****************************************************************************
* @brief 向RTDB中写入值
* @param[in] type: 实时库的类型 默认选择Rtdb_ShMem
* @param[in] devType: 设备类型
* @param[in] devId: 设备序号 从0开始
* @param[in] pointId: 该设备中点号从0开始
* @param[in] value: 向RTDB中写入的值
*****************************************************************************/
void setRtdbPointValue(rtdb_type_e type, uint16_t devType, uint16_t devId, uint16_t pointId, double value);
/*****************************************************************************
* @brief 初始化用于web与c写配置变化的通知组件
* @param[in] type: 实时库的类型 默认选择Rtdb_ShMem
* @param[in] arg: 所有测点属性的指针
* @return 0-成功 1失败
*****************************************************************************/
uint8_t initWebSign(sign_share_type_e rtype, shm_creat_type_e rwtype);
/*****************************************************************************
* @brief 读取web与c写配置变化的通知组件
* @param[in] type: 实时库的类型 默认选择Rtdb_ShMem
* @param[in] signType: 通知的地址
* @return 0-成功 1失败
*****************************************************************************/
uint16_t readWebSign(sign_share_type_e rtype, cfg_web_sign_e signType);
/*****************************************************************************
* @brief 写入web与c写配置变化的通知组件
* @param[in] type: 实时库的类型
* @param[in] signType: 通知的地址
* @param[in] val: 对应的值
* @return 0-成功 1失败
*****************************************************************************/
void writeWebSign(sign_share_type_e rtype, cfg_web_sign_e signType, uint16_t val);
#endif // BSP_RTDB_H