Exemplo n.º 1
0
        /// <summary>
        /// Reset all data buffers.
        /// </summary>
        private void ResetDataBuffers()
        {
            if (_eegBuff != null)
            {
                _dsProcess.EEGDataReceived -= _eegBuff.OnDataReceived;
                _eegBuff.Clear();
                _eegBuff = null;
            }
            if (_devBuff != null)
            {
                _dsProcess.DevDataReceived -= _devBuff.OnDevDataReceived;
                _devBuff.Clear();
                _devBuff = null;
            }
            if (_bandpowerBuff != null)
            {
                _dsProcess.BandPowerDataReceived -= _bandpowerBuff.OnBandPowerReceived;
                _bandpowerBuff.Clear();
                _bandpowerBuff = null;
            }
            if (_motionBuff != null)
            {
                _dsProcess.MotionDataReceived -= _motionBuff.OnDataReceived;
                _motionBuff.Clear();
                _motionBuff = null;
            }
            if (_pmBuff != null)
            {
                _dsProcess.PerfDataReceived -= _pmBuff.OnPMDataReceived;
                _pmBuff.Clear();
                _pmBuff = null;
            }
            if (_facLists != null)
            {
                _dsProcess.FacialExpReceived -= OnFacialExpressionReceived;
                _facLists.Clear();
                _facLists = null;
            }
            if (_mentalCommandLists != null)
            {
                _dsProcess.MentalCommandReceived -= OnMentalCommandReceived;
                _mentalCommandLists.Clear();
                _mentalCommandLists = null;
            }
            if (_sysLists != null)
            {
                _dsProcess.SysEventsReceived -= OnSysEventReceived;
                _sysLists.Clear();
                _sysLists = null;
                SysEventUnSubscribed(this, "");
            }

            UnityEngine.Debug.Log("DataStreamManager:ResetDataBuffers Done");
        }
