2025-03-16 14:20:19 +08:00
|
|
|
|
#ifndef SLAVE_DEFINE_H
|
2025-03-04 11:27:16 +08:00
|
|
|
|
#define SLAVE_DEFINE_H
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
2025-03-16 14:20:19 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
2025-03-04 11:27:16 +08:00
|
|
|
|
|
|
|
|
|
typedef struct _tagSlave
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
int function_code;
|
|
|
|
|
int start_address;
|
|
|
|
|
int quantity;
|
|
|
|
|
int interval;
|
|
|
|
|
} SlaveItem;
|
|
|
|
|
|
|
|
|
|
typedef std::vector<SlaveItem*> SlaveData;
|
|
|
|
|
|
2025-03-16 14:20:19 +08:00
|
|
|
|
//存储解码后的数据
|
|
|
|
|
typedef struct __DisplayDataItem
|
|
|
|
|
{
|
|
|
|
|
int device_type;
|
|
|
|
|
int order;
|
|
|
|
|
std::string title;
|
|
|
|
|
int precision;
|
|
|
|
|
int value;
|
|
|
|
|
std::string unit;
|
|
|
|
|
int display_location; //1:board 2:table
|
|
|
|
|
} DisplayDataItem;
|
|
|
|
|
|
|
|
|
|
typedef std::vector<DisplayDataItem> DisplayDataItems;
|
|
|
|
|
|
2025-03-04 11:27:16 +08:00
|
|
|
|
class DeviceData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DeviceData()
|
|
|
|
|
:m_device_type(-1),m_device_online_state(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
virtual ~DeviceData()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
int m_device_type;
|
|
|
|
|
int m_device_online_state;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-16 14:20:19 +08:00
|
|
|
|
class GeneralDeviceData: public DeviceData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GeneralDeviceData()
|
|
|
|
|
{
|
|
|
|
|
m_device_type = 8899;
|
|
|
|
|
m_device_online_state = 0;
|
|
|
|
|
}
|
|
|
|
|
virtual ~GeneralDeviceData() {}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DisplayDataItems m_PanelDisplayDataItems;
|
|
|
|
|
};
|
2025-03-04 11:27:16 +08:00
|
|
|
|
|
|
|
|
|
class TemperatureData : public DeviceData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TemperatureData()
|
|
|
|
|
{
|
|
|
|
|
m_device_type = 81;
|
|
|
|
|
bDecodeAlarm = false;
|
|
|
|
|
bDecodeTemp = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~TemperatureData() {}
|
|
|
|
|
|
|
|
|
|
public:
|
2025-03-16 14:20:19 +08:00
|
|
|
|
bool bDecodeAlarm;
|
|
|
|
|
bool bDecodeTemp;
|
2025-03-04 11:27:16 +08:00
|
|
|
|
float TempValue;
|
|
|
|
|
float HumidityValue;
|
|
|
|
|
float DewPointValue;
|
|
|
|
|
int DO;
|
|
|
|
|
int DI1;
|
|
|
|
|
int DI2;
|
|
|
|
|
int TempHighAlarm;
|
|
|
|
|
int HumidityHighAlarm;
|
|
|
|
|
int TempLowAlarm;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-16 14:20:19 +08:00
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// //
|
|
|
|
|
// 以下数据结构是为了存取json配置文件设置 //
|
|
|
|
|
// 保存串口的从机号、寄存器开始地址、数量、寄存器数据描述等等信息 //
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
|
* 逻辑结构
|
|
|
|
|
*
|
|
|
|
|
SlaveItems 定义有多少个从机
|
|
|
|
|
slaveAddress 定义每一个从机有多少要读取的地址,每一个起始地址并不保证连续
|
|
|
|
|
registryData 定义每一个起始地址需要读取的数据
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************/
|
|
|
|
|
|
|
|
|
|
//寄存器的数据,以及控制策略描述
|
|
|
|
|
typedef struct __registryData
|
|
|
|
|
{
|
|
|
|
|
__registryData():
|
|
|
|
|
comment(""), precision(1.0f), unit(""), title_chn("中文"), title_en("eng"), display(1), skip(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::string comment; // ":"在线状态", 注释字段,为了方便读,无实际意义
|
|
|
|
|
int order; // 定义解码的顺序,从0开始,数量 =slaveAddress.quantity,
|
|
|
|
|
float precision; // " : 1, 精度,标注小数点用
|
|
|
|
|
std::string unit; // " : "", 单位
|
|
|
|
|
std::string title_chn; // " : 中文显示
|
|
|
|
|
std::string title_en; // " : 英文显示
|
|
|
|
|
int display; // " : 1, 是否显示,0不显示,1显示在board,2显示在表格
|
|
|
|
|
int skip; //" : 0 //1跳过 0不跳过
|
|
|
|
|
} registryData;
|
|
|
|
|
|
|
|
|
|
//寄存器的数据数组
|
|
|
|
|
typedef std::map<int,registryData> RegisterDataItems;
|
|
|
|
|
|
|
|
|
|
typedef struct __slaveAddress
|
|
|
|
|
{
|
|
|
|
|
int start_addr; // ":40000, 寄存器地址
|
|
|
|
|
unsigned short quantity; // " : 9, 连续读取多少个寄存器
|
|
|
|
|
unsigned short bytes_per_register; // " : 2, 每个寄存器的字节数,缺省是uint16,两个字节
|
2025-03-17 09:58:54 +08:00
|
|
|
|
std::string lang; // 使用语言,"chn": 中文 "en":English
|
2025-03-16 14:20:19 +08:00
|
|
|
|
std::string device_name_chn; // " : "温湿度", 该寄存器数组代表的设备名称
|
|
|
|
|
std::string device_name_eng; // " : "温湿度", 该寄存器数组代表的设备名称,英文
|
|
|
|
|
|
|
|
|
|
//标识本地址的数据是哪一个类型的设备
|
|
|
|
|
/*
|
|
|
|
|
PANEL_TEMPERATURE = 1,
|
|
|
|
|
PANEL_BATTERY = 2,
|
|
|
|
|
PANEL_POWER = 3,
|
|
|
|
|
PANEL_AC = 4,
|
|
|
|
|
PANEL_PV = 5,
|
|
|
|
|
PANEL_ALARM = 6,
|
|
|
|
|
PANEL_INVERTER = 7,
|
|
|
|
|
PANEL_OTHER = 88,
|
|
|
|
|
PANEL_HOME = 99,
|
|
|
|
|
* */
|
|
|
|
|
int device_type;
|
|
|
|
|
|
|
|
|
|
RegisterDataItems register_data_items; //寄存器数据,数组
|
|
|
|
|
} slaveAddress;
|
|
|
|
|
|
|
|
|
|
//需要读取的从机的地址信息
|
|
|
|
|
typedef std::vector<slaveAddress> SlaveAddressItems;
|
|
|
|
|
|
|
|
|
|
typedef struct __slaveItem
|
|
|
|
|
{
|
|
|
|
|
int slave_id; //从机ID
|
|
|
|
|
int function_code; //功能码,缺省是3
|
|
|
|
|
SlaveAddressItems slave_address_items; //该从机ID需要读取的地址信息描述
|
|
|
|
|
} slaveItem;
|
|
|
|
|
|
|
|
|
|
//需要处理的从机列表
|
|
|
|
|
typedef std::vector<slaveItem> SlaveItems;
|
|
|
|
|
|
|
|
|
|
|
2025-03-04 11:27:16 +08:00
|
|
|
|
#endif // SLAVE_DEFINE_H
|