62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using Assets.Scripts.Ble.Commands;
|
|
using Assets.Scripts.Ble.Service;
|
|
using Assets.Scripts.Commands;
|
|
using Assets.Scripts.Devices.Ble;
|
|
using Assets.Scripts.Devices.Ble.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Ble.HeartRate
|
|
{
|
|
public class HeartRateService : BleService
|
|
{
|
|
private BleCharacteristicInfo heartRateCharacteristic;
|
|
|
|
public HeartRateService(BleServiceInfo serviceInfo, BleWinHwInterface bleWinHwInterface) :base(serviceInfo, bleWinHwInterface)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void CharacteristicsDiscovered(BleResponse<List<BleCharacteristicInfo>> response)
|
|
{
|
|
foreach (var item in response.Data)
|
|
{
|
|
if (item.MatchGuid(ServiceUuids.Characteristics.HrMeasurement))
|
|
{
|
|
this.heartRateCharacteristic = item;
|
|
base.SubscribeCharacteristic(item, HrmCharacteristicSubscribed, HrmCharacteristicRead);
|
|
}
|
|
if (item.MatchGuid(ServiceUuids.Characteristics.BodySensorLocation))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void HrmCharacteristicSubscribed(IBleWinHwInterface winHwInterface, BleCharacteristicInfo characteristic, BleResponse response)
|
|
{
|
|
|
|
}
|
|
|
|
private void HrmCharacteristicRead(IBleWinHwInterface winHwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
|
{
|
|
HeartRateMeasurementValue heartRateMeasurementValue;
|
|
if(base.CheckCharacteristicResponse<HeartRateMeasurementValue>(characteristic, response, (BleCharacteristicInfo info, BleResponse<byte[]> bleResponse) => new HeartRateMeasurementValue(bleResponse.Data), out heartRateMeasurementValue) != CommandResponseCode.Success)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//Debug.Log("心率:"+heartRateMeasurementValue.BeatsPerMinute);
|
|
}
|
|
|
|
protected override BleCharacteristicInfo GetCharacteristicForCommandType(CommandType type)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|