From 3a37ce9c5be05071bd16df54a3c82bea5ee34bc5 Mon Sep 17 00:00:00 2001 From: lnk Date: Sat, 8 Feb 2025 17:04:39 +0800 Subject: [PATCH] modify for ledgerupdate --- cfg_parse/SimpleProducer.cpp | 4 +- cfg_parse/cfg_parser.cpp | 76 ++++++++++++++++-- json/create_json.cpp | 28 ++++--- json/save2json.cpp | 145 ++++++++++++++++++++++++++++++++--- 4 files changed, 223 insertions(+), 30 deletions(-) diff --git a/cfg_parse/SimpleProducer.cpp b/cfg_parse/SimpleProducer.cpp index 86aba7b..bfb64b6 100644 --- a/cfg_parse/SimpleProducer.cpp +++ b/cfg_parse/SimpleProducer.cpp @@ -130,13 +130,13 @@ RocketMQConsumer::RocketMQConsumer(const std::string& consumerName, const std::s std::cout << "error setting groupId"<< std::endl; throw std::runtime_error("Failed to set Consumer Group ID."); } - +/* // 设置消费模式为广播模式 if (SetPushConsumerMessageModel(consumer_, BROADCASTING) != 0) { DestroyPushConsumer(consumer_); std::cout << "error setting messagemodel"<< std::endl; } - +*/ //调试用 std::string consumerlog = "./mqconsumer/" + consumerName +".log"; if ( (SetPushConsumerLogPath(consumer_,consumerlog.c_str()) || SetPushConsumerLogFileNumAndSize(consumer_,10,100) || SetPushConsumerLogLevel(consumer_,E_LOG_LEVEL_DEBUG) ) != 0) {//记录消费日志 diff --git a/cfg_parse/cfg_parser.cpp b/cfg_parse/cfg_parser.cpp index c5ad1c0..3153b91 100644 --- a/cfg_parse/cfg_parser.cpp +++ b/cfg_parse/cfg_parser.cpp @@ -3872,13 +3872,18 @@ int parse_rpt_log_ini() for (cpuno = 0; cpuno < ied->cpucount; cpuno++) { LD_info = &(ied_usr->LD_info[cpuno]); - char str[256]; + char str[256]; //256С char* tmp = Get_IED(ied_usr->dev_type); qDebug() << tmp << endl; apr_snprintf(str, sizeof(str), tmp, cpuno + 1); - ied_usr->LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str);//domin + //lnk20250208ʹapr_pstrdupʹù̶СڴֱӸ + //ied_usr->LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str);//domin + // g_init_pool ڴз̶ 256 ֽڵڴ + ied_usr->LD_info[cpuno].LD_name = (char *)apr_palloc(g_init_pool, 256); + // str еݸƵԤȷڴУิ 256 ֽڣ + apr_cpystrn(ied_usr->LD_info[cpuno].LD_name, str, 256); delete[] tmp; @@ -12437,7 +12442,7 @@ int parse_device_cfg_web() //ied = find_ied_from_dev_code(line_info.terminal_code); //ҪϼնˣѾն if (ied && ied->usr_ext && line_info.cpuno && (static_cast(line_info.cpuno) < 10)) { - char str[256]; + char str[256]; //256С byte_t cpuno = line_info.cpuno; cout << "cpuno:" << line_info.cpuno << endl; @@ -12447,7 +12452,14 @@ int parse_device_cfg_web() ied_usr->LD_info[cpuno - 1] = line_info; //cpunoĬ1 ied_usr->LD_info[cpuno - 1].ied = ied; apr_snprintf(str, sizeof(str), "PQMonitorPQM%d", cpuno);//߼תΪPQMonitorPQM+߼ - 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} ʽ + + //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].LD_name = (char *)apr_palloc(g_init_pool, 256); + // str еݸƵԤȷڴУิ 256 ֽڣ + apr_cpystrn(ied_usr->LD_info[cpuno].LD_name, str, 256); + //Ŀռ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 ںĴпܻᱻ @@ -14195,9 +14207,23 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i apr_snprintf(str, sizeof(str), "PQMonitorPQM%d", cpuno); // ûֵʱ LD_nameظڴ if (ied_usr->LD_info[cpuno - 1].LD_name == NULL) { - ied_usr->LD_info[cpuno - 1].LD_name = apr_pstrdup(g_init_pool, str); + + //lnk20250208 + std::cout << "new space for LD_name" << std::endl; + + //lnk20250208ʹapr_pstrdupʹù̶СڴֱӸ + //ied_usr->LD_info[cpuno - 1].LD_name = apr_pstrdup(g_init_pool, str); + // g_init_pool ڴз̶ 256 ֽڵڴ + ied_usr->LD_info[cpuno].LD_name = (char *)apr_palloc(g_init_pool, 256); + // str еݸƵԤȷڴУิ 256 ֽڣ + apr_cpystrn(ied_usr->LD_info[cpuno].LD_name, str, 256); + } else {//滻ԭпռϸ - apr_cpystrn(ied_usr->LD_info[cpuno - 1].LD_name, str, sizeof(ied_usr->LD_info[cpuno - 1].LD_name)); + + //lnk20250208 + std::cout << "old space for LD_name" << std::endl; + + apr_cpystrn(ied_usr->LD_info[cpuno - 1].LD_name, str, 256); } ldname = ied_usr->LD_info[cpuno - 1].LD_name; @@ -14394,7 +14420,15 @@ int parse_rpt_log_ini_one(ied_t* ied) //g_DevFlagûʹ parse_one_rpt_log_ini(g_DevFlag, rpt_cfg_strlists[type], log_cfg_strlists[type], ied_usr->dev_type); } + + //lnk20250208 + std::cout << "ied->cpucount:" << (int)(ied->cpucount) <cpucount; cpuno++) {//iedʵʵļ + + //lnk20250208 + std::cout << "cpuno:" << cpuno << "log init !!!!!!" <LD_info[cpuno]); //Щеڴ棬жϲܴg_init_poolзڴ棬lnk20250122 @@ -14406,13 +14440,39 @@ int parse_rpt_log_ini_one(ied_t* ied) // ûֵʱ LD_nameظڴ if (ied_usr->LD_info[cpuno].LD_name == NULL) { - ied_usr->LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str); + + //lnk20250208 + std::cout << "cpuno:" << cpuno << "apr_pstrdup" <LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str); + // g_init_pool ڴз̶ 256 ֽڵڴ + ied_usr->LD_info[cpuno].LD_name = (char *)apr_palloc(g_init_pool, 256); + // str еݸƵԤȷڴУิ 256 ֽڣ + apr_cpystrn(ied_usr->LD_info[cpuno].LD_name, str, 256); + } else {//滻ԭпռϸ - apr_cpystrn(ied_usr->LD_info[cpuno - 1].LD_name, str, sizeof(ied_usr->LD_info[cpuno - 1].LD_name)); + + //lnk20250208 + std::cout << "cpuno:" << cpuno << "apr_cpystrn" <LD_info[cpuno].LD_name)" << strlen(ied_usr->LD_info[cpuno].LD_name) <LD_info[cpuno].LD_name)) { + apr_cpystrn(ied_usr->LD_info[cpuno].LD_name, str, 256); + } else { + std::cerr << "Error: target buffer is too small." << std::endl; + // ѡڴʽ + } } delete[] tmp;//Get_IEDзڴ棬ʹúɾ + //lnk20250208 + std::cout << "cpuno:" << cpuno << " fill report control" <size()); for (int i = 0; i < rpt_cfg_strlists[type]->size(); ++i) { diff --git a/json/create_json.cpp b/json/create_json.cpp index bdb1c8f..6a86868 100644 --- a/json/create_json.cpp +++ b/json/create_json.cpp @@ -597,10 +597,12 @@ bool ParseXMLConfig2(XmlConfig *cfg, list *ctopiclist,QString path) // QFile file(xml_dir + JSON_CONFIG_FN); if (!file.open(QIODevice::ReadOnly | QFile::Text)) //ֻʽxml { + std::cout << "can't open not define config file" << std::endl;//lnk20250208 return 0; } if (!doc.setContent(&file)) //ļݶdoc { + std::cout << "can't read not define config file" << std::endl;//lnk20250208 file.close(); return 0; } @@ -613,10 +615,12 @@ bool ParseXMLConfig2(XmlConfig *cfg, list *ctopiclist,QString path) // QFile file(tmppath); if (!file.open(QIODevice::ReadOnly | QFile::Text)) //ֻʽxml { + std::cout << "can't open config file" << tmppath.toStdString() <updataflag = true; } - + //lnk20250208ʹִ } - xmlinfo_list[type]->xmlbase.MODEL_ID.append(id); - xmlinfo_list[type]->xmlbase.TMNL_TYPE.append(type); - xmlinfo_list[type]->xmlbase.FILE_PATH.append(filepath); - xmlinfo_list[type]->xmlbase.FILE_NAME.append(name); + //lnk20250208ӦǸǶ׷ + //xmlinfo_list[type]->xmlbase.MODEL_ID.append(id); + //xmlinfo_list[type]->xmlbase.TMNL_TYPE.append(type); + //xmlinfo_list[type]->xmlbase.FILE_PATH.append(filepath); + //xmlinfo_list[type]->xmlbase.FILE_NAME.append(name); + xmlinfo_list[type]->xmlbase.MODEL_ID = id; + xmlinfo_list[type]->xmlbase.TMNL_TYPE = type; + xmlinfo_list[type]->xmlbase.FILE_PATH = filepath; + xmlinfo_list[type]->xmlbase.FILE_NAME = name; + QDateTime time(QDate(year, month, day), QTime(hour, minute, second)); xmlinfo_list[type]->xmlbase.datetime = time; @@ -3047,7 +3057,7 @@ char* Get_IED(char* devtype) QString type; type.append(devtype); if (xmlinfo_list.contains(type)) { - cout << "!!!!!!!!!! xmlinfo_list.contains(devtype) == 1 !!!!!!!!!!!" << endl; + cout << "!!!!!!!!!! Get_IED xmlinfo_list.contains(devtype) == 1 !!!!!!!!!!!" << endl; QString ied; ied.append(xmlinfo_list[devtype]->xmlcfg.IEDname);//PQMonitor ied.append(xmlinfo_list[devtype]->xmlcfg.LDevicePrefix); @@ -3059,7 +3069,7 @@ char* Get_IED(char* devtype) return charArray; } else { - cout << "!!!!!!!!!! xmlinfo_list.contains(devtype) == 0 !!!!!!!!!!!" << endl; + cout << "!!!!!!!!!! Get_IED xmlinfo_list.contains(devtype) == 0 !!!!!!!!!!!" << endl; //cout << "ttttttttttttttt" << topicList.size() << endl; //cout << "ttttttttttttttt" << xmlcfg.IEDname.toAscii().data() << endl; QString ied; diff --git a/json/save2json.cpp b/json/save2json.cpp index 173e347..bf66278 100644 --- a/json/save2json.cpp +++ b/json/save2json.cpp @@ -721,8 +721,16 @@ std::string extractDataJson(const char* inputJson) { return ""; } + // ȡ "messageBoy" + cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy"); + if (messageBoy == NULL || messageBoy->type != cJSON_Object) { + std::cerr << "'messageBoy' is missing or is not an object" << std::endl; + cJSON_Delete(root); + return ""; + } + // ȡ "data" - cJSON* data = cJSON_GetObjectItem(root, "data"); + cJSON* data = cJSON_GetObjectItem(messageBoy, "data"); if (data == NULL || data->type != cJSON_Array) { std::cerr << "'data' is missing or is not an array" << std::endl; cJSON_Delete(root); @@ -768,12 +776,20 @@ bool parseJsonMessageRT(const std::string& body, std::string& devSeries, std::st return false; } + // ȡ "messageBoy" + cJSON* messageBoy = cJSON_GetObjectItem(root, "messageBoy"); + if (messageBoy == NULL || messageBoy->type != cJSON_Object) { + std::cerr << "'messageBoy' is missing or is not an object" << std::endl; + cJSON_Delete(root); + return ""; + } + // ȡֶ - cJSON* devSeriesItem = cJSON_GetObjectItem(root, "devSeries"); - cJSON* lineItem = cJSON_GetObjectItem(root, "line"); - cJSON* realDataItem = cJSON_GetObjectItem(root, "realData"); - cJSON* soeDataItem = cJSON_GetObjectItem(root, "soeData"); - cJSON* limitItem = cJSON_GetObjectItem(root, "limit"); + cJSON* devSeriesItem = cJSON_GetObjectItem(messageBoy, "devSeries"); + cJSON* lineItem = cJSON_GetObjectItem(messageBoy, "line"); + cJSON* realDataItem = cJSON_GetObjectItem(messageBoy, "realData"); + cJSON* soeDataItem = cJSON_GetObjectItem(messageBoy, "soeData"); + cJSON* limitItem = cJSON_GetObjectItem(messageBoy, "limit"); if (devSeriesItem && lineItem && realDataItem && soeDataItem && limitItem) { devSeries = devSeriesItem->valuestring; @@ -896,6 +912,46 @@ void close_listening_socket() { } } +//Уipʽ +bool isValidIP(const std::string &ip) { + std::vector parts; + std::stringstream ss(ip); + std::string part; + + // ʹ "." Ϊָ IP ַָɸ + while (getline(ss, part, '.')) { + parts.push_back(part); + } + + // IP ַ 4 + if (parts.size() != 4) { + return false; + } + + // УÿһǷΪϷ 0 255 ֮ + for (size_t i = 0; i < parts.size(); ++i) { + // УÿǷΪ + for (size_t j = 0; j < parts[i].size(); ++j) { + if (!isdigit(parts[i][j])) { + return false; + } + } + + // תΪǷЧΧ + int num = atoi(parts[i].c_str()); + if (num < 0 || num > 255) { + return false; + } + + // Ƿǰ㣨 01001 ȣ + if (parts[i].length() > 1 && parts[i][0] == '0') { + return false; + } + } + + return true; +} + //ִнűƽ void execute_bash(string fun,int process_num,string type) { @@ -918,6 +974,25 @@ void execute_bash(string fun,int process_num,string type) system(command); } +//ִнűƽ +void execute_bash_debug(string fun,string ip,string type) +{ + + const char* script = "/FeProject/bin/set_debug.sh";//ʹsetsidֹ˿ռ + const char* param1 = fun.c_str(); + const char* param2 = ip.c_str(); + const char* param3 = type.c_str(); + + // + char command[256]; + snprintf(command, sizeof(command), "%s %s %s %s &", script, param1, param2, param3); + + std::cout << "command:" << command <type != cJSON_Object) { + std::cerr << "'messageBoy' is missing or is not an object" << std::endl; + cJSON_Delete(root); + return ; + } + // ȡ code ֶ - cJSON* code = cJSON_GetObjectItem(root, "code"); + cJSON* code = cJSON_GetObjectItem(messageBoy, "code"); if (code == nullptr) { std::cout << "Missing 'code' in JSON." << std::endl; cJSON_Delete(root); @@ -946,7 +1029,7 @@ void parse_set(const std::string& json_str) { string index_value_str = index->valuestring; int index_value = StringToInt(index_value_str); - //̺Ϊ0Ľ̴̨˸Ϣ + //̺Ϊ0Ľ̴пϢ if (index_value != g_front_seg_index && g_front_seg_index !=0) { std::cout << "msg index:"<< index_value <<"doesnt match self index:" << g_front_seg_index << std::endl; cJSON_Delete(root); @@ -997,6 +1080,38 @@ void parse_set(const std::string& json_str) { } } + else if (code_str == "set_debug"){ + if(g_node_id == STAT_DATA_BASE_NODE_ID && g_front_seg_index == 1){ + std::cout << "cfg_stat_data process" << g_front_seg_index <<" handle this msg" << std::endl; + // set_process + cJSON* data = cJSON_GetObjectItem(root, "data"); + if (data != nullptr && data->type == cJSON_Array) { + int data_size = cJSON_GetArraySize(data); + for (int i = 0; i < data_size; i++) { + cJSON* item = cJSON_GetArrayItem(data, i); + + std::string fun = cJSON_GetObjectItem(item, "fun")->valuestring; + std::string ip = cJSON_GetObjectItem(item, "ip")->valuestring; + std::string frontType = cJSON_GetObjectItem(item, "frontType")->valuestring; + + //У + if((fun == "start" || fun == "delete") && + isValidIP(ip) && + (frontType == "stat" || frontType == "recall" || frontType == "3s" || frontType == "comtrade")){ + execute_bash_debug(fun, ip, frontType); + std::cout << "!!!!!!!!!!!!!!!! execute mark:" << i << " !!!!!!!!!!!!!!!" <type != cJSON_Object) { + std::cerr << "'messageBoy' is missing or is not an object" << std::endl; + cJSON_Delete(root); + return ; + } + // ȡ code ֶ - cJSON* code = cJSON_GetObjectItem(root, "code"); + cJSON* code = cJSON_GetObjectItem(messageBoy, "code"); if (code == nullptr) { std::cout << "Missing 'code' in JSON." << std::endl; cJSON_Delete(root); return; } - cJSON* index = cJSON_GetObjectItem(root, "index"); + cJSON* index = cJSON_GetObjectItem(messageBoy, "index"); if (index == nullptr) { std::cout << "Missing 'index' in JSON." << std::endl; cJSON_Delete(root); @@ -1235,7 +1358,7 @@ void parse_control(const std::string& json_str, const std::string& output_dir) { std::cout << "add or update ledger" <type == cJSON_Array) { int data_size = cJSON_GetArraySize(data); for (int i = 0; i < data_size; i++) {