Ejemplo n.º 1
0
        /// <summary>
        /// 解析数据并显示在对话框中,如果shown为真,则同时在对话框的设置项中显示单独数据
        /// </summary>
        /// <param name="ba"></param>
        private string ParseDataAndDisplay(BitArray ba, bool shown)
        {
            MainForm.ParseLock.WaitOne();
            SourceDataClass.GetData(ba);
            int    nodeid   = SourceDataClass.GetIntValueFromBit(6);
            int    nodetype = SourceDataClass.GetIntValueFromBit(1);
            int    emit     = SourceDataClass.GetIntValueFromBit(3);
            int    set1     = SourceDataClass.GetIntValueFromBit(8);
            int    set2     = SourceDataClass.GetIntValueFromBit(8);
            int    energy   = SourceDataClass.GetIntValueFromBit(3);
            Int16  commtype = (short)SourceDataClass.GetIntValueFromBit(16);
            int    n        = SourceDataClass.GetIntValueFromBit(28);
            double lang     = 0;

            if (n >> 27 == 1)//西经
            {
                n   &= 0x7ffffff;
                lang = (double)n / 10000 / 60;
                lang = -lang;
            }
            else//北纬
            {
                n   &= 0x7ffffff;
                lang = (double)n / 10000 / 60;
            }
            n = SourceDataClass.GetIntValueFromBit(28);
            double lat = 0;

            if (n >> 27 == 1)//南纬
            {
                n  &= 0x7ffffff;
                lat = (double)n / 10000 / 60;
                lat = -lang;
            }
            else//北纬
            {
                n  &= 0x7ffffff;
                lat = (double)n / 10000 / 60;
            }
            double depth = SourceDataClass.GetIntValueFromBit(14) * 0.5;

            SourceDataClass.clear();
            MainForm.ParseLock.ReleaseMutex();
            if (shown)
            {
                NodeNameBox.Text = "节点" + nodeid;
                Nodetypebox.Text = nodetype == 1?"移动节点":"静态节点";
                EmitSet.Value    = emit;
                Set1Box.Text     = Enum.GetName(typeof(SourceDataClass.DeviceAddr), set1);
                Set2Box.Text     = Enum.GetName(typeof(SourceDataClass.DeviceAddr), set2);
                if (energy == 0)
                {
                    leftenergy.Value = 5;
                }
                else if (energy == 1)
                {
                    leftenergy.Value = 20;
                }
                else if (energy == 2)
                {
                    leftenergy.Value = 35;
                }
                else if (energy == 3)
                {
                    leftenergy.Value = 50;
                }
                else if (energy == 4)
                {
                    leftenergy.Value = 65;
                }
                else if (energy == 5)
                {
                    leftenergy.Value = 80;
                }
                else if (energy == 6)
                {
                    leftenergy.Value = 95;
                }
                byte[]   b = BitConverter.GetBytes(commtype);
                BitArray a = new BitArray(b);
                for (int i = 0; i < 16; i++)
                {
                    CommType.SetItemChecked(i, false);
                }
                for (int i = 0; i < a.Count; i++)
                {
                    CommType.SetItemChecked(i, a[i]);
                }
                Lat.Value        = lat;
                Lang.Value       = lang;
                DepthInput.Value = depth;
            }
            return("节点" + nodeid + ":" + ((nodetype == 1) ? " 移动节点" : " 静态节点") + " 换能器数" + emit.ToString()
                   + " " + Enum.GetName(typeof(SourceDataClass.DeviceAddr), set1) + " " + Enum.GetName(typeof(SourceDataClass.DeviceAddr), set2)
                   + " 能量 " + energy.ToString() + " 纬度 " + lat.ToString() + " 经度 " + lang.ToString() + " 深度 "
                   + depth.ToString());
        }