51 lines
2.1 KiB
C#
51 lines
2.1 KiB
C#
using JiShe.CollectBus.Common.Extensions;
|
||
using JiShe.CollectBus.Protocol.Interfaces;
|
||
|
||
namespace JiShe.CollectBus.Protocol.T37612012.Appendix
|
||
{
|
||
public class Appendix_A23 : IAnalysisStrategy<List<string>, decimal>
|
||
{
|
||
|
||
public async Task<decimal> ExecuteAsync(List<string> data)
|
||
{
|
||
decimal value = 0.000M;
|
||
if (data[0].Check3761Byte())
|
||
value += GetValue(0, 4, 1000M, 4, 4, 10000M, data[0], 1);
|
||
if (data[1].Check3761Byte())
|
||
value += GetValue(0, 4, 10M, 4, 4, 100M, data[1], 1);
|
||
if (data[2].Check3761Byte())
|
||
value += GetValue(0, 4, 10M, 4, 4, 1M, data[2], 0);
|
||
return await Task.FromResult(value);
|
||
}
|
||
/// <summary>
|
||
/// 解析值
|
||
/// </summary>
|
||
/// <param name="startIndex">二进制低位字符串截取位置</param>
|
||
/// <param name="startLength">截取长度</param>
|
||
/// <param name="startQuantile">分位值,1000M</param>
|
||
/// <param name="endIndex">二进制高位字符串截取位置</param>
|
||
/// <param name="endLength">截取长度</param>
|
||
/// <param name="endQuantile">分位值,100M</param>
|
||
/// <param name="data">数据</param>
|
||
/// <param name="calType">计算类型,0:乘法,1:除法</param>
|
||
/// <returns></returns>
|
||
private decimal GetValue(int startIndex, int startLength, decimal startQuantile, int endIndex, int endLength, decimal endQuantile, string data, int calType = 0)
|
||
{
|
||
var value = 0M;
|
||
string binString = data.HexTo4BinZero();
|
||
switch (calType)
|
||
{
|
||
case 0:
|
||
value = (binString.Substring(startIndex, startLength).BinToDec() * startQuantile) + (binString.Substring(endIndex, endLength).BinToDec() * endQuantile);
|
||
break;
|
||
case 1:
|
||
value = (binString.Substring(startIndex, startLength).BinToDec() / startQuantile) + (binString.Substring(endIndex, endLength).BinToDec() / endQuantile);
|
||
break;
|
||
}
|
||
return value;
|
||
}
|
||
|
||
|
||
}
|
||
}
|