From cc35ad2664a6a8cb4f3093cdaf2a687619967179 Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Thu, 24 Apr 2025 19:31:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=A5=E6=96=87?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Abstracts/ProtocolPlugin.cs | 215 +++++++++--------- .../Models/TB3761.cs | 16 +- .../Protocol/Dto/AFN0_F1_AnalysisDto.cs | 13 -- .../Protocol/Dto/AFN10_F10_AnalysisDto.cs | 95 ++++++++ .../Protocol/Dto/AFN10_F66_AnalysisDto.cs | 45 ++++ .../Protocol/Dto/AFN12_F129_AnalysisDto.cs | 13 ++ .../Protocol/Dto/AFN12_F130_AnalysisDto.cs | 13 ++ .../Protocol/Dto/AFN12_F131_AnalysisDto.cs | 13 ++ .../Protocol/Dto/AFN12_F132_AnalysisDto.cs | 13 ++ .../Protocol/Dto/AFN12_F145_AnalysisDto.cs | 19 ++ .../Protocol/Dto/AFN12_F149_AnalysisDto.cs | 18 ++ .../Protocol/Dto/AFN12_F188_AnalysisDto.cs | 12 + .../Protocol/Dto/AFN12_F25_AnalysisDto.cs | 16 ++ .../Protocol/Dto/AFN12_F2_AnalysisDto.cs | 12 + .../Protocol/Dto/AFN12_F33_AnalysisDto.cs | 55 +++++ .../Protocol/Dto/AFN12_F49_AnalysisDto.cs | 15 ++ .../Protocol/Dto/AFN9_F1_AnalysisDto.cs | 38 ++++ .../Protocol/Dto/AnalysisBaseDto.cs | 46 ++++ .../{UnitDataDto.cs => UnitDataAnalysis.cs} | 30 +-- .../AnalysisData/AFN_00H/AFN0_F1_Analysis.cs | 22 +- .../AnalysisData/AFN_00H/AFN0_F2_Analysis.cs | 47 ++++ .../AnalysisData/AFN_09H/AFN9_F1_Analysis.cs | 74 ++++++ .../AnalysisData/AFN_09H/AFN9_F9_Analysis.cs | 51 +++++ .../AFN_0AH/AFN10_F10_Analysis.cs | 165 ++++++++++++++ .../AFN_0AH/AFN10_F66_Analysis.cs | 84 +++++++ .../AFN_0AH/AFN10_F68_Analysis.cs | 49 ++++ .../AFN_0CH/AFN12_F129_Analysis.cs | 103 +++++++++ .../AFN_0CH/AFN12_F130_Analysis.cs | 94 ++++++++ .../AFN_0CH/AFN12_F131_Analysis.cs | 94 ++++++++ .../AFN_0CH/AFN12_F132_Analysis.cs | 95 ++++++++ .../AFN_0CH/AFN12_F145_Analysis.cs | 108 +++++++++ .../AFN_0CH/AFN12_F149_Analysis.cs | 120 ++++++++++ .../AFN_0CH/AFN12_F188_Analysis.cs | 73 ++++++ .../AFN_0CH/AFN12_F25_Analysis.cs | 120 ++++++++++ .../AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs | 72 ++++++ .../AFN_0CH/AFN12_F33_Analysis.cs | 124 ++++++++++ .../AFN_0CH/AFN12_F49_Analysis.cs | 95 ++++++++ .../Appendix/Appendix_02800002.cs | 40 ++++ .../Appendix/Appendix_04000201.cs | 33 +++ .../Appendix/Appendix_04000202.cs | 28 +++ .../Appendix/Appendix_04000203.cs | 28 +++ .../Appendix/Appendix_04000204.cs | 28 +++ .../Appendix/Appendix_04010000.cs | 38 ++++ .../Appendix/Appendix_04010001.cs | 28 +++ .../Appendix/Appendix_04010002.cs | 28 +++ .../Appendix/Appendix_04010003.cs | 28 +++ .../Appendix/Appendix_04010004.cs | 30 +++ .../Appendix/Appendix_04010005.cs | 28 +++ .../Appendix/Appendix_04010006.cs | 28 +++ .../Appendix/Appendix_04010007.cs | 27 +++ .../Appendix/Appendix_04010008.cs | 28 +++ .../Appendix/Appendix_A1.cs | 33 +++ .../Appendix/Appendix_A11.cs | 57 +++++ .../Appendix/Appendix_A13.cs | 56 +++++ .../Appendix/Appendix_A14.cs | 57 +++++ .../Appendix/Appendix_A15.cs | 24 ++ .../Appendix/Appendix_A17.cs | 16 ++ .../Appendix/Appendix_A23.cs | 50 ++++ .../Appendix/Appendix_A25.cs | 33 +++ .../Appendix/Appendix_A5.cs | 27 +++ .../Appendix/Appendix_A7.cs | 27 +++ .../Appendix/Appendix_A9.cs | 36 +++ .../Protocol3761Extensions.cs | 129 +++++++++++ .../StandardProtocolPlugin.cs | 12 +- .../Plugins/TcpMonitor.cs | 4 +- .../Subscribers/SubscriberAppService.cs | 8 +- .../Extensions/StringExtensions.cs | 32 +++ 67 files changed, 3139 insertions(+), 169 deletions(-) delete mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN0_F1_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F10_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F66_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F129_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F130_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F131_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F132_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F145_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F149_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F188_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F25_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F2_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F33_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F49_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN9_F1_AnalysisDto.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AnalysisBaseDto.cs rename protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/{UnitDataDto.cs => UnitDataAnalysis.cs} (52%) create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_02800002.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000201.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000202.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000203.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000204.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010000.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010001.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010002.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010003.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010004.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010005.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010006.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010007.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010008.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A1.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A11.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A13.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A14.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A15.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A17.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A23.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A25.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A5.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A7.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A9.cs create mode 100644 protocols/JiShe.CollectBus.Protocol/Protocol3761Extensions.cs diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Abstracts/ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Abstracts/ProtocolPlugin.cs index 16b9401..fafef64 100644 --- a/protocols/JiShe.CollectBus.Protocol.Contracts/Abstracts/ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Abstracts/ProtocolPlugin.cs @@ -93,8 +93,9 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// 控制域C解析 /// /// - public virtual C? Analysis_C(List hexStringList) + public virtual C Analysis_C(List hexStringList) { + C c = new C(); try { if (hexStringList.Count > 6) @@ -107,7 +108,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts if (baseHexMessage.HexMessageList.Count == 0) return null; string binStr = baseHexMessage.HexMessageString.HexTo4BinZero(); - C c = new C + c = new C { BaseHexMessage = baseHexMessage, FC = binStr.Substring(binStr.Length - 4, 4).BinToDec(), @@ -124,7 +125,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts _logger.LogError($"解析Analysis_C错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}"); } - return null; + return c; } /// @@ -132,8 +133,9 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// /// /// - public virtual A? Analysis_A(List hexStringList) + public virtual A Analysis_A(List hexStringList) { + A a = new A(); try { if (hexStringList.Count > 7) @@ -143,17 +145,15 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts HexMessageList = hexStringList.GetRange(7, 5) // 地址域 5个字节 }; baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - A a = new A + 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')}"; - return a; + a.Code = $"{a.A1.PadLeft(4, '0')}{a.A2.ToString()!.PadLeft(5, '0')}"; + } } catch (Exception ex) @@ -161,7 +161,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts _logger.LogError($"解析Analysis_A错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}"); } - return null; + return a; } @@ -170,185 +170,192 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// /// 地址域A集合 /// - public virtual A3? Analysis_A3(List hexAList) + public virtual A3 Analysis_A3(List hexAList) { + A3 a3 = new A3(); try { - BaseHexMessage baseHexMessage = new BaseHexMessage + if (hexAList.Count != 0) { - HexMessageList = hexAList.GetRange(4, 1) // 站地址和组地址标志A3 1个字节 - }; - baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - var binStr = baseHexMessage.HexMessageString.HexTo4BinZero(); - A3 a3 = new A3 - { - BaseHexMessage = baseHexMessage, - D0 = binStr.Substring(binStr.Length - 1, 1).BinToDec(), - D1_D7 = binStr.Substring(0, binStr.Length - 1).BinToDec() - }; - return a3; + 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 null; + return a3; } /// /// AFN_FC功能码 /// /// - public virtual AFN_FC? Analysis_AFN_FC(List hexStringList) + public virtual AFN_FC Analysis_AFN_FC(List hexStringList) { + AFN_FC aFN_FC = new AFN_FC(); try { - BaseHexMessage baseHexMessage = new BaseHexMessage + if (hexStringList.Count == 0) { - HexMessageList = hexStringList.GetRange(12, 1) //AFN功能码 1个字节 - }; - baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - AFN_FC aFN_FC = new AFN_FC - { - BaseHexMessage = baseHexMessage, - AFN = baseHexMessage.HexMessageString.HexToDec(), - }; - return aFN_FC; + + 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 null; + return aFN_FC; } /// /// 解析帧序列域SEQ /// /// - public virtual SEQ? Analysis_SEQ(List hexStringList) + public virtual SEQ Analysis_SEQ(List hexStringList) { + SEQ seq = new SEQ(); try { - BaseHexMessage baseHexMessage = new BaseHexMessage + if (hexStringList.Count != 0) { - HexMessageList = hexStringList.GetRange(13, 1) //帧序列域 SEQ 1个字节 - }; - baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - var binStr = baseHexMessage.HexMessageString.HexTo4BinZero(); - SEQ 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() - }; - return seq; + 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 null; + return seq; } /// /// 数据单元标识及数据单元数据 /// - public virtual UnitData? Analysis_UnitData(List hexStringList) + public virtual UnitData Analysis_UnitData(List hexStringList) { + UnitData unitData = new UnitData(); try { - - UnitData unitData = new UnitData + if (hexStringList.Count != 0) { - HexMessageList = hexStringList.GetRange(14, hexStringList.Count - 14 - 2) //总数字节数-固定长度报文头-控制域C-地址域A-校验和CS-结束字符(16H) - }; - unitData.HexMessageString = string.Join("", unitData.HexMessageList); - if (unitData.HexMessageList.Count == 0) - return null; - return unitData; + 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 null; + return unitData; } /// /// 信息点DA Pn /// /// - public virtual DA? Analysis_DA(List hexStringList) + public virtual DA Analysis_DA(List hexStringList) { + DA da = new DA(); try { - BaseHexMessage baseHexMessage = new BaseHexMessage + if (hexStringList.Count != 0) { - HexMessageList = hexStringList.GetRange(14, 2) //信息点DA Pn 2个字节 - }; - baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - var da1 = baseHexMessage.HexMessageList[0]; - var da2 = baseHexMessage.HexMessageList[1]; - DA da = new DA() - { - BaseHexMessage = baseHexMessage, - Pn = CalculatePn(da1, da2) - }; - return da; - + 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 null; + return da; } /// /// 信息类DT Fn /// /// - public virtual DT? Analysis_DT(List hexStringList) + public virtual DT Analysis_DT(List hexStringList) { + DT dt = new DT(); try { - BaseHexMessage baseHexMessage = new BaseHexMessage + if (hexStringList.Count != 0) { - HexMessageList = hexStringList.GetRange(16, 2) //信息类DT Fn 2个字节 - }; - baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList); - if (baseHexMessage.HexMessageList.Count == 0) - return null; - var dt1 = baseHexMessage.HexMessageList[0]; - var dt2 = baseHexMessage.HexMessageList[1]; - DT dt = new DT() - { - BaseHexMessage = baseHexMessage, - Fn = CalculateFn(dt1, dt2) - }; - return dt; - + 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 null; + return dt; } @@ -359,7 +366,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// /// /// - public int CalculatePn(string da1, string da2) => (da2.HexToDec() - 1) * 8 + (8 - da1.HexTo4BinZero().IndexOf(da1.Equals("00") ? "0" : "1")); + public static int CalculatePn(string da1, string da2) => (da2.HexToDec() - 1) * 8 + (8 - da1.HexTo4BinZero().IndexOf(da1.Equals("00") ? "0" : "1")); /// @@ -368,7 +375,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// /// /// - public int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1")); + public static int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1")); } } diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/TB3761.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/TB3761.cs index a24090a..75727d2 100644 --- a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/TB3761.cs +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/TB3761.cs @@ -15,45 +15,45 @@ namespace JiShe.CollectBus.Protocol.Contracts.Models /// /// 报文 /// - public BaseHexMessage? BaseHexMessage { get; set;} + public BaseHexMessage BaseHexMessage { get; set;}=new BaseHexMessage(); /// /// 控制域C /// - public C? C { get; set; } + public C C { get; set; } = new C(); /// /// 地址域A /// - public A? A { get; set; } + public A A { get; set; } = new A(); /// /// 帧序列域 SEQ /// - public SEQ? SEQ { get; set; } + public SEQ SEQ { get; set; } = new SEQ(); /// /// 用户数据区 /// 功能码 /// - public AFN_FC? AFN_FC { get; set; } + public AFN_FC AFN_FC { get; set; } = new AFN_FC(); /// /// 用户数据区 /// 信息点DA Pn /// - public DA? DA { get; set; } + public DA DA { get; set; } = new DA(); /// /// 用户数据区 /// 信息类DT Fn /// - public DT? DT { get; set; } + public DT DT { get; set; } = new DT(); /// /// 数据单元标识和数据单元格式 /// - public UnitData? UnitData { get; set; } + public UnitData UnitData { get; set; } = new UnitData(); } #region diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN0_F1_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN0_F1_AnalysisDto.cs deleted file mode 100644 index ede07c1..0000000 --- a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN0_F1_AnalysisDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace JiShe.CollectBus.Protocol.Dto -{ - public class AFN0_F1_AnalysisDto: UnitDataDto - { - public bool Verify { get; set; } = true; - } -} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F10_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F10_AnalysisDto.cs new file mode 100644 index 0000000..46b7581 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F10_AnalysisDto.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Protocol.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN10_F10_AnalysisDto + { + /// + /// 本次电能表/交流采样装置配置数量 n + /// + public int ConfigNum { get; set; } + + /// + /// 电能表/交流采样装置配置信息 + /// + public List AFN10F10Entitys { get; set; } = new List(); + } + + + public class AFN10F10Entity + { + /// + /// 电能表/交流采样装置序号 + /// + public int SerialNum { get; set; } + + /// + /// 所属测量点号 + /// + public int Point { get; set; } + + /// + /// 通信速率 + /// + public int BaudRate { get; set; } + + /// + /// 端口号 + /// + public int Port { get; set; } + + + /// + /// 通信协议类型 + /// + public string RuleType { get; set; } + + /// + /// 通信地址 + /// + public string ComAddress { get; set; } + + /// + /// 通信密码 + /// + public string ComPwd { get; set; } + + + /// + /// 电能费率个数 + /// + public int ElectricityRatesNum { get; set; } + + + /// + /// 有功电能示值整数位及小数位个数 + /// + public int IntegerBitsNum { get; set; } + + /// + /// 有功电能示值小数位个数 + /// + public int DecimalPlacesNum { get; set; } + + /// + /// 所属采集器通信地址 + /// + public string CollectorAddress{ get; set; } + + /// + /// 用户大类号 + /// + public int UserCategoryNum { get; set;} + + /// + /// 用户小类号 + /// + public int UserSubclassNum { get; set; } + } + +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F66_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F66_AnalysisDto.cs new file mode 100644 index 0000000..c3c8306 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN10_F66_AnalysisDto.cs @@ -0,0 +1,45 @@ +using JiShe.CollectBus.Protocol.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN10_F66_AnalysisDto + { + /// + /// 定时发送周期 + /// 1:用 D6~D7 编码表示,取值 0~3 依次表示分、时、日、月 + /// 2:用 D0~D5 表示,为定时上报数据的时间周期 + /// + public int Cycle { get; set; } + /// + /// 定时发送周期(单位) + /// + public int Unit { get; set; } + /// + /// 发送基准时间 + /// + public DateTime BaseTime { get; set; } + + /// + /// 曲线数据提取倍率 + /// + public int CurveRatio { get; set; } + + /// + /// 任务号 + /// + public int Pn { get; set; } + + public List Details { get; set; } = new List(); + } + + public class SetAutoItemCodeDetails + { + public int Pn { get; set; } + public int Fn { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F129_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F129_AnalysisDto.cs new file mode 100644 index 0000000..30719e9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F129_AnalysisDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F129_AnalysisDto : AnalysisBaseDto + { + public DateTime ReadTime { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F130_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F130_AnalysisDto.cs new file mode 100644 index 0000000..9a9259b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F130_AnalysisDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F130_AnalysisDto : AnalysisBaseDto + { + public DateTime ReadTime { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F131_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F131_AnalysisDto.cs new file mode 100644 index 0000000..edc5ca7 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F131_AnalysisDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F131_AnalysisDto: AnalysisBaseDto + { + public DateTime ReadTime { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F132_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F132_AnalysisDto.cs new file mode 100644 index 0000000..1625f15 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F132_AnalysisDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F132_AnalysisDto: AnalysisBaseDto + { + public DateTime ReadTime { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F145_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F145_AnalysisDto.cs new file mode 100644 index 0000000..96f0c37 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F145_AnalysisDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F145_AnalysisDto : AnalysisBaseDto + { + /// + /// 最大需量时标 + /// + public string TimeSpan { get; set; } + + public DateTime ReadingDate { get; set; } + } + +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F149_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F149_AnalysisDto.cs new file mode 100644 index 0000000..fb9dafe --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F149_AnalysisDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F149_AnalysisDto : AnalysisBaseDto + { + /// + /// 最大需量时标 + /// + public string TimeSpan { get; set; } + + public DateTime ReadingDate { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F188_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F188_AnalysisDto.cs new file mode 100644 index 0000000..1afb8ff --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F188_AnalysisDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F188_AnalysisDto : AnalysisBaseDto + { + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F25_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F25_AnalysisDto.cs new file mode 100644 index 0000000..ca8b8ff --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F25_AnalysisDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F25_AnalysisDto: AnalysisBaseDto + { + /// + /// 读取时间 + /// + public DateTime ReadTime { get; set; } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F2_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F2_AnalysisDto.cs new file mode 100644 index 0000000..e069382 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F2_AnalysisDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F2_AnalysisDto: AnalysisBaseDto + { + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F33_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F33_AnalysisDto.cs new file mode 100644 index 0000000..b917969 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F33_AnalysisDto.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F33_AnalysisDto + { + /// + /// 终端抄表时间 + /// + public string ReadTime { get; set; } + + /// + /// 费率数M(1≤M≤12) + /// + public int RatingCount { get; set; } + /// + /// 当前正向有功总电能示值 + /// + public ParentNodes F_A_Kwh { get; set; } + /// + /// 当前正向无功(组合无功1)总电能示值 + /// + public ParentNodes R_R_Kvarh { get; set; } + + /// + /// 当前一象限无功总电能示值 + /// + public ParentNodes Q1_R_Kvarh { get; set; } + /// + /// 当前四象限无功总电能示值 + /// + public ParentNodes Q4_R_Kvarh { get; set; } + } + + public class ParentNodes + { + /// + /// 总电能示值 + /// + public decimal Total_Value { get; set; } + public List childNodes { get; set; } + } + public class ChildNodes + { + /// + /// 费率总电能示值 + /// + public decimal Value { get; set; } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F49_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F49_AnalysisDto.cs new file mode 100644 index 0000000..ce0aeb7 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN12_F49_AnalysisDto.cs @@ -0,0 +1,15 @@ +using JiShe.CollectBus.Protocol.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN12_F49_AnalysisDto: AnalysisBaseDto + { + } + + +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN9_F1_AnalysisDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN9_F1_AnalysisDto.cs new file mode 100644 index 0000000..7b7bc3a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AFN9_F1_AnalysisDto.cs @@ -0,0 +1,38 @@ +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AFN9_F1_AnalysisDto + { + public int FocusID { get; set; } + public string? AreaCode { get; set; } + public string? Address { get; set; } + + /// + /// 厂商代号 + /// + public string? MakerNo { get; set; } + /// + /// 设备编号 + /// + public string? DeviceNo { get; set; } + /// + /// 终端软件版本号 + /// + public string? SoftwareVersion { get; set; } + /// + /// 终端软件发布日期:日月年 + /// + public string? SoftwareReleaseDate { get; set; } + + /// + /// 硬件软件版本号 + /// + public string? HardwareVersion { get; set; } + /// + /// 硬件软件发布日期:日月年 + /// + public string? HardwareReleaseDate { get; set; } + + public string? AddDate { get; set; } + } + +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AnalysisBaseDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AnalysisBaseDto.cs new file mode 100644 index 0000000..49f9054 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/AnalysisBaseDto.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto +{ + public class AnalysisBaseDto + { + + /// + /// 是否有效数据 + /// + public bool ValidData { get; set; } = true; + + /// + /// 数据类型 + /// + public string DataType { get; set; } + + /// + /// 错误码信息 + /// + public string ErrorCodeMsg { get; set; } + + /// + /// 字段名 + /// + public string FiledName { get; set; } + + /// + /// 字段描述 + /// + public string FiledDesc { get; set; } + } + + public class AnalysisBaseDto : AnalysisBaseDto + { + /// + /// 抄读值 + /// + public T? DataValue { get; set; } + } + +} diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataDto.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataAnalysis.cs similarity index 52% rename from protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataDto.cs rename to protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataAnalysis.cs index cd59203..3a03923 100644 --- a/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataDto.cs +++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Protocol/Dto/UnitDataAnalysis.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace JiShe.CollectBus.Protocol.Dto +namespace JiShe.CollectBus.Protocol.Dto { - public class UnitDataDto + public class UnitDataAnalysis { /// /// 集中器地址 @@ -28,15 +22,15 @@ namespace JiShe.CollectBus.Protocol.Dto /// public int Fn { get; set; } - /// - /// 数据时标(最近数据时间点的时间),如:8:00 08:15 记录08:15 - /// - public string? DataTime { get; set; } - - /// - /// 密度(分) - /// - public int TimeDensity { get; set; } + } - + + public class UnitDataAnalysis: UnitDataAnalysis + { + /// + /// 数据 + /// + public T? Data { get; set; } + } + } diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs index 3ff0882..408c038 100644 --- a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs @@ -13,9 +13,9 @@ using System.Threading.Tasks; namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H { /// - /// 全部确认:对收到报文中的全部数据单元标识进行确认 + /// 5.1.3.1 F1:全部确认:对收到报文中的全部数据单元标识进行确认 /// - public class AFN0_F1_Analysis: IAnalysisStrategy + public class AFN0_F1_Analysis: IAnalysisStrategy> { private readonly ILogger _logger; @@ -23,24 +23,24 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H { _logger = logger; } - - public Task ExecuteAsync(TB3761 tB3761) + public Task> ExecuteAsync(TB3761 input) { try { - ArgumentNullException.ThrowIfNull(nameof(tB3761)); - AFN0_F1_AnalysisDto dto = new AFN0_F1_AnalysisDto + ArgumentNullException.ThrowIfNull(input); + UnitDataAnalysis dto = new UnitDataAnalysis { - Code = tB3761.A?.Code, - AFN = tB3761.AFN_FC?.AFN ?? 0, - Fn = tB3761.DT?.Fn ?? 0, - Pn = tB3761.DA?.Pn ?? 0 + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn , + Data = true, }; return Task.FromResult(dto); } catch (Exception ex) { - _logger.LogError(ex, $"00_1解析失败:{tB3761.A?.Code}-{tB3761.DT?.Fn ?? 0}-{tB3761?.BaseHexMessage?.HexMessageString},{ex.Message}"); + _logger.LogError(ex, $"00_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); return null; } } diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs new file mode 100644 index 0000000..2801a3c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs @@ -0,0 +1,47 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H +{ + /// + /// 5.1.3.2 F2:全部否认 + /// + public class AFN0_F2_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN0_F2_Analysis(ILogger logger) + { + _logger = logger; + } + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = false, + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"00_2解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs new file mode 100644 index 0000000..2e76ae5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs @@ -0,0 +1,74 @@ +using DeviceDetectorNET.Class; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.AFN_00H; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TouchSocket.Core; +using YamlDotNet.Core; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H +{ + /// + /// 5.9.1.2 F1:终端版本信息 + /// + public class AFN9_F1_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN9_F1_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + var data = AnalysisDataUnit(input.UnitData.HexMessageList); + data.AreaCode = input.A.Code?.Substring(0, 4); + data.Address = input.A.Code?.Substring(4, 5); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data= data + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"09_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + private AFN9_F1_AnalysisDto AnalysisDataUnit(List hexMessageList) + { + AFN9_F1_AnalysisDto version = new AFN9_F1_AnalysisDto(); + version.MakerNo = Encoding.ASCII.GetString(string.Join("", hexMessageList.Skip(4).Take(4).ToList()).HexToByte());//厂商代号 + version.DeviceNo = Encoding.ASCII.GetString(string.Join("", hexMessageList.Skip(8).Take(8).ToList()).HexToByte()).Replace("\0", "");//设备编号 + version.SoftwareVersion = Encoding.ASCII.GetString(string.Join("", hexMessageList.Skip(16).Take(4).ToList()).HexToByte());//终端软件版本号 + version.HardwareVersion = Encoding.ASCII.GetString(string.Join("", hexMessageList.Skip(38).Take(4).ToList()).HexToByte());//终端硬件版本号 + version.AddDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var dateArr = hexMessageList.Skip(20).Take(3).ToList(); + var dateArr2 = hexMessageList.Skip(42).Take(3).ToList(); + dateArr.Reverse(); + dateArr2.Reverse(); + version.SoftwareReleaseDate = $"{DateTime.Now.Year.ToString().Substring(0, 2)}{string.Join("-", dateArr)}";//终端软件发布日期:日月年 + version.HardwareReleaseDate = $"{DateTime.Now.Year.ToString().Substring(0, 2)}{string.Join("-", dateArr2)}";//终端硬件发布日期:日月年 + return version; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs new file mode 100644 index 0000000..fefe177 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs @@ -0,0 +1,51 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.AFN_00H; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H +{ + /// + /// 5.9.2.4.9 F9:远程通信模块版本信息(只读解析SIM卡号) + /// + public class AFN9_F9_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN9_F9_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = Encoding.ASCII.GetString(string.Join("", input.UnitData.HexMessageList.Skip(30).Take(20).ToList()).HexToByte()).Replace("\0", "") //SIM卡 + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"00_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs new file mode 100644 index 0000000..9f2e384 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs @@ -0,0 +1,165 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +{ + /// + /// 5.10.1.3.1 F10:终端电能表/交流采样装置配置参数 + /// + internal class AFN10_F10_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN10_F10_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + Tuple> tuple = AFN10F10EntityAnalysis(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data=new AFN10_F10_AnalysisDto() + { + AFN10F10Entitys = tuple.Item2, + ConfigNum = tuple.Item1 + } + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0A_10解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + + + public Tuple> AFN10F10EntityAnalysis(List hexMessageList) + { + List> meterList = new List>(); + int total = $"{hexMessageList[5]}{hexMessageList[4]}".HexToDec(); + List aFN10F10Entitys = new List(); + for (int i = 0; i < total; i++) + { + List sArray = hexMessageList.GetRange(6 + 27 * i, 27); + AFN10F10Entity aFN10F10Entity = new AFN10F10Entity() + { + SerialNum = $"{sArray[1]}{sArray[0]}".HexToDec(), + Point = $"{sArray[3]}{sArray[2]}".HexToDec(), + RuleType= GetProtocol(sArray[5]), + ComAddress= $"{sArray[11]}{sArray[10]}{sArray[9]}{sArray[8]}{sArray[7]}{sArray[6]}", + ComPwd= $"{sArray[17]}{sArray[16]}{sArray[15]}{sArray[14]}{sArray[13]}{sArray[12]}".Substring(6, 6), + ElectricityRatesNum= sArray[18].HexToBin().Substring(2, 6).BinToDec(), + CollectorAddress = $"{sArray[25]}{sArray[24]}{sArray[23]}{sArray[22]}{sArray[21]}{sArray[20]}", + + }; + + string baudPort = sArray[4].HexToBin().PadLeft(8, '0'); //波特率和端口号放在一个字节内 + aFN10F10Entity.BaudRate = GetBaudrate(baudPort.Substring(0, 3)); + aFN10F10Entity.Port = baudPort.Substring(3, 5).BinToDec(); + + string dataDigit = sArray[19].HexToBin().PadLeft(8, '0'); //有功电能示值整数位及小数位个数 + aFN10F10Entity.IntegerBitsNum = dataDigit.Substring(4, 2).BinToDec() + 4; + aFN10F10Entity.DecimalPlacesNum = dataDigit.Substring(6, 2).BinToDec() + 1; + + string classNo = sArray[26].HexToBin().PadLeft(8, '0');//用户大类号及用户小类号 + aFN10F10Entity.UserCategoryNum = classNo.Substring(0, 4).BinToDec() + 1; + aFN10F10Entity.UserCategoryNum = classNo.Substring(4, 4).BinToDec() + 1; + aFN10F10Entitys.Add(aFN10F10Entity); + } + return Tuple.Create(total, aFN10F10Entitys); + } + + /// + /// 获取波特率 + /// + /// + /// + private int GetBaudrate(string binBaud) + { + int baudRate = 0; + switch (binBaud) + { + case "001": + baudRate = 600; + break; + case "010": + baudRate = 1200; + break; + case "011": + baudRate = 2400; + break; + case "100": + baudRate = 4800; + break; + case "101": + baudRate = 7200; + break; + case "110": + baudRate = 9600; + break; + case "111": + baudRate = 19200; + break; + default: + baudRate = 0; + break; + } + return baudRate; + } + + /// + /// 获取通信协议文本说明 + /// + /// + /// + private string GetProtocol(string protocol) + { + int dataUnit = protocol.HexToDec(); + + if (dataUnit == 1) + { + return "DL/T 645—1997"; + } + if (dataUnit == 2) + { + return "交流采样装置通信协议"; + } + if (dataUnit == 30) + { + return "DL/T 645—2007"; + } + if (dataUnit == 31) + { + return "串行接口连接窄带低压载波通信模块"; + } + if (dataUnit == 32) + { + return "CJ/T 188—2018协议"; + } + return "其他协议"; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs new file mode 100644 index 0000000..ce2cf12 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs @@ -0,0 +1,84 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Abstracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +{ + /// + /// 5.5.1.3.53 F66:定时上报 2 类数据任务设置 + /// + public class AFN10_F66_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN10_F66_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext= analysisStrategyContext; + } + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + var data = await GenerateFinalResult(input.UnitData.HexMessageList); + data.Pn = input.DA.Pn; + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data= data + }; + return await Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0A_66解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + public async Task GenerateFinalResult(List hexMessageList) + { + AFN10_F66_AnalysisDto entity = new AFN10_F66_AnalysisDto(); + var cycleBin = hexMessageList[4].HexToBin().PadLeft(8, '0'); + var cycleUnitBin = cycleBin.Substring(0, 2); + var cycleValueBin = cycleBin.Substring(2, 6); + + entity.Cycle = cycleValueBin.BinToDec();//定时发送周期 + entity.Unit = cycleUnitBin.BinToDec();//定时发送周期(单位) + //TODO:发送基准时间 + var arrBaseTime = hexMessageList.GetRange(5, 6); + + var baseTimeArrStr = await _analysisStrategyContext.ExecuteAsync, string>("Appendix_A1", arrBaseTime); + var baseTimeArr= baseTimeArrStr.Split('_'); + //entity.BaseTime = DateTime.Parse($"{DateTime.Now.Year.ToString().Substring(0, 2)}{arrBaseTime[0]}-{arrBaseTime[1]}-{arrBaseTime[2]} {arrBaseTime[3]}:{arrBaseTime[4]}:{arrBaseTime[5]}"); + + entity.BaseTime = Convert.ToDateTime(baseTimeArr[0]); + entity.CurveRatio = hexMessageList[11].HexToDec(); + var count = hexMessageList[12].HexToDec(); + var dataArr = hexMessageList.GetRange(13, 4 * count); + for (int i = 0; i < count; i++) + { + var pnfnArr = dataArr.GetRange(0, 4); + var tempPn = ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]); + var tempFn = ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]); + entity.Details.Add(new SetAutoItemCodeDetails() { Fn = tempFn, Pn = tempPn }); + dataArr.RemoveRange(0, 4); + } + + return entity; + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs new file mode 100644 index 0000000..8b32e24 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs @@ -0,0 +1,49 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +{ + /// + /// 5.5.1.3.55 F68:定时上报 2 类数据任务启动/停止设置 + /// + public class AFN10_F68_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN10_F68_Analysis(ILogger logger) + { + _logger = logger; + } + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = input.UnitData.HexMessageList[4].Equals("55") + }; + + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0A_68解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs new file mode 100644 index 0000000..e857bcd --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs @@ -0,0 +1,103 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.85 F129:当前正向有功电能示值(总、费率1~M) + /// + public class AFN12_F129_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F129_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + List list = GenerateFinalResult(2, datas, "正向有功电能示值", input.AFN_FC.AFN, input.DT.Fn); + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_129解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + #region 单元数据值解析 + /// + /// 单元数据值解析 + /// + /// + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int rationgCount = hexMessageList.GetRatingCount(9, 1); + values.Add(rationgCount.ToString()); + for (int i = 0; i < rationgCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + (i * 5), 5); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + #endregion + + public List GenerateFinalResult(int index, List data, string remark = "", int afn = 0, int fn = 0) + { + List list = new List(); + for (int i = index; i < data.Count; i++) + { + AFN12_F129_AnalysisDto meter = new AFN12_F129_AnalysisDto(); + + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + meter.ValidData = false; + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + + meter.DataType = $"{afn.ToString().PadLeft(2, '0')}_{fn}_{i - index}"; + meter.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + list.Add(meter); + } + return list; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs new file mode 100644 index 0000000..0afadc6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs @@ -0,0 +1,94 @@ +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.86 F130:当前正向无功(组合无功 1)电能示值(总、费率 1~M) + /// + public class AFN12_F130_Analysis : IAnalysisStrategy>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F130_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + List list = GenerateFinalResult(2, datas, "正向无功电能示值", input.AFN_FC.AFN, input.DT.Fn); + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_130解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int ratingCount = hexMessageList.GetRatingCount(9, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + public List GenerateFinalResult(int index, List data, string remark = "", int afn = 0, int fn = 0) + { + List list = new List(); + for (int i = index; i < data.Count; i++) + { + AFN12_F130_AnalysisDto meter = new AFN12_F130_AnalysisDto(); + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + meter.ValidData = false; + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + meter.DataType = $"{afn.ToString().PadLeft(2, '0')}_{fn}_{i - index}"; + meter.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + list.Add(meter); + } + return list; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs new file mode 100644 index 0000000..c52e7e3 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs @@ -0,0 +1,94 @@ +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.87 F131:当前反向有功电能示值(总、费率 1~M) + /// + public class AFN12_F131_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F131_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + List list = GenerateFinalResult(2, datas, "反向有功总电能示值", input.AFN_FC.AFN, input.DT.Fn); + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_131解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int ratingCount = hexMessageList.GetRatingCount(9, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + (i * 5), 5); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + public List GenerateFinalResult(int index, List data, string remark = "", int afn = 0, int fn = 0) + { + List list = new List(); + for (int i = index; i < data.Count; i++) + { + AFN12_F131_AnalysisDto meter = new AFN12_F131_AnalysisDto(); + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + meter.ValidData = false; + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + meter.DataType = $"{afn.ToString().PadLeft(2, '0')}_{fn}_{i - index}"; + meter.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + list.Add(meter); + } + return list; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs new file mode 100644 index 0000000..85c3f88 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.88 F132:当前反向无功(组合无功 2)电能示值(总、费率 1~M) + /// + public class AFN12_F132_Analysis : IAnalysisStrategy>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F132_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + List list = GenerateFinalResult(2, datas, "反向无功电能示值", (int)input.AFN_FC.AFN!, (int)input.DT.Fn!); + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn , + Pn = input.DA.Pn, + Data = list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_132解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int ratingCount = hexMessageList.GetRatingCount(9, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加4个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + public List GenerateFinalResult(int index, List data, string remark = "",int afn=0,int fn=0) + { + List list = new List(); + for (int i = index; i < data.Count; i++) + { + AFN12_F132_AnalysisDto meter = new AFN12_F132_AnalysisDto(); + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + meter.ValidData = false; + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + meter.DataType = $"{afn.ToString().PadLeft(2, '0')}_{fn}_{i - index}"; + meter.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + list.Add(meter); + } + return list; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs new file mode 100644 index 0000000..6a3d126 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs @@ -0,0 +1,108 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.101 F145:当月正向有功最大需量及发生时间(总、费率 1~M) + /// + public class AFN12_F145_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F145_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + AFN12_F145_AnalysisDto data = GenerateFinalResult(2, datas, "当月正向有功最大需量及发生时间"); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = data + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_145解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int ratingCount = hexMessageList.GetRatingCount(9, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + i * 7, 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A23), arr); + values.Add(value.ToString());//正向有功总最大需量 + } + arr = hexMessageList.GetRange(10 + i * 7 + 3, 4); + + errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, string>(nameof(Appendix_A17), arr); + values.Add(value.ToString());//正向有功总最大需量发生时间 + } + } + return values; + } + + public AFN12_F145_AnalysisDto GenerateFinalResult(int index, List data, string remark = "") + { + AFN12_F145_AnalysisDto dto = new AFN12_F145_AnalysisDto(); + + decimal value = 0; + var errorCode = data[2].CheckErrorCode(); + if (errorCode != null) + dto.ValidData = false; + else + decimal.TryParse(data[2], out value); + + dto.DataValue = value; + dto.TimeSpan = $"{DateTime.Now.Year}-{data[3].Substring(0, 2)}-{data[3].Substring(2, 2)} {data[3].Substring(4, 2)}:{data[3].Substring(6, 2)}:00";//$"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)}"; + if (DateTime.TryParse(dto.TimeSpan, out DateTime readingDate)) + { + dto.ReadingDate = readingDate; + } + return dto; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs new file mode 100644 index 0000000..986d52b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs @@ -0,0 +1,120 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.105 F149:上月(上一结算日)正向有功最大需量及发生时间(总、费率 1~M) + /// + public class AFN12_F149_Analysis : IAnalysisStrategy> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F149_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List datas = await AnalysisDataUnit(input.UnitData.HexMessageList); + AFN12_F149_AnalysisDto data = GenerateFinalResult(2, datas, "上月(上一结算日)正向有功最大需量及发生时间"); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis + { + Code = input.A?.Code, + AFN = input.AFN_FC?.AFN ?? 0, + Fn = input.DT?.Fn ?? 0, + Pn = input.DA?.Pn ?? 0, + Data = data + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_149解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + + } + private async Task> AnalysisDataUnit(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + int ratingCount = hexMessageList.GetRatingCount(9, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(10 + i * 7, 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode!=null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A23), arr); + values.Add(value.ToString());//正向有功总最大需量 + } + + arr = hexMessageList.GetRange(13 + i * 7, 4); + + errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, string>(nameof(Appendix_A17), arr);//正向有功总最大需量发生时间 + values.Add(value);//正向有功总最大需量 + } + } + return values; + } + public AFN12_F149_AnalysisDto GenerateFinalResult(int index, List data, string remark = "") + { + AFN12_F149_AnalysisDto dto = new AFN12_F149_AnalysisDto(); + + var errorCodeInfo = data[2].CheckErrorCode(); + if (errorCodeInfo != null) + dto.ValidData = false; + decimal.TryParse(data[2], out decimal value); + dto.DataValue = value; + + //TODO:最大需量发生时间 + errorCodeInfo = data[3].CheckErrorCode(); + if (data[3].Length != 8 && errorCodeInfo != null) + dto.ValidData = false; + else + dto.TimeSpan = $"{DateTime.Now.Year}-{data[3].Substring(0, 2)}-{data[3].Substring(2, 2)} {data[3].Substring(4, 2)}:{data[3].Substring(6, 2)}:00"; + + + //TODO:时间标 + if (!DateTime.TryParse(dto.TimeSpan, out DateTime readingDate)) + dto.ValidData = false; + dto.ReadingDate = readingDate; + if (DateTime.Now.Month.Equals(1))//如果为1月份,则日期减去1年 + { + dto.ReadingDate = dto.ReadingDate.AddYears(-1); + dto.TimeSpan = dto.ReadingDate.ToString("yyyy-MM-dd HH:mm:ss"); + } + return dto; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs new file mode 100644 index 0000000..45f455d --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs @@ -0,0 +1,73 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 水表抄读取 + /// + public class AFN12_F188_Analysis : IAnalysisStrategy> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F188_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(TB3761 input) + { + + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + ArgumentNullException.ThrowIfNull(input.AFN_FC.AFN); + ArgumentNullException.ThrowIfNull(input.DT.Fn); + var data = GenerateFinalResult(input.UnitData.HexMessageList); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = data + }; + return await Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_188解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + public AFN12_F149_AnalysisDto GenerateFinalResult(List hexMessageList) + { + AFN12_F149_AnalysisDto dto = new AFN12_F149_AnalysisDto(); + decimal value = 0; + var arr = hexMessageList.GetRange(11, 4); + var errorCodeInfo = arr.CheckErrorCode(); + if (errorCodeInfo != null) + { + dto.ValidData = false; + dto.ErrorCodeMsg = errorCodeInfo.Item2; + } + else + decimal.TryParse($"{arr[11]}{arr[12]}{arr[13]}.{arr[14]}", out value); + + dto.DataValue = value; + //dto.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + return dto; + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs new file mode 100644 index 0000000..f3fd66b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs @@ -0,0 +1,120 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using YamlDotNet.Core.Tokens; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.22 F25:当前三相及总有/无功功率、功率因数,三相电压、电流、零序电流、视在功率 + /// + public class AFN12_F25_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F25_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public List DataType { get; set; } = new List() { "YGGL", "YGGL_A", "YGGL_B", "YGGL_C", "WGGL", "WGGL_A", "WGGL_B", "WGGL_C", "GLYS", "GLYS_A", "GLYS_B", "GLYS_C", "DY_A", "DY_B", "DY_C", "DL_A", "DL_B", "DL_C", "LXDL", "SZGL", "SZGL_A", "SZGL_B", "SZGL_C" }; + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + List remarks = new List() { "当前总有功功率", "当前A相有功功率", "当前B相有功功率", "当前C相有功功率", "当前总无功功率", "当前A相无功功率", "当前B相无功功率", "当前C相无功功率", "当前总功率因数", "当前A相功率因数", "当前B相功率因数", "当前C相功率因数", "当前A相电压", "当前B相电压", "当前C相电压", "当前A相电流", "当前C相电流", "当前 C相电流", "当前零序电流", "当前总视在功率", "当前A相视在功率", "当前B相视在功率", "当前C相视在功率" }; + List list = new List(); + List data = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + + for (int i = 1; i < data.Count; i++) + { + AFN12_F25_AnalysisDto dto = new AFN12_F25_AnalysisDto(); + decimal value = 0; + var errorCodeInfo = data[i].CheckErrorCode(); + if (errorCodeInfo != null) + { + dto.ValidData = false; + dto.ErrorCodeMsg = errorCodeInfo.Item2; + } + else + decimal.TryParse(data[i], out value); + dto.DataValue = value; + dto.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}_{DataType[i-1]}"; + dto.FiledName = DataType[i - 1]; + dto.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00"); + dto.FiledDesc = remarks[i - 1]; + list.Add(dto); + } + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_25解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 5)); + values.AddRange(await CutOutAsync(9, 8, 3, nameof(Appendix_A9), hexMessageList));//解析 总/ABC相有功/无功功率 + values.AddRange(await CutOutAsync(33, 4, 2, nameof(Appendix_A5), hexMessageList));//解析 总/ABC相功率因数 + values.AddRange(await CutOutAsync(41, 3, 2, nameof(Appendix_A7), hexMessageList));//ABC相电压 + values.AddRange(await CutOutAsync(47, 4, 3, nameof(Appendix_A25), hexMessageList));//ABC相/零序电流 + values.AddRange(await CutOutAsync(59, 4, 3, nameof(Appendix_A9), hexMessageList));//总视\ABC相视在功率 + return values; + } + /// + /// 截取值 + /// + /// 开始位置 + /// 总项数 + /// 每项字节数 + /// 解析方式 + /// 解析数据 + private async Task> CutOutAsync(int Index, int count, int byteCount, string appendixName, List hexMessageList) + { + List values = new List(); + var temp = hexMessageList.GetRange(Index, count * byteCount);//截取位置(9),解析项*截取字节数(8*3) + for (int i = 0; i < count; i++) + { + var arr = temp.GetRange(i * byteCount, byteCount); + var errorCode = arr.CheckErrorCode(); + if (errorCode!=null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(appendixName, arr); + values.Add(value.ToString()); + } + } + return values; + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs new file mode 100644 index 0000000..bd034c6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs @@ -0,0 +1,72 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.1 F2:终端日历时钟 + /// + public class AFN12_F2_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F2_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(TB3761 input) + { + + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + var data= await GenerateFinalResultAsync(input.UnitData.HexMessageList); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = data + }; + return await Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_2解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + public async Task GenerateFinalResultAsync(List hexMessageList) + { + AFN12_F2_AnalysisDto dto = new AFN12_F2_AnalysisDto(); + var arr = hexMessageList.GetRange(4, 6); + var errorCodeInfo = arr.CheckErrorCode(); + if (errorCodeInfo != null) + { + dto.ValidData = false; + dto.ErrorCodeMsg = errorCodeInfo.Item2; + } + else + dto.DataValue = await _analysisStrategyContext.ExecuteAsync, string>(nameof(Appendix_A1), arr); + + dto.FiledName = "TerminalTime"; + dto.FiledDesc = "召读终端时间"; + return await Task.FromResult(dto); + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs new file mode 100644 index 0000000..12d49fc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs @@ -0,0 +1,124 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.30 F33:当前正向有/无功电能示值、一/四象限无功电能示值(总、费率 1~M,1≤M≤12) + /// + public class AFN12_F33_Analysis : IAnalysisStrategy> + { + private List DataUnitHexList { get; set; }=new List(); + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F33_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + int rationgCount = input.UnitData.HexMessageList!.GetRatingCount(23, 1); + + DataUnitHexList = input.UnitData.HexMessageList.GetRange(24, (5 * (rationgCount + 1)) + (4 * (rationgCount + 1)) * 3); + GetDataUnitHexString(input.UnitData.HexMessageList, rationgCount); + UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = await AnalysisDataUnit(input.UnitData.HexMessageList, rationgCount) + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_33解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + #region 获取当前正向有/无功电能示值数据单元格式 private void GetDataUnitHexString(int rationgCount) + private void GetDataUnitHexString(List hexMessageList, int rationgCount) + { + //(5*(x+1))+(4*(x+1))*3 + var lenght = (5 * (rationgCount + 1)) + (4 * (rationgCount + 1)) * 3;//(rationgCount * 5 + 5) + (4 * 3) + (rationgCount * 4) * 2;//费率数(R):4 公式:5+5+(费率数*5)+ (4+(费率数*4))*2 + DataUnitHexList = hexMessageList.GetRange(24, lenght); + } + #endregion + + #region 单元数据值解析 private F33Entity AnalysisDataUnit() + private async Task AnalysisDataUnit(List hexMessageList, int rationgCount) + { + AFN12_F33_AnalysisDto f33Entity = new AFN12_F33_AnalysisDto(); + f33Entity.ReadTime = hexMessageList.GetReadTime(18, 5); // 终端抄表时间 + f33Entity.RatingCount = hexMessageList.GetRatingCount(23, 1); // 费率数 M(1≤M≤12) + f33Entity.F_A_Kwh = await GetDataAsync(f33Entity.RatingCount, 0, 5, nameof(Appendix_A14));//当前正向有功总电能示值 + f33Entity.R_R_Kvarh = await GetDataAsync(f33Entity.RatingCount, 25, 4, nameof(Appendix_A11));//当前正向无功(组合无功1)总电能示值 0+5*5 + f33Entity.Q1_R_Kvarh = await GetDataAsync(f33Entity.RatingCount, 45, 4, nameof(Appendix_A11));//当前一象限无功总电能示值 25+4*5 + f33Entity.Q4_R_Kvarh = await GetDataAsync(f33Entity.RatingCount, 65, 4, nameof(Appendix_A11));//当前四象限无功总电能示值 45+4*5 + return f33Entity; + } + #region 有功/无功、费率总电能示值 + /// + /// 有功/无功、费率总电能示值 + /// + /// 费率数 + /// 开始位置 + /// 长度 + /// + private async Task GetDataAsync(int ratingCount, int startIndex, int len, string appendxName) + { + ParentNodes parent = new ParentNodes(); + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(appendxName, DataUnitHexList.GetRange(startIndex, len)); + parent.Total_Value = value; + parent.childNodes = await GetChildDataAsync(ratingCount, startIndex, len, appendxName); + return parent; + } + + /// + /// 费率总电能示值 + /// + /// + /// + /// + /// + /// + private async Task> GetChildDataAsync(int RatingCount, int startIndex, int len, string appendxName) + { + List children = new List(); + for (int i = 0; i < RatingCount; i++) + { + ChildNodes model = new ChildNodes() + { + Value = await _analysisStrategyContext.ExecuteAsync, decimal>(appendxName, DataUnitHexList.GetRange((i * len) + (startIndex + len), len)) //29,4 33,4 37,4 41,4 + }; + children.Add(model); + } + return children; + } + + + #endregion + + + #endregion + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs new file mode 100644 index 0000000..14b46ad --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +{ + /// + /// 5.12.2.4.46 F49:当前电压、电流相位角 + /// + public class AFN12_F49_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public AFN12_F49_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public List DataType { get; set; } = new List() { "Uab_Ua", "Ub", "Ucb_Uc", "Ia", "Ib", "Ic" }; + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + + List data = await AnalysisDataUnitAsync(input.UnitData?.HexMessageList!); + List remarks = new List() { "Uab/Ua 相位角", "Ub 相位角", "Ucb/Uc 相位角", "Ia 相位角", "Ib 相位角", "Ic 相位角" }; + List list = new List(); + for (int i = 0; i < data.Count; i++) + { + AFN12_F49_AnalysisDto dto = new AFN12_F49_AnalysisDto(); + decimal value = 0; + var errorCodeInfo = data[i].CheckErrorCode(); + if (errorCodeInfo != null) + { + dto.ValidData = false; + dto.ErrorCodeMsg = errorCodeInfo.Item2; + } + else + decimal.TryParse(data[i], out value); + dto.DataValue = value; + + dto.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}_{DataType[i]}"; + dto.FiledName = DataType[i]; + dto.FiledDesc= remarks[i]; + list.Add(dto); + } + UnitDataAnalysis> unitDataAnalysis = new UnitDataAnalysis> + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data= list + }; + + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0C_49解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + for (int i = 0; i < 6; i++) + { + var arr = hexMessageList.GetRange(4 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode!=null) + values.Add(errorCode.Item1); + else + { + var value= await _analysisStrategyContext.ExecuteAsync,decimal>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + + } + return values; + } + + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_02800002.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_02800002.cs new file mode 100644 index 0000000..c197e04 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_02800002.cs @@ -0,0 +1,40 @@ +using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 2 日时段表数据 + /// + public class Appendix_02800002 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + + public Appendix_02800002(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(List data) + { + try + { + if (data.Count != 2) + return null; + var value = string.Join(".", data); + var values= new List() { "电网频率", "10_97", "1", value }; + return Task.FromResult(values); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Appendix_02800002解析失败:{ex.Message}"); + return null; + } + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000201.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000201.cs new file mode 100644 index 0000000..9cc7b92 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000201.cs @@ -0,0 +1,33 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 年时区数 p≤14 + /// + public class Appendix_04000201 : IAnalysisStrategy, List> + { + private int valueByteCount = 1; + private readonly ILogger _logger; + + public Appendix_04000201(ILogger logger) + { + _logger = logger; + } + + public async Task> ExecuteAsync(List data) + { + List values = new List(); + values.Insert(0, "10_94"); + values.Insert(0, "年时区数"); + values.Add((data.Count / valueByteCount).ToString());//值总数 + foreach (var item in data) + { + values.Add(item.HexToDec().ToString()); + } + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000202.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000202.cs new file mode 100644 index 0000000..2fbe5d5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000202.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 日时段表数 q≤8 + /// + public class Appendix_04000202 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04000202(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04000201", data); + values[0] = "日时段表数"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000203.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000203.cs new file mode 100644 index 0000000..e3d2248 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000203.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 日时段数(每日切换数) m≤14 + /// + public class Appendix_04000203 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04000203(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04000201", data); + values[0] = "日时段数(每日切换数)"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000204.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000204.cs new file mode 100644 index 0000000..99ba631 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04000204.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 费率数 k≤63 + /// + public class Appendix_04000204 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04000204(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04000201", data); + values[0] = "费率数"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010000.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010000.cs new file mode 100644 index 0000000..69e7a5c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010000.cs @@ -0,0 +1,38 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套时区表数据 + /// + public class Appendix_04010000 : IAnalysisStrategy, List> + { + /// + /// 每个值字节数 + /// + private const int valueByteCount = 3; + private readonly ILogger _logger; + + public Appendix_04010000(ILogger logger) + { + _logger = logger; + } + + public async Task> ExecuteAsync(List data) + { + List values = new List(); + int valueCount = data.Count / valueByteCount; + values.Insert(0, "10_94"); + values.Insert(0, "第一套第{0}时区起始日期及日时段表号"); + values.Add(valueCount.ToString());//值总数 11 11 11 22 22 22 33 33 33 + for (int i = 0; i < valueCount; i++) + { + var value = data.GetRange(i * 3, valueByteCount);//MMDDNN + values.Add($"{value[0]}:{value[1]}");//MM:DD 或hhmm + values.Add(value[2]);//NN 费率号 + } + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010001.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010001.cs new file mode 100644 index 0000000..c6aa07f --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010001.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 1 日时段表数据: + /// + public class Appendix_04010001 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010001(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第1日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010002.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010002.cs new file mode 100644 index 0000000..f7ac153 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010002.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 2 日时段表数据 + /// + public class Appendix_04010002 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010002(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第2日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010003.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010003.cs new file mode 100644 index 0000000..39c32f6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010003.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 3 日时段表数据 + /// + public class Appendix_04010003 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010003(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第3日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010004.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010004.cs new file mode 100644 index 0000000..fa5958c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010004.cs @@ -0,0 +1,30 @@ +using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 4 日时段表数据 + /// + public class Appendix_04010004 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010004(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List> ("Appendix_04010000", data); + values[0] = "第一套第4日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010005.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010005.cs new file mode 100644 index 0000000..0905d45 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010005.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 5 日时段表数据 + /// + public class Appendix_04010005 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010005(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第5日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010006.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010006.cs new file mode 100644 index 0000000..f97be46 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010006.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 6 日时段表数据 + /// + public class Appendix_04010006 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010006(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第6日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010007.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010007.cs new file mode 100644 index 0000000..7546af9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010007.cs @@ -0,0 +1,27 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 7 日时段表数据 + /// + public class Appendix_04010007 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010007(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第7日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010008.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010008.cs new file mode 100644 index 0000000..2ca689c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_04010008.cs @@ -0,0 +1,28 @@ +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 第一套第 8 日时段表数据 + /// + public class Appendix_04010008 : IAnalysisStrategy, List> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + + public Appendix_04010008(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + } + + public async Task> ExecuteAsync(List data) + { + var values = await _analysisStrategyContext.ExecuteAsync, List>("Appendix_04010000", data); + values[0] = "第一套第8日第{0}时段起始时间及费率号"; + return await Task.FromResult(values); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A1.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A1.cs new file mode 100644 index 0000000..cd17247 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A1.cs @@ -0,0 +1,33 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A1 : IAnalysisStrategy, string> + { + private readonly ILogger _logger; + + public Appendix_A1(ILogger logger) + { + _logger = logger; + } + + public async Task ExecuteAsync(List data) + { + var seconds = data[0]; + var minutes = data[1]; + var hours = data[2]; + var day = data[3]; + string binString = data[4].HexTo4BinZero(); + var months = (binString.Substring(3, 1).BinToDec() * 10) + Convert.ToInt32(binString.Substring(4, 4).BinToHex()); + var week = binString.Substring(0, 3).HexTo4BinZero(); + var year = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{data[5]}"; + string date= $"{year}-{months.ToString().PadLeft(2, '0')}-{day} {hours}:{minutes}:{seconds}_{week}"; + return await Task.FromResult(date); + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A11.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A11.cs new file mode 100644 index 0000000..9989bf4 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A11.cs @@ -0,0 +1,57 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 附录A.11数据格式 + /// + class Appendix_A11 : IAnalysisStrategy, decimal> + { + private readonly ILogger _logger; + + public Appendix_A11(ILogger logger) + { + _logger = logger; + } + + public async Task ExecuteAsync(List data) + { + decimal value = 0.00M; + List decimalDCBList = new List(); + decimalDCBList.Add(new decimal[2] { 10M, 100M }); + decimalDCBList.Add(new decimal[2] { 10M, 1M }); + decimalDCBList.Add(new decimal[2] { 1000M, 100M }); + decimalDCBList.Add(new decimal[2] { 100000M, 10000M }); + for (int i = 0; i < data.Count; i++) + { + int CalcType = i > 0 ? 2 : 1; + value += GetByteDCD(data[i].HexTo4BinZero(), CalcType, decimalDCBList[i]); + } + return await Task.FromResult(value); + } + + /// + /// 附录A.14数据格式计算规则方法 + /// + /// 二进制字符串 + /// //计算类型,1为除法,2为乘法 + /// 除数数组 + /// + private decimal GetByteDCD(string binString, int calcType, decimal[] bcd) + { + decimal result = 0.00000M; + switch (calcType) + { + case 1: + result = (binString.Substring(0, 4).BinToDec() / bcd[0]) + (binString.Substring(4, 4).BinToDec() / bcd[1]); + break; + case 2: + result = (binString.Substring(0, 4).BinToDec() * bcd[0]) + (binString.Substring(4, 4).BinToDec() * bcd[1]); + break; + } + return result; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A13.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A13.cs new file mode 100644 index 0000000..ca45b2b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A13.cs @@ -0,0 +1,56 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 附录A.13数据格式 + /// + class Appendix_A13 : IAnalysisStrategy, decimal> + { + private readonly ILogger _logger; + + public Appendix_A13(ILogger logger) + { + _logger = logger; + } + + public async Task ExecuteAsync(List data) + { + decimal value = 0.00M; + List decimalDCBList = new List(); + decimalDCBList.Add(new decimal[2] { 1000M, 10000M }); + decimalDCBList.Add(new decimal[2] { 10M, 100M }); + decimalDCBList.Add(new decimal[2] { 10M, 1M }); + decimalDCBList.Add(new decimal[2] { 1000M, 100M }); + for (int i = 0; i < data.Count; i++) + { + int CalcType = i > 1 ? 2 : 1; + value += GetByteDCD(data[i].HexTo4BinZero(), CalcType, decimalDCBList[i]); + } + return await Task.FromResult(value); + } + /// + /// 附录A.13数据格式计算规则方法 + /// + /// 二进制字符串 + /// //计算类型,1为除法,2为乘法 + /// 除数数组 + /// + private decimal GetByteDCD(string binString, int calcType, decimal[] bcd) + { + decimal result = 0.00000M; + switch (calcType) + { + case 1: + result = (binString.Substring(0, 4).BinToDec() / bcd[0]) + (binString.Substring(4, 4).BinToDec() / bcd[1]); + break; + case 2: + result = (binString.Substring(0, 4).BinToDec() * bcd[0]) + (binString.Substring(4, 4).BinToDec() * bcd[1]); + break; + } + return result; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A14.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A14.cs new file mode 100644 index 0000000..d4179c6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A14.cs @@ -0,0 +1,57 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + /// + /// 附录A.14数据格式 + /// + class Appendix_A14 : IAnalysisStrategy, decimal> + { + private readonly ILogger _logger; + + public Appendix_A14(ILogger logger) + { + _logger = logger; + } + public async Task ExecuteAsync(List data) + { + decimal value = 0.0000M; + List decimalDCBList = new List(); + decimalDCBList.Add(new decimal[2] { 1000M, 10000M }); + decimalDCBList.Add(new decimal[2] { 10M, 100M }); + decimalDCBList.Add(new decimal[2] { 10M, 1M }); + decimalDCBList.Add(new decimal[2] { 1000M, 100M }); + decimalDCBList.Add(new decimal[2] { 100000M, 10000M }); + for (int i = 0; i < data.Count; i++) + { + int CalcType = i > 1 ? 2 : 1; + value += GetByteDCD(data[i].HexTo4BinZero(), CalcType, decimalDCBList[i]); + } + return await Task.FromResult(value); + } + + /// + /// 附录A.14数据格式计算规则方法 + /// + /// 二进制字符串 + /// //计算类型,1为除法,2为乘法 + /// 除数数组 + /// + private decimal GetByteDCD(string binString, int calcType, decimal[] bcd) + { + decimal result = 0.00000M; + switch (calcType) + { + case 1: + result = (binString.Substring(0, 4).BinToDec() / bcd[0]) + (binString.Substring(4, 4).BinToDec() / bcd[1]); + break; + case 2: + result = (binString.Substring(0, 4).BinToDec() * bcd[0]) + (binString.Substring(4, 4).BinToDec() * bcd[1]); + break; + } + return result; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A15.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A15.cs new file mode 100644 index 0000000..c2c3859 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A15.cs @@ -0,0 +1,24 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A15 : IAnalysisStrategy, string> + { + private readonly ILogger _logger; + + public Appendix_A15(ILogger logger) + { + _logger = logger; + } + + public async Task ExecuteAsync(List data) + { + data.Reverse(); + data.Insert(0, DateTime.Now.ToString("yyyy").Substring(0, 2)); + string date= string.Join("", data); + return await Task.FromResult(date); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A17.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A17.cs new file mode 100644 index 0000000..2753afd --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A17.cs @@ -0,0 +1,16 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A17 : IAnalysisStrategy, string> + { + public async Task ExecuteAsync(List data) + { + data.Reverse(); + string datasStr= string.Join("", data); + return await Task.FromResult(datasStr); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A23.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A23.cs new file mode 100644 index 0000000..a8415e4 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A23.cs @@ -0,0 +1,50 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A23 : IAnalysisStrategy, decimal> + { + + public async Task ExecuteAsync(List 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); + } + /// + /// 解析值 + /// + /// 二进制低位字符串截取位置 + /// 截取长度 + /// 分位值,1000M + /// 二进制高位字符串截取位置 + /// 截取长度 + /// 分位值,100M + /// 数据 + /// 计算类型,0:乘法,1:除法 + /// + 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; + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A25.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A25.cs new file mode 100644 index 0000000..4401502 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A25.cs @@ -0,0 +1,33 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A25 : IAnalysisStrategy, decimal> + { + public async Task ExecuteAsync(List data) + { + decimal value = 0.000M; + string binString = string.Empty; + if (data[0].Check3761Byte()) + { + binString = data[0].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 100M) + (binString.Substring(4, 4).BinToDec() / 1000M); + } + if (data[1].Check3761Byte()) + { + binString = data[1].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 1M) + (binString.Substring(4, 4).BinToDec() / 10M); + } + if (data[2].Check3761Byte()) + { + binString = data[2].HexTo4BinZero(); + value += (binString.Substring(1, 3).BinToDec() * 100M) + (binString.Substring(4, 4).BinToDec() * 10M); + int sign = Convert.ToInt32(binString.Substring(0, 1));//正负值标记 + value = sign == 0 ? value * 1 : value * -1; + } + return await Task.FromResult(value); + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A5.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A5.cs new file mode 100644 index 0000000..daebff2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A5.cs @@ -0,0 +1,27 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A5 : IAnalysisStrategy, decimal> + { + public async Task ExecuteAsync(List data) + { + decimal value = 0.0M; + string binString = string.Empty; + if (data[0].Check3761Byte()) + { + binString = data[0].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 1M) + (binString.Substring(4, 4).BinToDec() / 10M); + } + if (data[1].Check3761Byte()) + { + binString = data[1].HexTo4BinZero(); + value += (binString.Substring(1, 3).BinToDec() * 100M) + (binString.Substring(4, 4).BinToDec() * 10M); + int sign = Convert.ToInt32(binString.Substring(0, 1));//正负值标记 + value = sign == 0 ? value * 1 : value * -1; + } + return await Task.FromResult(value); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A7.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A7.cs new file mode 100644 index 0000000..a305fa2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A7.cs @@ -0,0 +1,27 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A7 : IAnalysisStrategy, decimal> + { + + public async Task ExecuteAsync(List data) + { + decimal value = 0.0M; + string binString = string.Empty; + if (data[0].Check3761Byte()) + { + binString = data[0].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 1M) + (binString.Substring(4, 4).BinToDec() / 10M); + } + if (data[1].Check3761Byte()) + { + binString = data[1].HexTo4BinZero(); + if (binString.Check3761Byte()) + value += (binString.Substring(0, 4).BinToDec() * 100M) + (binString.Substring(4, 4).BinToDec() * 10M); + } + return await Task.FromResult(value); + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A9.cs b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A9.cs new file mode 100644 index 0000000..f290932 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Appendix/Appendix_A9.cs @@ -0,0 +1,36 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +{ + public class Appendix_A9 : IAnalysisStrategy, decimal> + { + + public async Task ExecuteAsync(List data) + { + decimal value = 0.0000M; + string binString = string.Empty; + if (data[0].Check3761Byte()) + { + binString = data[0].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 1000M) + (binString.Substring(4, 4).BinToDec() / 10000M); + } + + if (data[1].Check3761Byte()) + { + binString = data[1].HexTo4BinZero(); + value += (binString.Substring(0, 4).BinToDec() / 10M) + (binString.Substring(4, 4).BinToDec() / 100M); + } + + if (data[2].Check3761Byte()) + { + binString = data[2].HexTo4BinZero(); + value += (binString.Substring(1, 3).BinToDec() * 10M) + (binString.Substring(4, 4).BinToDec() * 1M); + int sign = Convert.ToInt32(binString.Substring(0, 1));//正负值标记 + value = sign == 0 ? value * 1 : value * -1; + } + return await Task.FromResult(value); + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/Protocol3761Extensions.cs b/protocols/JiShe.CollectBus.Protocol/Protocol3761Extensions.cs new file mode 100644 index 0000000..6f8985a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol/Protocol3761Extensions.cs @@ -0,0 +1,129 @@ +using JiShe.CollectBus.Common.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol +{ + public static class Protocol3761Extensions + { + + /// + /// 3761协议数据字节校验 + /// + /// + /// + public static bool Check3761Byte(this string value) + { + if (!value.ToUpper().Equals("FF") && !value.ToUpper().Equals("EE")) + return true; + return false; + } + + /// + /// 字符串中是否包含字母 + /// + /// + /// + public static bool IsLetterExists(this string value) + { + return Regex.Matches(value, "[a-zA-Z]").Count > 0; + } + + /// + /// 判断错误代码 + /// + public static Tuple? CheckErrorCode(this List data) + { + var value = string.Join("", data); + if (value.IsLetterExists()) + { + var code = ErrorCodes().Where(f => value.Contains(f.Key)).FirstOrDefault(); + if (code.Key != null) + return Tuple.Create(code.Key,code.Value); + else + return Tuple.Create("EE", "未知数据错误"); + } + return null; + } + + /// + /// 判断错误代码 + /// + public static Tuple? CheckErrorCode(this string value) + { + if (value.IsLetterExists()) + { + var code = ErrorCodes().Where(f => value.Contains(f.Key)).FirstOrDefault(); + if (code.Key != null) + return Tuple.Create(code.Key, code.Value); + else + return Tuple.Create("EE", "未知数据错误"); + } + return null; + } + + /// + /// 错误信息 + /// + /// + public static Dictionary ErrorCodes() + { + return new Dictionary() + { + { "FF", "电表无此数据项" }, + { "EE", "未知数据错误" }, + { "E1", "数据点缺少(停电)" }, + { "E2", "通讯异常" }, + { "E3", "集中器未配置数据项" }, + { "E4", "电表档案无效" }, + { "E5", "电表无此数据项" }, + { "E6", "电表时间异常" }, + { "E7","暂停抄表" } + }; + } + + + /// + /// 费率数 + /// + /// + /// + /// + public static int GetRatingCount(this List hexMessageList ,int index, int len) + { + var list = hexMessageList.GetRange(index, len); + return list.Count > 0 ? list[0].HexToDec() : 0; + } + + + /// + /// 抄表时间 + /// + /// + /// + /// + public static string GetReadTime(this List hexMessageList, int index, int len) + { + var list = hexMessageList.GetRange(index, len); + return list.GetReadTime(); + } + + /// + /// 抄表时间 + /// + /// + /// + public static string GetReadTime(this List data) + { + data.Reverse(); + data.Insert(0, DateTime.Now.ToString("yyyy").Substring(0, 2)); + return string.Join("", data); + } + + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs index 27f7466..094f9e8 100644 --- a/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs @@ -29,6 +29,7 @@ namespace JiShe.CollectBus.Protocol private readonly IRepository _deviceRepository; private readonly ITcpService _tcpService; + /// /// Initializes a new instance of the class. /// @@ -216,11 +217,8 @@ namespace JiShe.CollectBus.Protocol DeviceNo = code, MessageId = Guid.NewGuid().ToString() }; - //await _producerBus.PublishAsync(ProtocolConst.SubscriberHeartbeatReceivedEventName, messageReceivedHeartbeatEvent); - await _producerService.ProduceAsync(ProtocolConst.SubscriberHeartbeatReceivedEventName, messageReceivedHeartbeatEvent); - //await _producerBus.Publish(messageReceivedHeartbeatEvent); - + var reqParam = new ReqParameter2() { AFN = AFN.确认或否认, @@ -239,8 +237,7 @@ namespace JiShe.CollectBus.Protocol Fn = 1 }; var bytes = Build3761SendData.BuildSendCommandBytes(reqParam); - //await _producerBus.PublishAsync(ProtocolConst.SubscriberHeartbeatIssuedEventName, new IssuedEventMessage { ClientId = messageReceived.ClientId, DeviceNo = messageReceived.DeviceNo, Message = bytes, Type = IssuedEventType.Heartbeat, MessageId = messageReceived.MessageId }); - + IssuedEventMessage issuedEventMessage = new IssuedEventMessage { ClientId = messageReceivedHeartbeatEvent.ClientId, @@ -255,9 +252,6 @@ namespace JiShe.CollectBus.Protocol _logger.LogWarning($"集中器地址{issuedEventMessage.ClientId} 心跳回复下发内容:{Convert.ToHexString(bytes)}"); await _producerService.ProduceAsync(ProtocolConst.SubscriberHeartbeatIssuedEventName, issuedEventMessage); } - - //await _producerBus.Publish(new IssuedEventMessage { ClientId = messageReceived.ClientId, DeviceNo = messageReceived.DeviceNo, Message = bytes, Type = IssuedEventType.Heartbeat, MessageId = messageReceived.MessageId }); - } diff --git a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs index 440239b..5e8a0be 100644 --- a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs +++ b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs @@ -155,7 +155,7 @@ namespace JiShe.CollectBus.Plugins // MessageId = NewId.NextGuid().ToString() //}); - if(tB3761?.AFN_FC?.AFN==null || tB3761.DT?.Fn==null) + if(tB3761?.AFN_FC.BaseHexMessage==null || tB3761.DT.BaseHexMessage == null) { _logger.LogError("376.1协议解析AFN失败"); return; @@ -165,7 +165,7 @@ namespace JiShe.CollectBus.Plugins // return; //TODO:根据AFN进行分流推送到kafka - string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, tB3761?.AFN_FC?.AFN.ToString().PadLeft(2,'0')); + string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, tB3761?.AFN_FC.AFN.ToString().PadLeft(2,'0')); List topics = ProtocolConstExtensions.GetAllTopicNamesByReceived(); diff --git a/services/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs b/services/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs index 07453d6..e162c72 100644 --- a/services/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs +++ b/services/JiShe.CollectBus.Application/Subscribers/SubscriberAppService.cs @@ -180,7 +180,7 @@ namespace JiShe.CollectBus.Subscribers } - [KafkaSubscribe(ProtocolConst.SubscriberAFN02HReceivedEventNameTemp)] + //[KafkaSubscribe(ProtocolConst.SubscriberAFN02HReceivedEventNameTemp)] public async Task ReceivedAFN00Event(MessageReceived receivedMessage) { @@ -205,12 +205,12 @@ namespace JiShe.CollectBus.Subscribers string serverName = $"AFN{tB3761.AFN_FC.AFN}_F{tB3761.DT.Fn}_Analysis"; //var analysisStrategy = _serviceProvider.GetKeyedService($"AFN0_F1_Analysis"); - //var data = await analysisStrategy.ExecuteAsync>(tB3761); + //var data = await analysisStrategy.ExecuteAsync>(tB3761); var executor = _serviceProvider.GetRequiredService(); - AFN0_F1_AnalysisDto aFN0_F1_AnalysisDto= await executor.ExecuteAsync("AFN0_F1_Analysis", tB3761); + bool isSucces= await executor.ExecuteAsync("AFN0_F1_Analysis", tB3761); } - return SubscribeAck.Success(); + return SubscribeAck.Fail(); } diff --git a/shared/JiShe.CollectBus.Common/Extensions/StringExtensions.cs b/shared/JiShe.CollectBus.Common/Extensions/StringExtensions.cs index 9ea2120..d2cea60 100644 --- a/shared/JiShe.CollectBus.Common/Extensions/StringExtensions.cs +++ b/shared/JiShe.CollectBus.Common/Extensions/StringExtensions.cs @@ -1178,6 +1178,17 @@ namespace JiShe.CollectBus.Common.Extensions return decimalNumber; } + /// + /// 转十进制字符串 + /// + /// + /// + public static string HexToDecStr(this int hexString) + { + var decimalString = Convert.ToString(hexString, 16); + return decimalString; + } + /// /// 十六进制转二进制 /// @@ -1229,6 +1240,27 @@ namespace JiShe.CollectBus.Common.Extensions return string.Join(" ", strArr); } + + /// + /// 16进制字符串转换成byte数组 + /// + /// 16进制字符串 + /// byte数组 + public static byte[] HexToByte(this string hexString) + { + hexString = hexString.Replace(" ", ""); + string tempStr = ""; + byte by = 0; + List bytes = new List(); + for (int i = 0; i < hexString.Length; i += 2) + { + tempStr = hexString.Substring(i, 2); + by = byte.Parse(tempStr, System.Globalization.NumberStyles.AllowHexSpecifier); + bytes.Add(by); + } + return bytes.ToArray(); + } + /// /// 判断数据是否有误 /// From 264eec540adad5ab40bed8a9a430627bcd88159b Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Thu, 24 Apr 2025 19:40:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisData/AFN_00H/AFN0_F1_Analysis.cs | 36 ++----------------- .../AnalysisData/AFN_00H/AFN0_F2_Analysis.cs | 2 +- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs index 09b23fc..d1249b7 100644 --- a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs @@ -25,12 +25,12 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H _logger = logger; } - public Task ExecuteAsync(TB3761 tB3761) + public Task> ExecuteAsync(TB3761 tB3761) { try { ArgumentNullException.ThrowIfNull(nameof(tB3761)); - AFN0_F1_AnalysisDto dto = new AFN0_F1_AnalysisDto + UnitDataAnalysis dto = new UnitDataAnalysis { Code = tB3761.A?.Code, AFN = tB3761.AFN_FC?.AFN ?? 0, @@ -47,36 +47,4 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H } } - public class AFN0_F2_Analysis : IAnalysisStrategy - { - private readonly ILogger _logger; - - public AFN0_F2_Analysis(ILogger logger) - { - _logger = logger; - } - public Task> ExecuteAsync(TB3761 input) - { - try - { - ArgumentNullException.ThrowIfNull(input); - UnitDataAnalysis dto = new UnitDataAnalysis - { - Code = input.A.Code, - AFN = input.AFN_FC.AFN, - Fn = input.DT.Fn, - Pn = input.DA.Pn , - Data = true, - }; - return Task.FromResult(dto); - } - catch (Exception ex) - { - _logger.LogError(ex, $"00_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); - return null; - } - } - } - - } diff --git a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs index 2801a3c..364542a 100644 --- a/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs @@ -39,7 +39,7 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H } catch (Exception ex) { - _logger.LogError(ex, $"00_2解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + _logger.LogError(ex, $"00_2解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); return null; } }