dev #2

Merged
admin merged 176 commits from dev into master 2025-04-18 01:31:49 +00:00
2 changed files with 7 additions and 11 deletions
Showing only changes of commit 9a5cb565e9 - Show all commits

View File

@ -55,15 +55,12 @@ namespace JiShe.CollectBus.Plugins
var aTuple = (Tuple<string, int>)hexStringList.GetAnalyzeValue(CommandChunkEnum.A); var aTuple = (Tuple<string, int>)hexStringList.GetAnalyzeValue(CommandChunkEnum.A);
if (aFn.HasValue && fn.HasValue && aTuple != null && !string.IsNullOrWhiteSpace(aTuple.Item1)) if (aFn.HasValue && fn.HasValue && aTuple != null && !string.IsNullOrWhiteSpace(aTuple.Item1))
{ {
string oldClinetId = client.Id;
await client.ResetIdAsync(aTuple.Item1);
if ((AFN)aFn == AFN.) if ((AFN)aFn == AFN.)
{ {
switch (fn) switch (fn)
{ {
case 1: case 1:
await OnTcpLoginReceived(client, messageHexString, aTuple.Item1, oldClinetId); await OnTcpLoginReceived(client, messageHexString, aTuple.Item1);
break; break;
case 3: case 3:
await OnTcpHeartbeatReceived(client, messageHexString, aTuple.Item1); await OnTcpHeartbeatReceived(client, messageHexString, aTuple.Item1);
@ -123,13 +120,12 @@ namespace JiShe.CollectBus.Plugins
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="messageHexString"></param> /// <param name="messageHexString"></param>
/// <param name="deviceNo">集中器编号</param> /// <param name="deviceNo">集中器编号</param>
/// <param name="oldClinetId">TCP首次连接时的Id</param>
/// <returns></returns> /// <returns></returns>
private async Task OnTcpLoginReceived(ITcpSessionClient client, string messageHexString, string deviceNo,string oldClinetId) private async Task OnTcpLoginReceived(ITcpSessionClient client, string messageHexString, string deviceNo)
{ {
var messageReceivedLoginEvent = new MessageReceivedLogin var messageReceivedLoginEvent = new MessageReceivedLogin
{ {
ClientId = oldClinetId, ClientId = client.Id,
ClientIp = client.IP, ClientIp = client.IP,
ClientPort = client.Port, ClientPort = client.Port,
MessageHexString = messageHexString, MessageHexString = messageHexString,
@ -140,11 +136,11 @@ namespace JiShe.CollectBus.Plugins
var entity = await _deviceRepository.FindAsync(a => a.Number == deviceNo); var entity = await _deviceRepository.FindAsync(a => a.Number == deviceNo);
if (entity == null) if (entity == null)
{ {
await _deviceRepository.InsertAsync(new Device(deviceNo, oldClinetId, DateTime.Now, DateTime.Now, DeviceStatus.Online)); await _deviceRepository.InsertAsync(new Device(deviceNo, client.Id,DateTime.Now, DateTime.Now, DeviceStatus.Online));
} }
else else
{ {
entity.UpdateByLoginAndHeartbeat(oldClinetId); entity.UpdateByLoginAndHeartbeat(client.Id);
await _deviceRepository.UpdateAsync(entity); await _deviceRepository.UpdateAsync(entity);
} }
} }

View File

@ -222,9 +222,9 @@ namespace JiShe.CollectBus.Host
{ {
context.Services.AddTcpService(config => context.Services.AddTcpService(config =>
{ {
config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "32580")) config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "10500"))
//.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter()) //.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter())
.SetGetDefaultNewId(() => Guid.NewGuid().ToString())//定义ClinetId的生成策略 //.SetGetDefaultNewId(() => Guid.NewGuid().ToString())//定义ClinetId的生成策略
.ConfigurePlugins(a => .ConfigurePlugins(a =>
{ {
a.Add<TcpCloseMonitor>(); a.Add<TcpCloseMonitor>();