Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Add a CoApDevice to the list of devices.
 /// </summary>
 /// <param name="value">the CoApDevice to add to the device collection</param>
 /// <returns>the index of the added item</returns>
 public int Add(CoApDevice value)
 {
     return(InnerList.Add(value));
 }
        /// <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);
        }