c2课程同步
This commit is contained in:
1 parent
46f7c2d4b1
commit
4d4f8feb8b
13 files changed
+125
-109
No files matched your search
@@ -11,11 +11,6 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
public class C2RowerData : ICharacteristic, IRowerCommonData
|
||||
{
|
||||
public static string JUSTROW_HEX = "F1 76 07 01 01 01 13 02 01 01 61 F2";
|
||||
public static string TERMINATEWORKOUT_HEX = "F1 76 04 13 02 01 02 62 F2";
|
||||
public static string FIXEDDISTANCE_HEX = "F1 76 18 01 01 03 03 05 80 00 00 07 D0 05 05 80 00 00 01 90 14 01 01 13 02 01 01 28 F2";
|
||||
public static string FIXEDTIME_HEX = "F1 76 07 01 01 01 13 02 01 01 61 F2";
|
||||
|
||||
public Guid Uuid => ServiceUuids.Characteristics.C2RowerData35;
|
||||
|
||||
public Guid ServiceUuid => ServiceUuids.Characteristics.C2Service;
|
||||
@@ -23,6 +18,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
public bool IsOptional => false;
|
||||
|
||||
public static event EventHandler EnableChanged;
|
||||
public static event EventHandler RowerTypeChanged;
|
||||
private static bool _isEnabled;
|
||||
public static bool IsEnabled
|
||||
{
|
||||
@@ -56,59 +52,62 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUserDefined { get; set; }
|
||||
|
||||
public static bool isReadyStatus { get; private set; }
|
||||
public static RowerTaskPanel.RowerType rowerType { get; private set; }
|
||||
public static RowerTaskPanel.RowerType rowerType = new RowerTaskPanel.RowerType() { type = 0 ,value = 0};
|
||||
public void HandleAttributeReceived(byte[] 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);
|
||||
}
|
||||
else if (data[0] == 0x3d)
|
||||
{
|
||||
if (data[2] == 0)
|
||||
{
|
||||
PullValue = 0;
|
||||
}
|
||||
//老款表头不支持
|
||||
//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)));
|
||||
//r.Add(pull);
|
||||
PullValue = pull;
|
||||
}
|
||||
|
||||
// Debug.Log("拉力曲线:" + string.Join(",", r));
|
||||
// Debug.Log("拉力曲线:" + string.Join(",", r));
|
||||
}
|
||||
else if (data[0] == 0x31)
|
||||
{
|
||||
byte status = data[18];
|
||||
ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 1)) / 100);
|
||||
TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 4)) / 10);
|
||||
|
||||
int status = (int)data[7];
|
||||
int value = (data[17] << 16) + (data[16] << 8) + data[15];
|
||||
if (status == 128 && value != 0)
|
||||
|
||||
int type = 0;
|
||||
//3 里程 5 时间 1直接划船
|
||||
if (status == 3)
|
||||
{
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 1;
|
||||
type = 1;
|
||||
}
|
||||
if (status == 5)
|
||||
{
|
||||
type = 2;
|
||||
value /= 100;
|
||||
}
|
||||
//如果课程发生变化
|
||||
if (status != 0 && type > 0 && ( rowerType.type != type || rowerType.value != value))
|
||||
{
|
||||
Debug.Log($"status{status}-type{type}-value{value}");
|
||||
rowerType.type = type;
|
||||
rowerType.value = value;
|
||||
IsUserDefined = true;
|
||||
RowerTypeChanged?.Invoke(this,null);
|
||||
}
|
||||
else if (status == 0)
|
||||
{
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 2;
|
||||
rowerType.value = value / 100;
|
||||
IsUserDefined = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType = null;
|
||||
IsUserDefined = false;
|
||||
}
|
||||
Debug.Log($"里程:{TotalDistance}峰力值:{PeakDriveForce} 均力值{AverageDriveForce} ReadyStatus:{isReadyStatus} TIME{DateTime.Now}");
|
||||
//isReadyStatus = data[9] == 0;
|
||||
|
||||
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
|
||||
Debug.Log("划船时间" + time);
|
||||
isReadyStatus = data[9] == 0;
|
||||
@@ -139,7 +138,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
else if (data[0] == 0x39)
|
||||
{
|
||||
ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 5)) / 100);
|
||||
TrainingTime = (Convert.ToDouble(BitConvertHelper.ToUInt24(data, 5)) / 100);
|
||||
ElapsedTime = (int)TrainingTime;
|
||||
TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 8)) / 10);
|
||||
CompleteEvent?.Invoke(this, null);
|
||||
}
|
||||
@@ -196,6 +196,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
|
||||
public int AveragePower { get; set; } = 0;
|
||||
public int ElapsedTime { get; set; } = 0;
|
||||
public double TrainingTime { get; set; } = 0;
|
||||
public int TotalEnergy { get; set; } = 0;
|
||||
public int EnergyPerHour { get; set; } = 0;
|
||||
public int EnergyPerMinute { get; set; } = 0;
|
||||
@@ -216,6 +217,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
this.EnergyPerHour = 0;
|
||||
this.EnergyPerMinute = 0;
|
||||
this.ElapsedTime = 0;
|
||||
this.TrainingTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
/// 运行时间
|
||||
/// </summary>
|
||||
public int ElapsedTime { get; set; } = 0;
|
||||
public double TrainingTime { get; set; } = 0;
|
||||
public int TotalEnergy { get; set; } = 0;
|
||||
public int EnergyPerHour { get; set; } = 0;
|
||||
public int EnergyPerMinute { get; set; } = 0;
|
||||
@@ -295,6 +296,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
this.EnergyPerHour = 0;
|
||||
this.EnergyPerMinute = 0;
|
||||
this.ElapsedTime = 0;
|
||||
this.TrainingTime = 0;
|
||||
}
|
||||
|
||||
public int SizeOfDataForFlag(RowerDataFlag flag)
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Assets.Scripts.Devices.Ble.Interfaces
|
||||
int InstantaneousPower { get; set; }
|
||||
int AveragePower { get; set; }
|
||||
int ElapsedTime { get; set; }
|
||||
double TrainingTime { get; set; }
|
||||
int TotalEnergy { get; set; }
|
||||
|
||||
int EnergyPerHour { get; set; }
|
||||
|
||||
Reference in new issue
Block a user