Files
energy_storage/src/app/DataStruct.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

2025-09-04 19:31:04 +08:00
#include "DataStruct.h"
2025-09-16 19:38:46 +08:00
#include "common/JsonN.h"
#include "common/Utils.h"
2025-09-04 19:31:04 +08:00
2025-09-16 19:38:46 +08:00
std::string REGAddrOffset(std::string addr, int offset)
2025-09-04 19:31:04 +08:00
{
2025-09-16 19:38:46 +08:00
unsigned int val;
std::stringstream ss;
ss << std::hex << addr;
ss >> val;
return Utils::toHexStr(val + offset);
2025-09-04 19:31:04 +08:00
}
2025-09-16 19:38:46 +08:00
std::map<std::string, std::map<std::string, RegAddrUnit>> REGAddr::s_mapReg;
void REGAddr::load(std::string filename)
{
njson json;
JSON::load(filename, json);
// 遍历 JSON 对象
for (auto& jsonitem : json.items())
{
std::string name = jsonitem.key();
auto& jsonnodeItem = jsonitem.value();
//int count = jsonnodeItem["count"];
auto jsonaddrs = jsonnodeItem["addr"];
auto& mapItem = s_mapReg[name];
int size = 0;
for (int i = 0; i<2; ++i)
{
for (auto& item : jsonaddrs)
{
std::string addr = item["key"];
mapItem[addr] = RegAddrUnit(addr, item["datatype"], item["remark"]);
}
}
}
//for (auto& item: s_mapReg["EMS_YC"])
//{
// auto& unit = item.second;
// spdlog::info("[{}]={}, {}", unit.key, unit.datatype, unit.remark);
//}
}
std::map<std::string, RegAddrUnit>* REGAddr::getRegMap(std::string name)
2025-09-04 19:31:04 +08:00
{
2025-09-16 19:38:46 +08:00
auto iter = s_mapReg.find(name);
if (iter != s_mapReg.end())
{
return &(iter->second);
}
return nullptr;
2025-09-04 19:31:04 +08:00
}