适配C2划船机课程和menu

This commit is contained in:
Caiyanpeng committed 2022-03-30 18:25:51 +08:00
1 parent e0649f7ea1
commit 06aefb93c4
6 files changed
+162 -77

No files matched your search

@@ -13,5 +13,6 @@ namespace Assets.Scripts.Devices.Ant.Interfaces
FtmsRowerData rowerData { get; }
void Reset();
void SetResistanceLevel(ushort v);
void C2GetStatus();
}
}
@@ -50,6 +50,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
}
}
}
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));
@@ -59,7 +62,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10);
Debug.Log($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}");
}
else if (data[0] == 61)
else if (data[0] == 61)
{
List<ushort> r = new List<ushort>();
for (int i = 3; i < data.Length; i += 2)
@@ -68,9 +71,36 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
r.Add(pull);
PullValue = pull;
}
Debug.Log("拉力曲线:"+ string.Join(",",r));
Debug.Log("拉力曲线:" + string.Join(",", r));
}
else if (data[0] == 49)
{
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;
//isReadyStatus = data[2] == 1 || data[2] == 129;
}
//else if (data[0] == 34)
//{
// isReadyStatus = data[2] == 1 || data[2] == 129;
//}
}
private double LbsToNewton(double lbs) => 4.4482216 * lbs;
public void SetUnavailable()
@@ -23,7 +23,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
private BleCharacteristicInfo controlPointCharacteristic;
private BleCharacteristicInfo c2Control;
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
{
Debug.Log(24);
base.Characteristics.Add(new FtmsFitnessMachineFeature());
@@ -44,7 +44,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
{
hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) =>
{
foreach (var character in response.Data)
{
//Debug.Log(character.Id.ToString());
@@ -70,13 +70,19 @@ namespace Assets.Scripts.Devices.Ble.Devices
//C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null);
}
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerStatus))
//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);
Debug.Log("c2划船机课程数据" + service.Id);
//C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null);
}
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl))
else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl))
{
Debug.Log("c2划船机控制台");
this.c2Control = character;
@@ -97,7 +103,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData);
c.HandleAttributeReceived(response.Data);
}
else
else
{
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData);
var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray();
@@ -121,6 +127,27 @@ namespace Assets.Scripts.Devices.Ble.Devices
// }
//}
}
public void C2GetStatus()
{
if (C2RowerData.IsEnabled == true)
{
//等对csafe协议研究透彻后写
//if (this.c2Control != null)
//{
// var cmd = new byte[] { 0x80, 0xe8 };
// 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()
{
@@ -375,7 +375,9 @@ namespace Assets.Scripts.Ble
//拉力曲线
public static Guid C2RowerData1 = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66");
//c2划船机状态
public static Guid C2RowerStatus = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66");
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 C2Service = new Guid("CE060030-43E5-11E4-916C-0800200C9A66");
//ce060030-43e5-11e4-916c-0800200c9a66
}