diff --git a/Repository/Station/BinInfoRepository.cs b/Repository/Station/BinInfoRepository.cs index ed051b1..c13ce62 100644 --- a/Repository/Station/BinInfoRepository.cs +++ b/Repository/Station/BinInfoRepository.cs @@ -33,4 +33,15 @@ public class BinInfoRepository : BaseRepository { return this.QueryByClause(it => it.No == binNo); } + + + /// + /// + /// + /// + /// + public BinInfo? QueryByChargeCode(string chargeNo) + { + return this.QueryByClause(it => it.ChargerNo == chargeNo); + } } \ No newline at end of file diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index 25e58bf..eeccee6 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -426,34 +426,7 @@ public class ChargerClient } - /// - /// 发送鉴权----并且发送电价配置 - /// - public Result SendAuth() - { - if (!Connected) - { - return Result.Fail($"charger-{BinNo} disconnect"); - } - - byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数] - byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码 - Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey); - CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented) + "\r\n" + - BitUtls.BytesToHexStr(auth.ToBytes()); - ServerMgr.Server.SessionMgr.GetSession(Sn).Send(auth); - - try - { - Log().Info("Auth after send SetPeakValleyTime"); - ServerMgr.Server.SessionMgr.GetSession(Sn).Send(BulidSetPeakValleyTimeObj(StaticStationInfo.Ceid)); - } - catch (Exception e) - { - Log().Info($"Auth after send SetPeakValleyTime deeor:{e}"); - } - return Result.Success(); - } + /// /// 监控平台发送远程开始充电指令 @@ -852,19 +825,7 @@ public class ChargerClient #endregion - /// - /// - /// - /// - /// - public void SessionAttr(string sn, string destAddr) - { - ChannelUtils.AddAttr(Channel, ChargerConst.ChargerSn, sn); - ChannelUtils.AddAttr(Channel, ChargerConst.EqmTypeNo, sn); - ChannelUtils.AddAttr(Channel, ChargerConst.EqmCode, sn); - ChannelUtils.AddAttr(Channel, ChargerConst.DestAddr, destAddr); - } - + /// /// 获取尖峰平谷字节数组 diff --git a/Service/Charger/Codec/Decoder.cs b/Service/Charger/Codec/Decoder.cs index f75908c..ff2d1e8 100644 --- a/Service/Charger/Codec/Decoder.cs +++ b/Service/Charger/Codec/Decoder.cs @@ -143,7 +143,7 @@ public class Decoder : ByteToMessageDecoder 11 => ModelConvert.Decode(bytes), 13 => ModelConvert.Decode(bytes), 21 => ModelConvert.Decode(bytes), - 25 => ModelConvert.Decode(bytes), + 24 => ModelConvert.Decode(bytes), 34 => ModelConvert.Decode(bytes), 35 => ModelConvert.Decode(bytes), 41 => ModelConvert.Decode(bytes), diff --git a/Service/Charger/Common/ChargerConst.cs b/Service/Charger/Common/ChargerConst.cs index 74227c2..8a12d3e 100644 --- a/Service/Charger/Common/ChargerConst.cs +++ b/Service/Charger/Common/ChargerConst.cs @@ -20,10 +20,7 @@ public static class ChargerConst public static readonly byte[] BatteryNo = { 0x00, 0xF8, 0x81 }; public static readonly byte[] BatteryBasicInfo = { 0x00, 0xF8, 0x82 }; - /// - /// 充电机和充电枪,枪号匹配 - /// - public static Dictionary, string> _dictionary = new Dictionary, string>(); + /// /// 启动方式 diff --git a/Service/Charger/Handler/AcMeterHandler.cs b/Service/Charger/Handler/AcMeterHandler.cs index c28f789..f27ebfe 100644 --- a/Service/Charger/Handler/AcMeterHandler.cs +++ b/Service/Charger/Handler/AcMeterHandler.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -21,7 +22,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, AcMeter msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.AcMeter = msg; diff --git a/Service/Charger/Handler/AdjustChargeRateResHandler.cs b/Service/Charger/Handler/AdjustChargeRateResHandler.cs index 3d5027f..cc12f35 100644 --- a/Service/Charger/Handler/AdjustChargeRateResHandler.cs +++ b/Service/Charger/Handler/AdjustChargeRateResHandler.cs @@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Service.Charger.Client; using Service.Charger.Msg.Charger.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -19,7 +20,7 @@ namespace Service.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(AdjustChargeRateResHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, AdjustChargeRateRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); } diff --git a/Service/Charger/Handler/AuthHandler.cs b/Service/Charger/Handler/AuthHandler.cs new file mode 100644 index 0000000..454b1e2 --- /dev/null +++ b/Service/Charger/Handler/AuthHandler.cs @@ -0,0 +1,72 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Newtonsoft.Json; +using Service.Charger.Client; +using Service.Charger.Common; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Charger.Resp; +using Service.Charger.Msg.Host.Resp; + +namespace Service.Charger.Handler +{ + /// + /// 接收到鉴权帧 + /// + /// 1,保存日志到log + /// 2,从SessionMgr中取目的地址,解析后写入ChargerManager + /// 3,保存鉴权状态和充电状态 + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class AuthHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(AuthHandler)); + private const String AUTH_CODE = "szhckj01"; + + protected override void ChannelRead0(IChannelHandlerContext ctx, Auth msg) + { + + Log.Info($"收到充电机鉴权认证请求: {msg}" ); + + byte[] receivedAuthCodes = msg.AuthCodes; + byte authCodeKey = msg.AuthCodeKey; + + // 鉴权码转换为字节数组 + byte[] expectedAuthCodes = Encoding.ASCII.GetBytes(AUTH_CODE);; + + // 验证鉴权码 + Boolean isValid = ValidateAuthCodes(receivedAuthCodes, expectedAuthCodes, authCodeKey); + + + // 鉴权结果处理 + byte authResult = (isValid ? (byte)0 : (byte)1); + AuthRes authRes = new AuthRes(authResult, msg.ConnSeq, authResult); + + Log.Info($"鉴权码验证{JsonConvert.SerializeObject(authRes)}, isValid {authResult}"); + // 返回鉴权响应 + ctx.Channel.WriteAndFlushAsync(authRes); + + + } + + private bool ValidateAuthCodes(byte[] receivedAuthCodes, byte[] expectedAuthCodes, byte authCodeKey) { + // 判断长度是否一致 + if (receivedAuthCodes.Length != expectedAuthCodes.Length) { + return false; + } + + // 字节异或 + for (int i = 0; i < expectedAuthCodes.Length; i++) { + if ((receivedAuthCodes[i] ^ authCodeKey) != expectedAuthCodes[i]) { + return false; + } + } + return true; + } + } + + +} \ No newline at end of file diff --git a/Service/Charger/Handler/AuthResHandler.cs b/Service/Charger/Handler/AuthResHandler.cs deleted file mode 100644 index ce21d50..0000000 --- a/Service/Charger/Handler/AuthResHandler.cs +++ /dev/null @@ -1,44 +0,0 @@ -using DotNetty.Transport.Channels; -using HybirdFrameworkCore.Autofac.Attribute; -using log4net; -using Service.Charger.Client; -using Service.Charger.Common; -using Service.Charger.Msg.Charger.Resp; - -namespace Service.Charger.Handler -{ - /// - /// 接收到鉴权帧 - /// - /// 1,保存日志到log - /// 2,从SessionMgr中取目的地址,解析后写入ChargerManager - /// 3,保存鉴权状态和充电状态 - /// - /// - [Order(8)] - [Scope("InstancePerDependency")] - public class AuthResHandler : SimpleChannelInboundHandler, IBaseHandler - { - private static readonly ILog Log = LogManager.GetLogger(typeof(AuthResHandler)); - - protected override void ChannelRead0(IChannelHandlerContext ctx, AuthRes msg) - { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) - { - if (msg.ConnSeq == client.AuthTimes) - { - if (msg.AuthResult == 0) - { - client.IsAuthed = true; - client.ChargingStatus = (int)ChargingStatus.Authed; - } - else - { - client.IsAuthed = false; - client.ChargingStatus = (int)ChargingStatus.AuthFailed; - } - } - } - } - } -} \ No newline at end of file diff --git a/Service/Charger/Handler/AuthVINResHandler.cs b/Service/Charger/Handler/AuthVINResHandler.cs index 59629d7..24bcc5b 100644 --- a/Service/Charger/Handler/AuthVINResHandler.cs +++ b/Service/Charger/Handler/AuthVINResHandler.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -22,7 +23,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, AuthVINRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/AuxiliaryPowerResHandler.cs b/Service/Charger/Handler/AuxiliaryPowerResHandler.cs index 5511329..410622d 100644 --- a/Service/Charger/Handler/AuxiliaryPowerResHandler.cs +++ b/Service/Charger/Handler/AuxiliaryPowerResHandler.cs @@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Service.Charger.Client; using Service.Charger.Msg.Charger.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -17,7 +18,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, AuxiliaryPowerRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.AuxiliaryPowerRes = msg; diff --git a/Service/Charger/Handler/BatteryPackDataHandler.cs b/Service/Charger/Handler/BatteryPackDataHandler.cs index 004811d..e3adf5a 100644 --- a/Service/Charger/Handler/BatteryPackDataHandler.cs +++ b/Service/Charger/Handler/BatteryPackDataHandler.cs @@ -6,6 +6,7 @@ using Service.Charger.Client; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackDataHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackData msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs b/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs index ce46250..e7737eb 100644 --- a/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs +++ b/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs @@ -6,6 +6,7 @@ using Service.Charger.Client; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackDataVoltageHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackDataVoltage msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs b/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs index c9425e2..730b6bf 100644 --- a/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs +++ b/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs @@ -6,6 +6,7 @@ using Service.Charger.Client; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackPortTemperatureHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackPortTemperature msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs b/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs index 8369d68..0d6c237 100644 --- a/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs +++ b/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs @@ -6,6 +6,7 @@ using Service.Charger.Client; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackStateAndFaultHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackStateAndFault msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs b/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs index 9cf104e..8ac68db 100644 --- a/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs +++ b/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs @@ -6,6 +6,7 @@ using Service.Charger.Client; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackTotalElectricityHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackTotalElectricity msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/ChangeChargeModeResHandler.cs b/Service/Charger/Handler/ChangeChargeModeResHandler.cs index 48223d4..e9dcf81 100644 --- a/Service/Charger/Handler/ChangeChargeModeResHandler.cs +++ b/Service/Charger/Handler/ChangeChargeModeResHandler.cs @@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Service.Charger.Client; using Service.Charger.Msg.Charger.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -20,7 +21,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, ChangeChargeModeRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); } diff --git a/Service/Charger/Handler/DetectionpointextremumdataHandler.cs b/Service/Charger/Handler/DetectionpointextremumdataHandler.cs index 25ef401..c2abf4e 100644 --- a/Service/Charger/Handler/DetectionpointextremumdataHandler.cs +++ b/Service/Charger/Handler/DetectionpointextremumdataHandler.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -19,7 +20,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, Detectionpointextremumdata msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); } diff --git a/Service/Charger/Handler/FinishStartChargingHandler.cs b/Service/Charger/Handler/FinishStartChargingHandler.cs index 9b149fa..47e4f90 100644 --- a/Service/Charger/Handler/FinishStartChargingHandler.cs +++ b/Service/Charger/Handler/FinishStartChargingHandler.cs @@ -10,6 +10,7 @@ using Service.Charger.Common; using Service.Charger.Handler; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace HybirdFrameworkServices.Charger.Handler { @@ -33,7 +34,7 @@ namespace HybirdFrameworkServices.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStartChargingHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStartCharging msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); msg.VehIdeNum = Encoding.ASCII.GetString(msg.Vin); diff --git a/Service/Charger/Handler/FinishStopChargingHandler.cs b/Service/Charger/Handler/FinishStopChargingHandler.cs index ffd697f..f5b8308 100644 --- a/Service/Charger/Handler/FinishStopChargingHandler.cs +++ b/Service/Charger/Handler/FinishStopChargingHandler.cs @@ -7,6 +7,7 @@ using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; using Service.Init; namespace Service.Charger.Handler @@ -30,7 +31,7 @@ namespace Service.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStopChargingHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStopCharging msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.IsCanSendStopCmd = false; diff --git a/Service/Charger/Handler/HeartBeatHandler.cs b/Service/Charger/Handler/HeartBeatHandler.cs index caff056..e03cf34 100644 --- a/Service/Charger/Handler/HeartBeatHandler.cs +++ b/Service/Charger/Handler/HeartBeatHandler.cs @@ -5,6 +5,7 @@ using Service.Charger.Client; using Service.Charger.Common; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -16,7 +17,7 @@ namespace Service.Charger.Handler private static readonly ILog Log = LogManager.GetLogger(typeof(HeartBeatHandler)); protected override void ChannelRead0(IChannelHandlerContext ctx, HeartBeat msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { //心跳存储日志 Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/LoginHandler.cs b/Service/Charger/Handler/LoginHandler.cs index 2e49d4d..dba7dbe 100644 --- a/Service/Charger/Handler/LoginHandler.cs +++ b/Service/Charger/Handler/LoginHandler.cs @@ -1,9 +1,14 @@ -using DotNetty.Transport.Channels; +using Autofac; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using log4net; +using Newtonsoft.Json; +using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Host.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -22,18 +27,29 @@ namespace Service.Charger.Handler { private readonly ILog Log = LogManager.GetLogger(typeof(LoginHandler)); + + public BinInfoRepository BinInfoRepository { get; set; } protected override void ChannelRead0(IChannelHandlerContext ctx, Login msg) { + ServerMgr.SessionAttr(ctx.Channel, msg.ChargerSn, "0,0,0,0"); - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) - { - Log.Info($"receive {msg} from {sn}"); - msg.ConnProtocolVersion = msg.ConnProtocolVersion0 + "." + msg.ConnProtocolVersion1 + "." + msg.ConnProtocolVersion2; - msg.ControllerHardwareVersion = msg.ControllerHardwareVersion0 + "." + msg.ControllerHardwareVersion1 + "." + msg.ControllerHardwareVersion2; - msg.ControllerSoftwareVersion = msg.ControllerSoftwareVersion0 + "." + msg.ControllerSoftwareVersion1 + "." + msg.ControllerSoftwareVersion2; + + msg.ConnProtocolVersion = msg.ConnProtocolVersion0 + "." + msg.ConnProtocolVersion1 + "." + msg.ConnProtocolVersion2; + msg.ControllerHardwareVersion = msg.ControllerHardwareVersion0 + "." + msg.ControllerHardwareVersion1 + "." + msg.ControllerHardwareVersion2; + msg.ControllerSoftwareVersion = msg.ControllerSoftwareVersion0 + "." + msg.ControllerSoftwareVersion1 + "." + msg.ControllerSoftwareVersion2; + Log.Info($"receive {JsonConvert.SerializeObject(msg)} from {msg.ChargerSn}"); + + + var binInfo = BinInfoRepository.QueryByChargeCode(msg.ChargerSn); - - } + ChargerClient client = AppInfo.Container.Resolve(); + client.Channel = ctx.Channel; + client.Sn = msg.ChargerSn; + client.Connected = true; + + client.BinNo = binInfo.No; + ServerMgr.AddBySn(msg.ChargerSn,client); + LogSignMessage logSignMessage = new LogSignMessage(0); ctx.Channel.WriteAndFlushAsync(logSignMessage); } diff --git a/Service/Charger/Handler/ModuleStateHandler.cs b/Service/Charger/Handler/ModuleStateHandler.cs index 818f28f..5185eee 100644 --- a/Service/Charger/Handler/ModuleStateHandler.cs +++ b/Service/Charger/Handler/ModuleStateHandler.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -24,7 +25,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, ModuleState msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/OfflineStopChargingResHandler.cs b/Service/Charger/Handler/OfflineStopChargingResHandler.cs index 2fad37d..2f795dd 100644 --- a/Service/Charger/Handler/OfflineStopChargingResHandler.cs +++ b/Service/Charger/Handler/OfflineStopChargingResHandler.cs @@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Service.Charger.Client; using Service.Charger.Msg.Charger.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -20,7 +21,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, OfflineStopChargingRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); } diff --git a/Service/Charger/Handler/OutCharger/PileAdjustPowerHandler.cs b/Service/Charger/Handler/OutCharger/PileAdjustPowerHandler.cs index ca2a1c7..fed7f28 100644 --- a/Service/Charger/Handler/OutCharger/PileAdjustPowerHandler.cs +++ b/Service/Charger/Handler/OutCharger/PileAdjustPowerHandler.cs @@ -2,6 +2,7 @@ using log4net; using Service.Charger.Client; using Service.Charger.Msg.Charger.OutCharger.Resp; +using Service.Charger.Server; namespace Service.Charger.Handler.OutCharger; /// @@ -14,7 +15,7 @@ public class PileAdjustPowerHandler : SimpleChannelInboundHandler @@ -17,7 +18,7 @@ public class PileStartChargeCompleteHandler : SimpleChannelInboundHandler @@ -23,7 +24,7 @@ public class PileStopChargeResHandler : SimpleChannelInboundHandler @@ -25,7 +26,7 @@ public class PileUploadRemoteSignalHandler: SimpleChannelInboundHandler, IBaseHandler protected override void ChannelRead0(IChannelHandlerContext ctx, UpBms msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.UpBms = msg; diff --git a/Service/Charger/Handler/UpgradeRequestHandler.cs b/Service/Charger/Handler/UpgradeRequestHandler.cs index 1dd963a..6e714ac 100644 --- a/Service/Charger/Handler/UpgradeRequestHandler.cs +++ b/Service/Charger/Handler/UpgradeRequestHandler.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -25,7 +26,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, UpgradeRequestRes msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); } diff --git a/Service/Charger/Handler/UplinkUpgradeHandler.cs b/Service/Charger/Handler/UplinkUpgradeHandler.cs index e137ada..ef052b7 100644 --- a/Service/Charger/Handler/UplinkUpgradeHandler.cs +++ b/Service/Charger/Handler/UplinkUpgradeHandler.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -24,7 +25,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, UplinkUpgrade msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.UplinkUpgrade = msg; diff --git a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs index 683d15a..bbaeffc 100644 --- a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs +++ b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs @@ -14,6 +14,7 @@ using Common.Const; using Entity.DbModel.Station; using Repository; using Repository.Station; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -43,7 +44,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, UploadRemoteSignalData msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { //存储日志 Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/UploadTelemetryDataHandler.cs b/Service/Charger/Handler/UploadTelemetryDataHandler.cs index 39f0f60..96d96de 100644 --- a/Service/Charger/Handler/UploadTelemetryDataHandler.cs +++ b/Service/Charger/Handler/UploadTelemetryDataHandler.cs @@ -6,6 +6,7 @@ using log4net; using Newtonsoft.Json; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -22,7 +23,7 @@ namespace Service.Charger.Handler public RedisHelper RedisHelper { get; set; } protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { msg.ChargerNo = sn; Log.Info($"receive {msg} from {sn}"); diff --git a/Service/Charger/Handler/VehicleVINHandler.cs b/Service/Charger/Handler/VehicleVINHandler.cs index 6b83eb4..df9324d 100644 --- a/Service/Charger/Handler/VehicleVINHandler.cs +++ b/Service/Charger/Handler/VehicleVINHandler.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -23,7 +24,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, VehicleVIN msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.VehicleVIN = msg; diff --git a/Service/Charger/Handler/VoltageCurrentSocHandler.cs b/Service/Charger/Handler/VoltageCurrentSocHandler.cs index 70ad7c4..e80ca5b 100644 --- a/Service/Charger/Handler/VoltageCurrentSocHandler.cs +++ b/Service/Charger/Handler/VoltageCurrentSocHandler.cs @@ -5,6 +5,7 @@ using log4net; using Repository.Station; using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -25,7 +26,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageCurrentSoc msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); bool update = _binInfoRepository.Update(it => new BinInfo() diff --git a/Service/Charger/Handler/VoltageExtremumStatisticsHandler.cs b/Service/Charger/Handler/VoltageExtremumStatisticsHandler.cs index 76c59a1..d7a440b 100644 --- a/Service/Charger/Handler/VoltageExtremumStatisticsHandler.cs +++ b/Service/Charger/Handler/VoltageExtremumStatisticsHandler.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Service.Charger.Server; namespace Service.Charger.Handler { @@ -20,7 +21,7 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageExtremumStatistics msg) { - if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); client.VoltageExtremumStatistics = msg; diff --git a/Service/Charger/Msg/Host/Req/Auth.cs b/Service/Charger/Msg/Charger/Req/Auth.cs similarity index 90% rename from Service/Charger/Msg/Host/Req/Auth.cs rename to Service/Charger/Msg/Charger/Req/Auth.cs index 8d0291c..b055a5f 100644 --- a/Service/Charger/Msg/Host/Req/Auth.cs +++ b/Service/Charger/Msg/Charger/Req/Auth.cs @@ -1,6 +1,6 @@ using HybirdFrameworkCore.Autofac.Attribute; -namespace Service.Charger.Msg.Host.Req +namespace Service.Charger.Msg.Charger.Req { /// /// 3.3.1 监控平台鉴权认证 @@ -37,7 +37,7 @@ namespace Service.Charger.Msg.Host.Req [Property(96, 8)] public byte AuthCodeKey { get; set; } - public Auth(ushort connseq, byte[] authcodes, byte authcodekey) + /*public Auth(ushort connseq, byte[] authcodes, byte authcodekey) { FrameTypeNo = 45; MsgBodyCount = 1; @@ -50,6 +50,6 @@ namespace Service.Charger.Msg.Host.Req ConnSeq = connseq; AuthCodes = authcodes; AuthCodeKey = authcodekey; - } + }*/ } } \ No newline at end of file diff --git a/Service/Charger/Msg/Charger/Req/Login.cs b/Service/Charger/Msg/Charger/Req/Login.cs index 9f6f060..9604cb4 100644 --- a/Service/Charger/Msg/Charger/Req/Login.cs +++ b/Service/Charger/Msg/Charger/Req/Login.cs @@ -14,10 +14,10 @@ namespace Service.Charger.Msg.Charger.Req public byte RecordType { get; set; } /// - /// 监控网关编号 + /// 充电机编号 /// [Property(8, 8*16)] - public String GatewayNo { get; set; } + public String ChargerSn { get; set; } /// /// 设备属性 diff --git a/Service/Charger/Msg/Charger/Resp/AuthRes.cs b/Service/Charger/Msg/Host/Resp/AuthRes.cs similarity index 59% rename from Service/Charger/Msg/Charger/Resp/AuthRes.cs rename to Service/Charger/Msg/Host/Resp/AuthRes.cs index 41cb503..db89105 100644 --- a/Service/Charger/Msg/Charger/Resp/AuthRes.cs +++ b/Service/Charger/Msg/Host/Resp/AuthRes.cs @@ -1,6 +1,6 @@ using HybirdFrameworkCore.Autofac.Attribute; -namespace Service.Charger.Msg.Charger.Resp +namespace Service.Charger.Msg.Host.Resp { /// /// 3.3.2 充放电机应答鉴权认证 @@ -31,5 +31,23 @@ namespace Service.Charger.Msg.Charger.Resp /// [Property(32, 8)] public byte FailReason { get; set; } + + public AuthRes(byte result,ushort conSeq,byte failReason) + { + + ConnSeq = conSeq; + AuthResult = result; + FailReason = failReason; + CtlArea = 0; + SrcAddr = 0; + FrameTypeNo = 45; + MsgBodyCount = 1; + TransReason = 4; + PublicAddr = 0; + MsgBodyAddr = new byte[] { 0, 0, 0 }; + RecordType = 25; + + } + } } \ No newline at end of file diff --git a/Service/Charger/MyTask/AutoChargeTask.cs b/Service/Charger/MyTask/AutoChargeTask.cs index 7760036..2b8fead 100644 --- a/Service/Charger/MyTask/AutoChargeTask.cs +++ b/Service/Charger/MyTask/AutoChargeTask.cs @@ -8,6 +8,7 @@ using log4net; using Newtonsoft.Json; using Repository.Station; using Service.Charger.Client; +using Service.Charger.Server; using Service.Init; namespace Service.Charger.MyTask; @@ -200,7 +201,7 @@ public class AutoChargeTask : ITask if (binInfo.ChargeStatus != 1) { //没有充电时候在充电 - Result? result = ClientMgr.GetBySn(binInfo.ChargerNo) + Result? result = ServerMgr.GetBySn(binInfo.ChargerNo) ?.StartCharge(chargeSoc, (float)power, 0); if (result is { IsSuccess: true }) { @@ -229,7 +230,7 @@ public class AutoChargeTask : ITask if (ch.Soc < StaticStationInfo.ChargeSoc) { Log.Info($"auto stop charge by more charging bin {ch.No} soc:{ch.Soc}"); - ClientMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging(); + ServerMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging(); count++; if (count == stopCount) { @@ -249,7 +250,7 @@ public class AutoChargeTask : ITask foreach (var binInfo in stopList) { Log.Info($"auto stop charge {binInfo.No} soc:{binInfo.Soc}"); - ClientMgr.GetBySn(binInfo.ChargerNo)?.SendRemoteStopCharging(); + ServerMgr.GetBySn(binInfo.ChargerNo)?.SendRemoteStopCharging(); } #endregion diff --git a/Service/Charger/MyTask/EmeterEnergyRecordTask.cs b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs index 9b59963..6a15142 100644 --- a/Service/Charger/MyTask/EmeterEnergyRecordTask.cs +++ b/Service/Charger/MyTask/EmeterEnergyRecordTask.cs @@ -7,6 +7,7 @@ using HybirdFrameworkCore.Utils; using log4net; using Repository.Station; using Service.Charger.Client; +using Service.Charger.Server; using Service.Init; namespace Service.Charger.MyTask; @@ -41,7 +42,7 @@ public class EmeterEnergyRecordTask : ITask EmeterEnergyRepository.Delete(i=>i.UploadTimei.UploadTime chargerClients = ClientMgr.Dictionary; + ConcurrentDictionary chargerClients = ServerMgr.Dictionary; if (chargerClients.Values.Count <= 0) { @@ -100,4 +101,4 @@ public class PileChargeRealtimeTask : ITask { _stop = false; } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/Service/Charger/MyTask/PileRealtimeTask.cs b/Service/Charger/MyTask/PileRealtimeTask.cs index 026bec3..ba03d61 100644 --- a/Service/Charger/MyTask/PileRealtimeTask.cs +++ b/Service/Charger/MyTask/PileRealtimeTask.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +/*using System.Collections.Concurrent; using Common.Util; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.AutoTask; @@ -8,6 +8,7 @@ using Service.Charger.Client; using Service.Charger.Common; using Service.Charger.Msg.Charger.OutCharger.Req; using Service.Charger.Msg.Http.Req; +using Service.Charger.Server; using Service.Init; namespace Service.Charger.MyTask; @@ -48,7 +49,7 @@ public class PileRealtimeTask : ITask } } if (ChargerConst._dictionary.Count <= 0)return; - ConcurrentDictionary chargerClients = ClientMgr.Dictionary; + ConcurrentDictionary chargerClients = ServerMgr.Dictionary; if (chargerClients.Values.Count <= 0) { @@ -117,4 +118,4 @@ public class PileRealtimeTask : ITask } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/Service/Charger/MyTask/QueryBatteryInfoTask.cs b/Service/Charger/MyTask/QueryBatteryInfoTask.cs index 679d661..85657a1 100644 --- a/Service/Charger/MyTask/QueryBatteryInfoTask.cs +++ b/Service/Charger/MyTask/QueryBatteryInfoTask.cs @@ -2,6 +2,7 @@ using HybirdFrameworkCore.AutoTask; using log4net; using Service.Charger.Client; +using Service.Charger.Server; namespace Service.Charger.MyTask; @@ -25,7 +26,7 @@ public class QueryBatteryInfoTask : ITask { try { - foreach (var (key, client) in ClientMgr.Dictionary) + foreach (var (key, client) in ServerMgr.Dictionary) { client.SendQueryBattery(); } diff --git a/Service/Charger/Server/ServerMgr.cs b/Service/Charger/Server/ServerMgr.cs index 256ddc1..916a2bf 100644 --- a/Service/Charger/Server/ServerMgr.cs +++ b/Service/Charger/Server/ServerMgr.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Threading.Channels; using Autofac; using DotNetty.Transport.Channels; using HybirdFrameworkCore.Autofac; @@ -69,4 +70,18 @@ public class ServerMgr return o; } + /// + /// + /// + /// + /// + public static void SessionAttr(IChannel channel,string sn, string destAddr) + { + ChannelUtils.AddAttr(channel, ChargerConst.ChargerSn, sn); + ChannelUtils.AddAttr(channel, ChargerConst.EqmTypeNo, sn); + ChannelUtils.AddAttr(channel, ChargerConst.EqmCode, sn); + ChannelUtils.AddAttr(channel, ChargerConst.DestAddr, destAddr); + } + + } \ No newline at end of file diff --git a/Service/MyTask/BatteryInfoUploadTask.cs b/Service/MyTask/BatteryInfoUploadTask.cs index b4a9b51..50a70ea 100644 --- a/Service/MyTask/BatteryInfoUploadTask.cs +++ b/Service/MyTask/BatteryInfoUploadTask.cs @@ -8,6 +8,7 @@ using log4net; using Newtonsoft.Json; using Repository.Station; using Service.Charger.Client; +using Service.Charger.Server; using Service.Init; using Service.Swap.Dto; using SqlSugar; @@ -41,7 +42,7 @@ public class BatteryInfoUploadTask : ITask List batInfos = binInfos.Where(it => it.Exists == 1).Select(it => { Log.Info("start BatteryInfoUploadTask uoload bininfo select"); - ChargerClient? client = ClientMgr.GetBySn(it.ChargerNo); + ChargerClient? client = ServerMgr.GetBySn(it.ChargerNo); SingleBatInfo batInfo = new SingleBatInfo() { bn = it.BatteryNo, diff --git a/Service/Station/BinInfoService.cs b/Service/Station/BinInfoService.cs index 31f9db0..d7723c1 100644 --- a/Service/Station/BinInfoService.cs +++ b/Service/Station/BinInfoService.cs @@ -83,7 +83,7 @@ public class BinInfoService : BaseServices // 功率赋值 foreach (var binInfoResp in binInfoList) { - ChargerClient? chargerClient = ClientMgr.GetBySn(binInfoResp.ChargerNo); + ChargerClient? chargerClient = ServerMgr.GetBySn(binInfoResp.ChargerNo); if (chargerClient != null) { binInfoResp.ChargeConnectFlag = chargerClient.Connected; diff --git a/WebStarter/Controllers/ChargeController.cs b/WebStarter/Controllers/ChargeController.cs index 2efa31d..6d1c3ec 100644 --- a/WebStarter/Controllers/ChargeController.cs +++ b/WebStarter/Controllers/ChargeController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Repository.Station; using Service.Charger; using Service.Charger.Client; +using Service.Charger.Server; using Service.Station; namespace WebStarter.Controllers; @@ -38,30 +39,11 @@ public class ChargeController : ControllerBase [Route("GetChargerCodeList")] public async Task>> GetChargerCodeList() { - List keysList = new List(ClientMgr.Dictionary.Keys); + List keysList = new List(ServerMgr.Dictionary.Keys); return Result>.Success(keysList); } - /// - /// 给充电机发鉴权 - /// - /// 充电机编码 - /// 发送结果 - [HttpGet] - [Route("ChargerSendAuth/{code}")] - public Result ChargerSendAuth(string code) - { - ChargerClient? chargerClient = ClientMgr.GetBySn(code); - - if (chargerClient != null) - { - chargerClient.SendAuth(); - return Result.Success(true); - } - - return Result.Fail("充电机未连接"); - - } + /// /// 给充电机发送功率调节指令 @@ -78,7 +60,7 @@ public class ChargeController : ControllerBase } string _code = _binInfoService.QueryByClause(i => i.Code == code).ChargerNo; - ChargerClient? chargerClient = ClientMgr.GetBySn(_code); + ChargerClient? chargerClient = ServerMgr.GetBySn(_code); if (chargerClient != null) { @@ -133,7 +115,7 @@ public class ChargeController : ControllerBase [Route("GetBinPowers")] public Result GetBinPowers() { - float[] results = ClientMgr.Dictionary.Values + float[] results = ServerMgr.Dictionary.Values .Select(chargerClient => chargerClient.RealTimeChargePower) .ToArray(); return Result.Success(results); diff --git a/WebStarter/Controllers/OutChargerController.cs b/WebStarter/Controllers/OutChargerController.cs index 2857fca..e061965 100644 --- a/WebStarter/Controllers/OutChargerController.cs +++ b/WebStarter/Controllers/OutChargerController.cs @@ -5,6 +5,7 @@ using Repository.Station; using Service.Charger.Client; using Service.Charger.Common; using Service.Charger.Msg.Http.Req; +using Service.Charger.Server; using Service.Init; using Service.Station; @@ -42,7 +43,7 @@ public class OutChargerController byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn); - ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode); + ChargerClient? chargerClient = ServerMgr.GetBySn(chargerCode); if (chargerClient == null) { @@ -94,7 +95,7 @@ public class OutChargerController byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn); - ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode); + ChargerClient? chargerClient = ServerMgr.GetBySn(chargerCode); if (chargerClient == null) { @@ -127,7 +128,7 @@ public class OutChargerController } string _code = _binInfoService.QueryByClause(i => i.Code == code).ChargerNo; - ChargerClient? chargerClient = ClientMgr.GetBySn(_code); + ChargerClient? chargerClient = ServerMgr.GetBySn(_code); if (chargerClient != null) { @@ -146,7 +147,7 @@ public class OutChargerController [Route("GetChargerPile")] public Result> GetChargerPile() { - var chargerClients = ClientMgr.Dictionary; + var chargerClients = ServerMgr.Dictionary; if (chargerClients.IsEmpty) { return Result>.Fail("没有充电机连接"); diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 6d27cd1..d83c8e6 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -8,6 +8,7 @@ using HybirdFrameworkCore.Job; using HybirdFrameworkCore.Redis; using log4net; using Service.Charger.Client; +using Service.Charger.Server; using Service.RealTime; using SqlSugar; using SqlSugar.IOC; @@ -101,9 +102,9 @@ foreach (var s in list.Split(";")) AppInfo.Container = app.Services.GetAutofacRoot(); -ClientMgr.InitClient(); +ServerMgr.InitServer(2408); -TaskInit.Init(); +//TaskInit.Init(); QuartzSchedulerFactory.Init(); app.Lifetime.ApplicationStopping.Register(QuartzSchedulerFactory.Shutdown); diff --git a/WebStarter/appsettings.dev.json b/WebStarter/appsettings.dev.json index ede9554..91eca2c 100644 --- a/WebStarter/appsettings.dev.json +++ b/WebStarter/appsettings.dev.json @@ -2,7 +2,7 @@ "ConnectionStrings": { "ConfigId": "master", "DbType": "MySql", - "SqlConnection": "server=180.76.133.253;Port=16306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;" + "SqlConnection": "server=localhost;Port=3306;Database=eaxing_back_africa_dev;Uid=root;Pwd=lxw123;Charset=utf8;" }, "Update": { "AutoUpdate": "false", @@ -10,7 +10,7 @@ "Url": "http://121.4.95.243:8090/Updates/AutoUpdaterStarter.xml" }, "Redis": { - "Connection": "106.12.36.89:6379,password=123456", + "Connection": "localhost:6379,password=123456", "InstanceName": "local", "DefaultDB": "8" }, @@ -35,5 +35,6 @@ "Job": { "Enabled": false }, + "AllowedHosts": "*" } diff --git a/WebStarter/log4net.config b/WebStarter/log4net.config index 0afbc89..d3dadbf 100644 --- a/WebStarter/log4net.config +++ b/WebStarter/log4net.config @@ -26,11 +26,11 @@ - + - + - + @@ -44,11 +44,11 @@ - + - + - + @@ -62,11 +62,11 @@ - + - + - + @@ -80,96 +80,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/WinFormStarter/Form2.cs b/WinFormStarter/Form2.cs index cc9cc76..af8b94f 100644 --- a/WinFormStarter/Form2.cs +++ b/WinFormStarter/Form2.cs @@ -111,7 +111,7 @@ public partial class Form2 : Form private void btnConn_Click(object sender, EventArgs e) { - string ip = txtIp.Text; + /*string ip = txtIp.Text; var port = int.Parse(txtPort.Text); string destAddr = txtDestAddr.Text; @@ -148,12 +148,12 @@ public partial class Form2 : Form EnableUi(this.rTxtSend, false); EnableUi(this.rTxtReceive, false); } - }); + });*/ } private void btnAuth_Click(object sender, EventArgs e) { - _chargerClient?.SendAuth(); +//_chargerClient?.SendAuth(); AppendText(this.rTxtSend, _chargerClient.CurrentCmd); DisplayData(); MessageBox.Show(@"发送成功");