📄 mmseasy.c
字号:
/************************************************************************//* ctrlCfun *//************************************************************************//* This function handles the ^c, and allows us to cleanup on exit */void ctrlCfun (int i) { doIt = SD_FALSE; }/************************************************************************//************************************************************************//************************************************************************//* CLIENT SPECIFIC FUNCTIONS *//************************************************************************//* connectServer *//************************************************************************//* This function is used to issue an MMSOP_INITIATE request to the server, *//* then wait for the confirm. */static ST_INT connectServer (ST_VOID) {MMSREQ_PEND *reqCtrl;/* We now have all information required to establish an association */ reqDone = SD_FALSE; reqStatus = SD_FAILURE; reqCtrl = mv_init (0, remArName); if (!reqCtrl) return (mms_op_err); while (reqDone == SD_FALSE && doIt == SD_TRUE) mmsCommService (); if (reqStatus == SD_SUCCESS) printf ("\n Connected to %s", remArName); else printf ("\n Could not connect to %s", remArName); return (reqStatus); }/************************************************************************//* u_mllp_a_assoc_conf *//************************************************************************//* This function is called (from within comm_serve) when the ACSE *//* associate confirm is received. Return SD_SUCCESS to allow the initiate *//* process to proceeed. */ST_RET u_mllp_a_assoc_conf (ST_INT chan, ACSE_ASSINFO *assinfo) { return (SD_SUCCESS); /* OK, allow to continue */ }/************************************************************************//* u_mv_init_conf *//************************************************************************//* This function is called (from within comm_serve) when the initiate *//* confirm is received from the remote node. Just set a flag to let *//* the application know it may continue */ST_VOID u_mv_init_conf (MMSREQ_PEND *reqCtrl) { if (reqCtrl->resp_err == CNF_RESP_OK) reqStatus = SD_SUCCESS; else reqStatus = SD_FAILURE; reqDone = SD_TRUE; ms_clr_mvreq (reqCtrl); /* clear the VM command info */ }/************************************************************************//* readServerVariable *//************************************************************************//* This function is used to issue a READ request to the server, *//* then wait for the confirm. */extern ST_BOOLEAN m_use_long_ints;static ST_INT readServerVariable (ST_VOID) {MMSREQ_PEND *reqCtrl;ST_CHAR buffer [1024];MV_READ_REQ_INFO mvReadInfo; READ_REQ_INFO *req_info;VARIABLE_LIST *vl;/* Create a read request info struct */ req_info = (READ_REQ_INFO *) buffer; req_info->spec_in_result = 0; req_info->va_spec.var_acc_tag = VAR_ACC_VARLIST; req_info->va_spec.num_of_variables = 1; vl = (VARIABLE_LIST *) (req_info + 1); vl->var_spec.var_spec_tag = VA_SPEC_NAMED; vl->var_spec.vs.name.object_tag = VMD_SPEC; vl->alt_access_pres = SD_FALSE; strcpy (vl->var_spec.vs.name.obj_name.vmd_spec, "Temperature");/* Note that the mvReadInfo data structure must be comitted until *//* the confirm is received. In this trivial application we can use *//* automatic storage for simplicity, but be careful when extending! */ if (useTypeLessReads != 0) { /* Install the typeLess data handling subsustem. */ ms_asn1_data_to_runtime_fun = ms_asn1_data_to_runtime; /* Since we don't know what type this is, but expect it to be an */ /* integer and don't want to deal with varying sizes, we will force */ /* the type extraction tools to make all integers ST_INT32 */ m_use_long_ints = SD_TRUE; /* Let MMS-EASE figure out the data type and allocate the buffer */ mvReadInfo.i.type = NULL; mvReadInfo.i.data_ptr = NULL; } else /* Not useTypeLessReads, we know the type and req'd buffer size */ { mvReadInfo.i.data_ptr = (ST_CHAR *) &remoteTemperature; mvReadInfo.i.type = int16Type; } mvReadInfo.i.alt_acc_pres = SD_FALSE; reqDone = SD_FALSE; reqStatus = SD_FAILURE; reqCtrl = mv_read_variables (0, 1, req_info, &mvReadInfo); if (!reqCtrl) return (mms_op_err); while (reqDone == SD_FALSE && doIt == SD_TRUE) mmsCommService ();/* Get the read request information and examine the result. If success, *//* the MMS-EASE VM will have already converted the data and put it into *//* the destination (remoteTemperature) for us. */ if (doIt == SD_TRUE && reqCtrl->resp_err == CNF_RESP_OK && mvReadInfo.o.result == ACC_RSLT_SUCCESS) { if (useTypeLessReads) { /* Verify that the derived type is as expected */ if (mvReadInfo.o.rt_out->el_tag == RT_INTEGER && mvReadInfo.o.rt_out->u.p.el_len == 4) { remoteTemperature = (ST_INT16) *((ST_INT32 *) mvReadInfo.o.data_ptr_out); printf ("\n Typeless Read OK, Temperature = %d", (int) remoteTemperature); chk_free (mvReadInfo.o.data_ptr_out); chk_free (mvReadInfo.o.rt_out); } } else { /* Not useTypeLessReads, nothing to free or examine - we have opur data */ printf ("\n Read OK, Temperature = %d", remoteTemperature); } } else printf ("\n Read Failed"); return (reqStatus); }/************************************************************************//* u_mv_read_vars_conf *//************************************************************************//* This function is called (from within comm_serve) when the read *//* confirm is received from the remote node. Just set a flag to let *//* the application know it may continue */ST_VOID u_mv_read_vars_conf (MMSREQ_PEND *reqCtrl) {MV_READ_REQ_INFO *varlist;/* Get the read request information and examine the result. If success, *//* the MMS-EASE VM will have already converted the data and put it into *//* the destination (remoteTemperature) for us. */ varlist = (MV_READ_REQ_INFO *) reqCtrl->req_info_ptr; if (varlist->o.result == ACC_RSLT_SUCCESS) reqStatus = SD_SUCCESS; else reqStatus = SD_FAILURE; reqDone = SD_TRUE; ms_clr_mvreq (reqCtrl); /* clear the VM command info */ }/************************************************************************//* u_mp_read_conf *//************************************************************************//* This function is required to satisfy linker references only. */ST_VOID u_mp_read_conf (MMSREQ_PEND *reqCtrl) { }/************************************************************************//* writeServerVariable *//************************************************************************//* This function is used to issue a WRITE request to the server, *//* then wait for the confirm. */static ST_INT writeServerVariable (ST_VOID) {MMSREQ_PEND *reqCtrl;ST_CHAR buffer [1024];MV_WRITE_REQ_INFO mvWriteInfo; VAR_ACC_SPEC *req_info;VARIABLE_LIST *vl;/* Create a write request info struct */ req_info = (VAR_ACC_SPEC *) buffer; req_info->var_acc_tag = VAR_ACC_VARLIST; req_info->num_of_variables = 1; vl = (VARIABLE_LIST *) (req_info + 1); vl->var_spec.var_spec_tag = VA_SPEC_NAMED; vl->var_spec.vs.name.object_tag = VMD_SPEC; vl->alt_access_pres = SD_FALSE; strcpy (vl->var_spec.vs.name.obj_name.vmd_spec, "Temperature"); remoteTemperature++; /* Turn up the heat a bit. */ mvWriteInfo.data_ptr = (ST_CHAR *) &remoteTemperature; mvWriteInfo.type = int16Type; mvWriteInfo.alt_acc_pres = SD_FALSE; reqDone = SD_FALSE; reqStatus = SD_FAILURE; reqCtrl = mv_write_variables (0, 1, req_info, &mvWriteInfo); if (!reqCtrl) return (mms_op_err); while (reqDone == SD_FALSE && doIt == SD_TRUE) mmsCommService (); if (reqStatus == SD_SUCCESS) printf ("\n Write OK, Temperature = %d", remoteTemperature); else printf ("\n Write Failed"); return (reqStatus); }/************************************************************************//* u_mv_write_vars_conf *//************************************************************************//* This function is called (from within comm_serve) when the write *//* confirm is received from the remote node. Just set a flag to let *//* the application know it may continue */ST_VOID u_mv_write_vars_conf (MMSREQ_PEND *reqCtrl) {WRITE_RESP_INFO *rspPtr;WRITE_RESULT *rsltPtr;/* Get the write response information and examine the result. */ rspPtr = (WRITE_RESP_INFO *) reqCtrl->resp_info_ptr; rsltPtr = (WRITE_RESULT *) (rspPtr + 1); if (rsltPtr->resp_tag == WR_RSLT_SUCCESS) reqStatus = SD_SUCCESS; else reqStatus = SD_FAILURE; reqDone = SD_TRUE; ms_clr_mvreq (reqCtrl); /* clear the VM command info */ }/************************************************************************//* u_mp_write_conf *//************************************************************************//* This function is required to satisfy linker references only. */ST_VOID u_mp_write_conf (MMSREQ_PEND *reqCtrl) { }/************************************************************************//* sendInfoReport *//************************************************************************//* Do the MMS-EASE call to setup information report for var Temperature */static ST_RET sendInfoReport (ST_VOID) {ST_INT rtnVal;MV_VARDESC stVarDesc; stVarDesc.name.object_tag = VMD_SPEC; strcpy (stVarDesc.name.obj_name.vmd_spec, "Temperature"); stVarDesc.type.object_tag = VMD_SPEC; strcpy (stVarDesc.type.obj_name.vmd_spec, "int16Type"); stVarDesc.data = (ST_CHAR *) &Temperature; Temperature += 10; rtnVal = mv_infovars (0, 1, &stVarDesc); if (rtnVal != SD_SUCCESS) printf ("\n Information Report Not Sent! 0x%x", rtnVal); else printf ("\n Information Report Setup Successfully."); return rtnVal; }/************************************************************************//* concludeServer *//************************************************************************//* This function is used to issue a MMSOP_CONCLUDE request to the server, *//* then wait for the confirm. */static ST_INT concludeServer (ST_VOID) {MMSREQ_PEND *reqCtrl; reqDone = SD_FALSE; reqStatus = SD_FAILURE; reqCtrl = mp_conclude (0); if (!reqCtrl) return (mms_op_err); while (reqDone == SD_FALSE && doIt == SD_TRUE) mmsCommService (); if (reqStatus == SD_SUCCESS) printf ("\n Concluded OK"); else printf ("\n Conclude Failed"); return (reqStatus); }/************************************************************************//* u_mp_conclude_conf *//************************************************************************//* This function is called (from within comm_serve) when the conclude *//* confirm is received from the remote node. Just set a flag to let *//* the application know it may continue */ST_VOID u_mp_conclude_conf (MMSREQ_PEND *reqCtrl) { if (reqCtrl->resp_err == CNF_RESP_OK) reqStatus = SD_SUCCESS; else reqStatus = SD_FAILURE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -