示例#1
0
        /**
         * This method is triggered when an image is caught.
         */
        private void camera_PictureCaptured(GTM.GHIElectronics.Camera sender, GT.Picture picture)
        {
            if (throw_allarm || picture == null || !setupComplete)
            {
                return;
            }

            Int32  HeurSum = 0;
            Bitmap bitmapB = picture.MakeBitmap();

            Debug.Print("Image captured! ");
            try
            {
                if (contImage < 2)
                {
                    if (contImage == 0)
                    {
                        setupCameraTakePicture();
                    }
                    contImage++;
                    return;
                }

                if (bitmapA == null)    //per gestire la prima volta
                {
                    WindowsManager.showWindowInsertPin();
                    bitmapA         = bitmapB;
                    RGlobal         = heuristicSum(bitmapA);
                    PreviousAverage = RGlobal / 9;
                    sendPicture(picture.PictureData, true);
                    return;
                }

                Debug.Print(DateTime.Now.ToString());
                HeurSum = heuristicSum(bitmapB);
                Debug.Print(DateTime.Now.ToString());

                Debug.Print(PreviousAverage.ToString());
                Int32 average = (HeurSum / 9);
                Debug.Print(average.ToString());

                if (System.Math.Abs(PreviousAverage - average) > 45)    //SOGLIA LIMITE 40/50
                {
                    Debug.Print("Suspicious picture!");
                    sendPicture(picture.PictureData, false);
                }

                RGlobal         = HeurSum;
                PreviousAverage = average;

                //  displayT35.SimpleGraphics.DisplayImage(picture, 0, 0); //TODO eliminare alla fine
            }
            catch (SocketException e)
            {
                timer_getimage.Stop();
                timer_keepAlive.Stop();
                WindowsManager.showWindowErrorServer();
            }
        }
示例#2
0
        private void initServer()
        {
            if (bindProxyService())
            {
                getAddressAndPort();

                IPAddress ipAddress = IPAddress.Parse(connectionInfo[0]);
                int       port      = int.Parse(connectionInfo[1]);
                if (port == -1)
                {
                    Debug.Print("Error: Invalid Port, impossible to establish a connection!\n");
                    WindowsManager.showWindowErrorServer();
                    serverUnreacheable = true;
                    return;
                }
                if (port == 404)
                {
                    Debug.Print("Error: Server Unreacheable!\n");
                    serverUnreacheable = true;
                    WindowsManager.showWindowServerDown();
                    return;
                }
                serverEndPoint = new IPEndPoint(ipAddress, port);
                servertime    += 35000;
                try
                {
                    var data = proxy.keepAlive(new keepAlive()
                    {
                        myMacAddress  = myMac,
                        mycurrentTime = servertime,
                        port          = int.Parse(connectionInfo[1]),
                    });
                }
                catch (Exception e)
                {
                    WindowsManager.showWindowServiceDown();
                    serverUnreacheable = true;
                    return;
                }

                timer_keepAlive       = new GT.Timer(35000);
                timer_keepAlive.Tick += keepAlive;
                timer_keepAlive.Start();

                bitmapA            = null;
                serverUnreacheable = false;
                setupComplete      = true;
                Thread.Sleep(300);
                contImage = 0;
                camera.TakePicture();
            }
        }