⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sclproc.c

📁 scl解析文件,欢迎大家学习共享,解析算法值得学习
💻 C
📖 第 1 页 / 共 5 页
字号:
                    scl_do->type, scl_do->name);
      return (SD_FAILURE);
      }
    }	/* end "for (scl_do...)" loop	*/

  if (tdl_ctxt->tdlptr > save_ptr_after_head)
    {		/* tdl was added. Finish it.	*/
    /* add ending text "},\n"	*/
    if (tdladd_string (tdl_ctxt, "},\n")!=SD_SUCCESS)
      return (SD_FAILURE);	/* error (already logged)	*/
    }
  else
    {				/* FC is empty so rollback changes	*/
    tdl_ctxt->tdlptr = save_start;		/* restore orig ptr		*/
    tdl_ctxt->len_avail = save_avail;	/* restore orig len		*/
    *save_start = '\0';			/* write NULL at orig ptr	*/
    }

  return (SD_SUCCESS);		/* this is only "good" return	*/
  }	/* end tdladd_fc	*/
/************************************************************************/
/*			tdladd_rp_or_br					*/
/* RETURNS:	SD_SUCCESS or error code				*/
/* Add the TDL for special FC=RP or FC=BR at the current pointer	*/
/* (tdl_ctxt->tdlptr).							*/
/* Increase (tdl_ctxt->tdlptr) by the number of bytes added.		*/
/* Decrease (tdl_ctxt->len_avail) by the number of bytes added.		*/
/* CRITICAL: Last arg "buffered" must be SD_TRUE or SD_FALSE (other	*/
/*           non-zero values NOT treated the same as SD_TRUE).		*/
/************************************************************************/
static ST_RET tdladd_rp_or_br (
	TDLADD_CTXT *tdl_ctxt,
	SCL_INFO *scl_info,
	SCL_LNTYPE *scl_lntype,
	SCL_LN *scl_ln,
	ST_BOOLEAN buffered)	/* SD_TRUE to add "buffered" reports	*/
				/* SD_FALSE to add "unbuffered" reports	*/
				/* CRITICAL: no other values allowed	*/
  {
SCL_RCB *scl_rcb;
SCL_RCB_COUNTERS scl_rcb_counters;
SCL_DATASET *scl_dataset;
ST_RET retcode = SD_SUCCESS;
ST_INT count = 0;

  /* CRITICAL: start with all 0 in struct.	*/
  memset (&scl_rcb_counters, 0, sizeof (scl_rcb_counters));

  for (scl_rcb = (SCL_RCB *) list_find_last ((DBL_LNK *) scl_ln->rcbHead);
       scl_rcb != NULL;
       scl_rcb = (SCL_RCB *) list_find_prev ((DBL_LNK *) scl_ln->rcbHead, (DBL_LNK *) scl_rcb))
    {
    /* If RCB doesn't match the kind we're looking for, ignore it.	*/
    if (scl_rcb->buffered != buffered)
      continue;

    scl_dataset = scl_find_dataset (scl_ln, scl_rcb->datSet);
    if (scl_dataset == NULL)
      {
      SXLOG_ERR1 ("tdladd_rp_or_br: datSet='%s' not found", scl_rcb->datSet);
      return (SD_FAILURE);
      }

    /* NOTE: if NOT the type we're looking for, never get here (see 'continue' above)*/
    /* NOTE: don't chk every tdladd.. return. If one call fails, subsequent calls fail too.*/
    if (buffered)	/* looking for buffered & this is buffered	*/
      {
      if (count==0)
        tdladd_string (tdl_ctxt, "(BR){\n");	/* first one needs (BR)	*/
      }
    else		/* looking for unbuffered & this is unbuffered	*/
      {
      if (count==0)
        tdladd_string (tdl_ctxt, "(RP){\n");	/* first one needs (RP)	*/
      }
    tdladd_string (tdl_ctxt, "(");
    tdladd_string (tdl_ctxt, scl_rcb->name);

    if (tdladd_string (tdl_ctxt, ")")!=SD_SUCCESS)
      return (SD_FAILURE);	/* error (already logged)	*/

    /* NOTE: if NOT the type we're looking for, never get here (see 'continue' above)*/
    if (buffered)	/* looking for buffered & this is buffered	*/
      retcode = tdladd_string (tdl_ctxt, brcb_tdl);
    else		/* looking for unbuffered & this is unbuffered	*/
      retcode = tdladd_string (tdl_ctxt, urcb_tdl);

    if (retcode)		/* if error, stop	*/
      return (retcode);	

    count++;	/* increment count of rcb	*/
    }	/* end loop	*/

  /* If any found, add ending text.	*/
  if (count>0)
    retcode = tdladd_string (tdl_ctxt, "},\n");

  return (retcode);	/* NOTE: may have returned sooner on some errors*/
  }	/* end tdladd_rp_or_br	*/

/************************************************************************/
/* Fixed TDL for defining IEC Setting Group Control Block (sgcb)	*/
/************************************************************************/
ST_CHAR *sgcb_tdl = "{\
(NumOfSG)Ubyte,\
(ActSG)Ubyte,\
(EditSG)Ubyte,\
(CnfEdit)Bool,\
(LActTim)Utctime,\
},\n";	/* TDL for IEC Setting Group Control Block	*/

