#include "DataStruct.h" #include "common/JsonN.h" #include "common/Utils.h" std::string REGAddrOffset(std::string addr, int offset) { unsigned int val; std::stringstream ss; ss << std::hex << addr; ss >> val; return Utils::toHexStr(val + offset); } std::map> 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* REGAddr::getRegMap(std::string name) { auto iter = s_mapReg.find(name); if (iter != s_mapReg.end()) { return &(iter->second); } return nullptr; }