4.14修改,设备连接去掉ftms骑行台

This commit is contained in:
Caiyanpeng committed 2022-04-14 19:18:44 +08:00
1 parent 29e7219c21
commit f383c54507
18 files changed
+2511 -10695

No files matched your search

+2 -1
View File
@@ -38,7 +38,8 @@ namespace Assets.Scripts.Devices.Ant
SpeedCadence,
Trainer,
VirtualPower,
Rower
Rower,
FtmsTrainer
}
public enum NetworkType
+31 -5
View File
@@ -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();
}
}
}
}
@@ -58,8 +58,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
//Debug.Log("数据" + string.Join(",", data));
if (data[0] == 53)
{
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10);
AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10);
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10,true);
AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10, true);
Debug.Log($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}");
}
else if (data[0] == 61)
@@ -67,7 +67,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
List<ushort> r = new List<ushort>();
for (int i = 3; i < data.Length; i += 2)
{
ushort pull = data[i] < 10 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i])));
ushort pull = data[i] < 10 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
r.Add(pull);
PullValue = pull;
}
@@ -105,7 +105,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
// isReadyStatus = data[2] == 1 || data[2] == 129;
//}
}
private double LbsToNewton(double lbs) => 4.4482216 * lbs;
private double LbsToNewton(double lbs,bool isKg = false) => 4.4482216 * lbs * (isKg ? (1f / 9.8f) : 1f);
public void SetUnavailable()
{
//throw new NotImplementedException();
@@ -226,6 +226,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
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;
@@ -102,13 +102,19 @@ namespace Assets.Scripts.Devices.Ble.Devices
if (characteristic.MatchGuid(ServiceUuids.Characteristics.RowerData))
{
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData);
c.HandleAttributeReceived(response.Data);
if (c != null)
{
c.HandleAttributeReceived(response.Data);
}
}
else
{
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData);
var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray();
c.HandleAttributeReceived(data);
if (c != null)
{
var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray();
c.HandleAttributeReceived(data);
}
}
//foreach (var item in base.Characteristics)
//{
@@ -134,17 +134,14 @@ namespace Assets.Scripts.Ble
{
continue;
}
//Debug.Log($"設備信息,{item.IdGuid},{string.Join(";", item.IdByteArray)}");
//Debug.Log($"設備{App.IsRowerMode}信息,{item.IdGuid},{string.Join(";", item.IdByteArray)}");
if (item.IdByteArray == ServiceUuids.Ftms)
{
if (App.IsRowerMode == true)
{
sensor = SensorType.Rower;
}
else
{
sensor = SensorType.Trainer;
}
sensor = SensorType.Rower;
//else
//{
// sensor = SensorType.FtmsTrainer;
//}
}
else if (item.IdByteArray == ServiceUuids.HeartRate)
{