Example #1
0
        public override void SetData(byte[] data, int startIndex, int len)
        {
            CheckData(data, startIndex, len);
            Array.Copy(data, startIndex, InsideData, 0, 3);
            int addrValueIndex = startIndex + 3;

            // 初始化中继地址列表
            if (RouteAddrList == null)
            {
                RouteAddrList = new List <NetAddr>();
            }
            RouteAddrList.Clear();

            for (int i = 0; i < RouteNodeNum; i++)
            {
                // 获取第i个中继地址模式
                var emLen = (EmAddrLen)InsideData.GetBits(10 + 2 * i, 2);

                NetAddr addr = new NetAddr()
                {
                    AddrMode = emLen
                };
                int addrLen = emLen == EmAddrLen.Two ? 2 : 6;
                addr.Value = new byte[addrLen];
                if (addrValueIndex + addrLen > len)
                {
                    throw new ArgumentOutOfRangeException("len", "len的长度不够");
                }
                addr.SetData(data, addrValueIndex, addrLen);
                addrValueIndex += addrLen;
                RouteAddrList.Add(addr);
            }
        }
Example #2
0
 /// <summary>
 /// 中继列表地址模式变动后 更新中继列表
 /// </summary>
 private void UpdateAddrList()
 {
     RouteAddrList.Clear();
     for (int i = 0; i < RouteNodeNum; i++)
     {
         // 获取第i个中继地址模式
         var     emLen = (EmAddrLen)InsideData.GetBits(10 + 2 * i, 2);
         NetAddr addr  = new NetAddr();
         addr.AddrMode = emLen;
         RouteAddrList.Add(addr);
     }
 }
Example #3
0
        /// <summary>
        /// 添加中继地址 自动设置 中继列表地址模式、中继索引、中继节点数
        /// </summary>
        /// <param name="addr"></param>
        public void Add(NetAddr addr)
        {
            if (addr == null)
            {
                throw new ArgumentNullException("addr", "addr不能为空");
            }
            if (RouteNodeNum > 6)
            {
                throw new Exception("中继地址已经超过了6个 不能再添加");
            }
            var mode = addr.AddrMode;

            InsideData.SetBits(10 + 2 * RouteNodeNum, 2, (byte)mode);
            RouteNodeNum++;
            RouteIndex++;
            RouteAddrList.Add(addr);
        }
Example #4
0
        public override void SetData(byte[] data, int startIndex, int len)
        {
            CheckData(data, startIndex, len);
            Ctrl.SetData(data, startIndex, 1);
            int targetAddrLen = Ctrl.TargetAddrMode == EmAddrLen.Two ? 2 : 6;
            int sourceAddrLen = Ctrl.SourceAddrMode == EmAddrLen.Two ? 2 : 6;

            TargetAddr.AddrMode = Ctrl.TargetAddrMode;
            TargetAddr.SetData(data, startIndex + 1, targetAddrLen);
            SourceAddr.AddrMode = Ctrl.SourceAddrMode;
            SourceAddr.SetData(data, startIndex + 1 + targetAddrLen, sourceAddrLen);

            byte seqAndRadius = data[startIndex + 1 + targetAddrLen + sourceAddrLen];

            Seq.Value    = (byte)(seqAndRadius >> 4);
            Radius.Value = (byte)(seqAndRadius & 0x0F);

            int curPos = startIndex + 2 + targetAddrLen + sourceAddrLen;

            if (Ctrl.RoutingInstruction == 1)
            {
                byte[] routeInfoValue = new byte[3];
                Array.Copy(data, curPos, routeInfoValue, 0, 3);
                //这里不能用下面的方式赋值 因为无法更新中继列表
                //Array.Copy(data, curPos, RouteInfo.Value, 0, 3);
                RouteInfo.Value = routeInfoValue;
                curPos         += 3;
                if (RouteInfo.RouteNodeNum > 6)
                {
                    throw new Exception("路由信息域 中继节点数不能超过6");
                }
                if (RouteInfo.RouteIndex > 6)
                {
                    throw new Exception("路由信息域 中继索引不能超过6");
                }
                for (int i = 0; i < RouteInfo.RouteNodeNum; i++)
                {
                    NetAddr na = RouteInfo.RouteAddrList[i];
                    if (na.AddrMode == EmAddrLen.Two)
                    {
                        na.SetData(data, curPos, 2);
                        curPos += 2;
                    }
                    else
                    {
                        na.SetData(data, curPos, 6);
                        curPos += 6;
                    }
                }
            }
            if (Ctrl.FrameType == EmNetFrameType.Command)
            {
                Du = new NetCmd();
                Du.SetData(data, curPos, startIndex + len - curPos);
            }
            else if (Ctrl.FrameType == EmNetFrameType.Data)
            {
                Du = new ApsFrame();
                Du.SetData(data, curPos, startIndex + len - curPos);
            }
        }