67 lines
2.6 KiB
C#
67 lines
2.6 KiB
C#
using JiShe.CollectBus.RabbitMQ.Models;
|
||
using JiShe.CollectBus.RabbitMQ.Senders;
|
||
using TouchSocket.Core;
|
||
using TouchSocket.Sockets;
|
||
|
||
namespace JiShe.CollectBus.Core.Plugins
|
||
{
|
||
public partial class TcpServiceReceivedPlugin(IMqSender sender) : PluginBase
|
||
{
|
||
[GeneratorPlugin(typeof(ITcpReceivedPlugin))]
|
||
public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||
{
|
||
////TODO: 电表主站到集中器的协议都是376.1协议,集中器下发到电表协议分为645-07和modbus
|
||
////TODO: 水表主站到集中器的协议分为118和645-97协议
|
||
////TODO: 连接成功时获取档案信息,根据档案信息匹配协议正则获取协议服务进行监听发送
|
||
|
||
//const string protocolType = "StandardProtocol";
|
||
|
||
//var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
|
||
//var protocolPluginInfo = await protocolPlugin.GetAsync();
|
||
//client.Logger.Info($"{protocolPluginInfo.Name},{protocolPluginInfo.RegularExpression}");
|
||
////从客户端收到信息
|
||
//var messageHexString = Convert.ToHexString(e.ByteBlock.Span);
|
||
//client.Logger.Info($"[TCP] 已从{client.GetIPPort()}接收到信息:{messageHexString}");
|
||
|
||
//await protocolPlugin.ReceivedAsync(client,e);
|
||
|
||
|
||
await sender.SendToReportAsync(new ReportDto
|
||
{
|
||
ClientIP = client.IP,
|
||
ClientId = client.Id,
|
||
Port = client.Port,
|
||
MessageHexString = Convert.ToHexString(e.ByteBlock.Span),
|
||
DeviceNo = "111"
|
||
});
|
||
|
||
await e.InvokeNext();
|
||
}
|
||
|
||
[GeneratorPlugin(typeof(ITcpConnectingPlugin))]
|
||
public async Task OnTcpConnecting(ITcpSessionClient client, ConnectingEventArgs e)
|
||
{
|
||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}正在连接中...");
|
||
|
||
await e.InvokeNext();
|
||
|
||
}
|
||
|
||
[GeneratorPlugin(typeof(ITcpConnectedPlugin))]
|
||
public async Task OnTcpConnected(ITcpSessionClient client, ConnectedEventArgs e)
|
||
{
|
||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已连接");
|
||
|
||
await e.InvokeNext();
|
||
}
|
||
|
||
[GeneratorPlugin(typeof(ITcpClosedPlugin))]
|
||
public async Task OnTcpClosed(ITcpSessionClient client, ClosedEventArgs e)
|
||
{
|
||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已关闭连接");
|
||
|
||
await e.InvokeNext();
|
||
}
|
||
}
|
||
}
|