调整协议池项目组结构
This commit is contained in:
parent
3490fc22f1
commit
710d2a60c4
@ -19,10 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Host", "we
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Common", "shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj", "{AD2F1928-4411-4511-B564-5FB996EC08B9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Protocol", "protocols\JiShe.CollectBus.Protocol\JiShe.CollectBus.Protocol.csproj", "{C62EFF95-5C32-435F-BD78-6977E828F894}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Protocol.Contracts", "protocols\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj", "{38C1808B-009A-418B-B17B-AB3626341B5D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.DbMigrator", "services\JiShe.CollectBus.DbMigrator\JiShe.CollectBus.DbMigrator.csproj", "{8BA01C3D-297D-42DF-BD63-EF07202A0A67}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.FreeSql", "modules\JiShe.CollectBus.FreeSql\JiShe.CollectBus.FreeSql.csproj", "{FE0457D9-4038-4A17-8808-DCAD06CFC0A0}"
|
||||
@ -49,10 +45,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5.Shared", "5.Shared", "{EB
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Kafka.Test", "modules\JiShe.CollectBus.Kafka.Test\JiShe.CollectBus.Kafka.Test.csproj", "{6D6A2A58-7406-9C8C-7B23-3E442CCE3E6B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6.External", "6.External", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6", "6", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.PluginFileWatcher", "external\JiShe.CollectBus.PluginFileWatcher\JiShe.CollectBus.PluginFileWatcher.csproj", "{F767D1C3-6807-4AE3-996A-3A28FE8124C2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Protocol.T1882018", "protocols\JiShe.CollectBus.Protocol.T1882018\JiShe.CollectBus.Protocol.T1882018.csproj", "{430D298B-377E-49B8-83AA-ADC7C0EBDB0F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Protocol.T37612012", "protocols\JiShe.CollectBus.Protocol.T37612012\JiShe.CollectBus.Protocol.T37612012.csproj", "{8A61DF78-069B-40B5-8811-614E2960443E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Protocol", "protocols\JiShe.CollectBus.Protocol\JiShe.CollectBus.Protocol.csproj", "{E27377CC-E2D3-4237-060F-96EA214D3129}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Protocol.T6452007", "protocols\JiShe.CollectBus.Protocol.T6452007\JiShe.CollectBus.Protocol.T6452007.csproj", "{75B7D419-C261-577D-58D6-AA3ACED9129F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -91,14 +95,6 @@ Global
|
||||
{AD2F1928-4411-4511-B564-5FB996EC08B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AD2F1928-4411-4511-B564-5FB996EC08B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AD2F1928-4411-4511-B564-5FB996EC08B9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C62EFF95-5C32-435F-BD78-6977E828F894}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C62EFF95-5C32-435F-BD78-6977E828F894}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C62EFF95-5C32-435F-BD78-6977E828F894}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C62EFF95-5C32-435F-BD78-6977E828F894}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{38C1808B-009A-418B-B17B-AB3626341B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{38C1808B-009A-418B-B17B-AB3626341B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{38C1808B-009A-418B-B17B-AB3626341B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{38C1808B-009A-418B-B17B-AB3626341B5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8BA01C3D-297D-42DF-BD63-EF07202A0A67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8BA01C3D-297D-42DF-BD63-EF07202A0A67}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8BA01C3D-297D-42DF-BD63-EF07202A0A67}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -135,6 +131,22 @@ Global
|
||||
{F767D1C3-6807-4AE3-996A-3A28FE8124C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F767D1C3-6807-4AE3-996A-3A28FE8124C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F767D1C3-6807-4AE3-996A-3A28FE8124C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{430D298B-377E-49B8-83AA-ADC7C0EBDB0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{430D298B-377E-49B8-83AA-ADC7C0EBDB0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{430D298B-377E-49B8-83AA-ADC7C0EBDB0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{430D298B-377E-49B8-83AA-ADC7C0EBDB0F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8A61DF78-069B-40B5-8811-614E2960443E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8A61DF78-069B-40B5-8811-614E2960443E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8A61DF78-069B-40B5-8811-614E2960443E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8A61DF78-069B-40B5-8811-614E2960443E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E27377CC-E2D3-4237-060F-96EA214D3129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E27377CC-E2D3-4237-060F-96EA214D3129}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E27377CC-E2D3-4237-060F-96EA214D3129}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E27377CC-E2D3-4237-060F-96EA214D3129}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{75B7D419-C261-577D-58D6-AA3ACED9129F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75B7D419-C261-577D-58D6-AA3ACED9129F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75B7D419-C261-577D-58D6-AA3ACED9129F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75B7D419-C261-577D-58D6-AA3ACED9129F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -148,8 +160,6 @@ Global
|
||||
{077AA5F8-8B61-420C-A6B5-0150A66FDB34} = {A02F7D8A-04DC-44D6-94D4-3F65712D6B94}
|
||||
{35829A15-4127-4F69-8BDE-9405DEAACA9A} = {A02F7D8A-04DC-44D6-94D4-3F65712D6B94}
|
||||
{AD2F1928-4411-4511-B564-5FB996EC08B9} = {EBF7C01F-9B4F-48E6-8418-2CBFDA51EB0B}
|
||||
{C62EFF95-5C32-435F-BD78-6977E828F894} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{38C1808B-009A-418B-B17B-AB3626341B5D} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{8BA01C3D-297D-42DF-BD63-EF07202A0A67} = {BA4DA3E7-9AD0-47AD-A0E6-A0BB6700DA23}
|
||||
{FE0457D9-4038-4A17-8808-DCAD06CFC0A0} = {2E0FE301-34C3-4561-9CAE-C7A9E65AEE59}
|
||||
{C06C4082-638F-2996-5FED-7784475766C1} = {2E0FE301-34C3-4561-9CAE-C7A9E65AEE59}
|
||||
@ -159,6 +169,10 @@ Global
|
||||
{443B4549-0AC0-4493-8F3E-49C83225DD76} = {2E0FE301-34C3-4561-9CAE-C7A9E65AEE59}
|
||||
{6D6A2A58-7406-9C8C-7B23-3E442CCE3E6B} = {2E0FE301-34C3-4561-9CAE-C7A9E65AEE59}
|
||||
{F767D1C3-6807-4AE3-996A-3A28FE8124C2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{430D298B-377E-49B8-83AA-ADC7C0EBDB0F} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{8A61DF78-069B-40B5-8811-614E2960443E} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{E27377CC-E2D3-4237-060F-96EA214D3129} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{75B7D419-C261-577D-58D6-AA3ACED9129F} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Extensions\**" />
|
||||
<EmbeddedResource Remove="Extensions\**" />
|
||||
<None Remove="Extensions\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="TouchSocket" Version="2.1.9" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\modules\JiShe.CollectBus.FreeRedis\JiShe.CollectBus.FreeRedis.csproj" />
|
||||
<ProjectReference Include="..\..\modules\JiShe.CollectBus.Kafka\JiShe.CollectBus.Kafka.csproj" />
|
||||
<ProjectReference Include="..\..\services\JiShe.CollectBus.Domain\JiShe.CollectBus.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Volo.Abp.Core" Version="8.3.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\services\JiShe.CollectBus.Domain\JiShe.CollectBus.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.T37612012\JiShe.CollectBus.Protocol.T37612012.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy $(TargetDir)JiShe.CollectBus.Protocol.T1882018.dll $(ProjectDir)..\..\web\JiShe.CollectBus.Host\Plugins\" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@ -16,11 +16,11 @@ using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class JiSheCollectBusProtocolModule : AbpModule
|
||||
public class JiSheCollectBusProtocolT1882018Module : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, StandardProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, T1882018ProtocolPlugin>(nameof(T1882018ProtocolPlugin));
|
||||
//RegisterProtocolAnalysis(context.Services);
|
||||
LoadAnalysisStrategy(context.Services);
|
||||
}
|
||||
@ -28,7 +28,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(T1882018ProtocolPlugin));
|
||||
await standardProtocol.LoadAsync();
|
||||
}
|
||||
|
||||
@ -10,30 +10,30 @@ namespace JiShe.CollectBus.Protocol.SendData
|
||||
/// <summary>
|
||||
/// 构建645-2007下发报文
|
||||
/// </summary>
|
||||
public static class Telemetry645PacketBuilder
|
||||
public static class Telemetry1882018PacketBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建报文的委托
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public delegate Telemetry645PacketResponse T645Delegate(Telemetry645PacketRequest request);
|
||||
public delegate Telemetry1882018PacketResponse T6452007Delegate(Telemetry1882018PacketRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 编码与方法的映射表
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, T645Delegate> T645ControlHandlers = new();
|
||||
public static readonly Dictionary<string, T6452007Delegate> T645ControlHandlers = new();
|
||||
|
||||
static Telemetry645PacketBuilder()
|
||||
static Telemetry1882018PacketBuilder()
|
||||
{
|
||||
// 初始化时自动注册所有符合命名规则的方法
|
||||
var methods = typeof(Telemetry645PacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
var methods = typeof(Telemetry1882018PacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
if (method.Name.StartsWith("C") && method.Name.EndsWith("_Send"))
|
||||
{
|
||||
string code = method.Name;
|
||||
var delegateInstance = (T645Delegate)Delegate.CreateDelegate(typeof(T645Delegate), method);
|
||||
var delegateInstance = (T6452007Delegate)Delegate.CreateDelegate(typeof(T6452007Delegate), method);
|
||||
T645ControlHandlers[code] = delegateInstance;
|
||||
}
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace JiShe.CollectBus.Protocol.SendData
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry645PacketResponse C1C_01_Send(Telemetry645PacketRequest request)
|
||||
public static Telemetry1882018PacketResponse C1C_01_Send(Telemetry1882018PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];
|
||||
@ -68,7 +68,7 @@ namespace JiShe.CollectBus.Protocol.SendData
|
||||
var dataUnit = strSJY.Replace(" ", "").StringToPairs();
|
||||
|
||||
var dataList = Build645SendData.Build645SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
return new Telemetry645PacketResponse() { Data = dataList };
|
||||
return new Telemetry1882018PacketResponse() { Data = dataList };
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ namespace JiShe.CollectBus.Protocol.SendData
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry645PacketResponse C1C_03_Send(Telemetry645PacketRequest request)
|
||||
public static Telemetry1882018PacketResponse C1C_03_Send(Telemetry1882018PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];
|
||||
@ -99,7 +99,7 @@ namespace JiShe.CollectBus.Protocol.SendData
|
||||
var dataUnit = strSJY.Replace(" ", "").StringToPairs();
|
||||
|
||||
var dataList = Build645SendData.Build645SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
return new Telemetry645PacketResponse() { Data = dataList };
|
||||
return new Telemetry1882018PacketResponse() { Data = dataList };
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// 构建645报文参数
|
||||
/// </summary>
|
||||
public class Telemetry645PacketRequest
|
||||
public class Telemetry1882018PacketRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 表地址
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// 返回645报文结果
|
||||
/// </summary>
|
||||
public class Telemetry645PacketResponse
|
||||
public class Telemetry1882018PacketResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文体
|
||||
@ -0,0 +1,506 @@
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Helpers;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.Enums;
|
||||
using JiShe.CollectBus.IotSystems.Devices;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Kafka.Producer;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using JiShe.CollectBus.Protocol.SendData;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TouchSocket.Sockets;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class T1882018ProtocolPlugin : T37612012ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<T1882018ProtocolPlugin> _logger;
|
||||
|
||||
private readonly IProducerService _producerService;
|
||||
|
||||
private readonly IRepository<Device, Guid> _deviceRepository;
|
||||
private readonly ITcpService _tcpService;
|
||||
|
||||
public readonly Dictionary<string, Telemetry3761PacketBuilder.T3761Delegate> T3761AFNHandlers;
|
||||
public readonly Dictionary<string, Telemetry1882018PacketBuilder.T6452007Delegate> T645ControlHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T1882018ProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public T1882018ProtocolPlugin(IServiceProvider serviceProvider, ILogger<T1882018ProtocolPlugin> logger, ITcpService tcpService) : base(serviceProvider, logger)
|
||||
{
|
||||
_logger = logger;
|
||||
//_logger = serviceProvider.GetRequiredService<ILogger<StandardProtocolPlugin>>();
|
||||
_producerService = serviceProvider.GetRequiredService<IProducerService>();
|
||||
_deviceRepository = serviceProvider.GetRequiredService<IRepository<Device, Guid>>();
|
||||
_tcpService = tcpService;
|
||||
T3761AFNHandlers = Telemetry3761PacketBuilder.T3761AFNHandlers;
|
||||
T645ControlHandlers = Telemetry1882018PacketBuilder.T645ControlHandlers;
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(T1882018ProtocolPlugin), "376.1", "TCP", "376.1协议", "DTS1980");
|
||||
|
||||
public override async Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? sendAction = null)
|
||||
{
|
||||
TB3761? tB3761 = Analysis3761(messageReceived);
|
||||
if (tB3761 != null)
|
||||
{
|
||||
if (tB3761.AFN_FC?.AFN == (int)AFN.链路接口检测)
|
||||
{
|
||||
if (tB3761.A == null || tB3761.A.Code.IsNullOrWhiteSpace() || tB3761.A.A3?.D1_D7 == null || tB3761.SEQ?.PSEQ == null)
|
||||
{
|
||||
_logger.LogError($"解析AFN.链路接口检测报文失败,报文:{messageReceived},TB3761:{tB3761.Serialize()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tB3761.DT?.Fn == (int)FN.登录)
|
||||
{
|
||||
// 登录回复
|
||||
if (tB3761.SEQ.CON == (int)CON.需要对该帧进行确认)
|
||||
await LoginAsync(client, messageReceived, tB3761.A.Code, tB3761.A.A3?.D1_D7, tB3761.SEQ?.PSEQ);
|
||||
}
|
||||
else if (tB3761.DT?.Fn == (int)FN.心跳)
|
||||
{
|
||||
// 心跳回复
|
||||
//心跳帧有两种情况:
|
||||
//1. 集中器先有登录帧,再有心跳帧
|
||||
//2. 集中器没有登录帧,只有心跳帧
|
||||
await HeartbeatAsync(client, messageReceived, tB3761.A.Code, tB3761.A.A3?.D1_D7, tB3761.SEQ?.PSEQ);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
await OnTcpNormalReceived(client, tB3761);
|
||||
}
|
||||
return (tB3761 as T)!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 正常帧处理,将不同的AFN进行分发
|
||||
/// </summary>
|
||||
/// <param name="tcpSessionClient"></param>
|
||||
/// <param name="messageHexString"></param>
|
||||
/// <param name="tB3761"></param>
|
||||
/// <returns></returns>
|
||||
private async Task OnTcpNormalReceived(ITcpSessionClient tcpSessionClient, TB3761 tB3761)
|
||||
{
|
||||
//string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, aFn);
|
||||
//todo 如何确定时标?目前集中器的采集频率,都是固定,数据上报的时候,根据当前时间,往后推测出应当采集的时间点作为时标。但是如果由于网络问题,数据一直没上报的情况改怎么计算?
|
||||
//await _producerBus.PublishAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived
|
||||
//{
|
||||
// ClientId = client.Id,
|
||||
// ClientIp = client.IP,
|
||||
// ClientPort = client.Port,
|
||||
// MessageHexString = messageHexString,
|
||||
// DeviceNo = deviceNo,
|
||||
// MessageId = NewId.NextGuid().ToString()
|
||||
//});
|
||||
|
||||
if (tB3761.AFN_FC.BaseHexMessage == null || tB3761.DT.BaseHexMessage == null || tB3761.BaseHexMessage.HexMessageString==null)
|
||||
{
|
||||
_logger.LogError("376.1协议解析AFN失败");
|
||||
return;
|
||||
}
|
||||
// 登录心跳已做了处理,故需要忽略登录和心跳帧
|
||||
if (tB3761.DT.Fn == (int)FN.登录 || tB3761.DT.Fn == (int)FN.心跳)
|
||||
return;
|
||||
//TODO:根据AFN进行分流推送到kafka
|
||||
string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, tB3761.AFN_FC.AFN.ToString().PadLeft(2, '0'));
|
||||
|
||||
MessageProtocolAnalysis<TB3761> messageReceivedAnalysis = new MessageProtocolAnalysis<TB3761>()
|
||||
{
|
||||
ClientId = tcpSessionClient.Id,
|
||||
ClientIp = tcpSessionClient.IP,
|
||||
ClientPort = tcpSessionClient.Port,
|
||||
MessageHexString = tB3761.BaseHexMessage.HexMessageString!,
|
||||
DeviceNo = tB3761.A.Code!,
|
||||
MessageId = Guid.NewGuid().ToString(),
|
||||
ReceivedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Data = tB3761
|
||||
};
|
||||
|
||||
List<string> topics = ProtocolConstExtensions.GetAllTopicNamesByReceived();
|
||||
if (topics.Contains(topicName))
|
||||
await _producerService.ProduceAsync(topicName, messageReceivedAnalysis);
|
||||
else
|
||||
{
|
||||
_logger.LogError($"不支持的上报kafka主题:{topicName}");
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberReceivedEventName, messageReceivedAnalysis);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录回复
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="msa"></param>
|
||||
/// <param name="pseq"></param>
|
||||
/// <returns></returns>
|
||||
public async Task LoginAsync(ITcpSessionClient client, string messageReceived, string code, int? msa, int? pseq)
|
||||
{
|
||||
string oldClientId = $"{client.Id}";
|
||||
await client.ResetIdAsync(code);
|
||||
var deviceInfoList = await _deviceRepository.GetListAsync(a => a.Number == code);
|
||||
if (deviceInfoList != null && deviceInfoList.Count > 1)
|
||||
{
|
||||
//todo 推送集中器编号重复预警
|
||||
_logger.LogError($"集中器编号:{code},存在多个集中器,请检查集中器编号是否重复");
|
||||
return;
|
||||
}
|
||||
|
||||
var entity = deviceInfoList?.FirstOrDefault(a => a.Number == code);
|
||||
if (entity == null)
|
||||
{
|
||||
await _deviceRepository.InsertAsync(new Device(code, oldClientId, DateTime.Now, DateTime.Now, DeviceStatus.Online));
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.UpdateByLoginAndHeartbeat(oldClientId);
|
||||
await _deviceRepository.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
var messageReceivedLoginEvent = new MessageReceivedLogin
|
||||
{
|
||||
ClientId = code,
|
||||
ClientIp = client.IP,
|
||||
ClientPort = client.Port,
|
||||
MessageHexString = messageReceived,
|
||||
DeviceNo = code,
|
||||
MessageId = Guid.NewGuid().ToString(),
|
||||
ReceivedTime=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberLoginReceivedEventName, messageReceivedLoginEvent);
|
||||
var reqParam = new ReqParameter2
|
||||
{
|
||||
AFN = AFN.确认或否认,
|
||||
FunCode = (int)CFromStationFunCode.链路数据,
|
||||
PRM = PRM.从动站报文,
|
||||
A = code,
|
||||
Seq = new Seq()
|
||||
{
|
||||
TpV = TpV.附加信息域中无时间标签,
|
||||
FIRFIN = FIRFIN.单帧,
|
||||
CON = CON.需要对该帧进行确认,
|
||||
PRSEQ = pseq!.Value
|
||||
},
|
||||
MSA = msa!.Value,
|
||||
Pn = 0,
|
||||
Fn = 1
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParam);
|
||||
var issuedEventMessage = new IssuedEventMessage
|
||||
{
|
||||
ClientId = messageReceivedLoginEvent.ClientId,
|
||||
DeviceNo = messageReceivedLoginEvent.DeviceNo,
|
||||
Message = bytes,
|
||||
Type = IssuedEventType.Login,
|
||||
MessageId = messageReceivedLoginEvent.MessageId
|
||||
};
|
||||
if (_tcpService.ClientExists(issuedEventMessage.ClientId))
|
||||
{
|
||||
await _tcpService.SendAsync(issuedEventMessage.ClientId, issuedEventMessage.Message);
|
||||
_logger.LogInformation($"集中器地址{issuedEventMessage.ClientId} 登录回复下发内容:{Convert.ToHexString(bytes)}");
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberLoginIssuedEventName, issuedEventMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 心跳帧解析
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="msa"></param>
|
||||
/// <param name="pseq"></param>
|
||||
/// <returns></returns>
|
||||
public async Task HeartbeatAsync(ITcpSessionClient client, string messageReceived, string code, int? msa, int? pseq)
|
||||
{
|
||||
|
||||
string clientId = code;
|
||||
string oldClientId = $"{client.Id}";
|
||||
var deviceInfoList = await _deviceRepository.GetListAsync(a => a.Number == code);
|
||||
if (deviceInfoList != null && deviceInfoList.Count > 1)
|
||||
{
|
||||
//todo 推送集中器编号重复预警
|
||||
_logger.LogError($"集中器编号:{code},存在多个集中器,请检查集中器编号是否重复");
|
||||
return;
|
||||
}
|
||||
|
||||
var entity = deviceInfoList?.FirstOrDefault(a => a.Number == code);
|
||||
if (entity == null) //没有登录帧的设备,只有心跳帧
|
||||
{
|
||||
await client.ResetIdAsync(clientId);
|
||||
await _deviceRepository.InsertAsync(new Device(code, oldClientId, DateTime.Now, DateTime.Now, DeviceStatus.Online));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientId != oldClientId)
|
||||
{
|
||||
entity.UpdateByLoginAndHeartbeat(oldClientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.UpdateByLoginAndHeartbeat();
|
||||
}
|
||||
|
||||
await _deviceRepository.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
var messageReceivedHeartbeatEvent = new MessageReceivedHeartbeat
|
||||
{
|
||||
ClientId = clientId,
|
||||
ClientIp = client.IP,
|
||||
ClientPort = client.Port,
|
||||
MessageHexString = messageReceived,
|
||||
DeviceNo = code,
|
||||
MessageId = Guid.NewGuid().ToString(),
|
||||
ReceivedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberHeartbeatReceivedEventName, messageReceivedHeartbeatEvent);
|
||||
|
||||
var reqParam = new ReqParameter2()
|
||||
{
|
||||
AFN = AFN.确认或否认,
|
||||
FunCode = (int)CFromStationFunCode.链路数据,
|
||||
PRM = PRM.从动站报文,
|
||||
A = code,
|
||||
Seq = new Seq()
|
||||
{
|
||||
TpV = TpV.附加信息域中无时间标签,
|
||||
FIRFIN = FIRFIN.单帧,
|
||||
CON = CON.不需要对该帧进行确认,
|
||||
PRSEQ = pseq!.Value,
|
||||
},
|
||||
MSA = msa!.Value,
|
||||
Pn = 0,
|
||||
Fn = 1
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParam);
|
||||
|
||||
IssuedEventMessage issuedEventMessage = new IssuedEventMessage
|
||||
{
|
||||
ClientId = messageReceivedHeartbeatEvent.ClientId,
|
||||
DeviceNo = messageReceivedHeartbeatEvent.DeviceNo,
|
||||
Message = bytes,
|
||||
Type = IssuedEventType.Heartbeat,
|
||||
MessageId = messageReceivedHeartbeatEvent.MessageId
|
||||
};
|
||||
if (_tcpService.ClientExists(issuedEventMessage.ClientId))
|
||||
{
|
||||
await _tcpService.SendAsync(issuedEventMessage.ClientId, bytes);
|
||||
_logger.LogWarning($"集中器地址{issuedEventMessage.ClientId} 心跳回复下发内容:{Convert.ToHexString(bytes)}");
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberHeartbeatIssuedEventName, issuedEventMessage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组装报文
|
||||
/// </summary>
|
||||
/// <param name="request">报文构建参数</param>
|
||||
/// <returns></returns>
|
||||
public override async Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception($"{nameof(T1882018ProtocolPlugin)} 报文构建失败,参数为空");
|
||||
}
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var aFNStr = itemCodeArr[0];
|
||||
var aFN = (AFN)aFNStr.HexToDec();
|
||||
var fn = int.Parse(itemCodeArr[1]);
|
||||
Telemetry3761PacketResponse builderResponse = null;
|
||||
|
||||
List<string> dataUnit = new List<string>();
|
||||
//数据转发场景 10H_F1_1CH
|
||||
if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false)
|
||||
{
|
||||
var t645PacketHandlerName = $"C{request.SubProtocolRequest.ItemCode}_Send";
|
||||
Telemetry1882018PacketResponse t645PacketResponse = null;
|
||||
|
||||
if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(t645PacketHandlerName
|
||||
, out var t645PacketHandler))
|
||||
{
|
||||
t645PacketResponse = t645PacketHandler(new Telemetry1882018PacketRequest()
|
||||
{
|
||||
MeterAddress = request.SubProtocolRequest.MeterAddress,
|
||||
Password = request.SubProtocolRequest.Password,
|
||||
ItemCode = request.SubProtocolRequest.ItemCode,
|
||||
});
|
||||
}
|
||||
|
||||
if (t645PacketResponse != null)
|
||||
{
|
||||
dataUnit = t645PacketResponse.Data;
|
||||
}
|
||||
}
|
||||
|
||||
string afnMethonCode = $"AFN{aFNStr}_Fn_Send";
|
||||
if (T3761AFNHandlers != null && T3761AFNHandlers.TryGetValue(afnMethonCode
|
||||
, out var handler))
|
||||
{
|
||||
builderResponse = handler(new Telemetry3761PacketRequest()
|
||||
{
|
||||
FocusAddress = request.FocusAddress,
|
||||
Fn = fn,
|
||||
Pn = request.Pn,
|
||||
DataUnit = dataUnit,
|
||||
});
|
||||
}
|
||||
|
||||
if (builderResponse == null)
|
||||
{
|
||||
return new ProtocolBuildResponse();
|
||||
}
|
||||
|
||||
var result = builderResponse.Adapt<ProtocolBuildResponse>();
|
||||
result.IsSuccess = true;
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
|
||||
#region 上行命令
|
||||
|
||||
//68
|
||||
//32 00
|
||||
//32 00
|
||||
//68
|
||||
//C9 1100'1001. 控制域C。
|
||||
// D7=1, (终端发送)上行方向。
|
||||
// D6=1, 此帧来自启动站。
|
||||
// D5=0, (上行方向)要求访问位。表示终端无事件数据等待访问。
|
||||
// D4=0, 保留
|
||||
// D3~D0=9, 功能码。链路测试
|
||||
|
||||
//20 32 行政区划码
|
||||
//90 26 终端地址
|
||||
//00 主站地址和组地址标志。终端为单地址。 //3220 09 87 2
|
||||
// 终端启动的发送帧的 MSA 应为 0, 其主站响应帧的 MSA 也应为 0.
|
||||
//02 应用层功能码。AFN=2, 链路接口检测
|
||||
//70 0111'0000. 帧序列域。无时间标签、单帧、需要确认。
|
||||
//00 00 信息点。DA1和DA2全为“0”时,表示终端信息点。
|
||||
//01 00 信息类。F1, 登录。
|
||||
//44 帧尾,包含用户区数据校验和
|
||||
//16 帧结束标志
|
||||
|
||||
/// <summary>
|
||||
/// 解析上行命令
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
/// <returns></returns>
|
||||
public CommandReulst? AnalysisCmd(string cmd)
|
||||
{
|
||||
CommandReulst? commandReulst = null;
|
||||
var hexStringList = cmd.StringToPairs();
|
||||
|
||||
if (hexStringList.Count < hearderLen)
|
||||
{
|
||||
return commandReulst;
|
||||
}
|
||||
//验证起始字符
|
||||
if (!hexStringList[0].IsStartStr() || !hexStringList[5].IsStartStr())
|
||||
{
|
||||
return commandReulst;
|
||||
}
|
||||
|
||||
var lenHexStr = $"{hexStringList[2]}{hexStringList[1]}";
|
||||
var lenBin = lenHexStr.HexToBin();
|
||||
var len = lenBin.Remove(lenBin.Length - 2).BinToDec();
|
||||
//验证长度
|
||||
if (hexStringList.Count - 2 != hearderLen + len)
|
||||
return commandReulst;
|
||||
|
||||
var userDataIndex = hearderLen;
|
||||
var c = hexStringList[userDataIndex];//控制域 1字节
|
||||
userDataIndex += 1;
|
||||
|
||||
var aHexList = hexStringList.Skip(userDataIndex).Take(5).ToList();//地址域 5字节
|
||||
var a = AnalysisA(aHexList);
|
||||
var a3Bin = aHexList[4].HexToBin().PadLeft(8, '0');
|
||||
var mSA = a3Bin.Substring(0, 7).BinToDec();
|
||||
userDataIndex += 5;
|
||||
|
||||
var aFN = (AFN)hexStringList[userDataIndex].HexToDec();//1字节
|
||||
userDataIndex += 1;
|
||||
|
||||
var seq = hexStringList[userDataIndex].HexToBin().PadLeft(8, '0');
|
||||
var tpV = (TpV)Convert.ToInt32(seq.Substring(0, 1));
|
||||
var fIRFIN = (FIRFIN)Convert.ToInt32(seq.Substring(1, 2));
|
||||
var cON = (CON)Convert.ToInt32(seq.Substring(3, 1));
|
||||
var prseqBin = seq.Substring(4, 4);
|
||||
userDataIndex += 1;
|
||||
|
||||
// (DA2 - 1) * 8 + DA1 = pn
|
||||
var da1Bin = hexStringList[userDataIndex].HexToBin();
|
||||
var da1 = da1Bin == "0" ? 0 : da1Bin.Length;
|
||||
userDataIndex += 1;
|
||||
var da2 = hexStringList[userDataIndex].HexToDec();
|
||||
var pn = da2 == 0 ? 0 : (da2 - 1) * 8 + da1;
|
||||
userDataIndex += 1;
|
||||
//(DT2*8)+DT1=fn
|
||||
var dt1Bin = hexStringList[userDataIndex].HexToBin();
|
||||
var dt1 = dt1Bin != "0" ? dt1Bin.Length : 0;
|
||||
userDataIndex += 1;
|
||||
var dt2 = hexStringList[userDataIndex].HexToDec();
|
||||
var fn = dt2 * 8 + dt1;
|
||||
userDataIndex += 1;
|
||||
|
||||
//数据单元
|
||||
var datas = hexStringList.Skip(userDataIndex).Take(len + hearderLen - userDataIndex).ToList();
|
||||
|
||||
//EC
|
||||
//Tp
|
||||
commandReulst = new CommandReulst()
|
||||
{
|
||||
A = a,
|
||||
MSA = mSA,
|
||||
AFN = aFN,
|
||||
Seq = new Seq()
|
||||
{
|
||||
TpV = tpV,
|
||||
FIRFIN = fIRFIN,
|
||||
CON = cON,
|
||||
PRSEQ = prseqBin.BinToDec(),
|
||||
},
|
||||
CmdLength = len,
|
||||
Pn = pn,
|
||||
Fn = fn,
|
||||
HexDatas = datas
|
||||
};
|
||||
|
||||
return commandReulst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析地址
|
||||
/// </summary>
|
||||
/// <param name="aHexList"></param>
|
||||
/// <returns></returns>
|
||||
private string AnalysisA(List<string> aHexList)
|
||||
{
|
||||
var a1 = aHexList[1] + aHexList[0];
|
||||
var a2 = aHexList[3] + aHexList[2];
|
||||
var a2Dec = a2.HexToDec();
|
||||
var a3 = aHexList[4];
|
||||
var a = $"{a1}{a2Dec.ToString().PadLeft(5, '0')}";
|
||||
return a;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,405 @@
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.FreeRedis;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TouchSocket.Sockets;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Abstracts
|
||||
{
|
||||
public abstract class T37612012ProtocolPlugin : IProtocolPlugin
|
||||
{
|
||||
//头部字节长度
|
||||
public const int hearderLen = 6;
|
||||
|
||||
public const int tPLen = 6;
|
||||
|
||||
public const string errorData = "EE";
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRepository<ProtocolInfo, Guid> _protocolInfoRepository;
|
||||
private readonly IFreeRedisProvider _redisProvider;
|
||||
|
||||
public T37612012ProtocolPlugin(IServiceProvider serviceProvider, ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_protocolInfoRepository = serviceProvider.GetRequiredService<IRepository<ProtocolInfo, Guid>>();
|
||||
_redisProvider = serviceProvider.GetRequiredService<IFreeRedisProvider>();
|
||||
}
|
||||
|
||||
|
||||
public abstract ProtocolInfo Info { get; }
|
||||
|
||||
public virtual async Task<ProtocolInfo> GetAsync() => await Task.FromResult(Info);
|
||||
|
||||
public virtual async Task LoadAsync()
|
||||
{
|
||||
if (Info == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Info));
|
||||
}
|
||||
|
||||
await _protocolInfoRepository.DeleteDirectAsync(a => a.Name == Info.Name);
|
||||
await _protocolInfoRepository.InsertAsync(Info);
|
||||
await _redisProvider.Instance.HDelAsync($"{RedisConst.ProtocolKey}", Info.Name);
|
||||
await _redisProvider.Instance.HSetAsync($"{RedisConst.ProtocolKey}", Info.Name, Info);
|
||||
}
|
||||
|
||||
public abstract Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null) where T : class;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解析376.1帧
|
||||
/// </summary>
|
||||
/// <param name="messageReceived"></param>
|
||||
/// <returns></returns>
|
||||
public virtual TB3761? Analysis3761(string messageReceived)
|
||||
{
|
||||
try
|
||||
{
|
||||
var hexStringList = messageReceived.StringToPairs();
|
||||
// 初步校验
|
||||
if (hexStringList.Count < 6 || hexStringList.FirstOrDefault() != "68" || hexStringList.Skip(5).Take(1).FirstOrDefault() != "68" || hexStringList.Count < 18 || hexStringList.LastOrDefault() != "16")
|
||||
{
|
||||
_logger.LogError($"解析Analysis3761校验不通过,报文:{messageReceived}");
|
||||
}
|
||||
else
|
||||
{
|
||||
TB3761 tB3761 = new TB3761
|
||||
{
|
||||
BaseHexMessage = new BaseHexMessage
|
||||
{
|
||||
HexMessageString = messageReceived,
|
||||
HexMessageList = hexStringList
|
||||
},
|
||||
C = Analysis_C(hexStringList),
|
||||
A = Analysis_A(hexStringList),
|
||||
AFN_FC = Analysis_AFN_FC(hexStringList),
|
||||
SEQ = Analysis_SEQ(hexStringList),
|
||||
UnitData = Analysis_UnitData(hexStringList),
|
||||
DA = Analysis_DA(hexStringList),
|
||||
DT = Analysis_DT(hexStringList)
|
||||
};
|
||||
return tB3761;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"解析Analysis3761错误,报文:{messageReceived},异常:{ex.Message}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制域C解析
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual C Analysis_C(List<string> hexStringList)
|
||||
{
|
||||
C c = new C();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count > 6)
|
||||
{
|
||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||
{
|
||||
HexMessageList = hexStringList.GetRange(6, 1) // 控制域 1字节
|
||||
};
|
||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||
if (baseHexMessage.HexMessageList.Count == 0)
|
||||
return null;
|
||||
string binStr = baseHexMessage.HexMessageString.HexTo4BinZero();
|
||||
c = new C
|
||||
{
|
||||
BaseHexMessage = baseHexMessage,
|
||||
FC = binStr.Substring(binStr.Length - 4, 4).BinToDec(),
|
||||
FCV = binStr.Substring(3, 1).BinToDec(),
|
||||
FCB = binStr.Substring(2, 1).BinToDec(),
|
||||
PRM = binStr.Substring(1, 1).BinToDec(),
|
||||
DIR = binStr.Substring(0, 1).BinToDec()
|
||||
};
|
||||
return c;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"解析Analysis_C错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 地址域A解析
|
||||
/// </summary>
|
||||
/// <param name="hexStringList"></param>
|
||||
/// <returns></returns>
|
||||
public virtual A Analysis_A(List<string> hexStringList)
|
||||
{
|
||||
A a = new A();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count > 7)
|
||||
{
|
||||
BaseHexMessage baseHexMessage = new BaseHexMessage
|
||||
{
|
||||
HexMessageList = hexStringList.GetRange(7, 5) // 地址域 5个字节
|
||||
};
|
||||
baseHexMessage.HexMessageString = string.Join("", baseHexMessage.HexMessageList);
|
||||
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')}";
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"解析Analysis_A错误,报文:{string.Join("", hexStringList)},异常:{ex.Message}");
|
||||
}
|
||||
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 站地址和组地址标志A3
|
||||
/// </summary>
|
||||
/// <param name="hexAList">地址域A集合</param>
|
||||
/// <returns></returns>
|
||||
public virtual A3 Analysis_A3(List<string> hexAList)
|
||||
{
|
||||
A3 a3 = new A3();
|
||||
try
|
||||
{
|
||||
if (hexAList.Count != 0)
|
||||
{
|
||||
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 a3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AFN_FC功能码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual AFN_FC Analysis_AFN_FC(List<string> hexStringList)
|
||||
{
|
||||
AFN_FC aFN_FC = new AFN_FC();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count == 0)
|
||||
{
|
||||
|
||||
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 aFN_FC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析帧序列域SEQ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual SEQ Analysis_SEQ(List<string> hexStringList)
|
||||
{
|
||||
SEQ seq = new SEQ();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count != 0)
|
||||
{
|
||||
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 seq;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据单元标识及数据单元数据
|
||||
/// </summary>
|
||||
public virtual UnitData Analysis_UnitData(List<string> hexStringList)
|
||||
{
|
||||
UnitData unitData = new UnitData();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count != 0)
|
||||
{
|
||||
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 unitData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信息点DA Pn
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual DA Analysis_DA(List<string> hexStringList)
|
||||
{
|
||||
DA da = new DA();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count != 0)
|
||||
{
|
||||
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 da;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 信息类DT Fn
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual DT Analysis_DT(List<string> hexStringList)
|
||||
{
|
||||
DT dt = new DT();
|
||||
try
|
||||
{
|
||||
if (hexStringList.Count != 0)
|
||||
{
|
||||
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 dt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算Pn
|
||||
/// </summary>
|
||||
/// <param name="da1"></param>
|
||||
/// <param name="da2"></param>
|
||||
/// <returns></returns>
|
||||
public static int CalculatePn(string da1, string da2) => (da2.HexToDec() - 1) * 8 + (8 - da1.HexTo4BinZero().IndexOf(da1.Equals("00") ? "0" : "1"));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算Fn
|
||||
/// </summary>
|
||||
/// <param name="dt1"></param>
|
||||
/// <param name="dt2"></param>
|
||||
/// <returns></returns>
|
||||
public static int CalculateFn(string dt1, string dt2) => dt2.HexToDec() * 8 + (8 - dt1.HexTo4BinZero().IndexOf("1"));
|
||||
|
||||
#region 下行命令构建
|
||||
|
||||
/// <summary>
|
||||
/// 组装报文
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="entity">设备数据实体</param>
|
||||
/// <param name="afnFnCode">映射读取执行方法的Code,例如10_1,表示 10H_F1_00000,10H_F1_00001,统一英文下划线分隔</param>
|
||||
/// <returns></returns>
|
||||
public abstract Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
using JiShe.CollectBus.FreeRedis.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts
|
||||
{
|
||||
public class CollectBusProtocolT37612012Module : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Volo.Abp.Core" Version="8.3.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\services\JiShe.CollectBus.Domain\JiShe.CollectBus.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy $(TargetDir)JiShe.CollectBus.Protocol.T37612012.dll $(ProjectDir)..\..\web\JiShe.CollectBus.Host\Plugins\" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath></BaseOutputPath>
|
||||
<LangVersion>preview</LangVersion>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Volo.Abp.Core" Version="8.3.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\services\JiShe.CollectBus.Domain\JiShe.CollectBus.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.T37612012\JiShe.CollectBus.Protocol.T37612012.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy $(TargetDir)JiShe.CollectBus.Protocol.T6452007.dll $(ProjectDir)..\..\web\JiShe.CollectBus.Host\Plugins\" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,111 @@
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData;
|
||||
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.Dto;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Core;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class JiSheCollectBusProtocolT6452007Module : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, T6452007ProtocolPlugin>(nameof(T6452007ProtocolPlugin));
|
||||
//RegisterProtocolAnalysis(context.Services);
|
||||
LoadAnalysisStrategy(context.Services);
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(T6452007ProtocolPlugin));
|
||||
await standardProtocol.LoadAsync();
|
||||
}
|
||||
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin OnApplicationShutdown");
|
||||
base.OnApplicationShutdown(context);
|
||||
}
|
||||
|
||||
public void LoadAnalysisStrategy(IServiceCollection services)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var analysisStrategyTypes = assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IAnalysisStrategy<,>)));
|
||||
foreach (var analysisStrategyType in analysisStrategyTypes)
|
||||
{
|
||||
var service = analysisStrategyType.GetInterfaces().First();
|
||||
services.AddKeyedSingleton(service, analysisStrategyType.Name,analysisStrategyType);
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterProtocolAnalysis(IServiceCollection services)
|
||||
{
|
||||
// 扫描并注册所有策略
|
||||
var strategyMetadata = new Dictionary<(string, Type, Type), Type>();
|
||||
services.AddTransient<AnalysisStrategyContext>();
|
||||
|
||||
// 批量注册
|
||||
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
if (string.IsNullOrWhiteSpace(assemblyPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dllFiles = Directory.GetFiles(Path.Combine(assemblyPath, "Plugins") , "*.dll");
|
||||
foreach (var file in dllFiles)
|
||||
{
|
||||
// 跳过已加载的程序集
|
||||
var assemblyName = AssemblyName.GetAssemblyName(file);
|
||||
var existingAssembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.FirstOrDefault(a => a.GetName().FullName == assemblyName.FullName);
|
||||
var assembly = existingAssembly ?? Assembly.LoadFrom(file);
|
||||
// 实现IAnalysisStrategy接口
|
||||
var analysisStrategyTypes = assembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IAnalysisStrategy<,>)));
|
||||
if (!analysisStrategyTypes.Any())
|
||||
continue;
|
||||
foreach (var analysisStrategyType in analysisStrategyTypes)
|
||||
{
|
||||
// 通过反射获取静态元数据
|
||||
var strategyType = analysisStrategyType.Name;
|
||||
var genericArgs = analysisStrategyType.GetInterface($"IAnalysisStrategy`2")!.GetGenericArguments();
|
||||
var inputType = genericArgs[0];
|
||||
var resultType = genericArgs[1];
|
||||
// 注册策略实现
|
||||
services.AddTransient(analysisStrategyType);
|
||||
strategyMetadata[(strategyType, inputType, resultType)] = analysisStrategyType;
|
||||
}
|
||||
}
|
||||
|
||||
// 注册元数据字典
|
||||
services.AddSingleton(strategyMetadata);
|
||||
|
||||
// 注册策略解析工厂
|
||||
services.AddTransient<Func<string, Type, Type, object?>>(provider => (name, inputType, resultType) =>
|
||||
{
|
||||
var metadata = provider.GetRequiredService<Dictionary<(string, Type, Type), Type>>();
|
||||
if (metadata.TryGetValue((name, inputType, resultType), out var strategyType))
|
||||
{
|
||||
return provider.GetRequiredService(strategyType);
|
||||
}
|
||||
else
|
||||
{
|
||||
var logger= provider.GetRequiredService<ILogger<AnalysisStrategyContext>>();
|
||||
logger.LogWarning($"未能找到解析策略:{name}-{inputType}-{resultType}");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
using FreeSql;
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建645-2007下发报文
|
||||
/// </summary>
|
||||
public static class Telemetry6452007PacketBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建报文的委托
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public delegate Telemetry6452007PacketResponse T6452007Delegate(Telemetry6452007PacketRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 编码与方法的映射表
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, T6452007Delegate> T645ControlHandlers = new();
|
||||
|
||||
static Telemetry6452007PacketBuilder()
|
||||
{
|
||||
// 初始化时自动注册所有符合命名规则的方法
|
||||
var methods = typeof(Telemetry6452007PacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
if (method.Name.StartsWith("C") && method.Name.EndsWith("_Send"))
|
||||
{
|
||||
string code = method.Name;
|
||||
var delegateInstance = (T6452007Delegate)Delegate.CreateDelegate(typeof(T6452007Delegate), method);
|
||||
T645ControlHandlers[code] = delegateInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 1CH 跳合闸、报警、保电
|
||||
|
||||
/// <summary>
|
||||
/// 1CH 跳合闸
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry6452007PacketResponse C1C_01_Send(Telemetry6452007PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];
|
||||
var n_data = itemCodeArr[1];
|
||||
string password = request.Password;
|
||||
string pwdLevel = "02";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(password) && password.Contains("|"))
|
||||
{
|
||||
var sp = password.Split('|');
|
||||
password = sp[0];
|
||||
pwdLevel = sp[1];
|
||||
}
|
||||
|
||||
var strDate = DateTime.Now.AddYears(3).ToString("000012ddMMyy").StrAddSpan();//命令有效截止时间
|
||||
|
||||
var strP = password.StrAddSpan().StrReverseOrder();
|
||||
var strSJY = " " + pwdLevel + " " + strP + " 01 00 00 00 " + n_data + " 00 " + strDate;
|
||||
var dataUnit = strSJY.Replace(" ", "").StringToPairs();
|
||||
|
||||
var dataList = Build645SendData.Build645SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
return new Telemetry6452007PacketResponse() { Data = dataList };
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 1CH 保电
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry6452007PacketResponse C1C_03_Send(Telemetry6452007PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];
|
||||
var n_data = itemCodeArr[1];
|
||||
string password = request.Password;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(password) && password.Contains("|"))
|
||||
{
|
||||
var sp = password.Split('|');
|
||||
password = sp[0];
|
||||
}
|
||||
|
||||
var strDate = (n_data + DateTime.Now.AddDays(1).ToString("00000012ddMMyy")).StrAddSpan();
|
||||
|
||||
var strP = password.StrAddSpan().StrReverseOrder();
|
||||
|
||||
var strSJY = " 02 " + strP + " 01 00 00 00 " + strDate;
|
||||
|
||||
var dataUnit = strSJY.Replace(" ", "").StringToPairs();
|
||||
|
||||
var dataList = Build645SendData.Build645SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
return new Telemetry6452007PacketResponse() { Data = dataList };
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
namespace JiShe.CollectBus.Protocol.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建645报文参数
|
||||
/// </summary>
|
||||
public class Telemetry6452007PacketRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 表地址
|
||||
/// </summary>
|
||||
public required string MeterAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public required string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作码
|
||||
/// </summary>
|
||||
public required string ItemCode { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
namespace JiShe.CollectBus.Protocol.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回645报文结果
|
||||
/// </summary>
|
||||
public class Telemetry6452007PacketResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文体
|
||||
/// </summary>
|
||||
public List<string> Data { get; set; }
|
||||
}
|
||||
}
|
||||
@ -21,9 +21,9 @@ using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class StandardProtocolPlugin : ProtocolPlugin
|
||||
public class T6452007ProtocolPlugin : ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<StandardProtocolPlugin> _logger;
|
||||
private readonly ILogger<T6452007ProtocolPlugin> _logger;
|
||||
|
||||
private readonly IProducerService _producerService;
|
||||
|
||||
@ -31,13 +31,13 @@ namespace JiShe.CollectBus.Protocol
|
||||
private readonly ITcpService _tcpService;
|
||||
|
||||
public readonly Dictionary<string, Telemetry3761PacketBuilder.T3761Delegate> T3761AFNHandlers;
|
||||
public readonly Dictionary<string, Telemetry645PacketBuilder.T645Delegate> T645ControlHandlers;
|
||||
public readonly Dictionary<string, Telemetry6452007PacketBuilder.T6452007Delegate> T645ControlHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StandardProtocolPlugin"/> class.
|
||||
/// Initializes a new instance of the <see cref="T6452007ProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public StandardProtocolPlugin(IServiceProvider serviceProvider, ILogger<StandardProtocolPlugin> logger, ITcpService tcpService) : base(serviceProvider, logger)
|
||||
public T6452007ProtocolPlugin(IServiceProvider serviceProvider, ILogger<T6452007ProtocolPlugin> logger, ITcpService tcpService) : base(serviceProvider, logger)
|
||||
{
|
||||
_logger = logger;
|
||||
//_logger = serviceProvider.GetRequiredService<ILogger<StandardProtocolPlugin>>();
|
||||
@ -45,10 +45,10 @@ namespace JiShe.CollectBus.Protocol
|
||||
_deviceRepository = serviceProvider.GetRequiredService<IRepository<Device, Guid>>();
|
||||
_tcpService = tcpService;
|
||||
T3761AFNHandlers = Telemetry3761PacketBuilder.T3761AFNHandlers;
|
||||
T645ControlHandlers = Telemetry645PacketBuilder.T645ControlHandlers;
|
||||
T645ControlHandlers = Telemetry6452007PacketBuilder.T645ControlHandlers;
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(StandardProtocolPlugin), "376.1", "TCP", "376.1协议", "DTS1980");
|
||||
public sealed override ProtocolInfo Info => new(nameof(T6452007ProtocolPlugin), "376.1", "TCP", "376.1协议", "DTS1980");
|
||||
|
||||
public override async Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? sendAction = null)
|
||||
{
|
||||
@ -318,7 +318,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception($"{nameof(StandardProtocolPlugin)} 报文构建失败,参数为空");
|
||||
throw new Exception($"{nameof(T6452007ProtocolPlugin)} 报文构建失败,参数为空");
|
||||
}
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var aFNStr = itemCodeArr[0];
|
||||
@ -331,12 +331,12 @@ namespace JiShe.CollectBus.Protocol
|
||||
if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false)
|
||||
{
|
||||
var t645PacketHandlerName = $"C{request.SubProtocolRequest.ItemCode}_Send";
|
||||
Telemetry645PacketResponse t645PacketResponse = null;
|
||||
Telemetry6452007PacketResponse t645PacketResponse = null;
|
||||
|
||||
if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(t645PacketHandlerName
|
||||
, out var t645PacketHandler))
|
||||
{
|
||||
t645PacketResponse = t645PacketHandler(new Telemetry645PacketRequest()
|
||||
t645PacketResponse = t645PacketHandler(new Telemetry6452007PacketRequest()
|
||||
{
|
||||
MeterAddress = request.SubProtocolRequest.MeterAddress,
|
||||
Password = request.SubProtocolRequest.Password,
|
||||
@ -17,7 +17,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\services\JiShe.CollectBus.Domain\JiShe.CollectBus.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\shared\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
|
||||
<ProjectReference Include="..\..\protocols\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
protocols/JiShe.CollectBus.Protocol/AnalysisData/Appendix.cs
Normal file
33
protocols/JiShe.CollectBus.Protocol/AnalysisData/Appendix.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.AnalysisData
|
||||
{
|
||||
/// <summary>
|
||||
/// 附录
|
||||
/// </summary>
|
||||
public static class Appendix
|
||||
{
|
||||
/// <summary>
|
||||
/// 附录1 A1格式
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Appendix_A1(List<string> data)
|
||||
{
|
||||
var seconds = data[0];
|
||||
var minutes = data[1];
|
||||
var hours = data[2];
|
||||
var day = data[3];
|
||||
var binString = data[4].HexToBin();
|
||||
var months = binString.Substring(3, 1).BinToDec() * 10 + Convert.ToInt32(binString.Substring(4, 4).BinToHex());
|
||||
var week = binString.Substring(0, 3).BinToHex();
|
||||
var year = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{data[5]}";
|
||||
return $"{year}-{months.ToString().PadLeft(2, '0')}-{day} {hours}:{minutes}:{seconds}_{week}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts
|
||||
{
|
||||
|
||||
public class AnalysisStrategyContext(IServiceProvider provider)
|
||||
{
|
||||
private readonly IServiceProvider _provider = provider;
|
||||
|
||||
/// <summary>
|
||||
/// 执行策略
|
||||
/// </summary>
|
||||
/// <typeparam name="TInput"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<TResult> ExecuteAsync<TInput, TResult>(string type, TInput input)
|
||||
{
|
||||
var factory = _provider.GetRequiredService<Func<string, Type, Type, object>>();
|
||||
var strategy = (IAnalysisStrategy<TInput, TResult>)factory(type, typeof(TInput), typeof(TResult));
|
||||
return strategy.ExecuteAsync(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ProtocolNameAttribute(string name) : Attribute
|
||||
{
|
||||
public string Name { get; set; } = name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
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.Interfaces
|
||||
{
|
||||
public interface IAnalysisStrategy<TInput, TResult>
|
||||
{
|
||||
Task<TResult> ExecuteAsync(TInput input);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user