runing with ledger interface
This commit is contained in:
@@ -2750,6 +2750,7 @@ void to_json(nlohmann::json& j, const MsgObj& m) {
|
||||
// FullObj to_json
|
||||
void to_json(nlohmann::json& j, const FullObj& f) {
|
||||
j = nlohmann::json{
|
||||
{"Id", f.mac},
|
||||
{"Mid", f.Mid},
|
||||
{"Did", f.Did},
|
||||
{"Pri", f.Pri},
|
||||
@@ -2758,6 +2759,7 @@ void to_json(nlohmann::json& j, const FullObj& f) {
|
||||
};
|
||||
}
|
||||
std::string generate_json(
|
||||
const std::string mac,
|
||||
int Mid, //需应答的报文订阅者收到后需以此ID应答,无需应答填入“-1”
|
||||
int Did, //设备唯一标识Ldid,填入0代表Ndid。
|
||||
int Pri, //报文处理的优先级
|
||||
@@ -2769,6 +2771,7 @@ std::string generate_json(
|
||||
const std::vector<DataArrayItem>& dataArray //数据数组。
|
||||
) {
|
||||
FullObj fobj;
|
||||
fobj.mac = mac;
|
||||
fobj.Mid = Mid;
|
||||
fobj.Did = Did;
|
||||
fobj.Pri = Pri;
|
||||
@@ -2792,7 +2795,7 @@ void upload_data_test(){
|
||||
arr.push_back({2, 1691741340, 0, 1, "yyyy"});
|
||||
|
||||
std::string js = generate_json(
|
||||
-1, 2, 1, 4866, 1, 0, 2, 1, arr
|
||||
"123",-1, 1, 1, 4866, 1, 0, 2, 1, arr
|
||||
);
|
||||
std::cout << js << std::endl;
|
||||
|
||||
@@ -2814,8 +2817,9 @@ std::vector<DeviceInfo> GenerateDeviceInfoFromLedger(const std::vector<terminal_
|
||||
DeviceInfo device;
|
||||
device.device_id = terminal.terminal_id;
|
||||
device.name = terminal.terminal_name;
|
||||
device.model = terminal.dev_series;
|
||||
device.mac = terminal.mac;
|
||||
device.model = terminal.dev_type;
|
||||
device.mac = terminal.addr_str;
|
||||
device.status = 1;
|
||||
|
||||
for (const auto& monitor : terminal.line) {
|
||||
PointInfo point;
|
||||
@@ -2826,6 +2830,9 @@ std::vector<DeviceInfo> GenerateDeviceInfoFromLedger(const std::vector<terminal_
|
||||
point.PT2 = monitor.PT2;
|
||||
point.CT1 = monitor.CT1;
|
||||
point.CT2 = monitor.CT2;
|
||||
point.strScale = monitor.voltage_level;
|
||||
point.nCpuNo = std::stoi(monitor.logical_device_seq);
|
||||
point.nPTType = std::stoi(monitor.terminal_connect);
|
||||
|
||||
device.points.push_back(point);
|
||||
}
|
||||
@@ -2882,7 +2889,7 @@ bool assign_qvvr_file_list(const std::string& id, ushort nCpuNo, const std::vect
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////下载成功通知
|
||||
//提取下载路径的文件名
|
||||
std::string extract_filename(const std::string& path) {
|
||||
std::string extract_filename1(const std::string& path) {
|
||||
size_t pos = path.find_last_of("/\\");
|
||||
return (pos != std::string::npos) ? path.substr(pos + 1) : path;
|
||||
}
|
||||
@@ -2946,7 +2953,7 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||
|
||||
// 去除 mac 路径前缀,仅保留文件名
|
||||
std::string filename = extract_filename(filename_with_mac);
|
||||
std::string filename = extract_filename1(filename_with_mac);
|
||||
|
||||
// 提取逻辑序号(如 PQM1 → 1)
|
||||
size_t under_pos = filename.find('_');
|
||||
@@ -2992,7 +2999,7 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
std::set<std::string> s_name(qfile.file_name.begin(), qfile.file_name.end());
|
||||
std::set<std::string> s_down;
|
||||
for (const auto& path : qfile.file_download) {
|
||||
s_down.insert(extract_filename(path)); // 提取每个路径中的文件名
|
||||
s_down.insert(extract_filename1(path)); // 提取每个路径中的文件名
|
||||
}
|
||||
|
||||
// 检查 file_download 是否与 file_name 完全一致(集合相同)
|
||||
@@ -3001,7 +3008,7 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
|
||||
// 找到其中的 .cfg 文件进行匹配
|
||||
for (const auto& fpath : qfile.file_download) {
|
||||
std::string fname = extract_filename(fpath);
|
||||
std::string fname = extract_filename1(fpath);
|
||||
if (fname.size() >= 4 && fname.substr(fname.size() - 4) == ".cfg") {
|
||||
// 提取文件时标和监测点事件的时标匹配
|
||||
qvvr_data matched;
|
||||
@@ -3064,3 +3071,10 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
|
||||
}
|
||||
return false; // 未匹配到终端ID或逻辑序号对应的监测点
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////提取mac
|
||||
std::string normalize_mac(const std::string& mac) {
|
||||
std::string result = mac;
|
||||
result.erase(std::remove(result.begin(), result.end(), '-'), result.end());
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user