44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
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;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|