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

📄 u_ivar.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************//* SISCO SOFTWARE MODULE HEADER *****************************************//************************************************************************//*   (c) Copyright Systems Integration Specialists Company, Inc.,	*//*      	  1986 - 2002, All Rights Reserved.		        *//*									*//* MODULE NAME : u_ivar.c						*//* PRODUCT(S)  : MMSEASE						*//*									*//* MODULE DESCRIPTION : 						*//*	This module contains user defined code to service variable	*//*	access indications.	 These functions are invoked from	*//*	the 'mms_ind_serve' function, and should perform the request	*//*	action.								*//*									*//* GLOBAL FUNCTIONS DEFINED IN THIS MODULE :				*//*									*//* MODIFICATION LOG :							*//*  Date     Who   Rev			Comments			*//* --------  ---  ------   -------------------------------------------	*//* 08/19/02  EJV     21    __alpha: elim warning in guess_read_resp	*//* 07/03/02  EJV     20    MMS_UTC_TIME: chg name usec to fraction.	*//* 11/14/01  EJV     19    Added support for new MMS type UtcTime:	*//*			   u_read_ind: added changing utc_time_now	*//* 10/19/01  EJV     18    u_read_ind: removed s_chk_sys_resources call	*//* 07/26/01  EJV     17    u_write_ind: replaced chk_malloc(2000) with	*//*			   calculated size.				*//* 03/23/01  EJV     16    UNIX: added typecast to elim compilation warn*//* 12/06/00  RKR     15    Added TEST_CODE to serve unnamed variables	*//* 01/11/00  RKR     14    Added call to update_var_blocks		*//* 01/28/99  EJV     13    Added some sys includes for select() call.	*//* 08/28/98  EJV     12    Added __hpux to pipe flow control code.	*//* 			   __hpux ST_INT64 addr starts on 8-byte boundry*//* 08/04/98  EJV     11    Added check for full pipe in u_read_ind (sun)*//* 08/04/98  RKR     10    changed prototype of calc_mill_since_12	*//* 07/13/98  EJV     09    Added check for full pipe in u_read_ind 	*//* 07/07/98  NAV     08    Remove static from  calc_days_since_1184 	*//* 06/19/98  EJV     07    Moved calc_* functs proto (to eliminate warn)*//* 06/03/98  IKE     07    Removed the bug of -ve miliseconds in DOS	*//*			   fixed no. of days since 84 in DOS platform	*/ /* 05/27/98  IKE     06    Removed the warnings on DOS platform		*//* 11/19/97  RKR     05    64-bit integer examples                      *//* 10/16/97  RKR     04    Changed Y2K BTOD6 to an Array of ST_INT32	*//* 10/09/97  RKR     03    Changes for BinaryTimeofDay			*//* 06/23/97  RKR     02    Changes for arbitrary data handling		*//* 06/17/97  RKR     01    Added code to cross a Y2K boundary		*//* 04/15/97  DSF   7.00    MMSEASE 7.0 release. See MODL70.DOC for	*//*			   history.					*//************************************************************************/#include "glbtypes.h"#include "sysincs.h"#include "mms_usr.h"#include "mms_pvar.h"#include "mms_vvar.h"#include "mms_vvmd.h"#include "userdefs.h"#include "mmsop_en.h"#include "gvaldefs.h"#include "scrndefs.h"#include "fkeydefs.h"#include "mem_chk.h"#if defined (_AIX) || (defined (__alpha) && !defined(__VMS)) || defined (__hpux)#if defined (__alpha)#include <sys/time.h>#endif#if !defined (__hpux)#include <sys/select.h>		/* we need define for fd_set struct */#endif#endif/************************************************************************//* For debug version, use a static pointer to avoid duplication of 	*//* __FILE__ strings.							*//************************************************************************/#ifdef DEBUG_SISCOstatic ST_CHAR *thisFileName = __FILE__;#endif/************************************************************************//************************************************************************/static	ST_BOOLEAN done;	/* used for input loop control	*/static	ST_INT tot_len;		/* used for total string len	*//************************************************************************//************************************************************************//*			VARIABLE ACCESS MANAGEMENT			*//************************************************************************//************************************************************************//* READ 								*//************************************************************************/#if MMS_READ_EN & RESP_EN#define READ_RESP_MODE		(MV_READ_RESP|RD_AUTO_RESP)#define MV_READ_RESP		0x0001	/* use VM if possible		*/#define RD_AUTO_RESP  		0x0004	/* no user intervention req'd	*//*#define TEST_CODE*/ST_VOID u_read_ind (MMSREQ_IND *req_info)  {ST_VOID send_read_resp (ST_VOID);ST_VOID guess_read_resp (MMSREQ_IND *req_info);READ_REQ_INFO  *req_ptr;#if !defined (NO_TEST_VAR_INCREMENT)#ifdef INT64_SUPPORTST_INT64        ti64;ST_UINT64       tu64;#endifST_INT16	ti16;time_t		ti32;ST_FLOAT	tfloat;ST_INT32	milliseconds_today;ST_INT32	days_since_84; MMS_UTC_TIME   *utc_time_now;#elseREAD_RESP_INFO *rsp_info;ACCESS_RESULT  *ar_ptr;VARIABLE_LIST  *vl_ptr;ST_CHAR	*from;ST_CHAR	*to;ST_INT dlen;register i;#endif  req_ptr = (READ_REQ_INFO *) req_info->req_info_ptr;  if (mms_debug_sel & MMS_LOG_USR_IND)    {    indic_info_print (req_info,"Read");    printf ("\n Specification with Result : ");    if (req_ptr->spec_in_result)      printf (" YES");    else      printf (" NO");    print_vaspec (&req_ptr->va_spec);    }    #ifndef NO_TEST_VAR_INCREMENT/* Increment the values of some named variables				*//* Offsets into the symbol table for the named variables 		*//*104 - Gtime  108 - BTOD4  112 - BTOD 6 120 - Y2KGtime  124 - Y2KBTOD6 *//* 132 - UtcTimeNow	*//* The current time in all 3 formats					*/    time (&ti32);    milliseconds_today = calc_mill_since_12();    days_since_84 = calc_days_since_1184();    *((time_t *) (logical_mem + 104)) = ti32;  /* GeneralizedTime	*/    *((ST_INT32 *) (logical_mem + 108)) = milliseconds_today;  /* BTOD4 */    *((ST_INT32 *) (logical_mem + 112)) = milliseconds_today;  /* BTOD6 */    *((ST_INT32 *) (logical_mem + 116)) = days_since_84;       /* BTOD6 */    /* UTC Time */    utc_time_now = (MMS_UTC_TIME *) (logical_mem + 132);    utc_time_now->secs = ti32;  	/* seconds since Jan 1, 1970	*/    utc_time_now->fraction += 1;/* Increment the Y2K time variables					*/    ti32 = *((ST_INT32 *) (logical_mem + 120));     *((time_t *) (logical_mem + 120)) =  ti32 + 1; /* cross a Y2K bound	*/    ti32 = *((ST_INT32 *) (logical_mem + 124));     *((ST_INT32 *) (logical_mem + 124)) =  ti32 + 201; /* ms cross a Y2K bound	*/    ti16 = *((ST_INT16 *) (logical_mem + 64)); /* Temperature		*/    *((ST_INT16 *) (logical_mem + 64)) = ti16 + 1;    ti16 = *((ST_INT16 *) (logical_mem + 66)); /* Air_Pressure		*/    *((ST_INT16 *) (logical_mem + 66)) = ti16 + 1;    tfloat = *((ST_FLOAT *) (logical_mem + 76)); /* Flex_Gage.Y_Dimension	*/    *((ST_FLOAT *) (logical_mem + 76)) = tfloat + (ST_FLOAT) 1.1;#ifdef INT64_SUPPORT/* Increment 64 bit integers                                            */    ti64 = *((ST_INT64 *) (logical_mem + 146)); /* SunTemperature       */    *((ST_INT64 *) (logical_mem + 146)) = ti64 + 1;    tu64 = *((ST_UINT64 *) (logical_mem + 154)); /* HugeCounter         */    *((ST_UINT64 *) (logical_mem + 154)) = tu64 + 1;#endif    update_var_blocks(READ_CTXT);#endif#if READ_RESP_MODE & MV_READ_RESP#if READ_RESP_MODE & RD_AUTO_RESP#if defined(TEST_CODE)  guess_read_resp(req_info);#else  mv_read_resp (req_info);		/* let VM respond		*/#endif#else/* use generalized read response function				*/  wait_msg ("\n Hit a key to enter response data - ");  send_read_resp (req_info);#endif		/* RD_AUTO_RESP */#else  /************ USE PRIMITIVE RESPONDER ****************************/					/* create a default response	*/  rsp_info = (READ_RESP_INFO *) dest_buffer;  if (req_ptr->spec_in_result)    {					/* return specification w/ rslt */    rsp_info->va_spec_pres = SD_TRUE;    rsp_info->va_spec.var_acc_tag = req_ptr->va_spec.var_acc_tag;    if (rsp_info->va_spec.var_acc_tag == 0)      {      rsp_info->va_spec.num_of_variables = req_ptr->va_spec.num_of_variables;      dlen = sizeof (VARIABLE_LIST)*rsp_info->va_spec.num_of_variables;      from = (ST_CHAR *) (req_ptr	+ 1);      to   = (ST_CHAR *) (rsp_info + 1);      memcpy (to, from, dlen);      }    else      {      from = (ST_CHAR *) &req_ptr->va_spec.vl_name.object_tag;      to   = (ST_CHAR *) &rsp_info->va_spec.vl_name.object_tag;      dlen = sizeof (OBJECT_NAME);      memcpy (to, from, dlen);      }    }  else    rsp_info->va_spec_pres = SD_FALSE;  rsp_info->num_of_acc_result = 0;  if (mms_debug_sel & MMS_LOG_USR_IND)    {    vl_ptr  = (VARIABLE_LIST *) (rsp_info + 1);    vl_ptr += rsp_info->va_spec.num_of_variables;    ar_ptr = (ACCESS_RESULT *) vl_ptr;    rsp_info->acc_rslt_list = ar_ptr;      done = SD_FALSE;    init_nxtbuf ();	/* initialize next buffer for access result	*/    printf ("\n ");    rsp_info->num_of_acc_result = 0;    while (!done)      {      if (get_acc_rslt (ar_ptr))        {        rsp_info->num_of_acc_result++;        ar_ptr++;        }      else        done = SD_TRUE;      }    }	  mp_read_resp (req_info, rsp_info);	/* send primitive response	*/#endif			/* PRIMITIVE RESPONDER */  indic_info_wait ();			/* allow user to see indic info */  }/************************************************************************/#if !(READ_RESP_MODE & RD_AUTO_RESP)ST_VOID send_read_resp (MMSREQ_IND *req_info)  {READ_REQ_INFO  *req_ptr;MV_READ_RESP_INFO *vm_info;MV_READ_RESP_INFO *vm_ptr;ST_INT i;ST_INT num_rslt;ST_CHAR *data_buf;ST_CHAR *data_ptr;OBJECT_NAME type;  req_ptr = (READ_REQ_INFO *) req_info->req_info_ptr;  printf ("\n\n Now need to enter the access result information, one variable");  printf ("\n at a time.");  printf ("\n How many 'access results' should be sent back (1) ? ");  num_rslt = 1;  intget (&num_rslt);  vm_info = (MV_READ_RESP_INFO *) 		chk_calloc (num_rslt,sizeof (MV_READ_RESP_INFO));  vm_ptr = vm_info;  data_buf = chk_malloc (1000);  data_ptr = data_buf;  for (i = 0; i < num_rslt; ++i,++vm_ptr)    {    vm_ptr->alt_acc_pres = 0;    printf ("\n Enter the 'result' for variable %d (1 == success) : ",i);    vm_ptr->result = ACC_RSLT_SUCCESS;    intget (&vm_ptr->result);    if (vm_ptr->result != ACC_RSLT_SUCCESS)      {      printf ("\n Enter the 'err_code' value : ");      vm_ptr->err_code = 10;      intget (&vm_ptr->err_code);      }    else      {      printf ("\n Enter Type : ");      if (get_objname (&type))        {        if (vm_ptr->type = ms_find_named_type_obj (&type,req_info->chan))          {          get_write_data (&type,data_ptr,req_info->chan);          vm_ptr->data_ptr = data_ptr;                      data_ptr += (vm_ptr->type)->blocked_len;                 }        else          {          vm_ptr->result = ACC_RSLT_FAILURE;          vm_ptr->err_code = 10;          }        }      else        {        vm_ptr->result = ACC_RSLT_FAILURE;        vm_ptr->err_code = 10;        }      }    }/* now we are ready to send the response - 				*/  mv_read_response (req_info,num_rslt,vm_info);  chk_free (data_buf);  chk_free (vm_info);  }#elseST_VOID guess_read_resp (MMSREQ_IND *req_info)  {READ_REQ_INFO  *req_ptr;MV_READ_RESP_INFO *vm_info;MV_READ_RESP_INFO *vm_ptr;ST_INT i;ST_INT num_rslt;VARIABLE_LIST *vl_ptr;NAMED_VAR *vptr;UNNAMED_VAR *unv;ST_UCHAR *address;NAMED_TYPE *ptptr;NAMED_TYPE **ttypes;ST_INT	ttype_no;ST_CHAR typename[MAX_IDENT_LEN+1];  req_ptr = (READ_REQ_INFO *) req_info->req_info_ptr;  if (req_ptr->va_spec.var_acc_tag==VAR_ACC_NAMEDLIST)    {    mv_read_resp(req_info);    return;    }  /* from here on down we process a ListOfVariables */  vl_ptr = (VARIABLE_LIST *)(req_ptr+1);  num_rslt = req_ptr->va_spec.num_of_variables;			  vm_info = (MV_READ_RESP_INFO *) 		chk_calloc (num_rslt,sizeof (MV_READ_RESP_INFO));  vm_ptr = vm_info;  /* set up the overhead to handle Described variables */  ttypes = (NAMED_TYPE **)chk_calloc(num_rslt,                                       sizeof(NAMED_TYPE *));  ttype_no = 0;  for (i = 0; i < num_rslt; ++i,++vm_ptr,++vl_ptr)    {    switch(vl_ptr->var_spec.var_spec_tag)      {      case VA_SPEC_NAMED:        /* see if we can find the thing */        if (vptr = ms_find_named_var_obj(&vl_ptr->var_spec.vs.name,                                         req_info->chan))          {          vm_ptr->alt_acc_pres = 0;          vm_ptr->result = ACC_RSLT_SUCCESS;          vm_ptr->data_ptr = u_get_named_addr(vptr);          vm_ptr->type = vptr->type;          }        else          {          vm_ptr->result = ACC_RSLT_FAILURE;          vm_ptr->err_code = ARE_OBJ_NONEXISTENT;	  }	 break;      case VA_SPEC_ADDRESSED:	switch(vl_ptr->var_spec.vs.address.addr_tag)	  {	  case NUM_ADDR:	    if (unv = ms_find_unnamed_var((ST_UCHAR *)vl_ptr->var_spec.vs.address.addr.num_addr))              {              vm_ptr->alt_acc_pres = 0;              vm_ptr->result = ACC_RSLT_SUCCESS;              vm_ptr->data_ptr = (ST_CHAR *) unv->address;              vm_ptr->type = unv->tptr;	      }	    else	      {              vm_ptr->result = ACC_RSLT_FAILURE;              vm_ptr->err_code = ARE_INVAL_ADDR;	      }	    break;	  case SYM_ADDR:	    sscanf(vl_ptr->var_spec.vs.address.addr.sym_addr,"%lx",&address);	    if (unv = ms_find_unnamed_var(address))              {              vm_ptr->alt_acc_pres = 0;              vm_ptr->result = ACC_RSLT_SUCCESS;              vm_ptr->data_ptr = (ST_CHAR *) unv->address;              vm_ptr->type = unv->tptr;	      }	    else	      {              vm_ptr->result = ACC_RSLT_FAILURE;              vm_ptr->err_code = ARE_INVAL_ADDR;	      }	    break;	    default: /* UNconstrained not supported */              vm_ptr->result = ACC_RSLT_FAILURE;              vm_ptr->err_code = ARE_INVAL_ADDR;            break;	  }	break;      case VA_SPEC_DESCRIBED:	switch(vl_ptr->var_spec.vs.var_descr.address.addr_tag)	  {	  case NUM_ADDR:	    if (unv = ms_find_unnamed_var((ST_UCHAR *)vl_ptr->var_spec.vs.var_descr.address.addr.num_addr))              {              vm_ptr->alt_acc_pres = 0;              vm_ptr->result = ACC_RSLT_SUCCESS;              vm_ptr->data_ptr = (ST_CHAR *) unv->address;	      /* turn the req ASN.1 into a type and comp lens */	      /* make up a new type name */	      sprintf(typename,"%s%d","ttype",ttype_no);	      ptptr = ms_add_named_type(&m_vmd_select->vmd_wide,	        			typename,		  			vl_ptr->var_spec.vs.var_descr.type.data,		  			vl_ptr->var_spec.vs.var_descr.type.len);              if (ptptr != NULL)		{		/* remember the type so we can delete it */  	        ttypes[ttype_no] = ptptr;		ttype_no++;

⌨️ 快捷键说明

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