修改代码
This commit is contained in:
parent
0d10c956db
commit
67dfab8a3c
@ -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<CustomFixedHeaderRequestInfo>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 接口实现,指示固定包头长度
|
||||||
|
/// </summary>
|
||||||
|
public override int HeaderLength => 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取新实例
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected override CustomFixedHeaderRequestInfo GetInstance()
|
||||||
|
{
|
||||||
|
return new CustomFixedHeaderRequestInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 报文开始前缀
|
||||||
|
/// </summary>
|
||||||
|
public string StartPrefix { get; set; } = "68";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 报文结束后缀
|
||||||
|
/// </summary>
|
||||||
|
public string EndPrefix { get; set; } = "16";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 头部长度
|
||||||
|
/// </summary>
|
||||||
|
public int HeadLength = 5;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 固定长度
|
||||||
|
/// </summary>
|
||||||
|
private const int FixedLength = 17;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 报文长度
|
||||||
|
/// </summary>
|
||||||
|
public int PacketLength { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控制域 C
|
||||||
|
/// </summary>
|
||||||
|
public int ControlDomain { get; set; }
|
||||||
|
|
||||||
|
public bool OnParsingHeader(ReadOnlySpan<byte> header)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnParsingBody(ReadOnlySpan<byte> body)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int BodyLength { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,7 +25,6 @@ namespace JiShe.CollectBus.Protocol
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnalysisData(cmdResult);
|
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,125 +175,6 @@ namespace JiShe.CollectBus.Protocol
|
|||||||
var a = $"{a1}{a2Dec.ToString().PadLeft(5, '0')}";
|
var a = $"{a1}{a2Dec.ToString().PadLeft(5, '0')}";
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析上行命令数据包
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="commandReulst"></param>
|
|
||||||
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user