예제 #1
0
        private void ReadInitialValues()
        {
            LowpanIdentity   = new LowpanIdentity(wpanApi);
            LowpanCredential = new LowpanCredential(wpanApi);
            LowpanScanner    = new LowpanScanner(wpanApi);

            ncpVersion            = wpanApi.GetPropNcpVersion();
            protocolVersion       = wpanApi.GetPropProtocolVersion();
            interfaceType         = (SpinelProtocolType)wpanApi.GetPropInterfaceType();
            vendor                = wpanApi.GetPropVendorId().ToString();
            capabilities          = wpanApi.GetPropCaps();
            supportedChannels     = wpanApi.GetPhyChanSupported();
            networkInterfaceState = wpanApi.GetNetIfUp();
            threadStackState      = wpanApi.GetNetStackUp();
            netRole               = (SpinelNetRole)wpanApi.GetNetRole();
            extendedAddress       = new HardwareAddress(wpanApi.GetMac_15_4_Laddr().bytes);
            hardwareAddress       = new HardwareAddress(wpanApi.GetPropHwaddr().bytes);
            ipAddresses           = NetUtilities.SpinelIPtoSystemIP(wpanApi.GetIPv6AddressTable());

            ipLinkLocal = new IPAddress(wpanApi.GetIPv6LLAddr().bytes);
            ipMeshLocal = new IPAddress(wpanApi.GetIPv6MLAddr().bytes);
            lastStatus  = (SpinelStatus)wpanApi.GetPropLastStatus();
        }
예제 #2
0
        public void Form(string networkName, byte channel, string masterkey = null, ushort panid = 0xFFFF)
        {
            if (networkName == string.Empty)
            {
                throw new ArgumentException("Networkname cannot be null or empty");
            }

            if (channel < 11 || channel > 26)
            {
                throw new ArgumentException("Channel number should be in between 11 and 26");
            }



            var scanResult = LowpanScanner.ScanBeacon();

            bool netExisted = false;

            if (scanResult != null)
            {
                foreach (var beacon in scanResult)
                {
                    if (beacon.NetworkName == networkName && beacon.Channel == channel)
                    {
                        netExisted = true;
                        break;
                    }
                }
            }

            if (netExisted)
            {
                throw new ArgumentException("Networkname with provided identity already exists.");
            }

            if (!ShutDownNetwork())
            {
                throw new ArgumentException("Shut Down network exception");
            }

            LowpanIdentity.Channel     = channel;
            LowpanIdentity.NetworkName = networkName;

            if (!NetworkInterfaceUp())
            {
                throw new InvalidOperationException("Interface up exception");
            }

            if (panid != 0xFFFF)
            {
                this.LowpanIdentity.Panid = panid;
            }

            if (masterkey != string.Empty)
            {
                this.LowpanCredential.MasterKey = Utilities.HexToBytes(masterkey);
            }

            if (!ThreadStackUp())
            {
                throw new InvalidOperationException("Thread start exception");
            }
        }