Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ffde5ea84 | |||
| 54a23099a6 | |||
| 57b4e65627 | |||
| 9f74ada894 | |||
| 86dc51d066 | |||
| abc5f9e735 | |||
| 0e2ade351c | |||
| fe16beb188 | |||
| 45d139e628 | |||
| 111ffa36bd | |||
| d78cef25a0 | |||
| c0860a48d6 | |||
| 62a9742287 |
@@ -156,6 +156,7 @@ public:
|
||||
char dev_type[64];
|
||||
char dev_key[255];
|
||||
char dev_series[255];
|
||||
char com_type[32];
|
||||
char addr_str[64];
|
||||
char port[64];
|
||||
char timestamp[64];
|
||||
@@ -860,6 +861,9 @@ void init_config() {
|
||||
else if (g_node_id == SOE_COMTRADE_BASE_NODE_ID) {//暂态录波
|
||||
TEST_PORT = TEST_PORT + SOE_COMTRADE_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
else if (g_node_id == PQDIF_DATA_BASE_NODE_ID) {
|
||||
TEST_PORT = TEST_PORT + PQDIF_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1700,6 +1704,8 @@ void add_terminal_to_trigger_update(trigger_update_xml_t* trigger_update_xml, co
|
||||
}
|
||||
}
|
||||
|
||||
static bool terminal_update_should_bind_to_current_process(const terminal* dev);
|
||||
|
||||
// 解析 XML 数据并提取 terminal 信息
|
||||
void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const std::string& str_tag, const std::string& data,const std::string& guid_value) {
|
||||
terminal work_terminal = {}; // 创建新的 terminal 对象
|
||||
@@ -1715,6 +1721,13 @@ void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const st
|
||||
strcpy(work_terminal.dev_type, extract_value(data, "devType").c_str());
|
||||
strcpy(work_terminal.dev_key, extract_value(data, "devKey").c_str());
|
||||
strcpy(work_terminal.dev_series, extract_value(data, "series").c_str());
|
||||
std::string com_type = extract_value(data, "comType");
|
||||
if (com_type.empty())
|
||||
com_type = extract_value(data, "com_type");
|
||||
if (com_type.empty())
|
||||
com_type = "MMS";
|
||||
strncpy(work_terminal.com_type, com_type.c_str(), sizeof(work_terminal.com_type) - 1);
|
||||
work_terminal.com_type[sizeof(work_terminal.com_type) - 1] = '\0';
|
||||
strcpy(work_terminal.processNo, extract_value(data, "processNo").c_str());
|
||||
strcpy(work_terminal.addr_str, extract_value(data, "ip").c_str());
|
||||
strcpy(work_terminal.port, extract_value(data, "port").c_str());
|
||||
@@ -1801,6 +1814,13 @@ void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const st
|
||||
|
||||
|
||||
// 根据 str_tag 将 terminal 添加到相应的数组
|
||||
if (!terminal_update_should_bind_to_current_process(&work_terminal)) {
|
||||
std::cout << "skip ledger update xml by comType:" << work_terminal.com_type
|
||||
<< " terminal:" << work_terminal.terminal_id
|
||||
<< " process:" << subdir << g_front_seg_index << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
add_terminal_to_trigger_update(trigger_update_xml, str_tag, work_terminal);
|
||||
}
|
||||
|
||||
@@ -1821,11 +1841,25 @@ void parse_ledger_update(trigger_update_xml_t* trigger_update_xml, const std::st
|
||||
if (strTag == "delete") {
|
||||
// 填充终端信息
|
||||
strcpy(delete_terminal.terminal_id, extract_value(data, "id").c_str());
|
||||
std::string com_type = extract_value(data, "comType");
|
||||
if (com_type.empty())
|
||||
com_type = extract_value(data, "com_type");
|
||||
if (com_type.empty())
|
||||
com_type = "MMS";
|
||||
strncpy(delete_terminal.com_type, com_type.c_str(), sizeof(delete_terminal.com_type) - 1);
|
||||
delete_terminal.com_type[sizeof(delete_terminal.com_type) - 1] = '\0';
|
||||
|
||||
//添加guid20250506
|
||||
strncpy(delete_terminal.guid, guid_value.c_str(), sizeof(delete_terminal.guid) - 1);
|
||||
delete_terminal.guid[sizeof(delete_terminal.guid) - 1] = '\0';
|
||||
|
||||
if (!terminal_update_should_bind_to_current_process(&delete_terminal)) {
|
||||
std::cout << "skip delete ledger update xml by comType:" << delete_terminal.com_type
|
||||
<< " terminal:" << delete_terminal.terminal_id
|
||||
<< " process:" << subdir << g_front_seg_index << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// 将删除信息写入 delete_updates
|
||||
std::cout << "delete ledger!!!!!"<<std::endl;
|
||||
if (trigger_update_xml->delete_update_num < MAX_UPDATEA_NUM) {
|
||||
@@ -3388,6 +3422,192 @@ void SendJsonAPI_web(const std::string& strUrl, const char* code, const std::str
|
||||
}
|
||||
|
||||
// 打印 terminal_dev_map 中所有内容的函数
|
||||
static bool is_cfg_pqdif_process()
|
||||
{
|
||||
return std::strstr(subdir, "cfg_pqdif_data") != NULL;
|
||||
}
|
||||
|
||||
static bool is_pqdif_com_type(const char* com_type)
|
||||
{
|
||||
QString type = com_type ? QString::fromLocal8Bit(com_type).trimmed() : QString();
|
||||
return type.compare("PQDIF", Qt::CaseInsensitive) == 0;
|
||||
}
|
||||
|
||||
static const char* PQDIF_CONFIG_DIR = "/FeProject/PQDIF/config";
|
||||
static const char* PQDIF_CONFIG_FILE = "/FeProject/PQDIF/config/pqdif-config.xml";
|
||||
static const char* PQDIF_CONFIG_TMP_FILE = "/FeProject/PQDIF/config/pqdif-config.xml.tmp";
|
||||
|
||||
static bool pqdif_config_value_valid(const char* value)
|
||||
{
|
||||
if (value == NULL)
|
||||
return false;
|
||||
|
||||
QString text = QString::fromLocal8Bit(value).trimmed();
|
||||
return !text.isEmpty() && text.compare("N/A", Qt::CaseInsensitive) != 0;
|
||||
}
|
||||
|
||||
static int pqdif_config_write_begin(QFile& file, QXmlStreamWriter& writer)
|
||||
{
|
||||
if (!QDir().mkpath(PQDIF_CONFIG_DIR)) {
|
||||
printf("[PQDIF][CONFIG] mkdir failed: %s\n", PQDIF_CONFIG_DIR);
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
QFile::remove(PQDIF_CONFIG_TMP_FILE);
|
||||
file.setFileName(PQDIF_CONFIG_TMP_FILE);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
|
||||
printf("[PQDIF][CONFIG] open tmp failed: %s, err=%s\n",
|
||||
PQDIF_CONFIG_TMP_FILE,
|
||||
file.errorString().toLocal8Bit().constData());
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
// Always write a complete temporary XML first. Java only reads the
|
||||
// final file after the tmp file has been closed and atomically renamed.
|
||||
writer.setDevice(&file);
|
||||
writer.setAutoFormatting(true);
|
||||
writer.setCodec("UTF-8");
|
||||
writer.writeStartDocument("1.0");
|
||||
writer.writeStartElement("PqdifConfig");
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
|
||||
static int pqdif_config_write_commit(QFile& file, QXmlStreamWriter& writer)
|
||||
{
|
||||
writer.writeEndElement();
|
||||
writer.writeEndDocument();
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
if (::rename(PQDIF_CONFIG_TMP_FILE, PQDIF_CONFIG_FILE) != 0) {
|
||||
printf("[PQDIF][CONFIG] rename %s to %s failed\n",
|
||||
PQDIF_CONFIG_TMP_FILE,
|
||||
PQDIF_CONFIG_FILE);
|
||||
QFile::remove(PQDIF_CONFIG_TMP_FILE);
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
|
||||
static void pqdif_config_write_abort(QFile& file)
|
||||
{
|
||||
if (file.isOpen())
|
||||
file.close();
|
||||
QFile::remove(PQDIF_CONFIG_TMP_FILE);
|
||||
}
|
||||
|
||||
static void pqdif_config_write_point(QXmlStreamWriter& writer, const LD_info_t* LD_info)
|
||||
{
|
||||
writer.writeEmptyElement("Point");
|
||||
writer.writeAttribute("pointNo", QString::number((int)LD_info->cpuno));
|
||||
writer.writeAttribute("monitorId", QString::fromLocal8Bit(LD_info->mp_id).trimmed());
|
||||
}
|
||||
|
||||
static int pqdif_config_write_device(QXmlStreamWriter& writer,
|
||||
ied_t* ied,
|
||||
ied_usr_t* ied_usr)
|
||||
{
|
||||
writer.writeStartElement("Device");
|
||||
writer.writeAttribute("ip", QString::fromLocal8Bit(ied->channel[0].addr_str).trimmed());
|
||||
writer.writeAttribute("pqdifType", QString::fromLocal8Bit(ied_usr->dev_type).trimmed());
|
||||
|
||||
int point_count = 0;
|
||||
if (ied_usr->LD_info != NULL) {
|
||||
for (int cpuno = 0; cpuno < ied->cpucount; ++cpuno) {
|
||||
LD_info_t* LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
if (LD_info->read_flag != ENABLE)
|
||||
continue;
|
||||
if (LD_info->cpuno == 0 || !pqdif_config_value_valid(LD_info->mp_id))
|
||||
continue;
|
||||
|
||||
pqdif_config_write_point(writer, LD_info);
|
||||
++point_count;
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeEndElement();
|
||||
return point_count;
|
||||
}
|
||||
|
||||
int pqdif_rebuild_config_from_current_ledger()
|
||||
{
|
||||
if (!is_cfg_pqdif_process())
|
||||
return APR_SUCCESS;
|
||||
|
||||
QFile file;
|
||||
QXmlStreamWriter writer;
|
||||
int write_count = 0;
|
||||
int point_count = 0;
|
||||
|
||||
if (pqdif_config_write_begin(file, writer) != APR_SUCCESS)
|
||||
return APR_EGENERAL;
|
||||
|
||||
if (g_node != NULL && g_node->clients != NULL) {
|
||||
for (int i = 0; i < g_node->n_clients; ++i) {
|
||||
ied_t* ied = g_node->clients[i];
|
||||
if (ied == NULL || ied->usr_ext == NULL || ied->chncount <= 0 || ied->channel == NULL)
|
||||
continue;
|
||||
|
||||
ied_usr_t* ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
if (ied_usr->dev_flag != ENABLE)
|
||||
continue;
|
||||
if (!is_pqdif_com_type(ied_usr->com_type))
|
||||
continue;
|
||||
if (!pqdif_config_value_valid(ied->channel[0].addr_str) ||
|
||||
!pqdif_config_value_valid(ied_usr->dev_type)) {
|
||||
printf("[PQDIF][CONFIG] skip invalid ledger, terminal=%s ip=%s type=%s\n",
|
||||
ied_usr->terminal_id,
|
||||
ied->channel[0].addr_str,
|
||||
ied_usr->dev_type);
|
||||
continue;
|
||||
}
|
||||
|
||||
point_count += pqdif_config_write_device(writer, ied, ied_usr);
|
||||
++write_count;
|
||||
}
|
||||
}
|
||||
|
||||
if (pqdif_config_write_commit(file, writer) != APR_SUCCESS) {
|
||||
pqdif_config_write_abort(file);
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
printf("[PQDIF][CONFIG] rebuild success, file=%s, devices=%d, points=%d\n",
|
||||
PQDIF_CONFIG_FILE,
|
||||
write_count,
|
||||
point_count);
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
|
||||
static bool terminal_should_bind_to_current_process(const terminal_dev* dev)
|
||||
{
|
||||
if (dev == NULL)
|
||||
return false;
|
||||
|
||||
if (is_pqdif_com_type(dev->com_type))
|
||||
return is_cfg_pqdif_process();
|
||||
|
||||
if (is_cfg_pqdif_process())
|
||||
return false;
|
||||
|
||||
return (atoi(dev->processNo) == g_front_seg_index || g_front_seg_index == 0);
|
||||
}
|
||||
|
||||
static bool terminal_update_should_bind_to_current_process(const terminal* dev)
|
||||
{
|
||||
if (dev == NULL)
|
||||
return false;
|
||||
|
||||
if (is_pqdif_com_type(dev->com_type))
|
||||
return is_cfg_pqdif_process();
|
||||
|
||||
if (is_cfg_pqdif_process())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void printTerminalDevMap(const QMap<QString, terminal_dev*>& terminal_dev_map) {
|
||||
QMap<QString, terminal_dev*>::const_iterator it;
|
||||
for (it = terminal_dev_map.constBegin(); it != terminal_dev_map.constEnd(); ++it) {
|
||||
@@ -3406,6 +3626,7 @@ void printTerminalDevMap(const QMap<QString, terminal_dev*>& terminal_dev_map) {
|
||||
<< ", Device Type:" << QString(dev->dev_type)
|
||||
<< ", Device Key:" << QString(dev->dev_key)
|
||||
<< ", Device Series:" << QString(dev->dev_series)
|
||||
<< ", Device comType:" << QString(dev->com_type)
|
||||
<< ", Device processNo:" << QString(dev->processNo)
|
||||
<< ", Device maxProcessNum:" << QString(dev->maxProcessNum)
|
||||
<< ", Address:" << QString(dev->addr_str)
|
||||
@@ -3440,6 +3661,7 @@ void printLedger(const ied_usr_t& ied_usr) {
|
||||
std::cout << "|-- dev_type: " << ied_usr.dev_type << std::endl;
|
||||
std::cout << "|-- dev_key: " << ied_usr.dev_key << std::endl;
|
||||
std::cout << "|-- dev_series: " << ied_usr.dev_series << std::endl;
|
||||
std::cout << "|-- com_type: " << ied_usr.com_type << std::endl;
|
||||
std::cout << "|-- dev_flag: " << ied_usr.dev_flag << std::endl;
|
||||
|
||||
std::cout << "|-- last_call_wavelist_time: " << ied_usr.last_call_wavelist_time << std::endl;
|
||||
@@ -3534,6 +3756,7 @@ void printLedgerinshell(const ied_usr_t& ied_usr, QIODevice* outputDevice) {
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_type: " + QByteArray(ied_usr.dev_type) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_key: " + QByteArray(ied_usr.dev_key) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_series: " + QByteArray(ied_usr.dev_series) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- com_type: " + QByteArray(ied_usr.com_type) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_processNo: " + QByteArray(ied_usr.processNo) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_flag: " + QByteArray::number(ied_usr.dev_flag) + "\n");
|
||||
outputDevice->write("\r\x1B[K");outputDevice->write("|-- last_call_wavelist_time: " + QByteArray::number(ied_usr.last_call_wavelist_time) + "\n");
|
||||
@@ -4085,6 +4308,13 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
else strncpy(dev->dev_series, "N/A", sizeof(dev->dev_series) - 1);
|
||||
dev->dev_series[sizeof(dev->dev_series) - 1] = '\0';
|
||||
|
||||
cJSON* comType = cJSON_GetObjectItem(item, "comType");
|
||||
if (comType == NULL)
|
||||
comType = cJSON_GetObjectItem(item, "com_type");
|
||||
if (comType && comType->type == cJSON_String) strncpy(dev->com_type, comType->valuestring, sizeof(dev->com_type) - 1);
|
||||
else strncpy(dev->com_type, "MMS", sizeof(dev->com_type) - 1);
|
||||
dev->com_type[sizeof(dev->com_type) - 1] = '\0';
|
||||
|
||||
//lnk20250210台账进程号
|
||||
cJSON* processNo = cJSON_GetObjectItem(item, "processNo"); // processNo转为字符串
|
||||
if (processNo && processNo->type == cJSON_Number) snprintf(dev->processNo, sizeof(dev->processNo), "%d", processNo->valueint);
|
||||
@@ -4190,19 +4420,20 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
|
||||
//lnk20260312防止内存泄漏
|
||||
bool inserted = false;
|
||||
bool should_bind = terminal_should_bind_to_current_process(dev);
|
||||
|
||||
// 检查是否存在重复键
|
||||
if (terminal_dev_map->contains(key)) {
|
||||
std::cerr << "Duplicate terminal_code found: " << key.toStdString() << std::endl;
|
||||
|
||||
// 删除旧的 terminal_dev 对象以避免内存泄漏
|
||||
delete terminal_dev_map->value(key);
|
||||
if (should_bind) delete terminal_dev_map->value(key);
|
||||
|
||||
// 移除旧的键值对
|
||||
terminal_dev_map->remove(key);
|
||||
if (should_bind) terminal_dev_map->remove(key);
|
||||
|
||||
// 插入新的 terminal_dev 对象
|
||||
if(atoi(dev->processNo) == g_front_seg_index || g_front_seg_index == 0){//lnk20250210匹配进程号
|
||||
if(should_bind){//lnk20250210匹配进程号
|
||||
//调试用
|
||||
std::cout<< "process num match" << std::endl;
|
||||
terminal_dev_map->insert(key, dev);
|
||||
@@ -4210,7 +4441,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
}//后续修改为只有进程号匹配上index才录入当前进程
|
||||
} else {
|
||||
// 插入新的 terminal_dev 对象
|
||||
if(atoi(dev->processNo) == g_front_seg_index || g_front_seg_index == 0){//lnk20250210匹配进程号
|
||||
if(should_bind){//lnk20250210匹配进程号
|
||||
//调试用
|
||||
std::cout<< "process num match" << std::endl;
|
||||
terminal_dev_map->insert(key, dev);
|
||||
@@ -4371,6 +4602,7 @@ int parse_device_cfg_web()
|
||||
char dev_type[64];
|
||||
char dev_key[255];
|
||||
char dev_series[255];
|
||||
char com_type[32];
|
||||
char addr_str[64];
|
||||
char port_char[64];
|
||||
|
||||
@@ -4400,6 +4632,8 @@ int parse_device_cfg_web()
|
||||
strncpy(dev_type, value->dev_type, sizeof(dev_type) - 1);
|
||||
strncpy(dev_key, value->dev_key, sizeof(dev_key) - 1);
|
||||
strncpy(dev_series, value->dev_series, sizeof(dev_series) - 1);
|
||||
strncpy(com_type, value->com_type, sizeof(com_type) - 1);
|
||||
com_type[sizeof(com_type) - 1] = '\0';
|
||||
strncpy(addr_str, value->addr_str, sizeof(addr_str) - 1);
|
||||
strncpy(port_char, value->port, sizeof(port_char) - 1);
|
||||
strncpy(processNo, value->processNo, sizeof(processNo) - 1);//进程号
|
||||
@@ -4465,6 +4699,14 @@ int parse_device_cfg_web()
|
||||
cout << "ied_usr->dev_type:" << ied_usr->dev_type << endl;
|
||||
}
|
||||
//lnk20250210台账进程号
|
||||
if (com_type != NULL && com_type[0] != '\0') {
|
||||
apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", com_type);//comType
|
||||
cout << "ied_usr->com_type:" << ied_usr->com_type << endl;
|
||||
}
|
||||
else {
|
||||
apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", "MMS");
|
||||
cout << "ied_usr->com_type(default):" << ied_usr->com_type << endl;
|
||||
}
|
||||
if (processNo != NULL) {
|
||||
apr_snprintf(ied_usr->processNo, sizeof(ied_usr->processNo), "%s", processNo);//processNo
|
||||
cout << "ied_usr->processNo:" << ied_usr->processNo << endl;
|
||||
@@ -4687,6 +4929,9 @@ int parse_device_cfg_web()
|
||||
|
||||
cout << "dev init create count:" << count_real;
|
||||
|
||||
if (pqdif_rebuild_config_from_current_ledger() != APR_SUCCESS)
|
||||
return APR_EGENERAL;
|
||||
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
catch (...)
|
||||
@@ -5734,6 +5979,13 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i
|
||||
apr_snprintf(ied_usr->dev_type, sizeof(ied_usr->dev_type), "%s", update[i].dev_type);
|
||||
printf("ied_usr->dev_type: %s\n", ied_usr->dev_type);
|
||||
}
|
||||
if (update[i].com_type != NULL && update[i].com_type[0] != '\0') {
|
||||
apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", update[i].com_type);
|
||||
printf("ied_usr->com_type: %s\n", ied_usr->com_type);
|
||||
} else {
|
||||
apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", "MMS");
|
||||
printf("ied_usr->com_type (default): %s\n", ied_usr->com_type);
|
||||
}
|
||||
if (update[i].processNo != NULL) {
|
||||
apr_snprintf(ied_usr->processNo, sizeof(ied_usr->processNo), "%s", update[i].processNo);
|
||||
printf("ied_usr->processNo: %s\n", ied_usr->processNo);
|
||||
@@ -6564,6 +6816,7 @@ void clearIedUsr(ied_usr_t *ied_usr) {
|
||||
memset(ied_usr->dev_type, 0, sizeof(ied_usr->dev_type));
|
||||
memset(ied_usr->dev_key, 0, sizeof(ied_usr->dev_key));
|
||||
memset(ied_usr->dev_series, 0, sizeof(ied_usr->dev_series));
|
||||
memset(ied_usr->com_type, 0, sizeof(ied_usr->com_type));
|
||||
memset(ied_usr->terminal_id, 0, sizeof(ied_usr->terminal_id));
|
||||
memset(ied_usr->org_name, 0, sizeof(ied_usr->org_name));
|
||||
memset(ied_usr->maint_name, 0, sizeof(ied_usr->maint_name));
|
||||
@@ -7290,6 +7543,8 @@ const char* get_front_msg_from_subdir() {
|
||||
return "实时数据进程";
|
||||
else if (std::strstr(subdir, "cfg_soe_comtrade") != NULL)
|
||||
return "暂态和告警进程";
|
||||
else if (std::strstr(subdir, "cfg_pqdif_data") != NULL)
|
||||
return "pqdif处理进程";
|
||||
else if (std::strstr(subdir, "cfg_recallhis_data") != NULL)
|
||||
return "稳态补招进程";
|
||||
else if (std::strstr(subdir, "cfg_stat_data") != NULL)
|
||||
|
||||
@@ -229,6 +229,8 @@ std::string get_front_type_from_subdir() {
|
||||
return "realTime";
|
||||
else if (std::strstr(subdir, "cfg_soe_comtrade") != NULL)
|
||||
return "comtrade";
|
||||
else if (std::strstr(subdir, "cfg_pqdif_data") != NULL)
|
||||
return "PQDIF";
|
||||
else if (std::strstr(subdir, "cfg_recallhis_data") != NULL)
|
||||
return "recall";
|
||||
else if (std::strstr(subdir, "cfg_stat_data") != NULL)
|
||||
|
||||
@@ -32,10 +32,12 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QMapIterator>
|
||||
#include <QStringList>
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
|
||||
// ★MOD: 全局追踪表:mp_id -> remaining times
|
||||
//全局追踪表:mp_id -> rpt_no -> remaining times
|
||||
static QMutex g_trace_mutex;
|
||||
static QHash<QString, int> g_trace_map;
|
||||
static QHash<QString, QHash<int, int> > g_trace_map;
|
||||
|
||||
///////////////////////////////////////////////////lnk2024-10-21////////////////////////////////////////////////////////
|
||||
extern void SendJsonAPI_web(const std::string& strUrl, const char* code, const std::string& json, char** ptr);
|
||||
@@ -258,36 +260,77 @@ static QString escape_json_string(const QString& s)
|
||||
return out;
|
||||
}
|
||||
|
||||
// 打开追踪:次数 times(比如 5)
|
||||
// 打开追踪:每个报告各追踪一次
|
||||
void process_trace_command(const std::string& id, int times)
|
||||
{
|
||||
if (times <= 0) return;
|
||||
(void)times;
|
||||
QString qid = QString::fromStdString(id).trimmed();
|
||||
if (qid.isEmpty()) return;
|
||||
|
||||
QList<int> rpt_nos;
|
||||
|
||||
QByteArray qid_bytes = qid.toLocal8Bit();
|
||||
|
||||
pthread_mutex_lock(&mtx);
|
||||
LD_info_t *ld_info = find_LD_info_only_from_mp_id(qid_bytes.data());
|
||||
if (ld_info != NULL && ld_info->rptinfo != NULL && ld_info->rptcount > 0) {
|
||||
for (int i = 0; i < ld_info->rptcount; ++i) {
|
||||
if (ld_info->rptinfo[i] == NULL)
|
||||
continue;
|
||||
|
||||
int rpt_no = ld_info->rptinfo[i]->rptNo;
|
||||
if (!rpt_nos.contains(rpt_no))
|
||||
rpt_nos.append(rpt_no);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mtx);
|
||||
|
||||
if (rpt_nos.isEmpty()) {
|
||||
cout << "[TRACE] mp_id=" << id << " has no report info" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QMutexLocker lk(&g_trace_mutex);
|
||||
g_trace_map[qid] = times; // 重新打开就覆盖/重置次数
|
||||
QHash<int, int>& rpt_map = g_trace_map[qid];
|
||||
for (int i = 0; i < rpt_nos.size(); ++i) {
|
||||
int rpt_no = rpt_nos.at(i);
|
||||
rpt_map[rpt_no] = 1;
|
||||
cout << "[TRACE] mp_id=" << id << " add rpt_no=" << rpt_no
|
||||
<< " left=" << rpt_map.value(rpt_no) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询是否要追踪
|
||||
static bool trace_is_enabled(const QString& mp_id)
|
||||
static bool trace_is_enabled(const QString& mp_id, int rpt_no)
|
||||
{
|
||||
QMutexLocker lk(&g_trace_mutex);
|
||||
auto it = g_trace_map.constFind(mp_id);
|
||||
return (it != g_trace_map.constEnd() && it.value() > 0);
|
||||
QHash<QString, QHash<int, int> >::const_iterator mp_it = g_trace_map.constFind(mp_id);
|
||||
if (mp_it == g_trace_map.constEnd())
|
||||
return false;
|
||||
|
||||
QHash<int, int>::const_iterator rpt_it = mp_it.value().constFind(rpt_no);
|
||||
return (rpt_it != mp_it.value().constEnd() && rpt_it.value() > 0);
|
||||
}
|
||||
|
||||
// 命中一次并扣减;扣到 0 自动删
|
||||
static void trace_hit_and_decrement(const QString& mp_id)
|
||||
static void trace_hit_and_decrement(const QString& mp_id, int rpt_no)
|
||||
{
|
||||
QMutexLocker lk(&g_trace_mutex);
|
||||
auto it = g_trace_map.find(mp_id);
|
||||
if (it == g_trace_map.end()) return;
|
||||
QHash<QString, QHash<int, int> >::iterator mp_it = g_trace_map.find(mp_id);
|
||||
if (mp_it == g_trace_map.end()) return;
|
||||
|
||||
int left = it.value();
|
||||
QHash<int, int>::iterator rpt_it = mp_it.value().find(rpt_no);
|
||||
if (rpt_it == mp_it.value().end()) return;
|
||||
|
||||
int left = rpt_it.value();
|
||||
left -= 1;
|
||||
if (left <= 0) g_trace_map.erase(it);
|
||||
else it.value() = left;
|
||||
if (left <= 0)
|
||||
mp_it.value().erase(rpt_it);
|
||||
else
|
||||
rpt_it.value() = left;
|
||||
|
||||
if (mp_it.value().isEmpty())
|
||||
g_trace_map.erase(mp_it);
|
||||
}
|
||||
|
||||
//追踪61850原始数据
|
||||
@@ -316,15 +359,20 @@ static QString build_mms_json_object(const json_block_data* data)
|
||||
return json;
|
||||
}
|
||||
|
||||
static QString build_trace_json(const json_block_data* data)
|
||||
static QString build_trace_json(const json_block_data* data, const char *v_wiring_type, const char *rpt_id, int rpt_no)
|
||||
{
|
||||
if (!data) return "{}";
|
||||
|
||||
QString mms_json = build_mms_json_object(data);
|
||||
QString wiring_type = v_wiring_type ? QString::fromLocal8Bit(v_wiring_type) : "";
|
||||
QString rpt = rpt_id ? QString::fromLocal8Bit(rpt_id) : "";
|
||||
|
||||
QString json;
|
||||
json += "{";
|
||||
json += QString("\"mp_id\":\"%1\",").arg(escape_json_string(data->mp_id));
|
||||
json += QString("\"v_wiring_type\":\"%1\",").arg(escape_json_string(wiring_type));
|
||||
json += QString("\"rpt_id\":\"%1\",").arg(escape_json_string(rpt));
|
||||
json += QString("\"rpt_no\":%1,").arg(rpt_no);
|
||||
json += QString("\"func_type\":%1,").arg(data->func_type);
|
||||
json += QString("\"data_time\":%1,").arg(QString::number((qlonglong)data->time));
|
||||
json += QString("\"voltage_level\":\"%1\",").arg(QString::number(data->voltage_level, 'f', 6));
|
||||
@@ -335,13 +383,13 @@ static QString build_trace_json(const json_block_data* data)
|
||||
return json;
|
||||
}
|
||||
|
||||
static void send_trace_if_needed(json_block_data* pdata)
|
||||
static void send_trace_if_needed(json_block_data* pdata, const char *v_wiring_type, const char *rpt_id, int rpt_no)
|
||||
{
|
||||
const QString mp_id_q = pdata->mp_id;
|
||||
if (trace_is_enabled(mp_id_q)) {
|
||||
if (trace_is_enabled(mp_id_q, rpt_no)) {
|
||||
|
||||
// 1) 组 json
|
||||
QString jsonText = build_trace_json(pdata);
|
||||
QString jsonText = build_trace_json(pdata, v_wiring_type, rpt_id, rpt_no);
|
||||
|
||||
// 2) 组 KafkaData
|
||||
Ckafka_data_t KafkaData;
|
||||
@@ -355,9 +403,25 @@ static void send_trace_if_needed(json_block_data* pdata)
|
||||
kafka_data_list_mutex.unlock();
|
||||
|
||||
// 3) 次数 -1
|
||||
trace_hit_and_decrement(mp_id_q);
|
||||
trace_hit_and_decrement(mp_id_q, rpt_no);
|
||||
}
|
||||
}
|
||||
|
||||
int trace_json_block_data(char v_wiring_type[], json_block_data *data, const char *rpt_id, int rpt_no)
|
||||
{
|
||||
send_trace_if_needed(data, v_wiring_type, rpt_id, rpt_no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int trace_json_is_enabled(const char *mp_id, int rpt_no)
|
||||
{
|
||||
QString mp_id_q = mp_id ? QString::fromLocal8Bit(mp_id).trimmed() : "";
|
||||
if (mp_id_q.isEmpty())
|
||||
return 0;
|
||||
|
||||
return trace_is_enabled(mp_id_q, rpt_no) ? 1 : 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////lnk20250710添加频率值存储
|
||||
struct mp_freq_save {
|
||||
double G_FREQ;
|
||||
@@ -1162,9 +1226,12 @@ void printCTopicList(const std::list<CTopic*>& ctopic_list) {
|
||||
val->fValue);
|
||||
}
|
||||
}
|
||||
break; // 只打印第一个 Item 的 SequenceList 和 DataValueList,避免输出过多
|
||||
}
|
||||
break; // 只打印第一个 Monitor 的 ItemList,避免输出过多
|
||||
}
|
||||
|
||||
|
||||
// 如果需要打印 SOEList,可加以下:
|
||||
/*
|
||||
int soeIndex = 0;
|
||||
@@ -1217,9 +1284,6 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
print_mms_str_map(data);
|
||||
}
|
||||
|
||||
//数据追踪上送
|
||||
send_trace_if_needed(data);
|
||||
|
||||
list<CTopic*> ctopic_list;
|
||||
|
||||
////lnk2024-8-15 区分星型,角型接线
|
||||
@@ -1562,7 +1626,9 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
kafka_data_list_mutex.unlock(); //解锁
|
||||
longjumpflag = true;
|
||||
}
|
||||
|
||||
else if (countflag < num && 0 != time_sec % 7200) {
|
||||
longjumpflag = true;//不发送数据
|
||||
}
|
||||
//lnk20260127
|
||||
if (typeofdata == false || data_have_static == false) {//不合并则处理完闪变就不处理其他数据,如果有统计数据或者数据类型区分了就继续处理其他数据
|
||||
if (longjumpflag == true || shortjumpflag == true) {
|
||||
@@ -2471,6 +2537,9 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
kafka_data_list_mutex.unlock(); //解锁
|
||||
longjumpflag = true;
|
||||
}
|
||||
else if (countflag < num && 0 != time_sec % 7200) {
|
||||
longjumpflag = true;//不发送数据
|
||||
}
|
||||
if (typeofdata == false || data_have_static == false) {//不合并则处理完闪变就不处理其他数据
|
||||
if (longjumpflag == true || shortjumpflag == true) {
|
||||
return 1;
|
||||
@@ -3758,4 +3827,3 @@ void Set_xml_nodeinfo_one(char* dev_type)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define THREE_SECS_DATA_BASE_NODE_ID 200 // 三秒数据、实时数据
|
||||
#define SOE_COMTRADE_BASE_NODE_ID 300 // soe 录波
|
||||
#define HIS_DATA_BASE_NODE_ID 400 //历史、补招
|
||||
#define PQDIF_DATA_BASE_NODE_ID 800 // pqdif数据
|
||||
|
||||
class json_block_data //json拼接参数类
|
||||
{
|
||||
@@ -74,6 +75,8 @@ public:
|
||||
};
|
||||
|
||||
int transfer_json_block_data(char v_wiring_type[], json_block_data* data);//lnk2024-8-16添加参数
|
||||
int trace_json_is_enabled(const char *mp_id, int rpt_no);
|
||||
int trace_json_block_data(char v_wiring_type[], json_block_data* data, const char *rpt_id, int rpt_no);
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
@@ -198,6 +198,7 @@ static QMap<int, QMap<int, QList<long long>>> real_data_report_map; //多个监
|
||||
static QMap<QString, json_block_data*> json_data_map;//CZY 2023-08-17 ww 2023年3月13日17:23:17扩展Map,用于保存各条线路的数据
|
||||
static QMap<QString, json_block_data*> json_flicker_data_map;//CZY 2023-09-11 展Map,用于保存各条线路的闪变数据
|
||||
static QMap<QString, json_block_data*> json_pst_data_map;//CZY 2023-09-11 展Map,用于保存各条线路的闪变数据
|
||||
static QMap<QString, json_block_data*> json_trace_data_map;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////lnk20260310文件控制
|
||||
pthread_mutex_t g_file_req_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
@@ -270,6 +271,8 @@ void add_comm_log(char* log_str)
|
||||
com_log_fn += "comm_300_comtrade.txt";
|
||||
else if (g_node_id == HIS_DATA_BASE_NODE_ID)
|
||||
com_log_fn += "comm_400_his.txt";
|
||||
else if (g_node_id == PQDIF_DATA_BASE_NODE_ID)
|
||||
com_log_fn += "comm_800_pqdif.txt";
|
||||
else if (g_node_id == NEW_HIS_DATA_BASE_NODE_ID) {
|
||||
com_log_fn.append(QString("comm_400_his_%1.txt").arg(g_front_seg_index));
|
||||
}
|
||||
@@ -1193,6 +1196,48 @@ void add_indent(std::stringstream& stream, int level) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_cfg_pqdif_process()
|
||||
{
|
||||
return std::strstr(subdir, "cfg_pqdif_data") != NULL;
|
||||
}
|
||||
|
||||
static bool is_pqdif_com_type(const char* com_type)
|
||||
{
|
||||
QString type = com_type ? QString::fromLocal8Bit(com_type).trimmed() : QString();
|
||||
return type.compare("PQDIF", Qt::CaseInsensitive) == 0;
|
||||
}
|
||||
|
||||
static void fill_terminal_com_type(terminal* tmnl, cJSON* item)
|
||||
{
|
||||
if (tmnl == NULL)
|
||||
return;
|
||||
|
||||
cJSON* comType = cJSON_GetObjectItem(item, "comType");
|
||||
if (comType == NULL)
|
||||
comType = cJSON_GetObjectItem(item, "com_type");
|
||||
|
||||
if (comType && comType->type == cJSON_String)
|
||||
std::strncpy(tmnl->com_type, comType->valuestring, sizeof(tmnl->com_type) - 1);
|
||||
else
|
||||
std::strncpy(tmnl->com_type, "MMS", sizeof(tmnl->com_type) - 1);
|
||||
|
||||
tmnl->com_type[sizeof(tmnl->com_type) - 1] = '\0';
|
||||
}
|
||||
|
||||
static bool terminal_update_should_write_file(const terminal* tmnl)
|
||||
{
|
||||
if (tmnl == NULL)
|
||||
return false;
|
||||
|
||||
if (is_pqdif_com_type(tmnl->com_type))
|
||||
return is_cfg_pqdif_process();
|
||||
|
||||
if (is_cfg_pqdif_process())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string prepare_update(const std::string& code_str, const terminal& json_data,const std::string& guid) //添加guid
|
||||
{
|
||||
std::cout << "prepare update" << std::endl;
|
||||
@@ -1264,6 +1309,9 @@ std::string prepare_update(const std::string& code_str, const terminal& json_dat
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<series>" << json_data.dev_series << "</series>" << std::endl;
|
||||
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<comType>" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "</comType>" << std::endl;
|
||||
|
||||
//lnk20250210
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<processNo>" << json_data.processNo << "</processNo>" << std::endl;
|
||||
@@ -1346,6 +1394,9 @@ std::string prepare_update(const std::string& code_str, const terminal& json_dat
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<id>" << json_data.terminal_id << "</id>" << std::endl;
|
||||
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<comType>" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "</comType>" << std::endl;
|
||||
|
||||
indentLevel--;
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "</terminalData>" << std::endl;
|
||||
@@ -1539,7 +1590,7 @@ int parse_log(const std::string& json_str) {
|
||||
}
|
||||
else if((level == "measurepoint") && (grade == "TRACE") && (!id.empty() && !is_blank(id))){ //数据追踪
|
||||
//打开监测点数据追踪开关
|
||||
process_trace_command(id,3); //3表示追踪次数
|
||||
process_trace_command(id,1); //每个报告各追踪1次
|
||||
}
|
||||
else{
|
||||
std::cout << "type doesnt match" <<std::endl;
|
||||
@@ -1624,7 +1675,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
std::string guid = guidstr->valuestring;
|
||||
|
||||
//进程号为0的进程处理所有台账更新消息
|
||||
if (process_No != g_front_seg_index && g_front_seg_index !=0) {
|
||||
if (!is_cfg_pqdif_process() && process_No != g_front_seg_index && g_front_seg_index !=0) {
|
||||
std::cout << "msg index:"<< process_No <<"doesnt match self index:" << g_front_seg_index << std::endl;
|
||||
cJSON_Delete(messageBody);
|
||||
cJSON_Delete(root);
|
||||
@@ -1653,6 +1704,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
cJSON* item = cJSON_GetArrayItem(data, i);
|
||||
|
||||
terminal json_data;
|
||||
memset(&json_data, 0, sizeof(json_data));
|
||||
// 填充 terminal_dev 的数据
|
||||
cJSON* id = cJSON_GetObjectItem(item, "id"); // terminal_id
|
||||
if (id && id->type == cJSON_String)
|
||||
@@ -1714,6 +1766,8 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
else
|
||||
std::strncpy(json_data.dev_series, "N/A", sizeof(json_data.dev_series) - 1);
|
||||
|
||||
fill_terminal_com_type(&json_data, item);
|
||||
|
||||
//lnk20250210台账进程号
|
||||
cJSON* processNo = cJSON_GetObjectItem(item, "processNo"); // processNo转为字符串
|
||||
if (processNo && processNo->type == cJSON_Number) snprintf(json_data.processNo, sizeof(json_data.processNo), "%d", processNo->valueint);
|
||||
@@ -1764,6 +1818,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
for (int j = 0; j < monitorData_size && j < 10; j++) { // 最多 10 个监测点
|
||||
cJSON* monitor_item = cJSON_GetArrayItem(monitorData, j);
|
||||
monitor monitor_data;
|
||||
memset(&monitor_data, 0, sizeof(monitor_data));
|
||||
|
||||
cJSON* monitor_id = cJSON_GetObjectItem(monitor_item, "id"); // monitor_id
|
||||
if (monitor_id && monitor_id->type == cJSON_String)
|
||||
@@ -1834,6 +1889,13 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
|
||||
print_terminal(&json_data);
|
||||
|
||||
if (!terminal_update_should_write_file(&json_data)) {
|
||||
std::cout << "skip ledger update by comType:" << json_data.com_type
|
||||
<< " terminal:" << json_data.terminal_id
|
||||
<< " process:" << subdir << g_front_seg_index << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 准备 XML 内容并写入文件
|
||||
std::string xmlContent = prepare_update(code_str, json_data,guid);//添加guid20250506
|
||||
if (xmlContent != "") {
|
||||
@@ -1867,7 +1929,17 @@ int parse_control(const std::string& json_str, const std::string& output_dir) {
|
||||
cJSON* id = cJSON_GetObjectItem(item, "id");
|
||||
if (id != nullptr) {
|
||||
terminal json_data;
|
||||
memset(&json_data, 0, sizeof(json_data));
|
||||
std::strncpy(json_data.terminal_id, cJSON_GetObjectItem(item, "id")->valuestring, sizeof(json_data.terminal_id) - 1);
|
||||
fill_terminal_com_type(&json_data, item);
|
||||
|
||||
if (!terminal_update_should_write_file(&json_data)) {
|
||||
std::cout << "skip delete ledger update by comType:" << json_data.com_type
|
||||
<< " terminal:" << json_data.terminal_id
|
||||
<< " process:" << subdir << g_front_seg_index << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 准备 XML 内容并写入文件
|
||||
std::string xmlContent = prepare_update(code_str, json_data,guid);//添加guid20250506
|
||||
if(xmlContent != ""){
|
||||
@@ -3633,6 +3705,119 @@ int json_block_create_data(char monid_char[], char* mms_str, double v, int flick
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static QString json_trace_block_key(char monid_char[], int flicker_flag, int rpt_no)
|
||||
{
|
||||
QString key;
|
||||
key.append(monid_char ? monid_char : "");
|
||||
key.append("|");
|
||||
key.append(QString::number(flicker_flag));
|
||||
key.append("|");
|
||||
key.append(QString::number(rpt_no));
|
||||
return key;
|
||||
}
|
||||
|
||||
static json_block_data* get_json_trace_block_data(char monid_char[], int flicker_flag, int rpt_no)
|
||||
{
|
||||
QString key = json_trace_block_key(monid_char, flicker_flag, rpt_no);
|
||||
if (!json_trace_data_map.contains(key))
|
||||
return NULL;
|
||||
return json_trace_data_map.value(key);
|
||||
}
|
||||
|
||||
static void init_json_trace_block_data(char monid_char[], char voltage_level[], int flicker_flag, int rpt_no)
|
||||
{
|
||||
QString key = json_trace_block_key(monid_char, flicker_flag, rpt_no);
|
||||
json_block_data* pdata = NULL;
|
||||
if (!json_trace_data_map.contains(key)) {
|
||||
pdata = new json_block_data();
|
||||
json_trace_data_map.insert(key, pdata);
|
||||
}
|
||||
|
||||
pdata = json_trace_data_map.value(key);
|
||||
pdata->monitorId = -1;
|
||||
pdata->func_type = g_node_id;
|
||||
pdata->flag = 0;
|
||||
pdata->time = 0;
|
||||
pdata->voltage_level = get_voltage_level(voltage_level);
|
||||
pdata->mp_id = monid_char ? QString::fromLocal8Bit(monid_char) : QString("not define");
|
||||
pdata->dev_type.clear();
|
||||
pdata->mms_str_map.clear();
|
||||
pdata->data_have_statistic = 0;
|
||||
}
|
||||
|
||||
int json_trace_block_create_start(char voltage_level[], char monid_char[], int flicker_flag, char temcode[], int line_id, char v_wiring_type[], char rpt_id[], int rpt_no)
|
||||
{
|
||||
(void)v_wiring_type;
|
||||
(void)rpt_id;
|
||||
if (!trace_json_is_enabled(monid_char, rpt_no))
|
||||
return 0;
|
||||
|
||||
try_start_kafka_thread();
|
||||
init_json_trace_block_data(monid_char, voltage_level, flicker_flag, rpt_no);
|
||||
|
||||
json_block_data* pdata = get_json_trace_block_data(monid_char, flicker_flag, rpt_no);
|
||||
if (pdata != NULL) {
|
||||
pdata->dev_type.append(temcode ? temcode : "");
|
||||
pdata->monitorId = line_id;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int json_trace_block_create_time(char monid_char[], long long Time, int flicker_flag, char rpt_id[], int rpt_no)
|
||||
{
|
||||
(void)rpt_id;
|
||||
json_block_data* pdata = get_json_trace_block_data(monid_char, flicker_flag, rpt_no);
|
||||
if (pdata == NULL)
|
||||
return 0;
|
||||
|
||||
pdata->time = Time;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int json_trace_block_create_flag(char monid_char[], int flag, int flicker_flag, char rpt_id[], int rpt_no)
|
||||
{
|
||||
(void)rpt_id;
|
||||
json_block_data* pdata = get_json_trace_block_data(monid_char, flicker_flag, rpt_no);
|
||||
if (pdata == NULL)
|
||||
return 0;
|
||||
|
||||
pdata->flag = flag;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int json_trace_block_create_data(char monid_char[], char* mms_str, double v, int flicker_flag, char rpt_id[], int rpt_no)
|
||||
{
|
||||
(void)rpt_id;
|
||||
json_block_data* pdata = get_json_trace_block_data(monid_char, flicker_flag, rpt_no);
|
||||
if (pdata == NULL)
|
||||
return 0;
|
||||
|
||||
pdata->mms_str_map.insert(QString::fromAscii(mms_str), v);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int json_trace_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag, char rpt_id[], int rpt_no)
|
||||
{
|
||||
QString key = json_trace_block_key(monid_char, flicker_flag, rpt_no);
|
||||
if (!json_trace_data_map.contains(key))
|
||||
return 1;
|
||||
|
||||
json_block_data* pdata = json_trace_data_map.value(key);
|
||||
if (pdata == NULL) {
|
||||
json_trace_data_map.remove(key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = 1;
|
||||
if (pdata->mms_str_map.count() > 0)
|
||||
ret = trace_json_block_data(v_wiring_type, pdata, rpt_id, rpt_no);
|
||||
|
||||
delete pdata;
|
||||
json_trace_data_map.remove(key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//lnk2024-8-16添加接线参数
|
||||
int json_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag)//WW 2023年3月13日16:38:41 多ICD修改
|
||||
@@ -3693,7 +3878,7 @@ int json_block_create_end(char v_wiring_type[], char monid_char[], int flicker_f
|
||||
json_pst_data_map.remove(monid_char);
|
||||
|
||||
}
|
||||
printf("---------- json_block_create_end: pdata->mms_str_map.count() == 0 ----------\n");
|
||||
printf("---------- json_block_create_end: mp_id= %s pdata->mms_str_map.count() == 0 ----------\n", monid_char);
|
||||
return 1;
|
||||
}
|
||||
//lnk2024-8-16添加接线参数
|
||||
|
||||
@@ -688,6 +688,7 @@ struct terminal // 终端台账
|
||||
char dev_type[64];
|
||||
char dev_key[255];
|
||||
char dev_series[255];
|
||||
char com_type[32];
|
||||
char processNo[64]; //lnk20250210进程号
|
||||
char addr_str[64];
|
||||
char port[64];
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define NEW_HIS_DATA_BASE_NODE_ID 500
|
||||
#define RECALL_HIS_DATA_BASE_NODE_ID 600
|
||||
#define RECALL_ALL_DATA_BASE_NODE_ID 700
|
||||
#define PQDIF_DATA_BASE_NODE_ID 800
|
||||
|
||||
#define REPORT_TYPE_STAT 1
|
||||
#define REPORT_TYPE_REAL 2
|
||||
@@ -74,6 +75,12 @@ int json_block_create_data(char monid_char[], char* mms_str , double v, int flic
|
||||
//lnk2024-8-16添加参数
|
||||
int json_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag); //CZY 2023-08-17 测试
|
||||
|
||||
int json_trace_block_create_start(char voltage_level[], char monid_char[], int flicker_flag, char temcode[], int line_id, char v_wiring_type[], char rpt_id[], int rpt_no);
|
||||
int json_trace_block_create_time(char monid_char[], long long Time, int flicker_flag, char rpt_id[], int rpt_no);
|
||||
int json_trace_block_create_flag(char monid_char[], int flag, int flicker_flag, char rpt_id[], int rpt_no);
|
||||
int json_trace_block_create_data(char monid_char[], char* mms_str, double v, int flicker_flag, char rpt_id[], int rpt_no);
|
||||
int json_trace_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag, char rpt_id[], int rpt_no);
|
||||
|
||||
//zw 2024-01-31 补招模式优化
|
||||
void add_mvl_type_ctrl(char doname[], int ctrl);
|
||||
int sel_mvl_type_ctrl_flag(char doname[]);
|
||||
|
||||
@@ -81,6 +81,8 @@ void init_global_function_enable()
|
||||
three_secs_enabled = 1;
|
||||
}else if (strcmp(subdir,"cfg_soe_comtrade")==0) { //告警和录波和暂态
|
||||
g_node_id = SOE_COMTRADE_BASE_NODE_ID;
|
||||
}else if (strcmp(subdir,"cfg_pqdif_data")==0) {
|
||||
g_node_id = PQDIF_DATA_BASE_NODE_ID;
|
||||
}else if (strcmp(subdir,"cfg_his_data")==0) { //不使用
|
||||
g_node_id = RECALL_ALL_DATA_BASE_NODE_ID;
|
||||
g_node_id = HIS_DATA_BASE_NODE_ID;
|
||||
|
||||
1058
mms/mms_process.c
1058
mms/mms_process.c
File diff suppressed because it is too large
Load Diff
@@ -993,6 +993,7 @@ ST_VOID u_iec_rpt_ind_data_by_devtype(MVL_VAR_ASSOC** info_va,
|
||||
ied = find_ied_from_dev_code(LD_info->terminal_code);
|
||||
|
||||
ied_usr_t* ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
json_trace_block_create_start(LD_info->voltage_level, LD_info->mp_id, rptinfo->flickerflag, ied_usr->dev_type, LD_info->line_id, LD_info->v_wiring_type, rcb_info->RptID, rptinfo->rptNo);
|
||||
|
||||
if (rptinfo->flickerflag==1)//CZY 2023-08-17 WW 2022-11-14 只有闪变和第一次进入才会初始化 json_block_create_start(LD_info->line_id);
|
||||
json_block_create_start( LD_info->voltage_level, LD_info->mp_id, rptinfo->flickerflag, ied_usr->dev_type, LD_info->line_id);
|
||||
@@ -1057,6 +1058,7 @@ ST_VOID u_iec_rpt_ind_data_by_devtype(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
json_block_create_flag(LD_info->mp_id, flag, rptinfo->flickerflag);
|
||||
json_trace_block_create_flag(LD_info->mp_id, flag, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
not_set_rpt_q_this = FALSE;
|
||||
}
|
||||
}
|
||||
@@ -1076,6 +1078,7 @@ ST_VOID u_iec_rpt_ind_data_by_devtype(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
json_block_create_time(LD_info->mp_id, t / 1000, rptinfo->flickerflag);
|
||||
json_trace_block_create_time(LD_info->mp_id, t / 1000, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
printf("rcb_info->RptID=%s ,LineId=%d , Timestamp= %lld \n", rcb_info->RptID, LD_info->line_id, t / 1000);
|
||||
not_set_rpt_TimeID_this = FALSE;
|
||||
/*if (strstr(rcb_info->RptID, "LLN0$RP$urcbRealData")) {//lnk 20250624
|
||||
@@ -1108,8 +1111,10 @@ ST_VOID u_iec_rpt_ind_data_by_devtype(MVL_VAR_ASSOC** info_va,
|
||||
else if (strstr(rcb_info->RptID, "RDRE")) {//CZY 2023-08-17 WW 2022-11-14 修改判断LLN0$BR$brcbRDRE
|
||||
processRDRE_data(LD_info, FULL_FCDA_Name, v);
|
||||
}
|
||||
else
|
||||
else {
|
||||
json_block_create_data(LD_info->mp_id, FULL_FCDA_Name, v, rptinfo->flickerflag);
|
||||
json_trace_block_create_data(LD_info->mp_id, FULL_FCDA_Name, v, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
}
|
||||
}//else
|
||||
}
|
||||
}
|
||||
@@ -1126,6 +1131,7 @@ ST_VOID u_iec_rpt_ind_data_by_devtype(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
printf("%d : %d", LD_info->rptRecvFlag, LD_info->rptRecvCheckFlag);
|
||||
json_trace_block_create_end(LD_info->v_wiring_type, LD_info->mp_id, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
//append_db_records(RPT_IDX);
|
||||
if (rptinfo->flickerflag==1)//CZY 2023-08-17 WW 2022-11-14 增加闪变标志
|
||||
{
|
||||
@@ -1376,6 +1382,7 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
ied = find_ied_from_dev_code(LD_info->terminal_code);
|
||||
|
||||
ied_usr_t* ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
json_trace_block_create_start(LD_info->voltage_level, LD_info->mp_id, rptinfo->flickerflag, ied_usr->dev_type, LD_info->line_id, LD_info->v_wiring_type, rcb_info->RptID, rptinfo->rptNo);
|
||||
if (rptinfo->flickerflag == 1)//CZY 2023-08-17 WW 2022-11-14 只有闪变和第一次进入才会初始化 json_block_create_start(LD_info->line_id);
|
||||
json_block_create_start(LD_info->voltage_level, LD_info->mp_id, rptinfo->flickerflag, ied_usr->dev_type, LD_info->line_id);
|
||||
else if (rptinfo->flickerflag == 0) {
|
||||
@@ -1461,6 +1468,7 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
json_block_create_flag(LD_info->mp_id, flag, rptinfo->flickerflag);
|
||||
json_trace_block_create_flag(LD_info->mp_id, flag, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
not_set_rpt_q_this = FALSE;
|
||||
}
|
||||
}
|
||||
@@ -1484,6 +1492,7 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
json_block_create_time(LD_info->mp_id, t / 1000, rptinfo->flickerflag);
|
||||
json_trace_block_create_time(LD_info->mp_id, t / 1000, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
printf("rcb_info->RptID=%s ,LineId=%d , Timestamp= %lld \n", rcb_info->RptID, LD_info->line_id, t / 1000);
|
||||
not_set_rpt_TimeID_this = FALSE;
|
||||
//if (strstr(rcb_info->RptID, "LLN0$RP$urcbRealData")) {
|
||||
@@ -1497,6 +1506,7 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
printf("rtdata RptID match");
|
||||
if (urcbRealDataHasReceived(ied_usr->dev_idx,rpt_no,LD_info, t / 1000)){//判断时间重复
|
||||
printf("this rt report Time repeats");
|
||||
//json_trace_block_create_end(LD_info->v_wiring_type, LD_info->mp_id, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1531,8 +1541,10 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
ied_usr_t* ied_usr = GET_IEDEXT_ADDR(ied);
|
||||
processGGIO_start_data_end(LD_info->mp_id, FULL_FCDA_Name, v, time, ied_usr->dev_type, LD_info->line_id);//GGIO数据全套处理流程
|
||||
}
|
||||
else
|
||||
else {
|
||||
json_block_create_data(LD_info->mp_id, FULL_FCDA_Name, v, rptinfo->flickerflag);
|
||||
json_trace_block_create_data(LD_info->mp_id, FULL_FCDA_Name, v, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
}
|
||||
}//else
|
||||
}
|
||||
|
||||
@@ -1550,6 +1562,7 @@ ST_VOID u_iec_rpt_ind_data(MVL_VAR_ASSOC** info_va,
|
||||
}
|
||||
else {
|
||||
printf("%d : %d", LD_info->rptRecvFlag, LD_info->rptRecvCheckFlag);
|
||||
json_trace_block_create_end(LD_info->v_wiring_type, LD_info->mp_id, rptinfo->flickerflag, rcb_info->RptID, rptinfo->rptNo);
|
||||
//append_db_records(RPT_IDX);
|
||||
if (rptinfo->flickerflag == 1)//CZY 2023-08-17 WW 2022-11-14 增加闪变标志
|
||||
{
|
||||
|
||||
@@ -205,6 +205,7 @@ apr_status_t init_rdb()
|
||||
//台账读取过后初始化各级的日志
|
||||
init_loggers();
|
||||
|
||||
if (g_node_id != PQDIF_DATA_BASE_NODE_ID) {
|
||||
rv = parse_model_cfg_web();
|
||||
if (rv != APR_SUCCESS) {//不可能
|
||||
echo_errg("Parsed model with error,try to run! \n");
|
||||
@@ -228,6 +229,10 @@ apr_status_t init_rdb()
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("[PQDIF] skip model xml and report init in init_rdb\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (app_get_private_config(g_my_conf_fname) != APR_SUCCESS) {
|
||||
echo_errg("Failed when processing private configuration\n");
|
||||
@@ -311,6 +316,9 @@ apr_status_t run_protocol()
|
||||
else if (g_node_id == SOE_COMTRADE_BASE_NODE_ID) {//暂态录波
|
||||
ServerPort = SOCKET_PORT + SOE_COMTRADE_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
else if (g_node_id == PQDIF_DATA_BASE_NODE_ID) {
|
||||
ServerPort = SOCKET_PORT + PQDIF_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
|
||||
struct sockaddr_in server_sockaddr;
|
||||
memset(&server_sockaddr, 0, sizeof(server_sockaddr));
|
||||
@@ -351,6 +359,9 @@ apr_status_t run_protocol()
|
||||
else if (g_node_id == SOE_COMTRADE_BASE_NODE_ID) {//暂态录波
|
||||
HTTP_PORT = HTTP_PORT + SOE_COMTRADE_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
else if (g_node_id == PQDIF_DATA_BASE_NODE_ID) {
|
||||
HTTP_PORT = HTTP_PORT + PQDIF_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
printf("try_start_web_http_thread \n");
|
||||
try_start_web_http_thread();
|
||||
printf("try_start_http_thread \n");
|
||||
|
||||
@@ -337,6 +337,7 @@ struct ied_usr_t{
|
||||
char dev_type[256]; /**< 设备类型 */
|
||||
char dev_key[256]; /**< 设备秘钥 */
|
||||
char dev_series[256]; /**< 设备识别码 */
|
||||
char com_type[32]; /**< 通讯类型 mms/pqdif */
|
||||
int dev_flag; /**< 设备标志 */
|
||||
void *cookie;
|
||||
double last_call_wavelist_time ; //上次召录波列表时间
|
||||
@@ -502,6 +503,7 @@ int stringToInt(const char* str, int* result);
|
||||
bool isCharPtrEmpty(const char* str);
|
||||
int parse_ledger_update_xml(trigger_update_xml_t* trigger_update_xml);
|
||||
int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_index,int ied_take);
|
||||
int pqdif_rebuild_config_from_current_ledger();
|
||||
void print_trigger_update_xml(const trigger_update_xml_t* trigger_update);
|
||||
char* parse_model_cfg_web_one(ied_t* ied,char* out_model);
|
||||
void Set_xml_nodeinfo_one(char* dev_type);
|
||||
|
||||
@@ -329,6 +329,7 @@ handle_reset() {
|
||||
sed -i '/cfg_recallhis_data/d' /FeProject/etc/runtime.cf
|
||||
sed -i '/cfg_3s_data/d' /FeProject/etc/runtime.cf
|
||||
sed -i '/cfg_soe_comtrade/d' /FeProject/etc/runtime.cf
|
||||
sed -i '/cfg_pqdif_data/d' /FeProject/etc/runtime.cf
|
||||
sed -i '/fe_watchdog/d' /FeProject/etc/runtime.cf
|
||||
|
||||
# 根据进程号添加对应进程配置
|
||||
@@ -340,6 +341,7 @@ handle_reset() {
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_recallhis_data -s 1_1^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_3s_data^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_soe_comtrade^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_pqdif_data^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
|
||||
else
|
||||
#看门狗固定放在第一个,防止stop时会把要杀死的进程重启
|
||||
@@ -353,6 +355,7 @@ handle_reset() {
|
||||
#以下部分没有多进程
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_3s_data^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_soe_comtrade^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
sed -i "2a\\$(printf '/FeProject/bin/ ^ pt61850netd_pqfe -d cfg_pqdif_data^ ^ ^ 1 ^ ^\n')" /FeProject/etc/runtime.cf
|
||||
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user