/**
* @file:    $RCSfile: mmscli_log.c,v $
* @brief:   $IEC 61850 Protocol  
*
* @version: $Revision: 1.7 $
* @date:    $Date: 2019/01/08 03:06:27 $
* @author:  $Author: lizhongming $
* @state:   $State: Exp $
*
* @latest:  $Id: mmscli_log.c,v 1.7 2019/01/08 03:06:27 lizhongming Exp $
*
*/
 
/************************************************************************/
#include "rdb_client.h"
#include "glbtypes.h"
#include "sysincs.h"
#include "signal.h"
#include "mmsdefs.h"
#include "mms_pvmd.h"
#include "mms_pvar.h"
#include "mms_vvar.h"
#include "mms_err.h"
#include "mms_pcon.h"
#include "asn1defs.h"
#include "mmsop_en.h"

#include "lean_a.h" 	//add by lzm
#include "tp0_sock.h"
#include "mvl_defs.h"
#include "acse2.h"

#include "mvl_acse.h"
#include "mvl_log.h"
#include "tp4api.h"
#include "clntobj.h"
#include "mmsclient.h"
#include "tp4.h"

#include "db_interface.h"
#include "../cfg_parse/custom_printf.h"//lnk20250225
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of 	*/
/* __FILE__ strings.							*/
/************************************************************************/

#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif



/************************************************************************/
/* Global variables.							*/
/************************************************************************/
 
extern pt61850app_t*	g_pt61850app;

extern bool DEBUGOPEN;

/************************************************************************/
/* Static function prototypes.						*/
/************************************************************************/

static ST_VOID log_var_jou_data (ST_INT	var_type_id,VAR_ACC_DATA *var ,MMS_DECODE_DATA *data, ST_CHAR* dom_name)
{
	ST_INT rc;
	ST_CHAR tdl_buf [500];	/* increase size if complex TDL expected*/
	MVL_TYPE_CTRL *type_ctrl;
	ST_INT  va_data_size;
	ST_CHAR* temp_data_buf;

	ST_INT num_rt;		/* Runtime type table			*/
	SD_CONST RUNTIME_TYPE* rt;
	ST_INT data_size;             /* size of data element			*/

	type_ctrl = mvl_type_ctrl_find (var_type_id);

	if (type_ctrl)
	{
		num_rt = type_ctrl->num_rt;
		rt = type_ctrl->rt;
		data_size = type_ctrl->data_size;

		if (ms_runtime_to_tdl (rt, num_rt, tdl_buf, sizeof(tdl_buf))>0)
			;
		else
			echo_warn ("  TYPE: unknown");

		va_data_size = data_size;
		temp_data_buf = (ST_CHAR*)malloc( va_data_size);
		rc = ms_asn1_to_local (rt, num_rt, var->data, var->len, temp_data_buf);

		my_local_to_data (temp_data_buf,rt,num_rt, data);
		if (data->item_num==0) {
			echo_warn("!!!!!!!!!!!!!!!!!!!data num is 0 !!!!!!!!!!!!!!!!\n");
		}
		free(temp_data_buf);
	}
	else
		echo_warn ("  ERR: type_id is invalid");
}

