Ejemplo n.º 1
0
        private void deactivateSystem()
        {
            invalidate    = true;
            setupComplete = false;

            if (throw_allarm)
            {
                SpegniAllarme();
                throw_allarm = false;
            }
            else
            {
                unBind();
            }
            if (timer_keepAlive.IsRunning)
            {
                timer_keepAlive.Stop();
            }
            if (timer_getimage.IsRunning)
            {
                timer_getimage.Stop();
            }


            WindowsManager.showWindowSetupCamera();
        }
Ejemplo n.º 2
0
        /**
         * This method binding the service
         */
        private Boolean bindProxyService()
        {
            Debug.Print("Binding proxy service...");
            try
            {
                WS2007HttpBinding a = new WS2007HttpBinding();
                ProtocolVersion11 b = new ProtocolVersion11();
                proxy = new IService1ClientProxy(a, b);

                // NOTE: the endpoint needs to match the endpoint of the servicehost
                proxy.EndpointAddress = SERVICE_ADDR;
            }
            catch (SocketException e)
            {
                WindowsManager.showWindowServiceDown();
                return(false);
            }
            catch (ObjectDisposedException e)
            {
                Debug.Print("Disposed object exception");
                WindowsManager.showWindowServiceDown();
                return(false);
            }


            Debug.Print("Binding proxy service COMPLETE");
            return(true);
        }
Ejemplo n.º 3
0
        public void setupCamera()
        {
            if (camera.CameraReady)
            {
                button.ButtonPressed += button_ButtonPressed;
                invalidate            = true;
                serverUnreacheable    = false;
                WindowsManager.showWindowLoadingStatic();
                try
                {
                    streaming = true;
                    camera.StartStreaming();
                }
                catch (InvalidOperationException e)
                {
                    Debug.Print("Already Streaming");
                }

                /*
                 * timer_progress = new GT.Timer(350);
                 * timer_progress.Tick += progressIncrement;
                 * timer_progress.Start();
                 */
            }
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
 /**
  * This method is triggered when the network goes up.
  */
 private void OnNetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
 {
     Debug.Print("Network up!");
     NetworkUp = true;
     multicolorLED.TurnGreen();
     ListNetworkInterfaces();
     ethernetJ11D.NetworkDown += OnNetworkDown;
     WindowsManager.showWindowInsertPin();
 }
Ejemplo n.º 6
0
 public static WindowsManager getInstance(Program p)
 {
     if (instance == null)
     {
         mProgram = p;
         instance = new WindowsManager();
     }
     return(instance);
 }
Ejemplo n.º 7
0
        /// <summary>This method runs automatically when the device is powered, and calls ProgramStarted.</summary>
        public static void Main()
        {
            // Important to initialize the Mainboard first
            Program.Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
            Program p = new Program();

            WindowsManager.getInstance(p);
            p.InitializeModules();
            p.ProgramStarted();
            // Starts Dispatcher
            p.Run();
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
        /**
         * This method is run when the mainboard is powered up or reset.
         */
        void ProgramStarted()
        {
            Debug.Print("Program Started");     // to show messages in "Output" window during debugging
            multicolorLED.TurnRed();

            Thread.Sleep(300);
            InitSensors();

            SetupEthernet();

            camera.PictureCaptured += camera_PictureCaptured;
            camera.BitmapStreamed  += camera_BitmapStreamed;

            camera.CameraDisconnected += camera_CameraDisconnected;
            camera.CameraConnected    += camera_CameraConnected;
            WindowsManager.showWindowInsertPin();
        }
Ejemplo n.º 10
0
 void camera_CameraDisconnected(Camera sender, EventArgs e)
 {
     cameraDisconnected = true;
     if (setupComplete)
     {
         timer_keepAlive.Stop();
         if (!throw_allarm)
         {
             ThrowAllarm();
         }
         WindowsManager.showWindowCameraDown();
     }
     else
     {
         WindowsManager.showWindowCameraDown();
         return;
     }
 }
Ejemplo n.º 11
0
        /**
         * This method is triggered when the network goes down.
         * It triggers the alarm.
         */
        private void OnNetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Network down!");
            NetworkUp = false;
            multicolorLED.TurnRed();
            if (proxy != null)
            {
                proxy.closeChannel();
                proxy.Dispose();
                proxy.Dispose();
                proxy = null;
            }

            if (streaming)
            {
                streaming = false;
                camera.StopStreaming();
                button.ButtonPressed -= button_ButtonPressed;
                if (timer_joystick.IsRunning)
                {
                    timer_joystick.Stop();
                }
            }

            if (setupComplete)
            {
                timer_keepAlive.Stop();
                if (!throw_allarm)
                {
                    ThrowAllarm();
                }
                WindowsManager.showWindowInsertPin();
            }
            else
            {
                camera.StopStreaming();
                Thread.Sleep(250);
                WindowsManager.showWindowNetworkDown();
                return;
            }
        }
Ejemplo n.º 12
0
        /**
         * This method get the port of the server socket to connect from the service
         */
        private void getAddressAndPort()
        {
            try
            {
                var data = proxy.getServerAddressWithPort(new getServerAddressWithPort()
                {
                    myMacAddress = myMac,
                });

                connectionInfo[0] = data.getServerAddressWithPortResult.address;
                connectionInfo[1] = data.getServerAddressWithPortResult.port;
                Debug.Print("Server address: " + data.getServerAddressWithPortResult.address);
                Debug.Print("Server port: " + data.getServerAddressWithPortResult.port);
                servertime = data.getServerAddressWithPortResult.serverTime;
                Debug.Print("Server time: " + servertime);
            }
            catch (Exception e)
            {
                WindowsManager.showWindowServiceDown();
            }
        }
Ejemplo n.º 13
0
        /**
         * This method is triggered when the button is pressed.
         */
        private void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
        {
            Debug.Print("Button pressed!");
            button.ButtonPressed -= button_ButtonPressed;
            streaming             = false;
            camera.StopStreaming();
            camera.StopStreaming();
            timer_joystick.Stop();
            WindowsManager.showWindowLoadingStatic();
            Thread.Sleep(200);

            if (NetworkUp)
            {
                initServer();
            }
            else
            {
                Debug.Print("Network_Down!!!");
                WindowsManager.showWindowNetworkDown();
            }
        }
Ejemplo n.º 14
0
        public int checkLogin(String pin)
        {
            // HashAlgorithm hashSHA256 = new HashAlgorithm(HashAlgorithmType.MD5);
            Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(pin);

            if ((setupComplete && !NetworkUp && VolatilePin.Length == 8) || (setupComplete && NetworkUp && VolatilePin.Length == 8))
            {
                if (VolatilePin.Equals(pin))
                {
                    deactivateSystem();
                    return(2);
                }
            }

            if (setupComplete && NetworkUp)
            {
                try
                {
                    var data = proxy.isValid(new isValid()
                    {
                        mac = myMac,
                        pin = dataToHmac
                    });

                    if (data.isValidResult)
                    {
                        deactivateSystem();
                        return(2);
                    }
                    return(-1);
                }
                catch (Exception e)
                {
                    WindowsManager.showWindowServiceDown();
                    return(1);
                }
            }

            if (!NetworkUp)
            {
                WindowsManager.showWindowNetworkDown();
                return(2);
            }


            bindProxyService();

            try
            {
                var data2 = proxy.isValid(new isValid()
                {
                    mac = myMac,
                    pin = dataToHmac
                });
                if (data2.isValidResult)
                {
                    VolatilePin = pin;
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception e)
            {
                WindowsManager.showWindowServiceDown();
                return(1);
            }
        }