private void StatusHandleReport(UInt16 source, MsgReport msg) { // update status lock (_statusLock) { int index = StatusGetNode(source, true, false); _status[index].traffic = new TrafficStatus[msg.nodeCount]; for (int i = 0; i < msg.nodeCount; i++) { _status[index].traffic[i].addr = msg.nodes[i].addr; _status[index].traffic[i].rxBps = msg.nodes[i].rxBps; } } }
private void DataIndicationHandler( object sender, UInt16 source, UInt16 targetShortAddr, Frame frame) { lock (_msgReport) { Message msg = (Message)frame.ReadByte(0); switch (msg) { case Message.Data: { if (_testMode) { _monitor.Print("received frame from 0x" + HexConverter.ConvertUintToHex(source, 4) + ", sduHandle=" + frame.ReadByte(1) + ", len=" + frame.LengthDataUsed + " bytes"); } for (int i = 0; i < _msgReport.nodeCount; i++) { if (_msgReport.nodes[i].addr == source) { _msgReport.nodes[i].rxBps += (UInt32)frame.LengthDataUsed; return; } } if (_msgReport.nodeCount < _msgReport.nodes.Length) { _msgReport.nodes[_msgReport.nodeCount].addr = source; _msgReport.nodes[_msgReport.nodeCount].rxBps = (UInt32)frame.LengthDataUsed; _msgReport.nodeCount++; } break; } case Message.Report: { MsgReport rep = new MsgReport(); if (rep.ReadFromFrame(frame)) { if (_testMode) { _monitor.Print("Report from node 0x" + HexConverter.ConvertUintToHex(source, 4) + ":"); for (int i = 0; i < rep.nodeCount; i++) { _monitor.Print(" " + rep.nodes[i].rxBps + " bytes per second from 0x" + HexConverter.ConvertUintToHex(rep.nodes[i].addr, 4)); } } if (_coordinator) { StatusHandleReport(source, rep); } } break; } case Message.Neighbors: { MsgNeighbors neigh = new MsgNeighbors(); if (neigh.ReadFromFrame(frame)) { if (_testMode) { _monitor.Print("Neighbors from node 0x" + HexConverter.ConvertUintToHex(source, 4) + ":"); for (int i = 0; i < neigh.neighborCount; i++) { _monitor.Print(" 0x" + HexConverter.ConvertUintToHex(neigh.neighbors[i].shortAdr, 4) + ": " + neigh.neighbors[i].lqi); } } if (_coordinator) { StatusHandleNeighbors(source, neigh); } } break; } } } Frame.Release(ref frame); }
public void StartSink() { StopSink(); _msgReport = new MsgReport(); _msgReport.nodes = new MsgReport.Node[16]; _net.DataIndication = DataIndicationHandler; _net.NodeChangedIndication = NodeChangedHandler; if (_coordinator) _reportInterval = cReportIntervalDefault * 2; // report only every second interval to ensure that we have the reports from all nodes _timerReport = new Timer(ReportCallback, null, _reportInterval, _reportInterval); _status = new NodeStatus[0]; }
public void StartSink() { StopSink(); _msgReport = new MsgReport(); _msgReport.nodes = new MsgReport.Node[16]; _net.DataIndication = DataIndicationHandler; _net.NodeChangedIndication = NodeChangedHandler; if (_coordinator) { _reportInterval = cReportIntervalDefault * 2; // report only every second interval to ensure that we have the reports from all nodes } _timerReport = new Timer(ReportCallback, null, _reportInterval, _reportInterval); _status = new NodeStatus[0]; }