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); } }
public override void SetData(byte[] data, int startIndex, int len) { CheckData(data, startIndex, len); int curPos = startIndex; Ctrl.SetData(data, curPos, 2); curPos += 2; if (Ctrl.HasSeq) { Seq.SetData(data, curPos, 1); curPos += 1; } if (Ctrl.HasPanID) { _panID.SetData(data, curPos, 2); curPos += 2; } int targetAddrLen = (Ctrl.TargetAddrMode == EmAddrLen.Two ? 2 : 6); TargetAddr.SetData(data, curPos, targetAddrLen); curPos += targetAddrLen; int sourceAddrLen = (Ctrl.SourceAddrMode == EmAddrLen.Two ? 2 : 6); SourceAddr.SetData(data, curPos, sourceAddrLen); curPos += sourceAddrLen; if (Ctrl.HasExtension) { int extLen = data[curPos]; Extension = new MacExtension(); Extension.SetData(data, curPos, extLen + 1); curPos += extLen + 1; } int duLen = startIndex + len - curPos; switch (Ctrl.FrameType) { case EmMacFrameType.Beacon: Du = new MacBeacon(); Du.SetData(data, curPos, duLen); break; case EmMacFrameType.Data: Du = new NetFrame(); Du.SetData(data, curPos, duLen); break; case EmMacFrameType.Ack: Du = null; break; case EmMacFrameType.Cmd: Du = new MacCmd(); Du.SetData(data, curPos, duLen); break; } }