610 lines
22 KiB
C
610 lines
22 KiB
C
/**
|
||
* @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"
|
||
/************************************************************************/
|
||
/* 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;
|
||
|
||
/************************************************************************/
|
||
/* 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);
|
||
//char doname[32];
|
||
//strcpy(doname, dom_name);
|
||
//type_ctrl = (MVL_TYPE_CTRL*)(sel_mvl_type_ctrl(doname));
|
||
//printf ("\naddress: %p \n", type_ctrl);
|
||
if (type_ctrl)
|
||
{
|
||
num_rt = type_ctrl->num_rt;
|
||
rt = type_ctrl->rt;
|
||
data_size = type_ctrl->data_size;
|
||
//printf ("\nTYPE: %d %d %d\n", num_rt, data_size, rt->el_size);
|
||
/* If the TDL produced is longer than max_tdl_len, this function */
|
||
/* "gracefully" fails (i.e. returns 0). */
|
||
if (ms_runtime_to_tdl (rt, num_rt, tdl_buf, sizeof(tdl_buf))>0)
|
||
;//SLOGCALWAYS1 (" TYPE: %s", tdl_buf);
|
||
else
|
||
echo_warn (" TYPE: unknown");
|
||
//printf("\nrt %p and rt_num: %d \n", &type_ctrl->rt,type_ctrl->num_rt);
|
||
//printf ("\nTYPE: %s \n", tdl_buf);
|
||
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);
|
||
//printf("type_ctrl->num_rt %d %x %x \n", type_ctrl->num_rt , &data, &(var->data));
|
||
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;//ִ<><D6B4>ǰ<EFBFBD><C7B0>ȡʱ<C8A1><CAB1>
|
||
int log_data_steady_type = 0;//<2F><>̬ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||
|
||
double start, end;
|
||
static double last_check_recall_config_time = 0.0;
|
||
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++;
|
||
}
|
||
//printf("do_name =====%s=====\n", do_name);
|
||
//start = sGetMsTime();
|
||
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);
|
||
//printf("create var_type_id =====%d=====%p======\n", var_type_id, &doname);
|
||
}
|
||
printf("\nbrf var_type_id");
|
||
var_type_id = sel_mvl_type_ctrl_flag(do_name);
|
||
printf("\nafter var_type_id");
|
||
//end = sGetMsTime();
|
||
//last_check_recall_config_time = last_check_recall_config_time + end - start;
|
||
//printf("jou_entry->ef.data.num_of_var =====%d===== =====%d=====\n", jou_entry->ef.data.num_of_var, var_type_id);
|
||
|
||
/*var_type_id = mms_var_type_id_create(clientNetInfo, DOM_SPEC,
|
||
dom_name, do_name, iTimeout);*/
|
||
//printf("var_type_id =====%d=====\n", var_type_id);
|
||
if (var_type_id < 0) {
|
||
//return SD_FAILURE;
|
||
continue;
|
||
}
|
||
log_var_jou_data(var_type_id,&(jou_entry->ef.data.list_of_var[j].value_spec),&mms_dec_data, do_name);
|
||
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);
|
||
|
||
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])) {
|
||
readtime = 1;
|
||
t = convert_btime6_to_apr_time(&(mms_dec_data.data_item[ii].u.data_bTime6));
|
||
}
|
||
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;
|
||
if (q[0] == '0' && q[1] == '0')
|
||
quality = 0;
|
||
else
|
||
quality = 1;
|
||
}
|
||
}
|
||
if (readtime == 1 && readquailty == 1) {
|
||
break;
|
||
}
|
||
}
|
||
if (readtime == 1 && readquailty == 1) {
|
||
if (quality == 1) {
|
||
timeflag = TRUE;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
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) //ʱ<>䷢<EFBFBD><E4B7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>json<6F><6E><EFBFBD><EFBFBD>
|
||
{
|
||
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->mp_id, 0);//<2F><>̬
|
||
json_block_create_end(loginfo->LD_info->mp_id, 1);//<2F><><EFBFBD><EFBFBD>
|
||
json_block_create_end(loginfo->LD_info->mp_id, 2);//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
process_jou_entry_t = t;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||
|
||
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);//<2F><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD> <20><><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>¶<EFBFBD><C2B6><EFBFBD> <20><>̬
|
||
json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 1, ied_usr->dev_type, loginfo->LD_info->line_id);//<2F><><EFBFBD><EFBFBD>
|
||
json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 2, ied_usr->dev_type, loginfo->LD_info->line_id);//<2F><><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
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;
|
||
//printf("%s %s = %f \n",jou_entry->ef.data.list_of_var[j].var_tag, mms_dec_data.data_item[ii].comp_name,v);
|
||
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]")) )
|
||
//printf("\nlog read: %s=%f\n",mms_ref,v);
|
||
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)) ){
|
||
//mvl_type_id_destroy(var_type_id);
|
||
return SD_SUCCESS;
|
||
}
|
||
|
||
if ( log_data_type == QVVR_DATA ) {
|
||
processQVVR_start(loginfo->LD_info);
|
||
//processQVVR_time(loginfo->LD_info,t/1000);
|
||
}
|
||
else if ( log_data_type == RDRE_DATA ) {
|
||
processRDRE_start(loginfo->LD_info);
|
||
}
|
||
else {
|
||
/*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);*/
|
||
//json_block_create_time(loginfo->LD_info->line_id,t/1000);
|
||
}
|
||
}
|
||
//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;
|
||
if (q[0]=='0'&& q[1]=='0')
|
||
quality = 0;
|
||
else
|
||
quality = 1;
|
||
if (quality == 1) {
|
||
continue;
|
||
}
|
||
//set_log_QualityFlag(quality);
|
||
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);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
//mvl_type_id_destroy(var_type_id);
|
||
}
|
||
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 {
|
||
//json_block_create_end(loginfo->LD_info->mp_id,0);
|
||
}
|
||
printf("\nend process_jou_entry");
|
||
//printf("process_jou_entry ==============%.2f================\n", last_check_recall_config_time);
|
||
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;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
|
||
static double heart_time_cout_start = 0.0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20><>ʼ
|
||
static double heart_time_cout_now = 0.0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ <20><>ǰ
|
||
do {
|
||
heart_time_cout_now = sGetMsTime();
|
||
if (heart_time_cout_now - heart_time_cout_start > 30000)//30<33><30> <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||
{
|
||
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];
|
||
//printf("\n chnl_usr->m_state ===== %d\n", chnl_usr->m_state);
|
||
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;
|
||
//append_db_records(LOG_IDX);
|
||
}
|
||
printf("\nbrf convert_btod_to_apr_time");
|
||
t = convert_btod_to_apr_time(&jou_entry->occur_time);
|
||
//set_log_TimeID(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)
|
||
{
|
||
//for (j = 0; j < jou_entry->ef.data.num_of_var; j++)
|
||
//{
|
||
// printf ("\n Var # %d: var_tag = %s", j, jou_entry->ef.data.list_of_var[j].var_tag);
|
||
// printf ("\n Var # %d: value_spec.len = %d", j,jou_entry->ef.data.list_of_var[j].value_spec.len);
|
||
//}
|
||
start = sGetMsTime();
|
||
printf("\nbrf process_jou_entry");
|
||
process_jou_entry(loginfo,t,jou_entry, clientNetInfo, dom_name, iTimeout) ;
|
||
//start = sGetMsTime();
|
||
if ( jread_resp->more_follows == 0 && ((i + 1) == jread_resp->num_of_jou_entry)) {
|
||
printf("\njread_resp->more_follows == 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||
json_block_create_end(loginfo->LD_info->mp_id, 0);//more followsΪ0 <20><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> ǿ<>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>ݵ<EFBFBD>json<6F><6E>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||
json_block_create_end(loginfo->LD_info->mp_id, 1);
|
||
json_block_create_end(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);//<2F><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD> <20><><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>¶<EFBFBD><C2B6><EFBFBD> <20><>̬
|
||
json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 1, ied_usr->dev_type, loginfo->LD_info->line_id);//<2F><><EFBFBD><EFBFBD>
|
||
json_block_create_start(loginfo->LD_info->voltage_level, loginfo->LD_info->mp_id, 2, ied_usr->dev_type, loginfo->LD_info->line_id);//<2F><><EFBFBD><EFBFBD>
|
||
}
|
||
end = sGetMsTime();
|
||
}
|
||
last_check_recall_config_time = last_check_recall_config_time + end - start;
|
||
//printf("jread_resp->more_follows = 0 ==============%.2f================\n", last_check_recall_config_time);
|
||
}
|
||
else {
|
||
printf ("\n annotation = %s", jou_entry->ef.annotation);
|
||
}
|
||
|
||
//apr_time_exp_t newTime;
|
||
//apr_time_exp_gmt(&newTime, t);
|
||
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)) //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ж<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䳬<EFBFBD><E4B3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʱ <20><><EFBFBD><EFBFBD>
|
||
{
|
||
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);
|
||
//mvl_type_id_destroy(1);
|
||
//del_mvl_type_ctrl();
|
||
//printf("do while ==============%.2f================\n", last_check_recall_config_time);
|
||
//append_db_records(LOG_IDX);
|
||
return (ret);
|
||
}
|
||
|