示例#1
0
文件: Mac.cs 项目: prabby/miniclr
        private Frame Encode(Header header, Command.Base cmd)
        {
            int lenHeader = header.Length();
            int len = _state.phyFrameHead + lenHeader; ;
            Frame frame = Frame.GetFrame(len, cmd.LengthMax + _state.phyFrameTail);
            if (!cmd.WriteToFrame(frame) || !header.WriteToFrameHeader(frame))
            {
                Frame.Release(ref frame);
                Trace.Print("Mac: unable to create command frame");
                return null;
            }

            return frame;
        }
        private void BeaconRequest()
        {
            bool send = true;
            Frame frame = null;

            lock (_state)
            {
                if (_state.autoBeacon)
                {
                    Header hdr = new Header();
                    hdr.fcs.SrcAddrMode = AddressingMode.Short;
                    hdr.srcAddrShort = _state.macShortAddr;
                    hdr.srcPanId = _state.macPanId;
                    hdr.seqNo = _state.macBSN++;

                    Beacon bc = new Beacon();
                    bc.beaconOrder = _state.macBeaconOrder;
                    bc.superframeOrder = _state.macSuperframeOrder;
                    // finalCapSlot
                    // batteryLifeExtension
                    if (_state.panCoordinator)
                        bc.panCoordinator = 1;
                    bc.associationPermit = 0;
                    // gtsPermit
                    // gtsDirectionsMask
                    // gtsDescriptor;
                    // shortAddrPending;
                    // extAddrPending;
                    bc.payload = _state.macBeaconPayload;

                    int lenHeader = hdr.Length();
                    int len = _state.phyFrameHead + lenHeader; ;
                    frame = Frame.GetFrame(len + bc.Length() + _state.phyFrameTail);
                    frame.ReserveHeader(len);
                    if (bc.WriteToFrame(frame) && hdr.WriteToFrameHeader(frame))
                    {
                        send = true;
                    }
                }
            }

            if (send)
            {
                _sendReceive.SendFrame(ref frame, false, 0);
            }

            Frame.Release(ref frame);
        }