添加错误映射文件的处理防止崩溃,优化mq处理topic前缀,添加空指针预防
This commit is contained in:
@@ -267,6 +267,23 @@ void RocketMQConsumer::subscribe(const std::string& topic, const std::string& ta
|
||||
// 使用 std::pair 作为键
|
||||
std::pair<std::string, std::string> mapKey(topic, tag);
|
||||
callbacks_[mapKey] = callback;
|
||||
|
||||
//冀北添加,其他地方也通用
|
||||
// 如果带 MQ_INST_xxx% 前缀,再注册一个短topic
|
||||
size_t pos = topic.find('%');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string shortTopic = topic.substr(pos + 1);
|
||||
|
||||
callbacks_[std::make_pair(shortTopic, tag)] = callback;
|
||||
|
||||
std::cout << "[CALLBACK_ALIAS] "
|
||||
<< topic
|
||||
<< " -> "
|
||||
<< shortTopic
|
||||
<< ", tag=" << tag
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
/*
|
||||
// 静态消息处理回调实现
|
||||
@@ -513,6 +530,8 @@ public:
|
||||
//SetProducerMaxMessageSize(producer_, 1024 * 1024); // 1MB
|
||||
producer_.setMaxMessageSize(1024 * 1024);
|
||||
|
||||
producer_.setSendMsgTimeout(3000);//添加超时防阻塞
|
||||
|
||||
//SetProducerSessionCredentials(producer_, G_MQCONSUMER_ACCESSKEY.c_str(),G_MQCONSUMER_SECRETKEY.c_str(), "");
|
||||
producer_.setSessionCredentials(
|
||||
G_MQCONSUMER_ACCESSKEY,
|
||||
|
||||
@@ -1527,8 +1527,8 @@ int parse_rpt_log_ini()
|
||||
|
||||
}
|
||||
|
||||
for (cpuno = 0; cpuno < ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
for (cpuno = 0; cpuno < ied->cpucount; cpuno++) {//遍历所有测点,但是某些测点可能为空,台账初始化时ied->cpucount取的是测点号
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);//测点号从1开始,cpuno从0开始,所以ied_usr->LD_info[cpuno]对应测点号为cpuno+1,注意台账初始化时ied_usr->LD_info数组的大小是按照测点总数分配的,所以有些测点号可能没有对应的LD_info,添加判断防止崩溃
|
||||
//char str[256]; //256大小
|
||||
char* tmp = Get_IED(ied_usr->dev_type);
|
||||
if(tmp == NULL){std::cerr << "front read ied config error!" << std::endl;continue;}
|
||||
@@ -1542,10 +1542,21 @@ int parse_rpt_log_ini()
|
||||
//调试用
|
||||
printf("%s使用内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno, (void*)ied_usr->LD_info[cpuno].LD_name);
|
||||
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
//添加判断,比如有的监测点没有cpuno为2,直接申请了LD_info[1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){ //空说明台账初始化没申请空间
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
|
||||
//添加默认值,防止崩溃20260601
|
||||
LD_info->rptcount = 0;
|
||||
LD_info->logcount = 0;
|
||||
LD_info->cpuno = 0;
|
||||
LD_info->LD_name = NULL;
|
||||
LD_info->rptinfo = NULL;
|
||||
LD_info->loginfo = NULL;
|
||||
|
||||
delete[] tmp;//释放内存
|
||||
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
@@ -1559,7 +1570,19 @@ int parse_rpt_log_ini()
|
||||
|
||||
apr_snprintf(buf, sizeof(buf), "%s", rpt_cfg_strlists[type]->at(i).toAscii().constData());
|
||||
|
||||
fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
//fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
int ret = fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
if (ret != 0) {
|
||||
printf("[RPT_INIT][ERROR] fill_rptctrl_by_cfg failed dev=%s cpu=%d rpt=%d cfg=%s\n",
|
||||
ied_usr->terminal_id, cpuno, i, buf);
|
||||
|
||||
DIY_ERRORLOG_CODE(ied_usr->terminal_id,1,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点的第%d个报告配置解析失败,请检查报告配置格式是否正确",ied_usr->terminal_id, cpuno + 1, i + 1);
|
||||
|
||||
if (LD_info->rptinfo && LD_info->rptinfo[i]) {
|
||||
LD_info->rptinfo[i]->rptID = NULL;
|
||||
LD_info->rptinfo[i]->LD_info = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3011,6 +3034,10 @@ void Cout_account_information() {
|
||||
add_comm_log(const_cast<char*>(text.toLocal8Bit().constData()));
|
||||
for (cpuno = 0; cpuno < ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
if (LD_info->cpuno == 0 || LD_info->LD_name == NULL)
|
||||
continue;
|
||||
|
||||
QString text2;//待组装的pgsql语句
|
||||
text2.append(QString("mp_id: \"%1\" terminal_code:\"%2\" ").arg(LD_info->mp_id).arg(LD_info->terminal_code));
|
||||
add_comm_log(const_cast<char*>(text2.toLocal8Bit().constData()));
|
||||
@@ -4526,7 +4553,7 @@ int parse_device_cfg_web()
|
||||
//otl_datetime timestamp;
|
||||
int monitor_log_level = 1;//监测点日志等级
|
||||
//for (int j = 0; j < 10; ++j) { // 假设最多有10个监测点
|
||||
for (int j = 0; value->line[j].monitor_id[0] != '\0'; ++j){
|
||||
for (int j = 0; value->line[j].monitor_id[0] != '\0'; ++j){//只看有测点号的监测点,避免访问无效数据
|
||||
ledger_monitor& monitor = value->line[j];
|
||||
// 检查监测点 ID 是否为空以避免访问无效数据
|
||||
/*if (monitor.monitor_id[0] != '\0') {
|
||||
@@ -4548,27 +4575,33 @@ int parse_device_cfg_web()
|
||||
strncpy(monitor_status, monitor.status, sizeof(monitor_status) - 1);//添加监测点状态
|
||||
monitor_log_level = monitor.log_level;//监测点日志等级
|
||||
//监测点台账处理
|
||||
count_real_monitor++;
|
||||
memset(&line_info, 0, sizeof(line_info));
|
||||
line_info.line_id = count_real_monitor; //监测点排号
|
||||
count_real_monitor++;//初始为0,进入一次+1,有效监测点排号从1开始
|
||||
memset(&line_info, 0, sizeof(line_info));//有效测点的初始化
|
||||
|
||||
line_info.line_id = count_real_monitor; //监测点排号,前置本地使用
|
||||
cout << "line_id:" << line_info.line_id << endl;
|
||||
strcpy(line_info.mp_id, monitor_id);
|
||||
|
||||
strcpy(line_info.mp_id, monitor_id);//测点id
|
||||
cout << "mp_id:" << line_info.mp_id << endl;
|
||||
|
||||
strcpy(line_info.terminal_code, terminal_code); //从上级获取的终端号
|
||||
cout << "terminal_code:" << line_info.terminal_code << endl;
|
||||
|
||||
if (isCharPtrEmpty(logical_device_seq)) {
|
||||
line_info.cpuno = 1; //默认监测点实例号1
|
||||
cout << "logical_device_seq:is null,set cpuno:"<< line_info.cpuno << endl;
|
||||
}
|
||||
else {
|
||||
line_info.cpuno = std::atoi(logical_device_seq);
|
||||
line_info.cpuno = std::atoi(logical_device_seq); //台账实例号,即台账的测点号
|
||||
cout << "logical_device_seq:"<< line_info.cpuno << endl;
|
||||
}
|
||||
//cout << "cpuno:" << line_info.cpuno << endl;
|
||||
strcpy(line_info.voltage_level, voltage_level);
|
||||
strcpy(line_info.voltage_level, voltage_level);//电压等级
|
||||
cout << "voltage_level:" << line_info.voltage_level << endl;
|
||||
strcpy(line_info.v_wiring_type, terminal_connect);
|
||||
|
||||
strcpy(line_info.v_wiring_type, terminal_connect);//接线方式
|
||||
cout << "v_wiring_type:" << line_info.v_wiring_type << endl;
|
||||
|
||||
//lnk2024-8-14记录接线标志
|
||||
if (strcmp(line_info.v_wiring_type, "0") != 0)
|
||||
{
|
||||
@@ -4576,7 +4609,7 @@ int parse_device_cfg_web()
|
||||
cout << "monitor_id" << monitor_id << "v_wiring_type:" << line_info.v_wiring_type << "is delta wiring:" << isdelta_flag << endl;
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_LEDGER,"【WARN】前置连接的监测点 %s 是角形接线,对应终端为%s 终端类型是%s",line_info.mp_id,ied_usr->terminal_id,ied_usr->dev_type);
|
||||
}
|
||||
strcpy(line_info.monitor_status, monitor_status);
|
||||
strcpy(line_info.monitor_status, monitor_status);//测点状态
|
||||
cout << "monitor_status:" << line_info.monitor_status << endl;
|
||||
//// 构造struct tm对象
|
||||
struct tm timeinfo;
|
||||
@@ -4587,27 +4620,32 @@ int parse_device_cfg_web()
|
||||
timeinfo.tm_min = timestamp.minute;
|
||||
timeinfo.tm_sec = timestamp.second;
|
||||
time_t time = std::mktime(&timeinfo);
|
||||
line_info.time = static_cast<long long>(time);
|
||||
line_info.time = static_cast<long long>(time);//测点更新时间
|
||||
cout << "time:" << line_info.time << endl;
|
||||
strcpy(line_info.name, monitor_name);
|
||||
|
||||
strcpy(line_info.name, monitor_name);//测点名
|
||||
cout << "name:" << line_info.name << endl;
|
||||
|
||||
line_info.read_flag = ENABLE; //监测点有效
|
||||
|
||||
line_info.log_level = monitor_log_level; //监测点日志等级
|
||||
cout << "log_level_monitor:" << line_info.log_level << endl;
|
||||
|
||||
//ied = find_ied_from_dev_code(line_info.terminal_code); //不需要再找上级终端了,已经在终端里了
|
||||
if (ied && ied->usr_ext && line_info.cpuno && (static_cast<int>(line_info.cpuno) < 10)) {
|
||||
if (ied && ied->usr_ext && line_info.cpuno && (static_cast<int>(line_info.cpuno) < 10)) {//台账测点号有效
|
||||
char str[256]; //256大小
|
||||
byte_t cpuno = line_info.cpuno;
|
||||
byte_t cpuno = line_info.cpuno; //台账的测点号
|
||||
cout << "cpuno:" << (int)line_info.cpuno << endl;
|
||||
cout << "index cpuno:" << cpuno-1 << endl;
|
||||
|
||||
ied_usr = (ied_usr_t*)ied->usr_ext;
|
||||
ied_usr->LD_info[cpuno - 1] = line_info; //cpuno默认是1
|
||||
ied_usr->LD_info[cpuno - 1].ied = ied;
|
||||
ied_usr->LD_info[cpuno - 1].ied = ied; //父级指针绑定
|
||||
apr_snprintf(str, sizeof(str), "PQMonitorPQM%d", cpuno);//将监测点逻辑号转为PQMonitorPQM+逻辑号
|
||||
//lnk20250208不使用apr_pstrdup,后续直接复用
|
||||
//ied_usr->LD_info[cpuno - 1].LD_name = apr_pstrdup(g_init_pool, str);//将 str 中的格式化字符串复制到内存池 g_init_pool 中。ied_usr->LD_info[cpuno - 1].LD_name 存储了这个字符串的副本,LD_name 现在是 PQMonitorPQM{cpuno} 的形式。
|
||||
// 从 g_init_pool 内存池中分配固定 256 字节的内存
|
||||
ied_usr->LD_info[cpuno - 1].LD_name = (char *)apr_palloc(g_init_pool, 256);
|
||||
ied_usr->LD_info[cpuno - 1].LD_name = (char *)apr_palloc(g_init_pool, 256);//根据台账中的测点号申请内存
|
||||
//调试用,申请的地址
|
||||
printf("%s分配内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno - 1, (void*)ied_usr->LD_info[cpuno - 1].LD_name);
|
||||
// 清空内存,防止残留数据
|
||||
@@ -4618,21 +4656,21 @@ int parse_device_cfg_web()
|
||||
//这里申请的空间基于ied的数量,挂载到ied上
|
||||
ied_usr->LD_info[cpuno - 1].ht_fcd = apr_hash_make(g_init_pool); //这两行代码分别为 ied_usr->LD_info[cpuno - 1] 的两个成员(ht_fcd 和 ht_full_fcda)创建了空的哈希表。apr_hash_make(g_init_pool) 会在 g_init_pool 内存池中为这两个哈希表分配内存空间
|
||||
ied_usr->LD_info[cpuno - 1].ht_full_fcda = apr_hash_make(g_init_pool);//它们的 key 值和 value 在后续的代码中可能会被填充
|
||||
ied_usr->LD_info[cpuno - 1].rptcount = 0;
|
||||
ied_usr->LD_info[cpuno - 1].rptcount = 0;//有效测点报告数为初始为0
|
||||
cout << "rptcount:" << ied_usr->LD_info[cpuno - 1].rptcount << endl;
|
||||
if (cpuno > ied->cpucount) {
|
||||
ied->cpucount = cpuno;
|
||||
if (cpuno > ied->cpucount) {//测点号大于测点数
|
||||
ied->cpucount = cpuno;//取测点号,后续遍历测点时需要跳过无效测点
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (count_real < count_cfg){
|
||||
if (count_real < count_cfg){//读取计数器和台账数量对比,如果读取的数量小于台账数量,说明有些台账读取失败了,按照读取的数量来设置进程的台账数量,避免后续访问读取失败的台账导致崩溃
|
||||
g_node->n_clients = count_real;
|
||||
}
|
||||
|
||||
if (count_cfg != count_real){
|
||||
if (count_cfg != count_real){//应该相等,如果不相等说明有些台账读取失败了,按照读取的数量来设置进程的台账数量,避免后续访问读取失败的台账导致崩溃
|
||||
return APR_EBADF;
|
||||
}
|
||||
|
||||
@@ -6169,10 +6207,22 @@ int parse_rpt_log_ini_one(ied_t* ied)
|
||||
|
||||
//调试
|
||||
printf("%s使用内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno, (void*)ied_usr->LD_info[cpuno].LD_name);
|
||||
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[2-1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点无法初始化报告,这个装置的台账存在缺失,请检查装置台账的监测点总数和各监测点的序号",ied_usr->terminal_id,cpuno + 1);
|
||||
|
||||
//添加默认值,防止崩溃20260601
|
||||
LD_info->rptcount = 0;
|
||||
LD_info->logcount = 0;
|
||||
LD_info->cpuno = 0;
|
||||
LD_info->LD_name = NULL;
|
||||
LD_info->rptinfo = NULL;
|
||||
LD_info->loginfo = NULL;
|
||||
|
||||
delete[] tmp;//Get_IED中分配了内存,使用后删除
|
||||
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
@@ -6191,7 +6241,18 @@ int parse_rpt_log_ini_one(ied_t* ied)
|
||||
init_rptctrl_by_count(LD_info, rpt_cfg_strlists[type]->size());
|
||||
for (int i = 0; i < rpt_cfg_strlists[type]->size(); ++i) {
|
||||
apr_snprintf(buf, sizeof(buf), "%s", rpt_cfg_strlists[type]->at(i).toAscii().constData());
|
||||
fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
//fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
int ret = fill_rptctrl_by_cfg(LD_info, i, buf);
|
||||
if (ret != 0) {
|
||||
printf("[RPT_INIT][ERROR] fill_rptctrl_by_cfg failed dev=%s cpu=%d rpt=%d cfg=%s\n",
|
||||
ied_usr->terminal_id, cpuno, i, buf);
|
||||
DIY_ERRORLOG_CODE(ied_usr->terminal_id,1,LOG_CODE_RPTINIT,"【ERROR】终端%s的监测点序号为%d的监测点的第%d个报告配置解析失败,请检查报告配置格式是否正确",ied_usr->terminal_id, cpuno + 1, i + 1);
|
||||
|
||||
if (LD_info->rptinfo && LD_info->rptinfo[i]) {
|
||||
LD_info->rptinfo[i]->rptID = NULL;
|
||||
LD_info->rptinfo[i]->LD_info = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
//初始化监测点的日志控制
|
||||
init_logctrl_by_count(LD_info, log_cfg_strlists[type]->size());
|
||||
|
||||
@@ -3109,9 +3109,9 @@ char* Get_IED(char* devtype)
|
||||
}
|
||||
|
||||
QString ied;
|
||||
ied.append(xmlinfo_list[type]->xmlcfg.IEDname); // 从配置文件读取的终端名
|
||||
ied.append(xmlinfo_list[type]->xmlcfg.LDevicePrefix); //// 从配置文件读取的监测点名
|
||||
ied.append("%d");
|
||||
ied.append(xmlinfo_list[type]->xmlcfg.IEDname); // 从配置文件读取的终端名PQ
|
||||
ied.append(xmlinfo_list[type]->xmlcfg.LDevicePrefix); //// 从配置文件读取的监测点名PQM
|
||||
ied.append("%d");//最后构成PQPQM1
|
||||
|
||||
QByteArray byteArray = ied.toLocal8Bit();
|
||||
|
||||
|
||||
@@ -334,65 +334,83 @@ void add_stat_kafka_json_log(char* log_str)
|
||||
/*新增rocketmq发送数据lnk10-10*/
|
||||
void my_rocketmq_send(Ckafka_data_t& data)
|
||||
{
|
||||
static std::string topic;
|
||||
static std::string cfg_His_tp;
|
||||
static std::string cfg_PLT_tp;
|
||||
static std::string cfg_PST_tp;
|
||||
static std::string cfg_Evt_tp;
|
||||
static std::string cfg_Alm_tp;
|
||||
static std::string cfg_Rt_tp;
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
try{
|
||||
static std::string topic;
|
||||
static std::string cfg_His_tp;
|
||||
static std::string cfg_PLT_tp;
|
||||
static std::string cfg_PST_tp;
|
||||
static std::string cfg_Evt_tp;
|
||||
static std::string cfg_Alm_tp;
|
||||
static std::string cfg_Rt_tp;
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
|
||||
cfg_His_tp = TOPIC_STAT;
|
||||
cfg_PLT_tp = TOPIC_PLT;
|
||||
cfg_PST_tp = TOPIC_PST;
|
||||
cfg_Evt_tp = TOPIC_EVENT;
|
||||
cfg_Alm_tp = TOPIC_ALARM;
|
||||
cfg_Rt_tp = TOPIC_RTDATA;
|
||||
cfg_His_tp = TOPIC_STAT;
|
||||
cfg_PLT_tp = TOPIC_PLT;
|
||||
cfg_PST_tp = TOPIC_PST;
|
||||
cfg_Evt_tp = TOPIC_EVENT;
|
||||
cfg_Alm_tp = TOPIC_ALARM;
|
||||
cfg_Rt_tp = TOPIC_RTDATA;
|
||||
|
||||
init = true;
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
std::string key = data.mp_id.toStdString();
|
||||
std::string senddata = data.strText.toStdString();
|
||||
if (data.strTopic == "HISDATA")
|
||||
{
|
||||
topic = cfg_His_tp;
|
||||
}
|
||||
else if (data.strTopic == "PLT")
|
||||
std::string key = data.mp_id.toStdString();
|
||||
std::string senddata = data.strText.toStdString();
|
||||
if (data.strTopic == "HISDATA")
|
||||
{
|
||||
topic = cfg_His_tp;
|
||||
}
|
||||
else if (data.strTopic == "PLT")
|
||||
{
|
||||
topic = cfg_PLT_tp;
|
||||
}
|
||||
else if (data.strTopic == "PST")
|
||||
else if (data.strTopic == "PST")
|
||||
{
|
||||
topic = cfg_PST_tp;
|
||||
}
|
||||
else if (data.strTopic == "Event")
|
||||
else if (data.strTopic == "Event")
|
||||
{
|
||||
topic = cfg_Evt_tp;
|
||||
}
|
||||
else if (data.strTopic == "Alm")
|
||||
else if (data.strTopic == "Alm")
|
||||
{
|
||||
topic = cfg_Alm_tp;
|
||||
}
|
||||
else if (data.strTopic == "RTDATA")//lnk20241220
|
||||
else if (data.strTopic == "RTDATA")//lnk20241220
|
||||
{
|
||||
topic = cfg_Rt_tp;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
topic = data.strTopic.toStdString();
|
||||
|
||||
}
|
||||
if (g_onlyIP[0] != 0)
|
||||
{
|
||||
//单例模式
|
||||
add_sng_log(data.strText.toAscii().data());
|
||||
if (g_onlyIP[0] != 0)
|
||||
{
|
||||
//单例模式
|
||||
add_sng_log(data.strText.toAscii().data());
|
||||
|
||||
}
|
||||
//rocketmq_producer_send(const_cast<char*>(senddata.c_str()),const_cast<char*>(topic.c_str()));
|
||||
rocketmq_producer_send(senddata, topic,FRONT_INST,key);//lnk20250623修复偶发性doublefree
|
||||
}
|
||||
//rocketmq_producer_send(const_cast<char*>(senddata.c_str()),const_cast<char*>(topic.c_str()));
|
||||
rocketmq_producer_send(senddata, topic,FRONT_INST,key);//lnk20250623修复偶发性doublefree
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cout << "[MQ][EXCEPTION] "
|
||||
<< e.what()
|
||||
<< std::endl;
|
||||
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,
|
||||
"mq发送异常:%s", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "[MQ][UNKNOWN_EXCEPTION]" << std::endl;
|
||||
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,
|
||||
"mq发送未知异常");
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -132,10 +132,25 @@ void CloseIECReports(chnl_usr_t *chnl_usr)
|
||||
ied_usr = GET_IEDEXT_ADDR(ied);
|
||||
for(cpuno=0 ; cpuno<ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->rptcount <= 0 ||
|
||||
LD_info->rptinfo == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(rpt_no=0 ; rpt_no<LD_info->rptcount; rpt_no++) {
|
||||
char rpt_inst_name[65];
|
||||
rptinfo = LD_info->rptinfo[rpt_no];
|
||||
if ( ! rptinfo->rpt_registered )
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (rptinfo == NULL)
|
||||
continue;
|
||||
|
||||
if ( !rptinfo->rpt_registered )
|
||||
continue;
|
||||
if ( rptinfo->chnl_id != chnl_usr->chnl_id)
|
||||
continue;
|
||||
@@ -260,6 +275,18 @@ void IECReport_tryGI(chnl_usr_t *chnl_usr,rptinfo_t *rptinfo)
|
||||
//增加处理根据稳态,或暂态功能等,决定 报告是否需要注册、取消注册或 不做任何处理
|
||||
int judge_rpt_next_should_do(rptinfo_t *rptinfo)
|
||||
{
|
||||
|
||||
if (rptinfo == NULL) {
|
||||
printf("[RPT][ERROR] rptinfo is NULL\n");
|
||||
return SHOULD_DO_NOTHING;
|
||||
}
|
||||
|
||||
if (rptinfo->LD_info == NULL) {
|
||||
printf("[RPT][ERROR] rptinfo->LD_info is NULL, rptID=%s\n",
|
||||
rptinfo->rptID ? rptinfo->rptID : "NULL");
|
||||
return SHOULD_DO_NOTHING;
|
||||
}
|
||||
|
||||
int should_register_state = 1; //各功能默认注册
|
||||
int is_real_report = (rptinfo->report_PQ_type & REPORT_TYPE_REAL);//报告控制中包含的类型
|
||||
int is_soe_report = (rptinfo->report_PQ_type & REPORT_TYPE_SOE);
|
||||
@@ -302,7 +329,23 @@ void ChannelCheckIECReports(chnl_usr_t *chnl_usr)
|
||||
{
|
||||
LD_info = &(ied_usr->LD_info[cpuno]); //遍历监测点
|
||||
|
||||
if (LD_info->cpuno==0){
|
||||
//添加保护,防止台账中测点号不连续导致的崩溃
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->rptcount <= 0 ||
|
||||
LD_info->rptinfo == NULL)
|
||||
{
|
||||
printf("[RPT][SKIP] invalid LD_info cpu=%d cpuno=%d LD_name=%p rptcount=%d rptinfo=%p\n",
|
||||
cpuno,
|
||||
LD_info->cpuno,
|
||||
LD_info->LD_name,
|
||||
LD_info->rptcount,
|
||||
LD_info->rptinfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
//未初始化的测点告警没有意义,直接访问id还可能崩溃
|
||||
/*if (LD_info->cpuno==0){
|
||||
// 仅在还没达到5次上限时打印
|
||||
if (!LD_info->has_logged_regist) {
|
||||
LD_info->registcount++;
|
||||
@@ -319,13 +362,39 @@ void ChannelCheckIECReports(chnl_usr_t *chnl_usr)
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
for(rpt_no=0 ; rpt_no<LD_info->rptcount; rpt_no++) { //遍历报告(映射文件中读取的报告控制)
|
||||
|
||||
rptinfo = LD_info->rptinfo[rpt_no] ;
|
||||
|
||||
//检查是否需要注册或取消注册报告,或不做任何处理
|
||||
printf("[RPT][CHECK] ip=%s cpu=%d rpt_no=%d rptcount=%d LD_name=%s rptinfo=%p\n",
|
||||
chnl_usr->ip_str,
|
||||
cpuno,
|
||||
rpt_no,
|
||||
LD_info->rptcount,
|
||||
LD_info->LD_name ? LD_info->LD_name : "NULL",
|
||||
rptinfo);
|
||||
|
||||
if (rptinfo == NULL) {
|
||||
printf("[RPT][ERROR] rptinfo NULL, skip\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rptinfo->LD_info == NULL) {
|
||||
printf("[RPT][ERROR] rptinfo->LD_info NULL, rptID=%s, skip\n",
|
||||
rptinfo->rptID ? rptinfo->rptID : "NULL");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rptinfo->rptID == NULL || rptinfo->rptID[0] == '\0') {
|
||||
printf("[RPT][ERROR] rptID empty, skip\n");
|
||||
continue;
|
||||
}
|
||||
//添加保护
|
||||
|
||||
if (judge_rpt_next_should_do(rptinfo)==SHOULD_DO_NOTHING)//检查是否触发
|
||||
{
|
||||
//DIY_DEBUGLOG_CODE(LD_info->mp_id,2,LOG_CODE_REPORT,"【DEBUG】监测点:%s - id:%s不注册报告", LD_info->name,LD_info->mp_id);
|
||||
@@ -496,8 +565,17 @@ void ChannelCheckIECLogs(chnl_usr_t *chnl_usr)
|
||||
for(cpuno=0 ; cpuno<ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
//添加保护,防止台账中测点号不连续导致的崩溃
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->logcount <= 0 ||
|
||||
LD_info->loginfo == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//日志控制块缺失
|
||||
if (LD_info->logcount<=0){
|
||||
/*if (LD_info->logcount<=0){
|
||||
// 仅在还没达到5次上限时打印
|
||||
if (!LD_info->has_logged_regist) {
|
||||
LD_info->registcount++;
|
||||
@@ -515,10 +593,14 @@ void ChannelCheckIECLogs(chnl_usr_t *chnl_usr)
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
loginfo = LD_info->loginfo[0] ;
|
||||
|
||||
//添加保护,防止台账中测点号不连续导致的崩溃
|
||||
if (loginfo == NULL || loginfo->LD_info == NULL)
|
||||
continue;
|
||||
|
||||
apr_sleep(apr_time_from_sec(1) / 10);
|
||||
|
||||
Check_Recall_Config(LD_info->mp_id);//尝试获取xml结构
|
||||
|
||||
@@ -135,6 +135,15 @@ int fill_rptctrl_by_cfg(LD_info_t* LD_info,int rptno,char *buf)
|
||||
|
||||
assert( (rptno+1) <= LD_info->rptcount ) ;
|
||||
rptinfo = LD_info->rptinfo[rptno];
|
||||
|
||||
|
||||
if (rptinfo == NULL) {
|
||||
printf("[RPT_INIT][ERROR] rptinfo NULL, rptno=%d\n", rptno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rptinfo->LD_info = LD_info;
|
||||
|
||||
if(!(str = strtok(buf,",")))
|
||||
return 1;
|
||||
|
||||
@@ -262,6 +271,13 @@ int fill_logctrl_by_cfg(LD_info_t* LD_info,int logno,char *buf,char* devtype)
|
||||
assert( (logno+1) <= LD_info->logcount ) ;
|
||||
loginfo = LD_info->loginfo[logno];
|
||||
|
||||
if (loginfo == NULL) {
|
||||
printf("[LOG_INIT][ERROR] loginfo NULL, logno=%d\n", logno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
loginfo->LD_info = LD_info;
|
||||
|
||||
if(!(str = strtok(buf,",")))
|
||||
return 1;
|
||||
tmp_str = apr_pstrdup(g_init_pool,str);
|
||||
|
||||
@@ -145,12 +145,26 @@ RCB_INFO* FindRcbInfo(MVL_NET_INFO *net_info,ST_CHAR *dom_name, ST_CHAR *rcb_nam
|
||||
|
||||
for(cpuno=0 ; cpuno<ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
if (!LD_info->LD_name)
|
||||
continue;
|
||||
//if (!LD_info->LD_name)
|
||||
// continue;
|
||||
//添加保护lnk20260602
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->rptcount <= 0 ||
|
||||
LD_info->rptinfo == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( strcmp(LD_info->LD_name,dom_name)!=0 )
|
||||
continue;
|
||||
for(rpt_no=0 ; rpt_no<LD_info->rptcount; rpt_no++) {
|
||||
rptinfo = LD_info->rptinfo[rpt_no];
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (rptinfo == NULL || rptinfo->rptID == NULL)
|
||||
continue;
|
||||
|
||||
get_rpt_inst_name(rptinfo,rpt_inst_name);
|
||||
if ( strcmp(rpt_inst_name,rcb_name)==0 ) {
|
||||
if (rptinfo->rpt_registered)
|
||||
@@ -181,8 +195,22 @@ rptinfo_t* find_rptinfo_from_net_rpt_info_name(MVL_NET_INFO *net_info, RCB_INFO
|
||||
for(cpuno=0 ; cpuno<ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->rptcount <= 0 ||
|
||||
LD_info->rptinfo == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(rpt_no=0 ; rpt_no<LD_info->rptcount; rpt_no++) {
|
||||
rptinfo = LD_info->rptinfo[rpt_no];
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (rptinfo == NULL || rptinfo->rptID == NULL || rcb_info == NULL || rcb_info->RptID == NULL)
|
||||
continue;
|
||||
|
||||
printf("%d rptinfo %s,rcbinfo %s ", rpt_no, rptinfo->rptID, rcb_info->RptID);
|
||||
if (strcmp(rcb_info->RptID,rptinfo->rptID)==0)//WW 修改为匹配字符串
|
||||
return rptinfo;
|
||||
@@ -211,8 +239,21 @@ rptinfo_t* find_rptinfo_from_net_rcb_info(MVL_NET_INFO *net_info,RCB_INFO *rcb_i
|
||||
for(cpuno=0 ; cpuno<ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
//添加保护lnk20260602
|
||||
if (LD_info->cpuno == 0 ||
|
||||
LD_info->LD_name == NULL ||
|
||||
LD_info->rptcount <= 0 ||
|
||||
LD_info->rptinfo == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(rpt_no=0 ; rpt_no<LD_info->rptcount; rpt_no++) {
|
||||
rptinfo = LD_info->rptinfo[rpt_no];
|
||||
|
||||
if (rptinfo == NULL)
|
||||
continue;
|
||||
|
||||
if (rcb_info==rptinfo->m_rcb_info)
|
||||
return rptinfo;
|
||||
}
|
||||
@@ -221,7 +262,7 @@ rptinfo_t* find_rptinfo_from_net_rcb_info(MVL_NET_INFO *net_info,RCB_INFO *rcb_i
|
||||
}
|
||||
////////////////////////////////////////
|
||||
//WW 2023-08-29 注释 end
|
||||
void get_rpt_inst_name(rptinfo_t *rptinfo, char * rpt_inst_name )
|
||||
/*void get_rpt_inst_name(rptinfo_t *rptinfo, char * rpt_inst_name )
|
||||
{
|
||||
strcpy(rpt_inst_name,rptinfo->rptID);
|
||||
if (rptinfo->instanceNeedSuffix) {
|
||||
@@ -229,7 +270,56 @@ void get_rpt_inst_name(rptinfo_t *rptinfo, char * rpt_inst_name )
|
||||
apr_snprintf(rpt_suffix_str,sizeof(rpt_suffix_str),"%02d",rptinfo->m_curRptSuffix);
|
||||
strcat(rpt_inst_name,rpt_suffix_str);
|
||||
}
|
||||
}
|
||||
} */
|
||||
void get_rpt_inst_name(rptinfo_t *rptinfo, char *rpt_inst_name)
|
||||
{
|
||||
if (rpt_inst_name == NULL)
|
||||
{
|
||||
printf("get_rpt_inst_name: rpt_inst_name is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rpt_inst_name[0] = '\0';
|
||||
|
||||
if (rptinfo == NULL)
|
||||
{
|
||||
printf("get_rpt_inst_name: rptinfo is NULL\n");
|
||||
strcpy(rpt_inst_name, "NULL_RPT");
|
||||
return;
|
||||
}
|
||||
|
||||
if (rptinfo->rptID == NULL)
|
||||
{
|
||||
printf("get_rpt_inst_name: rptID is NULL\n");
|
||||
strcpy(rpt_inst_name, "NULL_RPT");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("[RPT] rptinfo=%p rptID=%s suffix=%d needSuffix=%d\n",
|
||||
rptinfo,
|
||||
rptinfo->rptID,
|
||||
rptinfo->m_curRptSuffix,
|
||||
rptinfo->instanceNeedSuffix);
|
||||
|
||||
// 原代码
|
||||
strncpy(rpt_inst_name, rptinfo->rptID, 64);
|
||||
rpt_inst_name[64] = '\0';
|
||||
|
||||
if (rptinfo->instanceNeedSuffix)
|
||||
{
|
||||
char rpt_suffix_str[8] = {0};
|
||||
|
||||
apr_snprintf(rpt_suffix_str,
|
||||
sizeof(rpt_suffix_str),
|
||||
"%02d",
|
||||
rptinfo->m_curRptSuffix);
|
||||
|
||||
// 防止越界
|
||||
strncat(rpt_inst_name,
|
||||
rpt_suffix_str,
|
||||
64 - strlen(rpt_inst_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void strip_file_name_tail_to_ms(char *fileName)
|
||||
@@ -359,12 +449,20 @@ LD_info_t* find_LD_info_only_from_line_id(int line_id)
|
||||
|
||||
LD_info_t* find_LD_info_from_mp_id(ied_t* ied, char* mp_id)
|
||||
{
|
||||
|
||||
if (mp_id == NULL)
|
||||
return NULL;
|
||||
|
||||
LD_info_t* LD_info = NULL;
|
||||
ied_usr_t* ied_usr = GET_IEDEXT_ADDR(ied);
|
||||
int cpuno;
|
||||
|
||||
for (cpuno = 0; cpuno < ied->cpucount; cpuno++) {
|
||||
LD_info = &(ied_usr->LD_info[cpuno]);
|
||||
|
||||
if (LD_info->cpuno == 0 || LD_info->LD_name == NULL)
|
||||
continue;
|
||||
|
||||
if (LD_info && strcmp(LD_info->mp_id, mp_id) == 0)
|
||||
return LD_info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user