82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using Assets.Scripts.Ble;
|
|
using Assets.Scripts.Devices.Ant.Interfaces;
|
|
using Assets.Scripts.Devices.Ble.Characteristic;
|
|
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.Devices.Ble.Devices
|
|
{
|
|
public class FtmsRower : BleDevice, IRowerDevice
|
|
{
|
|
private FtmsRowerData _rowerData;
|
|
public FtmsRowerData rowerData { get => _rowerData; }
|
|
|
|
|
|
private List<BleServiceInfo> Services;
|
|
private BleCharacteristicInfo controlPointCharacteristic;
|
|
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
|
|
{
|
|
Debug.Log(24);
|
|
base.Characteristics.Add(new FtmsFitnessMachineFeature());
|
|
//划船机
|
|
this._rowerData = new FtmsRowerData();
|
|
base.Characteristics.Add(rowerData);
|
|
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
|
}
|
|
|
|
protected override void CreateServices(List<BleServiceInfo> discoveredServices)
|
|
{
|
|
this.Services = discoveredServices;
|
|
|
|
foreach (var service in this.Services)
|
|
{
|
|
hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) =>
|
|
{
|
|
foreach (var character in response.Data)
|
|
{
|
|
if (character.MatchGuid(ServiceUuids.Characteristics.FitnessMachineControlPoint))
|
|
{
|
|
Debug.Log("中控台获取");
|
|
this.controlPointCharacteristic = character;
|
|
}
|
|
else if (character.MatchGuid(ServiceUuids.Characteristics.RowerData))
|
|
{
|
|
Debug.Log("划船机");
|
|
this.hwInterface.SubscribeCharacteristic(character, (hw, cha, res) =>
|
|
{
|
|
//Debug.Log("1111111111111111111111");
|
|
//Debug.WriteLine(res.ToString());
|
|
var res1 = (res as BleResponse<byte[]>);
|
|
Debug.Log("收到消息划船机:" + string.Join(",", res1));
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void CharacteristicReadMainCallback(IBleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
|
{
|
|
foreach (var item in base.Characteristics)
|
|
{
|
|
if (characteristic.MatchGuid(item.Uuid))
|
|
{
|
|
//Debug.Log(string.Join(",", response.Data));
|
|
item.HandleAttributeReceived(response.Data);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Debug.Log("发送重置命令"+this.controlPointCharacteristic.ToString());
|
|
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, new byte[] { 0x01 });
|
|
}
|
|
}
|
|
}
|