public SignalsVisualization()
        {
            AssetManager.Instance.Bridge = new Bridge();
            gsrAsset = RealTimeArousalDetectionUsingGSRAsset.Instance;
            settings = (RealTimeArousalDetectionAssetSettings)gsrAsset.Settings;
            logger   = (ILog)AssetManager.Instance.Bridge;

            if ("BackgroundMode".Equals(settings.FormMode))
            {
                this.WindowState = FormWindowState.Minimized;
                Load            += new EventHandler(Form_Load);
            }
            else
            {
                InitializeComponent();
                lblErrors.Text = "";

                StartGSRDevice();
                if (DoesChartDisplay())
                {
                    GSRChartDisplay();
                    timer1.Tick += timer1_Tick;
                }

                StartSocket();
                lblSampleRateValue.Text    = !"TestWithoutDevice".Equals(settings.ApplicationMode) ? gsrAsset.GetSignalSampleRate().ToString() : "0";
                lblSocketAddressValue.Text = settings.SocketIPAddress + ":" + settings.SocketPort;
                lblTimeWindowValue.Text    = settings.DefaultTimeWindow + " s";
                btnSocketLight.BackColor   = Color.GreenYellow;

                this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.gsrChart_MouseWheel);
            }
        }
        public RealTimeArousalDetectionUsingGSRAsset() : base()
        {
            socketListener = new SocketListener();
            gsrDevice      = GSRHRDevice.Instance;
            gsrProcessor   = new GSRSignalProcessor();
            settings       = RealTimeArousalDetectionAssetSettings.Instance;
            logger         = (ILog)AssetManager.Instance.Bridge;

            //preventing multiple asset creation
            if (AssetManager.Instance.findAssetsByClass(this.Class).Count > 1)
            {
                logger.Log(Severity.Error, "Attempt for more than one instance of the class RealTimeArousalDetectionUsingGSRAsset (it is not allowed).");
            }
        }
Ejemplo n.º 3
0
    private CacheSignalData()
    {
        signalValuesCache = new List <SignalDataByTime>();
        config            = RealTimeArousalDetectionAssetSettings.Instance;
        double butterworthPhasicFrequency = config.ButterworthPhasicFrequency;
        double butterworthTonicFrequency  = config.ButterworthTonicFrequency;

        sampleRate = config.Samplerate;
        butterworthHighPassFilter = new FilterButterworth(butterworthPhasicFrequency, sampleRate, ButterworthPassType.Highpass, "compute EDA high");
        butterworthLowPassFilter  = new FilterButterworth(butterworthTonicFrequency, sampleRate, ButterworthPassType.Lowpass, "compute EDA low");

        if ("TestWithoutDevice".Equals(config.ApplicationMode))
        {
            FillTestGSRDataFromFile();
        }

        applicationMode = config.ApplicationMode;
    }
Ejemplo n.º 4
0
 private GSRHRDevice()
 {
     device   = new HMDevice.HMDevice();
     settings = RealTimeArousalDetectionAssetSettings.Instance;
 }
        public void StartListening()
        {
            settings = RealTimeArousalDetectionAssetSettings.Instance;
            logger   = (ILog)AssetManager.Instance.Bridge;
            try
            {
                // Set the TcpListener
                Int32     port      = settings.SocketPort;
                IPAddress localAddr = IPAddress.Parse(settings.SocketIPAddress);
                server = new TcpListener(localAddr, port);

                // Start listening for client requests.
                server.Start();
                isTcpListenerActive = true;

                RealTimeArousalDetectionUsingGSRAsset gsrAsset = RealTimeArousalDetectionUsingGSRAsset.Instance;

                // Buffer for reading data
                Byte[] bytes = new Byte[256];
                String data  = null;

                // Enter the listening loop.
                while (true && isTcpListenerActive)
                {
                    // You could also user server.AcceptSocket() here.
                    client = server.AcceptTcpClient();

                    data = null;

                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    int i;

                    // Loop to receive all the data sent by the client.
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        // Translate data bytes to a ASCII string.
                        data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

                        StringBuilder response = new StringBuilder();
                        response.Append("Received at ");
                        response.Append(DateTime.Now.ToString());
                        response.Append("\r\n");
                        response.Append(data);

                        //Start Of Calibration Period
                        if (data.Equals("SOCP"))
                        {
                            response.Append("\r\n");
                            string result = gsrAsset.StartOfCalibrationPeriod();
                            response.Append(result);
                        }

                        //End Of Calibration Period
                        if (data.Equals("EOCP"))
                        {
                            response.Append("\r\n");
                            string result = gsrAsset.EndOfCalibrationPeriod();
                            response.Append(result);
                        }

                        if (data.Equals("GET_EDA"))
                        {
                            response.Append("\r\n");
                            string result = gsrAsset.GetEDA();
                            response.Append(result);
                        }

                        //End Of Measurement
                        if (data.Equals("EOM"))
                        {
                            response.Append("\r\n");
                            string result = gsrAsset.EndOfMeasurement();
                            response.Append(result);
                        }

                        byte[] msg = System.Text.Encoding.ASCII.GetBytes(response.ToString());

                        // Send back a response.
                        stream.Write(msg, 0, msg.Length);
                    }

                    // Shutdown and end connection
                    client.Close();
                }
            }
            catch (SocketException e)
            {
                isTcpListenerActive = false;
                logger.Log(Severity.Error, "SocketException: " + e);
            }
            finally
            {
                // Stop listening for new clients.
                isTcpListenerActive = false;
                if (client != null)
                {
                    client.Close();
                }
                server.Stop();
            }
        }