diff --git a/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs b/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs new file mode 100644 index 0000000..3aacf09 --- /dev/null +++ b/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs @@ -0,0 +1,27 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TouchSocket.Core; + +namespace JiShe.CollectBus.Protocol.Contracts.Adapters +{ + public class StandardFixedHeaderDataHandlingAdapter : CustomFixedHeaderDataHandlingAdapter + { + /// + /// 接口实现,指示固定包头长度 + /// + public override int HeaderLength => 3; + + /// + /// 获取新实例 + /// + /// + protected override CustomFixedHeaderRequestInfo GetInstance() + { + return new CustomFixedHeaderRequestInfo(); + } + } +} diff --git a/JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs b/JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs new file mode 100644 index 0000000..377322d --- /dev/null +++ b/JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TouchSocket.Core; + +namespace JiShe.CollectBus.Protocol.Contracts.Interfaces +{ + public class CustomFixedHeaderRequestInfo : IFixedHeaderRequestInfo + { + /// + /// 报文开始前缀 + /// + public string StartPrefix { get; set; } = "68"; + + /// + /// 报文结束后缀 + /// + public string EndPrefix { get; set; } = "16"; + + /// + /// 头部长度 + /// + public int HeadLength = 5; + + /// + /// 固定长度 + /// + private const int FixedLength = 17; + + /// + /// 报文长度 + /// + public int PacketLength { get; set; } + + /// + /// 控制域 C + /// + public int ControlDomain { get; set; } + + public bool OnParsingHeader(ReadOnlySpan header) + { + throw new NotImplementedException(); + } + + public bool OnParsingBody(ReadOnlySpan body) + { + throw new NotImplementedException(); + } + + public int BodyLength { get; } + } +} diff --git a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs index fe6072d..a47456a 100644 --- a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs @@ -25,7 +25,6 @@ namespace JiShe.CollectBus.Protocol { return; } - AnalysisData(cmdResult); await Task.CompletedTask; } @@ -176,125 +175,6 @@ namespace JiShe.CollectBus.Protocol var a = $"{a1}{a2Dec.ToString().PadLeft(5, '0')}"; return a; } - - /// - /// 解析上行命令数据包 - /// - /// - public void AnalysisData(CommandReulst commandReulst) - { - switch (commandReulst.AFN) - { - case AFN.确认或否认: - //commandReulst.fn - //1:全部确认 - //2:全部否认 - //3:按数据单元表示确认和否认 - //4 硬件安全认证错误应答 - break; - case AFN.复位: - break; - case AFN.链路接口检测: - AnalysisAFN02(commandReulst); - break; - case AFN.中继站命令: - break; - case AFN.设置参数: - break; - case AFN.控制命令: - break; - case AFN.身份认证及密钥协商: - break; - case AFN.备用: - break; - case AFN.请求被级联终端主动上报: - break; - case AFN.请求终端配置: - break; - case AFN.查询参数: - break; - case AFN.请求任务数据: - break; - case AFN.请求实时数据: - break; - case AFN.请求历史数据: - break; - case AFN.请求事件数据: - break; - case AFN.文件传输: - break; - case AFN.数据转发: - break; - default: - break; - } - } - - //终端启动发送帧的MSA应为零,其主站响应帧的MSA也应为零 - public void AnalysisAFN02(CommandReulst commandReulst) - { - if (commandReulst.Fn == 1) //登录 - { - Console.WriteLine($"{commandReulst.A},登录:{DateTime.Now}"); - var reqParam = new ReqParameter2() - { - AFN = AFN.确认或否认, - FunCode = (int)CFromStationFunCode.链路数据, - PRM = PRM.从动站报文, - A = commandReulst.A, - Seq = new Seq() - { - TpV = TpV.附加信息域中无时间标签, - FIRFIN = FIRFIN.单帧, - CON = CON.需要对该帧进行确认, - PRSEQ = commandReulst.Seq.PRSEQ, - }, - MSA = commandReulst.MSA, - Pn = 0, - Fn = 1 - }; - commandReulst.ReplyBytes = HexStringExtensions.BuildSendCommandBytes(reqParam); - } - else if (commandReulst.Fn == 2)//退出登录 - { - Console.WriteLine($"{commandReulst.A},退出登录:{DateTime.Now}"); - } - else if (commandReulst.Fn == 3)//心跳 - { - Console.WriteLine($"{commandReulst.A},心跳:{DateTime.Now}"); - AnalysisHeartbeat(commandReulst); - } - } - - public void AnalysisHeartbeat(CommandReulst commandReulst) - { - if (commandReulst.Seq.TpV == TpV.附加信息域中带时间标签) - { - //解析 - - } - if (commandReulst.Seq.CON == CON.需要对该帧进行确认) - { - var reqParam = new ReqParameter2() - { - AFN = AFN.确认或否认, - FunCode = (int)CFromStationFunCode.链路数据, - PRM = PRM.从动站报文, - A = commandReulst.A, - Seq = new Seq() - { - TpV = TpV.附加信息域中无时间标签, - FIRFIN = FIRFIN.单帧, - CON = CON.不需要对该帧进行确认, - PRSEQ = commandReulst.Seq.PRSEQ, - }, - MSA = commandReulst.MSA, - Pn = 0, - Fn = 1 - }; - commandReulst.ReplyBytes = HexStringExtensions.BuildSendCommandBytes(reqParam); - } - } #endregion } }