Ejemplo n.º 1
0
        public string[] split_char_list = new string[0];       //本协议的特殊分隔符
        public PD_LineObj(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
        {
            if (v.ContainsKey("split_char_list"))
            {
                ArrayList l = v["split_char_list"] as ArrayList;
                split_char_list = new string[l.Count];
                for (int i = 0; i < l.Count; i++)
                {
                    split_char_list[i] = l[i] as string;
                }
            }
            ArrayList list = v["prot_list"] as ArrayList;

            foreach (var item in list)
            {
                var      tv = item as Dictionary <string, object>;
                DataType tp = DataType.df;                 //默认类型是double
                if (tv.ContainsKey("type"))
                {
                    string ts = MC_Prot.json_ser.Serialize(tv["type"]);
                    tp = MC_Prot.json_ser.Deserialize <DataType>(ts); //取得参数类型
                }
                var p = new PD_Str(tv, tp, p_mcp);                    //递归创建自己的子协议域
                p.father_Dom = null;                                  //给上层引用赋值
                prot_list.Add(p);
            }
        }
Ejemplo n.º 2
0
        public Dictionary <string, PD_LineObj> textline_dict = new Dictionary <string, PD_LineObj>(); //文本协议字典
        public void formJson(Dictionary <string, object> v)                                           //初始化
        {
            if (v.ContainsKey("para_dict"))
            {
                ArrayList list = v["para_dict"] as ArrayList;
                foreach (var item in list)
                {
                    var    tv = item as Dictionary <string, object>;
                    string s  = tv["name"] as string;
                    para_dict[s] = ParaValue.factory(tv);                     //构建参数
                }
            }
            if (v.ContainsKey("prot_root"))
            {
                prot_root = MC_Prot.factory(v["prot_root"] as Dictionary <string, object>, this);                //递归创建自己的子协议域
            }
            //文本行协议
            if (v.ContainsKey("textline_dict"))
            {
                ArrayList list = v["textline_dict"] as ArrayList;
                foreach (var item in list)
                {
                    var tv = item as Dictionary <string, object>;

                    string s = "";
                    if (tv.ContainsKey("name"))
                    {
                        s = tv["name"] as string;
                    }
                    int col_n = (int)tv["col_n"];                     //必须描述此协议的列数
                    s += "-" + col_n.ToString();
                    textline_dict[s] = new PD_LineObj(tv, DataType.str, this);
                }
            }
        }
Ejemplo n.º 3
0
        public ParaValue ref_para = null;                                     //引用的参数
        public ProtDom(Dictionary <string, object> v, DataType t, MC_Prot pd) //从json构造对象
        {                                                                     //这里遇到错误就throw出去,不想throw的才判断
            p_mcp = pd;
            if (v.ContainsKey("id"))
            {
                id = (int)v["id"];
            }
            if (v.ContainsKey("name"))
            {
                name = (string)v["name"];
            }
            type = t;
            while (v.ContainsKey("ref_name"))
            {
                ref_name = (string)v["ref_name"];
                if (!p_mcp.para_dict.ContainsKey(ref_name))
                {
                    break;                                            //引用的参数不对,按没有算
                }
                ref_para = p_mcp.para_dict[ref_name];                 //参数表先于协议加载
                return;
            }
            //没有引用参数,说明是协议内部结构数据
            var tv = new Dictionary <string, object>();

            tv["type"] = "u64";
            tv["name"] = "";
            tv["len"]  = 8;
            ref_para   = new ParaValue_Val(tv, DataType.u64);           //创建一个内部参数对象
        }
Ejemplo n.º 4
0
        public Dictionary <string, ProtDom> prot_dict = new Dictionary <string, ProtDom>(); //协议字典
        public PD_Obj(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
        {
            if (!v.ContainsKey("prot_list"))
            {
                return;
            }
            ArrayList list = v["prot_list"] as ArrayList;

            foreach (var item in list)
            {
                var    tv = item as Dictionary <string, object>;
                string s;
                if (tv.ContainsKey("name"))
                {
                    s = tv["name"] as string;
                }
                else
                {
                    s = name + "._" + prot_list.Count.ToString();                  //若没有显式指明名称,分配自动名称
                }
                prot_list.Add(s);
                var p = MC_Prot.factory(tv, p_mcp); //递归创建自己的子协议域
                p.father_Dom = this;                //给上层引用赋值
                p.name       = s;                   //覆盖子节点的名称
                prot_dict[s] = p;
            }
        }
Ejemplo n.º 5
0
        public Dictionary <int, ProtDom> prot_map = new Dictionary <int, ProtDom>(); //各协议描述符头部,由int对协议进行索引
        public PD_Switch(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
        {
            ref_type = v["ref_type"] as string;
            if (v.ContainsKey("cfg_str_type"))
            {
                cfg_str_type = v["cfg_str_type"] as string;                     //
            }
            var dict = v["prot_map"] as Dictionary <string, object>;            //各协议由字典组织

            foreach (var item in dict)
            {
                int k = 0;
                if (cfg_str_type == "hex")
                {
                    k = int.Parse(item.Key, System.Globalization.NumberStyles.HexNumber);
                }
                else
                {
                    int.TryParse(item.Key, out k);
                }
                var tv = item.Value as Dictionary <string, object>;
                var p  = MC_Prot.factory(tv, p_mcp); //递归创建自己的子协议域
                p.father_Dom = this;                 //给上层引用赋值
                prot_map[k]  = p;
            }
        }
Ejemplo n.º 6
0
 public string str_type = "";  //空为10进制,hex:16进制
 public PD_Str(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
 {
     if (v.ContainsKey("str_type"))
     {
         str_type = v["str_type"] as string;
     }
 }
Ejemplo n.º 7
0
 } = 0;                                           //是否是有符号数
 public PD_Node(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
 {
     if (v.ContainsKey("pro_k"))
     {
         pro_k = (double)(decimal)v["pro_k"];
     }
     if (v.ContainsKey("pro_b"))
     {
         pro_b = (double)(decimal)v["pro_b"];
     }
     if (v.ContainsKey("bit_st"))
     {
         bit_st = (int)v["bit_st"];                                      //默认从0bit开始
     }
     if (v.ContainsKey("bit_len"))
     {
         bit_len = (int)v["bit_len"];
     }
     if (v.ContainsKey("bit_singed"))
     {
         bit_st = (int)v["bit_singed"];                                          //默认从0bit开始
     }
     if (v.ContainsKey("skip_n"))
     {
         skip_n = (int)v["skip_n"];
     }
     len = DATA_UNION.get_type_len(type);
 }
Ejemplo n.º 8
0
 public string ref_len = "";   //引用的协议域,用于确定重复次数
 public PD_Loop(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
 {
     if (v.ContainsKey("ref_len"))
     {
         ref_len = v["ref_len"] as string;
     }
     else             //需要直接指定
     {
         var para = ref_para as ParaValue_Val;
         para.data.ds32 = (int)v["loop_n"];
     }
 }
Ejemplo n.º 9
0
        public static ProtDom factory(Dictionary <string, object> v, MC_Prot pd) //构建工厂,输入配置,测控协议对象
        {
            string   s = json_ser.Serialize(v["type"]);                          //这样取得的字符串带"
            DataType t = DataType.u64;                                           //默认类型

            try
            {
                t = json_ser.Deserialize <DataType>(s); //取得参数类型,enum类型的反串行化需要字符串带"
            }
            catch (Exception e)                         //若不是基础类型,则建立协议组织类型
            {
                s = s.Replace("\"", "");                //去掉"
                switch (s)
                {
                case "obj": return(new PD_Obj(v, t, pd));

                case "switch": return(new PD_Switch(v, t, pd));

                case "loop": return(new PD_Loop(v, t, pd));

                default:
                    break;
                }
            }
            switch (t)             //若是基础类型
            {
            case DataType.undef: return(new PD_Array(v, t, pd));

            case DataType.str: return(new PD_Str(v, t, pd));

            case DataType.u8:
            case DataType.u16:
            case DataType.u32:
            case DataType.u64:
            case DataType.s8:
            case DataType.s16:
            case DataType.s32:
            case DataType.s64:
            case DataType.f:
            case DataType.df: return(new PD_Node(v, t, pd));

            default: throw new Exception("type err");
            }
        }
Ejemplo n.º 10
0
 public int len = 0;         //本域的数据长度
 public PD_Array(Dictionary <string, object> v, DataType t, MC_Prot pd) : base(v, t, pd)
 {
     len = (int)v["len"];
 }