Merge branch 'dev_cyp' into dev_ar_cyp
# Conflicts: # Assets/Resources/UI/Font/HanWangZonYi.ttf.meta # Assets/Resources/UI/language.json # Assets/Scenes/Login.unity # Assets/Scripts/Apis/Models/MapRoute.cs # Assets/Scripts/App.cs # Assets/Scripts/ConfigHelper.cs # Assets/Scripts/Scenes/Ride/Scripts/PlayerController.cs # Assets/Scripts/UIManager.cs # Assets/Scripts/Utils/Utils.cs
This commit is contained in:
commit
e513eeac5c
301 files changed
+49814
-11770
No files matched your search
@@ -9,7 +9,10 @@ namespace Assets.Scripts.Devices.Ant.Interfaces
|
||||
{
|
||||
interface IRowerDevice
|
||||
{
|
||||
C2RowerData c2RowerData { get; }
|
||||
FtmsRowerData rowerData { get; }
|
||||
void Reset();
|
||||
void SetResistanceLevel(ushort v);
|
||||
void C2GetStatus(byte[] bs);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@ namespace Assets.Scripts.Devices.Ant
|
||||
SpeedCadence,
|
||||
Trainer,
|
||||
VirtualPower,
|
||||
Rower
|
||||
Rower,
|
||||
FtmsTrainer
|
||||
}
|
||||
|
||||
public enum NetworkType
|
||||
|
||||
@@ -57,18 +57,30 @@ namespace Assets.Scripts.Devices.Ble
|
||||
}
|
||||
|
||||
public override void StartScan()
|
||||
{
|
||||
{
|
||||
hwInterface.StartScan((device) =>
|
||||
{
|
||||
{
|
||||
if (!discoveredDevices.ContainsKey(device.Peripheral.Address))
|
||||
{
|
||||
Debug.Log($"发现设备{ device.Peripheral.Address }, \t\tName:{ device.Peripheral.Name }, type:{ device.SensorType }");
|
||||
Debug.Log($"发现设备{ device.Peripheral.Address }, \t\tName:{ device.Peripheral.Name }, type:{ device.SensorType } 服务:{string.Join(",", device.Services)}");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(device.Peripheral.Name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (device.SensorType == Ant.SensorType.Trainer)
|
||||
if (device.SensorType == Ant.SensorType.FtmsTrainer)
|
||||
{
|
||||
var device1 = new Ftms(device.Peripheral, hwInterface);
|
||||
if (discoveredDevices.ContainsKey(device.Peripheral.Address))
|
||||
{
|
||||
discoveredDevices[device.Peripheral.Address] = device1;
|
||||
}
|
||||
else
|
||||
{
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
}
|
||||
else if (device.SensorType == Ant.SensorType.Trainer)
|
||||
{
|
||||
//var device1 = new Ftms(device.Peripheral, hwInterface);
|
||||
//discoveredDevices.Add(device.Peripheral.Address, device0);
|
||||
@@ -122,7 +134,21 @@ namespace Assets.Scripts.Devices.Ble
|
||||
{
|
||||
//TODO:取消注释,自动连接设备
|
||||
//Debug.Log("自动连接" + device111.Id);
|
||||
device111.Connect();
|
||||
|
||||
if (App.IsRowerMode == true)
|
||||
{
|
||||
if (device111.Sensor == Ant.SensorType.Rower || device111.Sensor == Ant.SensorType.HeartRate)
|
||||
{
|
||||
device111.Connect();
|
||||
}
|
||||
}
|
||||
else if(App.IsRowerMode == false)
|
||||
{
|
||||
if (device111.Sensor != Ant.SensorType.Rower)
|
||||
{
|
||||
device111.Connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
using Assets.Scripts.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.Devices.Ble.Characteristic
|
||||
{
|
||||
public class C2RowerData : ICharacteristic, IRowerCommonData
|
||||
{
|
||||
public Guid Uuid => ServiceUuids.Characteristics.C2RowerData35;
|
||||
|
||||
public Guid ServiceUuid => ServiceUuids.Characteristics.C2Service;
|
||||
|
||||
public bool IsOptional => false;
|
||||
|
||||
public static event EventHandler EnableChanged;
|
||||
private static bool _isEnabled;
|
||||
public static bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
_isEnabled = value;
|
||||
if (EnableChanged != null)
|
||||
{
|
||||
EnableChanged(_isEnabled, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//0.1 lbs of force, max=6553.5m 单位0.1磅
|
||||
public double PeakDriveForce { get; set; }
|
||||
public double AverageDriveForce { get; set; }
|
||||
|
||||
public event EventHandler PullChanged;
|
||||
private ushort _pullValue;
|
||||
public ushort PullValue
|
||||
{
|
||||
get { return _pullValue; }
|
||||
set
|
||||
{
|
||||
_pullValue = value;
|
||||
if (this.PullChanged != null)
|
||||
{
|
||||
this.PullChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool isReadyStatus { get; private set; }
|
||||
public static RowerTaskPanel.RowerType rowerType { get; private set; }
|
||||
public void HandleAttributeReceived(byte[] data)
|
||||
{
|
||||
Debug.Log("数据" + string.Join(",", data));
|
||||
if (data[0] == 0x35)
|
||||
{
|
||||
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10, true);
|
||||
AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10, true);
|
||||
ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 1)) / 100);
|
||||
TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 4)) / 10);
|
||||
StrokeCount = BitConvertHelper.ToUInt16(data, 19);
|
||||
Debug.Log($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}");
|
||||
}
|
||||
else if (data[0] == 0x3d)
|
||||
{
|
||||
//老款表头不支持
|
||||
List<ushort> r = new List<ushort>();
|
||||
for (int i = 3; i < data.Length; i += 2)
|
||||
{
|
||||
ushort pull = data[i] < 5 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
|
||||
r.Add(pull);
|
||||
PullValue = pull;
|
||||
}
|
||||
|
||||
Debug.Log("拉力曲线:" + string.Join(",", r));
|
||||
}
|
||||
else if (data[0] == 0x31)
|
||||
{
|
||||
byte status = data[18];
|
||||
int value = (data[17] << 16) + (data[16] << 8) + data[15];
|
||||
if (status == 128 && value != 0)
|
||||
{
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 1;
|
||||
rowerType.value = value;
|
||||
}
|
||||
else if (status == 0)
|
||||
{
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 2;
|
||||
rowerType.value = value / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType = null;
|
||||
}
|
||||
//isReadyStatus = data[9] == 0;
|
||||
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
|
||||
Debug.Log("划船时间" + time);
|
||||
isReadyStatus = data[9] == 0;
|
||||
if (RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(data[19], new EventArgs());
|
||||
}
|
||||
ResistanceLevel = data[19];
|
||||
//isReadyStatus = data[2] == 1 || data[2] == 129;
|
||||
}
|
||||
else if (data[0] == 0x32)
|
||||
{
|
||||
InstantaneousPace = (ushort)(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 8)) / 100);
|
||||
AveragePace = (ushort)(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 10)) / 100);
|
||||
//AveragePower = BitConvertHelper.ToUInt16(data, 17);
|
||||
StrokeRate = (uint)data[6];
|
||||
}
|
||||
else if (data[0] == 0x33)
|
||||
{
|
||||
TotalEnergy = BitConvertHelper.ToUInt16(data, 7);
|
||||
AveragePower = BitConvertHelper.ToUInt16(data, 5);
|
||||
}
|
||||
else if (data[0] == 0x36)
|
||||
{
|
||||
InstantaneousPower = BitConvertHelper.ToUInt16(data, 4);
|
||||
//TotalEnergy = BitConvertHelper.ToUInt16(data, 6);
|
||||
}
|
||||
//else if (data[0] == 0x39)
|
||||
//{
|
||||
// AverageStrokeRate = (int)data[11];
|
||||
// ResistanceLevel = (int)data[16];
|
||||
//}
|
||||
//else if (data[0] == 34)
|
||||
//{
|
||||
// isReadyStatus = data[2] == 1 || data[2] == 129;
|
||||
//}
|
||||
}
|
||||
public event EventHandler StartEvent;
|
||||
private double LbsToNewton(double lbs,bool isKg = false) => 4.4482216 * lbs * (isKg ? (1f / 9.8f) : 1f);
|
||||
public void SetUnavailable()
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 划桨频率
|
||||
/// </summary>
|
||||
public uint StrokeRate { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 划桨次数
|
||||
/// </summary>
|
||||
public UInt16 StrokeCount { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均划桨频率
|
||||
/// </summary>
|
||||
public int AverageStrokeRate { get; set; } = 0;
|
||||
private UInt32 _totalDistance = 0;
|
||||
public UInt32 TotalDistance
|
||||
{
|
||||
get => _totalDistance;
|
||||
set
|
||||
{
|
||||
if (_totalDistance == 0 && value != 0 && StartEvent != null)
|
||||
{
|
||||
StartEvent.Invoke(null, new EventArgs());
|
||||
}
|
||||
_totalDistance = value;
|
||||
}
|
||||
}
|
||||
//private UInt16 _instantaneousPace = 0;
|
||||
/// <summary>
|
||||
/// 即时配速
|
||||
/// </summary>
|
||||
public UInt16 InstantaneousPace { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均配速
|
||||
/// </summary>
|
||||
public UInt16 AveragePace { get; set; } = 0;
|
||||
|
||||
public int InstantaneousPower { get; set; } = 0;
|
||||
|
||||
public int AveragePower { get; set; } = 0;
|
||||
public int ElapsedTime { get; set; } = 0;
|
||||
public int TotalEnergy { get; set; } = 0;
|
||||
public int EnergyPerHour { get; set; } = 0;
|
||||
public int EnergyPerMinute { get; set; } = 0;
|
||||
public event EventHandler RowerResChanged;
|
||||
public int ResistanceLevel { get; set; } = 0;
|
||||
public void Reset()
|
||||
{
|
||||
this.StrokeRate = 0;
|
||||
this.StrokeCount = 0;
|
||||
this.AverageStrokeRate = 0;
|
||||
this.TotalDistance = 0;
|
||||
this.InstantaneousPace = 0;
|
||||
this.AveragePace = 0;
|
||||
this.InstantaneousPower = 0;
|
||||
this.AveragePower = 0;
|
||||
this.ResistanceLevel = 0;
|
||||
this.TotalEnergy = 0;
|
||||
this.EnergyPerHour = 0;
|
||||
this.EnergyPerMinute = 0;
|
||||
this.ElapsedTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64ae3a6d26480b04c8fed17cc833d179
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using Assets.Scripts.Ble;
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using Assets.Scripts.Devices.Ble.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,46 +10,77 @@ using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
public class FtmsRowerData : ICharacteristic
|
||||
public class FtmsRowerData : ICharacteristic, IRowerCommonData
|
||||
{
|
||||
/// <summary>
|
||||
/// 划桨频率
|
||||
/// </summary>
|
||||
public uint StrokeRate { get; private set; } = 0;
|
||||
public uint StrokeRate { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 划桨次数
|
||||
/// </summary>
|
||||
public UInt16 StrokeCount { get; private set; } = 0;
|
||||
public UInt16 StrokeCount { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均划桨频率
|
||||
/// </summary>
|
||||
public int AverageStrokeRate { get; private set; } = 0;
|
||||
public int AverageStrokeRate { get; set; } = 0;
|
||||
|
||||
public UInt32 TotalDistance { get; private set; } = 0;
|
||||
private UInt32 _totalDistance = 0;
|
||||
public UInt32 TotalDistance
|
||||
{
|
||||
get => _totalDistance;
|
||||
set
|
||||
{
|
||||
if (_totalDistance == 0 && value != 0 && StartEvent != null)
|
||||
{
|
||||
StartEvent.Invoke(null, new EventArgs());
|
||||
}
|
||||
_totalDistance = value;
|
||||
}
|
||||
}
|
||||
//private UInt16 _instantaneousPace = 0;
|
||||
/// <summary>
|
||||
/// 即时配速
|
||||
/// </summary>
|
||||
public UInt16 InstantaneousPace { get; private set; } = 0;
|
||||
public UInt16 InstantaneousPace { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均配速
|
||||
/// </summary>
|
||||
public UInt16 AveragePace { get; private set; } = 0;
|
||||
public UInt16 AveragePace { get; set; } = 0;
|
||||
|
||||
public int InstantaneousPower { get; private set; } = 0;
|
||||
public int InstantaneousPower { get; set; } = 0;
|
||||
|
||||
public int AveragePower { get; private set; } = 0;
|
||||
|
||||
public int ResistanceLevel { get; private set; } = 0;
|
||||
public int AveragePower { get; set; } = 0;
|
||||
public event EventHandler RowerResChanged;
|
||||
private int commonRes = 50;
|
||||
private int thinkRes = 50;
|
||||
|
||||
public int ResistanceLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (device == null) return 0;
|
||||
if (device.Name.Contains("Think"))
|
||||
{
|
||||
return thinkRes;
|
||||
}
|
||||
else
|
||||
{
|
||||
return commonRes;
|
||||
}
|
||||
}
|
||||
set { }
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行时间
|
||||
/// </summary>
|
||||
public int ElapsedTime { get; private set; } = 0;
|
||||
|
||||
public int TotalEnergy { get; private set; } = 0;
|
||||
|
||||
public int EnergyPerHour { get; private set; } = 0;
|
||||
|
||||
public int EnergyPerMinute { get; private set; } = 0;
|
||||
public int ElapsedTime { get; set; } = 0;
|
||||
public int TotalEnergy { get; set; } = 0;
|
||||
public int EnergyPerHour { get; set; } = 0;
|
||||
public int EnergyPerMinute { get; set; } = 0;
|
||||
public double PeakDriveForce { get; set; } = 0;
|
||||
public double AverageDriveForce { get; set; } = 0;
|
||||
|
||||
public Guid Uuid => ServiceUuids.Characteristics.RowerData;
|
||||
|
||||
@@ -59,6 +91,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
public RowerDataFlag Flags;
|
||||
//拉力相关
|
||||
public event EventHandler PullChanged;
|
||||
//开始事件
|
||||
public event EventHandler StartEvent;
|
||||
private ushort _pullValue;
|
||||
public ushort PullValue
|
||||
{
|
||||
@@ -152,7 +186,12 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ResistanceLevel))
|
||||
{
|
||||
this.ResistanceLevel = BitConvertHelper.ToInt16(data, b);
|
||||
this.commonRes = BitConvertHelper.ToInt16(data, b);
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (device != null && !device.Name.Contains("Think") && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.commonRes, null);
|
||||
}
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ResistanceLevel);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ExpendedEnergy))
|
||||
@@ -184,20 +223,45 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.RemainingTime);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ThinkDragFactor))
|
||||
{
|
||||
this.thinkRes = BitConvertHelper.ToInt16(data, b + 1);
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (device != null && device.Name.Contains("Think") && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.thinkRes, null);
|
||||
}
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ThinkDragFactor);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.Pull))
|
||||
{
|
||||
List<ushort> list = new List<ushort>();
|
||||
for (int pullB = 4; pullB < data.Length; pullB += 2)
|
||||
{
|
||||
var val = BitConverter.ToUInt16(data, pullB);
|
||||
val = Convert.ToUInt16(((double)val) /9.8f);
|
||||
list.Add(val);
|
||||
PullValue = val;
|
||||
|
||||
}
|
||||
if (pullList == null) pullList = new List<ushort>();
|
||||
foreach (var pull in list)
|
||||
{
|
||||
if (pull == 0)
|
||||
{
|
||||
if (pullList.Count != 0)
|
||||
{
|
||||
PeakDriveForce = pullList.Max();
|
||||
AverageDriveForce = (double)pullList.Average(x=>x);
|
||||
}
|
||||
pullList.Clear();
|
||||
}
|
||||
pullList.Add(pull);
|
||||
}
|
||||
Debug.Log("拉力:" + string.Join(",",list));
|
||||
}
|
||||
//Debug.Log("原始数据:" + string.Join(",", data));
|
||||
}
|
||||
List<ushort> pullList;
|
||||
public void Reset()
|
||||
{
|
||||
this.StrokeRate = 0;
|
||||
@@ -208,7 +272,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
this.AveragePace = 0;
|
||||
this.InstantaneousPower = 0;
|
||||
this.AveragePower = 0;
|
||||
this.ResistanceLevel = 0;
|
||||
//this.commonRes = 50;
|
||||
//this.thinkRes = 50;
|
||||
//this.ResistanceLevel = 0;
|
||||
this.TotalEnergy = 0;
|
||||
this.EnergyPerHour = 0;
|
||||
this.EnergyPerMinute = 0;
|
||||
@@ -258,6 +324,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
case RowerDataFlag.RemainingTime:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.ThinkDragFactor:
|
||||
num = 5;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -288,7 +357,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
//单周期能耗
|
||||
SingleEnergy = 8192,
|
||||
//拉力曲綫
|
||||
Pull = 16384
|
||||
Pull = 16384,
|
||||
//Think 阻力
|
||||
ThinkDragFactor = 32768
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -16,44 +17,92 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
private FtmsRowerData _rowerData;
|
||||
public FtmsRowerData rowerData { get => _rowerData; }
|
||||
|
||||
|
||||
C2RowerData _c2RowerData;
|
||||
public C2RowerData c2RowerData { get => _c2RowerData; }
|
||||
private List<BleServiceInfo> Services;
|
||||
private BleCharacteristicInfo controlPointCharacteristic;
|
||||
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
|
||||
private BleCharacteristicInfo c2Control;
|
||||
|
||||
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);
|
||||
this._c2RowerData = new C2RowerData();
|
||||
base.Characteristics.Add(c2RowerData);
|
||||
bleWinHwInterface.CharacteristicReadEvent -= CharacteristicReadMainCallback;
|
||||
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
||||
}
|
||||
|
||||
protected override void CreateServices(List<BleServiceInfo> discoveredServices)
|
||||
{
|
||||
this.Services = discoveredServices;
|
||||
|
||||
Debug.Log("服务+" + string.Join(",", Services.Select(x => x.Id.ToString())));
|
||||
foreach (var service in this.Services)
|
||||
{
|
||||
hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) =>
|
||||
{
|
||||
|
||||
foreach (var character in response.Data)
|
||||
{
|
||||
//Debug.Log(character.Id.ToString());
|
||||
if (character.MatchGuid(ServiceUuids.Characteristics.FitnessMachineControlPoint))
|
||||
{
|
||||
Debug.Log("中控台获取");
|
||||
this.controlPointCharacteristic = character;
|
||||
}
|
||||
C2RowerData.IsEnabled = false;
|
||||
}
|
||||
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));
|
||||
});
|
||||
Debug.Log("ftms划船机" + service.Id);
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData35))
|
||||
{
|
||||
Debug.Log("c2划船机基本数据" + service.Id);
|
||||
//C2RowerData.IsEnabled = true;
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData3d))
|
||||
{
|
||||
Debug.Log("c2划船机拉力数据" + service.Id);
|
||||
//C2RowerData.IsEnabled = true;
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData32))
|
||||
{
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData33))
|
||||
{
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData36))
|
||||
{
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerData39))
|
||||
{
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
//else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerStatus))
|
||||
//{
|
||||
// Debug.Log("c2划船机响应数据" + service.Id);
|
||||
// //C2RowerData.IsEnabled = true;
|
||||
// this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
//}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerCourse))
|
||||
{
|
||||
Debug.Log("c2划船机课程数据" + service.Id);
|
||||
C2RowerData.IsEnabled = true;
|
||||
this.hwInterface.SubscribeCharacteristic(character, null);
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl))
|
||||
{
|
||||
Debug.Log("c2划船机控制台");
|
||||
this.c2Control = character;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -62,20 +111,113 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
|
||||
private void CharacteristicReadMainCallback(IBleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
||||
{
|
||||
foreach (var item in base.Characteristics)
|
||||
|
||||
//var tc = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData);
|
||||
//tc.HandleAttributeReceived(new byte[] { 61, 89, 0, 0, 0, 33, 0, 33, 0, 46, 0, 46, 0, 53, 0, 60, 0, 60, 0, 68, 0, 68, 0, 0, 0 });
|
||||
//tc.HandleAttributeReceived(new byte[] { 53, 223, 211, 0, 162, 57, 0, 82, 62, 96, 0, 94, 2, 183, 3, 125, 2, 208, 7, 203, 0 });
|
||||
if (characteristic.MatchGuid(ServiceUuids.Characteristics.RowerData))
|
||||
{
|
||||
if (characteristic.MatchGuid(item.Uuid))
|
||||
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData);
|
||||
if (c != null && !C2RowerData.IsEnabled)
|
||||
{
|
||||
//Debug.Log(string.Join(",", response.Data));
|
||||
item.HandleAttributeReceived(response.Data);
|
||||
c.HandleAttributeReceived(response.Data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData35);
|
||||
if (c != null)
|
||||
{
|
||||
var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray();
|
||||
c.HandleAttributeReceived(data);
|
||||
}
|
||||
}
|
||||
//foreach (var item in base.Characteristics)
|
||||
//{
|
||||
// if (characteristic.MatchGuid(item.Uuid) || characteristic.Id == ServiceUuids.Characteristics.C2RowerData1)
|
||||
// {
|
||||
// if (item.Uuid == ServiceUuids.Characteristics.C2RowerData1)
|
||||
// {
|
||||
// Debug.Log("c2");
|
||||
// var data = new byte[] { item.Uuid.ToByteArray()[0] }.Concat(response.Data).ToArray();
|
||||
// item.HandleAttributeReceived(data);
|
||||
// }
|
||||
// else if (item.Uuid == ServiceUuids.Characteristics.RowerData)
|
||||
// {
|
||||
// Debug.Log("ftms");
|
||||
// item.HandleAttributeReceived(response.Data);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
public void C2GetStatus(byte[] bs)
|
||||
{
|
||||
if (C2RowerData.IsEnabled == true)
|
||||
{
|
||||
//等对csafe协议研究透彻后写
|
||||
if (this.c2Control != null)
|
||||
{
|
||||
var cmd = bs;
|
||||
byte a = cmd[0];
|
||||
for (int i = 1; i < cmd.Length; i++)
|
||||
{
|
||||
a ^= cmd[i];
|
||||
}
|
||||
cmd = new byte[] { 0xf1 }.Concat(cmd).Concat(new byte[] { a, 0xf2 }).ToArray();
|
||||
Debug.Log("发送获取命令" + string.Join(",", cmd));
|
||||
hwInterface.WriteCharacteristic(this.c2Control, cmd);
|
||||
//hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x81, 0x81, 0xF2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Debug.Log("发送重置命令"+this.controlPointCharacteristic.ToString());
|
||||
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, new byte[] { 0x01 });
|
||||
if (C2RowerData.IsEnabled == true)
|
||||
{
|
||||
////等对csafe协议研究透彻后写
|
||||
//if (this.c2Control != null)
|
||||
//{
|
||||
// Debug.Log("发送重置命令" + this.c2Control.ToString());
|
||||
// hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x80, 0x80, 0xF2 });
|
||||
// //hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x81, 0x81, 0xF2 });
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.controlPointCharacteristic != null)
|
||||
{
|
||||
Debug.Log("发送重置命令" + this.controlPointCharacteristic.ToString());
|
||||
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, new byte[] { 0x01 });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void SetResistanceLevel(ushort v)
|
||||
{
|
||||
if (C2RowerData.IsEnabled == true)
|
||||
{
|
||||
//等对csafe协议研究透彻后写
|
||||
//if (this.c2Control != null)
|
||||
//{
|
||||
// var data = new byte[] { 0x29 }.Concat(BitConverter.GetBytes(v)).ToArray();
|
||||
// byte checksum = (byte)((byte)(data[0] ^ data[1]) ^ data[2]);
|
||||
// var r = new byte[] { 0xF1 }.Concat(data).Concat(new byte[] { checksum, 0xf2 }) .ToArray();
|
||||
// Debug.Log($"设置阻力{v}, {string.Join(",", r)}");
|
||||
// hwInterface.WriteCharacteristic(this.c2Control, r);
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.controlPointCharacteristic != null)
|
||||
{
|
||||
//特注:81是think专有指令,后期可能需要兼容其他设备
|
||||
var r = new byte[] { 0x81 }.Concat(BitConverter.GetBytes((ushort)(50 + v))).ToArray();
|
||||
Debug.Log($"设置阻力{v}, {string.Join(",", r)}");
|
||||
hwInterface.WriteCharacteristic(this.controlPointCharacteristic, r);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ble.Interfaces
|
||||
{
|
||||
interface IRowerCommonData
|
||||
{
|
||||
event EventHandler PullChanged;
|
||||
ushort PullValue { get; set; }
|
||||
double PeakDriveForce { get; set; }
|
||||
double AverageDriveForce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 划桨频率
|
||||
/// </summary>
|
||||
uint StrokeRate { get; set; }
|
||||
/// <summary>
|
||||
/// 划桨次数
|
||||
/// </summary>
|
||||
UInt16 StrokeCount { get; set;}
|
||||
/// <summary>
|
||||
/// 平均划桨频率
|
||||
/// </summary>
|
||||
int AverageStrokeRate { get; set; }
|
||||
UInt32 TotalDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 即时配速
|
||||
/// </summary>
|
||||
UInt16 InstantaneousPace { get; set; }
|
||||
/// <summary>
|
||||
/// 平均配速
|
||||
/// </summary>
|
||||
UInt16 AveragePace { get; set; }
|
||||
int InstantaneousPower { get; set; }
|
||||
int AveragePower { get; set; }
|
||||
int ElapsedTime { get; set; }
|
||||
int TotalEnergy { get; set; }
|
||||
|
||||
int EnergyPerHour { get; set; }
|
||||
|
||||
int EnergyPerMinute { get; set; }
|
||||
int ResistanceLevel { get; set; }
|
||||
void Reset();
|
||||
event EventHandler StartEvent;
|
||||
event EventHandler RowerResChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b9b93075aa03cf4587d75a49b2bfaa8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -44,6 +44,10 @@ namespace Assets.Scripts.Ble
|
||||
(byte) 24,
|
||||
(byte) 38
|
||||
};
|
||||
public static readonly byte[] C2Rower = new byte[]
|
||||
{
|
||||
(byte)206,(byte)6
|
||||
};
|
||||
public static readonly byte[] KineticInRide = new byte[16]
|
||||
{
|
||||
(byte) 233,
|
||||
@@ -164,6 +168,7 @@ namespace Assets.Scripts.Ble
|
||||
new ServiceUuid(new Guid("6e40fec1-b5a3-f393-e0a9-e50e24dcca9e"), ServiceUuids.TacxBle, true),
|
||||
new ServiceUuid(new Guid("01007b34-3576-8b40-8918-8ff3949ce592"), ServiceUuids.Elite, true),
|
||||
new ServiceUuid(new Guid("3a01f4c0-37a8-6541-bab9-654ef70747c6"), ServiceUuids.PowerBeam, true),
|
||||
new ServiceUuid(new Guid("CE060000-43E5-11E4-916C-0800200C9A66"), ServiceUuids.C2Rower,true),
|
||||
};
|
||||
public static readonly IReadOnlyList<ServiceUuid> CyclingServices = ServiceUuids.Services.Where(s => s.IsCycling).ToList();
|
||||
|
||||
@@ -367,6 +372,23 @@ namespace Assets.Scripts.Ble
|
||||
public static Guid WahooFitnessSensorMeasurementInput = new Guid("A026E016-0A7D-4AB3-97FA-F1500F9FEB8B");
|
||||
|
||||
public static Guid RowerData = new Guid("00002AD1-0000-1000-8000-00805F9B34FB");
|
||||
|
||||
|
||||
public static Guid C2RowerControl = new Guid("ce060021-43e5-11e4-916c-0800200c9a66");
|
||||
//0x35 有峰力值和均力值
|
||||
public static Guid C2RowerData35 = new Guid("ce060035-43e5-11e4-916c-0800200c9a66");
|
||||
//拉力曲线
|
||||
public static Guid C2RowerData3d = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66");
|
||||
//c2划船机状态
|
||||
public static Guid C2RowerStatus = new Guid("ce060022-43e5-11e4-916c-0800200c9a66");
|
||||
//c2划船机课程
|
||||
public static Guid C2RowerCourse = new Guid("CE060031-43E5-11E4-916C-0800200C9A66");
|
||||
public static Guid C2RowerData32 = new Guid("CE060032-43E5-11E4-916C-0800200C9A66");
|
||||
public static Guid C2RowerData33 = new Guid("CE060033-43E5-11E4-916C-0800200C9A66");
|
||||
public static Guid C2RowerData36 = new Guid("CE060036-43E5-11E4-916C-0800200C9A66");
|
||||
public static Guid C2RowerData39 = new Guid("CE060039-43E5-11E4-916C-0800200C9A66");
|
||||
public static Guid C2Service = new Guid("CE060030-43E5-11E4-916C-0800200C9A66");
|
||||
//ce060030-43e5-11e4-916c-0800200c9a66
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,17 +134,14 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//Debug.Log($"設備信息,{item.IdGuid},{string.Join(";",item.IdByteArray)}" );
|
||||
if (item.IdByteArray == ServiceUuids.Ftms)
|
||||
//Debug.Log($"設備{App.IsRowerMode}信息,{item.IdGuid},{string.Join(";", item.IdByteArray)}");
|
||||
if (item.IdByteArray == ServiceUuids.Ftms || item.IdByteArray == ServiceUuids.C2Rower)
|
||||
{
|
||||
if (App.IsRowerMode == true)
|
||||
{
|
||||
sensor = SensorType.Rower;
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor = SensorType.Trainer;
|
||||
}
|
||||
sensor = SensorType.Rower;
|
||||
//else
|
||||
//{
|
||||
// sensor = SensorType.FtmsTrainer;
|
||||
//}
|
||||
}
|
||||
else if (item.IdByteArray == ServiceUuids.HeartRate)
|
||||
{
|
||||
@@ -230,7 +227,7 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
callback?.Invoke(self, info, s);
|
||||
this.callbacks.Remove(info);
|
||||
Debug.Log("连接成功!");
|
||||
Debug.Log("连接成功!"+info.Name);
|
||||
if (this.callbacks.Any())
|
||||
{
|
||||
this.ConnectPeripheral(this.callbacks.First().Key, this.callbacks.First().Value);
|
||||
@@ -373,8 +370,11 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
this.characteristicNotificationCallbacks.Add(characteristic.Peripheral, callback);
|
||||
}
|
||||
BluetoothLEHardwareInterface.Log("SubscribeCharacteristic" + characteristic.Peripheral.Name + characteristic.Service.ToString() + characteristic.Service.ToString());
|
||||
BluetoothLEHardwareInterface.SubscribeCharacteristicWithDeviceAddress(characteristic.Peripheral.Address, characteristic.Service.ToString(), characteristic.Id.ToString(), null, (deviceAddress, characteristric, bytes) =>
|
||||
Debug.Log("SubscribeCharacteristic" + characteristic.Peripheral.Name + characteristic.Service.ToString() + characteristic.Service.ToString());
|
||||
BluetoothLEHardwareInterface.SubscribeCharacteristicWithDeviceAddress(characteristic.Peripheral.Address, characteristic.Service.ToString(), characteristic.Id.ToString(), (a,b)=>
|
||||
{
|
||||
Debug.Log("返回特征值," + a + "," + b);
|
||||
}, (deviceAddress, characteristric, bytes) =>
|
||||
{
|
||||
if (characteristicReadEvent != null)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user