2025-04-24 19:31:28 +08:00

51 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using JiShe.CollectBus.Common.Extensions;
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
namespace JiShe.CollectBus.Protocol.AnalysisData.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;
}
}
}