diff --git a/cfg_parse/cfg_parser.cpp b/cfg_parse/cfg_parser.cpp index 7f76673..cedcdd4 100644 --- a/cfg_parse/cfg_parser.cpp +++ b/cfg_parse/cfg_parser.cpp @@ -14481,6 +14481,239 @@ apr_status_t init_rem_dib_table_one(ied_t *ied) } return APR_SUCCESS; } +///////////////////////////////////////////////////////////////////////////////////////////////////清理ied +void clearLogInfo(loginfo_t *loginfo) { + if (loginfo == nullptr) { + return; // 如果传入的指针为空,直接返回 + } + + // 清空字符数组 + memset(loginfo->logName, 0, sizeof(loginfo->logName)); + + // 清空其他非指针成员 + loginfo->IntgPd = 0; + loginfo->reasonCode = 0; + loginfo->TrgOpt = 0; + loginfo->start_time = 0; + loginfo->end_time = 0; + loginfo->need_steady = 0; + loginfo->need_voltage = 0; + + // 对指针成员进行清理,但不释放内存 + if (loginfo->lcbName != nullptr) { + memset(loginfo->lcbName, 0, strlen(loginfo->lcbName)); // 清空字符串内容 + } + if (loginfo->datasetName != nullptr) { + memset(loginfo->datasetName, 0, strlen(loginfo->datasetName)); // 清空字符串内容 + } + + // 由于 LD_info 是指针,它不清理,仍指向上级 +} + +void clearRptInfo(rptinfo_t *rptinfo) { + if (rptinfo == nullptr) { + return; // 如果传入的指针为空,直接返回 + } + + // 清空字符数组和非指针成员 + memset(rptinfo->OptFlds, 0, sizeof(rptinfo->OptFlds)); + rptinfo->IntgPd = 0; + rptinfo->report_PQ_type = 0; + rptinfo->rpt_registered = 0; + rptinfo->chnl_id = 0; + rptinfo->m_LastDataTime = 0; + rptinfo->m_LastGITime = 0; + rptinfo->m_LastRegisterFailedTime = 0; + rptinfo->m_LastUnRegisterFailedTime = 0; + memset(rptinfo->m_EntryID, 0, sizeof(rptinfo->m_EntryID)); + rptinfo->m_curRptSuffix = 0; + rptinfo->count = 0; + rptinfo->rptNo = 0; + rptinfo->flickerflag = 0; + rptinfo->pstflag = 0; + + // 对指针成员进行清理,但不释放内存 + if (rptinfo->rptID != nullptr) { + memset(rptinfo->rptID, 0, strlen(rptinfo->rptID)); // 清空字符串内容 + } + + // 由于 LD_info 是指针,它不需要清理,仍指向父级 + //rptinfo->LD_info = nullptr; + + // 对 RCBC_INFO 结构体指针进行处理,假设不需要清理 + if (rptinfo->m_rcb_info != nullptr) { + // 如果需要,可以选择清理结构体内部内容,但不释放内存 + rptinfo->m_rcb_info = nullptr;//这里可以清空,因为这个指针指向的区域在连接通道关闭时会被清理: + } +} + +void clearLDInfo(LD_info_t *ld_info) { + if (ld_info == nullptr) { + std::cout << "ldinfo is null" << std::endl; + return; + } + // 清空指针成员 + if (ld_info->loginfo != nullptr) { + for (int i = 0; i < ld_info->logcount; ++i) { + if (ld_info->loginfo[i] != nullptr) { + clearLogInfold_info->loginfo[i]); //清空日志控制块 + } + } + } + + std::cout << "clean loginfo_t!!!" << std::endl; + + if (ld_info->autorecall != nullptr) { + for (int i = 0; i < ld_info->autorecallcount; ++i) { + if (ld_info->autorecall[i] != nullptr) { + memset(ld_info->autorecall[i], 0, sizeof(autorecall_t)); + delete ld_info->autorecall[i]; //删除数组元素空间 + } + } + delete ld_info->autorecall; //删除数组空间 + } + + std::cout << "clean autorecall_t!!!" << std::endl; + + if (ld_info->rptinfo != nullptr) { + for (int i = 0; i < ld_info->rptcount; ++i) { + if (ld_info->rptinfo[i] != nullptr) { + memset(ld_info->rptinfo[i], 0, sizeof(rptinfo_t)); + + } + } + + } + + std::cout << "clean rptinfo_t!!!" << std::endl; + + if (ld_info->ht_fcd != nullptr) { + apr_hash_clear(ld_info->ht_fcd); + } + if (ld_info->ht_full_fcda != nullptr) { + apr_hash_clear(ld_info->ht_full_fcda); + } + + // 清空其他指针成员 + if (ld_info->LD_name != nullptr) { + memset(ld_info->LD_name, 0, sizeof(char) * 256); + } + if (ld_info->mp_id != nullptr) { + memset(ld_info->mp_id, 0, sizeof(char) * 256); + } + if (ld_info->voltage_level != nullptr) { + memset(ld_info->voltage_level, 0, sizeof(char) * 256); + } + if (ld_info->v_wiring_type != nullptr) { + memset(ld_info->v_wiring_type, 0, sizeof(char) * 256); + } + if (ld_info->monitor_status != nullptr) { + memset(ld_info->monitor_status, 0, sizeof(char) * 64); + } + if (ld_info->terminal_code != nullptr) { + memset(ld_info->terminal_code, 0, sizeof(char) * 256); + } + + // 清空 LD_info_t 结构体中的非指针部分 + ld_info->rptcount = 0; + ld_info->read_flag = 0; + ld_info->logcount = 0; + ld_info->autorecallflag = 0; + ld_info->autorecallcount = 0; + ld_info->line_id = 0; + ld_info->real_data = 0; + ld_info->soe_data = 0; + ld_info->limit = 0; + ld_info->count = 0; + ld_info->SubV_Index = 0; + ld_info->Dev_Index = 0; + ld_info->Sub_Index = 0; + ld_info->GD_Index = 0; + ld_info->RDRE_FltNum = 0; + + +} + +void clearIedUsr(ied_usr_t *ied_usr) { + if (ied_usr == nullptr) { + std::cout << "ied_usr is null" << std::endl; + return; + } + + // 清空 ied_usr_t 中的非指针部分 + //ied_usr->dev_idx = 0;//保留index + ied_usr->dev_flag = UNUSED; + ied_usr->last_call_wavelist_time = 0; + ied_usr->time = 0; + ied_usr->update_flag = 0;//暂不使用 + + // 清空指针部分,但不清理非空指针 + if (ied_usr->LD_info != nullptr) { + // 如果 LD_info 不为空,清理它内部的内容 + for (int i = 0; i < MAX_CPUNO; ++i) { + if (ied_usr->LD_info[i] != nullptr) { + clearLDInfo(ied_usr->LD_info[i]); + } + } + } + + if (ied_usr->cookie != nullptr) { + std::cout << "cookie not null" << std::endl; + } + + // 清空其他非指针部分 + 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->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)); + memset(ied_usr->station_name, 0, sizeof(ied_usr->station_name)); + memset(ied_usr->tmnl_factory, 0, sizeof(ied_usr->tmnl_factory)); + memset(ied_usr->tmnl_status, 0, sizeof(ied_usr->tmnl_status)); + memset(ied_usr->terminal_code, 0, sizeof(ied_usr->terminal_code)); +} + +void clearIed(ied_t *ied) { + if (ied == nullptr) { + return; + } + + // 清理 channel 里的 chnl_usr_t 部分 + if (ied->channel != nullptr && ied->channel[0].connect != nullptr) { + chnl_usr_t *chnl_usr = (chnl_usr_t*)ied->channel[0].connect; + memset(chnl_usr, 0, sizeof(chnl_usr_t)); + chnl_usr->chnl_id = 0; + chnl_usr->m_state = CHANNEL_DISCONNECTED; + chnl_usr->m_ClosedMsTime = NEXT_CONNECT_TIME * (-1); + } + + // 清空 ied_t 结构体的非指针部分 + ied->id = 0; + ied->flags = 0; + ied->type = 0; + ied->chncount = 0; + ied->cpucount = 0; + ied->station = 0; + ied->node = 0; + ied->frequency = 0; + ied->delay = 0; + ied->count = 0; + ied->systoken_st = 0; + ied->index = 0; + ied->status = {0}; // 假设 status_t 可清空 + ied->last_ticks = 0; + ied->last_gi = 0; + + // 清空指针部分 + if (ied->usr_ext != nullptr) { + ied_usr_t *ied_usr = (ied_usr_t*)ied->usr_ext; + clearIedUsr(ied_usr); + } + memset(ied->name, 0, sizeof(ied->name)); + memset(ied->channel, 0, sizeof(ied->channel)); + memset(ied->cpuinfo, 0, sizeof(ied->cpuinfo)); // 假设是指针类型,可以清空 +} /*封装C可调用的台账更新函数 *///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/mms/mms_process.c b/mms/mms_process.c index 30084b7..e1f89f2 100644 --- a/mms/mms_process.c +++ b/mms/mms_process.c @@ -843,7 +843,7 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml) for (i=0; idev_flag = ENABLE;//终端有效 - ied->chncount = 1; //通信端口数 + ied->chncount = 1; //通信端口数,一个终端一般只有一个 ied->channel = (channel_t*)apr_pcalloc(g_cfg_pool, sizeof(channel_t) * ied->chncount);//内存挂到ied上 ied->channel[0].ied = ied; //通道的所属设备 ied->channel[0].status = STATUS_BREAKOFF;//初始化为通信中断 @@ -994,7 +994,7 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml) for (i=0; idelete_updates; //处理新增台账部分 + update = ledger_update_xml->delete_updates; //处理删除台账部分 update_num = ledger_update_xml->delete_update_num; printf("delete ledger num:%d\n",update_num); - for (i=0; ichncount; chnl_no++) { chnl_usr = (chnl_usr_t*)ied->channel[chnl_no].connect; - if (chnl_usr->m_state!=CHANNEL_CONNECTED){ //跳过没连接的 + if (chnl_usr->m_state!=CHANNEL_CONNECTED){ //跳过没连接的通道,一般一个终端只有一个 continue; } closeChannel(chnl_usr);//关闭更新台账后,任务会自动连接 @@ -1097,7 +1099,6 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml) } } - // 先清理要删除的 ied 的内容 ied_t* ied_to_remove = g_node->clients[index_to_remove];//指向g_node对应的内存区 @@ -1105,16 +1106,16 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml) printf("this ied is ied_to_remove\n"); } - + //清空ied的内容 //3-删除台账内容/////////////////////////////////// //4-配置映射文件////////////////////////////// - //映射文件保留 + //映射文件保留,如果再次添加这个ied,如果是相同的映射文件则可以直接加载 //4-配置映射文件/////////////////////////////////// //5-报告块////////////////////////////// - + //报告块清空 //5-报告块/////////////////////////////////// //6-init_rem_dib_table//////////////////////////////