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

📄 u_data.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************************************//* SISCO SOFTWARE MODULE HEADER *****************************************//************************************************************************//*   (c) Copyright Systems Integration Specialists Company, Inc.,	*//*      	  1986 - 2002, All Rights Reserved.		        *//*									*//* MODULE NAME : u_data.c						*//* PRODUCT(S)  : MMSEASE						*//*									*//* MODULE DESCRIPTION : 						*//*	User defined data handling functions				*//*									*//* GLOBAL FUNCTIONS DEFINED IN THIS MODULE :				*//*									*//* MODIFICATION LOG :							*//*  Date     Who   Rev			Comments			*//* --------  ---  ------   -------------------------------------------	*//* 07/29/02  EJV     25    MMS_UTC_TIME: chg qflags value.		*//* 07/03/02  EJV     24    MMS_UTC_TIME: chg name usec to fraction.	*//* 02/07/02  EJV     23    Closed comment.				*//* 01/31/02  EJV     22    Added support for DOM_SPEC journals		*//* 11/29/01  EJV     21    Del code for old LATT, XENIX, ultrix, RMX86.	*//* 11/14/01  EJV     20    Added support for new MMS type UtcTime:	*//*			   Added utc_time_now var in set_user_vars	*//*			   arb_init_ctrl[]: added initUtc		*//* 03/23/01  EJV     19    UNIX: added typecast to elim compilation warn*//* 03/22/01  EJV     18    Added else after ms_add_named_var-Temperature*//* 01/11/00  RKR     17    added block variable support			*//* 02/22/99  EJV     16    _AIX   ST_INT64 constant must end with LL.	*//* 08/28/98  EJV     15    __hpux ST_INT64 constant must end with LL.	*//* 			   __hpux ST_INT64 addr starts on 8-byte boundry*//* 08/04/98  RKR     14    Fixed init time of BTOD variables		*//* 07/06/98  NAV     13    Add Journal Configuration			*//* 01/28/98  EJV     12    Changed 1 arg to ST_INT32 initBt4, initBt6	*//* 01/16/98  RKR     11    Cleaned up some warnings                 	*//* 11/19/97  RKR     10    64-bit integer examples                      *//* 10/21/97  JRB     09    address_string must be array (not ptr).	*//* 10/16/97  RKR     08    Changed Y2K BTOD6 to an Array of ST_INT32	*//* 10/09/97  RKR     07    Repositioned named variables for MMS time	*//* 09/11/97  MDE     06    MMS ARB user funs now return ST_RET		*//* 09/04/97  RKR     05    Added mem_chk statistics			*//* 08/28/97  RKR     04    Changed error handling of cfg functions      *//* 06/17/97  RKR     03    Added Y2K_Gtime and Y2K_BTOD6		*//* 06/09/97  MDE     02    Changes to Runtime Type handling 		*//* 05/14/97  DSF     01    Cleaned up compilation warnings      	*//* 04/15/97  DSF   7.00    MMSEASE 7.0 release. See MODL70.DOC for	*//*			   history.					*//************************************************************************/#include "glbtypes.h"#include "sysincs.h"#if (SYSTEM_SEL & (SYS_5))#include <signal.h>#endif#include "mms_usr.h"#include "mms_pprg.h"#include "mms_vprg.h"#include "mms_pdom.h"#include "mms_vdom.h"#include "mms_pvar.h"#include "mms_vvar.h"#include "mms_vvmd.h"#include "mms_vjou.h"#include "userdefs.h"	      #include "cfg_util.h"#include "mem_chk.h"#include "mmsop_en.h"#include "fkeydefs.h"/************************************************************************//* For debug version, use a static pointer to avoid duplication of 	*//* __FILE__ strings.							*//************************************************************************/#ifdef DEBUG_SISCOstatic ST_CHAR *thisFileName = __FILE__;#endif/************************************************************************//************************************************************************//*			set_user_data					*//* Function to allocate large user data items, to conserve static data	*//* space.								*//************************************************************************/ST_VOID set_user_data (ST_VOID)  {  dest_buffer = chk_calloc (1,10000);/* allocate 'dest_buffer'      */  source_buf = chk_calloc (1,1020);  /* allocate 'source_buf'       */  tbuf = chk_calloc (1,1020);  	       }/************************************************************************//* Allow exclusion of all variable access MMSEASE code if not needed	*//************************************************************************/#if MMS_VA_EN		/* if any variable access stuff enabled 	*/#if (SYSTEM_SEL & (SYS_5))/************************************************************************//*                         increment_variables                          *//* This is a function installed as the thing to do when a Unix timer	*//* expires.  Code to arm the timer is elsewhere in mmsapp.c.		*//* Each time this function is called it will increment NamedVariables 	*//* 'short0' through 'short499', 'Temperature', 'Air_Pressure', and a	*//* domain specific variable named 'Flex_Gage:Y_Dimension'.		*//************************************************************************/ST_VOID increment_variables (int sig)  {ST_INT	i;ST_CHAR	var_name[ MAX_IDENT_LEN + 1 ];NAMED_VAR	*var_ptr;ST_CHAR *addr;ST_INT16	*short_ptr;ST_INT16	t16;ST_FLOAT	tfloat;/* This loop increments Named Variables 'short0' through 'short499'	*//* which are normally added to the application when reading in the 	*//* mmsvar.cfg.								*/  for (i = 0; i < 500; i++)    {    sprintf (var_name, "short%d", i);    var_ptr = ms_find_named_var (&m_vmd_select->vmd_wide, var_name);    if (var_ptr != NULL)      {      addr = u_get_named_addr (var_ptr);      if (addr != NULL)        {        short_ptr = (ST_INT16 *)(addr);        t16 = *(short_ptr);        *short_ptr = (ST_INT16)(t16 + 1);        }      }    }/* This code bumps up the value of some favorite Named Variables	*/  t16 = *((ST_INT16*)(logical_mem +64));  /* Temperature */  *((ST_INT16 *)(logical_mem + 64)) = t16 + 1;  t16 = *((ST_INT16*)(logical_mem +66));  /* Air_Pressure */  *((ST_INT16 *)(logical_mem + 66)) = t16 + 1;  tfloat = *((ST_FLOAT*)(logical_mem +76));  /* Flex_Gage.Y_Dimension */  *((ST_FLOAT *)(logical_mem + 76)) = tfloat + (ST_FLOAT)1.1;  sigset (SIGALRM, increment_variables);  }#endif/************************************************************************//*			u_get_named_addr				*//* User function to translate variable def structure to physical addr	*//* Return 0 for fail, otherwise return a pointer to data area. This is	*//* called by the virtual machine when servicing read or write requests	*//* (mv_read_resp, mv_write_resp).					*//*									*//* In this sample application, a 'logical' address space has been       *//* defined (in uservar.c, userdefs.h). Treat symbolic address items as	*//* character string that represents offset into this space.		*//* Numeric addresses are treated as pointers.				*//* Unconstrained addresses not really treated here, just return base	*//* address of the logical buffer.					*//************************************************************************/ST_CHAR *u_get_named_addr (NAMED_VAR *vardef)  {ST_INT offset;ST_CHAR	*byte_addr;  switch (vardef->addr.addr_tag)    {    case NUM_ADDR : 		/* numeric address			*/				/* assume this is a long pointer	*/				/* this is machine specific operation	*/      return ((ST_CHAR *) vardef->addr.addr.num_addr);    break;    case SYM_ADDR : 		/* symbolic address			*/      /* Let's see if this is a pointer in disguise or just somebody	*/      /* living in the symbol table.					*/      /* When the second character of the address is an 'x' or 'X'	*/      /* then we believe that this is a pointer converted into a string.*/      if ((vardef->addr.addr.sym_addr[ 1 ] == 'x') ||           (vardef->addr.addr.sym_addr[ 1 ] == 'X'))        {        /* format of the symbolic address is "Ox[a hexadecimal pointer]"*/        /* therefore the value of the pointer is contained staring at	*/        /* byte 2 and continuing through to the end of the string.	*/        sscanf (&vardef->addr.addr.sym_addr[2], "%p", &byte_addr);        return (byte_addr);        }      else        { 	/* assume ST_CHAR string = offset into				*/        offset = atoi (vardef->addr.addr.sym_addr); /* user defined space */        if (offset > log_mem_len || offset < 0) /* check for bad offset	*/	  return ((ST_CHAR *) 0);        if (offset > log_mem_len) 	/* make sure not too long	*/	  return ((ST_CHAR *) 0);        return (logical_mem + offset);        }    break;    case UNCON_ADDR :	 	/* unconstrained address		*/      return ((ST_CHAR *) vardef->addr.addr.unc_addr.unc_ptr);    break;    }  return (NULL);		/* not valid form			*/  }/************************************************************************//* Domain names used in the demo					*/static ST_CHAR dom_1[] = "Flex_Gage";static ST_CHAR dom_2[] = "A_Application";static ST_CHAR dom_3[] = "Z_Application";static ST_CHAR dom_4[] = "Robot";/************************************************************************//*			set_user_pis					*//* Function to create named program invocations for the sample appl'n. 	*//************************************************************************/ST_VOID set_user_pis (ST_VOID)  {ST_CHAR *dname_list[3];PROG_INV *pi_ptr;  dname_list[0] = dom_1;  dname_list[1] = dom_2;  dname_list[2] = dom_3;  if ((pi_ptr = ms_add_pi ("Sisco_pi",3,dname_list,0xff)) == NULL)    wait_msg ("PI ADD FAILURE ");  pi_ptr->start_arg = chk_calloc (1, 120);  strcpy ((ST_CHAR *) pi_ptr->start_arg,   "this is a fake argument meant to be passed to a fake program.  No one is sure of it's meaning or how to get it done.");  pi_ptr->start_len = 118;  dname_list[0] = dom_1;  dname_list[1] = dom_2;  dname_list[2] = dom_3;  if ((pi_ptr = ms_add_pi ("PI_number_2",3,dname_list,0xff)) == NULL)    wait_msg ("PI ADD FAILURE ");  pi_ptr->start_arg = chk_calloc (1, 30);  strcpy ((ST_CHAR *)pi_ptr->start_arg, "this is shorter argument.");  pi_ptr->start_len = 26;  }/************************************************************************//*			set_user_doms					*//* Function to create named domains for the sample application. 	*//************************************************************************/ST_VOID set_user_doms (ST_VOID)  {INITDOWN_REQ_INFO *dom_info = NULL;ST_CHAR	**capab_list_ptr;/* allocate enough memory to contain the domain info, and a  capab ptr 	*//* array of four capabilities						*/  dom_info = (INITDOWN_REQ_INFO *)             chk_calloc (1,sizeof (INITDOWN_REQ_INFO) + 	               (sizeof (ST_CHAR **) * 4));  strcpy (dom_info->dname, dom_1);  /* Flex_Gage	*/  dom_info->sharable = SD_TRUE;  dom_info->num_of_capab = 3;  capab_list_ptr = (ST_CHAR **)(dom_info + 1);  *capab_list_ptr = "read/write memory";  capab_list_ptr++;  *capab_list_ptr = "physical I/O";  capab_list_ptr++;  *capab_list_ptr = "set own priv";  if (!ms_add_named_domain (dom_info, 0x7F))     wait_msg ("NAMED DOMAIN ADD FAILURE");  strcpy (dom_info->dname, dom_3);	/* Z_Application	*/  dom_info->sharable = SD_TRUE;  dom_info->num_of_capab = 0;  if (!ms_add_named_domain (dom_info, 0x7F))     wait_msg ("NAMED DOMAIN ADD FAILURE");  strcpy (dom_info->dname, dom_2);  /* A_Application	*/  dom_info->sharable = SD_TRUE;  dom_info->num_of_capab = 2;  capab_list_ptr = (ST_CHAR **)(dom_info + 1);  *capab_list_ptr = "delete directory";  capab_list_ptr++;  *capab_list_ptr = "automatic overdraft";  if (!ms_add_named_domain (dom_info,0x7F))     wait_msg ("NAMED DOMAIN ADD FAILURE");  strcpy (dom_info->dname, dom_4);	/* Robot 	*/  dom_info->sharable = SD_TRUE;  dom_info->num_of_capab = 0;  if (!ms_add_named_domain (dom_info,0x7F))     wait_msg ("NAMED DOMAIN ADD FAILURE");  chk_free (dom_info);  }/************************************************************************//*			set_user_types					*//* Function to set up the type definitions required for the application *//* just do VMD specific types for now.					*//************************************************************************/ST_VOID set_user_types (ST_VOID)  {  if (ms_add_std_types (&m_vmd_select->vmd_wide))    wait_msg ("Problem Adding Standard Types");/* Add a type for generalized time					*/  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "GeneralizedTime",                         (ST_UCHAR*)"\x8b\x00",2))    wait_msg ("Problem Adding Gtime");/* And types for BinaryTimeOfDay lengths 4 and 6			*/  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "BinaryTimeOfDay4",                         (ST_UCHAR*)"\x8c\x01\x00",3))    wait_msg ("Problem Adding BTOD4");  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "BinaryTimeOfDay6",                         (ST_UCHAR*)"\x8c\x01\x01",3))    wait_msg ("Problem Adding BTOD6");  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "UtcTime",                         (ST_UCHAR*)"\x91\x00",2))    wait_msg ("Problem Adding UtcTime");#ifdef INT64_SUPPORT/* 64 bit integer support                                               */  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "Integer64",                         (ST_UCHAR*)"\x85\x01\x40",3))    wait_msg ("Problem Adding Integer64");  if (!ms_add_named_type (&m_vmd_select->vmd_wide, "Unsigned64",                         (ST_UCHAR*)"\x86\x01\x40",3))    wait_msg ("Problem Adding Unsigned64");#endif  }/************************************************************************//*			set_user_vars					*//* Function to add sample application variable names to name table.	*//* Before these names can be added, the type names used must have been	*//* registered.								*//************************************************************************/ST_DOUBLE doubleVar;ST_FLOAT floatVar;ST_VOID set_user_vars (ST_VOID)  {VAR_ACC_ADDR adr;DOMAIN_OBJS  *dom;OBJECT_NAME  type;NAMED_DOM_CTRL *ndom;VARIABLE_LIST	*var_list_ptr;VARIABLE_LIST   *var_list_idx;time_t clock_time;MMS_UTC_TIME    *utc_time_now;ST_CHAR address_string [40];ST_INT32	milliseconds_today;ST_INT32	days_since_84; NAMED_TYPE	*tptr;/* Create the logical memory space					*/  logical_mem = chk_malloc (log_mem_len);/* All types are VMD wide						*//* All are symbolic Addresses						*/  type.object_tag = 0;		/* select VMD scope type		*/  adr.addr_tag = SYM_ADDR; 	/* select symbolic address		*//* First VMD wide variables, select the domain obj's structure          */  dom = &m_vmd_select->vmd_wide;/* add all as VMD scope 		*/				/* using VMD scope standard types	*/  adr.addr.sym_addr = "000";            /* 00 byte offset               */  strcpy (type.obj_name.vmd_spec,"String64");      /* select type       */  if (!ms_add_named_var (dom,"VMD_Name",&type,&adr,0))     wait_msg ("Local Variable Name ADD FAILURE");  else     strcpy (logical_mem + atoi (adr.addr.sym_addr),				"Virtual_Manufacturing_Device_#1");/* Add a Double and a Float for direct access				*/  adr.addr_tag = NUM_ADDR; 	  /* select numeric address		*/  adr.addr.num_addr = (ST_ULONG) &doubleVar;  strcpy (type.obj_name.vmd_spec,"Double");     /* select type       */  if (!ms_add_named_var (dom,"doubleVar",&type,&adr,0))     wait_msg ("doubleVar Variable Name ADD FAILURE");  doubleVar = 1.0000001;  adr.addr.num_addr = (ST_ULONG) &floatVar;  strcpy (type.obj_name.vmd_spec,"Float");     /* select type       */  if (!ms_add_named_var (dom,"floatVar",&type,&adr,0))     wait_msg ("floatVar Variable Name ADD FAILURE");  floatVar = (ST_FLOAT)10001000100010001.00010001;

⌨️ 快捷键说明

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