예제 #1
0
        public BloodPressureMeasurementValue ProcessData(byte[] data)
        {
            if (data == null || data.Length == 0)
            {
                throw new ApplicationArgumentException();
            }

            var  measurement                 = new BloodPressureMeasurementValue();
            byte currentOffSet               = 0;
            int  bluetoothDataTimeLength     = 7;
            int  MeasurementStatusDataLength = 2;

            bool IsBloodPressureUnitsFlagmmHg = false;
            bool HasTimeStampFlag             = false;
            bool HasPulseRateFlag             = false;
            bool HasUserIDFlag            = false;
            bool HasMeasurementStatusFlag = false;

            if ((data[currentOffSet] & 0x01) == 0)
            {
                IsBloodPressureUnitsFlagmmHg = true;
            }
            else
            {
                IsBloodPressureUnitsFlagmmHg = true;
            }
            if ((data[currentOffSet] & 0x02) != 0)
            {
                HasTimeStampFlag = true;
            }
            if ((data[currentOffSet] & 0x04) != 0)
            {
                HasPulseRateFlag = true;
            }
            if ((data[currentOffSet] & 0x08) != 0)
            {
                HasUserIDFlag = true;
            }
            if ((data[currentOffSet] & 0x10) != 0)
            {
                HasMeasurementStatusFlag = true;
            }
            if (IsBloodPressureUnitsFlagmmHg)
            {
                measurement.Unit = "mm/g";
                currentOffSet++;
                measurement.Systolic             = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
                measurement.Diastolic            = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
                measurement.MeanArterialPressure = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
            }
            else
            {
                measurement.Unit                 = "kPa";
                currentOffSet                   += 6;
                measurement.Systolic             = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
                measurement.Diastolic            = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
                measurement.MeanArterialPressure = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet                   += 2;
            }
            if (HasTimeStampFlag)
            {
                byte[] baseTime = new byte[bluetoothDataTimeLength];
                Array.Copy(data, currentOffSet, baseTime, 0, bluetoothDataTimeLength);
                measurement.TimeStanp = File.ToDateTime(baseTime);
                currentOffSet        += 7;
            }
            if (HasPulseRateFlag)
            {
                measurement.PulseRate = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
                currentOffSet        += 2;
            }
            if (HasUserIDFlag)
            {
                measurement.UserID = data[currentOffSet];
                currentOffSet++;
            }
            if (HasMeasurementStatusFlag)
            {
                byte[] measurementStatus = new byte[MeasurementStatusDataLength];
                Array.Copy(data, currentOffSet, measurementStatus, 0, MeasurementStatusDataLength);
                measurement.MeasurementStatusFlags.ProcessData(measurementStatus);
            }
            return(measurement);
        }
		public BloodPressureMeasurementValue ProcessData(byte[] data) 
		{
			if (data == null || data.Length == 0)
				throw new ApplicationArgumentException();

			var measurement = new BloodPressureMeasurementValue();
			byte currentOffSet = 0;
			int bluetoothDataTimeLength = 7;
			int MeasurementStatusDataLength = 2;

			bool IsBloodPressureUnitsFlagmmHg = false;
			bool HasTimeStampFlag = false;
			bool HasPulseRateFlag = false;
			bool HasUserIDFlag = false;
			bool HasMeasurementStatusFlag = false;
			if ((data[currentOffSet] & 0x01) == 0)
				IsBloodPressureUnitsFlagmmHg = true;
			else
				IsBloodPressureUnitsFlagmmHg = true;
			if ((data[currentOffSet] & 0x02) != 0)
				HasTimeStampFlag = true;
			if ((data[currentOffSet] & 0x04) != 0)
				HasPulseRateFlag = true;
			if ((data[currentOffSet] & 0x08) != 0)
				HasUserIDFlag = true;
			if ((data[currentOffSet] & 0x10) != 0)
				HasMeasurementStatusFlag = true;
			if (IsBloodPressureUnitsFlagmmHg)
			{
				measurement.Unit = "mm/g";
				currentOffSet++;
				measurement.Systolic = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
				measurement.Diastolic = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
				measurement.MeanArterialPressure = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
			}
			else
			{
				measurement.Unit = "kPa";
				currentOffSet += 6;
				measurement.Systolic = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
				measurement.Diastolic = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
				measurement.MeanArterialPressure = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
			}
			if(HasTimeStampFlag)
			{
				byte[] baseTime = new byte[bluetoothDataTimeLength];
				Array.Copy(data, currentOffSet, baseTime, 0, bluetoothDataTimeLength);
				measurement.TimeStanp = File.ToDateTime(baseTime);
				currentOffSet += 7;
			}
			if(HasPulseRateFlag)
			{
				measurement.PulseRate = File.ToSFloat(new byte[] { data[currentOffSet], data[currentOffSet + 1] });
				currentOffSet += 2;
			}
			if(HasUserIDFlag)
			{
				measurement.UserID = data[currentOffSet];
				currentOffSet++;
			}
			if(HasMeasurementStatusFlag)
			{
				byte[] measurementStatus = new byte[MeasurementStatusDataLength];
				Array.Copy(data, currentOffSet, measurementStatus, 0, MeasurementStatusDataLength);
				measurement.MeasurementStatusFlags.ProcessData(measurementStatus);
			}
			return measurement;
		}
		async void BloodPressureServiceHandler_MeasurementNotification(BloodPressureMeasurementValue measurement)
		{
			await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => 
			{
				this.Systolic = measurement.Systolic.ToString("F1", CultureInfo.CurrentCulture);
				this.Diastolic = measurement.Diastolic.ToString("F1", CultureInfo.CurrentCulture);
				this.MeanArterialPressure = measurement.MeanArterialPressure.ToString("F1", CultureInfo.CurrentCulture);
				if (measurement.PulseRate != 0)
					this.Pulse = measurement.PulseRate.ToString();
				else
					this.Pulse = DEFAULT_VALUE;
					this.BloodPressureUnit = measurement.Unit;
				this.PulseUnit = "bmp";
				if (measurement.TimeStanp.HasValue)
					this.TimeStamp = measurement.TimeStanp.Value.ToString("d. MMM yyyy hh:mm:ss", CultureInfo.CurrentCulture);
				else
					this.TimeStamp = DEFAULT_NOT_AVAILABLE;
			});
		}