📄 datademo.c
字号:
static ST_VOID vmdt_write_ind (MMSREQ_IND *ind_ctrl) {register j;struct write_req_info *req_ptr;struct var_acc_data *data_ptr;struct write_resp_info *rsp_info;struct write_result *rslt_info;struct variable_list *vl;ST_RET err;ST_CHAR *dest;ST_INT resp_info_size; req_ptr = (struct write_req_info *) ind_ctrl->req_info_ptr; if (mms_debug_sel & MMS_LOG_USR_IND) { indic_info_print (ind_ctrl,"Write"); print_vaspec (&req_ptr->va_spec); data_ptr = req_ptr->va_data; printf ("\n Number of Data to Write : %d ", req_ptr->num_of_data); for (j = 0; j < req_ptr->num_of_data; j++,data_ptr++) { printf ("\n Write Data %d) ", j+1); list_bytes (data_ptr->data,data_ptr->len); } }/* Allocate the response info buffer */ resp_info_size = sizeof (struct write_resp_info) + (req_ptr->num_of_data * sizeof (struct write_result)); rsp_info = (struct write_resp_info *) chk_malloc (resp_info_size); rsp_info->num_of_result = req_ptr->num_of_data; rslt_info = (struct write_result *) (rsp_info + 1); vl = (struct variable_list *) (req_ptr+1); for (j = 0; j < req_ptr->num_of_data; ++j, ++vl, ++rslt_info) { if (!strcmp (vl->var_spec.vs.name.obj_name.vmd_spec,"str1")) { dest = (ST_CHAR *) &server_str1; err = ms_extract_write_data (ind_ctrl,j,str1_type,dest,SD_FALSE); if (!err) { rslt_info->resp_tag = WR_RSLT_SUCCESS; printf ("\n Write Data Extracted OK, str1 new values :"); printf ("\n b = %d", server_str1.b); printf ("\n s = %d", (int) server_str1.s); printf ("\n l = %ld", server_str1.l); } else { printf ("\n Write data extract error (0x%04x) ",err); rslt_info->resp_tag = WR_RSLT_FAILURE; rslt_info->failure = ARE_OBJ_UNDEFINED; } } else { printf ("\n Write : Unknown variable name"); rslt_info->resp_tag = WR_RSLT_FAILURE; rslt_info->failure = ARE_OBJ_UNDEFINED; } } mp_write_resp (ind_ctrl, rsp_info); /* send primitive response */ chk_free (rsp_info); /* free the response info */ indic_info_wait (); /* allow user to see indic info */ }/************************************************************************//************************************************************************/static ST_VOID send_test_info (ST_INT indx, ST_INT chan) {ST_INT num_var;ST_INT i;struct var_acc_spec *info;struct mv_info_req_info *mv;struct mv_info_req_info *mv_info_ptr;struct variable_list *vl;struct alt_acc_el aa1[1];struct alt_acc_el aa2[2];struct alt_acc_el aa3[2];struct alt_acc_el aa4[1];struct str1_P2 lbsrc;ST_INT ssrc;static ST_INT z = 10; num_var = 4;/* Need to calloc a buffer for the VM information, since it needs to be *//* committed until the confirm is received */ mv_info_ptr = (struct mv_info_req_info *) chk_calloc (num_var,sizeof (struct mv_info_req_info)); info = (struct var_acc_spec *) ((ST_CHAR *)dest_buffer); info->var_acc_tag = VA_SPEC_NAMED; info->num_of_variables = 4; vl = (struct variable_list *) (info+1); mv = mv_info_ptr;/* All elements of this info are about the same, except for the way the *//* returned data is to be handled. */ for (i = 0; i < num_var; ++i, ++vl, ++mv) { if (i == 3) /* for the 4th element only */ { vl->alt_access_pres = SD_TRUE; /* we supply ASN1.1 AA */ vl->alt_access.data = asn1_aa; vl->alt_access.len = 5; } else /* for all others */ vl->alt_access_pres = SD_FALSE; /* let the VM make ASN1.1 AA */ vl->var_spec.var_spec_tag = VA_SPEC_NAMED; vl->var_spec.vs.name.object_tag = VMD_SPEC; strcpy (vl->var_spec.vs.name.obj_name.vmd_spec,"str1");/* Now VM information */ mv->type = str1_type; mv->alt_acc_pres = SD_TRUE; }/* Now do the AA specifications for each variable *//* Non-packed, single component ('s') only */ mv = mv_info_ptr; client_str1.s = (ST_INT16) z; mv->data_ptr = (ST_CHAR *) &client_str1; mv->alt_acc_data_packed = SD_FALSE; mv->alt_acc.num_aa = 1; mv->alt_acc.aa = aa1; aa1[0].comp_name_pres = SD_FALSE; aa1[0].sel_type = AA_COMP; strcpy (aa1[0].u.component,"s");/* Non-packed, two components ('s' and 'l' */ mv++; client_str1.s = 2 + (ST_INT16) z; client_str1.l = 3 + (ST_INT32) z; mv->data_ptr = (ST_CHAR *)&client_str1; mv->alt_acc_data_packed = SD_FALSE; mv->alt_acc.num_aa = 2; mv->alt_acc.aa = aa2; aa2[0].comp_name_pres = SD_FALSE; aa2[0].sel_type = AA_COMP; strcpy (aa2[0].u.component,"s"); aa2[1].comp_name_pres = SD_FALSE; aa2[1].sel_type = AA_COMP; strcpy (aa2[1].u.component,"l");/* Packed, two components, reversed order ('l' and 'b' */ mv++; lbsrc.b = 1; lbsrc.l = 4 + (ST_INT32) z; mv->data_ptr = (ST_CHAR *)&lbsrc; mv->alt_acc_data_packed = SD_TRUE; mv->alt_acc.num_aa = 2; mv->alt_acc.aa = aa3; aa3[0].comp_name_pres = SD_FALSE; aa3[0].sel_type = AA_COMP; strcpy (aa3[0].u.component,"l"); aa3[1].comp_name_pres = SD_FALSE; aa3[1].sel_type = AA_COMP; strcpy (aa3[1].u.component,"b");/* Packed, single component ('s') only */ mv++; ssrc = 5 + (ST_INT16) z; mv->data_ptr = (ST_CHAR *)&ssrc; mv->alt_acc_data_packed = SD_TRUE; mv->alt_acc.num_aa = 1; mv->alt_acc.aa = aa4; aa4[0].comp_name_pres = SD_FALSE; aa4[0].sel_type = AA_COMP; strcpy (aa4[0].u.component,"s"); confirm_rcvd = SD_FALSE; if (mv_info_report (chan,info,num_var,mv_info_ptr)) print_req_error (); chk_free (mv_info_ptr); ++z; }/************************************************************************/static ST_VOID vmdt_info_ind (MMSREQ_IND *ind_ctrl) {ST_INT j;struct info_req_info *req_ptr;struct access_result *ar_ptr;struct variable_list *vl;ST_RET err;ST_CHAR *dest; req_ptr = (struct info_req_info *) ind_ctrl->req_info_ptr; ar_ptr = req_ptr->acc_rslt_list; if (mms_debug_sel & MMS_LOG_USR_IND) { indic_info_print (ind_ctrl,"Information Report"); req_ptr = (struct info_req_info *) ind_ctrl->req_info_ptr; ar_ptr = req_ptr->acc_rslt_list; print_vaspec (&req_ptr->va_spec); printf ("\n Number of Access Results = %d ", req_ptr->num_of_acc_result); for (j = 0; j < req_ptr->num_of_acc_result; j++) { printf ("\n Result %3d) ", j+1); if (ar_ptr->acc_rslt_tag == ACC_RSLT_FAILURE) printf ("Failure : %d ", ar_ptr->failure); else { printf ("Success : "); list_bytes (ar_ptr->va_data.data,ar_ptr->va_data.len); } ar_ptr++; } } vl = (struct variable_list *) (req_ptr+1); for (j = 0; j < req_ptr->num_of_acc_result; ++j, ++vl, ++ar_ptr) { if (!strcmp (vl->var_spec.vs.name.obj_name.vmd_spec,"str1")) { dest = (ST_CHAR *) &server_str1; err = ms_extract_info_data (ind_ctrl,j,str1_type,dest,SD_FALSE); if (!err) { printf ("\n Info Data Extracted OK, str1 new values :"); printf ("\n b = %d", server_str1.b); printf ("\n s = %d", (int) server_str1.s); printf ("\n l = %ld", server_str1.l); } else { printf ("\n Info data extract error (0x%04x) ",err); } } else { printf ("\n Info Rpt : Unknown variable name"); } } indic_info_wait (); /* allow user to see indic info */ }/************************************************************************//************************************************************************//* These functions demonstrate how to encode/decode data at a low level *//* without having to have a named type. One method uses the 'runtime *//* type' and the 'ms_xxx_to_yyy' functions, the other uses the ASN.1 *//* tools directly *//************************************************************************/#define ASN1_BUF_LEN 100static ST_VOID do_data_convert (ST_VOID) {ST_RET ret;ST_INT asn1_len;ST_UCHAR *asn1_start;struct runtime_type int_rt_type;ST_INT16 i16_src;ST_INT16 i16_dest;ASN1_ENC_CTXT localEncCtx;ASN1_ENC_CTXT *aEncCtx = &localEncCtx;ASN1_DEC_CTXT localDecCtx;ASN1_DEC_CTXT *aDecCtx = &localDecCtx; memset (aDecCtx, 0, sizeof(ASN1_DEC_CTXT));/* Execute the process to encode/decode an Integer 16 variable *//* USING THE RUNTIME TYPE METHOD *//* First construct the runtime type array, which has 1 element for *//* primitive data types. */ int_rt_type.el_tag = RT_INTEGER; int_rt_type.u.p.el_len = 2;/* Build an ASN.1 data element, encoding the value of i16_src as a 16 *//* bit integer. */ i16_src = 3;/* First we need to initizlize the ASN.1 encode tools, then do the *//* encode */ asn1r_strt_asn1_bld (aEncCtx, asn1_buf,ASN1_BUF_LEN); ret = ms_local_to_asn1 (aEncCtx, &int_rt_type, 1, (ST_CHAR *) &i16_src); if (ret) printf ("\n Local to ASN.1 Error : 0x%04x",ret);/* When the ASN.1 encode is complete, 'asn1_field_ptr' points 1 byte ahead *//* of the start of the message. The ASN.1 message is build from back to *//* front, so that is now we calculate the length of the PDU */ asn1_start = aEncCtx->asn1r_field_ptr + 1; asn1_len = (asn1_buf + ASN1_BUF_LEN) - asn1_start;/* OK, the message is fully encoded, now decode it into the variable *//* 'i16_dest' */ i16_dest = 0; ret = ms_asn1_to_local (&int_rt_type,1,asn1_start,asn1_len, (ST_CHAR *) &i16_dest); if (ret) printf ("\n ASN.1 to Local Error : 0x%04x",ret); else { printf ("\n Source = %d, Dest = %d",i16_src, i16_dest); printf ("\n ASN.1 : "); list_bytes (asn1_start, asn1_len); }/* USING THE ASN.1 TOOLS DIRECTLY *//* Build an ASN.1 data element, encoding the value of i16_src as a 16 *//* bit integer. */ i16_src = 3;/* First we need to initizlize the ASN.1 encode tools, then do the *//* encode */ asn1r_strt_asn1_bld (aEncCtx, asn1_buf, ASN1_BUF_LEN); asn1r_wr_i16 (aEncCtx, i16_src); asn1r_fin_prim (aEncCtx, RT_INTEGER, CTX); /* finish the primitive *//* When the ASN.1 encode is complete, 'asn1_field_ptr' points 1 byte ahead *//* of the start of the message. The ASN.1 message is build from back to *//* front, so that is now we calculate the length of the PDU */ asn1_start = aEncCtx->asn1r_field_ptr + 1; asn1_len = (asn1_buf + ASN1_BUF_LEN) - asn1_start;/* OK, the message is fully encoded, now decode it into the variable *//* 'i16_dest' */ i16_dest = 0; aDecCtx->asn1r_field_ptr = asn1_start; asn1r_head_decode (aDecCtx); if (aDecCtx->asn1r_elmnt_id == RT_INTEGER) /* Could also check asn1_constr_elmnt & asn1_elmnt_class */ { if (asn1r_get_i16 (aDecCtx, &i16_dest)) printf ("\n Get problem"); } else printf ("\n asn1_elmnt_id problem"); printf ("\n Source = %d, Dest = %d",i16_src, i16_dest); printf ("\n ASN.1 : "); list_bytes (asn1_start, asn1_len); wait_key (); (*menu_set_fun)(); }/************************************************************************/#endif /* end if '#if MMS_VA_EN' *//************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -