From 2672cce1249a6690137d1995ec0c135a89b2d43f Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Sun, 19 May 2024 23:42:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=9C=BA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/ChargeOrder.cs | 2 +- Service/Charger/Client/ChargerClient.cs | 87 ++++++++++++-- .../Charger/Handler/RecordChargeHandler.cs | 110 +++++++++++++----- .../Charger/Msg/Charger/Req/RecordCharge.cs | 2 +- .../Charger/Msg/Host/Req/AdjustChargeRate.cs | 14 ++- ...Charging.cs => OutSideAllowChargingSoc.cs} | 5 +- .../Charger/Msg/Host/Req/PowerRegulation.cs | 4 +- .../Msg/Host/Req/RemoteStartCharging.cs | 6 + .../Msg/Host/Req/RemoteStopCharging.cs | 5 + .../Msg/Host/Resp/RecordChargRespData.cs | 40 ------- .../Msg/Host/Resp/RecordChargeRespData.cs | 40 +++++++ WinFormStarter/Form2.Designer.cs | 53 ++++++++- WinFormStarter/Form2.cs | 95 ++++++++++++++- 13 files changed, 363 insertions(+), 100 deletions(-) rename Service/Charger/Msg/Host/Req/{OutSideAllowCharging.cs => OutSideAllowChargingSoc.cs} (72%) delete mode 100644 Service/Charger/Msg/Host/Resp/RecordChargRespData.cs create mode 100644 Service/Charger/Msg/Host/Resp/RecordChargeRespData.cs diff --git a/Entity/DbModel/Station/ChargeOrder.cs b/Entity/DbModel/Station/ChargeOrder.cs index d80d0a1..668f865 100644 --- a/Entity/DbModel/Station/ChargeOrder.cs +++ b/Entity/DbModel/Station/ChargeOrder.cs @@ -117,7 +117,7 @@ namespace Entity.DbModel.Station /// Nullable:True /// [SugarColumn(ColumnName="charge_time_count")] - public string ChargeTimeCount {get;set;} + public int? ChargeTimeCount {get;set;} /// /// Desc:充电电量 diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index 365f2b7..c4207ef 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using Service.Charger.Codec; using Service.Charger.Common; using Service.Charger.Handler; +using Service.Charger.Msg; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Resp; using Service.Charger.Msg.Host.Req; @@ -19,6 +20,9 @@ namespace Service.Charger.Client; [Scope("InstancePerDependency")] public class ChargerClient : TcpClient { + + #region 属性 + public ushort AuthTimes { get; set; } = 0; public bool IsAuthed { get; set; } = false; @@ -95,8 +99,6 @@ public class ChargerClient : TcpClient /// 充电机告警-遥信数据包总告警 00H正常、01H告警 /// public bool TotalWarning { get; set; } - - /// /// 充电机遥测数据 /// @@ -113,13 +115,34 @@ public class ChargerClient : TcpClient /// /// 电池编码 /// - public string BatterSn { get; set; } + public string? BatterSn { get; set; } /// /// 远程升级-监控网关上送升级完成确认帧 /// public UplinkUpgrade UplinkUpgrade { get; set; } - + /// + /// 充电订单号 + /// + public string? ChargeOrderNo { get; set; } + /// + /// 当前指令 + /// public string? CurrentCmd { get; set; } + /// + /// 当前接收报文 + /// + public string? CurrentMsg { get; set; } + + #endregion + + /// + /// + /// + /// + public void ReceiveMsgHandle(ASDU asdu) + { + this.CurrentMsg = CurrentCmd = JsonConvert.SerializeObject(asdu, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(asdu.ToBytes()); + } #region 发送指令 @@ -146,7 +169,7 @@ public class ChargerClient : TcpClient byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数] byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码 Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey); - CurrentCmd = JsonConvert.SerializeObject(auth)+ "\r\n" + BitUtls.BytesToHexStr(auth.ToBytes()); + CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auth.ToBytes()); this.Channel.WriteAndFlushAsync(auth); } @@ -157,7 +180,7 @@ public class ChargerClient : TcpClient /// 功率调节指令类型.默认1 绝对功率值 /// 0.1kw/位,默认3600 /// 充电流水号 - public void SendRemoteStartCharging(byte socLimit, float changePower, byte changePowerCmdType=1, + public string SendRemoteStartCharging(byte socLimit, float changePower=3600, byte changePowerCmdType=1, string? chargeOrderNo = null) { if (string.IsNullOrWhiteSpace(chargeOrderNo)) @@ -165,8 +188,10 @@ public class ChargerClient : TcpClient chargeOrderNo = ChargerUtils.GenChargeOrderSn(); } var remoteStartCharging = new RemoteStartCharging(socLimit, changePowerCmdType, changePower, chargeOrderNo); - CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging)+ "\r\n" + BitUtls.BytesToHexStr(remoteStartCharging.ToBytes()); + CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(remoteStartCharging.ToBytes()); this.Channel.WriteAndFlushAsync(remoteStartCharging); + + return chargeOrderNo; } /// @@ -176,7 +201,7 @@ public class ChargerClient : TcpClient public void SendRemoteStopCharging(byte reason) { RemoteStopCharging remoteStopCharging = new RemoteStopCharging(reason); - CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging) + "\r\n" + BitUtls.BytesToHexStr(remoteStopCharging.ToBytes()); + CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging, Formatting.Indented) + "\r\n" + BitUtls.BytesToHexStr(remoteStopCharging.ToBytes()); this.Channel.WriteAndFlushAsync(remoteStopCharging); } @@ -184,12 +209,22 @@ public class ChargerClient : TcpClient /// 监控平台发送功率调节指令 /// /// 期望运行功率 - public void SendPowerRegulation(ushort expectedOperatingPower) + public void SendPowerRegulation(float expectedOperatingPower) { PowerRegulation powerRegulation = new PowerRegulation(expectedOperatingPower); this.Channel.WriteAndFlushAsync(powerRegulation); } + /// + /// 倍率 例如,0.单5C位该0值.1C为 5 ,1C 时该值为 10 + /// + /// + public void SendAdjustChargeRate(float rate) + { + AdjustChargeRate adjustChargeRate = new AdjustChargeRate(rate); + this.Channel.WriteAndFlushAsync(adjustChargeRate); + } + /// /// 监控平台下发辅源控制指令 /// @@ -197,6 +232,7 @@ public class ChargerClient : TcpClient public void SendAuxiliaryPower(byte openFlag) { AuxiliaryPower auxiliaryPower = new AuxiliaryPower(openFlag); + CurrentCmd = JsonConvert.SerializeObject(auxiliaryPower, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auxiliaryPower.ToBytes()); this.Channel.WriteAndFlushAsync(auxiliaryPower); } @@ -209,6 +245,7 @@ public class ChargerClient : TcpClient public void SendBatteryHolderStatus(byte battery, byte connectionState, byte waterCondition) { BatteryHolderStatus batteryHolderStatus = new BatteryHolderStatus(battery, connectionState, waterCondition); + CurrentCmd = JsonConvert.SerializeObject(batteryHolderStatus, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(batteryHolderStatus.ToBytes()); this.Channel.WriteAndFlushAsync(batteryHolderStatus); } @@ -240,6 +277,36 @@ public class ChargerClient : TcpClient this.Channel.WriteAndFlushAsync(upgradeRequest); } + /// + /// 设置尖峰平谷时间段 + /// + /// + public void SendSetPeakValleyTime(SetPeakValleyTime setPeakValleyTime) + { + CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(setPeakValleyTime.ToBytes()); + this.Channel.WriteAndFlushAsync(setPeakValleyTime); + } + + /// + /// 3.4.7 监控平台下发掉线停止充电 + /// + /// 0:不使能 1:使能 + public void SendOfflineStopCharging(byte enabled) + { + OfflineStopCharging offlineStopCharging = new OfflineStopCharging(enabled); + CurrentCmd = JsonConvert.SerializeObject(offlineStopCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(offlineStopCharging.ToBytes()); + this.Channel.WriteAndFlushAsync(offlineStopCharging); + } + + /// + /// 3.4.12 站控设备切换站内/站外充电切换 + /// + /// 00:无效 01:站内 02:站外 + public void SendChangeChargeMode(byte chargeMode) + { + ChangeChargeMode req = new ChangeChargeMode(chargeMode); + this.Channel.WriteAndFlushAsync(req); + } /// /// @@ -247,7 +314,7 @@ public class ChargerClient : TcpClient public void SendQueryBattery() { QueryBattery queryBattery = new QueryBattery(ChargerConst.BatteryNo); - CurrentCmd = JsonConvert.SerializeObject(queryBattery)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes()); + CurrentCmd = JsonConvert.SerializeObject(queryBattery, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes()); this.Channel.WriteAndFlushAsync(queryBattery); } diff --git a/Service/Charger/Handler/RecordChargeHandler.cs b/Service/Charger/Handler/RecordChargeHandler.cs index 4628e3b..87ae85e 100644 --- a/Service/Charger/Handler/RecordChargeHandler.cs +++ b/Service/Charger/Handler/RecordChargeHandler.cs @@ -1,10 +1,11 @@ -using Autofac; -using DotNetty.Transport.Channels; -using HybirdFrameworkCore.Autofac; +using DotNetty.Transport.Channels; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; -using HybirdFrameworkCore.Redis; using log4net; +using Repository.Station; +using Service.Charger.Client; using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; namespace Service.Charger.Handler { @@ -21,39 +22,86 @@ namespace Service.Charger.Handler [Order(8)] [Scope("InstancePerDependency")] public class RecordChargeHandler : SimpleChannelInboundHandler, IBaseHandler - { + { private static readonly ILog Log = LogManager.GetLogger(typeof(RecordChargeHandler)); - protected override void ChannelRead0(IChannelHandlerContext ctx, RecordCharge? msg) + + private ChargeOrderRepository _chargeOrderRepository; + + /// + /// + /// + /// + public RecordChargeHandler(ChargeOrderRepository chargeOrderRepository) + { + _chargeOrderRepository = chargeOrderRepository; + } + + protected override void ChannelRead0(IChannelHandlerContext ctx, RecordCharge msg) { + + if(ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + msg.StartTime = (msg.StartYear+1900) + "-" + msg.StartMonth + "-" + msg.StartDay + " " + msg.StartHour + ":" + msg.StartMinute + ":" + msg.StartSecond; + msg.EndTime = (msg.EndYear+1900) + "-" + msg.EndMonth + "-" + msg.EndDay + " " + msg.EndHour + ":" + msg.EndMinute + ":" + msg.EndSecond; - msg.StartTime = (msg.StartYear+1900) + "-" + msg.StartMonth + "-" + msg.StartDay + " " + msg.StartHour + ":" + msg.StartMinute + ":" + msg.StartSecond; - msg.EndTime = (msg.EndYear+1900) + "-" + msg.EndMonth + "-" + msg.EndDay + " " + msg.EndHour + ":" + msg.EndMinute + ":" + msg.EndSecond; + float[] powersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷 + if (msg.FlagOfTime1 >= 1 && msg.FlagOfTime1 <= 4){powersPeriods[msg.FlagOfTime1 - 1] += msg.ChargingPowerOfTime1;} + if (msg.FlagOfTime2 >= 1 && msg.FlagOfTime2 <= 4){powersPeriods[msg.FlagOfTime2 - 1] += msg.ChargingPowerOfTime2;} + if (msg.FlagOfTime3 >= 1 && msg.FlagOfTime3 <= 4){powersPeriods[msg.FlagOfTime3 - 1] += msg.ChargingPowerOfTime3;} + if (msg.FlagOfTime4 >= 1 && msg.FlagOfTime4 <= 4){powersPeriods[msg.FlagOfTime4 - 1] += msg.ChargingPowerOfTime4;} + if (msg.FlagOfTime5 >= 1 && msg.FlagOfTime5 <= 4){powersPeriods[msg.FlagOfTime5 - 1] += msg.ChargingPowerOfTime5;} + if (msg.FlagOfTime6 >= 1 && msg.FlagOfTime6 <= 4){powersPeriods[msg.FlagOfTime6 - 1] += msg.ChargingPowerOfTime6;} + if (msg.FlagOfTime7 >= 1 && msg.FlagOfTime7 <= 4){powersPeriods[msg.FlagOfTime7 - 1] += msg.ChargingPowerOfTime7;} + if (msg.FlagOfTime8 >= 1 && msg.FlagOfTime8 <= 4){powersPeriods[msg.FlagOfTime8 - 1] += msg.ChargingPowerOfTime8;} + + float[] acPowersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷 + if (msg.AcFlagOfTime1 >= 1 && msg.AcFlagOfTime1 <= 4){acPowersPeriods[msg.AcFlagOfTime1 - 1] += msg.AcChargingPowerOfTime1;} + if (msg.AcFlagOfTime2 >= 1 && msg.AcFlagOfTime2 <= 4){acPowersPeriods[msg.AcFlagOfTime2 - 1] += msg.AcChargingPowerOfTime2;} + if (msg.AcFlagOfTime3 >= 1 && msg.AcFlagOfTime3 <= 4){acPowersPeriods[msg.AcFlagOfTime3 - 1] += msg.AcChargingPowerOfTime3;} + if (msg.AcFlagOfTime4 >= 1 && msg.AcFlagOfTime4 <= 4){acPowersPeriods[msg.AcFlagOfTime4 - 1] += msg.AcChargingPowerOfTime4;} + if (msg.AcFlagOfTime5 >= 1 && msg.AcFlagOfTime5 <= 4){acPowersPeriods[msg.AcFlagOfTime5 - 1] += msg.AcChargingPowerOfTime5;} + if (msg.AcFlagOfTime6 >= 1 && msg.AcFlagOfTime6 <= 4){acPowersPeriods[msg.AcFlagOfTime6 - 1] += msg.AcChargingPowerOfTime6;} + if (msg.AcFlagOfTime7 >= 1 && msg.AcFlagOfTime7 <= 4){acPowersPeriods[msg.AcFlagOfTime7 - 1] += msg.AcChargingPowerOfTime7;} + if (msg.AcFlagOfTime8 >= 1 && msg.AcFlagOfTime8 <= 4){acPowersPeriods[msg.AcFlagOfTime8 - 1] += msg.AcChargingPowerOfTime8;} + client.ChargeOrderNo = msg.ChargerOrderNo; - float[] powersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷 - if (msg.FlagOfTime1 >= 1 && msg.FlagOfTime1 <= 4){powersPeriods[msg.FlagOfTime1 - 1] += msg.ChargingPowerOfTime1;} - if (msg.FlagOfTime2 >= 1 && msg.FlagOfTime2 <= 4){powersPeriods[msg.FlagOfTime2 - 1] += msg.ChargingPowerOfTime2;} - if (msg.FlagOfTime3 >= 1 && msg.FlagOfTime3 <= 4){powersPeriods[msg.FlagOfTime3 - 1] += msg.ChargingPowerOfTime3;} - if (msg.FlagOfTime4 >= 1 && msg.FlagOfTime4 <= 4){powersPeriods[msg.FlagOfTime4 - 1] += msg.ChargingPowerOfTime4;} - if (msg.FlagOfTime5 >= 1 && msg.FlagOfTime5 <= 4){powersPeriods[msg.FlagOfTime5 - 1] += msg.ChargingPowerOfTime5;} - if (msg.FlagOfTime6 >= 1 && msg.FlagOfTime6 <= 4){powersPeriods[msg.FlagOfTime6 - 1] += msg.ChargingPowerOfTime6;} - if (msg.FlagOfTime7 >= 1 && msg.FlagOfTime7 <= 4){powersPeriods[msg.FlagOfTime7 - 1] += msg.ChargingPowerOfTime7;} - if (msg.FlagOfTime8 >= 1 && msg.FlagOfTime8 <= 4){powersPeriods[msg.FlagOfTime8 - 1] += msg.ChargingPowerOfTime8;} - - float[] acPowersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值;1:尖;2:峰;3:平;4:谷 - if (msg.AcFlagOfTime1 >= 1 && msg.AcFlagOfTime1 <= 4){acPowersPeriods[msg.AcFlagOfTime1 - 1] += msg.AcChargingPowerOfTime1;} - if (msg.AcFlagOfTime2 >= 1 && msg.AcFlagOfTime2 <= 4){acPowersPeriods[msg.AcFlagOfTime2 - 1] += msg.AcChargingPowerOfTime2;} - if (msg.AcFlagOfTime3 >= 1 && msg.AcFlagOfTime3 <= 4){acPowersPeriods[msg.AcFlagOfTime3 - 1] += msg.AcChargingPowerOfTime3;} - if (msg.AcFlagOfTime4 >= 1 && msg.AcFlagOfTime4 <= 4){acPowersPeriods[msg.AcFlagOfTime4 - 1] += msg.AcChargingPowerOfTime4;} - if (msg.AcFlagOfTime5 >= 1 && msg.AcFlagOfTime5 <= 4){acPowersPeriods[msg.AcFlagOfTime5 - 1] += msg.AcChargingPowerOfTime5;} - if (msg.AcFlagOfTime6 >= 1 && msg.AcFlagOfTime6 <= 4){acPowersPeriods[msg.AcFlagOfTime6 - 1] += msg.AcChargingPowerOfTime6;} - if (msg.AcFlagOfTime7 >= 1 && msg.AcFlagOfTime7 <= 4){acPowersPeriods[msg.AcFlagOfTime7 - 1] += msg.AcChargingPowerOfTime7;} - if (msg.AcFlagOfTime8 >= 1 && msg.AcFlagOfTime8 <= 4){acPowersPeriods[msg.AcFlagOfTime8 - 1] += msg.AcChargingPowerOfTime8;} - - - RedisHelper redisHelper = AppInfo.Container.Resolve(); - var hlpChannelARedis = redisHelper.GetDatabase(7); + int count = _chargeOrderRepository.GetCount(it => it.Sn == client.ChargeOrderNo); + if (count < 1) + { + ChargeOrder chargeOrder = new ChargeOrder() + { + Sn = client.ChargeOrderNo, + BatteryNo = client.BatterSn, + StartTime = new DateTime((msg.StartYear+1900) , msg.StartMonth ,msg.StartDay ,msg.StartHour, msg.StartMinute, msg.StartSecond), + EndTime = new DateTime(msg.EndYear + 1900, msg.EndMonth, msg.EndDay, msg.EndHour, msg.EndMinute, msg.EndSecond), + StartSoc = msg.SocBefore, + StopSoc = msg.SocAfter, + ChargeTimeCount= msg.ChargingTimeCount, + ElecCount = Convert.ToDecimal(msg.ChargingPower), + AcElecCount = Convert.ToDecimal(msg.AcMeterElecCount), + StartAcElec = Convert.ToDecimal(msg.AcMeterDataBefore), + StopAcElec = Convert.ToDecimal(msg.AcMeterDataAfter), + StartDcElec = Convert.ToDecimal(msg.DcMeterDataBefore), + StopDcElec = Convert.ToDecimal(msg.DcMeterDataAfter), + SharpElecCount = Convert.ToDecimal(powersPeriods[0]), + PeakElecCount = Convert.ToDecimal(powersPeriods[0]), + FlatElecCount = Convert.ToDecimal(powersPeriods[0]), + ValleyElecCount = Convert.ToDecimal(powersPeriods[0]), + AcSharpElecCount = Convert.ToDecimal(acPowersPeriods[0]), + AcPeakElecCount = Convert.ToDecimal(acPowersPeriods[0]), + AcFlatElecCount = Convert.ToDecimal(acPowersPeriods[0]), + AcValleyElecCount = Convert.ToDecimal(acPowersPeriods[0]), + ChargeMode = msg.ChargeMode, + StartMode = msg.StartMode + }; + + _chargeOrderRepository.Insert(chargeOrder); + } + + ctx.Channel.WriteAndFlushAsync(new RecordChargeRespData()); + } } } diff --git a/Service/Charger/Msg/Charger/Req/RecordCharge.cs b/Service/Charger/Msg/Charger/Req/RecordCharge.cs index dd80e0f..0993ee2 100644 --- a/Service/Charger/Msg/Charger/Req/RecordCharge.cs +++ b/Service/Charger/Msg/Charger/Req/RecordCharge.cs @@ -8,7 +8,7 @@ namespace Service.Charger.Msg.Charger.Req public class RecordCharge : ASDU { /// - /// 充电开始时间-秒 + /// 订单编号 /// [Property(0, 256, PropertyReadConstant.Byte)] public string ChargerOrderNo { get; set; } diff --git a/Service/Charger/Msg/Host/Req/AdjustChargeRate.cs b/Service/Charger/Msg/Host/Req/AdjustChargeRate.cs index 6ff2277..556eb36 100644 --- a/Service/Charger/Msg/Host/Req/AdjustChargeRate.cs +++ b/Service/Charger/Msg/Host/Req/AdjustChargeRate.cs @@ -3,12 +3,12 @@ namespace Service.Charger.Msg.Host.Req { /// - /// 3.4.1 监控平台发送功率调节指令 + /// 3.4.5 监控平台下发充电速率设置 /// public class AdjustChargeRate : ASDU { /// - /// 记录类型 + /// 倍率 例如,0.单5C位该0值.1C为 5 ,1C 时该值为 10 /// [Property(0, 8)] public byte RecordType { get; set; } @@ -17,9 +17,13 @@ namespace Service.Charger.Msg.Host.Req ///期望运行 功率 /// [Property(8, 16, scale: 0.1)] - public float ExpectedOperatingPower { get; set; } + public float ChargeRage { get; set; } - public AdjustChargeRate(float expectedOperatingPower) + /// + /// + /// + /// + public AdjustChargeRate(float chargeRage) { FrameTypeNo = 45; MsgBodyCount = 1; @@ -28,7 +32,7 @@ namespace Service.Charger.Msg.Host.Req MsgBodyAddr = new byte[] { 0, 0, 0 }; RecordType = 20; - ExpectedOperatingPower = expectedOperatingPower; + ChargeRage = chargeRage; } } } \ No newline at end of file diff --git a/Service/Charger/Msg/Host/Req/OutSideAllowCharging.cs b/Service/Charger/Msg/Host/Req/OutSideAllowChargingSoc.cs similarity index 72% rename from Service/Charger/Msg/Host/Req/OutSideAllowCharging.cs rename to Service/Charger/Msg/Host/Req/OutSideAllowChargingSoc.cs index e37e767..5ff0da9 100644 --- a/Service/Charger/Msg/Host/Req/OutSideAllowCharging.cs +++ b/Service/Charger/Msg/Host/Req/OutSideAllowChargingSoc.cs @@ -3,14 +3,15 @@ namespace Service.Charger.Msg.Host.Req { /// - /// 3.4.7 监控平台下发站外允许充电 SOC + /// 3.4.9 监控平台下发站外允许充电 SOC /// - public class OutSideAllowCharging : ASDU + public class OutSideAllowChargingSoc : ASDU { /// /// SOC 限制值 /// [Property(0, 8)] public byte SocValue { get; set; } + } } \ No newline at end of file diff --git a/Service/Charger/Msg/Host/Req/PowerRegulation.cs b/Service/Charger/Msg/Host/Req/PowerRegulation.cs index 82fceae..b0c9a02 100644 --- a/Service/Charger/Msg/Host/Req/PowerRegulation.cs +++ b/Service/Charger/Msg/Host/Req/PowerRegulation.cs @@ -22,9 +22,9 @@ namespace Service.Charger.Msg.Host.Req /// 期望运行功率 /// [Property(8, 16, scale: 0.1)] - public ushort ExpectedOperatingPower { get; set; } + public float ExpectedOperatingPower { get; set; } - public PowerRegulation(ushort expectedOperatingPower) + public PowerRegulation(float expectedOperatingPower) { PackLen = 0; CtlArea = 0; diff --git a/Service/Charger/Msg/Host/Req/RemoteStartCharging.cs b/Service/Charger/Msg/Host/Req/RemoteStartCharging.cs index 6d92313..461c3da 100644 --- a/Service/Charger/Msg/Host/Req/RemoteStartCharging.cs +++ b/Service/Charger/Msg/Host/Req/RemoteStartCharging.cs @@ -10,6 +10,12 @@ namespace Service.Charger.Msg.Host.Req public RemoteStartCharging(byte socLimit, byte changePowerCmdType, float changePower, string chargeOrderNo) { + FrameTypeNo = 47; + MsgBodyCount = 1; + TransReason = 3; + PublicAddr = 0; + MsgBodyAddr = new byte[] { 0, 0, 0 }; + SocLimit = socLimit; ChangePowerCmdType = changePowerCmdType; ChangePower = changePower; diff --git a/Service/Charger/Msg/Host/Req/RemoteStopCharging.cs b/Service/Charger/Msg/Host/Req/RemoteStopCharging.cs index 5300102..059caed 100644 --- a/Service/Charger/Msg/Host/Req/RemoteStopCharging.cs +++ b/Service/Charger/Msg/Host/Req/RemoteStopCharging.cs @@ -15,6 +15,11 @@ namespace Service.Charger.Msg.Host.Req public RemoteStopCharging(byte stopReason) { + FrameTypeNo = 50; + MsgBodyCount = 1; + TransReason = 3; + PublicAddr = 0; + MsgBodyAddr = new byte[] { 0, 0, 0 }; StopReason = stopReason; } } diff --git a/Service/Charger/Msg/Host/Resp/RecordChargRespData.cs b/Service/Charger/Msg/Host/Resp/RecordChargRespData.cs deleted file mode 100644 index 89eb6ce..0000000 --- a/Service/Charger/Msg/Host/Resp/RecordChargRespData.cs +++ /dev/null @@ -1,40 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; - -namespace Service.Charger.Msg.Host.Resp -{ - /// - /// 3.5.6 主动上送充电记录响应 - /// - public class RecordChargRespData : ASDU - { - //保留1 - [Property(0, 8)] public byte Reserve1 { get; set; } - - /// - /// 充电流水号 - /// - [Property(8, 16, PropertyReadConstant.Byte)] - public byte[] ChargingWater { get; set; } - - /// - /// 充电流水号 - /// - public string ChargingSn { get; set; } - - public RecordChargRespData(string chargingWater) - { - PackLen = 0; - CtlArea = 0; - SrcAddr = 0; - - FrameTypeNo = 70; - MsgBodyCount = 1; - TransReason = 3; - PublicAddr = 0; - MsgBodyAddr = new byte[] { 0, 0, 0 }; - - Reserve1 = 0; - ChargingSn = chargingWater; - } - } -} \ No newline at end of file diff --git a/Service/Charger/Msg/Host/Resp/RecordChargeRespData.cs b/Service/Charger/Msg/Host/Resp/RecordChargeRespData.cs new file mode 100644 index 0000000..64cd770 --- /dev/null +++ b/Service/Charger/Msg/Host/Resp/RecordChargeRespData.cs @@ -0,0 +1,40 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Charger.Msg.Host.Resp +{ + /// + /// 3.5.7 主动上送充电记录响应 + /// + public class RecordChargeRespData : ASDU + { + /// + /// + /// + [Property(0, 8)] + public byte Reserve1 { get; set; } + + /// + /// 充电流水号 + /// + [Property(8, 8)] + public byte Reserve2 { get; set; } + /// + /// + /// + public RecordChargeRespData() + { + PackLen = 0; + CtlArea = 0; + SrcAddr = 0; + + FrameTypeNo = 43; + MsgBodyCount = 1; + TransReason = 4; + PublicAddr = 0; + MsgBodyAddr = new byte[] { 0, 0, 0 }; + + Reserve1 = 0; + Reserve2 = 0; + } + } +} \ No newline at end of file diff --git a/WinFormStarter/Form2.Designer.cs b/WinFormStarter/Form2.Designer.cs index d5a6326..bcdb398 100644 --- a/WinFormStarter/Form2.Designer.cs +++ b/WinFormStarter/Form2.Designer.cs @@ -62,6 +62,10 @@ partial class Form2 this.label2 = new System.Windows.Forms.Label(); this.txtIp = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.btnRefreshData = new System.Windows.Forms.Button(); + this.lblBatterNo = new System.Windows.Forms.Label(); + this.lblChargeOrderNo = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.grpData.SuspendLayout(); this.grpMsg.SuspendLayout(); @@ -73,6 +77,7 @@ partial class Form2 this.groupBox7.SuspendLayout(); this.grpCmd.SuspendLayout(); this.groupBox2.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // groupBox1 @@ -91,6 +96,7 @@ partial class Form2 // // grpData // + this.grpData.Controls.Add(this.panel1); this.grpData.Controls.Add(this.rTxtData); this.grpData.Dock = System.Windows.Forms.DockStyle.Fill; this.grpData.Location = new System.Drawing.Point(3, 718); @@ -102,10 +108,10 @@ partial class Form2 // // rTxtData // - this.rTxtData.Dock = System.Windows.Forms.DockStyle.Fill; + this.rTxtData.Dock = System.Windows.Forms.DockStyle.Left; this.rTxtData.Location = new System.Drawing.Point(3, 19); this.rTxtData.Name = "rTxtData"; - this.rTxtData.Size = new System.Drawing.Size(1106, 407); + this.rTxtData.Size = new System.Drawing.Size(613, 407); this.rTxtData.TabIndex = 0; this.rTxtData.Text = ""; // @@ -405,6 +411,43 @@ partial class Form2 this.label1.TabIndex = 0; this.label1.Text = "IP:"; // + // panel1 + // + this.panel1.Controls.Add(this.lblChargeOrderNo); + this.panel1.Controls.Add(this.lblBatterNo); + this.panel1.Controls.Add(this.btnRefreshData); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(616, 19); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(493, 407); + this.panel1.TabIndex = 1; + // + // btnRefreshData + // + this.btnRefreshData.Location = new System.Drawing.Point(28, 31); + this.btnRefreshData.Name = "btnRefreshData"; + this.btnRefreshData.Size = new System.Drawing.Size(75, 23); + this.btnRefreshData.TabIndex = 19; + this.btnRefreshData.Text = "刷新数据"; + this.btnRefreshData.UseVisualStyleBackColor = true; + this.btnRefreshData.Click += new System.EventHandler(this.btnRefreshData_Click); + // + // lblBatterNo + // + this.lblBatterNo.AutoSize = true; + this.lblBatterNo.Location = new System.Drawing.Point(148, 35); + this.lblBatterNo.Name = "lblBatterNo"; + this.lblBatterNo.Size = new System.Drawing.Size(0, 15); + this.lblBatterNo.TabIndex = 20; + // + // lblChargeOrderNo + // + this.lblChargeOrderNo.AutoSize = true; + this.lblChargeOrderNo.Location = new System.Drawing.Point(148, 77); + this.lblChargeOrderNo.Name = "lblChargeOrderNo"; + this.lblChargeOrderNo.Size = new System.Drawing.Size(0, 15); + this.lblChargeOrderNo.TabIndex = 21; + // // Form2 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -425,6 +468,8 @@ partial class Form2 this.grpCmd.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); this.ResumeLayout(false); } @@ -462,4 +507,8 @@ partial class Form2 private RichTextBox rTxtSend; private GroupBox grpData; private RichTextBox rTxtData; + private Panel panel1; + private Button btnRefreshData; + private Label lblChargeOrderNo; + private Label lblBatterNo; } \ No newline at end of file diff --git a/WinFormStarter/Form2.cs b/WinFormStarter/Form2.cs index 374cb2c..70ef0c8 100644 --- a/WinFormStarter/Form2.cs +++ b/WinFormStarter/Form2.cs @@ -3,12 +3,15 @@ using DotNetty.Handlers.Logging; using HybirdFrameworkCore.Autofac; using Newtonsoft.Json; using Service.Charger.Client; +using Service.Charger.Msg.Host.Req; +using Timer = System.Windows.Forms.Timer; namespace WinFormStarter; public partial class Form2 : Form { private ChargerClient? _chargerClient; + private Timer _timer= new Timer(); public Form2() { @@ -27,6 +30,21 @@ public partial class Form2 : Form this.rTxtSend.Enabled = false; this.rTxtReceive.Enabled = false; + + _timer.Tick += TimerOnTick; + _timer.Enabled = true; + _timer.Interval = 500; + _timer.Start(); + } + + private void TimerOnTick(object? sender, EventArgs e) + { + if (_chargerClient != null) + { + SetText(this.rTxtSend, _chargerClient?.CurrentCmd?? ""); + SetText(this.rTxtReceive, _chargerClient?.CurrentMsg?? ""); + SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented)); + } } #region ui invoke @@ -64,7 +82,7 @@ public partial class Form2 : Form rtxt.AppendText(t); } } - + private void SetText(Control textBox, string t) { if (textBox.InvokeRequired) @@ -87,10 +105,7 @@ public partial class Form2 : Form private void DisplayData() { this.SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented)); - } - - private void btnChangeInOrOut_Click(object sender, EventArgs e) - { + this.lblBatterNo.Text = _chargerClient?.BatterSn; } private void btnConn_Click(object sender, EventArgs e) @@ -139,49 +154,117 @@ public partial class Form2 : Form { _chargerClient?.SendAuth(); AppendText(this.rTxtSend, _chargerClient.CurrentCmd); - DisplayData(); + MessageBox.Show(@"发送成功"); } private void btnSendBinStatus_Click(object sender, EventArgs e) { + _chargerClient.SendBatteryHolderStatus(1, 1, 1); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnSendAuxiliaryPower_Click(object sender, EventArgs e) { + _chargerClient.SendAuxiliaryPower(1); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnStartCharge_Click(object sender, EventArgs e) { + string chargeOrderNo = _chargerClient.SendRemoteStartCharging(100); + _chargerClient.ChargeOrderNo = chargeOrderNo; + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnStopCharge_Click(object sender, EventArgs e) { + _chargerClient.SendRemoteStopCharging(0); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnChangePower_Click(object sender, EventArgs e) { + _chargerClient.SendPowerRegulation(1800); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnSetChargeRate_Click(object sender, EventArgs e) { + _chargerClient.SendAdjustChargeRate(10); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnOfflineStopCharge_Click(object sender, EventArgs e) { + _chargerClient.SendOfflineStopCharging(0); + MessageBox.Show(@"发送成功"); + DisplayData(); + } + + private void btnChangeInOrOut_Click(object sender, EventArgs e) + { + _chargerClient.SendChangeChargeMode(1); + MessageBox.Show(@"发送成功"); + DisplayData(); } + private void btnSendOutEnableCharge_Click(object sender, EventArgs e) { } private void btnSetPrice_Click(object sender, EventArgs e) { + SetPeakValleyTime setPeakValleyTime = new SetPeakValleyTime() + { + NumberTime = 8, + StartHH1 = 0, + StartHH2 = 3, + StartHH3 = 6, + StartHH4 = 9, + StartHH5 = 12, + StartHH6 = 15, + StartHH7 = 18, + StartHH8 = 21, + StartMM1 = 0, + StartMM2 = 0, + StartMM3 = 0, + StartMM4 = 0, + StartMM5 = 0, + StartMM6 = 0, + StartMM7 = 0, + StartMM8 = 0, + TimePeak1 = 1, + TimePeak2 = 2, + TimePeak3 = 3, + TimePeak4 = 4, + TimePeak5 = 4, + TimePeak6 = 3, + TimePeak7 = 2, + TimePeak8 = 1 + }; + + _chargerClient.SendSetPeakValleyTime(setPeakValleyTime); + MessageBox.Show(@"发送成功"); + DisplayData(); } private void btnReadBatteryInfo_Click(object sender, EventArgs e) { _chargerClient.SendQueryBattery(); + MessageBox.Show(@"发送成功"); + DisplayData(); + } + + private void btnRefreshData_Click(object sender, EventArgs e) + { DisplayData(); } } \ No newline at end of file