📄 mmseasy.c
字号:
/************************************************************************//* SISCO SOFTWARE MODULE HEADER *****************************************//************************************************************************//* (c) Copyright Systems Integration Specialists Company, Inc., *//* 1996 - 2000, All Rights Reserved. *//* *//* MODULE NAME : mmseasy.c *//* PRODUCT(S) : MMSEASE *//* *//* MODULE DESCRIPTION : *//* This is a simple MMS-EASE application, all in one source module. It *//* contains code for both a client and a server. As a client it simply */ /* reads the named variable 'Temperature' from the specified server. *//* As a server, it exposes two variables to the MMS network and allows *//* client applications full read/write access to those variables. The *//* server portion of this application also supports the 'Get Name List' *//* and 'Get Variable Access Attributes' services as a server. *//* *//* Please note that this is intended only as a simple demonstration of *//* what can be done easily, and does not make use of system specific *//* event notification facilties provided by MMS-EASE. *//* *//* Usage : mmseasy {-c | -s} localArName remoteArName *//* *//* *//* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : *//* *//* MODIFICATION LOG : *//* Date Who Rev Comments *//* -------- --- ------ ------------------------------------------- *//* 09/13/00 EJV 12 Corrected exit statement. *//* 05/03/00 EJV 11 Added initialization of m_mem_debug=SD_TRUE *//* 06/03/98 IKE 10 Added MLOG_DISABLE define use *//* 03/10/98 EJV 09 Added pstInfo u_info_ind *//* 02/10/98 MDE 08 Fixed info handling print *//* 01/26/98 EJV 07 Changed param to ST_LONG in u_llp_error_ind *//* 11/05/97 RKR 06 Open comment on line 19 *//* 10/30/96 NAV 05 Add info report and modify u_get_named_addr *//* 10/07/96 DSF 04 Minor Usage changes *//* 09/30/96 MDE 03 Added client write *//* 08/08/96 MDE 02 Back to mv_init, now set m_version *//* 08/07/96 MDE 01 Changed mv_init to mv_initiate *//* 07/30/96 MDE 1.00 Created *//************************************************************************//************************************************************************//* MMSOP_EN.H REQUIREMENTS : *//* The following defines must be set as shown in mmsop_en.h. All others *//* should be set to REQ_RESP_DIS. *//* *//* #define MMS_INIT_EN REQ_RESP_EN *//* #define MMS_CONCLUDE_EN REQ_RESP_EN *//* #define MMS_GETNAMES_EN RESP_EN *//* #define MMS_MV_RDVARS_EN REQ_RESP_EN *//* #define MMS_READ_EN REQ_RESP_EN *//* #define MMS_MV_WRVARS_EN REQ_RESP_EN *//* #define MMS_WRITE_EN REQ_RESP_EN *//* #define MMS_INFO_EN REQ_RESP_EN *//* #define MMS_GETVAR_EN RESP_EN *//* *//************************************************************************/#if !defined(MLOG_DISABLE)#define USE_MLOG#endif #include "glbtypes.h"#include "sysincs.h"#include "mem_chk.h"#include "mms_usr.h"#include "mms_pvmd.h"#include "mms_vvmd.h"#include "mms_pcon.h"#include "mms_vcon.h"#include "mms_pvar.h"#include "mms_vvar.h"#include "mms_ms.h"#include "mms_llp.h"#include "mmsop_en.h"#include "mem_chk.h"#ifdef USE_MLOG#include "mloguser.h"#endif#include "signal.h"/************************************************************************//* This variable is used with the chk_calloc call */static ST_CHAR *thisFileName = __FILE__;/************************************************************************//************************************************************************//* Local functions */static ST_VOID printUsage (ST_VOID);static ST_INT readServerVariable (ST_VOID);static ST_INT writeServerVariable (ST_VOID);static ST_INT sendInfoReport (ST_VOID);static ST_INT concludeServer (ST_VOID);static ST_INT connectServer (ST_VOID);static ST_INT initMMS (ST_VOID);static ST_VOID mSetLogCfg (ST_VOID);static ST_VOID mmsCommService (ST_VOID);static ST_VOID wait_any_event (ST_LONG msToWait);static NAMED_TYPE *addNamedType (ST_CHAR *typeName, ST_CHAR *tdl);static NAMED_VAR *addServerVar (ST_CHAR *varName, ST_VOID *addr, NAMED_TYPE *namedType);void ctrlCfun (int);/************************************************************************//* Local and Remote AR Names */static ST_CHAR *locArName;static ST_CHAR *remArName;/* Coordination between request and done functions */static ST_BOOLEAN reqDone;static ST_RET reqStatus;static ST_BOOLEAN doIt = SD_TRUE;static ST_BOOLEAN useTypeLessReads = SD_FALSE;/* Used in issuing the client read */static NAMED_TYPE *int16Type; static NAMED_TYPE *structType; static ST_INT16 remoteTemperature;/* Our exposed server variables */static ST_INT16 Temperature = 71;struct testStruct { ST_INT32 l; ST_FLOAT f; ST_CHAR s[32]; } myStruct = {77777, (ST_FLOAT) 1.022, "Hey!"};/* Client/Server mode selection */#define CLIENT_MODE 1#define SERVER_MODE 2static ST_INT mode;/************************************************************************//************************************************************************//* main *//************************************************************************//* Usage : mmseasy {-c | -s} localArName remoteArName */ST_VOID main (int argc, char **argv) { /* set the flag allowing to track memory problems (previously set in lib code) */ m_mem_debug = SD_TRUE; if ((argc < 3) || (argc > 4)) { printUsage (); exit (1); } if (!strcmp (argv[1], "-c")) { if (argc != 4) { printUsage (); exit (1); } mode = CLIENT_MODE; locArName = argv[2]; remArName = argv[3]; } else if (!strcmp (argv[1], "-s")) { if (argc != 3) { printUsage (); exit (1); } mode = SERVER_MODE; locArName = argv[2]; } else { printUsage (); exit (1); }/* Set the ^c catcher */ signal (SIGINT, ctrlCfun);#ifdef USE_MLOG/* We will use the MLOG subsystem in order to log the MMS activity */ mSetLogCfg ();#endif/* Start MMS-EASE */ if (initMMS () != SD_SUCCESS) return;/* If we are the client, connect to the server and do our business */ if (mode == CLIENT_MODE) { printf ("\n Client Mode, Connecting to %s", remArName); if (connectServer () == SD_SUCCESS) { readServerVariable (); writeServerVariable (); sendInfoReport (); concludeServer (); } } else { printf ("\n Server Mode, Hit ^c to terminate ..."); while (doIt == SD_TRUE) mmsCommService (); }/* Terminate MMS-EASE */ end_MMS (); }/************************************************************************//* initMMS *//************************************************************************//* Initialize MMS-EASE and add all required types and server variables */static ST_INT initMMS (ST_VOID) {ST_RET ret;NAMED_VAR *namedVar;#ifdef USE_MLOG m_mlog_install (); /* Install the MLOG subsystem */#endif/* Set up some MMS-EASE configuration variables */ max_mms_chan = 2; /* We need two channels */ mms_max_msgsize = 1000; /* Set the requested MAX MMS PDU Size */ m_version = 1; /* Use MMS IS *//* Start the MMS-EASE subsystem */ if (ret = strt_MMS ()) { printf ("\n MMS failed to start err: "); ms_perror (ret); /* display a desc. of the error */ return (ret); }/* Activate our local AR Name */ ret = mllp_act_arname (locArName, ACSE30_LLP); if (ret != SD_SUCCESS) { printf ("\n ACTIVATE ERROR : %d", (int) ret); return (ret); }/* Assign our local AR name to all channels */ ret = mllp_reg_ar_name (0, locArName); ret |= mllp_reg_ar_name (1, locArName); if (ret != SD_SUCCESS) { printf ("\n REGISTER ERROR : %d", (int) ret); return (ret); } ret = mllp_ass_listen (1); if (ret != SD_SUCCESS) { printf ("\n LISTEN ERROR : %d", (int) ret); return (ret); }/* We want to allow 'natural' access to data, rather than packed *//* This needs to be done prior to adding any types. */ m_data_algn_tbl = m_def_data_algn_tbl;/* To do a read, we need to have a named type of the appropriate type */ int16Type = addNamedType ("int16Type", "Short"); structType = addNamedType ("structType", "{Long, Float, Vstring31}");/* Here's where we add our exposed server variables. We will allow *//* remote applications (clients) to read these variables directly. */ if (mode == SERVER_MODE) { namedVar = addServerVar ("Temperature", &Temperature, int16Type); namedVar = addServerVar ("myStruct", &myStruct, structType); } return (SD_SUCCESS); }/************************************************************************//* addNamedType *//************************************************************************//* This function creates a MMS-EASE named type given the TDL (Type *//* Definition Language) string. These types are required for handling *//* MMS variables as a client or server */#define MAX_ASN1_TYPE_LEN 1000static NAMED_TYPE *addNamedType (ST_CHAR *typeName, ST_CHAR *tdl) {ST_INT len;ST_UCHAR *asn1ptr;ST_UCHAR *asn1_buf;NAMED_TYPE *tnew = NULL;/* We generate the ASN.1 encoding in a malloc'd buffer */ asn1_buf = (ST_UCHAR *) chk_calloc (1, MAX_ASN1_TYPE_LEN); len = MAX_ASN1_TYPE_LEN;/* If the TDL is good then we allocate a chunk of memory and put *//* the ASN.1 encoding in. */ if (asn1ptr = ms_mk_asn1_type (&len, asn1_buf, tdl)) { tnew = ms_add_named_type (&m_vmd_select->vmd_wide, typeName, asn1ptr, (ST_INT)len); if (!tnew) printf ("\n Failed adding named type '%s'",typeName); } chk_free (asn1_buf); return (tnew); }/************************************************************************//* mmsCommService *//************************************************************************//* This function is used to service MMS-EASE communications, typically *//* while waiting for MMS activity. */static ST_VOID mmsCommService (ST_VOID) { wait_any_event (1000); /* wait for action */ while (ms_comm_serve ()) /* while MMS activity, service it */ ; }/************************************************************************//* wait_any_event *//************************************************************************//* This function is supposed to wait for MMS, keyboard, or other types *//* of activity. This function is quite O/S specific, and so for *//* simplicity we will just wait. This will cause this application to *//* burn the CPU needlessly. See the MMS-EASE demo (mmsapp.c) for a *//* more useful implementation of this function. */static ST_VOID wait_any_event (ST_LONG msToWait) { }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -