Example #1
0
 internal void SetPressureParams([NotNull] PatientPressureParams pressureParams)
 {
     if (pressureParams == null)
     {
         throw new ArgumentNullException(nameof(pressureParams));
     }
     IsAnyValueObtained        = true;
     SystolicArterialPressure  = new DeviceValue <short>(pressureParams.SystolicArterialPressure);
     DiastolicArterialPressure = new DeviceValue <short>(pressureParams.DiastolicArterialPressure);
     AverageArterialPressure   = new DeviceValue <short>(pressureParams.AverageArterialPressure);
 }
        private async Task UpdateDataAsync()
        {
            var isCommonParamsRequested   = _isCommonParamsRequested == IsRequestedValue;
            var isPressureParamsRequested = _isPressureParamsRequested == IsRequestedValue;
            var isEcgParamsRequested      = _isEcgParamsRequested == IsRequestedValue;

            if (!isCommonParamsRequested && !isPressureParamsRequested && !isEcgParamsRequested && !_isPumpingRequested)
            {
                return;
            }
            AssertConnection();

            await _updateDataSyncSemaphore
            .WaitAsync()
            .ConfigureAwait(false);

            var ecgValue = new short[2];

            try
            {
                var commonParams = await _mitar
                                   .GetCommonParams()
                                   .ConfigureAwait(false);

                var pressureParams = await _mitar
                                     .GetPressureParams()
                                     .ConfigureAwait(false);

                _pumpingStatus = await _mitar
                                 .GetPumpingStatus()
                                 .ConfigureAwait(false);

                if (_isPumpingRequested)
                {
                    if (!_isPumpingStarted && _pumpingStatus == PumpingStatus.InProgress)
                    {
                        _isPumpingStarted = true;
                    }
                    if (_isPumpingStarted &&
                        (_pumpingStatus != PumpingStatus.InProgress))
                    {
                        _isPumpingStarted   = false;
                        _isPumpingRequested = false;
                        _pumpingReady.Set();
                    }
                }


                if (isCommonParamsRequested)
                {
                    _lastCommonParams = commonParams;
                    _commonParamsReady.Set();
                }

                if (isPressureParamsRequested)
                {
                    _lastPressureParams = pressureParams;
                    _pressureParamsReady.Set();
                }

                if (isEcgParamsRequested)
                {
                    _ecgValues.Enqueue(ecgValue[0]);
                    _ecgValues.Enqueue(ecgValue[1]);
                    var currentTime = DateTime.UtcNow;

                    if (currentTime > _startedEcgCollectingTime &&
                        currentTime - _startedEcgCollectingTime >= _ecgCollectionDuration)
                    {
                        _lastEcgParams = new PatientEcgParams(_ecgValues.ToArray());
                        while (_ecgValues.TryDequeue(out _))
                        {
                        }

                        _ecgParamsReady.Set();
                    }
                }
            }
            catch (Exception)
            {
                // чтобы не было deadlock'ов
                if (isCommonParamsRequested)
                {
                    _commonParamsReady.Set();
                }

                if (isPressureParamsRequested)
                {
                    _commonParamsReady.Set();
                }

                if (isEcgParamsRequested)
                {
                    _ecgParamsReady.Set();
                }

                throw;
            }
            finally
            {
                _updateDataSyncSemaphore.Release();
            }
        }