合并
This commit is contained in:
commit
946dffbaa7
@ -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}"
|
||||
@ -51,7 +47,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Kafka.Test
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6.External", "6.External", "{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}"
|
||||
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
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.PluginFileWatcher", "external\JiShe.CollectBus.PluginFileWatcher\JiShe.CollectBus.PluginFileWatcher.csproj", "{0F67A493-A4DF-550E-AB4D-95F55144C706}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -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
|
||||
@ -131,10 +127,26 @@ Global
|
||||
{6D6A2A58-7406-9C8C-7B23-3E442CCE3E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6D6A2A58-7406-9C8C-7B23-3E442CCE3E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6D6A2A58-7406-9C8C-7B23-3E442CCE3E6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F767D1C3-6807-4AE3-996A-3A28FE8124C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
{0F67A493-A4DF-550E-AB4D-95F55144C706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0F67A493-A4DF-550E-AB4D-95F55144C706}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F67A493-A4DF-550E-AB4D-95F55144C706}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F67A493-A4DF-550E-AB4D-95F55144C706}.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}
|
||||
@ -158,7 +168,11 @@ Global
|
||||
{A377955E-7EA1-6F29-8CF7-774569E93925} = {3C3F9DB2-EC97-4464-B49F-BF1A0C2B46DC}
|
||||
{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}
|
||||
{0F67A493-A4DF-550E-AB4D-95F55144C706} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Confluent.Kafka;
|
||||
using JiShe.CollectBus.Common;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Kafka.Serialization;
|
||||
@ -30,6 +31,8 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
|
||||
private readonly KafkaOptionConfig _kafkaOptionConfig;
|
||||
|
||||
private readonly ServerApplicationOptions _applicationOptions;
|
||||
|
||||
private readonly KafkaPollyPipeline _kafkaPollyPipeline;
|
||||
|
||||
/// <summary>
|
||||
@ -37,10 +40,11 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="kafkaOptionConfig"></param>
|
||||
public ConsumerService(ILogger<ConsumerService> logger, IOptions<KafkaOptionConfig> kafkaOptionConfig, KafkaPollyPipeline kafkaPollyPipeline)
|
||||
public ConsumerService(ILogger<ConsumerService> logger, IOptions<KafkaOptionConfig> kafkaOptionConfig, KafkaPollyPipeline kafkaPollyPipeline, IOptions<ServerApplicationOptions> applicationOptions)
|
||||
{
|
||||
_logger = logger;
|
||||
_kafkaOptionConfig = kafkaOptionConfig.Value;
|
||||
_applicationOptions = applicationOptions.Value;
|
||||
_kafkaPollyPipeline = kafkaPollyPipeline;
|
||||
}
|
||||
|
||||
@ -67,7 +71,7 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
var config = new ConsumerConfig
|
||||
{
|
||||
BootstrapServers = _kafkaOptionConfig.BootstrapServers,
|
||||
GroupId = groupId ?? _kafkaOptionConfig.ServerTagName,
|
||||
GroupId = groupId ?? _applicationOptions.ServerTagName,
|
||||
AutoOffsetReset = AutoOffsetReset.Earliest,
|
||||
EnableAutoCommit = false, // 禁止AutoCommit
|
||||
EnablePartitionEof = true, // 启用分区末尾标记
|
||||
@ -161,7 +165,7 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
}
|
||||
if (_kafkaOptionConfig.EnableFilter)
|
||||
{
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) } };
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) } };
|
||||
// 检查 Header 是否符合条件
|
||||
if (!headersFilter.Match(result.Message.Headers))
|
||||
{
|
||||
@ -244,7 +248,7 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
}
|
||||
if (_kafkaOptionConfig.EnableFilter)
|
||||
{
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) } };
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) } };
|
||||
// 检查 Header 是否符合条件
|
||||
if (!headersFilter.Match(result.Message.Headers))
|
||||
{
|
||||
@ -348,7 +352,7 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
{
|
||||
if (_kafkaOptionConfig.EnableFilter)
|
||||
{
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) } };
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) } };
|
||||
// 检查 Header 是否符合条件
|
||||
if (!headersFilter.Match(result.Message.Headers))
|
||||
{
|
||||
@ -485,7 +489,7 @@ namespace JiShe.CollectBus.Kafka.Consumer
|
||||
{
|
||||
if (_kafkaOptionConfig.EnableFilter)
|
||||
{
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) } };
|
||||
var headersFilter = new HeadersFilter { { "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) } };
|
||||
// 检查 Header 是否符合条件
|
||||
if (!headersFilter.Match(result.Message.Headers))
|
||||
{
|
||||
|
||||
@ -9,11 +9,6 @@ public class KafkaOptionConfig
|
||||
/// </summary>
|
||||
public string BootstrapServers { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 服务器标识
|
||||
/// </summary>
|
||||
public string ServerTagName { get; set; } = "KafkaFilterKey";
|
||||
|
||||
/// <summary>
|
||||
/// kafka主题副本数量
|
||||
/// </summary>
|
||||
@ -54,8 +49,4 @@ public class KafkaOptionConfig
|
||||
/// </summary>
|
||||
public string? SaslPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 首次采集时间
|
||||
/// </summary>
|
||||
public DateTime? FirstCollectionTime { get; set; }
|
||||
}
|
||||
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Confluent.Kafka;
|
||||
using JiShe.CollectBus.Common;
|
||||
using JiShe.CollectBus.Kafka.Consumer;
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Kafka.Serialization;
|
||||
@ -23,18 +24,19 @@ namespace JiShe.CollectBus.Kafka.Producer
|
||||
private readonly ConcurrentDictionary<Type, object> _producerCache = new();
|
||||
private class KafkaProducer<TKey, TValue> where TKey : notnull where TValue : class { }
|
||||
private readonly KafkaOptionConfig _kafkaOptionConfig;
|
||||
|
||||
private readonly ServerApplicationOptions _applicationOptions;
|
||||
/// <summary>
|
||||
/// ProducerService
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="kafkaOptionConfig"></param>
|
||||
public ProducerService(IConfiguration configuration,ILogger<ProducerService> logger, IOptions<KafkaOptionConfig> kafkaOptionConfig)
|
||||
public ProducerService(IConfiguration configuration,ILogger<ProducerService> logger, IOptions<KafkaOptionConfig> kafkaOptionConfig, IOptions<ServerApplicationOptions> applicationOptions)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
_kafkaOptionConfig = kafkaOptionConfig.Value;
|
||||
_applicationOptions = applicationOptions.Value;
|
||||
}
|
||||
|
||||
#region private 私有方法
|
||||
@ -119,7 +121,7 @@ namespace JiShe.CollectBus.Kafka.Producer
|
||||
Key = key,
|
||||
Value = value,
|
||||
Headers = new Headers{
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) }
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) }
|
||||
}
|
||||
};
|
||||
await producer.ProduceAsync(topic, message);
|
||||
@ -141,7 +143,7 @@ namespace JiShe.CollectBus.Kafka.Producer
|
||||
//Key= _kafkaOptionConfig.ServerTagName,
|
||||
Value = value,
|
||||
Headers = new Headers{
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) }
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) }
|
||||
}
|
||||
};
|
||||
await producer.ProduceAsync(topic, message);
|
||||
@ -165,7 +167,7 @@ namespace JiShe.CollectBus.Kafka.Producer
|
||||
Key = key,
|
||||
Value = value,
|
||||
Headers = new Headers{
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) }
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) }
|
||||
}
|
||||
};
|
||||
var typeKey = typeof(KafkaProducer<TKey, TValue>);
|
||||
@ -200,7 +202,7 @@ namespace JiShe.CollectBus.Kafka.Producer
|
||||
//Key = _kafkaOptionConfig.ServerTagName,
|
||||
Value = value,
|
||||
Headers = new Headers{
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_kafkaOptionConfig.ServerTagName) }
|
||||
{ "route-key", Encoding.UTF8.GetBytes(_applicationOptions.ServerTagName) }
|
||||
}
|
||||
};
|
||||
var typeKey = typeof(KafkaProducer<Null, TValue>);
|
||||
|
||||
@ -1,388 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.FreeRedis;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
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 ProtocolPlugin: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 ProtocolPlugin(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"));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
@ -0,0 +1,31 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Reflection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class JiSheCollectBusProtocolT1882018Module : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, T1882018ProtocolPlugin>(nameof(T1882018ProtocolPlugin));
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine($"{nameof(T1882018ProtocolPlugin)} OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(T1882018ProtocolPlugin));
|
||||
await standardProtocol.LoadAsync();
|
||||
}
|
||||
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context)
|
||||
{
|
||||
Console.WriteLine($"{nameof(T1882018ProtocolPlugin)} OnApplicationShutdown");
|
||||
base.OnApplicationShutdown(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
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>
|
||||
/// 构建188-2018下发报文
|
||||
/// </summary>
|
||||
public static class Telemetry1882018PacketBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建报文的委托
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public delegate Telemetry1882018PacketResponse T1882018Delegate(Telemetry1882018PacketRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 编码与方法的映射表
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, T1882018Delegate> T1882018ControlHandlers = new();
|
||||
|
||||
static Telemetry1882018PacketBuilder()
|
||||
{
|
||||
// 初始化时自动注册所有符合命名规则的方法
|
||||
var methods = typeof(Telemetry1882018PacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
if (method.Name.StartsWith("CTR") && method.Name.EndsWith("_Send"))
|
||||
{
|
||||
string code = method.Name;
|
||||
var delegateInstance = (T1882018Delegate)Delegate.CreateDelegate(typeof(T1882018Delegate), method);
|
||||
T1882018ControlHandlers[code] = delegateInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 读数据
|
||||
|
||||
/// <summary>
|
||||
/// 读取计量数据
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry1882018PacketResponse CTR_01_Send(Telemetry1882018PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];//01
|
||||
var d_data = itemCodeArr[1];//91 或者 90
|
||||
var dataUnit = new List<string>() { "1F", d_data, "00" };
|
||||
var dataList = Build188SendData.Build188SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
|
||||
return new Telemetry1882018PacketResponse() { Data = dataList };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 写数据
|
||||
/// <summary>
|
||||
/// 阀控
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static Telemetry1882018PacketResponse CTR_04_Send(Telemetry1882018PacketRequest request)
|
||||
{
|
||||
var itemCodeArr = request.ItemCode.Split('_');
|
||||
var c_data = itemCodeArr[0];//01
|
||||
var d_data = itemCodeArr[1];//55 或者 99
|
||||
var dataUnit = new List<string>() { "A0", "17", "00", d_data };
|
||||
var dataList = Build188SendData.Build188SendCommand(request.MeterAddress, c_data, dataUnit);
|
||||
|
||||
return new Telemetry1882018PacketResponse() { Data = dataList };
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
namespace JiShe.CollectBus.Protocol.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建645报文参数
|
||||
/// </summary>
|
||||
public class Telemetry1882018PacketRequest
|
||||
{
|
||||
/// <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 Telemetry1882018PacketResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文体
|
||||
/// </summary>
|
||||
public List<string> Data { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,147 @@
|
||||
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.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
|
||||
{
|
||||
/// <summary>
|
||||
/// T1882018协议插件
|
||||
/// </summary>
|
||||
public class T1882018ProtocolPlugin : T37612012ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<T1882018ProtocolPlugin> _logger;
|
||||
|
||||
public readonly Dictionary<string, Telemetry1882018PacketBuilder.T1882018Delegate> T188ControlHandlers;
|
||||
|
||||
/// <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, tcpService)
|
||||
{
|
||||
_logger = logger;
|
||||
T188ControlHandlers = Telemetry1882018PacketBuilder.T1882018ControlHandlers;
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(T1882018ProtocolPlugin), "376.1/188-2018", "TCP", "376.1/188-2018协议", "HJ-LXS-15 DN15");
|
||||
|
||||
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)!;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 组装报文
|
||||
/// </summary>
|
||||
/// <param name="request">报文构建参数</param>
|
||||
/// <returns></returns>
|
||||
public override async Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
_logger.LogError($"{nameof(T1882018ProtocolPlugin)} 报文构建失败,参数为空");
|
||||
return new ProtocolBuildResponse();
|
||||
}
|
||||
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
|
||||
if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false)
|
||||
{
|
||||
var t188PacketHandlerName = $"{T1882018PacketItemCodeConst.BasicT1882018}_{request.SubProtocolRequest.ItemCode}_Send";
|
||||
Telemetry1882018PacketResponse t645PacketResponse = null;
|
||||
|
||||
if (T188ControlHandlers != null && T188ControlHandlers.TryGetValue(t188PacketHandlerName
|
||||
, 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 (base.T3761AFNHandlers != null && base.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,7 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
||||
{
|
||||
@ -32,16 +24,17 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
||||
ArgumentNullException.ThrowIfNull(nameof(tB3761));
|
||||
UnitDataAnalysis<bool> dto = new UnitDataAnalysis<bool>
|
||||
{
|
||||
Code = tB3761.A?.Code,
|
||||
AFN = tB3761.AFN_FC?.AFN ?? 0,
|
||||
Fn = tB3761.DT?.Fn ?? 0,
|
||||
Pn = tB3761.DA?.Pn ?? 0
|
||||
Code = tB3761.A.Code,
|
||||
AFN = tB3761.AFN_FC.AFN,
|
||||
Fn = tB3761.DT.Fn,
|
||||
Pn = tB3761.DA.Pn,
|
||||
Data= true
|
||||
};
|
||||
return Task.FromResult(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"00_1解析失败:{tB3761.A?.Code}-{tB3761.DT?.Fn ?? 0}-{tB3761?.BaseHexMessage?.HexMessageString},{ex.Message}");
|
||||
_logger.LogError(ex, $"00_1解析失败:{tB3761.A.Code}-{tB3761.DT.Fn}-{tB3761.BaseHexMessage.HexMessageString},{ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,7 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H
|
||||
{
|
||||
@ -1,18 +1,10 @@
|
||||
using DeviceDetectorNET.Class;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.AFN_00H;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
using YamlDotNet.Core;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H
|
||||
{
|
||||
@ -1,15 +1,9 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.AFN_00H;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H
|
||||
{
|
||||
@ -1,16 +1,9 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
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.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH
|
||||
@ -71,8 +71,8 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var pnfnArr = dataArr.GetRange(0, 4);
|
||||
var tempPn = ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]);
|
||||
var tempFn = ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]);
|
||||
var tempPn = T37612012ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]);
|
||||
var tempFn = T37612012ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]);
|
||||
entity.Details.Add(new SetAutoItemCodeDetails() { Fn = tempFn, Pn = tempPn });
|
||||
dataArr.RemoveRange(0, 4);
|
||||
}
|
||||
@ -1,13 +1,7 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH
|
||||
{
|
||||
@ -1,10 +1,15 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Encrypt;
|
||||
using JiShe.CollectBus.Common.Helpers;
|
||||
using JiShe.CollectBus.IoTDB.Interface;
|
||||
using JiShe.CollectBus.IoTDB.Options;
|
||||
using JiShe.CollectBus.IoTDB.Provider;
|
||||
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -16,11 +21,13 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
{
|
||||
private readonly ILogger<AFN12_F129_Analysis> _logger;
|
||||
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
||||
private readonly IIoTDbProvider _dbProvider;
|
||||
|
||||
public AFN12_F129_Analysis(ILogger<AFN12_F129_Analysis> logger, AnalysisStrategyContext analysisStrategyContext)
|
||||
public AFN12_F129_Analysis(ILogger<AFN12_F129_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, IIoTDbProvider dbProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_analysisStrategyContext = analysisStrategyContext;
|
||||
_dbProvider= dbProvider;
|
||||
}
|
||||
|
||||
public async Task<UnitDataAnalysis<List<AFN12_F129_AnalysisDto>>> ExecuteAsync(TB3761 input)
|
||||
@ -29,16 +36,34 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
|
||||
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
|
||||
List<AFN12_F129_AnalysisDto> list = GenerateFinalResult(2, datas, "正向有功电能示值", input.AFN_FC.AFN, input.DT.Fn);
|
||||
ArgumentNullException.ThrowIfNull(input.A.A3?.D1_D7);
|
||||
UnitDataAnalysis<List<AFN12_F129_AnalysisDto>> unitDataAnalysis = new UnitDataAnalysis<List<AFN12_F129_AnalysisDto>>
|
||||
{
|
||||
Code = input.A.Code,
|
||||
Code = input.A.Code!,
|
||||
AFN = input.AFN_FC.AFN,
|
||||
Fn = input.DT.Fn,
|
||||
Pn = input.DA.Pn,
|
||||
Data = list
|
||||
MSA= input.A.A3.D1_D7,
|
||||
PSEQ= input.SEQ.PSEQ,
|
||||
};
|
||||
string taskMark = CommonHelper.GetTaskMark(unitDataAnalysis.AFN, unitDataAnalysis.Fn, unitDataAnalysis.Pn, unitDataAnalysis.MSA, unitDataAnalysis.PSEQ);
|
||||
string scoreValue = $"{unitDataAnalysis.Code}.{taskMark}".Md5Fun();
|
||||
|
||||
var conditions = new List<QueryCondition>();
|
||||
conditions.Add(new QueryCondition()
|
||||
{
|
||||
Field = "ScoreValue",
|
||||
Operator = "=",
|
||||
IsNumber = false,
|
||||
Value = scoreValue
|
||||
});
|
||||
var taskSendInfo = await _dbProvider.QueryAsync<MeterReadingTelemetryPacketInfo>(new IoTDBQueryOptions() { TableNameOrTreePath = DevicePathBuilder.GetTableName<MeterReadingTelemetryPacketInfo>(), Conditions = conditions,PageIndex=0,PageSize=1});
|
||||
|
||||
|
||||
|
||||
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
|
||||
List<AFN12_F129_AnalysisDto> list = GenerateFinalResult(2, datas, "正向有功电能示值", input.AFN_FC.AFN, input.DT.Fn);
|
||||
unitDataAnalysis.Data= list;
|
||||
|
||||
return await Task.FromResult(unitDataAnalysis);
|
||||
}
|
||||
@ -98,6 +123,13 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
return list;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 生成最终结果
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//public Task<bool> SaveIotDbAsync()
|
||||
//{
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,9 +1,9 @@
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,9 +1,9 @@
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,10 +1,10 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,13 +1,11 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
{
|
||||
@ -1,9 +1,9 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,17 +1,11 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using YamlDotNet.Core.Tokens;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -1,12 +1,10 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.Appendix;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
||||
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData
|
||||
{
|
||||
public class DataStorage:ITransientDependency
|
||||
{
|
||||
public DataStorage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,4 +1,4 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,8 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.AnalysisData.AFN_09H;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,6 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,5 +1,4 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
@ -1,6 +1,4 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix
|
||||
{
|
||||
@ -1,40 +1,31 @@
|
||||
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 JiShe.CollectBus.Protocol.Interfaces;
|
||||
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
|
||||
namespace JiShe.CollectBus.Protocol.Contracts
|
||||
{
|
||||
public class JiSheCollectBusProtocolModule : AbpModule
|
||||
public class CollectBusProtocolT37612012Module : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, StandardProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
context.Services.AddKeyedSingleton<IProtocolPlugin, T37612012ProtocolPlugin>(nameof(T37612012ProtocolPlugin));
|
||||
//RegisterProtocolAnalysis(context.Services);
|
||||
LoadAnalysisStrategy(context.Services);
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(StandardProtocolPlugin));
|
||||
Console.WriteLine($"{nameof(T37612012ProtocolPlugin)} OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(T37612012ProtocolPlugin));
|
||||
await standardProtocol.LoadAsync();
|
||||
}
|
||||
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context)
|
||||
{
|
||||
Console.WriteLine("StandardProtocolPlugin OnApplicationShutdown");
|
||||
Console.WriteLine($"{nameof(T37612012ProtocolPlugin)} OnApplicationShutdown");
|
||||
base.OnApplicationShutdown(context);
|
||||
}
|
||||
|
||||
@ -45,7 +36,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
foreach (var analysisStrategyType in analysisStrategyTypes)
|
||||
{
|
||||
var service = analysisStrategyType.GetInterfaces().First();
|
||||
services.AddKeyedSingleton(service, analysisStrategyType.Name,analysisStrategyType);
|
||||
services.AddKeyedSingleton(service, analysisStrategyType.Name, analysisStrategyType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +52,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dllFiles = Directory.GetFiles(Path.Combine(assemblyPath, "Plugins") , "*.dll");
|
||||
var dllFiles = Directory.GetFiles(Path.Combine(assemblyPath, "Plugins"), "*.dll");
|
||||
foreach (var file in dllFiles)
|
||||
{
|
||||
// 跳过已加载的程序集
|
||||
@ -83,8 +74,6 @@ namespace JiShe.CollectBus.Protocol
|
||||
// 注册策略实现
|
||||
services.AddTransient(analysisStrategyType);
|
||||
strategyMetadata[(strategyType, inputType, resultType)] = analysisStrategyType;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +90,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
}
|
||||
else
|
||||
{
|
||||
var logger= provider.GetRequiredService<ILogger<AnalysisStrategyContext>>();
|
||||
var logger = provider.GetRequiredService<ILogger<AnalysisStrategyContext>>();
|
||||
logger.LogWarning($"未能找到解析策略:{name}-{inputType}-{resultType}");
|
||||
return null;
|
||||
}
|
||||
@ -111,3 +100,6 @@ namespace JiShe.CollectBus.Protocol
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
<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="..\..\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" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol\JiShe.CollectBus.Protocol.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy $(TargetDir)JiShe.CollectBus.Protocol.T37612012.dll $(ProjectDir)..\..\web\JiShe.CollectBus.Host\Plugins\" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@ -1,51 +1,42 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
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
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建下发报文,只适用与定时抄读
|
||||
/// 构建3761下发报文
|
||||
/// </summary>
|
||||
public static class TelemetryPacketBuilder
|
||||
public static class Telemetry3761PacketBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建报文的委托
|
||||
/// </summary>
|
||||
/// <param name="request.FocusAddress"></param>
|
||||
/// <param name="request.Fn"></param>
|
||||
/// <param name="request.Pn"></param>
|
||||
public delegate TelemetryPacketResponse AFNDelegate(TelemetryPacketRequest request);
|
||||
public delegate Telemetry3761PacketResponse T3761Delegate(Telemetry3761PacketRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 编码与方法的映射表
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string, AFNDelegate> AFNHandlersDictionary = new();
|
||||
public static readonly Dictionary<string, T3761Delegate> T3761AFNHandlers = new();
|
||||
|
||||
static TelemetryPacketBuilder()
|
||||
static Telemetry3761PacketBuilder()
|
||||
{
|
||||
// 初始化时自动注册所有符合命名规则的方法
|
||||
var methods = typeof(TelemetryPacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
var methods = typeof(Telemetry3761PacketBuilder).GetMethods(BindingFlags.Static | BindingFlags.Public);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
if (method.Name.StartsWith("AFN") && method.Name.EndsWith("_Fn_Send"))
|
||||
{
|
||||
string code = method.Name;
|
||||
var delegateInstance = (AFNDelegate)Delegate.CreateDelegate(typeof(AFNDelegate), method);
|
||||
AFNHandlersDictionary[code] = delegateInstance;
|
||||
var delegateInstance = (T3761Delegate)Delegate.CreateDelegate(typeof(T3761Delegate), method);
|
||||
T3761AFNHandlers[code] = delegateInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region AFN_00H 确认∕否认
|
||||
public static TelemetryPacketResponse AFN00_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN00_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -64,13 +55,13 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region AFN_01H 复位命令
|
||||
public static TelemetryPacketResponse AFN01_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN01_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -89,13 +80,13 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region AFN_02H 链路接口检测
|
||||
public static TelemetryPacketResponse AFN02_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN02_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -114,12 +105,12 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AFN_04H 设置参数
|
||||
public static TelemetryPacketResponse AFN04_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN04_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -138,13 +129,13 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AFN_05H 控制命令
|
||||
public static TelemetryPacketResponse AFN05_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN05_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -163,12 +154,12 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AFN_09H 请求终端配置及信息
|
||||
public static TelemetryPacketResponse AFN09_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN09_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -187,13 +178,13 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AFN_0AH 查询参数
|
||||
public static TelemetryPacketResponse AFN0A_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN0A_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -212,12 +203,12 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AFN_0CH 请求一类数据
|
||||
public static TelemetryPacketResponse AFN0C_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN0C_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -236,12 +227,12 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AFN_0DH 请求二类数据
|
||||
public static TelemetryPacketResponse AFN0D_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN0D_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -260,12 +251,12 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AFN10H 数据转发
|
||||
public static TelemetryPacketResponse AFN10_Fn_Send(TelemetryPacketRequest request)
|
||||
public static Telemetry3761PacketResponse AFN10_Fn_Send(Telemetry3761PacketRequest request)
|
||||
{
|
||||
var reqParameter = new ReqParameter2()
|
||||
{
|
||||
@ -284,7 +275,7 @@ namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
Fn = request.Fn
|
||||
};
|
||||
var bytes = Build3761SendData.BuildSendCommandBytes(reqParameter, request.DataUnit);
|
||||
return new TelemetryPacketResponse() { Seq = reqParameter.Seq, Data = bytes, MSA = reqParameter.MSA, };
|
||||
return new Telemetry3761PacketResponse() { Seq = reqParameter.Seq.PRSEQ, Data = bytes, MSA = reqParameter.MSA, };
|
||||
}
|
||||
|
||||
#region SpecialAmmeter 特殊电表转发
|
||||
@ -1,20 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Common.BuildSendDatas
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文构建参数
|
||||
/// 构建3761报文参数
|
||||
/// </summary>
|
||||
public class TelemetryPacketRequest
|
||||
public class Telemetry3761PacketRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 集中器地址
|
||||
/// </summary>
|
||||
public string FocusAddress { get; set; }
|
||||
public required string FocusAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 抄读功能码
|
||||
@ -0,0 +1,23 @@
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回3761报文结果
|
||||
/// </summary>
|
||||
public class Telemetry3761PacketResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 帧序列域SEQ
|
||||
/// </summary>
|
||||
public int Seq { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址域A3的主站地址MSA
|
||||
/// </summary>
|
||||
public int MSA { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报文体
|
||||
/// </summary>
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,836 @@
|
||||
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.SendData;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TouchSocket.Sockets;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class T37612012ProtocolPlugin : ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<T37612012ProtocolPlugin> _logger;
|
||||
|
||||
private readonly IProducerService _producerService;
|
||||
|
||||
private readonly IRepository<Device, Guid> _deviceRepository;
|
||||
private readonly ITcpService _tcpService;
|
||||
|
||||
public readonly Dictionary<string, Telemetry3761PacketBuilder.T3761Delegate> T3761AFNHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T37612012ProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public T37612012ProtocolPlugin(IServiceProvider serviceProvider, ILogger<T37612012ProtocolPlugin> 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;
|
||||
}
|
||||
|
||||
public override ProtocolInfo Info => new(nameof(T37612012ProtocolPlugin), "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(T37612012ProtocolPlugin)} 报文构建失败,参数为空");
|
||||
}
|
||||
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";
|
||||
//Telemetry645PacketResponse t645PacketResponse = null;
|
||||
|
||||
//if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(t645PacketHandlerName
|
||||
// , out var t645PacketHandler))
|
||||
//{
|
||||
// t645PacketResponse = t645PacketHandler(new Telemetry645PacketRequest()
|
||||
// {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <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 上行命令
|
||||
|
||||
//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,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,29 @@
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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));
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
Console.WriteLine($"{nameof(T6452007ProtocolPlugin)} OnApplicationInitializationAsync");
|
||||
var standardProtocol = context.ServiceProvider.GetRequiredKeyedService<IProtocolPlugin>(nameof(T6452007ProtocolPlugin));
|
||||
await standardProtocol.LoadAsync();
|
||||
}
|
||||
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context)
|
||||
{
|
||||
Console.WriteLine($"{nameof(T6452007ProtocolPlugin)} OnApplicationShutdown");
|
||||
base.OnApplicationShutdown(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,271 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.IotSystems.Devices;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Kafka.Producer;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// T6452007协议插件
|
||||
/// </summary>
|
||||
public class T6452007ProtocolPlugin : T37612012ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<T6452007ProtocolPlugin> _logger;
|
||||
|
||||
public readonly Dictionary<string, Telemetry6452007PacketBuilder.T6452007Delegate> T645ControlHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T6452007ProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public T6452007ProtocolPlugin(IServiceProvider serviceProvider, ILogger<T6452007ProtocolPlugin> logger, ITcpService tcpService) : base(serviceProvider, logger, tcpService)
|
||||
{
|
||||
_logger = logger;
|
||||
T645ControlHandlers = Telemetry6452007PacketBuilder.T645ControlHandlers;
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(T6452007ProtocolPlugin), "376.1/645-2007", "TCP", "376.1/645-2007协议", "DTS1980");
|
||||
|
||||
public override async Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? sendAction = null)
|
||||
{
|
||||
//TODO:645解析报文
|
||||
//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)!;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 组装报文
|
||||
/// </summary>
|
||||
/// <param name="request">报文构建参数</param>
|
||||
/// <returns></returns>
|
||||
public override async Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
_logger.LogError($"{nameof(ProtocolBuildResponse)} 报文构建失败,参数为空");
|
||||
return new ProtocolBuildResponse();
|
||||
}
|
||||
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";
|
||||
Telemetry6452007PacketResponse t645PacketResponse = null;
|
||||
|
||||
if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(t645PacketHandlerName
|
||||
, out var t645PacketHandler))
|
||||
{
|
||||
t645PacketResponse = t645PacketHandler(new Telemetry6452007PacketRequest()
|
||||
{
|
||||
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 (base.T3761AFNHandlers != null && base.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
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@
|
||||
<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" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.T37612012\JiShe.CollectBus.Protocol.T37612012.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
|
||||
@ -1,30 +1,31 @@
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Test
|
||||
{
|
||||
public class TestProtocolPlugin : ProtocolPlugin
|
||||
public class TestProtocolPlugin : T37612012ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<TestProtocolPlugin> _logger;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public TestProtocolPlugin(IServiceProvider serviceProvider, ILogger<TestProtocolPlugin> logger) : base(serviceProvider, logger)
|
||||
public TestProtocolPlugin(IServiceProvider serviceProvider, ILogger<TestProtocolPlugin> logger, ITcpService tcpService) : base(serviceProvider, logger, tcpService)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(TestProtocolPlugin), "Test", "TCP", "Test协议", "DTS1980-TEST-01");
|
||||
public override ProtocolInfo Info => new(nameof(TestProtocolPlugin), "Test", "TCP", "Test协议", "DTS1980-TEST");
|
||||
|
||||
public override Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? receivedAction = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.FreeRedis;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
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 ProtocolPlugin : 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 ProtocolPlugin(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;
|
||||
|
||||
#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
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,5 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.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
|
||||
{
|
||||
@ -0,0 +1,7 @@
|
||||
namespace JiShe.CollectBus.Protocol.Interfaces
|
||||
{
|
||||
public interface IAnalysisStrategy<TInput, TResult>
|
||||
{
|
||||
Task<TResult> ExecuteAsync(TInput input);
|
||||
}
|
||||
}
|
||||
@ -4,9 +4,10 @@ using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
|
||||
namespace JiShe.CollectBus.Protocol.Interfaces
|
||||
{
|
||||
public interface IProtocolPlugin
|
||||
{
|
||||
@ -16,10 +17,12 @@ namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
|
||||
|
||||
Task<T> AnalyzeAsync<T>(ITcpSessionClient client, string messageReceived, Action<T>? sendAction = null) where T : class;
|
||||
|
||||
TB3761? Analysis3761(string messageReceived);
|
||||
|
||||
//Task LoginAsync(MessageReceivedLogin messageReceived);
|
||||
|
||||
//Task HeartbeatAsync(MessageReceivedHeartbeat messageReceived);
|
||||
/// <summary>
|
||||
/// 组装报文
|
||||
/// </summary>
|
||||
/// <typeparam name="T">是否需要转发的扩展协议入参对象</typeparam>
|
||||
/// <param name="afnFnCode">映射读取执行方法的Code,例如10_1,表示10H_F1</param>
|
||||
/// <returns></returns>
|
||||
Task<ProtocolBuildResponse> BuildAsync(ProtocolBuildRequest request);
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
|
||||
namespace JiShe.CollectBus.Protocol.Interfaces
|
||||
{
|
||||
public interface IProtocolService
|
||||
{
|
||||
@ -4,24 +4,30 @@
|
||||
<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" />
|
||||
<Compile Remove="Extensions\**" />
|
||||
<EmbeddedResource Remove="Extensions\**" />
|
||||
<None Remove="Extensions\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<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" />
|
||||
<Compile Remove="Abstracts\BaseProtocolPlugin_bak.cs" />
|
||||
<Compile Remove="QGDW3761Config.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy $(TargetDir)JiShe.CollectBus.Protocol.dll $(ProjectDir)..\..\web\JiShe.CollectBus.Host\Plugins\" />
|
||||
</Target>
|
||||
<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>
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文构建参数
|
||||
/// </summary>
|
||||
public class ProtocolBuildRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 集中器地址
|
||||
/// </summary>
|
||||
public required string FocusAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 抄读计量点,也就是终端电表对应端口
|
||||
/// </summary>
|
||||
public int Pn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 3761协议构建组合功能码
|
||||
/// </summary>
|
||||
public required string ItemCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 集中器转发协议构建构建参数
|
||||
/// </summary>
|
||||
public SubProtocolBuildRequest SubProtocolRequest { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.SendData
|
||||
{
|
||||
/// <summary>
|
||||
/// 报文构建返回结果
|
||||
/// </summary>
|
||||
public class ProtocolBuildResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 帧功能域AFN
|
||||
/// </summary>
|
||||
public int AFn { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// 帧功能域FN
|
||||
/// </summary>
|
||||
public int Fn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 帧序列域SEQ
|
||||
/// </summary>
|
||||
public int Seq { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址域A3的主站地址MSA
|
||||
/// </summary>
|
||||
public int MSA { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报文体
|
||||
/// </summary>
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 子协议构建参数
|
||||
/// </summary>
|
||||
public class SubProtocolBuildRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 表地址
|
||||
/// </summary>
|
||||
public required string MeterAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public required string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作码
|
||||
/// </summary>
|
||||
public required string ItemCode { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,12 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.FreeRedis;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol.Contracts.Services
|
||||
{
|
||||
@ -19,11 +14,13 @@ namespace JiShe.CollectBus.Protocol.Contracts.Services
|
||||
{
|
||||
private readonly IFreeRedisProvider _freeRedisProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<ProtocolService> _logger;
|
||||
|
||||
public ProtocolService(IFreeRedisProvider freeRedisProvider, IServiceProvider serviceProvider)
|
||||
public ProtocolService(IFreeRedisProvider freeRedisProvider, IServiceProvider serviceProvider, ILogger<ProtocolService> logger)
|
||||
{
|
||||
_freeRedisProvider = freeRedisProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger= logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -61,6 +58,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "获取协议失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,390 +0,0 @@
|
||||
using DeviceDetectorNET.Parser.Device;
|
||||
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.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TouchSocket.Sockets;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
public class StandardProtocolPlugin : ProtocolPlugin
|
||||
{
|
||||
private readonly ILogger<StandardProtocolPlugin> _logger;
|
||||
|
||||
private readonly IProducerService _producerService;
|
||||
|
||||
private readonly IRepository<Device, Guid> _deviceRepository;
|
||||
private readonly ITcpService _tcpService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StandardProtocolPlugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public StandardProtocolPlugin(IServiceProvider serviceProvider,ILogger<StandardProtocolPlugin> 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;
|
||||
}
|
||||
|
||||
public sealed override ProtocolInfo Info => new(nameof(StandardProtocolPlugin), "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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return (tB3761 as T)!;
|
||||
}
|
||||
|
||||
|
||||
/// <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()
|
||||
};
|
||||
|
||||
//await _producerBus.PublishAsync(ProtocolConst.SubscriberLoginReceivedEventName, messageReceivedLoginEvent);
|
||||
|
||||
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberLoginReceivedEventName, messageReceivedLoginEvent);
|
||||
|
||||
//await _producerBus.Publish( messageReceivedLoginEvent);
|
||||
|
||||
//var aTuple = (Tuple<string, int>)messageReceived.StringToPairs().GetAnalyzeValue(CommandChunkEnum.A);
|
||||
//var seq = (Seq)messageReceived.StringToPairs().GetAnalyzeValue(CommandChunkEnum.SEQ);
|
||||
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
|
||||
};
|
||||
//await _producerBus.PublishAsync(ProtocolConst.SubscriberLoginIssuedEventName, new IssuedEventMessage { ClientId = messageReceived.ClientId, DeviceNo = messageReceived.DeviceNo, Message = bytes, Type = IssuedEventType.Login, MessageId = messageReceived.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);
|
||||
}
|
||||
|
||||
//await _producerBus.Publish(new IssuedEventMessage { ClientId = messageReceived.ClientId, DeviceNo = messageReceived.DeviceNo, Message = bytes, Type = IssuedEventType.Login, MessageId = messageReceived.MessageId });
|
||||
}
|
||||
|
||||
/// <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()
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.Ammeters;
|
||||
using JiShe.CollectBus.GatherItem;
|
||||
@ -72,6 +73,13 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
/// <returns></returns>
|
||||
Task AmmeterScheduledAutoValveControl();
|
||||
|
||||
/// <summary>
|
||||
/// 电表自动校时
|
||||
/// </summary>
|
||||
/// <param name="timeDensity">采集频率</param>
|
||||
/// <returns></returns>
|
||||
Task AmmeterScheduledAutomaticVerificationTime(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.CollectBus.Subscribers
|
||||
{
|
||||
public interface ISubscriberAnalysisAppService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.Common.Models;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Volo.Abp.Application.Services;
|
||||
|
||||
namespace JiShe.CollectBus.Subscribers
|
||||
@ -11,7 +12,7 @@ namespace JiShe.CollectBus.Subscribers
|
||||
{
|
||||
Task<ISubscribeAck> LoginIssuedEvent(List<IssuedEventMessage> issuedEventMessage);
|
||||
Task<ISubscribeAck> HeartbeatIssuedEvent(List<IssuedEventMessage> issuedEventMessage);
|
||||
Task<ISubscribeAck> ReceivedEvent(MessageReceived receivedMessage);
|
||||
Task<ISubscribeAck> ReceivedEvent(MessageProtocolAnalysis<TB3761> receivedMessage);
|
||||
Task<ISubscribeAck> ReceivedHeartbeatEvent(List<MessageReceivedHeartbeat> receivedHeartbeatMessage);
|
||||
Task<ISubscribeAck> ReceivedLoginEvent(List<MessageReceivedLogin> receivedLoginMessage);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<PackageReference Include="TouchSocket" Version="3.0.19" />
|
||||
<PackageReference Include="TouchSocket.Hosting" Version="3.0.19" />
|
||||
<PackageReference Include="Volo.Abp.EventBus.Kafka" Version="8.3.3" />
|
||||
<ProjectReference Include="..\..\protocols\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\protocols\JiShe.CollectBus.Protocol\JiShe.CollectBus.Protocol.csproj" />
|
||||
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Application.Contracts\JiShe.CollectBus.Application.Contracts.csproj" />
|
||||
|
||||
|
||||
@ -1,35 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using DeviceDetectorNET.Parser.Device;
|
||||
using JiShe.CollectBus.Ammeters;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.Common.Helpers;
|
||||
using JiShe.CollectBus.Enums;
|
||||
using JiShe.CollectBus.Interceptors;
|
||||
using JiShe.CollectBus.IotSystems.Ammeters;
|
||||
using JiShe.CollectBus.IotSystems.Ammeters;
|
||||
using JiShe.CollectBus.IotSystems.Devices;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using JiShe.CollectBus.Kafka.Producer;
|
||||
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.Contracts.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using JiShe.CollectBus.Protocol3761;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
using static FreeSql.Internal.GlobalFilter;
|
||||
|
||||
namespace JiShe.CollectBus.Plugins
|
||||
{
|
||||
@ -77,12 +58,9 @@ namespace JiShe.CollectBus.Plugins
|
||||
TB3761? tB3761 = await protocolPlugin!.AnalyzeAsync<TB3761>(tcpSessionClient, messageHexString);
|
||||
if (tB3761 == null)
|
||||
{
|
||||
// TODO: 暂时不处理,后续再处理
|
||||
_logger.LogError($"指令初步解析失败,指令内容:{messageHexString}");
|
||||
}
|
||||
else
|
||||
{
|
||||
await OnTcpNormalReceived(tcpSessionClient, messageHexString, tB3761);
|
||||
}
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
@ -124,76 +102,5 @@ namespace JiShe.CollectBus.Plugins
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 正常帧处理,将不同的AFN进行分发
|
||||
/// </summary>
|
||||
/// <param name="tcpSessionClient"></param>
|
||||
/// <param name="messageHexString"></param>
|
||||
/// <param name="tB3761"></param>
|
||||
/// <returns></returns>
|
||||
private async Task OnTcpNormalReceived(ITcpSessionClient tcpSessionClient,string messageHexString, TB3761? tB3761)
|
||||
{
|
||||
//await _producerBus.Publish(new MessageReceived
|
||||
//{
|
||||
// ClientId = client.Id,
|
||||
// ClientIp = client.IP,
|
||||
// ClientPort = client.Port,
|
||||
// MessageHexString = messageHexString,
|
||||
// DeviceNo = deviceNo,
|
||||
// MessageId = NewId.NextGuid().ToString()
|
||||
//});
|
||||
|
||||
|
||||
//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)
|
||||
{
|
||||
_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'));
|
||||
|
||||
List<string> topics = ProtocolConstExtensions.GetAllTopicNamesByReceived();
|
||||
|
||||
if(topics.Contains(topicName))
|
||||
await _producerService.ProduceAsync(topicName, new MessageReceived
|
||||
{
|
||||
ClientId = tcpSessionClient.Id,
|
||||
ClientIp = tcpSessionClient.IP,
|
||||
ClientPort = tcpSessionClient.Port,
|
||||
MessageHexString = messageHexString,
|
||||
DeviceNo = tB3761?.A?.Code!,
|
||||
MessageId = Guid.NewGuid().ToString()
|
||||
});
|
||||
else
|
||||
{
|
||||
_logger.LogError($"不支持的上报kafka主题:{topicName}");
|
||||
await _producerService.ProduceAsync(ProtocolConst.SubscriberReceivedEventName, new MessageReceived
|
||||
{
|
||||
ClientId = tcpSessionClient.Id,
|
||||
ClientIp = tcpSessionClient.IP,
|
||||
ClientPort = tcpSessionClient.Port,
|
||||
MessageHexString = messageHexString,
|
||||
DeviceNo = tB3761?.A?.Code!,
|
||||
MessageId = Guid.NewGuid().ToString()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,11 +10,11 @@ using JiShe.CollectBus.IoTDB.Context;
|
||||
using JiShe.CollectBus.IoTDB.Interface;
|
||||
using JiShe.CollectBus.IoTDB.Model;
|
||||
using JiShe.CollectBus.IoTDB.Options;
|
||||
using JiShe.CollectBus.IoTDB.Provider;
|
||||
using JiShe.CollectBus.IotSystems.Ammeters;
|
||||
using JiShe.CollectBus.IotSystems.PrepayModel;
|
||||
using JiShe.CollectBus.Kafka.Attributes;
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -24,7 +24,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using JiShe.CollectBus.IotSystems.Ammeters;
|
||||
|
||||
namespace JiShe.CollectBus.Samples;
|
||||
|
||||
|
||||
@ -1,35 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Apache.IoTDB.DataStructure;
|
||||
using Apache.IoTDB;
|
||||
using Confluent.Kafka;
|
||||
using JiShe.CollectBus.Ammeters;
|
||||
using JiShe.CollectBus.FreeSql;
|
||||
using JiShe.CollectBus.IotSystems.PrepayModel;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using JiShe.CollectBus.Common.Helpers;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Cassandra;
|
||||
using JiShe.CollectBus.Cassandra;
|
||||
using JiShe.CollectBus.Common.Enums;
|
||||
using JiShe.CollectBus.Common.Extensions;
|
||||
using JiShe.CollectBus.DynamicModule;
|
||||
using JiShe.CollectBus.Interceptors;
|
||||
using JiShe.CollectBus.IotSystems.MessageIssueds;
|
||||
using Volo.Abp.Application.Services;
|
||||
using JiShe.CollectBus.IotSystems.MessageReceiveds;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Cassandra;
|
||||
using JiShe.CollectBus.Interceptors;
|
||||
using JiShe.CollectBus.IotSystems.Protocols;
|
||||
using TouchSocket.Core;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Modularity;
|
||||
using JiShe.CollectBus.DynamicModule;
|
||||
|
||||
namespace JiShe.CollectBus.Samples;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using JiShe.CollectBus.Application.Contracts;
|
||||
using JiShe.CollectBus.Common.BuildSendDatas;
|
||||
using JiShe.CollectBus.Common;
|
||||
using JiShe.CollectBus.Common.Consts;
|
||||
using JiShe.CollectBus.Common.DeviceBalanceControl;
|
||||
using JiShe.CollectBus.Common.Encrypt;
|
||||
@ -18,8 +18,9 @@ using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
||||
using JiShe.CollectBus.IotSystems.Watermeter;
|
||||
using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.Kafka.Producer;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.SendData;
|
||||
using JiShe.CollectBus.Protocol.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
@ -40,8 +41,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
private readonly IProducerService _producerService;
|
||||
private readonly IRedisDataCacheService _redisDataCacheService;
|
||||
private readonly KafkaOptionConfig _kafkaOptions;
|
||||
private readonly ServerApplicationOptions _applicationOptions;
|
||||
private readonly IoTDBRuntimeContext _runtimeContext;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IProtocolService _protocolService;
|
||||
|
||||
int pageSize = 3000;
|
||||
|
||||
@ -51,8 +53,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
IRedisDataCacheService redisDataCacheService,
|
||||
IIoTDbProvider dbProvider,
|
||||
IoTDBRuntimeContext runtimeContext,
|
||||
IServiceProvider serviceProvider,
|
||||
IOptions<KafkaOptionConfig> kafkaOptions)
|
||||
IProtocolService protocolService,
|
||||
IOptions<KafkaOptionConfig> kafkaOptions,
|
||||
IOptions<ServerApplicationOptions> applicationOptions)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbProvider = dbProvider;
|
||||
@ -60,7 +63,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
_producerService = producerService;
|
||||
_redisDataCacheService = redisDataCacheService;
|
||||
_kafkaOptions = kafkaOptions.Value;
|
||||
_serviceProvider = serviceProvider;
|
||||
_applicationOptions = applicationOptions.Value;
|
||||
_protocolService = protocolService;
|
||||
|
||||
_runtimeContext.UseTableSessionPool = true;
|
||||
}
|
||||
@ -109,6 +113,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
}
|
||||
|
||||
var currentTime = DateTime.Now;
|
||||
|
||||
//定时抄读
|
||||
foreach (var item in taskInfos)
|
||||
{
|
||||
var tasksToBeIssueModel = await FreeRedisProvider.Instance.GetAsync<TasksToBeIssueModel>(item);
|
||||
@ -127,6 +133,27 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
timeDensity = 15;
|
||||
}
|
||||
|
||||
|
||||
//电表定时广播校时,一天一次。
|
||||
string currentTimeStr = $"{currentTime:HH:mm:00}";
|
||||
//判断是否是自动校时时间
|
||||
if (!string.Equals(currentTimeStr, _applicationOptions.AutomaticVerificationTime, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
_logger.LogInformation($"{nameof(AmmeterScheduledAutomaticVerificationTime)} 电表自动校时,非自动校时时间");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = CreateMeterPublishTask<AmmeterInfo>(
|
||||
timeDensity: timeDensity,
|
||||
nextTaskTime: currentTime,
|
||||
meterType: MeterTypeEnum.Ammeter,
|
||||
taskCreateAction: async (timeDensity, data, groupIndex, timestamps) =>
|
||||
{
|
||||
await AmmeterScheduledAutomaticVerificationTime(timeDensity, data, groupIndex, timestamps);
|
||||
});
|
||||
}
|
||||
|
||||
//检查任务时间节点,由于定时任务10秒钟运行一次,需要判定当前时间是否在任务时间节点内,不在则跳过
|
||||
if (!IsTaskTime(tasksToBeIssueModel.NextTaskTime, timeDensity))
|
||||
{
|
||||
@ -145,15 +172,15 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
timeDensity: timeDensity,
|
||||
nextTaskTime: currentTaskTime,
|
||||
meterType: MeterTypeEnum.Ammeter,
|
||||
taskCreateAction: (timeDensity, data, groupIndex, timestamps) =>
|
||||
taskCreateAction: async (timeDensity, data, groupIndex, timestamps) =>
|
||||
{
|
||||
var tempTask = AmmerterCreatePublishTaskAction(timeDensity, data, groupIndex, timestamps);
|
||||
var tempTask = await AmmerterCreatePublishTaskAction(timeDensity, data, groupIndex, timestamps);
|
||||
if (tempTask == null || tempTask.Count <= 0)
|
||||
{
|
||||
_logger.LogWarning($"电表 {data.Name} 任务数据构建失败:{data.Serialize()}");
|
||||
return;
|
||||
}
|
||||
_dbProvider.BatchInsertAsync(metadata, tempTask);
|
||||
_ = _dbProvider.BatchInsertAsync(metadata, tempTask);
|
||||
});
|
||||
}
|
||||
else if (meteryType == MeterTypeEnum.WaterMeter.ToString())
|
||||
@ -163,16 +190,16 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
timeDensity: timeDensity,
|
||||
nextTaskTime: currentTaskTime,
|
||||
meterType: MeterTypeEnum.WaterMeter,
|
||||
taskCreateAction: (timeDensity, data, groupIndex, timestamps) =>
|
||||
taskCreateAction: async (timeDensity, data, groupIndex, timestamps) =>
|
||||
{
|
||||
var tempTask = WatermeterCreatePublishTaskAction(timeDensity, data, groupIndex, timestamps);
|
||||
var tempTask = await WatermeterCreatePublishTaskAction(timeDensity, data, groupIndex, timestamps);
|
||||
|
||||
if (tempTask == null || tempTask.Count <= 0)
|
||||
{
|
||||
_logger.LogWarning($"水表 {data.Name} 任务数据构建失败:{data.Serialize()}");
|
||||
return;
|
||||
}
|
||||
_dbProvider.BatchInsertAsync(metadata, tempTask);
|
||||
_ = _dbProvider.BatchInsertAsync(metadata, tempTask);
|
||||
});
|
||||
}
|
||||
else
|
||||
@ -189,6 +216,10 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
tasksToBeIssueModel.NextTaskTime = currentTaskTime.CalculateNextCollectionTime(timeDensity);
|
||||
await FreeRedisProvider.Instance.SetAsync(item, tasksToBeIssueModel);
|
||||
}
|
||||
|
||||
//电表定时阀控任务处理。
|
||||
_= AmmeterScheduledAutoValveControl();
|
||||
|
||||
}
|
||||
|
||||
#region 电表采集处理
|
||||
@ -275,9 +306,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
//根据采集频率分组,获得采集频率分组
|
||||
var meterInfoGroupByTimeDensity = meterInfos.GroupBy(d => d.TimeDensity);
|
||||
|
||||
if (_kafkaOptions.FirstCollectionTime.HasValue == false)
|
||||
if (_applicationOptions.FirstCollectionTime.HasValue == false)
|
||||
{
|
||||
_kafkaOptions.FirstCollectionTime = DateTime.Now;
|
||||
_applicationOptions.FirstCollectionTime = DateTime.Now;
|
||||
}
|
||||
//先处理采集频率任务缓存
|
||||
foreach (var item in meterInfoGroupByTimeDensity)
|
||||
@ -286,7 +317,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
{
|
||||
LastTaskTime = null,
|
||||
TimeDensity = item.Key,
|
||||
NextTaskTime = _kafkaOptions.FirstCollectionTime.Value.CalculateNextCollectionTime(item.Key),//使用首次采集时间作为下一次采集时间
|
||||
NextTaskTime = _applicationOptions.FirstCollectionTime.Value.CalculateNextCollectionTime(item.Key),//使用首次采集时间作为下一次采集时间
|
||||
};
|
||||
|
||||
//todo 首次采集时间节点到目前运行时间中漏采的时间点,可以考虑使用IoTDB的存储,利用时间序列处理。
|
||||
@ -500,11 +531,20 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
/// <param name="groupIndex">集中器所在分组</param>
|
||||
/// <param name="timestamps">采集频率对应的时间戳</param>
|
||||
/// <returns></returns>
|
||||
private List<MeterReadingTelemetryPacketInfo> AmmerterCreatePublishTaskAction(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps)
|
||||
private async Task<List<MeterReadingTelemetryPacketInfo>> AmmerterCreatePublishTaskAction(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps)
|
||||
{
|
||||
var currentTime = DateTime.Now;
|
||||
|
||||
var handlerPacketBuilder = TelemetryPacketBuilder.AFNHandlersDictionary;
|
||||
//根据电表型号获取协议插件
|
||||
var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType);
|
||||
if (protocolPlugin == null)
|
||||
{
|
||||
//_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有找到对应的协议组件,-105");
|
||||
//return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//todo 检查需要待补抄的电表的时间点信息,保存到需要待补抄的缓存中。如果此线程异常,该如何补偿?
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ammeterInfo.ItemCodes))
|
||||
@ -601,43 +641,18 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
continue;
|
||||
}
|
||||
|
||||
var itemCodeArr = tempItem.Split('_');
|
||||
var aFNStr = itemCodeArr[0];
|
||||
var aFN = (AFN)aFNStr.HexToDec();
|
||||
var fn = int.Parse(itemCodeArr[1]);
|
||||
TelemetryPacketResponse builderResponse = null;
|
||||
if (ammeterInfo.AutomaticReport.Equals(1) && aFN == AFN.请求实时数据)
|
||||
{
|
||||
//实时数据
|
||||
builderResponse = TelemetryPacketBuilder.AFN0C_Fn_Send(new TelemetryPacketRequest()
|
||||
{
|
||||
FocusAddress = ammeterInfo.FocusAddress,
|
||||
Fn = fn,
|
||||
Pn = ammeterInfo.MeteringCode
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
string methonCode = $"AFN{aFNStr}_Fn_Send";
|
||||
//特殊表暂不处理
|
||||
if (handlerPacketBuilder != null && handlerPacketBuilder.TryGetValue(methonCode
|
||||
, out var handler))
|
||||
{
|
||||
builderResponse = handler(new TelemetryPacketRequest()
|
||||
{
|
||||
FocusAddress = ammeterInfo.FocusAddress,
|
||||
Fn = fn,
|
||||
Pn = ammeterInfo.MeteringCode
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"{nameof(AmmerterCreatePublishTaskAction)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}无效编码。");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//TODO:特殊表
|
||||
//var itemCodeArr = tempItem.Split('_');
|
||||
//var aFNStr = itemCodeArr[0];
|
||||
//var aFN = (AFN)aFNStr.HexToDec();
|
||||
//var fn = int.Parse(itemCodeArr[1]);
|
||||
|
||||
//TODO:特殊表
|
||||
ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
|
||||
{
|
||||
FocusAddress = ammeterInfo.FocusAddress,
|
||||
Pn = ammeterInfo.MeteringCode,
|
||||
ItemCode = tempItem,
|
||||
});
|
||||
if (builderResponse == null || builderResponse.Data.Length <= 0)
|
||||
{
|
||||
//_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。");
|
||||
@ -645,7 +660,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
}
|
||||
|
||||
|
||||
string taskMark = CommonHelper.GetTaskMark((int)aFN, fn, ammeterInfo.MeteringCode, builderResponse.MSA);
|
||||
string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, ammeterInfo.MeteringCode, builderResponse.MSA, builderResponse.Seq);
|
||||
var meterReadingRecords = new MeterReadingTelemetryPacketInfo()
|
||||
{
|
||||
SystemName = SystemType,
|
||||
@ -657,9 +672,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
PendingCopyReadTime = timestamps,
|
||||
CreationTime = currentTime,
|
||||
MeterAddress = ammeterInfo.AmmerterAddress,
|
||||
AFN = (int)aFN,
|
||||
Fn = fn,
|
||||
//Seq = builderResponse.Seq,
|
||||
AFN = builderResponse.AFn,
|
||||
Fn = builderResponse.Fn,
|
||||
Seq = builderResponse.Seq,
|
||||
MSA = builderResponse.MSA,
|
||||
ItemCode = tempItem,
|
||||
TaskMark = taskMark,
|
||||
@ -697,6 +712,110 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
throw new NotImplementedException($"{nameof(AmmeterScheduledAutoValveControl)}请根据不同系统类型进行实现");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 电表自动校时
|
||||
/// </summary>
|
||||
/// <param name="timeDensity">采集频率</param>
|
||||
/// <param name="ammeterInfo">电表信息</param>
|
||||
/// <param name="groupIndex">集中器所在分组</param>
|
||||
/// <param name="timestamps">采集频率对应的时间戳</param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task AmmeterScheduledAutomaticVerificationTime(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps)
|
||||
{
|
||||
var currentTime = DateTime.Now;
|
||||
string currentTimeStr = $"{currentTime:HH:mm:00}";
|
||||
|
||||
try
|
||||
{
|
||||
//判断是否是自动校时时间
|
||||
if (!string.Equals(currentTimeStr , _applicationOptions.AutomaticVerificationTime,StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
_logger.LogInformation($"{nameof(AmmeterScheduledAutomaticVerificationTime)} 电表自动校时,非自动校时时间");
|
||||
return;
|
||||
}
|
||||
|
||||
List<MeterReadingTelemetryPacketInfo> taskList = new List<MeterReadingTelemetryPacketInfo>();
|
||||
var metadata = await _dbProvider.GetMetadata<MeterReadingTelemetryPacketInfo>();
|
||||
|
||||
var temCode = "10_01";
|
||||
|
||||
//根据电表型号获取协议插件
|
||||
var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType);
|
||||
if (protocolPlugin == null)
|
||||
{
|
||||
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有找到对应的协议组件,-105");
|
||||
return;
|
||||
}
|
||||
|
||||
ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
|
||||
{
|
||||
FocusAddress = ammeterInfo.FocusAddress,
|
||||
Pn = ammeterInfo.MeteringCode,
|
||||
ItemCode = temCode,
|
||||
SubProtocolRequest = new SubProtocolBuildRequest()
|
||||
{
|
||||
MeterAddress = ammeterInfo.AmmerterAddress,
|
||||
Password = ammeterInfo.Password,
|
||||
ItemCode = T6452007PacketItemCodeConst.C08,
|
||||
}
|
||||
});
|
||||
|
||||
string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, ammeterInfo.MeteringCode, builderResponse.MSA, builderResponse.Seq);
|
||||
var meterReadingRecords = new MeterReadingTelemetryPacketInfo()
|
||||
{
|
||||
SystemName = SystemType,
|
||||
ProjectId = $"{ammeterInfo.ProjectID}",
|
||||
DeviceType = $"{MeterTypeEnum.Ammeter}",
|
||||
DeviceId = $"{ammeterInfo.MeterId}",
|
||||
Timestamps = currentTime.GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
||||
DatabaseBusiID = ammeterInfo.DatabaseBusiID,
|
||||
PendingCopyReadTime = currentTime,
|
||||
CreationTime = currentTime,
|
||||
MeterAddress = ammeterInfo.AmmerterAddress,
|
||||
AFN = builderResponse.AFn,
|
||||
Fn = builderResponse.Fn,
|
||||
Seq = builderResponse.Seq,
|
||||
MSA = builderResponse.MSA,
|
||||
ItemCode = temCode,
|
||||
TaskMark = taskMark,
|
||||
IsSend = false,
|
||||
ManualOrNot = false,
|
||||
Pn = ammeterInfo.MeteringCode,
|
||||
IssuedMessageId = GuidGenerator.Create().ToString(),
|
||||
IssuedMessageHexString = Convert.ToHexString(builderResponse.Data),
|
||||
IsReceived = false,
|
||||
ScoreValue = $"{ammeterInfo.FocusAddress}.{taskMark}".Md5Fun(),
|
||||
};
|
||||
taskList.Add(meterReadingRecords);
|
||||
|
||||
if (taskList == null || taskList.Count <= 0)
|
||||
{
|
||||
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有自动阀控任务生成,-106");
|
||||
return;
|
||||
}
|
||||
|
||||
//任务记录入库
|
||||
await _dbProvider.BatchInsertAsync(metadata, taskList);
|
||||
|
||||
//任务信息推送Kafka
|
||||
_ = DeviceGroupBalanceControl.ProcessWithThrottleAsync<MeterReadingTelemetryPacketInfo>(
|
||||
items: taskList,
|
||||
deviceIdSelector: data => data.DeviceId,
|
||||
processor: (data, groupIndex) =>
|
||||
{
|
||||
_ = KafkaProducerIssuedMessageAction(ProtocolConst.AmmeterSubscriberWorkerOtherIssuedEventName, data, groupIndex);
|
||||
}
|
||||
);
|
||||
|
||||
//todo 阀控记录入库,推送到新的服务
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -736,9 +855,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
|
||||
//根据采集频率分组,获得采集频率分组
|
||||
var meterInfoGroupByTimeDensity = meterInfos.GroupBy(d => d.TimeDensity);
|
||||
if (_kafkaOptions.FirstCollectionTime.HasValue == false)
|
||||
if (_applicationOptions.FirstCollectionTime.HasValue == false)
|
||||
{
|
||||
_kafkaOptions.FirstCollectionTime = DateTime.Now;
|
||||
_applicationOptions.FirstCollectionTime = DateTime.Now;
|
||||
}
|
||||
|
||||
//先处理采集频率任务缓存
|
||||
@ -748,7 +867,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
{
|
||||
LastTaskTime = null,
|
||||
TimeDensity = item.Key,
|
||||
NextTaskTime = _kafkaOptions.FirstCollectionTime.Value.CalculateNextCollectionTime(item.Key),//使用首次采集时间作为下一次采集时间
|
||||
NextTaskTime = _applicationOptions.FirstCollectionTime.Value.CalculateNextCollectionTime(item.Key),//使用首次采集时间作为下一次采集时间
|
||||
};
|
||||
|
||||
//todo 首次采集时间节点到目前运行时间中漏采的时间点,可以考虑使用IoTDB的存储,利用时间序列处理。
|
||||
@ -851,10 +970,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
/// <param name="groupIndex">集中器所在分组</param>
|
||||
/// <param name="timestamps">时间格式的任务批次名称</param>
|
||||
/// <returns></returns>
|
||||
private List<MeterReadingTelemetryPacketInfo> WatermeterCreatePublishTaskAction(int timeDensity
|
||||
private async Task<List<MeterReadingTelemetryPacketInfo>> WatermeterCreatePublishTaskAction(int timeDensity
|
||||
, WatermeterInfo watermeter, int groupIndex, DateTime timestamps)
|
||||
{
|
||||
var handlerPacketBuilder = TelemetryPacketBuilder.AFNHandlersDictionary;
|
||||
var currentTime = DateTime.Now;
|
||||
|
||||
string typeName;
|
||||
@ -912,10 +1030,12 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
tempCodes = new List<string>() { "10_1" };
|
||||
}
|
||||
|
||||
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
||||
//根据表型号获取协议插件
|
||||
var protocolPlugin = await _protocolService.GetProtocolServiceAsync(watermeter.Code);
|
||||
if (protocolPlugin == null)
|
||||
{
|
||||
_logger.LogError("协议不存在!");
|
||||
//_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有找到对应的协议组件,-105");
|
||||
//return;
|
||||
}
|
||||
|
||||
foreach (var tempItem in tempCodes)
|
||||
@ -931,39 +1051,57 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
continue;
|
||||
}
|
||||
|
||||
var itemCodeArr = tempItem.Split('_');
|
||||
var aFNStr = itemCodeArr[0];
|
||||
var aFN = (AFN)aFNStr.HexToDec();
|
||||
var fn = int.Parse(itemCodeArr[1]);
|
||||
TelemetryPacketResponse builderResponse = null;
|
||||
//var itemCodeArr = tempItem.Split('_');
|
||||
//var aFNStr = itemCodeArr[0];
|
||||
//var aFN = (AFN)aFNStr.HexToDec();
|
||||
//var fn = int.Parse(itemCodeArr[1]);
|
||||
//TelemetryPacketResponse builderResponse = null;
|
||||
|
||||
string methonCode = $"AFN{aFNStr}_Fn_Send";
|
||||
//特殊表暂不处理
|
||||
if (handlerPacketBuilder != null && handlerPacketBuilder.TryGetValue(methonCode
|
||||
, out var handler))
|
||||
{
|
||||
builderResponse = handler(new TelemetryPacketRequest()
|
||||
//string methonCode = $"AFN{aFNStr}_Fn_Send";
|
||||
////特殊表暂不处理
|
||||
//if (handlerPacketBuilder != null && handlerPacketBuilder.TryGetValue(methonCode
|
||||
// , out var handler))
|
||||
//{
|
||||
// builderResponse = handler(new TelemetryPacketRequest()
|
||||
// {
|
||||
// FocusAddress = watermeter.FocusAddress,
|
||||
// Fn = fn,
|
||||
// Pn = watermeter.MeteringCode,
|
||||
// DataUnit = Build188SendData.Build188WaterMeterReadingSendDataUnit(watermeter.Address),
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{tempItem}无效编码。");
|
||||
// continue;
|
||||
//}
|
||||
|
||||
ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
|
||||
{
|
||||
FocusAddress = watermeter.FocusAddress,
|
||||
Fn = fn,
|
||||
Pn = watermeter.MeteringCode,
|
||||
DataUnit = Build188SendData.Build188WaterMeterReadingSendDataUnit(watermeter.Address),
|
||||
});
|
||||
}
|
||||
else
|
||||
ItemCode = tempItem,
|
||||
SubProtocolRequest = new SubProtocolBuildRequest()
|
||||
{
|
||||
_logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的电表{watermeter.Name}采集项{tempItem}无效编码。");
|
||||
MeterAddress = watermeter.MeterAddress,
|
||||
Password = watermeter.Password,
|
||||
ItemCode = tempItem,
|
||||
}
|
||||
});
|
||||
if (builderResponse == null || builderResponse.Data.Length <= 0)
|
||||
{
|
||||
//_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (builderResponse == null || builderResponse.Data.Length <= 0)
|
||||
{
|
||||
_logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的电表{watermeter.Name}采集项{tempItem}未能正确获取报文。");
|
||||
_logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{tempItem}未能正确获取报文。");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
string taskMark = CommonHelper.GetTaskMark((int)aFN, fn, watermeter.MeteringCode, builderResponse.MSA);
|
||||
string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, watermeter.MeteringCode, builderResponse.MSA, builderResponse.Seq);
|
||||
var meterReadingRecords = new MeterReadingTelemetryPacketInfo()
|
||||
{
|
||||
SystemName = SystemType,
|
||||
@ -975,9 +1113,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
PendingCopyReadTime = timestamps,
|
||||
CreationTime = currentTime,
|
||||
MeterAddress = watermeter.MeterAddress,
|
||||
AFN = (int)aFN,
|
||||
Fn = fn,
|
||||
//Seq = builderResponse.Seq,
|
||||
AFN = builderResponse.AFn,
|
||||
Fn = builderResponse.Fn,
|
||||
Seq = builderResponse.Seq,
|
||||
MSA = builderResponse.MSA,
|
||||
ItemCode = tempItem,
|
||||
TaskMark = taskMark,
|
||||
@ -1102,8 +1240,6 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
||||
bool hasNext;
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
||||
var ddd = _runtimeContext.UseTableSessionPool;
|
||||
|
||||
do
|
||||
{
|
||||
options.PageIndex = pageNumber++;
|
||||
|
||||
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