diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs
index cfde2d3..9f6ee76 100644
--- a/protocols/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs
+++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs
@@ -25,7 +25,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
/// 是否需要转发的扩展协议入参对象
/// 映射读取执行方法的Code,例如10_1,表示10H_F1
///
- Task BuildAsync(BuildRequest request);
+ Task BuildAsync(ProtocolBuildRequest request);
//Task LoginAsync(MessageReceivedLogin messageReceived);
diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildRequest.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildRequest.cs
similarity index 67%
rename from protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildRequest.cs
rename to protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildRequest.cs
index 962d533..31b386b 100644
--- a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildRequest.cs
+++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildRequest.cs
@@ -1,9 +1,11 @@
-namespace JiShe.CollectBus.Protocol.Contracts.SendData
+using JiShe.CollectBus.Protocol.Contracts.Models;
+
+namespace JiShe.CollectBus.Protocol.Contracts.SendData
{
///
/// 报文构建参数
///
- public class BuildRequest
+ public class ProtocolBuildRequest
{
///
/// 集中器地址
@@ -21,8 +23,8 @@
public required string ItemCode { get; set; }
///
- /// 集中器转发协议构建组合功能码
+ /// 集中器转发协议构建构建参数
///
- public string SubItemCode { get; set; }
+ public SubProtocolBuildRequest SubProtocolRequest { get; set; }
}
}
diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildResponse.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildResponse.cs
similarity index 95%
rename from protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildResponse.cs
rename to protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildResponse.cs
index 07d235b..09afc47 100644
--- a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/BuildResponse.cs
+++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolBuildResponse.cs
@@ -3,7 +3,7 @@
///
/// 报文构建返回结果
///
- public class BuildResponse
+ public class ProtocolBuildResponse
{
///
/// 是否成功
diff --git a/protocols/JiShe.CollectBus.Protocol.Contracts/Models/SubProtocolBuildRequest.cs b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/SubProtocolBuildRequest.cs
new file mode 100644
index 0000000..c104ea7
--- /dev/null
+++ b/protocols/JiShe.CollectBus.Protocol.Contracts/Models/SubProtocolBuildRequest.cs
@@ -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
+{
+ ///
+ /// 子协议构建参数
+ ///
+ public class SubProtocolBuildRequest
+ {
+ ///
+ /// 表地址
+ ///
+ public required string MeterAddress { get; set; }
+
+ ///
+ /// 密码
+ ///
+ public required string Password { get; set; }
+
+ ///
+ /// 操作码
+ ///
+ public required string ItemCode { get; set; }
+ }
+}
diff --git a/protocols/JiShe.CollectBus.Protocol/SendData/Telemetry645PacketBuilder.cs b/protocols/JiShe.CollectBus.Protocol/SendData/Telemetry645PacketBuilder.cs
index 870278d..a7faf67 100644
--- a/protocols/JiShe.CollectBus.Protocol/SendData/Telemetry645PacketBuilder.cs
+++ b/protocols/JiShe.CollectBus.Protocol/SendData/Telemetry645PacketBuilder.cs
@@ -77,7 +77,7 @@ namespace JiShe.CollectBus.Protocol.SendData
///
///
///
- public static Telemetry645PacketResponse C1C_02_Send(Telemetry645PacketRequest request)
+ public static Telemetry645PacketResponse C1C_03_Send(Telemetry645PacketRequest request)
{
var itemCodeArr = request.ItemCode.Split('_');
var c_data = itemCodeArr[0];
diff --git a/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs
index d94a380..faf3f8c 100644
--- a/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs
+++ b/protocols/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs
@@ -1,6 +1,4 @@
-using Azure.Core;
-using DeviceDetectorNET.Parser.Device;
-using JiShe.CollectBus.Common.BuildSendDatas;
+using JiShe.CollectBus.Common.BuildSendDatas;
using JiShe.CollectBus.Common.Consts;
using JiShe.CollectBus.Common.Enums;
using JiShe.CollectBus.Common.Extensions;
@@ -12,14 +10,12 @@ 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 JiShe.CollectBus.Protocol.Contracts.SendData;
using JiShe.CollectBus.Protocol.SendData;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Newtonsoft.Json.Linq;
using TouchSocket.Sockets;
using Volo.Abp.Domain.Repositories;
@@ -276,12 +272,14 @@ namespace JiShe.CollectBus.Protocol
///
/// 组装报文
///
- ///
- /// 设备数据实体
- /// 映射读取执行方法的Code,例如10_1,表示 10H_F1_00000,10H_F1_00001,统一英文下划线分隔
+ /// 报文构建参数
///
- public override async Task BuildAsync(BuildRequest request)
+ public override async Task BuildAsync(ProtocolBuildRequest request)
{
+ if (request == null)
+ {
+ throw new Exception($"{nameof(StandardProtocolPlugin)} 报文构建失败,参数为空");
+ }
var itemCodeArr = request.ItemCode.Split('_');
var aFNStr = itemCodeArr[0];
var aFN = (AFN)aFNStr.HexToDec();
@@ -289,21 +287,20 @@ namespace JiShe.CollectBus.Protocol
Telemetry3761PacketResponse builderResponse = null;
List dataUnit = new List();
- //10H_F1_1CH
- if (aFNStr == "10" && string.IsNullOrWhiteSpace(request.SubItemCode) == false)
+ //数据转发场景 10H_F1_1CH
+ if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false)
{
-
- var subItem = $"C{request.SubItemCode}_Send";
+ var t645PacketHandlerName = $"C{request.SubProtocolRequest.ItemCode}_Send";
Telemetry645PacketResponse t645PacketResponse = null;
- if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(subItem
- , out var cchandler))
+ if (T645ControlHandlers != null && T645ControlHandlers.TryGetValue(t645PacketHandlerName
+ , out var t645PacketHandler))
{
- t645PacketResponse = cchandler(new Telemetry645PacketRequest()
+ t645PacketResponse = t645PacketHandler(new Telemetry645PacketRequest()
{
- MeterAddress = "",
- Password = "",
- ItemCode = "",
+ MeterAddress = request.SubProtocolRequest.MeterAddress,
+ Password = request.SubProtocolRequest.Password,
+ ItemCode = request.SubProtocolRequest.ItemCode,
});
}
@@ -328,10 +325,10 @@ namespace JiShe.CollectBus.Protocol
if (builderResponse == null)
{
- return new BuildResponse();
+ return new ProtocolBuildResponse();
}
- var result = builderResponse.Adapt();
+ var result = builderResponse.Adapt();
result.IsSuccess = true;
return await Task.FromResult(result);
diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
index 6e87ddb..4a7d74c 100644
--- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
+++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs
@@ -20,6 +20,7 @@ using JiShe.CollectBus.IotSystems.Watermeter;
using JiShe.CollectBus.Kafka.Internal;
using JiShe.CollectBus.Kafka.Producer;
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
+using JiShe.CollectBus.Protocol.Contracts.Models;
using JiShe.CollectBus.Protocol.Contracts.SendData;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -619,7 +620,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
//var fn = int.Parse(itemCodeArr[1]);
//TODO:特殊表
- BuildResponse builderResponse = await protocolPlugin.BuildAsync(new BuildRequest()
+ ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
{
FocusAddress = ammeterInfo.FocusAddress,
Pn = ammeterInfo.MeteringCode,
@@ -898,7 +899,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading
tempCodes = new List() { "10_1" };
}
- //根据电表型号获取协议插件
+ //根据表型号获取协议插件
var protocolPlugin = await _protocolService.GetProtocolServiceAsync(watermeter.Code);
if (protocolPlugin == null)
{
@@ -944,11 +945,17 @@ namespace JiShe.CollectBus.ScheduledMeterReading
// continue;
//}
- BuildResponse builderResponse = await protocolPlugin.BuildAsync(new BuildRequest()
+ ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
{
FocusAddress = watermeter.FocusAddress,
Pn = watermeter.MeteringCode,
ItemCode = tempItem,
+ SubProtocolRequest = new SubProtocolBuildRequest()
+ {
+ MeterAddress = watermeter.MeterAddress,
+ Password = watermeter.Password,
+ ItemCode = tempItem,
+ }
});
if (builderResponse == null || builderResponse.Data.Length <= 0)
{
diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
index d61a641..e2bae0a 100644
--- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
+++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs
@@ -16,6 +16,7 @@ using JiShe.CollectBus.IotSystems.Watermeter;
using JiShe.CollectBus.Kafka.Internal;
using JiShe.CollectBus.Kafka.Producer;
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
+using JiShe.CollectBus.Protocol.Contracts.Models;
using JiShe.CollectBus.Protocol.Contracts.SendData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
@@ -226,16 +227,22 @@ namespace JiShe.CollectBus.ScheduledMeterReading
//获取对应的缓存电表信息
var ammeterInfo = ammeterInfos.First();
bool tripStateResult = false;
+ string subItemCode = string.Empty;
if (settingInfo.TripType.Equals("on"))
{
ammeterInfo.TripState = 0;
tripStateResult = true;
+ subItemCode = T645PacketItemCodeConst.C1C01C;
+ if (ammeterInfo.TypeName != 1)
+ {
+ subItemCode = T645PacketItemCodeConst.C1C01B;
+ }
}
else if (settingInfo.TripType.Equals("off"))
{
ammeterInfo.TripState = 1;
tripStateResult = false;
-
+ subItemCode = T645PacketItemCodeConst.C1C01A;
}
else
{
@@ -253,11 +260,17 @@ namespace JiShe.CollectBus.ScheduledMeterReading
return;
}
- BuildResponse builderResponse = await protocolPlugin.BuildAsync(new BuildRequest()
+ 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 = subItemCode,
+ }
});
string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, ammeterInfo.MeteringCode, builderResponse.MSA,builderResponse.Seq);
diff --git a/services/JiShe.CollectBus.Application/Subscribers/WorkerSubscriberAppService.cs b/services/JiShe.CollectBus.Application/Subscribers/WorkerSubscriberAppService.cs
index fa90fed..e34c087 100644
--- a/services/JiShe.CollectBus.Application/Subscribers/WorkerSubscriberAppService.cs
+++ b/services/JiShe.CollectBus.Application/Subscribers/WorkerSubscriberAppService.cs
@@ -82,6 +82,7 @@ namespace JiShe.CollectBus.Subscribers
[KafkaSubscribe(ProtocolConst.AmmeterSubscriberWorkerAutoValveControlIssuedEventName)]
public async Task AmmeterScheduledAutoValveControl(MeterReadingTelemetryPacketInfo receivedMessage)
{
+ //todo 如果是时段自动阀控,需要检查当前的时间,如果时间在自动阀控时间段内,则发送自动阀控报文,否则不发送,尤其是消息队列阻塞或者延时过长的时候。以免造成生产事故。
_logger.LogInformation("电表自动阀控下行消息消费队列开始处理");
return await SendMessagesAsync(receivedMessage);
}
diff --git a/shared/JiShe.CollectBus.Common/Consts/T645PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T645PacketItemCodeConst.cs
new file mode 100644
index 0000000..449ef9a
--- /dev/null
+++ b/shared/JiShe.CollectBus.Common/Consts/T645PacketItemCodeConst.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JiShe.CollectBus.Common.Consts
+{
+ ///
+ /// T645报文项编码
+ ///
+ public class T645PacketItemCodeConst
+ {
+ #region 跳合闸、报警、保电
+ ///
+ /// 跳闸
+ ///
+ public const string C1C01A = "1C_1A";
+
+ ///
+ /// 单相合闸
+ ///
+ public const string C1C01B = "1C_1B";
+
+ ///
+ /// 三相合闸
+ ///
+ public const string C1C01C = "1C_1C";
+
+ ///
+ /// 触发报警
+ ///
+ public const string C1C02A = "1C_2A";
+
+ ///
+ /// 报警解除
+ ///
+ public const string C1C02B = "1C_2B";
+
+ ///
+ /// 保电开始
+ ///
+ public const string C1C03A = "1C_3A";
+
+ ///
+ /// 保电结束
+ ///
+ public const string C1C03B = "1C_3B";
+ #endregion
+
+ #region 广播校时
+
+ ///
+ /// 广播校时
+ ///
+ public const string C08 = "08";
+ #endregion
+ }
+}