Exemple #1
0
        private void NeighborConfirmHandler(
            object sender,
            Status status,
            Neighbor[] neighbors)
        {
            MsgNeighbors msg = new MsgNeighbors();

            msg.neighbors     = neighbors;
            msg.neighborCount = 0;
            if (neighbors != null)
            {
                msg.neighborCount = neighbors.Length;
            }

            Frame frame = null;

            if (msg.neighborCount > 0)
            {
                frame = Frame.GetFrame(_head, msg.Length() + _tail);
                if (msg.WriteToFrame(frame))
                {
                    _net.DataRequest(0, ref frame, 0, null);
                }

                Frame.Release(ref frame);
            }

            if (_coordinator)
            {
                lock (_statusLock)
                {
                    for (int i = 0; i < _status.Length; i++)
                    {
                        _status[i].txBps = (_status[i].txBps * 1000) / (UInt32)_reportInterval;
                    }

                    _monitor.Status(_status);
                    // reset status
                    NodeStatus[] res = new NodeStatus[_status.Length];
                    for (int i = 0; i < _status.Length; i++)
                    {
                        res[i].addr = _status[i].addr;
                    }

                    _status = res;
                }
            }
        }
Exemple #2
0
        private int StatusGetNode(UInt16 addr, bool add, bool delete)
        {
            int index = -1;;

            for (int i = 0; i < _status.Length; i++)
            {
                if (_status[i].addr == addr)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1 && add)
            {
                // add to array
                NodeStatus[] res = new NodeStatus[_status.Length + 1];
                index = _status.Length;
                for (int i = 0; i < _status.Length; i++)
                {
                    res[i] = _status[i];
                }
                res[index]      = new NodeStatus();
                res[index].addr = addr;
                _status         = res;
            }

            if (index != -1 && delete)
            {
                // remove from array
                NodeStatus[] res = new NodeStatus[_status.Length - 1];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = _status[i];
                }
                if (index != res.Length)
                {
                    res[index] = _status[res.Length];
                }
                _status = res;
                index   = -1;
            }

            return(index);
        }
Exemple #3
0
        private void StatusInit(UInt16[] nodes)
        {
            lock (_statusLock)
            {
                int len = 0;
                if (nodes != null)
                {
                    len = nodes.Length;
                }
                _status = new NodeStatus[len];
                for (int i = 0; i < len; i++)
                {
                    _status[i]      = new NodeStatus();
                    _status[i].addr = nodes[i];
                }

                StatusGetNode(0, true, false); // ensure that local node is present
            }
        }
Exemple #4
0
            public void Status(NodeStatus[] status)
            {
                Print("Status update");
                if (status != null)
                {
                    for (int i = 0; i < status.Length; i++)
                    {
                        Print("0x" + HexConverter.ConvertUintToHex(status[i].addr, 4) + ":");

                        if (status[i].txBps > 0)
                        {
                            Print("  TX: " + status[i].txBps.ToString() + " bytes/s");
                        }

                        if (status[i].neighbors == null || status[i].neighbors.Length == 0)
                        {
                            Print("  no neighbors");
                        }
                        else
                        {
                            for (int j = 0; j < status[i].neighbors.Length; j++)
                            {
                                Print("  neighbor 0x" + HexConverter.ConvertUintToHex(status[i].neighbors[j].addr, 4) +
                                    ": LQI " + status[i].neighbors[j].lqi);
                            }
                        }

                        if (status[i].traffic == null || status[i].traffic.Length == 0)
                        {
                            Print("  no traffic");
                        }
                        else
                        {
                            for (int j = 0; j < status[i].traffic.Length; j++)
                            {
                                Print("  traffic from 0x" + HexConverter.ConvertUintToHex(status[i].traffic[j].addr, 4) +
                                    ": " + status[i].traffic[j].rxBps + " bytes/sec");
                            }
                        }
                    }
                }
            }
Exemple #5
0
        private void NeighborConfirmHandler(
            object sender,
            Status status,
            Neighbor[] neighbors)
        {
            MsgNeighbors msg = new MsgNeighbors();
            msg.neighbors = neighbors;
            msg.neighborCount = 0;
            if (neighbors != null)
                msg.neighborCount = neighbors.Length;

            Frame frame = null;
            if (msg.neighborCount > 0)
            {
                frame = Frame.GetFrame(_head, msg.Length() + _tail);
                if (msg.WriteToFrame(frame))
                {
                    _net.DataRequest(0, ref frame, 0, null);
                }

                Frame.Release(ref frame);
            }

            if (_coordinator)
            {
                lock (_statusLock)
                {
                    for (int i = 0; i < _status.Length; i++)
                        _status[i].txBps = (_status[i].txBps * 1000) / (UInt32)_reportInterval;

                    _monitor.Status(_status);
                    // reset status
                    NodeStatus[] res = new NodeStatus[_status.Length];
                    for (int i = 0; i < _status.Length; i++)
                    {
                        res[i].addr = _status[i].addr;
                    }

                    _status = res;
                }
            }
        }
Exemple #6
0
        private int StatusGetNode(UInt16 addr, bool add, bool delete)
        {
            int index = -1; ;
            for (int i = 0; i < _status.Length; i++)
            {
                if (_status[i].addr == addr)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1 && add)
            {
                // add to array
                NodeStatus[] res = new NodeStatus[_status.Length + 1];
                index = _status.Length;
                for (int i = 0; i < _status.Length; i++)
                    res[i] = _status[i];
                res[index] = new NodeStatus();
                res[index].addr = addr;
                _status = res;
            }

            if (index != -1 && delete)
            {
                // remove from array
                NodeStatus[] res = new NodeStatus[_status.Length - 1];
                for (int i = 0; i < res.Length; i++)
                    res[i] = _status[i];
                if (index != res.Length)
                    res[index] = _status[res.Length];
                _status = res;
                index = -1;
            }

            return index;
        }
Exemple #7
0
        private void StatusInit(UInt16[] nodes)
        {
            lock (_statusLock)
            {
                int len = 0;
                if (nodes != null)
                    len = nodes.Length;
                _status = new NodeStatus[len];
                for (int i = 0; i < len; i++)
                {
                    _status[i] = new NodeStatus();
                    _status[i].addr = nodes[i];
                }

                StatusGetNode(0, true, false); // ensure that local node is present
            }
        }