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

📄 u_ijou.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 5 页
字号:
    ret = ms_locl_to_asn1 (aCtx, pstType, dataSrc);    if (!ret)      {      asn1Start = aCtx->asn1r_field_ptr+1;      asn1Len = (asn1Buf + asn1BufSize) - asn1Start;      currVarInfo->value_spec.len = asn1Len;      tmp = chk_malloc (asn1Len);      memcpy (tmp, asn1Start, asn1Len);      currVarInfo->value_spec.data = tmp;      currVarInfo++;      }    else      {      SLOGALWAYS0 ("Encoding Problem");      printf ("\nEncoding Failure.");      cfg_set_config_err ();      }    }  else    {    SLOGALWAYS1 ("Can't find type %s", currVarTypeName);    printf ("\nCan't find type %s", currVarTypeName);    cfg_set_config_err ();    }	  }/************************************************************************//* cfgEndVars:  handle keyword EndVars%					*//************************************************************************/static ST_VOID cfgEndVars (ST_VOID)  {  if (cfg_tbl_pop (1) != SD_SUCCESS)    cfg_set_config_err ();  }/************************************************************************//* cfgEndEntry:  handle keyword %EndEntry				*//************************************************************************/static ST_VOID cfgEndEntry (ST_VOID)  {JOURNAL_ENTRY *pstJE;int entrySize, numVars;VAR_INFO *pstVarInfo;ST_UCHAR *tmp;  if (cfg_tbl_pop (1) != SD_SUCCESS)    cfg_set_config_err ();  /* stash the entry in the local journal	*/  if (entryCtrl->bInProgress && !entryCtrl->bDiscardEntry)    {    if (entryCtrl->currEntry.orig_ae_len == 0)      {      tmp = chk_malloc (2);      tmp[0] = 0x30;      tmp[1] = 0x00;      entryCtrl->currEntry.orig_ae_len = 2;      entryCtrl->currEntry.orig_ae = tmp;      }    numVars = entryCtrl->numVars;    entrySize = sizeof (JOURNAL_ENTRY) + numVars * sizeof (VAR_INFO);    pstJE = chk_malloc (entrySize);    pstLocalJrnl[localJrnlLevel++] = pstJE;    memcpy (pstJE, &entryCtrl->currEntry, sizeof (JOURNAL_ENTRY));    if (numVars > 0)      {      pstVarInfo = (VAR_INFO *) (pstJE + 1);      memcpy (pstVarInfo, entryCtrl->aPtr, (numVars * sizeof (VAR_INFO)));      }    }  else    {    if (entryCtrl->aPtr)		      {      chk_free (entryCtrl->aPtr);      entryCtrl->aPtr = NULL;      }    freeJournalEntry (&entryCtrl->currEntry);    }  entryCtrl->bInProgress = SD_FALSE;  }/************************************************************************//* cfgEndJrnl:  handle keyword %EndJrnl					*//************************************************************************/static ST_VOID cfgEndJrnl (ST_VOID)  {  if (cfg_tbl_pop (1) != SD_SUCCESS)    cfg_set_config_err ();  cfg_set_endfile_ok ();  }/************************************************************************//* freeLocalJrnl:  clean up memory associated with the local journal	*//************************************************************************/static ST_VOID freeLocalJrnl (ST_VOID)  {JOURNAL_ENTRY *pstJE;int i;  for (i=0; i<localJrnlLevel; i++)    {    pstJE = pstLocalJrnl[i];    pstLocalJrnl[i] = NULL;    if (pstJE)      {      freeJournalEntry (pstJE);      chk_free (pstJE);      }    }  localJrnlLevel = 0;  }/************************************************************************//* freeJournalEntry:  clean up memory associated with a JOURNAL_ENTRY	*//************************************************************************/static ST_VOID freeJournalEntry (JOURNAL_ENTRY *pstJE)  {ENTRY_CONTENT *pstContent;  if (pstJE->entry_id_len > 0)    chk_free (pstJE->entry_id);  if (pstJE->orig_ae_len > 0)    chk_free (pstJE->orig_ae);  pstContent = &pstJE->ent_content;  if (pstContent->entry_form_tag == 3)    chk_free (pstContent->ef.annotation);  }/************************************************************************//* compareMmsBtod:  compare to MMS_BTOD dates and return:		*//*			-1 if btod1 < btod2				*//*			 0 if btod1 = btod2				*//*			 1 if btod1 > btod2				*//************************************************************************/static ST_INT compareMmsBtod (MMS_BTOD *btod1, MMS_BTOD *btod2)  {ST_INT32 msec1, msec2, days1, days2, days84;  days84 = calc_days_since_1184 ();    if (btod1->form == MMS_BTOD4)    days1 = days84;  else    days1 = btod1->day;  msec1 = btod1->ms;  if (btod2->form == MMS_BTOD4)    days2 = days84;  else    days2 = btod2->day;  msec2 = btod2->ms;  if (days1 < days2)    return -1;  if (days1 > days2)    return 1;  if (msec1 < msec2)    return -1;  if (msec1 > msec2)    return 1;  return 0;  }/************************************************************************//* findVarTag:  search TagList for varTag				*//************************************************************************/static ST_BOOLEAN findVarTag (ST_CHAR *varTag, ST_INT numVars, 			      ST_CHAR **ppTagList)  {int i = 0;ST_CHAR **pTemp;ST_BOOLEAN bFound = SD_FALSE;  pTemp = ppTagList;  while (i<numVars && !bFound)    {    if (strcmp (varTag, *pTemp) == 0)      bFound = SD_TRUE;    else      {      pTemp++;      i++;      }    }  return (bFound);  }/************************************************************************//* getFirstTS:  search the local journal for the first occurence time	*//*		greater than or equal to give time.  return value of	*//*		-1 indicates not found					*//************************************************************************/static ST_INT getFirstTS (MMS_BTOD *btod, ST_INT level)  {int i;ST_BOOLEAN bDone = SD_FALSE;  i = level;  while (i<localJrnlLevel && !bDone)    {    if (compareMmsBtod (&pstLocalJrnl[i]->ent_content.occur_time,    			btod) >= 0)      bDone = SD_TRUE;    else      i++;    }  if (bDone)    return (i);  else    return (-1);  }/************************************************************************//* getLastTS:  search the local journal for the last occurence of occur	*//*	       time - if not found - return -1;				*//************************************************************************/static ST_INT getLastTS (MMS_BTOD *btod)  {int i;ST_BOOLEAN bDone = SD_FALSE;  i = localJrnlLevel-1;  while (i >= 0 && !bDone)    {    if (compareMmsBtod (&pstLocalJrnl[i]->ent_content.occur_time,    			btod) <= 0)      bDone = SD_TRUE;    else      i--;    }  if (bDone)    return (i);  else    return (-1);  }/************************************************************************//* writeLocalJrnl:							*//************************************************************************/static ST_VOID writeLocalJrnl (JOURNAL *pstJrnl)  {FILE *fp;int i;  fp = fopen (pstJrnl->usr, "w");  if (!fp)    {    SLOGALWAYS1 ("Write Local Journal - Error opening file %s", pstJrnl->usr);    }  else    {    fprintf (fp, "%%BeginJournal\n");    for (i=0; i<localJrnlLevel; i++)      {      if (pstLocalJrnl[i] != NULL)        writeLocalJE (fp, pstLocalJrnl[i]);      }    fprintf (fp, "%%EndJournal\n");    fclose (fp);    }  }/************************************************************************//* writeLocalJE:  take data from JOURNAL_ENTRY struct and put it in	*//*		  cfg text file.					*//************************************************************************/static ST_VOID writeLocalJE (FILE *fp, JOURNAL_ENTRY *pstJE)  {ENTRY_CONTENT *pstEC;APP_REF stAppRef;char temp[1024], dataBuf[65];ST_RET rtnCode;OBJECT_NAME *pstObj;int i;VAR_INFO *pstVarInfo;RUNTIME_TYPE *rt;ST_INT rtNum, intData;NAMED_TYPE *pstType;ST_DOUBLE dblData;ST_BOOLEAN bIsInt, bIsDbl, bIsStr;  pstEC = &pstJE->ent_content;  /* write the entry id							*/  memcpy (temp, pstJE->entry_id, pstJE->entry_id_len);  temp[pstJE->entry_id_len]=0;  fprintf (fp, "  %%BeginEntry\n");  fprintf (fp, "    EntryID=%s\n", temp);  /* write entry originator identification				*/  ms_asn1_to_appref (&stAppRef, pstJE->orig_ae, pstJE->orig_ae_len);  rtnCode = ms_appref_to_arname (temp, &stAppRef);  if (rtnCode)    strcpy (temp, "UNKNOWN");  fprintf (fp, "    OrigAR=%s\n", temp);  /* write occurence time						*/  if (pstEC->occur_time.form == MMS_BTOD4)    {    if (Btime4ValsToString (temp, pstEC->occur_time.ms) == SD_SUCCESS)      fprintf (fp, "    OccurTime=%s\n", temp);    else      fprintf (fp, "    OccurTime=InvalidBtime4\n");    }  else if (pstEC->occur_time.form == MMS_BTOD6)    {    if (Btime6ValsToString (temp, pstEC->occur_time.day,     			    pstEC->occur_time.ms) == SD_SUCCESS)      fprintf (fp, "    OccurTime=%s\n", temp);    else      fprintf (fp, "    OccurTime=InvalidBtime6\n");    }  else    fprintf (fp, "    OccurTime=InvalidMMS_BTOD\n");  if (pstEC->entry_form_tag == 3)		/* annotation	*/    {    fprintf (fp, "    Annotation=%s\n", pstEC->ef.annotation);    }  else    {    /* write event data						*/    if (pstEC->ef.data.event_pres)      {      pstObj = &pstEC->ef.data.evcon_name;      switch (pstObj->object_tag)        {        case VMD_SPEC:          fprintf (fp, "    EventName=%s\n", pstObj->obj_name.vmd_spec);      	  fprintf (fp, "    EventScope=VMD\n");	  break;        case DOM_SPEC:          fprintf (fp, "    EventName=%s\n", pstObj->obj_name.item_id);	  fprintf (fp, "    EventScope=DOM\n");	  fprintf (fp, "    EventDomain=%s\n", pstObj->domain_id);	  break;        case AA_SPEC:          fprintf (fp, "    EventName=%s\n", pstObj->obj_name.aa_spec);	  fprintf (fp, "    EventScope=AA\n");	  break;        }      switch (pstEC->ef.data.cur_state)        {        case 0:		          fprintf (fp, "    EventState=DISABLED\n");	  break;        case 1:		          fprintf (fp, "    EventState=IDLE\n");	  break;        case 2:          fprintf (fp, "    EventState=ACTIVE\n");	  break;        }      }    /* write variable data						*/    if (pstEC->ef.data.list_of_var_pres && pstEC->ef.data.num_of_var > 0)      {      fprintf (fp, "    NumVars=%d\n", pstEC->ef.data.num_of_var);      fprintf (fp, "    %%BeginVars\n");      pstVarInfo = (VAR_INFO *) (pstJE + 1);      for (i=0; i<pstEC->ef.data.num_of_var; i++, pstVarInfo++)        {	/* derive type from encoded data				*/	rt=NULL;	bIsInt = bIsDbl = bIsStr = SD_FALSE;	if (ms_asn1_data_to_runtime (&rt, &rtNum,				     pstVarInfo->value_spec.data,				     pstVarInfo->value_spec.len)				     == SD_SUCCESS)	  {	  if (rt->el_tag == RT_INTEGER)	    {	    strcpy (temp, "Integer16");	    bIsInt = SD_TRUE;	    }	  else if (rt->el_tag == RT_FLOATING_POINT)	    {	    strcpy (temp, "Double");	    bIsDbl = SD_TRUE;	    }	  else	    {	    strcpy (temp, "Vstring64");	    bIsStr = SD_TRUE;	    }	  }	else	  strcpy (temp, "InvalidType");        pstType = ms_find_named_type (&m_vmd_select->vmd_wide, temp);	if (pstType)	  {	  memset (dataBuf, 0, 65);	  if ( ms_asn1_to_locl (pstType, 				pstVarInfo->value_spec.data,				pstVarInfo->value_spec.len,			        dataBuf) != SD_SUCCESS)	    {	    bIsStr = SD_TRUE;	    bIsInt = bIsDbl = SD_FALSE;	    strcpy (dataBuf, "Decoding Failed");	    }	  }	else	  {	  bIsStr = SD_TRUE;	  bIsInt = bIsDbl = SD_FALSE;	  strcpy (dataBuf, "Type Not Found");	  }	if (bIsStr)	  {	  fprintf (fp, "      VarTag=%s\t| VarType=%s\t | VarData=%s\n",	  	   pstVarInfo->var_tag, temp, dataBuf);	  }	else if (bIsInt)	  {	  memcpy (&intData, dataBuf, sizeof (ST_INT));	  fprintf (fp, "      VarTag=%s\t| VarType=%s\t | VarData=%d\n",	  	   pstVarInfo->var_tag, temp, intData);	  }	else	  {	  memcpy (&dblData, dataBuf, sizeof (ST_DOUBLE));	  fprintf (fp, "      VarTag=%s\t| VarType=%s\t | VarData=%f\n",	  	   pstVarInfo->

⌨️ 快捷键说明

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