/************************************************************************/
/************************************************************************/ 
#define STEADY_DATA		(0)
#define QVVR_DATA		(1)
#define RDRE_DATA		(2)
apr_time_t process_jou_entry_t = apr_time_from_sec(0);
static ST_RET process_jou_entry(loginfo_t *loginfo,apr_time_t t,
	MVL_JOURNAL_ENTRY *jou_entry, MVL_NET_INFO *clientNetInfo, ST_CHAR *dom_name, ST_INT iTimeout) 
{
	ST_RET			ret = SD_SUCCESS;
	ST_INT			var_type_id;		/* type_id for "ctrl_name" arg	*/
	int				ii,j;
	char			*do_name;
	MMS_DECODE_DATA mms_dec_data;
	int				log_data_type = STEADY_DATA;
	ST_INT			not_set_log_q_this;
	ST_INT			not_set_log_t_this;
	int				length_FCDA;

	not_set_log_q_this = TRUE;
	not_set_log_t_this = TRUE;

	ST_INT timeflag = TRUE;//执行前先取时标
	int log_data_steady_type = 0;//稳态 长闪 短闪标志

	double start, end;
	static double last_check_recall_config_time = 0.0;
	if(DEBUGOPEN)printf("\nbrf for");
	for (j = 0;  j < jou_entry->ef.data.num_of_var;  j++)  {

		printf("\nfor %d", jou_entry->ef.data.num_of_var);
		printf("\nfor %s", jou_entry->ef.data.list_of_var[j].var_tag);

		if (strstr(jou_entry->ef.data.list_of_var[j].var_tag, dom_name) == NULL)
		{
			do_name = jou_entry->ef.data.list_of_var[j].var_tag;
		}
		else if (strstr(jou_entry->ef.data.list_of_var[j].var_tag, "reasonCode") != NULL)
		{
			continue;
		}
		else 
		{
			do_name = strstr(jou_entry->ef.data.list_of_var[j].var_tag, "/");
			do_name++;
		}

		if(DEBUGOPEN)printf("\nbrf if");
		if (sel_mvl_type_ctrl_flag(do_name) == -1)
		{
			var_type_id = mms_var_type_id_create(clientNetInfo, DOM_SPEC,
				dom_name, do_name, iTimeout);

			char doname[32];
			strcpy(doname, do_name);
			add_mvl_type_ctrl(doname, var_type_id);

		}
		if(DEBUGOPEN)printf("\nbrf var_type_id");
		var_type_id = sel_mvl_type_ctrl_flag(do_name);
		if(DEBUGOPEN)printf("\nafter var_type_id");

		if (var_type_id < 0) {
			continue;
		}
		log_var_jou_data(var_type_id,&(jou_entry->ef.data.list_of_var[j].value_spec),&mms_dec_data, do_name);
		if(DEBUGOPEN)printf("\nafter log_var_jou_data");
		if (timeflag) {
			int readtime = 0;
			int readquailty = 0;
			apr_time_t t;
			int quality;
			for (ii = 0; ii < mms_dec_data.item_num; ++ii) {
				double v = 0.0;
				char mms_ref[256];
				if (mms_dec_data.data_item[ii].type == DATA_INT_TYPE)
					v = mms_dec_data.data_item[ii].u.data_int;
				else if (mms_dec_data.data_item[ii].type == DATA_UINT_TYPE)
					v = mms_dec_data.data_item[ii].u.data_uint;
				else if (mms_dec_data.data_item[ii].type == DATA_INT64_TYPE)
					v = (double)mms_dec_data.data_item[ii].u.data_int64;
				else if (mms_dec_data.data_item[ii].type == DATA_UINT64_TYPE)
					v = (double)mms_dec_data.data_item[ii].u.data_uint64;
				else if (mms_dec_data.data_item[ii].type == DATA_DOUBLE_TYPE)
					v = mms_dec_data.data_item[ii].u.data_double;
				apr_snprintf(mms_ref, sizeof(mms_ref), "%s$%s", do_name, mms_dec_data.data_item[ii].comp_name);

				//调试用
				printf("u.data_str: %s (as hex: 0x%X)\n", mms_dec_data.data_item[ii].u.data_str, *((ST_UINT16*)mms_dec_data.data_item[ii].u.data_str));

				if (strstr(mms_ref, "QVVR")) {
					log_data_type = QVVR_DATA;
					timeflag = FALSE;
					break;
				}
				else if (strstr(mms_ref, "RDRE")) {
					log_data_type = RDRE_DATA;
					timeflag = FALSE;
					break;
				}

				length_FCDA = strlen(mms_ref);
				if (('$' == mms_ref[length_FCDA - 2]) && ('t' == mms_ref[length_FCDA - 1])) {
					//调试用lnk20250307
					printf("readtime = 1");
					readtime = 1;
					t = convert_btime6_to_apr_time(&(mms_dec_data.data_item[ii].u.data_bTime6));

					//调试用
					// 定义一个结构体保存转换后的时间信息
					apr_time_exp_t xt;

					// 使用本地时区转换（也可以用 apr_time_exp_gmt(&xt, t) 得到 GMT 时间）
					if (apr_time_exp_lt(&xt, t) == APR_SUCCESS) {
					    // tm_year 表示自 1900 年起的年数，需要加上 1900；tm_mon 范围为 0~11，需要加 1
					    printf("Converted time: %04d-%02d-%02d %02d:%02d:%02d.%06d\n",
					           xt.tm_year + 1900,
					           xt.tm_mon + 1,
					           xt.tm_mday,
					           xt.tm_hour,
					           xt.tm_min,
					           xt.tm_sec,
					           xt.tm_usec);
					} else {
					    printf("Failed to convert apr_time_t\n");
					}
					//调试用
				}
				if (('$' == mms_ref[length_FCDA - 2]) && ('q' == mms_ref[length_FCDA - 1])) {
					if (log_data_type == STEADY_DATA) {
						readquailty = 1;
						char* q = mms_dec_data.data_item[ii].u.data_str;

						//调试用lnk20250307
						if (q != NULL)
{
    int i;
    for (i = 0; q[i] != '\0'; i++)
    {
        /* 如果当前字符是 '\0' 则跳过，但循环条件已经排除了 '\0' */
        if (q[i] == '\0')
            continue;
        printf("q[%d] = %c\n", i, q[i]);
    }
    printf("!!!!!\n");
}
						//调试用lnk20250307

						if (q[0] == '0' && q[1] == '0'){
							quality = 0;

							//调试用lnk20250307
							printf("quality = 0");	

						}else{
							//调试用lnk20250307
							printf("quality = 1");
							quality = 1;
						}
							
					}
				}
				if (readtime == 1 && readquailty == 1) {
					//调试用lnk20250307
					printf("readtime == 1 && readquailty = 1");
					break;
				}
			}
			if (readtime == 1 && readquailty == 1) {
				if (0) {//调试，要改回quality == 0
					timeflag = TRUE;
					//调试用lnk20250307
					printf("readtime == 1 && readquailty = 1 && quality == 1 continue");
					continue;
				}
				else 
				{
					//调试用lnk20250307
					printf("readtime == 1 && readquailty = 1 && quality == 0 log");

					timeflag = FALSE;
					if (process_jou_entry_t == 0) {
						process_jou_entry_t = t;
					}

					apr_time_exp_t newTime;
					apr_time_exp_gmt(&newTime, t);

					apr_time_exp_t preTime;
					apr_time_exp_gmt(&preTime, process_jou_entry_t);
					if (newTime.tm_year != preTime.tm_year || newTime.tm_mon != preTime.tm_mon || newTime.tm_mday != preTime.tm_mday || newTime.tm_hour != preTime.tm_hour || newTime.tm_min != preTime.tm_min) //时间发生跳变 长闪 短闪 和稳态数据执行json推送
					{
						printf("\n newTime: %d %d %d %d %d %d", newTime.tm_year, newTime.tm_mon, newTime.tm_mday, newTime.tm_hour, newTime.tm_min, newTime.tm_sec);
						printf("\n preTime: %d %d %d %d %d %d", preTime.tm_year, preTime.tm_mon, preTime.tm_mday, preTime.tm_hour, preTime.tm_min, preTime.tm_sec);
						json_block_create_end(loginfo->LD_info->v_wiring_type,loginfo->LD_info->mp_id, 0);//稳态
						json_block_create_end(loginfo->LD_info->v_wiring_type,loginfo->LD_info->mp_id, 1);//长闪
						json_block_create_end(loginfo->LD_info->v_wiring_type,loginfo->LD_info->mp_id, 2);//短闪 波动
						process_jou_entry_t = t;//调整至最新时标

						ied_t* ied;
						ied = find_ied_from_dev_code(loginfo->LD_info->terminal_code);
						ied_usr_t* ied_usr = (ied_usr_t*)ied->usr_ext;
						json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 0, ied_usr->dev_type, loginfo->LD_info->line_id);//推送结束 重新初始化新队列 稳态
						json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 1, ied_usr->dev_type, loginfo->LD_info->line_id);//长闪
						json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 2, ied_usr->dev_type, loginfo->LD_info->line_id);//短闪
					}
				}
			}
		}

		for ( ii = 0; ii < mms_dec_data.item_num; ++ii) {
			double v = 0.0;
			char mms_ref[256];
			if (mms_dec_data.data_item[ii].type==DATA_INT_TYPE)
				v = mms_dec_data.data_item[ii].u.data_int;
			else if (mms_dec_data.data_item[ii].type==DATA_UINT_TYPE)
				v = mms_dec_data.data_item[ii].u.data_uint;
			else if (mms_dec_data.data_item[ii].type==DATA_INT64_TYPE)
				v = (double)mms_dec_data.data_item[ii].u.data_int64;	
			else if (mms_dec_data.data_item[ii].type==DATA_UINT64_TYPE)
				v = (double)mms_dec_data.data_item[ii].u.data_uint64;
			else if (mms_dec_data.data_item[ii].type==DATA_DOUBLE_TYPE)
				v = mms_dec_data.data_item[ii].u.data_double;	

			apr_snprintf(mms_ref,sizeof(mms_ref),"%s$%s",do_name,mms_dec_data.data_item[ii].comp_name);
			if ( (strstr(mms_ref,"]")==NULL) || (strstr(mms_ref,"0]"))  )

			if (j==0 && ii==0) {
				printf("\n ----------------------------------------------------------------log read: %s=%f--------------------------------------------------------------\n",mms_ref,v);
				if ( strstr(mms_ref,"QVVR") )  {
					log_data_type = QVVR_DATA;
				}
				else if ( strstr(mms_ref,"RDRE") )  {
					log_data_type = RDRE_DATA;
				}
				else if (strcasestr(mms_ref, "PLT") ) {
					log_data_steady_type = 1;
				}
				else if (strcasestr(mms_ref, "PST") || strcasestr(mms_ref, "FLUC")) {
					log_data_steady_type = 2;
				}
				if (   ( (loginfo->need_steady==0) &&(log_data_type == STEADY_DATA)) 
					|| ( (loginfo->need_voltage==0) &&(log_data_type != STEADY_DATA))  ){
					return SD_SUCCESS;
				}
				
				if ( log_data_type == QVVR_DATA )  {
					processQVVR_start(loginfo->LD_info);
				}
				else if ( log_data_type == RDRE_DATA )  {
					processRDRE_start(loginfo->LD_info);
				}
				else  {
				}
			}
			//set_db_value(LOG_IDX,mms_ref,v,FALSE);
			length_FCDA = strlen( mms_ref );
			if ( ('$'==mms_ref[length_FCDA-2]) && ('q'==mms_ref[length_FCDA-1]) )  {


				if(not_set_log_q_this && ( log_data_type == STEADY_DATA )) {
					int quality = 0;
					char* q = mms_dec_data.data_item[ii].u.data_str;

					//调试用lnk20250307
					printf("q[0] = %c ,q[1] = %c !!!!!",q[0],q[1]);

					if (q[0]=='0'&& q[1]=='0'){
						printf("quality = 0");
						quality = 0;
					}else{
						printf("quality = 1");
						quality = 1;
					}
					if (0) {//调试用，要改回quality == 0
						printf("quality = 1 continue");
						continue;
					}
					if (log_data_steady_type == 0) {
						json_block_create_flag(loginfo->LD_info->mp_id, quality, 0);
					}
					else if (log_data_steady_type == 1) {
						json_block_create_flag(loginfo->LD_info->mp_id, quality, 1);
					}
					else if (log_data_steady_type == 2) {
						json_block_create_flag(loginfo->LD_info->mp_id, quality, 2);
					}
					not_set_log_q_this = FALSE;					 
				}
			}
			else if ( ('$'==mms_ref[length_FCDA-2]) && ('t'==mms_ref[length_FCDA-1]) )  {

				if (not_set_log_t_this)  {
					apr_time_t t = convert_btime6_to_apr_time(&(mms_dec_data.data_item[ii].u.data_bTime6));
					if ( log_data_type == QVVR_DATA )  {
						if ( strstr(mms_ref,"VarStr$t") ) {
							processQVVR_time(loginfo->LD_info,t/1000);
							not_set_log_t_this = FALSE; 
						}
					}
					else if ( log_data_type == RDRE_DATA )  {
						//need do nothing!
						not_set_log_t_this = FALSE; 
					}
					else {
						if (log_data_steady_type == 0) {
							json_block_create_time(loginfo->LD_info->mp_id, t / 1000, 0);
						}
						else if (log_data_steady_type == 1) {
							json_block_create_time(loginfo->LD_info->mp_id, t / 1000, 1);
						}
						else if (log_data_steady_type == 2) {
							json_block_create_time(loginfo->LD_info->mp_id, t / 1000, 2);
						}
						not_set_log_t_this = FALSE; 
					}
				}
			}
			else  {

				if ( log_data_type == QVVR_DATA ){
					processQVVR_data(loginfo->LD_info,mms_ref,v);
				}
				else if ( log_data_type == RDRE_DATA ) {
					processRDRE_data(loginfo->LD_info,mms_ref,v);
				}
				else
				{
					if (log_data_steady_type == 0) {
						json_block_create_data(loginfo->LD_info->mp_id, mms_ref, v, 0);
					}
					else if (log_data_steady_type == 1) {
						json_block_create_data(loginfo->LD_info->mp_id, mms_ref, v, 1);
					}
					else if (log_data_steady_type == 2) {
						json_block_create_data(loginfo->LD_info->mp_id, mms_ref, v, 2);
					}
				}
					
			}
			
		}
		
	}
	if(DEBUGOPEN)printf("\naft for");
	if ( log_data_type == QVVR_DATA )  {
		processQVVR_end(loginfo->LD_info);
	}
	else if ( log_data_type == RDRE_DATA )  {
		processRDRE_end(loginfo->LD_info);
	}
	else { 

	}
	printf("\nend process_jou_entry");
	return ret;
}