/************************************************************************/
/*			tdladd_sp					*/
/* RETURNS:	SD_SUCCESS or error code				*/
/* Add the TDL for special FC=SG at the current pointer	*/
/* (tdl_ctxt->tdlptr).							*/
/* Increase (tdl_ctxt->tdlptr) by the number of bytes added.		*/
/* Decrease (tdl_ctxt->len_avail) by the number of bytes added.		*/
/************************************************************************/
static ST_RET tdladd_sp (
	TDLADD_CTXT *tdl_ctxt,
	SCL_INFO *scl_info,
	SCL_LNTYPE *scl_lntype,
	SCL_LN *scl_ln)
  {
SCL_SGCB *scl_sgcb;
ST_INT count = 0;
ST_RET retcode = SD_SUCCESS;

  for (scl_sgcb = (SCL_SGCB *) list_find_last ((DBL_LNK *) scl_ln->sgcbHead);
       scl_sgcb != NULL;
       scl_sgcb = (SCL_SGCB *) list_find_prev ((DBL_LNK *) scl_ln->sgcbHead, (DBL_LNK *) scl_sgcb))
    {
    /* NOTE: don't chk every tdladd.. return. If one call fails, subsequent calls fail too.*/
    tdladd_string (tdl_ctxt, "(SP){\n");	/* first one needs (BR)	*/
    tdladd_string (tdl_ctxt, "(");
    tdladd_string (tdl_ctxt, "SGCB");

    if (tdladd_string (tdl_ctxt, ")")!=SD_SUCCESS)
      return (SD_FAILURE);	/* error (already logged)	*/

    /* NOTE: if NOT the type we're looking for, never get here (see 'continue' above)*/
    retcode = tdladd_string (tdl_ctxt, sgcb_tdl);

    if (retcode)		/* if error, stop	*/
      return (retcode);	

    count++;	/* increment count of rcb	*/
    }	/* end loop	*/

  /* If any found, add ending text.	*/
  if (count>0)
    retcode = tdladd_string (tdl_ctxt, "},\n");

  return (retcode);	/* NOTE: may have returned sooner on some errors*/
  }	/* end tdladd_sp	*/

/************************************************************************/
/*			tdladd_lg					*/
/* RETURNS:	SD_SUCCESS or error code				*/
/* Add the TDL for special FC=LG at the current pointer (tdl_ctxt->tdlptr).*/
/* Increase (tdl_ctxt->tdlptr) by the number of bytes added.		*/
/* Decrease (tdl_ctxt->len_avail) by the number of bytes added.		*/
/* NOTE: OptFlds in 61850-7-2 not mapped to MMS.			*/
/************************************************************************/
ST_CHAR *lcb_tdl = "{\
(LogEna)Bool,\
(LogRef)Vstring65,\
(DatSet)Vstring65,\
(OldEntrTm)Btime6,\
(NewEntrTm)Btime6,\
(OldEnt)Ostring8,\
(NewEnt)Ostring8,\
(OptFlds)BVString10,\
(TrgOps)BString6,\
(IntgPd)Ulong,\
},\n";	/* TDL for LCB (IEC Log Control Block)	*/

static ST_RET tdladd_lg (
	TDLADD_CTXT *tdl_ctxt,
	SCL_INFO *scl_info,
	SCL_LNTYPE *scl_lntype,
	SCL_LN *scl_ln)
  {
SCL_LCB *scl_lcb;
SCL_DATASET *scl_dataset;
ST_RET retcode = SD_SUCCESS;
ST_INT count = 0;

  for (scl_lcb = (SCL_LCB *) list_find_last ((DBL_LNK *) scl_ln->lcbHead);
       scl_lcb != NULL;
       scl_lcb = (SCL_LCB *) list_find_prev ((DBL_LNK *) scl_ln->lcbHead, (DBL_LNK *) scl_lcb))
    {
    scl_dataset = scl_find_dataset (scl_ln, scl_lcb->datSet);
    if (scl_dataset == NULL)
      {
      SXLOG_ERR1 ("tdladd_lg: datSet='%s' not found", scl_lcb->datSet);
      return (SD_FAILURE);
      }

    if (count==0)
      retcode = tdladd_string (tdl_ctxt, "(LG){\n(");	/* first one needs (LG)	*/
    else
      retcode = tdladd_string (tdl_ctxt, "(");

    if (retcode)		/* if error, stop	*/
      return (retcode);

    /* Add lcb name as component name.*/  
    if (tdladd_string (tdl_ctxt, scl_lcb->name)!=SD_SUCCESS)
      return (SD_FAILURE);	/* error (already logged)	*/

    if (tdladd_string (tdl_ctxt, ")")!=SD_SUCCESS)	/* add end of comp name	*/
      return (SD_FAILURE);	/* error (already logged)	*/

    retcode = tdladd_string (tdl_ctxt, lcb_tdl);

    if (retcode)		/* if error, stop	*/
      return (retcode);	

    count++;	/* increment count of lcb	*/
    }	/* end loop	*/

  /* If any found, add ending text.	*/
  if (count>0)
    retcode = tdladd_string (tdl_ctxt, "},\n");

  return (retcode);	/* NOTE: may have returned sooner on some errors*/
  }	/* end tdladd_lg	*/

