Example #1
0
        private void LoadNodes()
        {
            CoApDeviceFinder finder  = (CoApDeviceFinder)NetworkInterface.Instance.NodeFinder;
            CoApDevices      devices = finder.LoadNodes();

            foreach (CoApDevice d in devices)
            {
                lstDevices.Items.Add(d.Name);
            }
        }
Example #2
0
        /// <summary>
        /// Find all CoAP devices defined in the simulator.
        /// </summary>
        /// <returns>A list of CoApDevice objects representing all registered devices</returns>
        public override CoApDevices LoadNodes()
        {
            CoApDevices devices = new CoApDevices();

            RequestDeviceList();
            if (__FindResult != null)
            {
                string[] devs = __FindResult.Split(';');
                foreach (string dev in devs)
                {
                    CoApDevice d = new CoApDevice(dev);
                    devices.Add(d);
                    d.Reachable = true;
                }
            }

            return(devices);
        }
Example #3
0
        /// <summary>
        /// Load devices based on the network interface settings.
        /// For each valid device, load a list of related CoAP resources.
        /// </summary>
        private void LoadNodes()
        {
            Cursor.Current = Cursors.WaitCursor;    // Show as buys while loading the resources.

            FileLogger.Write("Loading all known devices");

            // Load the correct device class based on current network option
            CoApDeviceFinder finder  = (CoApDeviceFinder)NetworkInterface.Instance.NodeFinder;
            CoApDevices      devices = new CoApDevices();

            try
            {
                // With the Ping change, we are capturing the gateway credentials earlier than we had planned.
                //SetGatewayCoapApiCredentials();
                devices = finder.LoadNodes();
            }
            catch (Exception devFail)
            {
                MessageBox.Show("Device fetch failed - " + devFail.Message);
                return;
            }

            // Loop through all fetched devices.
            // If the device was successfully pinged, then we can load related resources.
            // Otherwise, we ignore it.
            foreach (CoApDevice d in devices)
            {
                TreeNode deviceNode = treeDevices.Nodes.Add(d.Name);
                if (d.Reachable)
                {
                    deviceNode.ForeColor = treeDevices.ForeColor;
                    if (NetworkInterface.Instance.UsingGateway)
                    {
                        CoAPSettings.Instance.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork;
                    }
                    if (NetworkInterface.Instance.UsingSimulator)
                    {
                        CoAPSettings.Instance.AddressFamily = System.Net.Sockets.AddressFamily.InterNetworkV6;
                    }
                    // We should never get here, but this is added in case we add other communication methods later.
                    if (!NetworkInterface.Instance.UsingGateway && !NetworkInterface.Instance.UsingSimulator)
                    {
                        if (HdkUtils.IsIPv4Address(d.Name))
                        {
                            CoAPSettings.Instance.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork;
                        }
                        else
                        {
                            CoAPSettings.Instance.AddressFamily = System.Net.Sockets.AddressFamily.InterNetworkV6;
                        }
                    }

                    // We need to load the credentials if they have not already been set.
                    bool credentialsOk = true;
                    //if (NetworkInterface.Instance.UsingGateway)
                    //{
                    //    credentialsOk = SetGatewayCoapApiCredentials();
                    //}

                    // Check to see if we are ready to load resources related to a device.
                    if (__LoadResources && credentialsOk)
                    {
                        //d.Resources = LoadResources(deviceNode);
                    }
                }
                // Unreachable devices will be grayed out.
                else
                {
                    deviceNode.ForeColor = Color.Gray;
                }
            }

            // Expand the tree so that all loaded devices and resources are visible.
            treeDevices.ExpandAll();

            Cursor.Current = Cursors.Default;   // Clear the "busy" cursor
        }
        /// <summary>
        /// Find all Gateway registered CoAP devices.
        /// </summary>
        /// <returns>A list of CoApDevice objects representing all registered devices</returns>
        public override CoApDevices LoadNodes()
        {
            CoAPSettings.Instance.AddressFamily = System.Net.Sockets.AddressFamily.InterNetworkV6;//.InterNetwork;
            CoApDevices devices = new CoApDevices();

            DevicesResponse jsonDevices;

            // Use SLDP API to fetch a list of devices.
            jsonDevices = GetDevices();
            if (jsonDevices != null)
            {
                foreach (SLDPAPI.DevicesResponse.Device dev in jsonDevices.devices)
                {
                    if (dev != null)
                    {
                        if (dev.deviceType == "MILLI")// && dev.domainInfo.nic_macID == "001350050047dc1f")// || dev.domainInfo.nic_macID == "001350050047dd88")
                        {
                            string mac = dev.domainInfo.nic_macID;
                            FileLogger.Write("Processing MAC " + mac);
                            CoApDevice d = new CoApDevice(mac);
                            devices.Add(d);
                            // If the ping fails then tag it as unreachable
                            //if (!j.Succeeded)
                            //{
                            //    d.Name = "UNREACHABLE - " + d.Name;
                            //    d.Reachable = false;
                            //}
                            //else
                            //{
                            d.Reachable = true;
                            //}
                        }
                    }
                }
                //if (jsonDevices.deviceSearch.queryResults != null)
                //{
                //    // Look through all discovered devices and add non-AP devices to the device list.
                //    for (int i = 0; i < jsonDevices.deviceSearch.queryResults.Count; i++)
                //    {

                //        FileLogger.Write("Processing MAC " + jsonDevices.deviceSearch.queryResults[i].nic_macId);
                //        if (jsonDevices.deviceSearch.queryResults[i].nic_imageType == "ACCESS_POINT")
                //        {
                //            FileLogger.Write("Ignoring access point " + jsonDevices.deviceSearch.queryResults[i].nic_macId);
                //        }

                //        // Ignore access points
                //        if (jsonDevices.deviceSearch.queryResults[i].nic_imageType != "ACCESS_POINT")
                //        {
                //            CoApDevice d = new CoApDevice(jsonDevices.deviceSearch.queryResults[i].nic_macId);
                //            devices.Add(d);
                //            // Ping the device
                //            //string ping = PingMacOLD(d.Name);
                //            //// Translate the ping JSON response into an equivalent C# object
                //            //PingResponseGateway j = new PingResponseGateway(ping);
                //            //// If the ping fails then tag it as unreachable
                //            //if (!j.Succeeded)
                //            //{
                //            //    d.Name = "UNREACHABLE - " + d.Name;
                //            //    d.Reachable = false;
                //            //}
                //            //else
                //            //{
                //            //    d.Reachable = true;
                //            //}
                //            bool ping = PingMac(d.Name);
                //            // If the ping fails then tag it as unreachable
                //            if (!ping)
                //            {
                //                d.Name = "UNREACHABLE - " + d.Name;
                //                d.Reachable = false;
                //            }
                //            else
                //            {
                //                d.Reachable = true;
                //            }
                //        }
                //    }
                //}
            }

            return(devices);
        }