コード例 #1
0
ファイル: FoscamScout.cs プロジェクト: RBSystems/LoT
        private void FillList()
        {
            lock (this)
            {
                using (var client = new UdpClient(m_portNumber))
                {
                    //configure the socket properly
                    client.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
                    client.Client.EnableBroadcast = true;
                    client.Client.ReceiveTimeout  = 1000;

                    ScoutHelper.BroadcastRequest(request, m_portNumber, logger);

                    try
                    {
                        // loop until you timeout or read a bad client
                        while (true)
                        {
                            //IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
                            //var buf = client.Receive(ref endPoint);
                            //int bytesRead = buf.Length;

                            SocketFlags         socketFlags = SocketFlags.None;
                            IPPacketInformation packetInfo;
                            EndPoint            endPoint = new IPEndPoint(IPAddress.Any, 0);
                            byte[] buf       = new byte[2000];
                            int    bytesRead = client.Client.ReceiveMessageFrom(buf, 0, 2000, ref socketFlags, ref endPoint, out packetInfo);

                            if (ScoutHelper.IsMyAddress(((IPEndPoint)endPoint).Address))
                            {
                                continue;
                            }

                            if (bytesRead < m_offset_router_IP + 4)
                            {
                                logger.Log("Foscam scout got invalid UDP packet of length {0}", bytesRead.ToString());
                                continue;
                            }

                            //var device = CreateDevice(buf, null);

                            var device = CreateDevice(buf, ScoutHelper.GetInterface(packetInfo));

                            currDeviceList.InsertDevice(device);
                        }
                    }
                    catch (SocketException)
                    {
                        //we expect this error becuase of timeout
                    }
                    catch (Exception e)
                    {
                        logger.Log("Exception in FoscamScout FillList: {0}", e.ToString());
                    }

                    client.Close();
                }
            }
        }
コード例 #2
0
        void ScanWifi()
        {
            //we are putting this lock here just in case two of these are running at the same time (e.g., if the ScanNow timer was really short)
            //only one of these calls can be active because of socket conflicts
            lock (this)
            {
                //logger.Log("GadgeteerScout:ScanWifi\n");

                using (var client = new UdpClient(responsePortNumber))
                {
                    //configure the socket properly
                    client.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
                    client.Client.EnableBroadcast = true;
                    client.Client.ReceiveTimeout  = 1000;

                    ScoutHelper.BroadcastRequest(request, queryPortNumber, logger);

                    try
                    {
                        // loop until you timeout or read a bad client
                        while (true)
                        {
                            //var buf = client.Receive(ref endPoint);

                            SocketFlags         socketFlags = SocketFlags.None;
                            EndPoint            endPoint    = new IPEndPoint(IPAddress.Any, 0);
                            IPPacketInformation packetInfo;
                            byte[] buf       = new byte[2000];
                            int    bytesRead = client.Client.ReceiveMessageFrom(buf, 0, 2000, ref socketFlags, ref endPoint, out packetInfo);

                            if (ScoutHelper.IsMyAddress(((IPEndPoint)endPoint).Address))
                            {
                                continue;
                            }

                            var device = CreateDeviceWifi(buf, bytesRead, (IPEndPoint)endPoint, ScoutHelper.GetInterface(packetInfo));
                            currentDeviceList.InsertDevice(device);
                            logger.Log("Put device on devicelist: {0} \n", device.ToString());
                        }
                    }
                    catch
                    {
                        ;
                    }
                }
            }
        }
コード例 #3
0
        private void FillList()
        {
            //var finder = new UPnPDeviceFinder();
            //var devices = finder.FindByType("upnp:rootdevice", 0);

            var devices = ScoutHelper.UpnpGetDevices();

            foreach (UPnPDevice upnpDevice in devices)
            {
                if (IsAxisDevice(upnpDevice))
                {
                    var device = CreateDevice(upnpDevice);

                    currentDeviceList.InsertDevice(device);
                }
            }
        }
コード例 #4
0
ファイル: FoscamScout.cs プロジェクト: RBSystems/LoT
        // this function relies on the following empirically observed behavior of wireless foscams
        //    the MAC address embedded in the discovery response is that of the ethernet NIC
        //    so cameras on WiFi have inconsistency in MAC addresses in discovery response and in ARP
        public List <string> IsDeviceOnWifi(string unqiueDeviceId)
        {
            Device device = currDeviceList.GetDevice(unqiueDeviceId);

            if (device == null)
            {
                return new List <string>()
                       {
                           "Could not find the device in my current list", ""
                       }
            }
            ;

            string macAddress = ScoutHelper.GetMacAddressByIP(IPAddress.Parse(device.DeviceIpAddress)).Replace("-", string.Empty);

            if (macAddress == null)
            {
                return new List <string>()
                       {
                           "Could not get MAC address of device", ""
                       }
            }
            ;

            string uniqueName = GetUniqueName(macAddress);

            if (!uniqueName.Equals(device.UniqueName))
            {
                return new List <string>()
                       {
                           "", "true"
                       }
            }
            ;

            return(new List <string>()
            {
                "", "false"
            });
        }
コード例 #5
0
        public void ReceiveCallback(IAsyncResult ar)
        {
            lock (this)
            {
                if (listenClientClosed)
                {
                    return;
                }
            }

            IPPacketInformation packetInfo;

            int bytesRead = listenClient.Client.EndReceiveMessageFrom(ar, ref asyncSocketFlags, ref asyncRemoteEndPoint, out packetInfo);

            var device = CreateDeviceWifi(asyncBuffer, bytesRead, (IPEndPoint)asyncRemoteEndPoint, ScoutHelper.GetInterface(packetInfo));

            currentDeviceList.InsertDevice(device);

            //logger.Log("GadgeteerListener got packet from {0}", device.UniqueName);

            //let the platform know of the device
            platform.ProcessNewDiscoveryResults(new List <Device>()
            {
                device
            });

            //start listening again
            //listenClient.BeginReceive(new AsyncCallback(ReceiveCallback), null);
            asyncSocketFlags    = SocketFlags.None;
            asyncRemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
            listenClient.Client.BeginReceiveMessageFrom(asyncBuffer, 0, 2000, asyncSocketFlags, ref asyncRemoteEndPoint, new AsyncCallback(ReceiveCallback), null);
        }