/************************************************************************/
/*			tdladd_go_or_gs					*/
/* RETURNS:	SD_SUCCESS or error code				*/
/* Add the TDL for special FC=GO or FC=GS at the current pointer	*/
/* (tdl_ctxt->tdlptr).							*/
/* Increase (tdl_ctxt->tdlptr) by the number of bytes added.		*/
/* Decrease (tdl_ctxt->len_avail) by the number of bytes added.		*/
/************************************************************************/
ST_CHAR *gcb_tdl = "{\
(GoEna)Bool,\
(GoID)Vstring65,\
(DatSet)Vstring65,\
(ConfRev)Ulong,\
(NdsCom)Bool,\
(DstAddress){\
  (Addr)Ostring6,\
  (PRIORITY)Ubyte,\
  (VID)Ushort,\
  (APPID)Ushort,\
},\
(Mode)Ubyte,\
},\n";	/* TDL for GCB (GOOSE Control Block)	*/

ST_CHAR *scb_tdl = "{\
(GsEna)Bool,\
(GsID)Vstring65,\
(DNALabels)[32:Vstring65],\
(UserSTLabels)[128:Vstring65],\
(LSentData) {\
  (GsID)Vstring65,\
  (t)Btime6,\
  (SqNum)Ulong,\
  (StNum)Ulong,\
  (TAL)Ulong,\
  (usec)Ulong,\
  (PhsID)Ushort,\
  (DNA)Bstring64,\
  (UserST)Bstring256,\
},\
},\n";	/* TDL for SCB (GSSE Control Block)	*/

static ST_RET tdladd_go_or_gs (
	TDLADD_CTXT *tdl_ctxt,
	SCL_INFO *scl_info,
	SCL_LNTYPE *scl_lntype,
	SCL_LN *scl_ln,
	ST_BOOLEAN isGoose)	/* SD_TRUE to add GOOSE (FC=GO)		*/
				/* SD_FALSE to add GSSE (FC=GS)		*/
				/* CRITICAL: no other values allowed	*/
  {
SCL_GCB *scl_gcb;
SCL_DATASET *scl_dataset;
ST_RET retcode = SD_SUCCESS;
ST_INT count = 0;

  for (scl_gcb = (SCL_GCB *) list_find_last ((DBL_LNK *) scl_ln->gcbHead);
       scl_gcb != NULL;
       scl_gcb = (SCL_GCB *) list_find_prev ((DBL_LNK *) scl_ln->gcbHead, (DBL_LNK *) scl_gcb))
    {
    /* If GCB doesn't match the kind we're looking for, ignore it.	*/
    if (scl_gcb->isGoose != isGoose)
      continue;

    /* NOTE: if NOT the type we're looking for, never get here (see 'continue' above)*/
    if (scl_gcb->isGoose)
      {
      /* GOOSE needs dataset. Find it now.	*/
      scl_dataset = scl_find_dataset (scl_ln, scl_gcb->datSet);
      if (scl_dataset == NULL)
        {
        SXLOG_ERR1 ("tdladd_go_or_gs: datSet='%s' not found", scl_gcb->datSet);
        return (SD_FAILURE);
        }

      if (count==0)
        retcode = tdladd_string (tdl_ctxt, "(GO){\n(");	/* first one needs (GO)	*/
      else
        retcode = tdladd_string (tdl_ctxt, "(");
      }
    else
      {
      if (count==0)
        retcode = tdladd_string (tdl_ctxt, "(GS){\n(");	/* first one needs (GS)	*/
      else
        retcode = tdladd_string (tdl_ctxt, "(");
      }

    if (retcode)		/* if error, stop	*/
      return (retcode);

    /* Add gcb name as component name.*/  
    if (tdladd_string (tdl_ctxt, scl_gcb->name)!=SD_SUCCESS)
      return (SD_FAILURE);	/* error (already logged)	*/

    if (tdladd_string (tdl_ctxt, ")")!=SD_SUCCESS)	/* add end of comp name	*/
      return (SD_FAILURE);	/* error (already logged)	*/

    /* NOTE: if NOT the type we're looking for, never get here (see 'continue' above)*/
    if (scl_gcb->isGoose)	/* looking for GOOSE & this is GOOSE	*/
      retcode = tdladd_string (tdl_ctxt, gcb_tdl);
    else			/* looking for GSSE & this is GSSE	*/
      retcode = tdladd_string (tdl_ctxt, scb_tdl);

    if (retcode)		/* if error, stop	*/
      return (retcode);	

    count++;	/* increment count of gcb	*/
    }	/* end loop	*/

  /* If any found, add ending text.	*/
  if (count>0)
    retcode = tdladd_string (tdl_ctxt, "},\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -