Files
energy_storage/src/app/Device.h
2025-09-12 18:44:34 +08:00

64 lines
1.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.
#pragma once
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <unordered_map>
#include "common/Fields.h"
class CommEntity;
class Device
{
public:
static std::shared_ptr<Device> create(Fields& fields);
void setFields(Fields& fields);
int startComm();
void getCacheVoltage(std::vector<std::string>& vec);
void getCacheCurrent(std::vector<std::string>& vec);
void getCachePower(std::vector<std::string>& vec);
// int datatype: 1: 电压2电流3功率
void setCache(int datatype, std::vector<double>& vec);
bool cache(int npos);
void storeDB(int npos);
void setParam(std::string k, std::string v);
std::string getParam(std::string k, std::string defaultVal = "");
void getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params);
public:
int deviceId = -1;
int type = -1;
std::string name;
std::string code;
int category;
bool isOpen = false;
std::string attrsJson = "";
int err = 0;
int online = 0;
int running = 0;
//std::map<std::string, std::string> mapAttrs;
Fields attrs;
// 通讯entity
std::shared_ptr<CommEntity> commEntity;
int64_t tsDataDate {};
std::map<int, double> mapCacheVoltage;
std::map<int, double> mapCacheCurrent;
std::map<int, double> mapCachePower;
std::map<std::string, std::string> mapParams;
};