Exemplo n.º 2
0
        private void OnSubscribedOK(object sender, Dictionary <string, JArray> e)
        {
            lock (_locker)
            {
                UnityEngine.Debug.Log("DataStreamManager: SubscribedOK");
                UnityEngine.Debug.Log(e.Keys.Count);
                foreach (string key in e.Keys)
                {
                    UnityEngine.Debug.Log(key);
                    int headerCount = e[key].Count;
                    if (key == DataStreamName.EEG)
                    {
                        if (_eegBuff == null)
                        {
                            _eegBuff = new EegMotionDataBuffer();
                            _eegBuff.SetDataType(EegMotionDataBuffer.DataType.EEG);
                            _eegBuff.SettingBuffer(4, 4, headerCount);
                            _eegBuff.SetChannels(e[key]);
                            _dsProcess.EEGDataReceived += _eegBuff.OnDataReceived;
                            UnityEngine.Debug.Log("Subscribed done EEG Data Stream");
                        }
                    }
                    else if (key == DataStreamName.Motion)
                    {
                        if (_motionBuff == null)
                        {
                            _motionBuff = new EegMotionDataBuffer();
                            _motionBuff.SetDataType(EegMotionDataBuffer.DataType.MOTION);
                            _motionBuff.SettingBuffer(4, 4, headerCount);
                            _motionBuff.SetChannels(e[key]);
                            _dsProcess.MotionDataReceived += _motionBuff.OnDataReceived;
                            UnityEngine.Debug.Log("Subscribed done Motion Data Stream");
                        }
                    }
                    else if (key == DataStreamName.BandPower)
                    {
                        if (_bandpowerBuff == null)
                        {
                            _bandpowerBuff = new BandPowerDataBuffer();
                            _bandpowerBuff.SettingBuffer(4, 4, headerCount);
                            _bandpowerBuff.SetChannels(e[key]);
                            _dsProcess.BandPowerDataReceived += _bandpowerBuff.OnBandPowerReceived;
                            UnityEngine.Debug.Log("Subscribed done: POW Stream");
                        }
                    }
                    else if (key == DataStreamName.DevInfos)
                    {
                        if (_devBuff == null)
                        {
                            _devBuff = new DevDataBuffer();
                            _devBuff.SettingBuffer(1, 1, headerCount);
                            _devBuff.SetChannels(e[key]);
                            _dsProcess.DevDataReceived += _devBuff.OnDevDataReceived;
                            UnityEngine.Debug.Log("Subscribed done: DEV Data Stream");
                        }
                    }
                    else if (key == DataStreamName.PerformanceMetrics)
                    {
                        if (_pmBuff == null)
                        {
                            _pmBuff = new PMDataBuffer();
                            int count = _pmBuff.SetChannels(e[key]);
                            _pmBuff.SettingBuffer(4, 4, count);
                            _dsProcess.PerfDataReceived += _pmBuff.OnPMDataReceived;
                            UnityEngine.Debug.Log("Subscribed done: Peformance metrics Data Stream");
                        }
                    }
                    else if (key == DataStreamName.FacialExpressions)
                    {
                        if (_facLists == null)
                        {
                            _facLists = new List <string>();
                            _facLists.Add("TimeStamp");
                            foreach (var ele in e[key])
                            {
                                _facLists.Add(ele.ToString());
                            }
                            _dsProcess.FacialExpReceived += OnFacialExpressionReceived;
                            UnityEngine.Debug.Log("Subscribed done: Facial expression Data Stream");
                        }
                    }
                    else if (key == DataStreamName.MentalCommands)
                    {
                        if (_mentalCommandLists == null)
                        {
                            _mentalCommandLists = new List <string>();
                            _mentalCommandLists.Add("TimeStamp");
                            foreach (var ele in e[key])
                            {
                                _mentalCommandLists.Add(ele.ToString());
                            }
                            _dsProcess.MentalCommandReceived += OnMentalCommandReceived;
                            UnityEngine.Debug.Log("Subscribed done: Mental command Data Stream");
                        }
                    }
                    else if (key == DataStreamName.SysEvents)
                    {
                        if (_sysLists == null)
                        {
                            _sysLists = new List <string>();
                            _sysLists.Add("TimeStamp");
                            foreach (var ele in e[key])
                            {
                                _sysLists.Add(ele.ToString());
                            }
                            _dsProcess.SysEventsReceived += OnSysEventReceived;

                            //SysEventSubscribed(this, _wantedHeadsetId);
                            UnityEngine.Debug.Log("Subscribed done: Sys event Stream");
                        }
                    }
                    else
                    {
                        UnityEngine.Debug.Log("SubscribedOK(): stream " + key);
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void OnStreamStopNotify(object sender, List <string> streams)
 {
     lock (_locker)
     {
         _wantedHeadsetId    = "";  // reset headset
         _readyCreateSession = true;
         UnityEngine.Debug.Log("OnStreamStopNotify: Stop data stream from Cortex.");
         foreach (string streamName in streams)
         {
             if (streamName == DataStreamName.EEG)
             {
                 // clear _eegBuffer
                 if (_eegBuff != null)
                 {
                     _dsProcess.EEGDataReceived -= _eegBuff.OnDataReceived;
                     _eegBuff.Clear();
                     _eegBuff = null;
                 }
             }
             else if (streamName == DataStreamName.DevInfos)
             {
                 if (_devBuff != null)
                 {
                     _dsProcess.DevDataReceived -= _devBuff.OnDevDataReceived;
                     _devBuff.Clear();
                     _devBuff = null;
                 }
             }
             else if (streamName == DataStreamName.BandPower)
             {
                 if (_bandpowerBuff != null)
                 {
                     _dsProcess.BandPowerDataReceived -= _bandpowerBuff.OnBandPowerReceived;
                     _bandpowerBuff.Clear();
                     _bandpowerBuff = null;
                 }
             }
             else if (streamName == DataStreamName.Motion)
             {
                 if (_motionBuff != null)
                 {
                     _dsProcess.MotionDataReceived -= _motionBuff.OnDataReceived;
                     _motionBuff.Clear();
                     _motionBuff = null;
                 }
             }
             else if (streamName == DataStreamName.PerformanceMetrics)
             {
                 if (_pmBuff != null)
                 {
                     _dsProcess.PerfDataReceived -= _pmBuff.OnPMDataReceived;
                     _pmBuff.Clear();
                     _pmBuff = null;
                 }
             }
             else if (streamName == DataStreamName.FacialExpressions)
             {
                 if (_facLists != null)
                 {
                     _dsProcess.FacialExpReceived -= OnFacialExpressionReceived;
                     _facLists.Clear();
                     _facLists = null;
                 }
             }
             else if (streamName == DataStreamName.SysEvents)
             {
                 if (_sysLists != null)
                 {
                     _dsProcess.SysEventsReceived -= OnSysEventReceived;
                     _sysLists.Clear();
                     _sysLists = null;
                     SysEventUnSubscribed(this, "");
                 }
             }
             else if (streamName == DataStreamName.MentalCommands)
             {
                 if (_mentalCommandLists != null)
                 {
                     _dsProcess.MentalCommandReceived -= OnMentalCommandReceived;
                     _mentalCommandLists.Clear();
                     _mentalCommandLists = null;
                 }
             }
             else
             {
                 UnityEngine.Debug.Log("DataStreamManager-OnStreamStopNotify: stream name:" + streamName);
             }
         }
     }
 }