适配v1表头,性能优化一波

This commit is contained in:
Caiyanpeng committed 2022-05-11 17:11:48 +08:00
1 parent edc629ed75
commit be687d6b77
10 files changed
+282 -162

No files matched your search

@@ -11,7 +11,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
{
public class C2RowerData : ICharacteristic, IRowerCommonData
{
public Guid Uuid => ServiceUuids.Characteristics.C2RowerData;
public Guid Uuid => ServiceUuids.Characteristics.C2RowerData35;
public Guid ServiceUuid => ServiceUuids.Characteristics.C2Service;
@@ -56,25 +56,29 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
public void HandleAttributeReceived(byte[] data)
{
Debug.Log("数据" + string.Join(",", data));
if (data[0] == 53)
if (data[0] == 0x35)
{
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10,true);
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] == 61)
else if (data[0] == 0x3d)
{
//老款表头不支持
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], true)));
ushort pull = Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));//data[i] < 10 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
r.Add(pull);
PullValue = pull;
}
Debug.Log("拉力曲线:" + string.Join(",", r));
}
else if (data[0] == 49)
else if (data[0] == 0x31)
{
byte status = data[18];
int value = (data[17] << 16) + (data[16] << 8) + data[15];
@@ -90,26 +94,114 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
rowerType.type = 2;
rowerType.value = value / 100;
}
else
else
{
rowerType = null;
}
//isReadyStatus = data[9] == 0;
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
Debug.Log("划船时间"+time);
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;
public UInt32 TotalDistance { get; set; } = 0;
public UInt16 _instantaneousPace = 0;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace {
get => _instantaneousPace;
set
{
if (_instantaneousPace == 0 && value != 0 && StartEvent != null)
{
StartEvent.Invoke(null, new EventArgs());
}
_instantaneousPace = value;
}
}
/// <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;
}
}
}
@@ -15,30 +15,42 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
/// <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;
public UInt32 TotalDistance { get; set; } = 0;
public UInt16 _instantaneousPace = 0;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace { get; private set; } = 0;
public UInt16 InstantaneousPace
{
get => _instantaneousPace;
set
{
if (_instantaneousPace == 0 && value != 0 && StartEvent != null)
{
StartEvent.Invoke(null, new EventArgs());
}
_instantaneousPace = value;
}
}
/// <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 static event EventHandler RowerResChanged;
public int AveragePower { get; set; } = 0;
public event EventHandler RowerResChanged;
private int commonRes = 50;
private int thinkRes = 50;
@@ -57,17 +69,15 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
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;
@@ -80,6 +90,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
public RowerDataFlag Flags;
//拉力相关
public event EventHandler PullChanged;
//开始事件
public event EventHandler StartEvent;
private ushort _pullValue;
public ushort PullValue
{