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); }
private void StatusHandleNeighbors(UInt16 source, MsgNeighbors msg) { // update status lock (_statusLock) { int index = StatusGetNode(source, true, false); _status[index].neighbors = new NeighborStatus[msg.neighborCount]; for (int i = 0; i < msg.neighborCount; i++) { _status[index].neighbors[i].addr = msg.neighbors[i].shortAdr; _status[index].neighbors[i].lqi = msg.neighbors[i].lqi; } } }
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; } } }
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; } } }