实现连接设备界面
This commit is contained in:
1 parent
996f924719
commit
ec7589096f
88 files changed
+11344
-156
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using Assets.Scripts.Devices.Ant.Pages.CalibrationPages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备校准的处理函数
|
||||
/// </summary>
|
||||
public class CalibrationPageHandler : IPageHandler
|
||||
{
|
||||
private readonly IList<ICalibrationPage> _calibrationPageHandlers = new List<ICalibrationPage>()
|
||||
{
|
||||
new CtfCalibrationPage(),
|
||||
new FecCalibrationPage(),
|
||||
new FailureCalibrationPage(),
|
||||
new SuccessCalibrationPage()
|
||||
};
|
||||
|
||||
public bool CanHandle(byte pageNumber)
|
||||
{
|
||||
if ((int)pageNumber != 1)
|
||||
{
|
||||
return (int)pageNumber == 240;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var calibrationPage = this._calibrationPageHandlers.FirstOrDefault(ph => ph.CanHandle(dataPayload[1]));
|
||||
if (calibrationPage == null)
|
||||
return;
|
||||
calibrationPage.Handle(dataPayload, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75c5b210cd34db1498a311b6656f9ad4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
|
||||
{
|
||||
public class CtfCalibrationPage : ICalibrationPage
|
||||
{
|
||||
public bool CanHandle(byte calibrationId)
|
||||
{
|
||||
return (int)calibrationId == 16;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null || (int)dataPayload[2] != 1)
|
||||
return;
|
||||
//参考类CtfCalibrationResult
|
||||
var offset = (int)((int)dataPayload[7] | (int)dataPayload[6] << 8);
|
||||
powerDevice.DoCalibrationSuccess(offset, AutoZeroStatus.NotSupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c60f86d0918cf4d9656359561b9c7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
|
||||
{
|
||||
/// <summary>
|
||||
/// 校准失败的处理函数
|
||||
/// </summary>
|
||||
public class FailureCalibrationPage : ICalibrationPage
|
||||
{
|
||||
public bool CanHandle(byte calibrationId)
|
||||
{
|
||||
return (int)calibrationId == 175;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87c2482dbcf031e488a6dd7cfc3b475b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
|
||||
{
|
||||
/// <summary>
|
||||
/// 校准成功的处理函数
|
||||
/// </summary>
|
||||
public class SuccessCalibrationPage : ICalibrationPage
|
||||
{
|
||||
public bool CanHandle(byte calibrationId)
|
||||
{
|
||||
return (int)calibrationId == 172;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
return;
|
||||
var autoZeroStatus = (AutoZeroStatus)dataPayload[2];
|
||||
var offset = (int)((int)dataPayload[7] << 8 | (int)dataPayload[6]);
|
||||
powerDevice.DoCalibrationSuccess(offset, autoZeroStatus);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c45f42f53396ece499b5153107ab46da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages
|
||||
{
|
||||
public class CrankPowerPageHandler : IPageHandler
|
||||
{
|
||||
private readonly TorquePowerDataCalculator _torquePowerDataCalculator = new TorquePowerDataCalculator();
|
||||
|
||||
public bool CanHandle(byte pageNumber)
|
||||
{
|
||||
return (int)pageNumber == 18;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
return;
|
||||
byte eventCount = dataPayload[1];
|
||||
int num = (int)dataPayload[3];
|
||||
ushort period = (ushort)((uint)dataPayload[4] | (uint)dataPayload[5] << 8);
|
||||
ushort accumulatedTorque = (ushort)(dataPayload[6] | (uint)dataPayload[7] << 8);
|
||||
this._torquePowerDataCalculator.Update(eventCount, period, accumulatedTorque);
|
||||
//powerDevice.UpdateCadence(new int?(this._torquePowerDataCalculator.Rpm));
|
||||
//powerDevice.UpdatePower(new int?(this._torquePowerDataCalculator.Power));
|
||||
powerDevice.Cadence = this._torquePowerDataCalculator.Rpm;
|
||||
powerDevice.Power = this._torquePowerDataCalculator.Power;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb07cd617b03b2b4eb8df137b07ae7fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// Crank Torque-Frequency Message 曲柄功率计的消息
|
||||
/// </summary>
|
||||
public class CtfPageHandler : IPageHandler
|
||||
{
|
||||
private readonly CrankTorqueFrequencyData _crankTorqueFrequency = new CrankTorqueFrequencyData();
|
||||
|
||||
public bool CanHandle(byte pageNumber)
|
||||
{
|
||||
return (int)pageNumber == 32;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
byte num1 = dataPayload[1];
|
||||
ushort num2 = (ushort)((uint)dataPayload[3] | (uint)dataPayload[2] << 8);
|
||||
ushort num3 = (ushort)((uint)dataPayload[5] | (uint)dataPayload[4] << 8);
|
||||
ushort num4 = (ushort)((uint)dataPayload[7] | (uint)dataPayload[6] << 8);
|
||||
|
||||
if (powerDevice.Offset.HasValue)
|
||||
{
|
||||
int offset = powerDevice.Offset.GetValueOrDefault(0);
|
||||
|
||||
CrankTorqueFrequencyData torqueFrequencyData = this._crankTorqueFrequency;
|
||||
int num5 = (int)num1;
|
||||
int num6 = (int)num3;
|
||||
int num7 = (int)num4;
|
||||
int num8 = (int)num2;
|
||||
|
||||
torqueFrequencyData.Update((byte)num5, (ushort)num6, (ushort)num7, (ushort)num8, offset);
|
||||
|
||||
Console.WriteLine("offset:" + offset);
|
||||
powerDevice.Power = this._crankTorqueFrequency.Power.GetValueOrDefault();
|
||||
}
|
||||
powerDevice.Cadence = this._crankTorqueFrequency.Cadence;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20f678fa75e9edb48a11bed1c1284daf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages
|
||||
{
|
||||
public class PowerOnlyPageHandler : IPageHandler
|
||||
{
|
||||
private DateTime _lastEventChange = DateTime.UtcNow;
|
||||
private byte _previousEventCount;
|
||||
|
||||
public bool CanHandle(byte pageNumber)
|
||||
{
|
||||
return (int)pageNumber == 16;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//var dataPayload = response.messageContents.Skip(1).ToArray();
|
||||
byte currentVal = dataPayload[1];
|
||||
if ((int)ByteExtensions.GetDifference(currentVal, this._previousEventCount) > 0) //ByteExtensions
|
||||
this._lastEventChange = DateTime.UtcNow;
|
||||
this._previousEventCount = currentVal;
|
||||
powerDevice.Power = this.IsNotMovingDueToNoEventChanges() ? 0 : (ushort)((uint)dataPayload[6] | (uint)dataPayload[7] << 8);
|
||||
if ((int)dataPayload[3] != (int)byte.MaxValue)
|
||||
powerDevice.Cadence = (this.IsNotMovingDueToNoEventChanges() ? 0 : (int)dataPayload[3]);
|
||||
else
|
||||
powerDevice.Cadence = 0;
|
||||
//int num1 = (int)dataPayload[2];
|
||||
//int num2 = 128;
|
||||
//bool flag = (uint)(num1 & num2) > 0U;
|
||||
//int num3 = (int)sbyte.MaxValue;
|
||||
//int num4 = num1 & num3;
|
||||
//int num5 = (int)byte.MaxValue;
|
||||
}
|
||||
|
||||
private bool IsNotMovingDueToNoEventChanges()
|
||||
{
|
||||
return this._lastEventChange.AddSeconds(3.0) <= DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 267f065da5b080847b6c2354e6af58f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// 轮盘功率计
|
||||
/// </summary>
|
||||
public class WheelPowerPageHandler : IPageHandler
|
||||
{
|
||||
private readonly TorquePowerDataCalculator _torquePowerDataCalculator = new TorquePowerDataCalculator();
|
||||
|
||||
public bool CanHandle(byte pageNumber)
|
||||
{
|
||||
return pageNumber == 17;
|
||||
}
|
||||
|
||||
public void Handle(byte[] dataPayload, AbstractAntDevice device)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
var powerDevice = device as PowerDevice;
|
||||
if (powerDevice == null)
|
||||
return;
|
||||
|
||||
var eventCount = dataPayload[1];
|
||||
var num = dataPayload[3];
|
||||
|
||||
var period = (ushort)((uint)dataPayload[4] | (uint)dataPayload[5] << 8);
|
||||
var accumulatedTorque = (ushort)((uint)dataPayload[6] | (uint)dataPayload[7] << 8);
|
||||
|
||||
_torquePowerDataCalculator.Update(eventCount, period, accumulatedTorque);
|
||||
|
||||
powerDevice.Power = _torquePowerDataCalculator.Power;
|
||||
powerDevice.Cadence = num;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 399061526025e6148ba3f55a5800ed56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user