/************************************************************************/
/*			mms_jread						*/
/************************************************************************/
ST_RET mms_jread (loginfo_t *loginfo,MVL_NET_INFO *clientNetInfo, ST_CHAR *dom_name,ST_CHAR *logName,
	 apr_time_t start_time,apr_time_t end_time,ST_INT iTimeout, ST_CHAR* ip)
{
	ST_RET ret;
	ST_INT i, k;
	MVL_REQ_PEND *reqCtrl;
	JREAD_REQ_INFO jread_req;
	MVL_JREAD_RESP_INFO *jread_resp;	/* set to reqCtrl->u.jread_resp_info*/
	MVL_JOURNAL_ENTRY *jou_entry;	 
	MMS_UTC_TIME utc_time_start,utc_time_end;
	MMS_BTOD	btod_time_start,btod_time_end;
	ST_UCHAR	entry_id[8];
	ST_INT		more_follows = 0;
	MMS_BTOD	last_occur_time;

	memset(&last_occur_time,0,sizeof(MMS_BTOD));
	memset(&jread_req,0,sizeof(MVL_JREAD_RESP_INFO));
	jread_req.jou_name.object_tag = DOM_SPEC;
	jread_req.jou_name.domain_id = dom_name;
 
	jread_req.jou_name.obj_name.vmd_spec = logName;//vmd_spec item_id
	jread_req.range_start_pres = 1;
	jread_req.range_stop_pres = 1;
	jread_req.start_tag = 0; //starting time
	jread_req.stop_tag = 0; //ending time
	convert_apr_time_to_utc_time(start_time,&utc_time_start);
	my_asn1_convert_utc_to_btod (&utc_time_start, &btod_time_start);
	memcpy(&jread_req.start_time, &btod_time_start, sizeof(MMS_BTOD));
	convert_apr_time_to_utc_time(end_time,&utc_time_end);
	my_asn1_convert_utc_to_btod (&utc_time_end, &btod_time_end);
	memcpy(&jread_req.end_time, &btod_time_end, sizeof(MMS_BTOD));
	jread_req.num_of_entries = 0;
	jread_req.num_of_var = 0;
	jread_req.list_of_var_pres = 0;
	jread_req.sa_entry_pres = 0;
	jread_req.entry_spec_len = 0;
	jread_req.entry_spec = 0;
	memcpy(&jread_req.time_spec, &btod_time_start, sizeof(MMS_BTOD));
	process_jou_entry_t = apr_time_from_sec(0);

	double start,end;
	static double last_check_recall_config_time = 0.0;

	static double heart_time_cout = 0.0;//心跳计时
	static double heart_time_cout_start = 0.0;//心跳计时 开始
	static double heart_time_cout_now = 0.0;//心跳计时 当前
	do {
		heart_time_cout_now = sGetMsTime();
		if (heart_time_cout_now - heart_time_cout_start > 30000)//30秒 定时心跳
		{
			printf("\n heart_time_cout OK");
			heart_time_cout_start = sGetMsTime();
			int i = 0;
			while (i < g_pt61850app->chnl_counts)
			{
				chnl_usr_t* chnl_usr;
				int	cpuno = 0;

				chnl_usr = g_pt61850app->chnl_usr[i];

				if (strstr(chnl_usr->ip_str, ip) != NULL)
				{
					printf("\nSame Ip %s : %s", chnl_usr->ip_str, ip);
					i++;
					continue;
				}
				if (chnl_usr->m_state == CHANNEL_CONNECTED) {
					char** varnames;
					int varnum;
					ST_RET ret = mms_mvla_getnam(chnl_usr->net_info, VMD_SPEC, NULL, MMS_CLASS_DOM, g_pt61850app->mmsOpTimeout,
						&varnames, &varnum, g_pt61850app->tmp_pool);
					chnl_usr->m_LastPosRespTime = sGetMsTime();
					if (ret == SD_SUCCESS) {
						printf("\n heart success!");
						chnl_usr->m_NegRespTimes = 0;
					}
					else {
						printf("%d--------------\n", chnl_usr->m_NegRespTimes);
						chnl_usr->m_NegRespTimes++;
					}
				}
				i++;
			}
			heart_time_cout_start = sGetMsTime();
		}
		ret = mvla_jread (clientNetInfo, &jread_req, &reqCtrl);
		if (ret == SD_SUCCESS)
			ret = waitReqDone (reqCtrl, iTimeout);
		if (ret != SD_SUCCESS) {
			more_follows = 0;
			printf ("\n mvl_jread () Error, ret = 0x%X.", ret);
		}
		else
		{
			printf ("\n mvl_jread OK");
			jread_resp = reqCtrl->u.jread.resp_info;
			printf ("\n   num_entry = %d", jread_resp->num_of_jou_entry);
			printf ("\n   more_follows = %d", jread_resp->more_follows);
			more_follows = jread_resp->more_follows;
			for (i = 0;  i < jread_resp->num_of_jou_entry;  i++)
			{
				apr_time_t t;
				jou_entry = &jread_resp->jou_entry[i];
				if ( ( (i+1)==jread_resp->num_of_jou_entry) && more_follows )  {
					jread_req.range_start_pres = 0;
					jread_req.sa_entry_pres = 1;
					jread_req.entry_spec_len = jou_entry->entry_id_len;
					memcpy(entry_id,jou_entry->entry_id,sizeof(entry_id));
					jread_req.entry_spec = entry_id;
					jread_req.time_spec = jou_entry->occur_time;
					jread_req.num_of_entries = 0;
				}
				printf ("\n   Journal Entry # %d:", i);
				printf ("\n     entry_id_len = %d    ", jou_entry->entry_id_len);
				for (k = 0;  k < jou_entry->entry_id_len;  k++)
					printf("%02x ", jou_entry->entry_id[k]);	
				printf ("\n     occur_time.form = %s", (jou_entry->occur_time.form == MMS_BTOD6 ? "MMS_BTOD6" : "MMS_BTOD4"));
				printf ("\n     occur_time.ms  = %lu", jou_entry->occur_time.ms);
				printf ("\n     occur_time.day = %lu", jou_entry->occur_time.day);
				printf ("\n     entry_form_tag = %d", jou_entry->entry_form_tag);

				if( (last_occur_time.day!=jou_entry->occur_time.day)||(last_occur_time.ms!=jou_entry->occur_time.ms) ) {
					last_occur_time=jou_entry->occur_time;
				
				}
				printf("\nbrf convert_btod_to_apr_time");
				t = convert_btod_to_apr_time(&jou_entry->occur_time);

				if (jou_entry->entry_form_tag == 2)
				{
					printf("\nbrf jou_entry->ef.data.list_of_var_pres");
					if (jou_entry->ef.data.list_of_var_pres)
					{
	
						start = sGetMsTime();
						printf("\nbrf process_jou_entry");
						process_jou_entry(loginfo,t,jou_entry, clientNetInfo, dom_name, iTimeout) ;

						if ( jread_resp->more_follows == 0 && ((i + 1) == jread_resp->num_of_jou_entry)) {
							printf("\njread_resp->more_follows == 0       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
							//lnk2024-8-16添加接线参数
							json_block_create_end(loginfo->LD_info->v_wiring_type, loginfo->LD_info->mp_id, 0);//more follows为0 数据接受最后一条 强行处理稳态数据的json防止遗留
							json_block_create_end(loginfo->LD_info->v_wiring_type, loginfo->LD_info->mp_id, 1);
							json_block_create_end(loginfo->LD_info->v_wiring_type, loginfo->LD_info->mp_id, 2);

							ied_t* ied;
							ied = find_ied_from_dev_code(loginfo->LD_info->terminal_code);
							ied_usr_t* ied_usr = (ied_usr_t*)ied->usr_ext;
							json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 0, ied_usr->dev_type, loginfo->LD_info->line_id);//推送结束 重新初始化新队列 稳态
							json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 1, ied_usr->dev_type, loginfo->LD_info->line_id);//长闪
							json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 2, ied_usr->dev_type, loginfo->LD_info->line_id);//短闪
						}
						end = sGetMsTime();
					}
					last_check_recall_config_time = last_check_recall_config_time + end - start;
				}
				else  {
					printf ("\n       annotation = %s", jou_entry->ef.annotation);
				}

				printf("\nstart timecheck");
				apr_time_exp_t newTime;
				apr_time_exp_gmt(&newTime, process_jou_entry_t);
				printf("\nstart timecheck_1");
				apr_time_exp_t preTime;
				apr_time_exp_gmt(&preTime, end_time);
				printf("\nstart timecheck_2");
				if (newTime.tm_year != preTime.tm_year || newTime.tm_mon != preTime.tm_mon || newTime.tm_mday != preTime.tm_mday || (newTime.tm_hour != preTime.tm_hour && newTime.tm_hour != preTime.tm_hour + 1 && newTime.tm_hour != preTime.tm_hour - 1)) //结束时标判断 当上送时间超过结束时标时 跳出
				{
					printf("\nstart timecheck_3");
					printf("\n more_follows newTime: %d %d %d %d %d %d", newTime.tm_year, newTime.tm_mon, newTime.tm_mday, newTime.tm_hour, newTime.tm_min, newTime.tm_sec);
					printf("\n more_follows preTime: %d %d %d %d %d %d", preTime.tm_year, preTime.tm_mon, preTime.tm_mday, preTime.tm_hour, preTime.tm_min, preTime.tm_sec);
					more_follows = 0;
				}
				printf("\nstart timecheck_end");
			}	/* end "loop"	*/
		}
		mvl_free_req_ctrl (reqCtrl);	/* CRITICAL:		*/
	} while (more_follows);
	return (ret);
}

