コード例 #1
0
        private void SendBeacon()
        {
            if (_host == null)
            {
                return;
            }
            Message.NeighborhoodDiscovery msg = new Message.NeighborhoodDiscovery();
            lock (_lock)
            {
                int count = _neighbours.Count;
                msg.Neighbours = new Message.NeighborhoodDiscovery.Neighbour[count];
                for (int i = 0; i < count; i++)
                {
                    Entry e = (Entry)_neighbours[i];
                    msg.Neighbours[i].Address = e.addrShort;
                    msg.Neighbours[i].Lqi     = e.lqiRx;
                }
            }

            Frame frame = Frame.GetFrame(_macHeader, msg.Length() + _macTailer);

            if (frame == null)
            {
                return;
            }
            if (msg.WriteToFrame(frame))
            {
                _host.SendBeacon(ref frame);
            }
            Frame.Release(ref frame);
        }
コード例 #2
0
ファイル: NeighbourTable.cs プロジェクト: prabby/miniclr
        private void SendBeacon()
        {
            if (_host == null)
                return;
            Message.NeighborhoodDiscovery msg = new Message.NeighborhoodDiscovery();
            lock (_lock)
            {
                int count = _neighbours.Count;
                msg.Neighbours = new Message.NeighborhoodDiscovery.Neighbour[count];
                for (int i = 0; i < count; i++)
                {
                    Entry e = (Entry)_neighbours[i];
                    msg.Neighbours[i].Address = e.addrShort;
                    msg.Neighbours[i].Lqi = e.lqiRx;
                }
            }

            Frame frame = Frame.GetFrame(_macHeader, msg.Length() + _macTailer);
            if (frame == null)
                return;
            if (msg.WriteToFrame(frame))
                _host.SendBeacon(ref frame);
            Frame.Release(ref frame);
        }
コード例 #3
0
        /// <summary>
        /// process received beacon
        /// </summary>
        /// <param name="senderAddr">address of sender of beacon</param>
        /// <param name="sdu">encoded beacon</param>
        /// <param name="lqi">LQI of beacon message</param>
        public void ReceiveBeacon(UInt16 senderAddr, ref Frame sdu, byte lqi)
        {
            if (sdu == null)
            {
                return;
            }
            Message.NeighborhoodDiscovery msg = new Message.NeighborhoodDiscovery();
            if (msg.ReadFromFrame(sdu))
            {
                lock (_lock)
                {
                    // check if we know this node
                    Entry e     = null;
                    int   count = _neighbours.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Entry _e = _neighbours[i] as Entry;
                        if (_e != null && _e.addrShort == senderAddr)
                        {
                            e = _e;
                            break;
                        }
                    }

                    // create/update our entry
                    if (e == null)
                    {
                        e           = new Entry();
                        e.addrShort = senderAddr;
                        if (_neighbours.Count < cMaxSize)
                        {
                            _neighbours.Add(e);
                        }
                    }

                    e.lqiRx       = lqi;
                    e.lqiTx       = 0;
                    e.lqiTxValid  = false;
                    e.missCounter = 0;

                    if (_neighbours.Count > cMaxSize)
                    {
                        // remove worst entry
                        byte lqiWorst = 0xff;
                        int  iWorst   = 0;
                        count = _neighbours.Count;
                        for (int i = 0; i < count; i++)
                        {
                            Entry eWorst = _neighbours[i] as Entry;
                            if (eWorst != null && eWorst.lqiRx < lqiWorst)
                            {
                                lqiWorst = eWorst.lqiRx;
                                iWorst   = i;
                            }
                        }

                        _neighbours.RemoveAt(iWorst);
                    }

                    // check if this node has information on us
                    if (msg.Neighbours != null)
                    {
                        int length = msg.Neighbours.Length;
                        for (int i = 0; i < length; i++)
                        {
                            if (msg.Neighbours[i].Address == _localAddr)
                            {
                                e.lqiTxValid = true;
                                e.lqiTx      = msg.Neighbours[i].Lqi;
                                break;
                            }
                        }
                    }
                }
            }

            Frame.Release(ref sdu);
        }
コード例 #4
0
ファイル: NeighbourTable.cs プロジェクト: prabby/miniclr
        /// <summary>
        /// process received beacon
        /// </summary>
        /// <param name="senderAddr">address of sender of beacon</param>
        /// <param name="sdu">encoded beacon</param>
        /// <param name="lqi">LQI of beacon message</param>
        public void ReceiveBeacon(UInt16 senderAddr, ref Frame sdu, byte lqi)
        {
            if (sdu == null)
                return;
            Message.NeighborhoodDiscovery msg = new Message.NeighborhoodDiscovery();
            if (msg.ReadFromFrame(sdu))
            {
                lock (_lock)
                {
                    // check if we know this node
                    Entry e = null;
                    int count = _neighbours.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Entry _e = _neighbours[i] as Entry;
                        if (_e != null && _e.addrShort == senderAddr)
                        {
                            e = _e;
                            break;
                        }
                    }

                    // create/update our entry
                    if (e == null)
                    {
                        e = new Entry();
                        e.addrShort = senderAddr;
                        if (_neighbours.Count < cMaxSize)
                            _neighbours.Add(e);
                    }

                    e.lqiRx = lqi;
                    e.lqiTx = 0;
                    e.lqiTxValid = false;
                    e.missCounter = 0;

                    if (_neighbours.Count > cMaxSize)
                    {
                        // remove worst entry
                        byte lqiWorst = 0xff;
                        int iWorst = 0;
                        count = _neighbours.Count;
                        for (int i = 0; i < count; i++)
                        {
                            Entry eWorst = _neighbours[i] as Entry;
                            if (eWorst != null && eWorst.lqiRx < lqiWorst)
                            {
                                lqiWorst = eWorst.lqiRx;
                                iWorst = i;
                            }
                        }

                        _neighbours.RemoveAt(iWorst);
                    }

                    // check if this node has information on us
                    if (msg.Neighbours != null)
                    {
                        int length = msg.Neighbours.Length;
                        for (int i = 0; i < length; i++)
                        {
                            if (msg.Neighbours[i].Address == _localAddr)
                            {
                                e.lqiTxValid = true;
                                e.lqiTx = msg.Neighbours[i].Lqi;
                                break;
                            }
                        }
                    }
                }
            }

            Frame.Release(ref sdu);
        }