71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using Assets.Scripts.Ble.Characteristic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Assets.Scripts.Ble.HeartRate
|
|
{
|
|
public class HeartRateMeasurementValue : SuccessOnlyCharacteristicValue
|
|
{
|
|
private HeartRateMeasurementValue.HrmFormat Format { get; }
|
|
|
|
// Token: 0x170005EB RID: 1515
|
|
// (get) Token: 0x0600214D RID: 8525 RVA: 0x0008999B File Offset: 0x00087B9B
|
|
public int BeatsPerMinute { get; }
|
|
|
|
public HeartRateMeasurementValue(byte[] data): base(ServiceUuids.Characteristics.HrMeasurement, data)
|
|
{
|
|
if(data == null || data.Length < 2)
|
|
{
|
|
throw new ArgumentException(string.Concat(new string[]
|
|
{
|
|
"Invalid data for ",
|
|
base.Id.ToString(),
|
|
" ",
|
|
(data != null) ? string.Join(",", data) : null,
|
|
"."
|
|
}), "data");
|
|
}
|
|
HeartRateMeasurementValue.HrmFlags hrmFlags = (HeartRateMeasurementValue.HrmFlags)BitConvertHelper.ToUInt8(data, 0);
|
|
this.Format = (HrmFormat)(hrmFlags.HasFlag(HeartRateMeasurementValue.HrmFlags.Format) ? 1 : 0);
|
|
if (this.Format == HeartRateMeasurementValue.HrmFormat.Short)
|
|
{
|
|
this.BeatsPerMinute = BitConvertHelper.ToUInt8(data, 1);
|
|
return;
|
|
}
|
|
if(data.Length < 3)
|
|
{
|
|
throw new ArgumentException("数据出错");
|
|
}
|
|
this.BeatsPerMinute = BitConvertHelper.ToUInt16(data, 1);
|
|
}
|
|
|
|
|
|
[Flags]
|
|
private enum HrmFlags
|
|
{
|
|
// Token: 0x040029D0 RID: 10704
|
|
Format = 1,
|
|
// Token: 0x040029D1 RID: 10705
|
|
SensorContactStatus1 = 2,
|
|
// Token: 0x040029D2 RID: 10706
|
|
SensorContactStatus2 = 4,
|
|
// Token: 0x040029D3 RID: 10707
|
|
Energy = 8,
|
|
// Token: 0x040029D4 RID: 10708
|
|
RR = 16
|
|
}
|
|
|
|
// Token: 0x02000921 RID: 2337
|
|
private enum HrmFormat
|
|
{
|
|
// Token: 0x040029D6 RID: 10710
|
|
Short,
|
|
// Token: 0x040029D7 RID: 10711
|
|
Long
|
|
}
|
|
}
|
|
}
|