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> 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 response) { HeartRateMeasurementValue heartRateMeasurementValue; if(base.CheckCharacteristicResponse(characteristic, response, (BleCharacteristicInfo info, BleResponse bleResponse) => new HeartRateMeasurementValue(bleResponse.Data), out heartRateMeasurementValue) != CommandResponseCode.Success) { return; } //Debug.Log("心率:"+heartRateMeasurementValue.BeatsPerMinute); } protected override BleCharacteristicInfo GetCharacteristicForCommandType(CommandType type) { return null; } } }