116 lines
3.9 KiB
C#
116 lines
3.9 KiB
C#
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.C2RowerData;
|
|
|
|
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] == 53)
|
|
{
|
|
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)
|
|
{
|
|
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)));
|
|
r.Add(pull);
|
|
PullValue = pull;
|
|
}
|
|
|
|
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;
|
|
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
|
|
Debug.Log("划船时间"+time);
|
|
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,bool isKg = false) => 4.4482216 * lbs * (isKg ? (1f / 9.8f) : 1f);
|
|
public void SetUnavailable()
|
|
{
|
|
//throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
}
|