Example #1
0
        public override void pro(byte[] b, ref int off, int n)
        {
            int ti = 0;

            if (ref_len != "")                                           //若是指定的
            {
                PD_Node pn   = father_Dom.prot_dict[ref_len] as PD_Node; //引用的一定是个值类型的协议域
                var     para = pn.ref_para as ParaValue_Val;
                ti = para.data.ds32;                                     //此时是变换以后的
            }
            else
            {
                var para = ref_para as ParaValue_Val;
                ti = para.data.ds32;                    //此时是变换以后的
            }
            var pr      = prot_dict.ToArray()[0].Value; //取得第一个协议域
            int pre_off = off;                          //上次偏移位置

            for (int i = 0; i < ti; i++)
            {
                pr.pro(b, ref off, n);
                n      -= off - pre_off;            //增加了多少字节,总字节数相应减掉
                pre_off = off;
            }
        }
Example #2
0
 public void fromJson(Dictionary <string, object> v)
 {
     if (v.ContainsKey("check_type"))             //配置校验类型
     {
         string s = json_ser.Serialize(v["check_type"]);
         check_type = json_ser.Deserialize <CHECK_TYPE>(s); //取得参数类型
     }
     if (v.ContainsKey("syn"))                              //配置同步字
     {
         ArrayList list = v["syn"] as ArrayList;
         SYNC = new byte[list.Count];
         for (int i = 0; i < list.Count; i++) //读取同步字列表
         {                                    //是16进制
             string s = list[i] as string;
             s       = s.Replace("0x", "");
             SYNC[i] = byte.Parse(s, System.Globalization.NumberStyles.HexNumber);
         }
     }
     if (v.ContainsKey("pre_offset"))
     {
         pre_offset = (byte)(int)v["pre_offset"];                                         //配置确定包长的偏移位置
     }
     if (v.ContainsKey("pack_len"))
     {
         pack_len = (int)v["pack_len"];                                        //配置包长
     }
     else
     {
         pack_len = pre_offset + 1;
     }
     if (v.ContainsKey("len_dom_off"))
     {
         len_dom_off = (int)v["len_dom_off"];                                           //
     }
     if (v.ContainsKey("len_dom"))
     {
         var      vt = v["len_dom"] as Dictionary <string, object>;
         string   s  = json_ser.Serialize(vt["type"]);
         DataType t  = json_ser.Deserialize <DataType>(s); //取得参数类型
         len_dom = new PD_Node(vt, t, null);               //一定没有引用参数,所以不使用测控架构对象
     }
     if (v.ContainsKey("len_dict"))                        //读取长度列表
     {
         var vd = v["len_dict"] as Dictionary <string, object>;
         foreach (var item in vd)
         {
             string s = item.Key;
             int    k = 0;
             if (s.StartsWith("0x"))                     //若是16进制
             {
                 k = int.Parse(s.Substring(2), System.Globalization.NumberStyles.HexNumber);
             }
             else
             {
                 k = int.Parse(s);
             }
             len_dict[k] = (int)item.Value;
         }
     }
 }
Example #3
0
        public override void pro(byte[] b, ref int off, int n)
        {
            PD_Node pn   = father_Dom.prot_dict[ref_type] as PD_Node; //引用的一定是个值类型的协议域
            var     para = pn.ref_para as ParaValue_Val;
            int     ti   = (int)para.data.du64;                       //此时是变换以后的

            prot_map[ti].pro(b, ref off, n);                          //找到这个协议,调用
        }