public override string ToString() { return("AddressReply [HopsLeft: " + HopsLeft + ", BrokerAddr: 0x" + HexConverter.ConvertUintToHex(BrokerAddr, 4) + ", DeviceAddr: 0x" + HexConverter.ConvertUint64ToHex(DeviceAddr, 16) + ", ShortAddr: 0x" + HexConverter.ConvertUintToHex(ShortAddr, 4) + ", DiscoveryInterval: " + DiscoveryInterval + "]"); }
/// <summary> /// allocate a short address /// </summary> /// <param name="extAddr">the extended address of the target node</param> /// <param name="shortAddr">the allocated short address</param> /// <returns>true on success</returns> public virtual bool AllocateAddress(UInt64 extAddr, out UInt16 shortAddr) { lock (_addresses) { int bucket = (int)(extAddr % cBuckets); // lookup old addr ArrayList list = _addresses.data[bucket]; Mapping mapping; int count = list.Count; for (int i = 0; i < count; i++) { mapping = (Mapping)list[i]; if (mapping.extAddr == extAddr) { shortAddr = mapping.shortAddr; return(true); } } // allocate new addr if (_addresses.nextAddr > cLastAddr) { shortAddr = 0; return(false); } shortAddr = _addresses.nextAddr++; // store addr mapping = new Mapping(); mapping.extAddr = extAddr; mapping.shortAddr = shortAddr; list.Add(mapping); Trace.Print("Allocating short address 0x" + HexConverter.ConvertUintToHex(shortAddr, 4) + " for device 0x" + HexConverter.ConvertUint64ToHex(extAddr, 16)); return(true); } }
public void Run(AutoResetEvent stopEvent) { UInt64 extAddr; _net.GetDeviceAddress(out extAddr); _monitor.Print("Device address is 0x" + HexConverter.ConvertUint64ToHex(extAddr, 16)); _monitor.Print("Frame structure: mtu=" + _mtu + ", head=" + _head + ", tail=" + _tail); UInt16 panId = 0x6366; AutoResetEvent callback = new AutoResetEvent(false); bool started = false; UInt16 shortAddr = 0; Byte logicalChannel = 0; Byte channelPage = 0; #if MICROFRAMEWORK _coordinator = false; #else _coordinator = true; #endif _monitor.Print("attempting to start network layer"); while (!started) { if (_coordinator) { _monitor.Print("StartRequest for PanId=0x" + HexConverter.ConvertUint64ToHex(panId, 4)); _net.StartRequest(panId, delegate( object sender, Status status, UInt16 _shortAddr, Byte _logicalChannel, Byte _channelPage) { _monitor.Print("StartConfirm: " + status.ToString()); if (status == Status.Success) { shortAddr = _shortAddr; logicalChannel = _logicalChannel; channelPage = _channelPage; started = true; } callback.Set(); }); } else { _monitor.Print("JoinRequest for PanId=0x" + HexConverter.ConvertUint64ToHex(panId, 4)); _net.JoinRequest(panId, delegate( object sender, Status status, UInt16 _shortAddr, Byte _logicalChannel, Byte _channelPage) { _monitor.Print("JoinConfirm: " + status.ToString()); if (status == Status.Success) { shortAddr = _shortAddr; logicalChannel = _logicalChannel; channelPage = _channelPage; started = true; } callback.Set(); }); } callback.WaitOne(); } _monitor.Print("network is running, logicalChannel=" + logicalChannel + ", channelPage=" + channelPage + ", shortAddr=0x" + HexConverter.ConvertUintToHex(shortAddr, 4)); _testMode = true; StartSink(); if (_coordinator) { StartSource(); } if (stopEvent != null) { stopEvent.WaitOne(); } else { for (; ;) { Thread.Sleep(60 * 1000); } } StopSource(); StopSink(); }
/// <summary> /// Returns a string representation of the object /// </summary> /// <returns>a string represetnation</returns> public override string ToString() { string description = fcs.ToString(); description += ", seqNo: " + seqNo.ToString(); AddressingMode dstMode = fcs.DstAddrMode; AddressingMode srcMode = fcs.SrcAddrMode; switch (dstMode) { case AddressingMode.None: description += ", no dst"; break; case AddressingMode.Reserved: description += ", bad dst"; break; case AddressingMode.Short: description += ", dstPanId: " + dstPanId.ToString(); description += ", dstAddrShort: " + HexConverter.ConvertUintToHex(dstAddrShort, 4); break; case AddressingMode.Extended: description += ", dstPanId: " + dstPanId.ToString(); description += ", dstAddrExt: " + HexConverter.ConvertUint64ToHex(dstAddrExt, 16); break; default: description += ", bad dst"; break; } switch (srcMode) { case AddressingMode.None: description += ", no src"; break; case AddressingMode.Reserved: description += ", bad src"; break; case AddressingMode.Short: if (!fcs.PanIdCompression) { description += ", srcPanId: " + srcPanId.ToString(); } description += ", srcAddrShort: " + HexConverter.ConvertUintToHex(srcAddrShort, 4); break; case AddressingMode.Extended: if (!fcs.PanIdCompression) { description += ", srcPanId: " + srcPanId.ToString(); } description += ", srcAddrExt: " + HexConverter.ConvertUint64ToHex(srcAddrExt, 16); break; default: description += ", bad src"; break; } // FIXME: secHeader return(description); }
public override string ToString() { return("AddressRequest [HopsLeft: " + HopsLeft + ", BrokerAddr: 0x" + HexConverter.ConvertUintToHex(BrokerAddr, 4) + ", DeviceAddr: 0x" + HexConverter.ConvertUint64ToHex(DeviceAddr, 16) + "]"); }