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>
|
2025-03-18 15:58:37 +08:00
|
|
|
|
/// 构建下发报文,只适用与定时抄读
|
2025-03-14 17:28:58 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class TelemetryPacketBuilder
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构建报文的委托
|
|
|
|
|
|
/// </summary>
|
2025-03-18 15:58:37 +08:00
|
|
|
|
/// <param name="request.FocusAddress"></param>
|
|
|
|
|
|
/// <param name="request.Fn"></param>
|
|
|
|
|
|
/// <param name="request.Pn"></param>
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public delegate TelemetryPacketResponse AFNDelegate(TelemetryPacketRequest request);
|
2025-03-14 17:28:58 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 编码与方法的映射表
|
|
|
|
|
|
/// </summary>
|
2025-03-18 15:58:37 +08:00
|
|
|
|
public static readonly Dictionary<string, AFNDelegate> AFNHandlersDictionary = new();
|
2025-03-14 17:28:58 +08:00
|
|
|
|
|
|
|
|
|
|
static TelemetryPacketBuilder()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 初始化时自动注册所有符合命名规则的方法
|
|
|
|
|
|
var methods = typeof(TelemetryPacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
|
|
|
|
|
foreach (var method in methods)
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
if (method.Name.StartsWith("AFN") && method.Name.EndsWith("_Fn_Send"))
|
2025-03-14 17:28:58 +08:00
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
string code = method.Name;
|
2025-03-14 17:28:58 +08:00
|
|
|
|
var delegateInstance = (AFNDelegate)Delegate.CreateDelegate(typeof(AFNDelegate), method);
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFNHandlersDictionary[code] = delegateInstance;
|
2025-03-14 17:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-17 11:34:30 +08:00
|
|
|
|
#region AFN_00H 确认∕否认
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN00_Fn_Send(TelemetryPacketRequest request)
|
2025-03-14 17:28:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.确认或否认,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-14 17:28:58 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
CON = CON.需要对该帧进行确认,
|
2025-03-14 17:28:58 +08:00
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-14 17:28:58 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-14 17:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-17 11:34:30 +08:00
|
|
|
|
#region AFN_01H 复位命令
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN01_Fn_Send(TelemetryPacketRequest request)
|
2025-03-14 17:28:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.复位,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.复位命令,
|
|
|
|
|
|
A = request.FocusAddress,
|
2025-03-14 17:28:58 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
CON = CON.需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 10,
|
2025-03-14 17:28:58 +08:00
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-14 17:28:58 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-14 17:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-17 11:34:30 +08:00
|
|
|
|
#region AFN_02H 链路接口检测
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN02_Fn_Send(TelemetryPacketRequest request)
|
2025-03-14 17:28:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN = AFN.链路接口检测,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-14 17:28:58 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-14 17:28:58 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-14 17:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
2025-03-17 11:34:30 +08:00
|
|
|
|
|
|
|
|
|
|
#region AFN_04H 设置参数
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN04_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.设置参数,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求1级数据,
|
|
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
CON = CON.需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 10,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_05H 控制命令
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN05_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.控制命令,
|
|
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求1级数据,
|
|
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
CON = CON.需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 10,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_09H 请求终端配置及信息
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN09_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.请求终端配置,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_0AH 查询参数
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN0A_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.查询参数,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AFN_0CH 请求一类数据
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN0C_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.请求实时数据,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
PRSEQ = 2,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
2025-03-18 15:58:37 +08:00
|
|
|
|
#endregion
|
2025-03-17 11:34:30 +08:00
|
|
|
|
|
2025-03-18 15:58:37 +08:00
|
|
|
|
#region AFN_0DH 请求二类数据
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN0D_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.请求历史数据,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
PRSEQ = 2,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
2025-04-18 11:31:23 +08:00
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
2025-03-18 15:58:37 +08:00
|
|
|
|
#endregion
|
2025-03-17 11:34:30 +08:00
|
|
|
|
|
2025-03-18 15:58:37 +08:00
|
|
|
|
#region AFN10H 数据转发
|
2025-04-18 11:31:23 +08:00
|
|
|
|
public static TelemetryPacketResponse AFN10_Fn_Send(TelemetryPacketRequest request)
|
2025-03-17 11:34:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var reqParameter = new ReqParameter2()
|
|
|
|
|
|
{
|
2025-03-18 15:58:37 +08:00
|
|
|
|
AFN = AFN.数据转发,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
FunCode = (int)CMasterStationFunCode.请求2级数据,
|
2025-03-18 15:58:37 +08:00
|
|
|
|
A = request.FocusAddress,
|
2025-03-17 11:34:30 +08:00
|
|
|
|
Seq = new Seq()
|
|
|
|
|
|
{
|
|
|
|
|
|
TpV = TpV.附加信息域中无时间标签,
|
|
|
|
|
|
FIRFIN = FIRFIN.单帧,
|
|
|
|
|
|
CON = CON.不需要对该帧进行确认,
|
|
|
|
|
|
PRSEQ = 0,
|
|
|
|
|
|
},
|
2025-03-18 15:58:37 +08:00
|
|
|
|
MSA = Build3761SendData.GetMSA(request.FocusAddress),
|
|
|
|
|
|
Pn = request.Pn,
|
|
|
|
|
|
Fn = request.Fn
|
2025-03-17 11:34:30 +08:00
|
|
|
|
};
|
2025-04-18 11:31:23 +08:00
|
|
|
|
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter, request.DataUnit);
|
|
|
|
|
|
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
2025-03-17 11:34:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region SpecialAmmeter 特殊电表转发
|
|
|
|
|
|
//TODO 特殊电表处理
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-03-14 17:28:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|