2025-03-14 17:28:58 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Models;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data.SqlTypes;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Common.BuildSendDatas
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构建下发报文
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class TelemetryPacketBuilder
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构建报文的委托
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
|
/// <param name="fn"></param>
|
|
|
|
|
|
/// <param name="pn"></param>
|
2025-03-15 23:06:27 +08:00
|
|
|
|
public delegate byte[] AFNDelegate(string address, int fn, int pn = 0);
|
2025-03-14 17:28:58 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 编码与方法的映射表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly Dictionary<string, AFNDelegate> AFNHandlers = new();
|
|
|
|
|
|
|
|
|
|
|
|
static TelemetryPacketBuilder()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 初始化时自动注册所有符合命名规则的方法
|
|
|
|
|
|
var methods = typeof(TelemetryPacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
|
|
|
|
|
foreach (var method in methods)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (method.Name.StartsWith("AFN") && method.Name.EndsWith("_Send"))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 提取编码部分(例如 "AFN0D_F184_Send" -> "0D_184")
|
|
|
|
|
|
string code = method.Name[3..^5].Replace("F", "_"); // 移除前缀和后缀,替换F为_
|
|
|
|
|
|
var delegateInstance = (AFNDelegate)Delegate.CreateDelegate(typeof(AFNDelegate), method);
|
|
|
|
|
|
AFNHandlers[code] = delegateInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_00H
|
|
|
|
|
|
public static byte[] AFN00_F1_Send(string address,int fn,int pn = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.确认或否认,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
|
|
|
|
|
A = address,
|
|
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
MSA = Build3761SendData.GetMSA(address),
|
|
|
|
|
|
Pn = pn,
|
|
|
|
|
|
Fn = fn
|
|
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] AFN00_F3_Send(string address, int fn, int pn = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.确认或否认,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
|
|
|
|
|
A = address,
|
|
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
MSA = Build3761SendData.GetMSA(address),
|
|
|
|
|
|
Pn = pn,
|
|
|
|
|
|
Fn = fn
|
|
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_01H
|
|
|
|
|
|
public static byte[] AFN01_F1_Send(string address, int fn, int pn = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.复位,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
|
|
|
|
|
A = address,
|
|
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
MSA = Build3761SendData.GetMSA(address),
|
|
|
|
|
|
Pn = pn,
|
|
|
|
|
|
Fn = fn
|
|
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_02H
|
|
|
|
|
|
public static byte[] AFN02_F2_Send(string address, int fn, int pn = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.链路接口检测,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
|
|
|
|
|
A = address,
|
|
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
MSA = Build3761SendData.GetMSA(address),
|
|
|
|
|
|
Pn = pn,
|
|
|
|
|
|
Fn = fn
|
|
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|