Compare commits
2 Commits
2dbf4ded4a
...
32617a9b83
| Author | SHA1 | Date | |
|---|---|---|---|
| 32617a9b83 | |||
| 825e7d5f18 |
@ -71,8 +71,8 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH
|
|||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var pnfnArr = dataArr.GetRange(0, 4);
|
var pnfnArr = dataArr.GetRange(0, 4);
|
||||||
var tempPn = ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]);
|
var tempPn = T37612012ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]);
|
||||||
var tempFn = ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]);
|
var tempFn = T37612012ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]);
|
||||||
entity.Details.Add(new SetAutoItemCodeDetails() { Fn = tempFn, Pn = tempPn });
|
entity.Details.Add(new SetAutoItemCodeDetails() { Fn = tempFn, Pn = tempPn });
|
||||||
dataArr.RemoveRange(0, 4);
|
dataArr.RemoveRange(0, 4);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
|||||||
ArgumentNullException.ThrowIfNull(input.A.A3?.D1_D7);
|
ArgumentNullException.ThrowIfNull(input.A.A3?.D1_D7);
|
||||||
UnitDataAnalysis<List<AFN12_F129_AnalysisDto>> unitDataAnalysis = new UnitDataAnalysis<List<AFN12_F129_AnalysisDto>>
|
UnitDataAnalysis<List<AFN12_F129_AnalysisDto>> unitDataAnalysis = new UnitDataAnalysis<List<AFN12_F129_AnalysisDto>>
|
||||||
{
|
{
|
||||||
Code = input.A.Code,
|
Code = input.A.Code!,
|
||||||
AFN = input.AFN_FC.AFN,
|
AFN = input.AFN_FC.AFN,
|
||||||
Fn = input.DT.Fn,
|
Fn = input.DT.Fn,
|
||||||
Pn = input.DA.Pn,
|
Pn = input.DA.Pn,
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
||||||
|
{
|
||||||
|
public class DataStorage:ITransientDependency
|
||||||
|
{
|
||||||
|
public DataStorage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -370,6 +370,340 @@ namespace JiShe.CollectBus.Protocol
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析376.1帧
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageReceived"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual TB3761? Analysis3761(string messageReceived)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var hexStringList = messageReceived.StringToPairs();
|
||||||
|
// 初步校验
|
||||||
|
if (hexStringList.Count < 6 || hexStringList.FirstOrDefault() != "68" || hexStringList.Skip(5).Take(1).FirstOrDefault() != "68" || hexStringList.Count < 18 || hexStringList.LastOrDefault() != "16")
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis3761校验不通过,报文:{messageReceived}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TB3761 tB3761 = new TB3761
|
||||||
|
{
|
||||||
|
BaseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageString = messageReceived,
|
||||||
|
HexMessageList = hexStringList
|
||||||
|
},
|
||||||
|
C = Analysis_C(hexStringList),
|
||||||
|
A = Analysis_A(hexStringList),
|
||||||
|
AFN_FC = Analysis_AFN_FC(hexStringList),
|
||||||
|
SEQ = Analysis_SEQ(hexStringList),
|
||||||
|
UnitData = Analysis_UnitData(hexStringList),
|
||||||
|
DA = Analysis_DA(hexStringList),
|
||||||
|
DT = Analysis_DT(hexStringList)
|
||||||
|
};
|
||||||
|
return tB3761;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis3761错误,报文:{messageReceived},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控制域C解析
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual C Analysis_C(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
C c = new C();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count > 6)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(6, 1) // 控制域 1字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
if (baseHexMessage.HexMessageList.Count == 0)
|
||||||
|
return null;
|
||||||
|
string binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
||||||
|
c = new C
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
FC = binStr.Substring(binStr.Length - 4, 4).BinToDec(),
|
||||||
|
FCV = binStr.Substring(3, 1).BinToDec(),
|
||||||
|
FCB = binStr.Substring(2, 1).BinToDec(),
|
||||||
|
PRM = binStr.Substring(1, 1).BinToDec(),
|
||||||
|
DIR = binStr.Substring(0, 1).BinToDec()
|
||||||
|
};
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_C错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 地址域A解析
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hexStringList"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual A Analysis_A(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
A a = new A();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count > 7)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(7, 5) // 地址域 5个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
a = new A
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
A1 = baseHexMessage.HexMessageList.ListReverseToStr(0, 2),//.DataConvert(10);//行政区划码A1
|
||||||
|
A2 = baseHexMessage.HexMessageList.ListReverseToStr(2, 2).PadLeft(5, '0').HexToDec(),//终端地址A2
|
||||||
|
A3 = Analysis_A3(baseHexMessage.HexMessageList) //主站地址和组地址标志A3
|
||||||
|
};
|
||||||
|
a.Code = $"{a.A1.PadLeft(4, '0')}{a.A2.ToString()!.PadLeft(5, '0')}";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_A错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return a;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 站地址和组地址标志A3
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hexAList">地址域A集合</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual A3 Analysis_A3(List<string> hexAList)
|
||||||
|
{
|
||||||
|
A3 a3 = new A3();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexAList.Count != 0)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexAList.GetRange(4, 1) // 站地址和组地址标志A3 1个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
var binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
||||||
|
a3 = new A3
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
D0 = binStr.Substring(binStr.Length - 1, 1).BinToDec(),
|
||||||
|
D1_D7 = binStr.Substring(0, binStr.Length - 1).BinToDec()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_A3错误,报文:{string.Join("", hexAList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return a3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AFN_FC功能码
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual AFN_FC Analysis_AFN_FC(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
AFN_FC aFN_FC = new AFN_FC();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(12, 1) //AFN功能码 1个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
|
||||||
|
aFN_FC = new AFN_FC
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
AFN = baseHexMessage.HexMessageString.HexToDec(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_AFN_FC错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return aFN_FC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析帧序列域SEQ
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual SEQ Analysis_SEQ(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
SEQ seq = new SEQ();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count != 0)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(13, 1) //帧序列域 SEQ 1个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
var binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
||||||
|
seq = new SEQ
|
||||||
|
{
|
||||||
|
PSEQ = binStr.Substring(binStr.Length - 4, 4).BinToDec(),
|
||||||
|
CON = binStr.Substring(3, 1).BinToDec(),
|
||||||
|
FIN = binStr.Substring(2, 1).BinToDec(),
|
||||||
|
FIR = binStr.Substring(1, 1).BinToDec(),
|
||||||
|
TpV = binStr.Substring(0, 1).BinToDec()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_SEQ错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
return seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据单元标识及数据单元数据
|
||||||
|
/// </summary>
|
||||||
|
public virtual UnitData Analysis_UnitData(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
UnitData unitData = new UnitData();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count != 0)
|
||||||
|
{
|
||||||
|
unitData = new UnitData
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(14, hexStringList.Count - 14 - 2) //总数字节数-固定长度报文头-控制域C-地址域A-校验和CS-结束字符(16H)
|
||||||
|
};
|
||||||
|
unitData.HexMessageString = string.Join("", unitData.HexMessageList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_UnitData错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
return unitData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 信息点DA Pn
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual DA Analysis_DA(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
DA da = new DA();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count != 0)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(14, 2) //信息点DA Pn 2个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
var da1 = baseHexMessage.HexMessageList[0];
|
||||||
|
var da2 = baseHexMessage.HexMessageList[1];
|
||||||
|
da = new DA()
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
Pn = CalculatePn(da1, da2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_DA错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
return da;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 信息类DT Fn
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual DT Analysis_DT(List<string> hexStringList)
|
||||||
|
{
|
||||||
|
DT dt = new DT();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hexStringList.Count != 0)
|
||||||
|
{
|
||||||
|
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||||
|
{
|
||||||
|
HexMessageList = hexStringList.GetRange(16, 2) //信息类DT Fn 2个字节
|
||||||
|
};
|
||||||
|
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||||
|
var dt1 = baseHexMessage.HexMessageList[0];
|
||||||
|
var dt2 = baseHexMessage.HexMessageList[1];
|
||||||
|
dt = new DT()
|
||||||
|
{
|
||||||
|
BaseHexMessage = baseHexMessage,
|
||||||
|
Fn = CalculateFn(dt1, dt2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"解析Analysis_DT错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return dt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算Pn
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="da1"></param>
|
||||||
|
/// <param name="da2"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int CalculatePn(string da1, string da2) => (da2.HexToDec() - 1) * 8 + (8 - da1.HexTo4BinZero().IndexOf(da1.Equals("00") ? "0" : "1"));
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算Fn
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dt1"></param>
|
||||||
|
/// <param name="dt2"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region 上行命令
|
#region 上行命令
|
||||||
|
|
||||||
//68
|
//68
|
||||||
|
|||||||
@ -52,337 +52,6 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts
|
|||||||
|
|
||||||
public abstract Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null) where T : class;
|
public abstract Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null) where T : class;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析376.1帧
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messageReceived"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual TB3761? Analysis3761(string messageReceived)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var hexStringList = messageReceived.StringToPairs();
|
|
||||||
// 初步校验
|
|
||||||
if (hexStringList.Count < 6 || hexStringList.FirstOrDefault() != "68" || hexStringList.Skip(5).Take(1).FirstOrDefault() != "68" || hexStringList.Count < 18 || hexStringList.LastOrDefault() != "16")
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis3761校验不通过,报文:{messageReceived}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TB3761 tB3761 = new TB3761
|
|
||||||
{
|
|
||||||
BaseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageString = messageReceived,
|
|
||||||
HexMessageList = hexStringList
|
|
||||||
},
|
|
||||||
C = Analysis_C(hexStringList),
|
|
||||||
A = Analysis_A(hexStringList),
|
|
||||||
AFN_FC = Analysis_AFN_FC(hexStringList),
|
|
||||||
SEQ = Analysis_SEQ(hexStringList),
|
|
||||||
UnitData = Analysis_UnitData(hexStringList),
|
|
||||||
DA = Analysis_DA(hexStringList),
|
|
||||||
DT = Analysis_DT(hexStringList)
|
|
||||||
};
|
|
||||||
return tB3761;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis3761错误,报文:{messageReceived},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 控制域C解析
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual C Analysis_C(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
C c = new C();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count > 6)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(6, 1) // 控制域 1字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
if (baseHexMessage.HexMessageList.Count == 0)
|
|
||||||
return null;
|
|
||||||
string binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
|
||||||
c = new C
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
FC = binStr.Substring(binStr.Length - 4, 4).BinToDec(),
|
|
||||||
FCV = binStr.Substring(3, 1).BinToDec(),
|
|
||||||
FCB = binStr.Substring(2, 1).BinToDec(),
|
|
||||||
PRM = binStr.Substring(1, 1).BinToDec(),
|
|
||||||
DIR = binStr.Substring(0, 1).BinToDec()
|
|
||||||
};
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_C错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 地址域A解析
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hexStringList"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual A Analysis_A(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
A a = new A();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count > 7)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(7, 5) // 地址域 5个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
a = new A
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
A1 = baseHexMessage.HexMessageList.ListReverseToStr(0, 2),//.DataConvert(10);//行政区划码A1
|
|
||||||
A2 = baseHexMessage.HexMessageList.ListReverseToStr(2, 2).PadLeft(5, '0').HexToDec(),//终端地址A2
|
|
||||||
A3 = Analysis_A3(baseHexMessage.HexMessageList) //主站地址和组地址标志A3
|
|
||||||
};
|
|
||||||
a.Code = $"{a.A1.PadLeft(4, '0')}{a.A2.ToString()!.PadLeft(5, '0')}";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_A错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return a;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 站地址和组地址标志A3
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hexAList">地址域A集合</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual A3 Analysis_A3(List<string> hexAList)
|
|
||||||
{
|
|
||||||
A3 a3 = new A3();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexAList.Count != 0)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexAList.GetRange(4, 1) // 站地址和组地址标志A3 1个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
var binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
|
||||||
a3 = new A3
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
D0 = binStr.Substring(binStr.Length - 1, 1).BinToDec(),
|
|
||||||
D1_D7 = binStr.Substring(0, binStr.Length - 1).BinToDec()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_A3错误,报文:{string.Join("", hexAList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return a3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AFN_FC功能码
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual AFN_FC Analysis_AFN_FC(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
AFN_FC aFN_FC = new AFN_FC();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(12, 1) //AFN功能码 1个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
|
|
||||||
aFN_FC = new AFN_FC
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
AFN = baseHexMessage.HexMessageString.HexToDec(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_AFN_FC错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return aFN_FC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析帧序列域SEQ
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual SEQ Analysis_SEQ(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
SEQ seq = new SEQ();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count != 0)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(13, 1) //帧序列域 SEQ 1个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
var binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
|
||||||
seq = new SEQ
|
|
||||||
{
|
|
||||||
PSEQ = binStr.Substring(binStr.Length - 4, 4).BinToDec(),
|
|
||||||
CON = binStr.Substring(3, 1).BinToDec(),
|
|
||||||
FIN = binStr.Substring(2, 1).BinToDec(),
|
|
||||||
FIR = binStr.Substring(1, 1).BinToDec(),
|
|
||||||
TpV = binStr.Substring(0, 1).BinToDec()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_SEQ错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
return seq;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 数据单元标识及数据单元数据
|
|
||||||
/// </summary>
|
|
||||||
public virtual UnitData Analysis_UnitData(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
UnitData unitData = new UnitData();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count != 0)
|
|
||||||
{
|
|
||||||
unitData = new UnitData
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(14, hexStringList.Count - 14 - 2) //总数字节数-固定长度报文头-控制域C-地址域A-校验和CS-结束字符(16H)
|
|
||||||
};
|
|
||||||
unitData.HexMessageString = string.Join("", unitData.HexMessageList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_UnitData错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
return unitData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 信息点DA Pn
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual DA Analysis_DA(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
DA da = new DA();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count != 0)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(14, 2) //信息点DA Pn 2个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
var da1 = baseHexMessage.HexMessageList[0];
|
|
||||||
var da2 = baseHexMessage.HexMessageList[1];
|
|
||||||
da = new DA()
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
Pn = CalculatePn(da1, da2)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_DA错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
return da;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 信息类DT Fn
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public virtual DT Analysis_DT(List<string> hexStringList)
|
|
||||||
{
|
|
||||||
DT dt = new DT();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (hexStringList.Count != 0)
|
|
||||||
{
|
|
||||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
|
||||||
{
|
|
||||||
HexMessageList = hexStringList.GetRange(16, 2) //信息类DT Fn 2个字节
|
|
||||||
};
|
|
||||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
|
||||||
var dt1 = baseHexMessage.HexMessageList[0];
|
|
||||||
var dt2 = baseHexMessage.HexMessageList[1];
|
|
||||||
dt = new DT()
|
|
||||||
{
|
|
||||||
BaseHexMessage = baseHexMessage,
|
|
||||||
Fn = CalculateFn(dt1, dt2)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"解析Analysis_DT错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return dt;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 计算Pn
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="da1"></param>
|
|
||||||
/// <param name="da2"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static int CalculatePn(string da1, string da2) => (da2.HexToDec() - 1) * 8 + (8 - da1.HexTo4BinZero().IndexOf(da1.Equals("00") ? "0" : "1"));
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 计算Fn
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dt1"></param>
|
|
||||||
/// <param name="dt2"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1"));
|
|
||||||
|
|
||||||
#region 下行命令构建
|
#region 下行命令构建
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ namespace JiShe.CollectBus.Common.Consts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataFieldConst
|
public class DataFieldConst
|
||||||
{
|
{
|
||||||
public const string ZYGDN = "ZYGDN";
|
public const string ZYGDN = "ZYGDN";
|
||||||
public const string ZWGDN = "ZWGDN";
|
public const string ZWGDN = "ZWGDN";
|
||||||
public const string FYGDN = "FYGDN";
|
public const string FYGDN = "FYGDN";
|
||||||
public const string FWGDN = "FWGDN";
|
public const string FWGDN = "FWGDN";
|
||||||
@ -116,4 +117,64 @@ namespace JiShe.CollectBus.Common.Consts
|
|||||||
public const string Ic = "0C_49_Ic"; // 当前电压、电流相位角
|
public const string Ic = "0C_49_Ic"; // 当前电压、电流相位角
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class DataFieldHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据字段映射
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<string, string> DataFieldDic = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建数据字段映射
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Dictionary<string, string> CreateDataFieldMapping()
|
||||||
|
{
|
||||||
|
if (DataFieldDic.Count > 0)
|
||||||
|
return DataFieldDic;
|
||||||
|
var dataFieldMapping = new Dictionary<string, string>();
|
||||||
|
Type dataType = typeof(ConstGatherDataType);
|
||||||
|
Type fieldType = typeof(DataFieldConst);
|
||||||
|
|
||||||
|
foreach (FieldInfo gatherField in dataType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy))
|
||||||
|
{
|
||||||
|
if (gatherField.IsLiteral && !gatherField.IsInitOnly)
|
||||||
|
{
|
||||||
|
// 获取ConstGatherDataType的字段值作为key
|
||||||
|
string key = (string)gatherField.GetValue(null)!;
|
||||||
|
|
||||||
|
// 查找DataFieldConst中同名字段
|
||||||
|
FieldInfo dataField = fieldType.GetField(gatherField.Name,
|
||||||
|
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)!;
|
||||||
|
|
||||||
|
if (dataField != null)
|
||||||
|
{
|
||||||
|
string value = (string)dataField.GetValue(null)!;
|
||||||
|
dataFieldMapping[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataFieldMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据采集数据类型获取数据字段
|
||||||
|
/// 返回null表示 无效字段
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="docDataType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string? GetDataFieldByGatherDataType(this string gatherDataType)
|
||||||
|
{
|
||||||
|
if (CreateDataFieldMapping().TryGetValue(gatherDataType, out string? column))
|
||||||
|
{
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -832,5 +832,7 @@ namespace JiShe.CollectBus.Common.Helpers
|
|||||||
return arr.Contains(weekName);
|
return arr.Contains(weekName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user